123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- using System.Xml;
- using UAS_AutoPass.ToolClass;
- using System.Text;
- using System.Media;
- namespace UAS_AutoPass
- {
- public partial class AutoAnalysisXml : Form
- {
- DataHelper dh;
- DataTable dt;
- DataTable DB;
- /// <summary>
- /// 用户编号
- /// </summary>
- string iusercode;
- /// <summary>
- /// 岗位资源
- /// </summary>
- string isource;
- Tip tipform;
- Thread InitDB;
- /// <summary>
- /// 线别
- /// </summary>
- string ilinecode;
- /// <summary>
- /// 不良代码组
- /// </summary>
- string ibadgroup;
- /// <summary>
- /// 当前工序
- /// </summary>
- string istepcode;
- StringBuilder sql = new StringBuilder();
- /// <summary>
- /// 缓存的文件
- /// </summary>
- public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
- /// <summary>
- /// 缓存的文件夹
- /// </summary>
- public static string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
- /// <summary>
- /// 需要解析的文件名
- /// </summary>
- List<string> _FileName = new List<string>();
- public AutoAnalysisXml()
- {
- tipform = new Tip();
- InitializeComponent();
- StartPosition = FormStartPosition.CenterScreen;
- }
- public AutoAnalysisXml(string iUserName, string iSource)
- {
- tipform = new Tip();
- InitializeComponent();
- iusercode = iUserName;
- isource = iSource.ToUpper();
- StartPosition = FormStartPosition.CenterScreen;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- tipform.Show();
- CheckForIllegalCrossThreadCalls = false;
- FormBorderStyle = FormBorderStyle.FixedSingle;
- InitDB = new Thread(ConnectDB);
- //添加监控事件
- XmlWatcher.Created += new FileSystemEventHandler(XmlWatcher_Created);
- SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
- 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
- {
- FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
- BackUpFolderPath.Text = BaseUtil.GetCacheData("BackUpFolderPath").ToString();
- Master.Text = BaseUtil.GetCacheData("Master").ToString();
- //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=" + DB.Rows[i]["ma_user"].ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.10)(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)
- {
- ilinecode = dt.Rows[0]["sc_linecode"].ToString();
- istepcode = dt.Rows[0]["sc_stepcode"].ToString();
- ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
- }
- }
- private void ConnectDB()
- {
- dh = new DataHelper();
- }
- private void StartWatch_Click(object sender, EventArgs e)
- {
- if (FolderPath.Text == "" || BackUpFolderPath.Text == "")
- {
- OperateResult.AppendText("请选择监控文件夹和备份文件夹\n");
- return;
- }
- else
- {
- if (!Directory.Exists(FolderPath.Text))
- {
- OperateResult.AppendText("监控文件夹不存在\n");
- return;
- }
- if (!Directory.Exists(BackUpFolderPath.Text))
- {
- OperateResult.AppendText("备份文件夹不存在\n");
- return;
- }
- }
- if (FolderPath.Text == BackUpFolderPath.Text)
- {
- OperateResult.AppendText("监控文件夹和备份文件夹不能相同\n");
- 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=" + DB.Rows[i]["ma_user"].ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.10)(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设备")
- {
- OperateResult.AppendText("工单不存在或者未下放\n");
- return;
- }
- if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'") && ma_code.Text != "" && Device.Text == "选焊设备")
- {
- OperateResult.AppendText("工单不存\n");
- return;
- }
- XmlWatcher.Path = FolderPath.Text;
- XmlWatcher.Filter = "*.txt";
- XmlWatcher.EnableRaisingEvents = true;
- //设置缓存数据
- BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
- BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
- BaseUtil.SetCacheData("Master", Master.Text);
- BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
- //设置按钮不可点击
- StartWatch.Enabled = false;
- ChooseFolder.Enabled = false;
- Master.Enabled = false;
- ma_code.Enabled = false;
- ChooseBackUpFolder.Enabled = false;
- StopWatch.Enabled = true;
- OperateResult.AppendText("开始执行监控\n");
- }
- public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
- {
- XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
- node.InnerText = value;
- parentNode.AppendChild(node);
- }
- 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;
- }
- }
- string nextLine;
- private void TxtHandleProcess(string FileName)
- {
- List<string> badcode = new List<string>();
- List<string> badlocation = new List<string>();
- List<string> badprod = new List<string>();
- if (Device.Text == "AOI设备")
- {
- StreamReader sR = File.OpenText(FileName);
- string[] data1 = null;
- while ((nextLine = sR.ReadLine()) != null)
- {
- data1 = nextLine.Split(';');
- }
- string SoftVersion = data1[0];
- List<string[]> dic = new List<string[]>();
- List<string> sndata = new List<string>();
- for (int i = 0; i < data1.Length; i++)
- {
- //如果软件版本相同的时候,则表示一个新的SN
- if ((SoftVersion == data1[i] && i != 0) || i == data1.Length - 1)
- {
- dic.Add(sndata.ToArray());
- sndata.Clear();
- }
- sndata.Add(data1[i]);
- }
- foreach (string[] content in dic)
- {
- string SN = "";
- string Machine = "";
- string EmName = "";
- string Day = "";
- string Time = "";
- string Result = "";
- string TotalPart = "";
- string NGPart = "";
- int MissTest = 0;
- string[] data = content;
- for (int i = 0; i < data.Length; i++)
- {
- switch (i.ToString())
- {
- case "0":
- SoftVersion = data[i];
- break;
- case "1":
- SN = data[i];
- break;
- case "2":
- Machine = data[i];
- break;
- case "4":
- EmName = data[i];
- break;
- case "6":
- Day = data[i];
- break;
- case "7":
- Time = data[i];
- break;
- case "8":
- Result += data[i];
- break;
- case "9":
- Result += data[i];
- break;
- case "10":
- Result += data[i];
- break;
- case "11":
- Result += data[i];
- break;
- case "13":
- TotalPart = data[i];
- break;
- case "14":
- NGPart = data[i];
- break;
- default:
- break;
- }
- }
- if (SN == "")
- {
- tipform.startthread("序列号不能为空", "NG");
- continue;
- }
- if (data.Length > 15)
- {
- for (int i = 15; i < data.Length; i++)
- {
- switch ((i - 15) % 6)
- {
- case 0:
- if (badlocation.Count >= 1)
- {
- continue;
- }
- badlocation.Add(data[i]);
- break;
- case 1:
- if (badprod.Count >= 1)
- {
- continue;
- }
- badprod.Add(data[i]);
- break;
- case 2:
- if (badcode.Count >= 1)
- {
- continue;
- }
- badcode.Add(data[i].ToUpper());
- break;
- default:
- break;
- }
- }
- }
- sR.Close();
- //如果没有不良位号等数据则是15个数据
- if (Result == "0001")
- {
- if (data.Length > 16)
- {
- MissTest = -1;
- Result = "NG";
- }
- else
- {
- Result = "OK";
- }
- }
- else
- {
- Result = "OK";
- }
- string makecode = "";
- string stepcode = "";
- string oErrMessage = "";
- string oMSID = "";
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, isource, SN, iusercode, out makecode, out oMSID, out oErrMessage))
- {
- //获取序列号ID最大的工单
- dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_id,ms_stepcode from makeserial where ms_sncode='" + SN + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
- makecode = dt.Rows[0]["ms_makecode"].ToString();
- stepcode = dt.Rows[0]["ms_stepcode"].ToString();
- if (stepcode == istepcode)
- {
- tipform.startthread("序列号 " + SN + "已执行过" + istepcode, "NG");
- OperateResult.AppendText("序列号 " + SN + "已执行过" + istepcode + "\n");
- continue;
- }
- SoundPlayer player = new SoundPlayer();
- switch (Result)
- {
- case "OK":
- if (!LogicHandler.SetStepResult(makecode, isource, SN, "自动过站采集", Result, iusercode, out oErrMessage))
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, Result);
- continue;
- }
- tipform.startthread("序列号 " + SN + "通过检测", Result);
- player.SoundLocation = Application.StartupPath + @"\8378.wav";
- player.Load();
- player.Play();
- break;
- case "NG":
- RecordBadInfo(SN, makecode, FileName, "", badcode.ToArray(), badlocation.ToArray(), badprod.ToArray());
- //所有的序列号均采集为良品
- if (!LogicHandler.SetTestNGDetail(SN, makecode, iusercode, isource, Result, out oErrMessage))
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, Result);
- continue;
- }
- tipform.startthread("序列号 " + SN + "未通过检测", Result);
- player.SoundLocation = Application.StartupPath + @"\5185.wav";
- player.Load();
- player.Play();
- break;
- default:
- break;
- }
- LogicHandler.AutoPassLog(SN, isource, makecode, Day + Time, istepcode, ilinecode, SoftVersion, Result == "NG" ? "-1" : "0", "0", MissTest, TotalPart, NGPart);
- FileName = FileName.Substring(FileName.LastIndexOf(@"\") + 1);
- FileInfo file = new FileInfo(FolderPath.Text + @"\" + FileName);
- if (file.Exists)
- {
- try
- {
- for (int i = 1; i <= 20; i++)
- {
- if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName))
- {
- file.MoveTo(BackUpFolderPath.Text + @"\" + FileName);
- OperateResult.AppendText("成功解析文件" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + FileName + "\n");
- break;
- }
- else if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]))
- {
- file.MoveTo(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]);
- OperateResult.AppendText("成功解析文件" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + FileName + "\n");
- break;
- }
- }
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(FileName + ex.Message + "\n");
- }
- }
- }
- }
- else
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, Result);
- continue;
- }
- }
- }
- else if (Device.Text == "选焊设备")
- {
- try
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- BaseUtil.GetWriteInfo(FileName, out dic);
- string sql = "insert into AOITESTDETAIL(atd_id,atd_makecode,atd_indate,";
- string sql1 = " values(AOITESTDETAIL_seq.nextval,'" + ma_code.Text + "',sysdate,";
- foreach (var item in dic)
- {
- sql += item.Key + ",";
- if (item.Key.Contains("starttime") || item.Key.Contains("endtime"))
- sql1 += "to_date('" + item.Value + "','dd/mm/yyyy hh24:mi:ss'),";
- else
- sql1 += "'" + item.Value + "',";
- }
- sql = sql.Substring(0, sql.Length - 1) + ")" + sql1.Substring(0, sql1.Length - 1) + ")";
- dh.ExecuteSql(sql, "insert");
- OperateResult.AppendText("解析成功:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n");
- }
- catch (Exception e)
- {
- OperateResult.AppendText("解析失败:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n" + e.Message + "\n");
- }
- }
- }
- /// <summary>
- /// 使用进程处理文件,避免界面假死
- /// </summary>
- private void XmlHandleProcess(string FileName)
- {
- string test_date = "";
- string test_result = "";
- string test_sn = "";
- string imageurl = "";
- string oMSID = "";
- string oErrMessage = "";
- XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + FileName);
- OperateResult.AppendText("读取文件" + FileName + "\n");
- //获取采集的项目名称
- List<string> badcode = new List<string>();
- //获取采集项目的结果
- List<string> badlocation = new List<string>();
- while (myReader.Read())
- {
- if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test" && myReader.IsStartElement())
- {
- test_sn = myReader.GetAttribute("test_sn");
- test_result = myReader.GetAttribute("test_result");
- test_date = myReader.GetAttribute("test_date");
- imageurl = myReader.GetAttribute("imgurl");
- }
- //if (myReader.NodeType == XmlNodeType.Text)
- //{
- // if (code_or_location % 2 == 0)
- // {
- // badcode.Add(myReader.Value);
- // code_or_location++;
- // }
- // else
- // {
- // badlocation.Add(myReader.Value);
- // code_or_location++;
- // }
- //}
- if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "err_reason" && myReader.IsStartElement())
- {
- badcode.Add(myReader.ReadInnerXml() + " ");
- }
- if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "err_location" && myReader.IsStartElement())
- {
- badlocation.Add(myReader.ReadInnerXml() + " ");
- }
- }
- myReader.Close();
- //获取文件名的序列号,如SA123456.xml,如果开头为-表示无条码需要自动获取
- string sncode = FileName.Substring(0, 1) == "-" ? "" : FileName.Split('.')[0];
- string makecode = "";
- //获取序列号ID最大的工单号,所有序列号都测试为良品
- if (sncode == "")
- {
- //获取资源,线别,工序相等,并且状态在线的序列号进行分配
- sql.Clear();
- sql.Append("select ms_sncode,ms_makecode from makeserial left join source on sc_code=ms_sccode where ");
- sql.Append("sc_linecode='" + ilinecode + "' and ms_nextstepcode='" + istepcode + "' and ms_status=1 order by ms_id");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- if (dt.Rows.Count > 0)
- {
- makecode = dt.Rows[0]["ms_makecode"].ToString();
- sncode = dt.Rows[0]["ms_sncode"].ToString();
- }
- else
- {
- OperateResult.AppendText("当前线别在" + istepcode + "无可分配序列号");
- tipform.startthread("当前线别在" + istepcode + "无可分配序列号", "NG");
- return;
- }
- //-2-NG2017/10/2514:46:29.xml取第二位版号
- string combinecode = FileName.Substring(1, 1);
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? makecode : ma_code.Text, isource, sncode, iusercode, out makecode, out oMSID, out oErrMessage))
- {
- //插入日志
- LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, FileName, test_result == "NG" ? "-1" : "0", "-1", 0, "", "");
- //如果是不良品记录日志,用于测试采集判负
- if (test_result == "NG")
- {
- RecordBadInfo(sncode, makecode, FileName, combinecode, badcode.ToArray(), badlocation.ToArray(), null);
- }
- if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, "NG");
- return;
- }
- tipform.startthread("序列号 " + sncode + "通过检测", test_result);
- }
- else
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, "NG");
- return;
- }
- }
- else
- {
- string status = "";
- string errmessage = "";
- bool NoteAlready = false;
- LogicHandler.GetMakeInfo(sncode, out makecode, out status, out errmessage);
- if (ma_code.Text != makecode && makecode != "" && ma_code.Text != "" && status != "2")
- {
- string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号" + sncode + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- //如果选择不切换赋值当前界面工单
- if (ChangeMakeCode != "Yes")
- {
- makecode = ma_code.Text;
- }
- else
- {
- NoteAlready = true;
- }
- }
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? makecode : ma_code.Text, isource, sncode, iusercode, out makecode, out oMSID, out oErrMessage))
- {
- if (!NoteAlready)
- {
- if (makecode != ma_code.Text && ma_code.Text != "")
- {
- string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- //如果选择不切换赋值当前界面工单
- if (ChangeMakeCode == "Yes")
- {
- ma_code.Text = makecode;
- }
- else
- {
- OperateResult.AppendText(">>请重新采集序列号\n");
- tipform.startthread("请重新采集序列号", test_result);
- return;
- }
- }
- }
- //获取序列号ID最大的工单
- dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_id from makeserial where ms_sncode='" + sncode + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
- makecode = dt.Rows[0]["ms_makecode"].ToString();
- switch (test_result)
- {
- case "OK":
- if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", test_result, iusercode, out oErrMessage))
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, test_result);
- return;
- }
- tipform.startthread("序列号 " + sncode + "通过检测", test_result);
- break;
- case "NG":
- RecordBadInfo(sncode, makecode, FileName, "", badcode.ToArray(), badlocation.ToArray(), null);
- //所有的序列号均采集为良品
- if (!LogicHandler.SetTestNGDetail(sncode, makecode, iusercode, isource, test_result, out oErrMessage))
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, test_result);
- return;
- }
- tipform.startthread("序列号 " + sncode + "未通过检测", test_result);
- break;
- default:
- break;
- }
- LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, FileName, test_result == "NG" ? "1" : "0", "0", 0, "", "");
- }
- }
- else
- {
- OperateResult.AppendText(oErrMessage + "\n");
- tipform.startthread(oErrMessage, "NG");
- return;
- }
- }
- FileInfo file = new FileInfo(FolderPath.Text + @"\" + FileName);
- if (file.Exists)
- {
- try
- {
- for (int i = 1; i <= 20; i++)
- {
- if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName))
- {
- file.MoveTo(BackUpFolderPath.Text + @"\" + FileName);
- OperateResult.AppendText("成功解析文件" + FileName + "\n");
- break;
- }
- else if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]))
- {
- file.MoveTo(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]);
- OperateResult.AppendText("成功解析文件" + FileName + "\n");
- break;
- }
- }
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(FileName + ex.Message + "\n");
- }
- }
- }
- private void RecordBadInfo(string sncode, string makecode, string filename, string combine, string[] badcode, string[] badlocation, string[] soncode)
- {
- string[] ID = dh.GetSEQ("makebad_seq", badcode.Length);
- sql.Clear();
- sql.Append("update makebad set mb_status=-1 where mb_sncode='" + sncode + "' and mb_stepcode='" + istepcode + "' and mb_makecode='" + makecode + "' and mb_status=0");
- dh.ExecuteSql(sql.ToString(), "update");
- sql.Clear();
- sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
- sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badlocation,mb_soncode,mb_content) select :ID");
- sql.Append(",ma_code,ms_code,ms_sncode,'" + iusercode + "',sysdate,'" + istepcode + "','" + isource + "',");
- sql.Append(":bc_code,'" + ibadgroup + "','','0',:location,:soncode,'" + nextLine + "' from make left join makeSerial on ms_makecode=ma_code ");
- sql.Append("where ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'");
- dh.BatchInsert(sql.ToString(), new string[] { "ID", "bc_code", "location", "soncode" }, ID, badcode, badlocation, soncode);
- sql.Clear();
- sql.Append("update makebad set mb_badname=(select DISTINCT bc_name from badcode where bc_code=mb_badcode),mb_bgname=(select DISTINCT bg_name from badgroup where bg_code=mb_bgcode) ");
- sql.Append("where mb_id=:ID");
- dh.BatchInsert(sql.ToString(), new string[] { "ID" }, ID);
- //记录判断日志
- if (dh.getFieldDataByCondition("source", "sc_scantype", "sc_code='" + isource + "'").ToString() == "REJUCE")
- {
- LogicHandler.AutoPassJudge(sncode, makecode, isource, filename, ilinecode, combine);
- }
- }
- private void StopWatch_Click(object sender, EventArgs e)
- {
- XmlWatcher.EnableRaisingEvents = false;
- StartWatch.Enabled = true;
- ma_code.Enabled = true;
- Master.Enabled = true;
- ChooseFolder.Enabled = true;
- ChooseBackUpFolder.Enabled = true;
- StopWatch.Enabled = false;
- OperateResult.AppendText("停止执行监控\n");
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void ChooseFolder_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog folder = new FolderBrowserDialog();
- folder.Description = "选择监控文件夹";
- DialogResult result = folder.ShowDialog();
- if (result == DialogResult.OK)
- {
- FolderPath.Text = folder.SelectedPath;
- }
- }
- private void ChooseBackUpFolder_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog folder = new FolderBrowserDialog();
- folder.Description = "选择备份文件夹";
- DialogResult result = folder.ShowDialog();
- if (result == DialogResult.OK)
- {
- BackUpFolderPath.Text = folder.SelectedPath;
- }
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (ExitConfirm != "Yes")
- {
- WindowState = FormWindowState.Minimized;
- e.Cancel = true;
- }
- }
- private void AutoStart_CheckedChanged(object sender, EventArgs e)
- {
- SetAutoRun();
- }
- private void SetAutoRun()
- {
- if (AutoStart.Checked) //设置开机自启动
- {
- string path = Application.ExecutablePath;
- RegistryKey rk = Registry.LocalMachine;
- RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
- rk2.SetValue("UAS自动过站解析器.exe", path);
- rk2.Close();
- rk.Close();
- }
- else //取消开机自启动
- {
- string path = Application.ExecutablePath;
- RegistryKey rk = Registry.LocalMachine;
- RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
- rk2.DeleteValue("UAS自动过站解析器.exe", false);
- rk2.Close();
- rk.Close();
- }
- }
- private void BatchAnalysus_Click(object sender, EventArgs e)
- {
- var AllXmls = Directory.GetFiles(FolderPath.Text, "*.txt");
- foreach (var Xml in AllXmls)
- {
- TxtHandleProcess(Xml);
- }
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- dh.ExecuteSql("select sysdate from dual", "select");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SoundPlayer player = new SoundPlayer();
- player.SoundLocation = Application.StartupPath + @"\8378.wav";
- player.Load();
- player.Play();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- SoundPlayer player = new SoundPlayer();
- player.SoundLocation = Application.StartupPath + @"\5185.wav";
- player.Load();
- player.Play();
- }
- }
- }
|