Make_ImeiCheck_EAN.cs 19 KB

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