frmCustommenuManager.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. using LYFZ.Weixin.SDK;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. namespace LYFZ.Software.MainBusiness.OAShopManagement
  8. {
  9. public class frmCustommenuManager:LYFZ.Software.UI.OAShopManagement.frmCustommenuManager
  10. {
  11. public int ID = 0;
  12. public string MenuData = "";
  13. BLL.BLL_ErpMicroInterface bllInterface = new BLL.BLL_ErpMicroInterface();
  14. public frmCustommenuManager(){
  15. this.Load += frmCustommenuManager_Load;
  16. this.btnxiazaiMenu.Click += btnxiazaiMenu_Click;
  17. this.btnUpdateMenu.Click += btnUpdateMenu_Click;
  18. this.btnReset.Click += btnReset_Click;
  19. this.linkLabelURL.Click += linkLabelURL_Click;
  20. this.btnSaveData.Click += btnSaveData_Click;
  21. }
  22. void btnSaveData_Click(object sender, EventArgs e)
  23. {
  24. if (CustommenuConfigureModel != null)
  25. {
  26. try
  27. {
  28. UpdateCurrentMenuList();
  29. if (SaveData())
  30. {
  31. MessageBoxCustom.Show("当前菜单配置已保存成功");
  32. }
  33. else
  34. {
  35. MessageBoxCustom.Show("当前菜单配置保存失败");
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. MessageBoxCustom.Show("当前菜单配置保存出错:" + ex.Message);
  41. }
  42. }
  43. }
  44. /// <summary>
  45. /// 保存菜单配置
  46. /// </summary>
  47. /// <returns></returns>
  48. bool SaveData()
  49. {
  50. if (CustommenuConfigureModel != null)
  51. {
  52. CustommenuConfigureModel.Sconfig_Value = CustomMenuAPI.GetMenuDataXML(CurrentMenuList);
  53. if (ID > 0)
  54. {
  55. LYFZ.Model.Model_ErpMicroInterface modFace = bllInterface.GetModel(ID);
  56. modFace.MenuData = CustommenuConfigureModel.Sconfig_Value;
  57. bllInterface.Update(modFace);
  58. }
  59. MenuData = CustommenuConfigureModel.Sconfig_Value;
  60. return bllMIF.UpdateMicroInterfaceCustommenuModel(CustommenuConfigureModel);
  61. }
  62. else
  63. {
  64. return false;
  65. }
  66. }
  67. void linkLabelURL_Click(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. System.Diagnostics.Process.Start(BLL.BLL_MicroInterface.GetGlobalReturnCodeURL());
  72. }
  73. catch { }
  74. }
  75. void btnReset_Click(object sender, EventArgs e)
  76. {
  77. for (int i = 1; i <= 3; i++)
  78. {
  79. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString()];
  80. cbxType.SelectedIndex=-1;
  81. ComponentLibrary.TextBoxEx txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  82. txtevalue.Text = "";
  83. ComponentLibrary.TextBoxEx txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtmname")];
  84. txtmname.Text = "";
  85. for (int j = 1; j <= 5; j++)
  86. {
  87. ComponentLibrary.ComboBoxEx sub_cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString() + "_" + j.ToString()];
  88. sub_cbxType.SelectedIndex = -1;
  89. ComponentLibrary.TextBoxEx sub_txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[sub_cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  90. sub_txtevalue.Text = "";
  91. ComponentLibrary.TextBoxEx sub_txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[sub_cbxType.Name.Replace("cbxmenutype", "txtmname")];
  92. sub_txtmname.Text = "";
  93. }
  94. }
  95. }
  96. /// <summary>
  97. /// 当前菜单集合
  98. /// </summary>
  99. List<MenuModel> CurrentMenuList = new List<MenuModel>();
  100. void UpdateCurrentMenuList()
  101. {
  102. CurrentMenuList.Clear();
  103. for (int i = 1; i <= 3; i++)
  104. {
  105. MenuModel mMode = new MenuModel();
  106. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString()];
  107. ComponentLibrary.TextBoxEx txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  108. ComponentLibrary.TextBoxEx txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtmname")];
  109. if (txtmname.Text.Trim().Length > 0)
  110. {
  111. mMode.Name = txtmname.Text.Trim();
  112. ItemValue typeItem = (ItemValue)cbxType.SelectedItem;
  113. CustomWXMenuType menuType = (CustomWXMenuType)typeItem.Value;
  114. if (SetMenuModel(mMode, menuType, txtevalue.Text.Trim()))
  115. {
  116. for (int j = 1; j <= 5; j++)
  117. {
  118. MenuModel sub_mMode = new MenuModel();
  119. ComponentLibrary.ComboBoxEx sub_cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString() + "_" + j.ToString()];
  120. ComponentLibrary.TextBoxEx sub_txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[sub_cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  121. ComponentLibrary.TextBoxEx sub_txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[sub_cbxType.Name.Replace("cbxmenutype", "txtmname")];
  122. if (sub_txtmname.Text.Trim().Length > 0)
  123. {
  124. sub_mMode.Name = sub_txtmname.Text.Trim();
  125. ItemValue sub_typeItem = (ItemValue)sub_cbxType.SelectedItem;
  126. CustomWXMenuType sub_menuType = (CustomWXMenuType)sub_typeItem.Value;
  127. if (SetMenuModel(sub_mMode, sub_menuType, sub_txtevalue.Text.Trim()))
  128. {
  129. mMode.Sub_buttons.Add(sub_mMode);
  130. }
  131. else
  132. {
  133. return;
  134. }
  135. }
  136. else
  137. {
  138. continue;
  139. }
  140. }
  141. CurrentMenuList.Add(mMode);
  142. }
  143. else {
  144. return;
  145. }
  146. }
  147. else {
  148. continue;
  149. }
  150. }
  151. }
  152. bool SetMenuModel(MenuModel _Model,CustomWXMenuType cMtype,string value)
  153. {
  154. if (value.Trim().Length <= 0 && cMtype!= CustomWXMenuType.Sub_button)
  155. {
  156. MessageBoxCustom.Show("请设置菜单事件值");
  157. return false; }
  158. string[] menuTypeDescriptions = LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(cMtype).Split('|');
  159. _Model.Type = (WXMenuType)Enum.Parse(typeof(WXMenuType), menuTypeDescriptions[1]);
  160. switch (_Model.Type)
  161. {
  162. case WXMenuType.click:
  163. case WXMenuType.location_select:
  164. _Model.Key = value;
  165. break;
  166. case WXMenuType.view:
  167. _Model.Url =value; //value;
  168. break;
  169. case WXMenuType.miniprogram:
  170. string[] tempValues = value.Split('|');
  171. if (tempValues.Length == 3)
  172. {
  173. _Model.Appid = tempValues[0];
  174. _Model.Pagepath = tempValues[1];
  175. _Model.Url = tempValues[2]; //value;
  176. }
  177. else {
  178. MessageBoxCustom.Show("链接小程序菜单事件值格试错误");
  179. return false;
  180. }
  181. break;
  182. case WXMenuType.view_limited:
  183. case WXMenuType.media_id:
  184. _Model.Media_id = value;
  185. break;
  186. case WXMenuType.scancode_waitmsg:
  187. case WXMenuType.scancode_push:
  188. case WXMenuType.pic_sysphoto:
  189. case WXMenuType.pic_photo_or_album:
  190. case WXMenuType.pic_weixin:
  191. _Model.Key = value;
  192. break;
  193. case WXMenuType.sub_button: break;
  194. default:
  195. goto case WXMenuType.click;
  196. // break;
  197. }
  198. return true;
  199. }
  200. void BindMenuType()
  201. {
  202. for (int i = 1; i <= 3; i++)
  203. {
  204. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString()];
  205. BindMenuType(cbxType);
  206. for (int j = 1; j <= 5; j++)
  207. {
  208. ComponentLibrary.ComboBoxEx sub_cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString()+"_"+j.ToString()];
  209. BindMenuType(sub_cbxType);
  210. }
  211. }
  212. }
  213. void BindMenuType(ComponentLibrary.ComboBoxEx cbxType)
  214. {
  215. cbxType.Items.Clear();
  216. foreach (int value in Enum.GetValues(typeof(LYFZ.Weixin.SDK.CustomWXMenuType)))
  217. {
  218. try
  219. {
  220. CustomWXMenuType menuType = (CustomWXMenuType)value;
  221. if (cbxType.Name.Contains("_") && menuType == CustomWXMenuType.Sub_button)
  222. {
  223. continue;
  224. }
  225. else
  226. {
  227. string[] menuTypeDescriptions = LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(menuType).Split('|');
  228. cbxType.Items.Add(new ItemValue(menuType, menuTypeDescriptions[0]));
  229. }
  230. }
  231. catch { }
  232. }
  233. cbxType.SelectedIndexChanged += cbxType_SelectedIndexChanged;
  234. cbxType.KeyUp += cbxType_KeyUp;
  235. }
  236. void cbxType_KeyUp(object sender, KeyEventArgs e)
  237. {
  238. if (e.KeyCode == Keys.Delete)
  239. {
  240. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)sender;
  241. cbxType.SelectedIndex = -1;
  242. }
  243. }
  244. void cbxType_SelectedIndexChanged(object sender, EventArgs e)
  245. {
  246. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)sender;
  247. ComponentLibrary.TextBoxEx txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  248. if (cbxType.SelectedItem != null)
  249. {
  250. ItemValue titem = (ItemValue)cbxType.SelectedItem;
  251. CustomWXMenuType menuType = (CustomWXMenuType)titem.Value;
  252. switch (menuType)
  253. {
  254. case CustomWXMenuType.Sub_button:
  255. txtevalue.Text = "";
  256. txtevalue.ReadOnly = true;
  257. break;
  258. case CustomWXMenuType.Click:
  259. txtevalue.ReadOnly = false;
  260. break;
  261. case CustomWXMenuType.View:
  262. txtevalue.ReadOnly = false;
  263. // txtevalue.Text = "";
  264. break;
  265. case CustomWXMenuType.miniprogram:
  266. txtevalue.ReadOnly = false;
  267. break;
  268. /* case CustomWXMenuType.LYFZ_OrderQuery:
  269. case CustomWXMenuType.LYFZ_MobileAPP:
  270. case CustomWXMenuType.LYFZ_MemberQuery:
  271. case CustomWXMenuType.LYFZ_JCBDZH:
  272. case CustomWXMenuType.LYFZ_AccountBonding:
  273. txtevalue.ReadOnly = true;
  274. txtevalue.Text = menuType.ToString();
  275. if (menuType == CustomWXMenuType.LYFZ_MobileAPP)
  276. {
  277. txtevalue.Text = LYFZ.BLL.BLL_MicroInterface.GetWebAPPGoToUrl(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.SDomainName.ToString());
  278. }
  279. break;*/
  280. default:
  281. txtevalue.ReadOnly = false;
  282. break;
  283. }
  284. }
  285. else
  286. {
  287. txtevalue.ReadOnly = false;
  288. }
  289. }
  290. LYFZ.BLL.BLL_MicroInterface bllMIF = new BLL.BLL_MicroInterface();
  291. //LYFZ.Model.Model_MicroInterface modelMIF = new Model.Model_MicroInterface();
  292. LYFZ.Model.Model_ErpMicroInterface modelMIF = new LYFZ.Model.Model_ErpMicroInterface();
  293. void btnUpdateMenu_Click(object sender, EventArgs e)
  294. {
  295. if (MessageBoxCustom.Show("确定要上传自定义菜单到服务器并替换吗?", msgBoxButton: MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  296. {
  297. string updateMenuMsg = "";
  298. foreach (MenuModel mMdel in CurrentMenuList)
  299. {
  300. if (mMdel.Type == WXMenuType.sub_button && mMdel.Sub_buttons.Count <= 0)
  301. {
  302. MessageBoxCustom.Show(mMdel.Name + " 菜单类型为“含有子菜单”,但实际含有子菜单为0个,请设置完整后重试。");
  303. return;
  304. }
  305. }
  306. UpdateCurrentMenuList();
  307. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  308. {
  309. try
  310. {
  311. backgroundWorker.ReportProgress(0, "正在保存菜单配置...");
  312. if (!SaveData())
  313. {
  314. MessageBoxCustom.Show("当前菜单配置保存失败,请重试");
  315. return;
  316. }
  317. backgroundWorker.ReportProgress(0, "正在上传菜单...");
  318. string menudata =CustomMenuAPI.GetMenuDataString(CurrentMenuList);
  319. if (CurrentMenuList.Count <= 0)
  320. {
  321. if (MessageBoxCustom.Show("当前没有任何自定义菜单项,如果继续上传将删除服务器上的菜单?", msgBoxButton: MessageBoxButtons.YesNo, backgroundWorker: backgroundWorker) == System.Windows.Forms.DialogResult.Yes)
  322. {
  323. updateMenuMsg = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET("http://wx.lyfz.net/WeiXinAPP/WXServiceHandler.aspx?type=delmenu&appid=" + modelMIF.AppID.Trim(), Encoding.UTF8);
  324. }
  325. else
  326. {
  327. updateMenuMsg = "";
  328. }
  329. }
  330. else
  331. {
  332. updateMenuMsg = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestPOST("http://wx.lyfz.net/WeiXinAPP/WXServiceHandler.aspx?type=addmenu&appid=" + modelMIF.AppID.Trim(), menudata, Encoding.UTF8);
  333. }
  334. }
  335. catch (Exception ex) { updateMenuMsg = "上传菜单时错误:" + ex.Message; }
  336. });
  337. if (updateMenuMsg.Contains("\"errmsg\":\"ok\""))
  338. {
  339. MessageBoxCustom.Show("菜单上传成功");
  340. }
  341. else if (updateMenuMsg.Trim().Length>0)
  342. {
  343. if (updateMenuMsg.Contains("40001"))
  344. {
  345. LYFZ.Weixin.SDK.Helpers.TokenHelper.ClearAccessToken();
  346. }
  347. MessageBoxCustom.Show(updateMenuMsg);
  348. }
  349. }
  350. }
  351. void btnxiazaiMenu_Click(object sender, EventArgs e)
  352. {
  353. string getMenuMsg = "";//CustomMenuAPI.GetTempXmlString();
  354. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  355. {
  356. try
  357. {
  358. backgroundWorker.ReportProgress(0, "正在下载菜单...");
  359. //modelMIF = bllMIF.Model;
  360. /* modelMIF = bllMIF.Model;
  361. mConfig = new LYFZ.BLL.BLL_Config().GetModel_SysConfig();
  362. int PortNumber = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.WebServerPort;
  363. if (!LYFZ.WinAPI.CustomPublicMethod.CheckInternaNetworkAddress(mConfig.ServerHostOrIP) && LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.YS_EnableMapped)
  364. {
  365. PortNumber = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.YS_tAppport;
  366. }*/
  367. getMenuMsg = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET("http://wx.lyfz.net/WeiXinAPP/WXServiceHandler.aspx?type=getmenu&appid=" + modelMIF.AppID.Trim(), Encoding.UTF8);
  368. }
  369. catch (Exception ex) { getMenuMsg = "获取菜单时错误:"+ex.Message; }
  370. });
  371. string menuXmlString = "";
  372. try
  373. {
  374. System.Xml.XmlDocument xml = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(getMenuMsg);
  375. menuXmlString = xml.InnerXml;
  376. }
  377. catch(Exception ex)
  378. {
  379. if (getMenuMsg.ToLower().IndexOf("{\"menu") == 0)
  380. {
  381. getMenuMsg = String.Format("获取菜单时错误:不支持的个性化菜单,{0}", ex.Message);
  382. }
  383. else
  384. {
  385. getMenuMsg = String.Format("获取菜单时错误:{0} {1}", ex.Message, getMenuMsg);
  386. }
  387. }
  388. if (getMenuMsg.Contains("获取菜单时错误:"))
  389. {
  390. if (getMenuMsg.Contains("40001"))
  391. {
  392. // LYFZ.Weixin.SDK.Helpers.TokenHelper.ClearAccessToken();
  393. MessageBoxCustom.Show("获取access_token时AppSecret错误,或者access_token无效");
  394. }
  395. else if (getMenuMsg.Contains("46003"))
  396. {
  397. MessageBoxCustom.Show("代码:“46003”,当前公众号还没有创建自定义菜单项,请添加自定义菜单后点击“上传菜单”即可。");
  398. }
  399. else if (getMenuMsg.Contains("48001"))
  400. {
  401. MessageBoxCustom.Show("代码:“48001”,当前公众号 API 功能未授权,请确认公众号已获得该接口,可以在公众平台官网-开发者中心页中查看接口权限");
  402. }
  403. else if (getMenuMsg.Contains("40155"))
  404. {
  405. MessageBoxCustom.Show("代码:“40155”,请勿添加其他公众号的主页链接,请对 “http://mp.weixin.qq.com/mp/”这样的公众号页面网址做网址缩短处理");
  406. }
  407. else {
  408. MessageBoxCustom.Show(getMenuMsg);
  409. }
  410. }
  411. else
  412. {
  413. if (menuXmlString.Trim().Length > 0)
  414. {
  415. bindMenuTrrViewList(menuXmlString);
  416. MessageBoxCustom.Show("自定义菜单下载成功");
  417. }
  418. }
  419. }
  420. void bindMenuTrrViewList(string menuXmlStr)
  421. {
  422. if (menuXmlStr.Trim().Length > 0)
  423. {
  424. System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
  425. try
  426. {
  427. xml.LoadXml(menuXmlStr);
  428. CurrentMenuList = CustomMenuAPI.GetMenuModelList(xml);
  429. bindMenuTrrViewList();
  430. }
  431. catch (Exception ex)
  432. {
  433. MessageBoxCustom.Show("解析菜单时出错:" + ex.Message);
  434. }
  435. }
  436. }
  437. /// <summary>
  438. /// 帮定菜单树结构
  439. /// </summary>
  440. void bindMenuTrrViewList()
  441. {
  442. for (int i = 1; i <= 3; i++)
  443. {
  444. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString()];
  445. cbxType.SelectedIndex = -1;
  446. ComponentLibrary.TextBoxEx txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  447. txtevalue.Text = "";
  448. ComponentLibrary.TextBoxEx txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtmname")];
  449. txtmname.Text = "";
  450. for (int j = 1; j <= 5; j++)
  451. {
  452. ComponentLibrary.ComboBoxEx sub_cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls["cbxmenutype" + i.ToString() + "_" + j.ToString()];
  453. sub_cbxType.SelectedIndex = -1;
  454. ComponentLibrary.TextBoxEx sub_txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[sub_cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  455. sub_txtevalue.Text = "";
  456. ComponentLibrary.TextBoxEx sub_txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[sub_cbxType.Name.Replace("cbxmenutype", "txtmname")];
  457. sub_txtmname.Text = "";
  458. }
  459. }
  460. for (int i = 0; i < CurrentMenuList.Count; i++)
  461. {
  462. MenuModel mMode = CurrentMenuList[i];
  463. bindMenuTrrView(mMode, 1, i + 1,0);
  464. }
  465. }
  466. void bindMenuTrrView(MenuModel mMode, int level,int index,int pindex)
  467. {
  468. string cName = "cbxmenutype" + index.ToString();
  469. if (level == 1)
  470. {
  471. cName = "cbxmenutype" + index.ToString();
  472. }
  473. else {
  474. cName = "cbxmenutype" + pindex + "_" + index.ToString();
  475. }
  476. ComponentLibrary.ComboBoxEx cbxType = (LYFZ.ComponentLibrary.ComboBoxEx)this.plMenuManager.Controls[cName];
  477. ComponentLibrary.TextBoxEx txtevalue = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtevalue")];
  478. ComponentLibrary.TextBoxEx txtmname = (LYFZ.ComponentLibrary.TextBoxEx)this.plMenuManager.Controls[cbxType.Name.Replace("cbxmenutype", "txtmname")];
  479. setCbxType(cbxType, mMode);
  480. setEvAlue(txtevalue, mMode);
  481. txtmname.Text = mMode.Name;
  482. txtmname.Tag = mMode;
  483. if (mMode.Sub_buttons.Count > 0)
  484. {
  485. for (int i = 0; i < mMode.Sub_buttons.Count; i++)
  486. {
  487. bindMenuTrrView(mMode.Sub_buttons[i], 2, i + 1,index);
  488. }
  489. }
  490. }
  491. void setCbxType(ComponentLibrary.ComboBoxEx cbxType, MenuModel mMode)
  492. {
  493. // CustomWXMenuType menuType = (CustomWXMenuType)Enum.Parse(typeof(CustomWXMenuType), mMode.Type.ToString(), true);
  494. if (mMode.Sub_buttons.Count > 0)
  495. {
  496. cbxType.SelectedIndex = 0;
  497. }
  498. else
  499. {
  500. switch (mMode.Type)
  501. {
  502. case WXMenuType.sub_button:
  503. cbxType.SelectedIndex = 0;
  504. break;
  505. case WXMenuType.click:
  506. if (cbxType.Items.Count == 4)
  507. {
  508. cbxType.SelectedIndex = 1;
  509. }
  510. else {
  511. cbxType.SelectedIndex = 0;
  512. }
  513. break;
  514. case WXMenuType.view:
  515. if (cbxType.Items.Count == 4)
  516. {
  517. cbxType.SelectedIndex = 2;
  518. }
  519. else
  520. {
  521. cbxType.SelectedIndex = 1;
  522. }
  523. break;
  524. case WXMenuType.miniprogram:
  525. if (cbxType.Items.Count == 4)
  526. {
  527. cbxType.SelectedIndex = 3;
  528. }
  529. else
  530. {
  531. cbxType.SelectedIndex = 1;
  532. }
  533. break;
  534. default:
  535. if (cbxType.Items.Count == 4)
  536. {
  537. cbxType.SelectedIndex = 1;
  538. }
  539. else
  540. {
  541. cbxType.SelectedIndex = 0;
  542. }
  543. break;
  544. }
  545. }
  546. }
  547. string getEvalue(MenuModel mMode)
  548. {
  549. switch (mMode.Type)
  550. {
  551. case WXMenuType.click:
  552. case WXMenuType.location_select:
  553. return mMode.Key;
  554. //break;
  555. case WXMenuType.view:
  556. return mMode.Url;
  557. case WXMenuType.miniprogram:
  558. return mMode.Appid + "|" + mMode.Pagepath + "|" + mMode.Url;
  559. // break;
  560. case WXMenuType.view_limited:
  561. case WXMenuType.media_id:
  562. return mMode.Media_id;
  563. // break;
  564. case WXMenuType.scancode_waitmsg:
  565. case WXMenuType.scancode_push:
  566. case WXMenuType.pic_sysphoto:
  567. case WXMenuType.pic_photo_or_album:
  568. case WXMenuType.pic_weixin:
  569. return mMode.Key;
  570. // break;
  571. case WXMenuType.sub_button:
  572. return "";
  573. // break;
  574. default:
  575. goto case WXMenuType.click;
  576. // break;
  577. }
  578. //return mMode.Key;
  579. }
  580. void setEvAlue(ComponentLibrary.TextBoxEx txtevalue, MenuModel mMode)
  581. {
  582. switch (mMode.Type)
  583. {
  584. case WXMenuType.click:
  585. case WXMenuType.location_select:
  586. txtevalue.Text = mMode.Key;
  587. break;
  588. case WXMenuType.view:
  589. txtevalue.Text = mMode.Url;
  590. break;
  591. case WXMenuType.miniprogram:
  592. txtevalue.Text = mMode.Appid + "|" + mMode.Pagepath + "|" + mMode.Url;
  593. break;
  594. case WXMenuType.view_limited:
  595. case WXMenuType.media_id:
  596. txtevalue.Text = mMode.Media_id;
  597. break;
  598. case WXMenuType.scancode_waitmsg:
  599. case WXMenuType.scancode_push:
  600. case WXMenuType.pic_sysphoto:
  601. case WXMenuType.pic_photo_or_album:
  602. case WXMenuType.pic_weixin:
  603. txtevalue.Text = mMode.Key;
  604. break;
  605. case WXMenuType.sub_button:
  606. txtevalue.Text = "";
  607. break;
  608. default:
  609. goto case WXMenuType.click;
  610. // break;
  611. }
  612. }
  613. /// <summary>
  614. /// 当前配置的菜单数据
  615. /// </summary>
  616. LYFZ.Model.Model_ErpSystemConfigure CustommenuConfigureModel = null;
  617. void frmCustommenuManager_Load(object sender, EventArgs e)
  618. {
  619. BindMenuType();
  620. CustommenuConfigureModel = bllMIF.GetCustommenuModel();
  621. string menuDataXmlString = CustommenuConfigureModel.Sconfig_Value;
  622. if (ID > 0)
  623. {
  624. modelMIF = bllInterface.GetModel(ID);
  625. menuDataXmlString = modelMIF.MenuData;
  626. MenuData = modelMIF.MenuData;
  627. }
  628. else if (ID == 0)
  629. {
  630. menuDataXmlString = "";
  631. }
  632. if (menuDataXmlString.Trim().Length > 0)
  633. {
  634. bindMenuTrrViewList(menuDataXmlString);
  635. }
  636. }
  637. }
  638. }