123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- using DevComponents.DotNetBar;
- using FreeRedis;
- using MessagePack;
- using MessagePack.Resolvers;
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using WCS_Client.Frm;
- using WCS_Client.UC;
- using WCS_Client.Utility;
- namespace WCS_Client
- {
- public partial class FrmMain : Form
- {
- public FrmMain()
- {
- InitializeComponent();
- InitFrm();
- WCS_Client.Frm.Current.InitData("wcs_pvc");
- }
- private void InitFrm()
- {
- #region 初始化任务栏
- string sX = "";
- try
- {
- DateTime D = CurrentHelper.User.Use_LoginTime;
- switch (D.DayOfWeek)
- {
- case DayOfWeek.Sunday:
- sX = "日";
- break;
- case DayOfWeek.Monday:
- sX = "一";
- break;
- case DayOfWeek.Tuesday:
- sX = "二";
- break;
- case DayOfWeek.Wednesday:
- sX = "三";
- break;
- case DayOfWeek.Thursday:
- sX = "四";
- break;
- case DayOfWeek.Friday:
- sX = "五";
- break;
- case DayOfWeek.Saturday:
- sX = "六";
- break;
- }
- }
- catch
- {
- }
- Btn_LoginUserTime.Text = string.Format("【{0}】【{1}】【{2}】【星期{3}】", CurrentHelper.User.Use_Name, CurrentHelper.User.Use_RoleName, CurrentHelper.User.Use_LoginTime, sX);
- Btn_Copyrignt.Text = "苏州博众精工科技有限公司版权所有";
- #endregion 初始化任务栏
- RefreshMenu();
- SetMdiForm("系统主页", "系统主页", typeof(FrmHome), false);
- if (eqpData.Redis == null)
- {
- RedisClient Redis = new RedisClient("212.64.66.35,database=11");
- MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
- Redis.Serialize = obj =>
- {
- var bytes = MessagePackSerializer.Serialize(obj);
- return bytes;
- };
- Redis.DeserializeRaw = (bytes, type) =>
- {
- var obj = MessagePackSerializer.Deserialize(type, bytes);
- return obj;
- };
- eqpData.init(Redis);
- }
- }
- private void RefreshMenu()
- {
- try
- {
- Bar_Menu.Items.Clear();
- AddMenu("", "MBtn_File", "文件", null, null);
- if (CurrentHelper.User.Use_RoleId == 1)
- {
- AddMenu("", "MBtn_User", "用户管理", null, null);
- }
- AddMenu("", "MBtn_Task", "任务管理", null, null);
- AddMenu("", "MBtn_Monitor", "设备监控", null, null);
- AddMenu("", "MBtn_Sys", "系统管理", null, null);
- AddMenu("", "MBtn_Help", "系统帮助", null, null);
- //MBtn_File
- AddMenu("MBtn_File", "MBtn_File_Calc", "计算器", null, Btn_Calc_Click);
- AddMenu("MBtn_File", "MBtn_File_Book", "记事本", null, Btn_Book_Click);
- AddMenu("MBtn_File", "MBtn_File_SysReset", "系统注销", null, Btn_SysReset_Click);
- AddMenu("MBtn_File", "MBtn_File_SysExit", "系统退出", null, Btn_SysExit_Click);
- //MBtn_User
- if (CurrentHelper.User.Use_RoleId == 1)
- {
- AddMenu("MBtn_User", "MBtn_User_User", "用户管理", typeof(Frm.FrmUser), Btn_Click);
- }
- //MBtn_Task
- AddMenu("MBtn_Task", "MBtn_CurrentTask", "当前任务管理", typeof(Frm.FrmWCS_Task), Btn_Click);
- AddMenu("MBtn_Task", "MBtn_DisTask", "历史任务查询", typeof(Frm.FrmWCS_TaskDIS), Btn_Click);
- AddMenu("MBtn_Task", "MBtn_AgvTask", "Agv任务查询", typeof(Frm.MBtn_AgvTask), Btn_Click);
- AddMenu("MBtn_Task", "MBtn_AgvTask_Dis", "Agv历史任务查询", typeof(Frm.MBtn_AgvTaskDis.MBtn_AgvTask_Dis), Btn_Click);
- ////MBtn_Monitor
- AddMenu("MBtn_Monitor", "MBtn_SCANN", "扫码信息查询", typeof(Frm.MBtn_SCANN), Btn_Click);
- //AddMenu("MBtn_Monitor", "MBtn_Mont", "设备监控查看", typeof(Frm.Frm_YongGuanMontior), Btn_Click);
- //MBtn_Sys
- AddMenu("MBtn_Sys", "MBtn_Interface_OPOrder", "日志管理", typeof(Frm.FrmLog), Btn_Click);
- //AddMenu("MBtn_Sys", "MBtn_Interface_OPUP", "系统设置", typeof(Frm.MBtn_Sys.FormSet), Btn_Click);
- AddMenu("MBtn_Sys", "MBtn_Interface_SrmInfoSet", "系统设置", typeof(Frm.FrmSrmInfoSet), Btn_Click);
- }
- catch (Exception ex)
- {
- MessageUtil.ShowError(ex.Message);
- this.Close();
- }
- }
- private List<ButtonItem> mbtn = new List<ButtonItem>();
- private void AddMenu(string PBtnName, string BtnName, string DisplayText, Type t, System.EventHandler BtnItem_Click)
- {
- ButtonItem BtnItem = mbtn.Find(a => a.Name == BtnName);
- if (BtnItem == null)
- {
- BtnItem = new ButtonItem();
- mbtn.Add(BtnItem);
- }
- BtnItem.Tag = t;
- BtnItem.Name = BtnName;
- BtnItem.Text = DisplayText;
- BtnItem.Visible = true;
- BtnItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
- if (BtnItem_Click != null)
- {
- BtnItem.Click += new EventHandler(BtnItem_Click);
- }
- ButtonItem PBtnItem = mbtn.Find(a => a.Name == PBtnName);
- if (PBtnItem == null)
- {
- Bar_Menu.Items.Add(BtnItem);
- }
- else
- {
- PBtnItem.SubItems.Add(BtnItem);
- }
- }
- private void Btn_Calc_Click(object sender, EventArgs e)
- {
- #region [ 启动计算器 ]
- System.Diagnostics.Process Proc;
- try
- {
- // 启动计算器
- Proc = new System.Diagnostics.Process();
- Proc.StartInfo.FileName = "calc.exe";
- Proc.StartInfo.UseShellExecute = false;
- Proc.StartInfo.RedirectStandardInput = true;
- Proc.StartInfo.RedirectStandardOutput = true;
- Proc.Start();
- }
- catch
- {
- Proc = null;
- }
- #endregion [ 启动计算器 ]
- }
- #region [ API: 记事本 ]
- /// <summary>
- /// 传递消息给记事本
- /// </summary>
- /// <param name="hWnd"></param>
- /// <param name="Msg"></param>
- /// <param name="wParam"></param>
- /// <param name="lParam"></param>
- /// <returns></returns>
- [DllImport("User32.DLL")]
- public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);
- /// <summary>
- /// 查找句柄
- /// </summary>
- /// <param name="hwndParent"></param>
- /// <param name="hwndChildAfter"></param>
- /// <param name="lpszClass"></param>
- /// <param name="lpszWindow"></param>
- /// <returns></returns>
- [DllImport("User32.DLL")]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- /// <summary>
- /// 记事本需要的常量
- /// </summary>
- public const uint WM_SETTEXT = 0x000C;
- #endregion [ API: 记事本 ]
- private void Btn_Book_Click(object sender, EventArgs e)
- {
- #region [ 启动记事本 ]
- System.Diagnostics.Process Proc;
- try
- {
- // 启动记事本
- Proc = new System.Diagnostics.Process();
- Proc.StartInfo.FileName = "notepad.exe";
- Proc.StartInfo.UseShellExecute = false;
- Proc.StartInfo.RedirectStandardInput = true;
- Proc.StartInfo.RedirectStandardOutput = true;
- Proc.Start();
- }
- catch
- {
- Proc = null;
- }
- #endregion [ 启动记事本 ]
- #region [ 传递数据给记事本 ]
- if (Proc != null)
- {
- // 调用 API, 传递数据
- while (Proc.MainWindowHandle == IntPtr.Zero)
- {
- Proc.Refresh();
- }
- IntPtr vHandle = FindWindowEx(Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);
- // 传递数据给记事本
- SendMessage(vHandle, WM_SETTEXT, 0, "");
- }
- #endregion [ 传递数据给记事本 ]
- }
- private void Btn_SysReset_Click(object sender, EventArgs e)
- {
- Current.PlcSet = new List<WCS_PLC>();
- Application.Restart();
- }
- private void Btn_SysExit_Click(object sender, EventArgs e)
- {
- Environment.Exit(0);
- Application.Exit();
- }
- private void Btn_Click(object sender, EventArgs e)
- {
- ButtonItem BtnItem = sender as ButtonItem;
- if (BtnItem == null)
- {
- return;
- }
- Type t = BtnItem.Tag as Type;
- if (t == null)
- {
- return;
- }
- SetMdiForm(BtnItem.Name, BtnItem.Text, t, true);
- }
- public void SetMdiForm(string TabName, string TabText, Type formType, bool CloseButtonVisible)
- {
- bool IsOpened = false;
- //遍历现有的Tab页面,如果存在,那么设置为选中即可
- foreach (SuperTabItem tabitem in STab_Main.Tabs)
- {
- if (tabitem.Name == TabName)
- {
- STab_Main.SelectedTab = tabitem;
- IsOpened = true;
- break;
- }
- }
- //如果在现有Tab页面中没有找到,那么就要初始化了Tab页面了
- if (!IsOpened)
- {
- //为了方便管理,调用LoadMdiForm函数来创建一个新的窗体,并作为MDI的子窗体
- //然后分配给SuperTab控件,创建一个SuperTabItem并显示
- Form form = Activator.CreateInstance(formType) as Form;
- form.FormBorderStyle = FormBorderStyle.None;
- form.TopLevel = false;
- form.Visible = true;
- SuperTabItem tabItem = STab_Main.CreateTab(TabName);
- tabItem.Name = TabName;
- tabItem.Text = TabText;
- tabItem.AttachedControl.Controls.Add(form);
- STab_Main.SelectedTab = tabItem;
- tabItem.CloseButtonVisible = CloseButtonVisible;
- form.Dock = DockStyle.Fill;
- }
- }
- }
- }
|