Make_ImeiCheck.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. //打开界面提示用户:请输入SN
  38. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  39. sql = new LogStringBuilder();
  40. dh = SystemInf.dh;
  41. StepCount.StepCode = User.CurrentStepCode;
  42. StepCount.Source = User.UserSourceCode;
  43. StepCount.LineCode = User.UserLineCode;
  44. StepCount.Dh = dh;
  45. StepCount.Start();
  46. }
  47. private void Make_LabelCheck_SizeChanged(object sender, EventArgs e)
  48. {
  49. asc.controlAutoSize(this);
  50. }
  51. private void sncode_KeyDown(object sender, KeyEventArgs e)
  52. {
  53. //判断是enter事件
  54. if (e.KeyCode == Keys.Enter)
  55. {
  56. if (sncode.Text == "")
  57. {
  58. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  59. return;
  60. }
  61. 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");
  62. if (dt.Rows.Count > 0)
  63. {
  64. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  65. }
  66. else
  67. {
  68. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sncode.Text + "' order by ms_id desc", "select");
  69. if (dt.Rows.Count > 0)
  70. {
  71. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  72. }
  73. }
  74. //输入的是SN
  75. if (!isImei1)
  76. {
  77. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  78. //查询是否存在该ms_id
  79. sql.Clear();
  80. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "' or ms_firstsn='" + sncode.Text + "'");
  81. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  82. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  83. {
  84. sql.Clear();
  85. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  86. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  87. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  88. {
  89. sql.Clear();
  90. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  91. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  92. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  93. {
  94. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.DarkRed, sncode);
  95. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  96. }
  97. }
  98. }
  99. //存在该SN号
  100. else
  101. {
  102. //根据该ms_id查询ms_imei1,ms_makecode信息
  103. sql.Clear();
  104. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  105. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  106. if (info.Rows.Count > 0)
  107. {
  108. //用变量记录imei1和makecode
  109. imei1 = info.Rows[0]["ms_sncode"].ToString();
  110. SN = sncode.Text;
  111. //>>SN对应的SN号为:xxxxxxxxx
  112. //>> 请输入彩盒上的SN
  113. OperateResult.AppendText("<<序列号" + sncode.Text + "对应的SN号为:" + imei1 + "\n", Color.Green);
  114. OperateResult.AppendText(">>请输入彩盒上的SN\n", Color.Black, sncode);
  115. //设定要输入imei1
  116. isImei1 = true;
  117. ////不为null 并且不为””才继续
  118. //if (info.Rows[0]["ms_imei1"].ToString() == null || info.Rows[0]["ms_imei1"].ToString() == "")
  119. //{
  120. // // SN对应的SN不存在
  121. // //>> 请输入SN
  122. // OperateResult.AppendText("<<序列号" + sncode.Text + "对应的SN不存在\n", Color.Red, sncode);
  123. // OperateResult.AppendText(">>请输入SN\n", Color.Black);
  124. //}
  125. //else
  126. ////存在该imei信息
  127. //{
  128. //}
  129. }
  130. else
  131. {
  132. OperateResult.AppendText("<<SN:" + sncode.Text + "对应的SN不存在\n", Color.Red, sncode);
  133. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  134. SetCheck set = new SetCheck("NG", Color.Red);
  135. BaseUtil.SetFormCenter(set);
  136. set.ShowDialog();
  137. }
  138. }
  139. }
  140. //输入的是imei1
  141. else
  142. {
  143. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  144. sql.Clear();
  145. sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "' or ms_code='" + sncode.Text + "'");
  146. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  147. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  148. {
  149. sql.Clear();
  150. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'");
  151. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  152. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  153. {
  154. sql.Clear();
  155. sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'");
  156. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  157. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  158. {
  159. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.DarkRed, sncode);
  160. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  161. }
  162. }
  163. }
  164. sql.Clear();
  165. sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'");
  166. info = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  167. string checksn = "";
  168. if (info.Rows.Count > 0)
  169. {
  170. checksn = info.Rows[0]["ms_sncode"].ToString();
  171. }
  172. if (imei1 == checksn)
  173. {
  174. //说明输入的imei1对比一致
  175. //判断工序属性attribute
  176. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  177. {
  178. //判断序列号下一工序(CHECKSTEPSNANDMACODE)
  179. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  180. {
  181. //调用 SETSTEPRESULT ,获取返回的工单号,
  182. if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, SN, "标签核对", "OK", User.UserCode, out oErrorMessage))
  183. {
  184. //提示正确返回时传递的信息
  185. if (oErrorMessage.Contains("AFTERSUCCESS"))
  186. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  187. //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  188. sql.Clear();
  189. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  190. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  191. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  192. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  193. BaseUtil.SetFormValue(Controls, dt);
  194. //将SN,时间,结果记录在页面
  195. recordResult(SN, DateTime.Now.ToString(), "成功");
  196. //记录日志
  197. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, "");
  198. //SN核对成功
  199. //>> 请输入SN
  200. OperateResult.AppendText("<<SN核对成功\n", Color.Green, sncode);
  201. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  202. SetCheck set = new SetCheck("OK", Color.Green);
  203. BaseUtil.SetFormCenter(set);
  204. set.ShowDialog();
  205. }
  206. else
  207. {
  208. //setstepresult不通过
  209. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  210. recordResult(SN, DateTime.Now.ToString(), "失败");
  211. SetCheck set = new SetCheck("NG", Color.Red);
  212. BaseUtil.SetFormCenter(set);
  213. set.ShowDialog();
  214. }
  215. }
  216. else
  217. {
  218. //判定序列号下一工序不通过
  219. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  220. recordResult(SN, DateTime.Now.ToString(), "失败");
  221. SetCheck set = new SetCheck("NG", Color.Red);
  222. BaseUtil.SetFormCenter(set);
  223. set.ShowDialog();
  224. }
  225. }
  226. else
  227. {
  228. //判定工序属性不通过
  229. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  230. recordResult(SN, DateTime.Now.ToString(), "失败");
  231. }
  232. }
  233. //说明比对不一致
  234. else
  235. {
  236. //清空imei1变量的值
  237. imei1 = "";
  238. //SN核对失败
  239. //>> 请输入SN
  240. OperateResult.AppendText(">>SN核对失败,不一致\n", Color.Red, sncode);
  241. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  242. }
  243. //imei1校对结束,下次输入的是SN
  244. isImei1 = false;
  245. }
  246. }
  247. }
  248. private void recordResult(string SN, string time, string result)
  249. {
  250. //if (showResult.Items.Count >= 10)
  251. //{
  252. // //如果有10行的话,则删除最前一行
  253. // showResult.Items.RemoveAt(0);
  254. //}
  255. //创建一个item
  256. ListViewItem lvi = new ListViewItem();
  257. //分条赋值
  258. lvi.SubItems.Add(SN);
  259. lvi.SubItems.Add(time);
  260. lvi.SubItems.Add(result);
  261. //添加结果的信息进去
  262. showResult.Items.Add(lvi);
  263. }
  264. private void clear()
  265. {
  266. //清空变量的值
  267. omakeCode = "";
  268. oMsid = "";
  269. SN = "";
  270. imei1 = "";
  271. }
  272. private void StepCount_Load(object sender, EventArgs e)
  273. {
  274. }
  275. }
  276. }