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

using Security;
namespace Security
{
    public partial class FeedBackSetting : PageBase
    {
		MysqlHelp mh = null;
		DataTable dt = null;
		protected void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
            {
				MysqlHelp mh = new MysqlHelp();
				
				///读取配置表信息：
				string setTitle="说说";
				string setContent="既然来了，就给我们说说吧!";
				string setButtonName="发表";
				bool setOpen=true;
				bool setPass=false;
				int setSize=200;
				DataTable settingDt=new DataTable();
				settingDt = mh.GetDatabysql("Select * From FeedBackSetting4DeepSoon");
				if(settingDt.Rows.Count > 0){
					setTitle = settingDt.Rows[0]["setTitle"].ToString();
					setContent = settingDt.Rows[0]["setContent"].ToString();
					setButtonName = settingDt.Rows[0]["setButtonName"].ToString();
					setOpen = (bool)settingDt.Rows[0]["setOpen"];
					setPass = (bool)settingDt.Rows[0]["setPass"];
					setSize = Convert.ToInt32(settingDt.Rows[0]["setSize"]);
				}
				this.txtSetTitle.Text = setTitle;
				this.txtSetContent.Text = setContent;
				this.txtSetButtonName.Text = setButtonName;				
				if(setOpen){
					this.dropSetOpen.SelectedIndex = 0;
				}else{
					this.dropSetOpen.SelectedIndex = 1;
				}				
				if(setPass){
					this.dropSetPass.SelectedIndex = 0;
				}
				else {
					this.dropSetPass.SelectedIndex = 1;
				}
				this.txtSetSize.Text = ""+setSize;
            }			
        }
		

		/// 功能：判断输入的是否是数字 
		/// 参数：string oText：源文本 
		/// 返回值：　bool true:是　false:否 
		public bool IsNumberic(string oText) 
		{ 
			try 
			{ 
				int var1=Convert.ToInt32 (oText); 
				return true; 
			} 
			catch 
			{ 
				return false; 
			} 
		}
		
		protected void btnUpdate_Click(object sender, EventArgs e)
		{
			string setTitle = this.txtSetTitle.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			if(setTitle.Length>20)setTitle = setTitle.Substring(0,20);			
			string setContent = this.txtSetContent.Text;
			string setButtonName = this.txtSetButtonName.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			if(setButtonName.Length>20)setButtonName = setButtonName.Substring(0,20);
			
			bool setOpen = true;
			string setOpenStr = this.dropSetOpen.SelectedItem.Value;
			if (setOpenStr=="false") setOpen = false;
			
			bool setPass = false;
			string setPassStr = this.dropSetPass.SelectedItem.Value;
			if (setPassStr == "true") setPass = true;
			
			int setSize = 200;
			if( this.txtSetSize.Text==null && !IsNumberic(this.txtSetSize.Text) )
				setSize = 200;
			else setSize = Convert.ToInt32(this.txtSetSize.Text);
			
			if(setTitle!="" && setContent !="" && setButtonName!="")///如果用户输入的参数没有空项
			{
				///创建数据连接对象：
				MysqlHelp mh = new MysqlHelp();
				///修改参数：
				mh.Runsql("Update FeedBackSetting4DeepSoon Set setTitle='"+setTitle+"',setContent='"+setContent+"',setButtonName='"+setButtonName+"',setOpen="+setOpen+",setPass="+setPass+",setSize="+setSize);
				this.labelUpdateInfor.Text="说说配置已经保存!";
				Response.Redirect("DeepSoonFeedBackSetting.aspx");	
			}
			else {
					this.labelUpdateInfor.Text="请将必填项填写完整!";
			}
		}

	}//end class
}//end nameSpace