Make_SMTStockStencil.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES;
  10. using UAS_MES.DataOperate;
  11. using UAS_MES.Entity;
  12. using UAS_MES.PublicMethod;
  13. namespace UAS_MES.Make
  14. {
  15. public partial class Make_SMTStockStencil : Form
  16. {
  17. DataTable Dbfind;
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. DataHelper dh = SystemInf.dh;
  20. StringBuilder sql = new StringBuilder();
  21. bool ifUsed = false;
  22. public Make_SMTStockStencil()
  23. {
  24. InitializeComponent();
  25. SU_DEVCODE.Enabled = false;
  26. SU_DEVCODE1.Enabled = false;
  27. ST_ENSIONA.Enabled = false;
  28. ST_ENSIONB.Enabled = false;
  29. ST_ENSIONC.Enabled = false;
  30. ST_ENSIOND.Enabled = false;
  31. ST_ENSIONE.Enabled = false;
  32. Receive.Enabled = false;
  33. Return.Enabled = false;
  34. Scrap.Enabled = false;
  35. }
  36. private void Make_SMTStencil_Load(object sender, EventArgs e)
  37. {
  38. asc.controllInitializeSize(this);
  39. //工单号放大镜配置
  40. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  41. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  42. ma_code.FormName = Name;
  43. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_detail", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  44. ma_code.Condition = "ma_statuscode in('STARTED','AUDITED')";
  45. ma_code.DbChange += Ma_code_DbChange;
  46. SU_DEVCODE.Focus();
  47. }
  48. private void Ma_code_DbChange(object sender, EventArgs e)
  49. {
  50. Dbfind = ma_code.ReturnData;
  51. BaseUtil.SetFormValue(this.Controls, Dbfind);
  52. Confirm.PerformClick();
  53. }
  54. private void Make_SMTStencil_SizeChanged(object sender, EventArgs e)
  55. {
  56. asc.controlAutoSize(this);
  57. }
  58. private void LoadGridData()
  59. {
  60. sql.Clear();
  61. sql.Append("select St_PCBCODE,su_stcode,su_table,su_status,su_linecode,su_usemacode,su_singlepringqty,su_stverison ");
  62. sql.Append("from StencilUse left join stencil on st_code=su_stcode where su_usemacode='" + ma_code.Text + "' and su_status='在线'");
  63. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  64. BaseUtil.FillDgvWithDataTable(ToolsBom, dt);
  65. }
  66. private void Confirm_Click(object sender, EventArgs e)
  67. {
  68. LoadGridData();
  69. }
  70. private void Receive_Click(object sender, EventArgs e)
  71. {
  72. DataTable dt = (DataTable)dh.ExecuteSql("select ST_USESTATUS,nvl(st_maxusecount,0)st_maxusecount,nvl(st_usecount,0)st_usecount from Stencil where st_code='" + SU_DEVCODE.Text + "' and st_statuscode='AUDITED'", "select");
  73. int WaringCount = int.Parse(dh.GetConfig("WaringCount", "Stencil").ToString());
  74. int st_maxusecount = 0;
  75. int st_usecount = 0;
  76. if (dt.Rows.Count > 0)
  77. {
  78. string status = dt.Rows[0]["ST_USESTATUS"].ToString();
  79. st_maxusecount = int.Parse(dt.Rows[0]["st_maxusecount"].ToString());
  80. st_usecount = int.Parse(dt.Rows[0]["st_usecount"].ToString());
  81. if (status == "借出" || status == "报废" || status == "在线")
  82. {
  83. MessageBox.Show("当前钢网" + SU_DEVCODE.Text + "处于" + status + "状态,无法领用");
  84. return;
  85. }
  86. }
  87. else
  88. {
  89. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "不存在或者未审核");
  90. return;
  91. }
  92. //使用次数预警
  93. if (st_maxusecount - st_usecount < WaringCount)
  94. {
  95. string close = MessageBox.Show(this.ParentForm, "钢网已使用" + st_usecount + ",距离使用上限还有" + (st_maxusecount - st_usecount) + "次", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  96. if (close != "Yes")
  97. {
  98. return;
  99. }
  100. }
  101. sql.Clear();
  102. sql.Append("insert into StencilUse(su_id,su_stid,su_stcode,su_stockusedate,su_useman,SU_USEMANCODE,su_stverison,SU_STATUS,SU_CLEANNUMS)");
  103. sql.Append("select StencilUse_seq.nextval,st_id,'" + SU_DEVCODE.Text + "',sysdate,'" + User.UserName + "','" + User.UserCode + "'");
  104. sql.Append(",st_version,'借出',ST_CLEANNUMS from ");
  105. sql.Append("Stencil where st_code='" + SU_DEVCODE.Text + "'");
  106. dh.ExecuteSql(sql.ToString(), "insert");
  107. dh.ExecuteSql("update Stencil set ST_USESTATUS='借出' where st_code='" + SU_DEVCODE.Text + "'", "update");
  108. MessageBox.Show("领用成功");
  109. SU_DEVCODE.Text = "";
  110. Receive.Enabled = false;
  111. LoadGridData();
  112. }
  113. private void Return_Click(object sender, EventArgs e)
  114. {
  115. if (ST_ENSIONA.Text != "" && ST_ENSIONB.Text != "" && ST_ENSIONC.Text != "" && ST_ENSIOND.Text != "" && ST_ENSIONE.Text != "")
  116. {
  117. if (SU_RETURNIFCLEAN.Checked)
  118. {
  119. DataTable dt = (DataTable)dh.ExecuteSql("select ST_USESTATUS,nvl(St_USECOUNT,0)St_USECOUNT from Stencil where st_code='" + SU_DEVCODE1.Text + "' and st_statuscode='AUDITED'", "select");
  120. if (dt.Rows.Count > 0)
  121. {
  122. string status = dt.Rows[0]["ST_USESTATUS"].ToString();
  123. if (status == "在线")
  124. {
  125. MessageBox.Show("当前钢网" + SU_DEVCODE1.Text + "处于在线状态,无法退回");
  126. return;
  127. }
  128. if (status == "在仓")
  129. {
  130. MessageBox.Show("当前钢网" + SU_DEVCODE1.Text + "未借出,无需归还");
  131. return;
  132. }
  133. if (status == "报废")
  134. {
  135. MessageBox.Show("当前钢网" + SU_DEVCODE1.Text + "处于" + status + "状态,无法退回");
  136. return;
  137. }
  138. }
  139. else
  140. {
  141. MessageBox.Show("钢网编号" + SU_DEVCODE1.Text + "不存在或者未审核");
  142. return;
  143. }
  144. sql.Clear();
  145. sql.Append("update StencilUse set SU_CLEANNUMS = nvl(SU_CLEANNUMS,0)+1,su_returnman='" + User.UserName + "',SU_STOCKBACKDATE=sysdate,SU_ENSIONA='" + ST_ENSIONA.Text + "',SU_ENSIONB='" + ST_ENSIONB.Text + "',SU_ENSIONC='" + ST_ENSIONC.Text + "',SU_ENSIOND='" + ST_ENSIOND.Text + "',");
  146. sql.Append("SU_ENSIONE='" + ST_ENSIONE.Text + "',SU_STATUS='在仓'");
  147. sql.Append(",SU_RETURNIFCLEAN='" + (SU_RETURNIFCLEAN.Checked ? "-1" : "0") + "' where su_id=(select max(su_id) from stenciluse where su_stcode='" + SU_DEVCODE1.Text + "' and su_status='借出' and su_stockusedate is not null)");
  148. dh.ExecuteSql(sql.ToString(), "update");
  149. sql.Clear();
  150. sql.Append("update Stencil set st_cleannums=nvl(st_cleannums,0)+1,ST_USESTATUS='在仓',ST_ENSIONA='" + ST_ENSIONA.Text + "',ST_ENSIONB='" + ST_ENSIONB.Text + "',");
  151. sql.Append("ST_ENSIONC='" + ST_ENSIONC.Text + "',ST_ENSIOND='" + ST_ENSIOND.Text + "',ST_ENSIONE='" + ST_ENSIONE.Text + "' ");
  152. sql.Append("where st_code='" + SU_DEVCODE1.Text + "'");
  153. dh.ExecuteSql(sql.ToString(), "update");
  154. MessageBox.Show("钢网" + SU_DEVCODE1.Text + "退回成功!");
  155. SU_DEVCODE1.Text = "";
  156. ST_ENSIONA.Text = "";
  157. ST_ENSIONB.Text = "";
  158. ST_ENSIONC.Text = "";
  159. ST_ENSIOND.Text = "";
  160. ST_ENSIONE.Text = "";
  161. SU_RETURNIFCLEAN.Checked = false;
  162. Return.Enabled = false;
  163. Confirm.PerformClick();
  164. }
  165. else
  166. {
  167. MessageBox.Show("请确认是否清洗钢网");
  168. }
  169. }
  170. else
  171. {
  172. MessageBox.Show("请维护完成的测试参数");
  173. }
  174. }
  175. Make_StencilScrapReason form;
  176. private void Scrap_Click(object sender, EventArgs e)
  177. {
  178. DataTable dt = (DataTable)dh.ExecuteSql("select st_usestatus,st_status from stencil where st_code='" + SU_DEVCODE1.Text + "' and st_statuscode='AUDITED'", "select");
  179. if (dt.Rows.Count > 0)
  180. {
  181. if (dt.Rows[0]["st_usestatus"].ToString() == "报废")
  182. {
  183. MessageBox.Show("钢网" + SU_DEVCODE1.Text + "已处于报废状态");
  184. return;
  185. }
  186. if (dt.Rows[0]["st_usestatus"].ToString() != "借出")
  187. {
  188. MessageBox.Show("报废钢网必须" + SU_DEVCODE1.Text + "处于借出状态");
  189. return;
  190. }
  191. string closetab_confirm = MessageBox.Show(this.ParentForm, "报废后不可撤销,是否确认报废", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  192. if (closetab_confirm != "Yes")
  193. {
  194. return;
  195. }
  196. form = new Make_StencilScrapReason();
  197. BaseUtil.SetFormCenter(form);
  198. form.Controls["ConfirmScrap"].Click += Make_SMTStencil_Click;
  199. form.ShowDialog();
  200. }
  201. else
  202. {
  203. MessageBox.Show("钢网编号" + SU_DEVCODE1.Text + "不存在或者未审核");
  204. }
  205. }
  206. private void Make_SMTStencil_Click(object sender, EventArgs e)
  207. {
  208. string Code = "";
  209. string scrapreason = form.Controls["Reason"].Text;
  210. if (scrapreason == "")
  211. {
  212. MessageBox.Show("报废原因不能为空");
  213. return;
  214. }
  215. sql.Clear();
  216. sql.Append("update StencilUse set SU_IFSCRAPOLD=-1,SU_STATUS='报废',SU_ENSIONA='" + ST_ENSIONA.Text + "',SU_ENSIONB='" + ST_ENSIONB.Text + "',SU_ENSIONC='" + ST_ENSIONC.Text + "',SU_ENSIOND='" + ST_ENSIOND.Text + "',SU_ENSIONE='" + ST_ENSIONE.Text + "'");
  217. sql.Append(",SU_RETURNIFCLEAN='" + (SU_RETURNIFCLEAN.Checked ? "-1" : "0") + "' where su_id=(select max(su_id) from stenciluse where su_stcode='" + SU_DEVCODE1.Text + "')");
  218. dh.ExecuteSql(sql.ToString(), "update");
  219. sql.Clear();
  220. sql.Append("update Stencil set ST_SCRAPREASON='" + scrapreason + "',ST_SCRAPMANCODE='" + User.UserCode + "',st_scrapman='" + User.UserName + "',st_scrapdate=sysdate,ST_USESTATUS='报废',ST_ENSIONA='" + ST_ENSIONA.Text + "',ST_ENSIONB='" + ST_ENSIONB.Text + "',");
  221. sql.Append("ST_ENSIONC='" + ST_ENSIONC.Text + "',ST_ENSIOND='" + ST_ENSIOND.Text + "',ST_ENSIONE='" + ST_ENSIONE.Text + "' ");
  222. sql.Append("where st_code='" + SU_DEVCODE1.Text + "'");
  223. dh.ExecuteSql(sql.ToString(), "insert");
  224. //推送人员信息
  225. string[] emid = dh.GetConfig("sendEmp", "Stencil").ToString().Replace("\n", "#").Split('#');
  226. for (int i = 0; i < emid.Length; i++)
  227. {
  228. string em_name = dh.getFieldDataByCondition("employee", "em_name", "em_id='" + emid[i] + "'").ToString();
  229. LogicHandler.SendMessage(emid[i], em_name, "钢网" + SU_DEVCODE1.Text + "已报废" + ",原因" + scrapreason + ",人员" + User.UserName);
  230. }
  231. form.Close();
  232. SU_DEVCODE1.Text = "";
  233. ST_ENSIONA.Text = "";
  234. ST_ENSIONB.Text = "";
  235. ST_ENSIONC.Text = "";
  236. ST_ENSIOND.Text = "";
  237. ST_ENSIONE.Text = "";
  238. SU_RETURNIFCLEAN.Checked = false;
  239. Scrap.Enabled = false;
  240. MessageBox.Show("报废成功!");
  241. }
  242. private void Radio_CheckedChanged(object sender, EventArgs e)
  243. {
  244. switch ((sender as Control).Name)
  245. {
  246. case "RadioReceive":
  247. if ((sender as RadioButton).Checked)
  248. {
  249. SU_DEVCODE.Enabled = true;
  250. Receive.Enabled = true;
  251. Receive.Enabled = true;
  252. SU_DEVCODE1.Enabled = false;
  253. ST_ENSIONA.Enabled = false;
  254. ST_ENSIONB.Enabled = false;
  255. ST_ENSIONC.Enabled = false;
  256. ST_ENSIOND.Enabled = false;
  257. ST_ENSIONE.Enabled = false;
  258. Return.Enabled = false;
  259. Scrap.Enabled = false;
  260. }
  261. break;
  262. case "RadioReturn":
  263. if ((sender as RadioButton).Checked)
  264. {
  265. SU_DEVCODE1.Enabled = true;
  266. ST_ENSIONA.Enabled = true;
  267. ST_ENSIONB.Enabled = true;
  268. ST_ENSIONC.Enabled = true;
  269. ST_ENSIOND.Enabled = true;
  270. ST_ENSIONE.Enabled = true;
  271. SU_DEVCODE.Enabled = false;
  272. Receive.Enabled = false;
  273. Receive.Enabled = false;
  274. }
  275. break;
  276. default:
  277. break;
  278. }
  279. }
  280. //默认范围39-55,如不在范围内则可以报废
  281. private void ST_ENSION_TextChanged(object sender, EventArgs e)
  282. {
  283. double Range = 0;
  284. List<string> Num = new List<string>();
  285. Num.Add(ST_ENSIONA.Text);
  286. Num.Add(ST_ENSIONB.Text);
  287. Num.Add(ST_ENSIONC.Text);
  288. Num.Add(ST_ENSIOND.Text);
  289. Num.Add(ST_ENSIONE.Text);
  290. int CheckCount = 0;
  291. int FillCount = 0;
  292. foreach (string item in Num)
  293. {
  294. if (item != "")
  295. {
  296. FillCount = FillCount + 1;
  297. if (double.TryParse(item, out Range))
  298. {
  299. //如果使用过张力范围39-55,使用过30-55
  300. if (ifUsed)
  301. {
  302. if (Range > 30 && Range <= 55)
  303. {
  304. CheckCount = CheckCount + 1;
  305. }
  306. }
  307. else
  308. {
  309. if (Range > 30 && Range <= 55)
  310. {
  311. CheckCount = CheckCount + 1;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. if (FillCount == 5)
  318. {
  319. if (CheckCount == 5)
  320. {
  321. Return.Enabled = true;
  322. Scrap.Enabled = false;
  323. }
  324. else
  325. {
  326. Return.Enabled = false;
  327. Scrap.Enabled = true;
  328. }
  329. }
  330. }
  331. private void SU_DEVCODE_KeyDown(object sender, KeyEventArgs e)
  332. {
  333. if (e.KeyCode == Keys.Enter)
  334. {
  335. DataTable dt = (DataTable)dh.ExecuteSql("select st_usestatus,st_table from stencil where st_code='" + SU_DEVCODE.Text + "' and st_statuscode='AUDITED'", "select");
  336. if (dt.Rows.Count == 0)
  337. {
  338. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "不存在或者未审核");
  339. }
  340. if (dt.Rows.Count > 0)
  341. {
  342. Receive.Enabled = true;
  343. if (dt.Rows[0]["st_usestatus"].ToString() == "报废")
  344. {
  345. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "已报废");
  346. }
  347. }
  348. }
  349. }
  350. private void SU_DEVCODE1_KeyDown(object sender, KeyEventArgs e)
  351. {
  352. if (e.KeyCode == Keys.Enter)
  353. {
  354. DataTable dt = (DataTable)dh.ExecuteSql("select nvl(st_usecount,0)st_usecount,case when nvl(ST_COMBINENUMBER,1)=0 then 1 else nvl(ST_COMBINENUMBER,1) end from STENCIL where st_code='" + SU_DEVCODE1.Text + "' and st_statuscode='AUDITED'", "select");
  355. if (dt.Rows.Count == 0)
  356. {
  357. MessageBox.Show("钢网编号" + SU_DEVCODE1.Text + "不存在或者未审核");
  358. }
  359. else
  360. {
  361. st_usecount.Text = dt.Rows[0]["st_usecount"].ToString();
  362. if (int.Parse(st_usecount.Text) > 0)
  363. {
  364. ifUsed = true;
  365. }
  366. else
  367. {
  368. ifUsed = false;
  369. }
  370. }
  371. }
  372. }
  373. private void ma_code_TextKeyDown(object sender, KeyEventArgs e)
  374. {
  375. if (e.KeyCode == Keys.Enter)
  376. {
  377. Confirm.PerformClick();
  378. }
  379. }
  380. }
  381. }