Make_ToolingManager.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using NPOI.SS.Formula.Functions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Net.Http;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using UAS_MES_NEW.CustomControl.ButtonUtil;
  13. using UAS_MES_NEW.CustomControl.RichText;
  14. using UAS_MES_NEW.DataOperate;
  15. using UAS_MES_NEW.Entity;
  16. using UAS_MES_NEW.PublicMethod;
  17. namespace UAS_MES_NEW.Make
  18. {
  19. public partial class Make_ToolingManager : Form
  20. {
  21. public Make_ToolingManager()
  22. {
  23. InitializeComponent();
  24. }
  25. DataHelper dh;
  26. DataTable Dbfind;
  27. DataTable dt;
  28. private void Make_ToolingManager_Load(object sender, EventArgs e)
  29. {
  30. dh = SystemInf.dh;
  31. li_code.Text = User.UserLineCode;
  32. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  33. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  34. ma_code.FormName = Name;
  35. ma_code.SetValueField = new string[] { "ma_code" };
  36. ma_code.DbChange += Ma_code_DbChange;
  37. li_code.TableName = "Line";
  38. li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
  39. li_code.Condition = "li_wccode='SMT'";
  40. li_code.FormName = Name;
  41. li_code.SetValueField = new string[] { "li_code", "li_name" };
  42. li_code.DbChange += Li_code_DbChange;
  43. toolingVal.SelectAll();
  44. toolingVal.Focus();
  45. }
  46. private void Li_code_DbChange(object sender, EventArgs e)
  47. {
  48. Dbfind = li_code.ReturnData;
  49. BaseUtil.SetFormValue(this.Controls, Dbfind);
  50. }
  51. private void Ma_code_DbChange(object sender, EventArgs e)
  52. {
  53. Dbfind = ma_code.ReturnData;
  54. BaseUtil.SetFormValue(this.Controls, Dbfind);
  55. //Confirm.PerformClick();
  56. }
  57. private void toolingVal_Leave(object sender, EventArgs e)
  58. {
  59. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  60. toolingVal_KeyPress(toolingVal, newEvent);
  61. }
  62. private void toolingVal_KeyPress(object sender, KeyPressEventArgs e)
  63. {
  64. if (e.KeyChar != (char)Keys.Enter) return;
  65. if (string.IsNullOrEmpty(toolingVal.Text.Trim()))
  66. {
  67. ShowMsg(MsgBox, 0, "NG,请输入治具编号");
  68. toolingVal.SelectAll();
  69. toolingVal.Focus();
  70. return;
  71. }
  72. dt = (DataTable)dh.ExecuteSql($"select st_kind,st_usestatus from stencil where st_code = '{toolingVal.Text.Trim()}' group by st_kind,st_usestatus", "select");
  73. if (dt.Rows.Count == 0)
  74. {
  75. ShowMsg(MsgBox, 0, "NG,未识别到治具类型,请先维护治具信息");
  76. toolingVal.SelectAll();
  77. toolingVal.Focus();
  78. return;
  79. }
  80. typeVal.Items.Clear();
  81. for (int i = 0; i < dt.Rows.Count; i++)
  82. {
  83. typeVal.Items.Add(dt.Rows[i][0].ToString());
  84. }
  85. typeVal.SelectedIndex = 0;
  86. currStatusVal.Text = dt.Rows[0]["st_usestatus"].ToString();
  87. if (typeVal.Text == "钢网")
  88. {
  89. stA.Enabled = true;
  90. stB.Enabled = true;
  91. stC.Enabled = true;
  92. stD.Enabled = true;
  93. stE.Enabled = true;
  94. gapVal1.Visible = false;
  95. gapLab1.Visible = false;
  96. gapVal2.Visible = false;
  97. gapLab2.Visible = false;
  98. gapVal3.Visible = false;
  99. gapLab3.Visible = false;
  100. }
  101. else
  102. {
  103. stA.Enabled = false;
  104. stB.Enabled = false;
  105. stC.Enabled = false;
  106. stD.Enabled = false;
  107. stE.Enabled = false;
  108. gapVal1.Visible = true;
  109. gapLab1.Visible = true;
  110. gapVal2.Visible = true;
  111. gapLab2.Visible = true;
  112. gapVal3.Visible = true;
  113. gapLab3.Visible = true;
  114. }
  115. dt = (DataTable)dh.ExecuteSql($"select su_status,su_usedate from (select su_status,su_usedate from stenciluse where su_stcode = '{toolingVal.Text.Trim()}' order by su_usedate desc) where rownum=1", "select");
  116. if (dt.Rows.Count == 0)
  117. {
  118. ShowMsg(MsgBox, 2, "NG,未识别到治具上次操作");
  119. }
  120. else
  121. {
  122. prevTypeVal.Text = dt.Rows[0]["su_status"].ToString();
  123. prevTimeVal.Text = dt.Rows[0]["su_usedate"].ToString();
  124. }
  125. if(currStatusVal.Text == "出库")
  126. {
  127. Return.Enabled = true;
  128. Scrap.Enabled = true;
  129. Receive.Enabled = false;
  130. }
  131. else if (currStatusVal.Text == "在库")
  132. {
  133. Return.Enabled = false;
  134. Scrap.Enabled = false;
  135. Receive.Enabled = true;
  136. }
  137. else
  138. {
  139. Return.Enabled = false;
  140. Scrap.Enabled = false;
  141. Receive.Enabled = true;
  142. }
  143. toolingVal.Enabled = false;
  144. }
  145. private void ShowMsg(RichTextAutoBottom msgBox, int type, string msg)
  146. {
  147. msg = msg.Replace("\r", "").Replace("\n", "");
  148. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  149. string showMsg = $"{msgTime}: {msg}\n";
  150. if (type == 0)
  151. {
  152. msgBox.AppendText(showMsg, Color.Red);
  153. msgBox.SelectionStart = msgBox.Text.Length;
  154. msgBox.ScrollToCaret();
  155. }
  156. else if (type == 1)
  157. {
  158. msgBox.AppendText(showMsg, Color.Green);
  159. msgBox.SelectionStart = msgBox.Text.Length;
  160. msgBox.ScrollToCaret();
  161. }
  162. else if (type == 2)
  163. {
  164. msgBox.AppendText(showMsg, Color.YellowGreen);
  165. msgBox.SelectionStart = msgBox.Text.Length;
  166. msgBox.ScrollToCaret();
  167. }
  168. }
  169. private void cancel_Click(object sender, EventArgs e)
  170. {
  171. toolingVal.Enabled = true;
  172. toolingVal.Focus();
  173. toolingVal.SelectAll();
  174. }
  175. private void Receive_Click(object sender, EventArgs e)
  176. {
  177. if (string.IsNullOrEmpty(ma_code.Text))
  178. {
  179. ShowMsg(MsgBox, 0, "NG,请选择使用工单");
  180. ma_code.Focus();
  181. return;
  182. }
  183. if (string.IsNullOrEmpty(li_code.Text))
  184. {
  185. ShowMsg(MsgBox, 0, "NG,请输入使用线体");
  186. li_code.Focus();
  187. return;
  188. }
  189. if (string.IsNullOrEmpty(sideVal.Text))
  190. {
  191. ShowMsg(MsgBox, 0, "NG,请选择使用面别");
  192. sideVal.Focus();
  193. return;
  194. }
  195. if (string.IsNullOrEmpty(empVal.Text))
  196. {
  197. ShowMsg(MsgBox, 0, "NG,请填写领用人员");
  198. empVal.Focus();
  199. empVal.SelectAll();
  200. return;
  201. }
  202. if (li_code.Text.Contains("A") || li_code.Text.Contains("B"))
  203. {
  204. ShowMsg(MsgBox, 0, "NG,A和B新线体不允许手动领用,须通过测试仪领用");
  205. li_code.Focus();
  206. return;
  207. }
  208. int st_maxusecount = (int)dh.getFieldDataByCondition("stencil", "nvl(st_maxusecount, 0)", $"st_code = '{toolingVal.Text.Trim()}'");
  209. int st_usecount = (int)dh.getFieldDataByCondition("stencil", "nvl(st_usecount, 0)", $"st_code = '{toolingVal.Text.Trim()}'");
  210. if (st_maxusecount - st_usecount <= 0)
  211. {
  212. ShowMsg(MsgBox, 0, $"NG,可使用次数不足,使用次数上限为:{st_maxusecount},当前使用次数为:{st_usecount}");
  213. return;
  214. }
  215. if (IsCheckProd.Checked)
  216. {
  217. dt = (DataTable)dh.ExecuteSql($"SELECT sp_detno FROM stenilcanusepro,make WHERE sp_stcode = '{toolingVal.Text.Trim()}' AND ma_code = '{ma_code.Text}' AND ma_code = sp_prodcode", "select");
  218. if(dt.Rows.Count == 0)
  219. {
  220. ShowMsg(MsgBox, 0, $"NG,治具编号:{toolingVal.Text}使用产品未维护,无法在工单{ma_code.Text}中使用");
  221. return;
  222. }
  223. }
  224. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_version,nvl(st_maxusecount, 0) st_maxusecount,nvl(st_usecount, 0) st_usecount
  225. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  226. string status = dt.Rows[0]["st_usestatus"].ToString();
  227. if (status == "出库" || status == "报废")
  228. {
  229. ShowMsg(MsgBox, 0, $"NG,无法领用,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  230. return;
  231. }
  232. int maxCount = Convert.ToInt32(dt.Rows[0]["st_maxusecount"].ToString());
  233. int useCount = Convert.ToInt32(dt.Rows[0]["st_usecount"].ToString());
  234. int warnCount = Convert.ToInt32(dh.GetConfig("WaringCount", "Stencil"));
  235. if (maxCount - useCount < warnCount)
  236. {
  237. //ShowMsg(MsgBox, 2, "Warning,钢网:" + toolingVal.Text + "使用次数接近上限");
  238. DialogResult result = MessageBox.Show(this.ParentForm, $"Warning,{typeVal.Text}:{toolingVal.Text}使用次数接近上限,已使用{useCount},距离上限还有{(maxCount - useCount)}次", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  239. if (result == DialogResult.No || result == DialogResult.Cancel) return;
  240. }
  241. dt = (DataTable)dh.ExecuteSql($"select ma_prodcode from make where ma_code='{ma_code.Text}'", "select");
  242. string ma_prodcode = dt.Rows[0]["ma_prodcode"].ToString();
  243. dt = (DataTable)dh.ExecuteSql($"select st_code from stencil where st_line='{li_code.Text}' and st_kind = '{typeVal.Text}'", "select");
  244. if(typeVal.Text == "钢网")
  245. {
  246. if (dt.Rows.Count > 0)
  247. {
  248. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  249. return;
  250. }
  251. dt = (DataTable)dh.ExecuteSql($@"SELECT su_ensiona, su_ensionb, su_ensionc, su_ensiond, su_ensione FROM
  252. (SELECT * FROM stenciluse WHERE su_stcode = '{toolingVal.Text.Trim()}' AND su_status = '归还' ORDER BY su_usedate DESC) WHERE ROWNUM = 1", "select");
  253. if (dt.Rows.Count > 0)
  254. {
  255. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  256. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status,
  257. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  258. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  259. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用',
  260. '{dt.Rows[0]["su_ensiona"].ToString()}','{dt.Rows[0]["su_ensionb"].ToString()}','{dt.Rows[0]["su_ensionc"].ToString()}',
  261. '{dt.Rows[0]["su_ensiond"].ToString()}','{dt.Rows[0]["su_ensione"].ToString()}'
  262. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  263. }
  264. else
  265. {
  266. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  267. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  268. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  269. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  270. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  271. }
  272. }
  273. else if (typeVal.Text == "刮刀")
  274. {
  275. if (dt.Rows.Count > 1)
  276. {
  277. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  278. return;
  279. }
  280. string seq = (string)dh.getFieldDataByCondition("dual", "stenciluse_seq.NEXTVAL seq", "1=1");
  281. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  282. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  283. SELECT '{seq}','{toolingVal.Text.Trim()}',st_id,
  284. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  285. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  286. if (!string.IsNullOrEmpty(gapVal1.Text) && !string.IsNullOrEmpty(gapVal2.Text) && !string.IsNullOrEmpty(gapVal3.Text))
  287. {
  288. dh.ExecuteSql($@"INSERT INTO steptestdetail( std_id, std_subclass1, std_subclass2, std_value9, std_value10, std_value11)
  289. VALUES ( steptestdetail_seq.NEXTVAL, '{seq}', '刮刀', '{gapVal1.Text}', '{gapVal2.Text}', '{gapVal3.Text}' )", "insert");
  290. }
  291. }
  292. dh.ExecuteSql($@"update stencil set st_usestatus= '出库',st_line = '{li_code.Text}',st_macode = '{ma_code.Text}',
  293. st_useofproduct = '{ma_prodcode}' where st_code='" + toolingVal.Text + "'", "update");
  294. ma_code.Text = "";
  295. sideVal.SelectedIndex = -1;
  296. empVal.Text = "";
  297. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已领用成功");
  298. CleanDetail("Receive");
  299. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  300. toolingVal_KeyPress(toolingVal, newEvent);
  301. }
  302. private void CleanDetail(string type)
  303. {
  304. // Stencil Scraper
  305. if (type == "Receive")
  306. {
  307. ma_code.Text = "";
  308. sideVal.SelectedIndex = -1;
  309. empVal.Text = "";
  310. }
  311. else if (type == "Return")
  312. {
  313. stA.Text = "";
  314. stB.Text = "";
  315. stC.Text = "";
  316. stD.Text = "";
  317. stE.Text = "";
  318. empVal1.Text = "";
  319. useCountVal.Text = "";
  320. IsClean.Checked = false;
  321. }
  322. }
  323. private void Return_Click(object sender, EventArgs e)
  324. {
  325. if (string.IsNullOrEmpty(empVal1.Text))
  326. {
  327. ShowMsg(MsgBox, 0, "NG,请填写归还人员");
  328. empVal1.Focus();
  329. empVal1.SelectAll();
  330. return;
  331. }
  332. if (string.IsNullOrEmpty(useCountVal.Text))
  333. {
  334. useCountVal.Text = "0";
  335. }
  336. string stLine = (string)dh.getFieldDataByCondition("stencil", "st_line", $"st_code = '{toolingVal.Text.Trim()}'");
  337. if (stLine.Contains("A") || stLine.Contains("B"))
  338. {
  339. ShowMsg(MsgBox, 0, "NG,A和B新线体不允许手动归还,须通过测试仪归还");
  340. return;
  341. }
  342. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_usecount
  343. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  344. string status = dt.Rows[0]["st_usestatus"].ToString();
  345. if (status == "在库" || status == "报废")
  346. {
  347. ShowMsg(MsgBox, 0, $"NG,无需归还,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  348. return;
  349. }
  350. int cleanCount = Convert.ToInt32(useCountVal.Text.Trim());
  351. if (typeVal.Text == "钢网")
  352. {
  353. dh.ExecuteSql($@"UPDATE stencil SET st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  354. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  355. st_usecount = nvl(st_usecount,0) + {cleanCount},st_usestatus = '在库',
  356. st_line = '',st_macode = '',st_useofproduct = ''
  357. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  358. if (IsClean.Checked) {
  359. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1
  360. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  361. }
  362. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  363. su_usemacode,su_useprodcode,su_linecode,su_table,
  364. su_useman,su_usedate,su_status,
  365. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  366. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  367. su_usemacode,su_useprodcode,su_linecode,su_table,
  368. '{empVal1.Text}',sysdate,'归还',
  369. st_ensiona,st_ensionb,st_ensionc,st_ensiond,st_ensione
  370. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  371. AND st_line = su_linecode", "insert");
  372. }
  373. else if(typeVal.Text == "刮刀")
  374. {
  375. dh.ExecuteSql($@"UPDATE stencil SET st_usecount = nvl(st_usecount,0) + {cleanCount},
  376. st_usestatus = '在库',st_line = '',st_macode = '',st_useofproduct = ''WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  377. if (IsClean.Checked)
  378. {
  379. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1 WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  380. }
  381. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  382. su_usemacode,su_useprodcode,su_linecode,su_table,
  383. su_useman,su_usedate,su_status,)
  384. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  385. su_usemacode,su_useprodcode,su_linecode,su_table,
  386. '{empVal1.Text}',sysdate,'归还',
  387. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  388. AND st_line = su_linecode", "insert");
  389. }
  390. stA.Text = "";
  391. stB.Text = "";
  392. stC.Text = "";
  393. stD.Text = "";
  394. stE.Text = "";
  395. empVal1.Text = "";
  396. IsClean.Checked = false;
  397. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已归还成功");
  398. CleanDetail("Receive");
  399. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  400. toolingVal_KeyPress(toolingVal, newEvent);
  401. }
  402. private void Scrap_Click(object sender, EventArgs e)
  403. {
  404. }
  405. }
  406. }