diff --git a/Cowain.Preheat.Common/Core/CSVHelper.cs b/Cowain.Preheat.Common/Core/CSVHelper.cs index 9286c2f..99be7c2 100644 --- a/Cowain.Preheat.Common/Core/CSVHelper.cs +++ b/Cowain.Preheat.Common/Core/CSVHelper.cs @@ -116,7 +116,32 @@ namespace Cowain.Preheat.Common.Core return filePath; } + public static void WriteMap(IEnumerable list, string filePath) where TMap : ClassMap + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture) + { + // 设置列头编码为UTF8以支持中文 + Delimiter = ",", + HasHeaderRecord = true, + Encoding = System.Text.Encoding.UTF8 + }; + + if (File.Exists(filePath)) + { + config.HasHeaderRecord = false; // 获取字段描述作为列头 + } + + using (var writer = new StreamWriter(filePath, true, System.Text.Encoding.UTF8)) + using (var csv = new CsvWriter(writer, config)) + { + // 注册自定义映射 + //csv.Context.RegisterClassMap(); + csv.Context.RegisterClassMap(); + // 写入记录 + csv.WriteRecords(list); + } + } public static void WriteMap(IEnumerable list ) where TMap : ClassMap //where TMap : ClassMap // 约束:必须是 ClassMap 或其子类 { string filePath = GetFilePath(); diff --git a/Cowain.Preheat.Main/Common/ExecCommonFun.cs b/Cowain.Preheat.Main/Common/ExecCommonFun.cs index eb3e3ea..da6af87 100644 --- a/Cowain.Preheat.Main/Common/ExecCommonFun.cs +++ b/Cowain.Preheat.Main/Common/ExecCommonFun.cs @@ -40,6 +40,7 @@ namespace Cowain.Preheat.Main.Common { List batteries = new List(); batteries.Add(batteryInfo); + _unityContainer.Resolve().BuildRecordFile(batteries); MESReturnOutputModel mesResult = _unityContainer.Resolve().CellOutput(batteries, "OK", "", "", new List(), true); if (null == mesResult) { diff --git a/Cowain.Preheat.Main/Properties/AssemblyInfo.cs b/Cowain.Preheat.Main/Properties/AssemblyInfo.cs index f545dd7..133abb2 100644 --- a/Cowain.Preheat.Main/Properties/AssemblyInfo.cs +++ b/Cowain.Preheat.Main/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.1.5")] -[assembly: AssemblyFileVersion("1.0.1.5")] +[assembly: AssemblyVersion("1.0.1.6")] +[assembly: AssemblyFileVersion("1.0.1.6")] diff --git a/Cowain.Preheat.Main/Station/ScannCodeStation.cs b/Cowain.Preheat.Main/Station/ScannCodeStation.cs index 48f52dc..8ca72c2 100644 --- a/Cowain.Preheat.Main/Station/ScannCodeStation.cs +++ b/Cowain.Preheat.Main/Station/ScannCodeStation.cs @@ -208,12 +208,12 @@ namespace Cowain.Preheat.Main.Station LogHelper.Instance.Error($"重复扫码:-{scanResult.Content},{_queueBatterys.Count}"); replyResult = (Int16)EResult.RepeatScann; } - else if (!IsCharFlag(scanResult.Content)) - { - msg = "A\\B面扫码异常"; - LogHelper.Instance.Error($"{msg}:-{scanResult.Content}"); - replyResult = (Int16)EResult.ErrorAB; - } + //else if (!IsCharFlag(scanResult.Content)) + //{ + // msg = "A\\B扫码异常"; + // LogHelper.Instance.Error($"{msg}:-{scanResult.Content}"); + // replyResult = (Int16)EResult.ErrorAB; + //} else { ////扫码OK入库 diff --git a/Cowain.Preheat.Main/Station/UnLoadingStation.cs b/Cowain.Preheat.Main/Station/UnLoadingStation.cs index 2926c69..b6e49dc 100644 --- a/Cowain.Preheat.Main/Station/UnLoadingStation.cs +++ b/Cowain.Preheat.Main/Station/UnLoadingStation.cs @@ -1,5 +1,6 @@ using Cowain.Preheat.BLL; using Cowain.Preheat.Common.Core; +using Cowain.Preheat.Common.CsvMap; using Cowain.Preheat.Common.Enums; using Cowain.Preheat.Common.Interface; using Cowain.Preheat.Communication.Interface; @@ -26,7 +27,7 @@ namespace Cowain.Preheat.Main.Station public string Name { get; set; } public IUnityContainer _unityContainer { get; set; } IPLCDevice PLC { get; set; } - + public readonly object _lockObj = new object(); public List WindowBtnInfo = new List(); public UnLoadingStation(IUnityContainer unityContainer) { @@ -213,45 +214,7 @@ namespace Cowain.Preheat.Main.Station return $"{(int)(diff.TotalSeconds / 60)}分钟{(int)(diff.TotalSeconds % 60) }秒"; } } - void BuildRecordFile(List batteryList) - { - string dateFile = ""; - string filePath = ""; - string path = _unityContainer.Resolve().GetValueByParaID(ESysSetup.DataFilePath.ToString());// - - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - dateFile = DateTime.Now.ToString("yyyyMMdd"); - filePath = path + $"\\{dateFile}.csv"; - if (null == batteryList) - { - return; - } - - try - { - CSVHelper.WriteDataTableToCsv(batteryList, new List { "Id","BatteryCode", - "PositionX", "PositionY", "Layer", "ScanTime","LoadingTime", "UnLoadingTime", "LodingTemperature", - "PreheatTemperature","UnLoadingTemperature","PreheatTime"}, new List - { "序号", "电芯条码", "行号", "列号", "层号","扫码时间", "上料时间", "下料时间" - ,"上料温度","预热温度","下料温度","预热时长" }, filePath); - - foreach (var item in batteryList) - { - if (0 == _unityContainer.Resolve().UpdateStatus(item.Id, (int)EBatteryStatus.OutBoundRecord)) - { - LogHelper.Instance.Fatal("修改记录出站状态失败!"); - } - } - } - catch (Exception ex) - { - LogHelper.Instance.GetCurrentClassFatal($"{ex.Message},{ex.StackTrace}"); - } - } + //public void GetSuccessBattery(ref int[] batteryIds) //{ @@ -303,7 +266,7 @@ namespace Cowain.Preheat.Main.Station LogHelper.Instance.Fatal($"出站数据大于11,电芯ID:{string.Join(",", batteryIds)}"); } - //BuildRecordFile(batteryList); //记录出站 + BuildRecordFile(batteryList); //记录出站 //真实上传MOM if (int.Parse(_unityContainer.Resolve().GetValueByParaID(ESysSetup.MOMEnable.ToString())) == (int)EMOMEnable.Enable) @@ -323,8 +286,50 @@ namespace Cowain.Preheat.Main.Station } return true; } - + public void BuildRecordFile(List batterys) + { + string dateFile = ""; + string filePath = ""; + string path = _unityContainer.Resolve().GetValueByParaID(ESysSetup.DataFilePath.ToString());// + if (null == batterys + || batterys.Count == 0) + { + return; + } + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + dateFile = DateTime.Now.ToString("yyyyMMdd"); + filePath = path + $"\\{dateFile}.csv"; + + try + { + // CSVHelper.WriteDataTableToCsv(batteryList, new List { "Id","BatteryCode", + //"PositionX", "PositionY", "Layer", "ScanTime","LoadingTime", "UnLoadingTime", "LodingTemperature", + // "PreheatTemperature","UnLoadingTemperature","PreheatTime"}, new List + //{ "序号", "电芯条码", "行号", "列号", "层号","扫码时间", "上料时间", "下料时间" + //,"上料温度","预热温度","下料温度","预热时长" }, filePath); + + //foreach (var item in batteryList) + //{ + // if (0 == _unityContainer.Resolve().UpdateStatus(item.Id, (int)EBatteryStatus.OutBoundRecord)) + // { + // LogHelper.Instance.Fatal("修改记录出站状态失败!"); + // } + //} + lock (_lockObj) + { + CSVHelper.WriteMap(batterys, filePath); + } + } + catch (Exception ex) + { + LogHelper.Instance.GetCurrentClassFatal($"{ex.Message},{ex.StackTrace}"); + } + } public void Stop() { diff --git a/README.md b/README.md index 835f79c..8dad934 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# 6098-5 \ No newline at end of file +1. # 八条线的程序和数据库都是一样的,每一条线都有自己的机台编号,在表TSysSetup中的ParamValue字段修改机台编号 +