using GeBoShi.SysCtrl; using GeBoShi.UI; using GeBoShi.UI.Load; using GeBoShi.UI.Product; using GeBoShi.UI.SysSet; using HZH_Controls.Forms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace GeBoShi { public partial class Main : Form { public Main() { InitializeComponent(); UIStyle.SetUIStyle(this); this.uiTitel1.FatherForm = this; this.uiTitel1.UserMenuStrip = this.menuStrip1; this.uiTitel1.ShowContrlBox(true, true, true); this.uiTitel1.ShowMenu(); this.DoubleBuffered = true;//设置本窗体 SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲 } #region 初始化 /// /// 初始化 /// /// private bool InitSystem() { //进入初始化,初始化失败则中断 InitFrm initFrm = new InitFrm(); initFrm.ShowDialog(); if (initFrm.DialogResult == DialogResult.OK) { //初始化成功 } else { initFrm.Dispose(); return false; } initFrm.Dispose(); return true; } #endregion #region 界面刷新 private void ResetUI(bool clearSN) { //保持产品名称和料号 //txtProductName.Text = txtProductCode.Text = txtProductSN.Text = ""; if (clearSN) cbPdtSN.Text = ""; this.lstLog.Items.Clear(); this.tsbtnImpStop.Enabled = false; this.tsbtnStart.Enabled = true; this.tsbtnStop.Enabled = false; this.cbPdtSN.Enabled = true; this.cbProductCode.Enabled = true; this.cbProductBatch.Enabled = true; this.cbProductReelNum.Enabled = true; this.cbProductNum.Enabled = true; tslabelTime.Text = "实时测试:0.00s"; this.Refresh(); } #endregion #region 权限判断 private void UserRightCheck() { this.tsmPdtMgr.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Product); this.tsmSysDataFind.Visible = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Statistics); this.tsmUserList.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.User); this.tsmUserRight.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Role); if (this.tsmUserList.Enabled == false && this.tsmUserRight.Enabled == false) this.tsmSysUserMgr.Visible = false; else this.tsmSysUserMgr.Visible = true; this.tsmDebug.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Debug); this.tsmSysSet.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.ParamsSetting); if (this.tsmDebug.Enabled == false && this.tsmSysSet.Enabled == false) this.stmSysSet.Visible = false; else this.stmSysSet.Visible = true; } #endregion #region 运行判断 /// /// 系统是否在运行 /// /// private bool SystemIsRun() { if (SysMgr.Instance.IsRuning) { FrmDialog.ShowDialog(this, "设备正在运行中!", "警告", false); //MessageBox.Show("设备正在运行中!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; } #endregion #region 界面事件 private void Main_Load(object sender, EventArgs e) { //登入 if (SysMgr.Instance.LoginSystem()) { //登入成功 if (InitSystem()) { this.Cursor = Cursors.WaitCursor; //this.WindowState = FormWindowState.Normal; this.Top = 0; this.Left = 0; this.Width = SystemInformation.WorkingArea.Width; this.Height = SystemInformation.WorkingArea.Height; //this.WindowState = FormWindowState.Maximized; //this.splitContainer1.SplitterDistance = this.Width / 3; ResetUI(true); this.Show(); this.tsslLoginInfo.Text = $"操作员:{SysMgr.Instance.UserMgr.LoginUser.Code}({SysMgr.Instance.UserMgr.LoginUser.Name})"; this.statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow; this.tsslLoginTime.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; this.tsslLoginInfo.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; this.tsAxisState.Text = ""; //更新数据库格式 Service.InitDB.initDB(ConfMgr.Instance.DBConStr); //权限判断 UserRightCheck(); //开启后台 //timer1.Enabled = true; //backgroundWorkerDo = true; //backgroundWorker1.RunWorkerAsync(); //s_BackWorker = true; //backgroundWorker.RunWorkerAsync(); //开启云端连接 //SysMgr.Instance.InitCloudConnect(); //开启产品服务 //SysMgr.Instance.InitPdtService(); //开启处理事件反馈 //SysMgr.Instance.InitDefectEvent(); //加载产品料号 //SysMgr.Instance.LoadProductCodeList(); //加载产品选择 //LoadPdtList(SysMgr.Instance.ProductCodeList); //LoadSNList(SysMgr.Instance.ProductSNList); this.Cursor = Cursors.Default; //运行前检测磁盘空间 SysMgr.CheckDisk(this); } else { Application.Exit(); } } else { Application.Exit(); } } private void Main_FormClosing(object sender, FormClosingEventArgs e) { //backgroundWorkerDo = false; Thread.Sleep(300); if (SystemIsRun()) { DialogResult dr = DialogResult.Cancel; if (SysMgr.Instance.IsInit) { dr = FrmDialog.ShowDialog(this, "确定要退出当前系统?", "警告", true); } else dr = DialogResult.OK; if (dr == DialogResult.Cancel) { e.Cancel = true; } else { Thread.Sleep(300); if (SysMgr.Instance.IsInit) SysMgr.Instance.Close(); //SysMgr.Instance.MainRuning -= main_running; } } else e.Cancel = true; } private void Main_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Maximized) { this.WindowState = FormWindowState.Normal; this.Top = 0; this.Left = 0; this.Width = SystemInformation.WorkingArea.Width; this.Height = SystemInformation.WorkingArea.Height; } } #endregion #region 菜单 #region 退出 private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 用户 private void tsmUserRight_Click(object sender, EventArgs e) { SysMgr.Instance.UserPermissiomMgr(); } private void tsmUserList_Click(object sender, EventArgs e) { SysMgr.Instance.UserListMgr(); } #endregion #region 系统设置 private void MainFrm_Paint(object sender, PaintEventArgs e) { this.tsbtnReset.Visible = ConfMgr.Instance.SysConfigParams.ShowResetBtn; } private void tsmSysSet_Click(object sender, EventArgs e) { if (SystemIsRun()) { SysMgr.Instance.StatusMgr.GotoSetParams(); SysMgr.Instance.SendStatus(); SysSetFrm frm = new SysSetFrm(); frm.ShowDialog(); MainFrm_Paint(null, null); SysMgr.Instance.StatusMgr.GotoNormalStandby(); SysMgr.Instance.SendStatus(); } } #endregion #endregion #region 检测管理 private string[] pdtlistData; private void LoadPdtList(List list) { this.cbDefectCode.Items.Clear(); this.pdtlistData = list.ToArray(); cbDefectCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些 cbDefectCode.TextUpdate += cobList_TextUpdate;//重新绑定事件 cbDefectCode.KeyDown += CobList_KeyDown; this.cbDefectCode.Text = ""; cbDefectCode.Focus(); cbDefectCode.SelectAll(); } private void tsmPdtMgr_Click(object sender, EventArgs e) { if (SystemIsRun()) { ProductListFrm frm = new ProductListFrm(); frm.ShowDialog(); //加载产品料号 SysMgr.Instance.LoadProductCodeList(); //加载产品选择 LoadPdtList(SysMgr.Instance.ProductCodeList); } } private void CobList_KeyDown(object sender, KeyEventArgs e) { ComboBox ctrl = sender as ComboBox; if (e.KeyCode == Keys.Enter) { if (ctrl.Items.Count == 1) ctrl.Text = ctrl.Items[0].ToString(); } } private void cobList_TextUpdate(object sender, EventArgs e) { ComboBox ctrl = sender as ComboBox; if (ctrl.Text != null) { string str = ctrl.Text; //获取cb_material控件输入内 //清空combobox ctrl.DataSource = null; ctrl.Items.Clear(); string[] workOrderFiltered; workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写 ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些 // 不存在符合条件时 //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列 ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置 if (workOrderFiltered.Length > 0) { if (!ctrl.DroppedDown) ctrl.DroppedDown = true; // 自动弹出下拉框 } ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列 } } #endregion } }