protected void lnk_Delete_Click(object sender, System.EventArgs e) { if (!base.IsAuthorizedOp(ActionType.Delete.ToString())) { base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền"); } else { int @int = WebUtils.GetInt((sender as LinkButton).CommandArgument); WxMenuInfo dataById = WxMenu.GetDataById(@int); if (dataById == null) { base.ShowAjaxMsg(this.UpdatePanel1, "Những thông tin này không được tìm thấy, các dữ liệu không tồn tại hoặc đã bị xóa"); } else if (dataById.ChildCount > 0) { base.ShowAjaxMsg(this.UpdatePanel1, "包含子菜单,请先删除子菜单"); } else if (WxMenu.Del(@int)) { this.BindData(); PageBase.log.AddEvent(base.LoginAccount.AccountName, "删除微信菜单[" + dataById.Name + "] thành công"); base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công"); } else { base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại"); } } }
public static bool Del(int intID) { WxMenuInfo dataById = WxMenu.GetDataById(intID); bool result; if (dataById.ChildCount > 0) { result = false; } else if (BizBase.dbo.DeleteModel <WxMenuInfo>(dataById)) { if (dataById.ParentID > 0) { BizBase.dbo.UpdateTable(string.Concat(new object[] { "update weixin_WxMenu set ChildCount=ChildCount-1,ChildIDs=REPLACE(ChildIDs,',", intID, "','') where AutoID=", dataById.ParentID })); } if (!string.IsNullOrEmpty(dataById.EventKey)) { AutoRly.DelEventKey(dataById.EventKey); } result = true; } else { result = false; } return(result); }
public static WxStatus Add(WxMenuInfo entity, AutoRlyInfo eventKey) { int count; if (entity.ParentID == 0) { count = WxMenu.GetCount("ParentID=0"); } else { count = WxMenu.GetCount("ParentID=" + entity.ParentID); } WxStatus result; if (entity.ParentID.Equals(0) && count > 3) { result = WxStatus.一级菜单个数不超过3个; } else if (entity.ParentID > 0 && count > 5) { result = WxStatus.二级菜单个数不超过5个; } else { if (entity.Type == "click" && eventKey != null) { AutoRly.Add(eventKey); entity.EventKey = eventKey.MsgKey; } int num = WxMenu.Add(entity); if (num > 0) { entity.AutoID = num; if (entity.ParentID.Equals(0)) { entity.RootID = num; WxMenu.Update(entity); } else { WxMenuInfo dataById = WxMenu.GetDataById(entity.ParentID); entity.RootID = dataById.RootID; dataById.ChildCount++; dataById.ChildIDs = dataById.ChildIDs + "," + num; WxMenu.Update(entity); WxMenu.Update(dataById); } result = WxStatus.增加成功; } else { result = WxStatus.增加失败; } } return(result); }
public static int Add(WxMenuInfo entity) { int result; if (entity == null) { result = 0; } else { result = BizBase.dbo.InsertModel <WxMenuInfo>(entity); } return(result); }
private void InitForModify() { WxMenuInfo dataById = WxMenu.GetDataById(base.OpID); this.InitMenuType = dataById.Type; ListItem listItem = this.parentmenu.Items.FindByValue(dataById.ParentID.ToString()); if (listItem != null) { listItem.Selected = true; } this.parentmenu.Enabled = false; this.menuname.Text = dataById.Name; ListItem listItem2 = this.menutype.Items.FindByValue(dataById.Type); if (listItem2 != null) { listItem2.Selected = true; } if (dataById.Type == "click" && !string.IsNullOrEmpty(dataById.EventKey)) { AutoRlyInfo eventRly = AutoRly.GetEventRly(dataById.EventKey); if (eventRly != null) { this.TextBox1.Text = eventRly.MsgText; this.TextBox2.Text = eventRly.MediaPath; this.Image1.ImageUrl = eventRly.MediaPath; this.TextBox3.Text = eventRly.Description; this.TextBox4.Text = eventRly.LinkUrl; } } else { this.TextBox4.Text = dataById.Url; } }
public static WxStatus Update(WxMenuInfo entity, AutoRlyInfo eventKey) { WxMenuInfo dataById = WxMenu.GetDataById(entity.AutoID); WxStatus result; if (WxMenu.Update(entity)) { if (entity.Type == "view" && !string.IsNullOrEmpty(dataById.EventKey)) { AutoRly.DelEventKey(dataById.EventKey); } else if (entity.Type == "click" && dataById.Type != "click" && eventKey != null) { AutoRly.Add(eventKey); } else if (entity.Type == "click" && dataById.Type == "click" && eventKey != null) { AutoRlyInfo eventRly = AutoRly.GetEventRly(dataById.EventKey); if (eventRly != null) { eventRly.MsgText = eventKey.MsgText; eventRly.Description = eventKey.Description; eventRly.MediaPath = eventKey.MediaPath; eventRly.LinkUrl = eventKey.LinkUrl; eventRly.AutoTimeStamp = DateTime.Now; AutoRly.Update(eventRly); } } result = WxStatus.修改成功; } else { result = WxStatus.修改失败; } return(result); }
private void LoadFromServer() { AccessTokenResult token = CommonApi.GetToken(SinGooCMS.Weixin.Config.AppID, SinGooCMS.Weixin.Config.AppSecret, "client_credential"); string strUrl = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", token.access_token); string strValue = NetWorkUtils.HttpGet(strUrl); GetMenuResultFull getMenuResultFull = JsonUtils.JsonToObject <GetMenuResultFull>(strValue); if (getMenuResultFull != null && getMenuResultFull.menu != null && getMenuResultFull.menu.button.Count > 0) { WxMenu.EmptyLocal(); int num = 1; foreach (MenuFull_RootButton current in getMenuResultFull.menu.button) { WxMenuInfo wxMenuInfo = new WxMenuInfo { RootID = 0, ParentID = 0, Type = (current.type ?? string.Empty), Name = current.name, EventKey = (current.key ?? string.Empty), Url = (current.url ?? string.Empty), ChildCount = 0, ChildIDs = string.Empty, Sort = num, AutoTimeStamp = System.DateTime.Now }; int num2 = WxMenu.Add(wxMenuInfo); if (num2 > 0) { wxMenuInfo.AutoID = num2; wxMenuInfo.RootID = num2; num++; if (current.sub_button != null && current.sub_button.Count > 0) { wxMenuInfo.ChildCount = current.sub_button.Count; int num3 = 1; foreach (MenuFull_RootButton current2 in current.sub_button) { WxMenuInfo entity = new WxMenuInfo { RootID = num2, ParentID = num2, Type = (current2.type ?? string.Empty), Name = current2.name, EventKey = (current2.key ?? string.Empty), Url = (current2.url ?? string.Empty), ChildCount = 0, ChildIDs = string.Empty, Sort = num3, AutoTimeStamp = System.DateTime.Now }; int num4 = WxMenu.Add(entity); if (num4 > 0) { WxMenuInfo expr_27E = wxMenuInfo; expr_27E.ChildIDs = expr_27E.ChildIDs + num4 + ","; num3++; } } } if (wxMenuInfo.ChildIDs.EndsWith(",")) { wxMenuInfo.ChildIDs = wxMenuInfo.ChildIDs.TrimEnd(new char[] { ',' }); } WxMenu.Update(wxMenuInfo); } } } this.BindData(); }
protected void btnok_Click(object sender, System.EventArgs e) { if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString())) { base.ShowMsg("Không có thẩm quyền"); } else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString())) { base.ShowMsg("Không có thẩm quyền"); } else { WxMenuInfo wxMenuInfo = new WxMenuInfo(); if (base.IsEdit) { wxMenuInfo = WxMenu.GetDataById(base.OpID); } wxMenuInfo.ParentID = WebUtils.GetInt(this.parentmenu.SelectedValue); wxMenuInfo.Name = WebUtils.GetString(this.menuname.Text); wxMenuInfo.Type = this.menutype.SelectedValue; wxMenuInfo.Url = WebUtils.GetString(this.TextBox4.Text); wxMenuInfo.EventKey = string.Empty; AutoRlyInfo autoRlyInfo = new AutoRlyInfo { RlyType = "事件回复", MsgKey = StringUtils.GetRandomNumber(), MsgText = WebUtils.GetString(this.TextBox1.Text), MediaPath = WebUtils.GetString(this.TextBox2.Text), Description = WebUtils.GetString(this.TextBox3.Text), LinkUrl = WebUtils.GetString(this.TextBox4.Text) }; if (string.IsNullOrEmpty(wxMenuInfo.Name)) { base.ShowMsg("菜单名称不能为空"); } else if (wxMenuInfo.ParentID == 0 && wxMenuInfo.Name.Length > 4) { base.ShowMsg("一级菜单文字长度不超过4个汉字"); } else if (wxMenuInfo.ParentID > 0 && wxMenuInfo.Name.Length > 8) { base.ShowMsg("二级菜单文字长度不超过8个汉字"); } else if (wxMenuInfo.Type == "click" && string.IsNullOrEmpty(autoRlyInfo.MsgText)) { base.ShowMsg("图文推送文本不能为空"); } else if (wxMenuInfo.Type == "click" && (autoRlyInfo.MsgText.Length > 600 || autoRlyInfo.Description.Length > 600)) { base.ShowMsg("推送图文中的文本不能超过600汉字"); } else if (wxMenuInfo.Type == "view" && string.IsNullOrEmpty(autoRlyInfo.LinkUrl)) { base.ShowMsg("地址跳转的地址不能为空"); } else { if (base.Action.Equals(ActionType.Add.ToString())) { wxMenuInfo.Sort = WxMenu.MaxSort + 1; wxMenuInfo.AutoTimeStamp = System.DateTime.Now; WxStatus wxStatus = WxMenu.Add(wxMenuInfo, autoRlyInfo); if (wxStatus == WxStatus.增加成功) { PageBase.log.AddEvent(base.LoginAccount.AccountName, "添加微信菜单[" + wxMenuInfo.Name + "] thành công"); MessageUtils.DialogCloseAndParentReload(this); } else { base.ShowMsg(wxStatus.ToString()); } } if (base.Action.Equals(ActionType.Modify.ToString())) { WxStatus wxStatus2 = WxMenu.Update(wxMenuInfo, autoRlyInfo); if (wxStatus2 == WxStatus.修改成功) { PageBase.log.AddEvent(base.LoginAccount.AccountName, "修改微信菜单[" + wxMenuInfo.Name + "] thành công"); MessageUtils.DialogCloseAndParentReload(this); } else { base.ShowMsg(wxStatus2.ToString()); } } } } }
public static bool Update(WxMenuInfo entity) { return(entity != null && BizBase.dbo.UpdateModel <WxMenuInfo>(entity)); }