| | |
| | | { |
| | | string erpordercode = group.erpordercode; |
| | | int count = 1; |
| | | foreach (var model in obj.Where(s => s.erpordercode==erpordercode).ToList()) |
| | | foreach (var model in obj.Where(s => s.erpordercode == erpordercode).ToList()) |
| | | { |
| | | //获取当前最大工单号 |
| | | sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0) as worknumb |
| | |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | sql = @"select * from TK_Wrk_Man where m_po=@erpordercode and status<> 'CLOSED'"; |
| | | sql = @"select * from TK_Wrk_Man where m_po=@erpordercode and sourceid=@sourceid"; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | dynamicParams.Add("@sourceid", erporderid); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前订单有下达未关闭的MES工单,订单不允许关闭,请先删除或关闭相关工单!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | //关闭订单 |
| | | sql = @"update TKimp_Ewo set status='CLOSED' where wo=@wo and id=@erporderid"; |
| | | // 使用LINQ和lambda表达式来转换wo_code字段的值为逗号隔开的字符串数组 |
| | | string[] result = data.AsEnumerable().Select(row => "" + row.Field<string>("wo_code") + "").ToArray(); |
| | | //关闭工序任务 |
| | | sql = @"update TK_Wrk_Step set status='CLOSED',closebeforestatus=status where wo_code in @wocode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid |
| | | wocode = result |
| | | } |
| | | }); |
| | | //关闭工单 |
| | | sql = @"update TK_Wrk_Man set status='CLOSED',closebeforestatus=status where m_po=@erpordercode and sourceid=@sourceid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | erpordercode = erpordercode, |
| | | sourceid = erporderid |
| | | } |
| | | }); |
| | | } |
| | | //关闭订单 |
| | | sql = @"update TKimp_Ewo set status='CLOSED',closebeforestatus=status where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid |
| | | } |
| | | }); |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | |
| | | 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[ERP订单反关闭] |
| | | public static ToMessage ReverseClosedErpOrder(string erporderid, string erpordercode, User us) |
| | | { |
| | | 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=@sourceid"; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | dynamicParams.Add("@sourceid", erporderid); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | // 使用LINQ和lambda表达式来转换wo_code字段的值为逗号隔开的字符串数组 |
| | | string[] result = data.AsEnumerable().Select(row => "" + row.Field<string>("wo_code") + "").ToArray(); |
| | | //关闭工序任务 |
| | | sql = @"update TK_Wrk_Step set status=closebeforestatus where wo_code in @ordercode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | ordercode = result |
| | | } |
| | | }); |
| | | //关闭工单 |
| | | sql = @"update TK_Wrk_Man set status=closebeforestatus where m_po=@erpordercode and sourceid=@sourceid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | erpordercode = erpordercode, |
| | | sourceid = erporderid |
| | | } |
| | | }); |
| | | } |
| | | //反关闭订单 |
| | | sql = @"update TKimp_Ewo set status=closebeforestatus where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid |
| | | } |
| | | }); |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "反关闭", "反关闭了订单:" + erpordercode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "订单反关闭成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "订单反关闭失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | try |
| | | { |
| | | //MES工单查找历史引用最新工序信息 |
| | | sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend from ( |
| | | select top 1 wo_code from TK_Wrk_Man |
| | | where wkshp_code=@wkshopcode and materiel_code=@partcode |
| | | order by lm_date desc |
| | | ) as A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code"; |
| | | sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend |
| | | from TK_Wrk_Step S |
| | | inner join ( |
| | | select top 1 A.wo_code from TK_Wrk_Man A |
| | | inner join TK_Wrk_Step S on A.wo_code=S.wo_code |
| | | where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode |
| | | order by A.lm_date desc |
| | | ) as W on S.wo_code=W.wo_code |
| | | left join TStep T on S.step_code=T.stepcode |
| | | order by S.seq"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@partcode", partcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | |
| | | var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.plan_qty,A.wkshp_code,C.torg_name as wkshp_name, |
| | | A.stck_code,D.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,A.saleOrderDeliveryDate,W.saleOrderCode,U.username as lm_user,A.lm_date,A.data_sources |
| | | from TK_Wrk_Man A |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code and A.sourceid=W.id |
| | | left join TMateriel_Info B on A.materiel_code=B.partcode |
| | | left join TOrganization C on A.wkshp_code=C.torg_code |
| | | left join TSecStck D on A.stck_code=D.code |
| | |
| | | for (int i = 0; i < wocodelist.Length; i++) |
| | | { |
| | | //关闭工单对应工序任务 |
| | | sql = @"update TK_Wrk_Step set status='CLOSED' where wo_code in @wocode"; |
| | | sql = @"update TK_Wrk_Step set status='CLOSED',closebeforestatus=status where wo_code in @wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocodelist } }); |
| | | //回写工单表状态为(关闭) |
| | | sql = @"update TK_Wrk_Man set status='CLOSED',closeuser=@username,closedate=@closedate where wo_code in @wocode"; |
| | | sql = @"update TK_Wrk_Man set status='CLOSED',closebeforestatus=status,closeuser=@username,closedate=@closedate where wo_code in @wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocodelist, username = us.usercode, closedate = DateTime.Now.ToString() } }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | |
| | | 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 MesOrderBitchReverseClosedSeave(User us, string[] wocodelist) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | for (int i = 0; i < wocodelist.Length; i++) |
| | | { |
| | | //关闭工单对应工序任务 |
| | | sql = @"update TK_Wrk_Step set status=closebeforestatus where wo_code in @wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocodelist } }); |
| | | //回写工单表状态为(关闭) |
| | | sql = @"update TK_Wrk_Man set status=closebeforestatus,closeuser=@username,closedate=@closedate where wo_code in @wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocodelist, username = us.usercode, closedate = DateTime.Now.ToString() } }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "反关闭", "关闭了工单:" + string.Join(",", wocodelist), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "工单反关闭成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "工单反关闭失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | #region[生产执行,报工审核列表数据查询接口] |
| | | public static ToMessage MesOrderStepReportVerifySearch(string wkshopcode, string wo_code, string partnumber, string partname, string partspec, string stepname, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderStepReportVerifySearch(string reviewstatus, string wkshopcode, string wo_code, string partnumber, string partname, string partspec, string stepname, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | | try |
| | | { |
| | | if (reviewstatus != "" && reviewstatus != null) |
| | | { |
| | | search += "and AA.verify=@reviewstatus "; |
| | | dynamicParams.Add("@reviewstatus", reviewstatus); |
| | | } |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and AA.wkshp_code=@wkshopcode "; |
| | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "报工审核", "自制报工记录id:" + string.Join(",", json.zdata), us.usertype); |
| | | LogHelper.DbOperateLog(us.usercode, "报工审核", "外协收料记录id:" + string.Join(",", json.wdata), us.usertype); |
| | | if (json.zdata.Count > 0) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "报工审核", "自制报工记录id:" + string.Join(",", json.zdata), us.usertype); |
| | | } |
| | | if (json.wdata.Count > 0) |
| | | { |
| | | LogHelper.DbOperateLog(us.usercode, "报工审核", "外协收料记录id:" + string.Join(",", json.wdata), us.usertype); |
| | | } |
| | | 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 MesOrderStepReportNotVerifySeave(User us, string id, string steptype) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (steptype == "Z")//自制工序 |
| | | { |
| | | //回写报工记录主表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_Record set verify='N',verifyuser=@verifyuser,verifydate=@verifydate where id=@id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } }); |
| | | //回写报工记录子表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_RecordSub set verify='N',verifyuser=@verifyuser,verifydate=@verifydate where m_id=@id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } }); |
| | | } |
| | | if (steptype == "W")//外协工序 |
| | | { |
| | | //回写外协记录主表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_OutRecord set verify='N',verifyuser=@verifyuser,verifydate=@verifydate where id=@id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } }); |
| | | //回写外协记录子表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_OutRecordSub set verify='N',verifyuser=@verifyuser,verifydate=@verifydate where m_id=@id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | if (steptype == "Z") |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "报工弃审", "自制报工记录id:" + string.Join(",", id), us.usertype); |
| | | } |
| | | if (steptype == "W") |
| | | { |
| | | LogHelper.DbOperateLog(us.usercode, "报工弃审", "外协收料记录id:" + string.Join(",", id), us.usertype); |
| | | } |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "审核成功!"; |