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 System.Data.SqlClient;

public partial class WTOSYSadmin_System_SysEmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        if (!IsPostBack)
        {
            this.databind();
        }
    }
    protected void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select Email,SmtpMail,EmailPwd,RegEmailSet,FindPswEmailSet,EditVIPEmailSet,ConsignmentEmailSet,OrderEmailSet from SystemBasicInformation", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        this.Email.Text = sdr.GetString(0);
        this.SmtpMail.Text = sdr.GetString(1);
        this.EmailPwd.Text = sdr.GetString(2);
        if (sdr.GetString(3) == "y")
        {
            this.RegEmailSet.Checked = true;
        }
        else
        {
            this.RegEmailSet.Checked = false;
        }
        if (sdr.GetString(4) == "y")
        {
            this.FindPswEmailSet.Checked = true;
        }
        else
        {
            this.FindPswEmailSet.Checked = false;
        }
        if (sdr.GetString(5)=="y")
        {
            this.EditVIPEmailSet.Checked = true;
        }
        else
        {
            this.EditVIPEmailSet.Checked = false;
        }
        if (sdr.GetString(6) == "y")
        {
            this.ConsignmentEmailSet.Checked = true;
        }
        else
        {
            this.ConsignmentEmailSet.Checked = false;
        }
        if (sdr.GetString(7) == "y")
        {
            this.OrderEmailSet.Checked = true;
        }
        else
        {
            this.OrderEmailSet.Checked = false;
        }
        sdr.Close();
        conn.Close();
    }

    protected void LinkButton1_Click1(object sender, EventArgs e)
    {
        //设置值
        string Email, EmailPwd,SmtpMail, RegEmailSet, FindPswEmailSet, EditVIPEmailSet, ConsignmentEmailSet, OrderEmailSet;
        //文本框取值
        
        Email = this.Email.Text;
        EmailPwd = this.EmailPwd.Text;
        SmtpMail = this.SmtpMail.Text;
     
        //其他控件取值
        if (this.RegEmailSet.Checked)
        {
            RegEmailSet = "y";
        }
        else
        {
            RegEmailSet = "n";
        }
        if (this.FindPswEmailSet.Checked)
        {
            FindPswEmailSet = "y";
        }
        else
        {
            FindPswEmailSet = "n";
        }
        if (this.EditVIPEmailSet.Checked)
        {
            EditVIPEmailSet = "y";
        }
        else
        {
            EditVIPEmailSet = "n";
        }
        if (this.ConsignmentEmailSet.Checked)
        {
            ConsignmentEmailSet = "y";
        }
        else
        {
            ConsignmentEmailSet = "n";
        }
        if (this.OrderEmailSet.Checked)
        {
            OrderEmailSet = "y";
        }
        else
        {
            OrderEmailSet = "n";
        }
        //LOGO上传

        string sqlstr = "update SystemBasicInformation set Email='"+Email+"',EmailPwd='"+EmailPwd+"',SmtpMail='"+SmtpMail+"',RegEmailSet='" + RegEmailSet + "',FindPswEmailSet='" + FindPswEmailSet + "',EditVIPEmailSet='" + EditVIPEmailSet + "',ConsignmentEmailSet='" + ConsignmentEmailSet + "',OrderEmailSet='" + OrderEmailSet + "'";
        if (Doadmin.Exec(sqlstr))
        {
            Doadmin.Exec("update  email set isopen='" + RegEmailSet + "' where lx='1'");
            Doadmin.Exec("update  email set isopen='" + FindPswEmailSet + "' where lx='2'");
            Doadmin.Exec("update  email set isopen='" + EditVIPEmailSet + "' where lx='3'");
            Doadmin.Exec("update  email set isopen='" + ConsignmentEmailSet + "' where lx='4'");
            Doadmin.Exec("update  email set isopen='" + OrderEmailSet + "' where lx='5'");
            Response.Write("<script>alert('更改成功!');window.location.href='SysEmail.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('操作失败');window.location.href='SysEmail.aspx'</script>");
        }
    }
    protected void LinkButton2_Click1(object sender, EventArgs e)
    {
        //初始化系统
        string sqlstr = "update SystemBasicInformation set Email='lb@WTO168.com',RegEmailSet='y',FindPswEmailSet='y',EditVIPEmailSet='y',ConsignmentEmailSet='y',OrderEmailSet='y',SmtpMail='mail.wto168.com',EmailPwd='123456'";
        if (Doadmin.Exec(sqlstr))
        {
            Response.Write("<script>alert('还原成功!');window.location.href='SysEmail.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('操作失败');window.location.href='SysEmail.aspx'</script>");
        }
    }
}
