| | |
| | | public static string strProcName = ""; //定义全局sql变量 |
| | | public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合 |
| | | public static SqlParameter[] parameters; //定义全局SqlParameter参数数组 |
| | | public static string sqlServerConnectString = AppSetting.GetAppSetting("DBServer"); |
| | | |
| | | |
| | | #region[ERP订单查询] |
| | |
| | | } |
| | | } |
| | | //获取工序信息 |
| | | sql = @"select S.wo_code,S.seq,S.step_code,T.stepname,S.stepprice,(isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | sql = @"select S.id,S.wo_code,S.seq,S.step_code,T.stepname,T.flwtype,S.stepprice as unprice,(isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty,(isnull(S.plan_qty,0)-(isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0))) as delive_qty,S.isbott,S.isend |
| | | from TK_Wrk_Step S |
| | | left join TStep T on S.step_code=T.stepcode |
| | | where S.wo_code=@wocode order by S.seq "; |
| | | dynamicParams.Add("@wocode", wocode); |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | var parents = DapperHelper.select<WorkRouteStepEqp>(sql, dynamicParams); |
| | | //获取工序对应设备信息 |
| | | for (int i = 0; i < parents.Count; i++) |
| | | { |
| | | if (parents[i].flwtype == "Z") |
| | | { |
| | | //通过工艺路线工序表ID查找对应设备信息 |
| | | sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as unprice,'Y' as enable, |
| | | (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_StepEqp S |
| | | inner join TEqpInfo E on S.eqp_code=E.code |
| | | where S.m_id=@m_id"; |
| | | dynamicParams.Add("@m_id", parents[i].id); |
| | | var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams); |
| | | parents[i].children = children.ToList(); |
| | | } |
| | | else |
| | | { |
| | | //通过工艺路线工序表ID查找对应外协供应商信息 |
| | | sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as unprice,'Y' as enable, |
| | | (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_StepEqp S |
| | | inner join TCustomer E on S.eqp_code=E.code |
| | | where S.m_id=@m_id"; |
| | | dynamicParams.Add("@m_id", parents[i].id); |
| | | var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams); |
| | | parents[i].children = children.ToList(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | dir.Add("canupdate_qty", canupdate_qty); |
| | | dir.Add("stepdata", data1); |
| | | dir.Add("stepdata", parents); |
| | | mes.code = "200"; |
| | | mes.count = data1.Rows.Count; |
| | | mes.count = parents.Count; |
| | | mes.message = "查询成功"; |
| | | mes.data = dir; |
| | | } |
| | |
| | | string sql = "", route_code = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | List<object> list = new List<object>(); |
| | | try |
| | | using (var conn = new SqlConnection(sqlServerConnectString)) |
| | | { |
| | | dynamic dynObj = JObject.Parse(us.mesSetting); |
| | | bool route = dynObj.route; |
| | | if (route) //工艺路线版 |
| | | conn.Open(); |
| | | using (var transaction = conn.BeginTransaction()) |
| | | { |
| | | 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,route_code,sourceid,m_po,saleOrderDeliveryDate,plan_startdate,plan_enddate,piroque,isaps,data_sources,isstep) |
| | | 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,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, |
| | | parm = new |
| | | { |
| | | wo_code = json.wocode, |
| | | wotype = json.wotype, |
| | | status = json.wostatus, |
| | | wkshp_code = json.wkshopcode, |
| | | plan_qty = json.woqty, |
| | | 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, |
| | | plan_startdate = json.paystartdate, |
| | | plan_enddate = json.payenddate, |
| | | orderlev = "3",//优先级:特级(1) 紧急(2) 正常(3) |
| | | isaps = "N", //是否排产,默认N Y=是 N=否 |
| | | data_sources = json.data_sources, |
| | | isstep = json.isstep //是否关联工序 |
| | | } |
| | | }); |
| | | //写入工序任务表 |
| | | for (int i = 0; i < json.WorkListSub.Count; i++) |
| | | { |
| | | 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, |
| | | parm = new |
| | | { |
| | | 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, |
| | | isbott = json.WorkListSub[i].isbott, |
| | | isend = json.WorkListSub[i].isend, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了工单:" + json.wocode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "MES工单新建成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "MES工单新建失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | if (operType == "Update") |
| | | { |
| | | //修改工单表 |
| | | 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,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 |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo_code = json.wocode, |
| | | wotype = json.wotype, |
| | | 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, |
| | | plan_startdate = json.paystartdate, |
| | | plan_enddate = json.payenddate, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString(), |
| | | isstep = json.isstep //是否关联工序 |
| | | } |
| | | }); |
| | | //删除工单工序表 |
| | | sql = @"delete TK_Wrk_Step where wo_code=@wo_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo_code = json.wocode |
| | | } |
| | | }); |
| | | //写入工单工序表 |
| | | for (int i = 0; i < json.WorkListSub.Count; i++) |
| | | { |
| | | 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, |
| | | parm = new |
| | | { |
| | | 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, |
| | | isbott = json.WorkListSub[i].isbott, |
| | | isend = json.WorkListSub[i].isend, |
| | | lm_user = us.usercode, |
| | | 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 |
| | | wo_code = json.wocode, |
| | | wotype = json.wotype, |
| | | status = json.wostatus, |
| | | wkshp_code = json.wkshopcode, |
| | | plan_qty = json.woqty, |
| | | 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, |
| | | plan_startdate = json.paystartdate, |
| | | plan_enddate = json.payenddate, |
| | | orderlev = "3",//优先级:特级(1) 紧急(2) 正常(3) |
| | | isaps = "N", //是否排产,默认N Y=是 N=否 |
| | | data_sources = json.data_sources, |
| | | isstep = json.isstep //是否关联工序 |
| | | } |
| | | }); |
| | | // 假设你已经有了插入主表和子表的SQL语句 |
| | | string workSql = @"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)"; |
| | | string masterInsertSql = @"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); SELECT CAST(SCOPE_IDENTITY() AS INT)"; |
| | | string detailInsertSql = @"insert into TK_Wrk_StepEqp(m_id,eqp_code,eqpprice) |
| | | values(@m_id,@eqp_code,@eqpprice)"; |
| | | |
| | | // 插入工单表 |
| | | var workParam = new DynamicParameters(); |
| | | workParam.Add("@wo_code", json.wocode); |
| | | workParam.Add("@wotype", json.wotype); |
| | | workParam.Add("@status", json.wostatus); |
| | | workParam.Add("@wkshp_code", json.wkshopcode); |
| | | workParam.Add("@plan_qty", json.woqty); |
| | | workParam.Add("@lm_user", us.usercode); |
| | | workParam.Add("@lm_date", DateTime.Now.ToString()); |
| | | workParam.Add("@materiel_code", json.partcode); |
| | | workParam.Add("@route_code", route_code); |
| | | workParam.Add("@sourceid", json.sourceid == "" ? null : json.sourceid); |
| | | workParam.Add("@m_po", json.sourcewo); |
| | | workParam.Add("@saleOrderDeliveryDate", json.deliverydate); |
| | | workParam.Add("@plan_startdate", json.paystartdate); |
| | | workParam.Add("@plan_enddate", json.payenddate); |
| | | workParam.Add("@orderlev", "3");//优先级:特级(1) 紧急(2) 正常(3) |
| | | workParam.Add("@isaps", "N");//是否排产,默认N Y=是 N=否 |
| | | workParam.Add("@data_sources", json.data_sources); |
| | | workParam.Add("@isstep", json.isstep);//是否关联工序 |
| | | conn.Execute(workSql, workParam, transaction); |
| | | |
| | | //写入工单工序表 |
| | | for (int i = 0; i < json.WorkListSub.Count; i++) |
| | | { |
| | | // 插入主表并获取新插入的ID |
| | | var masterParam = new DynamicParameters(); |
| | | masterParam.Add("@wo_code", json.wocode); |
| | | masterParam.Add("@seq", json.WorkListSub[i].stepseq); |
| | | masterParam.Add("@step_code", json.WorkListSub[i].stepcode); |
| | | masterParam.Add("@route_code", route_code); |
| | | masterParam.Add("@stepprice", json.WorkListSub[i].unprice); |
| | | masterParam.Add("@plan_qty", json.woqty); |
| | | masterParam.Add("@status", json.wostatus); |
| | | masterParam.Add("@isbott", json.WorkListSub[i].isbott); |
| | | masterParam.Add("@isend", json.WorkListSub[i].isend); |
| | | masterParam.Add("@lm_user", us.usercode); |
| | | masterParam.Add("@lm_date", DateTime.Now.ToString()); |
| | | |
| | | int masterId = Convert.ToInt32(conn.ExecuteScalar(masterInsertSql, masterParam, transaction)); |
| | | |
| | | // 写入工序任务表 |
| | | foreach (var detail in json.WorkListSub[i].WorkEqpListSub) |
| | | { |
| | | var detailParam = new DynamicParameters(); |
| | | detailParam.Add("@m_id", masterId); |
| | | detailParam.Add("@eqp_code", detail.eqpcode); |
| | | detailParam.Add("@eqpprice", detail.unprice); |
| | | conn.Execute(detailInsertSql, detailParam, transaction); |
| | | } |
| | | } |
| | | |
| | | // 所有插入成功,提交事务 |
| | | transaction.Commit(); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "MES工单新建成功!"; |
| | | mes.data = null; |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了工单:" + json.wocode, us.usertype); |
| | | } |
| | | if (operType == "Update") |
| | | { |
| | | //通过工单查找工序任务 |
| | | sql = @"select * from TK_Wrk_Step where wo_code=@wo_code"; |
| | | dynamicParams.Add("@wo_code", json.wocode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | |
| | | // 假设你已经有了插入主表和子表的SQL语句 |
| | | string workSql = @"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,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"; |
| | | string deleteWrkStepEqp = @"delete TK_Wrk_StepEqp where m_id=@m_id"; |
| | | string deleteWrkStep = @"delete TK_Wrk_Step where wo_code=@wo_code"; |
| | | string masterInsertSql = @"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); SELECT CAST(SCOPE_IDENTITY() AS INT)"; |
| | | string detailInsertSql = @"insert into TK_Wrk_StepEqp(m_id,eqp_code,eqpprice) |
| | | values(@m_id,@eqp_code,@eqpprice)"; |
| | | string EwoStatusSql = @"update TKimp_Ewo set status=@status,relse_qty=@relse_qty where id=@sourceid and wo=@sourcewo"; |
| | | |
| | | // 修改工单表 |
| | | var workParam = new DynamicParameters(); |
| | | workParam.Add("@wo_code", json.wocode); |
| | | workParam.Add("@wotype", json.wotype); |
| | | workParam.Add("@wkshp_code", json.wkshopcode); |
| | | workParam.Add("@plan_qty", json.woqty); |
| | | workParam.Add("@lm_user", us.usercode); |
| | | workParam.Add("@lm_date", DateTime.Now.ToString()); |
| | | workParam.Add("@materiel_code", json.partcode); |
| | | workParam.Add("@route_code", route_code); |
| | | workParam.Add("@sourceid", json.sourceid == "" ? null : json.sourceid); |
| | | workParam.Add("@m_po", json.sourcewo); |
| | | workParam.Add("@saleOrderDeliveryDate", json.deliverydate); |
| | | workParam.Add("@plan_startdate", json.paystartdate); |
| | | workParam.Add("@plan_enddate", json.payenddate); |
| | | workParam.Add("@isstep", json.isstep);//是否关联工序 |
| | | conn.Execute(workSql, workParam, transaction); |
| | | |
| | | //删除工单工序设备表 |
| | | for (int i = 0; i < data.Rows.Count; i++) |
| | | { |
| | | var wrkStepEqpParam = new DynamicParameters(); |
| | | wrkStepEqpParam.Add("@m_id", data.Rows[i]["ID"].ToString()); |
| | | conn.Execute(deleteWrkStepEqp, wrkStepEqpParam, transaction); |
| | | } |
| | | |
| | | |
| | | //删除工单工序表 |
| | | var workStepParam = new DynamicParameters(); |
| | | workStepParam.Add("@wo_code", json.wocode); |
| | | conn.Execute(deleteWrkStep, workStepParam, transaction); |
| | | |
| | | //写入工单工序表 |
| | | for (int i = 0; i < json.WorkListSub.Count; i++) |
| | | { |
| | | // 插入主表并获取新插入的ID |
| | | var masterParam = new DynamicParameters(); |
| | | masterParam.Add("@wo_code", json.wocode); |
| | | masterParam.Add("@seq", json.WorkListSub[i].stepseq); |
| | | masterParam.Add("@step_code", json.WorkListSub[i].stepcode); |
| | | masterParam.Add("@route_code", route_code); |
| | | masterParam.Add("@stepprice", json.WorkListSub[i].unprice); |
| | | masterParam.Add("@plan_qty", json.woqty); |
| | | masterParam.Add("@status", json.wostatus); |
| | | masterParam.Add("@isbott", json.WorkListSub[i].isbott); |
| | | masterParam.Add("@isend", json.WorkListSub[i].isend); |
| | | masterParam.Add("@lm_user", us.usercode); |
| | | masterParam.Add("@lm_date", DateTime.Now.ToString()); |
| | | |
| | | int masterId = Convert.ToInt32(conn.ExecuteScalar(masterInsertSql, masterParam, transaction)); |
| | | |
| | | // 写入工序任务表 |
| | | foreach (var detail in json.WorkListSub[i].WorkEqpListSub) |
| | | { |
| | | var detailParam = new DynamicParameters(); |
| | | detailParam.Add("@m_id", masterId); |
| | | detailParam.Add("@eqp_code", detail.eqpcode); |
| | | detailParam.Add("@eqpprice", detail.unprice); |
| | | conn.Execute(detailInsertSql, detailParam, transaction); |
| | | } |
| | | } |
| | | //判断源头单据是否来源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";//部分下达 |
| | | } |
| | | //更新订单表状态、已下达数量 |
| | | var EwoStatusParam = new DynamicParameters(); |
| | | EwoStatusParam.Add("@status", staus); |
| | | EwoStatusParam.Add("@relse_qty", relse_qty); |
| | | EwoStatusParam.Add("@sourceid", json.sourceid); |
| | | EwoStatusParam.Add("@sourcewo", json.sourcewo); |
| | | conn.Execute(EwoStatusSql, EwoStatusParam, transaction); |
| | | } |
| | | } |
| | | // 所有插入成功,提交事务 |
| | | transaction.Commit(); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "修改操作成功!"; |
| | | mes.data = null; |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "修改", "修改了工单:" + json.wocode, us.usertype); |
| | | } |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | catch (Exception e) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "修改", "修改了工单:" + json.wocode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "修改操作成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | // 捕获异常,回滚事务 |
| | | transaction.Rollback(); |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "修改操作失败!"; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | |
| | | sql = @"update TKimp_Ewo set status='CREATING',relse_qty=relse_qty-@orderqty where wo=@m_po and id=@souceid"; |
| | | list.Add(new { str = sql, parm = new { m_po = m_po, souceid = souceid, orderqty = decimal.Parse(orderqty) } }); |
| | | } |
| | | } |
| | | //删除工单工序设备表 |
| | | sql = @"select * from TK_Wrk_Step where wo_code=@wo_code"; |
| | | dynamicParams.Add("@wo_code", wocode); |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | for (int i = 0; i < data1.Rows.Count; i++) |
| | | { |
| | | sql = @"delete TK_Wrk_StepEqp where m_id=@m_id"; |
| | | list.Add(new { str = sql, parm = new { m_id = data1.Rows[i]["ID"].ToString() } }); |
| | | } |
| | | //删除工单工序表 |
| | | sql = @"delete TK_Wrk_Step where wo_code=@wocode"; |
| | |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | List<WorkRouteStepEqp> parents = new List<WorkRouteStepEqp>(); |
| | | try |
| | | { |
| | | dynamic dynObj = JObject.Parse(us.mesSetting); |
| | |
| | | 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"; |
| | | sql = @"select S.id,S.wo_code,S.seq,S.step_code,T.stepname,T.flwtype,S.stepprice as unprice,'0' as produceq_qty, |
| | | '0' as good_qty,'0' as ng_qty,'0' as laborbad_qty,'0' as materielbad_qty,'0' as delive_qty,isbott,isend |
| | | from TK_Wrk_Step S |
| | | inner join ( |
| | | select top 1 S.id,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); |
| | | parents = DapperHelper.select<WorkRouteStepEqp>(sql, dynamicParams); |
| | | //获取工序对应设备信息 |
| | | for (int i = 0; i < parents.Count; i++) |
| | | { |
| | | if (parents[i].flwtype == "Z") |
| | | { |
| | | //通过工艺路线工序表ID查找对应设备信息 |
| | | sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as unprice,'Y' as enable, |
| | | (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_StepEqp S |
| | | inner join TEqpInfo E on S.eqp_code=E.code |
| | | where S.m_id=@m_id"; |
| | | dynamicParams.Add("@m_id", parents[i].id); |
| | | var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams); |
| | | parents[i].children = children.ToList(); |
| | | } |
| | | else |
| | | { |
| | | //通过工艺路线工序表ID查找对应外协供应商信息 |
| | | sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as unprice,'Y' as enable, |
| | | (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_StepEqp S |
| | | inner join TCustomer E on S.eqp_code=E.code |
| | | where S.m_id=@m_id"; |
| | | dynamicParams.Add("@m_id", parents[i].id); |
| | | var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams); |
| | | parents[i].children = children.ToList(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //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 from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code |
| | | where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode |
| | | order by A.lm_date desc |
| | | ) as W on S.wo_code=W.wo_code |
| | | left join TStep T on S.step_code=T.stepcode |
| | | order by S.seq"; |
| | | sql = @"select S.id,S.wo_code,S.seq,S.step_code,T.stepname,T.flwtype,S.stepprice as unprice,'0' as produceq_qty, |
| | | '0' as good_qty,'0' as ng_qty,'0' as laborbad_qty,'0' as materielbad_qty,'0' as delive_qty,isbott,isend |
| | | from TK_Wrk_Step S |
| | | inner join ( |
| | | select top 1 A.wo_code from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code |
| | | where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode |
| | | order by A.lm_date desc |
| | | ) as W on S.wo_code=W.wo_code |
| | | left join TStep T on S.step_code=T.stepcode |
| | | order by S.seq"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@partcode", partcode); |
| | | parents = DapperHelper.select<WorkRouteStepEqp>(sql, dynamicParams); |
| | | //获取工序对应设备信息 |
| | | for (int i = 0; i < parents.Count; i++) |
| | | { |
| | | if (parents[i].flwtype == "Z") |
| | | { |
| | | //通过工艺路线工序表ID查找对应设备信息 |
| | | sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as unprice,'Y' as enable, |
| | | (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_StepEqp S |
| | | inner join TEqpInfo E on S.eqp_code=E.code |
| | | where S.m_id=@m_id"; |
| | | dynamicParams.Add("@m_id", parents[i].id); |
| | | var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams); |
| | | parents[i].children = children.ToList(); |
| | | } |
| | | else |
| | | { |
| | | //通过工艺路线工序表ID查找对应外协供应商信息 |
| | | sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as unprice,'Y' as enable, |
| | | (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty, |
| | | S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_StepEqp S |
| | | inner join TCustomer E on S.eqp_code=E.code |
| | | where S.m_id=@m_id"; |
| | | dynamicParams.Add("@m_id", parents[i].id); |
| | | var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams); |
| | | parents[i].children = children.ToList(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.count = data.Rows.Count; |
| | | mes.data = data; |
| | | mes.count = parents.Count; |
| | | mes.data = parents; |
| | | mes.message = "查询成功!"; |
| | | } |
| | | catch (Exception e) |
| | |
| | | else //不按序收发料 |
| | | { |
| | | mes = ScanStartReport.NoWXEncodingSeach(SelectType, wocode, stepcode); |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else //不按序 |
| | |
| | | //控制逻辑:当前工序报工调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废) ==不能小于下道报工总数 |
| | | list.Clear(); |
| | | //判断当前工序是自制工序还是外协工序 |
| | | if (json[0].flw_type.ToString() == "Z") |
| | | 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); |
| | |
| | | return mes; |
| | | } |
| | | } |
| | | if (json[0].flw_type.ToString() == "W") |
| | | if (json[0].flw_type.ToString() == "W") |
| | | { |
| | | //获取当前工序、供应商对应的总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as fqty |
| | |
| | | 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())) |
| | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | step_price=decimal.Parse(json[0].unprice), |
| | | step_price = decimal.Parse(json[0].unprice), |
| | | good_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | step_price=decimal.Parse(json[0].unprice), |
| | | step_price = decimal.Parse(json[0].unprice), |
| | | good_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |