Make_CollectNetCode.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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_CollectNetCode : Form
  15. {
  16. DataHelper dh;
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataTable dt;
  20. //当前序列号记录
  21. string sn_code;
  22. //制造单号
  23. string macode;
  24. //采集网标号
  25. string net_code;
  26. //网标查询条件ms_id
  27. string oMsID;
  28. //判断是否输入网标
  29. Boolean isnetcode = false;
  30. //打印计数
  31. int printcount = 0;
  32. int ma_unlimitin;
  33. public Make_CollectNetCode()
  34. {
  35. InitializeComponent();
  36. }
  37. private void Make_CollectNetCode_Load(object sender, EventArgs e)
  38. {
  39. asc.controllInitializeSize(this);
  40. sncode.Focus();
  41. dh = SystemInf.dh;
  42. StepCount.StepCode = User.CurrentStepCode;
  43. StepCount.Source = User.UserSourceCode;
  44. StepCount.LineCode = User.UserLineCode;
  45. StepCount.Dh = dh;
  46. StepCount.Start();
  47. }
  48. private void sncode_KeyDown(object sender, KeyEventArgs e)
  49. {
  50. if (e.KeyCode == Keys.Enter)
  51. {
  52. string ErrorMessage2;
  53. string oMakeCode;
  54. //采集序列号
  55. if (!isnetcode)
  56. {
  57. if (sncode.Text == "")
  58. {
  59. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  60. return;
  61. }
  62. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage2))
  63. {
  64. //判断界面工单是否为空时的序列号是否自动归属工单
  65. string oStatus = "";
  66. if (!LogicHandler.GetMakeInfo(sncode.Text, out oMakeCode, out oStatus, out ErrorMessage2))
  67. {
  68. if (ms_makecode.Text == "")
  69. {
  70. OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  71. return;
  72. }
  73. }
  74. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  75. // 获取工单归属工单下一工序是否正确
  76. if (LogicHandler.CheckStepSNAndMacode(ms_makecode.Text == "" ? oMakeCode : ms_makecode.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2))
  77. {
  78. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  79. if (nextstepcode != User.CurrentStepCode)
  80. {
  81. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, sncode);
  82. return;
  83. }
  84. sql.Clear();
  85. sql.Append("select ma_code as ms_makecode,nvl(mcd_okqty,0),ma_prodcode,pr_detail,");
  86. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0) ma_unlimitin from make left join makecraftdetail on ");
  87. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  88. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  89. if (dt.Rows.Count > 0)
  90. {
  91. ma_unlimitin = int.Parse(dt.Rows[0]["ma_unlimitin"].ToString());
  92. BaseUtil.SetFormValue(this.Controls, dt);
  93. //dh.UpdateByCondition("makeserial", "ms_currentstepcode = '" + User.CurrentStepCode + "'", "ms_id = '" + oMsID + "'");
  94. OperateResult.AppendText(">>请输入网标\n", Color.Black);
  95. sn_code = sncode.Text;
  96. sncode.Text = "";
  97. isnetcode = true;
  98. return;
  99. }
  100. else OperateResult.AppendText(">>序列号" + sncode.Text + "没有对应工序\n", Color.Red, sncode);
  101. }
  102. else OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  103. }
  104. else OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  105. }
  106. //采集netcode
  107. else
  108. {
  109. if (sncode.Text == "")
  110. {
  111. OperateResult.AppendText(">>网标号不能为空\n", Color.Red);
  112. return;
  113. }
  114. #region
  115. sql.Clear();
  116. sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'NETCODE'");
  117. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  118. if (dt.Rows.Count > 0)
  119. {
  120. int psr_length = int.Parse(dt.Rows[0][1].ToString());
  121. string psr_prefix = dt.Rows[0][0].ToString();
  122. if (!checkLengthOrPre(psr_length, psr_prefix, "网标"))
  123. {
  124. sncode.Text = "";
  125. sncode.Focus();
  126. return;
  127. }
  128. }
  129. else {
  130. OperateResult.AppendText("<<产品" + ma_prodcode.Text + "未维护网标关联信息\n", Color.Red,sncode);
  131. }
  132. #endregion
  133. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  134. string ErrorMessage = "";
  135. string result = "";
  136. ////根据序列号获取此时网标号
  137. //net_code = dh.getFieldDataByCondition("makeserial", "ms_netcode", "ms_id = '" + oMsID + "'").ToString();
  138. if (int.Parse(mcd_remainqty.Text) <= 0 && ma_unlimitin == 0)
  139. {
  140. ErrorMessage = "工单" + ms_makecode.Text + "剩余采集数不足\n>>>请输入SN";
  141. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  142. return;
  143. }
  144. if (dh.CheckExist("sninfo", "si_netcode = '" + sncode.Text + "'"))
  145. {
  146. OperateResult.AppendText(">>录入错误,此网标:" + sncode.Text + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_netcode = '" + sncode.Text + "'").ToString() + "使用\n", Color.Red, sncode);
  147. OperateResult.AppendText(">>请输入网标\n", Color.Black);
  148. return;
  149. }
  150. if (dh.CheckExist("makeserial", "ms_netcode = '" + sncode.Text + "'"))
  151. {
  152. OperateResult.AppendText(">>录入错误,此网标:" + sncode.Text + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_netcode = '" + sncode.Text + "'").ToString() + "使用\n", Color.Red, sncode);
  153. OperateResult.AppendText(">>请输入网标\n", Color.Black);
  154. return;
  155. }
  156. else
  157. {
  158. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code, "网标采集", "网标采集完成", User.UserCode, out ErrorMessage))
  159. {
  160. //提示正确返回时传递的信息
  161. if (ErrorMessage.Contains("AFTERSUCCESS"))
  162. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  163. //dh.UpdateByCondition("makeserial", "ms_netcode = '" + sncode.Text + "'", "ms_id = '" + oMsID + "'");
  164. string si_id = dh.getFieldDataByCondition("sninfo", "max(si_id) si_id", " si_sn in (select '" + sn_code + "' from dual union select sn from makesnrelation where beforesn = '" + sn_code + "' and sn <> ' ' union select beforesn from makesnrelation where sn = '" + sn_code + "' and beforesn <> ' ') ").ToString();
  165. if (si_id != "")
  166. {
  167. dh.BatchInsert("update sninfo set si_netcode = :netcode,si_indate = sysdate where si_id = :osiId", new String[] { "netcode", "osiId" }, new string[] { sncode.Text },new string[] { si_id });
  168. }
  169. else
  170. {
  171. dh.BatchInsert("insert into sninfo (si_id,si_sn,si_netcode,si_indate) values (SnInfo_seq.nextval,:si_sn,:netcode,sysdate)", new String[] { "si_sn", "netcode"}, new string[] { sn_code }, new string[] { sncode.Text });
  172. }
  173. dh.BatchInsert("update makeserial set ms_netcode = :netcode where ms_id = :oMsId", new String[] { "netcode", "oMsId" }, new string[] { sncode.Text }, new string[] { oMsID.ToString() });
  174. OperateResult.AppendText(">>网标采集完成,执行更新\n", Color.Green);
  175. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "网标采集", "采集成功", sn_code, "");
  176. sql.Clear();
  177. sql.Append("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  178. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  179. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  180. BaseUtil.SetFormValue(Controls, dt);
  181. printcount++;
  182. mcd_okqty.Text = printcount + "";
  183. isnetcode = false;
  184. sncode.Text = "";
  185. sncode.Focus();
  186. }
  187. else
  188. {
  189. OperateResult.AppendText(">>更新错误" + ErrorMessage + "\n", Color.Red);
  190. }
  191. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  192. }
  193. }
  194. }
  195. }
  196. private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
  197. {
  198. asc.controlAutoSize(this);
  199. }
  200. private void Make_CollectNetCode_Activated(object sender, EventArgs e)
  201. {
  202. sncode.Focus();
  203. }
  204. /// <summary>
  205. /// 检验长度或者前缀是否合法
  206. /// </summary>
  207. /// <param name="checkbox"></param>
  208. /// <param name="c"></param>
  209. /// <param name="info"></param>
  210. private bool checkLengthOrPre(int psr_length, string psr_prefix, string TSNorSN)
  211. {
  212. //则判断输入转换前的序列号长度是否合法,不合法则提示
  213. if (sncode.Text.Trim().Length != psr_length && psr_length != 0)
  214. {
  215. //序列号校验错误,长度错误
  216. OperateResult.AppendText("<<" + TSNorSN + ":" + sncode.Text + "校验错误,长度错误\n", Color.Red, sncode);
  217. OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
  218. return false;
  219. }
  220. string[] pres = psr_prefix.Split('|');
  221. bool f = false;
  222. for (int i = 0; i < pres.Length; i++)
  223. {
  224. if (pres[i] == "" ? true : sncode.Text.StartsWith(pres[i]))
  225. {
  226. //满足其中一条即可
  227. f = true;
  228. break;
  229. }
  230. }
  231. //则判断输入转换前的序列号前缀是否合法,不合法则提示
  232. if (!f)
  233. {
  234. //序列号校验错误,前缀错误
  235. OperateResult.AppendText("<<" + TSNorSN + ":" + sncode.Text + "校验错误,前缀错误\n", Color.Red, sncode);
  236. OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
  237. return false;
  238. }
  239. return true;
  240. }
  241. private void deleteButton1_Click(object sender, EventArgs e)
  242. {
  243. if (isnetcode)
  244. {
  245. BaseUtil.CleanForm(this);
  246. mcd_okqty.Text = printcount + "";
  247. mcd_remainqty.Text = 0 + "";
  248. OperateResult.AppendText(">>清除完成,清重新输入SN号\n", Color.Green);
  249. isnetcode = false;
  250. sncode.Focus();
  251. }
  252. }
  253. }
  254. }