| | |
| | | using Dapper; |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | |
| | | |
| | | |
| | | #region[ERP订单查询] |
| | | public static ToMessage ErpOrderSearch(string erporderstus, string erpordercode, 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 = ""; |
| | | try |
| | | { |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and C.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (erporderstus != "" && erporderstus != null) |
| | | { |
| | | search += "and A.status=@erporderstus "; |
| | |
| | | { |
| | | search += "and A.wo like '%'+@erpordercode+'%' "; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | } |
| | | if (saleordercode != "" && saleordercode != null) |
| | | { |
| | | search += "and A.saleOrderCode like '%'+@saleordercode+'%' "; |
| | | dynamicParams.Add("@saleordercode", saleordercode); |
| | | } |
| | | if (partcode != "" && partcode != null) |
| | | { |
| | |
| | | // --------------查询指定数据-------------- |
| | | 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.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 |
| | | left join T_Sec_Stck D on A.stck_code=D.code |
| | | left join TUser U on A.createuser=U.usercode |
| | | left join TOrganization L on C.parent_id=L.id |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | |
| | | #endregion |
| | | |
| | | #region[ERP订单下达] |
| | | public static ToMessage MarkSaveErpOrder(string erporderid, string erpordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, 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>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | |
| | | try |
| | | { |
| | | list.Clear(); |
| | |
| | | //获取最大单据号 |
| | | if (i == 1) //首单获取工单号 |
| | | { |
| | | sql = @"select isnull(max(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code))),0)+1 as worknumb from TK_Wrk_Man where m_po=@erpordercode"; |
| | | 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"; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString()); |
| | |
| | | } |
| | | if (i == Convert.ToInt32(ordernum)) //最后一单时 |
| | | { |
| | | 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) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@materiel_code,@sourceid,@m_po,@username,@CreateDate)"; |
| | | 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, |
| | |
| | | sourceid = erporderid, |
| | | m_po = erpordercode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString() |
| | | CreateDate = DateTime.Now.ToString(), |
| | | saleOrderCode = saleordercode, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | sumqty = sumqty + (decimal.Parse(markqty) - sumqty); |
| | |
| | | else |
| | | { |
| | | |
| | | 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) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@materiel_code,@sourceid,@m_po,@username,@CreateDate)"; |
| | | 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, |
| | |
| | | sourceid = erporderid, |
| | | m_po = erpordercode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString() |
| | | CreateDate = DateTime.Now.ToString(), |
| | | saleOrderCode = saleordercode, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | if (decimal.Parse(erpqty) == decimal.Parse(markqty) + decimal.Parse(relse_qty)) //如果ERP订单=下单数量+已下单数量,则更新ERP订单表状态为CREATED:已创建 |
| | | { |
| | | sql = @"update TKimp_Ewo set status='CREATED',relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | 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, |
| | |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid, |
| | | sumqty = sumqty |
| | | sumqty = sumqty, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | } |
| | | else //更新ERP订单表状态为CREATING:创建中 |
| | | { |
| | | sql = @"update TKimp_Ewo set status='CREATING',relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | sql = @"update TKimp_Ewo set status='CREATING',saleOrderDeliveryDate=@saleOrderDeliveryDate,relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid, |
| | | sumqty = sumqty |
| | | sumqty = sumqty, |
| | | 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 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 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 = ""; |
| | | try |
| | | { |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and C.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (mesorderstus != "" && mesorderstus != null) |
| | | { |
| | | search += "and A.status=@mesorderstus "; |
| | |
| | | { |
| | | 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 |
| | | 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 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 |
| | | left join TFlw_Rout E on A.route_code=E.code |
| | | left join T_Sec_Stck F on A.stck_code=F.code |
| | | left join TUser U on A.lm_user=U.usercode |
| | | left join TOrganization L on C.parent_id=L.id |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | |
| | | } |
| | | #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) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | | try |
| | | { |
| | | if (mesordercode != "" && mesordercode != null) |
| | | { |
| | | search += "and A.wo_code like '%'+@mesordercode+'%' "; |
| | | dynamicParams.Add("@mesordercode", mesordercode); |
| | | } |
| | | if (sourceorder != "" && sourceorder != null) |
| | | { |
| | | 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 (partcode != "" && partcode != null) |
| | | { |
| | | search += "and A.materiel_code like '%'+@partcode+'%' "; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | } |
| | | if (partname != "" && partname != null) |
| | | { |
| | | search += "and B.partname like '%'+@partname+'%' "; |
| | | dynamicParams.Add("@partname", partname); |
| | | } |
| | | if (partspec != "" && partspec != null) |
| | | { |
| | | search += "and B.partspec like '%'+@partspec+'%' "; |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | if (createdate != "" && createdate != null) |
| | | { |
| | | search += "and CONVERT(varchar(100),A.lm_date,23)=@createdate "; |
| | | dynamicParams.Add("@createdate", createdate); |
| | | } |
| | | if (creatuser != "" && creatuser != null) |
| | | { |
| | | search += "and U.username like '%'+@creatuser+'%' "; |
| | | dynamicParams.Add("@creatuser", creatuser); |
| | | } |
| | | |
| | | if (search == "") |
| | | { |
| | | search = "and 1=1 "; |
| | | } |
| | | // --------------查询指定数据-------------- |
| | | 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,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 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 |
| | | left join T_Sec_Stck D on A.stck_code=D.code |
| | | left join TFlw_Rout E on A.route_code=E.code |
| | | left join T_Sec_Stck F on A.stck_code=F.code |
| | | left join TUser U on A.lm_user=U.usercode |
| | | where A.is_delete<>'1' and A.status='START' and A.wotype='PO' and S.bad_qty>0 " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data.ToList(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[产品编码查找工艺路线下拉接口] |
| | | public static ToMessage PartSelectRoute(string partcode) |
| | | public static ToMessage PartSelectRoute(string partcode, string wkshopcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | |
| | | sql = @"select R.code,R.name,A.default_route from TMateriel_Info A |
| | | inner join TMateriel_Route M on A.partcode=M.materiel_code |
| | | inner join TFlw_Rout R on M.route_code=R.code |
| | | where A.partcode=@partcode "; |
| | | where A.partcode=@partcode and M.torg_code=@torg_code"; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@torg_code", wkshopcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | |
| | | #endregion |
| | | |
| | | #region[工艺路线查找车间下拉接口] |
| | | public static ToMessage RouteSelectWkshop(string partcode, string routecode) |
| | | public static ToMessage RouteSelectWkshop(string stu_torgcode, string stu_torgtypecode, string partcode) |
| | | { |
| | | string sql = ""; |
| | | string search = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and F.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //获取车间下拉框数据 |
| | | sql = @"select distinct F.org_code,F.org_name from TFlw_Rout A |
| | | inner join TMateriel_Route M on A.code=M.route_code |
| | | inner join TFlw_Rtdt B on A.code=B.rout_code |
| | | sql = @"select distinct F.org_code,F.org_name from TMateriel_Route M |
| | | inner join TFlw_Rtdt B on M.route_code=B.rout_code |
| | | inner join TStep C on B.step_code=C.stepcode |
| | | inner join TFlw_Rteqp D on C.stepcode=D.step_code |
| | | inner join TEqpInfo E on D.eqp_code=E.code |
| | | left join TOrganization F on E.wksp_code=F.org_code |
| | | where A.code=@routecode and M.materiel_code=@partcode "; |
| | | left join TOrganization L on F.parent_id=L.id |
| | | where M.materiel_code=@partcode and E.enable='Y' " + search; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@routecode", routecode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | |
| | | 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); |
| | |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region【生产管理、工单新增、编辑时,选择排程是时获取物料清单版本号】 |
| | | public static ToMessage JobCreationSonAddVison(string partnumber) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | sql = @" select id,version from TBom_Main where materiel_code=@partnumber and status='Y' order by version desc "; |
| | | dynamicParams.Add("@partnumber", partnumber); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[工单派发选择工艺路线或选择生产车间时判断绑定条件] |
| | | public static ToMessage SelectRouteOrWkshop(string partcode, string routecode, string wkshopcode, string is_steprice) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | mes.code = "200"; |
| | | mes.Message = ""; |
| | | mes.data = null; |
| | | //判断工艺路线对应工序是否都有关联工作站 |
| | | sql = @"select B.step_code,C.eqp_code 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 |
| | | where A.code=@routecode and A.torg_code=@wkshopcode"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@routecode", routecode); |
| | | var dtck = DapperHelper.selectdata(sql, dynamicParams); |
| | | for (int i = 0; i < dtck.Rows.Count; i++) |
| | | { |
| | | if (dtck.Rows[i].IsNull("eqp_code")) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工艺路线对应工序【" + dtck.Rows[i]["step_code"].ToString() + "】,未关联设备,请关联所有工序对应设备!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | //判断工作站(设备)是否可用 |
| | | sql = @"select B.step_code from TFlw_Rout A |
| | | inner join TFlw_Rtdt B on A.code=B.rout_code |
| | | where A.code=@routecode and A.torg_code=@wkshopcode"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@routecode", routecode); |
| | | var dtck1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | for (int i = 0; i < dtck1.Rows.Count; i++) |
| | | { |
| | | //工序查找设备 |
| | | sql = @"select E.code,E.name,E.enable |
| | | from TFlw_Rteqp C |
| | | left join TEqpInfo E on C.eqp_code=E.code |
| | | where C.step_code=@step_code and C.torg_code=@wkshopcode"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@step_code", dtck1.Rows[i]["step_code"].ToString()); |
| | | var dtck2 = DapperHelper.selectdata(sql, dynamicParams); |
| | | int query = dtck2.AsEnumerable().Where<DataRow>(a => a["enable"].ToString() == "N").Count(); |
| | | if (dtck2.Rows.Count == query) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工艺路线对应工序【" + dtck.Rows[i]["step_code"].ToString() + "】,设备不可用!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | 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 |
| | | left join TStep S on B.step_code=S.stepcode |
| | | where A.code=@route_code and A.torg_code=@wkshopcode |
| | | ) 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") //判断工序是否为自制 |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[MES工单新增、获取工单号] |
| | | public static ToMessage AddMesOrderCodeSearch() |
| | | { |
| | | string sql = ""; |
| | | string wo_code = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //获取单据号 |
| | | sql = @"SELECT 'SGPO'+CONVERT(varchar(12) , getdate(), 112 )+'_'+cast(isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as varchar) as numct |
| | | FROM TK_Wrk_Man where wo_code like '%SGPO%'"; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data.Rows[0]["numct"].ToString(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | where A.m_id=@bom_id"; |
| | | list.Add(new { str = sql, parm = new { wocode = mesordercode, uomqty = mesqty, bom_id = bom_id } }); |
| | | |
| | | wo_status = "NEW"; |
| | | wrk_status = "NEW"; |
| | | wo_status = "NOSCHED"; |
| | | wrk_status = "NOSCHED"; |
| | | } |
| | | else //否 |
| | | { |
| | |
| | | wrk_status = "ALLO"; |
| | | } |
| | | //写入工单表 |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,plan_startdate,plan_enddate,route_code,stck_code,lm_user,lm_date,materiel_code,m_po,piroque) |
| | | values(@mesordercode,@wotype,@mesorderstus,@wkshopcode,@mesqty,@planstartdate,@planenddate,@routecode,@stck_code,@username,@CreateDate,@materiel_code,@m_po,@orderlev)"; |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,plan_startdate,plan_enddate,route_code,stck_code,lm_user,lm_date,materiel_code,m_po,piroque,isaps) |
| | | values(@mesordercode,@wotype,@mesorderstus,@wkshopcode,@mesqty,@planstartdate,@planenddate,@routecode,@stck_code,@username,@CreateDate,@materiel_code,@m_po,@orderlev,@isaps)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | materiel_code = partcode, |
| | | orderlev = orderlev |
| | | orderlev = orderlev, |
| | | isaps = is_aps |
| | | } |
| | | }); |
| | | //写入工序任务表 |
| | |
| | | } |
| | | }); |
| | | |
| | | //写入工单工艺路线工序工价复制表 |
| | | 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,@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 |
| | | 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, |
| | | wkshopcode = wkshopcode, |
| | | partcode = partcode, |
| | | routecode = routecode, |
| | | usercode = username |
| | | } |
| | | }); |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | |
| | | } |
| | | if (opertype == "Update") |
| | | { |
| | | sql = @"update TK_Wrk_Man set route_code=@routecode,wkshp_code=@wkshopcode,plan_startdate=@planstartdate,plan_enddate=@planenddate,status=@status,piroque=@orderlev,lm_user=@username,lm_date=@CreateDate where wo_code=@mesordercode"; |
| | | if (is_aps == "Y") //是否排程(是) |
| | | { |
| | | //判断物料清单 |
| | | sql = "select id from TBom_Main where materiel_code=@partcode and status='Y' and id=@bom_id"; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@bom_id", bom_id); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count <= 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "工单对应的产品没有建立BOM或BOM未审核!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //增加工单用料表(子件) |
| | | sql = @"insert into TK_Wrk_Allo(wo_code, seq, materiel_code, basqty, qty,bom_id,materieltype,stck_code,stopfeed,base_quantity,loss_quantity,m_quantity) |
| | | select @wocode,A.seq,A.smateriel_code,A.total_quantity,(convert(decimal(18, 0), @uomqty)*A.Base_Quantity*(1+A.LOSS_QUANTITY/100))/C.quantity, |
| | | A.m_id,A.pn_type,'','N',A.base_quantity,A.loss_quantity,C.quantity |
| | | from TBom_Deta A left join TBom_Main C on A.m_Id=C.id |
| | | left join TMateriel_Info B on A.smateriel_code = B.partcode |
| | | where A.m_id=@bom_id"; |
| | | list.Add(new { str = sql, parm = new { wocode = mesordercode, uomqty = mesqty, bom_id = bom_id } }); |
| | | |
| | | wo_status = "NOSCHED"; |
| | | wrk_status = "NOSCHED"; |
| | | } |
| | | else //否 |
| | | { |
| | | wo_status = "ALLO"; |
| | | wrk_status = "ALLO"; |
| | | } |
| | | sql = @"update TK_Wrk_Man set route_code=@routecode,wkshp_code=@wkshopcode,plan_startdate=@planstartdate,plan_enddate=@planenddate,status=@status,piroque=@orderlev,lm_user=@username,lm_date=@CreateDate,isaps=@isaps where wo_code=@mesordercode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | wkshopcode = wkshopcode, |
| | | planstartdate = planstartdate, |
| | | planenddate = planenddate, |
| | | status = "ALLO", //派发 |
| | | status = wo_status, |
| | | routecode = routecode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | orderlev = orderlev |
| | | orderlev = orderlev, |
| | | isaps = is_aps |
| | | } |
| | | }); |
| | | //写入工序任务表 |
| | |
| | | mesqty = mesqty, |
| | | planstartdate = planstartdate, |
| | | planenddate = planenddate, |
| | | status = "ALLO", //派发 |
| | | status = wo_status, |
| | | username = username, |
| | | routecode = routecode, |
| | | CreateDate = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | //删除工单工艺路线工序工价复制表 |
| | | sql = @"delete TWoPrteEqp_Stad where wo=@mesordercode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | mesordercode = mesordercode |
| | | } |
| | | }); |
| | | //写入工单工艺路线工序工价复制表 |
| | | 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,@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 |
| | | 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, |
| | | wkshopcode = wkshopcode, |
| | | partcode = partcode, |
| | | routecode = routecode, |
| | | usercode = username |
| | | } |
| | | }); |
| | | |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //判断工单是否为未开始状态或者已派发状态(满足其中一种都可删除,否则不允许删除) |
| | | sql = @"select * from TK_Wrk_Man where wo_code=@wocode and status='NEW' or status='ALLO'"; |
| | | //判断工单是否为未开始状态或者已派发或待排程状态(满足其中一种都可删除,否则不允许删除) |
| | | sql = @"select * from TK_Wrk_Man where wo_code=@wocode and status in('NEW','ALLO','NOSCHED')"; |
| | | dynamicParams.Add("@wocode", wocode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | |
| | | } |
| | | //删除工单工序表 |
| | | sql = @"delete TK_Wrk_Step where wo_code=@wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode } }); |
| | | |
| | | //删除加工单用料表(子件) |
| | | sql = @"delete TK_Wrk_Allo where wo_code=@wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode } }); |
| | | |
| | | //删除工单表 |
| | |
| | | left join TStep B on A.step_code=B.stepcode |
| | | left join TK_Wrk_Man M on A.wo_code=M.wo_code |
| | | left join TMateriel_Info P on M.materiel_code=P.partcode |
| | | where A.wo_code=@wo_code"; |
| | | where A.wo_code=@wo_code order by A.seq"; |
| | | dynamicParams.Add("@wo_code", wo_code); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(自制)] |
| | | public static ToMessage MesOrderStepSearch(string orderstepqrcode, int startNum, int endNum, string prop, string order) |
| | | #region[MES工单打印更新打印次数] |
| | | public static ToMessage UpdateMesOrderPrintCount(string wo_code) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | | 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) |
| | | { |
| | | var sql = ""; |
| | | string search = "";//定义一个查询参数,查询条件有前端传入 |
| | | string ordercode = ""; |
| | | string stepcode = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | var total = 0; //总条数 |
| | | try |
| | | { |
| | | if (orderstepqrcode != "" && orderstepqrcode != null) |
| | |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && ordercode != null) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | } |
| | | if (ordercode != "" && stepcode != "") //工单号不为空,工序号不为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | search += "and S.stepcode=@stepcode "; |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // mes.code = "300"; |
| | | // mes.count = 0; |
| | | // mes.Message = "二维码信息为空!"; |
| | | // mes.data = null; |
| | | // return mes; |
| | | //} |
| | | if (stepcode != "") |
| | | { |
| | | //查找当前工序属性 |
| | |
| | | } |
| | | } |
| | | } |
| | | //根据条件查询工单工序设备(自制工序) |
| | | sql = @"select B.eqp_code,E.name as eqp_name from TK_Wrk_Step A |
| | | inner join TFlw_Rteqp B on A.step_code=B.step_code |
| | | left join TEqpInfo E on B.eqp_code=E.code |
| | | where B.style='E' and A.wo_code=@ordercode and A.step_code=@stepcode |
| | | order by B.eqp_code"; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | return mes; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务无可执行设备!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取当前工序对应的供方(外协)] |
| | | public static ToMessage MesOrderWxStepEqpSearch(string orderstepqrcode) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | | string ordercode = ""; |
| | | string stepcode = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (orderstepqrcode != "" && orderstepqrcode != null) |
| | | { |
| | | string[] arra = orderstepqrcode.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) //工单号+工序号二维码 |
| | | { |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | } |
| | | if (stepcode != "") |
| | | { |
| | | //查找当前工序属性 |
| | | sql = @"select * from TStep where stepcode=@stepcode"; |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data0.Rows.Count > 0) |
| | | { |
| | | if (data0.Rows[0]["FLWTYPE"].ToString() == "Z") |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务为自制工序任务,请前往自制操作页签执行!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | //根据条件查询工单工序外协供方(外协工序) |
| | | sql = @"select B.eqp_code as customercode,C.name as customername from TK_Wrk_Step A |
| | | inner join TFlw_Rteqp B on A.step_code=B.step_code |
| | | left join TCustomer C on B.eqp_code=C.code |
| | | where B.style='W' and A.wo_code=@ordercode and A.step_code=@stepcode |
| | | order by B.eqp_code"; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | return mes; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序无可执行外协供方!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(自制)] |
| | | 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 = ""; |
| | | string ordercode = ""; |
| | | string stepcode = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | var total = 0; //总条数 |
| | | try |
| | | { |
| | | if (wocode != "" && wocode != null) |
| | | { |
| | | string[] arra = wocode.Split(';'); |
| | | if (arra.Length == 1) //工单号二维码 |
| | | { |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | } |
| | | if (arra.Length == 2) //工单号+工序号二维码 |
| | | { |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code like '%'+@ordercode+'%' "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | } |
| | | if (ordercode != "" && stepcode != "") //工单号不为空,工序号不为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | search += "and S.stepcode=@stepcode "; |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | } |
| | | } |
| | | if (stepcode != "") |
| | | { |
| | | //查找当前工序属性 |
| | | sql = @"select * from TStep where stepcode=@stepcode"; |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data0.Rows.Count > 0) |
| | | { |
| | | if (data0.Rows[0]["FLWTYPE"].ToString() == "W") |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务为外协工序任务,请前往外协操作页签执行!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and F.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | 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 |
| | | from TK_Wrk_Step A |
| | | left join TK_Wrk_Man B on A.wo_code=B.wo_code |
| | | left join TMateriel_Info M on B.materiel_code=M.partcode |
| | | left join TStep S on A.step_code=S.stepcode |
| | | where A.status<>'CLOSED' and S.flwtype='Z' " + search; |
| | | 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 |
| | | left join TOrganization L on F.parent_id=L.id |
| | | where A.status in('ALLO','START') and S.flwtype='Z' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | if (data.ToList().Count > 0) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.data = null; |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(外协)] |
| | | public static ToMessage MesOrderWxStepSearch(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 = ""; |
| | |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | if (ordercode != "" && ordercode != null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | } |
| | | } |
| | | } |
| | | //根据条件查询工单工序任务(自制工序) |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and F.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //根据条件查询工单工序任务(外协工序) |
| | | 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 |
| | | 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 |
| | | where A.status<>'CLOSED' and S.flwtype='W' " + search; |
| | | left join TOrganization F on B.wkshp_code=F.org_code |
| | | left join TOrganization L on F.parent_id=L.id |
| | | where A.status in('ALLO','START') and S.flwtype='W' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | if (data.ToList().Count > 0) |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(不良)] |
| | | public static ToMessage MesOrderNgStepSearch(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 = ""; |
| | |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | if (ordercode != "" && ordercode != null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | return mes; |
| | | } |
| | | } |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and F.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //根据条件查询工单工序任务,且不良数量大于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 |
| | | from TK_Wrk_Step A |
| | | left join TK_Wrk_Man B on A.wo_code=B.wo_code |
| | | left join TMateriel_Info M on B.materiel_code=M.partcode |
| | | left join TStep S on A.step_code=S.stepcode |
| | | where A.status<>'CLOSED' and A.ng_qty>0 " + search; |
| | | 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 |
| | | left join TOrganization L on F.parent_id=L.id |
| | | where A.status in('ALLO','START') and A.ng_qty>0 " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | if (data.ToList().Count > 0) |
| | | { |
| | |
| | | } |
| | | } |
| | | //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 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(ordercode, stepcode); |
| | | mes = ScanStartReport.ZZEncodingSeach(stu_torgcode, SelectType, ordercode, stepcode); |
| | | break; |
| | | case "WX": |
| | | mes = ScanStartReport.WXEncodingSeach(SelectType, ordercode, stepcode); |
| | | mes = ScanStartReport.WXEncodingSeach(stu_torgcode, SelectType, ordercode, stepcode); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | return mes; |
| | | } |
| | | //获取工序关联的设备 |
| | | sql = @"select B.code,B.name from TFlw_Rteqp A |
| | | sql = @"select B.code,B.name from TK_Wrk_Man M |
| | | inner join TFlw_Rtdt R on M.route_code=R.rout_code |
| | | inner join TFlw_Rteqp A on R.step_code=A.step_code |
| | | left join TEqpInfo B on A.eqp_code=B.code |
| | | where A.style='E' and A.step_code=@stepcode"; |
| | | where A.style='E' and M.wo_code=@wo_code and A.step_code=@stepcode and B.enable='Y'"; |
| | | dynamicParams.Add("@wo_code", ordercode); |
| | | dynamicParams.Add("@stepcode", stepcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | 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) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工:报工时获取生产班组下拉框] |
| | | public static ToMessage MesOrderStepReportSelectUserGroup(string stu_torgcode, string stu_torgtypecode, string wkshopcode) |
| | | { |
| | | string sql = ""; |
| | | string search = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and A.torg_code=@workShop "; |
| | | dynamicParams.Add("@workShop", wkshopcode); |
| | | } |
| | | else |
| | | { |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | search += "and T.description=@description "; |
| | | dynamicParams.Add("@description", "W"); |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | } |
| | | } |
| | | //获取用户组 |
| | | 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; |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工:报工时获取生产班组下拉框] |
| | | public static ToMessage MesOrderStepReportSelectUserGroup() |
| | | { |
| | | string sql = ""; |
| | | try |
| | | { |
| | | //获取用户组 |
| | | sql = @"select group_code,group_name from TGroup"; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工:根据生产班组查找人员列表] |
| | | public static ToMessage MesOrderGroupSelectUser(string usergroupcode) |
| | | public static ToMessage MesOrderGroupSelectUser(string stu_torgcode, string usergroupcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //班组获取人员列表 |
| | | sql = @"select usercode,username from TUser where usergroup_code=@usergroupcode and is_delete<>'1'"; |
| | | 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 |
| | | where G.torg_code=@stu_torgcode and G.group_code=@usergroupcode"; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | dynamicParams.Add("@usergroupcode", usergroupcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | |
| | | 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 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(); |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | //截取报工人员 |
| | | arra = reportuser.Split(';'); |
| | | if (ngqty != "" || ngqty != "0") |
| | | //获取报工人员、分配比例 |
| | | JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(reportuser); |
| | | //判断是否有不良数据 |
| | | 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 A.style='S'"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | 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) |
| | | values(@mesordercode,@stepseq,@stepcode,@eqpcode,@partcode,@taskqty,@startqty,@reportqty,@ngqty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = username, lm_date = date } }); |
| | | 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)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = username, lm_date = date, inbarcode = inbarcode } }); |
| | | |
| | | //写入子表 |
| | | for (int i = 0; i < arra.Length; i++) |
| | | for (int i = 0; i < arra.Count; i++) |
| | | { |
| | | sql = @"insert into TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,usergroup_code,ng_qty,style,lm_user,lm_date) |
| | | values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@usergroup_code,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), eqp_code = eqpcode, report_person = arra[i], report_date = date, report_qty = reportqty, usergroup_code = usergroupcode, ng_qty = ngqty, style = "B", lm_user = username, lm_date = date } }); |
| | | sql = @"insert into TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,reckway,usergroup_code,ratio,ng_qty,style,lm_user,lm_date) |
| | | values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@reckway,@usergroup_code,@ratio,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(dt.Rows[0]["ID"].ToString()), |
| | | eqp_code = eqpcode, |
| | | report_person = arra[i]["usercode"].ToString(), |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = decimal.Parse(arra[i]["ratio"].ToString()), |
| | | ng_qty = ngqty, |
| | | 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 } }); |
| | | |
| | | } |
| | | } |
| | |
| | | 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) |
| | | values(@mesordercode,@stepseq,@stepcode,@eqpcode,@partcode,@taskqty,@startqty,@reportqty,@ngqty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = username, lm_date = date } }); |
| | | 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)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = username, lm_date = date, inbarcode = inbarcode } }); |
| | | |
| | | //写入子表 |
| | | for (int i = 0; i < arra.Length; i++) |
| | | for (int i = 0; i < arra.Count; i++) |
| | | { |
| | | sql = @"insert into TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,usergroup_code,ng_qty,style,lm_user,lm_date) |
| | | values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@usergroup_code,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), eqp_code = eqpcode, report_person = arra[i], report_date = date, report_qty = reportqty, usergroup_code = usergroupcode, ng_qty = ngqty, style = "B", lm_user = username, lm_date = date } }); |
| | | sql = @"insert into TK_Wrk_RecordSub(m_id,eqp_code,report_person,report_date,report_qty,reckway,usergroup_code,ratio,ng_qty,style,lm_user,lm_date) |
| | | values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@reckway,@usergroup_code,@ratio,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(dt.Rows[0]["ID"].ToString()), |
| | | eqp_code = eqpcode, |
| | | report_person = arra[i]["usercode"].ToString(), |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = decimal.Parse(arra[i]["ratio"].ToString()), |
| | | ng_qty = ngqty, |
| | | 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 } }); |
| | | |
| | | } |
| | | } |
| | |
| | | //sql = @"update TK_Wrk_Man set good_qty=good_qty+@reportqty,ng_qty=ng_qty+@ngqty where wo_code=@mesordercode"; |
| | | //list.Add(new { str = sql, parm = new { mesordercode = mesordercode, reportqty = reportqty, ngqty = ngqty } }); |
| | | |
| | | //写入ERP入库单 |
| | | |
| | | //判断是否末道工序完工报工(自动关闭工单及工序任务) |
| | | //list = AutosCloseOrder.AutosColseOrderReport(list,mesordercode, partcode, stepseq,stepcode,reportqty,ngqty); |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工, 收料提交] |
| | | public static ToMessage SavaMesOrderStepIn(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, 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; |
| | |
| | | sql = @"select ISNULL(IDENT_CURRENT('TK_Wrk_OutRecord')+1,1) as id"; |
| | | var dt = DapperHelper.selecttable(sql); |
| | | //写入外协记录主表 |
| | | sql = @"insert into TK_Wrk_OutRecord(wo_code,step_seq,step_code,wx_code,materiel_code,style,sqty,ng_qty,lm_user,lm_date) |
| | | values(@mesordercode,@stepseq,@stepcode,@wx_code,@partcode,@style,@sqty,@ngqty,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, wx_code = wxcode, partcode = partcode, style = 'S', sqty = sqty, ngqty = ngqty, lm_user = username, lm_date = date } }); |
| | | sql = @"insert into TK_Wrk_OutRecord(wo_code,step_seq,step_code,wx_code,materiel_code,style,sqty,ng_qty,lm_user,lm_date,inbarcode) |
| | | values(@mesordercode,@stepseq,@stepcode,@wx_code,@partcode,@style,@sqty,@ngqty,@lm_user,@lm_date,@inbarcode)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, wx_code = wxcode, partcode = partcode, style = 'S', sqty = sqty, ngqty = ngqty, lm_user = username, lm_date = date, inbarcode = inbarcode } }); |
| | | |
| | | //写入外协记录子表 |
| | | sql = @"insert into TK_Wrk_OutRecordSub(m_id,wx_code,in_person,in_time,sqty,ng_qty,style,lm_user,lm_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 } }); |
| | | |
| | | } |
| | | } |
| | |
| | | sql = @"select ISNULL(IDENT_CURRENT('TK_Wrk_OutRecord')+1,1) as id"; |
| | | var dt = DapperHelper.selecttable(sql); |
| | | //写入外协记录主表 |
| | | sql = @"insert into TK_Wrk_OutRecord(wo_code,step_seq,step_code,wx_code,materiel_code,style,sqty,ng_qty,lm_user,lm_date) |
| | | values(@mesordercode,@stepseq,@stepcode,@wx_code,@partcode,@style,@sqty,@ngqty,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, wx_code = wxcode, partcode = partcode, style = 'S', sqty = sqty, ngqty = ngqty, lm_user = username, lm_date = date } }); |
| | | sql = @"insert into TK_Wrk_OutRecord(wo_code,step_seq,step_code,wx_code,materiel_code,style,sqty,ng_qty,lm_user,lm_date,inbarcode) |
| | | values(@mesordercode,@stepseq,@stepcode,@wx_code,@partcode,@style,@sqty,@ngqty,@lm_user,@lm_date,@inbarcode)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, wx_code = wxcode, partcode = partcode, style = 'S', sqty = sqty, ngqty = ngqty, lm_user = username, lm_date = date, inbarcode = inbarcode } }); |
| | | |
| | | //写入外协记录子表 |
| | | sql = @"insert into TK_Wrk_OutRecordSub(m_id,wx_code,in_person,in_time,sqty,ng_qty,style,lm_user,lm_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 } }); |
| | | |
| | | } |
| | | } |
| | |
| | | //回写工单表合格数量、不良数量 |
| | | //sql = @"update TK_Wrk_Man set good_qty=good_qty+@sqty,ng_qty=ng_qty+@ngqty where wo_code=@mesordercode"; |
| | | //list.Add(new { str = sql, parm = new { mesordercode = mesordercode, sqty = sqty, ngqty = ngqty } }); |
| | | |
| | | ////写入ERP入库单 |
| | | |
| | | //判断是否末道工序完工报工(自动关闭工单及工序任务) |
| | | //list = AutosCloseOrder.AutosColseOrderReport(list, mesordercode, partcode, stepseq, stepcode, sqty, ngqty); |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | |
| | | 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 MesOrderStepCheckSearch(string orderstepqrcode) |
| | | |
| | | |
| | | #region[工序检验扫码获取任务信息] |
| | | public static ToMessage MesOrderStepCheckSearch(string stu_torgcode, string orderstepqrcode, string checktype) |
| | | { |
| | | var sql = ""; |
| | | string ordercode = ""; |
| | | string stepcode = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | Dictionary<string, object> list = new Dictionary<string, object>(); |
| | | try |
| | | { |
| | | if (orderstepqrcode != "" && orderstepqrcode != null) |
| | |
| | | ordercode = arra[0]; //获取指定字符串前面的字符 |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | //判断当前工单是否关闭 |
| | | sql = @"select * from TK_Wrk_Man where wo_code=@ordercode and wkshp_code=@stu_torgcode and status='CLOSED'"; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | var da0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (da0.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工单已关闭,不允许检验操作!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | //0.判断当前工单所属车间是否为当前登录人员车间 |
| | | sql = @"select * from TK_Wrk_Man where wo_code=@ordercode and wkshp_code=@stu_torgcode"; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | var da1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (da1.Rows.Count <= 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "不是本车间生产任务,不允许检验操作!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | //通过扫描二维码信息查找任务信息 |
| | | sql = @"select A.wo_code,M.partcode,M.partname,M.partspec,S.stepcode,S.stepname |
| | | sql = @"select A.wo_code,A.good_qty,M.partcode,M.partname,M.partspec,M.stocktype_code,S.stepcode,S.stepname |
| | | from TK_Wrk_Step A |
| | | inner join TK_Wrk_Man P on A.wo_code=P.wo_code |
| | | left join TMateriel_Info M on P.materiel_code=M.partcode |
| | |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | return mes; |
| | | if (decimal.Parse(data.Rows[0]["good_qty"].ToString()) > 0) |
| | | { |
| | | //获取绑定的质检方案、抽样方式、样本数 |
| | | sql = @"select code as checkstandcode,name as checkstandname,sampmethod,sampscare |
| | | from TStepCheckStandard |
| | | where (PATINDEX('%,' + RTRIM(@partcode) + ',%',',' + suitpart + ',')>0 or PATINDEX('%,' + RTRIM(@stocktype_code) + ',%',',' + suitpart + ',')>0) |
| | | and checktype=@checktype and stepcode=@stepcode "; |
| | | dynamicParams.Add("@partcode", data.Rows[0]["partcode"].ToString());//物料编码 |
| | | dynamicParams.Add("@stepcode", stepcode);//工序编码 |
| | | dynamicParams.Add("@stocktype_code", data.Rows[0]["stocktype_code"].ToString());//存货类型编码 |
| | | dynamicParams.Add("@checktype", checktype);//检验类型 |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data1.Rows.Count > 0) |
| | | { |
| | | list.Add("labcont", data); |
| | | list.Add("chekstand", data1); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = list; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前产品【" + data.Rows[0]["partname"].ToString() + "】,对应工序【" + data.Rows[0]["stepname"].ToString() + "】,未指定质检方案!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务无报工产出!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验获取检验标准下拉框数据] |
| | | public static ToMessage MesOrderStepCheckSelect() |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //获取工序检验标准 |
| | | sql = @"select code,name from TStepCheckStandard where is_delete<>'1'"; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验根据检验标准获取检验项目列表] |
| | | #region[工序检验根据选择的检验方案查找检验项目] |
| | | public static ToMessage MesOrderStepCheckItemList(string checkstandcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //根据检验标准编码获取工序检验项目 |
| | | sql = @"select B.code,B.name,A.stepcheckitem_desc,A.stepcheckitem_seq from TStepCheckStandardSub A |
| | | //质检方案编码获取检验项 |
| | | sql = @"select A.stepcheckitem_seq, B.code,B.name,A.required,A.numberjudge,A.unit,A.decimalnum, |
| | | A.standvalue,A.uppervalue,A.lowervalue,A.stepcheckitem_desc |
| | | from TStepCheckStandardSub A |
| | | left join TStepCheckItem B on A.stepcheckitem_code=B.code |
| | | where B.is_delete<>'1' and A.stepstaned_code=@checkstandcode"; |
| | | dynamicParams.Add("@checkstandcode", checkstandcode); |
| | | where A.stepstaned_code=@checkstandcode |
| | | order by A.stepcheckitem_seq"; |
| | | dynamicParams.Add("@checkstandcode", checkstandcode);//质检方案编码 |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前质检方案无检验项!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验提交保存] |
| | | public static ToMessage SaveMesOrderStepCheckItem(string mesordercode, string partcode, string stepcode, string checkstanedcode, string checkusercode, string checktypecode, string checkresult, string checkdescr, string checkqty, string username, List<StepCheck> json) |
| | | #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) |
| | | { |
| | | var sql = ""; |
| | | string[] arra = new string[] { }; |
| | | string[] arra1 = new string[] { }; |
| | | List<object> list = new List<object>(); |
| | | string checktypename = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | |
| | | string datetime = DateTime.Now.ToString(); //获取系统时间 |
| | | //获取检验项目信息 |
| | | JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(checkitemcont); |
| | | list.Clear(); |
| | | switch (checktypecode) |
| | | |
| | | //写入检验记录主表 |
| | | sql = @"insert into TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,sampmethod,check_result,check_qty,good_qty,ng_qty,lm_user,lm_date,torg_code) |
| | | values(@wo_code,@partcode,@step_code,@checkstaned_code,@check_user,@check_type,@check_typename,@sampmethod,@check_result,@check_qty,@good_qty,@ng_qty,@lm_user,@lm_date,@torg_code)"; |
| | | switch (check_type) |
| | | { |
| | | case "FirstCheck": |
| | | checktypename = "首检"; |
| | |
| | | default: |
| | | break; |
| | | } |
| | | //写入工序检验记录主表 |
| | | sql = @"insert into TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,check_result,check_descr,check_qty,lm_user,lm_date) |
| | | values(@mesordercode,@partcode,@stepcode,@checkstanedcode,@checkusercode,@checktypecode,@checktypename,@checkresult,@checkdescr,@check_qty,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, partcode = partcode, stepcode = stepcode, checkstanedcode = checkstanedcode, checkusercode = checkusercode, checktypecode = checktypecode, checktypename = checktypename, checkresult = checkresult, checkdescr = checkdescr, check_qty = checkqty, lm_user = username, lm_date = date } }); |
| | | //写入工序检验记录子表 |
| | | //获取主表最大ID |
| | | sql = @"select ISNULL(IDENT_CURRENT('TStepCheckRecord')+1,1) as id"; |
| | | var dt = DapperHelper.selecttable(sql); |
| | | for (int i = 0; i < json.Count; i++) |
| | | list.Add(new |
| | | { |
| | | sql = @"insert into TStepCheckRecordSub(m_id,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_result,lm_user,lm_date) |
| | | values(@m_id,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_result,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), checkiem_seq = int.Parse(json[i].seq), checkitem_code = json[i].code, checkitem_name = json[i].name, checkitem_descr = json[i].descr, check_result = json[i].checkresult, lm_user = username, lm_date = date } }); |
| | | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo_code = wocode, |
| | | partcode = partcode, |
| | | step_code = stepcode, |
| | | checkstaned_code = checkstandcode, |
| | | check_user = username, |
| | | check_type = check_type, |
| | | check_typename = checktypename, |
| | | sampmethod = sampmethod, |
| | | check_result = qualitystatus, |
| | | check_qty = decimal.Parse(sampleqty), |
| | | good_qty = decimal.Parse(goodqty), |
| | | ng_qty = decimal.Parse(ngqty), |
| | | lm_user = username, |
| | | lm_date = datetime, |
| | | torg_code = stu_torgcode |
| | | } |
| | | }); |
| | | //写入检验记录子表 |
| | | for (int j = 0; j < arra.Count; j++) |
| | | { |
| | | sql = @"insert into TStepCheckRecordSub(m_id,checknum,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_value,check_result,lm_user,lm_date,torg_code) |
| | | values(CONVERT(INT,IDENT_CURRENT('TStepCheckRecord')),@checknum,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_value,@check_result,@lm_user,@lm_date,@torg_code)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | checknum = arra[j]["checknum"].ToString(), |
| | | checkiem_seq = arra[j]["checkiem_seq"].ToString(), |
| | | checkitem_code = arra[j]["checkitem_code"].ToString(), |
| | | checkitem_name = arra[j]["checkitem_name"].ToString(), |
| | | checkitem_descr = arra[j]["checkitem_descr"].ToString(), |
| | | check_value = arra[j]["check_value"].ToString(), |
| | | check_result = arra[j]["check_result"].ToString(), |
| | | lm_user = username, |
| | | lm_date = datetime, |
| | | torg_code = stu_torgcode |
| | | } |
| | | }); |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "检验成功!"; |
| | | mes.Message = "操作成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "检验失败!"; |
| | | mes.Message = "操作失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | |
| | | #region[MES工单批量关闭查询] |
| | | public static ToMessage MesOrderBitchClosedSearch(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 = ""; |
| | | try |
| | | { |
| | | switch (stu_torgtypecode) |
| | | { |
| | | case "": |
| | | break; |
| | | case "D": |
| | | search += "and L.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | case "W": |
| | | search += "and C.org_code=@stu_torgcode "; |
| | | dynamicParams.Add("@stu_torgcode", stu_torgcode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (mesorderstus != "" && mesorderstus != null) |
| | | { |
| | | search += "and A.status=@mesorderstus "; |
| | |
| | | { |
| | | 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 |
| | | left join TFlw_Rout E on A.route_code=E.code |
| | | left join T_Sec_Stck F on A.stck_code=F.code |
| | | left join TUser U on A.lm_user=U.usercode |
| | | left join TOrganization L on C.parent_id=L.id |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | |
| | | List<CapaPlan> list4 = ids1.Except(ids).ToList(); //表示ids1中哪些值是ids中所不存在的; |
| | | list4 = list3.Union(list4).ToList(); |
| | | //查找关键工序设备、工位群组的所有设备 |
| | | string sql3 = @"select * from( |
| | | select distinct A.code,A.name from TEqpInfo A |
| | | string sql3 = @"select distinct A.code,A.name from TEqpInfo A |
| | | left join TFlw_Rteqp B on A.code=B.eqp_code |
| | | left join TFlw_Rtdt D on B.step_code=D.step_code |
| | | where A.wksp_code=@wkshopcode and D.first_choke='Y' order by A.code)"; |
| | | where A.wksp_code=@wkshopcode and D.first_choke='Y' order by A.code"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | var dt3 = DapperHelper.selectdata(sql3, dynamicParams); |
| | | if (list4.Count > 0) //如果日期有变动 |
| | |
| | | } |
| | | } |
| | | //更新排产生产资源主表 |
| | | sql = @"update gn_wkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_time=@lm_time where id=@id"; |
| | | sql = @"update TWkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_date=@lm_time where id=@id"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | //循环写入排产生产资源子表 |
| | | for (int i = 0; i < objs.Count; i++) |
| | | { |
| | | sql = @"insert into TWkm_capac_plan_sub(m_id,wkdate,wkshift_code) values()"; |
| | | sql = @"insert into TWkm_capac_plan_sub(m_id,wkdate,wkshift_code) values(@m_id,@wkdate,@wkshift_code)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | A.plan_qty AdvaScheQty, |
| | | U.name AdvaScheUom, |
| | | isnull(E.sched_qty,0) AdvaScheYPQty, |
| | | CONVERT(varchar(100), B.planenddate, 23) AdvaScheEndDate, |
| | | CONVERT(varchar(100), A.saleOrderDeliveryDate, 23) AdvaScheEndDate, |
| | | convert(varchar(20),isnull(E.sched_qty,0))+'/'+convert(varchar(20),isnull(A.plan_qty,0)) AdvaScheSpeed, |
| | | A.route_code AdvaScheRoutid, |
| | | F.name AdvaScheRoutName, |
| | |
| | | (case when CONVERT(varchar(100), H.maxtime, 23)<=CONVERT(varchar(100), E.plan_enddate, 23) then 'Y' when H.MAXTime is null then 'Y' else 'N' end) Flag, |
| | | (case when A.PiroQue='1' then '特急' when A.PiroQue='2' then '紧急' when A.PiroQue='3' then '正常' end) AdvaSchePiroQue |
| | | from TK_Wrk_Man A |
| | | left join TKimp_Ewo B on A.m_po=B.wo |
| | | left join TMateriel_Info C on C.partcode= A.materiel_code |
| | | left join T_Dict D on C.stocktype_code= d.code |
| | | left join TK_Wrk_Step E on E.wo_code=A.wo_code |
| | |
| | | left join (select wo_code, max(TIME_END) MAXTime,min(time_start) MINTime from TK_Wrk_EqpAps group by wo_code) H on A.wo_code=H.wo_code |
| | | left join TUom U on C.uom_code=U.code |
| | | left join TOrganization M on A.wkshp_code=M.org_code |
| | | where E.isbott = 'Y' and A.status='NEW' and A.isaps='Y'"; |
| | | where E.isbott = 'Y' and A.status='NOSCHED' and A.isaps='Y' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | |
| | | return list; |
| | | } |
| | | bool IsCap = false; //是否设置产能 |
| | | //通过工单查找工艺路线对应关键工序所关联的设备是否可用 |
| | | //通过工单查找对应车间工艺路线下关键工序所关联的设备是否可用 |
| | | sql = @"select distinct C.eqp_code ,D.Enable from TK_Wrk_Man A |
| | | left join TFlw_Rout K on A.route_code=K.code |
| | | left join TFlw_Rtdt B on K.code=B.rout_code and B.first_choke='Y' |
| | | left join TFlw_Rteqp C on B.step_code= C.step_code |
| | | left join TEqpInfo D on C.eqp_code=D.code |
| | | where A.wo_code=@wocode and A.materiel_code=@partcode"; |
| | | where A.wo_code=@wocode and A.materiel_code=@partcode and D.wksp_code=@wkshpcode"; |
| | | dynamicParams.Add("@wocode", wocode); |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@wkshpcode", wkshpcode); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt_0.Rows.Count > 0) |
| | | { |
| | |
| | | string sy = "0"; |
| | | for (int i = 0; i < dt0.Rows.Count; i++) |
| | | { |
| | | if (dt0.Rows[i]["WKSHOP"].ToString() == wkshpcode) //工单创建车间是否等于排产设备 车间 |
| | | if (dt0.Rows[i]["WKSP_CODE"].ToString() == wkshpcode) //工单创建车间是否等于排产设备 车间 |
| | | { |
| | | sy = "1"; |
| | | break; |
| | |
| | | mes.count = 0; |
| | | mes.Message = "排产设备车间与工单创建的车间不同!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | else |
| | | { |
| | |
| | | from TWkm_capac_plan E |
| | | left join TWkm_capac_plan_sub F on E.id=F.m_id |
| | | left join TBas_wkshift_info G on F.wkshift_code=G.code |
| | | where E.wkshop='CJ001'and E.eqp_typecode='SBLX001' and E.ClassType='D' |
| | | and CONVERT(varchar(100), F.wkdate, 23)='2022-10-11' and E.enable='Y'"; |
| | | where E.wkshop=@wkshop and E.eqp_typecode=@eqp_typecode and E.ClassType=@classtype |
| | | and CONVERT(varchar(100), F.wkdate, 23)=@wkdate and E.enable='Y'"; |
| | | dynamicParams.Add("@wkshop", wkshpcode); |
| | | dynamicParams.Add("@eqp_typecode", listData[j].Style.ToString()); |
| | | dynamicParams.Add("@classtype", listData[j].ClassType.ToString()); |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "排程设备未设置产能!"; |
| | | mes.Message = "当前工单加工产品对应工艺路线设备未设置产能或未设置生产节拍!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | public static DataTable AlreadyScheduling(string wocode, string wkshpcode, string partcode, string botproccode, string startdate, string enddate) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | DataTable dt; |
| | | try |
| | | { |
| | | List<APSList> listData = SchedulingMethod.SchedulingMethodTF(wocode, wkshpcode, partcode); |
| | | string[] empIds = listData.Select(a => a.eqp_id).ToArray(); |
| | | string str = string.Join(",", empIds); |
| | | string s1 = string.Format("'{0}'", str.Replace(",", "','")); |
| | | string[] s1 = Array.ConvertAll<string, string>(str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] |
| | | //string s1 = string.Format("'{0}'", str.Replace(",", "','")); |
| | | |
| | | string sql = @"select B.wo_code, B.eqp_code,B.time_start,B.time_end, 'S' status , B.alloc_qty,D.partname as part_name |
| | | string sql = @"select B.wo_code, B.eqp_code,B.time_start,B.time_end, 'S' status , B.alloc_qty,D.partcode as part_code,D.partname as part_name,T.name as uom_name |
| | | from TK_Wrk_EqpAps B |
| | | left join TK_Wrk_Man C on B.wo_code=C.wo_code |
| | | left join TMateriel_Info D on C.materiel_code=D.partcode |
| | | where B.eqp_code in(@s1) |
| | | left join TUom T on D.uom_code=T.code |
| | | where B.eqp_code in @eqpcode |
| | | and convert(varchar(100),B.Time_Start,21)>=@startdate and convert(varchar(100),B.Time_End,21)<=@enddate order by time_end"; |
| | | dynamicParams.Add("@s1", s1); |
| | | dynamicParams.Add("@startdate", startdate + " 00:00:00"); |
| | | dynamicParams.Add("@enddate", enddate + " 23:59:59"); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | dt = DapperHelper.selectlist(sql, new { eqpcode = s1.ToArray(), startdate = startdate + " 00:00:00", enddate = enddate + " 23:59:59" }); |
| | | //dynamicParams.Add("@s1", new { shopcode = s1.ToArray() }); |
| | | //dynamicParams.Add("@startdate", startdate + " 00:00:00"); |
| | | //dynamicParams.Add("@enddate", enddate + " 23:59:59"); |
| | | //var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt == null || dt.Rows.Count == 0) |
| | | { |
| | | return null; |
| | |
| | | } |
| | | |
| | | return dt; |
| | | } |
| | | #endregion |
| | | |
| | | #region[NEW排产设备信息] |
| | | public static List<AdvancedSchedulingDevice> NewOnclickAdvancedSchedulingDevice(List<ApsOrderSerch> json, ref ToMessage mes) |
| | | { |
| | | string sql = "", sql0 = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | List<AdvancedSchedulingDevice> list = new List<AdvancedSchedulingDevice>(); |
| | | DataTable dt, dt1; |
| | | //List<ApsOrderSerch> json = new List<ApsOrderSerch>(); |
| | | try |
| | | { |
| | | for (int w = 0; w < json.Count; w++) |
| | | { |
| | | |
| | | |
| | | DateTime beginDate = Convert.ToDateTime(json[w].startdate); |
| | | DateTime endDate = DateTime.Parse(json[w].enddate); |
| | | if (beginDate > endDate) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "要求交付时间不能小于当前系统时间!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | bool IsCap = false; //是否设置产能 |
| | | //通过工单查找对应车间工艺路线下关键工序所关联的设备是否可用 |
| | | sql = @"select distinct C.eqp_code ,D.Enable from TK_Wrk_Man A |
| | | left join TFlw_Rout K on A.route_code=K.code |
| | | left join TFlw_Rtdt B on K.code=B.rout_code and B.first_choke='Y' |
| | | left join TFlw_Rteqp C on B.step_code= C.step_code |
| | | left join TEqpInfo D on C.eqp_code=D.code |
| | | where A.wo_code=@wocode and A.materiel_code=@partcode and D.wksp_code=@wkshpcode"; |
| | | dynamicParams.Add("@wocode", json[w].wocode); |
| | | dynamicParams.Add("@partcode", json[w].partcode); |
| | | dynamicParams.Add("@wkshpcode", json[w].wkshpcode); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt_0.Rows.Count > 0) |
| | | { |
| | | int cout = dt_0.Rows.Count; |
| | | int num = 0; |
| | | for (int m = 0; m < dt_0.Rows.Count; m++) |
| | | { |
| | | if (dt_0.Rows[m]["Enable"].ToString() == "N") |
| | | { |
| | | num = num + 1; |
| | | } |
| | | } |
| | | if (num == cout) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "设备不可用!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "工艺路线未关联设备!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | |
| | | //通过工单查找工艺路线对应关键工序所关联的设备所属车间 |
| | | sql0 = @"select distinct D.wksp_code from TK_Wrk_Man A |
| | | left join TFlw_Rout K on A.route_code=K.code |
| | | left join TFlw_Rtdt B on K.code=B.rout_code and B.first_choke='Y' |
| | | left join TFlw_Rteqp C on B.step_code= C.step_code |
| | | left join TEqpInfo D on C.eqp_code=D.code |
| | | where A.wo_code=@wocode and A.materiel_code=@partcode "; |
| | | dynamicParams.Add("@wocode", json[w].wocode); |
| | | dynamicParams.Add("@partcode", json[w].partcode); |
| | | var dt0 = DapperHelper.selectdata(sql0, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | string sy = "0"; |
| | | for (int i = 0; i < dt0.Rows.Count; i++) |
| | | { |
| | | if (dt0.Rows[i]["WKSP_CODE"].ToString() == json[w].wkshpcode) //工单创建车间是否等于排产设备 车间 |
| | | { |
| | | sy = "1"; |
| | | break; |
| | | } |
| | | else |
| | | { |
| | | sy = "0"; |
| | | } |
| | | } |
| | | if (sy == "0") |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "排产设备车间与工单创建的车间不同!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | else |
| | | { |
| | | List<APSList> listData = SchedulingMethod.SchedulingMethodTF(json[w].wocode, json[w].wkshpcode, json[w].partcode); |
| | | for (DateTime date = beginDate; date <= endDate; date = date.AddDays(1)) |
| | | { |
| | | AdvancedSchedulingDevice tbj = new AdvancedSchedulingDevice(); |
| | | tbj.wo_code = json[w].wocode; |
| | | tbj.YearDate = date.ToString("yyyy-MM-dd"); |
| | | tbj.children = new List<AdvancedSchedulingDeviceCont>(); |
| | | for (int j = 0; j < listData.Count; j++) |
| | | { |
| | | if (listData[j].AdvaDevicCropMob.ToString() == "0" || listData[j].AdvaDevicRhythm.ToString() == "") |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "排程设备" + listData[j].eqp_id.ToString() + "稼动率不能为0或为空!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | if (listData[j].AdvaDevicRhythm.ToString() == "0" || listData[j].AdvaDevicRhythm.ToString() == "") |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "排程设备" + listData[j].eqp_id.ToString() + "未设置节拍!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | string sql1 = @"select wktme1_start,wktme2_start,wktme3_start,wktme4_start,wktme5_start,G.name |
| | | from TWkm_capac_plan E |
| | | left join TWkm_capac_plan_sub F on E.id=F.m_id |
| | | left join TBas_wkshift_info G on F.wkshift_code=G.code |
| | | where E.wkshop=@wkshop and E.eqp_typecode=@eqp_typecode and E.ClassType=@classtype |
| | | and CONVERT(varchar(100), F.wkdate, 23)=@wkdate and E.enable='Y'"; |
| | | dynamicParams.Add("@wkshop", json[w].wkshpcode); |
| | | dynamicParams.Add("@eqp_typecode", listData[j].Style.ToString()); |
| | | dynamicParams.Add("@classtype", listData[j].ClassType.ToString()); |
| | | dynamicParams.Add("@wkdate", date.ToString("yyyy-MM-dd")); |
| | | dt1 = DapperHelper.selectdata(sql1, dynamicParams); |
| | | |
| | | AdvancedSchedulingDeviceCont tbjson = new AdvancedSchedulingDeviceCont(); |
| | | tbjson.AdvaDevicNumber = listData[j].eqp_id.ToString(); |
| | | tbjson.AdvaDevicName = listData[j].name.ToString(); |
| | | tbjson.AdvaDevicCropMob = listData[j].AdvaDevicCropMob.ToString(); //稼动率 |
| | | tbjson.AdvaDevicRhythm = listData[j].AdvaDevicRhythm.ToString(); //生产节拍 |
| | | if (dt1.Rows.Count > 0) |
| | | { |
| | | tbjson.OneStartDate = dt1.Rows[0]["wktme1_start"].ToString(); |
| | | tbjson.TwoStartDate = dt1.Rows[0]["wktme2_start"].ToString(); |
| | | tbjson.ThreeStartDate = dt1.Rows[0]["wktme3_start"].ToString(); |
| | | tbjson.FourStartDate = dt1.Rows[0]["wktme4_start"].ToString(); |
| | | tbjson.FiveStartDate = dt1.Rows[0]["wktme5_start"].ToString(); |
| | | tbj.children.Add(tbjson); |
| | | IsCap = true; |
| | | } |
| | | else |
| | | { |
| | | |
| | | tbjson.OneStartDate = ""; |
| | | tbjson.TwoStartDate = ""; |
| | | tbjson.ThreeStartDate = ""; |
| | | tbjson.FourStartDate = ""; |
| | | tbjson.FiveStartDate = ""; |
| | | tbj.children.Add(tbjson); |
| | | } |
| | | } |
| | | |
| | | list.Add(tbj); |
| | | } |
| | | if (list.Select(p => p.children).ToList().Count > 0) |
| | | { |
| | | int one = list.Where(t => t.children.Select(s => s.OneStartDate).Any(x => x != "")).ToList().Count; |
| | | int two = list.Where(t => t.children.Select(s => s.TwoStartDate).Any(x => x != "")).ToList().Count; |
| | | int three = list.Where(t => t.children.Select(s => s.ThreeStartDate).Any(x => x != "")).ToList().Count; |
| | | int four = list.Where(t => t.children.Select(s => s.FourStartDate).Any(x => x != "")).ToList().Count; |
| | | int five = list.Where(t => t.children.Select(s => s.FiveStartDate).Any(x => x != "")).ToList().Count; |
| | | if (one <= 0 && two <= 0 && three <= 0 && four <= 0 && five <= 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工单加工产品对应工艺路线设备未设置产能或未设置生产节拍!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "设备没有关联车间!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | | #region[New设备已排程信息] |
| | | public static List<DataTable> NewAlreadyScheduling(List<ApsOrderSerch> json) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | DataTable dt; |
| | | List<DataTable> list = new List<DataTable>(); |
| | | try |
| | | { |
| | | for (int i = 0; i < json.Count; i++) |
| | | { |
| | | List<APSList> listData = SchedulingMethod.SchedulingMethodTF(json[i].wocode, json[i].wkshpcode, json[i].partcode); |
| | | string[] empIds = listData.Select(a => a.eqp_id).ToArray(); |
| | | string str = string.Join(",", empIds); |
| | | string[] s1 = Array.ConvertAll<string, string>(str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] |
| | | //string s1 = string.Format("'{0}'", str.Replace(",", "','")); |
| | | |
| | | string sql = @"select B.wo_code, B.eqp_code,B.time_start,B.time_end, 'S' status , B.alloc_qty,D.partcode as part_code,D.partname as part_name,T.name as uom_name |
| | | from TK_Wrk_EqpAps B |
| | | left join TK_Wrk_Man C on B.wo_code=C.wo_code |
| | | left join TMateriel_Info D on C.materiel_code=D.partcode |
| | | left join TUom T on D.uom_code=T.code |
| | | where B.eqp_code in @eqpcode |
| | | and convert(varchar(100),B.Time_Start,21)>=@startdate and convert(varchar(100),B.Time_End,21)<=@enddate order by time_end"; |
| | | dt = DapperHelper.selectlist(sql, new { eqpcode = s1.ToArray(), startdate = json[i].startdate + " 00:00:00", enddate = json[i].enddate + " 23:59:59" }); |
| | | //dynamicParams.Add("@s1", new { shopcode = s1.ToArray() }); |
| | | //dynamicParams.Add("@startdate", startdate + " 00:00:00"); |
| | | //dynamicParams.Add("@enddate", enddate + " 23:59:59"); |
| | | //var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt == null || dt.Rows.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | list.Add(dt); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | |
| | | string status = dt.Rows[0]["STATUS"].ToString(); |
| | | Decimal nm = 0; //瓶径工序的前置天数 |
| | | Decimal nn = Decimal.Parse(dt.Rows[0]["BottFrointv"].ToString()); //瓶径工序的后置天数 |
| | | if (status != "NEW" && status != "SCHED") //工序任务的状态已经派发(审核) |
| | | if (status != "NEW" && status != "SCHED" && status != "NOSCHED") //工序任务的状态已经派发(审核) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | |
| | | { |
| | | sql = @"insert into TK_Wrk_EqpApsSum (wo_code,eqp_code,step_taid,p_date, t_date, qty,status) |
| | | select min(wo_code),min(eqp_code),min(step_taid),min(time_start),max(time_end),sum(Alloc_Qty),'NEW' from TK_Wrk_EqpAps |
| | | where wo_code=@wocode and eqp_code=''"; |
| | | where wo_code=@wocode and eqp_code=@eqp_code"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode, eqp_code = dt1.Rows[i]["EQP_CODE"].ToString() } }); |
| | | } |
| | | |
| | |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | list.Clear(); |
| | | //写入设备任务(汇总表)用料 计划数量*子件基本用量*(1+损耗率)/母件基本用量 |
| | | sql = @"insert into TK_Wrk_EqpSum_Allo(m_id, seq, invcode, qty,wo_code,pn_type) |
| | | sql = @"insert into TK_Wrk_EqpSum_Allo(m_id, seq, materiel_code, qty,wo_code,materieltype) |
| | | select A.id M_id, B.seq,B.materiel_code,(round(A.qty,2)*BE.Base_Quantity*(1+BE.LOSS_QUANTITY/100))/BM.quantity qty,A.wo_code,B.materieltype |
| | | from TK_Wrk_EqpApsSum A |
| | | left join TK_Wrk_Allo B on A.Wo_Code= B.Wo_Code |
| | |
| | | } |
| | | }); |
| | | //主工单的“计划开机日期 = 瓶径工序的预开工日期 - 瓶径工序的前置日期) 主工单:计划完工日期 = 瓶径工序的预完工日期 + 瓶径工序的后置日期 |
| | | sql = @"update mes_tk_wrk_man set status='SCHED',plan_startdate =convert(varchar(100),@plan_startdate,21), plan_enddate =convert(varchar(100),@plan_enddate,21), exchag='Y',allocfag='N' where wo_code =@wocode"; |
| | | sql = @"update TK_Wrk_Man set status='SCHED',plan_startdate =convert(varchar(100),@plan_startdate,21), plan_enddate =convert(varchar(100),@plan_enddate,21), exchag='Y',allocfag='N' where wo_code =@wocode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region[生产入库条码补打] |
| | | public static ToMessage ProductInHouseLabCode(string ordercode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //获取末道工序报工条码数据 |
| | | sql = @"select * from( |
| | | select A.inbarcode,A.wo_code,P.partcode,P.partname,P.partspec, |
| | | A.good_qty,U.username,A.lm_date |
| | | from TK_Wrk_Record A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | inner join TMateriel_Info P on A.materiel_code=P.partcode |
| | | inner join TUser U on A.lm_user=U.usercode |
| | | where A.style='B' and S.isend='Y' and A.good_qty>0 |
| | | union all |
| | | select A.inbarcode,A.wo_code,P.partcode,P.partname,P.partspec, |
| | | A.sqty as sqty,U.username,A.lm_date |
| | | from TK_Wrk_OutRecord A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | inner join TMateriel_Info P on A.materiel_code=P.partcode |
| | | inner join TUser U on A.lm_user=U.usercode |
| | | where A.style='S' and S.isend='Y' and A.sqty>0 |
| | | ) as AA where AA.wo_code=@ordercode"; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产入库通过车间查找生产订单] |
| | | public static ToMessage ProductInHouseWkshopOrder(string ordertype, string wkshopcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (ordertype == "Y") //有源单 |
| | | { |
| | | sql = @"select distinct AA.ordercode from ( |
| | | select A.m_po as ordercode |
| | | from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step B on A.wo_code=B.wo_code |
| | | inner join TK_Wrk_Record S on B.wo_code=S.wo_code and B.step_code=S.step_code |
| | | where S.style='B' and B.isend='Y' and A.m_po<>'' and S.good_qty>0 and S.good_qty>isnull(S.inhouseqty,0) and A.wkshp_code=@wkshopcode |
| | | union all |
| | | select A.m_po as ordercode |
| | | from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step B on A.wo_code=B.wo_code |
| | | inner join TK_Wrk_OutRecord S on B.wo_code=S.wo_code and B.step_code=S.step_code |
| | | where S.style='S' and B.isend='Y' and A.m_po<>'' and S.sqty>0 and S.sqty>isnull(S.inhouseqty,0) and A.wkshp_code=@wkshopcode |
| | | ) as AA"; |
| | | } |
| | | if (ordertype == "N") |
| | | { |
| | | sql = @"select distinct AA.ordercode from ( |
| | | select A.wo_code as ordercode |
| | | from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step B on A.wo_code=B.wo_code |
| | | inner join TK_Wrk_Record S on B.wo_code=S.wo_code and B.step_code=S.step_code |
| | | where S.style='B' and B.isend='Y' and A.m_po='' and S.good_qty>0 and S.good_qty>isnull(S.inhouseqty,0) and A.wkshp_code=@wkshopcode |
| | | union all |
| | | select A.wo_code as ordercode |
| | | from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step B on A.wo_code=B.wo_code |
| | | inner join TK_Wrk_OutRecord S on B.wo_code=S.wo_code and B.step_code=S.step_code |
| | | where S.style='S' and B.isend='Y' and A.m_po='' and S.sqty>0 and S.sqty>isnull(S.inhouseqty,0) and A.wkshp_code=@wkshopcode |
| | | ) as AA"; |
| | | } |
| | | |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产入库信息查询] |
| | | public static ToMessage ProductInHouseOrderSearch(string wkshopcode, string erpordercode, string mesordercode, string partcode, string partname, string partspec, string startorderdate, string endorderdate) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and AA.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (erpordercode != "" && erpordercode != null) |
| | | { |
| | | search += "and AA.m_po like '%'+@erpordercode+'%' "; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | } |
| | | if (mesordercode != "" && mesordercode != null) |
| | | { |
| | | search += "and AA.wo_code like '%'+@mesordercode+'%' "; |
| | | dynamicParams.Add("@mesordercode", mesordercode); |
| | | } |
| | | if (partcode != "" && partcode != null) |
| | | { |
| | | search += "and AA.partcode like '%'+@partcode+'%' "; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | } |
| | | if (partname != "" && partname != null) |
| | | { |
| | | search += "and AA.partname like '%'+@partname+'%' "; |
| | | dynamicParams.Add("@partname", partname); |
| | | } |
| | | if (partspec != "" && partspec != null) |
| | | { |
| | | search += "and AA.partspec like '%'+@partspec+'%' "; |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | if (startorderdate != "" && startorderdate != null) |
| | | { |
| | | search += "and AA.lm_date between @startorderdate and @endorderdate "; |
| | | dynamicParams.Add("@opencheckdate", startorderdate + " 00:00:00"); |
| | | dynamicParams.Add("@endorderdate", endorderdate + " 23:59:59"); |
| | | } |
| | | // --------------查询指定数据-------------- |
| | | var total = 0; //总条数 |
| | | var sql = @"select * from( |
| | | select A.inbarcode,E.saleOrderid,isnull(E.saleOrderCode,'') as saleOrderCode,E.saleOrderDetailId,E.woid as mpoid,M.m_po,E.sbid,M.id as wo_id,A.wo_code,E.materiel_id,P.partcode,P.partname,P.partspec,E.unitid,E.unitcode,E.unitname, |
| | | A.step_code,E.wkshp_id,M.wkshp_code,stck_id,K.code as stockcode,k.name as stockname, |
| | | E.saleOrderqty,E.qty,M.plan_qty,A.good_qty,isnull(A.inhouseqty,0) as inhouseqty,A.good_qty-isnull(A.inhouseqty,0) as stinhouseqty,M.lm_date,A.style |
| | | from TK_Wrk_Record A |
| | | 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 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 |
| | | select A.inbarcode,E.saleOrderid,isnull(E.saleOrderCode,'') as saleOrderCode,E.saleOrderDetailId,E.woid as mpoid,M.m_po,E.sbid,M.id as wo_id,A.wo_code,E.materiel_id,P.partcode,P.partname,P.partspec,E.unitid,E.unitcode,E.unitname, |
| | | A.step_code,E.wkshp_id,M.wkshp_code,stck_id,K.code as stockcode,k.name as stockname, |
| | | E.saleOrderqty,E.qty,M.plan_qty,A.sqty as sqty,isnull(A.inhouseqty,0) as inhouseqty,A.sqty-isnull(A.inhouseqty,0) as stinhouseqty,M.lm_date,A.style |
| | | from TK_Wrk_OutRecord A |
| | | 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 T_Sec_Stck K on E.stck_code=K.code |
| | | where A.style='S' and S.isend='Y' and A.sqty>0 |
| | | ) as AA where AA.good_qty>AA.inhouseqty " + search; |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产入库获取单据号] |
| | | public static ToMessage ProductInHouseOrderCodeSearch(string rightcode) |
| | | { |
| | | try |
| | | { |
| | | mes = SeachEncodeJob.EncodingSeach(rightcode); |
| | | return mes; |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产入库提交] |
| | | public static ToMessage ProductInHouseOrderSeave(string username, JObject obj) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | var dynamicParams1 = new DynamicParameters(); |
| | | try |
| | | { |
| | | string sub = obj["sub"].ToString();//明细 |
| | | string subsum = obj["subsum"].ToString();//汇总 |
| | | //获取报工明细 |
| | | JArray sub_arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(sub); |
| | | //获取汇总 |
| | | JArray subsum_arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(subsum); |
| | | |
| | | //回写报工记录主表、工单工序表已入库数量、写入MES库存表 |
| | | for (int i = 0; i < sub_arra.Count; i++) |
| | | { |
| | | if (sub_arra[i]["style"].ToString() == "B") |
| | | { |
| | | //回写报工记录主表的入库数量 |
| | | sql = @"update TK_Wrk_Record set inhouseqty=inhouseqty+@stinhouseqty where inbarcode=@inbarcode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | stinhouseqty = decimal.Parse(sub_arra[i]["stinhouseqty"].ToString()), |
| | | inbarcode = sub_arra[i]["inbarcode"].ToString() |
| | | } |
| | | }); |
| | | } |
| | | if (sub_arra[i]["style"].ToString() == "S") |
| | | { |
| | | //回写外协收料记录主表的入库数量 |
| | | sql = @"update TK_Wrk_OutRecord set inhouseqty=inhouseqty+@stinhouseqty where inbarcode=@inbarcode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | stinhouseqty = decimal.Parse(sub_arra[i]["stinhouseqty"].ToString()), |
| | | inbarcode = sub_arra[i]["inbarcode"].ToString() |
| | | } |
| | | }); |
| | | } |
| | | //回写工单工序表末道工序已入库数量 |
| | | sql = @"update TK_Wrk_Step set inhouseqty=inhouseqty+@stinhouseqty where wo_code=@wo_code and step_code=@step_code and isend='Y'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | stinhouseqty = decimal.Parse(sub_arra[i]["stinhouseqty"].ToString()), |
| | | wo_code = sub_arra[i]["wo_code"].ToString(), |
| | | step_code = sub_arra[i]["step_code"].ToString() |
| | | } |
| | | }); |
| | | //写入MES库存表 |
| | | sql = @"insert into TK_WMS_Stock(hbillno,labcode,materiel_code,storehouse_code,qty,lm_user,lm_date) |
| | | values(@hbillno,@labcode,@materiel_code,@storehouse_code,@qty,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | hbillno = obj["head"]["hbillno"].ToString(), |
| | | labcode = sub_arra[i]["inbarcode"].ToString(), |
| | | materiel_code = sub_arra[i]["partcode"].ToString(), |
| | | storehouse_code = sub_arra[i]["stockcode"].ToString(), |
| | | qty = decimal.Parse(sub_arra[i]["stinhouseqty"].ToString()), |
| | | lm_user = username, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | //写MES入库记录主表 |
| | | sql = @"insert into TK_WMS_Inwh_Main(docu_typecode,hbillno,hsoucenillnoid,hsoucenillno,saleorderid,saleordercode,status,wkshpcode,lm_user,lm_date) |
| | | values(@docu_typecode,@hbillno,@hsoucenillnoid,@hsoucenillno,@saleorderid,@saleordercode,@status,@wkshpcode,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | docu_typecode = "1202", |
| | | hbillno = obj["head"]["hbillno"].ToString(), |
| | | hsoucenillnoid = obj["head"]["sourceVoucherId"].ToString(), |
| | | hsoucenillno = obj["head"]["sourceVoucherCode"].ToString(), |
| | | saleorderid = obj["head"]["saleOrderId"].ToString(), |
| | | saleordercode = obj["head"]["saleOrderCode"].ToString(), |
| | | status = "NEW", |
| | | wkshpcode = obj["head"]["wkshpcode"].ToString(), |
| | | lm_user = username, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | |
| | | //获取ERP入库表sql |
| | | //DataTable dt = DapperHelper.lissql("h_p_MesInErpProductWareHous"); |
| | | //写入ERP入库记录主表 |
| | | //sql = @"" + dt.Rows[0]["cname"].ToString() + ""; |
| | | //list.Add(new |
| | | //{ |
| | | // str = sql, |
| | | // parm = new |
| | | // { |
| | | // code = obj["head"]["hbillno"].ToString(), |
| | | // sourceVoucherId = obj["head"]["sourceVoucherId"].ToString(), |
| | | // sourceVoucherCode = obj["head"]["sourceVoucherCode"].ToString(), |
| | | // saleOrderId = obj["head"]["saleOrderId"].ToString(), |
| | | // saleOrderCode = obj["head"]["saleOrderCode"].ToString(), |
| | | // rdDirectionFlag = obj["head"]["rdDirectionFlag"].ToString(), |
| | | // makerid = obj["head"]["makerid"].ToString(), |
| | | // maker = obj["head"]["maker"].ToString(), |
| | | // accountingyear = obj["head"]["accountingyear"].ToString(), |
| | | // VoucherYear = obj["head"]["VoucherYear"].ToString(), |
| | | // VoucherPeriod = obj["head"]["VoucherPeriod"].ToString(), |
| | | // ManufactureOrderCode = obj["head"]["ManufactureOrderCode"].ToString(), |
| | | // idbusitype = obj["head"]["idbusitype"].ToString(), |
| | | // iddepartment = obj["head"]["iddepartment"].ToString(), |
| | | // idrdstyle = obj["head"]["idrdstyle"].ToString(), |
| | | // idwarehouse = obj["head"]["idwarehouse"].ToString(), |
| | | // voucherState = obj["head"]["voucherState"].ToString(), |
| | | // idvouchertype = obj["head"]["idvouchertype"].ToString(), |
| | | // voucherdate = obj["head"]["voucherdate"].ToString(), |
| | | // madedate = obj["head"]["madedate"].ToString(), |
| | | // createdtime = obj["head"]["createdtime"].ToString(), |
| | | // DataSource = obj["head"]["DataSource"].ToString(), |
| | | // idsourcevouchertype= obj["head"]["idsourcevouchertype"].ToString() |
| | | |
| | | // } |
| | | //}); |
| | | //写入ERP、MES入库记录子表 |
| | | for (int j = 0; j < subsum_arra.Count; j++) |
| | | { |
| | | //写入ERP入库记录子表 |
| | | //sql = @"" + dt.Rows[1]["cname"].ToString() + ""; |
| | | //list.Add(new |
| | | //{ |
| | | // str = sql, |
| | | // parm = new |
| | | // { |
| | | // code = subsum_arra[j]["code"].ToString(), |
| | | // arrivalQuantity = subsum_arra[j]["arrivalQuantity"].ToString(), |
| | | // quantity = subsum_arra[j]["quantity"].ToString(), |
| | | // compositionQuantity = subsum_arra[j]["compositionQuantity"].ToString(), |
| | | // baseQuantity = subsum_arra[j]["baseQuantity"].ToString(), |
| | | // sourceVoucherId = subsum_arra[j]["sourceVoucherId"].ToString(), |
| | | // sourceVoucherCode = subsum_arra[j]["sourceVoucherCode"].ToString(), |
| | | // sourceVoucherDetailId = subsum_arra[j]["sourceVoucherDetailId"].ToString(), |
| | | // idsourcevouchertype = subsum_arra[j]["idsourcevouchertype"].ToString(), |
| | | // saleOrderId = subsum_arra[j]["saleOrderId"].ToString(), |
| | | // saleOrderCode = subsum_arra[j]["saleOrderCode"].ToString(), |
| | | // saleOrderDetailId = subsum_arra[j]["saleOrderDetailId"].ToString(), |
| | | // ManufactureOrderId = subsum_arra[j]["ManufactureOrderId"].ToString(), |
| | | // ManufactureOrderCode = subsum_arra[j]["ManufactureOrderCode"].ToString(), |
| | | // ManufactureOrderDetailId = subsum_arra[j]["ManufactureOrderDetailId"].ToString(), |
| | | // idbusiTypeByMergedFlow = subsum_arra[j]["idbusiTypeByMergedFlow"].ToString(), |
| | | // idinventory = subsum_arra[j]["idinventory"].ToString(), |
| | | // idbaseunit = subsum_arra[j]["idbaseunit"].ToString(), |
| | | // idunit = subsum_arra[j]["idunit"].ToString(), |
| | | // idwarehouse = subsum_arra[j]["idwarehouse"].ToString(), |
| | | // SourceVoucherIdByMergedFlow = subsum_arra[j]["SourceVoucherIdByMergedFlow"].ToString(), |
| | | // SourceVoucherCodeByMergedFlow = subsum_arra[j]["SourceVoucherCodeByMergedFlow"].ToString(), |
| | | // SourceVoucherDetailIdByMergedFlow = subsum_arra[j]["SourceVoucherDetailIdByMergedFlow"].ToString(), |
| | | // idsourceVoucherTypeByMergedFlow = subsum_arra[j]["idsourceVoucherTypeByMergedFlow"].ToString(), |
| | | // createdtime = subsum_arra[j]["createdtime"].ToString(), |
| | | // DataSource = subsum_arra[j]["DataSource"].ToString() |
| | | // } |
| | | //}); |
| | | //写入ERP现存量查询表 |
| | | //sql = @"" + dt.Rows[2]["cname"].ToString() + ""; |
| | | //list.Add(new |
| | | //{ |
| | | // str = sql, |
| | | // parm = new |
| | | // { |
| | | // idinventory = subsum_arra[j]["idinventory"].ToString(), |
| | | // idwarehouse = subsum_arra[j]["idwarehouse"].ToString(), |
| | | // propertyName = "ProductForReceive", |
| | | // baseQuantity= subsum_arra[j]["quantity"].ToString(), |
| | | // IdMarketingOrgan="1", |
| | | // idbaseunit= subsum_arra[j]["idbaseunit"].ToString(), |
| | | // updated= DateTime.Now.ToString(), |
| | | // isCarriedForwardOut ="0", |
| | | // isCarriedForwardIn = "0" |
| | | // } |
| | | //}); |
| | | |
| | | |
| | | |
| | | //写入MES入库记录子表 |
| | | sql = @"insert into TK_WMS_Inwh_Sub(hbillno,rownumber,materiel_code,storehouse_code,qty) |
| | | values(@hbillno,@rownumber,@materiel_code,@storehouse_code,@qty)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | hbillno = obj["head"]["hbillno"].ToString(), |
| | | rownumber = subsum_arra[j]["rownumber"].ToString(), |
| | | materiel_code = subsum_arra[j]["materiel_code"].ToString(), |
| | | storehouse_code = subsum_arra[j]["warehouse"].ToString(), |
| | | qty = decimal.Parse(subsum_arra[j]["quantity"].ToString()) |
| | | } |
| | | }); |
| | | } |
| | | //更新单据流水号 |
| | | List<object> list1 = SeachEncodeJob.StrEncodingUpdate(obj["head"]["rightcode"].ToString(), obj["head"]["incbit"].ToString()); |
| | | list.Add(list1[0]); |
| | | 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 MesAppProductInHouseOrderBarCodeSearch(string labcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //判断条码是否存在 |
| | | sql = @"select distinct AA.inbarcode from ( |
| | | select A.inbarcode |
| | | from TK_Wrk_Record A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | where A.style='B' and S.isend='Y' and A.good_qty>0 and A.inbarcode=@labcode |
| | | union all |
| | | select A.inbarcode |
| | | from TK_Wrk_OutRecord A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | where A.style='S' and S.isend='Y' and A.sqty>0 and A.inbarcode=@labcode |
| | | ) as AA"; |
| | | dynamicParams.Add("@labcode", labcode); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data0.Rows.Count <= 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = "无效条码!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断条码是否存可用 |
| | | sql = @"select distinct AA.inbarcode,AA.good_qty,AA.inhouseqty from ( |
| | | select A.inbarcode,sum(A.good_qty) as good_qty,sum(isnull(A.inhouseqty,0)) as inhouseqty |
| | | from TK_Wrk_Record A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | where A.style='B' and S.isend='Y' and A.good_qty>0 and A.inbarcode=@labcode |
| | | group by A.inbarcode |
| | | union all |
| | | select A.inbarcode,sum(A.sqty) as good_qty,sum(isnull(A.inhouseqty,0)) as inhouseqty |
| | | from TK_Wrk_OutRecord A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code |
| | | where A.style='S' and S.isend='Y' and A.sqty>0 and A.inbarcode=@labcode |
| | | group by A.inbarcode |
| | | ) as AA where AA.good_qty>AA.inhouseqty "; |
| | | dynamicParams.Add("@labcode", labcode); |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data1.Rows.Count <= 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = "当前条码已入库!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | //根据采购订单号查询物料信息,供应商信息 |
| | | sql = @"select * from( |
| | | select A.inbarcode,E.saleOrderid,isnull(E.saleOrderCode,'') as saleOrderCode,E.saleOrderDetailId,E.woid as mpoid,M.m_po,E.sbid,M.id as wo_id,A.wo_code,E.materiel_id,P.partcode,P.partname,P.partspec,E.unitid,E.unitcode,E.unitname, |
| | | A.step_code,E.wkshp_id,M.wkshp_code,stck_id,K.code as stockcode,k.name as stockname, |
| | | E.saleOrderqty,E.qty,M.plan_qty,A.good_qty,isnull(A.inhouseqty,0) as inhouseqty,A.good_qty-isnull(A.inhouseqty,0) as stinhouseqty,A.lm_date,A.style |
| | | from TK_Wrk_Record A |
| | | 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 T_Sec_Stck K on E.stck_code=K.code |
| | | where A.style='B' and S.isend='Y' and A.good_qty>0 and A.inbarcode=@labcode |
| | | union all |
| | | select A.inbarcode,E.saleOrderid,isnull(E.saleOrderCode,'') as saleOrderCode,E.saleOrderDetailId,E.woid as mpoid,M.m_po,E.sbid,M.id as wo_id,A.wo_code,E.materiel_id,P.partcode,P.partname,P.partspec,E.unitid,E.unitcode,E.unitname, |
| | | A.step_code,E.wkshp_id,M.wkshp_code,stck_id,K.code as stockcode,k.name as stockname, |
| | | E.saleOrderqty,E.qty,M.plan_qty,A.sqty as sqty,isnull(A.inhouseqty,0) as inhouseqty,A.sqty-isnull(A.inhouseqty,0) as stinhouseqty,A.lm_date,A.style |
| | | from TK_Wrk_OutRecord A |
| | | 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 T_Sec_Stck K on E.stck_code=K.code |
| | | where A.style='S' and S.isend='Y' and A.sqty>0 and A.inbarcode=@labcode |
| | | ) as AA where AA.good_qty>AA.inhouseqty"; |
| | | dynamicParams.Add("@labcode", labcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | 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) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | } |
| | | } |