| | |
| | | } |
| | | // --------------查询指定数据-------------- |
| | | var total = 0; //总条数 |
| | | var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.plan_qty,A.wkshp_code,C.torg_name as wkshp_name, |
| | | var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.route_code,R.name as route_name,A.plan_qty,A.wkshp_code,C.torg_name as wkshp_name, |
| | | A.stck_code,D.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,A.saleOrderDeliveryDate,W.saleOrderCode,U.username as lm_user,A.lm_date,A.data_sources,A.isstep,A.clerkuser |
| | | from TK_Wrk_Man A |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code and A.sbid=W.sbid |
| | |
| | | left join TSecStck D on A.stck_code=D.code |
| | | left join TUser U on A.lm_user=U.usercode |
| | | left join TOrganization L on C.parent_id=L.id |
| | | left join TFlw_Rout R on A.route_code=R.code |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | |
| | | if (data_sources == "ERP") //数据来源ERP |
| | | { |
| | | //查询订单任务总数 |
| | | sql = @"select qty from TKimp_Ewo where id=@sourceid and wo=@sourcewo"; |
| | | sql = @"select qty,relse_qty from TKimp_Ewo where id=@sourceid and wo=@sourcewo"; |
| | | dynamicParams.Add("@sourceid", sourceid); |
| | | dynamicParams.Add("@sourcewo", sourcewo); |
| | | dynamicParams.Add("@wocode", wocode); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | //查询当前工单可修改数量=订单总数-已下达工单总数 |
| | | sql = @"select isnull(sum(plan_qty),0) as plan_qty from TK_Wrk_Man |
| | |
| | | #region[MES工单新增、编辑提交] |
| | | public static ToMessage AddUpdateMesOrder(string operType, WorkList json, User us) |
| | | { |
| | | string sql = ""; |
| | | string sql = "", route_code = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | List<object> list = new List<object>(); |
| | | try |
| | | { |
| | | dynamic dynObj = JObject.Parse(us.mesSetting); |
| | | bool route = dynObj.route; |
| | | if (route) //工艺路线版 |
| | | { |
| | | route_code = json.routecode; |
| | | } |
| | | else //工序版 |
| | | { |
| | | route_code = null; |
| | | } |
| | | if (operType == "Add") |
| | | { |
| | | //写入工单表 |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,lm_user,lm_date,materiel_code,sourceid,m_po,saleOrderDeliveryDate,plan_startdate,plan_enddate,piroque,isaps,data_sources,isstep) |
| | | values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@lm_user,@lm_date,@materiel_code,@sourceid,@m_po,@saleOrderDeliveryDate,@plan_startdate,@plan_enddate,@orderlev,@isaps,@data_sources,@isstep)"; |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,lm_user,lm_date,materiel_code,route_code,sourceid,m_po,saleOrderDeliveryDate,plan_startdate,plan_enddate,piroque,isaps,data_sources,isstep) |
| | | values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@lm_user,@lm_date,@materiel_code,@route_code,@sourceid,@m_po,@saleOrderDeliveryDate,@plan_startdate,@plan_enddate,@orderlev,@isaps,@data_sources,@isstep)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString(), |
| | | materiel_code = json.partcode, |
| | | route_code = route_code, |
| | | sourceid = json.sourceid == "" ? null : json.sourceid, //无源单时赋值NULL |
| | | m_po = json.sourcewo, |
| | | saleOrderDeliveryDate = json.deliverydate, |
| | |
| | | //写入工序任务表 |
| | | for (int i = 0; i < json.WorkListSub.Count; i++) |
| | | { |
| | | sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date) |
| | | values(@wo_code,@seq,@step_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)"; |
| | | sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,route_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date) |
| | | values(@wo_code,@seq,@step_code,@route_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | wo_code = json.wocode, |
| | | seq = json.WorkListSub[i].stepseq, |
| | | step_code = json.WorkListSub[i].stepcode, |
| | | route_code = route_code, |
| | | stepprice = json.WorkListSub[i].stepprice, |
| | | plan_qty = json.woqty, |
| | | status = json.wostatus, |
| | |
| | | { |
| | | //修改工单表 |
| | | sql = @"update TK_Wrk_Man set wotype=@wotype,wkshp_code=@wkshp_code,plan_qty=@plan_qty,lm_user=@lm_user,lm_date=@lm_date, |
| | | materiel_code=@materiel_code,sourceid=@sourceid,m_po=@m_po,saleOrderDeliveryDate=@saleOrderDeliveryDate,plan_startdate=@plan_startdate,plan_enddate=@plan_enddate,isstep=@isstep |
| | | materiel_code=@materiel_code,route_code=@route_code,sourceid=@sourceid,m_po=@m_po,saleOrderDeliveryDate=@saleOrderDeliveryDate,plan_startdate=@plan_startdate,plan_enddate=@plan_enddate,isstep=@isstep |
| | | where wo_code=@wo_code"; |
| | | list.Add(new |
| | | { |
| | |
| | | wkshp_code = json.wkshopcode, |
| | | plan_qty = json.woqty, |
| | | materiel_code = json.partcode, |
| | | route_code = route_code, |
| | | sourceid = json.sourceid == "" ? null : json.sourceid, //无源单时赋值NULL |
| | | m_po = json.sourcewo, |
| | | saleOrderDeliveryDate = json.deliverydate, |
| | |
| | | //写入工单工序表 |
| | | for (int i = 0; i < json.WorkListSub.Count; i++) |
| | | { |
| | | sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date) |
| | | values(@wo_code,@seq,@step_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)"; |
| | | sql = @"insert into TK_Wrk_Step(wo_code,seq,step_code,route_code,stepprice,plan_qty,status,isbott,isend,lm_user,lm_date) |
| | | values(@wo_code,@seq,@step_code,@route_code,@stepprice,@plan_qty,@status,@isbott,@isend,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | wo_code = json.wocode, |
| | | seq = json.WorkListSub[i].stepseq, |
| | | step_code = json.WorkListSub[i].stepcode, |
| | | route_code = route_code, |
| | | stepprice = json.WorkListSub[i].stepprice, |
| | | plan_qty = json.woqty, |
| | | status = json.wostatus, |
| | |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | //判断源头单据是否来源ERP |
| | | if (json.data_sources == "ERP") |
| | | { |
| | | //判断工单修改数量差值是否为0 |
| | | if (json.difference != "0") |
| | | { |
| | | string staus = ""; |
| | | //查询订单总数,已下达数量 |
| | | sql = @"select qty,relse_qty from TKimp_Ewo where id=@sourceid and wo=@sourcewo"; |
| | | dynamicParams.Add("@sourceid", json.sourceid); |
| | | dynamicParams.Add("@sourcewo", json.sourcewo); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | //当前工单可修改数量=订单数量-非当前工单总下达工单数量 |
| | | decimal qty = decimal.Parse(data0.Rows[0]["qty"].ToString());//订单总数 |
| | | decimal relse_qty = decimal.Parse(data0.Rows[0]["relse_qty"].ToString());//订单已下达总数 |
| | | relse_qty = relse_qty + decimal.Parse(json.difference);//新的下达数量=原始下达数量+差值(正负) |
| | | if (qty == relse_qty) |
| | | { |
| | | staus = "CREATED"; //全部下达 |
| | | } |
| | | else |
| | | { |
| | | staus = "CREATING";//部分下达 |
| | | } |
| | | //更新订单表状态、已下达数量 |
| | | sql = @"update TKimp_Ewo set status=@status,relse_qty=@relse_qty where id=@sourceid and wo=@sourcewo"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | status = staus, |
| | | relse_qty = relse_qty, |
| | | sourceid = json.sourceid, |
| | | sourcewo = json.sourcewo |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | |
| | | #endregion |
| | | |
| | | #region[MES工单查找历史引用最新工序信息] |
| | | public static ToMessage MesOrderNewStepContent(string wkshopcode, string partcode, User us) |
| | | public static ToMessage MesOrderNewStepContent(string wkshopcode, string routecode, string partcode, User us) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | dynamic dynObj = JObject.Parse(us.mesSetting); |
| | | bool route = dynObj.route; |
| | | if (route) //工艺路线版 |
| | | { |
| | | //MES工单查找历史引用最新工序信息 |
| | | sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend |
| | | from TK_Wrk_Step S |
| | | inner join ( |
| | | select top 1 A.wo_code,A.route_code from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.route_code=S.route_code |
| | | where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode and A.route_code=@routecode |
| | | order by A.lm_date desc |
| | | ) as W on S.wo_code=W.wo_code and S.route_code=W.route_code |
| | | left join TStep T on S.step_code=T.stepcode |
| | | order by S.seq"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@routecode", routecode); |
| | | } |
| | | else |
| | | { |
| | | //MES工单查找历史引用最新工序信息 |
| | | sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend |
| | |
| | | order by S.seq"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@partcode", partcode); |
| | | } |
| | | |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.count = data.Rows.Count; |
| | |
| | | #endregion |
| | | |
| | | #region [生产开报工:报工/外协(发料/收料)时条件判断及数据返回接口] |
| | | public static ToMessage MesOrderStepStart(string OperType, string SelectType, string wocode, string stepcode) |
| | | public static ToMessage MesOrderStepStart(string OperType, string SelectType, string wocode, string stepcode, User us) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | dynamic dynObj = JObject.Parse(us.mesSetting); |
| | | bool isOrder = dynObj.isOrder; |
| | | switch (OperType) |
| | | { |
| | | case "ZZ": |
| | | if (isOrder) //按序生产 |
| | | { |
| | | mes = ScanStartReport.ZZEncodingSeach(wocode, stepcode); |
| | | } |
| | | else //不按序生产 |
| | | { |
| | | mes = ScanStartReport.NoZZEncodingSeach(wocode, stepcode); |
| | | } |
| | | break; |
| | | case "WX": |
| | | if (isOrder) //按序收发料 |
| | | { |
| | | mes = ScanStartReport.WXEncodingSeach(SelectType, wocode, stepcode); |
| | | } |
| | | else //不按序收发料 |
| | | { |
| | | mes = ScanStartReport.NoWXEncodingSeach(SelectType, wocode, stepcode); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | dynamic dynObj = JObject.Parse(us.mesSetting); |
| | | bool isOrder = dynObj.isOrder; |
| | | //获取此次报工调整提交的数据(合格数量、不良数量、工废数量、料废数量) |
| | | decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //报工数量(合格) |
| | | decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总 |
| | | decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总 |
| | | decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总 |
| | | decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总 |
| | | decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总 |
| | | decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总 |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | if (isOrder) //按序 |
| | | { |
| | | //控制逻辑:首道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>任务数量 ==不能大于任务数量 |
| | | //控制逻辑:首道工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废) ==不能小于下道报工总数 |
| | | //控制逻辑:末道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数 ==不能大于上道工序报工合格总数 |
| | | //控制逻辑:中间工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数 ==不能大于上道工序报工合格总数 |
| | | //控制逻辑:中间工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废) ==不能小于下道报工总数 |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | |
| | | |
| | | list.Clear(); |
| | | //获取当前工序上道工序及属性 |
| | | sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A |
| | |
| | | //判断当前工序是自制工序还是外协工序 |
| | | if (json[0].flw_type.ToString() == "Z")//自制工序 |
| | | { |
| | | //获取此次报工调整提交的数据(合格数量、不良数量、工废数量、料废数量) |
| | | decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //报工数量(合格) |
| | | decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总 |
| | | decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总 |
| | | decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总 |
| | | decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总 |
| | | decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总 |
| | | decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总 |
| | | //首道工序的报工 |
| | | if (json[0].first_choke == "Y") |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (json[0].flw_type.ToString() == "W")//外协工序 |
| | | { |
| | | //查询当前首道工序非此次供应商收料:总收料数量 |
| | | sql = @"select isnull(sum(sqty),0) as sqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code<>@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_c = DapperHelper.selectdata(sql, dynamicParams); |
| | | |
| | | //获取当前工序、供应商对应的发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as fqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | //首道工序的收料 |
| | | if (json[0].first_choke == "Y") |
| | | { |
| | | //查询当前首道工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前外协工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前外协工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次收料数+本次报工调整收料数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前外协工序收料总数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | //末道工序的报工 |
| | | else if (json[0].last_choke == "Y") |
| | | { |
| | | //查询当前末道报工工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前末道工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前末道工序非本次报工总数 |
| | | decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前末道工序非本次报工工废总数 |
| | | decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前末道工序非本次报工料废总数 |
| | | //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次收料总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty; |
| | | //判断当前工序供应商收料总数>当前工序供应商对应发料数量 |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序供应商收料总数量:【" + updatereportsumqty + "】不能大于工序供应商发料总数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | } |
| | | else //中间工序的报工 |
| | | { |
| | | |
| | | //查询当前首道工序供应商非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前外协工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前外协工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次收料数+本次报工调整收料数+非当前供应商同工序收料总数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前外协工序收料总数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else //不按序 |
| | | { |
| | | //控制逻辑:当前工序报工调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废) ==不能小于下道报工总数 |
| | | list.Clear(); |
| | | //判断当前工序是自制工序还是外协工序 |
| | | if (json[0].flw_type.ToString() == "Z") |
| | | { |
| | | |
| | | //查询当前报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次报工总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次报工数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>工单任务数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(json[0].task_qty.ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于工单任务数量:【" + json[0].task_qty.ToString() + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | if (json[0].flw_type.ToString() == "W") |
| | | { |
| | | //获取当前工序、供应商对应的总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as fqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | |
| | | //查询当前工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前末道工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前末道工序非本次报工总数 |
| | | decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前末道工序非本次报工工废总数 |
| | | decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前末道工序非本次报工料废总数 |
| | | //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty; |
| | | //判断当前工序供应商收料总数>当前工序供应商对应发料数量 |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序供应商收料总数量:【" + updatereportsumqty + "】不能大于工序供应商发料总数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | |
| | | switch (json[0].flw_type.ToString()) |
| | | { |
| | | case "Z": |
| | | ///////////////////////////////修改报工////////////////////////////// |
| | | |
| | | //回写对应的报工记录子表合格数量、不良数量、报废数量 |
| | |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | if (json[0].flw_type.ToString() == "W")//外协工序 |
| | | { |
| | | //查询当前首道工序非此次供应商收料:总收料数量 |
| | | sql = @"select isnull(sum(sqty),0) as sqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code<>@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_c = DapperHelper.selectdata(sql, dynamicParams); |
| | | //获取此次报工调整提交的数据(收料数量、不良数量、工废数量、料废数量) |
| | | decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //收料数量 |
| | | decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总 |
| | | decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总 |
| | | decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总 |
| | | decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总 |
| | | decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总 |
| | | decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总 |
| | | //获取当前工序、供应商对应的发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as fqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | //首道工序的收料 |
| | | if (json[0].first_choke == "Y") |
| | | { |
| | | //查询当前首道工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次收料数+本次报工调整收料数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料总数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | //末道工序的报工 |
| | | else if (json[0].last_choke == "Y") |
| | | { |
| | | //查询当前末道报工工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前末道工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前末道工序非本次报工总数 |
| | | decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前末道工序非本次报工工废总数 |
| | | decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前末道工序非本次报工料废总数 |
| | | //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次收料总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty; |
| | | //判断当前工序供应商收料总数>当前工序供应商对应发料数量 |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序供应商收料总数量:【" + updatereportsumqty + "】不能大于工序供应商发料总数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | } |
| | | else //中间工序的报工 |
| | | { |
| | | |
| | | //查询当前首道工序供应商非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次收料数+本次报工调整收料数+非当前供应商同工序收料总数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料总数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | break; |
| | | case "W": |
| | | ///////////////////////////////修改报工////////////////////////////// |
| | | |
| | | //回写对应的外协记录子表收料数量、不良数量、报废数量 |
| | |
| | | } |
| | | }); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |