123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_StepReport : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- DataTable dt;
- LogStringBuilder sql = new LogStringBuilder();
- DataTable Dbfind;
- string ma_id;
- //上一次查询的工单号
- string last_macoe = "";
- string craftcode_condition = "";
- public Make_StepReport()
- {
- InitializeComponent();
- }
- private void Make_PositionStock_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- ma_code.TableName = "make left join product on ma_prodcode=pr_code ";
- ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,pr_orispeccode # 型号,ma_qty # 工单数量, ma_wccode # 车间,ma_inqty # 投入数,ma_craftcode # 工艺路线";
- ma_code.FormName = Name;
- ma_code.DBTitle = "工单查询";
- ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_orispeccode", "ma_craftcode", "ma_qty" };
- ma_code.Condition = "ma_statuscode='STARTED'";
- ma_code.DbChange += Ma_code_DbChange;
- sc_stepcode.Text = User.CurrentStepCode;
- ma_code.SetLockCheckBox(Lock);
- Lock.GetMakeCodeCtl(ma_code);
- dh = SystemInf.dh;
- }
- private void Ma_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- FillDataGridView();
- }
- private void Make_PositionStock_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- //物料批号Enter事件
- private void pr_batchnum_KeyDown(object sender, KeyEventArgs e)
- {
-
-
- }
- //加载Grid数据
- private void FillDataGridView()
- {
- sql.Clear();
- 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 ");
- sql.Append("where ms_makecode = '"+ma_code.Text+"' and ms_stepcode = '"+User.CurrentStepCode+"' and ms_status = 0 order by ms_id desc");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(BatchProductDGV56, dt);
- sql.Clear();
- sql.Append("select sum(ms_okqty)oksum,sum(ms_agokqty) agoksum,sum(ms_ngqty)ngsum,sum(ms_failqty)failsum from MES_STEPREPORT ");
- sql.Append("where ms_makecode = '" + ma_code.Text + "' and ms_stepcode = '" + User.CurrentStepCode + "' and ms_status = 0");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- private void Confirm_Click(object sender, EventArgs e)
- {
- pr_batchnum_KeyDown(sender, new KeyEventArgs(Keys.Enter));
- }
- private void Screen_Click(object sender, EventArgs e)
- {
- FillDataGridView();
- }
- private void ma_prodcode_TextChanged(object sender, EventArgs e)
- {
- if (ma_code.Text != "")
- {
- 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");
- if (dt.Rows.Count > 0)
- {
- ma_id = dt.Rows[0]["ma_id"].ToString();
- string craftcode = dt.Rows[0]["ma_craftcode"].ToString();
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- else OperateResult.AppendText(">>工单号不存在\n", Color.Red);
- }
- else OperateResult.AppendText(">>工单号不允许为空\n", Color.Red);
- }
- private void BatchProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "DeleteRow")
- {
- if (e.RowIndex >= 0)
- {
- string id = BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString();
- if (id != "0")
- {
- dh.ExecuteSql("update MES_STEPREPORT set ms_status =-1 where ms_id='" + id + "'", "delete");
- dh.ExecuteSql("update MES_STEPREPORTFAIL set msf_status = -1 where msf_msid = '" + id + "'", "update");
- dh.ExecuteSql("update MES_STEPREPORTdet set msd_status = -1 where msd_msid = '" + id + "'", "update");
- DataTable dt = (DataTable)dh.ExecuteSql("select cm_id,cm_barcode,cm_inqty from craftmaterial where cm_msid = " + id + "", "select");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- dh.UpdateByCondition("craftmaterial","cm_status =-1","cm_id = "+dt.Rows[i]["cm_id"].ToString() +"");
- 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() + "'");
- dh.UpdateByCondition("barcode", "bar_remain =bar_remain+" + dt.Rows[i]["cm_inqty"].ToString() + "", "bar_code = '" + dt.Rows[i]["cm_barcode"].ToString() + "'");
- }
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "工序报工", "删除记录" + id, "", "");
- OperateResult.AppendText(">>报工记录删除成功\n",Color.Green);
- FillDataGridView();
- }
- }
- }
- if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "AddBad")
- {
- if (e.RowIndex >= 0)
- {
- string id = BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString();
- double ngqty = double.Parse(BatchProductDGV56.Rows[e.RowIndex].Cells["ms_ngqty"].Value.ToString());
- if (ma_code.Text == "" || ngqty == 0)
- {
- OperateResult.AppendText(">>工单号与不良不允许为空\n", Color.Red);
- }
- else
- {
- Make_StepReportDetail badcode = new Make_StepReportDetail(id, ngqty,ma_code.Text);
- BaseUtil.SetFormCenter(badcode);
- badcode.ShowDialog();
- }
- }
- }
- if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "AddFail")
- {
- if (e.RowIndex >= 0)
- {
- string id = BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString();
- double failqty = double.Parse(BatchProductDGV56.Rows[e.RowIndex].Cells["ms_failqty"].Value.ToString());
- if (ma_code.Text == "" || failqty == 0)
- {
- OperateResult.AppendText(">>工单号与报废不允许为空\n", Color.Red);
- }
- else
- {
- Make_StepReportDetailFail badcode = new Make_StepReportDetailFail(id, failqty, ma_code.Text);
- BaseUtil.SetFormCenter(badcode);
- badcode.ShowDialog();
- }
- }
- }
- }
- private void ma_code_UserControlTextChanged(object sender, EventArgs e)
- {
- if (ma_code.Text.Length > 4)
- {
- string ErrMessage = "";
- if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
- {
- craftcode_condition = "";
- DataTable dt = (DataTable)dh.ExecuteSql("select ma_craftcode from make where ma_code='" + ma_code.Text + "'", "select");
- string craftcode = "";
- if (dt.Rows.Count > 0)
- {
- craftcode = dt.Rows[0]["ma_craftcode"].ToString();
- }
- sql.Clear();
- sql.Append("select distinct ms_craftcode ma_craftcode from makeserial left join craft on cr_code=ms_craftcode ");
- sql.Append("where ms_makecode='" + ma_code.Text + "' and ms_craftcode<>'" + craftcode + "'");
- dt.Merge((DataTable)dh.ExecuteSql(sql.GetString(), "select"));
- ma_craftcode.DisplayMember = "ma_craftcode";
- ma_craftcode.ValueMember = "ma_craftcode";
- ma_craftcode.DataSource = dt;
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows.Count - 1 == i)
- craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "'";
- else
- craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "',";
- }
- }
- }
- }
- private void BatchProductDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- }
- private void BatchProductDGV_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
- {
- if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "DeleteRow")
- {
- if (BatchProductDGV56.Rows[e.RowIndex].Cells["ms_id"].Value.ToString() == "0")
- e.Value = Properties.Resources.WhiteImage;
- else
- e.Value = Properties.Resources.bindingNavigatorDeleteItem_Image;
- }
- }
- private void ma_craftcode_SelectedIndexChanged(object sender, EventArgs e)
- {
- Screen.PerformClick();
- }
- private void BatchProductDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
- {
- bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
- if (e.ColumnIndex > 0)
- {
- if (BatchProductDGV56.Columns[e.ColumnIndex].Name == "mss_remain")
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.White, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- }
- }
-
- private void normalButton1_Click(object sender, EventArgs e)
- {
- }
- private void normalButton2_Click(object sender, EventArgs e)
- {
- if (okqty.Text == "" && ngqty.Text == ""&&agokqty.Text == "" && failqty.Text == "")
- {
- OperateResult.AppendText(">>录入信息不可为空\n", Color.Green);
- return;
- }
- if (!dh.CheckExist("step", "st_code ='" + User.CurrentStepCode + "' and st_ifoutline = -1"))
- {
- OperateResult.AppendText(">>工序"+User.CurrentStepCode+"不允许在此界面采集\n", Color.Red);
- return;
- }
- int ok = int.Parse(okqty.Text == "" ? "0" : okqty.Text);
- int ng = int.Parse(ngqty.Text == "" ? "0" : ngqty.Text);
- int agok = int.Parse(agokqty.Text == "" ? "0" : agokqty.Text);
- int fail = int.Parse(failqty.Text == "" ? "0" : failqty.Text);
- int inagsum = int.Parse(agoksum.Text == "" ? "0" : agoksum.Text);
- int inngsum = int.Parse(ngsum.Text == "" ? "0" : ngsum.Text);
- if (agok + inagsum > inngsum)
- {
- OperateResult.AppendText(">>再次通过数:"+agok+"+已采集再次通过数:"+inagsum+"大于不良数:"+inngsum+",无法采集\n", Color.Red);
- return;
- }
- string msid = dh.GetSEQ("MES_STEPREPORT_seq");
- if (dh.CheckExist("step", "st_code ='" + User.CurrentStepCode + "' and st_ifinput = -1"))
- {
- DataTable dt;
- DataTable dta;
- DataTable dtb;
- sql.Clear();
- 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 ");
- 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 ");
- 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 ");
- sql.Append(" on mm_prodcode=mss_fprodcode where (nvl(mss_fprodcode,' ')=' ' or A.remain<b.baseqty*"+(ok+ng)+") AND rownum<20 ");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (int.Parse(dt.Rows[0]["cn"].ToString()) > 0)
- {
- OperateResult.AppendText(">>批次物料" + dt.Rows[0]["mm_prodcode"].ToString() + "备料不足\n", Color.Red);
- return;
- }
- sql.Clear();
- sql.Append(" SELECT mss_fprodcode,max(mss_baseqty)*"+(ok+ng)+ " baseqty,count(1)cn FROM makesourcestock where mss_linecode='" + User.UserLineCode + "' ");
- 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) ");
- sql.Append(" and mss_remain>0 group by mss_fprodcode ");
- dta = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- for (int i = 0; i < dta.Rows.Count; i++)
- {
- double baseqty = double.Parse(dta.Rows[i]["baseqty"].ToString());
- sql.Clear();
- 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 + "' ");
- sql.Append(" and mss_fprodcode='"+dta.Rows[i]["mss_fprodcode"].ToString() +"' AND mss_invalidtime is null order by mss_id asc ");
- dtb = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- for (int j = 0; j < dtb.Rows.Count; j++)
- {
- if (baseqty > 0)
- {
- double v_v_useqty = 0;
- if (double.Parse(dtb.Rows[j]["mss_remain"].ToString()) >= baseqty || j == dtb.Rows.Count - 1)
- {
- v_v_useqty = baseqty;
- baseqty = 0;
- 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() + "");
- }
- else {
- v_v_useqty = double.Parse(dtb.Rows[j]["mss_remain"].ToString());
- baseqty = baseqty- v_v_useqty;
- 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() + "");
- }
- dh.UpdateByCondition("barcode", "bar_remain=bar_remain-"+ v_v_useqty + "", "bar_code='"+ dtb.Rows[j]["mss_barcode"].ToString() + "' and bar_remain>0");
- 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");
- }
- }
- }
- }
-
- sql.Clear();
- sql.Append("insert into MES_STEPREPORT (MS_ID,MS_MAKECODE,MS_PRODCODE ,MS_STEPCODE,");
- sql.Append("MS_LINECODE,MS_SOURCECODE,MS_MAN,MS_INDATE,MS_OKQTY,MS_NGQTY,");
- sql.Append("MS_REMARK,MS_STATUS,MS_AGOKQTY,MS_FAILQTY) values(" + msid + ",'" + ma_code.Text + "','" + ma_prodcode.Text + "',");
- sql.Append("'" +User.CurrentStepCode + "','" + User.UserLineCode + "','" + User.UserSourceCode + "','" + User.UserName + "',");
- sql.Append("sysdate,'" + ok + "','" + ng + "','" + Remark.Text + "','" + 0 + "','"+agok+"','"+fail+"')");
- dh.ExecuteSql(sql.GetString(), "insert");
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "工序报工", "良品:"+ok+",再次通过:"+agok+",不良品:"+ng+",报废:"+fail+"", "", "");
- //数据插入成功后加载Grid的数据
- FillDataGridView();
- OperateResult.AppendText(">>工单"+ma_code.Text+",良品:" + ok + ",再次通过:" + agok + ",不良品:" + ng + ",报废:"+fail+"报工成功\n", Color.Green, okqty,ngqty,agokqty);
- failqty.Text = "";
- Remark.Text = "";
- }
- }
- }
|