| | |
| | | // --------------查询指定数据-------------- |
| | | var total = 0; //总条数 |
| | | var sql = @"select A.id, A.status,A.wo,A.materiel_code as partcode,B.partname,B.partspec,A.qty,A.relse_qty,A.wkshp_code,C.org_name as wkshp_name, |
| | | A.stck_code,D.name as stck_name,A.planstartdate,A.planenddate,U.username as createuser,A.createdate |
| | | A.stck_code,D.name as stck_name,saleOrderDeliveryDate,A.planstartdate,A.planenddate,U.username as createuser,A.createdate |
| | | from TKimp_Ewo A |
| | | left join TMateriel_Info B on A.materiel_code=B.partcode |
| | | left join TOrganization C on A.wkshp_code=C.org_code |
| | |
| | | #endregion |
| | | |
| | | #region[ERP订单下达] |
| | | public static ToMessage MarkSaveErpOrder(string erporderid, string erpordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty, string username) |
| | | public static ToMessage MarkSaveErpOrder(string erporderid, string erpordercode, string partcode, string wkshopcode, string warehousecode, string erpqty, string markqty, string ordernum, string relse_qty,string saleOrderDeliveryDate, string username) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | |
| | | try |
| | | { |
| | | list.Clear(); |
| | |
| | | } |
| | | if (decimal.Parse(erpqty) == decimal.Parse(markqty) + decimal.Parse(relse_qty)) //如果ERP订单=下单数量+已下单数量,则更新ERP订单表状态为CREATED:已创建 |
| | | { |
| | | sql = @"update TKimp_Ewo set status='CREATED',relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | sql = @"update TKimp_Ewo set status='CREATED',saleOrderDeliveryDate=@saleOrderDeliveryDate,relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid, |
| | | sumqty = sumqty |
| | | sumqty = sumqty, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | } |
| | | else //更新ERP订单表状态为CREATING:创建中 |
| | | { |
| | | sql = @"update TKimp_Ewo set status='CREATING',relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | sql = @"update TKimp_Ewo set status='CREATING',saleOrderDeliveryDate=@saleOrderDeliveryDate,relse_qty=relse_qty+@sumqty where wo=@wo and id=@erporderid"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | { |
| | | wo = erpordercode, |
| | | erporderid = erporderid, |
| | | sumqty = sumqty |
| | | sumqty = sumqty, |
| | | saleOrderDeliveryDate = Convert.ToDateTime(saleOrderDeliveryDate) |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region【生产管理、工单新增、编辑时,选择排程是时获取物料清单版本号】 |
| | | public static ToMessage JobCreationSonAddVison(string partnumber) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | sql = @" select id,version from TBom_Main where materiel_code=@partnumber and status='Y' order by version desc "; |
| | | dynamicParams.Add("@partnumber", partnumber); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[MES工单新增、编辑提交] |
| | | public static ToMessage AddUpdateMesOrder(string mesorderstus, string sourceorder, string ordertype, string mesordercode, string partcode, string mesqty, string routecode, string wkshopcode, string planstartdate, string planenddate, string orderlev, string username, string opertype, string is_aps, string bom_id) |
| | | { |
| | |
| | | where A.m_id=@bom_id"; |
| | | list.Add(new { str = sql, parm = new { wocode = mesordercode, uomqty = mesqty, bom_id = bom_id } }); |
| | | |
| | | wo_status = "NEW"; |
| | | wrk_status = "NEW"; |
| | | wo_status = "NOSCHED"; |
| | | wrk_status = "NOSCHED"; |
| | | } |
| | | else //否 |
| | | { |
| | |
| | | wrk_status = "ALLO"; |
| | | } |
| | | //写入工单表 |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,plan_startdate,plan_enddate,route_code,stck_code,lm_user,lm_date,materiel_code,m_po,piroque) |
| | | values(@mesordercode,@wotype,@mesorderstus,@wkshopcode,@mesqty,@planstartdate,@planenddate,@routecode,@stck_code,@username,@CreateDate,@materiel_code,@m_po,@orderlev)"; |
| | | sql = @"insert into TK_Wrk_Man(wo_code,wotype,status,wkshp_code,plan_qty,plan_startdate,plan_enddate,route_code,stck_code,lm_user,lm_date,materiel_code,m_po,piroque,isaps) |
| | | values(@mesordercode,@wotype,@mesorderstus,@wkshopcode,@mesqty,@planstartdate,@planenddate,@routecode,@stck_code,@username,@CreateDate,@materiel_code,@m_po,@orderlev,@isaps)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | materiel_code = partcode, |
| | | orderlev = orderlev |
| | | orderlev = orderlev, |
| | | isaps = is_aps |
| | | } |
| | | }); |
| | | //写入工序任务表 |
| | |
| | | } |
| | | if (opertype == "Update") |
| | | { |
| | | sql = @"update TK_Wrk_Man set route_code=@routecode,wkshp_code=@wkshopcode,plan_startdate=@planstartdate,plan_enddate=@planenddate,status=@status,piroque=@orderlev,lm_user=@username,lm_date=@CreateDate where wo_code=@mesordercode"; |
| | | if (is_aps == "Y") //是否排程(是) |
| | | { |
| | | //判断物料清单 |
| | | sql = "select id from TBom_Main where materiel_code=@partcode and status='Y' and id=@bom_id"; |
| | | dynamicParams.Add("@partcode", partcode); |
| | | dynamicParams.Add("@bom_id", bom_id); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count <= 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "工单对应的产品没有建立BOM或BOM未审核!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //增加工单用料表(子件) |
| | | sql = @"insert into TK_Wrk_Allo(wo_code, seq, materiel_code, basqty, qty,bom_id,materieltype,stck_code,stopfeed,base_quantity,loss_quantity,m_quantity) |
| | | select @wocode,A.seq,A.smateriel_code,A.total_quantity,(convert(decimal(18, 0), @uomqty)*A.Base_Quantity*(1+A.LOSS_QUANTITY/100))/C.quantity, |
| | | A.m_id,A.pn_type,'','N',A.base_quantity,A.loss_quantity,C.quantity |
| | | from TBom_Deta A left join TBom_Main C on A.m_Id=C.id |
| | | left join TMateriel_Info B on A.smateriel_code = B.partcode |
| | | where A.m_id=@bom_id"; |
| | | list.Add(new { str = sql, parm = new { wocode = mesordercode, uomqty = mesqty, bom_id = bom_id } }); |
| | | |
| | | wo_status = "NOSCHED"; |
| | | wrk_status = "NOSCHED"; |
| | | } |
| | | else //否 |
| | | { |
| | | wo_status = "ALLO"; |
| | | wrk_status = "ALLO"; |
| | | } |
| | | sql = @"update TK_Wrk_Man set route_code=@routecode,wkshp_code=@wkshopcode,plan_startdate=@planstartdate,plan_enddate=@planenddate,status=@status,piroque=@orderlev,lm_user=@username,lm_date=@CreateDate,isaps=@isaps where wo_code=@mesordercode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | wkshopcode = wkshopcode, |
| | | planstartdate = planstartdate, |
| | | planenddate = planenddate, |
| | | status = "ALLO", //派发 |
| | | status = wo_status, |
| | | routecode = routecode, |
| | | username = username, |
| | | CreateDate = DateTime.Now.ToString(), |
| | | orderlev = orderlev |
| | | orderlev = orderlev, |
| | | isaps= is_aps |
| | | } |
| | | }); |
| | | //写入工序任务表 |
| | |
| | | mesqty = mesqty, |
| | | planstartdate = planstartdate, |
| | | planenddate = planenddate, |
| | | status = "ALLO", //派发 |
| | | status = wo_status, |
| | | username = username, |
| | | routecode = routecode, |
| | | CreateDate = DateTime.Now.ToString() |
| | |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //判断工单是否为未开始状态或者已派发状态(满足其中一种都可删除,否则不允许删除) |
| | | sql = @"select * from TK_Wrk_Man where wo_code=@wocode and status='NEW' or status='ALLO'"; |
| | | //判断工单是否为未开始状态或者已派发或待排程状态(满足其中一种都可删除,否则不允许删除) |
| | | sql = @"select * from TK_Wrk_Man where wo_code=@wocode and status in('NEW','ALLO','NOSCHED')"; |
| | | dynamicParams.Add("@wocode", wocode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | |
| | | } |
| | | //删除工单工序表 |
| | | sql = @"delete TK_Wrk_Step where wo_code=@wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode } }); |
| | | |
| | | //删除加工单用料表(子件) |
| | | sql = @"delete TK_Wrk_Allo where wo_code=@wocode"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode } }); |
| | | |
| | | //删除工单表 |
| | |
| | | left join TStep B on A.step_code=B.stepcode |
| | | left join TK_Wrk_Man M on A.wo_code=M.wo_code |
| | | left join TMateriel_Info P on M.materiel_code=P.partcode |
| | | where A.wo_code=@wo_code"; |
| | | where A.wo_code=@wo_code order by A.seq"; |
| | | dynamicParams.Add("@wo_code", wo_code); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | |
| | | } |
| | | } |
| | | //更新排产生产资源主表 |
| | | sql = @"update TWkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_time=@lm_time where id=@id"; |
| | | sql = @"update TWkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_date=@lm_time where id=@id"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | //循环写入排产生产资源子表 |
| | | for (int i = 0; i < objs.Count; i++) |
| | | { |
| | | sql = @"insert into TWkm_capac_plan_sub(m_id,wkdate,wkshift_code) values()"; |
| | | sql = @"insert into TWkm_capac_plan_sub(m_id,wkdate,wkshift_code) values(@m_id,@wkdate,@wkshift_code)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | left join (select wo_code, max(TIME_END) MAXTime,min(time_start) MINTime from TK_Wrk_EqpAps group by wo_code) H on A.wo_code=H.wo_code |
| | | left join TUom U on C.uom_code=U.code |
| | | left join TOrganization M on A.wkshp_code=M.org_code |
| | | where E.isbott = 'Y' and A.status='NEW' and A.isaps='Y'"; |
| | | where E.isbott = 'Y' and A.status='NOSCHED' and A.isaps='Y' " + search; |
| | | var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | |
| | | string sy = "0"; |
| | | for (int i = 0; i < dt0.Rows.Count; i++) |
| | | { |
| | | if (dt0.Rows[i]["WKSHOP"].ToString() == wkshpcode) //工单创建车间是否等于排产设备 车间 |
| | | if (dt0.Rows[i]["WKSP_CODE"].ToString() == wkshpcode) //工单创建车间是否等于排产设备 车间 |
| | | { |
| | | sy = "1"; |
| | | break; |
| | |
| | | mes.count = 0; |
| | | mes.Message = "排产设备车间与工单创建的车间不同!"; |
| | | mes.data = null; |
| | | return list; |
| | | } |
| | | else |
| | | { |
| | |
| | | from TWkm_capac_plan E |
| | | left join TWkm_capac_plan_sub F on E.id=F.m_id |
| | | left join TBas_wkshift_info G on F.wkshift_code=G.code |
| | | where E.wkshop='CJ001'and E.eqp_typecode='SBLX001' and E.ClassType='D' |
| | | and CONVERT(varchar(100), F.wkdate, 23)='2022-10-11' and E.enable='Y'"; |
| | | where E.wkshop=@wkshop and E.eqp_typecode=@eqp_typecode and E.ClassType=@classtype |
| | | and CONVERT(varchar(100), F.wkdate, 23)=@wkdate and E.enable='Y'"; |
| | | dynamicParams.Add("@wkshop", wkshpcode); |
| | | dynamicParams.Add("@eqp_typecode", listData[j].Style.ToString()); |
| | | dynamicParams.Add("@classtype", listData[j].ClassType.ToString()); |
| | |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "排程设备未设置产能!"; |
| | | mes.Message = "当前工单加工产品对应工艺路线设备未设置产能或未设置生产节拍!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | |
| | | string status = dt.Rows[0]["STATUS"].ToString(); |
| | | Decimal nm = 0; //瓶径工序的前置天数 |
| | | Decimal nn = Decimal.Parse(dt.Rows[0]["BottFrointv"].ToString()); //瓶径工序的后置天数 |
| | | if (status != "NEW" && status != "SCHED") //工序任务的状态已经派发(审核) |
| | | if (status != "NEW" && status != "SCHED" && status != "NOSCHED") //工序任务的状态已经派发(审核) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | |
| | | { |
| | | sql = @"insert into TK_Wrk_EqpApsSum (wo_code,eqp_code,step_taid,p_date, t_date, qty,status) |
| | | select min(wo_code),min(eqp_code),min(step_taid),min(time_start),max(time_end),sum(Alloc_Qty),'NEW' from TK_Wrk_EqpAps |
| | | where wo_code=@wocode and eqp_code=''"; |
| | | where wo_code=@wocode and eqp_code=@eqp_code"; |
| | | list.Add(new { str = sql, parm = new { wocode = wocode, eqp_code = dt1.Rows[i]["EQP_CODE"].ToString() } }); |
| | | } |
| | | |
| | |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | |
| | | list.Clear(); |
| | | //写入设备任务(汇总表)用料 计划数量*子件基本用量*(1+损耗率)/母件基本用量 |
| | | sql = @"insert into TK_Wrk_EqpSum_Allo(m_id, seq, invcode, qty,wo_code,pn_type) |
| | | sql = @"insert into TK_Wrk_EqpSum_Allo(m_id, seq, materiel_code, qty,wo_code,materieltype) |
| | | select A.id M_id, B.seq,B.materiel_code,(round(A.qty,2)*BE.Base_Quantity*(1+BE.LOSS_QUANTITY/100))/BM.quantity qty,A.wo_code,B.materieltype |
| | | from TK_Wrk_EqpApsSum A |
| | | left join TK_Wrk_Allo B on A.Wo_Code= B.Wo_Code |
| | |
| | | } |
| | | }); |
| | | //主工单的“计划开机日期 = 瓶径工序的预开工日期 - 瓶径工序的前置日期) 主工单:计划完工日期 = 瓶径工序的预完工日期 + 瓶径工序的后置日期 |
| | | sql = @"update mes_tk_wrk_man set status='SCHED',plan_startdate =convert(varchar(100),@plan_startdate,21), plan_enddate =convert(varchar(100),@plan_enddate,21), exchag='Y',allocfag='N' where wo_code =@wocode"; |
| | | sql = @"update TK_Wrk_Man set status='SCHED',plan_startdate =convert(varchar(100),@plan_startdate,21), plan_enddate =convert(varchar(100),@plan_enddate,21), exchag='Y',allocfag='N' where wo_code =@wocode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |