PdnMainMenu.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using SmartCoalApplication.SystemLayer;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace SmartCoalApplication.Menus
  9. {
  10. /// <summary>
  11. /// 主菜单容器
  12. /// 包含所有菜单
  13. /// </summary>
  14. internal sealed class PdnMainMenu : MenuStripEx
  15. {
  16. private FileMenu fileMenu;
  17. private MeasureMenu measureMenu;
  18. private EditMenu editMenu;
  19. public ImageCollectionMenu imageCollectionMenu;
  20. private ImageMenu imageMenu;
  21. private SettingMenu settingMenu;
  22. private MeasureProcedureMenu measureProcedureMenu;
  23. private HelpMenu helpMenu;
  24. private AppWorkspace appWorkspace;
  25. private string[] menuIdArr;
  26. public AppWorkspace AppWorkspace
  27. {
  28. get
  29. {
  30. return this.appWorkspace;
  31. }
  32. set
  33. {
  34. this.appWorkspace = value;
  35. this.fileMenu.AppWorkspace = value;
  36. //this.measureMenu.AppWorkspace = value;
  37. this.editMenu.AppWorkspace = value;
  38. this.imageCollectionMenu.AppWorkspace = value;
  39. this.imageMenu.AppWorkspace = value;
  40. this.settingMenu.AppWorkspace = value;
  41. this.measureProcedureMenu.AppWorkspace = value;
  42. this.helpMenu.AppWorkspace = value;
  43. }
  44. }
  45. public PdnMainMenu()
  46. {
  47. InitializeComponent();
  48. //模块管理,暂时先注释掉
  49. InitializeModule();
  50. }
  51. private void InitializeComponent()
  52. {
  53. this.fileMenu = new FileMenu(100);
  54. //this.measureMenu = new MeasureMenu(230);
  55. this.editMenu = new EditMenu(300);
  56. this.imageCollectionMenu = new ImageCollectionMenu(400);
  57. this.imageMenu = new ImageMenu(500);
  58. this.settingMenu = new SettingMenu(1300);
  59. this.measureProcedureMenu = new MeasureProcedureMenu(900);
  60. this.helpMenu = new HelpMenu(1400);
  61. SuspendLayout();
  62. //
  63. // PdnMainMenu
  64. //
  65. this.Name = "PdnMainMenu";
  66. this.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
  67. this.Items.AddRange(
  68. new ToolStripItem[]
  69. {
  70. this.fileMenu,
  71. //this.measureMenu,
  72. //this.editMenu,
  73. //this.imageCollectionMenu,
  74. this.imageMenu,
  75. this.measureProcedureMenu,
  76. this.settingMenu,//###
  77. this.helpMenu
  78. });
  79. ResumeLayout();
  80. }
  81. /// <summary>
  82. /// 模块管理
  83. /// 需要先从加密锁过滤一遍
  84. /// 然后再模块管理的配置过滤一遍
  85. /// </summary>
  86. private void InitializeModule()
  87. {
  88. /*if (Startup.instance.moduleConfigModel != null)
  89. {
  90. for (int i = 0; i < this.Items.Count; i++)
  91. {
  92. this.Items[i].Visible = false;
  93. if (Startup.instance.moduleConfigModel.items.Find(a => a.ParentId == ((PdnMenuItem)this.Items[i]).MenuId) != null)
  94. {
  95. this.Items[i].Visible = true;
  96. }
  97. }
  98. }*/
  99. //以下为新的模块管理代码
  100. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\ModuleConfig.txt";
  101. if (System.IO.File.Exists(filePath))
  102. {
  103. string str = System.IO.File.ReadAllText(filePath);
  104. if (str.IndexOf(',') != -1)
  105. {
  106. menuIdArr = str.Split(',');
  107. }
  108. else
  109. {
  110. if (!string.IsNullOrEmpty(str))
  111. {
  112. menuIdArr = new string[] { str };
  113. }
  114. }
  115. if (menuIdArr != null && menuIdArr.Count() > 0)
  116. {
  117. RecursionMenuId(this.Items, 0);
  118. }
  119. else
  120. {
  121. ////模块管理永远显示(已取消的业务注释)
  122. //for (int i = 0; i < this.Items.Count; i++)
  123. //{
  124. // this.Items[i].Visible = false;
  125. // if (this.Items[i].Name == "Menu.Setting")
  126. // {
  127. // this.Items[i].Visible = true;
  128. // if (((PdnMenuItem)this.Items[i]).DropDownItems.Count > 0)
  129. // {
  130. // ToolStripItemCollection collection = ((PdnMenuItem)this.Items[i]).DropDownItems;
  131. // for (int j = 0; j < collection.Count; j++)
  132. // {
  133. // collection[j].Visible = false;
  134. // if (collection[j].Name == "ModuleSetting")
  135. // {
  136. // //collection[j].Visible = true;
  137. // }
  138. // }
  139. // }
  140. // }
  141. //}
  142. }
  143. }
  144. }
  145. /// <summary>
  146. ///
  147. /// </summary>
  148. /// <param name="toolStripItemCollection"></param>
  149. /// <param name="parentLevel"></param>
  150. /// <returns>返回父菜单是否显示</returns>
  151. private bool RecursionMenuId(ToolStripItemCollection toolStripItemCollection, int parentLevel)
  152. {
  153. bool showParentMenu = false;
  154. if (toolStripItemCollection != null && toolStripItemCollection.Count > 0)
  155. {
  156. bool toShowSeparator = false;
  157. if (parentLevel > 1)
  158. toShowSeparator = true;
  159. for (int i = 0; i < toolStripItemCollection.Count; i++)
  160. {
  161. if (toolStripItemCollection[i].GetType() != typeof(ToolStripSeparator))
  162. {
  163. bool showToolStripItemI = false;
  164. //toolStripItemCollection[i].Visible = false;
  165. if (Array.IndexOf(menuIdArr, ((PdnMenuItem)toolStripItemCollection[i]).MenuId.ToString()) != -1 && Program.getMenuIdVisible(((PdnMenuItem)toolStripItemCollection[i]).MenuId))
  166. {
  167. showToolStripItemI = true;
  168. ////toolStripItemCollection[i].Visible = true;
  169. //if (parentLevel == 1)
  170. // toShowSeparator = true;
  171. }
  172. ////控制最后一条分割线不显示
  173. //else if (parentLevel == 1 && i == toolStripItemCollection.Count - 1)
  174. //{
  175. // for (int last_i = toolStripItemCollection.Count - 2; last_i > 0; last_i--)
  176. // {
  177. // if (toolStripItemCollection[last_i].GetType() != typeof(ToolStripSeparator))
  178. // {
  179. // //if (Array.IndexOf(menuIdArr, ((PdnMenuItem)toolStripItemCollection[last_i]).MenuId.ToString()) != -1)
  180. // break;
  181. // }
  182. // else
  183. // toolStripItemCollection[last_i].Visible = false;
  184. // }
  185. //}
  186. ////模块管理永远显示(已取消的业务注释)
  187. //if (toolStripItemCollection[i].Name.Equals("ModuleSetting") || toolStripItemCollection[i].Name.Equals("Menu.Setting"))
  188. //{
  189. // //toolStripItemCollection[i].Visible = true;
  190. // showParentMenu = true;
  191. //}
  192. //控制所有子菜单都没有授权的父菜单也不显示
  193. if (showToolStripItemI && (RecursionMenuId(((PdnMenuItem)toolStripItemCollection[i]).DropDownItems, parentLevel + 1) || toolStripItemCollection[i].Name.Equals("OpenRecent")))
  194. {
  195. toolStripItemCollection[i].Visible = true;
  196. toShowSeparator = true;
  197. showParentMenu = true;
  198. }
  199. else
  200. toolStripItemCollection[i].Visible = false;
  201. }
  202. else if (parentLevel == 1 && toShowSeparator)
  203. toShowSeparator = false;
  204. else if (parentLevel == 1 && !toShowSeparator)
  205. toolStripItemCollection[i].Visible = false;
  206. }
  207. }
  208. else
  209. showParentMenu = true;
  210. return showParentMenu;
  211. }
  212. }
  213. }