UPDATE calendar set CalendarDesc=#{calendarDesc},status=#{status} WHERE CalendarID = #{calendarId} INSERT INTO calendar(site,calendarID,calendarDesc,status) VALUES (#{site},#{calendarId},#{calendarDesc},#{status}) DELETE FROM calendar WHERE CalendarID = #{calendarId} UPDATE calendar_datetype_shift set shiftdesc=#{shiftdesc},startexacttime=#{startexacttime} ,endexacttime=#{endexacttime},starttime=#{starttime},endtime=#{endtime} AND site = #{site} AND DateType = #{datetype} and ShiftNo =#{shiftno} INSERT INTO calendar_datetype_shift (shiftno,datetype,site,shiftdesc,startexacttime,endexacttime,starttime,endtime) VALUES (#{shiftno},#{datetype},#{site},#{shiftdesc},#{startexacttime},#{endexacttime},#{starttime},#{endtime}) INSERT INTO calendar_datetype (site,datetype,excepttime1,exceptduration1,excepttime2,exceptduration2,excepttime3,exceptduration3,excepttime4,exceptduration4, excepttime5,exceptduration5,excepttime6,exceptduration6,worktime,remark,exceptexacttime1,exceptexacttime2,exceptexacttime3,exceptexacttime4,exceptexacttime5,exceptexacttime6) VALUES(#{site},#{datetype},#{excepttime1},#{exceptduration1},#{excepttime2},#{exceptduration2},#{excepttime3},#{exceptduration3},#{excepttime4},#{exceptduration4}, #{excepttime5},#{exceptduration5},#{excepttime6},#{exceptduration6},#{worktime},#{remark},#{exceptexacttime1},#{exceptexacttime2},#{exceptexacttime3},#{exceptexacttime4},#{exceptexacttime5},#{exceptexacttime6}) DELETE FROM calendar_datetype WHERE site= #{site} and datetype=#{datetype} DELETE FROM calendar_exception_shift WHERE site = #{site} AND CalendarId = #{calendarId} AND ScheduleDate = #{scheduledate} INSERT INTO calendar_exception (site,CalendarID,scheduledate,excepttime1,exceptduration1,excepttime2,exceptduration2,excepttime3 ,exceptduration3,excepttime4,exceptduration4,excepttime5,exceptduration5,excepttime6,exceptduration6,worktime,datetype,exceptexacttime1 ,exceptexacttime2,exceptexacttime3,exceptexacttime4,exceptexacttime5,exceptexacttime6) VALUES (#{site},#{calendarId},#{scheduledate},#{excepttime1},#{exceptduration1},#{excepttime2},#{exceptduration2},#{excepttime3}, #{exceptduration3},#{excepttime4},#{exceptduration4},#{excepttime5},#{exceptduration5},#{excepttime6},#{exceptduration6},#{worktime},#{datetype},#{exceptexacttime1} ,#{exceptexacttime2},#{exceptexacttime3},#{exceptexacttime4},#{exceptexacttime5},#{exceptexacttime6}) INSERT INTO calendar_exception_shift (site,calendarID,shiftno,scheduledate,shiftdesc,startexacttime,endexacttime, starttime,endtime) VALUES (#{site},#{calendarId},#{shiftno},#{scheduledate},#{shiftdesc},#{startexacttime},#{endexacttime}, #{starttime},#{endtime}) DELETE FROM calendar_exception WHERE site = #{site} and CalendarId = #{calendarId} AND scheduledate = #{scheduledate} UPDATE calendar_datetype set excepttime1=#{excepttime1},exceptduration1=#{exceptduration1}, excepttime2=#{excepttime2},exceptduration2=#{exceptduration2},excepttime3=#{excepttime3},exceptduration3=#{exceptduration3},excepttime4=#{excepttime4},exceptduration4=#{exceptduration4}, excepttime5=#{excepttime5},exceptduration5=#{exceptduration5},excepttime6=#{excepttime6},exceptduration6=#{exceptduration6},worktime=#{worktime},remark=#{remark},exceptexacttime1=#{exceptexacttime1}, exceptexacttime2=#{exceptexacttime2},exceptexacttime3=#{exceptexacttime3},exceptexacttime4=#{exceptexacttime4},exceptexacttime5=#{exceptexacttime5},exceptexacttime6=#{exceptexacttime6} AND site = #{site} AND datetype = #{datetype} DELETE FROM calendar_datetype_shift WHERE shiftno=#{shiftno} AND site=#{site} AND DateType=#{datetype} INSERT INTO WorkCenterResource (Site,WorkCenterNo,ResourceID,ResourceDesc,Efficiency,Utilization,Active,Remark,CreatedDate,CalendarID,VirturlFlag) VALUES(#{site},#{workCenterNo},#{resourceID},#{resourceDesc},#{efficiency},#{utilization},#{active},#{remark},GetDate(),#{calendarID},'N') update WorkCenterResource SET ResourceDesc=#{resourceDesc},Efficiency=#{efficiency},Utilization=#{utilization},Active=#{active},Remark=#{remark},CalendarID=#{calendarID} where Site=#{site} and ResourceID=#{resourceID} INSERT INTO Site (SiteID,SiteName,SiteName_E,Address,Address_E,ContactName,PostCode,Email,FaxNo,PhoneNo,Active,Website,CompanyID,ShipTime, ReferenceCustomerID) VALUES (#{siteID},#{siteName},#{siteNameE},#{address},#{addressE},#{contactName},#{postCode},#{email},#{faxNo},#{phoneNo},#{active}, #{website},#{companyID},#{shipTime},#{referenceCustomerID}) update Site SET SiteName=#{siteName},SiteName_E=#{siteNameE},Address=#{address},Address_E=#{addressE},ContactName=#{contactName},PostCode=#{postCode}, Email=#{email},FaxNo=#{faxNo},PhoneNo=#{phoneNo},Active=#{active},Website=#{website},CompanyID=#{companyID},ShipTime=#{shipTime},ReferenceCustomerID=#{referenceCustomerID} where SiteID=#{siteID} INSERT INTO PartFamily (FamilyID,Site,FamilyName,Active,CheckPercentage) values (#{familyID},#{site},#{familyName},#{active},#{checkPercentage}) UPDATE PartFamily SET Site=#{site},FamilyName=#{familyName},Active=#{active},CheckPercentage=#{checkPercentage} where FamilyID=#{familyID} and Site=#{site} delete from PartFamily where FamilyID=#{familyID} and Site=#{site} INSERT INTO UM (UMID,Site,UMName,Active) values (#{umid},#{site},#{uMName},#{active}) UPDATE UM SET Site=#{site},UMName=#{uMName},Active=#{active} where UMID=#{umid} and Site=#{site} delete from UM where UMID=#{umid} and Site=#{site} INSERT INTO DowntimeReason (Site,ReasonCode,Area,ReasonDescription,Active) values (#{site},#{reasonCode},#{area},#{reasonDescription},#{active}) UPDATE DowntimeReason SET Active=#{active},Area=#{area},ReasonDescription=#{reasonDescription} where ReasonCode=#{reasonCode} and Site=#{site} delete from DowntimeReason where ReasonCode=#{reasonCode} and Site=#{site} INSERT INTO ReferencePartInfo (Site,CustomerID,PartNo,ReferencePartDesc,SupplierID,FGPartNo,LastUpdateBy) values (#{site},#{customerID},#{partNo},#{referencePartDesc},#{supplierID},#{fGPartNo},#{user}) UPDATE ReferencePartInfo SET Site=#{site},CustomerID=#{customerID},PartNo=#{partNo},ReferencePartDesc=#{referencePartDesc},SupplierID=#{supplierID},FGPartNo=#{fGPartNo},LastUpdateBy=#{user} where CustomerID=#{customerID} and Site=#{site} and FGPartNo=#{fGPartNo} and PartNo=#{partNo} delete from ReferencePartInfo where CustomerID=#{customerID} and Site=#{site} and FGPartNo=#{fGPartNo} and PartNo=#{partNo} INSERT INTO ProductionLine (Site,ProLineNo,ProLineDesc,Active,CreatedDate) values (#{site},#{proLineNo},#{proLineDesc},#{active},#{createdDate}) UPDATE ProductionLine SET ProLineDesc=#{proLineDesc},Active=#{active},CreatedDate=#{createdDate} where ProLineNo=#{proLineNo} and Site=#{site} delete from ProductionLine where ProLineNo=#{proLineNo} and Site=#{site} INSERT INTO WorkCenter (Site,WorkCenterNo,WorkCenterDesc,WorkCenterType_DB,WorkCenterType,AverageCapacity,Efficiency,Utilization,CapacityType_DB, CapacityType,UMID,Active,Remark,CreatedDate,ProLineNo,CanCreateNewRollFlag,NeedSetupFlag) values (#{site},#{workCenterNo},#{workCenterDesc},#{workCenterTypeDb},#{workCenterType},0,100,100,'I','无限能力', #{umid},#{active},#{remark},#{createdDate},#{proLineNo},#{canCreateNewRollFlag},#{needSetupFlag}) UPDATE WorkCenter SET WorkCenterDesc=#{workCenterDesc},Active=#{active},WorkCenterType=#{workCenterNo},WorkCenterType_DB=#{workCenterTypeDb}, Remark=#{remark},CreatedDate=#{createdDate},ProLineNo=#{proLineNo}, CanCreateNewRollFlag=#{canCreateNewRollFlag},NeedSetupFlag=#{needSetupFlag} where WorkCenterNo=#{workCenterNo} and Site=#{site} delete from WorkCenter where WorkCenterNo=#{workCenterNo} and Site=#{site} delete from WorkCenterResource where ResourceID=#{resourceID} and Site=#{site} UPDATE WorkCenterResource SET VirturlFlag=#{virturlFlag} where ResourceID=#{resourceID} and Site=#{site} INSERT INTO Company (CompanyID,CompanyName,Active,TaxNo,BankName,BankAccount,CutoffDate_DB,CutoffDate,CutoffDate_FixDate) values (#{companyID},#{companyName},#{active},#{taxNo},#{bankName},#{bankAccount},#{cutoffDateDb},#{cutoffDate},#{cutoffDateFixDate}) UPDATE Company SET CompanyName=#{companyName},CutoffDate_DB=#{cutoffDateDb},Active=#{active}, TaxNo=#{taxNo},BankName=#{bankName},BankAccount=#{bankAccount},CutoffDate=#{cutoffDate},CutoffDate_FixDate=#{cutoffDateFixDate} where CompanyID=#{companyID} delete from Company where CompanyID=#{companyID} insert into RoutingDetail (Site,PartNo,RevNo,ItemNo,OperationDesc,WorkCenterNo,MachSetupTime,MachRunFactor,FactorUnit_DB,FactorUnit,Efficiency, Crewsize,JJGZ_UnitFactor_DB,JJGZ_UnitFactor,JJGZ_UnitPrice,Remark,WX_UnitCost,BatchQty) VALUES(#{site},#{partNo},#{revNo},#{itemNo},#{operationDesc},#{workCenterNo},#{machSetupTime},#{machRunFactor},#{factorUnitDb},#{factorUnit},#{efficiency}, #{crewsize},#{jjgzUnitFactorDb},#{jjgzUnitFactor},#{jjgzUnitPrice},#{remark},0,0) UPDATE RoutingDetail SET OperationDesc=#{operationDesc},WorkCenterNo=#{workCenterNo},MachSetupTime=#{machSetupTime}, MachRunFactor=#{machRunFactor},FactorUnit_DB=#{factorUnitDb},FactorUnit=#{factorUnit},Efficiency=#{efficiency}, Crewsize=#{crewsize},JJGZ_UnitFactor_DB=#{jjgzUnitFactorDb},JJGZ_UnitFactor=#{jjgzUnitFactor},JJGZ_UnitPrice=#{jjgzUnitPrice},Remark=#{remark} WHERE partNo = #{partNo} and site = #{site} and revNo = #{revNo} and ItemNo = #{itemNo} delete from RoutingDetail where site=#{site} and PartNo=#{partNo} and RevNo=#{revNo} and ItemNo=#{itemNo} INSERT INTO RoutingDetail_AvailableResource(Site,PartNo,RevNo,ItemNo,ResourceID) VALUES (#{site},#{partNo},#{revNo},#{itemNo},#{resourceID}) delete from RoutingDetail_AvailableResource where site=#{site} and PartNo=#{partNo} and revNo=#{revNo} and itemNo=#{itemNo} and ResourceID=#{resourceID} INSERT INTO RoutingTool(Site,PartNo,RevNo,ItemNo,ToolID,ToolQty,Remark,CreateDate,CreatedBy) VALUES(#{site},#{partNo},#{revNo},#{itemNo},#{toolID},#{toolQty},#{remark},GETDATE(),#{user} ) update RoutingTool SET ToolQty=#{toolQty},Remark=#{remark} WHERE Site=#{site} and PartNo=#{partNo} and ToolID=#{toolID} and RevNo=#{revNo} and ItemNo=#{itemNo} delete from RoutingTool WHERE Site=#{site} and PartNo=#{partNo} and ToolID=#{toolID} and RevNo=#{revNo} and ItemNo=#{itemNo} update RoutingHeader SET status=#{status} where Site=#{site} and PartNo=#{partNo} and RevNo=#{revNo} Select Site,OrderNo,LotSize into ${tableName} from ShopOrder as T where Site=#{site} and PartNo=#{partNo} and (Status='已计划' or Status='已下达') and Not exists(Select 1 from SOScheduledRouting as D Where T.Site=D.Site and T.OrderNo=D.OrderNo) and T.OrderType != 'P' Update ShopOrder Set RoutingRevNo=#{revNo} from ${tableName} as T where ShopOrder.Site=T.Site and ShopOrder.OrderNo=T.OrderNo Delete SORouting from ${tableName} as T where SORouting.Site=T.Site and SORouting.OrderNo=T.OrderNo Delete SOTool from ${tableName} as T where SOTool.Site=T.Site and SOTool.OrderNo=T.OrderNo Insert into SORouting(Site,OrderNo,ItemNo,OperationDesc,WorkCenterNo,MachSetupTime,MachRunFactor ,FactorUnit_DB,FactorUnit,TimeRequired,TimeReported,Efficiency,Remark,QtyRequired,QtyReported,QtyApprove ,PlanStartTime,PlanFinishTime,BarcodeID,PartNo,ClosedFlag,OutWorkFlag,OutWorkPartNo,QtyOnPR,QtyOnPO,QtyScrapt,Crewsize ,PreItemNo,NextItemNo,ScheduledFlag,QtyScheduled) Select T.Site,D.OrderNo,ItemNo,OperationDesc,WorkCenterNo,MachSetupTime,MachRunFactor,FactorUnit_DB,FactorUnit, (MachSetupTime+(Case when MachRunFactor=0 then 0 else (Case when FactorUnit_DB='1' then D.LotSize/MachRunFactor when FactorUnit_DB='2' then D.LotSize*MachRunFactor when FactorUnit_DB='3' then MachRunFactor end) end)/(Efficiency/100)) as TimeRequired,0,Efficiency,Remark ,D.LotSize,0,0,0,0 ,(Case when len(OrderNo)>10 then D.Site + '-' + D.OrderNo + '-' + dbo.Get_PadL(ItemNo,4,'0') else D.Site + '-' + dbo.Get_PadL(D.OrderNo,10,'0') + '-' + dbo.Get_PadL(ItemNo,4,'0') end),T.PartNo,'N' ,(Case when dbo.Get_WorkCenter_TypeDB(T.Site,WorkCenterNo)='O' then 'Y' else 'N' end) as OutWorkFlag,WX_PartNo as OutWorkPartNo,0.0 as QtyOnPR,0.0 as QtyOnPO,0.0 as QtyScrapt,Crewsize ,Isnull((Select Max(D.ItemNo) as PreItemNo from RoutingDetail as D Where D.Site=T.Site and D.PartNo=T.PartNo and D.RevNo=T.RevNo and T.ItemNo>D.ItemNo),0) ,Isnull((Select Min(D.ItemNo) as NextItemNo from RoutingDetail as D Where D.Site=T.Site and D.PartNo=T.PartNo and D.RevNo=T.RevNo and D.ItemNo>T.ItemNo),0) ,'N',0 from RoutingDetail as T, ${tableName} as D Where D.Site=T.Site and T.site=#{site} and T.PartNo=#{partNo} and T.RevNo=#{revNo} Insert into SOTool(Site,OrderNo,ItemNo,ToolID,ToolQty,Remark,CreateDate,CreatedBy) Select T.Site,D.OrderNo,ItemNo,ToolID,ToolQty,Remark,getdate(),#{user} from RoutingTool as T,${tableName} as D Where D.Site=T.Site and T.site=#{site} and T.PartNo=#{partNo} and T.RevNo=#{revNo} Drop table ${tableName}