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 MailSetting : 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;
				string Host="smtp.126.com";
				string Account="";
				string PWD="";
				string FromMail="XXX@126.com";
				string ToMail="XXX@qq.com";
	
				DataTable settingDt=new DataTable();
				settingDt = mh.GetDatabysql("Select * From MailSetting4DeepSoon");
				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"];
					Host = settingDt.Rows[0]["Host"].ToString();
					Account = settingDt.Rows[0]["Account"].ToString();
					PWD = settingDt.Rows[0]["PWD"].ToString();
					FromMail = settingDt.Rows[0]["FromMail"].ToString();
					ToMail = settingDt.Rows[0]["ToMail"].ToString();
				}
				this.txtSetTitle.Text = setTitle;
				this.txtSetContent.Text = setContent;
				this.txtSetButtonName.Text = setButtonName;				
				if(setOpen){
					this.dropSetOpen.SelectedIndex = 0;
				}else{
					this.dropSetOpen.SelectedIndex = 1;
				}				
				this.txtHost.Text = ""+Host;
				this.txtAccount.Text = ""+Account;
				this.txtPWD.Text = ""+PWD;
				this.txtFromMail.Text = ""+FromMail;
				this.txtToMail.Text = ""+ToMail;
            }			
        }
		
		
		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;
			
			string setHost = this.txtHost.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			string setAccount = this.txtAccount.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			string setPWD = this.txtPWD.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			string setFromMail = this.txtFromMail.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			string setToMail = this.txtToMail.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			
			
			
			if(setTitle!="" && setContent !="" && setButtonName!="" && setHost!="" && setAccount!= "" && setPWD!="" && setFromMail!="" && setToMail!="")///如果用户输入的参数没有空项
			{
				///创建数据连接对象：
				MysqlHelp mh = new MysqlHelp();
				///修改参数：
				mh.Runsql("Update MailSetting4DeepSoon Set setTitle='"+setTitle+"',setContent='"+setContent+"',setButtonName='"+setButtonName+"',setOpen="+setOpen+",Host='"+setHost+"',Account='"+setAccount+"',PWD='"+setPWD+"',FromMail='"+setFromMail+"',ToMail='"+setToMail+"'");
				this.labelUpdateInfor.Text="邮箱配置已经保存!";
				Response.Redirect("DeepSoonMailSetting.aspx");	
			}
			else {
					this.labelUpdateInfor.Text="请将必填项填写完整!";
			}
		}

	}//end class
}//end nameSpace