From 82ed13594646062763e23b804854894bc1ef41aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?liming=20=E8=94=A1?= Date: Thu, 13 Aug 2026 20:08:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E7=AB=99=E6=95=B0=E6=8D=AE=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JY.Inspection/Common/CollectionUtil.cs | 20 + JY.Inspection/ConstValue.cs | 64 ++ JY.Inspection/HomeForm.cs | 1180 +++++++++++++++--------- JY.Inspection/HomeForm.designer.cs | 303 +----- JY.Inspection/JY.Inspection.csproj | 1 + JY.Model/DB.Entity/BlankingData.cs | 23 + replace_method.py | 196 ++++ 7 files changed, 1032 insertions(+), 755 deletions(-) create mode 100644 JY.Inspection/ConstValue.cs create mode 100644 replace_method.py diff --git a/JY.Inspection/Common/CollectionUtil.cs b/JY.Inspection/Common/CollectionUtil.cs index 0713077..42bb6c6 100644 --- a/JY.Inspection/Common/CollectionUtil.cs +++ b/JY.Inspection/Common/CollectionUtil.cs @@ -22,5 +22,25 @@ namespace JY.Inspection.Common } return list; } + + public static List GetListFloat(int Num) + { + List list = new List(); + for (int i = 0; i < Num; i++) + { + list.Add(1); + } + return list; + } + + public static List GetListInt(int Num) + { + List list = new List(); + for (int i = 0; i < Num; i++) + { + list.Add(1); + } + return list; + } } } diff --git a/JY.Inspection/ConstValue.cs b/JY.Inspection/ConstValue.cs new file mode 100644 index 0000000..302a900 --- /dev/null +++ b/JY.Inspection/ConstValue.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JY.Inspection +{ + public class ConstValue + { + /// + /// CCD的OK/NG数量 + /// + //public const int CCD_SCount = 16; + public const string CCD_OK = "OK"; + public const string CCD_NG = "NG"; + + public static readonly Dictionary CCD_SDict = new Dictionary() + { + { "CCD1", "正面侧面_3D" }, + { "CCD2", "正面侧面_2D" }, + { "CCD3", "正面底面棱_3D" }, + { "CCD4", "后面右侧面_2D" }, + { "CCD5", "后面底面棱_3D" }, + { "CCD6", "极柱面_3D" }, + { "CCD7", "极柱面_2D" }, + { "CCD8", "底面_3D" }, + { "CCD9", "底面_2D" }, + { "CCD10", "左中间棱_3D" }, + { "CCD11", "右中间棱_3D" }, + { "CCD12", "防爆阀_2D" }, + { "CCD13", "左右极柱_2D" }, + { "CCD14", "L胶检测结果" }, + { "CCD15", "二维码等级判定结果" } + }; + + /// + /// CCD的浮点数数量 + /// + //public const int CCD_FCount = 3; + + public static readonly Dictionary CCD_FDict = new Dictionary() + { + { "CCDF1", "大面平面度" }, + { "CCDF2", "侧面平面度" }, + { "CCDF3", "底面平面度" } + }; + + /// + /// CCD的整数数量 + /// + //public const int CCD_ICount = 6; + + public static readonly Dictionary CCD_IDict = new Dictionary() + { + { "CCDI1", "通道" }, + { "CCDI2", "下面凹坑数量" }, + { "CCDI3", "前面凹坑数量" }, + { "CCDI4", "后面凹坑数量" }, + { "CCDI5", "左面凹坑数量" }, + { "CCDI6", "右面凹坑数量" } + }; + } +} diff --git a/JY.Inspection/HomeForm.cs b/JY.Inspection/HomeForm.cs index 96ec46b..3aeba27 100644 --- a/JY.Inspection/HomeForm.cs +++ b/JY.Inspection/HomeForm.cs @@ -257,6 +257,8 @@ namespace JY.Inspection dgvDataShow_A.DataSource = listTA; this.dgvDataShow_A.DataError += delegate (object sender, DataGridViewDataErrorEventArgs e) { }; + InitDgvBColumns(); + //利用反射设置DataGridView的双缓冲 Type dgvType1 = this.dgvDataShow_B.GetType(); PropertyInfo pi1 = dgvType1.GetProperty("DoubleBuffered", @@ -278,6 +280,237 @@ namespace JY.Inspection this.Resizable = true; } + private void InitDgvBColumns() + { + + DataGridViewTextBoxColumn Column6 = new DataGridViewTextBoxColumn(); + Column6.DataPropertyName = "TD"; + Column6.HeaderText = "序号"; + Column6.MinimumWidth = 6; + Column6.Name = "Column6"; + Column6.ReadOnly = true; + Column6.Width = 52; + + DataGridViewTextBoxColumn Column8 = new DataGridViewTextBoxColumn(); + Column8.DataPropertyName = "WorkShift"; + Column8.HeaderText = "班次"; + Column8.MinimumWidth = 6; + Column8.Name = "Column8"; + Column8.ReadOnly = true; + Column8.Width = 52; + + DataGridViewTextBoxColumn Column31 = new DataGridViewTextBoxColumn(); + Column31 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column31.DataPropertyName = "TDGroup"; + Column31.HeaderText = "主道"; + Column31.MinimumWidth = 8; + Column31.Name = "Column31"; + Column31.ReadOnly = true; + Column31.Width = 52; + + DataGridViewTextBoxColumn Column26 = new DataGridViewTextBoxColumn(); + Column26.DataPropertyName = "ArrivalBarCode"; + Column26.HeaderText = "入站条码"; + Column26.MinimumWidth = 8; + Column26.Name = "Column26"; + Column26.ReadOnly = true; + Column26.Width = 64; + + DataGridViewTextBoxColumn Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column7.DataPropertyName = "DepartureBarCode"; + Column7.HeaderText = "出站条码"; + Column7.MinimumWidth = 6; + Column7.Name = "Column7"; + Column7.ReadOnly = true; + Column7.Width = 64; + + DataGridViewTextBoxColumn Column27 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column27.DataPropertyName = "TMDB"; + Column27.HeaderText = "条码对比"; + Column27.MinimumWidth = 8; + Column27.Name = "Column27"; + Column27.ReadOnly = true; + Column27.Width = 64; + + DataGridViewTextBoxColumn Column25 = new DataGridViewTextBoxColumn(); + Column25.DataPropertyName = "OutTime"; + Column25.HeaderText = "出站时间"; + Column25.MinimumWidth = 6; + Column25.Name = "Column25"; + Column25.ReadOnly = true; + Column25.Width = 64; + + DataGridViewTextBoxColumn Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column9.DataPropertyName = "CCD1"; + Column9.HeaderText = "正面(2D/3D)"; + Column9.MinimumWidth = 6; + Column9.Name = "Column9"; + Column9.ReadOnly = true; + Column9.Width = 86; + + DataGridViewTextBoxColumn Column10= new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column10.DataPropertyName = "CCD2"; + Column10.HeaderText = "反面(2D/3D)"; + Column10.MinimumWidth = 6; + Column10.Name = "Column10"; + Column10.ReadOnly = true; + Column10.Width = 86; + + DataGridViewTextBoxColumn Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column11.DataPropertyName = "CCD3"; + Column11.HeaderText = "左侧面(2D/3D)"; + Column11.MinimumWidth = 6; + Column11.Name = "Column11"; + Column11.ReadOnly = true; + Column11.Width = 98; + + DataGridViewTextBoxColumn Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column12.DataPropertyName = "CCD4"; + Column12.HeaderText = "右侧面(2D/3D)"; + Column12.MinimumWidth = 6; + Column12.Name = "Column12"; + Column12.ReadOnly = true; + Column12.Width = 98; + + DataGridViewTextBoxColumn Column13 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column13.DataPropertyName = "CCD5"; + Column13.HeaderText = "顶面(2D/3D)"; + Column13.MinimumWidth = 6; + Column13.Name = "Column13"; + Column13.ReadOnly = true; + Column13.Width = 86; + + DataGridViewTextBoxColumn Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column14.DataPropertyName = "CCD6"; + Column14.HeaderText = "底面(2D/3D)"; + Column14.MinimumWidth = 6; + Column14.Name = "Column14"; + Column14.ReadOnly = true; + Column14.Width = 86; + + DataGridViewTextBoxColumn Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column15.DataPropertyName = "CCD7"; + Column15.HeaderText = "底棱边WE1"; + Column15.MinimumWidth = 6; + Column15.Name = "Column15"; + Column15.ReadOnly = true; + Column15.Width = 85; + + DataGridViewTextBoxColumn Column16 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column16.DataPropertyName = "CCD8"; + Column16.HeaderText = "底棱边WE2"; + Column16.MinimumWidth = 6; + Column16.Name = "Column16"; + Column16.ReadOnly = true; + Column16.Width = 85; + + DataGridViewTextBoxColumn Column17 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column17.DataPropertyName = "CCD9"; + Column17.HeaderText = "底棱边WE3"; + Column17.MinimumWidth = 6; + Column17.Name = "Column17"; + Column17.ReadOnly = true; + Column17.Width = 85; + + DataGridViewTextBoxColumn Column18 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column18.DataPropertyName = "CCD10"; + Column18.HeaderText = "底棱边WE4"; + Column18.MinimumWidth = 6; + Column18.Name = "Column18"; + Column18.ReadOnly = true; + Column18.Width = 85; + + DataGridViewTextBoxColumn Column19 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column19.DataPropertyName = "CCD11"; + Column19.HeaderText = "中棱边ME1"; + Column19.MinimumWidth = 6; + Column19.Name = "Column19"; + Column19.ReadOnly = true; + Column19.Width = 84; + + DataGridViewTextBoxColumn Column20 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column20.DataPropertyName = "CCD12"; + Column20.HeaderText = "中棱边ME2"; + Column20.MinimumWidth = 6; + Column20.Name = "Column20"; + Column20.ReadOnly = true; + Column20.Width = 84; + + DataGridViewTextBoxColumn Column21 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column21.DataPropertyName = "CCD13"; + Column21.HeaderText = "中棱边ME3"; + Column21.MinimumWidth = 6; + Column21.Name = "Column21"; + Column21.ReadOnly = true; + Column21.Width = 84; + + DataGridViewTextBoxColumn Column23 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column23.DataPropertyName = "CCD14"; + Column23.HeaderText = "中棱边ME4"; + Column23.MinimumWidth = 6; + Column23.Name = "Column23"; + Column23.ReadOnly = true; + Column23.Width = 84; + + DataGridViewTextBoxColumn Column28 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column28.DataPropertyName = "CCD15"; + Column28.HeaderText = "极柱(POS/NEG)"; + Column28.MinimumWidth = 8; + Column28.Name = "Column28"; + Column28.ReadOnly = true; + + DataGridViewTextBoxColumn Column29 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column29.DataPropertyName = "CCD16"; + Column29.HeaderText = "防爆阀(PRO)"; + Column29.MinimumWidth = 8; + Column29.Name = "Column29"; + Column29.ReadOnly = true; + Column29.Width = 89; + + DataGridViewTextBoxColumn Column22 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column22.DataPropertyName = "Result"; + Column22.HeaderText = "综合结果"; + Column22.MinimumWidth = 6; + Column22.Name = "Column22"; + Column22.ReadOnly = true; + Column22.Width = 64; + + DataGridViewTextBoxColumn Column24 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Column24.DataPropertyName = "Remark"; + Column24.HeaderText = "备注"; + Column24.MinimumWidth = 6; + Column24.Name = "Column24"; + Column24.ReadOnly = true; + Column24.Width = 52; + + this.dgvDataShow_B.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + Column6, + Column8, + Column31, + Column26, + Column7, + Column27, + Column25, + Column9, + Column10, + Column11, + Column12, + Column13, + Column14, + Column15, + Column16, + Column17, + Column18, + Column19, + Column20, + Column21, + Column23, + Column28, + Column29, + Column22, + Column24}); + } + /// /// 单例 @@ -2045,343 +2278,7 @@ namespace JY.Inspection try { sw.Restart(); - List list = new List(); - List listBarIn = StrUtil.GetListString(2, "NG");//进站条码 - List listBarOut = StrUtil.GetListString(2, "NG");//出站条码 - List> listBarResult = new List>(); //CCD结果 - List listBar1Result = CollectionUtil.GetListUShort(16); - List listBar2Result = CollectionUtil.GetListUShort(16); - List listBar3Result = CollectionUtil.GetListUShort(16); - listBarResult.Add(listBar1Result); - listBarResult.Add(listBar2Result); - listBarResult.Add(listBar3Result); - List listResult = CollectionUtil.GetListUShort(2); - //读取plc地址W260。1 是开启屏蔽。2 是默认不开启。 反馈地址w261。 1 是正常不报警。 2 是报警。 - var isCCDMask = omronPLCCom.lstMcUI[0].ReadshortDReg("W260"); - int id = 0; - - byte[] bytes = resByte.Content.ByteReverse(); - //前面有2个占位标识 04 - int offset = 0; - for (int i = 0; i < 2; i++) - { - listBarOut[i] = TransformBase.TransString(bytes, 0 + offset + (i*40 *2), 20 *2, System.Text.Encoding.ASCII).Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();//1# 出站条码 - var lstBarResult = listBarResult[i]; - for (int j = 0; j < 16; j++) - { - - // var okNg = TransformBase.TransString(bytes, 40 + offset + (i * 40*2) + j *2, 1*2, System.Text.Encoding.ASCII).Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim(); - int ccdDefault = TransformBase.TransInt16(resByte.Content, 40 + offset + (i * 40 * 2) + j * 2); - // int.TryParse(okNg,out ccdDefault); - lstBarResult[j] = (short)ccdDefault; - // TransformBase.TransInt16(resByte.Content, 20 + offset+(i * 40)+j,1);//1#CCD1结果CCD给0是OK,1是NG - } - listBarIn[i] = TransformBase.TransString(bytes, 140 * 2 + offset + (i * 20*2), 20 * 2, System.Text.Encoding.ASCII).Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();// - // listBarIn[i] = listBarOut[i]; - ///1# 进站条码 - } - - FeedingDataService service = (FeedingDataService)IocConfig.Provider.GetService(); - - for (int i = 0; i < listBarOut.Count; i++) - { - BlankingData m = new BlankingData(); - id = i + 1; - - No = No + 1; - m.TD = No; - m.WorkShift = ClassShift == 0 ? "白班" : "夜班"; - m.ArrivalBarCode = listBarIn[i]; - m.DepartureBarCode = listBarOut[i]; - m.OutTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - - - var listEntity = service.GetFeedingData(m.ArrivalBarCode); - if (listEntity.Count() > 0) - { - m.TDGroup = listEntity.First().TDGroup; - } - var lstBarResult = listBarResult[i]; - #region CCD结果 0 ok ;1 ng - m.CCD1 = lstBarResult[0] == 1 ? "OK" : "NG"; - m.CCD2 = lstBarResult[1] == 1 ? "OK" : "NG"; - m.CCD3 = lstBarResult[2] == 1 ? "OK" : "NG"; - m.CCD4 = lstBarResult[3] == 1 ? "OK" : "NG"; - m.CCD5 = lstBarResult[4] == 1 ? "OK" : "NG"; - m.CCD6 = lstBarResult[5] == 1 ? "OK" : "NG"; - m.CCD7 = lstBarResult[6] == 1 ? "OK" : "NG"; - m.CCD8 = lstBarResult[7] == 1 ? "OK" : "NG"; - m.CCD9 = lstBarResult[8] == 1 ? "OK" : "NG"; - m.CCD10 = lstBarResult[9] == 1 ? "OK" : "NG"; - m.CCD11 = lstBarResult[10] == 1 ? "OK" : "NG"; - m.CCD12 = lstBarResult[11] == 1 ? "OK" : "NG"; - m.CCD13 = lstBarResult[12] == 1 ? "OK" : "NG"; - m.CCD14 = lstBarResult[13] == 1 ? "OK" : "NG"; - m.CCD15 = lstBarResult[14] == 1 ? "OK" : "NG"; - m.CCD16 = lstBarResult[15] == 1 ? "OK" : "NG"; - - //var cfgList = Global.systemConfig.CollectItemCfgList - // .Where(it => it.IsEnable && it.PLCRelAddress != null) - // .OrderBy(it => it.PLCRelAddress).ToList(); - - //for (int k = 0; k < cfgList.Count; k++) - //{ - // var item = cfgList[k]; - - // int index = (int)item.PLCRelAddress - 1; - - // if (index < listBar2Result.Count) - // { - // var code = listBar2Result[index] == 1 ? "OK" : "NG"; - // m.PLCValDic.Add((int)item.PLCRelAddress, code); - // } - //} - #endregion - string levelresult = null; - string strErr = ""; - //入站条码判断 - if (String.IsNullOrEmpty(m.ArrivalBarCode) || m.ArrivalBarCode.Trim() == "ERROR") - m.ArrivalBarCode = "ERROR" + Guid.NewGuid().ToString("N").Substring(0, 8); - //出站条码判断 - if (String.IsNullOrEmpty(m.DepartureBarCode) || m.DepartureBarCode.Trim() == "ERROR") - m.DepartureBarCode = "ERROR" + Guid.NewGuid().ToString("N").Substring(0, 8); - - var lstError = new List(); - listResult[i] = GetResult(m, ref strErr,ref lstError); - - m.Result = listResult[i] == 1 ? "OK" : "NG"; - m.Remark = strErr; - //扫码不良 进出站扫码不对应 不需要上传MES - var scanCount = lstError.Count(x => x == 2 || x == 3); - var ccdOkNg = "OK"; //ccd总结果 ok ng - if (scanCount > 0) - { - m.Result = "扫码NG"; - } - else - { - //扫码ng 另一分支ccd NG - var ccdNgCount = lstError.Count(x => x > 10); - if(ccdNgCount >0) - { - ccdOkNg = "NG"; - m.Result = "CCD结果NG"; - } - } - - - //OK - //扫码ng的不进行mes分档,CCD NG的也进行mes分档 - var isOkGrading = false; //是否已经完成OK挡位的分档成功 - if (listResult[i] == 1 || ccdOkNg =="NG") - { - if (Global.systemConfig.isUpMes && chkCkGrading) - { - //分档接口 - //21~24 OK挡位 - MesResponse resGrading = ToMesData.GetMesIn(m.DepartureBarCode, m.ArrivalBarCode);//分档查询 - try - { - //listResult[i] = (short)(88);//默认分档NG - //m.Remark = "外观检OK分档NG"; - if (resGrading.success) - { - if (resGrading.rows != null && resGrading.rows.Count > 0 && resGrading.rows[0].rank != null) - { - var rank = resGrading.rows[0].rank; - //不分类 - // 读取plc地址W260。9 是开启屏蔽 使用不分类。1 是默认不开启。 反馈地址w261。 1 是正常不报警。 2 是报警。 - - #region //CCD屏蔽被修改 报警 - var listGradingCCD = new List(); - listGradingCCD.Add(Global.systemConfig.Grading1);//k77_ok - listGradingCCD.Add(Global.systemConfig.Grading2); - listGradingCCD.Add(Global.systemConfig.Grading3); - listGradingCCD.Add(Global.systemConfig.Grading4); - if (isCCDMask == 9) - { - ccdOkNg = "不分类"; - var gradingCCD_NoClassCount = listGradingCCD.Count(x => x.Contains("不分类")); - if (gradingCCD_NoClassCount <= 0) - { - //CCD屏蔽被修改 报警 - omronPLCCom.lstMcUI[0].WriteDReg("W261", (short)2); - } - } - else - { - //必须有一个OK ccd结果拉带 - var gradingCCD_OKCount = listGradingCCD.Count(x => x.Contains("OK")); - if (gradingCCD_OKCount <= 0) - { - //CCD屏蔽被修改 报警 - omronPLCCom.lstMcUI[0].WriteDReg("W261", (short)2); - } - var lstGradingCCD_NG = listGradingCCD.Where(x => x.Contains("NG")).Distinct().ToList(); - foreach (var item_NG in lstGradingCCD_NG) - { - var grading_array = item_NG.Substring(0,item_NG.Length-2); - var indexGrading = listGradingCCD.IndexOf(grading_array + "OK"); - if (indexGrading < 0) - { - //CCD屏蔽被修改 报警 - omronPLCCom.lstMcUI[0].WriteDReg("W261", (short)2); - } - } - } - #endregion - - - rank += ccdOkNg; - //k77 + 不分类 ng ok - if (rank.Equals(Global.systemConfig.Grading1) ) - { - listResult[i] = (short)(MESGradingSet[0]); - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; - isOkGrading = true; - } - else if (rank.Equals(Global.systemConfig.Grading2) ) - { - listResult[i] = (short)(MESGradingSet[1]); - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; - isOkGrading = true; - } - else if (rank.Equals(Global.systemConfig.Grading3) ) - { - listResult[i] = (short)(MESGradingSet[2]); - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; - isOkGrading = true; - } - else if (rank.Equals(Global.systemConfig.Grading4)) - { - listResult[i] = (short)(MESGradingSet[3]); - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; - isOkGrading = true; - } - else - { - if (isCCDMask == 9) - { - m.Result = "分档NG"; - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD屏蔽状态"; - } - else - { - m.Result = "分档NG"; - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}与设置档位不匹配NG"; - } - - } - levelresult = resGrading.rows[0].level; - - } - else - { - m.Result = "分档NG"; - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OK分档NG,MES未反馈正确档位"; - } - - } - else - { - if (resGrading.error == 9 || resGrading.error == 99) - { - omronPLCCom.lstMcUI[0].WriteDReg("W249", (short)1);//MES网络异常 - LogManagerControl.AddLog($"出站条码[{m.DepartureBarCode}]访问MES异常", LogAddtype.local, Logtype.Error); - } - m.Result = "分档NG"; - m.Remark = $"出站条码[{m.DepartureBarCode}]外观检MES分档请求失败,访问MES异常"; - } - - } - catch (Exception ex) - { - m.Result = "分档NG"; - m.Remark = $"出站条码[{m.DepartureBarCode}]解析出站MES分档数据异常,分档NG"; - LogManagerControl.AddLog("解析出站MES分档数据异常:" + ex.Message, LogAddtype.local, Logtype.Error); - } - - } - else - { - listResult[i] = 80;//不开启分档 - } - // - } - //NG - if (m.Result.IndexOf("NG") >= 0 && !isOkGrading) - { - if (IsStartNGFL) - { - listResult[i] = 99; - m.Result = "NG不分类"; - m.Remark = $"出站条码[{m.DepartureBarCode}],出站NG不分类"; - } - else - { - var NgOkChannelNo = 0; - var NgOkChannelValue = ""; - var indexFD = strNgBound.ToList().FindIndex(x => x == m.Result); - var smAndFdNg = false; - if (indexFD >= 0) - { - listResult[i] = (short)indexFD; - // m.Remark = $"出站条码[{m.DepartureBarCode},{m.Result}]"; - // - var smNgGradingSet = NgGradingSet.ToList().FindIndex(x => x == (indexFD+10)); - if(smNgGradingSet >= 0) - { - listResult[i] = (short)(NgGradingSet[smNgGradingSet]); - smAndFdNg = true; - NgOkChannelNo = smNgGradingSet; - m.Remark = $"出站条码[{m.DepartureBarCode},{m.Result},通道[{NgOkChannelNo + 5}]出站NG拉带值{listResult[i]},MES获取等级{levelresult}"; - } - } - if(!smAndFdNg) - { - var NgGrading1 = lstError.FindIndex(x => x == NgGradingSet[0]); - var NgGrading2 = lstError.FindIndex(x => x == NgGradingSet[1]); - var NgGrading3 = lstError.FindIndex(x => x == NgGradingSet[2]); - - if (NgGrading1 >= 0) - { - listResult[i] = (short)(NgGradingSet[0]); - NgOkChannelNo = 0; - } - else if (NgGrading2 >= 0) - { - listResult[i] = (short)(NgGradingSet[1]); - NgOkChannelNo = 1; - } - else if (NgGrading3 >= 0) - { - listResult[i] = (short)(NgGradingSet[2]); - NgOkChannelNo = 2; - } - else - { - var indexQT = strNgBound.ToList().FindIndex(x => x == "其他"); - var smNgGradingSet = NgGradingSet.ToList().FindIndex(x => x == (indexQT+10)); - if (smNgGradingSet >= 0) - { - listResult[i] = NgGradingSet[smNgGradingSet]; - NgOkChannelNo = smNgGradingSet; - } - else - { - listResult[i] = 88; - } - - } - m.Remark = $"出站条码[{m.DepartureBarCode}],NG,通道[{NgOkChannelNo + 5}]出站NG拉带值{listResult[i]},MES获取等级{levelresult}"; - } - } - } - - list.Add(m); - //电芯判断结果返回PLC - omronPLCCom.lstMcUI[0].WriteDReg("W302" + i.ToString(), listResult[i]); - } + var list = ProcessOutgoingBlankingData(resByte); //复位PLC信号 omronPLCCom.lstMcUI[0].ClearReg(omronPLCCom.lstMcUI[0].lstTrgUI[1].TrgParams.TriggerAddr, VarType.Short); sw.Stop(); @@ -2406,6 +2303,475 @@ namespace JY.Inspection } } + #region 出站数据处理 - 辅助方法 + + /// + /// 处理出站(下料)数据的主入口 + /// + private List ProcessOutgoingBlankingData(OperateResult resByte) + { + var list = new List(); + + // 1. 初始化数据容器 + var containers = InitializeOutgoingContainers(); + var isCCDMask = omronPLCCom.lstMcUI[0].ReadshortDReg("W260"); + + // 2. 解析PLC字节数据到容器 + ParsePlcOutgoingData(resByte.Content, containers); + + // 3. 获取FeedingData服务 + var service = (FeedingDataService)IocConfig.Provider.GetService(); + + // 4. 逐个处理每个通道的出站数据 + for (int i = 0; i < containers.ListBarOut.Count; i++) + { + var item = ProcessSingleOutgoingItem(i, containers, isCCDMask, service); + list.Add(item.Data); + + // 5. 结果写回PLC + omronPLCCom.lstMcUI[0].WriteDReg("W302" + i, item.ResultCode); + } + + return list; + } + + /// + /// 出站数据容器 - 封装解析过程中使用的集合 + /// + private class OutgoingContainers + { + public List ListBarIn { get; set; } + public List ListBarOut { get; set; } + public List> ListCCDSResult { get; set; } + + public List> ListCCDFResult { get; set; } + + public List> ListCCDIResult { get; set; } + + public List ListResult { get; set; } + } + + /// + /// 初始化出站数据容器 + /// + private OutgoingContainers InitializeOutgoingContainers() + { + return new OutgoingContainers + { + ListBarIn = StrUtil.GetListString(2, "NG"), + ListBarOut = StrUtil.GetListString(2, "NG"), + ListCCDSResult = new List> + { + CollectionUtil.GetListUShort(ConstValue.CCD_SDict.Count), + CollectionUtil.GetListUShort(ConstValue.CCD_SDict.Count), + CollectionUtil.GetListUShort(ConstValue.CCD_SDict.Count) + }, + ListCCDFResult = new List> { + CollectionUtil.GetListFloat(ConstValue.CCD_FDict.Count), + CollectionUtil.GetListFloat(ConstValue.CCD_FDict.Count), + CollectionUtil.GetListFloat(ConstValue.CCD_FDict.Count) + }, + ListCCDIResult = new List> { + CollectionUtil.GetListInt(ConstValue.CCD_IDict.Count), + CollectionUtil.GetListInt(ConstValue.CCD_IDict.Count), + CollectionUtil.GetListInt(ConstValue.CCD_IDict.Count) + }, + ListResult = CollectionUtil.GetListUShort(2) + }; + } + + /// + /// 从PLC原始字节中解析出站条码、CCD结果等数据 + /// + private void ParsePlcOutgoingData(byte[] content, OutgoingContainers containers) + { + var bytes = content.ByteReverse(); + + for (int i = 0; i < 2; i++) + { + // 出站条码: 偏移0, 每通道40字节(20字符) + containers.ListBarOut[i] = TransformBase.TransString( + bytes, 0 + (i * 40 * 2), 20 * 2, System.Text.Encoding.ASCII) + .Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim(); + + var lstBarResult = containers.ListCCDSResult[i]; + + // OK/NG结果: 3400-3415, 每通道偏移100字节/3450-3465 + for (int j = 0; j < ConstValue.CCD_SDict.Count; j++) + { + int index = 390 * 2 + (i * 50 * 2) + j * 2; + lstBarResult[j] = (short)TransformBase.TransInt16(content, index); + } + + // 浮点型结果: 3500起/3550 + for (int k = 0; k < ConstValue.CCD_FDict.Count; k++) + { + int index = 490 * 2 + (i * 50 * 2) + k * 2 * 2; + containers.ListCCDFResult[i][k] = TransformBase.TransSingle(content, index); + } + + // 整型结果: 3600起/3650 + for (int k = 0; k < ConstValue.CCD_IDict.Count; k++) + { + int index = 590 * 2 + (i * 50 * 2) + k * 2; + containers.ListCCDIResult[i][k] = TransformBase.TransInt16(content, index); + } + + // 进站条码: 偏移280(140*2), 每通道40字节 + containers.ListBarIn[i] = TransformBase.TransString( + bytes, 140 * 2 + (i * 20 * 2), 20 * 2, System.Text.Encoding.ASCII) + .Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim(); + } + } + + /// + /// 单个出站数据处理结果 + /// + private class OutgoingItemResult + { + public BlankingData Data { get; set; } + public short ResultCode { get; set; } + } + + /// + /// 处理单个通道的出站数据:构建实体 → 判断结果 → 分档 → 返回 + /// + private OutgoingItemResult ProcessSingleOutgoingItem(int index, OutgoingContainers containers, short isCCDMask, FeedingDataService service) + { + // 1. 构建实体 + var m = BuildBlankingEntity(index, containers, service); + + // 2. 映射CCD结果到实体属性 + MapCcdResultsToEntity(m, containers, index); + + // 3. 判断扫码和CCD结果 + string strErr = ""; + var lstError = new List(); + containers.ListResult[index] = GetResult(m, ref strErr, ref lstError); + + m.Result = containers.ListResult[index] == 1 ? "OK" : "NG"; + m.Remark = strErr; + + // 4. 判断扫码NG与CCD NG + var ccdOkNg = "OK"; + if (containers.ListResult[index] == 2 || containers.ListResult[index] == 3) + { + m.Result = "扫码NG"; + } + else if (containers.ListResult[index] == 4) + { + ccdOkNg = "NG"; + m.Result = "CCD结果NG"; + } + + // 5. OK路径: MES分档(仅当扫码OK或CCD NG时触发) + bool isOkGrading = false; + string levelresult = null; + short result = containers.ListResult[index]; + if (containers.ListResult[index] == 1 || ccdOkNg == "NG") + { + HandleOkPathGrading(m, ref result, ref isOkGrading, ref levelresult, isCCDMask, ccdOkNg); + containers.ListResult[index] = result; + } + + // 6. NG路径: 拉带分档 + if (m.Result.IndexOf("NG") >= 0 && !isOkGrading) + { + HandleNgPathGrading(m, ref result, lstError, levelresult); + containers.ListResult[index] = result; + } + + return new OutgoingItemResult { Data = m, ResultCode = containers.ListResult[index] }; + } + + /// + /// 构建BlankingData实体,填充基础字段和TDGroup + /// + private BlankingData BuildBlankingEntity(int index, OutgoingContainers containers, FeedingDataService service) + { + No = No + 1; + var m = new BlankingData + { + TD = No, + WorkShift = ClassShift == 0 ? "白班" : "夜班", + ArrivalBarCode = containers.ListBarIn[index], + DepartureBarCode = containers.ListBarOut[index], + OutTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + }; + + // 通过进站条码查询TDGroup + var listEntity = service.GetFeedingData(m.ArrivalBarCode); + if (listEntity.Count() > 0) + { + m.TDGroup = listEntity.First().TDGroup; + } + + // 处理空条码 + if (string.IsNullOrEmpty(m.ArrivalBarCode) || m.ArrivalBarCode.Trim() == "ERROR") + m.ArrivalBarCode = "ERROR" + Guid.NewGuid().ToString("N").Substring(0, 8); + if (string.IsNullOrEmpty(m.DepartureBarCode) || m.DepartureBarCode.Trim() == "ERROR") + m.DepartureBarCode = "ERROR" + Guid.NewGuid().ToString("N").Substring(0, 8); + + return m; + } + + + // 缓存属性信息 + private static readonly Dictionary BlankingDataProps = typeof(BlankingData) + .GetProperties() + .ToDictionary(p => p.Name); + + /// + /// 将CCD原始结果映射到实体的CCD1-CCD16属性(0=OK, 1=NG) + /// + private void MapCcdResultsToEntity(BlankingData m, OutgoingContainers containers, int orderIndex) + { + int index = 0; + foreach (var propName in ConstValue.CCD_SDict.Keys) + { + if (BlankingDataProps.TryGetValue(propName, out var prop)) + { + prop.SetValue(m, containers.ListCCDSResult[orderIndex][index] == 1 ? "NG" : "OK"); + + index++; + } + } + + index = 0; + foreach (var propName in ConstValue.CCD_FDict.Keys) + { + if (BlankingDataProps.TryGetValue(propName, out var prop)) + { + prop.SetValue(m, containers.ListCCDFResult[orderIndex][index]); + } + } + + foreach (var propName in ConstValue.CCD_SDict.Keys) + { + if (BlankingDataProps.TryGetValue(propName, out var prop)) + { + prop.SetValue(m, containers.ListCCDIResult[orderIndex][index]); + } + } + } + + /// + /// OK路径处理:扫码OK或CCD NG时,请求MES分档并判断档位 + /// + private void HandleOkPathGrading(BlankingData m, ref short listResult, ref bool isOkGrading, ref string levelresult, short isCCDMask, string ccdOkNg) + { + if (!Global.systemConfig.isUpMes || !chkCkGrading) + { + listResult = 80; + return; + } + + var resGrading = ToMesData.GetMesIn(m.DepartureBarCode, m.ArrivalBarCode); + + try + { + if (!resGrading.success) + { + if (resGrading.error == 9 || resGrading.error == 99) + { + omronPLCCom.lstMcUI[0].WriteDReg("W249", (short)1); + LogManagerControl.AddLog($"出站条码[{m.DepartureBarCode}]访问MES异常", LogAddtype.local, Logtype.Error); + } + m.Result = "分档NG"; + m.Remark = $"出站条码[{m.DepartureBarCode}]外观检MES分档请求失败,访问MES异常"; + return; + } + + if (resGrading.rows == null || resGrading.rows.Count == 0 || resGrading.rows[0].rank == null) + { + m.Result = "分档NG"; + m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OK分档NG,MES未反馈正确档位"; + return; + } + + var rank = resGrading.rows[0].rank; + + // CCD屏蔽逻辑:检查配置的拉带CCD结果是否符合要求 + ccdOkNg = ValidateCcdGradingMask(isCCDMask, ccdOkNg); + + rank += ccdOkNg; + + // 匹配MES反馈档位与系统配置 + MatchMesRankToGradingSet(m, rank, resGrading, ccdOkNg, isCCDMask, ref listResult, ref isOkGrading); + + levelresult = resGrading.rows[0].level; + } + catch (Exception ex) + { + m.Result = "分档NG"; + m.Remark = $"出站条码[{m.DepartureBarCode}]解析出站MES分档数据异常,分档NG"; + LogManagerControl.AddLog("解析出站MES分档数据异常:" + ex.Message, LogAddtype.local, Logtype.Error); + } + } + + /// + /// 验证CCD屏蔽状态,返回修正后的CCD结果字符串,必要时触发PLC报警 + /// + private string ValidateCcdGradingMask(short isCCDMask, string currentCcdOkNg) + { + var listGradingCCD = new List + { + Global.systemConfig.Grading1, + Global.systemConfig.Grading2, + Global.systemConfig.Grading3, + Global.systemConfig.Grading4 + }; + + if (isCCDMask == 9) + { + // CCD屏蔽开启,使用"不分类" + currentCcdOkNg = "不分类"; + var noClassCount = listGradingCCD.Count(x => x.Contains("不分类")); + if (noClassCount <= 0) + { + omronPLCCom.lstMcUI[0].WriteDReg("W261", (short)2); + } + } + else + { + // 校验至少有一个OK结果 + var okCount = listGradingCCD.Count(x => x.Contains("OK")); + if (okCount <= 0) + { + omronPLCCom.lstMcUI[0].WriteDReg("W261", (short)2); + } + + // 校验NG结果是否都有对应的OK + var ngList = listGradingCCD.Where(x => x.Contains("NG")).Distinct().ToList(); + foreach (var ngItem in ngList) + { + var gradingBase = ngItem.Substring(0, ngItem.Length - 2); + var okIndex = listGradingCCD.IndexOf(gradingBase + "OK"); + if (okIndex < 0) + { + omronPLCCom.lstMcUI[0].WriteDReg("W261", (short)2); + } + } + } + + return currentCcdOkNg; + } + + /// + /// 将MES反馈档位与系统配置的Grading1-4进行匹配 + /// + private void MatchMesRankToGradingSet(BlankingData m, string rank, MesResponse resGrading, string ccdOkNg, short isCCDMask, ref short listResult, ref bool isOkGrading) + { + if (rank.Equals(Global.systemConfig.Grading1)) + { + listResult = MESGradingSet[0]; + m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; + isOkGrading = true; + } + else if (rank.Equals(Global.systemConfig.Grading2)) + { + listResult = MESGradingSet[1]; + m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; + isOkGrading = true; + } + else if (rank.Equals(Global.systemConfig.Grading3)) + { + listResult = MESGradingSet[2]; + m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; + isOkGrading = true; + } + else if (rank.Equals(Global.systemConfig.Grading4)) + { + listResult = MESGradingSet[3]; + m.Remark = $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD结果{ccdOkNg}"; + isOkGrading = true; + } + else + { + m.Result = "分档NG"; + m.Remark = isCCDMask == 9 + ? $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}-CCD屏蔽状态" + : $"出站条码[{m.DepartureBarCode}]外观检OKMES反馈档位:{resGrading.rows[0].rank}与设置档位不匹配NG"; + } + } + + /// + /// NG路径处理:根据NG类型选择对应的拉带档位 + /// + private void HandleNgPathGrading(BlankingData m, ref short listResult, List lstError, string levelresult) + { + if (IsStartNGFL) + { + listResult = 99; + m.Result = "NG不分类"; + m.Remark = $"出站条码[{m.DepartureBarCode}],出站NG不分类"; + return; + } + + // 优先匹配扫码NG对应的拉带档位 + var ngOkChannelNo = 0; + var indexFD = strNgBound.ToList().FindIndex(x => x == m.Result); + var smAndFdNg = false; + + if (indexFD >= 0) + { + listResult = (short)indexFD; + var smNgGradingSet = NgGradingSet.ToList().FindIndex(x => x == (indexFD + 10)); + if (smNgGradingSet >= 0) + { + listResult = NgGradingSet[smNgGradingSet]; + smAndFdNg = true; + ngOkChannelNo = smNgGradingSet; + m.Remark = $"出站条码[{m.DepartureBarCode},{m.Result},通道[{ngOkChannelNo + 5}]出站NG拉带值{listResult},MES获取等级{levelresult}"; + } + } + + // 回退方案:按NG错误类型选择档位 + if (!smAndFdNg) + { + var ngGradingIndices = new[] + { + lstError.FindIndex(x => x == NgGradingSet[0]), + lstError.FindIndex(x => x == NgGradingSet[1]), + lstError.FindIndex(x => x == NgGradingSet[2]) + }; + + if (ngGradingIndices[0] >= 0) + { + listResult = NgGradingSet[0]; + ngOkChannelNo = 0; + } + else if (ngGradingIndices[1] >= 0) + { + listResult = NgGradingSet[1]; + ngOkChannelNo = 1; + } + else if (ngGradingIndices[2] >= 0) + { + listResult = NgGradingSet[2]; + ngOkChannelNo = 2; + } + else + { + var indexQT = strNgBound.ToList().FindIndex(x => x == "其他"); + var smNgGradingSet = NgGradingSet.ToList().FindIndex(x => x == (indexQT + 10)); + if (smNgGradingSet >= 0) + { + listResult = NgGradingSet[smNgGradingSet]; + ngOkChannelNo = smNgGradingSet; + } + else + { + listResult = 88; + } + } + + m.Remark = $"出站条码[{m.DepartureBarCode}],NG,通道[{ngOkChannelNo + 5}]出站NG拉带值{listResult},MES获取等级{levelresult}"; + } + } + + #endregion + /// /// 结果加工参数上传 /// @@ -2559,28 +2925,27 @@ namespace JY.Inspection bBar = false; m.TMDB = bBar ? "OK" : "NG"; - bool[] b0 = new bool[16] { true, true, true, true, true, true, true, true, true, true, true, true, true, true,true,true }; - b0[0] = m.CCD1 == "OK" ? true : false; - b0[1] = m.CCD2 == "OK" ? true : false; - b0[2] = m.CCD3 == "OK" ? true : false; - b0[3] = m.CCD4 == "OK" ? true : false; - b0[4] = m.CCD5 == "OK" ? true : false; - b0[5] = m.CCD6 == "OK" ? true : false; - b0[6] = m.CCD7 == "OK" ? true : false; - b0[7] = m.CCD8 == "OK" ? true : false; - b0[8] = m.CCD9 == "OK" ? true : false; - b0[9] = m.CCD10 == "OK" ? true : false; - b0[10] = m.CCD11 == "OK" ? true : false; - b0[11] = m.CCD12 == "OK" ? true : false; - b0[12] = m.CCD13 == "OK" ? true : false; - b0[13] = m.CCD14 == "OK" ? true : false; - b0[14] = m.CCD15 == "OK" ? true : false; - b0[15] = m.CCD16 == "OK" ? true : false; + // CCD判断 + bool isAllCCD = true; + StringBuilder sb = new StringBuilder(); + foreach (var propName in ConstValue.CCD_SDict.Keys) + { + if (BlankingDataProps.TryGetValue(propName, out var prop)) + { + string result = prop.GetValue(m).ToString(); + + if (result != "OK") + { + isAllCCD = false; + sb.Append($",{ConstValue.CCD_SDict[propName]}不良"); + } + } + } #endregion #region - if ( IsBarOK && bBar && b0[0] && b0[1] && b0[2] && b0[3] && b0[4] && b0[5] && b0[6] && b0[7] && b0[8] && b0[9] && b0[10] && b0[11] && b0[12] && b0[13] && b0[14] && b0[15]) + if (IsBarOK && bBar && isAllCCD) { strErr = "良品"; res = 1; @@ -2605,109 +2970,16 @@ namespace JY.Inspection res = 3; lstError.Add(res); } + if (!isAllCCD) + { + strErr = sb.ToString(); + res = 4; + lstError.Add(res); + } - if (!b0[0]) - { - strErr = "正面(2D/3D)不良"; - res = 11; - lstError.Add(res); - } - if (!b0[1]) - { - strErr = "反面(2D/3D)不良"; - res = 12; - lstError.Add(res); - } - if (!b0[2]) - { - strErr = "左侧面(2D/3D)不良"; - res =13; - lstError.Add(res); - } - if (!b0[3]) - { - strErr = "右侧面(2D/3D)不良"; - res = 14; - lstError.Add(res); - } - if (!b0[4]) - { - strErr = "顶面(2D/3D)不良"; - res = 15; - lstError.Add(res); - } - if (!b0[5]) - { - strErr = "底面(2D/3D)不良"; - res = 16; - lstError.Add(res); - } - if (!b0[6]) - { - strErr = "底WE1不良"; - res = 17; - lstError.Add(res); - } - if (!b0[7]) - { - strErr = "底WE2不良"; - res = 18; - lstError.Add(res); - } - if (!b0[8]) - { - strErr = "底WE3不良"; - res = 19; - lstError.Add(res); - } - if (!b0[9]) - { - strErr = "底WE4不良"; - res = 20; - lstError.Add(res); - } - if (!b0[10]) - { - strErr = "中ME1不良"; - res = 21; - lstError.Add(res); - } - if (!b0[11]) - { - strErr = "中ME2不良"; - res = 22; - lstError.Add(res); - } - if (!b0[12]) - { - strErr = "中ME3不良"; - res = 23; - lstError.Add(res); - } - if (!b0[13]) - { - strErr = "中ME4不良"; - res = 24; - lstError.Add(res); - } - if (!b0[14]) - { - strErr = "极柱(POS/NEG)不良"; - res = 25; - lstError.Add(res); - } - if (!b0[15]) - { - strErr = "防爆阀(PRO)不良"; - res = 26; - lstError.Add(res); - } return 0; #endregion - - - } diff --git a/JY.Inspection/HomeForm.designer.cs b/JY.Inspection/HomeForm.designer.cs index 1ec56a5..03f681a 100644 --- a/JY.Inspection/HomeForm.designer.cs +++ b/JY.Inspection/HomeForm.designer.cs @@ -83,31 +83,6 @@ namespace JY.Inspection this.txtlog = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.dgvDataShow_B = new JY.Inspection.GridViewBuff(); - this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column31 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column26 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column27 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column25 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column13 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column16 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column17 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column18 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column19 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column20 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column21 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column23 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column28 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column29 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column22 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column24 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.dgvDataShow_A = new JY.Inspection.GridViewBuff(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -667,32 +642,6 @@ namespace JY.Inspection this.dgvDataShow_B.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.dgvDataShow_B.ColumnHeadersHeight = 29; this.dgvDataShow_B.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; - this.dgvDataShow_B.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Column6, - this.Column8, - this.Column31, - this.Column26, - this.Column7, - this.Column27, - this.Column25, - this.Column9, - this.Column10, - this.Column11, - this.Column12, - this.Column13, - this.Column14, - this.Column15, - this.Column16, - this.Column17, - this.Column18, - this.Column19, - this.Column20, - this.Column21, - this.Column23, - this.Column28, - this.Column29, - this.Column22, - this.Column24}); dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -726,230 +675,6 @@ namespace JY.Inspection this.dgvDataShow_B.TabIndex = 0; this.dgvDataShow_B.RowPrePaint += new System.Windows.Forms.DataGridViewRowPrePaintEventHandler(this.dgvDataShow_B_RowPrePaint); // - // Column6 - // - this.Column6.DataPropertyName = "TD"; - this.Column6.HeaderText = "序号"; - this.Column6.MinimumWidth = 6; - this.Column6.Name = "Column6"; - this.Column6.ReadOnly = true; - this.Column6.Width = 52; - // - // Column8 - // - this.Column8.DataPropertyName = "WorkShift"; - this.Column8.HeaderText = "班次"; - this.Column8.MinimumWidth = 6; - this.Column8.Name = "Column8"; - this.Column8.ReadOnly = true; - this.Column8.Width = 52; - // - // Column31 - // - this.Column31.DataPropertyName = "TDGroup"; - this.Column31.HeaderText = "主道"; - this.Column31.MinimumWidth = 8; - this.Column31.Name = "Column31"; - this.Column31.ReadOnly = true; - this.Column31.Width = 52; - // - // Column26 - // - this.Column26.DataPropertyName = "ArrivalBarCode"; - this.Column26.HeaderText = "入站条码"; - this.Column26.MinimumWidth = 8; - this.Column26.Name = "Column26"; - this.Column26.ReadOnly = true; - this.Column26.Width = 64; - // - // Column7 - // - this.Column7.DataPropertyName = "DepartureBarCode"; - this.Column7.HeaderText = "出站条码"; - this.Column7.MinimumWidth = 6; - this.Column7.Name = "Column7"; - this.Column7.ReadOnly = true; - this.Column7.Width = 64; - // - // Column27 - // - this.Column27.DataPropertyName = "TMDB"; - this.Column27.HeaderText = "条码对比"; - this.Column27.MinimumWidth = 8; - this.Column27.Name = "Column27"; - this.Column27.ReadOnly = true; - this.Column27.Width = 64; - // - // Column25 - // - this.Column25.DataPropertyName = "OutTime"; - this.Column25.HeaderText = "出站时间"; - this.Column25.MinimumWidth = 6; - this.Column25.Name = "Column25"; - this.Column25.ReadOnly = true; - this.Column25.Width = 64; - // - // Column9 - // - this.Column9.DataPropertyName = "CCD1"; - this.Column9.HeaderText = "正面(2D/3D)"; - this.Column9.MinimumWidth = 6; - this.Column9.Name = "Column9"; - this.Column9.ReadOnly = true; - this.Column9.Width = 86; - // - // Column10 - // - this.Column10.DataPropertyName = "CCD2"; - this.Column10.HeaderText = "反面(2D/3D)"; - this.Column10.MinimumWidth = 6; - this.Column10.Name = "Column10"; - this.Column10.ReadOnly = true; - this.Column10.Width = 86; - // - // Column11 - // - this.Column11.DataPropertyName = "CCD3"; - this.Column11.HeaderText = "左侧面(2D/3D)"; - this.Column11.MinimumWidth = 6; - this.Column11.Name = "Column11"; - this.Column11.ReadOnly = true; - this.Column11.Width = 98; - // - // Column12 - // - this.Column12.DataPropertyName = "CCD4"; - this.Column12.HeaderText = "右侧面(2D/3D)"; - this.Column12.MinimumWidth = 6; - this.Column12.Name = "Column12"; - this.Column12.ReadOnly = true; - this.Column12.Width = 98; - // - // Column13 - // - this.Column13.DataPropertyName = "CCD5"; - this.Column13.HeaderText = "顶面(2D/3D)"; - this.Column13.MinimumWidth = 6; - this.Column13.Name = "Column13"; - this.Column13.ReadOnly = true; - this.Column13.Width = 86; - // - // Column14 - // - this.Column14.DataPropertyName = "CCD6"; - this.Column14.HeaderText = "底面(2D/3D)"; - this.Column14.MinimumWidth = 6; - this.Column14.Name = "Column14"; - this.Column14.ReadOnly = true; - this.Column14.Width = 86; - // - // Column15 - // - this.Column15.DataPropertyName = "CCD7"; - this.Column15.HeaderText = "底棱边WE1"; - this.Column15.MinimumWidth = 6; - this.Column15.Name = "Column15"; - this.Column15.ReadOnly = true; - this.Column15.Width = 85; - // - // Column16 - // - this.Column16.DataPropertyName = "CCD8"; - this.Column16.HeaderText = "底棱边WE2"; - this.Column16.MinimumWidth = 6; - this.Column16.Name = "Column16"; - this.Column16.ReadOnly = true; - this.Column16.Width = 85; - // - // Column17 - // - this.Column17.DataPropertyName = "CCD9"; - this.Column17.HeaderText = "底棱边WE3"; - this.Column17.MinimumWidth = 6; - this.Column17.Name = "Column17"; - this.Column17.ReadOnly = true; - this.Column17.Width = 85; - // - // Column18 - // - this.Column18.DataPropertyName = "CCD10"; - this.Column18.HeaderText = "底棱边WE4"; - this.Column18.MinimumWidth = 6; - this.Column18.Name = "Column18"; - this.Column18.ReadOnly = true; - this.Column18.Width = 85; - // - // Column19 - // - this.Column19.DataPropertyName = "CCD11"; - this.Column19.HeaderText = "中棱边ME1"; - this.Column19.MinimumWidth = 6; - this.Column19.Name = "Column19"; - this.Column19.ReadOnly = true; - this.Column19.Width = 84; - // - // Column20 - // - this.Column20.DataPropertyName = "CCD12"; - this.Column20.HeaderText = "中棱边ME2"; - this.Column20.MinimumWidth = 6; - this.Column20.Name = "Column20"; - this.Column20.ReadOnly = true; - this.Column20.Width = 84; - // - // Column21 - // - this.Column21.DataPropertyName = "CCD13"; - this.Column21.HeaderText = "中棱边ME3"; - this.Column21.MinimumWidth = 6; - this.Column21.Name = "Column21"; - this.Column21.ReadOnly = true; - this.Column21.Width = 84; - // - // Column23 - // - this.Column23.DataPropertyName = "CCD14"; - this.Column23.HeaderText = "中棱边ME4"; - this.Column23.MinimumWidth = 6; - this.Column23.Name = "Column23"; - this.Column23.ReadOnly = true; - this.Column23.Width = 84; - // - // Column28 - // - this.Column28.DataPropertyName = "CCD15"; - this.Column28.HeaderText = "极柱(POS/NEG)"; - this.Column28.MinimumWidth = 8; - this.Column28.Name = "Column28"; - this.Column28.ReadOnly = true; - // - // Column29 - // - this.Column29.DataPropertyName = "CCD16"; - this.Column29.HeaderText = "防爆阀(PRO)"; - this.Column29.MinimumWidth = 8; - this.Column29.Name = "Column29"; - this.Column29.ReadOnly = true; - this.Column29.Width = 89; - // - // Column22 - // - this.Column22.DataPropertyName = "Result"; - this.Column22.HeaderText = "综合结果"; - this.Column22.MinimumWidth = 6; - this.Column22.Name = "Column22"; - this.Column22.ReadOnly = true; - this.Column22.Width = 64; - // - // Column24 - // - this.Column24.DataPropertyName = "Remark"; - this.Column24.HeaderText = "备注"; - this.Column24.MinimumWidth = 6; - this.Column24.Name = "Column24"; - this.Column24.ReadOnly = true; - this.Column24.Width = 52; - // // groupBox2 // this.groupBox2.Controls.Add(this.dgvDataShow_A); @@ -2415,32 +2140,8 @@ namespace JY.Inspection private System.Windows.Forms.DataGridViewTextBoxColumn Column2; private System.Windows.Forms.DataGridViewTextBoxColumn Column3; private System.Windows.Forms.DataGridViewTextBoxColumn Column4; - private System.Windows.Forms.DataGridViewTextBoxColumn Column5; - private System.Windows.Forms.DataGridViewTextBoxColumn Column6; - private System.Windows.Forms.DataGridViewTextBoxColumn Column8; - private System.Windows.Forms.DataGridViewTextBoxColumn Column31; - private System.Windows.Forms.DataGridViewTextBoxColumn Column26; - private System.Windows.Forms.DataGridViewTextBoxColumn Column7; - private System.Windows.Forms.DataGridViewTextBoxColumn Column27; - private System.Windows.Forms.DataGridViewTextBoxColumn Column25; - private System.Windows.Forms.DataGridViewTextBoxColumn Column9; - private System.Windows.Forms.DataGridViewTextBoxColumn Column10; - private System.Windows.Forms.DataGridViewTextBoxColumn Column11; - private System.Windows.Forms.DataGridViewTextBoxColumn Column12; - private System.Windows.Forms.DataGridViewTextBoxColumn Column13; - private System.Windows.Forms.DataGridViewTextBoxColumn Column14; - private System.Windows.Forms.DataGridViewTextBoxColumn Column15; - private System.Windows.Forms.DataGridViewTextBoxColumn Column16; - private System.Windows.Forms.DataGridViewTextBoxColumn Column17; - private System.Windows.Forms.DataGridViewTextBoxColumn Column18; - private System.Windows.Forms.DataGridViewTextBoxColumn Column19; - private System.Windows.Forms.DataGridViewTextBoxColumn Column20; - private System.Windows.Forms.DataGridViewTextBoxColumn Column21; - private System.Windows.Forms.DataGridViewTextBoxColumn Column23; - private System.Windows.Forms.DataGridViewTextBoxColumn Column28; - private System.Windows.Forms.DataGridViewTextBoxColumn Column29; - private System.Windows.Forms.DataGridViewTextBoxColumn Column22; - private System.Windows.Forms.DataGridViewTextBoxColumn Column24; + private System.Windows.Forms.DataGridViewTextBoxColumn Column5; + private System.Windows.Forms.TextBox txtTensionStrapCCD1; private MetroFramework.Controls.MetroLabel metroLabel5; private System.Windows.Forms.TextBox txtTensionStrapCCD4; diff --git a/JY.Inspection/JY.Inspection.csproj b/JY.Inspection/JY.Inspection.csproj index d79d98f..6527327 100644 --- a/JY.Inspection/JY.Inspection.csproj +++ b/JY.Inspection/JY.Inspection.csproj @@ -194,6 +194,7 @@ + Form diff --git a/JY.Model/DB.Entity/BlankingData.cs b/JY.Model/DB.Entity/BlankingData.cs index 2401067..7782549 100644 --- a/JY.Model/DB.Entity/BlankingData.cs +++ b/JY.Model/DB.Entity/BlankingData.cs @@ -160,6 +160,29 @@ namespace JY.Model [Name("防爆阀(PRO)结果1")] [SugarColumn(ColumnName = "CCD16")] public string CCD16 { set; get; } + + #region CCD浮点数结果 + public float CCDF1 { get; set; } + + public float CCDF2 { get; set; } + + public float CCDF3 { get; set; } + #endregion + + #region CCD整数结果 + public int CCDI1 { get; set; } + + public int CCDI2 { get; set; } + + public int CCDI3 { get; set; } + + public string CCDI4 { get; set; } + + public string CCDI5 { get; set; } + + public string CCDI6 { get; set; } + #endregion + /// /// 综合结果 /// diff --git a/replace_method.py b/replace_method.py new file mode 100644 index 0000000..f2a79e1 --- /dev/null +++ b/replace_method.py @@ -0,0 +1,196 @@ +import re + +file_path = r'd:\CodeProject\1440\JY.Inspection\HomeForm.cs' + +with open(file_path, 'r', encoding='utf-8-sig') as f: + content = f.read() + +# Define the old method block (from doc comment to closing brace) +old_pattern = r''' /// + /// 结果判断 + /// + /// + /// + /// + private short GetResult\(BlankingData m, ref string strErr,ref List lstError\) + \{ + short res = 0; + + strErr = ""; + #region 判断各项参数 + //入站条码判断 + bool IsBarInOK = !m\.ArrivalBarCode\.Contains\("ERROR"\); + //出站条码判断 + bool IsBarOK = !m\.DepartureBarCode\.Contains\("ERROR"\); + //判断条码是否一致 + bool bBar = true; + if \(m\.ArrivalBarCode\.Trim\(\) != m\.DepartureBarCode\.Trim\(\)\) + bBar = false; + m\.TMDB = bBar \? "OK" : "NG"; + + // CCD判断 + bool isAllCCD = true; + foreach \(var propName in ConstValue\.CCD_SDict\.Keys\) + \{ + if \(BlankingDataProps\.TryGetValue\(propName, out var prop\)\) + \{ + string result = prop\.GetValue\(m\)\.ToString\(\); + + if \(result != "OK"\) + \{ + isAllCCD = false; + \} + \} + \} + + bool\[\] b0 = new bool\[16\] \{ true, true, true, true, true, true, true, true, true, true, true, true, true, true,true,true \}; + b0\[0\] = m\.CCD1 == "OK" \? true : false; + b0\[1\] = m\.CCD2 == "OK" \? true : false; + b0\[2\] = m\.CCD3 == "OK" \? true : false; + b0\[3\] = m\.CCD4 == "OK" \? true : false; + b0\[4\] = m\.CCD5 == "OK" \? true : false; + b0\[5\] = m\.CCD6 == "OK" \? true : false; + b0\[6\] = m\.CCD7 == "OK" \? true : false; + b0\[7\] = m\.CCD8 == "OK" \? true : false; + b0\[8\] = m\.CCD9 == "OK" \? true : false; + b0\[9\] = m\.CCD10 == "OK" \? true : false; + b0\[10\] = m\.CCD11 == "OK" \? true : false; + b0\[11\] = m\.CCD12 == "OK" \? true : false; + b0\[12\] = m\.CCD13 == "OK" \? true : false; + b0\[13\] = m\.CCD14 == "OK" \? true : false; + b0\[14\] = m\.CCD15 == "OK" \? true : false; + b0\[15\] = m\.CCD16 == "OK" \? true : false; + #endregion + + + #region + if \( IsBarOK && bBar && b0\[0\] && b0\[1\] && b0\[2\] && b0\[3\] && b0\[4\] && b0\[5\] && b0\[6\] && b0\[7\] && b0\[8\] && b0\[9\] && b0\[10\] && b0\[11\] && b0\[12\] && b0\[13\] && b0\[14\] && b0\[15\]\) + \{ + strErr = "良品"; + res = 1; + lstError\.Add\(res\); + return 1; + \}.*?return 0; + + #endregion + + + + \}''' + +new_method = ''' /// + /// 检验结果错误类型 + /// + private enum InspectionErrorType + { + ScanError, + BarcodeMismatch, + CcdError + } + + /// + /// 检验错误项 + /// + private class InspectionError + { + public InspectionErrorType Type { get; set; } + public string Description { get; set; } + } + + /// + /// CCD检测项名称(索引0-15对应CCD1-CCD16) + /// + private static readonly string[] CcdDefectNames = { + "正面(2D/3D)不良", "反面(2D/3D)不良", "左侧面(2D/3D)不良", "右侧面(2D/3D)不良", + "顶面(2D/3D)不良", "底面(2D/3D)不良", "底WE1不良", "底WE2不良", + "底WE3不良", "底WE4不良", "中ME1不良", "中ME2不良", + "中ME3不良", "中ME4不良", "极柱(POS/NEG)不良", "防爆阀(PRO)不良" + }; + + /// + /// 结果判断:检查条码和CCD结果,返回错误列表(空列表=良品) + /// + /// 出站数据实体 + /// 错误列表,空列表表示良品 + private List GetResult(BlankingData m, ref string strErr) + { + var errors = new List(); + strErr = ""; + + // 1. 条码检查 + bool isBarOK = !m.DepartureBarCode.Contains("ERROR"); + bool isBarcodeMatch = m.ArrivalBarCode.Trim() == m.DepartureBarCode.Trim(); + m.TMDB = isBarcodeMatch ? "OK" : "NG"; + + // 2. CCD结果检查 + var ccdValues = new[] { + m.CCD1, m.CCD2, m.CCD3, m.CCD4, m.CCD5, m.CCD6, m.CCD7, m.CCD8, + m.CCD9, m.CCD10, m.CCD11, m.CCD12, m.CCD13, m.CCD14, m.CCD15, m.CCD16 + }; + bool allCcdOk = Array.TrueForAll(ccdValues, v => v == "OK"); + + // 3. 全部通过 = 良品 + if (isBarOK && isBarcodeMatch && allCcdOk) + { + strErr = "良品"; + return errors; + } + + // 4. 分类收集错误 + if (!isBarOK) + { + errors.Add(new InspectionError + { + Type = InspectionErrorType.ScanError, + Description = $"出站扫码不良,出站条码:{m.DepartureBarCode}" + }); + } + + if (!isBarcodeMatch) + { + errors.Add(new InspectionError + { + Type = InspectionErrorType.BarcodeMismatch, + Description = "入站与出站条码不一致" + }); + } + + for (int i = 0; i < ccdValues.Length; i++) + { + if (ccdValues[i] != "OK") + { + errors.Add(new InspectionError + { + Type = InspectionErrorType.CcdError, + Description = CcdDefectNames[i] + }); + } + } + + strErr = string.Join(";", errors.Select(e => e.Description)); + return errors; + }''' + +# Use DOTALL to match across lines +new_content = re.sub(old_pattern, new_method, content, flags=re.DOTALL) + +if new_content == content: + print("ERROR: Pattern not found!") + # Try to find partial matches + if '结果判断' in content: + print("Found '结果判断' in content") + if 'private short GetResult' in content: + print("Found 'private short GetResult' in content") + if '防爆阀(PRO)不良' in content: + print("Found '防爆阀(PRO)不良' in content") + # Check for the exact method signature + idx = content.find('private short GetResult') + if idx >= 0: + print(f"Found at index {idx}") + print(f"Context: {repr(content[idx:idx+100])}") +else: + with open(file_path, 'w', encoding='utf-8-sig') as f: + f.write(new_content) + print("SUCCESS: Method replaced!") + print(f"Old content length: {len(content)}") + print(f"New content length: {len(new_content)}")