📄 apchequesprintform.pas
字号:
unit APChequesPrintForm;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, ComCtrls, DB, DBTables, Mask, DBCtrls, Dialogs, BDE, Printers, qrprntr;
type
TfrmAPChequesPrint = class(TForm)
btnOK: TButton;
btnCancel: TButton;
qryAPCheq: TQuery;
lblRecordCount: TLabel;
ProgressBar1: TProgressBar;
tblAPInvChq: TTable;
dsAPCheq: TDataSource;
tblAPCheq: TTable;
tblAPInv: TTable;
dsAPInvChq: TDataSource;
qryAPCheqChequeID: TIntegerField;
qryAPCheqChequeNo: TIntegerField;
qryAPCheqVendorID: TIntegerField;
qryAPCheqBankID: TIntegerField;
qryAPCheqChequeDate: TDateField;
qryAPCheqChequeAmount: TCurrencyField;
qryAPCheqPosted: TBooleanField;
qryAPCheqVendorNo: TStringField;
qryAPCheqVendorName: TStringField;
tblAPCheqChequeID: TIntegerField;
tblAPCheqChequeNo: TIntegerField;
tblAPInvChqAPInvoiceID: TIntegerField;
tblAPInvChqChequeID: TIntegerField;
tblAPInvChqSeq: TIntegerField;
tblAPInvChqPaymentAmount: TCurrencyField;
tblAPInvAPInvoiceID: TIntegerField;
tblAPInvInvoiceNo: TStringField;
tblAPInvInvoiceDate: TDateField;
tblAPInvInvoiceAmount: TCurrencyField;
tblAPInvOwing: TCurrencyField;
tblAPInvChqInvoiceNo: TStringField;
tblAPInvChqInvoiceAmount: TCurrencyField;
tblAPInvChqInvoiceDate: TDateField;
tblAPInvChqOwing: TCurrencyField;
qryAPCheqAddressLine1: TStringField;
qryAPCheqAddressLine2: TStringField;
qryAPCheqCity: TStringField;
qryAPCheqStateProv: TStringField;
qryAPCheqZipCode: TStringField;
qryAPCheqCountry: TStringField;
qryAPCheqCityStateZip: TStringField;
cboBank: TComboBox;
Label1: TLabel;
PrintDialog1: TPrintDialog;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure qryAPCheqCalcFields(DataSet: TDataSet);
procedure cboBankExit(Sender: TObject);
procedure cboBankClick(Sender: TObject);
private
{ Private declarations }
procedure SetNextChequeNo(NextChequeNo: integer);
function GetNextChequeNo: integer;
public
{ Public declarations }
property NextChequeNo: integer read GetNextChequeNo write SetNextChequeNo;
end;
var
frmAPChequesPrint: TfrmAPChequesPrint;
implementation
uses BS1Form, APChequeReport, LookUpsData;
{$R *.DFM}
var
RecordCount, intNextChequeNo: integer;
cboBankIDs: TStringList;
procedure TfrmAPChequesPrint.SetNextChequeNo(NextChequeNo: integer);
begin
intNextChequeNo := NextChequeNo;
end;
function TfrmAPChequesPrint.GetNextChequeNo: integer;
begin
Result := intNextChequeNo;
end;
procedure cboBank_Load(const Tbl: TTable; const Cbo: TCombobox);
var
LookupResults: variant;
begin
Cbo.Items.Clear; //Populate "Bank" combobox.
cboBankIDs.Clear;
Tbl.First;
while not Tbl.EOF do begin
Cbo.Items.Add(Tbl['BankName']);
cboBankIDs.Add(Tbl['BankID']);
Tbl.Next;
end;
if Cbo.Items.count > 0 then begin
if frmBS1.tblCompanyDefaultCurrencyID.value > 0 then begin
LookupResults := dmLookUps.tblBank.LookUp('CurrencyID', frmBS1.tblCompanyDefaultCurrencyID.value, 'BankID');
if LookupResults = null then Cbo.ItemIndex := 0
else Cbo.ItemIndex := cboBankIDs.IndexOf(VarToStr(LookupResults));
end else Cbo.ItemIndex := 0;
end;
end;
procedure TfrmAPChequesPrint.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfrmAPChequesPrint.FormCreate(Sender: TObject);
begin
qryAPCheq.DatabaseName := strDatabaseName;
tblAPCheq.DatabaseName := strDatabaseName;
tblAPInvChq.DatabaseName := strDatabaseName;
tblAPInv.DatabaseName := strDatabaseName;
dmLookUps.tblBank.active := true;
cboBankIDs := TStringList.create; //Create a TStringList to store BankIDs for the combobox.
cboBank_Load(dmLookUps.tblBank, cboBank); //Populate "Bank" combobox.
try qryAPCheq.Params[0].AsInteger := StrToInt(cboBankIDs[cboBank.ItemIndex]); except end; //Try in case no banks set up yet.
qryAPCheq.Active := true;
RecordCount := qryAPCheq.RecordCount;
lblRecordCount.caption := IntToStr(RecordCount) + ' cheque(s) to be printed';
end;
procedure TfrmAPChequesPrint.btnOKClick(Sender: TObject);
var
aComponent: TComponent;
strNextChequeNo: string;
begin
if (cboBank.Items.count > 0) and (cboBank.Items.IndexOf(cboBank.Text) < 0) then begin //If Enter was pressed, this edit hasn't been done yet.
cboBank.setfocus;
raise(Exception.Create('Choose an item from the list'));
end;
ModalResult := mrCancel; //Set to mrCancel to prevent subsequent requery in case job can't be started.
if RecordCount = 0 then exit;
aComponent := Application.FindComponent('frmAPCheque');
if Assigned (aComponent) then raise(Exception.Create('A conflicting program is running...' + #13 + 'Please close ' + '''' + 'AP Cheque' + '''' + ' form'));
if InputQuery(Application.Title, 'Please enter the number of the first cheque...', strNextChequeNo) = true then begin
try intNextChequeNo := StrToInt(strNextChequeNo); except ModalResult := mrNone; raise; end;
if intNextChequeNo < 0 then begin
ModalResult := mrNone;
raise(exception.create('''' + strNextChequeNo + '''' + ' is not a valid cheque no'));
end;
end else begin //Cancel pressed.
ModalResult := mrNone;
exit;
end;
repaint;
PrintDialog1.options := [];
PrintDialog1.Copies := 1;
PrintDialog1.Collate := false;
if PrintDialog1.execute = false then begin ModalResult := mrNone; exit; end;
//if PrintDialog1.Copies > 1 then raise(exception.create('Multiple copies is not supported for printing cheques'));
if PrintDialog1.Copies > 1 then begin
MessageDlg('Multiple copies is not supported for printing cheques', mtInformation, [mbOK], 0);
QRPrinter.Copies := 1;
end;
repaint;
repeat //Exclusive open to prevent locking Delphi 2 locking bug.
try
tblAPCheq.Active := True;
Break; //If no error, exit the loop.
except
on EDatabaseError do if MessageDlg('Unable to open Cheques table exclusively.', mtError, [mbRetry, mbCancel], 0) <> mrRetry then begin
ModalResult := mrCancel;
raise;
end;
end;
until False;
modalResult := mrOK;
screen.cursor := crHourglass;
tblAPInvChq.Active := true;
ProgressBar1.max := qryAPCheq.RecordCount;
ProgressBar1.step := 1;
application.createform (TrptAPCheque,rptAPCheque);
screen.cursor := crDefault;
rptAPCheque.QuickReport.PrinterSettings.PrinterIndex := Printer.PrinterIndex; //Required for Delphi 3.
rptAPCheque.QuickReport.Print;
lblRecordCount.caption := '';
try
if MessageDlg('Did cheque(s) print OK?', mtConfirmation, [mbYes, mbNo], 0) <> mrYes then begin
ModalResult := mrCancel; //No need to requery.
lblRecordCount.caption := 'Resetting cheque(s)';
qryAPCheq.First;
progressbar1.position := 0;
progressbar1.visible := true;
while not qryAPCheq.EOF do begin
try
tblAPCheq.Edit;
tblAPCheqChequeNo.AsVariant := null;
tblAPCheq.Post;
except raise; end;
ProgressBar1.StepIt;
qryAPCheq.next;
end;
end;
finally
DbiSaveChanges(tblAPCheq.handle);
tblAPCheq.Close;
screen.cursor := crDefault;
end;
end;
procedure TfrmAPChequesPrint.qryAPCheqCalcFields(DataSet: TDataSet);
begin
qryAPCheqCityStateZip.value := qryAPCheqCity.value;
if qryAPCheqStateProv.value <> '' then qryAPCheqCityStateZip.value := qryAPCheqCityStateZip.value + ', ' + qryAPCheqStateProv.value;
if qryAPCheqZipCode.value <> '' then qryAPCheqCityStateZip.value := qryAPCheqCityStateZip.value + ' ' + qryAPCheqZipCode.value;
end;
procedure TfrmAPChequesPrint.cboBankExit(Sender: TObject);
begin
if (cboBank.Items.count > 0) and (cboBank.Items.IndexOf(cboBank.Text) < 0) then begin
cboBank.setfocus;
raise(Exception.Create('Choose an item from the list'));
end;
end;
procedure TfrmAPChequesPrint.cboBankClick(Sender: TObject);
begin
cursor := crHourglass;
qryAPCheq.Active := false;
qryAPCheq.Params[0].AsInteger := StrToInt(cboBankIDs[cboBank.ItemIndex]);
qryAPCheq.Active := true;
RecordCount := qryAPCheq.RecordCount;
lblRecordCount.caption := IntToStr(RecordCount) + ' cheque(s) to be printed';
cursor := crDefault;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -