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 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); }