internal void DbProcessMenuButton(MenuButtonMessage message) { W_WeChatInfoBLL weChatInfoBll = new W_WeChatInfoBLL(); W_WeChatInfo weChatInfo = weChatInfoBll.GetByWechatID(message.ToUserName); if (weChatInfo == null) { return; } W_ResourcesCataBLL resourcesCataBll = new W_ResourcesCataBLL(); List <W_ResourcesCata> resourcesCataList = resourcesCataBll.GetByWeChatInfo(weChatInfo); if (resourcesCataList.Count <= 0) { return; } W_KeyWordBLL keyWordBll = new W_KeyWordBLL(); foreach (W_ResourcesCata resourcesCata in resourcesCataList) { List <W_KeyWord> keyWordList = keyWordBll.GetByResourcesCata(resourcesCata); foreach (W_KeyWord keyWord in keyWordList) { if (message.EventKey == keyWord.WKey) { DoKeyWord(keyWord); return; } } } }
// 改 public bool Update(W_WeChatInfo weChatInfo) { using (SqlHelper helper = WechatDataBaseHelper.Create()) { int rows = helper.ExecuteNonQuery("update [W_WeChatInfo] set AppID=@AppID,AppSecret=@AppSecret,Token=@Token,WechatID=@WechatID,AppNamespace=@AppNamespace,CreateTime=@CreateTime,IsDelete=@IsDelete where WID=@WID", new SqlParameter("@WID", weChatInfo.WID), new SqlParameter("@AppID", weChatInfo.AppID), new SqlParameter("@AppSecret", weChatInfo.AppSecret), new SqlParameter("@Token", weChatInfo.Token), new SqlParameter("@WechatID", weChatInfo.WechatID), new SqlParameter("@AppNamespace", weChatInfo.AppNamespace), new SqlParameter("@CreateTime", weChatInfo.CreateTime), new SqlParameter("@IsDelete", weChatInfo.IsDelete)); return(rows > 0); } }
// 删 public bool Delete(W_WeChatInfo weChatInfo) { using (SqlHelper helper = WechatDataBaseHelper.Create()) { int rows = helper.ExecuteNonQuery("delete from [W_WeChatInfo] where WID=@WID", new SqlParameter("@WID", weChatInfo.WID)); return(rows > 0); } }
// 增 public bool Add(W_WeChatInfo weChatInfo) { using (SqlHelper helper = WechatDataBaseHelper.Create()) { int rows = helper.ExecuteNonQuery("insert into [W_WeChatInfo] values (@WID,@AppID,@AppSecret,@Token,@WechatID,@AppNamespace,@CreateTime,@IsDelete)", new SqlParameter("@WID", weChatInfo.WID), new SqlParameter("@AppID", weChatInfo.AppID), new SqlParameter("@AppSecret", weChatInfo.AppSecret), new SqlParameter("@Token", weChatInfo.Token), new SqlParameter("@WechatID", weChatInfo.WechatID), new SqlParameter("@AppNamespace", weChatInfo.AppNamespace), new SqlParameter("@CreateTime", weChatInfo.CreateTime), new SqlParameter("@IsDelete", weChatInfo.IsDelete)); return(rows > 0); } }
internal void GetNamespaceFromDataBase() { if (this.Request != null) { string toUserName = this.Request.ToUserName; W_WeChatInfoBLL bll = new W_WeChatInfoBLL(); W_WeChatInfo weChatInfo = bll.GetByWechatID(toUserName); if (weChatInfo != null) { this.Namespace = weChatInfo.AppNamespace; } } }
public static Menu LoadFromDataBaseByAppId(string appid) { W_WeChatInfoBLL weChatInfoBll = new W_WeChatInfoBLL(); W_WeChatInfo weChatInfo = weChatInfoBll.GetByAppID(appid); W_MenuBLL menuBll = new W_MenuBLL(); List <W_Menu> menuButtons = menuBll.GetByWeChatInfo(weChatInfo).OrderBy(temp => temp.Sort).ToList();// 获取对应的一级菜单并按 sort 排序。 Menu menu = new Menu(); foreach (W_Menu menuButton in menuButtons) { MenuButton button = new MenuButton(); button.Name = menuButton.MenuName; if (menuButton.MenuType == "click") { button.Type = MenuButtonType.Click; button.Key = menuButton.MenuKey; } else if (menuButton.MenuType == "view") { button.Type = MenuButtonType.View; button.Url = menuButton.MenuURL; } List <W_Menu> menuSubButtons = menuBll.GetChildButtons(menuButton).OrderBy(temp => temp.Sort).ToList(); foreach (W_Menu menuSubButton in menuSubButtons) { MenuSubButton subButton = new MenuSubButton(); subButton.Name = menuButton.MenuName; if (menuSubButton.MenuType == "click") { subButton.Type = MenuButtonType.Click; subButton.Key = menuButton.MenuKey; } else if (menuSubButton.MenuType == "view") { subButton.Type = MenuButtonType.View; subButton.Url = menuSubButton.MenuURL; } button.SubButton.Add(subButton); } menu.Button.Add(button); } return(menu); }
internal void DbProcessText(TextMessage message) { W_WeChatInfoBLL weChatInfoBll = new W_WeChatInfoBLL(); W_WeChatInfo weChatInfo = weChatInfoBll.GetByWechatID(message.ToUserName); if (weChatInfo == null) { return; } W_ResourcesCataBLL resourcesCataBll = new W_ResourcesCataBLL(); List <W_ResourcesCata> resourcesCataList = resourcesCataBll.GetByWeChatInfo(weChatInfo); if (resourcesCataList.Count <= 0) { return; } W_KeyWordBLL keyWordBll = new W_KeyWordBLL(); foreach (W_ResourcesCata resourcesCata in resourcesCataList) { List <W_KeyWord> keyWordList = keyWordBll.GetByResourcesCata(resourcesCata); foreach (W_KeyWord keyWord in keyWordList) { if (keyWord.WOption == "Equals" && keyWord.WContent == message.Content) { DoKeyWord(keyWord); return; } else if (keyWord.WOption == "EqualsIgnoreCase" && string.Equals(keyWord.WContent, message.Content, StringComparison.OrdinalIgnoreCase) == true) { DoKeyWord(keyWord); return; } else if (keyWord.WOption == "Contains" && string.IsNullOrEmpty(message.Content) == false && message.Content.Contains(keyWord.WContent) == true) { DoKeyWord(keyWord); return; } else if (keyWord.WOption == "ContainsIgnoreCase" && string.IsNullOrEmpty(message.Content) == false && message.Content.IndexOf(keyWord.WContent, StringComparison.OrdinalIgnoreCase) >= 0) { DoKeyWord(keyWord); return; } } } }
public List <W_Menu> GetByWeChatInfo(W_WeChatInfo weChatInfo) { return(GetAll().Where(temp => temp.WID == weChatInfo.WID).ToList()); }
public static bool SaveToDataBase(Menu menu, string appid) { try { #region delete current database menu W_WeChatInfoBLL weChatInfoBll = new W_WeChatInfoBLL(); W_WeChatInfo weChatInfo = weChatInfoBll.GetByAppID(appid); W_MenuBLL menuBll = new W_MenuBLL(); List <W_Menu> menus = menuBll.GetByWeChatInfo(weChatInfo);// 一级菜单 foreach (W_Menu wMenu in menus) { List <W_Menu> subMenus = menuBll.GetChildButtons(wMenu); foreach (W_Menu subMenu in subMenus) { menuBll.Delete(subMenu); } menuBll.Delete(wMenu); } #endregion #region add current to database List <W_Menu> addList = new List <W_Menu>(); foreach (var button in menu.Button) { W_Menu w = new W_Menu(); w.MenuID = Guid.NewGuid().ToString(); w.WID = weChatInfo.WID; w.MenuName = button.Name; if (button.Type == MenuButtonType.Click) { w.MenuType = "click"; w.MenuKey = button.Key; } else if (button.Type == MenuButtonType.View) { w.MenuType = "view"; w.MenuURL = button.Key; } w.PMenuID = "0"; w.ResponseType = ""; w.ResourcesID = ""; w.CreateTime = DateTime.Now; w.IsDelete = 0; addList.Add(w); foreach (var subButton in button.SubButton) { W_Menu ww = new W_Menu(); ww.MenuID = Guid.NewGuid().ToString(); ww.WID = Guid.NewGuid().ToString(); ww.MenuName = subButton.Name; if (subButton.Type == MenuButtonType.Click) { ww.MenuType = "click"; ww.MenuKey = subButton.Key; } else if (subButton.Type == MenuButtonType.View) { ww.MenuType = "view"; ww.MenuURL = subButton.Url; } ww.PMenuID = w.MenuID; ww.ResponseType = ""; ww.ResourcesID = ""; ww.CreateTime = DateTime.Now; ww.IsDelete = 0; addList.Add(ww); } } foreach (var temp in addList) { menuBll.Add(temp); } return(true); #endregion } catch { return(false); } }
// 改 public bool Update(W_WeChatInfo weChatInfo) { return(new W_WeChatInfoDAL().Update(weChatInfo)); }
// 删 public bool Delete(W_WeChatInfo weChatInfo) { return(new W_WeChatInfoDAL().Delete(weChatInfo)); }
// 增 public bool Add(W_WeChatInfo weChatInfo) { return(new W_WeChatInfoDAL().Add(weChatInfo)); }