|
- using CCWin;
- using CCWin.SkinControl;
- using HalconDotNet;
- using HZH_Controls.Forms;
- using MaiMuAOI.SysCtrl;
- using MaiMuAOI.SysUI.DefectPicShow;
- using MaiMuAOI.SysUI.Load;
- using MaiMuAOI.SysUI.ProcessStep;
- using MaiMuAOI.SysUI.ProcessStep.Ctrl;
- using MaiMuAOI.SysUI.ProductAndStep;
- using MaiMuAOI.SysUI.SysSet;
- using MaiMuAOI.SysUI.Web;
- using MaiMuAOI.UI.SysSet;
- using MaiMuControl.Device;
- using MaiMuControl.Device.CamDev;
- using MaiMuControl.Device.IOCardDev;
- using MaiMuControl.SysStatusMgr.StatusMgr;
- using Models;
- using Newtonsoft.Json.Linq;
- using OpenCvSharp;
- using ProductionControl;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static MaiMuAOI.SysCtrl.SysMgr;
-
- namespace MaiMuAOI
- {
- public partial class MainFrm : Form
- {
- private Service.ProductService svcProduct = new Service.ProductService();
- object AddTextLock = new object();
- object AddPicLock = new object();
- bool backgroundWorkerDo;
-
- bool DisEnableBuzz;
- bool DisEnableDoor;
- private Stopwatch RunStartTime = new Stopwatch();
-
- public MainFrm()
- {
- InitializeComponent();
-
- 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); // 双缓冲
-
- SysMgr.Instance.MainRuning += main_running;
- SysMgr.Instance.AutoRuning += auto_runing;
- SysMgr.Instance.AutoShowImg += auto_ShowMoreImg;
-
- //显示行号与列宽度自动调整
- dgvProcess.RowHeadersVisible = true;
- dgvProcess.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
- dgvProcess.RowPostPaint += (sender, e) =>
- {
- SysMgr.showRowNum_onDataGrid_RowPostPaint(this.dgvProcess, sender, e);
- };
-
- dgvProcess.DefaultCellStyle.ForeColor = System.Drawing.Color.Black;
-
- this.lblTimeLen.Top = toolStrip1.Top + 10;
- this.lblTimeLen.Left = toolStrip1.Width - 300;
- this.lblOutput.Top = toolStrip1.Top + 10 + lblTimeLen.Height + 5;
- this.lblOutput.Left = toolStrip1.Width - 300;
-
- this.chkBuzzer.Top = toolStrip1.Top + 20;
- this.chkDoorSensor.Top = toolStrip1.Top + 20;
- }
-
- #region 私有方法
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- private bool InitSystem()
- {
- //进入初始化,初始化失败则中断
- InitFrm initFrm = new InitFrm();
- initFrm.ShowDialog();
- if (initFrm.DialogResult == DialogResult.OK)
- {
- //初始化成功
- }
- else
- {
- initFrm.Dispose();
- return false;
- }
- initFrm.Dispose();
- return true;
- }
- /// <summary>
- /// 系统是否在运行
- /// </summary>
- /// <returns></returns>
- private bool SystemIsRun()
- {
- if (SysMgr.Instance.IsRuning)
- {
- FrmDialog.ShowDialog(this, "设备正在运行中!", "警告", false);
- //MessageBox.Show("设备正在运行中!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- return true;
- }
-
- private void ClearDefectBmps()
- {
- this.pnlBmpList.Controls.Clear();
- this.gboxDefectList.Text = $"缺陷图像";
- this.gboxDefectList.Tag = 0;
-
- this.lblDefectAddTag.Text = "";
- this.lblDefectAddTag.Tag = 0;
- }
- private void ResetUI(bool clearSN)
- {
-
- //保持产品名称和料号
- //txtProductName.Text = txtProductCode.Text = txtProductSN.Text = "";
- if(clearSN)
- cbProductSN.Text = "";
-
- lblTension.ForeColor = Color.White;
- lblTension.Text = "0.00";
- lblTensionMax.Text = "0.00";
- lblTensionMin.Text = "0.00";
-
- lblHeight.ForeColor = Color.White;
- lblHeight.Text = "0.00";
- lblHeightMax.Text = "0.00";
- lblHeightMin.Text = "0.00";
-
- lblLineWidth.ForeColor = Color.White;
- lblLineWidth.Text = "0.00";
- lblLineWidthMax.Text = "0.00";
- lblLineWidthMin.Text = "0.00";
-
- lblPT.ForeColor = Color.White;
- lblPT.Text = "0.00";
- lblPTMax.Text = "0.00";
- lblPTMin.Text = "0.00";
-
- lblCompareResult.ForeColor = Color.White;
- lblCompareResult.Text = "无";
- //lblCompareCount.Text = "未通过:";
-
- lblDefectResult.ForeColor = Color.White;
- lblDefectResult.Text = "无";
- lblDefectResultCount.Text = "无";
-
- this.dgvProcess.DataSource = null;
- this.dgvProcess.DataSource = null;
- this.lstLog.Items.Clear();
- this.ClearDefectBmps();
-
- this.flpProcessStep.Controls.Clear();
-
- this.picScanner0.Image = null;
- picScanner0.Refresh();
- this.picScanner1.Image = null;
- picScanner1.Refresh();
-
- this.tsbtnStop.Enabled = false;
-
- this.cbOrderCode.Enabled = true;
- this.cbProductCode.Enabled = true;
- this.cbProductSN.Enabled = true;
-
- lblTimeLen.Text = "检测时长: 0 秒";
- tslabelTime.Text = "实时测试:0.00s";
-
- int daout = 0;
- if(ConfMgr.Instance.GetDailyOutput(out daout))
- {
- lblOutput.Text = $"当日产量: {daout} 个";
- }
- MainFrm_Paint(null, null);
- this.Refresh();
- }
-
- private void UserRightCheck()
- {
- this.tsmStepMgr.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Step);
- 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);
- this.tsmSysPoints.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
-
- private void MainFrm_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.dgvProcess.AutoGenerateColumns = false;
- this.tsslLoginInfo.Text = $"操作员:{SysMgr.Instance.UserMgr.LoginUser.Code}({SysMgr.Instance.UserMgr.LoginUser.Name})";
- //this.tsslLoginTime.Text = $" 登录时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}";
-
- 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 = "";
-
- //设置流程卡显示
- this.tabControl1.SelectTab(0);
- //this.tabControl1.SelectTab(1);
-
- //更新数据库格式
- Service.InitDB.initDB();
- //权限判断
- UserRightCheck();
- //开启后台
- //timer1.Enabled = true;
- backgroundWorkerDo = true;
- backgroundWorker1.RunWorkerAsync();
- //s_BackWorker = true;
- //backgroundWorker.RunWorkerAsync();
- //开启web服务器
- SysMgr.Instance.InitWebServer();
- //开启云端连接
- 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 MainFrm_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;
- }
-
- #region 主界面
- private void toolStrip1_Paint(object sender, PaintEventArgs e)
- {
- if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
- {
- Rectangle rect = new Rectangle(0, 0, this.toolStrip1.Width, this.toolStrip1.Height - 2);
- e.Graphics.SetClip(rect);
- }
- }
- private void chkBuzzer_CheckedChanged(object sender, EventArgs e)
- {
- DisEnableBuzz = chkBuzzer.Checked;
- }
-
- private void chkDoorSensor_CheckedChanged(object sender, EventArgs e)
- {
- DisEnableDoor = chkDoorSensor.Checked;
- }
-
- private void MainFrm_Shown(object sender, EventArgs e)
- {
-
- }
- #endregion
-
- #region 菜单按钮
-
- 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();
- }
- }
- private void tsmUserRight_Click(object sender, EventArgs e)
- {
- SysMgr.Instance.UserPermissiomMgr();
- }
- private void tsmUserList_Click(object sender, EventArgs e)
- {
- SysMgr.Instance.UserListMgr();
- }
- private void tsmDebug_Click(object sender, EventArgs e)
- {
- if (SystemIsRun())
- {
- SysMgr.Instance.StatusMgr.GotoDebug();
- SysMgr.Instance.SendStatus();
- SysDebugFrm frm = new SysDebugFrm();
- frm.ShowDialog();
- SysMgr.Instance.StatusMgr.GotoNormalStandby();
- SysMgr.Instance.SendStatus();
- }
- }
- private void tsmSysPoints_Click(object sender, EventArgs e)
- {
- if (SystemIsRun())
- {
- SysMgr.Instance.StatusMgr.GotoSetParams();
- SysMgr.Instance.SendStatus();
- SysPointsFrm frm = new SysPointsFrm();
- frm.ShowDialog();
- SysMgr.Instance.StatusMgr.GotoNormalStandby();
- SysMgr.Instance.SendStatus();
- }
- }
- private void tsmSysDataFind_Click(object sender, EventArgs e)
- {
- //WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B",
- // "http://127.0.0.1:" + ConfMgr.Instance.SysConfigParams.HttpServerPort.ToString() + "/static/index.html#/");
- //WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B");
- //frm.WindowState = FormWindowState.Maximized;
- //frm.Show();
- }
-
- private void web数据查询ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B");
- frm.WindowState = FormWindowState.Maximized;
- frm.Show();
- }
-
- private void 本地数据库查询ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- DataQueryFrm frm = new DataQueryFrm();
- frm.WindowState = FormWindowState.Maximized;
- frm.Show();
- }
-
- private void 系统管理ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (SystemIsRun())
- {
- ProductListFrm frm = new ProductListFrm();
- frm.ShowDialog();
- //加载产品料号
- SysMgr.Instance.LoadProductCodeList();
- //加载产品选择
- LoadPdtList(SysMgr.Instance.ProductCodeList);
- }
- }
-
- private void toolStripMenuItem1_Click(object sender, EventArgs e)
- {
- if (SystemIsRun())
- {
- StepListFrm frm = new StepListFrm();
- frm.ShowDialog();
- }
- }
- private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void tsmInfoUS_Click(object sender, EventArgs e)
- {
- SysInfoFrm frm = new SysInfoFrm();
- frm.ShowDialog();
- }
-
- private void tsmReadLog_Click(object sender, EventArgs e)
- {
- SysLogFrm frm = new SysLogFrm();
- frm.ShowDialog();
- }
-
- private void tsmHelpInfo_Click(object sender, EventArgs e)
- {
- //MessageBox.Show(SysUpdata.Updata, "更新信息");
- SysUpdataInfoFrm frm = new SysUpdataInfoFrm(SysUpdata.Updata);
- frm.ShowDialog();
- }
-
- private void tsmSoftFile_Click(object sender, EventArgs e)
- {
- string fileName = ConfMgr.Instance.SpecificationPath;//输入打开文件路径
- Process.Start(fileName);//使用process进程打开
- }
- #endregion
-
- #region 显示图像和消息
- private void lstLog_DrawItem(object sender, DrawItemEventArgs e)
- {
- e.DrawBackground();
- if (e.Index < 0) return;
-
- try
- {
- string str = lstLog.Items[e.Index].ToString();
- e.Graphics.DrawString(str.Substring(1), e.Font,
- new SolidBrush(str[0] == 'R' ? Color.Red : (str[0] == 'Y' ? Color.Orange : Color.Black)),
- e.Bounds);
- }
- catch(Exception ex)
- {
- e.Graphics.DrawString(ex.Message, e.Font,
- new SolidBrush( Color.Red ),
- e.Bounds);
- }
- }
-
- /// <summary>
- /// 异步输出日志
- /// </summary>
- /// <param name="tag">模板标识</param>
- /// <param name="msg">内容</param>
- /// <param name="type"></param>
- private void AddTextEvent(string tag, string msg, WarningEnum level = WarningEnum.Normal)
- {
- lock (AddTextLock)
- {
- if (tag != null && tag != "")
- tag = $" - [{tag}]";
-
- var now = DateTime.Now;
- msg = now.ToString("HH:mm:ss fff") + tag + " - " + msg;
-
- msg = (level == WarningEnum.Normal ? "B" : level == WarningEnum.Low ? "Y" : "R") + msg;
-
- if (this.lstLog.Items.Count > 1000)
- this.lstLog.Items.Clear();
- lstLog.Items.Insert(0, msg);
-
- }
- }
-
- private void main_running(object sender, MainEventArgs e)
- {
- ShowMessage(e);
- }
- private delegate void ShowMessageDelegate(MainEventArgs e);
- private void ShowMessage(MainEventArgs e)
- {
- if (InvokeRequired)
- {
- ShowMessageDelegate smd = new ShowMessageDelegate(ShowMessage);
- this.BeginInvoke(smd, e);
- }
- else
- {
- AddTextEvent(e.Tag, e.Message, e.Warning);
- }
- }
-
- /// <summary>
- /// 自动运行流程显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void auto_runing(object sender, RunEventArgs e)
- {
- ShowUIEvent(e);
- }
-
- private delegate void ShowUIEventDelegate(RunEventArgs e);
- Bitmap bmp0;
- Bitmap bmp1;
- private void ShowUIEvent(RunEventArgs e)
- {
- if (InvokeRequired)
- {
- ShowUIEventDelegate smd = new ShowUIEventDelegate(ShowUIEvent);
- this.BeginInvoke(smd, e);
- }
- else
- {
- try
- {
- if (e.Cmd == 0) //显示SN和流程
- {
- this.cbProductSN.Text = e.SN;
- if (e.NewStep)
- {
- this.tabControl1.SelectTab(1);
- ShowNewStepProcess(e.StepProcessesList);
- }
- else
- {
- this.tabControl1.SelectTab(0);
- this.dgvProcess.DataSource = new BindingSource(e.StepProcessesList, null);
- }
-
-
- }
- else if (e.Cmd == 1) //显示当前运行步骤
- {
- this.dgvProcess.Rows[e.StepIndex].Selected = true;
- dgvProcess.CurrentCell = dgvProcess.Rows[e.StepIndex].Cells[1];
- }
- else if (e.Cmd == 2) //显示当前运行步骤 和步骤详情
- {
- this.dgvProcess.Rows[e.StepIndex].Cells["colValue"].Value = e.Mesg;
- }
- else if (e.Cmd == 3) //图纸比对结果
- {
- this.lblCompareResult.Text = (e.CompareResult ? "通过" : $"未通过");
- this.lblCompareResultCount.Text = e.Cnt.ToString();
- if (!e.CompareResult)
- {
- this.lblCompareResult.ForeColor = Color.Red;
- }
- else
- this.lblCompareResult.ForeColor = Color.Lime;
- }
- else if (e.Cmd == 4) //缺陷结果
- {
- lblDefectResult.Text = "未通过";
- lblDefectResultCount.Text = $"总数:{e.Cnt},详细:{e.CompareResultString}";
- this.toolTip1.SetToolTip(lblDefectResultCount, lblDefectResultCount.Text);
- this.lblDefectResult.Text = (e.CompareResult ? "通过" : "未通过");
- if (!e.CompareResult)
- {
- this.lblDefectResult.ForeColor = Color.Red;
- }
- else
- this.lblDefectResult.ForeColor = Color.Lime;
- }
- else if (e.Cmd == 5) //加载缺陷小图
- {
- ;
- }
- else if (e.Cmd == 6) //显示主图
- {
- if (e.PicIndex == 0)
- {
- bmp0 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
- picScanner0.Image = bmp0;
- picScanner0.Refresh();
- }
- else
- {
- bmp1 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
- picScanner1.Image = bmp1;
- picScanner1.Refresh();
- }
- }
- else if (e.Cmd == 7) //显示测试时间
- {
- lblTimeLen.Text = "检测时长: " + e.Time.ToString("0.000") + " 秒";
- }
- else if (e.Cmd == 8) //显示测试时间
- {
- lblOutput.Text = "当日产量: " + e.Num.ToString("0") + " 个";
- }
- else if (e.Cmd == 10) //测试结束
- {
- this.tsbtnStart.Enabled = true;
- this.tsbtnStop.Enabled = false;
-
- this.cbOrderCode.Enabled = true;
- this.cbProductCode.Enabled = true;
- this.cbProductSN.Enabled = true;
- }
-
- else if (e.Cmd == 21) //厚度显示
- {
- double value = Math.Round(e.Value.Average(), 2);
- double valueMax = e.Value.Max();
- double valueMin = e.Value.Min();
-
- Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
- Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
- Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
-
- this.lblHeight.Text = Math.Round(value, 2).ToString();
- this.lblHeight.ForeColor = color;
-
- this.lblHeightMax.Text = Math.Round(valueMax, 2).ToString();
- this.lblHeightMax.ForeColor = colorMax;
-
- this.lblHeightMin.Text = Math.Round(valueMin, 2).ToString();
- this.lblHeightMin.ForeColor = colorMin;
- }
- else if (e.Cmd == 22) //PT显示
- {
- double value = Math.Round(e.Value.Average(), 4);
- double valueMax = e.Value.Max();
- double valueMin = e.Value.Min();
-
- Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
- Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
- Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
-
- this.lblPT.Text = Math.Round(value, 4).ToString();
- this.lblPT.ForeColor = color;
-
- this.lblPTMax.Text = Math.Round(valueMax, 4).ToString();
- this.lblPTMax.ForeColor = colorMax;
-
- this.lblPTMin.Text = Math.Round(valueMin, 4).ToString();
- this.lblPTMin.ForeColor = colorMin;
- }
- else if (e.Cmd == 23) //线宽显示
- {
- double value = Math.Round(e.Value.Average(), 2);
- double valueMax = e.Value.Max();
- double valueMin = e.Value.Min();
-
- Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
- Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
- Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
-
- this.lblLineWidth.Text = Math.Round(value, 2).ToString();
- this.lblLineWidth.ForeColor = color;
-
- this.lblLineWidthMax.Text = Math.Round(valueMax, 2).ToString();
- this.lblLineWidthMax.ForeColor = colorMax;
-
- this.lblLineWidthMin.Text = Math.Round(valueMin, 2).ToString();
- this.lblLineWidthMin.ForeColor = colorMin;
- }
- else if (e.Cmd == 30) //新流程 厚度, 张力, pt, 线宽显示
- {
- Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex +1), true);
- //滚动条滚动
- //int scrollStep = (this.flpProcessStep.VerticalScroll.Maximum / (flpProcessStep.Controls.Count - 1));
-
- this.flpProcessStep.VerticalScroll.Value = e.StepIndex * controls[0].Height > this.flpProcessStep.VerticalScroll.Maximum? this.flpProcessStep.VerticalScroll.Maximum: e.StepIndex * controls[0].Height;
-
- if (!e.ProcessType)
- {
- NewStepShow newStepShow = controls[0] as NewStepShow;
-
- if (e.Mesg == "镜头变焦")
- {
- string str1 = e.Value_ave == 0 ? "开启自动聚焦" : "关闭自动聚焦";
- string str2 = e.Value_up == 0 ? "自动变倍" : "手动变倍";
- string str3 = e.Value_low == 0 ? "自动Z轴聚焦" : "手动Z轴聚焦";
- string ShowData = e.Mesg + $"-{str1}-{str2}-{str3}";
-
- newStepShow.StepString = ShowData;
- }
- if (e.Mesg == "光源设置")
- {
- string ShowData = e.Mesg + $":通道号:{e.Value_up},亮度:{e.Value_low}";
- newStepShow.StepString = ShowData;
- }
- else
- {
- newStepShow.StepMax = e.Value_up;
- newStepShow.StepMin = e.Value_low;
- newStepShow.StepData = e.Value_ave;
- if (e.Value !=null && e.Value.Count > 0)
- {
- string ShowData = e.Mesg + $"1:{e.Value[0]}";
- for (int i = 1; i < e.Value.Count; i++)
- {
- ShowData += $",{e.Mesg}{i + 1}:{e.Value[i]}";
- }
- newStepShow.StepString = ShowData;
- }
- else
- newStepShow.StepString = e.Mesg;
- }
- if (e.ProcessSts == 1)
- newStepShow.StepStatus = NewStepShow.StepStsEnum.Testing;
- else if (e.ProcessSts == 2)
- newStepShow.StepStatus = NewStepShow.StepStsEnum.OK;
- else if (e.ProcessSts == 3)
- newStepShow.StepStatus = NewStepShow.StepStsEnum.NG;
- else if (e.ProcessSts == 0)
- newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
- else if (e.ProcessSts == 4)
- newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
- }
- else
- {
- NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
- newStepShowDef.StepString = e.Mesg;
- if (e.ProcessSts == 1)
- newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Testing;
- else if (e.ProcessSts == 2)
- newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.OK;
- else if (e.ProcessSts == 3)
- newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.NG;
- else if (e.ProcessSts == 0)
- newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
- else if (e.ProcessSts == 4)
- newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Error;
-
- if (e.Value_ave == 0)
- {
- newStepShowDef.StepSizeData = (int)e.Value_up;
- if (e.Value_up > 0)
- newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.NG;
- else if (e.Value_up < 0)
- newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
- else if (e.Value_up == 0)
- newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.OK;
- else
- newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.Error;
- }
- else
- {
- if (e.Value_low == 0)
- newStepShowDef.StepDefectData = (int)e.Value_low;
- else if (e.Value_low > 0)
- newStepShowDef.StepDefectData = newStepShowDef.StepDefectData + (int)e.Value_low;
-
-
- //if (e.Value_low > 0)
- // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.NG;
- //else if (e.Value_low < 0)
- // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
- //else if ((e.Value_low == 0)&&(e.Value_up == 0))
- // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.OK;
- if ((e.Value_up == -1) && (e.Value_low == -1))
- newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Error;
- else if (e.Value_up == 1)
- newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Testing;
- else if (e.Value_up == 0)
- {
- newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Done;
- newStepShowDef.StepDefectData = (int)e.Value_low;
- }
- }
- }
-
- }
- else if (e.Cmd == 31) //忽略流程 厚度, 张力, pt, 线宽显示
- {
- Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex + 1), true);
- if (controls != null)
- {
- if (!e.ProcessType)
- {
- NewStepShow newStepShow = controls[0] as NewStepShow;
- newStepShow.StepMax = 0;
- newStepShow.StepMin = 0;
- newStepShow.StepData = 0;
- string ShowData = e.Mesg;
- newStepShow.StepString = ShowData;
-
- if (e.ProcessSts == 4)
- newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
- else
- newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
- }
- else
- {
- NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
- newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
- newStepShowDef.StepDefectData = -1;
- newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
- newStepShowDef.StepSizeData = -1;
- newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
- newStepShowDef.StepString = "未启用或被禁用";
- newStepShowDef.StepString = e.Mesg;
- }
- }
-
- }
-
- Application.DoEvents();
- }
- catch { }
- }
- }
-
- void ShowNewStepProcess(List<StepProcess> list)
- {
- flpProcessStep.Controls.Clear();
- int index = 0;
- int splitWidth = 5;
- foreach (StepProcess stepProcess in list)
- {
- index++;
- if (stepProcess.ProcessCode != "SizeAndDefect")
- {
- NewStepShow newStepShow = new NewStepShow();
- newStepShow.Width = flpProcessStep.Width - splitWidth * 2 - 30;
- newStepShow.StepName = stepProcess.ProcessName;
- newStepShow.StepIndex = index;
- newStepShow.StepMax = 0;
- newStepShow.StepMin = 0;
- newStepShow.StepData = 0;
- newStepShow.StepString = "";
- newStepShow.StepStatus = NewStepShow.StepStsEnum.Wait;
-
- newStepShow.Margin = new Padding(splitWidth, splitWidth, 0, 0);
-
- newStepShow.Name = "Step_" + index;
- flpProcessStep.Controls.Add(newStepShow);
- }
- else
- {
- NewStepShowDefect newStepShowDefect = new NewStepShowDefect();
- newStepShowDefect.Width = flpProcessStep.Width - splitWidth * 2 - 30;
- newStepShowDefect.StepName = stepProcess.ProcessName;
- newStepShowDefect.StepIndex = index;
-
- bool opensize = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenSize");
- newStepShowDefect.StepSizeSts = opensize ? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
- newStepShowDefect.StepSizeData = -1;
- bool opendefect = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenDefect");
- newStepShowDefect.StepDefectSts = opendefect? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
- newStepShowDefect.StepDefectData = -1;
-
- newStepShowDefect.StepString = "";
- newStepShowDefect.StepStatus = NewStepShowDefect.StepStsEnum.Wait;
-
- newStepShowDefect.Margin = new Padding(splitWidth, splitWidth, 0, 0);
-
- newStepShowDefect.Name = "Step_" + index;
- flpProcessStep.Controls.Add(newStepShowDefect);
- }
- }
- }
- /// <summary>
- /// 缺陷小图多图显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void auto_ShowMoreImg(object sender, ImgEventArgs e)
- {
- ShowImgEvent(e);
- }
-
- private delegate void ShowImgEventDelegate(ImgEventArgs e);
- private void ShowImgEvent(ImgEventArgs e)
- {
- if (InvokeRequired)
- {
- ShowImgEventDelegate smd = new ShowImgEventDelegate(ShowImgEvent);
- this.BeginInvoke(smd, e);
- }
- else
- {
- //Task<int> tt = new Task<int>(() =>
- //{
- //lock (AddPicLock)
- {
- //加载缺陷小图
- //纵向显示
- int imgWidth = this.pnlBmpList.ClientSize.Width - 50;
- int imgHeight = (int)((e.Bitmaps[0].Height * 1.0f / e.Bitmaps[0].Width) * imgWidth + 0.5);
- int splitWidth = 20;
- int pnlWidth = this.pnlBmpList.ClientSize.Width;
- int index = (int)this.gboxDefectList.Tag;
- //横向显示
- //int imgHeight = this.pnlBmpList.Height - 50;
- //int imgWidth = (int)((e.Bitmaps[0].Width * 1.0f / e.Bitmaps[0].Height) * imgHeight + 0.5);
- //int splitWidth = 20;
- //int pnlWidth = this.pnlBmpList.Height;
- //int index = (int)this.gboxDefectList.Tag;
-
- int len = e.Info.Count();
- int range = 100;
- int uselen = len > 100 ? 100 : len;
- for (int x = 0; x < uselen / range + 1; x++)
- {
- for (int i = 0; i < (x < (uselen / range) ? range : uselen % range); i++)
- {
- foreach (var item in e.Info[(x * range + i)]) //单个info[x] = {"1":[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]}
- {
- //统计缺陷类型
- SysMgr.Instance.countDefectClass(item.Value);//[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]
-
- //
- PictureBox picbox = new PictureBox();
- picbox.Width = imgWidth;
- picbox.Height = imgHeight;
-
- picbox.Image = (Bitmap)e.Bitmaps[(x * range + i)].Clone();
- picbox.Name = "imgDefect_" + index;
- picbox.Tag = item.Key + "," + e.X + "," + e.Y;
-
- picbox.Click += new EventHandler(defectBmpBox_Click);
- picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
- picbox.BorderStyle = BorderStyle.FixedSingle;
- //picbox.Margin = new Padding((pnlWidth - picbox.Height) / 2, splitWidth, 0, 0);
- picbox.Margin = new Padding((pnlWidth - picbox.Width) / 2, splitWidth, 0, 0);
- picbox.MouseHover += simpleTip_MouseHover;
- picbox.Visible = true;
-
- //this.Invoke(new MethodInvoker(() =>
- // {
- this.pnlBmpList.Controls.Add(picbox);
- //this.Refresh();
- //this.dgvProcess.Refresh();
- //this.lstLog.Refresh();
- //this.statusStrip1.Refresh();
- // }));
-
- break;
- }
-
- //
- index++;
- //Thread.Sleep(10);
- //Application.DoEvents();
- }
- //Application.DoEvents();
- //this.Invoke(new MethodInvoker(() =>
- //{
- //this.Refresh();
- pnlBmpList.VerticalScroll.Value = pnlBmpList.VerticalScroll.Maximum;
- //}));
- //Thread.Sleep(10);
- }
- //this.Invoke(new MethodInvoker(() =>
- //{
- //this.gboxDefectList.Tag = len + (int)this.gboxDefectList.Tag;
- this.gboxDefectList.Tag = index;
- this.gboxDefectList.Text = $"缺陷图像:{index} 张";
- }
- //}));
- //return 0;
- // });
- // tt.Start();
- // await tt;
- }
- }
- #endregion
-
- #region 工具栏
- private void tsbtnImpStop_Click(object sender, EventArgs e)
- {
- SysMgr.Instance.LedPause();
- AddTextEvent("急停", "手动急停", WarningEnum.High);
- SysMgr.Instance.StatusMgr.GotoWarning( WarningEnum.High, "急停", "手动急停");
- SysMgr.Instance.SendStatus();
- SysMgr.Instance.EmergencyStop();
- }
- private void tsbOpenLight_Click(object sender, EventArgs e)
- {
- if (this.tsbOpenLight.Text == "开灯")
- {
- SysMgr.Instance.OpenFloodlight(true);
- this.tsbOpenLight.Text = "关灯";
- }
- else
- {
- SysMgr.Instance.OpenFloodlight(false);
- this.tsbOpenLight.Text = "开灯";
- }
- }
-
- private void tsbtnStart_Click(object sender, EventArgs e)
- {
- if (!SysMgr.Instance.IsRuning)
- {
- //低报警自动复位
- if(SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
- {
- if (SysMgr.Instance.StatusMgr.Warning == WarningEnum.Low)
- {
- SysMgr.Instance.StatusMgr.ClearWarning();
- SysMgr.Instance.StatusMgr.GotoNormalStandby();
- }
- }
- //提示正在报警中
- if (SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
- {
- FrmDialog.ShowDialog(this, "系统报警中!无法启动运行!", "警告", false);
- return;
- }
- this.Cursor = Cursors.WaitCursor;
- System.Windows.Forms.Application.DoEvents();
- if (SysMgr.Instance.StatusMgr.Status != SystemStsEnum.Pause)
- {
- ResetUI(false);
- AddTextEvent("运行", $"启动自动检测流程");
- this.lstLog.Refresh();
- if (SysMgr.Instance.StartRun(this, this.cbOrderCode.Text, this.cbProductCode.Text, this.cbProductSN.Text))
- {
- this.tsbtnStop.Enabled = true;
- this.tsbtnStart.Enabled = false;
- //锁定信息
- this.cbOrderCode.Enabled = false;
- this.cbProductCode.Enabled = false;
- this.cbProductSN.Enabled = false;
- //记录开始运行时间
- RunStartTime.Restart();
- }
- }
- else //暂停状态开始
- {
- if (SysMgr.Instance.ReStartRun())
- {
- this.tsbtnStop.Enabled = true;
- this.tsbtnStart.Enabled = false;
- }
- }
- this.Cursor = Cursors.Default;
- }
- }
-
- private void tsbtnStop_Click(object sender, EventArgs e)
- {
- AddTextEvent("暂停", "手动暂停");
- this.tsbtnStart.Enabled = true;
- SysMgr.Instance.StatusMgr.GotoPause();
- SysMgr.Instance.SendStatus();
- SysMgr.Instance.LedPause();
- //this.tsbtnStart.Enabled = true;
- }
- private void tsbtnReset_Click(object sender, EventArgs e)
- {
- if (SystemIsRun())
- {
- DialogResult dr = DialogResult.Cancel;
-
- dr = FrmDialog.ShowDialog(this, "确定要复位当前系统?", "警告", true);
- if (dr == DialogResult.OK)
- {
- this.tsbtnStart.Enabled = true;
- this.tsbtnStop.Enabled = false;
- Task.Factory.StartNew(() =>
- {
- SysMgr.Instance.LedRset(true);
-
- SysMgr.Instance.GotoReadyPosAndIO();
-
- SysMgr.Instance.LedRset(false);
- });
- ResetUI(true);
- //AddTextEvent("复位", "复位完成");
- }
- }
- }
- private void tsbtnWarning_Click(object sender, EventArgs e)
- {
- if(SysMgr.Instance.StatusMgr.Warning != WarningEnum.Normal)
- {
- AddTextEvent("清除", "手动清除报警");
- SysMgr.Instance.StatusMgr.ClearWarning();
- SysMgr.Instance.LedReady();
- if (SysMgr.Instance.IsAuto)
- SysMgr.Instance.StatusMgr.GotoPause();
- else
- SysMgr.Instance.StatusMgr.GotoNormalStandby();
- SysMgr.Instance.SendStatus();
- }
- }
- private void tsbGoHome_Click(object sender, EventArgs e)
- {
- if (SystemIsRun())
- {
- DialogResult dr = DialogResult.Cancel;
-
- dr = FrmDialog.ShowDialog(this, "确定要复位当前系统所有硬件位置?", "警告", true);
- if (dr == DialogResult.OK)
- {
- this.tsbtnStart.Enabled = true;
- this.tsbtnStop.Enabled = false;
- this.Cursor = Cursors.WaitCursor;
- System.Windows.Forms.Application.DoEvents();
- Task.Factory.StartNew(() =>
- {
- SysMgr.Instance.LedRset(true);
- SysMgr.Instance.AllResetAndGoHome();
- SysMgr.Instance.LedRset(false);
- });
- this.Cursor = Cursors.Default;
- }
- }
- }
-
- //缺陷+比对与图纸查看
- private void tsbtnDefectImage_Click(object sender, EventArgs e)
- {
- try
- {
- string gbxBmpPath = "";
- Order temp_order = null;
- if (SysMgr.Instance.GetDefectDistribution(out gbxBmpPath, out temp_order))
- {
- //
- ToolStripButton btn = sender as ToolStripButton;
- DefectImageShowFrm frm = new DefectImageShowFrm(gbxBmpPath , temp_order, string.IsNullOrEmpty(btn.Tag.ToString()) ? 0 : Convert.ToInt32(btn.Tag.ToString()));
- frm.Show();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
- }
- }
- #endregion
-
- #region 小图操作
- private void defectBmpBox_Click(object sender, EventArgs e)
- {
- PictureBox picbox = sender as PictureBox;
- if (SysMgr.Instance.IsAuto || SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Auto)//检测中
- {
- //只查看
- AddTextEvent("查看", $"运行中查看缺陷{SysMgr.Instance.IsAuto} - {SysMgr.Instance.StatusMgr.Status}");
- ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
- frm.ShowDialog(this);
- }
- else//完成
- {
- AddTextEvent("查看", $"查看缺陷{ConfMgr.Instance.SysConfigParams.OpenDefectSanp}");
- ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls,
- Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]), ConfMgr.Instance.SysConfigParams.OpenDefectSanp);
- frm.ShowDialog(this);
- }
-
- }
- private void simpleTip_MouseHover(object sender, EventArgs e)
- {
- PictureBox pb = sender as PictureBox;
- // 创建the ToolTip
- ToolTip toolTip1 = new ToolTip();
-
- // 设置显示样式
- toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
- toolTip1.InitialDelay = 500;//事件触发多久后出现提示
- toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
- toolTip1.ShowAlways = true;//是否显示提示框
-
- // 设置伴随的对象.
- toolTip1.SetToolTip(pb, pb.Name + "[" +pb.Tag.ToString() + "]");//设置提示按钮和提示内容
- }
- #endregion
-
- #region 时钟捕获
- GetPN pn = new GetPN();
- private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
- {
- while (backgroundWorkerDo)
- {
- try
- {
- this.Invoke(new MethodInvoker(() =>
- {
- this.tsslLoginTime.Text = $" 当前时间:{DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss")}";
- }));
- //检测按钮和实时状态
- if (SysMgr.Instance.IsInit)
- {
- bool sts = SysMgr.Instance.WarningShowLed(DisEnableBuzz);
- if (sts)
- {
- this.Invoke(new MethodInvoker(() =>
- {
- this.tsbtnStart.Enabled = true;
- this.tsbtnStop.Enabled = false;
- }));
- }
- int stsno = 0;
- stsno = SysMgr.Instance.ButtonIOTrg(DisEnableDoor);
- if (stsno == 1)
- {
- this.Invoke(new MethodInvoker(() =>
- {
- tsbtnStart_Click(null, null);
- }));
- }
- else if (stsno == 2)
- {
- this.Invoke(new MethodInvoker(() =>
- {
- this.tsbtnStart.Enabled = true;
- }));
- SysMgr.Instance.LedPause();
- }
- else if (stsno == 3)
- {
- this.Invoke(new MethodInvoker(() =>
- {
- tsbtnReset_Click(null, null);
- }));
-
- }
- else if (stsno == 4) //老流程张力读取
- {
- TensionResult tensionResult;
- if (SysMgr.Instance.TensionGetValue(out tensionResult) >= 0)
- {
- this.Invoke(new MethodInvoker(() =>
- {
- this.lblTension.Text = Math.Round(tensionResult.value, 2).ToString();
- this.lblTension.ForeColor = tensionResult.color;
-
- this.lblTensionMax.Text = Math.Round(tensionResult.valueMax, 2).ToString();
- this.lblTensionMax.ForeColor = tensionResult.colorMax;
-
- this.lblTensionMin.Text = Math.Round(tensionResult.valueMin, 2).ToString();
- this.lblTensionMin.ForeColor = tensionResult.colorMin;
- }));
- }
-
- }
- else if (stsno == 5) //新流程张力读取
- {
-
- //this.Invoke(new MethodInvoker(() =>
- //{
- // tsbtnReset_Click(null, null);
- //}));
-
- }
- //显示实际位置
- this.Invoke(new MethodInvoker(() =>
- {
- tsAxisState.Text = SysMgr.Instance.GetAxisPos();
- }));
- }
- if (pn.P(SysMgr.Instance.IsRuning))
- {
- //继续计时
- RunStartTime.Start();
- }
- if (pn.N(SysMgr.Instance.IsRuning))
- {
- //停止计时
- RunStartTime.Stop();
- }
- if (SysMgr.Instance.IsRuning)
- {
- //实时显示
- RunStartTime.Stop();
- this.Invoke(new MethodInvoker(() =>
- {
- tslabelTime.Text = "实时测试:" + ((double)RunStartTime.ElapsedMilliseconds / 1000.0).ToString("0.000") + "s";
- //this.Refresh();
- }));
- RunStartTime.Start();
- }
- Thread.Sleep(100);
- }
- catch { }
- }
- }
- /// <summary>
- /// 信号上升沿下降沿捕获
- /// </summary>
- class GetPN
- {
- bool _P = false;
- bool _N = false;
- /// <summary>
- /// 判断上升沿
- /// </summary>
- /// <param name="Value"></param>
- /// <returns></returns>
- public bool P(bool Value)
- {
- if (Value && !_P)
- {
- _P = true;
- return true;
- }
-
- if (!Value)
- _P = false;
-
- return false;
- }
- /// <summary>
- /// 判断下降沿
- /// </summary>
- /// <param name="Value"></param>
- /// <returns></returns>
- public bool N(bool Value)
- {
- if (!Value && _N)
- {
- _N = false;
- return true;
- }
-
- if (Value)
- _N = true;
- return false;
- }
- }
- #endregion
-
- #region 料号和产品编码选择
- private void txtProductCode_DoubleClick(object sender, EventArgs e)
- {
- string pdtName = SysMgr.Instance.SelectProduct();
- if (!string.IsNullOrWhiteSpace(pdtName))
- this.cbProductCode.Text = pdtName;
- }
-
- private void txtProductCode_TextChanged(object sender, EventArgs e)
- {
-
- }
-
- private void txtProductSN_DoubleClick(object sender, EventArgs e)
- {
- InputFrm frm = new InputFrm(null, "请输入网版编码:");
- if (frm.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(frm.inputData))
- {
- this.cbProductSN.Text = frm.inputData;
- }
- else
- {
- this.cbProductSN.Text = "";
- }
- }
-
- private string[] pdtlistData;
- private string[] snlistData;
-
- private void LoadPdtList(List<string> list)
- {
- this.cbProductCode.Items.Clear();
- this.pdtlistData = list.ToArray();
- cbProductCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
- cbProductCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
- cbProductCode.KeyDown += CobList_KeyDown;
- this.cbProductCode.Text = "";
- cbProductCode.Focus();
- cbProductCode.SelectAll();
- }
-
- private void LoadSNList(List<string> list)
- {
- this.cbProductSN.Items.Clear();
- this.snlistData = list.ToArray();
- cbProductSN.Items.AddRange(snlistData);//比使用DataSource速度要快一些
- //cbProductSN.TextUpdate += cobList_TextUpdate;//重新绑定事件
- cbProductSN.KeyDown += CobList_KeyDown;
- this.cbProductSN.Text = "";
- cbProductSN.Focus();
- cbProductSN.SelectAll();
- }
-
- 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;
- if (ctrl.Name == "cbProductCode")
- workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
- else
- workOrderFiltered = snlistData.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
-
- private void MainFrm_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;
- }
- }
-
- private void tsmSysUserMgr_Click(object sender, EventArgs e)
- {
-
- }
-
- private void tabPage1_Resize(object sender, EventArgs e)
- {
- int allWidth = this.tabPage1.Width;
- this.flpnlResultData.Width = allWidth;
- kanban1.Width = kanban2.Width = kanban3.Width = kanban4.Width = kanban5.Width = kanban6.Width = (flpnlResultData.Width - 30) / 6;
- tabControl1.Region = new Region(new RectangleF(this.tabPage1.Left, this.tabPage1.Top, this.tabPage1.Width, this.tabPage1.Height));
- }
-
- private void tabPage2_Resize(object sender, EventArgs e)
- {
- int allWidth = this.tabPage2.Width;
- tabControl1.Region = new Region(new RectangleF(this.tabPage2.Left, this.tabPage2.Top, this.tabPage2.Width, this.tabPage2.Height));
- }
- private void MainFrm_Paint(object sender, PaintEventArgs e)
- {
- this.tsbtnReset.Visible = ConfMgr.Instance.SysConfigParams.ShowResetBtn;
- this.chkBuzzer.Visible = ConfMgr.Instance.SysConfigParams.ShowBuzz;
- this.chkDoorSensor.Visible = ConfMgr.Instance.SysConfigParams.ShowDoorAlm;
- this.tsbtnDefectImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
- this.tsbtnSizeImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
- }
-
- private void flpProcessStep_SizeChanged(object sender, EventArgs e)
- {
- int splitWidth = 5;
- foreach (Control item in this.flpProcessStep.Controls)
- {
- item.Width = flpProcessStep.Width - splitWidth * 2 - 30;
- }
- this.flpProcessStep.Refresh();
- this.gpbProcessList.Refresh();
- }
-
- private void cbProductSN_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- this.cbProductSN.Text = "";
- this.cbProductSN.Select();
- }
- }
- }
|