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 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 DataModelList = new List(); 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 eModuleList = new List(); 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 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; } } }