| | |
| | | using System.Linq; |
| | | using System.Threading.Tasks; |
| | | using VueWebCoreApi.Models; |
| | | using VueWebCoreApi.Models.UpdateReport; |
| | | using VueWebCoreApi.Models.WorkData; |
| | | using VueWebCoreApi.Tools; |
| | | |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | 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,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 TStep S on A.step_code=S.stepcode |
| | | 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) |
| | | { |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | 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,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 |
| | | 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) |
| | | { |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | |
| | | if (ordercode != "" && stepcode == null) //工单号不为空,工序号为空 |
| | | if (ordercode != "" && (stepcode == null || stepcode == "")) //工单号不为空,工序号为空 |
| | | { |
| | | search += "and A.wo_code=@ordercode "; |
| | | dynamicParams.Add("@ordercode", ordercode); |
| | |
| | | dynamicParams.Add("@partspec", partspec); |
| | | } |
| | | //根据条件查询工单工序任务(自制工序) |
| | | sql = @"select A.wo_code,M.partcode,M.partname,M.partspec,A.seq,A.isend, |
| | | sql = @"select A.id,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 TStep S on A.step_code=S.stepcode |
| | | 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 = ScanStartReport.ZZEncodingSeach(wocode, stepcode); |
| | | break; |
| | | case "WX": |
| | | mes = ScanStartReport.WXEncodingSeach(SelectType, stepcode, stepcode); |
| | | mes = ScanStartReport.WXEncodingSeach(SelectType, wocode, stepcode); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | #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) |
| | | 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); |
| | | //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(); // 汇总不良数量 |
| | |
| | | dynamicParams.Add("@step_code", stepcode); |
| | | dynamicParams.Add("@eqpcode", eqpcode); |
| | | var data0 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data0.Rows.Count <= 0) |
| | | 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)"; |
| | | list.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 } }); |
| | | 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"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | list0.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | |
| | | //回写工单工序表状态为已开工 |
| | | sql = @"update TK_Wrk_Step set status='START' where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | //回写工单表状态为: 开工:START |
| | | sql = @"update TK_Wrk_Man set status='START' where wo_code=@mesordercode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode } }); |
| | | 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 = @"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 } }); |
| | | 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 } }); |
| | | |
| | | //写入子表 |
| | | for (int i = 0; i < arra.Count; i++) |
| | | { |
| | | 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) |
| | | 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 |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(dt.Rows[0]["ID"].ToString()), |
| | | eqp_code = eqpcode, |
| | | report_person = arra[i]["usercode"].ToString(), |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = decimal.Parse(arra[i]["ratio"].ToString()), |
| | | ng_qty = ngqty, |
| | | style = "B", |
| | | lm_user = us.usercode, |
| | | lm_date = date |
| | | } |
| | | }); |
| | | |
| | | } |
| | | 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) |
| | | { |
| | | //写入缺陷记录表 |
| | |
| | | //写入开报工记录表 |
| | | 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 } }); |
| | | 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 } }); |
| | | |
| | | //写入子表 |
| | | for (int i = 0; i < arra.Count; i++) |
| | | { |
| | | 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) |
| | | 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 |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(dt.Rows[0]["ID"].ToString()), |
| | | eqp_code = eqpcode, |
| | | report_person = arra[i]["usercode"].ToString(), |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = decimal.Parse(arra[i]["ratio"].ToString()), |
| | | ng_qty = ngqty, |
| | | style = "B", |
| | | lm_user = us.usercode, |
| | | lm_date = date |
| | | } |
| | | }); |
| | | |
| | | } |
| | | 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) |
| | | { |
| | | //写入缺陷记录表 |
| | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "报工", "报工了工单:" + mesordercode + "工序:" + stepcode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "操作成功!"; |
| | |
| | | //修改发料记录 |
| | | 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 } }); |
| | | 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)"; |
| | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "外协发料", "外协发料工单:" + mesordercode + "工序:" + stepcode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "发料成功!"; |
| | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "外协收料", "外协收料工单:" + mesordercode + "工序:" + stepcode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "收成功!"; |
| | |
| | | string[] arra1 = new string[] { }; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | decimal sumrepair_qty = 0, sumlaborbad_qty = 0,summaterielbad_qty=0; //累计维修数量、累计工废数量、累计料废数量 |
| | | decimal sumrepair_qty = 0, sumlaborbad_qty = 0, summaterielbad_qty = 0; //累计维修数量、累计工废数量、累计料废数量 |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | |
| | | } |
| | | }); |
| | | //回写缺陷记录表的待处理数量 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | 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 |
| | | { |
| | |
| | | id = int.Parse(json.Data.Rows[i]["ID"].ToString()) |
| | | } |
| | | }); |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,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 |
| | | //判断缺陷记录处理表是否存在记录 |
| | | 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) |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | //写入报工缺陷处理记录表 |
| | | 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 |
| | | { |
| | | 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 |
| | | } |
| | | }); |
| | | 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()); |
| | |
| | | } |
| | | }); |
| | | //回写缺陷记录表的待处理数量 |
| | | sql = @"update CSR_WorkRecord_Defect set defect_pendqty=defect_pendqty-@repair_qty-@laborbad_qty-@materielbad_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty |
| | | 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 |
| | | { |
| | |
| | | id = int.Parse(json.Data.Rows[i]["ID"].ToString()) |
| | | } |
| | | }); |
| | | //写入报工缺陷处理记录表 |
| | | sql = @"insert into CSR_WorkRecord_DefectHandle(defect_id,wo_code,partnumber,step_seq,step_code,repair_qty,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 |
| | | //判断缺陷记录处理表是否存在记录 |
| | | 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) |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | //写入报工缺陷处理记录表 |
| | | 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 |
| | | { |
| | | 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 |
| | | } |
| | | }); |
| | | 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()); |
| | |
| | | stepcode = json.Data.Rows[0]["STEP_CODE"].ToString(), |
| | | sumrepair_qty = sumrepair_qty, |
| | | sumlaborbad_qty = sumlaborbad_qty, |
| | | summaterielbad_qty= summaterielbad_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 = "操作成功!"; |
| | |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region[生产执行,报工调整数据查询接口] |
| | | public static ToMessage MesOrderStepVerifySearch(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 (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 |
| | | 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 B.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 |
| | | 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 |
| | | where A.style = 'S' and B.style = 'S' and M.status<>'CLOSED' and B.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(); |
| | | //判断当前工序是自制工序还是外协工序 |
| | | 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; |
| | | } |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | 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 + decimal.Parse(json[0].report_qty) < last_updatereportsumqty)) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "自制首道工序修改报工总合格数量:【" + (notthis_reportqty + decimal.Parse(json[0].report_qty)) + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】,请输入合法数值或先修改下道工序报工数量!"; |
| | | 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; |
| | | |
| | | //查询当前末道工序上道工序:总报工数量、总不良数量、总报废数量 |
| | | 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(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; |
| | | //查询当前工序上道工序:总报工数量、总不良数量、总工废数量、总料废数量 |
| | | 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; |
| | | } |
| | | } |
| | | //查询当前工序下道工序:总报工数量、总不良数量、总报废数量 |
| | | 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 + decimal.Parse(json[0].report_qty)< last_updatereportsumqty)) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "自制工序修改报工总合格数量:【" + (notthis_reportqty + decimal.Parse(json[0].report_qty)) + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】,请输入合法数值或先修改下道工序报工数量!"; |
| | | 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 |
| | | 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) |
| | | } |
| | | }); |
| | | //回写工单工序表 |
| | | 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")//外协工序 |
| | | { |
| | | |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "修改报工成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "修改报工失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | } |
| | | } |