NavagationBar.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Data;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using DevExpress.XtraNavBar;
  10. using System.Collections;
  11. using System.Reflection;
  12. namespace UAS_MES_NEW.CustomControl.AccordionMenu
  13. {
  14. public partial class NavagationBar : NavBarControl
  15. {
  16. StringBuilder sql = new StringBuilder();
  17. public static int WinIndex = 0;
  18. /// <summary>
  19. /// 记录当前功能面板中的按钮
  20. /// </summary>
  21. private ArrayList ArrFunButton = new ArrayList();
  22. /// <summary>
  23. /// 记录当前功能面板中的listview
  24. /// </summary>
  25. private ArrayList ArrFunListView = new ArrayList();
  26. /// <summary>
  27. /// 已经打开的Form
  28. /// </summary>
  29. public static Dictionary<string, int> OpenedFormName = new Dictionary<string, int>();
  30. public NavagationBar()
  31. {
  32. InitializeComponent();
  33. DataHelper dh = SystemInf.dh;
  34. if (dh == null)
  35. return;
  36. if (User.UserAccountType == "admin")
  37. {
  38. sql.Clear();
  39. sql.Append("select distinct sn_id,sn_detno,sn_module,sn_modulecode,sn_classname,sn_displayname,sn_caller ugp_caller,1 ugp_ifdelete,1 ugp_ifread,1 ugp_ifspecial,1 ugp_ifall,");
  40. sql.Append("1 ugp_ifwrite from CS$SYSNAVATION left join CS$USERGROUPPOWER on sn_caller=ugp_caller where sn_using=1 order by sn_modulecode,sn_detno");
  41. }
  42. else
  43. {
  44. sql.Clear();
  45. sql.Append("select sn_id,sn_detno,sn_module,sn_displayname,sn_modulecode,sn_classname,ugp_caller,max(ugp_ifdelete)ugp_ifdelete,max(ugp_ifread)ugp_ifread");
  46. sql.Append(",max(ugp_ifspecial)ugp_ifspecial,max(ugp_ifwrite)ugp_ifwrite,max(ugp_ifall)ugp_ifall from CS$USERGROUPPOWER ");
  47. sql.Append("left join CS$SYSNAVATION on sn_caller=ugp_caller where sn_using=1 and ugp_groupcode in ( select eg_groupcode from cs$empgroup ");
  48. sql.Append("left join cs$userresource on ur_groupcode = eg_groupcode where eg_emcode = '" + User.UserCode + "') and (nvl(ugp_ifread,0)<>0 or nvl(ugp_ifall,0)<>0) group by sn_id,sn_caller,sn_detno,sn_modulecode,sn_classname,sn_module,sn_displayname,ugp_caller order by sn_modulecode,sn_detno");
  49. }
  50. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  51. if (dt.Rows.Count == 0 && User.UserAccountType != "admin")
  52. {
  53. return;
  54. }
  55. for (int i = 0; i < dt.Rows.Count; i++)
  56. {
  57. bool ContainGroup = false;
  58. string module_name = dt.Rows[i]["sn_module"].ToString();
  59. string caller = dt.Rows[i]["sn_displayname"].ToString();
  60. NavBarItem nbi = new NavBarItem(caller);
  61. nbi.Tag = dt.Rows[i]["sn_classname"].ToString();
  62. nbi.LinkClicked += Nbi_LinkClicked;
  63. nbi.Tag = dt.Rows[i]["sn_classname"].ToString();
  64. nbi.Hint = dt.Rows[i]["ugp_caller"].ToString();
  65. nbi.Name = dt.Rows[i]["sn_id"].ToString();
  66. for (int j = 0; j < Groups.Count; j++)
  67. {
  68. if (Groups[j].Caption == module_name)
  69. {
  70. ContainGroup = true;
  71. if (dt.Rows[i]["ugp_ifread"].ToString() != "0" || dt.Rows[i]["ugp_ifall"].ToString() != "0")
  72. {
  73. Groups[j].ItemLinks.Add(nbi);
  74. }
  75. }
  76. else
  77. {
  78. ContainGroup = false;
  79. }
  80. }
  81. if (!ContainGroup)
  82. {
  83. NavBarGroup nbg = new NavBarGroup(module_name);
  84. //如果加载Icon失败则加载默认图片
  85. try
  86. {
  87. nbg.LargeImage = new Bitmap(@Application.StartupPath + "/Resources/" + dt.Rows[i]["sn_module"].ToString() + ".png");
  88. }
  89. catch (Exception)
  90. {
  91. try
  92. {
  93. nbg.LargeImage = new Bitmap(@Application.StartupPath + "/Resources/defaulticon.png");
  94. }
  95. catch (Exception)
  96. {
  97. nbg.ImageUri = null;
  98. }
  99. }
  100. Groups.Add(nbg);
  101. nbg.ItemLinks.Add(nbi);
  102. }
  103. }
  104. //查询出的用户可见的Caller
  105. //将查询出的数据添加到队列中
  106. for (int i = 0; i < dt.Rows.Count; i++)
  107. {
  108. //添加权限
  109. Dictionary<string, bool> dic = new Dictionary<string, bool>();
  110. dic.Add("IFDELETE", dt.Rows[i]["UGP_IFDELETE"].ToString() != "1" ? false : true);
  111. dic.Add("IFREAD", dt.Rows[i]["UGP_IFREAD"].ToString() != "1" ? false : true);
  112. dic.Add("IFWRITE", dt.Rows[i]["UGP_IFWRITE"].ToString() != "1" ? false : true);
  113. dic.Add("IFSPECIAL", dt.Rows[i]["UGP_IFSPECIAL"].ToString() != "1" ? false : true);
  114. dic.Add("IFALL", dt.Rows[i]["UGP_IFALL"].ToString() != "1" ? false : true);
  115. //之后通过Call来获取页面操作的权限
  116. if (SystemInf.Caller.ContainsKey(dt.Rows[i]["ugp_caller"].ToString()))
  117. {
  118. SystemInf.Caller.Remove(dt.Rows[i]["ugp_caller"].ToString());
  119. }
  120. SystemInf.Caller.Add(dt.Rows[i]["ugp_caller"].ToString(), dic);
  121. }
  122. }
  123. private void Nbi_LinkClicked(object sender, NavBarLinkEventArgs e)
  124. {
  125. NavBarItem nbi = (sender as NavBarItem);
  126. Form OpenForm = (Form)Assembly.GetExecutingAssembly().CreateInstance("UAS_MES_NEW." + nbi.Tag.ToString());
  127. //if (nbi.Tag.ToString() != "Query.Query_MacAddress")
  128. //{
  129. // DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from DeviceMacAddress where dma_mac='" + SystemInf.MacAddress + "'", "select");
  130. // if (dt.Rows.Count == 0)
  131. // {
  132. // MessageBox.Show("该设备不在作业设备清单中,请先上传MAC以及设备信息");
  133. // return;
  134. // }
  135. //}
  136. OpenForm.Dock = DockStyle.Fill;
  137. OpenForm.Text = nbi.Caption;
  138. //用Tag保存Caller
  139. OpenForm.Tag = nbi.Hint;
  140. TabControl tc = (TabControl)this.Parent.Controls["MainTabControl"];
  141. //如果窗体不存在进行打开,item.ToolTip是Caller
  142. if (!OpenedFormName.ContainsKey(nbi.Hint))
  143. {
  144. TabPage tb = new TabPage { Name = nbi.Name, Tag = nbi.Hint, Text = OpenForm.Text };
  145. OpenForm.TopLevel = false;
  146. tc.TabPages.Add(tb);
  147. //直接选中新打开的界面
  148. tc.SelectedTab = tb;
  149. tb.Controls.Add(OpenForm);
  150. OpenedFormName.Add(nbi.Hint, WinIndex);
  151. tc.TabIndex = WinIndex;
  152. WinIndex++;
  153. OpenForm.Show();
  154. }
  155. //如果窗体已存在展示该窗体
  156. else
  157. tc.SelectTab(nbi.Name);
  158. }
  159. }
  160. }