| | |
| | | using Dapper; |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | |
| | | using System.Linq; |
| | | using System.Threading.Tasks; |
| | | using VueWebCoreApi.Models; |
| | | using VueWebCoreApi.Models.ErpOrder; |
| | | using VueWebCoreApi.Models.ReportVerify; |
| | | using VueWebCoreApi.Models.UpdateReport; |
| | | using VueWebCoreApi.Models.WorkData; |
| | | using VueWebCoreApi.Tools; |
| | | |
| | |
| | | { |
| | | public static DataTable dt; //定义全局变量dt |
| | | public static bool res; //定义全局变量dt |
| | | |
| | | public static ToMessage mes = new ToMessage(); //定义全局返回信息对象 |
| | | public static string strProcName = ""; //定义全局sql变量 |
| | | public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合 |
| | |
| | | |
| | | |
| | | #region[ERP订单查询] |
| | | public static ToMessage ErpOrderSearch(string erporderstus, string erpordercode, string saleordercode, string partcode, string partname, string partspec, int startNum, string paydatestartdate, string paydateenddate, string paydatestartdate1, string paydateenddate2, string creatuser, int endNum, string prop, string order) |
| | | public static ToMessage ErpOrderSearch(string erporderstus, string wkshopcode, 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 = ""; |
| | |
| | | { |
| | | search += "and A.status=@erporderstus "; |
| | | dynamicParams.Add("@erporderstus", erporderstus); |
| | | } |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and A.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (erpordercode != "" && erpordercode != null) |
| | | { |
| | |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data.ToList(); |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "下达", "下达了工单:" + wo, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "下达MES工单成功!"; |
| | | mes.message = "下达MES工单成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "下达MES工单成功失败!"; |
| | | mes.message = "下达MES工单成功失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[订单批量下达] |
| | | public static ToMessage MarkBatchSaveErpOrder(List<ErpOrderBatch> obj, User us) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | |
| | | try |
| | | { |
| | | list.Clear(); |
| | | string result = ""; |
| | | //var groupedModels = obj.GroupBy(m => m.erpordercode); |
| | | var groupedModels = obj.GroupBy(s => s.erpordercode).Select(g => new { erpordercode = g.Key }).ToList(); |
| | | foreach (var group in groupedModels) |
| | | { |
| | | string erpordercode = group.erpordercode; |
| | | int count = 1; |
| | | 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 |
| | | 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); |
| | | result += wo.ToString() + ","; |
| | | //写入工单表 |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,stck_code,sbid,materiel_code,sourceid,m_po,lm_user,lm_date,saleOrderCode,saleOrderDeliveryDate,data_sources,isstep) values(@wo_code,@wotype,@status,@wkshp_code,@plan_qty,@stck_code,@sbid,@materiel_code,@sourceid,@m_po,@username,@CreateDate,@saleOrderCode,@saleOrderDeliveryDate,@data_sources,@isstep)"; |
| | | 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, |
| | | sbid = model.sbid, |
| | | materiel_code = model.partcode, |
| | | sourceid = model.erporderid, |
| | | m_po = model.erpordercode, |
| | | username = us.usercode, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | saleOrderCode = model.saleordercode, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(model.saleOrderDeliveryDate), |
| | | data_sources = "ERP", |
| | | isstep = "N" //是否关联工序 |
| | | } |
| | | }); |
| | | |
| | | //更新订单状态 |
| | | 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) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "批量下达", "批量下达了工单:" + result.TrimEnd(','), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "批量下达MES工单成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "批量下达MES工单成功失败!"; |
| | | mes.data = null; |
| | | } |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前订单有下达未关闭的MES工单,订单不允许关闭,请先删除或关闭相关工单!"; |
| | | mes.message = "当前订单有下达未关闭的MES工单,订单不允许关闭,请先删除或关闭相关工单!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "关闭", "关闭了订单:" + erpordercode, us.usertype); |
| | | 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; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前订单下有工单已派发或已开工或已完工(关闭),不允许删除!"; |
| | | mes.message = "当前订单下有工单已派发或已开工或已完工(关闭),不允许删除!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "删除", "删除了订单:" + erpordercode, us.usertype); |
| | | 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; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | |
| | | |
| | | #region[MES工单查询] |
| | | public static ToMessage MesOrderSearch(string mesorderstus, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderSearch(string mesorderstus, string wkshopcode, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | |
| | | { |
| | | search += "and A.status=@mesorderstus "; |
| | | dynamicParams.Add("@mesorderstus", mesorderstus); |
| | | } |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and A.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (mesordercode != "" && mesordercode != 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.torg_name as wkshp_name, |
| | | A.stck_code,D.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,A.saleOrderDeliveryDate,W.saleOrderCode,U.username as lm_user,A.lm_date,A.data_sources |
| | | A.stck_code,D.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,A.saleOrderDeliveryDate,W.saleOrderCode,U.username as lm_user,A.lm_date,A.data_sources,A.isstep |
| | | 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.sbid=W.sbid |
| | | 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 |
| | |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data.ToList(); |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | #endregion |
| | | |
| | | #region[MES报废补单工单查询] |
| | | public static ToMessage MesBadOrderSearch(string mesordercode, string sourceorder, string saleordercode, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | public static ToMessage MesBadOrderSearch(string wkshopcode, 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 (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and A.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (mesordercode != "" && mesordercode != null) |
| | | { |
| | | search += "and A.wo_code like '%'+@mesordercode+'%' "; |
| | |
| | | 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,S.laborbad_qty,S.materielbad_qty |
| | | from TK_Wrk_Man A |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code |
| | | left join TKimp_Ewo W on A.m_po=W.wo and A.materiel_code=W.materiel_code and A.sbid=W.sbid |
| | | left join (select wo_code,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty from TK_Wrk_Step where (laborbad_qty+materielbad_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.torg_code |
| | |
| | | where A.is_delete<>'1' and (S.laborbad_qty+S.materielbad_qty)>0 " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data.ToList(); |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | FROM TK_Wrk_Man where wo_code like '%SGPO%'"; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.message = "查询成功!"; |
| | | mes.data = data.Rows[0]["numct"].ToString(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | dir.Add("stepdata", data1); |
| | | mes.code = "200"; |
| | | mes.count = data1.Rows.Count; |
| | | mes.Message = "查询成功"; |
| | | mes.message = "查询成功"; |
| | | mes.data = dir; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了工单:" + json.wocode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "MES工单新建成功!"; |
| | | mes.message = "MES工单新建成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "MES工单新建失败!"; |
| | | mes.message = "MES工单新建失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "修改", "修改了工单:" + json.wocode, us.usertype); |
| | | 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; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | //list.Add(new { str = sql, parm = new { wocode = wocode } }); |
| | | |
| | | //删除工单表 |
| | | sql = @"update TK_Wrk_Man set is_delete='1' where wo_code=@wocode"; |
| | | sql = @"delete TK_Wrk_Man where wo_code=@wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode } }); |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "工单执行中或已关闭,不允许删除!"; |
| | | mes.message = "工单执行中或已关闭,不允许删除!"; |
| | | mes.data = null; |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "删除", "删除了工单:" + wocode, us.usertype); |
| | | 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; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[MES工单查找历史引用最新工序信息] |
| | | public static ToMessage MesOrderNewStepContent(string wkshopcode, string partcode, User us) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | 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"; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | dynamicParams.Add("@partcode", partcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.count = data.Rows.Count; |
| | | mes.data = data; |
| | | mes.message = "查询成功!"; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "派发", "派发了工单:" + string.Join(",", wocodelist), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "MES工单派发成功!"; |
| | | mes.message = "MES工单派发成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "MES工建派发失败!"; |
| | | mes.message = "MES工建派发失败!"; |
| | | mes.data = null; |
| | | } |
| | | |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | |
| | | |
| | | #region[工单关闭列表查询] |
| | | public static ToMessage MesOrderClosedSearch(string mesorderstus, string mesordercode, string sourceorder, string saleordercode, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderClosedSearch(string mesorderstus, string wkshopcode, 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 |
| | | { |
| | | if (mesorderstus == "已关闭") |
| | | if (mesorderstus == "CLOSED") |
| | | { |
| | | search += "and A.status=@mesorderstus "; |
| | | dynamicParams.Add("@mesorderstus", "CLOSED"); |
| | | } |
| | | if (mesorderstus == "未关闭") |
| | | if (mesorderstus == "NOCLOSED") |
| | | { |
| | | search += "and A.status<>@mesorderstus "; |
| | | dynamicParams.Add("@mesorderstus", "CLOSED"); |
| | | } |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and A.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (mesordercode != "" && mesordercode != 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.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.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 TMateriel_Info B on A.materiel_code=B.partcode |
| | |
| | | where A.is_delete<>'1' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data.ToList(); |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | for (int i = 0; i < dt.Rows.Count; i++) |
| | | for (int i = 0; i < wocodelist.Length; i++) |
| | | { |
| | | //关闭工单对应工序任务 |
| | | sql = @"update TK_Wrk_Step set status='CLOSED' where wo_code in @wocode"; |
| | |
| | | LogHelper.DbOperateLog(us.usercode, "关闭", "关闭了工单:" + string.Join(",", wocodelist), us.usertype); |
| | | 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; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(自制)] |
| | | public static ToMessage MesOrderStepSearch(string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderStepSearch(string wkshopcode, string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | var total = 0; //总条数 |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and B.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (wocode != "" && wocode != null) |
| | | { |
| | | string[] arra = wocode.Split(';'); |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务为外协工序任务,请前往外协操作页签执行!"; |
| | | mes.message = "当前工序任务为外协工序任务,请前往外协操作页签执行!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | //根据条件查询工单工序任务(自制工序) |
| | | sql = @"select A.status,A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isbott,A.isend, |
| | | sql = @"select A.id,A.status,B.wkshp_code,T.torg_name as wkshp_name,A.wo_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.laborbad_qty,A.materielbad_qty,B.lm_date |
| | | 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 |
| | | left join TOrganization T on B.wkshp_code=T.torg_code |
| | | 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) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = total; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data.ToList(); |
| | | return mes; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | mes.code = "200"; |
| | | mes.count = total; |
| | | mes.message = "查询成功!"; |
| | | mes.data = data.ToList(); |
| | | return mes; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(外协)] |
| | | public static ToMessage MesOrderWxStepSearch(string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderWxStepSearch(string wkshopcode, string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | var total = 0; //总条数 |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and B.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (wocode != "" && wocode != null) |
| | | { |
| | | string[] arra = wocode.Split(';'); |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务为自制工序任务,请前往自制操作页签执行!"; |
| | | mes.message = "当前工序任务为自制工序任务,请前往自制操作页签执行!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | //根据条件查询工单工序任务(自制工序) |
| | | sql = @"select A.status,A.wo_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.laborbad_qty,A.materielbad_qty,A.plan_startdate,A.plan_enddate,B.lm_date |
| | | sql = @"select A.id,A.status,B.wkshp_code,T.torg_name as wkshp_name,A.wo_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, |
| | | (select isnull(sum(fqty),0) as fqty from TK_Wrk_OutRecord where wo_code=A.wo_code and step_code=A.step_code and style='F') as fqty, |
| | | A.laborbad_qty,A.materielbad_qty,A.plan_startdate,A.plan_enddate,B.lm_date |
| | | 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 |
| | | left join TOrganization T on B.wkshp_code=T.torg_code |
| | | 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) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = total; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data.ToList(); |
| | | return mes; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | mes.code = "200"; |
| | | mes.count = total; |
| | | mes.message = "查询成功!"; |
| | | mes.data = data.ToList(); |
| | | return mes; |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | #endregion |
| | | |
| | | #region[生产开报工扫码获取工单对应工序任务(不良)] |
| | | public static ToMessage MesOrderNgStepSearch(string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage MesOrderNgStepSearch(string wkshopcode, string wocode, string partcode, string partname, string partspec, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var sql = ""; |
| | | string search = ""; |
| | |
| | | var total = 0; //总条数 |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and B.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (wocode != "" && wocode != null) |
| | | { |
| | | string[] arra = wocode.Split(';'); |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务不存在,无效条码!"; |
| | | mes.message = "当前工序任务不存在,无效条码!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | //根据条件查询工单工序任务(自制工序) |
| | | sql = @"select A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isend, |
| | | sql = @"select A.id,B.wkshp_code,T.torg_name as wkshp_name,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.laborbad_qty,A.materielbad_qty,B.lm_date |
| | | 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 |
| | | left join TOrganization T on B.wkshp_code=T.torg_code |
| | | 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) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = total; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data.ToList(); |
| | | return mes; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | mes.code = "200"; |
| | | mes.count = total; |
| | | mes.message = "查询成功!"; |
| | | mes.data = data.ToList(); |
| | | return mes; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务不存在!"; |
| | | mes.message = "当前工序任务不存在!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | |
| | | list.Add("data2", dt); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.message = "查询成功!"; |
| | | mes.data = list; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.message = "无可执行的生产任务,任务已完成或已关闭!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | |
| | | mes = ScanStartReport.ZZEncodingSeach(wocode, stepcode); |
| | | break; |
| | | case "WX": |
| | | mes = ScanStartReport.WXEncodingSeach(SelectType, stepcode, stepcode); |
| | | mes = ScanStartReport.WXEncodingSeach(SelectType, wocode, stepcode); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,报工提交] |
| | | public static ToMessage SavaMesOrderStepReport(string mesordercode, string partcode, string stepseq, string stepcode, string stepprice, string eqpcode, string inbarcode, string reckway, string usergroupcode, string reportuser, string taskqty, string startqty, string reportqty, List<ReportDefectList> defectobjs, string remarks, User us) |
| | | { |
| | | var sql = ""; |
| | | decimal ngqty = 0; |
| | | string[] arra1 = new string[] { }; |
| | | List<object> list0 = new List<object>(); |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | //获取报工人员、分配比例 |
| | | //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(); // 汇总不良数量 |
| | | if (groupedItems.Count <= 0) |
| | | { |
| | | 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='S' and eqp_code=@eqpcode"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@eqpcode", eqpcode); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data0.Rows.Count <= 0) |
| | | { |
| | | //写入开报工记录表 |
| | | sql = @"insert into TK_Wrk_Record(wo_code,step_seq,step_code,step_price,eqp_code,materiel_code,open_person,open_time,task_qty,start_qty,style,lm_user,lm_date) |
| | | values(@mesordercode,@stepseq,@stepcode,@step_price,@eqpcode,@partcode,@username,@opentime,@taskqty,@startqty,@style,@lm_user,@lm_date)"; |
| | | list0.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, step_price = stepprice, eqpcode = eqpcode, partcode = partcode, username = us.usercode, opentime = date, taskqty = taskqty, startqty = startqty, style = "S", lm_user = us.usercode, lm_date = date } }); |
| | | //回写工单工序表状态为START: 开工 |
| | | sql = @"update TK_Wrk_Step set status='START' where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list0.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | |
| | | //回写工单表状态为: 开工:START |
| | | sql = @"update TK_Wrk_Man set status='START' where wo_code=@mesordercode"; |
| | | list0.Add(new { str = sql, parm = new { mesordercode = mesordercode } }); |
| | | bool st = DapperHelper.DoTransaction(list0); |
| | | if (st) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "开工", "开工了工单:" + mesordercode + "工序:" + stepcode, 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; |
| | | } |
| | | } |
| | | |
| | | //判断是否有报工记录(有:修改 无:新增) |
| | | sql = @"select * from TK_Wrk_Record where wo_code=@wo_code and step_code=@step_code and style='B'"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | ////获取开工记录的默认选中的设备(产线)与报工时的设备产线做对比判断 |
| | | //sql = @"select A.eqp_code,B.name from TK_Wrk_Record A |
| | | // inner join TEqpInfo B on A.eqp_code=B.code |
| | | // where A.wo_code=@wo_code and A.step_code=@step_code and eqp_code=@eqpcode and A.style='S'"; |
| | | //dynamicParams.Add("@wo_code", mesordercode); |
| | | //dynamicParams.Add("@step_code", stepcode); |
| | | //dynamicParams.Add("@eqpcode", eqpcode); |
| | | //var da = DapperHelper.selectdata(sql, dynamicParams); |
| | | //if (da.Rows[0]["EQP_CODE"].ToString() != eqpcode) |
| | | //{ |
| | | // mes.code = "300"; |
| | | // mes.count = 0; |
| | | // mes.message = "操作失败,当前报工产线应为:" + da.Rows[0]["NAME"].ToString() + "!"; |
| | | // mes.data = null; |
| | | // return mes; |
| | | //} |
| | | 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,step_price,eqp_code,materiel_code,task_qty,start_qty,good_qty,ng_qty,style,lm_user,lm_date,inbarcode) |
| | | values(@mesordercode,@stepseq,@stepcode,@step_price,@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, step_price = stepprice, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = us.usercode, lm_date = date, inbarcode = inbarcode } }); |
| | | |
| | | //写入子表 |
| | | 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 = reportuser, |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = 0, //分配比例 |
| | | ng_qty = ngqty, |
| | | style = "B", |
| | | lm_user = us.usercode, |
| | | lm_date = date |
| | | } |
| | | }); |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | 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_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 = us.usercode, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //获取主表最大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,step_price,eqp_code,materiel_code,task_qty,start_qty,good_qty,ng_qty,style,lm_user,lm_date,inbarcode) |
| | | values(@mesordercode,@stepseq,@stepcode,@step_price,@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, step_price = stepprice, eqpcode = eqpcode, partcode = partcode, taskqty = taskqty, startqty = startqty, reportqty = reportqty, ngqty = ngqty, style = "B", lm_user = us.usercode, lm_date = date, inbarcode = inbarcode } }); |
| | | |
| | | //写入子表 |
| | | 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 = reportuser, |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = 0, //分配比例 |
| | | ng_qty = ngqty, |
| | | style = "B", |
| | | lm_user = us.usercode, |
| | | lm_date = date |
| | | } |
| | | }); |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | 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_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 = us.usercode, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //回写工单工序表合格数量、不良数量 |
| | | sql = @"update TK_Wrk_Step set good_qty=good_qty+@reportqty,ng_qty=ng_qty+@ngqty where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, reportqty = reportqty, ngqty = ngqty } }); |
| | | |
| | | //回写工单表合格数量、不良数量 |
| | | //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) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "报工", "报工了工单:" + mesordercode + "工序:" + stepcode, 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 SavaMesOrderStepOut(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, string outuser, string taskqty, string fqty, User us) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | list.Clear(); |
| | | //判断是否有发料记录(有(同工单+工序+外协供方修改) 无:新增) |
| | | sql = @"select * from TK_Wrk_OutRecord where wo_code=@wo_code and step_code=@step_code and wx_code=@wx_code and style='F'"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@wx_code", wxcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | //修改发料记录 |
| | | sql = @"update TK_Wrk_OutRecord set fqty=fqty+@fqty,lm_user=@username,lm_date=@CreateDate |
| | | where wo_code=@mesordercode and step_code=@stepcode and wx_code=@wx_code and style='F'"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, wx_code = wxcode, fqty = decimal.Parse(fqty), username = us.usercode, CreateDate = date } }); |
| | | //写入子表 |
| | | sql = @"insert into TK_Wrk_OutRecordSub(m_id,wx_code,out_person,out_time,fqty,style,lm_user,lm_date) |
| | | values(@m_id,@wx_code,@out_person,@out_time,@fqty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(data.Rows[0]["ID"].ToString()), wx_code = wxcode, out_person = outuser, out_time = date, fqty = fqty, style = 'F', lm_user = us.usercode, lm_date = date } }); |
| | | } |
| | | else |
| | | { |
| | | //获取主表最大ID |
| | | 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,fqty,lm_user,lm_date) |
| | | values(@mesordercode,@stepseq,@stepcode,@wx_code,@partcode,@style,@fqty,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepseq = stepseq, stepcode = stepcode, wx_code = wxcode, partcode = partcode, style = 'F', fqty = fqty, lm_user = us.usercode, lm_date = date } }); |
| | | |
| | | //写入子表 |
| | | sql = @"insert into TK_Wrk_OutRecordSub(m_id,wx_code,out_person,out_time,fqty,style,lm_user,lm_date) |
| | | values(@m_id,@wx_code,@out_person,@out_time,@fqty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), wx_code = wxcode, out_person = outuser, out_time = date, fqty = fqty, style = 'F', lm_user = us.usercode, 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 } }); |
| | | |
| | | |
| | | //回写工单表状态为: 开工: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) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "外协发料", "外协发料工单:" + mesordercode + "工序:" + stepcode, 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 SavaMesOrderStepIn(string mesordercode, string partcode, string stepseq, string stepcode, string wxcode, string inbarcode, string inuser, string taskqty, string sqty, List<ReportDefectList> defectobjs, string remarks, User us) |
| | | { |
| | | 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(); //获取系统时间 |
| | | //判断是否有不良数据 |
| | | 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) |
| | | { |
| | | ngqty = 0; |
| | | } |
| | | else |
| | | { |
| | | //汇总不良数量 |
| | | ngqty = groupedItems.Sum(item => Convert.ToDecimal(item.badqty)); |
| | | } |
| | | |
| | | list.Clear(); |
| | | //判断是否有收料记录(有:(同工单+工序+外协供方修改) 无:新增) |
| | | sql = @"select * from TK_Wrk_OutRecord where wo_code=@wo_code and step_code=@step_code and wx_code=@wx_code and style='S'"; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@wx_code", wxcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | //获取发料记录的默认选中的外协供应商与收料时的外协供应商做对比判断 |
| | | sql = @"select A.wx_code,B.name,A.fqty from TK_Wrk_OutRecord A |
| | | inner join TCustomer B on A.wx_code=B.code |
| | | where A.wo_code=@wo_code and A.step_code=@step_code and wx_code=@wx_code and A.style='F' "; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@wx_code", wxcode); |
| | | var da = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (da.Rows.Count <= 0) |
| | | { |
| | | sql = @"select A.wx_code,B.name,A.fqty from TK_Wrk_OutRecord A |
| | | inner join TCustomer B on A.wx_code=B.code |
| | | where A.wo_code=@wo_code and A.step_code=@step_code and A.style='F' "; |
| | | dynamicParams.Add("@wo_code", mesordercode); |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | var da1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | var dr = da1.AsEnumerable().ToList().Select(x => x.Field<string>("NAME")).ToList(); |
| | | string wxstring = (string.Join(",", dr.Select(x => x.ToString()).ToArray())); |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "操作失败,当前收料外协供方与发料外协供应商不匹配,应为:【" + wxstring + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | if ((decimal.Parse(sqty) + ngqty) > decimal.Parse(da.Rows[0]["FQTY"].ToString())) //收料数量+不良数量>发料数量 |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "操作失败,当前收料数量+不良数量,不能大于发料数量:" + da.Rows[0]["FQTY"].ToString() + "!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //if (da.Rows[0]["WX_CODE"].ToString() != wxcode) |
| | | //{ |
| | | // mes.code = "300"; |
| | | // mes.count = 0; |
| | | // mes.message = "操作失败,当前收料外协供方应为:" + da.Rows[0]["NAME"].ToString() + "!"; |
| | | // mes.data = null; |
| | | // return mes; |
| | | //} |
| | | if (data.Rows.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) + ngqty) > sum_fqty) //已收料总数+当前收料数量+不良数量>总发料数量 |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "操作失败,当前收料数量+不良数量,不能大于待收数量:" + (sum_fqty - sum_sqty) + "!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | |
| | | //获取主表最大ID |
| | | 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,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 = us.usercode, 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 = us.usercode, lm_date = date } }); |
| | | |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | 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_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 = us.usercode, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //获取主表最大ID |
| | | 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,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 = us.usercode, 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 = us.usercode, lm_date = date } }); |
| | | |
| | | if (groupedItems.Count > 0) |
| | | { |
| | | //写入缺陷记录表 |
| | | 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_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 = us.usercode, lm_date = date } }); |
| | | |
| | | } |
| | | } |
| | | } |
| | | //回写工单工序表合格数量、不良数量 |
| | | sql = @"update TK_Wrk_Step set good_qty=good_qty+@sqty,ng_qty=ng_qty+@ngqty where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode, sqty = sqty, ngqty = ngqty } }); |
| | | |
| | | //回写工单表合格数量、不良数量 |
| | | //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) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "外协收料", "外协收料工单:" + mesordercode + "工序:" + stepcode, 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 EditOrderNgStepSeave(ReportDefectHandle json, User us) |
| | | { |
| | | var sql = ""; |
| | | string[] arra1 = new string[] { }; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | decimal sumrepair_qty = 0, sumlaborbad_qty = 0, summaterielbad_qty = 0; //累计维修数量、累计工废数量、累计料废数量 |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | list.Clear(); |
| | | |
| | | |
| | | //循环json数据 |
| | | for (int i = 0; i < json.Data.Rows.Count; i++) |
| | | { |
| | | //自制工序 |
| | | if (json.Data.Rows[i]["STYLE"].ToString() == "Z") |
| | | { |
| | | //回写对应的报工记录子表合格数量、不良数量、工废数量、料废数量 |
| | | sql = @"update TK_Wrk_RecordSub set report_qty=report_qty+@repair_qty,ng_qty=ng_qty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where m_id=@m_id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(json.Data.Rows[i]["M_ID"].ToString()), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()) |
| | | } |
| | | }); |
| | | //回写对应的报工记录主表合格数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_Record set good_qty=good_qty+@repair_qty,ng_qty=ng_qty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_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]["M_ID"].ToString()) |
| | | } |
| | | }); |
| | | //回写缺陷记录表的待处理数量 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty-@repair_qty-@laborbad_qty-@materielbad_qty, defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_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 = @"select * from CSR_WorkRecord_DefectHandle where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id"; |
| | | dynamicParams.Add("@wo_code", json.Data.Rows[i]["WO_CODE"].ToString()); |
| | | dynamicParams.Add("@step_code", json.Data.Rows[i]["STEP_CODE"].ToString()); |
| | | dynamicParams.Add("@defect_id", json.Data.Rows[i]["ID"].ToString()); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count <= 0) |
| | | { |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,laborbad_qty,materielbad_qty,defect_code,style,lm_user,lm_date) |
| | | values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@laborbad_qty,@materielbad_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(), |
| | | stepcode = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()), |
| | | defect_code = json.Data.Rows[i]["DEFECT_CODE"].ToString(), |
| | | style = "B", |
| | | lm_user = us.usercode, |
| | | lm_date = date |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //更新报工缺陷处理记录表 |
| | | sql = @"update CSR_WorkRecord_DefectHandle set repair_qty=repair_qty+@repair_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id"; |
| | | 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(), |
| | | step_code = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()) |
| | | } |
| | | }); |
| | | } |
| | | |
| | | sumrepair_qty = sumrepair_qty + decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()); |
| | | sumlaborbad_qty = sumlaborbad_qty + decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()); |
| | | summaterielbad_qty = summaterielbad_qty + decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()); |
| | | } |
| | | //外协工序 |
| | | if (json.Data.Rows[i]["STYLE"].ToString() == "S") |
| | | { |
| | | //回写对应的收料记录子表收料数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_OutRecordSub set sqty=sqty+@repair_qty,ng_qty=ng_qty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where m_id=@m_id and style='S'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(json.Data.Rows[i]["M_ID"].ToString()), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()) |
| | | } |
| | | }); |
| | | //回写对应的收料记录主表合格数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_OutRecord set sqty=sqty+@repair_qty,ng_qty=ng_qty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='S'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_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]["M_ID"].ToString()) |
| | | } |
| | | }); |
| | | //回写缺陷记录表的待处理数量 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty-@repair_qty-@laborbad_qty-@materielbad_qty,defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='S'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_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 = @"select * from CSR_WorkRecord_DefectHandle where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id"; |
| | | dynamicParams.Add("@wo_code", json.Data.Rows[i]["WO_CODE"].ToString()); |
| | | dynamicParams.Add("@step_code", json.Data.Rows[i]["STEP_CODE"].ToString()); |
| | | dynamicParams.Add("@defect_id", json.Data.Rows[i]["ID"].ToString()); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count <= 0) |
| | | { |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,laborbad_qty,materielbad_qty,defect_code,style,lm_user,lm_date) |
| | | values(@defect_id,@wo_code,@partcode,@stepseq,@stepcode,@repair_qty,@laborbad_qty,@materielbad_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(), |
| | | stepcode = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()), |
| | | defect_code = json.Data.Rows[i]["DEFECT_CODE"].ToString(), |
| | | style = "S", |
| | | lm_user = us.usercode, |
| | | lm_date = date |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //更新报工缺陷处理记录表 |
| | | sql = @"update CSR_WorkRecord_DefectHandle set repair_qty=repair_qty+@repair_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id"; |
| | | 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(), |
| | | step_code = json.Data.Rows[i]["STEP_CODE"].ToString(), |
| | | repair_qty = decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()), |
| | | laborbad_qty = decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()), |
| | | materielbad_qty = decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()) |
| | | } |
| | | }); |
| | | } |
| | | sumrepair_qty = sumrepair_qty + decimal.Parse(json.Data.Rows[i]["REPAIR_QTY"].ToString()); |
| | | sumlaborbad_qty = sumlaborbad_qty + decimal.Parse(json.Data.Rows[i]["LABORBAD_QTY"].ToString()); |
| | | summaterielbad_qty = summaterielbad_qty + decimal.Parse(json.Data.Rows[i]["MATERIELBAD_QTY"].ToString()); |
| | | } |
| | | } |
| | | |
| | | //回写工单工序表合格数量、不良数量 |
| | | sql = @"update TK_Wrk_Step set good_qty=good_qty+@sumrepair_qty,ng_qty=ng_qty-@sumrepair_qty-@sumlaborbad_qty-@summaterielbad_qty,laborbad_qty=laborbad_qty+@sumlaborbad_qty,materielbad_qty=materielbad_qty+@summaterielbad_qty |
| | | where wo_code=@wo_code and step_code=@stepcode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo_code = json.Data.Rows[0]["WO_CODE"].ToString(), |
| | | stepcode = json.Data.Rows[0]["STEP_CODE"].ToString(), |
| | | sumrepair_qty = sumrepair_qty, |
| | | sumlaborbad_qty = sumlaborbad_qty, |
| | | summaterielbad_qty = summaterielbad_qty |
| | | } |
| | | }); |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "不良处理", "工单:" + json.Data.Rows[0]["WO_CODE"].ToString() + "工序:" + json.Data.Rows[0]["STEP_CODE"].ToString(), 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 MesOrderStepVerifySearch(string wkshopcode, string wo_code, string partnumber, string partname, string partspec, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and AA.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (wo_code != "" && wo_code != null) |
| | | { |
| | | search += "and AA.wo_code like '%'+@wo_code+'%' "; |
| | | dynamicParams.Add("@wo_code", wo_code); |
| | | } |
| | | if (partnumber != "" && partnumber != null) |
| | | { |
| | | search += "and AA.partnumber like '%'+@partnumber+'%' "; |
| | | dynamicParams.Add("@partnumber", partnumber); |
| | | } |
| | | 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 (reportuser != "" && reportuser != null) |
| | | { |
| | | search += "and AA.usercode like '%'+@reportuser+'%' "; |
| | | dynamicParams.Add("@reportuser", reportuser); |
| | | } |
| | | if (reportdateopendate != "" && reportdateopendate != null) |
| | | { |
| | | search += "and AA.report_date between @reportdateopendate and @reportdateclosedate "; |
| | | dynamicParams.Add("@reportdateopendate", reportdateopendate + " 00:00:00"); |
| | | dynamicParams.Add("@reportdateclosedate", reportdateclosedate + " 23:59:59"); |
| | | } |
| | | |
| | | |
| | | if (search == "") |
| | | { |
| | | search = "and 1=1 "; |
| | | } |
| | | search = search.Substring(3);//截取索引2后面的字符 |
| | | // --------------查询指定自制报工外协收料数据-------------- |
| | | var total = 0; //总条数 |
| | | var sql = @"select * from( |
| | | select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,A.task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.eqp_code,E.name as eqp_name, |
| | | A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,B.reckway,B.usergroup_code,G.usergroupname as usergroup_name, |
| | | B.report_person as usercode, |
| | | STUFF((SELECT ',' + U.username |
| | | FROM TUser U |
| | | WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.report_person + ',') > 0 |
| | | FOR XML PATH('')), 1, 1, '') AS username, |
| | | B.report_date,B.report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,'' as wx_code,'' as wx_name |
| | | from TK_Wrk_Record A |
| | | inner join TK_Wrk_RecordSub B on A.id=B.m_id |
| | | left join TK_Wrk_Man M on A.wo_code=M.wo_code |
| | | left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code |
| | | left join TStep S on A.step_code=S.stepcode |
| | | left join TMateriel_Info P on A.materiel_code=P.partcode |
| | | left join TOrganization T on M.wkshp_code=T.torg_code |
| | | left join TEqpInfo E on A.eqp_code=E.code |
| | | left join TGroup G on G.usergroupcode=B.usergroup_code |
| | | where A.style='B' and B.style='B' and M.status<>'CLOSED' and A.verify='N' |
| | | union all |
| | | select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,M.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.wx_code as eqp_code,E.name as eqp_name, |
| | | A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,'person' as reckway,'' as usergroup_code,'' as usergroup_name, |
| | | B.in_person as usercode, |
| | | STUFF((SELECT ',' + U.username |
| | | FROM TUser U |
| | | WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.in_person + ',') > 0 |
| | | FOR XML PATH('')), 1, 1, '') AS username, |
| | | B.in_time as report_date,B.sqty as report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,A.wx_code,C.name as wx_name |
| | | from TK_Wrk_OutRecord A |
| | | inner join TK_Wrk_OutRecordSub B on A.id = B.m_id |
| | | left join TK_Wrk_Man M on A.wo_code = M.wo_code |
| | | left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code |
| | | left join TStep S on A.step_code = S.stepcode |
| | | left join TMateriel_Info P on A.materiel_code = P.partcode |
| | | left join TOrganization T on M.wkshp_code = T.torg_code |
| | | left join TCustomer E on A.wx_code = E.code |
| | | left join TCustomer C on A.wx_code=C.code |
| | | where A.style = 'S' and B.style = 'S' and M.status<>'CLOSED' and A.verify='N' |
| | | ) as AA where" + 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 MesOrderStepModelSearch(string wo_code, string step_code, string step_type, string isbott, string isend, string id, string sbid) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (step_type == "Z") |
| | | { |
| | | sql = @"select D.id,D.record_id,D.defect_code, |
| | | STUFF((SELECT ',' + F.name |
| | | FROM TDefect F |
| | | WHERE CHARINDEX(',' + F.code + ',', ',' + D.defect_code + ',') > 0 |
| | | FOR XML PATH('')), 1, 1, '') AS defect_name, |
| | | D.defect_qty,laborbad_qty,materielbad_qty |
| | | from CSR_WorkRecord_Defect D |
| | | where wo_code=@wo_code and step_code=@step_code and record_id=@id"; |
| | | dynamicParams.Add("@wo_code", wo_code); |
| | | dynamicParams.Add("@step_code", step_code); |
| | | dynamicParams.Add("@id", id); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "查询成功!"; |
| | | mes.data = data; |
| | | |
| | | } |
| | | if (step_type == "W") |
| | | { |
| | | sql = @"select D.id,D.record_id,D.defect_code, |
| | | STUFF((SELECT ',' + F.name |
| | | FROM TDefect F |
| | | WHERE CHARINDEX(',' + F.code + ',', ',' + D.defect_code + ',') > 0 |
| | | FOR XML PATH('')), 1, 1, '') AS defect_name, |
| | | D.defect_qty,laborbad_qty,materielbad_qty |
| | | from CSR_WorkRecord_Defect D |
| | | where wo_code=@wo_code and step_code=@step_code and record_id=@id"; |
| | | dynamicParams.Add("@wo_code", wo_code); |
| | | dynamicParams.Add("@step_code", step_code); |
| | | dynamicParams.Add("@id", id); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | 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 MesOrderStepUpdateSeave(User us, List<UpdateProductReport> json) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //控制逻辑:首道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>任务数量 ==不能大于任务数量 |
| | | //控制逻辑:首道工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废) ==不能小于下道报工总数 |
| | | //控制逻辑:末道工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数 ==不能大于上道工序报工合格总数 |
| | | //控制逻辑:中间工序调整-> 本道工序当前调整总数(合格+不良+报废)+本道工序非当前报工总数(合格+不良+报废)>上道工序报工合格总数 ==不能大于上道工序报工合格总数 |
| | | //控制逻辑:中间工序调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废) ==不能小于下道报工总数 |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | list.Clear(); |
| | | //获取当前工序上道工序及属性 |
| | | sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A |
| | | left join TStep T on A.step_code=T.stepcode |
| | | where A.wo_code=@ordercode and A.seq=@seq-1 "; |
| | | dynamicParams.Add("@ordercode", json[0].wo_code); |
| | | dynamicParams.Add("@seq", json[0].step_seq); |
| | | var pre = DapperHelper.selectdata(sql, dynamicParams); |
| | | //获取当前工序下道工序及属性 |
| | | sql = @"select T.stepcode,T.stepname,T.flwtype from TK_Wrk_Step A |
| | | left join TStep T on A.step_code=T.stepcode |
| | | where A.wo_code=@ordercode and A.seq=@seq+1 "; |
| | | dynamicParams.Add("@ordercode", json[0].wo_code); |
| | | dynamicParams.Add("@seq", json[0].step_seq); |
| | | var next = DapperHelper.selectdata(sql, dynamicParams); |
| | | //判断当前工序是自制工序还是外协工序 |
| | | if (json[0].flw_type.ToString() == "Z")//自制工序 |
| | | { |
| | | //获取此次报工调整提交的数据(合格数量、不良数量、工废数量、料废数量) |
| | | decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //报工数量(合格) |
| | | decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总 |
| | | decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总 |
| | | decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总 |
| | | decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总 |
| | | decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总 |
| | | decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总 |
| | | //首道工序的报工 |
| | | if (json[0].first_choke == "Y") |
| | | { |
| | | //查询当前首道报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次报工总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次报工数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>工单任务数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(json[0].task_qty.ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序修改报工总数量:【" + updatereportsumqty + "】不能大于工单任务数量:【" + json[0].task_qty.ToString() + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | //末道工序的报工 |
| | | else if (json[0].last_choke == "Y") |
| | | { |
| | | //查询当前末道报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前末道工序非本次报工总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前末道工序非本次报工总数 |
| | | decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前末道工序非本次报工工废总数 |
| | | decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前末道工序非本次报工料废总数 |
| | | //获取当前末道工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次报工总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty; |
| | | |
| | | //判断是否存在上道工序及属性 |
| | | if (pre.Rows.Count > 0) |
| | | { |
| | | if (pre.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前末道工序上道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq-1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //上道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //上道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //上道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //上道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断:当前末道工序报工记录:当前末道工序报工总数量>上道工序报工合格总数 |
| | | if (updatereportsumqty > last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总合格数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序上道工序:总收料数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and step_seq=@step_seq-1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:收料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断:当前末道工序报工记录:当前末道工序报工总数量>上道工序收料合格总数 |
| | | if (updatereportsumqty > last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序收料总合格数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else //中间工序的报工 |
| | | { |
| | | //查询当前中间报工工序非此次报工:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次报工总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总数 |
| | | decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工工费总数 |
| | | decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工料废总数 |
| | | //获取当前中间工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改工废数量+本次修改料废总数+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty; |
| | | |
| | | //判断是否存在上道工序及属性 |
| | | if (pre.Rows.Count > 0) |
| | | { |
| | | if (pre.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序上道工序:总报工数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq-1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //上道工序报工总合格数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //上道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //上道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString());//上道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断:当前工序报工记录:当前工序报工总数>上道工序报工总合格数 |
| | | if (updatereportsumqty > last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总合格数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序上道工序:总收料数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and step_seq=@step_seq-1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:收料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //上道工序收料总合格数量 |
| | | //判断:当前末道工序报工记录:当前工序报工总数量>上道工序收料总合格数量 |
| | | if (updatereportsumqty > last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序收料总合格数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //判断是否存在下道工序属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt1.Rows.Count > 0) |
| | | { |
| | | decimal last_reportqty = decimal.Parse(dt1.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt1.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt1.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt1.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序修改报工总合格数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总合格数量 |
| | | //判断(当前非本次报工总合格数+本次报工调整合格数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序修改报工总数量:【" + (notthis_reportqty + this_reportqty) + "】不能大于下道工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | ///////////////////////////////修改报工////////////////////////////// |
| | | |
| | | //回写对应的报工记录子表合格数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_RecordSub set report_qty=report_qty+@repair_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty, |
| | | updatereportuser=@updatereportuser,updatereportdate=@updatereportdate |
| | | where m_id=@m_id and id=@id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(json[0].id), |
| | | id = int.Parse(json[0].sbid), |
| | | repair_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | | materielbad_qty = this_materielbad_dvalue, |
| | | //bad_money = decimal.Parse(json[i].badmoney_dvalue), |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | //回写对应的报工记录主表合格数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_Record set start_qty=start_qty+@good_qty, good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty, |
| | | updatereportuser=@updatereportuser,updatereportdate=@updatereportdate |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | good_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | | materielbad_qty = this_materielbad_dvalue, |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code, |
| | | id = int.Parse(json[0].id), |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | //回写工单工序表 |
| | | sql = @"update TK_Wrk_Step set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | good_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | | materielbad_qty = this_materielbad_dvalue, |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code |
| | | } |
| | | }); |
| | | |
| | | for (int i = 0; i < json[0].children.Count; i++) |
| | | { |
| | | //回写不良 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,defect_pendqty=defect_pendqty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty, |
| | | updatereportuser=@updatereportuser,updatereportdate=@updatereportdate |
| | | where wo_code=@wo_code and step_code=@step_code and id=@ng_id and record_id=@record_id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | ng_qty = decimal.Parse(json[0].children[i].ng_dvalue), |
| | | laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue), |
| | | materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue), |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code, |
| | | ng_id = int.Parse(json[0].children[i].ng_id), |
| | | record_id = json[0].id, |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | //回写不良处理 |
| | | sql = @"update CSR_WorkRecord_DefectHandle set laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id and style='B'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue), |
| | | materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue), |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code, |
| | | defect_id = int.Parse(json[0].children[i].ng_id), |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | if (json[0].flw_type.ToString() == "W")//外协工序 |
| | | { |
| | | //查询当前首道工序非此次供应商收料:总收料数量 |
| | | sql = @"select isnull(sum(sqty),0) as sqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code<>@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_c = DapperHelper.selectdata(sql, dynamicParams); |
| | | //获取此次报工调整提交的数据(收料数量、不良数量、工废数量、料废数量) |
| | | decimal this_reportqty = decimal.Parse(json[0].report_qty.ToString()); //收料数量 |
| | | decimal this_ngqty = json[0].children.Sum(item => decimal.Parse(item.ng_qty));//不良数量汇总 |
| | | decimal this_laborbadqty = json[0].children.Sum(item => decimal.Parse(item.laborbad_qty));//工废数量汇总 |
| | | decimal this_materielbadqty = json[0].children.Sum(item => decimal.Parse(item.materielbad_qty));//料废数量汇总 |
| | | decimal this_ng_dvalue = json[0].children.Sum(item => decimal.Parse(item.ng_dvalue));//不良数量差值汇总 |
| | | decimal this_laborbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.laborbad_dvalue));//工废数量差值汇总 |
| | | decimal this_materielbad_dvalue = json[0].children.Sum(item => decimal.Parse(item.materielbad_dvalue));//料废数量差值汇总 |
| | | //获取当前工序、供应商对应的发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as fqty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt_0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | //首道工序的收料 |
| | | if (json[0].first_choke == "Y") |
| | | { |
| | | //查询当前首道工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次收料数+本次报工调整收料数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料总数量:【" + (notthis_reportqty + this_reportqty) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | //末道工序的报工 |
| | | else if (json[0].last_choke == "Y") |
| | | { |
| | | //查询当前末道报工工序非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前末道工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前末道工序非本次报工总数 |
| | | decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前末道工序非本次报工工废总数 |
| | | decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前末道工序非本次报工料废总数 |
| | | //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前末道工序非本次收料总数+当前末道工序非本次不良总数+当前末道工序非本次工废总数+当前末道工序非本次料废总数 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty; |
| | | //判断当前工序供应商收料总数>当前工序供应商对应发料数量 |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前工序供应商收料总数量:【" + updatereportsumqty + "】不能大于工序供应商发料总数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | } |
| | | else //中间工序的报工 |
| | | { |
| | | |
| | | //查询当前首道工序供应商非此次收料:总收料数量、总不良数量、总工废数量、总料废数量 |
| | | sql = @"select isnull(sum(sqty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='S' and id<>@id and step_code=@step_code and wx_code=@wx_code"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@id", json[0].id); |
| | | dynamicParams.Add("@step_code", json[0].step_code); |
| | | dynamicParams.Add("@wx_code", json[0].wxcode); |
| | | var dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString()); //当前工序非本次收料总数 |
| | | decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString()); //当前工序非本次报工总不良数 |
| | | decimal notthis_laborbadqty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString()); //当前工序非本次报工总工废数 |
| | | decimal notthis_materielbadqty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString()); //当前工序非本次报工总料废数 |
| | | //判断:当前工序报工记录:本次收料数量+本次不良数量+本次工废数量+本次料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数>发料数量 |
| | | decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbadqty + notthis_materielbadqty; |
| | | if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString())) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序对应供应商收料总数量:【" + updatereportsumqty + "】不能大于发料数量:【" + decimal.Parse(dt_0.Rows[0]["fqty"].ToString()) + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断是否存在下道工序及属性 |
| | | if (next.Rows.Count > 0) |
| | | { |
| | | if (next.Rows[0]["flwtype"].ToString() == "Z") |
| | | { |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty |
| | | from TK_Wrk_Record where wo_code=@wo_code and style='B' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:报工总数数量+不良总数数量+工废总数量+料废总数量<下道工序报工总数量+下道工序不良总数量+下道工序工废总数量+下道工序料废总数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序报工总数量 |
| | | decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString()); //下道工序不良总数量 |
| | | decimal last_laborbad_qty = decimal.Parse(dt0.Rows[0]["laborbad_qty"].ToString()); //下道工序工废总数量 |
| | | decimal last_materielbad_qty = decimal.Parse(dt0.Rows[0]["materielbad_qty"].ToString()); //下道工序料废总数量 |
| | | decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_laborbad_qty + last_materielbad_qty; |
| | | //判断(当前非本次收料数+本次收料调整数+非当前供应商同工序收料总数)<下道工序报工总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_updatereportsumqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道自制工序报工总数量:【" + last_updatereportsumqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //查询当前工序下道工序:总发料数量 |
| | | sql = @"select isnull(sum(fqty),0) as good_qty |
| | | from TK_Wrk_OutRecord where wo_code=@wo_code and style='F' and step_seq=@step_seq+1"; |
| | | dynamicParams.Add("@wo_code", json[0].wo_code); |
| | | dynamicParams.Add("@step_seq", json[0].step_seq); |
| | | var dt0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt0.Rows.Count > 0) |
| | | { |
| | | //判断当前工序:发料总数数量 |
| | | decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString()); //下道工序发料总数量 |
| | | //判断(当前非本次收料数+本次报工调整收料数+非当前供应商同工序收料总数)<下道工序发料总数 |
| | | if ((notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) < last_reportqty) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "当前首道工序收料总数量:【" + (notthis_reportqty + this_reportqty + decimal.Parse(dt_c.Rows[0]["sqty"].ToString())) + "】不能小于下道外协工序发料总数量:【" + last_reportqty + "】!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | ///////////////////////////////修改报工////////////////////////////// |
| | | |
| | | //回写对应的外协记录子表收料数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_OutRecordSub set sqty=sqty+@repair_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty, |
| | | updatereportuser=@updatereportuser,updatereportdate=@updatereportdate |
| | | where m_id=@m_id and id=@id and style='S' and wx_code=@wx_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(json[0].id), |
| | | id = int.Parse(json[0].sbid), |
| | | repair_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | | materielbad_qty = this_materielbad_dvalue, |
| | | wx_code = json[0].wxcode, |
| | | //bad_money = decimal.Parse(json[i].badmoney_dvalue), |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | //回写对应的收料记录主表收料数量、不良数量、报废数量 |
| | | sql = @"update TK_Wrk_OutRecord set sqty=sqty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty, |
| | | updatereportuser=@updatereportuser,updatereportdate=@updatereportdate |
| | | where wo_code=@wo_code and step_code=@step_code and id=@id and style='S' and wx_code=@wx_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | good_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | | materielbad_qty = this_materielbad_dvalue, |
| | | wx_code = json[0].wxcode, |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code, |
| | | id = int.Parse(json[0].id), |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | //回写工单工序表 |
| | | sql = @"update TK_Wrk_Step set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | good_qty = decimal.Parse(json[0].report_dvalue), |
| | | ng_qty = this_ng_dvalue, |
| | | laborbad_qty = this_laborbad_dvalue, |
| | | materielbad_qty = this_materielbad_dvalue, |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code |
| | | } |
| | | }); |
| | | |
| | | for (int i = 0; i < json[0].children.Count; i++) |
| | | { |
| | | //回写不良 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,defect_pendqty=defect_pendqty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty, |
| | | updatereportuser=@updatereportuser,updatereportdate=@updatereportdate |
| | | where wo_code=@wo_code and step_code=@step_code and id=@ng_id and record_id=@record_id and style='S'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | ng_qty = decimal.Parse(json[0].children[i].ng_dvalue), |
| | | laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue), |
| | | materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue), |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code, |
| | | ng_id = int.Parse(json[0].children[i].ng_id), |
| | | record_id = json[0].id, |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | //回写不良处理 |
| | | sql = @"update CSR_WorkRecord_DefectHandle set laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | where wo_code=@wo_code and step_code=@step_code and defect_id=@defect_id and style='S'"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | laborbad_qty = decimal.Parse(json[0].children[i].laborbad_dvalue), |
| | | materielbad_qty = decimal.Parse(json[0].children[i].materielbad_dvalue), |
| | | wo_code = json[0].wo_code, |
| | | step_code = json[0].step_code, |
| | | defect_id = int.Parse(json[0].children[i].ng_id), |
| | | updatereportuser = us.usercode, |
| | | updatereportdate = date |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "报工调整", "工单:" + json[0].wo_code + "工序:" + json[0].step_code, 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 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) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string search = ""; |
| | | try |
| | | { |
| | | if (wkshopcode != "" && wkshopcode != null) |
| | | { |
| | | search += "and AA.wkshp_code=@wkshopcode "; |
| | | dynamicParams.Add("@wkshopcode", wkshopcode); |
| | | } |
| | | if (wo_code != "" && wo_code != null) |
| | | { |
| | | search += "and AA.wo_code like '%'+@wo_code+'%' "; |
| | | dynamicParams.Add("@wo_code", wo_code); |
| | | } |
| | | if (partnumber != "" && partnumber != null) |
| | | { |
| | | search += "and AA.partnumber like '%'+@partnumber+'%' "; |
| | | dynamicParams.Add("@partnumber", partnumber); |
| | | } |
| | | 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 (stepname != "" && stepname != null) |
| | | { |
| | | search += "and AA.stepname like '%'+@stepname+'%' "; |
| | | dynamicParams.Add("@stepname", stepname); |
| | | } |
| | | if (reportuser != "" && reportuser != null) |
| | | { |
| | | search += "and AA.usercode like '%'+@reportuser+'%' "; |
| | | dynamicParams.Add("@reportuser", reportuser); |
| | | } |
| | | if (reportdateopendate != "" && reportdateopendate != null) |
| | | { |
| | | search += "and AA.report_date between @reportdateopendate and @reportdateclosedate "; |
| | | dynamicParams.Add("@reportdateopendate", reportdateopendate + " 00:00:00"); |
| | | dynamicParams.Add("@reportdateclosedate", reportdateclosedate + " 23:59:59"); |
| | | } |
| | | |
| | | |
| | | if (search == "") |
| | | { |
| | | search = "and 1=1 "; |
| | | } |
| | | search = search.Substring(3);//截取索引2后面的字符 |
| | | // --------------查询指定自制报工外协收料数据-------------- |
| | | var total = 0; //总条数 |
| | | var sql = @"select * from( |
| | | select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,A.task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.eqp_code,E.name as eqp_name, |
| | | A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,B.reckway,B.usergroup_code,G.usergroupname as usergroup_name, |
| | | B.report_person as usercode, |
| | | STUFF((SELECT ',' + U.username |
| | | FROM TUser U |
| | | WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.report_person + ',') > 0 |
| | | FOR XML PATH('')), 1, 1, '') AS username, |
| | | B.report_date,B.report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,'' as wx_code,'' as wx_name,A.verify |
| | | from TK_Wrk_Record A |
| | | inner join TK_Wrk_RecordSub B on A.id=B.m_id |
| | | left join TK_Wrk_Man M on A.wo_code=M.wo_code |
| | | left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code |
| | | left join TStep S on A.step_code=S.stepcode |
| | | left join TMateriel_Info P on A.materiel_code=P.partcode |
| | | left join TOrganization T on M.wkshp_code=T.torg_code |
| | | left join TEqpInfo E on A.eqp_code=E.code |
| | | left join TGroup G on G.usergroupcode=B.usergroup_code |
| | | where A.style='B' and B.style='B' and M.status<>'CLOSED' |
| | | union all |
| | | select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,M.plan_qty as task_qty,M.wkshp_code,T.torg_name as wkshp_name,A.wx_code as eqp_code,E.name as eqp_name, |
| | | A.step_seq,A.step_code,S.stepname,S.flwtype as steptype,k.isbott as first_choke,k.isend as last_choke,A.step_price,'person' as reckway,'' as usergroup_code,'' as usergroup_name, |
| | | B.in_person as usercode, |
| | | STUFF((SELECT ',' + U.username |
| | | FROM TUser U |
| | | WHERE CHARINDEX(',' + U.usercode + ',', ',' + B.in_person + ',') > 0 |
| | | FOR XML PATH('')), 1, 1, '') AS username, |
| | | B.in_time as report_date,B.sqty as report_qty,B.ng_qty,B.laborbad_qty,B.materielbad_qty,A.wx_code,C.name as wx_name,A.verify |
| | | from TK_Wrk_OutRecord A |
| | | inner join TK_Wrk_OutRecordSub B on A.id = B.m_id |
| | | left join TK_Wrk_Man M on A.wo_code = M.wo_code |
| | | left join TK_Wrk_Step K on M.wo_code=K.wo_code and A.step_code=K.step_code |
| | | left join TStep S on A.step_code = S.stepcode |
| | | left join TMateriel_Info P on A.materiel_code = P.partcode |
| | | left join TOrganization T on M.wkshp_code = T.torg_code |
| | | left join TCustomer E on A.wx_code = E.code |
| | | left join TCustomer C on A.wx_code=C.code |
| | | where A.style = 'S' and B.style = 'S' and M.status<>'CLOSED' |
| | | ) as AA where" + 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 MesOrderStepReportVerifySeave(User us, DataModel json) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (json.zdata.Count > 0) |
| | | { |
| | | //回写报工记录主表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_Record set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate where id in @id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.zdata } }); |
| | | //回写报工记录子表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_RecordSub set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate where m_id in @id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.zdata } }); |
| | | } |
| | | if (json.wdata.Count > 0) |
| | | { |
| | | //回写外协记录主表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_OutRecord set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate where id in @id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.wdata } }); |
| | | //回写外协记录子表审核状态、审核人、审核时间 |
| | | sql = @"update TK_Wrk_OutRecordSub set verify='Y',verifyuser=@verifyuser,verifydate=@verifydate where m_id in @id"; |
| | | list.Add(new { str = sql, parm = new { verifyuser = us.usercode, verifydate = DateTime.Now.ToString(), id = json.wdata } }); |
| | | } |
| | | 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); |
| | | 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 |
| | | } |
| | | } |