From 28ddc75eadee6c73da2b955e320132fdbecc88de Mon Sep 17 00:00:00 2001
From: C3031 <shitiangui@lanpucloud.cn>
Date: 星期五, 16 一月 2026 16:44:11 +0800
Subject: [PATCH] 修改关闭按钮位置
---
LB_SmartVision/CSV/CsvDataHelperRecordProductData.cs | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 110 insertions(+), 0 deletions(-)
diff --git a/LB_SmartVision/CSV/CsvDataHelperRecordProductData.cs b/LB_SmartVision/CSV/CsvDataHelperRecordProductData.cs
new file mode 100644
index 0000000..813ccb6
--- /dev/null
+++ b/LB_SmartVision/CSV/CsvDataHelperRecordProductData.cs
@@ -0,0 +1,110 @@
+锘縰sing LB_SmartVision.SQL;
+using LB_SmartVisionCommon;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using CsvHelper;
+namespace LB_SmartVision.CSV
+{
+ internal class CsvDataHelperRecordProductData
+ {
+ /// <summary>
+ /// 灏哛ecordProductDatas瀛楀吀淇濆瓨鍒癈SV鏂囦欢
+ /// </summary>
+ /// <param name="filePath">CSV鏂囦欢璺緞</param>
+ /// <param name="recordProductDatas">瑕佷繚瀛樼殑鏁版嵁瀛楀吀</param>
+ public static void SaveToCsv(string filePath, List<RecordProductData> recordProductDatas)
+ {
+ try
+ {
+ using (var writer = new StreamWriter(filePath))
+ using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
+ {
+ csv.Context.RegisterClassMap<CsvRecordProductDataMap>();
+ // 灏嗗瓧鍏歌浆鎹负CsvRecord鍒楄〃
+ var records = recordProductDatas.Select(kvp => new CsvRecordProductData
+ {
+ //DictionaryKey = kvp.Key,
+ ProductName = kvp.ProductName,
+ ProductSN = kvp.ProductSN,
+ InspectionOperator = kvp.InspectionOperator,
+ NGType = kvp.NGType,
+ NGSize = kvp.NGSize,
+ DetectionTime = kvp.DetectionTime,
+ CameraInspection = kvp.CameraInspection,
+
+ }).ToList();
+ for (int i = 0; i < records.Count; i++)
+ {
+ AsyncLogHelper.Warn("鐗╂枡鍙锋垨浜у搧鍚嶇О锛�" + records[i].ProductName + "\r\n" +
+ "锛屼骇鍝丼N鍙凤細" + records[i].ProductSN + "\r\n" +
+ "锛屾娴嬩綔涓氬憳锛�" + records[i].InspectionOperator + "\r\n" +
+ "锛孨G绫诲瀷锛�" + records[i].NGType + " mm" + "\r\n" +
+ "锛孨G澶у皬锛�" + records[i].NGSize + " mm" + "\r\n" +
+ "锛屾娴嬫椂闂达細" + records[i].DetectionTime + "\r\n" +
+ "锛屾娴嬬浉鏈猴細" + records[i].CameraInspection + " mm" + "\r\n" );
+
+ }
+ csv.WriteRecords(records);
+ }
+ LogHelper.Info($"鏁版嵁鎴愬姛淇濆瓨鍒�: {filePath}");
+ }
+ catch (Exception ex)
+ {
+ LogHelper.Error($"淇濆瓨CSV鏂囦欢鏃跺嚭閿�: {ex.Message}");
+ //throw;
+ }
+ //Task.Factory.StartNew(() =>
+ //{
+ //});
+ }
+ /// <summary>
+ /// 浠嶤SV鏂囦欢璇诲彇鏁版嵁鍒癛ecordProductDatas瀛楀吀
+ /// </summary>
+ /// <param name="filePath">CSV鏂囦欢璺緞</param>
+ /// <returns>璇诲彇鐨勬暟鎹瓧鍏�</returns>
+ public static List<RecordProductData> LoadFromCsv(string filePath)
+ {
+ var recordProductDatas = new List<RecordProductData>();
+ try
+ {
+ if (!File.Exists(filePath))
+ {
+ LogHelper.Info($"鏂囦欢涓嶅瓨鍦�: {filePath}");
+ return recordProductDatas;
+ }
+ using (var reader = new StreamReader(filePath))
+ using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
+ {
+ csv.Context.RegisterClassMap<CsvRecordProductDataMap>();
+ var records = csv.GetRecords<CsvRecordProductData>();
+ foreach (var record in records)
+ {
+ var productData = new RecordProductData
+ {
+ ProductName = record.ProductName,
+ ProductSN = record.ProductSN,
+ InspectionOperator = record.InspectionOperator,
+ NGType = record.NGType,
+ NGSize = record.NGSize,
+ DetectionTime = record.DetectionTime,
+ CameraInspection = record.CameraInspection,
+ };
+ recordProductDatas.Add(productData);
+ }
+ }
+ LogHelper.Info($"浠� {filePath} 鎴愬姛璇诲彇 {recordProductDatas.Count} 鏉¤褰�");
+ }
+ catch (Exception ex)
+ {
+ LogHelper.Error($"璇诲彇CSV鏂囦欢鏃跺嚭閿�: {ex.Message}");
+ //throw;
+ }
+ return recordProductDatas;
+ }
+
+ }
+}
--
Gitblit v1.9.3