mrp_enter_newmossparent.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 545 行 · 第 1/2 页
PAS
545 行
+' left outer join Uom on Item.UomCode=Uom.UomCode'
// +' join Bom on MrpResult.ItemCode=Bom.ItemCode'
+' where '+iifstring(peggingType=1,' ordinal=3 ','(ordinal=2 or ordinal=3)')
+' and MrpResult.ItemCode= '+quotedstr(copy(strpath,1,pos(',',strpath)-1))
+' and MrpResult.releasedate='+quotedstr(slCalendar(dbconnect,AdoQry_Main.fieldbyname('releasedate').asstring,iifinteger(AdoQry_Main.fieldbyname('PmCode').asinteger=0,fieldbyname('Qclt').asinteger+AdoQry_Main.fieldbyname('Preparelt').asinteger+getlt(AdoQry_Main.fieldbyname('ItemCode').asstring,3),fieldbyname('Qclt').asinteger+getlt(AdoQry_Main.fieldbyname('ItemCode').asstring,4))));
// +' 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_NewMoSsParent.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_NewMoSsParent.FormCreate(Sender: TObject);
begin
inherited;
//tlbtn_Sum.Action:=action1;
//tlbtn_look.Action:=action2;
end;
function TFrm_Mrp_Enter_NewMoSsParent.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, '
+' noFinishqty=convert(float,0), '
+' 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.Preparelt+Item.runlt as 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.runlt,Item.Qclt';
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 realOrderqty when 3 then onhand end, '
+' noFinishqty=case ordinal when 2 then Orderqty when 3 then null 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 '+iifstring(peggingType=1,' ordinal=3 ','(ordinal=2 or ordinal=3)')
+' and MrpResult.canpegging=1 '
+' 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 3 then onhand end, '
+' noFinishqty=case ordinal when 2 then Orderqty when 3 then null 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 '+iifstring(peggingType=1,' ordinal=3 ','(ordinal=2 or ordinal=3)')
+' and MrpResult.canpegging=1 '
+'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 ';
// showmessage(tMpsqltext);
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_NewMoSsParent.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_NewMoSsParent.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_NewMoSsParent.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('Preparelt').asinteger+fieldbyname('runlt').asinteger;
end;
end;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_NewMoSsParent.setItemInfo(ItemCode: string);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.EnableBCD:=False;
AdoQry.Connection:=dbconnect;
sqltext:='select Item.*,Uom.UomName,Itemflag=ItemCode+'' ''+ItemName'+
' from Item,Uom '+
' where Item.UomCode*=Uom.UomCode '+
' and Item.ItemCode ='+quotedstr(ItemCode);
try
Executesql(AdoQry,sqltext,0);
label3.Caption:=ItemCode;
label4.Caption:=AdoQry.fieldbyname('ItemName').asstring;
label6.Caption:=AdoQry.fieldbyname('UomName').asstring;
case AdoQry.fieldbyname('ItemType').asinteger of
0: label8.Caption:='0 普通物料';
1: label8.Caption:='1 资源';
2: label8.Caption:='2 工具';
3: label8.Caption:='3 参考';
4: label8.Caption:='4 虚项';
5: label8.Caption:='5 劳务';
6: label8.Caption:='6 副产品';
7: label8.Caption:='7 成本';
end;
case AdoQry.fieldbyname('PmCode').asinteger of
0: label10.Caption:='0 制造';
1: label10.Caption:='1 采购';
2: label10.Caption:='2 委外';
3: label10.Caption:='3 既自制又委外';
end;
// label24.Caption:=floattostr(AdoQry.fieldbyname('mnldtime').asfloat);
// label26.Caption:=floattostr(AdoQry.fieldbyname('purchldtime').asfloat);
label28.Caption:=floattostr(AdoQry.fieldbyname('Preparelt').asfloat);
label30.Caption:=floattostr(AdoQry.fieldbyname('runlt').asfloat);
label32.Caption:=floattostr(AdoQry.fieldbyname('Qclt').asfloat);
case AdoQry.fieldbyname('Batchstrat').asinteger of
0: label12.Caption:='0 直接批量法';
1: label12.Caption:='1 固定批量法';
end;
label14.Caption:=floattostr(AdoQry.fieldbyname('PmBatch').asfloat);
label16.Caption:=floattostr(AdoQry.fieldbyname('maxqty').asfloat);
label18.Caption:=floattostr(AdoQry.fieldbyname('minqty').asfloat);
finally
AdoQry.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?