Make_ToolingManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. }
  95. else
  96. {
  97. stA.Enabled = false;
  98. stB.Enabled = false;
  99. stC.Enabled = false;
  100. stD.Enabled = false;
  101. stE.Enabled = false;
  102. }
  103. 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");
  104. if (dt.Rows.Count == 0)
  105. {
  106. ShowMsg(MsgBox, 2, "NG,未识别到治具上次操作");
  107. }
  108. else
  109. {
  110. prevTypeVal.Text = dt.Rows[0]["su_status"].ToString();
  111. prevTimeVal.Text = dt.Rows[0]["su_usedate"].ToString();
  112. }
  113. if(currStatusVal.Text == "出库")
  114. {
  115. Return.Enabled = true;
  116. Scrap.Enabled = true;
  117. Receive.Enabled = false;
  118. }
  119. else if (currStatusVal.Text == "在库")
  120. {
  121. Return.Enabled = false;
  122. Scrap.Enabled = false;
  123. Receive.Enabled = true;
  124. }
  125. else
  126. {
  127. Return.Enabled = false;
  128. Scrap.Enabled = false;
  129. Receive.Enabled = true;
  130. }
  131. toolingVal.Enabled = false;
  132. }
  133. private void ShowMsg(RichTextAutoBottom msgBox, int type, string msg)
  134. {
  135. msg = msg.Replace("\r", "").Replace("\n", "");
  136. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  137. string showMsg = $"{msgTime}: {msg}\n";
  138. if (type == 0)
  139. {
  140. msgBox.AppendText(showMsg, Color.Red);
  141. msgBox.SelectionStart = msgBox.Text.Length;
  142. msgBox.ScrollToCaret();
  143. }
  144. else if (type == 1)
  145. {
  146. msgBox.AppendText(showMsg, Color.Green);
  147. msgBox.SelectionStart = msgBox.Text.Length;
  148. msgBox.ScrollToCaret();
  149. }
  150. else if (type == 2)
  151. {
  152. msgBox.AppendText(showMsg, Color.YellowGreen);
  153. msgBox.SelectionStart = msgBox.Text.Length;
  154. msgBox.ScrollToCaret();
  155. }
  156. }
  157. private void cancel_Click(object sender, EventArgs e)
  158. {
  159. toolingVal.Enabled = true;
  160. toolingVal.Focus();
  161. toolingVal.SelectAll();
  162. }
  163. private void Receive_Click(object sender, EventArgs e)
  164. {
  165. if (string.IsNullOrEmpty(ma_code.Text))
  166. {
  167. ShowMsg(MsgBox, 0, "NG,请选择使用工单");
  168. ma_code.Focus();
  169. return;
  170. }
  171. if (string.IsNullOrEmpty(li_code.Text))
  172. {
  173. ShowMsg(MsgBox, 0, "NG,请输入使用线体");
  174. li_code.Focus();
  175. return;
  176. }
  177. if (string.IsNullOrEmpty(sideVal.Text))
  178. {
  179. ShowMsg(MsgBox, 0, "NG,请选择使用面别");
  180. sideVal.Focus();
  181. return;
  182. }
  183. if (string.IsNullOrEmpty(empVal.Text))
  184. {
  185. ShowMsg(MsgBox, 0, "NG,请填写领用人员");
  186. empVal.Focus();
  187. empVal.SelectAll();
  188. return;
  189. }
  190. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_version,nvl(st_maxusecount, 0) st_maxusecount,nvl(st_usecount, 0) st_usecount
  191. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  192. string status = dt.Rows[0]["st_usestatus"].ToString();
  193. if (status == "出库" || status == "报废")
  194. {
  195. ShowMsg(MsgBox, 0, $"NG,无法领用,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  196. return;
  197. }
  198. int maxCount = Convert.ToInt32(dt.Rows[0]["st_maxusecount"].ToString());
  199. int useCount = Convert.ToInt32(dt.Rows[0]["st_usecount"].ToString());
  200. int warnCount = Convert.ToInt32(dh.GetConfig("WaringCount", "Stencil"));
  201. if (maxCount - useCount < warnCount)
  202. {
  203. //ShowMsg(MsgBox, 2, "Warning,钢网:" + toolingVal.Text + "使用次数接近上限");
  204. DialogResult result = MessageBox.Show(this.ParentForm, $"Warning,{typeVal.Text}:{toolingVal.Text}使用次数接近上限,已使用{useCount},距离上限还有{(maxCount - useCount)}次", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  205. if (result == DialogResult.No || result == DialogResult.Cancel) return;
  206. }
  207. dt = (DataTable)dh.ExecuteSql($"select ma_prodcode from make where ma_code='{ma_code.Text}'", "select");
  208. string ma_prodcode = dt.Rows[0]["ma_prodcode"].ToString();
  209. dt = (DataTable)dh.ExecuteSql($"select st_code from stencil where st_line='{li_code.Text}' and st_kind = '{typeVal.Text}'", "select");
  210. if(typeVal.Text == "钢网")
  211. {
  212. if (dt.Rows.Count > 0)
  213. {
  214. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  215. return;
  216. }
  217. dt = (DataTable)dh.ExecuteSql($@"SELECT su_ensiona, su_ensionb, su_ensionc, su_ensiond, su_ensione FROM
  218. (SELECT * FROM stenciluse WHERE su_stcode = '{toolingVal.Text.Trim()}' AND su_status = '归还' ORDER BY su_usedate DESC) WHERE ROWNUM = 1", "select");
  219. if (dt.Rows.Count > 0)
  220. {
  221. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  222. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status,
  223. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  224. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  225. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用',
  226. '{dt.Rows[0]["su_ensiona"].ToString()}','{dt.Rows[0]["su_ensionb"].ToString()}','{dt.Rows[0]["su_ensionc"].ToString()}',
  227. '{dt.Rows[0]["su_ensiond"].ToString()}','{dt.Rows[0]["su_ensione"].ToString()}'
  228. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  229. }
  230. else
  231. {
  232. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  233. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  234. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  235. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  236. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  237. }
  238. }
  239. else if (typeVal.Text == "刮刀")
  240. {
  241. if (dt.Rows.Count > 1)
  242. {
  243. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  244. return;
  245. }
  246. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  247. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  248. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  249. '{ma_code.Text}','{ma_prodcode}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  250. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  251. }
  252. dh.ExecuteSql($@"update stencil set st_usestatus= '出库',st_line = '{li_code.Text}',st_macode = '{ma_code.Text}',
  253. st_useofproduct = '{ma_prodcode}' where st_code='" + toolingVal.Text + "'", "update");
  254. ma_code.Text = "";
  255. sideVal.SelectedIndex = -1;
  256. empVal.Text = "";
  257. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已领用成功");
  258. CleanDetail("Receive");
  259. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  260. toolingVal_KeyPress(toolingVal, newEvent);
  261. }
  262. private void CleanDetail(string type)
  263. {
  264. // Stencil Scraper
  265. if (type == "Receive")
  266. {
  267. ma_code.Text = "";
  268. sideVal.SelectedIndex = -1;
  269. empVal.Text = "";
  270. }
  271. else if (type == "Return")
  272. {
  273. stA.Text = "";
  274. stB.Text = "";
  275. stC.Text = "";
  276. stD.Text = "";
  277. stE.Text = "";
  278. empVal1.Text = "";
  279. useCountVal.Text = "";
  280. IsClean.Checked = false;
  281. }
  282. }
  283. private void Return_Click(object sender, EventArgs e)
  284. {
  285. if (string.IsNullOrEmpty(empVal1.Text))
  286. {
  287. ShowMsg(MsgBox, 0, "NG,请填写归还人员");
  288. empVal1.Focus();
  289. empVal1.SelectAll();
  290. return;
  291. }
  292. if (string.IsNullOrEmpty(useCountVal.Text))
  293. {
  294. useCountVal.Text = "0";
  295. }
  296. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_usecount
  297. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  298. string status = dt.Rows[0]["st_usestatus"].ToString();
  299. if (status == "在库" || status == "报废")
  300. {
  301. ShowMsg(MsgBox, 0, $"NG,无需归还,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  302. return;
  303. }
  304. int cleanCount = Convert.ToInt32(useCountVal.Text.Trim());
  305. if (typeVal.Text == "钢网")
  306. {
  307. dh.ExecuteSql($@"UPDATE stencil SET st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  308. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  309. st_usecount = nvl(st_usecount,0) + {cleanCount},st_usestatus = '在库',
  310. st_line = '',st_macode = '',st_useofproduct = ''
  311. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  312. if (IsClean.Checked) {
  313. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1
  314. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  315. }
  316. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  317. su_usemacode,su_useprodcode,su_linecode,su_table,
  318. su_useman,su_usedate,su_status,
  319. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  320. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  321. su_usemacode,su_useprodcode,su_linecode,su_table,
  322. '{empVal1.Text}',sysdate,'归还',
  323. st_ensiona,st_ensionb,st_ensionc,st_ensiond,st_ensione
  324. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  325. AND st_line = su_linecode", "insert");
  326. }
  327. else if(typeVal.Text == "刮刀")
  328. {
  329. dh.ExecuteSql($@"UPDATE stencil SET st_usecount = nvl(st_usecount,0) + {cleanCount},
  330. st_usestatus = '在库',st_line = '',st_macode = '',st_useofproduct = ''WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  331. if (IsClean.Checked)
  332. {
  333. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1 WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  334. }
  335. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  336. su_usemacode,su_useprodcode,su_linecode,su_table,
  337. su_useman,su_usedate,su_status,)
  338. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  339. su_usemacode,su_useprodcode,su_linecode,su_table,
  340. '{empVal1.Text}',sysdate,'归还',
  341. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  342. AND st_line = su_linecode", "insert");
  343. }
  344. stA.Text = "";
  345. stB.Text = "";
  346. stC.Text = "";
  347. stD.Text = "";
  348. stE.Text = "";
  349. empVal1.Text = "";
  350. IsClean.Checked = false;
  351. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已归还成功");
  352. CleanDetail("Receive");
  353. KeyPressEventArgs newEvent = new KeyPressEventArgs((char)Keys.Enter);
  354. toolingVal_KeyPress(toolingVal, newEvent);
  355. }
  356. private void Scrap_Click(object sender, EventArgs e)
  357. {
  358. }
  359. }
  360. }