|
|
@@ -1,4 +1,5 @@
|
|
|
using BarTender;
|
|
|
+using DevExpress.Utils.OAuth.Provider;
|
|
|
using DevExpress.Xpo.Logger;
|
|
|
using DevExpress.XtraEditors.Controls;
|
|
|
using DevExpress.XtraExport;
|
|
|
@@ -11,6 +12,7 @@ using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Net;
|
|
|
using System.Security;
|
|
|
using System.Security.AccessControl;
|
|
|
using System.Security.Principal;
|
|
|
@@ -26,6 +28,7 @@ using UAS_MES_NEW.DataOperate;
|
|
|
using UAS_MES_NEW.Entity;
|
|
|
using UAS_MES_NEW.PublicMethod;
|
|
|
using static DevExpress.Xpo.DB.DataStoreLongrunnersWatch;
|
|
|
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
|
|
|
|
|
|
namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
@@ -36,18 +39,21 @@ namespace UAS_MES_NEW.Make
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
|
- FileSystemWatcher watcher = new FileSystemWatcher();
|
|
|
+ FileSystemWatcher watcher;
|
|
|
|
|
|
LogStringBuilder sql = new LogStringBuilder();
|
|
|
DataTable Dbfind;
|
|
|
DataTable dt;
|
|
|
|
|
|
DataHelper dh;
|
|
|
- string currFileType = "";
|
|
|
+ string currFileType = "",equiType = "";
|
|
|
|
|
|
string SN, omakeCode, oMsid, oErrorMessage = "";
|
|
|
- string equiType = "";
|
|
|
List<string> fileList = new List<string>();
|
|
|
+
|
|
|
+ Timer formsTimer;
|
|
|
+ string outXmlFilePath;
|
|
|
+
|
|
|
private void Make_ParseLog_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
dh = SystemInf.dh;
|
|
|
@@ -56,8 +62,21 @@ namespace UAS_MES_NEW.Make
|
|
|
fileList.Add("D:\\EYSPI\\DataExport\\Res"); // 思泰克SPI
|
|
|
fileList.Add("E:\\MES_TEXT_PATH"); // AOI
|
|
|
fileList.Add("C:\\GKGPrintTemp"); // GKG印刷机
|
|
|
- fileList.Add("");
|
|
|
-
|
|
|
+ fileList.Add(""); // 贴片机
|
|
|
+ fileList.Add("D:\\JANETSSC\\SMT\\MachineMonitoring"); // JUKI贴片机
|
|
|
+
|
|
|
+ formsTimer = new Timer();
|
|
|
+ formsTimer.Interval = 10000;
|
|
|
+ formsTimer.Tick += timer1_Tick;
|
|
|
+ //outXmlFilePath = "C:\\Users\\MI\\Desktop\\贴片机\\outLogs";
|
|
|
+ outXmlFilePath = "D:\\JANETSSR";
|
|
|
+
|
|
|
+ watcher = new FileSystemWatcher();
|
|
|
+ watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
|
|
|
+ watcher.Created += OnFileCreated;
|
|
|
+ /*watcher.Changed += OnFileChanged;
|
|
|
+ watcher.Deleted += OnFileChanged;
|
|
|
+ watcher.Renamed += OnFileChanged;*/
|
|
|
|
|
|
//设置锁定工单
|
|
|
LockMakeCode.GetMakeCodeCtl(ma_code);
|
|
|
@@ -89,8 +108,40 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
private void Device_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2)
|
|
|
+ if (Device.SelectedIndex == -1) return;
|
|
|
+
|
|
|
+ switch (Device.SelectedIndex)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ currFileType = "txt";
|
|
|
+ equiType = "SPI";
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ currFileType = "csv";
|
|
|
+ equiType = "SPI";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ currFileType = "txt";
|
|
|
+ equiType = "AOI";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ currFileType = "csv";
|
|
|
+ equiType = "印刷机";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ currFileType = "xml";
|
|
|
+ equiType = "贴片机";
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ currFileType = "xml";
|
|
|
+ equiType = "贴片机";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2 || Device.SelectedIndex == 5)
|
|
|
{
|
|
|
+ txtPath.Text = fileList[Device.SelectedIndex];
|
|
|
+ ma_code.Text = "";
|
|
|
ma_code.Enabled = false;
|
|
|
txtPath.Focus();
|
|
|
txtPath.SelectAll();
|
|
|
@@ -99,6 +150,7 @@ namespace UAS_MES_NEW.Make
|
|
|
if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
{
|
|
|
Device.SelectedIndex = -1;
|
|
|
+ txtPath.Text = "";
|
|
|
MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
return;
|
|
|
}
|
|
|
@@ -140,12 +192,18 @@ namespace UAS_MES_NEW.Make
|
|
|
currFileType = "xml";
|
|
|
equiType = "贴片机";
|
|
|
break;
|
|
|
+ case 5:
|
|
|
+ dialog.Description = "请选择读取JUKI贴片机的文本文件夹";
|
|
|
+ currFileType = "xml";
|
|
|
+ equiType = "贴片机";
|
|
|
+ break;
|
|
|
}
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
txtPath.Text = dialog.SelectedPath;
|
|
|
txtPath.Enabled = false;
|
|
|
Device.Enabled = false;
|
|
|
+ watcher.EnableRaisingEvents = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -155,10 +213,13 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
private void allParse_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ if (Device.SelectedIndex == 0 || Device.SelectedIndex == 1 || Device.SelectedIndex == 3)
|
|
|
{
|
|
|
- MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
- return;
|
|
|
+ if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ {
|
|
|
+ MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
if (Device.SelectedIndex == -1)
|
|
|
{
|
|
|
@@ -176,7 +237,7 @@ namespace UAS_MES_NEW.Make
|
|
|
string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
|
|
|
if (txtFiles.Length == 0)
|
|
|
{
|
|
|
- LogMessage($"当前{txtPath.Text},没有{currFileType.ToUpper()}格式文件");
|
|
|
+ LogMessage($"当前{txtPath.Text},没有{equiType}设备{currFileType.ToUpper()}文件");
|
|
|
return;
|
|
|
}
|
|
|
RefreshFileList();
|
|
|
@@ -184,10 +245,13 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
private void onWatch_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ if (Device.SelectedIndex == 0 || Device.SelectedIndex == 1 || Device.SelectedIndex == 3)
|
|
|
{
|
|
|
- MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
- return;
|
|
|
+ if (string.IsNullOrEmpty(ma_code.Text))
|
|
|
+ {
|
|
|
+ MessageBox.Show(this.ParentForm, "请选择工单", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
if (Device.SelectedIndex == -1)
|
|
|
{
|
|
|
@@ -211,25 +275,85 @@ namespace UAS_MES_NEW.Make
|
|
|
currFileType = txtFiles.Length > csvFiles.Length ? "txt" : "csv";
|
|
|
watcher.Filter = $"*.{currFileType}";*/
|
|
|
#endregion
|
|
|
-
|
|
|
watcher.Path = txtPath.Text;
|
|
|
watcher.Filter = $"*.{currFileType}";
|
|
|
- watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
|
|
|
- watcher.Created += OnFileCreated;
|
|
|
- /*watcher.Changed += OnFileChanged;
|
|
|
- watcher.Deleted += OnFileChanged;
|
|
|
- watcher.Renamed += OnFileChanged;*/
|
|
|
|
|
|
if (onWatch.Text == "开启解析")
|
|
|
{
|
|
|
watcher.EnableRaisingEvents = true;
|
|
|
onWatch.Text = "关闭解析";
|
|
|
+
|
|
|
+ if (Device.SelectedIndex == 5) // JUKI贴片机
|
|
|
+ {
|
|
|
+ formsTimer.Start();
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
watcher.EnableRaisingEvents = false;
|
|
|
- watcher.Dispose();
|
|
|
+ //watcher.Dispose();
|
|
|
onWatch.Text = "开启解析";
|
|
|
+ formsTimer.Stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(this.ParentForm, ex.Message, "警告");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void timer1_Tick(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ sql.Clear();
|
|
|
+ sql.Append($@"SELECT dd_date,dd_name,dd_status,dd_id FROM devicedata WHERE dd_status = 0");
|
|
|
+ dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ string currentDate = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
+ XmlWriterSettings settings = new XmlWriterSettings
|
|
|
+ {
|
|
|
+ Indent = true,
|
|
|
+ Encoding = System.Text.Encoding.UTF8
|
|
|
+ };
|
|
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ var hasFileAry = Directory.GetFiles(outXmlFilePath, $"*.{currFileType}");
|
|
|
+ string xmlName;
|
|
|
+ if (hasFileAry.Length > 0)
|
|
|
+ {
|
|
|
+ var lastFile = Directory.GetFiles(outXmlFilePath).Select(f => new FileInfo(f))
|
|
|
+ .Where(f => f.CreationTime.Date == DateTime.Today)
|
|
|
+ .OrderByDescending(f => f.CreationTime).FirstOrDefault().Name;
|
|
|
+
|
|
|
+ string seqNumStr = lastFile.Substring(lastFile.Length - 7, 3);
|
|
|
+ string fileSeqNum = (int.Parse(seqNumStr) + 1).ToString().PadLeft(seqNumStr.Length, '0'); ;
|
|
|
+ xmlName = $"1.08_{currentDate}_{currentDate}{fileSeqNum}.xml";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ xmlName = $"1.08_{currentDate}_{currentDate}001.xml";
|
|
|
+ }
|
|
|
+ string fullPath = Path.Combine(outXmlFilePath, xmlName);
|
|
|
+
|
|
|
+ using (XmlWriter writer = XmlWriter.Create(fullPath, settings))
|
|
|
+ {
|
|
|
+ writer.WriteStartDocument();
|
|
|
+ writer.WriteStartElement("RequestTotalProductionInfo");
|
|
|
+ writer.WriteAttributeString("MachineName", dr["dd_name"].ToString());
|
|
|
+ writer.WriteEndElement();
|
|
|
+ writer.WriteEndDocument();
|
|
|
+ }
|
|
|
+ if (File.Exists(fullPath))
|
|
|
+ {
|
|
|
+ File.ReadAllText(fullPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ sql.Clear();
|
|
|
+ sql.Append($"UPDATE devicedata SET dd_status = -1 WHERE dd_name = '{dr["dd_name"].ToString()}'");
|
|
|
+ dh.ExecuteSql(sql.GetString(), "update");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -237,7 +361,6 @@ namespace UAS_MES_NEW.Make
|
|
|
MessageBox.Show(this.ParentForm, ex.Message, "警告");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
|
|
|
private void OnFileCreated(object sender, FileSystemEventArgs e)
|
|
|
{
|
|
|
@@ -278,14 +401,62 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
foreach (string file in txtFiles)
|
|
|
{
|
|
|
+ if (!File.Exists(file))
|
|
|
+ {
|
|
|
+ LogMessage($"文件不存在: {file}");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if (Device.SelectedIndex == 0) // 劲拓SPI
|
|
|
{
|
|
|
- string fileType = Path.GetExtension(file).ToLower();
|
|
|
ParseLogInsert(file);
|
|
|
}
|
|
|
else if (Device.SelectedIndex == 1) // 思泰克SPI
|
|
|
{
|
|
|
- List<SpiData> csvData;
|
|
|
+ string fileName = Path.GetFileName(file);
|
|
|
+ string[] lines = File.ReadAllLines(file, Encoding.GetEncoding("GB2312"));
|
|
|
+
|
|
|
+ //string modelName = lines[1].Split(',')[0];
|
|
|
+ //string lineNumber = lines[1].Split(',')[1];
|
|
|
+ //string boardStatus = lines[2].Split(',')[1];
|
|
|
+ SN = lines[4].Split(',')[16];
|
|
|
+ if (string.IsNullOrEmpty(SN))
|
|
|
+ {
|
|
|
+ LogMessage($"文件: {file},无SN信息");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LogMessage($"文件: {file},开始上传");
|
|
|
+ if (UploadFileToFtp(file))
|
|
|
+ {
|
|
|
+ dh.ExecuteSql($@"insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class,std_testresult)
|
|
|
+ select STEPTESTDETAIL_seq.nextval,'{SN}','{ma_code.Text}',sysdate,'思泰克SPI',
|
|
|
+ 'http://112.48.67.154:8088/ftp/mes/TestData/{DateTime.Now.ToString("yyyyMMdd")}/{Path.GetFileName(file)}.xml' from dual", "insert");
|
|
|
+
|
|
|
+ string xmlContent = File.ReadAllText(file);
|
|
|
+ if (ConsoleLog(xmlContent, file))
|
|
|
+ {
|
|
|
+ File.Delete(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
|
|
|
+ {
|
|
|
+ if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, SN, "日志解析", "OK", User.UserCode, out oErrorMessage))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogMessage(">>" + oErrorMessage + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogMessage(">>" + oErrorMessage + "\n");
|
|
|
+ }*/
|
|
|
+
|
|
|
+ #region // 20250630 M 调整对接方式
|
|
|
+ /*List<SpiData> csvData;
|
|
|
//csvData = ParseCsvFile(file);
|
|
|
csvData = ParseCsvFile<SpiData>(file, MapToSpiData);
|
|
|
|
|
|
@@ -359,7 +530,8 @@ namespace UAS_MES_NEW.Make
|
|
|
if (ConsoleLog(xmlContent, file))
|
|
|
{
|
|
|
File.Delete(file);
|
|
|
- }
|
|
|
+ }*/
|
|
|
+ #endregion
|
|
|
}
|
|
|
else if (Device.SelectedIndex == 2) // AOI
|
|
|
{
|
|
|
@@ -439,7 +611,7 @@ namespace UAS_MES_NEW.Make
|
|
|
if (priMacData.Count == 0)
|
|
|
{
|
|
|
LogMessage($"文件: {file},读取记录 {priMacData.Count} 条");
|
|
|
- return;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
sql.Clear();
|
|
|
@@ -450,7 +622,7 @@ namespace UAS_MES_NEW.Make
|
|
|
std_value15,std_value16,
|
|
|
STD_TESTRESULT,std_value18,std_value19,std_value20,std_value21,
|
|
|
std_rescode)
|
|
|
- (select steptestdetail_seq.nextval,:BarCode,'{ma_code.Text}',to_date(:TimeStamp,'yyyy-mm-dd hh24:mi:ss'),:FileName,:ProgramRunning,
|
|
|
+ (select steptestdetail_seq.nextval,:BarCode,'{ma_code.Text}',to_date(:TimeStamp,'yyyy-mm-dd hh24:mi:ss'),'印刷机',:ProgramRunning,
|
|
|
:CycleTime,:DSPIResult2,:PrintSpeed,:FrontSQGPress,:RearSQGPress,:PrintMode,
|
|
|
:SnapOffDistance,:SnapOffSpeed,:SnapOffDelay,:SQGUpSpeed,:SQGDownSpeed,
|
|
|
:SQGUpFirst,:SQGHeightAtSnapOff,:CleaningAfterLastBoard,:CleaningFrequency,:CleaningSpeed,
|
|
|
@@ -459,13 +631,13 @@ namespace UAS_MES_NEW.Make
|
|
|
'{User.UserSourceCode}' from dual)");
|
|
|
|
|
|
dh.BatchInsert(sql.GetString(),
|
|
|
- new string[] { "BarCode", "TimeStamp", "FileName","ProgramRunning",
|
|
|
+ new string[] { "BarCode", "TimeStamp","ProgramRunning",
|
|
|
"CycleTime","DSPIResult_2","PrintSpeed","FrontSQGPress","RearSQGPress","PrintMode",
|
|
|
"SnapOffDistance","SnapOffSpeed","SnapOffDelay","SQGUpSpeed","SQGDownSpeed",
|
|
|
"SQGUpFirst","SQGHeightAtSnapOff","CleaningAfterLastBoard","CleaningFrequency","CleaningSpeed",
|
|
|
"CleaningType","AddSPMode",
|
|
|
"PrintDirection","PCBSize","TableUpX","TableUpY1","TableUpY2"},
|
|
|
- BarCode.ToArray(), TimeStamp.ToArray(), FileName.ToArray(), ProgramRunning.ToArray(),
|
|
|
+ BarCode.ToArray(), TimeStamp.ToArray(), ProgramRunning.ToArray(),
|
|
|
CycleTime.ToArray(), DSPIResult_2.ToArray(), PrintSpeed.ToArray(), FrontSQGPress.ToArray(), RearSQGPress.ToArray(), PrintMode.ToArray(),
|
|
|
SnapOffDistance.ToArray(), SnapOffSpeed.ToArray(), SnapOffDelay.ToArray(), SQGUpSpeed.ToArray(), SQGDownSpeed.ToArray(),
|
|
|
SQGUpFirst.ToArray(), SQGHeightAtSnapOff.ToArray(), CleaningAfterLastBoard.ToArray(), CleaningFrequency.ToArray(), CleaningSpeed.ToArray(),
|
|
|
@@ -479,18 +651,18 @@ namespace UAS_MES_NEW.Make
|
|
|
File.Delete(file);
|
|
|
}
|
|
|
}
|
|
|
- else if (Device.SelectedIndex == 4) // 贴片机
|
|
|
+ else if (Device.SelectedIndex == 4 || Device.SelectedIndex == 5) // 贴片机
|
|
|
{
|
|
|
- if (!File.Exists(file))
|
|
|
+ if (Device.SelectedIndex == 5 && !file.Contains("TotalProduction"))
|
|
|
{
|
|
|
- LogMessage($"文件不存在: {file}");
|
|
|
+ continue;
|
|
|
}
|
|
|
string xmlContent = File.ReadAllText(file);
|
|
|
var xmlList = ParseXml(xmlContent);
|
|
|
if (xmlList.Count == 0)
|
|
|
{
|
|
|
LogMessage($"文件: {file},读取记录 {xmlList.Count} 条");
|
|
|
- return;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
List<string> param = new List<string>() { };
|
|
|
@@ -532,7 +704,7 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
sql.Clear();
|
|
|
sql.Append("insert into productsmtlocation(PSL_ID, PSL_PSID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
|
|
|
- "select productsmtlocation_seq.nextval," + ps_id + ",:letArr, :ReelNo,:ReelNo,:Station,BD_BASEQTY,'' from bom@ERP " +
|
|
|
+ "select productsmtlocation_seq.nextval," + ps_id + ",:letArr, :ReelNo,:ReelNo,:Station,BD_BASEQTY,'A' from bom@ERP " +
|
|
|
"left join bomdetail@ERP on bo_id=bd_bomid where bo_mothercode='" + Part_ + "' and BD_SONCODE=:ReelNo");
|
|
|
dh.BatchInsert(sql.GetString(), new string[] { "letArr", "ReelNo", "ReelNo", "Station", "ReelNo" },
|
|
|
letNo.ToArray(), ReelNo.ToArray(), ReelNo.ToArray(), Station.ToArray(), ReelNo.ToArray());
|
|
|
@@ -553,6 +725,99 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public bool UploadFileToFtp(string localFilePath)
|
|
|
+ {
|
|
|
+ string ftpServer = "ftp://10.8.0.208:21/mes/TestData/";
|
|
|
+ string username = "vsftpd";
|
|
|
+ string password = "vsftpd3cd79018fl";
|
|
|
+
|
|
|
+ string currentDate = DateTime.Now.ToString("yyyyMMdd");
|
|
|
+
|
|
|
+ string ftpFullPath = $"{ftpServer.TrimEnd('/')}/{currentDate}";
|
|
|
+ string outResult = CreateFtpDirectoryIfNotExists(ftpFullPath, username, password);
|
|
|
+ if (outResult.Substring(0, 2) == "NG")
|
|
|
+ {
|
|
|
+ LogMessage(outResult);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ string remoteFileName = Path.GetFileName(localFilePath);
|
|
|
+ string uri = $"{ftpFullPath}/{remoteFileName}";
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var request = (FtpWebRequest)WebRequest.Create(uri);
|
|
|
+ request.Method = WebRequestMethods.Ftp.UploadFile;
|
|
|
+ request.Credentials = new NetworkCredential(username, password);
|
|
|
+ request.UsePassive = true;
|
|
|
+ request.UseBinary = true;
|
|
|
+ request.KeepAlive = false;
|
|
|
+
|
|
|
+ using (var fileStream = File.OpenRead(localFilePath))
|
|
|
+ using (var requestStream = request.GetRequestStream())
|
|
|
+ {
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
|
|
|
+ {
|
|
|
+ requestStream.Write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ using (var response = (FtpWebResponse)request.GetResponse())
|
|
|
+ {
|
|
|
+ LogMessage($"文件: {localFilePath}上传成功,状态{response.StatusDescription}");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (WebException ex)
|
|
|
+ {
|
|
|
+ if (ex.Response is FtpWebResponse response)
|
|
|
+ {
|
|
|
+ LogMessage($"FTP 错误码: {(int)response.StatusCode} - {response.StatusDescription}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogMessage("Web异常: " + ex.Message);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogMessage($"上传失败: " + ex.Message);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string CreateFtpDirectoryIfNotExists(string ftpDirectoryPath, string username, string password)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpDirectoryPath);
|
|
|
+ request.Method = WebRequestMethods.Ftp.MakeDirectory;
|
|
|
+ request.Credentials = new NetworkCredential(username, password);
|
|
|
+ request.UsePassive = true;
|
|
|
+ request.UseBinary = true;
|
|
|
+ request.KeepAlive = false;
|
|
|
+
|
|
|
+ using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
|
|
|
+ {
|
|
|
+ return "OK,目录创建成功: " + response.StatusDescription;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (WebException ex)
|
|
|
+ {
|
|
|
+ if (ex.Response is FtpWebResponse response && response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
|
|
|
+ {
|
|
|
+ return "OK,目录已存在: " + response.StatusDescription;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return "NG,创建目录时发生错误: " + ex.Message;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void ParseLogInsert(string PathName)
|
|
|
{
|
|
|
try
|
|
|
@@ -569,18 +834,33 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(item)) continue;
|
|
|
string[] currItem = item.Split(',');
|
|
|
- string res = "";
|
|
|
+ string res = "",wo = "";
|
|
|
if(equiType == "SPI")
|
|
|
{
|
|
|
res = currItem[1];
|
|
|
+ wo = ma_code.Text;
|
|
|
}
|
|
|
else if (equiType == "AOI")
|
|
|
{
|
|
|
res = currItem[3];
|
|
|
+
|
|
|
+ sql.Clear();
|
|
|
+ sql.Append($"SELECT a.li_code,b.dl_macode FROM line_ipaoi a, deviceline b WHERE a.ipaddress = '{currItem[2]}' AND a.li_code = b.dl_linecode");
|
|
|
+ dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ wo = dt.Rows[0]["dd_name"].ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogMessage($"IP:{currItem[2]},无对应线体工单");
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
Log itemLog = new Log()
|
|
|
{
|
|
|
SN = currItem[0],
|
|
|
+ work_order = wo,
|
|
|
Result = res,
|
|
|
Details = equiType == "SPI" ? currItem[1] : currItem[3]
|
|
|
};
|
|
|
@@ -636,7 +916,7 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
|
|
|
param.Add(item.SN);
|
|
|
- param.Add(ma_code.Text ?? omakeCode);
|
|
|
+ param.Add(item.work_order);
|
|
|
if (item.Result == "PASS")
|
|
|
{
|
|
|
param.Add(item.Result);
|
|
|
@@ -952,6 +1232,7 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
private class Log
|
|
|
{
|
|
|
+ public string work_order { get; set; }
|
|
|
public string SN { set; get; }
|
|
|
public string Result { set; get; }
|
|
|
/*public List<NgData> Details { set; get; }*/
|
|
|
@@ -1129,7 +1410,6 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
private class PrinterData
|
|
|
{
|