Make_CollectBTMAC.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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_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. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  140. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sncode);
  141. return;
  142. }
  143. sql.Clear();
  144. sql.Append("select ma_code as ms_makecode,nvl(mcd_okqty,0),ma_prodcode,pr_detail,");
  145. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0) ma_unlimitin from make left join makecraftdetail on ");
  146. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  147. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  148. if (dt.Rows.Count > 0)
  149. {
  150. ma_unlimitin = int.Parse(dt.Rows[0]["ma_unlimitin"].ToString());
  151. BaseUtil.SetFormValue(this.Controls, dt);
  152. //dh.UpdateByCondition("makeserial", "ms_currentstepcode = '" + User.CurrentStepCode + "'", "ms_id = '" + oMsID + "'");
  153. OperateResult.AppendText(">>请输入BT\n", Color.Black);
  154. sn_code = sncode.Text;
  155. sncode.Text = "";
  156. isBT = true;
  157. return;
  158. }
  159. else
  160. {
  161. OperateResult.AppendText(">>序列号" + sncode.Text + "没有对应工序\n", Color.Red, sncode);
  162. }
  163. }
  164. else
  165. {
  166. OperateResult.AppendText(ErrorMessage2 + "\n", Color.Red, sncode);
  167. }
  168. }
  169. else
  170. {
  171. OperateResult.AppendText(ErrorMessage2 + "\n", Color.Red, sncode);
  172. }
  173. }
  174. else
  175. //采集BT
  176. {
  177. if (sncode.Text == "")
  178. {
  179. OperateResult.AppendText(">>BT号不能为空\n", Color.Red);
  180. return;
  181. }
  182. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  183. string ErrorMessage = "";
  184. string result = "";
  185. sql.Clear();
  186. sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'BT'");
  187. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  188. if (dt.Rows.Count > 0)
  189. {
  190. int psr_length = int.Parse(dt.Rows[0][1].ToString());
  191. string psr_prefix = dt.Rows[0][0].ToString();
  192. if (!checkLengthOrPre(psr_length, psr_prefix, "BT"))
  193. {
  194. sncode.Text = "";
  195. sncode.Focus();
  196. return;
  197. }
  198. }
  199. string checkbt = sncode.Text.Replace(":", "").Replace("-", "");
  200. if (dh.CheckExist("MakeAddressList", "mal_makecode = '" + ms_makecode.Text + "'"))
  201. {
  202. sql.Append("select mal_bt from MakeAddressList where mal_bt = '" + checkbt + "' and mal_makecode = '" + ms_makecode.Text + "'");
  203. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  204. if (!(dt.Rows.Count > 0))
  205. {
  206. OperateResult.AppendText(">>BT号" + checkbt + "不符合工单导入要求\n", Color.Red, sncode);
  207. return;
  208. }
  209. }
  210. else
  211. {
  212. ////根据工单号获取销售单号
  213. //sale_code = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code = '" + ms_makecode.Text + "'").ToString();
  214. //sql.Clear();
  215. //sql.Append("select sr_startcode,sr_endcode from SaleMacBTRange where sr_sacode = '" + sale_code + "' and sr_type = 'BT'");
  216. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  217. //if (dt.Rows.Count > 0)
  218. //{
  219. // if (!(dt.Rows[0]["sr_startcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkbt) <= 0 && dt.Rows[0]["sr_endcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkbt) >= 0))
  220. // {
  221. // OperateResult.AppendText(">>BT号" + checkbt + "不符合销售单合同范围\n", Color.Red, sncode);
  222. // return;
  223. // }
  224. //}
  225. if (!LogicHandler.checkMacOrBtRange(oMsID, checkbt, "BT"))
  226. {
  227. OperateResult.AppendText(">>BT号" + checkbt + "不符合销售单合同范围\n", Color.Red, sncode);
  228. return;
  229. }
  230. }
  231. //根据序列号获取此时BT号
  232. //ms_bt = dh.getFieldDataByCondition("makeserial", "ms_bt", "ms_id = '" + oMsID + "'").ToString();
  233. if (int.Parse(mcd_remainqty.Text) <= 0 && ma_unlimitin == 0)
  234. {
  235. ErrorMessage = "工单" + ms_makecode.Text + "剩余采集数不足\n>>>请输入SN";
  236. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  237. return;
  238. }
  239. if (dh.CheckExist("sninfo", "si_bt = '" + checkbt + "'"))
  240. {
  241. OperateResult.AppendText(">>录入错误,此BT:" + checkbt + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_bt = '" + checkbt + "'").ToString() + "使用\n", Color.Red, sncode);
  242. OperateResult.AppendText(">>请输入BT\n", Color.Black);
  243. return;
  244. }
  245. if (dh.CheckExist("makeserial", "ms_bt = '" + checkbt + "'"))
  246. {
  247. OperateResult.AppendText(">>录入错误,此BT:" + checkbt + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_bt = '" + checkbt + "'").ToString() + "使用\n", Color.Red, sncode);
  248. OperateResult.AppendText(">>请输入BT\n", Color.Black);
  249. return;
  250. }
  251. else
  252. {
  253. ms_bt = checkbt;
  254. OperateResult.AppendText(">>BT采集完成\n>>请输入MAC\n", Color.Green, sncode);
  255. isBT = false;
  256. isMAC = true;
  257. sncode.Focus();
  258. return;
  259. }
  260. }
  261. }
  262. else
  263. {
  264. //采集MAC
  265. if (sncode.Text == "")
  266. {
  267. OperateResult.AppendText(">>MAC号不能为空\n", Color.Red);
  268. return;
  269. }
  270. OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  271. string ErrorMessage = "";
  272. string result = "";
  273. sql.Clear();
  274. sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'MAC'");
  275. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  276. if (dt.Rows.Count > 0)
  277. {
  278. int psr_length = int.Parse(dt.Rows[0][1].ToString());
  279. string psr_prefix = dt.Rows[0][0].ToString();
  280. if (!checkLengthOrPre(psr_length, psr_prefix, "MAC"))
  281. {
  282. sncode.Text = "";
  283. sncode.Focus();
  284. return;
  285. }
  286. }
  287. string checkmac = sncode.Text.Replace(":", "").Replace("-", "");
  288. if (dh.CheckExist("MakeAddressList", "mal_makecode = '" + ms_makecode.Text + "'"))
  289. {
  290. sql.Append("select mal_mac from MakeAddressList where mal_mac = '" + checkmac + "' and mal_makecode = '" + ms_makecode.Text + "'");
  291. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  292. if (!(dt.Rows.Count > 0))
  293. {
  294. OperateResult.AppendText(">>MAC号" + checkmac + "不符合工单导入要求\n", Color.Red, sncode);
  295. return;
  296. }
  297. }
  298. else
  299. {
  300. ////根据工单号获取销售单号
  301. //sale_code = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code = '" + ms_makecode.Text + "'").ToString();
  302. //sql.Clear();
  303. //sql.Append("select sr_startcode,sr_endcode from SaleMacBTRange where sr_sacode = '" + sale_code + "' and sr_type = 'MAC'");
  304. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  305. //if (dt.Rows.Count > 0)
  306. //{
  307. // if (!(dt.Rows[0]["sr_startcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkmac) <= 0 && dt.Rows[0]["sr_endcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkmac) >= 0))
  308. // {
  309. // OperateResult.AppendText(">>MAC号" + checkmac + "不符合销售单合同范围\n", Color.Red, sncode);
  310. // return;
  311. // }
  312. //}
  313. if (!LogicHandler.checkMacOrBtRange(oMsID, checkmac, "MAC"))
  314. {
  315. OperateResult.AppendText(">>MAC号" + checkmac + "不符合销售单合同范围\n", Color.Red, sncode);
  316. return;
  317. }
  318. }
  319. if (int.Parse(mcd_remainqty.Text) <= 0 && ma_unlimitin == 0)
  320. {
  321. ErrorMessage = "工单" + ms_makecode.Text + "剩余采集数不足\n>>>请输入SN";
  322. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  323. return;
  324. }
  325. if (dh.CheckExist("sninfo", "si_mac = '" + checkmac + "'"))
  326. {
  327. OperateResult.AppendText(">>录入错误,此MAC:" + checkmac + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_mac = '" + checkmac + "'").ToString() + "使用\n", Color.Red, sncode);
  328. OperateResult.AppendText(">>请输入MAC\n", Color.Black);
  329. return;
  330. }
  331. if (dh.CheckExist("makeserial", "ms_mac = '" + checkmac + "'"))
  332. {
  333. OperateResult.AppendText(">>录入错误,此MAC:" + checkmac + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_mac = '" + checkmac + "'").ToString() + "使用\n", Color.Red, sncode);
  334. OperateResult.AppendText(">>请输入MAC\n", Color.Black);
  335. return;
  336. }
  337. else
  338. {
  339. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code, "BT/MAC采集", "BT/MAC采集完成", User.UserCode, out ErrorMessage))
  340. {
  341. //提示正确返回时传递的信息
  342. if (ErrorMessage.Contains("AFTERSUCCESS"))
  343. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  344. 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();
  345. if (si_id != "")
  346. {
  347. 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 });
  348. }
  349. else
  350. {
  351. 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 });
  352. }
  353. 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() });
  354. OperateResult.AppendText(">>BT/MAC采集完成,执行更新\n", Color.Green);
  355. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "BT/MAC采集", "采集成功", sn_code, "");
  356. if (CollectRemark.Checked && Remark.Text != "")
  357. {
  358. LogicHandler.CollectRemarkInf(sn_code, "", "", ms_makecode.Text, ma_prodcode.Text, Remark.Text);
  359. }
  360. sql.Clear();
  361. sql.Append("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  362. 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 + "'");
  363. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  364. BaseUtil.SetFormValue(Controls, dt);
  365. printcount++;
  366. mcd_okqty.Text = printcount + "";
  367. isMAC = false;
  368. sncode.Text = "";
  369. sncode.Focus();
  370. }
  371. else
  372. {
  373. OperateResult.AppendText(">>采集错误" + ErrorMessage + "\n", Color.Red);
  374. return;
  375. }
  376. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }