M182轴承端盖外观缺陷AOI
kingno
2025-05-26 5a405c7dce20d8c79a733c9c786cc42eb59fe81c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using Bro.M141.Process;
using Bro.UI.Model.Winform;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.Util;
using Org.BouncyCastle.Asn1.X509;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Bro.Common.Helper.EnumHelper;
using static NPOI.HSSF.Util.HSSFColor;
using static System.Windows.Forms.AxHost;
 
namespace Bro.M135.Process.UI
{
    //[MenuNode("点检", "点检", 2, TopMenu.SystemInfo, MenuNodeType.Form)]
    public partial class SpotCheck : MenuFormBase
    {
        M141Process prM141Process => Process as M141Process;
        public SpotCheck()
        {
            InitializeComponent();
        }
        private void initGrid(List<Produre> DataModelList)
        {
            M141Config eM141Config = prM141Process.Config as M141Config;
            double CheckInfo = 0.1;// eM141Config.Check;
 
            //var SpectList = eM141Config.GetSpecList();
            foreach (Produre produre in DataModelList)
            {
                produre.CheckValue = "OK";
                foreach (var item in produre.Value)
                {
                    if (!double.TryParse(item.Value, out double Number1))
                    {
                        if (item.Value != item.ProValue)
                        {
                            produre.CheckValue = "NG";
                            break;
                        }
                    }
                    else
                    {
 
                        //var spc = SpectList.FirstOrDefault(ss => ss.Code == item.Name);
                        double standardVlaue = double.Parse(item.Value);
                        if (item.ProValue != null)
                        {
                            if (Math.Abs(double.Parse(item.ProValue) - standardVlaue) / standardVlaue < CheckInfo)
                            {
                                produre.CheckValue = "OK";
                                break;
                            }
                            else
                            {
                                produre.CheckValue = "NG";
                                break;
                            }
                        }
                        else
                        {
                            if (item.ProValue == null)
                            {
                                rTLog.AppendText("生产数据中无" + item.Name + "列\r\n");
                            }
                        }
                    }
                }
            }
            Produre Fristprodure = DataModelList.FirstOrDefault();
            grid.Redim(DataModelList.Count() + 2, Fristprodure.Value.Count() * 2 + 3);
            SourceGrid.Cells.Views.Cell titleModel = new SourceGrid.Cells.Views.Cell();
            titleModel.BackColor = Color.SteelBlue;
            titleModel.ForeColor = Color.White;
            titleModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
            SourceGrid.Cells.Views.Cell captionModel = new SourceGrid.Cells.Views.Cell();
            captionModel.BackColor = grid.BackColor;
            int currentRow = 0;
 
            grid[currentRow, 2] = new SourceGrid.Cells.Cell("标准值");
            grid[currentRow, 2].View = captionModel;
            grid[currentRow, 2].ColumnSpan = Fristprodure.Value.Count();
 
 
            grid[currentRow, Fristprodure.Value.Count() + 2] = new SourceGrid.Cells.Cell("检测值");
            grid[currentRow, Fristprodure.Value.Count() + 2].View = captionModel;
            grid[currentRow, Fristprodure.Value.Count() + 2].ColumnSpan = Fristprodure.Value.Count();
 
            currentRow = 1;
            grid[currentRow, 2 * Fristprodure.Value.Count() + 2] = new SourceGrid.Cells.Cell("点检结果");
            grid[currentRow, 2 * Fristprodure.Value.Count() + 2].View = captionModel;
 
 
 
            grid[currentRow, 0] = new SourceGrid.Cells.Cell("时间");
            grid[currentRow, 0].View = titleModel;
            grid[currentRow, 1] = new SourceGrid.Cells.Cell("条码");
            grid[currentRow, 1].View = titleModel;
 
            int CloumnIndex = 2;
 
 
            if (Fristprodure != null)
            {
                var ListModel = Fristprodure.Value;
                foreach (var item in ListModel)
                {
                    grid[currentRow, CloumnIndex] = new SourceGrid.Cells.Cell(item.Name);
                    grid[currentRow, CloumnIndex].View = titleModel;
                    CloumnIndex++;
                }
                foreach (var item in ListModel)
                {
                    grid[currentRow, CloumnIndex] = new SourceGrid.Cells.Cell(item.Name);
                    grid[currentRow, CloumnIndex].View = titleModel;
                    CloumnIndex++;
                }
            }
 
            foreach (Produre eProdure in DataModelList)
            {
                currentRow++;
 
                grid[currentRow, 0] = new SourceGrid.Cells.Cell(eProdure.DateTime);
                grid[currentRow, 0].View = captionModel;
 
                grid[currentRow, 1] = new SourceGrid.Cells.Cell(eProdure.Code);
                grid[currentRow, 1].View = captionModel;
                int CloumnIndexinfo = 2;
                foreach (var item in eProdure.Value)
                {
                    grid[currentRow, CloumnIndexinfo] = new SourceGrid.Cells.Cell(item.Value);
                    grid[currentRow, CloumnIndexinfo].View = captionModel;
                    CloumnIndexinfo++;
                }
                foreach (var item in eProdure.Value)
                {
                    grid[currentRow, CloumnIndexinfo] = new SourceGrid.Cells.Cell(item.ProValue);
                    grid[currentRow, CloumnIndexinfo].View = captionModel;
                    CloumnIndexinfo++;
                }
 
                grid[currentRow, CloumnIndexinfo] = new SourceGrid.Cells.Cell(eProdure.CheckValue);
                grid[currentRow, CloumnIndexinfo].View = captionModel;
            }
            grid.AutoSizeCells();
            grid.AutoStretchColumnsToFitWidth = true;
            grid.Columns.StretchToFit();
 
        }
        private void btLoadprodure_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.tbProdure.Text = dialog.FileName;
            }
 
        }
 
        private void btLoadTmp_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.tbCheck.Text = dialog.FileName;
            }
        }
 
        private void BtCompensate_Click(object sender, EventArgs e)
        {
            List<Produre> DataModelList = new List<Produre>();
            int proNumber = 0;
            using (var stream = File.OpenRead(tbCheck.Text))
            {
                IWorkbook FileIWorkbook = WorkbookFactory.Create(stream);
                ISheet eISheet = FileIWorkbook.GetSheetAt(0);
 
                int rowCount = eISheet.LastRowNum;
                int fristrowindex = 1;
                IRow fristrow = eISheet.GetRow(fristrowindex);
                for (int i = 2; i < rowCount; i++)
                {
                    IRow Row = eISheet.GetRow(i);
 
                    if (Row != null)
                    {
                        Produre eProdure = new Produre();
                        eProdure.DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:MM:SS");
                        if (Row.GetCell(1).CellType == CellType.Numeric)
                        {
                            eProdure.Code = Row.GetCell(1).NumericCellValue.ToString();
                        }
                        else
                        {
                            eProdure.Code = Row.GetCell(1).StringCellValue;
                        }
                        if (!string.IsNullOrEmpty(eProdure.Code))
                        {
                            List<Module> eModuleList = new List<Module>();
                            for (int cloumn = 2; cloumn < Row.Count(); cloumn++)
                            {
                                Module eModule = new Module();
 
                                eModule.Name = fristrow.GetCell(cloumn).StringCellValue;
 
                                if (!eModule.Name.Contains("FAI"))
                                {
                                    eModule.ProValue = "OK";
                                }
                                if (Row.GetCell(cloumn).CellType == CellType.Numeric)
                                {
                                    eModule.Value = Row.GetCell(cloumn).NumericCellValue.ToString();
                                }
                                else
                                {
                                    eModule.Value = Row.GetCell(cloumn).StringCellValue.ToString();
                                }
                                if (eModuleList.FirstOrDefault(x => x.Name == eModule.Name) == null)
                                {
 
                                    eModuleList.Add(eModule);
                                }
                            }
                            eProdure.Value = eModuleList;
                            DataModelList.Add(eProdure);
                        }
 
                    }
 
                }
                if (File.Exists(tbProdure.Text))
                {
                    proNumber = DataModelList.Count();
                    string[] ProData = File.ReadAllLines(tbProdure.Text);
                    if (proNumber > ProData.Count())
                    {
                        rTLog.AppendText("生产数据小于模板数据");
                        return;
                    }
                    int StratProRowIndex = ProData.Count() - proNumber;
                    int Rowid = 0;
                    string[] Head = ProData[0].Split(',');
                    int i = 0;
                    for (int End = StratProRowIndex; End < ProData.Count(); End++)
                    {
                        string[] proData = ProData[End].Split(',');
                        string Code = proData[1];
                        var ModelInfo = DataModelList.Get(i);
                        i++;
                        for (int ProInde = 3; ProInde < proData.Length - 1; ProInde++)
                        {
                            var ModelVar = ModelInfo.Value.FirstOrDefault(model => model.Name == Head[ProInde]);
                            if (ModelVar != null)
                            {
                                ModelVar.ProValue = proData[ProInde];
                            }
                            else
                            {
                                rTLog.AppendText("生产数据中无" + Head[ProInde] + "列\r\n");
                            }
 
                        }
 
                    }
                }
                initGrid(DataModelList);
            }
        }
 
        private void btLoadFilePath_Click(object sender, EventArgs e)
        {
            M141Config eM141Config = prM141Process.Config as M141Config;
            if (eM141Config.TmpPath != null)
                tbCheck.Text = eM141Config.TmpPath;
 
            string YYYYMMDD = DateTime.Now.ToString("yyyyMMdd");
            string filepath = eM141Config.LogPath + "\\" + YYYYMMDD + "\\ProductRecord_" + YYYYMMDD + ".csv";
            if (File.Exists(filepath))
            {
                this.tbProdure.Text = filepath;
            }
        }
 
        private void btExport_Click(object sender, EventArgs e)
        {
            FileSave.ShowDialog(this);
            string l_Path = FileSave.FileName;
            if (!string.IsNullOrEmpty(l_Path))
            {
                try
                {
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(l_Path, false, System.Text.Encoding.Default))
                    {
                        SourceGrid.Exporter.CSV csv = new SourceGrid.Exporter.CSV();
                        csv.Export(grid, writer);
                        writer.Close();
                    }
 
                    DevAge.Shell.Utilities.OpenFile(l_Path);
                }
                catch (Exception err)
                {
                    DevAge.Windows.Forms.ErrorDialog.Show(this, err, "CSV Export Error");
                }
            }
 
        }
    }
    public class Produre
    {
        public string Code { get; set; }
        public string DateTime { get; set; }
        public List<Module> Value { get; set; }
 
        public string CheckValue { get; set; }
    }
    public class Module
    {
        public string Name { get; set; }
        public string Value { get; set; }
 
        public string ProValue { get; set; }
    }
}