| | |
| | | using Bro.Process; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | |
| | | //Excel报表输出 (单个产品的excel导出) |
| | | ExportProductionExcel(measurementUnitResultAndKeyUnitDataSet); |
| | | |
| | | ExportProductionInColumns(measurementUnitResultAndKeyUnitDataSet); |
| | | ////数据库保存 |
| | | //SaveProductionData(measurementUnitResultAndKeyUnitDataSet); |
| | | |
| | |
| | | }); |
| | | } |
| | | |
| | | static object excelExportLock = new object(); |
| | | private async void ExportProductionInColumns(ProductionMeasurementUnitResultAndKeyUnitDataSet exportData) |
| | | { |
| | | if (!Config.IsCSVOutputEnabled) |
| | | return; |
| | | |
| | | await Task.Run(() => |
| | | { |
| | | if (!Directory.Exists(Config.LogPath)) |
| | | { |
| | | Directory.CreateDirectory(Config.LogPath); |
| | | } |
| | | var fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd")}.xlsx"); |
| | | bool isExisted = File.Exists(fileName); |
| | | using (ExcelPackage package = new ExcelPackage(new FileInfo(fileName))) |
| | | { |
| | | ExcelWorksheet rawDataSheet = null; |
| | | ExcelWorksheet slantSheet = null; |
| | | ExcelWorksheet alignmentSheet = null; |
| | | ExcelWorksheet rowAlignmentSheet = null; |
| | | if (!isExisted) |
| | | { |
| | | package.Workbook.Worksheets.Add("RawData"); |
| | | rawDataSheet = package.Workbook.Worksheets["RawData"]; |
| | | for (int i = 0; i < Config.KeyNameCollection.Count; i++) |
| | | { |
| | | var cell = rawDataSheet.Cells[i + 3, 1]; |
| | | cell.Value = Config.KeyNameCollection[i]; |
| | | cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(31, 73, 125)); |
| | | } |
| | | |
| | | //package.Workbook.Worksheets.Add("Slant"); |
| | | //slantSheet = package.Workbook.Worksheets["Slant"]; |
| | | //for(int i=0;i<exportData.MeasurementUnitResultList) |
| | | //package.Workbook.Worksheets.Add("Alignment"); |
| | | //package.Workbook.Worksheets.Add("RowAlignment"); |
| | | } |
| | | |
| | | rawDataSheet = package.Workbook.Worksheets["RawData"]; |
| | | |
| | | int rowDataStartCol = rawDataSheet.Dimension.Columns; |
| | | var barcodeCell = rawDataSheet.Cells[1, rowDataStartCol + 1, 1, rowDataStartCol + 1 + 4]; |
| | | barcodeCell.Merge = true; |
| | | barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode; |
| | | |
| | | var z1Cell = rawDataSheet.Cells[2, rowDataStartCol + 1]; |
| | | z1Cell.Value = "Z1"; |
| | | |
| | | var z2Cell = rawDataSheet.Cells[2, rowDataStartCol + 2]; |
| | | z2Cell.Value = "Z2"; |
| | | |
| | | var z3Cell = rawDataSheet.Cells[2, rowDataStartCol + 3]; |
| | | z3Cell.Value = "Z3"; |
| | | |
| | | var z4Cell = rawDataSheet.Cells[2, rowDataStartCol + 4]; |
| | | z4Cell.Value = "Z4"; |
| | | |
| | | exportData.KeyUnitDataList.ForEach(k => |
| | | { |
| | | int keyIndex = Config.KeyNameCollection.IndexOf(k.Key); |
| | | int zIndex = int.Parse(k.MeasurementItem.Substring(1)); |
| | | |
| | | var cell = rawDataSheet.Cells[keyIndex + 1 + 2, rowDataStartCol + zIndex]; |
| | | cell.Value = k.ItemValue; |
| | | }); |
| | | |
| | | package.Save(); |
| | | }; |
| | | }); |
| | | } |
| | | |
| | | #region 图像保存 |
| | | private void SaveWholeImage(ProductionMeasurement pMeasure) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | string fileName = Path.Combine(Config.ImageSaveFolder, "BeforeRun", $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.tif"); |
| | | imgSet.HImage.WriteImage("tiff", 0, fileName); |
| | | |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage; |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |