| | |
| | | |
| | | |
| | | #region[ERP订单查询] |
| | | public static ToMessage ErpOrderSearch(string stu_torgcode,string stu_torgtypecode,string erporderstus, string erpordercode,string saleordercode, string partcode, string partname, string partspec, int startNum, string paydatestartdate, string paydateenddate, string paydatestartdate1, string paydateenddate2, string creatuser, int endNum, string prop, string order) |
| | | public static ToMessage ErpOrderSearch(string stu_torgcode, string stu_torgtypecode, string erporderstus, string erpordercode, string saleordercode, string partcode, string partname, string partspec, int startNum, string paydatestartdate, string paydateenddate, string paydatestartdate1, string paydateenddate2, string creatuser, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | |
| | | // --------------查询指定数据-------------- |
| | | var total = 0; //总条数 |
| | | var sql = @"select A.id, A.status,A.wo,A.materiel_code as partcode,B.partname,B.partspec,A.qty,A.relse_qty,A.wkshp_code,C.org_name as wkshp_name, |
| | | A.stck_code,D.name as stck_name,A.saleOrderCode,A.saleOrderDeliveryDate,A.planstartdate,A.planenddate,U.username as createuser,A.createdate |
| | | A.stck_code,D.name as stck_name,A.saleOrderCode,A.saleOrderDeliveryDate,A.planstartdate,A.planenddate,U.username as createuser,A.createdate,A.sbid |
| | | from TKimp_Ewo A |
| | | left join TMateriel_Info B on A.materiel_code=B.partcode |
| | | left join TOrganization C on A.wkshp_code=C.org_code |
| | |
| | | #endregion |
| | | |
| | | #region[ERP订单下达] |
| | | public static ToMessage MarkSaveErpOrder(string erporderid, string erpordercode,string saleordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string saleOrderDeliveryDate, string username) |
| | | public static ToMessage MarkSaveErpOrder(string erporderid, string erpordercode, string saleordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string saleOrderDeliveryDate, string username) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | |
| | | if (i == 1) //首单获取工单号 |
| | | { |
| | | sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as worknumb |
| | | from TK_Wrk_Man where m_po=@erpordercode"; |
| | | from TK_Wrk_Man where m_po=@erpordercode"; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString()); |
| | |
| | | m_po = erpordercode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | saleOrderCode=saleordercode, |
| | | saleOrderCode = saleordercode, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | |
| | | m_po = erpordercode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | saleOrderCode=saleordercode, |
| | | saleOrderCode = saleordercode, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | |
| | | mes.Message = "下达MES工单成功失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[ERP订单批量下达] |
| | | public static ToMessage MarkBatchSaveErpOrder(List<ErpOrderBatch> obj, string username) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | |
| | | try |
| | | { |
| | | list.Clear(); |
| | | |
| | | var groupedModels = obj.GroupBy(m => m.erpordercode); |
| | | foreach (var group in groupedModels) |
| | | { |
| | | string erpordercode = group.Key; |
| | | int count = 1; |
| | | foreach (var model in group) |
| | | { |
| | | //获取当前最大工单号 |
| | | sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0) as worknumb |
| | | from TK_Wrk_Man where m_po=@erpordercode"; |
| | | dynamicParams.Add("@erpordercode", model.erpordercode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | int num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString()); |
| | | string wo = model.erpordercode + "_" + (num + count); |
| | | //写入工单表 |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo_code = wo, |
| | | wotype = "PO", |
| | | status = "NEW", |
| | | wkshp_code = model.wkshopcode, |
| | | plan_qty = decimal.Parse(model.erpqty), //订单数量 |
| | | stck_code = model.warehousecode, |
| | | materiel_code = model.partcode, |
| | | sourceid = model.erporderid, |
| | | m_po = model.erpordercode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | saleOrderCode = model.saleordercode, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(model.saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | |
| | | //更新订单状态 |
| | | sql = @"update TKimp_Ewo set status='CREATED',saleOrderDeliveryDate=@saleOrderDeliveryDate,relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo = model.erpordercode, |
| | | erporderid = model.erporderid, |
| | | sumqty = decimal.Parse(model.markqty), |
| | | saleOrderDeliveryDate = Convert.ToDateTime(model.saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | count++; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | 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; |
| | | } |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[ERP订单删除] |
| | | public static ToMessage DeleteErpOrder(string erporderid, string erpordercode, string username) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | sql = @"select * from TK_Wrk_Man where m_po=@erpordercode and sourceid=@erporderid and status<>'NEW'"; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | dynamicParams.Add("@erporderid", erporderid); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前订单下有工单已派发或已开工或已完工(关闭),不允许删除!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | else |
| | | { |
| | | //删除工单 |
| | | sql = @"delete TK_Wrk_Man where m_po=@wo and sourceid=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid |
| | | } |
| | | }); |
| | | //删除订单 |
| | | sql = @"delete TKimp_Ewo where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid |
| | | } |
| | | }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | LogHelper.WriteLogData(aa.ToString()); |
| | | if (aa) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "订单删除成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "订单删除失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region[MES工单查询] |
| | | public static ToMessage MesOrderSearch(string stu_torgcode,string stu_torgtypecode,string mesorderstus, string mesordercode, string sourceorder,string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderSearch(string stu_torgcode, string stu_torgtypecode, string mesorderstus, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | |
| | | } |
| | | // --------------查询指定数据-------------- |
| | | 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.org_name as wkshp_name, |
| | | var sql = @"select A.id, A.status,A.wotype,A.printcount,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.plan_qty,A.wkshp_code,C.org_name as wkshp_name, |
| | | A.route_code,E.name as route_name,A.stck_code,F.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,W.saleOrderCode,U.username as lm_user,A.lm_date |
| | | from TK_Wrk_Man A |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code and A.sourceid=W.id |
| | | left join TMateriel_Info B on A.materiel_code=B.partcode |
| | | left join TOrganization C on A.wkshp_code=C.org_code |
| | | left join T_Sec_Stck D on A.stck_code=D.code |
| | |
| | | #endregion |
| | | |
| | | #region[MES报废补单工单查询] |
| | | public static ToMessage MesBadOrderSearch(string mesordercode, string sourceorder,string saleordercode, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | public static ToMessage MesBadOrderSearch(string mesordercode, string sourceorder, string saleordercode, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | |
| | | 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.org_name as wkshp_name, |
| | | A.route_code,E.name as route_name,A.stck_code,F.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,W.saleOrderCode,U.username as lm_user,A.lm_date,S.bad_qty |
| | | from TK_Wrk_Man A |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code and A.sourceid=W.id |
| | | left join (select wo_code,sum(bad_qty) as bad_qty from TK_Wrk_Step where bad_qty>0 group by wo_code) S on A.wo_code=S.wo_code |
| | | left join TMateriel_Info B on A.materiel_code=B.partcode |
| | | left join TOrganization C on A.wkshp_code=C.org_code |
| | |
| | | #endregion |
| | | |
| | | #region[产品编码查找工艺路线下拉接口] |
| | | public static ToMessage PartSelectRoute(string partcode,string wkshopcode) |
| | | public static ToMessage PartSelectRoute(string partcode, string wkshopcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | |
| | | #endregion |
| | | |
| | | #region[工艺路线查找车间下拉接口] |
| | | public static ToMessage RouteSelectWkshop(string stu_torgcode,string stu_torgtypecode,string partcode) |
| | | public static ToMessage RouteSelectWkshop(string stu_torgcode, string stu_torgtypecode, string partcode) |
| | | { |
| | | string sql = ""; |
| | | string search = ""; |
| | |
| | | inner join TEqpInfo E on D.eqp_code=E.code |
| | | left join TOrganization F on E.wksp_code=F.org_code |
| | | left join TOrganization L on F.parent_id=L.id |
| | | where M.materiel_code=@partcode and E.enable='Y' "+search; |
| | | where M.materiel_code=@partcode and E.enable='Y' " + search; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | |
| | | try |
| | | { |
| | | //获取工艺路线对应工序信息 |
| | | sql = @"select A.seq,T.stepcode,T.stepname,T.flwtype,T.descr from TFlw_Rtdt A |
| | | sql = @"select A.seq,T.stepcode,T.stepname,T.flwtype,T.descr,'0' as stepprice from TFlw_Rtdt A |
| | | left join TStep T on A.step_code=T.stepcode |
| | | where A.rout_code=@partcode "; |
| | | dynamicParams.Add("@partcode", routecode); |
| | |
| | | #endregion |
| | | |
| | | #region[工单派发选择工艺路线或选择生产车间时判断绑定条件] |
| | | public static ToMessage SelectRouteOrWkshop(string partcode, string routecode, string wkshopcode) |
| | | public static ToMessage SelectRouteOrWkshop(string partcode, string routecode, string wkshopcode, string is_steprice) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | |
| | | return mes; |
| | | } |
| | | } |
| | | //判断工艺路线对应工序关联的工作站是否有设置节拍工价 |
| | | sql = @"select AA.step_code,AA.eqp_code,AA.flwtype,S.unprice from ( |
| | | if (is_steprice == "Y") |
| | | { |
| | | //判断工艺路线对应工序关联的工作站是否有设置节拍工价 |
| | | sql = @"select AA.step_code,AA.eqp_code,AA.flwtype,S.unprice from ( |
| | | select A.code,B.step_code,C.eqp_code,S.flwtype from TFlw_Rout A |
| | | inner join TFlw_Rtdt B on A.code=B.rout_code |
| | | left join TFlw_Rteqp C on B.step_code=C.step_code |
| | |
| | | ) as AA |
| | | left join (select * from TPrteEqp_Stad where materiel_code=@partcode and route_code=@route_code and wkspcode=@wkshopcode) as S on |
| | | AA.code=S.route_code and AA.step_code=S.step_code and AA.eqp_code=S.eqp_code"; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@route_code", routecode); |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | var dtc = DapperHelper.selectdata(sql, dynamicParams); |
| | | for (int i = 0; i < dtc.Rows.Count; i++) |
| | | { |
| | | if (dtc.Rows[i]["flwtype"].ToString() == "Z") //判断工序是否为自制 |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@route_code", routecode); |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | var dtc = DapperHelper.selectdata(sql, dynamicParams); |
| | | for (int i = 0; i < dtc.Rows.Count; i++) |
| | | { |
| | | if (dtc.Rows[i].IsNull("unprice") || decimal.Parse(dtc.Rows[i]["unprice"].ToString()) == 0) |
| | | if (dtc.Rows[i]["flwtype"].ToString() == "Z") //判断工序是否为自制 |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "节拍工价中:当前产品【" + partcode + "】,对应工艺路线【" + routecode + "】未设置(或未设置全)或工价小于等于0!"; |
| | | mes.data = null; |
| | | return mes; |
| | | if (dtc.Rows[i].IsNull("unprice") || decimal.Parse(dtc.Rows[i]["unprice"].ToString()) == 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "节拍工价中:当前产品【" + partcode + "】,对应工艺路线【" + routecode + "】未设置(或未设置全)或工价小于等于0!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | CreateDate = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | |
| | | //写入工单工艺路线工序工价复制表 |
| | | sql = @"insert into TWoPrteEqp_Stad(wo,materiel_code,eqp_code,stand_value,opc_conver,route_code,unprice,eqp_value,cavity_qty,wkspcode,lm_user,lm_date,torg_code,is_delete,step_code) |
| | | select distinct @mesordercode as wo,S.materiel_code,S.eqp_code,S.stand_value,S.opc_conver,S.route_code,S.unprice, |
| | | S.eqp_value,S.cavity_qty,S.wkspcode,S.lm_user,S.lm_date,S.torg_code,S.is_delete,S.step_code |
| | | select distinct @mesordercode as wo,@partcode as materiel_code,AA.eqp_code,isnull(S.stand_value,0) as stand_value,isnull(S.opc_conver,0) as opc_conver,AA.rout_code, |
| | | isnull(S.unprice,0) as unprice,isnull(S.eqp_value,0) as eqp_value,isnull(S.cavity_qty,0) as cavity_qty,@wkshopcode as wkspcode,@usercode as lm_user, |
| | | getdate() as lm_date,S.torg_code,isnull(S.is_delete,0) as is_delete,AA.step_code from ( |
| | | select A.rout_code,A.step_code,C.eqp_code |
| | | from TFlw_Rtdt A |
| | | inner join TFlw_Rteqp C on A.step_code=C.step_code |
| | | inner join (select * from TPrteEqp_Stad where materiel_code=@materiel_code and route_code=@routecode) as S on C.step_code=S.step_code and C.eqp_code=S.eqp_code"; |
| | | where A.rout_code=@routecode |
| | | ) as AA |
| | | left join (select * from TPrteEqp_Stad where materiel_code=@partcode and route_code=@routecode) as S on AA.step_code=S.step_code and AA.eqp_code=S.eqp_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | mesordercode = mesordercode, |
| | | materiel_code = partcode, |
| | | routecode = routecode |
| | | wkshopcode = wkshopcode, |
| | | partcode = partcode, |
| | | routecode = routecode, |
| | | usercode = username |
| | | } |
| | | }); |
| | | |
| | |
| | | }); |
| | | //写入工单工艺路线工序工价复制表 |
| | | sql = @"insert into TWoPrteEqp_Stad(wo,materiel_code,eqp_code,stand_value,opc_conver,route_code,unprice,eqp_value,cavity_qty,wkspcode,lm_user,lm_date,torg_code,is_delete,step_code) |
| | | select distinct @mesordercode as wo,S.materiel_code,S.eqp_code,S.stand_value,S.opc_conver,S.route_code,S.unprice, |
| | | S.eqp_value,S.cavity_qty,S.wkspcode,S.lm_user,S.lm_date,S.torg_code,S.is_delete,S.step_code |
| | | select distinct @mesordercode as wo,@partcode as materiel_code,AA.eqp_code,isnull(S.stand_value,0) as stand_value,isnull(S.opc_conver,0) as opc_conver,AA.rout_code, |
| | | isnull(S.unprice,0) as unprice,isnull(S.eqp_value,0) as eqp_value,isnull(S.cavity_qty,0) as cavity_qty,@wkshopcode as wkspcode,@usercode as lm_user, |
| | | getdate() as lm_date,S.torg_code,isnull(S.is_delete,0) as is_delete,AA.step_code from ( |
| | | select A.rout_code,A.step_code,C.eqp_code |
| | | from TFlw_Rtdt A |
| | | inner join TFlw_Rteqp C on A.step_code=C.step_code |
| | | inner join (select * from TPrteEqp_Stad where materiel_code=@materiel_code and route_code=@routecode) as S on C.step_code=S.step_code and C.eqp_code=S.eqp_code"; |
| | | where A.rout_code=@routecode |
| | | ) as AA |
| | | left join (select * from TPrteEqp_Stad where materiel_code=@partcode and route_code=@routecode) as S on AA.step_code=S.step_code and AA.eqp_code=S.eqp_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | mesordercode = mesordercode, |
| | | materiel_code = partcode, |
| | | routecode = routecode |
| | | wkshopcode = wkshopcode, |
| | | partcode = partcode, |
| | | routecode = routecode, |
| | | usercode = username |
| | | } |
| | | }); |
| | | |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[MES工单打印更新打印次数] |
| | | public static ToMessage UpdateMesOrderPrintCount(string wo_code) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //更新工单打印次数 |
| | | sql = @"update TK_Wrk_Man set printcount=printcount+1 where wo_code=@wo_code"; |
| | | list.Add(new { str = sql, parm = new { wo_code = wo_code } }); |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "更新成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "更新失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region[生产开报工扫码获取当前工序对应的设备(自制)] |
| | | public static ToMessage MesOrderStepEqpSearch(string orderstepqrcode) |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(自制)] |
| | | public static ToMessage MesOrderStepSearch(string stu_torgcode,string stu_torgtypecode, string orderstepqrcode, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderStepSearch(string stu_torgcode, string stu_torgtypecode, string wocode, string saleOrderCode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | var total = 0; //总条数 |
| | | try |
| | | { |
| | | if (orderstepqrcode != "" && orderstepqrcode != null) |
| | | if (wocode != "" && wocode != null) |
| | | { |
| | | string[] arra = orderstepqrcode.Split(';'); |
| | | string[] arra = wocode.Split(';'); |
| | | if (arra.Length == 1) //工单号二维码 |
| | | { |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "请扫描工序二维码!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | if (arra.Length == 2) //工单号+工序号二维码 |
| | | { |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | search += "and A.wo_code like '%'+@ordercode+'%' "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | } |
| | | if (ordercode != "" && stepcode != "") //工单号不为空,工序号不为空 |
| | |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // mes.code = "300"; |
| | | // mes.count = 0; |
| | | // mes.Message = "二维码信息为空!"; |
| | | // mes.data = null; |
| | | // return mes; |
| | | //} |
| | | if (stepcode != "") |
| | | { |
| | | //查找当前工序属性 |
| | |
| | | default: |
| | | break; |
| | | } |
| | | if (saleOrderCode != "" && saleOrderCode != null) |
| | | { |
| | | search += "and W.saleOrderCode like '%'+@saleOrderCode+'%' "; |
| | | dynamicParams.Add("@saleOrderCode", saleOrderCode); |
| | | } |
| | | if (partcode != "" && partcode != null) |
| | | { |
| | | search += "and M.partcode like '%'+@partcode+'%' "; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | } |
| | | if (partname != "" && partname != null) |
| | | { |
| | | search += "and M.partname like '%'+@partname+'%' "; |
| | | dynamicParams.Add("@partname", partname); |
| | | } |
| | | if (partspec != "" && partspec != null) |
| | | { |
| | | search += "and M.partspec like '%'+@partspec+'%' "; |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | //根据条件查询工单工序任务(自制工序) |
| | | sql = @"select A.status,A.wo_code,B.route_code,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend, |
| | | S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,A.plan_startdate,A.plan_enddate,B.lm_date |
| | | S.stepcode,S.stepname,S.descr,A.plan_qty,A.start_qty,A.good_qty,A.ng_qty,A.bad_qty,A.plan_startdate,A.plan_enddate,B.lm_date, |
| | | B.m_po,W.saleOrderCode |
| | | from TK_Wrk_Step A |
| | | left join TK_Wrk_Man B on A.wo_code=B.wo_code |
| | | left join TKimp_Ewo W on B.m_po=W.wo and B.materiel_code=W.materiel_code and B.sourceid=W.id |
| | | left join TMateriel_Info M on B.materiel_code=M.partcode |
| | | left join TStep S on A.step_code=S.stepcode |
| | | left join TOrganization F on B.wkshp_code=F.org_code |
| | |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.data = null; |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(外协)] |
| | | public static ToMessage MesOrderWxStepSearch(string stu_torgcode,string stu_torgtypecode,string orderstepqrcode, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderWxStepSearch(string stu_torgcode, string stu_torgtypecode, string orderstepqrcode, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | } |
| | | //根据条件查询工单工序任务(外协工序) |
| | | sql = @"select A.status,A.wo_code,B.route_code,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend, |
| | | S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,A.plan_startdate,A.plan_enddate,B.lm_date |
| | | S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,A.plan_startdate,A.plan_enddate,B.lm_date, |
| | | B.m_po,W.saleOrderCode |
| | | from TK_Wrk_Step A |
| | | left join TK_Wrk_Man B on A.wo_code=B.wo_code |
| | | left join TKimp_Ewo W on B.m_po=W.wo and B.materiel_code=W.materiel_code and B.sourceid=W.id |
| | | left join TMateriel_Info M on B.materiel_code=M.partcode |
| | | left join TStep S on A.step_code=S.stepcode |
| | | left join TOrganization F on B.wkshp_code=F.org_code |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(不良)] |
| | | public static ToMessage MesOrderNgStepSearch(string stu_torgcode,string stu_torgtypecode,string orderstepqrcode, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderNgStepSearch(string stu_torgcode, string stu_torgtypecode, string orderstepqrcode, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | } |
| | | //根据条件查询工单工序任务,且不良数量大于0 |
| | | sql = @"select A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isend, |
| | | S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,B.lm_date |
| | | S.stepcode,S.stepname,S.descr,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,B.lm_date, |
| | | B.m_po,W.saleOrderCode |
| | | from TK_Wrk_Step A |
| | | left join TK_Wrk_Man B on A.wo_code=B.wo_code |
| | | left join TKimp_Ewo W on B.m_po=W.wo and B.materiel_code=W.materiel_code and B.sourceid=W.id |
| | | left join TMateriel_Info M on B.materiel_code=M.partcode |
| | | left join TStep S on A.step_code=S.stepcode |
| | | left join TOrganization F on B.wkshp_code=F.org_code |
| | |
| | | } |
| | | } |
| | | //1.根据工单+工序查找当前工序是否首道工序 |
| | | sql = @"select A.wo_code,P.partcode,P.partname,P.partspec, T.stepcode,T.stepname,A.seq,T.flwtype,T.descr,A.status,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,A.isbott,A.isend |
| | | sql = @"select A.wo_code,P.partcode,P.partname,P.partspec, T.stepcode,T.stepname,A.seq,T.flwtype,T.descr,A.status,A.plan_qty,A.good_qty,A.ng_qty,A.bad_qty,A.isbott,A.isend, |
| | | M.m_po,W.saleOrderCode |
| | | from TK_Wrk_Step A |
| | | left join TStep T on A.step_code=T.stepcode |
| | | left join TK_Wrk_Man M on A.wo_code=M.wo_code |
| | | left join TKimp_Ewo W on M.m_po=W.wo and M.materiel_code=W.materiel_code and M.sourceid=W.id |
| | | left join TMateriel_Info P on M.materiel_code=P.partcode |
| | | where A.wo_code=@ordercode and A.step_code=@stepcode"; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | rt.wo_code = data.Rows[0]["WO_CODE"].ToString(); //工单号 |
| | | rt.saleOrderCode = data.Rows[0]["saleOrderCode"].ToString(); //销售订单号 |
| | | rt.m_po = data.Rows[0]["m_po"].ToString(); //订单号 |
| | | rt.partnumber = data.Rows[0]["PARTCODE"].ToString(); //产品编码 |
| | | rt.partname = data.Rows[0]["PARTNAME"].ToString(); //产品名称 |
| | | rt.partspec = data.Rows[0]["PARTSPEC"].ToString(); //产品规格 |
| | |
| | | #endregion |
| | | |
| | | #region [生产开报工:开工(开始/报工)/外协发料时条件判断及数据返回接口] |
| | | public static ToMessage MesOrderStepStart(string OperType,string stu_torgcode, string SelectType, string orderstepqrcode) |
| | | public static ToMessage MesOrderStepStart(string OperType, string stu_torgcode, string SelectType, string orderstepqrcode) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | switch (OperType) |
| | | { |
| | | case "ZZ": |
| | | mes = ScanStartReport.ZZEncodingSeach(stu_torgcode, SelectType,ordercode, stepcode); |
| | | mes = ScanStartReport.ZZEncodingSeach(stu_torgcode, SelectType, ordercode, stepcode); |
| | | break; |
| | | case "WX": |
| | | mes = ScanStartReport.WXEncodingSeach(stu_torgcode,SelectType, ordercode, stepcode); |
| | | mes = ScanStartReport.WXEncodingSeach(stu_torgcode, SelectType, ordercode, stepcode); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | dynamicParams.Add("@wo_code", ordercode); |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = "当前工序未关联生产设备!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工:报工时获取生产班组下拉框] |
| | | public static ToMessage MesOrderStepReportSelectUserGroup(string stu_torgcode,string stu_torgtypecode,string wkshopcode) |
| | | public static ToMessage MesOrderStepReportSelectUserGroup(string stu_torgcode, string stu_torgtypecode, string wkshopcode) |
| | | { |
| | | string sql = ""; |
| | | string search = ""; |
| | |
| | | sql = @"select group_code,group_name from TGroup A |
| | | left join TOrganization T on A.torg_code=T.org_code |
| | | left join TOrganization as L on T.parent_id=L.id |
| | | where 1=1 "+search; |
| | | where 1=1 " + search; |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | |
| | | try |
| | | { |
| | | //班组获取人员列表 |
| | | sql = @"select U.username,U.username |
| | | sql = @"select U.usercode,U.username |
| | | from TGroup G |
| | | inner join TGroupUser T on G.group_code=T.group_code |
| | | left join TUser U on T.user_code=U.usercode |
| | |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | list.Clear(); |
| | | //判断是否有开工记录 |
| | | sql = @"select * from TK_Wrk_Record where wo_code=@wo_code and step_code=@step_code and eqp_code=@eqpcode and style='S'"; |
| | | sql = @"select * from TK_Wrk_Record where wo_code=@wo_code and step_code=@step_code and style='S'"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@eqpcode", eqpcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务设备已开工!"; |
| | | mes.data = null; |
| | | return mes; |
| | | //修改开报工记录表(开工数量) |
| | | sql = @"update TK_Wrk_Record set start_qty=start_qty+@startqty where wo_code=@mesordercode and step_seq=@stepseq and step_code=@stepcode and materiel_code=@partcode and style=@style"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, partcode = partcode, startqty = startqty, style = "S" } }); |
| | | //修改工单工序表(开工数量) |
| | | sql = @"update TK_Wrk_Step set start_qty=start_qty+@startqty where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, startqty = startqty } }); |
| | | } |
| | | else |
| | | { |
| | | //写入开报工记录表 |
| | | sql = @"insert into TK_Wrk_Record(wo_code,step_seq,step_code,eqp_code,materiel_code,open_person,open_time,task_qty,start_qty,style,lm_user,lm_date) |
| | | values(@mesordercode,@stepseq,@stepcode,@eqpcode,@partcode,@username,@opentime,@taskqty,@startqty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, eqpcode = eqpcode, partcode = partcode, username = username, opentime = date, taskqty = taskqty, startqty = startqty, style = "S", lm_user = username, lm_date = date } }); |
| | | //回写工单工序表状态为START: 开工 |
| | | sql = @"update TK_Wrk_Step set status='START',start_qty=@startqty where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, startqty = startqty } }); |
| | | |
| | | //回写工单表状态为: 开工:START |
| | | sql = @"update TK_Wrk_Man set status='START' where wo_code=@mesordercode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode } }); |
| | | } |
| | | |
| | | //写入开报工记录表 |
| | | sql = @"insert into TK_Wrk_Record(wo_code,step_seq,step_code,eqp_code,materiel_code,open_person,open_time,task_qty,start_qty,style,lm_user,lm_date) |
| | | values(@mesordercode,@stepseq,@stepcode,@eqpcode,@partcode,@username,@opentime,@taskqty,@startqty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, eqpcode = eqpcode, partcode = partcode, username = username, opentime = date, taskqty = taskqty, startqty = startqty, style = "S", lm_user = username, lm_date = date } }); |
| | | //回写工单工序表状态为START: 开工 |
| | | sql = @"update TK_Wrk_Step set status='START' where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | |
| | | //回写工单工序表状态为已开工 |
| | | sql = @"update TK_Wrk_Step set status='START' where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | //回写工单表状态为: 开工:START |
| | | sql = @"update TK_Wrk_Man set status='START' where wo_code=@mesordercode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode } }); |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工,报工提交] |
| | | public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string eqpcode, string inbarcode, string reckway, string usergroupcode, string reportuser, string taskqty, string startqty, string reportqty, string ngqty, string badcode, string remarks, string username) |
| | | public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string eqpcode, string inbarcode, string reckway, string usergroupcode, string reportuser, string taskqty, string startqty, string reportqty, List<ReportDefectList> defectobjs, string remarks, string username) |
| | | { |
| | | var sql = ""; |
| | | //string[] arra = new string[] { }; |
| | | decimal ngqty = 0; |
| | | string[] arra1 = new string[] { }; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | //获取报工人员、分配比例 |
| | | JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(reportuser); |
| | | if (ngqty != "" || ngqty != "0") |
| | | //判断是否有不良数据 |
| | | var groupedItems = defectobjs.GroupBy(item => item.defect_code) // 按编码code分组 |
| | | .Select(group => new { defect_code = group.Key, badqty = group.Sum(item => Convert.ToDecimal(item.badqty)) }).ToList(); // 汇总数量qty |
| | | if (groupedItems.Count <= 0) |
| | | { |
| | | //截取不良原因 |
| | | arra1 = badcode.Split(';'); |
| | | ngqty = 0; |
| | | } |
| | | |
| | | else |
| | | { |
| | | //汇总不良数量 |
| | | ngqty = groupedItems.Sum(item => Convert.ToDecimal(item.badqty)); |
| | | } |
| | | list.Clear(); |
| | | //判断是否有报工记录(有:修改 无:新增) |
| | | sql = @"select * from TK_Wrk_Record where wo_code=@wo_code and step_code=@step_code and style='B'"; |
| | |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | //获取开工记录的默认选中的设备(产线)与报工时的设备产线做对比判断 |
| | | sql = @"select A.eqp_code,B.name from TK_Wrk_Record A |
| | | inner join TEqpInfo B on A.eqp_code=B.code |
| | | where A.wo_code=@wo_code and A.step_code=@step_code and eqp_code=@eqpcode and A.style='S'"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@eqpcode", eqpcode); |
| | | var da = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (da.Rows[0]["EQP_CODE"].ToString() != eqpcode) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "操作失败,当前报工产线应为:" + da.Rows[0]["NAME"].ToString() + "!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //sql = @"select A.eqp_code,B.name from TK_Wrk_Record A |
| | | // inner join TEqpInfo B on A.eqp_code=B.code |
| | | // where A.wo_code=@wo_code and A.step_code=@step_code and eqp_code=@eqpcode and A.style='S'"; |
| | | //dynamicParams.Add("@wo_code", mesordercode); |
| | | //dynamicParams.Add("@step_code", stepcode); |
| | | //dynamicParams.Add("@eqpcode", eqpcode); |
| | | //var da = DapperHelper.selectdata(sql, dynamicParams); |
| | | //if (da.Rows[0]["EQP_CODE"].ToString() != eqpcode) |
| | | //{ |
| | | // mes.code = "300"; |
| | | // mes.count = 0; |
| | | // mes.Message = "操作失败,当前报工产线应为:" + da.Rows[0]["NAME"].ToString() + "!"; |
| | | // mes.data = null; |
| | | // return mes; |
| | | //} |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | //获取主表最大ID |
| | | sql = @"select ISNULL(IDENT_CURRENT('TK_Wrk_Record')+1,1) as id"; |
| | | var dt = DapperHelper.selecttable(sql); |
| | | |
| | | //写入开报工记录表 |
| | | sql = @"insert into TK_Wrk_Record(wo_code,step_seq,step_code,eqp_code,materiel_code,task_qty,start_qty,good_qty,ng_qty,style,lm_user,lm_date,inbarcode) |
| | | values(@mesordercode,@stepseq,@stepcode,@eqpcode,@partcode,@taskqty,@startqty,@reportqty,@ngqty,@style,@lm_user,@lm_date,@inbarcode)"; |
| | |
| | | }); |
| | | |
| | | } |
| | | if (badcode != "" && ngqty != "0") |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | for (int i = 0; i < arra1.Length; i++) |
| | | for (int i = 0; i < groupedItems.Count; i++) |
| | | { |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "B", lm_user = username, lm_date = date } }); |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "B", lm_user = username, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | |
| | | }); |
| | | |
| | | } |
| | | if (badcode != "" && ngqty != "0") |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | for (int i = 0; i < arra1.Length; i++) |
| | | for (int i = 0; i < groupedItems.Count; i++) |
| | | { |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "B", lm_user = username, lm_date = date } }); |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "B", lm_user = username, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工, 收料提交] |
| | | public static ToMessage SavaMesOrderStepIn(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, string inbarcode, string inuser, string taskqty, string sqty, string ngqty, string badcode, string remarks, string username) |
| | | public static ToMessage SavaMesOrderStepIn(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, string inbarcode, string inuser, string taskqty, string sqty, List<ReportDefectList> defectobjs, string remarks, string username) |
| | | { |
| | | var sql = ""; |
| | | string[] arra1 = new string[] { }; |
| | | decimal ngqty = 0; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | //截取不良原因 |
| | | if (ngqty != "" || ngqty != "0") |
| | | //判断是否有不良数据 |
| | | var groupedItems = defectobjs.GroupBy(item => item.defect_code) // 按编码code分组 |
| | | .Select(group => new { defect_code = group.Key, badqty = group.Sum(item => Convert.ToDecimal(item.badqty)) }).ToList(); // 汇总数量qty |
| | | if (groupedItems.Count <= 0) |
| | | { |
| | | //截取不良原因 |
| | | arra1 = badcode.Split(';'); |
| | | ngqty = 0; |
| | | } |
| | | else |
| | | { |
| | | //汇总不良数量 |
| | | ngqty = groupedItems.Sum(item => Convert.ToDecimal(item.badqty)); |
| | | } |
| | | |
| | | list.Clear(); |
| | |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | if ((decimal.Parse(sqty) + decimal.Parse(ngqty)) > decimal.Parse(da.Rows[0]["FQTY"].ToString())) //收料数量+不良数量>发料数量 |
| | | if ((decimal.Parse(sqty) + ngqty) > decimal.Parse(da.Rows[0]["FQTY"].ToString())) //收料数量+不良数量>发料数量 |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | |
| | | { |
| | | decimal sum_sqty = data.AsEnumerable().Select(d => d.Field<decimal>("SQTY")).Sum(); //获取同单号,同工序,同外协供应商收料总数量 |
| | | decimal sum_fqty = da.AsEnumerable().Select(d => d.Field<decimal>("FQTY")).Sum(); //获取同单号,同工序,同外协供应商发料总数量 |
| | | if ((sum_sqty + decimal.Parse(sqty) + decimal.Parse(ngqty)) > sum_fqty) //已收料总数+当前收料数量+不良数量>总发料数量 |
| | | if ((sum_sqty + decimal.Parse(sqty) + ngqty) > sum_fqty) //已收料总数+当前收料数量+不良数量>总发料数量 |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | |
| | | values(@m_id,@wxcode,@in_person,@in_time,@sqty,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), wxcode = wxcode, in_person = inuser, in_time = date, sqty = sqty, ng_qty = ngqty, style = "S", lm_user = username, lm_date = date } }); |
| | | |
| | | if (badcode != "" && ngqty != "0") |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | for (int i = 0; i < arra1.Length; i++) |
| | | for (int i = 0; i < groupedItems.Count; i++) |
| | | { |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "S", lm_user = username, lm_date = date } }); |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "S", lm_user = username, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | |
| | | values(@m_id,@wxcode,@in_person,@in_time,@sqty,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), wxcode = wxcode, in_person = inuser, in_time = date, sqty = sqty, ng_qty = ngqty, style = "S", lm_user = username, lm_date = date } }); |
| | | |
| | | if (badcode != "" && ngqty != "0") |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | for (int i = 0; i < arra1.Length; i++) |
| | | for (int i = 0; i < groupedItems.Count; i++) |
| | | { |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = ngqty, defect_code = arra1[i], remarks = remarks, style = "S", lm_user = username, lm_date = date } }); |
| | | sql = @"insert into CSR_WorkRecord_Defect(record_id,wo_code,partnumber,step_seq,step_code,defect_qty,defect_pendqty,defect_code,remarks,style,lm_user,lm_date) |
| | | values(@record_id,@wo_code,@partcode,@stepseq,@stepcode,@ngqty,@defect_pendqty,@defect_code,@remarks,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { record_id = int.Parse(dt.Rows[0]["ID"].ToString()), wo_code = mesordercode, partcode = partcode, stepseq = stepseq, stepcode = stepcode, ngqty = groupedItems[i].badqty, defect_pendqty = groupedItems[i].badqty, defect_code = groupedItems[i].defect_code, remarks = remarks, style = "S", lm_user = username, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(json.Data.Rows[i]["ID"].ToString()), |
| | | m_id = int.Parse(json.Data.Rows[i]["M_ID"].ToString()), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | bad_qty = decimal.Parse(json.Data.Rows[i]["BAD_QTY"].ToString()) |
| | | } |
| | |
| | | bad_qty = decimal.Parse(json.Data.Rows[i]["BAD_QTY"].ToString()), |
| | | wo_code = json.Data.Rows[i]["WO_CODE"].ToString(), |
| | | step_code = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | id = int.Parse(json.Data.Rows[i]["ID"].ToString()) |
| | | id = int.Parse(json.Data.Rows[i]["M_ID"].ToString()) |
| | | } |
| | | }); |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(record_subid,wo_code,partnumber,step_seq,step_code,repair_qty,bad_qty,defect_code,style,lm_user,lm_date) |
| | | values(@record_subid,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@bad_qty,@defect_code,@style,@lm_user,@lm_date)"; |
| | | //回写缺陷记录表的待处理数量 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty-@repair_qty-@bad_qty,defect_pendqty=defect_pendqty-@repair_qty-@bad_qty,bad_qty=bad_qty+@bad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | record_subid = int.Parse(json.Data.Rows[i]["M_ID"].ToString()), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | bad_qty = decimal.Parse(json.Data.Rows[i]["BAD_QTY"].ToString()), |
| | | wo_code = json.Data.Rows[i]["WO_CODE"].ToString(), |
| | | step_code = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | id = int.Parse(json.Data.Rows[i]["ID"].ToString()) |
| | | } |
| | | }); |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,bad_qty,defect_code,style,lm_user,lm_date) |
| | | values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@bad_qty,@defect_code,@style,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()), |
| | | wo_code = json.Data.Rows[i]["WO_CODE"].ToString(), |
| | | partcode = json.Data.Rows[i]["MATERIEL_CODE"].ToString(), |
| | | stepseq = json.Data.Rows[i]["SEQ"].ToString(), |
| | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(json.Data.Rows[i]["ID"].ToString()), |
| | | m_id = int.Parse(json.Data.Rows[i]["M_ID"].ToString()), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | bad_qty = decimal.Parse(json.Data.Rows[i]["BAD_QTY"].ToString()) |
| | | } |
| | |
| | | bad_qty = decimal.Parse(json.Data.Rows[i]["BAD_QTY"].ToString()), |
| | | wo_code = json.Data.Rows[i]["WO_CODE"].ToString(), |
| | | step_code = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | id = int.Parse(json.Data.Rows[i]["ID"].ToString()) |
| | | id = int.Parse(json.Data.Rows[i]["M_ID"].ToString()) |
| | | } |
| | | }); |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(record_subid,wo_code,partnumber,step_seq,step_code,repair_qty,bad_qty,defect_code,style,lm_user,lm_date) |
| | | values(@record_subid,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@bad_qty,@defect_code,@style,@lm_user,@lm_date)"; |
| | | //回写缺陷记录表的待处理数量 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty-@repair_qty-@bad_qty,defect_pendqty=defect_pendqty-@repair_qty-@bad_qty,bad_qty=bad_qty+@bad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='S'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | record_subid = int.Parse(json.Data.Rows[i]["M_ID"].ToString()), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | bad_qty = decimal.Parse(json.Data.Rows[i]["BAD_QTY"].ToString()), |
| | | wo_code = json.Data.Rows[i]["WO_CODE"].ToString(), |
| | | step_code = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | id = int.Parse(json.Data.Rows[i]["ID"].ToString()) |
| | | } |
| | | }); |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,bad_qty,defect_code,style,lm_user,lm_date) |
| | | values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@bad_qty,@defect_code,@style,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | defect_id = int.Parse(json.Data.Rows[i]["ID"].ToString()), |
| | | wo_code = json.Data.Rows[i]["WO_CODE"].ToString(), |
| | | partcode = json.Data.Rows[i]["MATERIEL_CODE"].ToString(), |
| | | stepseq = json.Data.Rows[i]["SEQ"].ToString(), |
| | |
| | | #endregion |
| | | |
| | | #region[工序检验,提交] |
| | | public static ToMessage SaveMesOrderStepCheckItem(string stu_torgcode,string wocode, string partcode, string stepcode, string checkstandcode, string check_type, string sampmethod, string qualitystatus, string labqty, string sampleqty, string goodqty, string ngqty, string checkitemcont, string username) |
| | | public static ToMessage SaveMesOrderStepCheckItem(string stu_torgcode, string wocode, string partcode, string stepcode, string checkstandcode, string check_type, string sampmethod, string qualitystatus, string labqty, string sampleqty, string goodqty, string ngqty, string checkitemcont, string username) |
| | | { |
| | | var sql = ""; |
| | | string checktypename = ""; |
| | |
| | | |
| | | |
| | | #region[MES工单批量关闭查询] |
| | | public static ToMessage MesOrderBitchClosedSearch(string stu_torgcode,string stu_torgtypecode,string mesorderstus, string mesordercode, string sourceorder, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderBitchClosedSearch(string stu_torgcode, string stu_torgtypecode, string mesorderstus, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | |
| | | { |
| | | search += "and A.m_po like '%'+@sourceorder+'%' "; |
| | | dynamicParams.Add("@sourceorder", sourceorder); |
| | | } |
| | | if (saleordercode != "" && saleordercode != null) |
| | | { |
| | | search += "and W.saleOrderCode like '%'+@saleordercode+'%' "; |
| | | dynamicParams.Add("@saleordercode", saleordercode); |
| | | } |
| | | if (ordertype != "" && ordertype != null) |
| | | { |
| | |
| | | // --------------查询指定数据-------------- |
| | | 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.org_name as wkshp_name, |
| | | A.route_code,E.name as route_name,A.stck_code,F.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,U.username as lm_user,A.lm_date |
| | | A.route_code,E.name as route_name,A.stck_code,F.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,W.saleOrderCode,U.username as lm_user,A.lm_date |
| | | ,(select sum(S.good_qty) from TK_Wrk_Step S where S.wo_code=A.wo_code and S.isend='Y') as good_qty |
| | | ,(select sum(S.ng_qty) from TK_Wrk_Step S where S.wo_code=A.wo_code and S.isend='Y') as ng_qty |
| | | ,(select sum(S.bad_qty) from TK_Wrk_Step S where S.wo_code=A.wo_code and S.isend='Y') as bad_qty |
| | | 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.sourceid=W.id |
| | | left join TMateriel_Info B on A.materiel_code=B.partcode |
| | | left join TOrganization C on A.wkshp_code=C.org_code |
| | | left join T_Sec_Stck D on A.stck_code=D.code |
| | |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | inner join TK_Wrk_Man M on S.wo_code=M.wo_code |
| | | inner join TMateriel_Info P on M.materiel_code=P.partcode |
| | | left join TKimp_Ewo E on M.sourceid=E.id |
| | | left join TKimp_Ewo E on M.sourceid=E.id |
| | | left join T_Sec_Stck K on E.stck_code=K.code |
| | | where A.style='B' and S.isend='Y' and A.good_qty>0 |
| | | union all |