bas_apbalance.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 705 行 · 第 1/2 页
PAS
705 行
//
unit Bas_ApBalance;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Panel, Db, Grids, DBGridEh, ActnList, AdODB, ExtCtrls, ComCtrls,
ToolWin, ExtPrintReport,dbtables, StdCtrls, jpeg;
Type
TFrm_Bas_ApBalance = Class(TFrm_Base_Panel)
DBGridEh1: TDBGridEh;
AdoQry_Main: TAdoQuery;
DataSource1: TDataSource;
ToolButton1: TToolButton;
TlBtn_Modify: TToolButton;
ToolButton3: TToolButton;
tlBtn_Save: TToolButton;
ToolButton7: TToolButton;
TlBtn_Exit: TToolButton;
ToolButton2: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
ExtPrintReport1: TExtPrintReport;
procedure TlBtn_ModifyClick(Sender: TObject);
procedure tlBtn_SaveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure AdoQry_MainBeforeInsert(DataSet: TDataSet);
procedure Act_ExcelExecute(Sender: TObject);
procedure Act_PreviewExecute(Sender: TObject);
procedure Act_PrintExecute(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
flag:integer;
AdoQryApBalance:TAdoQuery;
procedure IniApBalance; //初始化ApBalance;
function CanModify:boolean; //判断是否能被修改;
function IsNew:boolean; //判断是否有新的供应商;
procedure AddNew; //增加新资料;
procedure Modify; //修改;
procedure DispApBalance ; //显示资料;
procedure dispnoApBalance; //显示资料(ApBalance中无记录)
procedure SetReport;
procedure UpdateCurrentAp; //修改CURRNETAp中的数据;
procedure UpdatetApParam; //修改ApParam 中的最近结帐月份;
function GetPreMonth(Month:string):string; //返回上个月的字符
public
{ Public declarations }
procedure InitForm(AdoConnection:TAdoConnection);
end;
var
Frm_Bas_ApBalance: TFrm_Bas_ApBalance;
implementation
uses Sys_Global;
{$R *.DFM}
procedure TFrm_Bas_ApBalance.AddNew;
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select VendorCode '+
' from Vendor '+
' where VendorCode in '+
' ( select VendorCode ' +
' from ApBalance )');
open;
while not eof do
begin
with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('insert into ApBalance'+
' Values('''+formatdatetime('yyyy.mm',now)+''','+
' '''+ fieldbyname('VendorCode').asstring+''')+');
execsql;
end;
next;
end;
end;
end;
function TFrm_Bas_ApBalance.CanModify: boolean;
var
//str1:string;
i,j:integer;
begin
//Result:=False;
{str1:='';
With AdoQry_Tmp do //取得已结帐月份;
begin
Close;
sql.clear;
sql.Add('select ApParamValuec '+
' from ApParam '+
' where ApParamCode=''clsperiod''');
open;
str1:=fieldbyname('ApParamValuec').asstring;
Close;
end;
if str1<>'' then
Result:=True
else
Result:=False;}
i:=0;
j:=0;
With AdoQry_Tmp do
begin
Close;
Sql.clear;
Sql.Add ('select * from ApInvoice');
open;
i:=recordCount;
Close;
Sql.clear;
Sql.Add ('select * from PayJournal');
open;
j:=recordCount;
Close;
if (i>0) or (j>0) then
Result:=True
else
Result:=False;
end;
end;
procedure TFrm_Bas_ApBalance.IniApBalance;
var
i:integer;
begin
i:=0;
with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('select ApBalance.ApBalanceMonth, '+
' ApBalance.VendorCode +'' ''+Vendor.VendorName as VendorCodeName,'+
' Vendor.CurrencyCode+'' ''+Currency.CurrencyName as CurrencyCodeName,'+
' ApBalance.InvoiceBalance,'+
' ApBalance.NoInviceBalance '+
' from Vendor left join Currency '+
' on Vendor.CurrencyCode=Currency.CurrencyCode'+
' left join ApBalance '+
' on ApBalance.VendorCode=Vendor.VendorCode '+
' where ApBalanceMonth is not null ' );
open;
i:=recordCount;
Close;
end;
if i=0 then
begin
flag:=1;
dispnoApBalance;
dbgrideh1.ReadOnly :=False;
TlBtn_Modify.Enabled :=False;
tlBtn_Save.enabled:=True;
end
else
begin
// if CanModify=False then
begin
flag:=2;
DispApBalance;
dbgrideh1.ReadOnly :=False;
TlBtn_Modify.Enabled :=True;
end;
end;
end;
procedure TFrm_Bas_ApBalance.InitForm(AdoConnection: TAdoConnection);
begin
inherited;
SetDBConnect(AdoConnection);
AdoQry_Main.Connection:=AdoConnection;
IniApBalance;
if CanModify then
begin
Pnl_Hint.Caption:='提示: 资料不能修改!' ;
dbgrideh1.ReadOnly:=True;
end
else
begin
Pnl_Hint.Caption:='提示: 若需修改资料,选请单击工具栏上修改按钮!';
AdoQryApBalance:=TAdoQuery.Create(nil);
AdoQryApBalance.Connection:=AdoQry_Main.Connection;
end;
controlBar.setfocus;
end;
function TFrm_Bas_ApBalance.IsNew: boolean;
begin
Result:=False;
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select VendorCode '+
' from Vendor '+
' where VendorCode not in '+
' ( select VendorCode ' +
' from ApBalance ) ');
open;
if not eof then
Result:=True;
Close;
end;
end;
{procedure TFrm_Bas_ApBalance.Modify;
begin
end;}
procedure TFrm_Bas_ApBalance.TlBtn_ModifyClick(Sender: TObject);
begin
inherited;
if CanModify then
begin
DispInfo('资料不能修改!',1);
dbgrideh1.ReadOnly:=True;
abort;
end;
flag:=2;
Pnl_Hint.Caption:='提示: 点选列表明细就可修改资料!';
if not AdoQry_Main.Connection.InTransaction then
AdoQry_Main.Connection.beginTrans ;
Dbgrideh1.ReadOnly:=False;
if AdoQry_Main.active=False then AdoQry_Main.active:=True;
AdoQry_Main.Edit;
dbgrideh1.setfocus;
TlBtn_Modify.enabled:=False;
TlBtn_Save.Enabled :=True;
end;
procedure TFrm_Bas_ApBalance.tlBtn_SaveClick(Sender: TObject);
var
BookmArk:TBookmArk ;
begin
inherited;
//AdoQry_Main.DisableControls;
if AdoQry_Main.RecordCount=0 then
begin
DispInfo('没有资料可保存!',3);
abort;
end;
BookmArk:=AdoQry_Main.GetBookmArk ;
try
if not AdoQry_Main.Connection.InTransaction then
AdoQry_Main.Connection.beginTrans ;
if flag=2 then
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add(' delete from ApBalance ' );
execsql;
end;
end;
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select * from ApBalance ');
open;
//数据交换;
AdoQry_Main.First;
while not AdoQry_Main.eof do
begin
AdoQry_Tmp.insert;
AdoQry_Tmp.fieldbyname('ApBalanceMonth').asstring:= AdoQry_Main.fieldbyname('ApBalanceMonth').asstring;
AdoQry_Tmp.fieldbyname('VendorCode').asstring:= GetCode(Trim(AdoQry_Main.fieldbyname('VendorCodeName').asstring));
AdoQry_Tmp.fieldbyname('InvoiceBalance').asfloat:= AdoQry_Main.fieldbyname('InvoiceBalance').asfloat;
AdoQry_Tmp.fieldbyname('NoInviceBalance').asfloat:= AdoQry_Main.fieldbyname('NoInviceBalance').asfloat;
AdoQry_Tmp.post;
AdoQry_Main.next;
end;
end;
AdoQry_Tmp.UpdateBatch;
UpdateCurrentAp; //修改CURRNETAp中的数据;
UpdatetApParam; //修改ApParam 中的最近结帐月份;
AdoQry_Main.Connection.CommitTrans ;
DispInfo('修改成功!',3);
flag:=0;
TlBtn_Save.enabled:=False;
TlBtn_Modify.Enabled :=True;
dbgrideh1.ReadOnly:=True;
AdoQry_Main.GotoBookmArk(BookmArk ) ;
AdoQry_Main.freeBookmArk(BookmArk ) ;
//AdoQry_Main.EnableControls;
except
AdoQry_Main.Connection.RollBackTrans ;
//AdoQry_Main.EnableControls;
DispInfo('修改失败!',1);
abort;
end;
Pnl_Hint.Caption:='提示:共有:'+Inttostr(AdoQry_Main.recordCount)+'条记录';
end;
procedure TFrm_Bas_ApBalance.FormCreate(Sender: TObject);
begin
inherited;
flag:=0;
TlBtn_Save.enabled:=False;
TlBtn_Modify.enabled:=True;
end;
procedure TFrm_Bas_ApBalance.DispApBalance;
var
TmpAdoQry:TAdoQuery;
begin
begin
TmpAdoQry:=TAdoQuery.Create(nil);
try
TmpAdoQry.Connection:= AdoQry_Main.Connection;
with TmpAdoQry do
begin
Close;
sql.clear;
sql.Add('set noCount on '+
'select ApBalance.ApBalanceMonth, '+
' ApBalance.VendorCode,'+
' Vendor.CurrencyCode,'+
' ApBalance.InvoiceBalance,'+
' ApBalance.NoInviceBalance '+
' into #TmpApBalance '+
' from Vendor left join Currency '+
' on Vendor.CurrencyCode=Currency.CurrencyCode '+
' left join ApBalance '+
' on ApBalance.VendorCode=Vendor.VendorCode '+
' select * from #TmpApBalance ' );
open;
end;
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select Vendor.VendorCode ,'+
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?