Make_ToolingManager.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 (IsCheckProd.Checked)
  203. {
  204. 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");
  205. if(dt.Rows.Count == 0)
  206. {
  207. ShowMsg(MsgBox, 0, $"NG,治具编号:{toolingVal.Text}使用产品未维护,无法在工单{ma_code.Text}中使用");
  208. return;
  209. }
  210. }
  211. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_version,nvl(st_maxusecount, 0) st_maxusecount,nvl(st_usecount, 0) st_usecount
  212. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  213. string status = dt.Rows[0]["st_usestatus"].ToString();
  214. if (status == "出库" || status == "报废")
  215. {
  216. ShowMsg(MsgBox, 0, $"NG,无法领用,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  217. return;
  218. }
  219. int maxCount = Convert.ToInt32(dt.Rows[0]["st_maxusecount"].ToString());
  220. int useCount = Convert.ToInt32(dt.Rows[0]["st_usecount"].ToString());
  221. int warnCount = Convert.ToInt32(dh.GetConfig("WaringCount", "Stencil"));
  222. if (maxCount - useCount < warnCount)
  223. {
  224. //ShowMsg(MsgBox, 2, "Warning,钢网:" + toolingVal.Text + "使用次数接近上限");
  225. DialogResult result = MessageBox.Show(this.ParentForm, $"Warning,{typeVal.Text}:{toolingVal.Text}使用次数接近上限,已使用{useCount},距离上限还有{(maxCount - useCount)}次", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  226. if (result == DialogResult.No || result == DialogResult.Cancel) return;
  227. }
  228. dt = (DataTable)dh.ExecuteSql($"select ma_prodcode from make where ma_code='{ma_code.Text}'", "select");
  229. string ma_prodcode = dt.Rows[0]["ma_prodcode"].ToString();
  230. dt = (DataTable)dh.ExecuteSql($"select st_code from stencil where st_line='{li_code.Text}' and st_kind = '{typeVal.Text}'", "select");
  231. if(typeVal.Text == "钢网")
  232. {
  233. if (dt.Rows.Count > 0)
  234. {
  235. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  236. return;
  237. }
  238. dt = (DataTable)dh.ExecuteSql($@"SELECT su_ensiona, su_ensionb, su_ensionc, su_ensiond, su_ensione FROM
  239. (SELECT * FROM stenciluse WHERE su_stcode = '{toolingVal.Text.Trim()}' AND su_status = '归还' ORDER BY su_usedate DESC) WHERE ROWNUM = 1", "select");
  240. if (dt.Rows.Count > 0)
  241. {
  242. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  243. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status,
  244. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  245. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  246. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用',
  247. '{dt.Rows[0]["su_ensiona"].ToString()}','{dt.Rows[0]["su_ensionb"].ToString()}','{dt.Rows[0]["su_ensionc"].ToString()}',
  248. '{dt.Rows[0]["su_ensiond"].ToString()}','{dt.Rows[0]["su_ensione"].ToString()}'
  249. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  250. }
  251. else
  252. {
  253. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  254. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  255. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  256. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  257. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  258. }
  259. }
  260. else if (typeVal.Text == "刮刀")
  261. {
  262. if (dt.Rows.Count > 1)
  263. {
  264. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  265. return;
  266. }
  267. string seq = (string)dh.getFieldDataByCondition("dual", "stenciluse_seq.NEXTVAL seq", "1=1");
  268. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  269. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  270. SELECT '{seq}','{toolingVal.Text.Trim()}',st_id,
  271. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  272. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  273. if (!string.IsNullOrEmpty(gapVal1.Text) && !string.IsNullOrEmpty(gapVal2.Text) && !string.IsNullOrEmpty(gapVal3.Text))
  274. {
  275. dh.ExecuteSql($@"INSERT INTO steptestdetail( std_id, std_subclass1, std_subclass2, std_value9, std_value10, std_value11)
  276. VALUES ( steptestdetail_seq.NEXTVAL, '{seq}', '刮刀', '{gapVal1.Text}', '{gapVal2.Text}', '{gapVal3.Text}' )", "insert");
  277. }
  278. }
  279. dh.ExecuteSql($@"update stencil set st_usestatus= '出库',st_line = '{li_code.Text}',st_macode = '{ma_code.Text}',
  280. st_useofproduct = '{ma_prodcode}' where st_code='" + toolingVal.Text + "'", "update");
  281. ma_code.Text = "";
  282. sideVal.SelectedIndex = -1;
  283. empVal.Text = "";
  284. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已领用成功");
  285. CleanDetail("Receive");
  286. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  287. toolingVal_KeyPress(toolingVal, newEvent);
  288. }
  289. private void CleanDetail(string type)
  290. {
  291. // Stencil Scraper
  292. if (type == "Receive")
  293. {
  294. ma_code.Text = "";
  295. sideVal.SelectedIndex = -1;
  296. empVal.Text = "";
  297. }
  298. else if (type == "Return")
  299. {
  300. stA.Text = "";
  301. stB.Text = "";
  302. stC.Text = "";
  303. stD.Text = "";
  304. stE.Text = "";
  305. empVal1.Text = "";
  306. useCountVal.Text = "";
  307. IsClean.Checked = false;
  308. }
  309. }
  310. private void Return_Click(object sender, EventArgs e)
  311. {
  312. if (string.IsNullOrEmpty(empVal1.Text))
  313. {
  314. ShowMsg(MsgBox, 0, "NG,请填写归还人员");
  315. empVal1.Focus();
  316. empVal1.SelectAll();
  317. return;
  318. }
  319. if (string.IsNullOrEmpty(useCountVal.Text))
  320. {
  321. useCountVal.Text = "0";
  322. }
  323. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_usecount
  324. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  325. string status = dt.Rows[0]["st_usestatus"].ToString();
  326. if (status == "在库" || status == "报废")
  327. {
  328. ShowMsg(MsgBox, 0, $"NG,无需归还,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  329. return;
  330. }
  331. int cleanCount = Convert.ToInt32(useCountVal.Text.Trim());
  332. if (typeVal.Text == "钢网")
  333. {
  334. dh.ExecuteSql($@"UPDATE stencil SET st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  335. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  336. st_usecount = nvl(st_usecount,0) + {cleanCount},st_usestatus = '在库',
  337. st_line = '',st_macode = '',st_useofproduct = ''
  338. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  339. if (IsClean.Checked) {
  340. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1
  341. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  342. }
  343. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  344. su_usemacode,su_useprodcode,su_linecode,su_table,
  345. su_useman,su_usedate,su_status,
  346. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  347. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  348. su_usemacode,su_useprodcode,su_linecode,su_table,
  349. '{empVal1.Text}',sysdate,'归还',
  350. st_ensiona,st_ensionb,st_ensionc,st_ensiond,st_ensione
  351. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  352. AND st_line = su_linecode", "insert");
  353. }
  354. else if(typeVal.Text == "刮刀")
  355. {
  356. dh.ExecuteSql($@"UPDATE stencil SET st_usecount = nvl(st_usecount,0) + {cleanCount},
  357. st_usestatus = '在库',st_line = '',st_macode = '',st_useofproduct = ''WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  358. if (IsClean.Checked)
  359. {
  360. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1 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. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  366. su_usemacode,su_useprodcode,su_linecode,su_table,
  367. '{empVal1.Text}',sysdate,'归还',
  368. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  369. AND st_line = su_linecode", "insert");
  370. }
  371. stA.Text = "";
  372. stB.Text = "";
  373. stC.Text = "";
  374. stD.Text = "";
  375. stE.Text = "";
  376. empVal1.Text = "";
  377. IsClean.Checked = false;
  378. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已归还成功");
  379. CleanDetail("Receive");
  380. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  381. toolingVal_KeyPress(toolingVal, newEvent);
  382. }
  383. private void Scrap_Click(object sender, EventArgs e)
  384. {
  385. }
  386. }
  387. }