Make_ImeiCheck_ThreeLabel_WN.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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_WN : 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_WN()
  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.DarkRed);
  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.DarkRed, 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.DarkRed, sncode);
  151. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  152. SetCheck set = new SetCheck("NG", Color.DarkRed);
  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.DarkRed, sncode);
  186. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  187. SetCheck set = new SetCheck("NG", Color.DarkRed);
  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.DarkRed, sncode);
  218. SetCheck set = new SetCheck("NG", Color.DarkRed);
  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 left join craftmaterial on cm_sncode=ms_sncode and cm_makecode=ms_makecode where cm_barcode ='" + sncode.Text + "' and nvl(cm_status,0)<>-1");
  232. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  233. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  234. {
  235. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.DarkRed, sncode);
  236. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  237. }
  238. sql.Clear();
  239. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  240. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  241. if (info.Rows.Count > 0)
  242. {
  243. imei2 = info.Rows[0]["ms_sncode"].ToString();
  244. }
  245. if (imei1 == checksn && imei2 == checksn)
  246. {
  247. //说明输入的imei1对比一致
  248. //判断工序属性attribute
  249. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  250. {
  251. //判断序列号下一工序(CHECKSTEPSNANDMACODE)
  252. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, checksn, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  253. {
  254. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
  255. if (nextstepcode != User.CurrentStepCode)
  256. {
  257. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  258. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.DarkRed, sncode);
  259. imei1 = "";
  260. imei2 = "";
  261. checksn = "";
  262. isImei1 = false;
  263. isImei2 = false;
  264. return;
  265. }
  266. //调用 SETSTEPRESULT ,获取返回的工单号,
  267. if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, checksn, "标签核对", "OK", User.UserCode, out oErrorMessage))
  268. {
  269. //提示正确返回时传递的信息
  270. if (oErrorMessage.Contains("AFTERSUCCESS"))
  271. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  272. //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  273. sql.Clear();
  274. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  275. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  276. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  277. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  278. BaseUtil.SetFormValue(Controls, dt);
  279. //将SN,时间,结果记录在页面
  280. recordResult(checksn, DateTime.Now.ToString(), "成功");
  281. //记录日志
  282. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, "");
  283. //SN核对成功
  284. //>> 请输入SN
  285. OperateResult.AppendText("<<条码2核对成功\n", Color.LightGreen, sncode);
  286. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  287. }
  288. else
  289. {
  290. //setstepresult不通过
  291. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode);
  292. recordResult(checksn, DateTime.Now.ToString(), "失败");
  293. SetCheck set = new SetCheck("NG", Color.DarkRed);
  294. BaseUtil.SetFormCenter(set);
  295. set.ShowDialog();
  296. }
  297. }
  298. else
  299. {
  300. //判定序列号下一工序不通过
  301. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode);
  302. recordResult(checksn, DateTime.Now.ToString(), "失败");
  303. SetCheck set = new SetCheck("NG", Color.DarkRed);
  304. BaseUtil.SetFormCenter(set);
  305. set.ShowDialog();
  306. }
  307. }
  308. else
  309. {
  310. //判定工序属性不通过
  311. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode);
  312. SetCheck set = new SetCheck("NG", Color.DarkRed);
  313. BaseUtil.SetFormCenter(set);
  314. set.ShowDialog();
  315. recordResult(checksn, DateTime.Now.ToString(), "失败");
  316. }
  317. }
  318. //说明比对不一致
  319. else
  320. {
  321. //清空imei1变量的值
  322. imei1 = "";
  323. imei2 = "";
  324. checksn = "";
  325. //SN核对失败
  326. //>> 请输入SN
  327. OperateResult.AppendText(">>SN核对失败,不一致\n", Color.DarkRed, sncode);
  328. SetCheck set = new SetCheck("NG", Color.DarkRed);
  329. BaseUtil.SetFormCenter(set);
  330. set.ShowDialog();
  331. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  332. }
  333. //imei1校对结束,下次输入的是SN
  334. isImei1 = false;
  335. isImei2 = false;
  336. }
  337. }
  338. }
  339. private void recordResult(string SN, string time, string result)
  340. {
  341. ListViewItem lvi = new ListViewItem();
  342. //分条赋值
  343. lvi.SubItems.Add(SN);
  344. lvi.SubItems.Add(time);
  345. lvi.SubItems.Add(result);
  346. //添加结果的信息进去
  347. showResult.Items.Add(lvi);
  348. }
  349. private void clear()
  350. {
  351. //清空变量的值
  352. omakeCode = "";
  353. oMsid = "";
  354. SN = "";
  355. imei1 = "";
  356. imei2 = "";
  357. checksn = "";
  358. }
  359. private void StepCount_Load(object sender, EventArgs e)
  360. {
  361. }
  362. }
  363. }