|
|
@@ -1,4 +1,6 @@
|
|
|
-using DevExpress.XtraPrinting;
|
|
|
+using BarTender;
|
|
|
+using DevExpress.Xpo.Logger;
|
|
|
+using DevExpress.XtraPrinting;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
@@ -6,11 +8,17 @@ using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Security;
|
|
|
+using System.Security.AccessControl;
|
|
|
+using System.Security.Principal;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Web.Services.Description;
|
|
|
+using System.Web.UI.WebControls;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Xml;
|
|
|
+using UAS_MES_NEW.CustomControl.ButtonUtil;
|
|
|
+using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
|
|
|
using UAS_MES_NEW.DataOperate;
|
|
|
using UAS_MES_NEW.Entity;
|
|
|
using UAS_MES_NEW.PublicMethod;
|
|
|
@@ -24,19 +32,86 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
+ LogStringBuilder sql = new LogStringBuilder();
|
|
|
+ DataTable Dbfind;
|
|
|
+ DataTable dt;
|
|
|
+
|
|
|
DataHelper dh;
|
|
|
+ string currFileType = "";
|
|
|
+
|
|
|
+ string SN,omakeCode, oMsid, oErrorMessage= "";
|
|
|
+ string equiType = "";
|
|
|
private void Make_ParseLog_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
dh = SystemInf.dh;
|
|
|
+
|
|
|
+ //设置锁定工单
|
|
|
+ LockMakeCode.GetMakeCodeCtl(ma_code);
|
|
|
+ ma_code.SetLockCheckBox(LockMakeCode);
|
|
|
+ //工单号放大镜配置
|
|
|
+ ma_code.TableName = "make left join product on ma_prodcode=pr_code";
|
|
|
+ ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
|
|
|
+ ma_code.FormName = Name;
|
|
|
+ ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
|
|
|
+ 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;
|
|
|
+ BaseUtil.SetFormValue(this.Controls, Dbfind);
|
|
|
+ //获取工单的其他信息
|
|
|
+ sql.Clear();
|
|
|
+ sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
|
|
|
+ sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
|
|
|
+ sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
|
|
|
+ dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ BaseUtil.SetFormValue(this.Controls, dt);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
private void Device_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
+ if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ {
|
|
|
+ Device.SelectedIndex = -1;
|
|
|
+ MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
txtPath.Focus();
|
|
|
txtPath.SelectAll();
|
|
|
}
|
|
|
-
|
|
|
+ private void allParse_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ {
|
|
|
+ MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Device.SelectedIndex == -1)
|
|
|
+ {
|
|
|
+ Device.Focus();
|
|
|
+ Device.SelectAll();
|
|
|
+ MessageBox.Show(this.ParentForm, "请选择设备", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (String.IsNullOrEmpty(txtPath.Text))
|
|
|
+ {
|
|
|
+ txtPath.Focus();
|
|
|
+ txtPath.SelectAll();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ RefreshFileList();
|
|
|
+ }
|
|
|
private void Choose_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
+ if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ {
|
|
|
+ MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (Device.SelectedIndex == -1)
|
|
|
{
|
|
|
Device.Focus();
|
|
|
@@ -50,20 +125,55 @@ namespace UAS_MES_NEW.Make
|
|
|
txtPath.SelectAll();
|
|
|
}
|
|
|
try {
|
|
|
- OpenFileDialog dialog = new OpenFileDialog();
|
|
|
- /*dialog.Multiselect = true;//该值确定是否可以选择多个文件*/
|
|
|
+ FolderBrowserDialog dialog = new FolderBrowserDialog();
|
|
|
switch (Device.SelectedIndex)
|
|
|
{
|
|
|
case 0:
|
|
|
- dialog.Title = "请选择读取SPI设备文本文件";
|
|
|
- dialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
|
|
|
+ dialog.Description = "请选择读取SPI设备文件夹";
|
|
|
+ currFileType = "txt";
|
|
|
+ equiType = "1";
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ dialog.Description = "请选择读取AOI设备文本文件";
|
|
|
+ currFileType = "txt";
|
|
|
+ equiType = "2";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ dialog.Description = "请选择读取印刷机设备的文本文件夹";
|
|
|
+ currFileType = "xml";
|
|
|
+ equiType = "3";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
+ {
|
|
|
+ txtPath.Text = dialog.SelectedPath;
|
|
|
+ txtPath.Enabled = false;
|
|
|
+ Device.Enabled = false;
|
|
|
+ var watcher = new FileSystemWatcher(txtPath.Text);
|
|
|
+ watcher.Filter = $"*.{currFileType}";
|
|
|
+ watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
|
|
|
+ watcher.Created += OnFileCreated;
|
|
|
+ /*watcher.Changed += OnFileChanged;
|
|
|
+ watcher.Deleted += OnFileChanged;
|
|
|
+ watcher.Renamed += OnFileChanged;*/
|
|
|
+ watcher.EnableRaisingEvents = true;
|
|
|
+ }
|
|
|
+ #region
|
|
|
+ /*OpenFileDialog dialog = new OpenFileDialog();
|
|
|
+ dialog.Multiselect = true;//该值确定是否可以选择多个文件
|
|
|
+ dialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
|
|
|
+ switch (Device.SelectedIndex)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ dialog.Title = "请选择读取SPI设备文件夹";
|
|
|
+ dialog.Filter = "All files (*.*)|*.*";
|
|
|
break;
|
|
|
case 1:
|
|
|
dialog.Title = "请选择读取AOI设备文本文件";
|
|
|
- dialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
|
|
|
+ dialog.Filter = "All files (*.*)|*.*";
|
|
|
break;
|
|
|
case 2:
|
|
|
- dialog.Title = "请选择读取印刷机设备的文本文件";
|
|
|
+ dialog.Title = "请选择读取印刷机设备的文本文件夹";
|
|
|
dialog.Filter = "文本文件 (*.xml)|*.xml|All files (*.*)|*.*";
|
|
|
break;
|
|
|
}
|
|
|
@@ -93,13 +203,77 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
PrinterData xmlData = ReadWithXmlReader(txtPath.Text);
|
|
|
Console.WriteLine();
|
|
|
- }
|
|
|
+ }*/
|
|
|
+ #endregion
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
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)
|
|
|
+ {
|
|
|
+ RefreshFileList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void RefreshFileList()
|
|
|
+ {
|
|
|
+ // 在UI线程上执行更新
|
|
|
+ if (lstFiles.InvokeRequired)
|
|
|
+ {
|
|
|
+ lstFiles.Invoke(new Action(RefreshFileList));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(txtPath.Text))
|
|
|
+ {
|
|
|
+ LogMessage($"目录不存在: {txtPath.Text}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ {
|
|
|
+ ParseLogInsert(file);
|
|
|
+ Console.WriteLine();
|
|
|
+ }
|
|
|
+ else if (Device.SelectedIndex == 1) // AOI
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (Device.SelectedIndex == 2) // 印刷机
|
|
|
+ {
|
|
|
+ PrinterData xmlData = ReadWithXmlReader(file);
|
|
|
+ Console.WriteLine();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LogMessage($"共找到{txtFiles.Length}个{currFileType.ToUpper()}文件");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogMessage($"刷新文件列表时出错: {ex.Message}");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void ParseLogInsert(string PathName)
|
|
|
{
|
|
|
@@ -110,10 +284,14 @@ namespace UAS_MES_NEW.Make
|
|
|
SR.Close();
|
|
|
SR.Dispose();
|
|
|
|
|
|
+ ConsoleLog(restOfStream, PathName);
|
|
|
+
|
|
|
List<Log> logArr = new List<Log>() { };
|
|
|
string[] lines = restOfStream.Split(new string[] { "\r\n" }, StringSplitOptions.None);
|
|
|
- foreach(var item in lines)
|
|
|
+ LogMessage($"文件夹{PathName},共{lines.Length}条记录");
|
|
|
+ foreach (var item in lines)
|
|
|
{
|
|
|
+ if (string.IsNullOrEmpty(item)) continue;
|
|
|
string[] currItem = item.Split(',');
|
|
|
string res = "";
|
|
|
/*List<NgData> data = new List<NgData>();*/
|
|
|
@@ -145,15 +323,20 @@ namespace UAS_MES_NEW.Make
|
|
|
Details = currItem[1]
|
|
|
};
|
|
|
logArr.Add(itemLog);
|
|
|
+
|
|
|
+ LogMessage($"已解析: {currItem[0]}");
|
|
|
}
|
|
|
- InsertDb(logArr);
|
|
|
+ InsertDb(logArr, PathName);
|
|
|
+
|
|
|
+ File.WriteAllText(PathName, string.Empty);
|
|
|
+ File.Delete(PathName);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MessageBox.Show(this.ParentForm, ex.Message, "警告");
|
|
|
}
|
|
|
}
|
|
|
- private void InsertDb(List<Log> logs)
|
|
|
+ private void InsertDb(List<Log> logs, string PathName)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
@@ -162,8 +345,8 @@ namespace UAS_MES_NEW.Make
|
|
|
List<string> param = new List<string>() { };
|
|
|
foreach (var item in logs)
|
|
|
{
|
|
|
- ConsoleLog(item);
|
|
|
param.Add(item.SN);
|
|
|
+ param.Add(ma_code.Text);
|
|
|
if (item.Result == "PASS")
|
|
|
{
|
|
|
param.Add(item.Result);
|
|
|
@@ -172,6 +355,7 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
param.Add(item.Result);
|
|
|
}
|
|
|
+ param.Add(equiType);
|
|
|
param.Add(item.Details);
|
|
|
param.Add(User.UserCode);
|
|
|
param.Add(User.UserSourceCode);
|
|
|
@@ -180,8 +364,32 @@ namespace UAS_MES_NEW.Make
|
|
|
param.Add(res);
|
|
|
string[] paramList = param.ToArray();
|
|
|
dh.CallProcedure("cs_insert_testrejects", ref paramList);
|
|
|
- Console.WriteLine(res);
|
|
|
param.Clear();
|
|
|
+
|
|
|
+ if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, item.SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
|
|
|
+ {
|
|
|
+ if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, item.SN, "日志解析", "OK", User.UserCode, out oErrorMessage))
|
|
|
+ {
|
|
|
+ if (oErrorMessage.Contains("AFTERSUCCESS")) LogMessage(">>" + oErrorMessage + "\n");
|
|
|
+ sql.Clear();
|
|
|
+ sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
|
|
|
+ sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
|
|
|
+ sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
|
|
|
+ dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
|
|
|
+ BaseUtil.SetFormValue(Controls, dt);
|
|
|
+ //记录日志
|
|
|
+ LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "日志解析", "日志解析成功", item.SN, "");
|
|
|
+ LogMessage("<<解析成功\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogMessage(">>" + oErrorMessage + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogMessage(">>" + oErrorMessage + "\n");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -190,11 +398,11 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void ConsoleLog(Log item)
|
|
|
+ private void ConsoleLog(string Content, string PathName)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- string sourceDir = Path.GetDirectoryName(txtPath.Text);
|
|
|
+ string sourceDir = Path.GetDirectoryName(PathName);
|
|
|
string newFolderName = "Logs";
|
|
|
string newFolderPath = Path.Combine(sourceDir, newFolderName);
|
|
|
|
|
|
@@ -202,18 +410,26 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
Directory.CreateDirectory(newFolderPath);
|
|
|
}
|
|
|
- string newFileName = "Log_" + Path.GetFileName(txtPath.Text);
|
|
|
+ string newFileName = "Log_" + Path.GetFileName(PathName);
|
|
|
string newFilePath = Path.Combine(newFolderPath, newFileName);
|
|
|
|
|
|
- string newContent = $"Time: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} SN:{item.SN},Result:{item.Result},NgDetails:{item.Details}\r\n";
|
|
|
- File.AppendAllText(newFilePath, newContent);
|
|
|
+ File.AppendAllText(newFilePath, Content + Environment.NewLine);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MessageBox.Show(this.ParentForm, ex.Message, "警告");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ private void LogMessage(string message)
|
|
|
+ {
|
|
|
+ if (lstFiles.InvokeRequired)
|
|
|
+ {
|
|
|
+ lstFiles.Invoke(new Action<string>(LogMessage), message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ lstFiles.Items.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
|
|
|
+ lstFiles.TopIndex = lstFiles.Items.Count - 1;
|
|
|
+ }
|
|
|
private PrinterData ReadWithXmlReader(string filePath)
|
|
|
{
|
|
|
PrinterData data = new PrinterData();
|
|
|
@@ -353,5 +569,9 @@ namespace UAS_MES_NEW.Make
|
|
|
public string StencilNum { get; set; }
|
|
|
}
|
|
|
|
|
|
+ private void claerBtn_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ lstFiles.Items.Clear();
|
|
|
+ }
|
|
|
}
|
|
|
}
|