Make_PositionStock.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES.DataOperate;
  7. using UAS_MES.Entity;
  8. using UAS_MES.PublicMethod;
  9. namespace UAS_MES.Make
  10. {
  11. public partial class Make_PositionStock : Form
  12. {
  13. AutoSizeFormClass asc = new AutoSizeFormClass();
  14. DataHelper dh;
  15. DataTable dt;
  16. LogStringBuilder sql = new LogStringBuilder();
  17. DataTable Dbfind;
  18. string ma_id;
  19. public Make_PositionStock()
  20. {
  21. InitializeComponent();
  22. }
  23. private void 岗位备料_Load(object sender, EventArgs e)
  24. {
  25. dh = new DataHelper();
  26. asc.controllInitializeSize(this);
  27. ma_code.TableName = "make left join product on ma_prodcode=pr_code ";
  28. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_craftcode # 工艺路线,pr_detail # 产品名称";
  29. ma_code.FormName = Name;
  30. ma_code.DBTitle = "工单查询";
  31. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_detail", "ma_craftcode" };
  32. ma_code.Condition = "ma_statuscode='STARTED'";
  33. ma_code.DbChange += Ma_code_DbChange;
  34. sc_linecode.Text = User.UserLineCode;
  35. sc_stepcode.Text = User.CurrentStepCode;
  36. }
  37. private void Ma_code_DbChange(object sender, EventArgs e)
  38. {
  39. Dbfind = ma_code.ReturnData;
  40. BaseUtil.SetFormValue(this.Controls, Dbfind);
  41. }
  42. private void 岗位备料_SizeChanged(object sender, EventArgs e)
  43. {
  44. asc.controlAutoSize(this);
  45. }
  46. private void Clean_Click(object sender, EventArgs e)
  47. {
  48. OperateResult.Clear();
  49. }
  50. //物料批号Enter事件
  51. private void pr_batchnum_KeyDown(object sender, KeyEventArgs e)
  52. {
  53. if (e.KeyCode == Keys.Enter)
  54. {
  55. if (pr_batchnum.Text != "")
  56. {
  57. if (ma_code.Text != "")
  58. {
  59. dt = (DataTable)dh.ExecuteSql("select bar_remain,bar_prodcode from barcode inner join product on pr_code=bar_prodcode where bar_code ='" + pr_batchnum.Text + "' and bar_status = 1 ", "select");
  60. if (dt.Rows.Count > 0)
  61. {
  62. string bar_remain = dt.Rows[0]["bar_remain"].ToString();
  63. string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  64. sql.Clear();
  65. sql.Append("select * from stepproduct inner join product on pr_code=sp_soncode left join makematerial on mm_prodcode=sp_soncode where ");
  66. sql.Append("sp_craftcode='" + ma_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode+"' and sp_mothercode='"+ bar_prodcode + "' and pr_tracekind=2 ");
  67. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  68. if (dt.Rows.Count > 0)
  69. {
  70. string mm_oneuseqty = dt.Rows[0]["mm_oneuseqty"].ToString();
  71. string mm_prodcode = dt.Rows[0]["mm_prodcode"].ToString();
  72. if (dh.getRowCount("makesourcestock", "mss_makecode='" + ma_code.Text + "' and mss_prodcode='" + mm_prodcode + "' and mss_barcode='" + pr_batchnum.Text + "'") == 0)
  73. {
  74. sql.Clear();
  75. sql.Append("insert into makesourcestock (mss_id,mss_makecode,mss_linecode ,mss_craftcode,");
  76. sql.Append("mss_stepcode,mss_barcode,mss_fprodcode,mss_indate,mss_inman,mss_qty,");
  77. sql.Append("mss_remain ,mss_baseqty ,mss_prodcode,mss_maid) values(makesourcestock_seq.nextval,'" + ma_code.Text + "','" + sc_linecode.Text + "',");
  78. sql.Append("'" + ma_craftcode.Text + "','" + sc_stepcode.Text + "','" + pr_batchnum.Text + "','" + mm_prodcode + "',");
  79. sql.Append("sysdate,'" + User.UserName + "'," + bar_remain + "," + bar_remain + ",'" + mm_oneuseqty + "','" + bar_prodcode + "'," + ma_id + ")");
  80. dh.ExecuteSql(sql.GetString(), "insert");
  81. dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + pr_batchnum.Text + "'");
  82. //数据插入成功后加载Grid的数据
  83. FillDataGridView();
  84. OperateResult.AppendText(">>批次号" + pr_batchnum.Text + "备料成功\n", Color.Green, pr_batchnum);
  85. }
  86. else OperateResult.AppendText(">>批次号" + pr_batchnum.Text + "的物料已分配\n", Color.Red, pr_batchnum);
  87. }
  88. else OperateResult.AppendText(">>批次" + pr_batchnum.Text + "对应的物料不是当前工单当前工序需要备的物料\n", Color.Red, pr_batchnum);
  89. }
  90. else OperateResult.AppendText(">>批号:" + pr_batchnum.Text + "不存在,或者状态无效\n", Color.Red, pr_batchnum);
  91. }
  92. else OperateResult.AppendText(">>工单号不能为空\n", Color.Red, pr_batchnum);
  93. }
  94. else OperateResult.AppendText(">>物料批号不允许为空\n", Color.Red);
  95. }
  96. }
  97. //加载Grid数据
  98. private void FillDataGridView()
  99. {
  100. sql.Clear();
  101. sql.Append("select mm_prodcode,mss_baseqty,mss_prodcode,mss_barcode,nvl(mss_qty,0) mss_qty,mss_remain");
  102. sql.Append(",mm_qty,pr_detail,pr_spec from makematerial left join product on pr_code=mm_prodcode left join makesourcestock on ");
  103. sql.Append("mss_maid=mm_maid and mss_stepcode = mm_stepcode and mm_prodcode=mss_fprodcode ");
  104. sql.Append("where mm_maid='" + ma_id + "' and mm_stepcode='" + sc_stepcode.Text + "' and pr_tracekind=2");
  105. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  106. BaseUtil.FillDgvWithDataTable(BatchProduct, dt);
  107. }
  108. private void Confirm_Click(object sender, EventArgs e)
  109. {
  110. KeyEventArgs e1 = new KeyEventArgs(Keys.Enter);
  111. pr_batchnum_KeyDown(sender, e1);
  112. }
  113. private void Screen_Click(object sender, EventArgs e)
  114. {
  115. FillDataGridView();
  116. }
  117. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  118. {
  119. if (ma_code.Text != "")
  120. {
  121. dt = (DataTable)dh.ExecuteSql("select ma_id,ma_craftcode,ma_statuscode,ma_code,ma_prodcode,pr_spec,pr_detail from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  122. //查询工单号是否存在
  123. if (dt.Rows.Count > 0)
  124. {
  125. ma_id = dt.Rows[0]["ma_id"].ToString();
  126. string craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  127. BaseUtil.SetFormValue(this.Controls, dt);
  128. //必须是已下放的工单才允许进行岗位备料
  129. if (dt.Rows[0]["ma_statuscode"].ToString() == "STARTED")
  130. {
  131. //判断当前用户的执行工序和岗位资源是否对应
  132. sql.Clear();
  133. sql.Append("select sp_soncode,mm_oneuseqty,mss_prodcode,mss_barcode,nvl(mss_qty,0)mss_qty,mss_remain,mm_qty,pr_detail,pr_spec ");
  134. sql.Append("from stepproduct inner join makematerial on sp_soncode=mm_Prodcode left join product on pr_code=mm_prodcode left join ");
  135. sql.Append("makesourcestock on mss_maid=mm_maid and mss_stepcode=mm_stepcode and mm_prodcode=mss_fprodcode where ");
  136. sql.Append("mm_maid='" + ma_id + "' and sp_mothercode='" + ma_prodcode.Text + "' and sp_craftcode='" + ma_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and pr_tracekind=2");
  137. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  138. //查询到有记录的话表示对应
  139. if (dt.Rows.Count > 0)
  140. FillDataGridView();
  141. //查询到没有结果表示不对应
  142. else OperateResult.AppendText(">>当前工单物料无需备料\n", Color.Red);
  143. }
  144. else OperateResult.AppendText(">>必须状态为已下放的工单才允许进行岗位备料\n", Color.Red);
  145. }
  146. else OperateResult.AppendText(">>工单号不存在\n", Color.Red);
  147. }
  148. else OperateResult.AppendText(">>工单号不允许为空\n", Color.Red);
  149. }
  150. }
  151. }