Make_ImeiCheck_ThreeLabel.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicForm;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_ImeiCheck_ThreeLabel : Form
  16. {
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. DataHelper dh;
  19. LogStringBuilder sql;
  20. DataTable dt;
  21. DataTable info;
  22. string imei1 = "";
  23. string imei2 = "";
  24. bool isImei1 = false;
  25. bool isImei2 = false;
  26. string oErrorMessage = "";
  27. string SN = "";
  28. string omakeCode = "";
  29. string oMsid = "";
  30. public Make_ImeiCheck_ThreeLabel()
  31. {
  32. InitializeComponent();
  33. }
  34. private void Make_LabelCheck_Load(object sender, EventArgs e)
  35. {
  36. asc.controllInitializeSize(this);
  37. //聚焦SN号
  38. sncode.Focus();
  39. //打开界面提示用户:请输入SN
  40. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  41. sql = new LogStringBuilder();
  42. dh = SystemInf.dh;
  43. StepCount.StepCode = User.CurrentStepCode;
  44. StepCount.Source = User.UserSourceCode;
  45. StepCount.LineCode = User.UserLineCode;
  46. StepCount.Dh = dh;
  47. StepCount.Start();
  48. }
  49. string checksn = "";
  50. private void Make_LabelCheck_SizeChanged(object sender, EventArgs e)
  51. {
  52. asc.controlAutoSize(this);
  53. }
  54. private void sncode_KeyDown(object sender, KeyEventArgs e)
  55. {
  56. //判断是enter事件
  57. if (e.KeyCode == Keys.Enter)
  58. {
  59. if (sncode.Text == "")
  60. {
  61. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  62. return;
  63. }
  64. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sncode.Text + "' order by ms_id desc", "select");
  65. if (dt.Rows.Count > 0)
  66. {
  67. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  68. }
  69. else
  70. {
  71. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sncode.Text + "' order by ms_id desc", "select");
  72. if (dt.Rows.Count > 0)
  73. {
  74. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  75. }
  76. else
  77. {
  78. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sncode.Text + "' order by mil_id desc", "select");
  79. if (dt.Rows.Count > 0)
  80. {
  81. sncode.Text = dt.Rows[0]["mil_sncode"].ToString();
  82. }
  83. else
  84. {
  85. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sncode.Text + "' order by mil_id desc", "select");
  86. if (dt.Rows.Count > 0)
  87. {
  88. sncode.Text = dt.Rows[0]["mil_sncode"].ToString();
  89. }
  90. }
  91. }
  92. }
  93. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  94. {
  95. }
  96. //输入的是SN
  97. if (!isImei1 && !isImei2)
  98. {
  99. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  100. sql.Clear();
  101. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "'");
  102. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  103. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  104. {
  105. sql.Clear();
  106. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  107. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  108. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  109. {
  110. sql.Clear();
  111. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  112. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  113. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  114. {
  115. sql.Clear();
  116. sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei1 ='" + sncode.Text + "'");
  117. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  118. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  119. {
  120. sql.Clear();
  121. sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei2 ='" + sncode.Text + "'");
  122. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  123. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  124. {
  125. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.Red, sncode);
  126. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  127. }
  128. }
  129. }
  130. }
  131. }
  132. //存在该SN号
  133. //根据该ms_id查询ms_imei1,ms_makecode信息
  134. sql.Clear();
  135. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  136. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  137. if (info.Rows.Count > 0)
  138. {
  139. //用变量记录imei1和makecode
  140. checksn = info.Rows[0]["ms_sncode"].ToString();
  141. SN = sncode.Text;
  142. //>> 请输入彩盒上的SN
  143. OperateResult.AppendText("<<条码" + sncode.Text + "对应的SN号为:" + checksn + "\n", Color.Green);
  144. OperateResult.AppendText(">>请输入需要核对的条码1\n", Color.Black, sncode);
  145. //设定要输入imei1
  146. isImei1 = true;
  147. }
  148. else
  149. {
  150. OperateResult.AppendText("<<SN:" + sncode.Text + "对应的SN不存在\n", Color.Red, sncode);
  151. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  152. SetCheck set = new SetCheck("NG", Color.Red);
  153. BaseUtil.SetFormCenter(set);
  154. set.ShowDialog();
  155. }
  156. }
  157. else if (isImei1)
  158. {
  159. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  160. sql.Clear();
  161. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "'");
  162. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  163. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  164. {
  165. sql.Clear();
  166. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  167. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  168. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  169. {
  170. sql.Clear();
  171. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  172. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  173. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  174. {
  175. sql.Clear();
  176. sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei1 ='" + sncode.Text + "'");
  177. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  178. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  179. {
  180. sql.Clear();
  181. sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei2 ='" + sncode.Text + "'");
  182. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  183. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  184. {
  185. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.Red, sncode);
  186. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  187. SetCheck set = new SetCheck("NG", Color.Red);
  188. BaseUtil.SetFormCenter(set);
  189. set.ShowDialog();
  190. }
  191. }
  192. }
  193. }
  194. }
  195. sql.Clear();
  196. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  197. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  198. if (info.Rows.Count > 0)
  199. {
  200. imei1 = info.Rows[0]["ms_sncode"].ToString();
  201. }
  202. if (imei1 == checksn)
  203. {
  204. OperateResult.AppendText("<<条码1核对成功\n", Color.Green, sncode);
  205. OperateResult.AppendText(">>请输入需要核对的条码2\n", Color.Black);
  206. isImei2 = true;
  207. isImei1 = false;
  208. }
  209. else
  210. {
  211. //清空imei1变量的值
  212. imei1 = "";
  213. imei2 = "";
  214. checksn = "";
  215. //SN核对失败
  216. //>> 请输入SN
  217. OperateResult.AppendText(">>SN核对失败,不一致\n", Color.Red, sncode);
  218. SetCheck set = new SetCheck("NG", Color.Red);
  219. BaseUtil.SetFormCenter(set);
  220. set.ShowDialog();
  221. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  222. isImei1 = false;
  223. isImei2 = false;
  224. }
  225. }
  226. //输入的是imei1
  227. else
  228. {
  229. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  230. sql.Clear();
  231. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "'");
  232. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  233. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  234. {
  235. sql.Clear();
  236. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  237. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  238. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  239. {
  240. sql.Clear();
  241. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  242. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  243. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  244. {
  245. sql.Clear();
  246. sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei1 ='" + sncode.Text + "'");
  247. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  248. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  249. {
  250. sql.Clear();
  251. sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei2 ='" + sncode.Text + "'");
  252. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  253. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  254. {
  255. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.Red, sncode);
  256. SetCheck set = new SetCheck("NG", Color.Red);
  257. BaseUtil.SetFormCenter(set);
  258. set.ShowDialog();
  259. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  260. }
  261. }
  262. }
  263. }
  264. }
  265. sql.Clear();
  266. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  267. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  268. if (info.Rows.Count > 0)
  269. {
  270. imei2 = info.Rows[0]["ms_sncode"].ToString();
  271. }
  272. if (imei1 == checksn && imei2 == checksn)
  273. {
  274. //说明输入的imei1对比一致
  275. //判断工序属性attribute
  276. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  277. {
  278. //判断序列号下一工序(CHECKSTEPSNANDMACODE)
  279. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, checksn, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  280. {
  281. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
  282. if (nextstepcode != User.CurrentStepCode)
  283. {
  284. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  285. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sncode);
  286. imei1 = "";
  287. imei2 = "";
  288. checksn = "";
  289. isImei1 = false;
  290. isImei2 = false;
  291. return;
  292. }
  293. //调用 SETSTEPRESULT ,获取返回的工单号,
  294. if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, checksn, "标签核对", "OK", User.UserCode, out oErrorMessage))
  295. {
  296. //提示正确返回时传递的信息
  297. if (oErrorMessage.Contains("AFTERSUCCESS"))
  298. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  299. //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  300. sql.Clear();
  301. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  302. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  303. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  304. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  305. BaseUtil.SetFormValue(Controls, dt);
  306. //将SN,时间,结果记录在页面
  307. recordResult(checksn, DateTime.Now.ToString(), "成功");
  308. //记录日志
  309. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, "");
  310. //SN核对成功
  311. //>> 请输入SN
  312. OperateResult.AppendText("<<条码2核对成功\n", Color.Green, sncode);
  313. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  314. }
  315. else
  316. {
  317. //setstepresult不通过
  318. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  319. recordResult(checksn, DateTime.Now.ToString(), "失败");
  320. SetCheck set = new SetCheck("NG", Color.Red);
  321. BaseUtil.SetFormCenter(set);
  322. set.ShowDialog();
  323. }
  324. }
  325. else
  326. {
  327. //判定序列号下一工序不通过
  328. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  329. recordResult(checksn, DateTime.Now.ToString(), "失败");
  330. SetCheck set = new SetCheck("NG", Color.Red);
  331. BaseUtil.SetFormCenter(set);
  332. set.ShowDialog();
  333. }
  334. }
  335. else
  336. {
  337. //判定工序属性不通过
  338. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  339. SetCheck set = new SetCheck("NG", Color.Red);
  340. BaseUtil.SetFormCenter(set);
  341. set.ShowDialog();
  342. recordResult(checksn, DateTime.Now.ToString(), "失败");
  343. }
  344. }
  345. //说明比对不一致
  346. else
  347. {
  348. //清空imei1变量的值
  349. imei1 = "";
  350. imei2 = "";
  351. checksn = "";
  352. //SN核对失败
  353. //>> 请输入SN
  354. OperateResult.AppendText(">>SN核对失败,不一致\n", Color.Red, sncode);
  355. SetCheck set = new SetCheck("NG", Color.Red);
  356. BaseUtil.SetFormCenter(set);
  357. set.ShowDialog();
  358. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  359. }
  360. //imei1校对结束,下次输入的是SN
  361. isImei1 = false;
  362. isImei2 = false;
  363. }
  364. }
  365. }
  366. private void recordResult(string SN, string time, string result)
  367. {
  368. ListViewItem lvi = new ListViewItem();
  369. //分条赋值
  370. lvi.SubItems.Add(SN);
  371. lvi.SubItems.Add(time);
  372. lvi.SubItems.Add(result);
  373. //添加结果的信息进去
  374. showResult.Items.Add(lvi);
  375. }
  376. private void clear()
  377. {
  378. //清空变量的值
  379. omakeCode = "";
  380. oMsid = "";
  381. SN = "";
  382. imei1 = "";
  383. imei2 = "";
  384. checksn = "";
  385. }
  386. private void StepCount_Load(object sender, EventArgs e)
  387. {
  388. }
  389. }
  390. }