Make_CollectBTMAC.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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.DataOperate;
  10. using UAS_MES.Entity;
  11. using UAS_MES.PublicMethod;
  12. namespace UAS_MES.Make
  13. {
  14. public partial class Make_CollectBTMAC : 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. //采集BT号
  25. string ms_bt;
  26. //采集销售单号
  27. string sale_code;
  28. //采集MAC
  29. string ms_mac;
  30. //网标查询条件ms_id
  31. string oMsID;
  32. //判断是否输入BT
  33. Boolean isBT = false;
  34. //判断是否输入BT
  35. Boolean isMAC = false;
  36. //打印计数
  37. int printcount;
  38. int ma_unlimitin;
  39. public Make_CollectBTMAC()
  40. {
  41. InitializeComponent();
  42. }
  43. private void Make_CollectBTMAC_Load(object sender, EventArgs e)
  44. {
  45. asc.controllInitializeSize(this);
  46. printcount = 0;
  47. sncode.Focus();
  48. dh = SystemInf.dh;
  49. StepCount.StepCode = User.CurrentStepCode;
  50. StepCount.Source = User.UserSourceCode;
  51. StepCount.LineCode = User.UserLineCode;
  52. StepCount.Dh = dh;
  53. StepCount.Start();
  54. }
  55. private void Make_CollectBTMAC_Activated(object sender, EventArgs e)
  56. {
  57. sncode.Focus();
  58. }
  59. private void Make_CollectBTMAC_SizeChanged(object sender, EventArgs e)
  60. {
  61. asc.controlAutoSize(this);
  62. }
  63. private void deleteButton1_Click(object sender, EventArgs e)
  64. {
  65. isBT = false;
  66. isMAC = false;
  67. BaseUtil.CleanForm(this);
  68. mcd_okqty.Text = printcount + "";
  69. mcd_remainqty.Text = 0 + "";
  70. OperateResult.AppendText(">>清除完成,请输入SN号\n", Color.Green);
  71. sncode.Focus();
  72. }
  73. /// <summary>
  74. /// 检验长度或者前缀是否合法
  75. /// </summary>
  76. /// <param name="checkbox"></param>
  77. /// <param name="c"></param>
  78. /// <param name="info"></param>
  79. private bool checkLengthOrPre(int psr_length, string psr_prefix, string TSNorSN)
  80. {
  81. if (sncode.Text.Trim().Length > 40)
  82. {
  83. sncode.Text = sncode.Text.Trim().Substring(0, 40);
  84. }
  85. //则判断输入转换前的序列号长度是否合法,不合法则提示
  86. if (sncode.Text.Trim().Length != psr_length && psr_length != 0)
  87. {
  88. //序列号校验错误,长度错误
  89. OperateResult.AppendText("<<" + TSNorSN + ":" + sncode.Text + "校验错误,长度错误\n", Color.Red, sncode);
  90. OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
  91. return false;
  92. }
  93. string[] pres = psr_prefix.Split('|');
  94. bool f = false;
  95. for (int i = 0; i < pres.Length; i++)
  96. {
  97. if (pres[i] == "" ? true : sncode.Text.StartsWith(pres[i]))
  98. {
  99. //满足其中一条即可
  100. f = true;
  101. break;
  102. }
  103. }
  104. //则判断输入转换前的序列号前缀是否合法,不合法则提示
  105. if (!f)
  106. {
  107. //序列号校验错误,前缀错误
  108. OperateResult.AppendText("<<" + TSNorSN + ":" + sncode.Text + "校验错误,前缀错误\n", Color.Red, sncode);
  109. OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
  110. return false;
  111. }
  112. return true;
  113. }
  114. private void sncode_KeyDown(object sender, KeyEventArgs e)
  115. {
  116. if (e.KeyCode == Keys.Enter)
  117. {
  118. if (!isMAC)
  119. {
  120. if (!isBT)
  121. {
  122. string ErrorMessage2;
  123. string oMakeCode;
  124. //由序列号获取数据
  125. if (sncode.Text == "")
  126. {
  127. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  128. return;
  129. }
  130. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage2))
  131. {
  132. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  133. // 获取工单归属工单下一工序是否正确
  134. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2))
  135. {
  136. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  137. if (nextstepcode != User.CurrentStepCode)
  138. {
  139. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, sncode);
  140. return;
  141. }
  142. sql.Clear();
  143. sql.Append("select ma_code as ms_makecode,nvl(mcd_okqty,0),ma_prodcode,pr_detail,");
  144. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0) ma_unlimitin from make left join makecraftdetail on ");
  145. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  146. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  147. if (dt.Rows.Count > 0)
  148. {
  149. ma_unlimitin = int.Parse(dt.Rows[0]["ma_unlimitin"].ToString());
  150. BaseUtil.SetFormValue(this.Controls, dt);
  151. //dh.UpdateByCondition("makeserial", "ms_currentstepcode = '" + User.CurrentStepCode + "'", "ms_id = '" + oMsID + "'");
  152. OperateResult.AppendText(">>请输入BT\n", Color.Black);
  153. sn_code = sncode.Text;
  154. sncode.Text = "";
  155. isBT = true;
  156. return;
  157. }
  158. else
  159. {
  160. OperateResult.AppendText(">>序列号" + sncode.Text + "没有对应工序\n", Color.Red, sncode);
  161. }
  162. }
  163. else
  164. {
  165. OperateResult.AppendText(ErrorMessage2 + "\n", Color.Red, sncode);
  166. }
  167. }
  168. else
  169. {
  170. OperateResult.AppendText(ErrorMessage2 + "\n", Color.Red, sncode);
  171. }
  172. }
  173. else
  174. //采集BT
  175. {
  176. if (sncode.Text == "")
  177. {
  178. OperateResult.AppendText(">>BT号不能为空\n", Color.Red);
  179. return;
  180. }
  181. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  182. string ErrorMessage = "";
  183. string result = "";
  184. sql.Clear();
  185. sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'BT'");
  186. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  187. if (dt.Rows.Count > 0)
  188. {
  189. int psr_length = int.Parse(dt.Rows[0][1].ToString());
  190. string psr_prefix = dt.Rows[0][0].ToString();
  191. if (!checkLengthOrPre(psr_length, psr_prefix, "BT"))
  192. {
  193. sncode.Text = "";
  194. sncode.Focus();
  195. return;
  196. }
  197. }
  198. string checkbt = sncode.Text.Replace(":", "").Replace("-", "");
  199. if (dh.CheckExist("MakeAddressList", "mal_makecode = '" + ms_makecode.Text + "'"))
  200. {
  201. sql.Append("select mal_bt from MakeAddressList where mal_bt = '" + checkbt + "' and mal_makecode = '" + ms_makecode.Text + "'");
  202. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  203. if (!(dt.Rows.Count > 0))
  204. {
  205. OperateResult.AppendText(">>BT号" + checkbt + "不符合工单导入要求\n", Color.Red, sncode);
  206. return;
  207. }
  208. }
  209. else
  210. {
  211. ////根据工单号获取销售单号
  212. //sale_code = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code = '" + ms_makecode.Text + "'").ToString();
  213. //sql.Clear();
  214. //sql.Append("select sr_startcode,sr_endcode from SaleMacBTRange where sr_sacode = '" + sale_code + "' and sr_type = 'BT'");
  215. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  216. //if (dt.Rows.Count > 0)
  217. //{
  218. // if (!(dt.Rows[0]["sr_startcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkbt) <= 0 && dt.Rows[0]["sr_endcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkbt) >= 0))
  219. // {
  220. // OperateResult.AppendText(">>BT号" + checkbt + "不符合销售单合同范围\n", Color.Red, sncode);
  221. // return;
  222. // }
  223. //}
  224. if (!LogicHandler.checkMacOrBtRange(oMsID, checkbt, "BT"))
  225. {
  226. OperateResult.AppendText(">>BT号" + checkbt + "不符合销售单合同范围\n", Color.Red, sncode);
  227. return;
  228. }
  229. }
  230. //根据序列号获取此时BT号
  231. //ms_bt = dh.getFieldDataByCondition("makeserial", "ms_bt", "ms_id = '" + oMsID + "'").ToString();
  232. if (int.Parse(mcd_remainqty.Text) <= 0 && ma_unlimitin == 0)
  233. {
  234. ErrorMessage = "工单" + ms_makecode.Text + "剩余采集数不足\n>>>请输入SN";
  235. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  236. return;
  237. }
  238. if (dh.CheckExist("sninfo", "si_bt = '" + checkbt + "'"))
  239. {
  240. OperateResult.AppendText(">>录入错误,此BT:" + checkbt + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_bt = '" + checkbt + "'").ToString() + "使用\n", Color.Red, sncode);
  241. OperateResult.AppendText(">>请输入BT\n", Color.Black);
  242. return;
  243. }
  244. if (dh.CheckExist("makeserial", "ms_bt = '" + checkbt + "'"))
  245. {
  246. OperateResult.AppendText(">>录入错误,此BT:" + checkbt + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_bt = '" + checkbt + "'").ToString() + "使用\n", Color.Red, sncode);
  247. OperateResult.AppendText(">>请输入BT\n", Color.Black);
  248. return;
  249. }
  250. else
  251. {
  252. ms_bt = checkbt;
  253. OperateResult.AppendText(">>BT采集完成\n>>请输入MAC\n", Color.Green, sncode);
  254. isBT = false;
  255. isMAC = true;
  256. sncode.Focus();
  257. return;
  258. }
  259. }
  260. }
  261. else
  262. {
  263. //采集MAC
  264. if (sncode.Text == "")
  265. {
  266. OperateResult.AppendText(">>MAC号不能为空\n", Color.Red);
  267. return;
  268. }
  269. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  270. string ErrorMessage = "";
  271. string result = "";
  272. sql.Clear();
  273. sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'MAC'");
  274. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  275. if (dt.Rows.Count > 0)
  276. {
  277. int psr_length = int.Parse(dt.Rows[0][1].ToString());
  278. string psr_prefix = dt.Rows[0][0].ToString();
  279. if (!checkLengthOrPre(psr_length, psr_prefix, "MAC"))
  280. {
  281. sncode.Text = "";
  282. sncode.Focus();
  283. return;
  284. }
  285. }
  286. string checkmac = sncode.Text.Replace(":", "").Replace("-", "");
  287. if (dh.CheckExist("MakeAddressList", "mal_makecode = '" + ms_makecode.Text + "'"))
  288. {
  289. sql.Append("select mal_mac from MakeAddressList where mal_mac = '" + checkmac + "' and mal_makecode = '" + ms_makecode.Text + "'");
  290. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  291. if (!(dt.Rows.Count > 0))
  292. {
  293. OperateResult.AppendText(">>MAC号" + checkmac + "不符合工单导入要求\n", Color.Red, sncode);
  294. return;
  295. }
  296. }
  297. else
  298. {
  299. ////根据工单号获取销售单号
  300. //sale_code = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code = '" + ms_makecode.Text + "'").ToString();
  301. //sql.Clear();
  302. //sql.Append("select sr_startcode,sr_endcode from SaleMacBTRange where sr_sacode = '" + sale_code + "' and sr_type = 'MAC'");
  303. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  304. //if (dt.Rows.Count > 0)
  305. //{
  306. // if (!(dt.Rows[0]["sr_startcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkmac) <= 0 && dt.Rows[0]["sr_endcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkmac) >= 0))
  307. // {
  308. // OperateResult.AppendText(">>MAC号" + checkmac + "不符合销售单合同范围\n", Color.Red, sncode);
  309. // return;
  310. // }
  311. //}
  312. if (!LogicHandler.checkMacOrBtRange(oMsID, checkmac, "MAC"))
  313. {
  314. OperateResult.AppendText(">>MAC号" + checkmac + "不符合销售单合同范围\n", Color.Red, sncode);
  315. return;
  316. }
  317. }
  318. if (int.Parse(mcd_remainqty.Text) <= 0 && ma_unlimitin == 0)
  319. {
  320. ErrorMessage = "工单" + ms_makecode.Text + "剩余采集数不足\n>>>请输入SN";
  321. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  322. return;
  323. }
  324. if (dh.CheckExist("sninfo", "si_mac = '" + checkmac + "'"))
  325. {
  326. OperateResult.AppendText(">>录入错误,此MAC:" + checkmac + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_mac = '" + checkmac + "'").ToString() + "使用\n", Color.Red, sncode);
  327. OperateResult.AppendText(">>请输入MAC\n", Color.Black);
  328. return;
  329. }
  330. if (dh.CheckExist("makeserial", "ms_mac = '" + checkmac + "'"))
  331. {
  332. OperateResult.AppendText(">>录入错误,此MAC:" + checkmac + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_mac = '" + checkmac + "'").ToString() + "使用\n", Color.Red, sncode);
  333. OperateResult.AppendText(">>请输入MAC\n", Color.Black);
  334. return;
  335. }
  336. else
  337. {
  338. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code, "BT/MAC采集", "BT/MAC采集完成", User.UserCode, out ErrorMessage))
  339. {
  340. //提示正确返回时传递的信息
  341. if (ErrorMessage.Contains("AFTERSUCCESS"))
  342. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  343. 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();
  344. if (si_id != "")
  345. {
  346. dh.BatchInsert("update sninfo set si_mac = :mac,si_bt =:bt,si_indate = sysdate where si_id = :osiId", new String[] { "mac", "bt", "osiId" }, new string[] { checkmac }, new string[] { ms_bt }, new string[] { si_id });
  347. }
  348. else
  349. {
  350. dh.BatchInsert("insert into sninfo (si_id,si_sn,si_mac,si_bt,si_indate) values (SnInfo_seq.nextval,:si_sn,:si_mac,:si_bt,sysdate)", new String[] { "si_sn", "si_mac", "si_bt" }, new string[] { sn_code }, new string[] { checkmac }, new string[] { ms_bt });
  351. }
  352. dh.BatchInsert("update makeserial set ms_mac = :mac,ms_bt =:bt where ms_id = :oMsId", new String[] { "mac", "bt", "oMsId" }, new string[] { checkmac }, new string[] { ms_bt }, new string[] { oMsID.ToString() });
  353. OperateResult.AppendText(">>BT/MAC采集完成,执行更新\n", Color.Green);
  354. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "BT/MAC采集", "采集成功", sn_code, "");
  355. if (CollectRemark.Checked && Remark.Text != "")
  356. {
  357. LogicHandler.CollectRemarkInf(sn_code, "", "", ms_makecode.Text, ma_prodcode.Text, Remark.Text);
  358. }
  359. sql.Clear();
  360. sql.Append("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  361. 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 + "'");
  362. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  363. BaseUtil.SetFormValue(Controls, dt);
  364. printcount++;
  365. mcd_okqty.Text = printcount + "";
  366. isMAC = false;
  367. sncode.Text = "";
  368. sncode.Focus();
  369. }
  370. else
  371. {
  372. OperateResult.AppendText(">>采集错误" + ErrorMessage + "\n", Color.Red);
  373. return;
  374. }
  375. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }