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_Sysmain3 : 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 * from SystemBasicInformation", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        this.CompanyName.Text = sdr.GetString(2);
        this.WEBName.Text = sdr.GetString(3);
        this.ContactPerson.Text = sdr.GetString(4);
        this.Tel.Text = sdr.GetString(5);
        this.Fax.Text = sdr.GetString(6);
        this.Email.Text = sdr.GetString(7);
        this.QQ.Text = sdr.GetString(8);
        this.Post.Text = sdr.GetString(9);

        this.Address.Text = sdr.GetString(10);

        this.CopyRight.Text = sdr.GetString(11);
        this.ICPno.Text = sdr.GetString(12);
        this.MSN.Text = sdr.GetString(13);
        this.TBWW.Text = sdr.GetString(14);
        this.LOGOpicS.Text = sdr.GetString(15);
        this.Image2.Attributes.Add("onclick", "window.open('../../images/" + sdr.GetString(15) + "')");

        if (sdr.GetString(1) == "y")
        {
            this.y.Checked = true;
        }
        else
        {
            this.n.Checked = true;
        }
        if (sdr.GetString(16) == "y")
        {
            this.RegY.Checked = true;
        }
        else
        {
            this.RegN.Checked = true;
        }
        if (sdr.GetString(17) == "y")
        {
            this.My.Checked = true;
        }
        else
        {
            this.Mn.Checked = true;
        }
        if (sdr.GetString(18) == "y")
        {
            this.Py.Checked = true;
        }
        else
        {
            this.Pn.Checked = true;
        }
        this.IntegralSet.Text =Convert.ToString(sdr.GetInt32(19));
        if (sdr.GetString(20) == "y")
        {
            this.RegEmailSet.Checked = true;
        }
        else
        {
            this.RegEmailSet.Checked = false;
        }
        if (sdr.GetString(21) == "y")
        {
            this.FindPswEmailSet.Checked = true;
        }
        else
        {
            this.FindPswEmailSet.Checked = false;
        }
        if (sdr.GetString(22)=="y")
        {
            this.EditVIPEmailSet.Checked = true;
        }
        else
        {
            this.EditVIPEmailSet.Checked = false;
        }
        if (sdr.GetString(23) == "y")
        {
            this.ConsignmentEmailSet.Checked = true;
        }
        else
        {
            this.ConsignmentEmailSet.Checked = false;
        }
        if (sdr.GetString(24) == "y")
        {
            this.OrderEmailSet.Checked = true;
        }
        else
        {
            this.OrderEmailSet.Checked = false;
        }
        sdr.Close();
        conn.Close();
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        //设置值
        string isopen, CompanyName, WEBName, ContactPerson, Tel, Fax, Email, QQ, Post, Address, CopyRight, ICPno, MSN, TBWW, LOGOpic="", RegVIPset, MessageSet, ProcuctMSet, RegEmailSet, FindPswEmailSet, EditVIPEmailSet, ConsignmentEmailSet, OrderEmailSet;
        int IntegralSet;
        //文本框取值
        CompanyName = this.CompanyName.Text;
        WEBName = this.WEBName.Text;
        ContactPerson = this.ContactPerson.Text;
        Tel = this.Tel.Text;
        Fax = this.Fax.Text;
        Email = this.Email.Text;
        QQ = this.QQ.Text;
        Post = this.Post.Text;
        Address = this.Address.Text;
        CopyRight = this.CopyRight.Text;
        ICPno = this.ICPno.Text;
        MSN = this.MSN.Text;
        TBWW = this.TBWW.Text;
        IntegralSet=Convert.ToInt32(this.IntegralSet.Text);
        string pic ="01.gif";
        //其他控件取值
        if (this.y.Checked)
        {
            isopen = "y";
        }
        else
        {
            isopen = "n";
        }
        if (this.RegY.Checked)
        {
            RegVIPset = "y";
        }
        else
        {
            RegVIPset = "n";
        }
        if (this.My.Checked)
        {
            MessageSet = "y";
        }
        else
        {
            MessageSet = "n";
        }
        if (this.Py.Checked)
        {
            ProcuctMSet = "y";
        }
        else
        {
            ProcuctMSet = "n";
        }
        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 fname1 = this.LOGOpic.FileName;
        string fpath1 = this.LOGOpic.PostedFile.FileName;
        if (fpath1 != "")
        {
            string ftype1 = this.LOGOpic.PostedFile.ContentType;
            string[] type1 = ftype1.Split('/');
            string[] fn1 = fname1.Split('.');
            if (type1[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                LOGOpic = "L" + DateTime.Now.ToString("HHmmssffff") + ".jpg";
                string pt1 = Server.MapPath("~/images/" + LOGOpic);
                this.LOGOpic.SaveAs(pt1);
                this.LOGOpic.Dispose();
            }
        }
        else
        {
            LOGOpic = this.LOGOpicS.Text;
        }
        string sqlstr = "update SystemBasicInformation set isopen='" + isopen + "',CompanyName='" + CompanyName + "',WEBName='" + WEBName + "',ContactPerson='" + ContactPerson + "',Tel='" + Tel + "',Fax='"+Fax+"',Post='" + Post + "',qq='"+QQ+"',smallpic='" + pic + "',";
        sqlstr += "Address='"+Address+"',CopyRight='"+CopyRight+"',ICPno='"+ICPno+"',email='"+Email+"',MSN='"+MSN+"',TBWW='"+TBWW+"',LOGOpic='"+LOGOpic+"',RegVIPset='"+RegVIPset+"',";
        sqlstr += "MessageSet='"+MessageSet+"',ProcuctMSet='"+ProcuctMSet+"',IntegralSet="+IntegralSet+",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='Sysmain3.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('操作失败');window.location.href='Sysmain3.aspx'</script>");
        }


    }
}
