AutoAnalysisXml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using System.Xml;
  9. using System.Text;
  10. using System.Media;
  11. namespace FileWatcher
  12. {
  13. public partial class AutoAnalysisXml : Form
  14. {
  15. DataHelper dh;
  16. DataTable dt;
  17. DataTable DB;
  18. /// <summary>
  19. /// 用户编号
  20. /// </summary>
  21. string iusercode;
  22. /// <summary>
  23. /// 岗位资源
  24. /// </summary>
  25. string isource;
  26. Tip tipform;
  27. Thread InitDB;
  28. /// <summary>
  29. /// 线别
  30. /// </summary>
  31. string ilinecode;
  32. /// <summary>
  33. /// 不良代码组
  34. /// </summary>
  35. string ibadgroup;
  36. /// <summary>
  37. /// 当前工序
  38. /// </summary>
  39. string istepcode;
  40. StringBuilder sql = new StringBuilder();
  41. /// <summary>
  42. /// 缓存的文件
  43. /// </summary>
  44. public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
  45. /// <summary>
  46. /// 缓存的文件夹
  47. /// </summary>
  48. public static string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
  49. /// <summary>
  50. /// 需要解析的文件名
  51. /// </summary>
  52. List<string> _FileName = new List<string>();
  53. ftpOperater ftp = new ftpOperater();
  54. public AutoAnalysisXml()
  55. {
  56. tipform = new Tip();
  57. InitializeComponent();
  58. StartPosition = FormStartPosition.CenterScreen;
  59. }
  60. public AutoAnalysisXml(string iUserName, string iSource)
  61. {
  62. tipform = new Tip();
  63. InitializeComponent();
  64. iusercode = iUserName;
  65. isource = iSource.ToUpper();
  66. StartPosition = FormStartPosition.CenterScreen;
  67. }
  68. private void Form1_Load(object sender, EventArgs e)
  69. {
  70. tipform.Show();
  71. CheckForIllegalCrossThreadCalls = false;
  72. FormBorderStyle = FormBorderStyle.FixedSingle;
  73. InitDB = new Thread(ConnectDB);
  74. //添加监控事件
  75. SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
  76. stw.StartPosition = FormStartPosition.CenterScreen;
  77. stw.ShowDialog();
  78. List<string> CacheInf = new List<string>();
  79. DB = (DataTable)dh.ExecuteSql("select ms_pwd,ma_user,ma_address,ma_inneraddress from master where ma_user='MES'", "select");
  80. Master.DataSource = DB;
  81. Master.DisplayMember = "ma_user";
  82. Master.ValueMember = "ma_user";
  83. //获取缓存信息
  84. try
  85. {
  86. //FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
  87. //BackUpFolderPath.Text = BaseUtil.GetCacheData("BackUpFolderPath").ToString();
  88. //Master.Text = BaseUtil.GetCacheData("Master").ToString();
  89. //AutoStart.Checked = (bool)BaseUtil.GetCacheData("AutoStart");
  90. }
  91. catch (Exception ex) { MessageBox.Show(ex.Message); }
  92. for (int i = 0; i < DB.Rows.Count; i++)
  93. {
  94. if (Master.Text == DB.Rows[i]["ma_user"].ToString())
  95. {
  96. DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  97. dh = new DataHelper();
  98. }
  99. }
  100. //获取岗位资源相关信息
  101. 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");
  102. if (dt.Rows.Count > 0)
  103. {
  104. ilinecode = dt.Rows[0]["sc_linecode"].ToString();
  105. istepcode = dt.Rows[0]["sc_stepcode"].ToString();
  106. ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
  107. }
  108. }
  109. private void ConnectDB()
  110. {
  111. dh = new DataHelper();
  112. }
  113. private void StartWatch_Click(object sender, EventArgs e)
  114. {
  115. if (FolderPath.Text == "")
  116. {
  117. OperateResult.AppendText("请选择监控文件夹\n");
  118. return;
  119. }
  120. else
  121. {
  122. if (!Directory.Exists(FolderPath.Text))
  123. {
  124. OperateResult.AppendText("监控文件夹不存在\n");
  125. return;
  126. }
  127. }
  128. for (int i = 0; i < DB.Rows.Count; i++)
  129. {
  130. if (Master.Text == DB.Rows[i]["ma_user"].ToString())
  131. {
  132. DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  133. dh = new DataHelper();
  134. LogicHandler.dh = new DataHelper();
  135. }
  136. }
  137. //存在工单必须是已下放状态
  138. if ((!dh.CheckExist("make", "ma_statuscode='STARTED' and ma_code='" + ma_code.Text + "'") || ma_code.Text == "") && Device.Text == "AOI设备")
  139. {
  140. OperateResult.AppendText("工单不存在或者未下放\n");
  141. return;
  142. }
  143. //设置缓存数据
  144. //BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
  145. //BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
  146. //BaseUtil.SetCacheData("Master", Master.Text);
  147. //BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
  148. //设置按钮不可点击
  149. StartWatch.Enabled = false;
  150. ChooseFolder.Enabled = false;
  151. Master.Enabled = false;
  152. ma_code.Enabled = false;
  153. StopWatch.Enabled = true;
  154. GetFiles.Start();
  155. OperateResult.AppendText("开始执行监控\n");
  156. }
  157. public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
  158. {
  159. XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
  160. node.InnerText = value;
  161. parentNode.AppendChild(node);
  162. }
  163. string nextLine;
  164. private void TxtHandleProcess(string FileName)
  165. {
  166. List<string> badcode = new List<string>();
  167. List<string> badlocation = new List<string>();
  168. List<string> badprod = new List<string>();
  169. if (Device.Text == "AOI设备")
  170. {
  171. StreamReader sR = File.OpenText(FileName);
  172. DataTable filedt = new DataTable();
  173. //文件内的行,用一个DataTable存储
  174. int Rowindex = 0;
  175. while ((nextLine = sR.ReadLine()) != null)
  176. {
  177. //DataTable用第一行的数据作为列名
  178. string[] title = nextLine.Split(',');
  179. DataRow dr = filedt.NewRow();
  180. for (int i = 0; i < title.Length; i++)
  181. {
  182. if (Rowindex == 0)
  183. {
  184. filedt.Columns.Add(title[i]);
  185. }
  186. else
  187. {
  188. dr[filedt.Columns[i].ColumnName] = title[i];
  189. }
  190. }
  191. //除了第一行,然后添加到表格中
  192. if (Rowindex > 0)
  193. {
  194. filedt.Rows.Add(dr);
  195. }
  196. Rowindex = Rowindex + 1;
  197. }
  198. sR.Close();
  199. string SN = FileName.Substring(FileName.LastIndexOf(@"\") + 1).Replace("-", "/").ToUpper().Replace(".TXT", "");
  200. string Result = "OK";
  201. string makecode = "";
  202. string stepcode = "";
  203. string oErrMessage = "";
  204. string oMSID = "";
  205. isource = "SMT_01_AOI";
  206. iusercode = "SMT_01_AOI";
  207. 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");
  208. if (dt.Rows.Count > 0)
  209. {
  210. ilinecode = dt.Rows[0]["sc_linecode"].ToString();
  211. istepcode = dt.Rows[0]["sc_stepcode"].ToString();
  212. ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
  213. }
  214. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, isource, SN, iusercode, out makecode, out oMSID, out oErrMessage))
  215. {
  216. for (int i = 0; i < filedt.Rows.Count; i++)
  217. {
  218. if (filedt.Rows[i]["c_result"].ToString() != "OK" && filedt.Rows[i]["c_result"].ToString() != "FC")
  219. {
  220. Result = "NG";
  221. //只添加一条记录
  222. if (badcode.Count == 0)
  223. {
  224. badcode.Add(filedt.Rows[i]["w_ng_name"].ToString());
  225. badlocation.Add(filedt.Rows[i]["c_subboard_number"].ToString());
  226. badprod.Add(filedt.Rows[i]["c_subboard_number"].ToString());
  227. }
  228. }
  229. }
  230. //获取序列号ID最大的工单
  231. dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_id,ms_stepcode from makeserial where ms_sncode='" + SN + "' order by ms_id desc", "select");
  232. if (dt.Rows.Count > 0)
  233. {
  234. ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
  235. makecode = dt.Rows[0]["ms_makecode"].ToString();
  236. stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  237. if (stepcode == istepcode)
  238. {
  239. tipform.startthread("序列号 " + SN + "已执行过" + istepcode, "NG");
  240. OperateResult.AppendText("序列号 " + SN + "已执行过" + istepcode + "\n");
  241. }
  242. switch (Result)
  243. {
  244. case "OK":
  245. if (!LogicHandler.SetStepResult(makecode, isource, SN, "自动过站采集", Result, iusercode, out oErrMessage))
  246. {
  247. OperateResult.AppendText(oErrMessage + "\n");
  248. tipform.startthread(oErrMessage, Result);
  249. File.Delete(FileName);
  250. }
  251. tipform.startthread("序列号 " + SN + "通过检测", Result);
  252. OperateResult.AppendText("序列号 " + SN + "通过检测" + "\n");
  253. break;
  254. case "NG":
  255. RecordBadInfo(SN, makecode, FileName, "", badcode.ToArray(), badlocation.ToArray(), badprod.ToArray());
  256. //所有的序列号均采集为良品
  257. if (!LogicHandler.SetTestNGDetail(SN, makecode, iusercode, isource, Result, out oErrMessage))
  258. {
  259. OperateResult.AppendText(oErrMessage + "\n");
  260. tipform.startthread(oErrMessage, Result);
  261. File.Delete(FileName);
  262. }
  263. tipform.startthread("序列号 " + SN + "未通过检测", Result);
  264. OperateResult.AppendText("序列号 " + SN + "未通过检测" + "\n");
  265. break;
  266. default:
  267. break;
  268. }
  269. }
  270. }
  271. else
  272. {
  273. OperateResult.AppendText(oErrMessage + "\n");
  274. tipform.startthread(oErrMessage, Result);
  275. // File.Delete(FileName);
  276. }
  277. }
  278. else if (Device.Text == "测试设备")
  279. {
  280. try
  281. {
  282. string filename = FileName;
  283. if (filename.Substring(filename.LastIndexOf(".") + 1).ToUpper() == "TXT" && !filename.ToUpper().Contains("TEMP"))
  284. {
  285. string folderpath = FileName.Substring(0, FileName.LastIndexOf(@"\"));
  286. string SN = FileName.Substring(FileName.LastIndexOf(@"\") + 1).Replace("-", "/").ToUpper().Replace(".TXT", "");
  287. if (MAC.Checked)
  288. {
  289. string Result = "";
  290. string makecode = ma_code.Text;
  291. string oErrMessage = "";
  292. string oMSID = "";
  293. string ms_sncode = dh.getFieldDataByCondition("makeserial", "ms_sncode", "substr(ms_sncode,0,12)='" + SN + "' order by ms_id").ToString();
  294. isource = "SMT_01_TEST01";
  295. iusercode = "SMT_01_TEST01";
  296. 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");
  297. if (dt.Rows.Count > 0)
  298. {
  299. ilinecode = dt.Rows[0]["sc_linecode"].ToString();
  300. istepcode = dt.Rows[0]["sc_stepcode"].ToString();
  301. ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
  302. }
  303. if (LogicHandler.CheckStepSNAndMacode("", isource, ms_sncode, iusercode, out makecode, out oMSID, out oErrMessage))
  304. {
  305. ma_code.Text = makecode;
  306. if (LogicHandler.SetStepResult(makecode, isource, ms_sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
  307. {
  308. try
  309. {
  310. string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
  311. ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
  312. 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://113.98.196.181:8099/ftp" + ftppath + SN + ".txt" + "' from makeserial where substr(ms_sncode,0,12)='" + SN + "'", "insert").ToString());
  313. if (num > 0)
  314. {
  315. OperateResult.AppendText("序列号:" + SN + "上传成功\n");
  316. File.Delete(FileName);
  317. }
  318. else
  319. {
  320. OperateResult.AppendText("序列号: " + SN + "前工段未扫描\n");
  321. MessageBox.Show("序列号: " + ms_sncode + "前工段未扫描", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
  322. }
  323. }
  324. catch (Exception ex)
  325. {
  326. Console.WriteLine(ex.Message);
  327. }
  328. }
  329. else
  330. {
  331. OperateResult.AppendText(oErrMessage + "\n");
  332. tipform.startthread(oErrMessage, Result);
  333. }
  334. tipform.startthread("序列号 " + ms_sncode + "通过检测", Result);
  335. }
  336. else
  337. {
  338. //File.Delete(FileName);
  339. OperateResult.AppendText(oErrMessage + "\n");
  340. tipform.startthread(oErrMessage, Result);
  341. }
  342. }
  343. else
  344. {
  345. string Result = "";
  346. string makecode = ma_code.Text;
  347. string oErrMessage = "";
  348. string oMSID = "";
  349. string ms_sncode = dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_sncode='" + SN + "' order by ms_id").ToString();
  350. isource = "SMT_01_TEST01";
  351. iusercode = "SMT_01_TEST01";
  352. 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");
  353. if (dt.Rows.Count > 0)
  354. {
  355. ilinecode = dt.Rows[0]["sc_linecode"].ToString();
  356. istepcode = dt.Rows[0]["sc_stepcode"].ToString();
  357. ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
  358. }
  359. if (LogicHandler.CheckStepSNAndMacode("", isource, ms_sncode, iusercode, out makecode, out oMSID, out oErrMessage))
  360. {
  361. ma_code.Text = makecode;
  362. if (LogicHandler.SetStepResult(makecode, isource, ms_sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
  363. {
  364. try
  365. {
  366. string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
  367. ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
  368. 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://113.98.196.181:8099/ftp" + ftppath + SN + ".txt" + "' from makeserial where ms_sncode='" + SN + "'", "insert").ToString());
  369. if (num > 0)
  370. {
  371. OperateResult.AppendText("序列号:" + SN + "上传成功\n");
  372. File.Delete(FileName);
  373. }
  374. else
  375. {
  376. OperateResult.AppendText("序列号: " + SN + "前工段未扫描\n");
  377. MessageBox.Show("序列号: " + ms_sncode + "前工段未扫描", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
  378. }
  379. }
  380. catch (Exception ex)
  381. {
  382. Console.WriteLine(ex.Message);
  383. }
  384. }
  385. else
  386. {
  387. OperateResult.AppendText(oErrMessage + "\n");
  388. tipform.startthread(oErrMessage, Result);
  389. }
  390. tipform.startthread("序列号 " + ms_sncode + "通过检测", Result);
  391. }
  392. else
  393. {
  394. // File.Delete(FileName);
  395. OperateResult.AppendText(oErrMessage + "\n");
  396. tipform.startthread(oErrMessage, Result);
  397. }
  398. }
  399. OperateResult.AppendText("解析成功:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n");
  400. }
  401. }
  402. catch (Exception e)
  403. {
  404. OperateResult.AppendText("解析失败:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n" + e.Message + "\n");
  405. }
  406. }
  407. }
  408. /// <summary>
  409. /// 使用进程处理文件,避免界面假死
  410. /// </summary>
  411. private void RecordBadInfo(string sncode, string makecode, string filename, string combine, string[] badcode, string[] badlocation, string[] soncode)
  412. {
  413. string[] ID = dh.GetSEQ("makebad_seq", badcode.Length);
  414. sql.Clear();
  415. sql.Append("update makebad set mb_status=-1 where mb_sncode='" + sncode + "' and mb_stepcode='" + istepcode + "' and mb_makecode='" + makecode + "' and mb_status=0");
  416. dh.ExecuteSql(sql.ToString(), "update");
  417. sql.Clear();
  418. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  419. sql.Append(",mb_sourcecode,mb_badname,mb_bgcode,mb_badtable,mb_status,mb_badlocation,mb_soncode,mb_content) select :ID");
  420. sql.Append(",ma_code,ms_code,ms_sncode,'" + iusercode + "',sysdate,'" + istepcode + "','" + isource + "',");
  421. sql.Append(":bc_code,'WG','','0',:location,:soncode,'" + nextLine + "' from make left join makeSerial on ms_makecode=ma_code ");
  422. sql.Append("where ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'");
  423. dh.BatchInsert(sql.ToString(), new string[] { "ID", "bc_code", "location", "soncode" }, ID, badcode, badlocation, soncode);
  424. sql.Clear();
  425. sql.Append("update makebad set mb_badcode=(select DISTINCT bc_code from badcode where bc_name=mb_badcode),mb_badname=mb_badcode,mb_bgname=(select DISTINCT bg_name from badgroup where bg_code=mb_bgcode) ");
  426. sql.Append("where mb_id=:ID");
  427. dh.BatchInsert(sql.ToString(), new string[] { "ID" }, ID);
  428. //记录判断日志
  429. if (dh.getFieldDataByCondition("source", "sc_scantype", "sc_code='" + isource + "'").ToString() == "REJUCE")
  430. {
  431. LogicHandler.AutoPassJudge(sncode, makecode, isource, filename, ilinecode, combine);
  432. }
  433. }
  434. private void StopWatch_Click(object sender, EventArgs e)
  435. {
  436. XmlWatcher.EnableRaisingEvents = false;
  437. StartWatch.Enabled = true;
  438. ma_code.Enabled = true;
  439. Master.Enabled = true;
  440. ChooseFolder.Enabled = true;
  441. StopWatch.Enabled = false;
  442. GetFiles.Stop();
  443. OperateResult.AppendText("停止执行监控\n");
  444. }
  445. private void Clean_Click(object sender, EventArgs e)
  446. {
  447. OperateResult.Clear();
  448. }
  449. private void ChooseFolder_Click(object sender, EventArgs e)
  450. {
  451. FolderBrowserDialog folder = new FolderBrowserDialog();
  452. folder.Description = "选择监控文件夹";
  453. DialogResult result = folder.ShowDialog();
  454. if (result == DialogResult.OK)
  455. {
  456. FolderPath.Text = folder.SelectedPath;
  457. }
  458. }
  459. private void ChooseBackUpFolder_Click(object sender, EventArgs e)
  460. {
  461. FolderBrowserDialog folder = new FolderBrowserDialog();
  462. folder.Description = "选择备份文件夹";
  463. DialogResult result = folder.ShowDialog();
  464. if (result == DialogResult.OK)
  465. {
  466. }
  467. }
  468. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  469. {
  470. string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  471. if (ExitConfirm != "Yes")
  472. {
  473. WindowState = FormWindowState.Minimized;
  474. e.Cancel = true;
  475. }
  476. }
  477. private void AutoStart_CheckedChanged(object sender, EventArgs e)
  478. {
  479. SetAutoRun();
  480. }
  481. private void SetAutoRun()
  482. {
  483. if (AutoStart.Checked) //设置开机自启动
  484. {
  485. string path = Application.ExecutablePath;
  486. RegistryKey rk = Registry.LocalMachine;
  487. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  488. rk2.SetValue("UAS自动过站解析器.exe", path);
  489. rk2.Close();
  490. rk.Close();
  491. }
  492. else //取消开机自启动
  493. {
  494. string path = Application.ExecutablePath;
  495. RegistryKey rk = Registry.LocalMachine;
  496. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  497. rk2.DeleteValue("UAS自动过站解析器.exe", false);
  498. rk2.Close();
  499. rk.Close();
  500. }
  501. }
  502. private void BatchAnalysus_Click(object sender, EventArgs e)
  503. {
  504. var AllXmls = Directory.GetFiles(FolderPath.Text, "*.txt");
  505. foreach (var Xml in AllXmls)
  506. {
  507. TxtHandleProcess(Xml);
  508. }
  509. }
  510. private void Timer_Tick(object sender, EventArgs e)
  511. {
  512. dh.ExecuteSql("select sysdate from dual", "select");
  513. }
  514. private void GetFiles_Tick(object sender, EventArgs e)
  515. {
  516. var AllXmls = Directory.GetFiles(FolderPath.Text, "*.txt");
  517. foreach (var Xml in AllXmls)
  518. {
  519. TxtHandleProcess(Xml);
  520. }
  521. }
  522. }
  523. }