| | |
| | | using Dapper; |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | |
| | | // --------------查询指定数据-------------- |
| | | 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 TMateriel_Info B on A.materiel_code=B.partcode |
| | |
| | | //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 |
| | |
| | | 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"); |
| | |
| | | // --------------查询指定数据-------------- |
| | | 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 |
| | |
| | | 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"; |
| | |
| | | } |
| | | #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> 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)"; |
| | | 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 } }); |
| | | //回写工单工序表状态为START: 开工 |
| | | sql = @"update TK_Wrk_Step set status='START' where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | |
| | | //回写工单工序表状态为已开工 |
| | | sql = @"update TK_Wrk_Step set status='START' where wo_code=@mesordercode and step_code=@stepcode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, stepcode = stepcode } }); |
| | | //回写工单表状态为: 开工:START |
| | | sql = @"update TK_Wrk_Man set status='START' where wo_code=@mesordercode"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode } }); |
| | | } |
| | | |
| | | //判断是否有报工记录(有:修改 无:新增) |
| | | 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 } }); |
| | | |
| | | //写入子表 |
| | | 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) |
| | | values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@reckway,@usergroup_code,@ratio,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(dt.Rows[0]["ID"].ToString()), |
| | | eqp_code = eqpcode, |
| | | report_person = arra[i]["usercode"].ToString(), |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = decimal.Parse(arra[i]["ratio"].ToString()), |
| | | ng_qty = ngqty, |
| | | style = "B", |
| | | lm_user = 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 } }); |
| | | |
| | | //写入子表 |
| | | 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) |
| | | values(@m_id,@eqp_code,@report_person,@report_date,@report_qty,@reckway,@usergroup_code,@ratio,@ng_qty,@style,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | m_id = int.Parse(dt.Rows[0]["ID"].ToString()), |
| | | eqp_code = eqpcode, |
| | | report_person = arra[i]["usercode"].ToString(), |
| | | report_date = date, |
| | | report_qty = reportqty, |
| | | reckway = reckway, |
| | | usergroup_code = usergroupcode, |
| | | ratio = decimal.Parse(arra[i]["ratio"].ToString()), |
| | | ng_qty = ngqty, |
| | | style = "B", |
| | | lm_user = 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) |
| | | { |
| | | 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) |
| | | { |
| | | 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) |
| | | { |
| | | 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_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 = @"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 |
| | | } |
| | | }); |
| | | |
| | | 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_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 = @"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 |
| | | } |
| | | }); |
| | | 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) |
| | | { |
| | | 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 |
| | | } |
| | | } |