Beispiel #1
0
        public bool Update(WX_Menu model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update WX_Menu set MenuName=@MenuName,Url=@Url,KeywordId=@KeywordId,MenuType=@MenuType,Sort=@Sort,MasterID=@MasterID,MinIprogramAppId=@MinIprogramAppId,MinIprogramPagePath=@MinIprogramPagePath");
            strSql.Append(" where ID=@ID");

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("ID", model.ID);
                dbOperator.AddParameter("MenuName", model.MenuName);
                dbOperator.AddParameter("Url", model.Url);

                dbOperator.AddParameter("KeywordId", model.KeywordId);

                dbOperator.AddParameter("MenuType", (int)model.MenuType);
                dbOperator.AddParameter("Sort", model.Sort);

                dbOperator.AddParameter("MasterID", model.MasterID);

                dbOperator.AddParameter("MinIprogramAppId", model.MinIprogramAppId);
                dbOperator.AddParameter("MinIprogramPagePath", model.MinIprogramPagePath);
                return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
            }
        }
Beispiel #2
0
        private string GetMenuTypeValue(List <WX_Menu> menus, int id)
        {
            WX_Menu menu   = menus.FirstOrDefault(p => p.ID == id);
            var     childs = menus.Where(p => p.MasterID == id);

            if (menu.MasterID == 0 && childs.Count() > 0)
            {
                return(string.Empty);
            }
            if (menu.MenuType == MenuType.GKeyValue && menu.KeywordId != 0)
            {
                WX_Keyword keyword = WXKeywordServices.QueryById(menu.KeywordId);
                if (keyword != null)
                {
                    return(keyword.Keyword);
                }
            }
            if (menu.MenuType == MenuType.Url)
            {
                return(menu.Url);
            }
            if (menu.MenuType == MenuType.WeiXinModule && menu.KeywordId != 0)
            {
                return(((WeiXinModule)menu.KeywordId).GetDescription());
            }
            if (menu.MenuType == MenuType.MinIprogram)
            {
                return(menu.MinIprogramPagePath);
            }
            return(string.Empty);
        }
Beispiel #3
0
        public bool Create(WX_Menu model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into WX_Menu(MenuName,Url,KeywordId,MenuType,Sort,MasterID,DataStatus,CreateTime,CompanyID,MinIprogramAppId,MinIprogramPagePath)");
            strSql.Append(" values(@MenuName,@Url,@KeywordId,@MenuType,@Sort,@MasterID,@DataStatus,@CreateTime,@CompanyID,@MinIprogramAppId,@MinIprogramPagePath)");

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("MenuName", model.MenuName);
                dbOperator.AddParameter("Url", model.Url);
                dbOperator.AddParameter("KeywordId", model.KeywordId);

                dbOperator.AddParameter("MenuType", (int)model.MenuType);
                dbOperator.AddParameter("Sort", model.Sort);
                dbOperator.AddParameter("MasterID", model.MasterID);
                dbOperator.AddParameter("DataStatus", (int)model.DataStatus);
                dbOperator.AddParameter("CreateTime", DateTime.Now);
                dbOperator.AddParameter("CompanyID", model.CompanyID);
                dbOperator.AddParameter("MinIprogramAppId", model.MinIprogramAppId);
                dbOperator.AddParameter("MinIprogramPagePath", model.MinIprogramPagePath);
                return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
            }
        }
        public ActionResult Menu_Create(FormCollection form)
        {
            ResultBase_form result = new ResultBase_form();
            WX_Menu         m      = new WX_Menu();

            TryUpdateModel <WX_Menu>(m, form);
            m.CompanyID = UserDateTicket.Company.ID;
            switch (m.Type)
            {
            case 0:
                m.URL = "";
                break;

            case 1:
                m.KeyWordID = Guid.Empty;
                break;

            case 2:
                m.URL       = "";
                m.KeyWordID = Guid.Empty;
                break;
            }
            if (m.ID == Guid.Empty)
            {
                result.status = WX_MenuService.instance().Insert(m);
            }
            else
            {
                result.status = WX_MenuService.instance().Update(m);
            }
            result.msg       = result.status == 0 ? "操作失败" : "操作成功";
            result.ResultURL = "/WeChat/Menu_Index";
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #5
0
        public ActionResult Update(WX_Menu info)
        {
            info.AppId = WXAPP.AppId;
            var r = new WX_MenuManager().Update(info);

            return(Json(r, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
 private string GetKeywordId(WX_Menu menu)
 {
     if (menu.MenuType == MenuType.GKeyValue)
     {
         return(menu.KeywordId.ToString());
     }
     return(string.Empty);
 }
Beispiel #7
0
        public ActionResult AddMenu(WX_Menu menu)
        {
            menu.AppId       = WXAPP.AppId;
            menu.MenuVisable = 0;
            var result = new WX_MenuManager().Add(menu);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #8
0
 private string GetModuleId(WX_Menu menu)
 {
     if (menu.MenuType == MenuType.WeiXinModule)
     {
         return(menu.KeywordId.ToString());
     }
     return(string.Empty);
 }
Beispiel #9
0
        public static bool Update(WX_Menu model)
        {
            IWXMenu factory = WXMenuFactory.GetFactory();
            bool    result  = factory.Update(model);

            if (result)
            {
                OperateLogServices.AddOperateLog <WX_Menu>(model, OperateType.Update);
            }
            return(result);
        }
Beispiel #10
0
        //从服务器拉取菜单
        public void Pull()
        {
            var            str     = new MenuService(WXAPP.AppId, WXAPP.AppSecret).Get();
            var            json    = JObject.Parse(str)["menu"]["button"];
            WX_MenuManager manager = new WX_MenuManager();
            var            r       = manager.Clear(WXAPP.AppId);

            foreach (var i in json.Children())
            {
                var menu = new WX_Menu();
                menu.AppId       = WXAPP.AppId;
                menu.MenuName    = i["name"].ToString();
                menu.MenuVisable = 0;
                if (i["sub_button"].Count() > 0)
                {
                    foreach (var j in i["sub_button"])
                    {
                        var sub_menu = new WX_Menu();
                        sub_menu.AppId       = WXAPP.AppId;
                        sub_menu.MenuName    = j["name"].ToString();
                        sub_menu.MenuVisable = 0;
                        string type = j["type"].ToString();
                        if (type.Equals("click"))
                        {
                            sub_menu.MenuKey = j["key"].ToString();
                            sub_menu.TypeId  = 1;
                        }
                        else
                        {
                            sub_menu.MenuUrl = j["url"].ToString();
                            sub_menu.TypeId  = 2;
                        }
                        menu.TypeId = 1;
                        menu.WX_Menu1.Add(sub_menu);
                    }
                }
                else
                {
                    string type = i["type"].ToString();
                    if (type.Equals("click"))
                    {
                        menu.MenuKey = i["key"].ToString();
                        menu.TypeId  = 1;
                    }
                    else
                    {
                        menu.MenuUrl = i["url"].ToString();
                        menu.TypeId  = 2;
                    }
                }

                manager.Add(menu);
            }
        }
Beispiel #11
0
        private string GetMenuTypeDescription(List <WX_Menu> menus, int id)
        {
            WX_Menu menu   = menus.FirstOrDefault(p => p.ID == id);
            var     childs = menus.Where(p => p.MasterID == id);

            if (menu.MasterID == 0 && childs.Count() > 0)
            {
                return(string.Empty);
            }
            return(menu.MenuType.GetDescription());
        }
        public ActionResult Menu_Create(string id)
        {
            WX_Menu m;

            if (string.IsNullOrEmpty(id))
            {
                m = new WX_Menu();
            }
            else
            {
                m = WX_MenuService.instance().Single(new Guid(id));
            }
            return(View(m));
        }
        public JsonResult Menu_Delete(string id)
        {
            WX_Menu m = WX_MenuService.instance().Single(new Guid(id));
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("DR", !m.DR);
            if (WX_MenuService.instance().ModifColumn(dic, id))
            {
                return(Json(new { status = 1, id = m.ID, dr = !m.DR }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { status = 0 }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #14
0
        private static JObject GetJson(this WX_Menu menu, JArray info)
        {
            JObject staff = new JObject();

            if (menu.WX_Menu1.Count() > 0)   //返回子菜单合集
            {
                JArray sub_button = new JArray();
                foreach (var i in menu.WX_Menu1)
                {
                    JObject temp = new JObject();
                    if (i.TypeId == 1)
                    {
                        temp.Add(new JProperty("type", i.WX_MenuType.TypeName));
                        temp.Add(new JProperty("name", i.MenuName));
                        temp.Add(new JProperty("key", i.MenuKey));
                    }
                    else
                    {
                        temp.Add(new JProperty("type", i.WX_MenuType.TypeName));
                        temp.Add(new JProperty("name", i.MenuName));
                        temp.Add(new JProperty("url", i.MenuUrl));
                    }
                    sub_button.Add(temp);
                }
                staff.Add(new JProperty("name", menu.MenuName));
                staff.Add(new JProperty("sub_button", sub_button));
            }
            else
            {
                if (menu.TypeId == 1)
                {
                    staff.Add(new JProperty("type", menu.WX_MenuType.TypeName));
                    staff.Add(new JProperty("name", menu.MenuName));
                    staff.Add(new JProperty("key", menu.MenuKey));
                }
                else
                {
                    staff.Add(new JProperty("type", menu.WX_MenuType.TypeName));
                    staff.Add(new JProperty("name", menu.MenuName));
                    staff.Add(new JProperty("url", menu.MenuUrl));
                }
            }
            info.Add(staff);
            return(staff);
        }
Beispiel #15
0
        public static bool Delete(string companyId, int menuId)
        {
            if (menuId < 1)
            {
                throw new ArgumentNullException("menuId");
            }

            IWXMenu        factory = WXMenuFactory.GetFactory();
            List <WX_Menu> models  = factory.GetMenus(companyId);
            WX_Menu        model   = models.FirstOrDefault(p => p.ID == menuId);

            if (model != null && models.Count(p => p.MasterID == menuId) > 0)
            {
                throw new MyException("请先删除该菜单下的二级菜单");
            }
            bool result = factory.Delete(menuId);

            if (result)
            {
                OperateLogServices.AddOperateLog(string.Format("删除菜单编号为:{0}菜单", menuId), OperateType.Update);
            }
            return(result);
        }
Beispiel #16
0
        public static bool IsHasEvent(this WX_Menu menu)
        {
            var r = new WXDataEntities().WX_MenuEvent.Where(m => m.MenuKey.Equals(menu.MenuKey)).Count() > 0;

            return(r);
        }
Beispiel #17
0
 public JsonResult AddOrUpdate(WX_Menu model)
 {
     try
     {
         model.MasterID = model.MasterID == -1 ? 0 : model.MasterID;
         CheckMenu(model.MasterID, model.ID, model.CompanyID);
         if (model.MenuType == Common.Entities.Enum.MenuType.Url)
         {
             if (string.IsNullOrWhiteSpace(model.Url))
             {
                 throw new MyException("请填写链接地址");
             }
             model.KeywordId = 0;
         }
         if (model.MenuType == Common.Entities.Enum.MenuType.GKeyValue)
         {
             if (model.KeywordId == 0)
             {
                 throw new MyException("请选择关键字");
             }
             model.Url = string.Empty;
         }
         if (model.MenuType == Common.Entities.Enum.MenuType.WeiXinModule)
         {
             if (string.IsNullOrWhiteSpace(Request["Module"]))
             {
                 throw new MyException("请选择系统模块");
             }
             model.KeywordId = int.Parse(Request["Module"].ToString());
             model.Url       = string.Empty;
         }
         if (model.MenuType == Common.Entities.Enum.MenuType.MinIprogram)
         {
             if (string.IsNullOrWhiteSpace(model.Url))
             {
                 throw new MyException("请填写链接地址");
             }
             if (string.IsNullOrWhiteSpace(model.MinIprogramAppId))
             {
                 throw new MyException("请填写小程序APPID");
             }
             if (string.IsNullOrWhiteSpace(model.MinIprogramPagePath))
             {
                 throw new MyException("请填写小程序的页面路径");
             }
         }
         if (model.ID < 1)
         {
             bool result = WXMenuServices.Create(model);
             if (!result)
             {
                 throw new MyException("添加失败");
             }
         }
         else
         {
             bool result = WXMenuServices.Update(model);
             if (!result)
             {
                 throw new MyException("修改失败");
             }
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "保存菜单信息失败");
         return(Json(MyResult.Error("保存失败")));
     }
 }