Esempio n. 1
0
        public void AddMenus(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string   s    = "{\"status\":\"1\"}";
            MenuInfo menu = new MenuInfo
            {
                Content = context.Request["Content"].Trim(),
                Name    = context.Request["Name"].Trim(),
                Bind    = 8
            };

            if (context.Request["ParentMenuId"] != null)
            {
                menu.ParentMenuId = (context.Request["ParentMenuId"] == "") ? 0 : int.Parse(context.Request["ParentMenuId"]);
            }
            else
            {
                menu.ParentMenuId = 0;
            }
            menu.Type = context.Request["Type"];
            if (VShopHelper.CanAddFuwuMenu(menu.ParentMenuId))
            {
                if (VShopHelper.SaveFuwuMenu(menu))
                {
                    if (menu.ParentMenuId > 0)
                    {
                        MenuInfo fuwuMenu = VShopHelper.GetFuwuMenu(menu.ParentMenuId);
                        if (fuwuMenu != null)
                        {
                            fuwuMenu.Bind    = 0;
                            fuwuMenu.Content = "";
                            VShopHelper.UpdateFuwuMenu(fuwuMenu);
                        }
                    }
                    s = "{\"status\":\"0\"}";
                }
            }
            else
            {
                s = "{\"status\":\"2\"}";
            }
            context.Response.Write(s);
        }
        private void btnAddMenu_Click(object sender, EventArgs e)
        {
            if ((this.ddlType.SelectedValue == "1") && (this.ddlValue.Items.Count <= 0))
            {
                this.ShowMsgToTarget("关键字不能为空", false, "parent");
            }
            else
            {
                MenuInfo menu = new MenuInfo();
                if (this.id > 0)
                {
                    menu = VShopHelper.GetFuwuMenu(this.id);
                }
                else
                {
                    menu.ParentMenuId = this.parentid;
                    if (!VShopHelper.CanAddFuwuMenu(menu.ParentMenuId))
                    {
                        this.ShowMsgToTarget("一级菜单不能超过三个,对应二级菜单不能超过五个", false, "parent");
                        return;
                    }
                }
                int    num = 0x10;
                string msg = "菜单标题不超过16个字节!";
                if (menu.ParentMenuId > 0)
                {
                    num = 14;
                    msg = "二级菜单不超过14个字节!";
                }
                string text = this.txtMenuName.Text;
                if (string.IsNullOrEmpty(text))
                {
                    this.ShowMsgToTarget("请填写菜单名称!", false, "parent");
                }
                else if (this.GetStrLen(text) > num)
                {
                    this.ShowMsgToTarget(msg, false, "parent");
                }
                else
                {
                    menu.Name = this.txtMenuName.Text;
                    menu.Type = "click";
                    if (menu.ParentMenuId == 0)
                    {
                        menu.Type = "view";
                    }
                    else if (string.IsNullOrEmpty(this.ddlType.SelectedValue) || (this.ddlType.SelectedValue == "0"))
                    {
                        this.ShowMsgToTarget("二级菜单必须绑定一个对象", false, "parent");
                        return;
                    }
                    menu.Bind = Convert.ToInt32(this.ddlType.SelectedValue);
                    BindType bindType = menu.BindType;
                    switch (bindType)
                    {
                    case BindType.Key:
                        menu.ReplyId = Convert.ToInt32(this.ddlValue.SelectedValue);
                        break;

                    case BindType.Topic:
                        menu.Content = this.ddlValue.SelectedValue;
                        break;

                    default:
                        if (bindType == BindType.Url)
                        {
                            menu.Content = this.txtUrl.Text.Trim();
                        }
                        break;
                    }
                    if (this.id > 0)
                    {
                        if (VShopHelper.UpdateFuwuMenu(menu))
                        {
                            this.DoFunction("菜单修改成功!");
                        }
                        else
                        {
                            this.ShowMsgToTarget("菜单添加失败", false, "parent");
                        }
                    }
                    else if (VShopHelper.SaveFuwuMenu(menu))
                    {
                        this.DoFunction("菜单添加成功!");
                    }
                    else
                    {
                        this.ShowMsgToTarget("菜单添加失败", false, "parent");
                    }
                }
            }
        }