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_WLWayDO : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
            this.databind();
        
    }
    protected void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        string type = Request.QueryString["type"].ToString().Trim();
        switch(type)
        {
            case "add":
                this.LinkButton1.Click+=new EventHandler(Add_Click);
                this.Label1.Text = "配送方式添加";
                break;
            case "edit":
                if (!IsPostBack)
                {
                    SqlCommand smd = new SqlCommand("select * from PWway where id=" + Request.QueryString["id"], conn);
                    SqlDataReader sdr = smd.ExecuteReader();
                    sdr.Read();
                    this.Label1.Text = "配送方式编辑";
                    this.title.Text = sdr.GetString(3);
                    this.sort.Text = Convert.ToString(sdr.GetInt32(8));
                    this.Description.Text = Server.HtmlDecode(sdr.GetString(6));
                    if (sdr.GetString(7) == "y")
                    {
                        this.y.Checked = true;
                    }
                    else
                    {
                        this.n.Checked = true;
                    }
                    sdr.Close();
                }
                this.LinkButton1.Click+=new EventHandler(edit_Click);
                break;
            case "change":
                switch (Request.QueryString["sta"])
                { 
                    case "open":

                        if (Doadmin.Exec("update PWway set isshow='y' where id="+Request.QueryString["id"].Trim()))
                        {
                            Response.Write("<script>alert('开启成功');window.location.href='../System/wuliuSet.aspx'</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('此次操作失败');window.location.href='../System/wuliuSet.aspx'</script>");
                        }
                        break;
                    case "close":
                        if (Doadmin.Exec("update PWway set isshow='n' where id=" + Request.QueryString["id"].Trim()))
                        {
                            Response.Write("<script>alert('操作成功');window.location.href='../System/wuliuSet.aspx'</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('此次操作失败');window.location.href='../System/wuliuSet.aspx'</script>");
                        }
                        break;
                }
                break;
            case "del":
                if (Doadmin.Exec("delete from PWway where id=" + Request.QueryString["id"]))
                {
                    Response.Write("<script>alert('操作成功');window.location.href='../System/wuliuSet.aspx'</script>");
                }
                else
                {
                    Response.Write("<script>alert('此次操作失败');window.location.href='../System/wuliuSet.aspx'</script>");
                }
                break;


        }
        conn.Close();


    }
    protected void edit_Click(object sender, EventArgs e)
    {
        string arvlu, altext, title, DefrayExpenses, GuaranteesPrice, sort, Description, isshow;
        arvlu = "001";
        altext = "长安";
        title = this.title.Text;
        DefrayExpenses ="0";
        GuaranteesPrice = "0";
        sort = this.sort.Text;
        Description = Server.HtmlEncode(this.Description.Text.Replace("'", "''")).Replace("\n", "<br />");
        if (this.y.Checked)
        {
            isshow = "y";
        }
        else
        {
            isshow = "n";
        }
        string sqlstr = "update PWway set bigId=" + arvlu + ",bigName='" + altext + "',title='" + title + "',DefrayExpenses=" + DefrayExpenses + ",GuaranteesPrice=" + GuaranteesPrice + ",Description='" + Description + "',isshow='" + isshow + "',sort=" + sort + " where id=" + Request.QueryString["id"].Trim();

        if (Doadmin.Exec(sqlstr))
        {
            Response.Write("<script>alert('提交成功');window.location.href='../System/wuliuSet.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作失败');window.location.href='WLWayDO.aspx'</script>");
        }
    }
    protected void Add_Click(object sender, EventArgs e)
    {

        string arvlu, altext, title, DefrayExpenses, GuaranteesPrice, sort, Description, isshow;
        arvlu = "001";
        altext = "长安";
        title = this.title.Text;
        DefrayExpenses ="0";
        GuaranteesPrice ="0";
        sort = this.sort.Text;
        Description = Server.HtmlEncode(this.Description.Text.Replace("'", "''")).Replace("\n", "<br />");
        if (this.y.Checked)
        {
            isshow = "y";
        }
        else
        {
            isshow = "n";
        }
        string sqlstr = "insert into PWway (bigId,bigName,title,DefrayExpenses,GuaranteesPrice,Description,isshow,sort) values ("+arvlu+",'" + altext + "','" + title + "'," + DefrayExpenses + "," + GuaranteesPrice + ",'" + Description + "','" + isshow + "'," + sort + ")";
        if (Doadmin.Exec(sqlstr))
        {
            Response.Write("<script>alert('添加成功');window.location.href='../System/wuliuSet.aspx'</script>");
        }
        else
        {
            Response.Write(sqlstr);
            Response.Write("<script>alert('此次操作失败');window.location.href='WLWayDO.aspx?type=add'</script>");
        }
    }
}
