Make_ToolingManager.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  18. namespace UAS_MES_NEW.Make
  19. {
  20. public partial class Make_ToolingManager : Form
  21. {
  22. public Make_ToolingManager()
  23. {
  24. InitializeComponent();
  25. }
  26. DataHelper dh;
  27. DataTable Dbfind;
  28. LogStringBuilder sql = new LogStringBuilder();
  29. DataTable dt;
  30. private void Make_ToolingManager_Load(object sender, EventArgs e)
  31. {
  32. dh = SystemInf.dh;
  33. li_code.Text = User.UserLineCode;
  34. //工单号放大镜配置
  35. LockMakeCode.GetMakeCodeCtl(ma_code);
  36. ma_code.SetLockCheckBox(LockMakeCode);
  37. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  38. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  39. ma_code.FormName = Name;
  40. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_detail", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  41. ma_code.DbChange += Ma_code_DbChange;
  42. li_code.TableName = "Line";
  43. li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
  44. li_code.Condition = "li_wccode='SMT'";
  45. li_code.FormName = Name;
  46. li_code.SetValueField = new string[] { "li_code", "li_name" };
  47. li_code.DbChange += Li_code_DbChange;
  48. toolingVal.SelectAll();
  49. toolingVal.Focus();
  50. }
  51. private void Li_code_DbChange(object sender, EventArgs e)
  52. {
  53. Dbfind = li_code.ReturnData;
  54. BaseUtil.SetFormValue(this.Controls, Dbfind);
  55. }
  56. private void Ma_code_DbChange(object sender, EventArgs e)
  57. {
  58. Dbfind = ma_code.ReturnData;
  59. BaseUtil.SetFormValue(this.Controls, Dbfind);
  60. //Confirm.PerformClick();
  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) return;
  206. }
  207. dt = (DataTable)dh.ExecuteSql($"select st_code from stencil where st_line='{li_code.Text}' and st_kind = '{typeVal.Text}'", "select");
  208. if(typeVal.Text == "钢网")
  209. {
  210. if (dt.Rows.Count > 0)
  211. {
  212. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  213. return;
  214. }
  215. }else if (typeVal.Text == "刮刀")
  216. {
  217. if (dt.Rows.Count > 1)
  218. {
  219. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  220. return;
  221. }
  222. }
  223. dh.ExecuteSql("update stencil set st_usestatus= '出库' where st_code='" + toolingVal.Text + "'", "update");
  224. dt = (DataTable)dh.ExecuteSql($"select ma_prodcode from make where ma_code='{ma_code.Text}'", "select");
  225. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  226. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  227. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  228. '{ma_code.Text}','{dt.Rows[0]["ma_prodcode"].ToString()}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  229. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  230. ma_code.Text = "";
  231. sideVal.SelectedIndex = -1;
  232. empVal.Text = "";
  233. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已领用成功");
  234. }
  235. private void Return_Click(object sender, EventArgs e)
  236. {
  237. if (string.IsNullOrEmpty(empVal1.Text))
  238. {
  239. ShowMsg(MsgBox, 0, "NG,请填写归还人员");
  240. empVal1.Focus();
  241. empVal1.SelectAll();
  242. return;
  243. }
  244. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_usecount
  245. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  246. string status = dt.Rows[0]["st_usestatus"].ToString();
  247. if (status == "在库" || status == "报废")
  248. {
  249. ShowMsg(MsgBox, 0, $"NG,无需归还,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  250. return;
  251. }
  252. if(typeVal.Text == "钢网")
  253. {
  254. if (IsClean.Checked) {
  255. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1,
  256. st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  257. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  258. st_usecount = '',st_usestatus = '在库'
  259. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  260. }
  261. else
  262. {
  263. dh.ExecuteSql($@"UPDATE stencil SET st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  264. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  265. st_usecount = '',st_usestatus = '在库'
  266. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  267. }
  268. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  269. su_usemacode,su_useprodcode,su_linecode,su_table,
  270. su_useman,su_usedate,su_status,
  271. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  272. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  273. su_usemacode,su_useprodcode,su_linecode,su_table,
  274. '{empVal1.Text}',sysdate,'归还',
  275. st_ensiona,st_ensionb,st_ensionc,st_ensiond,st_ensione
  276. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  277. AND st_line = su_linecode", "insert");
  278. }
  279. else if(typeVal.Text == "刮刀")
  280. {
  281. if (IsClean.Checked)
  282. {
  283. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1,st_usecount = '',
  284. st_usestatus = '在库' WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  285. }
  286. else
  287. {
  288. dh.ExecuteSql($@"UPDATE stencil SET st_usecount = '',st_usestatus = '在库'
  289. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  290. }
  291. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  292. su_usemacode,su_useprodcode,su_linecode,su_table,
  293. su_useman,su_usedate,su_status,)
  294. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  295. su_usemacode,su_useprodcode,su_linecode,su_table,
  296. '{empVal1.Text}',sysdate,'归还',
  297. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  298. AND st_line = su_linecode", "insert");
  299. }
  300. stA.Text = "";
  301. stB.Text = "";
  302. stC.Text = "";
  303. stD.Text = "";
  304. stE.Text = "";
  305. empVal1.Text = "";
  306. IsClean.Checked = false;
  307. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已归还成功");
  308. }
  309. private void Scrap_Click(object sender, EventArgs e)
  310. {
  311. }
  312. }
  313. }