Make_StepReport.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. namespace UAS_MES_NEW.Make
  11. {
  12. public partial class Make_StepReport : Form
  13. {
  14. AutoSizeFormClass asc = new AutoSizeFormClass();
  15. DataHelper dh;
  16. DataTable dt;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. DataTable Dbfind;
  19. string ma_id;
  20. //上一次查询的工单号
  21. string last_macoe = "";
  22. string craftcode_condition = "";
  23. public Make_StepReport()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Make_PositionStock_Load(object sender, EventArgs e)
  28. {
  29. asc.controllInitializeSize(this);
  30. ma_code.TableName = "make left join product on ma_prodcode=pr_code ";
  31. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,pr_orispeccode # 型号,ma_qty # 工单数量, ma_wccode # 车间,ma_inqty # 投入数,ma_craftcode # 工艺路线";
  32. ma_code.FormName = Name;
  33. ma_code.DBTitle = "工单查询";
  34. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_orispeccode", "ma_craftcode", "ma_qty" };
  35. ma_code.Condition = "ma_statuscode='STARTED'";
  36. ma_code.DbChange += Ma_code_DbChange;
  37. sc_stepcode.Text = User.CurrentStepCode;
  38. ma_code.SetLockCheckBox(Lock);
  39. Lock.GetMakeCodeCtl(ma_code);
  40. dh = SystemInf.dh;
  41. }
  42. private void Ma_code_DbChange(object sender, EventArgs e)
  43. {
  44. Dbfind = ma_code.ReturnData;
  45. BaseUtil.SetFormValue(this.Controls, Dbfind);
  46. FillDataGridView();
  47. }
  48. private void Make_PositionStock_SizeChanged(object sender, EventArgs e)
  49. {
  50. asc.controlAutoSize(this);
  51. }
  52. private void Clean_Click(object sender, EventArgs e)
  53. {
  54. OperateResult.Clear();
  55. }
  56. //物料批号Enter事件
  57. private void pr_batchnum_KeyDown(object sender, KeyEventArgs e)
  58. {
  59. }
  60. //加载Grid数据
  61. private void FillDataGridView()
  62. {
  63. sql.Clear();
  64. sql.Append("select ms_id,ms_makecode,ms_prodcode,ms_stepcode,ms_linecode,ms_sourcecode,ms_man,ms_indate,ms_okqty,ms_ngqty,ms_agokqty,ms_failqty from MES_STEPREPORT ");
  65. sql.Append("where ms_makecode = '"+ma_code.Text+"' and ms_stepcode = '"+User.CurrentStepCode+"' and ms_status = 0 order by ms_id desc");
  66. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  67. BaseUtil.FillDgvWithDataTable(BatchProductDGV56, dt);
  68. sql.Clear();
  69. sql.Append("select sum(ms_okqty)oksum,sum(ms_agokqty) agoksum,sum(ms_ngqty)ngsum,sum(ms_failqty)failsum from MES_STEPREPORT ");
  70. sql.Append("where ms_makecode = '" + ma_code.Text + "' and ms_stepcode = '" + User.CurrentStepCode + "' and ms_status = 0");
  71. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  72. BaseUtil.SetFormValue(this.Controls, dt);
  73. }
  74. private void Confirm_Click(object sender, EventArgs e)
  75. {
  76. pr_batchnum_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  77. }
  78. private void Screen_Click(object sender, EventArgs e)
  79. {
  80. FillDataGridView();
  81. }
  82. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  83. {
  84. if (ma_code.Text != "")
  85. {
  86. dt = (DataTable)dh.ExecuteSql("select ma_id,ma_craftcode,ma_statuscode,ma_code,ma_prodcode,pr_spec,pr_detail,ma_bomversion from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  87. if (dt.Rows.Count > 0)
  88. {
  89. ma_id = dt.Rows[0]["ma_id"].ToString();
  90. string craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  91. BaseUtil.SetFormValue(this.Controls, dt);
  92. }
  93. else OperateResult.AppendText(">>工单号不存在\n", Color.Red);
  94. }
  95. else OperateResult.AppendText(">>工单号不允许为空\n", Color.Red);
  96. }
  97. private void BatchProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
  98. {
  99. if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "DeleteRow")
  100. {
  101. if (e.RowIndex >= 0)
  102. {
  103. string id = BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString();
  104. if (id != "0")
  105. {
  106. dh.ExecuteSql("update MES_STEPREPORT set ms_status =-1 where ms_id='" + id + "'", "delete");
  107. dh.ExecuteSql("update MES_STEPREPORTFAIL set msf_status = -1 where msf_msid = '" + id + "'", "update");
  108. dh.ExecuteSql("update MES_STEPREPORTdet set msd_status = -1 where msd_msid = '" + id + "'", "update");
  109. DataTable dt = (DataTable)dh.ExecuteSql("select cm_id,cm_barcode,cm_inqty from craftmaterial where cm_msid = " + id + "", "select");
  110. for (int i = 0; i < dt.Rows.Count; i++)
  111. {
  112. dh.UpdateByCondition("craftmaterial","cm_status =-1","cm_id = "+dt.Rows[i]["cm_id"].ToString() +"");
  113. dh.UpdateByCondition("makesourcestock", "mss_remain =mss_remain+"+ dt.Rows[i]["cm_inqty"].ToString() + ",mss_useqty = mss_useqty-" + dt.Rows[i]["cm_inqty"].ToString() + "", "mss_barcode = '" + dt.Rows[i]["cm_barcode"].ToString() + "'");
  114. dh.UpdateByCondition("barcode", "bar_remain =bar_remain+" + dt.Rows[i]["cm_inqty"].ToString() + "", "bar_code = '" + dt.Rows[i]["cm_barcode"].ToString() + "'");
  115. }
  116. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "工序报工", "删除记录" + id, "", "");
  117. OperateResult.AppendText(">>报工记录删除成功\n",Color.Green);
  118. FillDataGridView();
  119. }
  120. }
  121. }
  122. if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "AddBad")
  123. {
  124. if (e.RowIndex >= 0)
  125. {
  126. string id = BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString();
  127. double ngqty = double.Parse(BatchProductDGV56.Rows[e.RowIndex].Cells["ms_ngqty"].Value.ToString());
  128. if (ma_code.Text == "" || ngqty == 0)
  129. {
  130. OperateResult.AppendText(">>工单号与不良不允许为空\n", Color.Red);
  131. }
  132. else
  133. {
  134. Make_StepReportDetail badcode = new Make_StepReportDetail(id, ngqty,ma_code.Text);
  135. BaseUtil.SetFormCenter(badcode);
  136. badcode.ShowDialog();
  137. }
  138. }
  139. }
  140. if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "AddFail")
  141. {
  142. if (e.RowIndex >= 0)
  143. {
  144. string id = BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString();
  145. double failqty = double.Parse(BatchProductDGV56.Rows[e.RowIndex].Cells["ms_failqty"].Value.ToString());
  146. if (ma_code.Text == "" || failqty == 0)
  147. {
  148. OperateResult.AppendText(">>工单号与报废不允许为空\n", Color.Red);
  149. }
  150. else
  151. {
  152. Make_StepReportDetailFail badcode = new Make_StepReportDetailFail(id, failqty, ma_code.Text);
  153. BaseUtil.SetFormCenter(badcode);
  154. badcode.ShowDialog();
  155. }
  156. }
  157. }
  158. }
  159. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  160. {
  161. if (ma_code.Text.Length > 4)
  162. {
  163. string ErrMessage = "";
  164. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  165. {
  166. craftcode_condition = "";
  167. DataTable dt = (DataTable)dh.ExecuteSql("select ma_craftcode from make where ma_code='" + ma_code.Text + "'", "select");
  168. string craftcode = "";
  169. if (dt.Rows.Count > 0)
  170. {
  171. craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  172. }
  173. sql.Clear();
  174. sql.Append("select distinct ms_craftcode ma_craftcode from makeserial left join craft on cr_code=ms_craftcode ");
  175. sql.Append("where ms_makecode='" + ma_code.Text + "' and ms_craftcode<>'" + craftcode + "'");
  176. dt.Merge((DataTable)dh.ExecuteSql(sql.GetString(), "select"));
  177. ma_craftcode.DisplayMember = "ma_craftcode";
  178. ma_craftcode.ValueMember = "ma_craftcode";
  179. ma_craftcode.DataSource = dt;
  180. for (int i = 0; i < dt.Rows.Count; i++)
  181. {
  182. if (dt.Rows.Count - 1 == i)
  183. craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "'";
  184. else
  185. craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "',";
  186. }
  187. }
  188. }
  189. }
  190. private void BatchProductDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  191. {
  192. }
  193. private void BatchProductDGV_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  194. {
  195. if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "DeleteRow")
  196. {
  197. if (BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString() == "0")
  198. e.Value = Properties.Resources.WhiteImage;
  199. else
  200. e.Value = Properties.Resources.bindingNavigatorDeleteItem_Image;
  201. }
  202. }
  203. private void ma_craftcode_SelectedIndexChanged(object sender, EventArgs e)
  204. {
  205. Screen.PerformClick();
  206. }
  207. private void BatchProductDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  208. {
  209. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  210. if (e.ColumnIndex > 0)
  211. {
  212. if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "mss_remain")
  213. {
  214. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  215. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  216. Rectangle border = e.CellBounds;
  217. border.Width -= 1;
  218. e.Graphics.DrawRectangle(Pens.White, border);
  219. e.PaintContent(e.CellBounds);
  220. e.Handled = true;
  221. }
  222. }
  223. }
  224. private void normalButton1_Click(object sender, EventArgs e)
  225. {
  226. }
  227. private void normalButton2_Click(object sender, EventArgs e)
  228. {
  229. if (okqty.Text == "" && ngqty.Text == ""&&agokqty.Text == "" && failqty.Text == "")
  230. {
  231. OperateResult.AppendText(">>录入信息不可为空\n", Color.Green);
  232. return;
  233. }
  234. if (!dh.CheckExist("step", "st_code ='" + User.CurrentStepCode + "' and st_ifoutline = -1"))
  235. {
  236. OperateResult.AppendText(">>工序"+User.CurrentStepCode+"不允许在此界面采集\n", Color.Red);
  237. return;
  238. }
  239. int ok = int.Parse(okqty.Text == "" ? "0" : okqty.Text);
  240. int ng = int.Parse(ngqty.Text == "" ? "0" : ngqty.Text);
  241. int agok = int.Parse(agokqty.Text == "" ? "0" : agokqty.Text);
  242. int fail = int.Parse(failqty.Text == "" ? "0" : failqty.Text);
  243. int inagsum = int.Parse(agoksum.Text == "" ? "0" : agoksum.Text);
  244. int inngsum = int.Parse(ngsum.Text == "" ? "0" : ngsum.Text);
  245. if (agok + inagsum > inngsum)
  246. {
  247. OperateResult.AppendText(">>再次通过数:"+agok+"+已采集再次通过数:"+inagsum+"大于不良数:"+inngsum+",无法采集\n", Color.Red);
  248. return;
  249. }
  250. string msid = dh.GetSEQ("MES_STEPREPORT_seq");
  251. if (dh.CheckExist("step", "st_code ='" + User.CurrentStepCode + "' and st_ifinput = -1"))
  252. {
  253. DataTable dt;
  254. DataTable dta;
  255. DataTable dtb;
  256. sql.Clear();
  257. sql.Append(" select wm_concat(mm_prodcode)mm_prodcode,count(1)cn from (select MAX(mm_oneuseqty) baseqty,mm_prodcode from make left join makematerial on mm_maid=ma_id left join Product on mm_prodcode=pr_code ");
  258. sql.Append(" where ma_prodcode='"+ma_prodcode.Text+"' and ma_code='"+ma_code.Text+"' and pr_mncode='"+User.CurrentStepCode+ "'and mm_oneuseqty>0 GROUP BY mm_prodcode) B left join ");
  259. sql.Append(" (select sum(nvl(mss_remain,0))remain,mss_fprodcode from makesourcestock where mss_linecode='"+User.UserLineCode+"' and mss_stepcode='" + User.CurrentStepCode + "' and mss_makecode = '"+ma_code.Text+"' group by mss_fprodcode)A ");
  260. sql.Append(" on mm_prodcode=mss_fprodcode where (nvl(mss_fprodcode,' ')=' ' or A.remain<b.baseqty*"+(ok+ng)+") AND rownum<20 ");
  261. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  262. if (int.Parse(dt.Rows[0]["cn"].ToString()) > 0)
  263. {
  264. OperateResult.AppendText(">>批次物料" + dt.Rows[0]["mm_prodcode"].ToString() + "备料不足\n", Color.Red);
  265. return;
  266. }
  267. sql.Clear();
  268. sql.Append(" SELECT mss_fprodcode,max(mss_baseqty)*"+(ok+ng)+ " baseqty,count(1)cn FROM makesourcestock where mss_linecode='" + User.UserLineCode + "' ");
  269. sql.Append(" and mss_stepcode='" + User.CurrentStepCode + "' and mss_makecode = '" + ma_code.Text + "' and exists (select 1 from make left join makematerial on mm_maid=ma_id left join Product on mm_prodcode=pr_code where ma_prodcode='" + ma_prodcode.Text + "' and ma_code='" + ma_code.Text + "' and pr_mncode='" + User.CurrentStepCode + "' and mss_fprodcode=mm_prodcode) ");
  270. sql.Append(" and mss_remain>0 group by mss_fprodcode ");
  271. dta = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  272. for (int i = 0; i < dta.Rows.Count; i++)
  273. {
  274. double baseqty = double.Parse(dta.Rows[i]["baseqty"].ToString());
  275. sql.Clear();
  276. sql.Append(" select mss_id,mss_remain,mss_barcode,mss_prodcode,mss_baseqty from makesourcestock where mss_linecode='" + User.UserLineCode + "' AND mss_stepcode='" + User.CurrentStepCode + "' and mss_makecode = '" + ma_code.Text + "' ");
  277. sql.Append(" and mss_fprodcode='"+dta.Rows[i]["mss_fprodcode"].ToString() +"' AND mss_invalidtime is null order by mss_id asc ");
  278. dtb = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  279. for (int j = 0; j < dtb.Rows.Count; j++)
  280. {
  281. if (baseqty > 0)
  282. {
  283. double v_v_useqty = 0;
  284. if (double.Parse(dtb.Rows[j]["mss_remain"].ToString()) >= baseqty || j == dtb.Rows.Count - 1)
  285. {
  286. v_v_useqty = baseqty;
  287. baseqty = 0;
  288. dh.UpdateByCondition("makesourcestock", "mss_remain= mss_remain - " + v_v_useqty + ",mss_useqty=NVL(mss_useqty,0)+" + v_v_useqty + ",mss_madeqty=NVL(mss_madeqty,0)+ceil(" + v_v_useqty + "/" + double.Parse(dtb.Rows[j]["mss_baseqty"].ToString()) + "),mss_validtime=(case when mss_validtime is null then sysdate else mss_validtime end),MSS_UABLE=-1 ", "mss_id=" + dtb.Rows[j]["mss_id"].ToString() + "");
  289. }
  290. else {
  291. v_v_useqty = double.Parse(dtb.Rows[j]["mss_remain"].ToString());
  292. baseqty = baseqty- v_v_useqty;
  293. dh.UpdateByCondition("makesourcestock", "mss_remain= mss_remain - " + v_v_useqty + ",mss_useqty=NVL(mss_useqty,0)+" + v_v_useqty + ",mss_madeqty=NVL(mss_madeqty,0)+ceil(" + v_v_useqty + "/" + double.Parse(dtb.Rows[j]["mss_baseqty"].ToString()) + "),mss_validtime=(case when mss_validtime is null then sysdate else mss_validtime end),MSS_UABLE=-1 ", "mss_id=" + dtb.Rows[j]["mss_id"].ToString() + "");
  294. }
  295. dh.UpdateByCondition("barcode", "bar_remain=bar_remain-"+ v_v_useqty + "", "bar_code='"+ dtb.Rows[j]["mss_barcode"].ToString() + "' and bar_remain>0");
  296. dh.ExecuteSql("insert into craftmaterial(CM_ID,CM_MAKECODE,CM_MAID,CM_MAPRODCODE,CM_STEPCODE,CM_CRAFTCODE,CM_BARCODE,CM_SONCODE,CM_FSONCODE,CM_INQTY,CM_INDATE,CM_INMAN,CM_LINECODE,CM_WCCODE,CM_SOURCECODE,CM_STATUS,CM_MSID) SELECT craftmaterial_seq.nextval,MA_CODE,ma_id,ma_prodcode,'"+User.CurrentStepCode+"', '"+ma_craftcode.Text+"','"+ dtb.Rows[j]["mss_barcode"].ToString() + "','"+ dtb.Rows[j]["mss_prodcode"].ToString() + "','"+ dtb.Rows[j]["mss_prodcode"].ToString() + "',"+ v_v_useqty + ",sysdate,'"+User.UserName+"','"+User.UserLineCode+"','"+User.WorkCenter+"','"+User.UserSourceCode+"',0,'"+ msid + "' FROM MAKE WHERE MA_CODE='"+ma_code.Text+"'", "select");
  297. }
  298. }
  299. }
  300. }
  301. sql.Clear();
  302. sql.Append("insert into MES_STEPREPORT (MS_ID,MS_MAKECODE,MS_PRODCODE ,MS_STEPCODE,");
  303. sql.Append("MS_LINECODE,MS_SOURCECODE,MS_MAN,MS_INDATE,MS_OKQTY,MS_NGQTY,");
  304. sql.Append("MS_REMARK,MS_STATUS,MS_AGOKQTY,MS_FAILQTY) values(" + msid + ",'" + ma_code.Text + "','" + ma_prodcode.Text + "',");
  305. sql.Append("'" +User.CurrentStepCode + "','" + User.UserLineCode + "','" + User.UserSourceCode + "','" + User.UserName + "',");
  306. sql.Append("sysdate,'" + ok + "','" + ng + "','" + Remark.Text + "','" + 0 + "','"+agok+"','"+fail+"')");
  307. dh.ExecuteSql(sql.GetString(), "insert");
  308. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "工序报工", "良品:"+ok+",再次通过:"+agok+",不良品:"+ng+",报废:"+fail+"", "", "");
  309. //数据插入成功后加载Grid的数据
  310. FillDataGridView();
  311. OperateResult.AppendText(">>工单"+ma_code.Text+",良品:" + ok + ",再次通过:" + agok + ",不良品:" + ng + ",报废:"+fail+"报工成功\n", Color.Green, okqty,ngqty,agokqty);
  312. failqty.Text = "";
  313. Remark.Text = "";
  314. }
  315. }
  316. }