|
|
@@ -1,6 +1,9 @@
|
|
|
using BarTender;
|
|
|
using DevExpress.Xpo.Logger;
|
|
|
+using DevExpress.XtraEditors.Controls;
|
|
|
+using DevExpress.XtraExport;
|
|
|
using DevExpress.XtraPrinting;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
@@ -56,6 +59,7 @@ namespace UAS_MES_NEW.Make
|
|
|
ma_code.Condition = "ma_statuscode='STARTED'";
|
|
|
ma_code.DbChange += Ma_code_DbChange;
|
|
|
}
|
|
|
+
|
|
|
private void Ma_code_DbChange(object sender, EventArgs e)
|
|
|
{
|
|
|
Dbfind = ma_code.ReturnData;
|
|
|
@@ -90,6 +94,12 @@ namespace UAS_MES_NEW.Make
|
|
|
txtPath.Focus();
|
|
|
txtPath.SelectAll();
|
|
|
}
|
|
|
+
|
|
|
+ private void claerBtn_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ lstFiles.Items.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
private void allParse_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
@@ -110,8 +120,15 @@ namespace UAS_MES_NEW.Make
|
|
|
txtPath.SelectAll();
|
|
|
return;
|
|
|
}
|
|
|
+ string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
|
|
|
+ if (txtFiles.Length == 0)
|
|
|
+ {
|
|
|
+ LogMessage($"当前没有{currFileType.ToUpper()}文件");
|
|
|
+ return;
|
|
|
+ }
|
|
|
RefreshFileList();
|
|
|
}
|
|
|
+
|
|
|
private void Choose_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
@@ -148,8 +165,8 @@ namespace UAS_MES_NEW.Make
|
|
|
break;
|
|
|
case 2:
|
|
|
dialog.Description = "请选择读取印刷机设备的文本文件夹";
|
|
|
- currFileType = "xml";
|
|
|
equiType = "印刷机";
|
|
|
+ currFileType = "csv";
|
|
|
break;
|
|
|
case 3:
|
|
|
dialog.Description = "请选择读取贴片机的文本文件夹";
|
|
|
@@ -163,7 +180,18 @@ namespace UAS_MES_NEW.Make
|
|
|
txtPath.Enabled = false;
|
|
|
Device.Enabled = false;
|
|
|
var watcher = new FileSystemWatcher(txtPath.Text);
|
|
|
- watcher.Filter = $"*.{currFileType}";
|
|
|
+ if (equiType == "SPI")
|
|
|
+ {
|
|
|
+ var txtFiles = Directory.GetFiles(txtPath.Text, "*.txt");
|
|
|
+ var csvFiles = Directory.GetFiles(txtPath.Text, "*.csv");
|
|
|
+ currFileType = txtFiles.Length > csvFiles.Length ? "txt" : "csv";
|
|
|
+ watcher.Filter = $"*.{currFileType}";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ watcher.Filter = $"*.{currFileType}";
|
|
|
+ }
|
|
|
+
|
|
|
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
|
|
|
watcher.Created += OnFileCreated;
|
|
|
/*watcher.Changed += OnFileChanged;
|
|
|
@@ -224,10 +252,12 @@ namespace UAS_MES_NEW.Make
|
|
|
MessageBox.Show(this.ParentForm, ex.Message, "警告");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void OnFileCreated(object sender, FileSystemEventArgs e)
|
|
|
{
|
|
|
RefreshFileList();
|
|
|
}
|
|
|
+
|
|
|
private void OnFileChanged(object sender, FileSystemEventArgs e)
|
|
|
{
|
|
|
if (e.ChangeType == WatcherChangeTypes.Changed)
|
|
|
@@ -235,12 +265,13 @@ namespace UAS_MES_NEW.Make
|
|
|
RefreshFileList();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void RefreshFileList()
|
|
|
{
|
|
|
- // 在UI线程上执行更新
|
|
|
if (lstFiles.InvokeRequired)
|
|
|
{
|
|
|
- lstFiles.Invoke(new Action(RefreshFileList));
|
|
|
+ //lstFiles.Invoke(new Action(RefreshFileList));
|
|
|
+ lstFiles.BeginInvoke(new Action(RefreshFileList));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -253,37 +284,61 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
|
|
|
string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
|
|
|
-
|
|
|
if (txtFiles.Length == 0)
|
|
|
{
|
|
|
- LogMessage($"当前没有{currFileType.ToUpper()}文件");
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (string file in txtFiles)
|
|
|
{
|
|
|
- LogMessage(file);
|
|
|
- if (Device.SelectedIndex == 0) // SPI 已测试对接
|
|
|
+ if (Device.SelectedIndex == 0) // SPI
|
|
|
{
|
|
|
- ParseLogInsert(file);
|
|
|
- Console.WriteLine();
|
|
|
+ string fileType = Path.GetExtension(file).ToLower();
|
|
|
+ List<SpiData> csvData;
|
|
|
+ if (fileType == ".txt") // 劲拓
|
|
|
+ {
|
|
|
+ ParseLogInsert(file);
|
|
|
+ }
|
|
|
+ else if (fileType == ".csv") // 思泰克 ?
|
|
|
+ {
|
|
|
+ //csvData = ParseCsvFile(file);
|
|
|
+ csvData = ParseCsvFile<SpiData>(file, MapToSpiData);
|
|
|
+
|
|
|
+ foreach(var item in csvData)
|
|
|
+ {
|
|
|
+ sql.Append($@"INSERT INTO steptestdetail (std_id,std_sn,std_makecode,
|
|
|
+ std_testresult,std_class,std_actualvalue,
|
|
|
+ std_rescode,STD_SUBCLASS1) VALUES (steptestdetail_seq.nextval,v_sn,v_wo,
|
|
|
+ decode(v_testres,'PASS','OK','NG','NG'),v_equi_type,'notfound',
|
|
|
+ v_sourcecode,v_equi_type)");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ string xmlContent = File.ReadAllText(file);
|
|
|
+ if (ConsoleLog(xmlContent, file))
|
|
|
+ {
|
|
|
+ File.Delete(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- else if (Device.SelectedIndex == 1) // AOI 已测试对接
|
|
|
+ else if (Device.SelectedIndex == 1) // AOI
|
|
|
{
|
|
|
ParseLogInsert(file);
|
|
|
- Console.WriteLine();
|
|
|
}
|
|
|
- else if (Device.SelectedIndex == 2) // 印刷机 待测试对接
|
|
|
+ else if (Device.SelectedIndex == 2) // 印刷机 ?
|
|
|
{
|
|
|
- // 印刷机xml文件解析
|
|
|
- //PrinterData xmlData = ReadWithXmlReader(file);
|
|
|
- //Console.WriteLine();
|
|
|
+ List<PrintData> priMacData;
|
|
|
+ priMacData = ParseCsvFile<PrintData>(file, MapToPriMacData);
|
|
|
|
|
|
- // 印刷机csv文件解析
|
|
|
- //var csvData = ParseCsvFile(file);
|
|
|
+ string xmlContent = File.ReadAllText(file);
|
|
|
+ if (ConsoleLog(xmlContent, file))
|
|
|
+ {
|
|
|
+ File.Delete(file);
|
|
|
+ }
|
|
|
}
|
|
|
- else if (Device.SelectedIndex == 3) // 贴片机 导站位表已测试对接
|
|
|
+ else if (Device.SelectedIndex == 3) // 贴片机
|
|
|
{
|
|
|
if (!File.Exists(file))
|
|
|
{
|
|
|
@@ -341,7 +396,6 @@ namespace UAS_MES_NEW.Make
|
|
|
Console.WriteLine();
|
|
|
}
|
|
|
}
|
|
|
- LogMessage($"共找到{txtFiles.Length}个{currFileType.ToUpper()}文件");
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -361,11 +415,11 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
List<Log> logArr = new List<Log>() { };
|
|
|
string[] lines = restOfStream.Split(new string[] { "\r\n" }, StringSplitOptions.None);
|
|
|
- int fileNum = 0;
|
|
|
+ int fileNum = string.IsNullOrEmpty(lines[lines.Length - 1]) ? lines.Length - 1 : lines.Length;
|
|
|
+ LogMessage($"文件夹{PathName},共{fileNum}条记录");
|
|
|
foreach (var item in lines)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(item)) continue;
|
|
|
- fileNum++;
|
|
|
string[] currItem = item.Split(',');
|
|
|
string res = "";
|
|
|
/*List<NgData> data = new List<NgData>();*/
|
|
|
@@ -413,7 +467,6 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
LogMessage($"已解析: {currItem[0]}");
|
|
|
}
|
|
|
- LogMessage($"文件夹{PathName},共{fileNum}条记录");
|
|
|
InsertDb(logArr, PathName);
|
|
|
|
|
|
File.WriteAllText(PathName, string.Empty);
|
|
|
@@ -427,6 +480,7 @@ namespace UAS_MES_NEW.Make
|
|
|
MessageBox.Show(this.ParentForm, ex.Message, "警告");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void InsertDb(List<Log> logs, string PathName)
|
|
|
{
|
|
|
try
|
|
|
@@ -513,6 +567,7 @@ namespace UAS_MES_NEW.Make
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void LogMessage(string message)
|
|
|
{
|
|
|
if (lstFiles.InvokeRequired)
|
|
|
@@ -523,6 +578,338 @@ namespace UAS_MES_NEW.Make
|
|
|
lstFiles.Items.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
|
|
|
lstFiles.TopIndex = lstFiles.Items.Count - 1;
|
|
|
}
|
|
|
+
|
|
|
+ public List<MachineList> ParseXml(string xmlContent)
|
|
|
+ {
|
|
|
+ List<MachineList> result = new List<MachineList>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ XmlDocument xmlDoc = new XmlDocument();
|
|
|
+ xmlDoc.LoadXml(xmlContent);
|
|
|
+
|
|
|
+ XmlNode machineNode = xmlDoc.SelectSingleNode("//TotalProductionInfo");
|
|
|
+ string machineName = machineNode?.Attributes["MachineName"]?.Value ?? "Unknown";
|
|
|
+ string part = machineNode?.Attributes["ProductionProgramName"]?.Value ?? "Unknown";
|
|
|
+
|
|
|
+ XmlNodeList feederNodes = xmlDoc.SelectNodes("//FeederProductionManageInfo");
|
|
|
+ foreach (XmlNode feederNode in feederNodes)
|
|
|
+ {
|
|
|
+ MachineList machineList = new MachineList();
|
|
|
+ string feederBankPosition = feederNode.Attributes["FeederBankPosition"]?.Value ?? "Unknown";
|
|
|
+ string holeNo = feederNode.Attributes["HoleNo"]?.Value ?? "Unknown";
|
|
|
+ string componentName = feederNode.Attributes["ComponentName"]?.Value ?? "Unknown";
|
|
|
+
|
|
|
+ machineList.MachineName = machineName;
|
|
|
+ machineList.Part = part;
|
|
|
+ machineList.ReelNo = componentName;
|
|
|
+ machineList.Station = $"{machineName}-{feederBankPosition[0]}-{holeNo}";
|
|
|
+ result.Add(machineList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogMessage($"Error parsing XML: {ex.Message}");
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SpiData> ParseCsvFile(string filePath)
|
|
|
+ {
|
|
|
+ var SpiDataList = new List<SpiData>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string fileName = Path.GetFileName(filePath);
|
|
|
+
|
|
|
+ Encoding fileEncoding = DetectFileEncoding(filePath);
|
|
|
+ string[] lines = File.ReadAllLines(filePath, fileEncoding);
|
|
|
+
|
|
|
+ if (lines.Length < 3) return SpiDataList;
|
|
|
+
|
|
|
+ string modelName = lines[1].Split(',')[0];
|
|
|
+ string lineNumber = lines[1].Split(',')[1];
|
|
|
+ string boardStatus = lines[2].Split(',')[1];
|
|
|
+ string[] headers = lines[3].Split(',');
|
|
|
+
|
|
|
+ for (int i = 4; i < lines.Length; i++)
|
|
|
+ {
|
|
|
+ string[] values = lines[i].Split(',');
|
|
|
+
|
|
|
+ var SpiData = new SpiData
|
|
|
+ {
|
|
|
+ FileName = fileName,
|
|
|
+ ModelName = modelName,
|
|
|
+ LineNumber = lineNumber,
|
|
|
+ BoardStatus = boardStatus,
|
|
|
+ PadID = GetValue(values, 0, headers, "PadID"),
|
|
|
+ ComponentID = GetValue(values, 1, headers, "ComponentID"),
|
|
|
+ Type = GetValue(values, 2, headers, "Type"),
|
|
|
+ AreaPercent = GetValue(values, 3, headers, "Area(%)"),
|
|
|
+ Height = GetValue(values, 4, headers, "Height"),
|
|
|
+ VolumePercent = GetValue(values, 5, headers, "Volume(%)"),
|
|
|
+ XOffset = GetValue(values, 6, headers, "XOffset"),
|
|
|
+ YOffset = GetValue(values, 7, headers, "YOffset"),
|
|
|
+ PadSizeX = GetValue(values, 8, headers, "PadSize(X)"),
|
|
|
+ PadSizeY = GetValue(values, 9, headers, "PadSize(Y)"),
|
|
|
+ Area = GetValue(values, 10, headers, "Area"),
|
|
|
+ HeightPercent = GetValue(values, 11, headers, "Height(%)"),
|
|
|
+ Volume = GetValue(values, 12, headers, "Volume"),
|
|
|
+ Result = GetValue(values, 13, headers, "Result"),
|
|
|
+ Errcode = GetValue(values, 14, headers, "Errcode"),
|
|
|
+ PinNum = GetValue(values, 15, headers, "PinNum"),
|
|
|
+ Barcode = GetValue(values, 16, headers, "Barcode"),
|
|
|
+ Date = GetValue(values, 17, headers, "Date"),
|
|
|
+ Time = GetValue(values, 18, headers, "Time"),
|
|
|
+ ArrayID = GetValue(values, 19, headers, "ArrayID")
|
|
|
+ };
|
|
|
+ SpiDataList.Add(SpiData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogMessage($"解析csv文件报错,{ex.Message}");
|
|
|
+ }
|
|
|
+
|
|
|
+ return SpiDataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<T> ParseCsvFile<T>(string filePath, Func<string, string[], string[], string, int, T> mapper) where T : class
|
|
|
+ {
|
|
|
+ var dataList = new List<T>();
|
|
|
+
|
|
|
+ if (!File.Exists(filePath))
|
|
|
+ {
|
|
|
+ LogMessage($"文件不存在: {filePath}");
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string fileName = Path.GetFileName(filePath);
|
|
|
+ /*Encoding fileEncoding = DetectFileEncoding(filePath);*/
|
|
|
+ string[] lines = File.ReadAllLines(filePath, Encoding.GetEncoding("GB2312"));
|
|
|
+
|
|
|
+ if (lines.Length < 4) return dataList;
|
|
|
+
|
|
|
+ for (int i = 1; i < lines.Length; i++)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(lines[i])) continue;
|
|
|
+
|
|
|
+ if (equiType == "SPI")
|
|
|
+ {
|
|
|
+ string modelName = lines[1].Split(',')[0];
|
|
|
+ string lineNumber = lines[1].Split(',')[1];
|
|
|
+ string boardStatus = lines[2].Split(',')[1];
|
|
|
+
|
|
|
+ if(i > 3)
|
|
|
+ {
|
|
|
+ string[] headers = lines[3].Split(',');
|
|
|
+ string[] values = lines[i].Split(',');
|
|
|
+ var item = mapper(fileName, headers, values, $"{modelName},{lineNumber},{boardStatus}", i);
|
|
|
+ if (item != null)
|
|
|
+ {
|
|
|
+ dataList.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (equiType == "印刷机")
|
|
|
+ {
|
|
|
+ string[] headers = lines[0].Split(',');
|
|
|
+ string[] values = lines[i].Split(',');
|
|
|
+ var item = mapper(fileName, headers, values, "", i);
|
|
|
+ if (item != null)
|
|
|
+ {
|
|
|
+ dataList.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogMessage($"解析csv文件报错: {ex.Message}");
|
|
|
+ }
|
|
|
+
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+ private SpiData MapToSpiData(string fileName, string[] headers, string[] values,string others,int num)
|
|
|
+ {
|
|
|
+ return new SpiData
|
|
|
+ {
|
|
|
+ FileName = fileName,
|
|
|
+ ModelName = others.Split(',')[0],
|
|
|
+ LineNumber = others.Split(',')[1],
|
|
|
+ BoardStatus = others.Split(',')[2],
|
|
|
+ PadID = GetValue(values, 0, headers, "PadID"),
|
|
|
+ ComponentID = GetValue(values, 1, headers, "ComponentID"),
|
|
|
+ Type = GetValue(values, 2, headers, "Type"),
|
|
|
+ AreaPercent = GetValue(values, 3, headers, "Area(%)"),
|
|
|
+ Height = GetValue(values, 4, headers, "Height"),
|
|
|
+ VolumePercent = GetValue(values, 5, headers, "Volume(%)"),
|
|
|
+ XOffset = GetValue(values, 6, headers, "XOffset"),
|
|
|
+ YOffset = GetValue(values, 7, headers, "YOffset"),
|
|
|
+ PadSizeX = GetValue(values, 8, headers, "PadSize(X)"),
|
|
|
+ PadSizeY = GetValue(values, 9, headers, "PadSize(Y)"),
|
|
|
+ Area = GetValue(values, 10, headers, "Area"),
|
|
|
+ HeightPercent = GetValue(values, 11, headers, "Height(%)"),
|
|
|
+ Volume = GetValue(values, 12, headers, "Volume"),
|
|
|
+ Result = GetValue(values, 13, headers, "Result"),
|
|
|
+ Errcode = GetValue(values, 14, headers, "Errcode"),
|
|
|
+ PinNum = GetValue(values, 15, headers, "PinNum"),
|
|
|
+ Barcode = GetValue(values, 16, headers, "Barcode"),
|
|
|
+ Date = GetValue(values, 17, headers, "Date"),
|
|
|
+ Time = GetValue(values, 18, headers, "Time"),
|
|
|
+ ArrayID = GetValue(values, 19, headers, "ArrayID")
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private PrintData MapToPriMacData(string fileName, string[] headers, string[] values, string others, int num)
|
|
|
+ {
|
|
|
+ return new PrintData
|
|
|
+ {
|
|
|
+ BarCode = GetValue(values, 0, headers, "BarCode"),
|
|
|
+ TimeStamp = GetValue(values, 1, headers, "TimeStamp"),
|
|
|
+ FileName = GetValue(values, 2, headers, "FileName"),
|
|
|
+ ProgramRunning = GetValue(values, 3, headers, "ProgramRunning"),
|
|
|
+
|
|
|
+ CycleTime = GetValue(values, 7, headers, "CycleTime"),
|
|
|
+ _2DSPIResult = GetValue(values, 8, headers, "_2DSPIResult"),
|
|
|
+ PrintSpeed = GetValue(values, 9, headers, "PrintSpeed"),
|
|
|
+ FrontSQGPress = GetValue(values, 10, headers, "FrontSQGPress"),
|
|
|
+ RearSQGPress = GetValue(values, 11, headers, "RearSQGPress"),
|
|
|
+ PrintMode = GetValue(values, 12, headers, "PrintMode"),
|
|
|
+
|
|
|
+ SnapOffDistance = GetValue(values, 14, headers, "SnapOffDistance"),
|
|
|
+ SnapOffSpeed = GetValue(values, 15, headers, "SnapOffSpeed"),
|
|
|
+ SnapOffDelay = GetValue(values, 16, headers, "SnapOffDelay"),
|
|
|
+ SQGUpSpeed = GetValue(values, 17, headers, "SQGUpSpeed"),
|
|
|
+ SQGDownSpeed = GetValue(values, 18, headers, "SQGDownSpeed"),
|
|
|
+ SQGUpFirst = GetValue(values, 19, headers, "SQGUpFirst"),
|
|
|
+ SQGHeightAtSnapOff = GetValue(values, 20, headers, "SQGHeightAtSnapOff"),
|
|
|
+ CleaningAfterLastBoard = GetValue(values, 21, headers, "CleaningAfterLastBoard"),
|
|
|
+ CleaningFrequency = GetValue(values, 22, headers, "CleaningFrequency"),
|
|
|
+ CleaningSpeed = GetValue(values, 23, headers, "CleaningSpeed"),
|
|
|
+
|
|
|
+
|
|
|
+ CleaningType = GetValue(values, 25, headers, "CleaningType"),
|
|
|
+ AddSPMode = GetValue(values, 26, headers, "AddSPMode"),
|
|
|
+
|
|
|
+ PrintDirection = GetValue(values, 29, headers, "PrintDirection"),
|
|
|
+ PCBSize = GetValue(values, 30, headers, "PCBSize"),
|
|
|
+ TableUpX = GetValue(values, 31, headers, "TableUpX"),
|
|
|
+ TableUpY1 = GetValue(values, 32, headers, "TableUpY1"),
|
|
|
+ TableUpY2 = GetValue(values, 33, headers, "TableUpY2"),
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Encoding DetectFileEncoding(string filePath)
|
|
|
+ {
|
|
|
+ byte[] bom = new byte[4];
|
|
|
+ using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
|
|
+ {
|
|
|
+ file.Read(bom, 0, 4);
|
|
|
+ }
|
|
|
+ if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) return Encoding.UTF8;
|
|
|
+ if (bom[0] == 0xff && bom[1] == 0xfe) return Encoding.Unicode;
|
|
|
+ if (bom[0] == 0xfe && bom[1] == 0xff) return Encoding.BigEndianUnicode;
|
|
|
+ if (bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff) return Encoding.UTF32;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string content = File.ReadAllText(filePath, Encoding.UTF8);
|
|
|
+ return Encoding.UTF8;
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return Encoding.GetEncoding("GB2312");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string GetValue(string[] values, int index, string[] headers, string expectedHeader)
|
|
|
+ {
|
|
|
+ if (index >= values.Length || index >= headers.Length || headers[index] != expectedHeader) return string.Empty;
|
|
|
+
|
|
|
+ return values[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ private class Log
|
|
|
+ {
|
|
|
+ public string SN { set; get; }
|
|
|
+ public string Result { set; get; }
|
|
|
+ /*public List<NgData> Details { set; get; }*/
|
|
|
+ public string Details { set; get; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class MachineList
|
|
|
+ {
|
|
|
+ public string MachineName { set; get; }
|
|
|
+
|
|
|
+ public string Part { set; get; }
|
|
|
+ public string Station { set; get; }
|
|
|
+ public string ReelNo { set; get; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class SpiData
|
|
|
+ {
|
|
|
+ public string FileName { get; set; }
|
|
|
+ public string ModelName { get; set; }
|
|
|
+ public string LineNumber { get; set; }
|
|
|
+ public string BoardStatus { get; set; }
|
|
|
+ public string PadID { get; set; }
|
|
|
+ public string ComponentID { get; set; }
|
|
|
+ public string Type { get; set; }
|
|
|
+ public string AreaPercent { get; set; }
|
|
|
+ public string Height { get; set; }
|
|
|
+ public string VolumePercent { get; set; }
|
|
|
+ public string XOffset { get; set; }
|
|
|
+ public string YOffset { get; set; }
|
|
|
+ public string PadSizeX { get; set; }
|
|
|
+ public string PadSizeY { get; set; }
|
|
|
+ public string Area { get; set; }
|
|
|
+ public string HeightPercent { get; set; }
|
|
|
+ public string Volume { get; set; }
|
|
|
+ public string Result { get; set; }
|
|
|
+ public string Errcode { get; set; }
|
|
|
+ public string PinNum { get; set; }
|
|
|
+ public string Barcode { get; set; }
|
|
|
+ public string Date { get; set; }
|
|
|
+ public string Time { get; set; }
|
|
|
+ public string ArrayID { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class PrintData
|
|
|
+ {
|
|
|
+ public string BarCode { get; set; }
|
|
|
+ public string TimeStamp { get; set; }
|
|
|
+ public string FileName { get; set; }
|
|
|
+ public string ProgramRunning { get; set; }
|
|
|
+
|
|
|
+ public string CycleTime { get; set; }
|
|
|
+ public string _2DSPIResult { get; set; }
|
|
|
+ public string PrintSpeed { get; set; }
|
|
|
+ public string FrontSQGPress { get; set; }
|
|
|
+ public string RearSQGPress { get; set; }
|
|
|
+ public string PrintMode { get; set; }
|
|
|
+
|
|
|
+ public string SnapOffDistance { get; set; }
|
|
|
+ public string SnapOffSpeed { get; set; }
|
|
|
+ public string SnapOffDelay { get; set; }
|
|
|
+ public string SQGUpSpeed { get; set; }
|
|
|
+ public string SQGDownSpeed { get; set; }
|
|
|
+ public string SQGUpFirst { get; set; }
|
|
|
+ public string SQGHeightAtSnapOff { get; set; }
|
|
|
+ public string CleaningAfterLastBoard { get; set; }
|
|
|
+ public string CleaningFrequency { get; set; }
|
|
|
+ public string CleaningSpeed { get; set; }
|
|
|
+
|
|
|
+ public string CleaningType { get; set; }
|
|
|
+ public string AddSPMode { get; set; }
|
|
|
+
|
|
|
+ public string PrintDirection { get; set; }
|
|
|
+ public string PCBSize { get; set; }
|
|
|
+ public string TableUpX { get; set; }
|
|
|
+ public string TableUpY1 { get; set; }
|
|
|
+ public string TableUpY2 { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
private PrinterData ReadWithXmlReader(string filePath)
|
|
|
{
|
|
|
PrinterData data = new PrinterData();
|
|
|
@@ -560,6 +947,7 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
return data;
|
|
|
}
|
|
|
+
|
|
|
private void ReadPanelData(XmlReader reader, Panel panel)
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
@@ -594,6 +982,7 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void ReadProcessData(XmlReader reader, Process process)
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
@@ -620,150 +1009,6 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public List<MachineList> ParseXml(string xmlContent)
|
|
|
- {
|
|
|
- List<MachineList> result = new List<MachineList>();
|
|
|
- try
|
|
|
- {
|
|
|
- XmlDocument xmlDoc = new XmlDocument();
|
|
|
- xmlDoc.LoadXml(xmlContent);
|
|
|
-
|
|
|
- XmlNode machineNode = xmlDoc.SelectSingleNode("//TotalProductionInfo");
|
|
|
- string machineName = machineNode?.Attributes["MachineName"]?.Value ?? "Unknown";
|
|
|
- string part = machineNode?.Attributes["ProductionProgramName"]?.Value ?? "Unknown";
|
|
|
-
|
|
|
- XmlNodeList feederNodes = xmlDoc.SelectNodes("//FeederProductionManageInfo");
|
|
|
- foreach (XmlNode feederNode in feederNodes)
|
|
|
- {
|
|
|
- MachineList machineList = new MachineList();
|
|
|
- string feederBankPosition = feederNode.Attributes["FeederBankPosition"]?.Value ?? "Unknown";
|
|
|
- string holeNo = feederNode.Attributes["HoleNo"]?.Value ?? "Unknown";
|
|
|
- string componentName = feederNode.Attributes["ComponentName"]?.Value ?? "Unknown";
|
|
|
-
|
|
|
- machineList.MachineName = machineName;
|
|
|
- machineList.Part = part;
|
|
|
- machineList.ReelNo = componentName;
|
|
|
- machineList.Station = $"{machineName}-{feederBankPosition[0]}-{holeNo}";
|
|
|
- result.Add(machineList);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogMessage($"Error parsing XML: {ex.Message}");
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public List<MesData> ParseCsvFile(string filePath)
|
|
|
- {
|
|
|
- var mesDataList = new List<MesData>();
|
|
|
- try
|
|
|
- {
|
|
|
- string fileName = Path.GetFileName(filePath);
|
|
|
-
|
|
|
- var lines = File.ReadAllLines(filePath);
|
|
|
-
|
|
|
- if (lines.Length == 0)
|
|
|
- return mesDataList;
|
|
|
-
|
|
|
- for (int i = 0; i < lines.Length; i++)
|
|
|
- {
|
|
|
- var values = ParseCsvLine(lines[i]);
|
|
|
- var mesData = new MesData
|
|
|
- {
|
|
|
- FileName = fileName,
|
|
|
- ModelName = GetValue(values, 0),
|
|
|
- LineNumber = GetValue(values, 1),
|
|
|
- BoardStatus = GetValue(values, 2),
|
|
|
- BoardBarcode = GetValue(values, 3),
|
|
|
- ArrayID = GetValue(values, 4),
|
|
|
- ArrayStatus = GetValue(values, 5),
|
|
|
- ArrayBarcode = GetValue(values, 6),
|
|
|
- DateTime = GetValue(values, 7),
|
|
|
- PadID = GetValue(values, 8),
|
|
|
- ComponentID = GetValue(values, 9),
|
|
|
- Type = GetValue(values, 10),
|
|
|
- AreaPercent = GetValue(values, 11),
|
|
|
- Height = GetValue(values, 12),
|
|
|
- VolumePercent = GetValue(values, 13),
|
|
|
- XOffset = GetValue(values, 14),
|
|
|
- YOffset = GetValue(values, 15),
|
|
|
- PadSizeX = GetValue(values, 16),
|
|
|
- PadSizeY = GetValue(values, 17),
|
|
|
- Area = GetValue(values, 18),
|
|
|
- HeightPercent = GetValue(values, 19),
|
|
|
- Volume = GetValue(values, 20),
|
|
|
- Result = GetValue(values, 21),
|
|
|
- Errcode = GetValue(values, 22),
|
|
|
- PinNum = GetValue(values, 23),
|
|
|
- Barcode = GetValue(values, 24),
|
|
|
- Date = GetValue(values, 25),
|
|
|
- Time = GetValue(values, 26),
|
|
|
- ArrayID2 = GetValue(values, 27)
|
|
|
- };
|
|
|
- mesDataList.Add(mesData);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogMessage($"解析csv文件报错,{ex.Message}");
|
|
|
- }
|
|
|
-
|
|
|
- return mesDataList;
|
|
|
- }
|
|
|
- private string[] ParseCsvLine(string line)
|
|
|
- {
|
|
|
- List<string> values = new List<string>();
|
|
|
- bool inQuotes = false;
|
|
|
- int startIndex = 0;
|
|
|
- for (int i = 0; i < line.Length; i++)
|
|
|
- {
|
|
|
- if (line[i] == '"')
|
|
|
- {
|
|
|
- inQuotes = !inQuotes;
|
|
|
- }
|
|
|
- else if (line[i] == ',' && !inQuotes)
|
|
|
- {
|
|
|
- string value = line.Substring(startIndex, i - startIndex).Trim('"');
|
|
|
- values.Add(value);
|
|
|
- startIndex = i + 1;
|
|
|
- }
|
|
|
- }
|
|
|
- string lastValue = line.Substring(startIndex).Trim('"');
|
|
|
- values.Add(lastValue);
|
|
|
-
|
|
|
- return values.ToArray();
|
|
|
- }
|
|
|
- private string GetValue(string[] values, int index)
|
|
|
- {
|
|
|
- return index < values.Length ? values[index] : string.Empty;
|
|
|
- }
|
|
|
- private class Log
|
|
|
- {
|
|
|
- public string SN { set; get; }
|
|
|
- public string Result { set; get; }
|
|
|
- /*public List<NgData> Details { set; get; }*/
|
|
|
- public string Details { set; get; }
|
|
|
- }
|
|
|
-
|
|
|
- public class MachineList
|
|
|
- {
|
|
|
- public string MachineName { set; get; }
|
|
|
-
|
|
|
- public string Part { set; get; }
|
|
|
- public string Station { set; get; }
|
|
|
- public string ReelNo { set; get; }
|
|
|
- }
|
|
|
-
|
|
|
- private class NgData
|
|
|
- {
|
|
|
- public string Code { set; get; }
|
|
|
-
|
|
|
- public List<string> Local { set; get; }
|
|
|
- }
|
|
|
-
|
|
|
private class PrinterData
|
|
|
{
|
|
|
public string SN { get; set; }
|
|
|
@@ -790,43 +1035,5 @@ namespace UAS_MES_NEW.Make
|
|
|
public string LineNumber { get; set; }
|
|
|
public string StencilNum { get; set; }
|
|
|
}
|
|
|
-
|
|
|
- public class MesData
|
|
|
- {
|
|
|
- public string FileName { get; set; }
|
|
|
- public string ModelName { get; set; }
|
|
|
- public string LineNumber { get; set; }
|
|
|
- public string BoardStatus { get; set; }
|
|
|
- public string BoardBarcode { get; set; }
|
|
|
- public string ArrayID { get; set; }
|
|
|
- public string ArrayStatus { get; set; }
|
|
|
- public string ArrayBarcode { get; set; }
|
|
|
- public string DateTime { get; set; }
|
|
|
- public string PadID { get; set; }
|
|
|
- public string ComponentID { get; set; }
|
|
|
- public string Type { get; set; }
|
|
|
- public string AreaPercent { get; set; }
|
|
|
- public string Height { get; set; }
|
|
|
- public string VolumePercent { get; set; }
|
|
|
- public string XOffset { get; set; }
|
|
|
- public string YOffset { get; set; }
|
|
|
- public string PadSizeX { get; set; }
|
|
|
- public string PadSizeY { get; set; }
|
|
|
- public string Area { get; set; }
|
|
|
- public string HeightPercent { get; set; }
|
|
|
- public string Volume { get; set; }
|
|
|
- public string Result { get; set; }
|
|
|
- public string Errcode { get; set; }
|
|
|
- public string PinNum { get; set; }
|
|
|
- public string Barcode { get; set; }
|
|
|
- public string Date { get; set; }
|
|
|
- public string Time { get; set; }
|
|
|
- public string ArrayID2 { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
- private void claerBtn_Click(object sender, EventArgs e)
|
|
|
- {
|
|
|
- lstFiles.Items.Clear();
|
|
|
- }
|
|
|
}
|
|
|
}
|