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 CommentSetting : PageBase
    {
		MysqlHelp mh = null;
		DataTable dt = null;
		protected void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
            {
				MysqlHelp mh = new MysqlHelp();
				
				///读取评论配置表信息：
				bool setOpen=true;
				bool setPass=false;
				int setSize=200;
				string openArea = "all";
				DataTable settingDt=new DataTable();
				settingDt = mh.GetDatabysql("Select * From CommentSetting4DeepSoon");
				if(settingDt.Rows.Count > 0){
					setOpen = (bool)settingDt.Rows[0]["setOpen"];
					setPass = (bool)settingDt.Rows[0]["setPass"];
					setSize = Convert.ToInt32(settingDt.Rows[0]["setSize"]);
					openArea = settingDt.Rows[0]["openArea"].ToString();
					///是否开放评论
					if(setOpen){
						this.dropSetOpen.SelectedIndex = 0;
					}else{
						this.dropSetOpen.SelectedIndex = 1;
					}
					///是否审核后显示
					if(setPass){
						this.dropSetPass.SelectedIndex = 0;
					}
					else {
						this.dropSetPass.SelectedIndex = 1;
					}
				
					///设定评论权限
					ListItem opentAreaItem=this.dropOpenArea.Items.FindByValue(openArea);
					if(opentAreaItem != null)
					{
						opentAreaItem.Selected = true;
					}
					///评论字数限制
					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)
		{
			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);
			
			string openArea = this.dropOpenArea.SelectedItem.Value;
			
			///创建数据连接对象：
			MysqlHelp mh = new MysqlHelp();
			///修改参数：
			mh.Runsql("Update CommentSetting4DeepSoon Set setOpen="+setOpen+",setPass="+setPass+",setSize="+setSize+",openArea='"+openArea+"'");
			this.labelUpdateInfor.Text="说说配置已经保存!";
			Response.Redirect("DeepSoonCommentSetting.aspx");	
			
		}

	}//end class
}//end nameSpace