Form1.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using System.Xml;
  10. using UAS_AutoPass.ToolClass;
  11. namespace UAS_XmlAnalysor
  12. {
  13. public partial class Form1 : Form
  14. {
  15. DataHelper dh;
  16. DataTable dt;
  17. Tip tipform;
  18. /// <summary>
  19. /// 用户编号
  20. /// </summary>
  21. string iusercode;
  22. /// <summary>
  23. /// 岗位资源
  24. /// </summary>
  25. string isource;
  26. /// <summary>
  27. /// 线别
  28. /// </summary>
  29. string ilinecode;
  30. /// <summary>
  31. /// 不良代码组
  32. /// </summary>
  33. string ibadgroup;
  34. /// <summary>
  35. /// 当前工序
  36. /// </summary>
  37. string istepcode;
  38. StringBuilder sql = new StringBuilder();
  39. DataTable DB;
  40. Thread InitDB;
  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. public Form1()
  50. {
  51. InitializeComponent();
  52. StartPosition = FormStartPosition.CenterScreen;
  53. tipform = new Tip();
  54. }
  55. public Form1(string iUserName, string iSource)
  56. {
  57. tipform = new Tip();
  58. InitializeComponent();
  59. iusercode = iUserName;
  60. isource = iSource.ToUpper();
  61. StartPosition = FormStartPosition.CenterScreen;
  62. }
  63. private void Form1_Load(object sender, EventArgs e)
  64. {
  65. tipform.Show();
  66. CheckForIllegalCrossThreadCalls = false;
  67. FormBorderStyle = FormBorderStyle.FixedSingle;
  68. InitDB = new Thread(ConnectDB);
  69. //添加监控事件
  70. XmlWatcher.Created += new FileSystemEventHandler(XmlWatcher_Created);
  71. SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
  72. stw.StartPosition = FormStartPosition.CenterScreen;
  73. stw.ShowDialog();
  74. List<string> CacheInf = new List<string>();
  75. DB = (DataTable)dh.ExecuteSql("select ms_pwd,ma_user,ma_address,ma_inneraddress from master", "select");
  76. Master.DataSource = DB;
  77. Master.DisplayMember = "ma_user";
  78. Master.ValueMember = "ma_user";
  79. //获取缓存信息
  80. try
  81. {
  82. FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
  83. BackUpFolderPath.Text = BaseUtil.GetCacheData("BackUpFolderPath").ToString();
  84. Master.Text = BaseUtil.GetCacheData("Master").ToString();
  85. AutoStart.Checked = (bool)BaseUtil.GetCacheData("AutoStart");
  86. }
  87. catch (Exception ex) { Console.WriteLine(ex.Message); }
  88. for (int i = 0; i < DB.Rows.Count; i++)
  89. {
  90. if (Master.Text == DB.Rows[i]["ma_user"].ToString())
  91. {
  92. 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=" + DB.Rows[i]["ma_inneraddress"].ToString() + ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  93. dh = new DataHelper();
  94. }
  95. }
  96. //获取岗位资源相关信息
  97. 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");
  98. if (dt.Rows.Count > 0)
  99. {
  100. ilinecode = dt.Rows[0]["sc_linecode"].ToString();
  101. istepcode = dt.Rows[0]["sc_stepcode"].ToString();
  102. ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
  103. }
  104. }
  105. private void ConnectDB()
  106. {
  107. dh = new DataHelper();
  108. }
  109. private void StartWatch_Click(object sender, EventArgs e)
  110. {
  111. if (FolderPath.Text == "" || BackUpFolderPath.Text == "")
  112. {
  113. OperateResult.AppendText("请选择监控文件夹和备份文件夹\n");
  114. return;
  115. }
  116. else
  117. {
  118. if (!Directory.Exists(FolderPath.Text))
  119. {
  120. OperateResult.AppendText("监控文件夹不存在\n");
  121. return;
  122. }
  123. if (!Directory.Exists(BackUpFolderPath.Text))
  124. {
  125. OperateResult.AppendText("备份文件夹不存在\n");
  126. return;
  127. }
  128. }
  129. if (FolderPath.Text == BackUpFolderPath.Text)
  130. {
  131. OperateResult.AppendText("监控文件夹和备份文件夹不能相同\n");
  132. return;
  133. }
  134. for (int i = 0; i < DB.Rows.Count; i++)
  135. {
  136. if (Master.Text == DB.Rows[i]["ma_user"].ToString())
  137. {
  138. 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=" + DB.Rows[i]["ma_inneraddress"].ToString() + ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  139. dh = new DataHelper();
  140. }
  141. }
  142. if (!dh.CheckExist("source", "sc_code='" + isource + "' and sc_statuscode='AUDITED'"))
  143. {
  144. OperateResult.AppendText("岗位资源错误或者未审核\n");
  145. return;
  146. }
  147. XmlWatcher.Path = FolderPath.Text;
  148. XmlWatcher.Filter = "*.xml";
  149. XmlWatcher.EnableRaisingEvents = true;
  150. BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
  151. BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
  152. BaseUtil.SetCacheData("Source", isource);
  153. BaseUtil.SetCacheData("Master", Master.Text);
  154. BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
  155. StartWatch.Enabled = false;
  156. ChooseFolder.Enabled = false;
  157. ChooseBackUpFolder.Enabled = false;
  158. StopWatch.Enabled = true;
  159. OperateResult.AppendText("开始执行监控\n");
  160. }
  161. public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
  162. {
  163. XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
  164. node.InnerText = value;
  165. parentNode.AppendChild(node);
  166. }
  167. public void SetAutoRun()
  168. {
  169. if (AutoStart.Checked) //设置开机自启动
  170. {
  171. string path = Application.ExecutablePath;
  172. RegistryKey rk = Registry.LocalMachine;
  173. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  174. rk2.SetValue("UAS_XML解析器.exe", path);
  175. rk2.Close();
  176. rk.Close();
  177. }
  178. else //取消开机自启动
  179. {
  180. string path = Application.ExecutablePath;
  181. RegistryKey rk = Registry.LocalMachine;
  182. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  183. rk2.DeleteValue("UAS_XML解析器.exe", false);
  184. rk2.Close();
  185. rk.Close();
  186. }
  187. }
  188. private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
  189. {
  190. while (true)
  191. {
  192. try
  193. {
  194. using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
  195. {
  196. if (stream != null)
  197. break;
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. Console.WriteLine(ex.Message);
  203. }
  204. }
  205. string test_result = "";
  206. string oErrMessage = "";
  207. string testDate = "";
  208. string testTime = "";
  209. XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + e.Name);
  210. //获取文件名的序列号,如SA123456.xml
  211. string sncode = e.Name.Split('.')[0];
  212. string makecode = "";
  213. //获取序列号ID最大的工单号
  214. OperateResult.AppendText("读取文件" + e.Name + "\n");
  215. //获取采集的项目名称
  216. List<string> name = new List<string>();
  217. //获取采集项目的结果
  218. List<string> result = new List<string>();
  219. string class2name = "";
  220. string class3name = "";
  221. List<string> class2 = new List<string>();
  222. //获取采集项目的结果
  223. List<string> class3 = new List<string>();
  224. while (myReader.Read())
  225. {
  226. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test" && myReader.IsStartElement())
  227. {
  228. test_result = myReader.GetAttribute("test_result");
  229. testDate = myReader.GetAttribute("test_date");
  230. testTime = myReader.GetAttribute("test_time");
  231. class2name = "";
  232. class3name = "";
  233. }
  234. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "OperatorInput" && myReader.IsStartElement())
  235. {
  236. class2name = "OperatorInput";
  237. class3name = "";
  238. }
  239. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "SelfTest" && myReader.IsStartElement())
  240. {
  241. class2name = "SelfTest";
  242. class3name = "";
  243. }
  244. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "BlueTooth" && myReader.IsStartElement())
  245. {
  246. class2name = "SelfTest";
  247. class3name = "BlueTooth";
  248. }
  249. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "wifi" && myReader.IsStartElement())
  250. {
  251. class2name = "SelfTest";
  252. class3name = "wifi";
  253. }
  254. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "temperature" && myReader.IsStartElement())
  255. {
  256. class2name = "SelfTest";
  257. class3name = "temperature";
  258. }
  259. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "nightvision" && myReader.IsStartElement())
  260. {
  261. class2name = "SelfTest";
  262. class3name = "nightvision";
  263. }
  264. //if (myReader.NodeType == XmlNodeType.Text)
  265. //{
  266. // if (name_or_result % 2 == 0)
  267. // {
  268. // name.Add(myReader.Value+" ");
  269. // name_or_result++;
  270. // }
  271. // else
  272. // {
  273. // result.Add(myReader.Value+" ");
  274. // name_or_result++;
  275. // class2.Add(class2name);
  276. // class3.Add(class3name);
  277. // }
  278. //}
  279. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "command_name" && myReader.IsStartElement())
  280. {
  281. name.Add(myReader.ReadInnerXml() + " ");
  282. }
  283. if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "command_result" && myReader.IsStartElement())
  284. {
  285. result.Add(myReader.ReadInnerXml() + " ");
  286. class2.Add(class2name);
  287. class3.Add(class3name);
  288. }
  289. }
  290. myReader.Close();
  291. string test_date = testDate + " " + testTime;
  292. string status = "";
  293. string errmessage = "";
  294. bool NoteAlready = false;
  295. LogicHandler.GetMakeInfo(sncode, out makecode, out status, out errmessage);
  296. if (ma_code.Text != makecode && makecode != "" && ma_code.Text != "" && status != "2")
  297. {
  298. string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号" + sncode + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  299. //如果选择不切换赋值当前界面工单
  300. if (ChangeMakeCode != "Yes")
  301. {
  302. makecode = ma_code.Text;
  303. }
  304. else
  305. {
  306. NoteAlready = true;
  307. }
  308. }
  309. if (CheckRoutePassed(sncode,isource, makecode,out oErrMessage))
  310. {
  311. if (!NoteAlready)
  312. {
  313. if (makecode != ma_code.Text && ma_code.Text != "" && status != "")
  314. {
  315. string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  316. //如果选择不切换赋值当前界面工单
  317. if (ChangeMakeCode == "Yes")
  318. {
  319. ma_code.Text = makecode;
  320. }
  321. else
  322. {
  323. OperateResult.AppendText(">>请重新采集序列号\n");
  324. tipform.startthread("请重新采集序列号", test_result);
  325. return;
  326. }
  327. }
  328. }
  329. //获取序列号ID最大的工单
  330. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_makecode,ms_id,ms_craftcode,ms_prodcode from makeserial where ms_sncode='" + sncode + "' order by ms_id desc", "select");
  331. if (dt.Rows.Count > 0)
  332. {
  333. string ms_status = dt.Rows[0]["ms_status"].ToString();
  334. string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  335. string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  336. ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
  337. makecode = dt.Rows[0]["ms_makecode"].ToString();
  338. switch (test_result)
  339. {
  340. case "OK":
  341. if(BaseUtil.GetCacheData("Status").ToString() != "offline")
  342. {
  343. if (ms_status == "3")
  344. {
  345. string nextstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id=cd_crid ", "cd_nextstepcode", "cr_code='" + ms_craftcode + "' and cr_prodcode='" + ms_prodcode + "' and cd_stepcode='" + istepcode + "'").ToString();
  346. dh.UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'");
  347. dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + sncode + "' and mb_makecode='" + makecode + "'");
  348. }
  349. if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", test_result, iusercode, out oErrMessage))
  350. {
  351. OperateResult.AppendText(oErrMessage + "\n");
  352. tipform.startthread(oErrMessage, test_result);
  353. return;
  354. }
  355. }
  356. tipform.startthread("序列号 " + sncode + "通过检测,OK", test_result);
  357. break;
  358. case "NG":
  359. if (BaseUtil.GetCacheData("Status").ToString() != "offline")
  360. {
  361. RecordBadInfo(sncode, makecode, e.Name, "");
  362. //所有的序列号均采集为良品
  363. if (!LogicHandler.SetTestNGDetail(sncode, makecode, iusercode, isource, test_result, out oErrMessage))
  364. {
  365. OperateResult.AppendText(oErrMessage + "\n");
  366. tipform.startthread(oErrMessage, test_result);
  367. return;
  368. }
  369. }
  370. tipform.startthread("序列号 " + sncode + "未通过检测,NG", test_result);
  371. break;
  372. default:
  373. break;
  374. }
  375. LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, e.Name, test_result == "NG" ? "1" : "0", "0");
  376. }
  377. }
  378. else
  379. {
  380. OperateResult.AppendText(oErrMessage + "\n");
  381. tipform.startthread(oErrMessage, "NG");
  382. return;
  383. }
  384. if (BaseUtil.GetCacheData("Mode").ToString() != "SPI")
  385. {
  386. string sql = "insert into STEPTESTDETAIL(std_id,std_makecode,std_sn,std_subclass1,std_subclass2,std_subclass3,std_testresult,std_indate,";
  387. sql += "std_rescode,std_testdate,std_testtime,std_date) values(STEPTESTDETAIL_seq.nextval, '" + makecode + "', ";
  388. sql += "'" + sncode + "',:std_subclass1,:std_subclass2,:std_subclass3,:std_testresult, sysdate,'" + isource + "',to_char(to_date('" + testDate + "','YYYY/MM/DD'), 'YYYYMMDD'),";
  389. sql += "to_char(to_date('" + testTime + "','hh24:mi:ss'), 'hh24miss'),to_date('" + test_date + "','YYYY/MM/DD hh24:mi:ss'))";
  390. dh.BatchInsert(sql, new string[] { "std_subclass1", "std_subclass2", "std_subclass3", "std_testresult" }, name.ToArray(), class2.ToArray(), class3.ToArray(), result.ToArray());
  391. }
  392. else {
  393. string sql = "insert into SPIDATA(SPI_ID,SPI_SNCODE,SPI_ITEM,SPI_RESULT,SPI_DATE,SPI_TESTDATE) values(SPIDATA_SEQ.nextval, ";
  394. sql += "'" + sncode + "',:std_subclass1,:std_testresult, sysdate,";
  395. sql += "to_date('" + test_date + "','YYYY/MM/DD hh24:mi:ss'))";
  396. dh.BatchInsert(sql, new string[] { "std_subclass1", "std_testresult" }, name.ToArray(), result.ToArray());
  397. }
  398. FileInfo file = new FileInfo(FolderPath.Text + @"\" + e.Name);
  399. if (file.Exists)
  400. {
  401. try
  402. {
  403. for (int i = 1; i <= 20; i++)
  404. {
  405. if (!File.Exists(BackUpFolderPath.Text + @"\" + e.Name))
  406. {
  407. file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name);
  408. OperateResult.AppendText("成功解析文件" + e.Name + "\n");
  409. //tipform.startthread(e.Name);
  410. break;
  411. }
  412. else if (!File.Exists(BackUpFolderPath.Text + @"\" + e.Name.Split('.')[0] + "(" + i + ")" + "." + e.Name.Split('.')[1]))
  413. {
  414. file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name.Split('.')[0] + "(" + i + ")" + "." + e.Name.Split('.')[1]);
  415. OperateResult.AppendText("成功解析文件" + e.Name + "\n");
  416. //tipform.startthread(e.Name);
  417. break;
  418. }
  419. }
  420. }
  421. catch (Exception ex)
  422. {
  423. OperateResult.AppendText(e.Name + ex.Message + "\n");
  424. }
  425. }
  426. }
  427. private void StopWatch_Click(object sender, EventArgs e)
  428. {
  429. XmlWatcher.EnableRaisingEvents = false;
  430. StartWatch.Enabled = true;
  431. ChooseFolder.Enabled = true;
  432. ChooseBackUpFolder.Enabled = true;
  433. StopWatch.Enabled = false;
  434. OperateResult.AppendText("停止执行监控\n");
  435. }
  436. private void Clean_Click(object sender, EventArgs e)
  437. {
  438. OperateResult.Clear();
  439. }
  440. private void ChooseFolder_Click(object sender, EventArgs e)
  441. {
  442. FolderBrowserDialog folder = new FolderBrowserDialog();
  443. folder.Description = "选择监控文件夹";
  444. DialogResult result = folder.ShowDialog();
  445. if (result == DialogResult.OK)
  446. {
  447. FolderPath.Text = folder.SelectedPath;
  448. }
  449. }
  450. private void ReadNodeFromXML(string FileName)
  451. {
  452. }
  453. private void RecordBadInfo(string sncode, string makecode, string filename, string combine)
  454. {
  455. string ID = dh.GetSEQ("makebad_seq");
  456. sql.Clear();
  457. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  458. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark) select "+ ID + "");
  459. sql.Append(",ma_code,ms_code,ms_sncode,'" + iusercode + "',sysdate,'" + istepcode + "','" + isource + "',");
  460. sql.Append("'','" + ibadgroup + "','','0','' from make left join makeSerial on ms_makecode=ma_code ");
  461. sql.Append("where ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'");
  462. dh.ExecuteSql(sql.ToString(),"insert");
  463. sql.Clear();
  464. 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) ");
  465. sql.Append("where mb_id="+ ID + "");
  466. dh.ExecuteSql(sql.ToString(), "insert");
  467. //记录判断日志
  468. if (dh.getFieldDataByCondition("source", "sc_scantype", "sc_code='" + isource + "'").ToString() == "REJUCE")
  469. {
  470. LogicHandler.AutoPassJudge(sncode, makecode, isource, filename, ilinecode, combine);
  471. }
  472. }
  473. private void ChooseBackUpFolder_Click(object sender, EventArgs e)
  474. {
  475. FolderBrowserDialog folder = new FolderBrowserDialog();
  476. folder.Description = "选择备份文件夹";
  477. DialogResult result = folder.ShowDialog();
  478. if (result == DialogResult.OK)
  479. {
  480. BackUpFolderPath.Text = folder.SelectedPath;
  481. }
  482. }
  483. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  484. {
  485. string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  486. if (ExitConfirm != "Yes")
  487. {
  488. WindowState = FormWindowState.Minimized;
  489. e.Cancel = true;
  490. }
  491. }
  492. private void AutoStart_CheckedChanged(object sender, EventArgs e)
  493. {
  494. SetAutoRun();
  495. }
  496. public bool CheckRoutePassed(string iSN, string iResCode,string makecode, out string oErrMessage)
  497. {
  498. if (iSN == "")
  499. {
  500. oErrMessage = "SN不能为空";
  501. return false;
  502. }
  503. oErrMessage = "";
  504. string[] param = new string[] { ma_code.Text == "" ? makecode : ma_code.Text, iResCode, iSN, iusercode, "", "", oErrMessage };
  505. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
  506. dh.CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  507. oErrMessage = param[6];
  508. DataTable dt = (DataTable)dh.ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=( select max(ms_id) from makeserial where ms_sncode in ( select '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
  509. string ms_status = "";
  510. string ms_stepcode = "";
  511. string ms_nextstepcode = "";
  512. if (dt.Rows.Count > 0)
  513. {
  514. ms_status = dt.Rows[0]["ms_status"].ToString();
  515. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  516. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  517. }
  518. string stepcode = GetStepCodeBySource(iResCode);
  519. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  520. {
  521. oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
  522. return false;
  523. }
  524. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
  525. {
  526. if (ms_status == "3")
  527. {
  528. oErrMessage = "";
  529. }
  530. return true;
  531. }
  532. else
  533. return false;
  534. }
  535. private string GetStepCodeBySource(string Source)
  536. {
  537. return dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  538. }
  539. }
  540. }