コード例 #1
0
ファイル: 副本 menu.aspx.cs プロジェクト: zklve/MallWechat
    protected void btnsaves_Click(object sender, EventArgs e)
    {
        Cms.BLL.wx_menu   wm  = new Cms.BLL.wx_menu();
        Cms.Model.wx_menu wmd = new Cms.Model.wx_menu();
        string            sid = "";

        if (ListBox1.SelectedItem != null)
        {
            sid = ListBox1.SelectedItem.Value;
        }

        if (ListBox2.SelectedItem != null)
        {
            sid = ListBox2.SelectedItem.Value;
        }

        if (ListBox3.SelectedItem != null)
        {
            sid = ListBox3.SelectedItem.Value;
        }


        string seven = ddeven.SelectedValue.ToString();

        if (sid != null && sid != "")
        {
            wmd      = wm.GetModel(int.Parse(sid));
            wmd.name = tbname.Text;
            if (seven == "0")
            {
                string smuen1 = tbmenu1.Text.Trim();
                string smuen2 = tbmenu2.Text.Trim();
                string smuen3 = tbmenu3.Text.Trim();
                string smuen4 = tbmenu4.Text.Trim();
                string smuen5 = tbmenu5.Text.Trim();
                string smuen  = "";
                if (smuen1 != "")
                {
                    smuen += smuen1 + ",";
                }
                if (smuen1 != "")
                {
                    smuen += smuen2 + ",";
                }
                if (smuen1 != "")
                {
                    smuen += smuen3 + ",";
                }
                if (smuen1 != "")
                {
                    smuen += smuen4 + ",";
                }
                if (smuen1 != "")
                {
                    smuen += smuen5 + ",";
                }
                if (smuen != "")
                {
                    smuen = smuen.Substring(0, smuen.Length - 1);
                }
                DataTable dtt    = wm.GetList("pid=" + sid).Tables[0];
                string    strid  = "";
                string    strid2 = "";
                foreach (DataRow dr in dtt.Rows)
                {
                    string str = dr["name"].ToString();
                    if (smuen.IndexOf(str) > -1)
                    {
                        strid += str + ",";
                    }
                    else
                    {
                        strid2 += dr["id"].ToString() + ",";
                    }
                }
                if (strid2 != "")
                {
                    strid2 = strid2.Substring(0, strid2.Length - 1);
                    wm.DeleteList(strid2);
                }

                string[] s = smuen.Split(',');
                foreach (string ss in s)
                {
                    if (strid.IndexOf(ss) == -1)
                    {
                        Cms.Model.wx_menu wmds = new Cms.Model.wx_menu();
                        wmds.name = ss;
                        wmds.pid  = sid;
                        wmds.time = DateTime.Now;
                        wm.Add(wmds);
                    }
                }
            }
            if (seven == "click")
            {
                wmd.type = "click";
                string skey = tbkey.Text.Trim();
                if (wmd.keys != skey)
                {
                    DataTable dt = wm.GetList("keys='" + skey + "'").Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('key值不能重复!')</script>");
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('key值不能重复!');", true);
                        return;
                    }
                }
                wmd.keys = tbkey.Text.Trim();
                wmd.info = tinfo.Value.Trim();
            }
            if (seven == "url")
            {
                wmd.keys = "";
                wmd.type = "view";
                wmd.url  = tburl.Text.Trim();
            }
            if (wm.Update(wmd))
            {
                // ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置成功!')</script>");
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('设置成功!');", true);
            }
            else
            {
                // ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置失败!')</script>");
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('设置失败!');", true);
            }
        }
        else
        {
            string name = tbname.Text.Trim();
            if (name != "")
            {
                DataTable dtwx = wm.GetList("").Tables[0];
                if (dtwx.Rows.Count == 0 || dtwx.Rows.Count < 3)
                {
                    wmd.name = name;
                    wmd.pid  = "0";
                    wmd.time = DateTime.Now;
                    if (wm.Add(wmd) > 0)
                    {
                        //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置成功!')</script>");
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('设置成功!');", true);
                    }
                    else
                    {
                        //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置失败!')</script>");
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('设置失败!');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('设置无效!');", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('设置无效!');", true);
            }
        }
    }