📄 mrp_enter_mossparent.pas
字号:
+' and MrpResult.releasedate='+quotedstr(slCalendar(dbconnect,AdoQry_Main.fieldbyname('releasedate').asstring,iifinteger(AdoQry_Main.fieldbyname('PmCode').asinteger=0,AdoQry_Main.fieldbyname('Preparelt').asinteger+getlt(AdoQry_Main.fieldbyname('ItemCode').asstring,3),getlt(AdoQry_Main.fieldbyname('ItemCode').asstring,4))));
Executesql(AdoQry,tMpsqltext,1);
end;
Executesql(AdoQry_Main,'select * from #tmpuPMrpResult where Mrpqty>0',0);
finally
AdoQry.free;
end;
//SelectFromSql:=' select distinct MrpResult.*,Bom.Bomqty,Mrpqty=case ordinal when 2 then Orderqty when 5 then netqty end, '
// +' ScrAprate=convert(varchAr,Bom.BomScrAp_Percent)+''%'','
// +' Itemflag=MrpResult.ItemCode+'' ''+Item.ItemName, '
// +' Uom.UomName '
// +' from MrpResult '
// +' join Item on MrpResult.ItemCode=Item.ItemCode '
// +' left outer join Uom on Item.UomCode=Uom.UomCode'
// +' join Bom on MrpResult.ItemCode=Bom.ItemCode';
//Condition:='(ordinal=2 or ordinal=5) and Bom.ite_ItemCode='+quotedstr(AdoQry_Main.fieldbyname('ItemCode').asstring)+' and MrpResult.ItemCode='+quotedstr(copy(strpath,1,pos(',',strpath)-1));
// if AdoQry_Main.fieldbyname('duedate').asstring<>'' then
//condition:=condition+' and MrpResult.releasedate='+quotedstr(AdoQry_Main.fieldbyname('duedate').asstring);
strpath:=copy(strpath,pos(',',strpath)+1,length(strpath)-pos(',',strpath));
//OrderByFields:='ItemCode,dueDate ';
//GetData;}
end;
procedure TFrm_Mrp_Enter_MoSsParent.Action2Execute(Sender: TObject);
var tMpstr:string;
begin
inherited;
tMpstr:=strpath;
if not existsfArItemCode(AdoQry_Main.fieldbyname('ItemCode').asstring) then
begin
DispInfo(AdoQry_Main.fieldbyname('ItemCode').asstring+'无父项物料!',3);
exit;
end;
strpath:=AdoQry_Main.fieldbyname('ItemCode').asstring+','+strpath;
tmplowPmCode:=AdoQry_Main.fieldbyname('PmCode').asinteger;
if not ifexistsiteItemCode(AdoQry_Main.fieldbyname('ItemCode').asstring,AdoQry_Main.fieldbyname('releasedate').asstring,inttostr(AdoQry_Main.fieldbyname('Qclt').asinteger)) then
begin
DispInfo(AdoQry_Main.fieldbyname('ItemCode').asstring+'无父项物料需求!',3);
strpath:=tMpstr;
exit;
end;
tmplowPmCode:=AdoQry_Main.fieldbyname('PmCode').asinteger;
lowBomqty:=AdoQry_Main.fieldbyname('Bomqty').asfloat;
lowScrAp:=AdoQry_Main.fieldbyname('ScrAprate').asstring;
Executesql(AdoQry_Main,'select * from #tmpuPMrpResult',0);
end;
procedure TFrm_Mrp_Enter_MoSsParent.FormCreate(Sender: TObject);
begin
inherited;
tlbtn_Sum.Action:=action1;
tlbtn_look.Action:=action2;
end;
function TFrm_Mrp_Enter_MoSsParent.ifexistsiteItemCode(ItemCode,
date,Qclt: string): boolean;
var AdoQry:TAdoQuery;tMpsqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.EnableBCD:=False;
AdoQry.Connection:=dbconnect;
try
try
Executesql(AdoQry_tmp,'drop table #tmpopenBom,#tmpopenBomResult,#tmpuPMrpResult',1);
except
end;
tMpsqltext:=' select top 0 MrpResult.*,Bom.Bomqty,Mrpqty=case ordinal when 2 then Orderqty when 5 then netqty end, '
+' ScrAprate=convert(varchAr,Bom.BomScrAp_Percent)+''%'','
+' Itemflag=MrpResult.ItemCode+'' ''+Item.ItemName, '
+' Item.Qclt, '
+' Item.Preparelt,'
+' Uom.UomName '
+' into #tmpuPMrpResult '
+' from MrpResult '
+' join Item on MrpResult.ItemCode=Item.ItemCode '
+' left outer join Uom on Item.UomCode=Uom.UomCode'
+' join Bom on MrpResult.ItemCode=Bom.ite_ItemCode';
Executesql(AdoQry_tmp,tMpsqltext,1);
Bomopen(dbconnect,ItemCode);
//tMpsqltext:='select Bom.ite_ItemCode as ItemCode,Item.Preparelt from Bom,Item where Bom.ite_ItemCode=Item.ItemCode and Bom.ItemCode='+quotedstr(ItemCode);
tMpsqltext:='select distinct Item.ItemCode,Item.PmCode,Item.Preparelt,Item.purchldtime,Bomqty=sum(Bomqty),BomScrAprate=sum(BomScrAprate) '
+' into #tmpopenBomResult '
+' From #TmpOpenBom,Item '
+' where #tmpopenBom.ItemCode=Item.ItemCode '
+' and exists(select * from MrpResult where #tmpopenBom.ItemCode=MrpResult.ItemCode) '
+' group by Item.ItemCode,Item.PmCode,Item.Preparelt,Item.purchldtime';
Executesql(AdoQry_tmp,tMpsqltext,1);
Executesql(AdoQry_tmp,'select * from #tmpopenBomResult',0);
with AdoQry_tmp do
begin
First;
while not eof do
begin
// showmessage(AdoQry_tmp.fieldbyname('ItemCode').asstring);
if tmplowPmCode=0 then
tMpsqltext:='insert into #tmpuPMrpResult'
+' select distinct MrpResult.*,#tmpopenBomResult.Bomqty,Mrpqty=case ordinal when 2 then Orderqty when 5 then netqty end, '
+' ScrAprate=convert(varchAr,#tmpopenBomResult.BomScrAprate)+''%'','
+' Itemflag=MrpResult.ItemCode+'' ''+Item.ItemName, '
+' Item.Qclt,'
+' Item.Preparelt,'
+' Uom.UomName '
+' from MrpResult '
+' join Item on MrpResult.ItemCode=Item.ItemCode '
+' left outer join Uom on Item.UomCode=Uom.UomCode'
+' join #tmpopenBomResult on MrpResult.ItemCode=#tmpopenBomResult.ItemCode'
+' where (ordinal=2 or ordinal=5) '
+' and MrpResult.ItemCode= '+quotedstr(fieldbyname('ItemCode').asstring)
+' and MrpResult.releasedate=case MrpResult.PmCode when 0 then '+quotedstr(slCalendar(dbconnect,date,-(strtoint(Qclt)+fieldbyname('Preparelt').asinteger+getlt(fieldbyname('ItemCode').asstring,3))))
+' else '+quotedstr(slCalendar(dbconnect,date,-(strtoint(Qclt)+fieldbyname('purchldtime').asinteger)))
+' end '
else
tMpsqltext:='insert into #tmpuPMrpResult'
+' select distinct MrpResult.*,#tmpopenBomResult.Bomqty,Mrpqty=case ordinal when 2 then Orderqty when 5 then netqty end, '
+' ScrAprate=convert(varchAr,#tmpopenBomResult.BomScrAprate)+''%'','
+' Itemflag=MrpResult.ItemCode+'' ''+Item.ItemName, '
+' Item.Qclt,'
+' Item.Preparelt,'
+' Uom.UomName '
+' from MrpResult '
+' join Item on MrpResult.ItemCode=Item.ItemCode '
+' left outer join Uom on Item.UomCode=Uom.UomCode'
+' join #tmpopenBomResult on MrpResult.ItemCode=#tmpopenBomResult.ItemCode'
+' where (ordinal=2 or ordinal=5) '
+'and MrpResult.ItemCode= '+quotedstr(fieldbyname('ItemCode').asstring)
+' and MrpResult.releasedate=case MrpResult.PmCode when 0 then '+quotedstr(slCalendar(dbconnect,date,-(fieldbyname('Preparelt').asinteger+getlt(fieldbyname('ItemCode').asstring,3))))
+' else '+quotedstr(slCalendar(dbconnect,date,-(fieldbyname('purchldtime').asinteger)))
+' end ';
Executesql(AdoQry,tMpsqltext,1);
next;
end;
end;
Executesql(AdoQry,'select * from #tmpuPMrpResult where Mrpqty>0',0);
if AdoQry.RecordCount>0 then
Result:=True
else
Result:=False;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_MoSsParent.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
try
Executesql(AdoQry_tmp,'drop table #tmpopenBom,#tmpopenBomResult,#tmpuPMrpResult',1);
except
end;
end;
function TFrm_Mrp_Enter_MoSsParent.existsfArItemCode(
ItemCode: string): boolean;
var AdoQry:TAdoQuery;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.EnableBCD:=False;
try
with AdoQry do
begin
Close;
Connection:=dbconnect;
sql.clear;
sql.Add('select ite_ItemCode from Bom where ItemCode='
+quotedstr(ItemCode));
open;
if recordCount=0 then
Result:=False
else Result:=True;
end;
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Enter_MoSsParent.getlt(ItemCode: string;
ltType: integer): integer;
var AdoQry:TAdoQuery;
begin
Result:=0;
AdoQry:=TAdoQuery.Create(self);
AdoQry.EnableBCD:=False;
try
with AdoQry do
begin
Close;
Connection:=dbconnect;
sql.clear;
sql.Add('select Preparelt,Qclt,runlt,purchldtime from Item where ItemCode='
+quotedstr(ItemCode));
open;
case ltType of
1: Result:=fieldbyname('Preparelt').asinteger;
2: Result:=fieldbyname('Qclt').asinteger;
3: Result:=fieldbyname('runlt').asinteger;
4: Result:=fieldbyname('purchldtime').asinteger;
end;
end;
finally
AdoQry.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -