using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using System.Web.Configuration;
using System.Text.RegularExpressions; 


public partial class feedBackClass : System.Web.UI.Page
{
	DeepSoonHelp dh = null;
	
	MysqlHelp mh = null;

	///说说配置参变量
	FeedBackInfor fi = null;
	
	int articlePageSize = 6;
	int articlePageCount = 1;
	int articlePageStart = 0;
	int articlePageCurrent = 0;
	
	protected void Page_Load(object sender, EventArgs e)
    {
		///不保存缓存，防止刷新重复提交
		Response.Cache.SetNoStore();
		
		///创建函数库
		dh = new DeepSoonHelp();
		
		///创建数据连接对象：
		mh = new MysqlHelp();
		
		///获取模板内容
		string themeHtml = dh.getThemeHtml("T_feedBack.html");
				
		///读取配置表信息：
		fi = dh.getFeedBackInfor();
		
		string helpStr = "<span class='feedBackHelp'>";
		helpStr += "#提示："+fi.setSize+"字内";
		if(fi.setPass){
			helpStr += "，新发布的说说需审核后方能显示!</span>";
		}
		helpStr += "</span>";
		
		string feedBackFormStr = "";
		if(fi.setOpen){
			feedBackFormStr += "<form action='feedBack.aspx' method='post'style='margin:0px;'>";
			feedBackFormStr += "<textarea name='feedBackContent' id='feedBackContent' class='content4FeedBack'></textarea><br>";
			feedBackFormStr += "<input type='Hidden' name='feedBackFatherID' value='0'>";
			feedBackFormStr += "<img src='System_Img/faceLogo.png' onclick='$getElementBy(\"facePanel\").style.position = \"absolute\";showFace(\"feedBackContent\",event);' style='cursor:pointer;float:left;'>";
			feedBackFormStr += "<input type='Text' name='feedBackAuthor' class='author4FeedBack' Value='请输入名字' onblur='if(this.value==\"\"){this.value=\"请输入名字\";}' onfocus='if(this.value==this.defaultValue){this.value=\"\";}'>";
			feedBackFormStr += "<input type='submit' value='"+fi.setButtonName+"' class='button4FeedBack'>";
			feedBackFormStr += "<div id='facePanel4feedBackContent'></div>";
			feedBackFormStr += "<div style='clear:both;'></div>";
			feedBackFormStr += "</form>";
		
			//this.labelfeedBackForm.Text = feedBackFormStr;
			//this.labelHelp.Text = helpStr;
		}
		else{
			fi.setContent = fi.setTitle+"已被管理员关闭!暂时不可以提交新信息。";
			feedBackFormStr = "";
			helpStr = "";
		}
		
		if( themeHtml.Contains("{dp:FeedBackTitle}") ){
				themeHtml = themeHtml.Replace("{dp:FeedBackTitle}", fi.setTitle);
		}
		if( themeHtml.Contains("{dp:FeedBackAddInfor}") ){
			themeHtml = themeHtml.Replace("{dp:FeedBackAddInfor}", fi.setContent);
		}
		if( themeHtml.Contains("{dp:feedBackForm}") ){
			themeHtml = themeHtml.Replace("{dp:feedBackForm}", feedBackFormStr);
			}
		if( themeHtml.Contains("{dp:FeedBackHelp}") ){
			themeHtml = themeHtml.Replace("{dp:FeedBackHelp}", helpStr);
		}
		
		///统计说说
		string feedBackCountSum = dh.countFeedBack();
		if( themeHtml.Contains("{dp:feedBackCount}") ){
				themeHtml = themeHtml.Replace("{dp:feedBackCount}", "已有"+feedBackCountSum+"条说说<br><br>");
		}
		
		///标题以及当前位置：
		Page.Title = fi.setTitle+"</b> &gt; <b>正文</b>";
						
		string feedBackAuthor = Request.Form["feedBackAuthor"];
		string feedBackContent = Request.Form["feedBackContent"];
		string feedBackFatherID = Request.Form["feedBackFatherID"];
		
		if(feedBackAuthor != null && feedBackContent != null && feedBackFatherID != null){
			dh.addFeedBack(fi,feedBackAuthor,feedBackContent,feedBackFatherID);
			Response.Redirect("feedBack.aspx");
		}
		
		///获取articlePageCurrentStr
		string articlePageCurrentStr = Request.QueryString["Page"];
		///获取合法的articlePageCurrentStr
		articlePageCurrentStr = dh.getValidateNumStr(articlePageCurrentStr);
		///获取当前页码		
		articlePageCurrent = Convert.ToInt32(articlePageCurrentStr);
		
		///获取feedID
		string feedIDStr = Request.QueryString["feedID"];
		///获取合法的feedID
		feedIDStr = dh.getValidateNumStr(feedIDStr);
		
		///查询符合条件的记录总数：
		articlePageCount = dh.getSumFeedBack(fi);
		///计算记录总数总共可以分为多少页：
		int PageCount = articlePageCount/articlePageSize;
		if(articlePageCount%articlePageSize==0)PageCount = PageCount-1;
		///如果当前页码越界：
		if( articlePageCurrent < 0 )articlePageCurrent=0;
		if( articlePageCurrent > PageCount)articlePageCurrent = PageCount;
		///查询记录的起始位置：
		articlePageStart = articlePageSize * articlePageCurrent;
		
		///如果有记录
		string feedBackHtml = "";
		if(articlePageCount>0){
			feedBackHtml = dh.getFeedBackHtml(fi,feedIDStr,articlePageStart,articlePageSize);
		}
		else{
			feedBackHtml += "还没有任何动静。";
		}
		
		string PageContent = "<div class='ListPageBox'>";
		if(articlePageCurrent-1 >= 0){
			PageContent += "<a href='feedBack.aspx?page="+(articlePageCurrent-1)+"&feedID="+feedIDStr+"'><div class='pageButton'>&lt;</div></a> ";
		}
		else PageContent += "<div class='pageGrayButton'>&lt;</div>";
				
		if(articlePageCurrent < PageCount){
			PageContent += "<a href='feedBack.aspx?page="+(articlePageCurrent+1)+"&feedID="+feedIDStr+"'><div class='pageButton'>&gt;</div></a> ";
		}
		else PageContent += "<div class='pageGrayButton'>&gt;</div>";
		PageContent += "</div>";
		
		feedBackHtml += PageContent;
		
		if( themeHtml.Contains("{dp:FeedBackContent}") ){
				themeHtml = themeHtml.Replace("{dp:FeedBackContent}", feedBackHtml);
		}
		
        this.labelFeedBackContent.Text = themeHtml;
    }
	
	
}