Make_SMTStencil.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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_SMTStencil : Form
  16. {
  17. DataTable Dbfind;
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. DataHelper dh = SystemInf.dh;
  20. StringBuilder sql = new StringBuilder();
  21. public Make_SMTStencil()
  22. {
  23. InitializeComponent();
  24. SU_DEVCODE.Enabled = false;
  25. st_combinenumber.Enabled = false;
  26. SU_DEVCODE1.Enabled = false;
  27. st_table.Enabled = false;
  28. su_singlepringqty1.Enabled = false;
  29. Receive.Enabled = false;
  30. Return.Enabled = false;
  31. }
  32. private void Make_SMTStencil_Load(object sender, EventArgs e)
  33. {
  34. asc.controllInitializeSize(this);
  35. li_code.Text = User.UserLineCode;
  36. //工单号放大镜配置
  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. ma_code.Controls["TextBox"].Focus();
  49. }
  50. private void Li_code_DbChange(object sender, EventArgs e)
  51. {
  52. Dbfind = li_code.ReturnData;
  53. BaseUtil.SetFormValue(this.Controls, Dbfind);
  54. }
  55. private void Ma_code_DbChange(object sender, EventArgs e)
  56. {
  57. Dbfind = ma_code.ReturnData;
  58. BaseUtil.SetFormValue(this.Controls, Dbfind);
  59. Confirm.PerformClick();
  60. }
  61. private void Make_SMTStencil_SizeChanged(object sender, EventArgs e)
  62. {
  63. asc.controlAutoSize(this);
  64. }
  65. private void LoadGridData()
  66. {
  67. sql.Clear();
  68. sql.Append("select St_PCBCODE,su_stcode,su_table,su_status,su_linecode,su_usemacode,su_singlepringqty,su_stverison ");
  69. sql.Append("from StencilUse left join stencil on st_code=su_stcode where su_usemacode='" + ma_code.Text + "' and su_status='在线'");
  70. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  71. BaseUtil.FillDgvWithDataTable(ToolsBom, dt);
  72. }
  73. private void Confirm_Click(object sender, EventArgs e)
  74. {
  75. LoadGridData();
  76. }
  77. private void Receive_Click(object sender, EventArgs e)
  78. {
  79. if (ma_code.Text == "")
  80. {
  81. MessageBox.Show("工单号不能为空");
  82. }
  83. int WaringCount =int.Parse(dh.GetConfig("WaringCount", "Stencil").ToString());
  84. DataTable dt = (DataTable)dh.ExecuteSql("select ST_USESTATUS,st_version,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");
  85. string status = "";
  86. string version = "";
  87. int st_maxusecount = 0;
  88. int st_usecount = 0;
  89. if (dt.Rows.Count > 0)
  90. {
  91. status = dt.Rows[0]["ST_USESTATUS"].ToString();
  92. version = dt.Rows[0]["st_version"].ToString();
  93. st_maxusecount =int.Parse( dt.Rows[0]["st_maxusecount"].ToString());
  94. st_usecount = int.Parse(dt.Rows[0]["st_usecount"].ToString());
  95. if (status == "在线" || status == "报废" || status == "在仓")
  96. {
  97. MessageBox.Show("当前钢网" + SU_DEVCODE.Text + "处于" + status + "状态,无法领用");
  98. return;
  99. }
  100. }
  101. else
  102. {
  103. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "不存在或者未审核");
  104. return;
  105. }
  106. //使用次数预警
  107. if (st_maxusecount - st_usecount < WaringCount)
  108. {
  109. string close = MessageBox.Show(this.ParentForm, "钢网已使用"+ st_usecount+",距离使用上限还有"+(st_maxusecount - st_usecount)+"次", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  110. if (close != "Yes")
  111. {
  112. return;
  113. }
  114. }
  115. //限制钢网使用的产品
  116. dt = (DataTable)dh.ExecuteSql("select 1 from STENILCANUSEPRO where sp_stcode='" + SU_DEVCODE.Text + "' and sp_prodcode='" + ma_prodcode.Text + "'", "select");
  117. if (dt.Rows.Count == 0)
  118. {
  119. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "不能在产品" + ma_prodcode.Text + "中使用");
  120. return;
  121. }
  122. //一条线只能在线一个钢网
  123. //dt = (DataTable)dh.ExecuteSql("select su_stcode from stenciluse where su_linecode='" + li_code.Text + "' and su_status='在线'", "select");
  124. //if (dt.Rows.Count > 0)
  125. //{
  126. // MessageBox.Show("线别" + li_code.Text + "已有领用的钢网" + dt.Rows[0]["su_stcode"].ToString() + ",请先退回");
  127. // return;
  128. //}
  129. //else
  130. //{
  131. dt = (DataTable)dh.ExecuteSql("select em_name from employee where em_code='" + em_code.Text + "'", "select");
  132. if (dt.Rows.Count > 0)
  133. {
  134. if (int.Parse(su_singlepringqty1.Text) > 0)
  135. {
  136. string em_name = dt.Rows[0]["em_name"].ToString();
  137. sql.Clear();
  138. sql.Append("insert into StencilUse(su_id,SU_USEPRODCODE,SU_CLEANNUMS,su_stid,su_linecode,su_stcode,su_usedate,su_useman,SU_USEMANCODE,SU_TABLE,su_usemacode,su_singlepringqty,su_stverison,SU_STATUS)");
  139. sql.Append("select StencilUse_seq.nextval,'" + ma_prodcode.Text + "',ST_CLEANNUMS,st_id,'" + li_code.Text + "','" + SU_DEVCODE.Text + "',sysdate,'" + em_name + "','" + em_code.Text + "','" + st_table.Text + "','" + ma_code.Text + "'");
  140. sql.Append(",'" + su_singlepringqty1.Text + "',st_version,'在线' from ");
  141. sql.Append("Stencil where st_code='" + SU_DEVCODE.Text + "'");
  142. dh.ExecuteSql(sql.ToString(), "insert");
  143. dh.ExecuteSql("update Stencil set ST_USESTATUS='在线' where st_code='" + SU_DEVCODE.Text + "'", "update");
  144. MessageBox.Show("领用成功");
  145. st_table.SelectedItem = null;
  146. SU_DEVCODE.Text = "";
  147. em_code.Text = "";
  148. Receive.Enabled = false;
  149. LoadGridData();
  150. }
  151. else
  152. {
  153. MessageBox.Show("单片印刷次数必须大于0");
  154. }
  155. }
  156. else
  157. {
  158. MessageBox.Show("人员编号" + em_code.Text + "不存在");
  159. }
  160. // }
  161. }
  162. private void Return_Click(object sender, EventArgs e)
  163. {
  164. if (SU_RETURNIFCLEAN.Checked)
  165. {
  166. DataTable dt = (DataTable)dh.ExecuteSql("select ST_USESTATUS,St_USECOUNT from Stencil where st_code='" + SU_DEVCODE1.Text + "' and st_statuscode='AUDITED'", "select");
  167. if (dt.Rows.Count > 0)
  168. {
  169. string status = dt.Rows[0]["ST_USESTATUS"].ToString();
  170. if (status == "在仓" || status == "借出")
  171. {
  172. MessageBox.Show("当前钢网" + SU_DEVCODE.Text + "未在线,无需归还");
  173. return;
  174. }
  175. if (status == "报废")
  176. {
  177. MessageBox.Show("当前钢网" + SU_DEVCODE.Text + "处于" + status + "状态,无法退回");
  178. return;
  179. }
  180. }
  181. else
  182. {
  183. MessageBox.Show("钢网编号" + SU_DEVCODE1.Text + "不存在或者未审核");
  184. }
  185. string St_USECOUNT = dt.Rows[0]["St_USECOUNT"].ToString();
  186. dt = (DataTable)dh.ExecuteSql("select em_name from employee where em_code='" + em_code1.Text + "'", "select");
  187. if (dt.Rows.Count > 0)
  188. {
  189. if (int.Parse(st_combinenumber.Text) >= 0)
  190. {
  191. sql.Clear();
  192. sql.Append("update StencilUse set su_cleannums=nvl(su_cleannums,0)+1, SU_BACKDATE=sysdate,su_returnman='" + dt.Rows[0]["em_name"].ToString() + "',su_returnmancode='" + em_code1.Text + "',");
  193. sql.Append("SU_THISUSETIMES='" + (st_combinenumber.Text == "" ? "0" : st_combinenumber.Text) + "',SU_STATUS='借出',su_usecount=" + (St_USECOUNT == "" ? "0" : St_USECOUNT) + "+" + st_combinenumber.Text);
  194. 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='在线')");
  195. dh.ExecuteSql(sql.ToString(), "update");
  196. sql.Clear();
  197. sql.Append("update Stencil set st_cleannums=nvl(st_cleannums,0)+1,St_USECOUNT=nvl(St_USECOUNT,0)+" + (st_combinenumber.Text == "" ? "0" : st_combinenumber.Text) + ",ST_USESTATUS='借出' where st_code='" + SU_DEVCODE1.Text + "'");
  198. dh.ExecuteSql(sql.ToString(), "update");
  199. MessageBox.Show("钢网" + SU_DEVCODE1.Text + "退回成功!");
  200. SU_DEVCODE1.Text = "";
  201. st_combinenumber.Text = "";
  202. em_code1.Text = "";
  203. SU_RETURNIFCLEAN.Checked = false;
  204. Confirm.PerformClick();
  205. }
  206. else
  207. {
  208. MessageBox.Show("加工小板数必须大于等于0");
  209. }
  210. }
  211. else
  212. {
  213. MessageBox.Show("人员编号" + em_code1.Text + "不存在");
  214. }
  215. }
  216. else
  217. {
  218. MessageBox.Show("请确认是否清洗钢网");
  219. }
  220. }
  221. private void Radio_CheckedChanged(object sender, EventArgs e)
  222. {
  223. switch ((sender as Control).Name)
  224. {
  225. case "RadioReceive":
  226. if ((sender as RadioButton).Checked)
  227. {
  228. SU_DEVCODE.Enabled = true;
  229. Receive.Enabled = true;
  230. st_table.Enabled = true;
  231. su_singlepringqty1.Enabled = true;
  232. Receive.Enabled = true;
  233. st_combinenumber.Enabled = false;
  234. SU_DEVCODE1.Enabled = false;
  235. Return.Enabled = false;
  236. }
  237. break;
  238. case "RadioReturn":
  239. if ((sender as RadioButton).Checked)
  240. {
  241. SU_DEVCODE1.Enabled = true;
  242. st_combinenumber.Enabled = true;
  243. Return.Enabled = true;
  244. SU_DEVCODE.Enabled = false;
  245. st_table.Enabled = false;
  246. su_singlepringqty1.Enabled = false;
  247. Receive.Enabled = false;
  248. }
  249. break;
  250. default:
  251. break;
  252. }
  253. }
  254. private void SU_DEVCODE_KeyDown(object sender, KeyEventArgs e)
  255. {
  256. if (e.KeyCode == Keys.Enter)
  257. {
  258. DataTable dt = (DataTable)dh.ExecuteSql("select st_usestatus,st_table from stencil where st_code='" + SU_DEVCODE.Text + "' and st_statuscode='AUDITED'", "select");
  259. if (dt.Rows.Count == 0)
  260. {
  261. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "不存在或者未审核");
  262. }
  263. if (dt.Rows.Count > 0)
  264. {
  265. for (int i = 0; i < st_table.Items.Count; i++)
  266. {
  267. if (st_table.Items[i].ToString() == dt.Rows[0]["st_table"].ToString())
  268. {
  269. st_table.SelectedItem = st_table.Items[i];
  270. }
  271. }
  272. Receive.Enabled = true;
  273. if (dt.Rows[0]["st_usestatus"].ToString() == "报废")
  274. {
  275. MessageBox.Show("钢网编号" + SU_DEVCODE.Text + "已报废");
  276. }
  277. }
  278. }
  279. }
  280. private void SU_DEVCODE1_KeyDown(object sender, KeyEventArgs e)
  281. {
  282. if (e.KeyCode == Keys.Enter)
  283. {
  284. DataTable dt = (DataTable)dh.ExecuteSql("select 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");
  285. if (dt.Rows.Count > 0)
  286. {
  287. try
  288. {
  289. st_combinenumber.Text = (Math.Ceiling(decimal.Parse(ma_qty.Text) / decimal.Parse(dt.Rows[0][0].ToString()))).ToString();
  290. }
  291. catch (Exception)
  292. {
  293. }
  294. }
  295. else
  296. {
  297. MessageBox.Show("钢网编号" + SU_DEVCODE1.Text + "不存在或者未审核");
  298. }
  299. }
  300. }
  301. private void ma_code_TextKeyDown(object sender, KeyEventArgs e)
  302. {
  303. if (e.KeyCode == Keys.Enter)
  304. {
  305. Confirm.PerformClick();
  306. }
  307. }
  308. }
  309. }