|
|
@@ -7,6 +7,7 @@ using System.Threading;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Xml;
|
|
|
using System.Text;
|
|
|
+using System.Media;
|
|
|
|
|
|
namespace FileWatcher
|
|
|
{
|
|
|
@@ -57,8 +58,6 @@ namespace FileWatcher
|
|
|
/// </summary>
|
|
|
List<string> _FileName = new List<string>();
|
|
|
|
|
|
- string master="WKS";
|
|
|
-
|
|
|
ftpOperater ftp = new ftpOperater();
|
|
|
|
|
|
public AutoAnalysisXml()
|
|
|
@@ -68,13 +67,12 @@ namespace FileWatcher
|
|
|
StartPosition = FormStartPosition.CenterScreen;
|
|
|
}
|
|
|
|
|
|
- public AutoAnalysisXml(string iUserName, string iSource,string iMaster)
|
|
|
+ public AutoAnalysisXml(string iUserName, string iSource)
|
|
|
{
|
|
|
tipform = new Tip();
|
|
|
InitializeComponent();
|
|
|
iusercode = iUserName;
|
|
|
isource = iSource.ToUpper();
|
|
|
- master = iMaster;
|
|
|
StartPosition = FormStartPosition.CenterScreen;
|
|
|
}
|
|
|
|
|
|
@@ -90,6 +88,10 @@ namespace FileWatcher
|
|
|
stw.StartPosition = FormStartPosition.CenterScreen;
|
|
|
stw.ShowDialog();
|
|
|
List<string> CacheInf = new List<string>();
|
|
|
+ DB = (DataTable)dh.ExecuteSql("select ms_pwd,ma_user,ma_address,ma_inneraddress from master where ma_user='MES'", "select");
|
|
|
+ Master.DataSource = DB;
|
|
|
+ Master.DisplayMember = "ma_user";
|
|
|
+ Master.ValueMember = "ma_user";
|
|
|
//获取缓存信息
|
|
|
try
|
|
|
{
|
|
|
@@ -99,6 +101,14 @@ namespace FileWatcher
|
|
|
//AutoStart.Checked = (bool)BaseUtil.GetCacheData("AutoStart");
|
|
|
}
|
|
|
catch (Exception ex) { MessageBox.Show(ex.Message); }
|
|
|
+ for (int i = 0; i < DB.Rows.Count; i++)
|
|
|
+ {
|
|
|
+ if (Master.Text == DB.Rows[i]["ma_user"].ToString())
|
|
|
+ {
|
|
|
+ DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=81.71.42.91)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
+ dh = new DataHelper();
|
|
|
+ }
|
|
|
+ }
|
|
|
//获取岗位资源相关信息
|
|
|
DataTable dt = (DataTable)dh.ExecuteSql("select sc_linecode,sc_stepcode,st_badgroupcode from source left join step on sc_stepcode=st_code where sc_code='" + isource + "'", "select");
|
|
|
if (dt.Rows.Count > 0)
|
|
|
@@ -111,7 +121,6 @@ namespace FileWatcher
|
|
|
|
|
|
private void ConnectDB()
|
|
|
{
|
|
|
- DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=" + master + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=81.71.42.91)(PORT=11678)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
dh = new DataHelper();
|
|
|
}
|
|
|
|
|
|
@@ -130,15 +139,15 @@ namespace FileWatcher
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- //for (int i = 0; i < DB.Rows.Count; i++)
|
|
|
- //{
|
|
|
- // if (Master.Text == DB.Rows[i]["ma_user"].ToString())
|
|
|
- // {
|
|
|
- // DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=81.71.42.91)(PORT=11678)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
- // dh = new DataHelper();
|
|
|
- // LogicHandler.dh = new DataHelper();
|
|
|
- // }
|
|
|
- //}
|
|
|
+ for (int i = 0; i < DB.Rows.Count; i++)
|
|
|
+ {
|
|
|
+ if (Master.Text == DB.Rows[i]["ma_user"].ToString())
|
|
|
+ {
|
|
|
+ DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=81.71.42.91)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
+ dh = new DataHelper();
|
|
|
+ LogicHandler.dh = new DataHelper();
|
|
|
+ }
|
|
|
+ }
|
|
|
//存在工单必须是已下放状态
|
|
|
if ((!dh.CheckExist("make", "ma_statuscode='STARTED' and ma_code='" + ma_code.Text + "'") || ma_code.Text == "") && Device.Text == "AOI设备")
|
|
|
{
|
|
|
@@ -153,8 +162,6 @@ namespace FileWatcher
|
|
|
//BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
|
|
|
//BaseUtil.SetCacheData("Master", Master.Text);
|
|
|
//BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
|
|
|
- Timer.Interval = 1000 * 10;
|
|
|
- Timer.Start();
|
|
|
//设置按钮不可点击
|
|
|
StartWatch.Enabled = false;
|
|
|
ChooseFolder.Enabled = false;
|
|
|
@@ -173,32 +180,32 @@ namespace FileWatcher
|
|
|
|
|
|
private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
|
|
|
{
|
|
|
- //while (true)
|
|
|
- //{
|
|
|
- // try
|
|
|
- // {
|
|
|
- // using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
- // {
|
|
|
- // if (stream != null)
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // catch (Exception ex)
|
|
|
- // {
|
|
|
- // Console.WriteLine(ex.Message);
|
|
|
- // }
|
|
|
- //}
|
|
|
- //switch (e.Name.Substring(e.Name.LastIndexOf(".") + 1).ToUpper())
|
|
|
- //{
|
|
|
- // case "TXT":
|
|
|
- // TxtHandleProcess(e.FullPath);
|
|
|
- // break;
|
|
|
- // case "XML":
|
|
|
- // XmlHandleProcess(e.FullPath);
|
|
|
- // break;
|
|
|
- // default:
|
|
|
- // break;
|
|
|
- //}
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
+ {
|
|
|
+ if (stream != null)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ switch (e.Name.Substring(e.Name.LastIndexOf(".") + 1).ToUpper())
|
|
|
+ {
|
|
|
+ case "TXT":
|
|
|
+ TxtHandleProcess(e.FullPath);
|
|
|
+ break;
|
|
|
+ case "XML":
|
|
|
+ XmlHandleProcess(e.FullPath);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
string nextLine;
|
|
|
private void TxtHandleProcess(string FileName)
|
|
|
@@ -260,7 +267,7 @@ namespace FileWatcher
|
|
|
{
|
|
|
Result = "NG";
|
|
|
//只添加一条记录
|
|
|
- if (badcode.Count == 0 && filedt.Rows[i]["w_ng_name"].ToString() != "")
|
|
|
+ if (badcode.Count == 0)
|
|
|
{
|
|
|
badcode.Add(filedt.Rows[i]["w_ng_name"].ToString());
|
|
|
badlocation.Add(filedt.Rows[i]["c_subboard_number"].ToString());
|
|
|
@@ -312,7 +319,7 @@ namespace FileWatcher
|
|
|
{
|
|
|
OperateResult.AppendText(oErrMessage + "\n");
|
|
|
tipform.startthread(oErrMessage, Result);
|
|
|
- //File.Delete(FileName);
|
|
|
+ File.Delete(FileName);
|
|
|
}
|
|
|
}
|
|
|
else if (Device.Text == "测试设备")
|
|
|
@@ -324,26 +331,123 @@ namespace FileWatcher
|
|
|
{
|
|
|
string folderpath = FileName.Substring(0, FileName.LastIndexOf(@"\"));
|
|
|
string SN = FileName.Substring(FileName.LastIndexOf(@"\") + 1).Replace("-", "/").ToUpper().Replace(".TXT", "");
|
|
|
- if (SN.Length == 12)
|
|
|
+ if (MAC.Checked)
|
|
|
{
|
|
|
- string ms_sncode = dh.getFieldDataByCondition("steppassed", "sp_sncode", "substr(sp_sncode,0,12)='" + SN + "' order by sp_id desc").ToString();
|
|
|
- string ms_makecode = dh.getFieldDataByCondition("steppassed", "sp_makecode", "substr(sp_sncode,0,12)='" + SN + "' order by sp_id desc").ToString();
|
|
|
+ string Result = "";
|
|
|
string makecode = ma_code.Text;
|
|
|
- string ftppath = "/"+master+"/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
|
|
|
- ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
|
|
|
- int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class)select STEPTESTDETAIL_seq.nextval,'"+ ms_sncode + "','"+ ms_makecode + "',sysdate,'http://81.71.42.91:8099/ftp" + ftppath + SN + ".txt" + "' from dual ", "insert").ToString());
|
|
|
- if (num > 0)
|
|
|
+ string oErrMessage = "";
|
|
|
+ string oMSID = "";
|
|
|
+ string ms_sncode = dh.getFieldDataByCondition("makeserial", "ms_sncode", "substr(ms_sncode,0,12)='" + SN + "' order by ms_id").ToString();
|
|
|
+ isource = "SMT_01_TEST01";
|
|
|
+ iusercode = "SMT_01_TEST01";
|
|
|
+ DataTable dt = (DataTable)dh.ExecuteSql("select sc_linecode,sc_stepcode,st_badgroupcode from source left join step on sc_stepcode=st_code where sc_code='" + isource + "'", "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ ilinecode = dt.Rows[0]["sc_linecode"].ToString();
|
|
|
+ istepcode = dt.Rows[0]["sc_stepcode"].ToString();
|
|
|
+ ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
|
|
|
+ }
|
|
|
+ if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, isource, ms_sncode, iusercode, out makecode, out oMSID, out oErrMessage))
|
|
|
+ {
|
|
|
+ ma_code.Text = makecode;
|
|
|
+ if (LogicHandler.SetStepResult(makecode, isource, ms_sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
|
|
|
+ ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
|
|
|
+ int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class)select STEPTESTDETAIL_seq.nextval,ms_sncode,ms_makecode,sysdate,'http://81.71.42.91:8099/ftp" + ftppath + SN + ".txt" + "' from makeserial where substr(ms_sncode,0,12)='" + SN + "'", "insert").ToString());
|
|
|
+ if (num > 0)
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("序列号:" + SN + "上传成功\n");
|
|
|
+ File.Delete(FileName);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("序列号: " + SN + "前工段未扫描\n");
|
|
|
+ MessageBox.Show("序列号: " + ms_sncode + "前工段未扫描", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OperateResult.AppendText(oErrMessage + "\n");
|
|
|
+ tipform.startthread(oErrMessage, Result);
|
|
|
+
|
|
|
+ }
|
|
|
+ tipform.startthread("序列号 " + ms_sncode + "通过检测", Result);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- OperateResult.AppendText("序列号:" + ms_sncode + "上传成功\n");
|
|
|
File.Delete(FileName);
|
|
|
+ OperateResult.AppendText(oErrMessage + "\n");
|
|
|
+ tipform.startthread(oErrMessage, Result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string Result = "";
|
|
|
+ string makecode = ma_code.Text;
|
|
|
+ string oErrMessage = "";
|
|
|
+ string oMSID = "";
|
|
|
+ string ms_sncode = dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_sncode='" + SN + "' order by ms_id").ToString();
|
|
|
+ isource = "SMT_01_TEST01";
|
|
|
+ iusercode = "SMT_01_TEST01";
|
|
|
+ DataTable dt = (DataTable)dh.ExecuteSql("select sc_linecode,sc_stepcode,st_badgroupcode from source left join step on sc_stepcode=st_code where sc_code='" + isource + "'", "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ ilinecode = dt.Rows[0]["sc_linecode"].ToString();
|
|
|
+ istepcode = dt.Rows[0]["sc_stepcode"].ToString();
|
|
|
+ ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
|
|
|
+ }
|
|
|
+ if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, isource, ms_sncode, iusercode, out makecode, out oMSID, out oErrMessage))
|
|
|
+ {
|
|
|
+ ma_code.Text = makecode;
|
|
|
+ if (LogicHandler.SetStepResult(makecode, isource, ms_sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
|
|
|
+ ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
|
|
|
+ int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class)select STEPTESTDETAIL_seq.nextval,ms_sncode,ms_makecode,sysdate,'http://81.71.42.91:8099/ftp" + ftppath + SN + ".txt" + "' from makeserial where ms_sncode='" + SN + "'", "insert").ToString());
|
|
|
+ if (num > 0)
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("序列号:" + SN + "上传成功\n");
|
|
|
+ File.Delete(FileName);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("序列号: " + SN + "前工段未扫描\n");
|
|
|
+ MessageBox.Show("序列号: " + ms_sncode + "前工段未扫描", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OperateResult.AppendText(oErrMessage + "\n");
|
|
|
+ tipform.startthread(oErrMessage, Result);
|
|
|
+
|
|
|
+ }
|
|
|
+ tipform.startthread("序列号 " + ms_sncode + "通过检测", Result);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- OperateResult.AppendText("序列号: " + ms_sncode + "上传失败\n");
|
|
|
- //MessageBox.Show("序列号: " + ms_sncode + "前工段未扫描", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
+ File.Delete(FileName);
|
|
|
+ OperateResult.AppendText(oErrMessage + "\n");
|
|
|
+ tipform.startthread(oErrMessage, Result);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ OperateResult.AppendText("解析成功:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n");
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
@@ -400,7 +504,6 @@ namespace FileWatcher
|
|
|
}
|
|
|
}
|
|
|
myReader.Close();
|
|
|
- //获取文件名的序列号,如SA123456.xml,如果开头为-表示无条码需要自动获取
|
|
|
string sncode = FileName.Substring(0, 1) == "-" ? "" : FileName.Split('.')[0];
|
|
|
string makecode = "";
|
|
|
//获取序列号ID最大的工单号,所有序列号都测试为良品
|
|
|
@@ -653,11 +756,7 @@ namespace FileWatcher
|
|
|
|
|
|
private void Timer_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
- var AllXmls = Directory.GetFiles(FolderPath.Text, "*.txt");
|
|
|
- foreach (var Xml in AllXmls)
|
|
|
- {
|
|
|
- TxtHandleProcess(Xml);
|
|
|
- }
|
|
|
+ dh.ExecuteSql("select sysdate from dual", "select");
|
|
|
}
|
|
|
}
|
|
|
}
|