| | |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.Dynamic; |
| | | using System.IO; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Windows; |
| | |
| | | private string visualTestId; |
| | | private Sqlite3Helper helper; |
| | | |
| | | private void InitCurrentTestHelper() |
| | | { |
| | | if (helper == null) |
| | | { |
| | | var now = DateTime.Now; |
| | | string dateStr = now.ToString("yyyyMMdd"); |
| | | visualTestId = $"{title}_{now.ToString("yyyyMMddHHmmssfff")}"; |
| | | helper = CheckSqlHelper(dateStr); |
| | | } |
| | | } |
| | | |
| | | public void SetStatus(string status) |
| | | { |
| | | Dispatcher.Invoke(() => |
| | |
| | | if (oldStatus != "testing" && status == "testing") |
| | | { |
| | | UpdateProbeCount(ProbeCount + 1); |
| | | var now = DateTime.Now; |
| | | string dateStr = now.ToString("yyyyMMdd"); |
| | | visualTestId = $"{title}_{now.ToString("yyyyMMddHHmmssfff")}"; |
| | | helper = CheckSqlHelper(dateStr); |
| | | InsertARecourd(); |
| | | InitCurrentTestHelper(); |
| | | InsertARecord(); |
| | | } |
| | | |
| | | if (oldStatus != "ok" && status == "ok") |
| | |
| | | }); |
| | | } |
| | | |
| | | private void InsertARecourd() |
| | | private void InsertARecord() |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ViewControl.Logger.Error($"Cell[{title}] SaveToDB Error.", ex); |
| | | ViewControl.Logger.Error($"Cell[{title}] InsertARecord Error.", ex); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | InitCurrentTestHelper(); |
| | | string model = table?.CbProduct?.SelectedItem?.ToString(); |
| | | sql = $@"INSERT INTO serialData (sn,model,station,position,step,limitDown,limitUp,unit,value,status,finalStatus,time,resultId) |
| | | VALUES ('{sn}','{model}','','{this.title}','{info.step}','{info.limitDown}','{info.limitUp}','{info.unit}','{info.value}','{info.result}', |
| | |
| | | } |
| | | } |
| | | |
| | | private void NormalCSV(string filePath) |
| | | public void NormalCSV(string filePath) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private void ReverseCSV(string filePath) |
| | | public void ReverseCSV_Bak(string filePath) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public void ReverseCSV(string filePath) |
| | | { |
| | | try |
| | | { |
| | | if (allInfos == null || allInfos.Count < 4) return; |
| | | |
| | | Dictionary<string, int> columnMap = new Dictionary<string, int>(); |
| | | int colPoint = 0; |
| | | List<string> titleRow = new List<string>(); |
| | | List<string[]> datas = new List<string[]>(); |
| | | List<string> timeRow = new List<string>(); |
| | | |
| | | void AddTitle(string title) |
| | | { |
| | | if (titleRow.IndexOf(title) < 0) |
| | | { |
| | | titleRow.Add(title); |
| | | } |
| | | } |
| | | |
| | | // 先设置表头 |
| | | for (int i = 0; i < allInfos.Count; i++) |
| | | { |
| | | var info = allInfos[i]; |
| | | if (IgnoreTestItem.Contains(info.step.ToLower())) |
| | | { |
| | | continue; |
| | | } |
| | | string testTime = info.updateTime; |
| | | int rowIndex = timeRow.IndexOf(testTime); |
| | | if (rowIndex < 0) |
| | | { |
| | | timeRow.Add(testTime); |
| | | } |
| | | |
| | | string title = $"{info.step}{(string.IsNullOrEmpty(info.unit) ? "" : $"({info.unit})")}"; |
| | | AddTitle("测试时间"); |
| | | AddTitle(title); |
| | | if (!string.IsNullOrEmpty(info.limitDown)) |
| | | { |
| | | string key2 = $"{info.step}下限"; |
| | | AddTitle(key2); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(info.limitUp)) |
| | | { |
| | | string key2 = $"{info.step}上限"; |
| | | AddTitle(key2); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(info.limitUp)) |
| | | { |
| | | string key2 = $"{info.step}测试结果"; |
| | | AddTitle(key2); |
| | | } |
| | | |
| | | //if (!string.IsNullOrEmpty(info.updateTime)) |
| | | //{ |
| | | // string key2 = $"{info.step}测试时间"; |
| | | // AddTitle(key2); |
| | | //} |
| | | } |
| | | |
| | | for (int i = 0; i < allInfos.Count; i++) |
| | | { |
| | | var info = allInfos[i]; |
| | | if (IgnoreTestItem.Contains(info.step.ToLower())) |
| | | { |
| | | continue; |
| | | } |
| | | string testTime = info.updateTime; |
| | | int row = timeRow.IndexOf(testTime); |
| | | if (row < 0) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | |
| | | string title = $"{info.step}{(string.IsNullOrEmpty(info.unit) ? "" : $"({info.unit})")}"; |
| | | int col = titleRow.IndexOf(title); |
| | | |
| | | if (datas.Count <= row) |
| | | { |
| | | datas.Add(new string[titleRow.Count]); |
| | | } |
| | | var arr = datas[row]; |
| | | arr[col] = info.value; |
| | | |
| | | |
| | | if (!string.IsNullOrEmpty(info.limitDown)) |
| | | { |
| | | string key2 = $"{info.step}下限"; |
| | | int col2 = titleRow.IndexOf(key2); |
| | | arr[col2] = info.limitDown; |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(info.limitUp)) |
| | | { |
| | | string key2 = $"{info.step}上限"; |
| | | int col2 = titleRow.IndexOf(key2); |
| | | arr[col2] = info.limitUp; |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(info.limitUp)) |
| | | { |
| | | string key2 = $"{info.step}测试结果"; |
| | | int col2 = titleRow.IndexOf(key2); |
| | | arr[col2] = info.result; |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(info.updateTime)) |
| | | { |
| | | string key2 = "测试时间";// $"{info.step}测试时间"; |
| | | int col2 = titleRow.IndexOf(key2); |
| | | arr[col2] = info.updateTime; |
| | | } |
| | | } |
| | | |
| | | |
| | | FileInfo fi = new FileInfo(filePath); |
| | | if (!fi.Directory.Exists) |
| | | { |
| | | fi.Directory.Create(); //文件不存在,创建文件 |
| | | } |
| | | |
| | | using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) |
| | | using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8)) |
| | | { |
| | | string title = string.Join(",", titleRow); |
| | | sw.WriteLine(title); |
| | | foreach (var info in datas) |
| | | { |
| | | string row = string.Join(",", info); |
| | | sw.WriteLine(row); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ViewControl.Logger.Error($"Cell[{title}] SaveInfoToCSV Error.", ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存测试数据到CSV |
| | | /// </summary> |
| | |
| | | /// <param name="filePath"></param> |
| | | public void SaveInfoToDB() |
| | | { |
| | | Dispatcher.BeginInvoke(new Action(() => |
| | | Dispatcher.Invoke(() => |
| | | { |
| | | try |
| | | { |
| | |
| | | { |
| | | ViewControl.Logger.Error($"Cell[{title}] SaveToDB Error.", ex); |
| | | } |
| | | })); |
| | | }); |
| | | } |
| | | |
| | | private void MenuItem_Click(object sender, RoutedEventArgs e) |
| | |
| | | return; |
| | | } |
| | | string modelPath = table.parent.testModelFile; |
| | | int dutNo = table.index * table.cellCount + this.index; |
| | | var win = new ManualDebugWindow(manualDebugSeq, modelPath) |
| | | { |
| | | Title = $"{this.title}手动调试", |
| | |
| | | OvenIndex = this.table.index, |
| | | OvenName = this.table.title, |
| | | |
| | | CellIndex = this.index, |
| | | CellIndex = dutNo, |
| | | CellName = this.title |
| | | }; |
| | | win.ShowDialog(); |
| | |
| | | }; |
| | | if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
| | | { |
| | | this.SaveInfoToCSV(sfd.FileName); |
| | | this.NormalCSV(sfd.FileName); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | public bool LightGreen(bool on, out string msg) |
| | | { |
| | | return S7Context.WriteData(RunTimeVariablePool.DEFAULT_PLC_NAME, |
| | | $"Oven{table.index + 1}_Cell{index + 1}_Light_OK", on, out msg); |
| | | string key = $"Oven{table.index + 1}_Cell{index + 1}_Light_OK"; |
| | | bool res = S7Context.WriteData(RunTimeVariablePool.DEFAULT_PLC_NAME, key, on, out msg); |
| | | if (res) |
| | | { |
| | | ViewControl.Logger.Debug($"Set Light [{key}] {on}."); |
| | | } |
| | | else |
| | | { |
| | | ViewControl.Logger.Debug($"Open Light [{key}] {on} Error.{msg}"); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | public bool LightRed(bool on, out string msg) |