Make_ToolingManager.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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_KeyPress(object sender, KeyPressEventArgs e)
  58. {
  59. if (e.KeyChar != (char)Keys.Enter) return;
  60. if (string.IsNullOrEmpty(toolingVal.Text.Trim()))
  61. {
  62. ShowMsg(MsgBox, 0, "NG,请输入治具编号");
  63. toolingVal.SelectAll();
  64. toolingVal.Focus();
  65. return;
  66. }
  67. dt = (DataTable)dh.ExecuteSql($"select st_kind,st_usestatus from stencil where st_code = '{toolingVal.Text.Trim()}' group by st_kind,st_usestatus", "select");
  68. if (dt.Rows.Count == 0)
  69. {
  70. ShowMsg(MsgBox, 0, "NG,未识别到治具类型,请先维护治具信息");
  71. toolingVal.SelectAll();
  72. toolingVal.Focus();
  73. return;
  74. }
  75. typeVal.Items.Clear();
  76. for (int i = 0; i < dt.Rows.Count; i++)
  77. {
  78. typeVal.Items.Add(dt.Rows[i][0].ToString());
  79. }
  80. typeVal.SelectedIndex = 0;
  81. currStatusVal.Text = dt.Rows[0]["st_usestatus"].ToString();
  82. if (typeVal.Text == "钢网")
  83. {
  84. stA.Enabled = true;
  85. stB.Enabled = true;
  86. stC.Enabled = true;
  87. stD.Enabled = true;
  88. stE.Enabled = true;
  89. }
  90. else
  91. {
  92. stA.Enabled = false;
  93. stB.Enabled = false;
  94. stC.Enabled = false;
  95. stD.Enabled = false;
  96. stE.Enabled = false;
  97. }
  98. 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");
  99. if (dt.Rows.Count == 0)
  100. {
  101. ShowMsg(MsgBox, 2, "NG,未识别到治具上次操作");
  102. }
  103. else
  104. {
  105. prevTypeVal.Text = dt.Rows[0]["su_status"].ToString();
  106. prevTimeVal.Text = dt.Rows[0]["su_usedate"].ToString();
  107. }
  108. if(currStatusVal.Text == "出库")
  109. {
  110. Return.Enabled = true;
  111. Scrap.Enabled = true;
  112. Receive.Enabled = false;
  113. }
  114. else if (currStatusVal.Text == "在库")
  115. {
  116. Return.Enabled = false;
  117. Scrap.Enabled = false;
  118. Receive.Enabled = true;
  119. }
  120. else
  121. {
  122. Return.Enabled = false;
  123. Scrap.Enabled = false;
  124. Receive.Enabled = true;
  125. }
  126. toolingVal.Enabled = false;
  127. }
  128. private void ShowMsg(RichTextAutoBottom msgBox, int type, string msg)
  129. {
  130. msg = msg.Replace("\r", "").Replace("\n", "");
  131. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  132. string showMsg = $"{msgTime}: {msg}\n";
  133. if (type == 0)
  134. {
  135. msgBox.AppendText(showMsg, Color.Red);
  136. msgBox.SelectionStart = msgBox.Text.Length;
  137. msgBox.ScrollToCaret();
  138. }
  139. else if (type == 1)
  140. {
  141. msgBox.AppendText(showMsg, Color.Green);
  142. msgBox.SelectionStart = msgBox.Text.Length;
  143. msgBox.ScrollToCaret();
  144. }
  145. else if (type == 2)
  146. {
  147. msgBox.AppendText(showMsg, Color.YellowGreen);
  148. msgBox.SelectionStart = msgBox.Text.Length;
  149. msgBox.ScrollToCaret();
  150. }
  151. }
  152. private void cancel_Click(object sender, EventArgs e)
  153. {
  154. toolingVal.Enabled = true;
  155. toolingVal.Focus();
  156. toolingVal.SelectAll();
  157. }
  158. private void Receive_Click(object sender, EventArgs e)
  159. {
  160. if (string.IsNullOrEmpty(ma_code.Text))
  161. {
  162. ShowMsg(MsgBox, 0, "NG,请选择使用工单");
  163. ma_code.Focus();
  164. return;
  165. }
  166. if (string.IsNullOrEmpty(li_code.Text))
  167. {
  168. ShowMsg(MsgBox, 0, "NG,请输入使用线体");
  169. li_code.Focus();
  170. return;
  171. }
  172. if (string.IsNullOrEmpty(sideVal.Text))
  173. {
  174. ShowMsg(MsgBox, 0, "NG,请选择使用面别");
  175. sideVal.Focus();
  176. return;
  177. }
  178. if (string.IsNullOrEmpty(empVal.Text))
  179. {
  180. ShowMsg(MsgBox, 0, "NG,请填写领用人员");
  181. empVal.Focus();
  182. empVal.SelectAll();
  183. return;
  184. }
  185. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_version,nvl(st_maxusecount, 0) st_maxusecount,nvl(st_usecount, 0) st_usecount
  186. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  187. string status = dt.Rows[0]["st_usestatus"].ToString();
  188. if (status == "出库" || status == "报废")
  189. {
  190. ShowMsg(MsgBox, 0, $"NG,无法领用,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  191. return;
  192. }
  193. int maxCount = Convert.ToInt32(dt.Rows[0]["st_maxusecount"].ToString());
  194. int useCount = Convert.ToInt32(dt.Rows[0]["st_usecount"].ToString());
  195. int warnCount = Convert.ToInt32(dh.GetConfig("WaringCount", "Stencil"));
  196. if (maxCount - useCount < warnCount)
  197. {
  198. //ShowMsg(MsgBox, 2, "Warning,钢网:" + toolingVal.Text + "使用次数接近上限");
  199. DialogResult result = MessageBox.Show(this.ParentForm, $"Warning,{typeVal.Text}:{toolingVal.Text}使用次数接近上限,已使用{useCount},距离上限还有{(maxCount - useCount)}次", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  200. if (result == DialogResult.No) return;
  201. }
  202. dt = (DataTable)dh.ExecuteSql($"select st_code from stencil where st_line='{li_code.Text}' and st_kind = '{typeVal.Text}'", "select");
  203. if(typeVal.Text == "钢网")
  204. {
  205. if (dt.Rows.Count > 0)
  206. {
  207. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  208. return;
  209. }
  210. }else if (typeVal.Text == "刮刀")
  211. {
  212. if (dt.Rows.Count > 1)
  213. {
  214. ShowMsg(MsgBox, 0, $"NG,线体已有在线{typeVal.Text},编号为:{dt.Rows[0]["st_code"].ToString()}");
  215. return;
  216. }
  217. }
  218. dh.ExecuteSql("update stencil set st_usestatus= '出库' where st_code='" + toolingVal.Text + "'", "update");
  219. dt = (DataTable)dh.ExecuteSql($"select ma_prodcode from make where ma_code='{ma_code.Text}'", "select");
  220. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  221. su_usemacode,su_useprodcode,su_linecode,su_table,su_useman,su_usedate,su_status)
  222. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  223. '{ma_code.Text}','{dt.Rows[0]["ma_prodcode"].ToString()}','{li_code.Text}','{sideVal.Text}','{empVal.Text}',sysdate, '领用'
  224. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "insert");
  225. ma_code.Text = "";
  226. sideVal.SelectedIndex = -1;
  227. empVal.Text = "";
  228. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已领用成功");
  229. }
  230. private void Return_Click(object sender, EventArgs e)
  231. {
  232. if (string.IsNullOrEmpty(empVal1.Text))
  233. {
  234. ShowMsg(MsgBox, 0, "NG,请填写归还人员");
  235. empVal1.Focus();
  236. empVal1.SelectAll();
  237. return;
  238. }
  239. dt = (DataTable)dh.ExecuteSql($@"SELECT st_usestatus,st_usecount
  240. FROM stencil WHERE st_code = '{toolingVal.Text.Trim()}'", "select");
  241. string status = dt.Rows[0]["st_usestatus"].ToString();
  242. if (status == "在库" || status == "报废")
  243. {
  244. ShowMsg(MsgBox, 0, $"NG,无需归还,{typeVal.Text}:{toolingVal.Text}为{status}状态");
  245. return;
  246. }
  247. if(typeVal.Text == "钢网")
  248. {
  249. if (IsClean.Checked) {
  250. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1,
  251. st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  252. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  253. st_usecount = '',st_usestatus = '在库'
  254. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  255. }
  256. else
  257. {
  258. dh.ExecuteSql($@"UPDATE stencil SET st_ensiona = '{stA.Text.Trim()}',st_ensionb = '{stB.Text.Trim()}',
  259. st_ensionc = '{stC.Text.Trim()}',st_ensiond = '{stD.Text.Trim()}',st_ensione = '{stE.Text.Trim()}',
  260. st_usecount = '',st_usestatus = '在库'
  261. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  262. }
  263. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  264. su_usemacode,su_useprodcode,su_linecode,su_table,
  265. su_useman,su_usedate,su_status,
  266. su_ensiona,su_ensionb,su_ensionc,su_ensiond,su_ensione)
  267. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  268. su_usemacode,su_useprodcode,su_linecode,su_table,
  269. '{empVal1.Text}',sysdate,'归还',
  270. st_ensiona,st_ensionb,st_ensionc,st_ensiond,st_ensione
  271. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  272. AND st_line = su_linecode", "insert");
  273. }
  274. else if(typeVal.Text == "刮刀")
  275. {
  276. if (IsClean.Checked)
  277. {
  278. dh.ExecuteSql($@"UPDATE stencil SET st_cleannums = nvl(st_cleannums, 0) + 1,st_usecount = '',
  279. st_usestatus = '在库' WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  280. }
  281. else
  282. {
  283. dh.ExecuteSql($@"UPDATE stencil SET st_usecount = '',st_usestatus = '在库'
  284. WHERE st_code = '{toolingVal.Text.Trim()}'", "update");
  285. }
  286. dh.ExecuteSql($@"INSERT INTO stenciluse (su_id,su_stcode,su_stid,
  287. su_usemacode,su_useprodcode,su_linecode,su_table,
  288. su_useman,su_usedate,su_status,)
  289. SELECT stenciluse_seq.NEXTVAL,'{toolingVal.Text.Trim()}',st_id,
  290. su_usemacode,su_useprodcode,su_linecode,su_table,
  291. '{empVal1.Text}',sysdate,'归还',
  292. FROM stencil,stenciluse WHERE st_code = '{toolingVal.Text.Trim()}'
  293. AND st_line = su_linecode", "insert");
  294. }
  295. stA.Text = "";
  296. stB.Text = "";
  297. stC.Text = "";
  298. stD.Text = "";
  299. stE.Text = "";
  300. empVal1.Text = "";
  301. IsClean.Checked = false;
  302. ShowMsg(MsgBox, 1, $"OK,{typeVal.Text}编号:{toolingVal.Text},已归还成功");
  303. }
  304. private void Scrap_Click(object sender, EventArgs e)
  305. {
  306. }
  307. }
  308. }