Make_ImeiCheck.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 : Form
  16. {
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. DataHelper dh;
  19. LogStringBuilder sql;
  20. DataTable dt;
  21. DataTable info;
  22. string imei1 = "";
  23. bool isImei1 = false;
  24. string oErrorMessage = "";
  25. string SN = "";
  26. string omakeCode = "";
  27. string oMsid = "";
  28. public Make_ImeiCheck()
  29. {
  30. InitializeComponent();
  31. }
  32. private void Make_LabelCheck_Load(object sender, EventArgs e)
  33. {
  34. asc.controllInitializeSize(this);
  35. //聚焦SN号
  36. sncode.Focus();
  37. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  38. ma_code.SelectField = "ma_code # 工单号,ma_pocode # 内部订单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  39. ma_code.FormName = Name;
  40. ma_code.SetValueField = new string[] { "ma_code", "ma_pocode", "ma_prodcode", "ma_qty", "substr(pr_spec,0,50)pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  41. ma_code.Condition = "ma_statuscode='STARTED'";
  42. ma_code.DbChange += Ma_code_DbChange;
  43. //打开界面提示用户:请输入SN
  44. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  45. sql = new LogStringBuilder();
  46. dh = SystemInf.dh;
  47. LockMakeCode.GetMakeCodeCtl(ma_code);
  48. ma_code.SetLockCheckBox(LockMakeCode);
  49. StepCount.StepCode = User.CurrentStepCode;
  50. StepCount.Source = User.UserSourceCode;
  51. StepCount.LineCode = User.UserLineCode;
  52. StepCount.Dh = dh;
  53. StepCount.Start();
  54. }
  55. DataTable Dbfind;
  56. private void Ma_code_DbChange(object sender, EventArgs e)
  57. {
  58. Dbfind = ma_code.ReturnData;
  59. BaseUtil.SetFormValue(this.Controls, Dbfind);
  60. }
  61. private void Make_LabelCheck_SizeChanged(object sender, EventArgs e)
  62. {
  63. asc.controlAutoSize(this);
  64. }
  65. private void sncode_KeyDown(object sender, KeyEventArgs e)
  66. {
  67. //判断是enter事件
  68. if (e.KeyCode == Keys.Enter)
  69. {
  70. if (sncode.Text == "")
  71. {
  72. OperateResult.AppendText("<<输入不能为空\n", Color.DarkRed);
  73. return;
  74. }
  75. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_code='" + sncode.Text + "' or ms_imei1='" + sncode.Text + "' order by ms_id desc", "select");
  76. if (dt.Rows.Count > 0)
  77. {
  78. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  79. }
  80. else
  81. {
  82. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sncode.Text + "' order by ms_id desc", "select");
  83. if (dt.Rows.Count > 0)
  84. {
  85. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  86. }
  87. else
  88. {
  89. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sncode.Text + "' order by mil_id desc", "select");
  90. if (dt.Rows.Count > 0)
  91. {
  92. sncode.Text = dt.Rows[0]["mil_sncode"].ToString();
  93. }
  94. else
  95. {
  96. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sncode.Text + "' order by mil_id desc", "select");
  97. if (dt.Rows.Count > 0)
  98. {
  99. sncode.Text = dt.Rows[0]["mil_sncode"].ToString();
  100. }
  101. }
  102. }
  103. }
  104. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  105. {
  106. }
  107. //输入的是SN
  108. if (!isImei1)
  109. {
  110. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  111. sql.Clear();
  112. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "' or ms_code='" + sncode.Text + "'");
  113. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  114. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  115. {
  116. sql.Clear();
  117. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  118. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  119. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  120. {
  121. sql.Clear();
  122. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  123. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  124. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  125. {
  126. sql.Clear();
  127. 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 + "'");
  128. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  129. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  130. {
  131. sql.Clear();
  132. 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 + "'");
  133. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  134. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  135. {
  136. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.DarkRed, sncode);
  137. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  138. }
  139. }
  140. }
  141. }
  142. }
  143. //存在该SN号
  144. //根据该ms_id查询ms_imei1,ms_makecode信息
  145. sql.Clear();
  146. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  147. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  148. if (info.Rows.Count > 0)
  149. {
  150. //用变量记录imei1和makecode
  151. imei1 = info.Rows[0]["ms_sncode"].ToString();
  152. SN = sncode.Text;
  153. //>> 请输入彩盒上的SN
  154. OperateResult.AppendText("<<条码" + sncode.Text + "对应的SN号为:" + imei1 + "\n", Color.Green);
  155. OperateResult.AppendText(">>请输入需要核对的条码\n", Color.Black, sncode);
  156. //设定要输入imei1
  157. isImei1 = true;
  158. }
  159. else
  160. {
  161. OperateResult.AppendText("<<SN:" + sncode.Text + "对应的SN不存在\n", Color.DarkRed, sncode);
  162. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  163. SetCheck set = new SetCheck("NG", Color.DarkRed);
  164. BaseUtil.SetFormCenter(set);
  165. set.ShowDialog();
  166. }
  167. }
  168. //输入的是imei1
  169. else
  170. {
  171. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  172. sql.Clear();
  173. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "' or ms_code='" + sncode.Text + "'");
  174. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  175. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  176. {
  177. sql.Clear();
  178. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  179. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  180. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  181. {
  182. sql.Clear();
  183. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  184. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  185. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  186. {
  187. sql.Clear();
  188. 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 + "'");
  189. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  190. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  191. {
  192. sql.Clear();
  193. 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 + "'");
  194. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  195. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  196. {
  197. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.DarkRed, sncode);
  198. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  199. }
  200. }
  201. }
  202. }
  203. }
  204. sql.Clear();
  205. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  206. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  207. string checksn = "";
  208. if (info.Rows.Count > 0)
  209. {
  210. checksn = info.Rows[0]["ms_sncode"].ToString();
  211. }
  212. if (imei1 == checksn)
  213. {
  214. //说明输入的imei1对比一致
  215. //判断工序属性attribute
  216. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  217. {
  218. //判断序列号下一工序(CHECKSTEPSNANDMACODE)
  219. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, checksn, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  220. {
  221. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
  222. if (nextstepcode != User.CurrentStepCode)
  223. {
  224. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  225. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.DarkRed, sncode);
  226. imei1 = "";
  227. isImei1 = false;
  228. return;
  229. }
  230. //调用 SETSTEPRESULT ,获取返回的工单号,
  231. if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, checksn, "标签核对", "OK", User.UserCode, out oErrorMessage))
  232. {
  233. //提示正确返回时传递的信息
  234. if (oErrorMessage.Contains("AFTERSUCCESS"))
  235. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  236. //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  237. sql.Clear();
  238. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  239. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  240. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  241. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  242. BaseUtil.SetFormValue(Controls, dt);
  243. //将SN,时间,结果记录在页面
  244. recordResult(checksn, DateTime.Now.ToString(), "成功");
  245. //记录日志
  246. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, "");
  247. //SN核对成功
  248. //>> 请输入SN
  249. OperateResult.AppendText("<<SN核对成功\n", Color.LightGreen, sncode);
  250. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  251. }
  252. else
  253. {
  254. //setstepresult不通过
  255. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode);
  256. recordResult(checksn, DateTime.Now.ToString(), "失败");
  257. SetCheck set = new SetCheck("NG", Color.DarkRed);
  258. BaseUtil.SetFormCenter(set);
  259. set.ShowDialog();
  260. }
  261. }
  262. else
  263. {
  264. //判定序列号下一工序不通过
  265. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode);
  266. recordResult(checksn, DateTime.Now.ToString(), "失败");
  267. SetCheck set = new SetCheck("NG", Color.DarkRed);
  268. BaseUtil.SetFormCenter(set);
  269. set.ShowDialog();
  270. }
  271. }
  272. else
  273. {
  274. //判定工序属性不通过
  275. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode);
  276. recordResult(checksn, DateTime.Now.ToString(), "失败");
  277. }
  278. }
  279. //说明比对不一致
  280. else
  281. {
  282. //清空imei1变量的值
  283. imei1 = "";
  284. //SN核对失败
  285. //>> 请输入SN
  286. OperateResult.AppendText(">>SN核对失败,不一致\n", Color.DarkRed, sncode);
  287. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  288. }
  289. //imei1校对结束,下次输入的是SN
  290. isImei1 = false;
  291. }
  292. }
  293. }
  294. private void recordResult(string SN, string time, string result)
  295. {
  296. ListViewItem lvi = new ListViewItem();
  297. //分条赋值
  298. lvi.SubItems.Add(SN);
  299. lvi.SubItems.Add(time);
  300. lvi.SubItems.Add(result);
  301. //添加结果的信息进去
  302. showResult.Items.Add(lvi);
  303. }
  304. private void clear()
  305. {
  306. //清空变量的值
  307. omakeCode = "";
  308. oMsid = "";
  309. SN = "";
  310. imei1 = "";
  311. }
  312. private void StepCount_Load(object sender, EventArgs e)
  313. {
  314. }
  315. }
  316. }