Make_LabelCheck.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.PublicMethod;
  12. namespace UAS_MES_NEW.Make
  13. {
  14. public partial class Make_LabelCheck : Form
  15. {
  16. AutoSizeFormClass asc = new AutoSizeFormClass();
  17. DataHelper dh;
  18. LogStringBuilder sql;
  19. DataTable dt;
  20. DataTable info;
  21. DataTable checkItemInfo;//存储需要核对的所有信息列表
  22. string needCheckedInfo = "";
  23. bool isCheckItem = false;
  24. string oErrorMessage = "";
  25. string SN = "";
  26. string TSN = "";//存TSN
  27. string omakeCode = "";
  28. string oMsid = "";
  29. int checkIndex = 0;//记录核对的当前位置,从0开始
  30. public Make_LabelCheck()
  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. private void Make_LabelCheck_SizeChanged(object sender, EventArgs e)
  50. {
  51. asc.controlAutoSize(this);
  52. }
  53. private void sncode_KeyDown(object sender, KeyEventArgs e)
  54. {
  55. //判断是enter事件
  56. if (e.KeyCode == Keys.Enter)
  57. {
  58. if (sncode.Text == "") {
  59. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  60. return;
  61. }
  62. //输入的是SN
  63. if (!isCheckItem)
  64. {
  65. OperateResult.AppendText("<<"+sncode.Text+"\n", Color.Black);
  66. //查询是否存在该ms_id
  67. sql.Clear();
  68. sql.Append("select ms_id,ms_prodcode,ms_makecode,ms_craftcode,ms_beforesn from makeserial where ms_id = (select max(ms_id) from makeserial where ms_sncode ='"+sncode.Text+"' )");
  69. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  70. if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "")
  71. {
  72. //SN错误,不存在
  73. //请输入SN
  74. OperateResult.AppendText("<<SN错误,序列号" + sncode.Text + "不存在\n", Color.Red, sncode);
  75. OperateResult.AppendText(">>请采集SN\n", Color.Black);
  76. return;
  77. }
  78. //存在该SN号,查询相关需要核对的信息
  79. sql.Clear();
  80. sql.Append("select checkitem,fsoncode,type,detno from (select psr_type checkitem ,'' fsoncode,'MS' type ,");
  81. sql.Append("ROW_NUMBER() OVER (order by psr_detno asc )detno from productsnrelation where psr_prodcode='"+ dt.Rows[0]["ms_prodcode"].ToString() + "' and nvl(psr_iflabelcheck,0)<>0");
  82. sql.Append(" UNION ALL select wm_concat(sp_soncode)checkitem,sp_fsoncode fsoncode ,'SP' type,");
  83. sql.Append(" ROW_NUMBER()OVER(order by min(sp_detno)asc) detno from make inner join stepbom on sb_bomversion=ma_bomversion and sb_prodcode=ma_prodcode");
  84. sql.Append(" inner join stepproduct on sp_sbid=sb_id where ma_code='"+ dt.Rows[0]["ms_makecode"].ToString() + "' and sb_craftcode='"+ dt.Rows[0]["ms_craftcode"].ToString() + "' and nvl(sp_iflabelcheck,0)<>0");
  85. sql.Append(" GROUP BY sp_fsoncode) order by type,detno");
  86. checkItemInfo = (DataTable)dh.ExecuteSql(sql.GetString(),"select");
  87. //判断是否无需要核对的项
  88. if (checkItemInfo.Rows.Count==0)
  89. {
  90. OperateResult.AppendText("<<序列号" + sncode.Text + "没有需要核对的项\n", Color.Red, sncode);
  91. OperateResult.AppendText(">>请采集SN\n", Color.Black);
  92. return;
  93. }
  94. //记录SN
  95. SN = sncode.Text;
  96. TSN = dt.Rows[0]["ms_beforesn"].ToString();
  97. //查询第一个需要核对的信息
  98. getNextInfo(checkIndex);
  99. //设定要输入核对信息
  100. isCheckItem = true;
  101. }
  102. //输入的是imei1
  103. else
  104. {
  105. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  106. if (needCheckedInfo == sncode.Text||((needCheckedInfo == sncode.Text.Replace(":", "").Replace("-", ""))&&(checkItemInfo.Rows[checkIndex]["checkitem"].ToString() == "MAC"|| checkItemInfo.Rows[checkIndex]["checkitem"].ToString() == "BT")))
  107. {
  108. checkIndex += 1;//序号+1,进入下一步
  109. if (checkIndex == checkItemInfo.Rows.Count)
  110. {
  111. //说明输入的核对信息对比一致
  112. //判断工序属性attribute
  113. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  114. {
  115. //判断序列号下一工序(CHECKSTEPSNANDMACODE)
  116. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  117. {
  118. //调用 SETSTEPRESULT ,获取返回的工单号,
  119. if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, SN, "标签核对", "OK", User.UserCode, out oErrorMessage))
  120. {
  121. //提示正确返回时传递的信息
  122. if (oErrorMessage.Contains("AFTERSUCCESS"))
  123. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  124. //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  125. sql.Clear();
  126. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  127. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  128. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  129. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  130. BaseUtil.SetFormValue(Controls, dt);
  131. //将SN,时间,结果记录在页面
  132. recordResult(SN, DateTime.Now.ToString(), "成功");
  133. //记录日志
  134. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, "");
  135. //IMEI核对成功
  136. //>> 请输入SN
  137. OperateResult.AppendText("<<核对成功\n", Color.Green, sncode);
  138. }
  139. else
  140. {
  141. //setstepresult不通过
  142. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  143. recordResult(SN, DateTime.Now.ToString(), "失败");
  144. }
  145. }
  146. else
  147. {
  148. //判定序列号下一工序不通过
  149. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  150. recordResult(SN, DateTime.Now.ToString(), "失败");
  151. }
  152. }
  153. else
  154. {
  155. //判定工序属性不通过
  156. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  157. recordResult(SN, DateTime.Now.ToString(), "失败");
  158. }
  159. OperateResult.AppendText(">>请采集SN\n", Color.Black);
  160. checkIndex = 0;
  161. isCheckItem = false;
  162. }
  163. else
  164. {
  165. //输入一致则进入下一个
  166. getNextInfo(checkIndex);
  167. }
  168. }
  169. //说明比对不一致
  170. else
  171. {
  172. //信息核对失败
  173. //>> 请输入SN
  174. OperateResult.AppendText(">>上料信息或序列号采集信息"+needCheckedInfo+"核对失败,不一致\n", Color.Red, sncode);
  175. //为采集信息
  176. if (checkItemInfo.Rows[checkIndex]["TYPE"].ToString() == "MS")
  177. {
  178. OperateResult.AppendText(">>请采集" + checkItemInfo.Rows[checkIndex]["checkitem"].ToString() + "\n", Color.Black, sncode);
  179. }
  180. else//为上料信息
  181. {
  182. OperateResult.AppendText(">>请采集物料" + checkItemInfo.Rows[checkIndex]["checkitem"].ToString() + "条码\n", Color.Black, sncode);
  183. }
  184. }
  185. }
  186. }
  187. }
  188. private void recordResult(string SN, string time, string result)
  189. {
  190. //if (showResult.Items.Count >= 10)
  191. //{
  192. // //如果有10行的话,则删除最前一行
  193. // showResult.Items.RemoveAt(0);
  194. //}
  195. //创建一个item
  196. ListViewItem lvi = new ListViewItem();
  197. //分条赋值
  198. lvi.SubItems.Add(SN);
  199. lvi.SubItems.Add(time);
  200. lvi.SubItems.Add(result);
  201. //添加结果的信息进去
  202. showResult.Items.Add(lvi);
  203. }
  204. private void clear() {
  205. //清空变量的值
  206. omakeCode = "";
  207. oMsid = "";
  208. SN = "";
  209. needCheckedInfo = "";
  210. }
  211. private void getNextInfo(int index)
  212. {
  213. //判断为上料或者采集信息
  214. //为采集信息
  215. if (checkItemInfo.Rows[index]["TYPE"].ToString() == "MS")
  216. {
  217. //从makeserial表中查询对应字段的值
  218. needCheckedInfo = dh.getFieldDataByCondition("makeserial","ms_"+ checkItemInfo.Rows[index]["checkitem"].ToString(),"ms_id ='"+ dt.Rows[0]["ms_id"].ToString() + "'").ToString();
  219. OperateResult.AppendText("<<序列号" + SN + "对应的"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "为" + needCheckedInfo + "\n", Color.Green);
  220. OperateResult.AppendText(">>请采集"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "\n", Color.Black, sncode);
  221. }
  222. else//为上料信息
  223. {
  224. //从craftmaterial中查询上料记录
  225. needCheckedInfo = dh.getFieldDataByCondition("craftmaterial", "cm_barcode", "cm_makecode='"+ dt.Rows[0]["ms_makecode"].ToString() + "' and cm_sncode in ('"+SN+"'"+(TSN==""?"":(",'"+TSN+"'"))+") and cm_fsoncode='"+checkItemInfo.Rows[index]["fsoncode"].ToString()+"' and cm_status=0").ToString();
  226. OperateResult.AppendText("<<序列号" + SN + "上料物料"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "的条码号为" + needCheckedInfo + "\n", Color.Green);
  227. OperateResult.AppendText(">>请采集物料"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "条码\n", Color.Black, sncode);
  228. }
  229. }
  230. private void cancel_Click(object sender, EventArgs e)
  231. {
  232. OperateResult.AppendText(">>请采集SN\n", Color.Black);
  233. checkIndex = 0;
  234. isCheckItem = false;
  235. SN = "";
  236. }
  237. }
  238. }