mrp_qry_halfrunmrp.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 242 行
PAS
242 行
unit Mrp_Qry_HalfRunMrp;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Outer, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
StdCtrls, ExtCtrls, ComCtrls, ToolWin,ComObj, DBCtrls;
Type
TFrm_Mrp_Qry_HalfRunMrp = Class(TFrm_Base_Outer)
AdoQry_MainMpsId: TBCDField;
AdoQry_MainMpsMonth: TStringField;
AdoQry_MainItemCode: TStringField;
AdoQry_MainMpsDATE: TDateTimeField;
AdoQry_MainMpsStatus: TIntegerField;
AdoQry_MainMpsRemArk: TStringField;
AdoQry_MainItemName: TStringField;
AdoQry_MainUomName: TStringField;
AdoQry_MainMpsQTY: TFloatField;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
DBText2: TDBText;
DBText3: TDBText;
Lbl_ItemFlag: TLabel;
AdoQry_MainMpScheck: TIntegerField;
AdoQry_MainItemflag: TStringField;
AdoQry_MainMpsnoFinishqty: TFloatField;
procedure FormDestroy(Sender: TObject);
procedure DataSourceDataChange(Sender: TObject; Field: TField);
procedure FormCreate(Sender: TObject);
procedure Act_LookExecute(Sender: TObject);
procedure DBGridEhTitleClick(Column: TColumnEh);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
flag:boolean;
{ Private declarations }
public
procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
procedure openBom(ItemCode:string;Mpsqty:real);
function existssonItem(ItemCode:string):boolean;
{ Public declarations }
end;
var
Frm_Mrp_Qry_HalfRunMrp: TFrm_Mrp_Qry_HalfRunMrp;
implementation
uses Mrp_Qry_HalfRunMrp_D, Sys_Global;
{$R *.DFM}
procedure TFrm_Mrp_Qry_HalfRunMrp.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var sqltext:string;
begin
Application.ProcessMessages;
inherited;
sqltext:='select Mps.*,Item.ItemName,Uom.UomName, '
+' Itemflag=Mps.ItemCode+'' ''+Item.ItemName, '
+' MpsnoFinishqty=Mps.Mpsqty-Mps.MpsFinishqty '
+' into #tmPmpsMain '
+' from Mps,Item,Uom '
+' where Mps.ItemCode=Item.ItemCode '
+' and Item.UomCode*=Uom.UomCode '
+' and Mpsstatus<4 '
+' and Item.ItemType=0 '
+' Order by MpsMonth,Mps.ItemCode';
selectfromsql:='select * from #tmPmpsMain';
Executesql(AdoQry_Main,sqltext,1);
Executesql(AdoQry_Main,'select * from #tmPmpsMain',0);
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.FormDestroy(Sender: TObject);
begin
inherited;
Frm_Mrp_Qry_HalfRunMrp:=nil;
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.DataSourceDataChange(Sender: TObject;
Field: TField);
begin
inherited;
Lbl_ItemFlag.Caption:=AdoQry_Main.fieldbyname('ItemCode').AsString+' '+AdoQry_Main.fieldbyname('ItemName').AsString;
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.FormCreate(Sender: TObject);
begin
inherited;
ExtendCaption:=False;
flag:=False;
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.Act_LookExecute(Sender: TObject);
var sqltext:string; Book:string;
begin
try
Executesql(AdoQry_tmp,'drop table #tMpson ',1);
except
end;
Executesql(AdoQry_tmp,'select top 0 ItemCode,convert(float,0) as grossqty into #tMpson from Item',1);
Book:=AdoQry_Main.BookmArk;
try
with AdoQry_Main do
begin
First;
while not eof do
begin
if AdoQry_Main.fieldbyname('MpScheck').asinteger=1 then
begin
sqltext:='insert into #tMpson Values('+quotedstr(fieldbyname('ItemCode').asstring)+','+floattostr(fieldbyname('MpsnoFinishqty').asfloat)+')';
Executesql(AdoQry_tmp,sqltext,1);
openBom(fieldbyname('ItemCode').asstring,fieldbyname('MpsnoFinishqty').asfloat);
end;
next;
end;
end;
Executesql(AdoQry_tmp,'select * from #tMpson',0);
if AdoQry_tmp.RecordCount=0 then abort;
If Frm_Mrp_Qry_HalfRunMrp_D=Nil Then
begin
Frm_Mrp_Qry_HalfRunMrp_D:=TFrm_Mrp_Qry_HalfRunMrp_D.Create(Self);
Frm_Mrp_Qry_HalfRunMrp_D.SetSysParam(userCode,ModuleCode,menuid,formatdatetime('yyyy.mm.dd',now));
Frm_Mrp_Qry_HalfRunMrp_D.InitForm(dbconnect,True);
end
Else
Frm_Mrp_Qry_HalfRunMrp_D.Show;
finally
AdoQry_Main.BookmArk:=Book;
end;
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.DBGridEhTitleClick(Column: TColumnEh);
var
BookMArk:String;
begin
inherited;
If Trim(Column.Title.Caption)<>'标识' Then
Abort;
If AdoQry_Main.RecordCount=0 Then
Abort;
BookMArk:=AdoQry_Main.BookmArk;
If Not Flag Then
begin
AdoQry_Main.First;
While Not AdoQry_Main.Eof Do
begin
AdoQry_Main.Edit;
AdoQry_Main.fieldbyname('MpScheck').AsInteger:=1;
AdoQry_Main.Post;
AdoQry_Main.Next;
end;
end
Else
begin
AdoQry_Main.First;
While Not AdoQry_Main.Eof Do
begin
AdoQry_Main.Edit;
AdoQry_Main.fieldbyname('MpScheck').AsInteger:=0;
AdoQry_Main.Post;
AdoQry_Main.Next;
end;
end;
AdoQry_Main.BookmArk:=BookMArk;
Flag:=Not Flag;
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
try
Executesql(AdoQry_tmp,'drop table #tmPmpsMain,#tMpson',1);
except
end;
end;
procedure TFrm_Mrp_Qry_HalfRunMrp.openBom(ItemCode: string; Mpsqty: real);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(Application);
AdoQry.EnableBCD:=False;
AdoQry.Connection:=dbconnect;
try
sqltext:='select ItemCode,BomItemType,grossqty=Bomqty*(1+BomScrAp_Percent/100)*'+floattostr(Mpsqty)
+' from Bom '
+' where Bom.ite_ItemCode='+quotedstr(ItemCode)
+' and Bom.ItemCode not in (select ItemCode from Item where PmCode=1 or PmCode=2)';
Executesql(AdoQry,sqltext,0);
with AdoQry do
begin
First;
while not eof do
begin
if fieldbyname('BomItemType').asinteger<>3 then
begin
sqltext:='insert into #tMpson '
+' Values('+quotedstr(fieldbyname('ItemCode').asstring)+','
+ floattostr(fieldbyname('grossqty').asfloat)+')';
Executesql(AdoQry_tmp,sqltext,1);
end;
if existssonItem(fieldbyname('ItemCode').asstring) then
openBom(fieldbyname('ItemCode').asstring,fieldbyname('grossqty').asfloat);
next;
end;
end;
finally
AdoQry.Free;
end;
end;
function TFrm_Mrp_Qry_HalfRunMrp.existssonItem(ItemCode: string): boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(Application);
AdoQry.EnableBCD:=False;
AdoQry.Connection:=dbconnect;
sqltext:='select ItemCode from Bom where ite_ItemCode='+quotedstr(ItemCode)
+' and ItemCode not in (select ItemCode from Item where PmCode=1 or PmCode=2)';
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
Result:=True;
finally
AdoQry.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?