FrmMain.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using DevComponents.DotNetBar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using WCS_Client.Frm;
  12. using WCS_Client.UC;
  13. using WCS_Client.Utility;
  14. namespace WCS_Client
  15. {
  16. public partial class FrmMain : Form
  17. {
  18. public FrmMain()
  19. {
  20. InitializeComponent();
  21. InitFrm();
  22. WCS_Client.Frm.Current.InitData("wcs_pvc");
  23. }
  24. private void InitFrm()
  25. {
  26. #region 初始化任务栏
  27. string sX = "";
  28. try
  29. {
  30. DateTime D = CurrentHelper.User.Use_LoginTime;
  31. switch (D.DayOfWeek)
  32. {
  33. case DayOfWeek.Sunday:
  34. sX = "日";
  35. break;
  36. case DayOfWeek.Monday:
  37. sX = "一";
  38. break;
  39. case DayOfWeek.Tuesday:
  40. sX = "二";
  41. break;
  42. case DayOfWeek.Wednesday:
  43. sX = "三";
  44. break;
  45. case DayOfWeek.Thursday:
  46. sX = "四";
  47. break;
  48. case DayOfWeek.Friday:
  49. sX = "五";
  50. break;
  51. case DayOfWeek.Saturday:
  52. sX = "六";
  53. break;
  54. }
  55. }
  56. catch
  57. {
  58. }
  59. Btn_LoginUserTime.Text = string.Format("【{0}】【{1}】【{2}】【星期{3}】", CurrentHelper.User.Use_Name, CurrentHelper.User.Use_RoleName, CurrentHelper.User.Use_LoginTime, sX);
  60. Btn_Copyrignt.Text = "苏州博众精工科技有限公司版权所有";
  61. #endregion
  62. RefreshMenu();
  63. SetMdiForm("系统主页", "系统主页", typeof(FrmHome), false);
  64. }
  65. private void RefreshMenu()
  66. {
  67. try
  68. {
  69. Bar_Menu.Items.Clear();
  70. AddMenu("", "MBtn_File", "文件", null, null);
  71. if (CurrentHelper.User.Use_RoleId == 1)
  72. {
  73. AddMenu("", "MBtn_User", "用户管理", null, null);
  74. }
  75. AddMenu("", "MBtn_Task", "任务管理", null, null);
  76. AddMenu("", "MBtn_Monitor", "设备监控", null, null);
  77. // AddMenu("", "MBtn_Sys", "系统管理", null, null);
  78. AddMenu("", "MBtn_Help", "系统帮助", null, null);
  79. //MBtn_File
  80. AddMenu("MBtn_File", "MBtn_File_Calc", "计算器", null, Btn_Calc_Click);
  81. AddMenu("MBtn_File", "MBtn_File_Book", "记事本", null, Btn_Book_Click);
  82. AddMenu("MBtn_File", "MBtn_File_SysReset", "系统注销", null, Btn_SysReset_Click);
  83. AddMenu("MBtn_File", "MBtn_File_SysExit", "系统退出", null, Btn_SysExit_Click);
  84. //MBtn_User
  85. if (CurrentHelper.User.Use_RoleId == 1)
  86. {
  87. AddMenu("MBtn_User", "MBtn_User_User", "用户管理", typeof(Frm.FrmUser), Btn_Click);
  88. //AddMenu("MBtn_User", "MBtn_User_RoleUser", "用户权限", null, null);
  89. }
  90. //MBtn_Task
  91. AddMenu("MBtn_Task", "MBtn_CurrentTask", "当前任务管理", typeof(Frm.FrmWCS_Task), Btn_Click);
  92. AddMenu("MBtn_Task", "MBtn_DisTask", "历史任务查询", typeof(Frm.FrmWCS_TaskDIS), Btn_Click);
  93. AddMenu("MBtn_Task", "MBtn_AgvTask", "Agv任务查询", typeof(Frm.MBtn_AgvTask), Btn_Click);
  94. AddMenu("MBtn_Task", "MBtn_AgvTask_Dis", "Agv历史任务查询", typeof(Frm.MBtn_AgvTaskDis.MBtn_AgvTask_Dis), Btn_Click);
  95. ////MBtn_Monitor
  96. //AddMenu("MBtn_Monitor", "MBtn_SCANN", "扫码信息查询", typeof(Frm.MBtn_SCANN), Btn_Click);
  97. //AddMenu("MBtn_Monitor", "MBtn_EQUMsg", "设备信号查询", typeof(Frm.FrmEquMsg), Btn_Click);
  98. //AddMenu("MBtn_Monitor", "MBtn_ALARAMRE", "历史报警记录", typeof(Frm.Frm_ALARAMRE), Btn_Click);
  99. //AddMenu("MBtn_Monitor", "MBtn_ALARAMERStatistics", "历史报警记录统计", typeof(Frm.Frm_ALARAMERStatistics), Btn_Click);
  100. AddMenu("MBtn_Monitor", "MBtn_Mont", "设备监控查看", typeof(Frm.Frm_YongGuanMontior), Btn_Click);
  101. //MBtn_Sys
  102. //AddMenu("MBtn_Sys", "MBtn_Interface_OPOrder", "日志管理", typeof(Frm.FrmLog), Btn_Click);
  103. //AddMenu("MBtn_Sys", "MBtn_Interface_OPUP", "系统设置", typeof(Frm.MBtn_Sys.FormSet), Btn_Click);
  104. //AddMenu("MBtn_Sys", "MBtn_Interface_SrmInfoSet", "堆垛机出入口配置", typeof(Frm.FrmSrmInfoSet), Btn_Click);
  105. //AddMenu("MBtn_Sys", "FrmPalletizingCode", "机械人码垛配置", typeof(Frm.FrmPalletizingCode), Btn_Click);
  106. }
  107. catch (Exception ex)
  108. {
  109. MessageUtil.ShowError(ex.Message);
  110. this.Close();
  111. }
  112. }
  113. List<ButtonItem> mbtn = new List<ButtonItem>();
  114. private void AddMenu(string PBtnName, string BtnName, string DisplayText, Type t, System.EventHandler BtnItem_Click)
  115. {
  116. ButtonItem BtnItem = mbtn.Find(a => a.Name == BtnName);
  117. if (BtnItem == null)
  118. {
  119. BtnItem = new ButtonItem();
  120. mbtn.Add(BtnItem);
  121. }
  122. BtnItem.Tag = t;
  123. BtnItem.Name = BtnName;
  124. BtnItem.Text = DisplayText;
  125. BtnItem.Visible = true;
  126. BtnItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  127. if (BtnItem_Click != null)
  128. {
  129. BtnItem.Click += new EventHandler(BtnItem_Click);
  130. }
  131. ButtonItem PBtnItem = mbtn.Find(a => a.Name == PBtnName);
  132. if (PBtnItem == null)
  133. {
  134. Bar_Menu.Items.Add(BtnItem);
  135. }
  136. else
  137. {
  138. PBtnItem.SubItems.Add(BtnItem);
  139. }
  140. }
  141. private void Btn_Calc_Click(object sender, EventArgs e)
  142. {
  143. #region [ 启动计算器 ]
  144. System.Diagnostics.Process Proc;
  145. try
  146. {
  147. // 启动计算器
  148. Proc = new System.Diagnostics.Process();
  149. Proc.StartInfo.FileName = "calc.exe";
  150. Proc.StartInfo.UseShellExecute = false;
  151. Proc.StartInfo.RedirectStandardInput = true;
  152. Proc.StartInfo.RedirectStandardOutput = true;
  153. Proc.Start();
  154. }
  155. catch
  156. {
  157. Proc = null;
  158. }
  159. #endregion
  160. }
  161. #region [ API: 记事本 ]
  162. /// <summary>
  163. /// 传递消息给记事本
  164. /// </summary>
  165. /// <param name="hWnd"></param>
  166. /// <param name="Msg"></param>
  167. /// <param name="wParam"></param>
  168. /// <param name="lParam"></param>
  169. /// <returns></returns>
  170. [DllImport("User32.DLL")]
  171. public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);
  172. /// <summary>
  173. /// 查找句柄
  174. /// </summary>
  175. /// <param name="hwndParent"></param>
  176. /// <param name="hwndChildAfter"></param>
  177. /// <param name="lpszClass"></param>
  178. /// <param name="lpszWindow"></param>
  179. /// <returns></returns>
  180. [DllImport("User32.DLL")]
  181. public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  182. /// <summary>
  183. /// 记事本需要的常量
  184. /// </summary>
  185. public const uint WM_SETTEXT = 0x000C;
  186. #endregion
  187. private void Btn_Book_Click(object sender, EventArgs e)
  188. {
  189. #region [ 启动记事本 ]
  190. System.Diagnostics.Process Proc;
  191. try
  192. {
  193. // 启动记事本
  194. Proc = new System.Diagnostics.Process();
  195. Proc.StartInfo.FileName = "notepad.exe";
  196. Proc.StartInfo.UseShellExecute = false;
  197. Proc.StartInfo.RedirectStandardInput = true;
  198. Proc.StartInfo.RedirectStandardOutput = true;
  199. Proc.Start();
  200. }
  201. catch
  202. {
  203. Proc = null;
  204. }
  205. #endregion
  206. #region [ 传递数据给记事本 ]
  207. if (Proc != null)
  208. {
  209. // 调用 API, 传递数据
  210. while (Proc.MainWindowHandle == IntPtr.Zero)
  211. {
  212. Proc.Refresh();
  213. }
  214. IntPtr vHandle = FindWindowEx(Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);
  215. // 传递数据给记事本
  216. SendMessage(vHandle, WM_SETTEXT, 0, "");
  217. }
  218. #endregion
  219. }
  220. private void Btn_SysReset_Click(object sender, EventArgs e)
  221. {
  222. Current.PlcSet = new List<WCS_PLC>();
  223. Application.Restart();
  224. }
  225. private void Btn_SysExit_Click(object sender, EventArgs e)
  226. {
  227. Application.Exit();
  228. }
  229. private void Btn_Click(object sender, EventArgs e)
  230. {
  231. ButtonItem BtnItem = sender as ButtonItem;
  232. if (BtnItem == null)
  233. {
  234. return;
  235. }
  236. Type t = BtnItem.Tag as Type;
  237. if (t == null)
  238. {
  239. return;
  240. }
  241. SetMdiForm(BtnItem.Name, BtnItem.Text, t, true);
  242. }
  243. public void SetMdiForm(string TabName, string TabText, Type formType, bool CloseButtonVisible)
  244. {
  245. bool IsOpened = false;
  246. //遍历现有的Tab页面,如果存在,那么设置为选中即可
  247. foreach (SuperTabItem tabitem in STab_Main.Tabs)
  248. {
  249. if (tabitem.Name == TabName)
  250. {
  251. STab_Main.SelectedTab = tabitem;
  252. IsOpened = true;
  253. break;
  254. }
  255. }
  256. //如果在现有Tab页面中没有找到,那么就要初始化了Tab页面了
  257. if (!IsOpened)
  258. {
  259. //为了方便管理,调用LoadMdiForm函数来创建一个新的窗体,并作为MDI的子窗体
  260. //然后分配给SuperTab控件,创建一个SuperTabItem并显示
  261. Form form = Activator.CreateInstance(formType) as Form;
  262. form.FormBorderStyle = FormBorderStyle.None;
  263. form.TopLevel = false;
  264. form.Visible = true;
  265. SuperTabItem tabItem = STab_Main.CreateTab(TabName);
  266. tabItem.Name = TabName;
  267. tabItem.Text = TabText;
  268. tabItem.AttachedControl.Controls.Add(form);
  269. STab_Main.SelectedTab = tabItem;
  270. tabItem.CloseButtonVisible = CloseButtonVisible;
  271. form.Dock = DockStyle.Fill;
  272. }
  273. }
  274. }
  275. }