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_Products_EmailAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        switch (Request.QueryString["type"].ToString().Trim())
        { 
            case "add":   
                this.title.Text = "添加自定义邮件";
                this.LinkButton1.Click+=new EventHandler(ADDemail);

                break;
            case "edit":
                this.title.Text = "编辑自定义邮件";
                if (!IsPostBack)
                {
                    SqlConnection conn = CDatabase.wtoconn();
                    conn.Open();
                    SqlCommand smd = new SqlCommand("select emailFL,content from email where lx='0' and type='0' and id=" + Request.QueryString["id"], conn);
                    SqlDataReader sdr = smd.ExecuteReader();
                    sdr.Read();
                    this.zt.Text = sdr.GetString(0);
                    this.Content.Text = Server.HtmlDecode(sdr.GetString(1));
                    sdr.Close();
                    conn.Close();
                }
                this.LinkButton1.Click+=new EventHandler(EDITemail);
                break;

        }
    }
    protected void ADDemail(object sender, EventArgs e)
    {
        string title,cont1;
        title = this.zt.Text;
        cont1 = (this.Content.Text.Replace("'", "''")).Replace("\n", "<br />");
        string sqlstr = "insert into email(lx,type,name,emailFL,isopen,content,addtime,posttime,title) values('0','0','自定义邮件','"+title+"','y','"+cont1+"','"+DateTime.Now.ToString()+"','"+DateTime.Now.ToString()+"','"+title+"')";
        if (Doadmin.Exec(sqlstr))
        {
            Response.Write("<script>alert('操作成功');window.location.href='../email/Emailmag.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作不成功')</script>");
        }
    }
    protected void EDITemail(object sender, EventArgs e)
    {
        string title, cont1;
        title = this.zt.Text;
        cont1 = (this.Content.Text.Replace("'", "''")).Replace("\n", "<br />");
        string sqlstr = "update email set emailFL='"+title+"',content='"+cont1+"' where lx='0' and  id="+Request.QueryString["id"];
        if (Doadmin.Exec(sqlstr))
        {
            Response.Write("<script>alert('操作成功');window.location.href='../email/Emailmag.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作不成功')</script>");
        }
    }
}
