📄 financialstmtlineform.pas
字号:
unit FinancialStmtLineForm;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Forms, Dialogs, Controls, StdCtrls,
Buttons, ComCtrls, ExtCtrls, Mask, DBCtrls, DB, DBTables, Menus, DBLookup,
Grids, DBGrids;
type
TfrmFinancialStmtLine = class(TForm)
Panel1: TPanel;
PageControl1: TPageControl;
Panel3: TPanel;
Panel2: TPanel;
TabSheet1: TTabSheet;
Panel4: TPanel;
btnOK: TButton;
btnCancel: TButton;
TabSheet2: TTabSheet;
gridAccounts: TDBGrid;
gridTotals: TDBGrid;
panelAccountsHeading: TPanel;
panelTotalsHeading: TPanel;
Label1: TLabel;
Label2: TLabel;
PopupMenu1: TPopupMenu;
popNew: TMenuItem;
popDelete: TMenuItem;
procedure FormShow(Sender: TObject);
procedure Panel2DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure btnCancelClick(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure popNewClick(Sender: TObject);
procedure popDeleteClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure gridAccountsExit(Sender: TObject);
procedure gridTotalsExit(Sender: TObject);
procedure gridAccountsEditButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmFinancialStmtLine: TfrmFinancialStmtLine;
implementation
uses BS1Form, FinancialStmtForm, GLAccountSearchForm;
var
intClientHeight, intClientWidth: Integer;
{$R *.DFM}
procedure TfrmFinancialStmtLine.FormShow(Sender: TObject);
begin
PageControl1.ActivePage := Tabsheet1;
frmFinancialStmt.tblFStmtLAc.First;
frmFinancialStmt.tblFStmtLTo.First;
gridAccounts.setfocus;
end;
procedure TfrmFinancialStmtLine.Panel2DblClick(Sender: TObject);
begin
ClientHeight := intClientHeight; //Resize form.
ClientWidth := intClientWidth;
end;
procedure TfrmFinancialStmtLine.FormCreate(Sender: TObject);
var
x: integer;
begin
if FontFactor <> 1 then begin //If using large fonts, resize form.
for x := 0 to gridAccounts.Columns.Count - 1 do gridAccounts.Columns[x].width := Trunc(gridAccounts.Columns[x].width*FontFactor);
for x := 0 to gridTotals.Columns.Count - 1 do gridTotals.Columns[x].width := Trunc(gridTotals.Columns[x].width*FontFactor);
ClientHeight := Trunc(ClientHeight*FontFactor);
ClientWidth := Trunc(ClientWidth*FontFactor);
PageControl1.TabWidth := Trunc(PageControl1.TabWidth*FontFactor);
end;
intClientHeight := ClientHeight; //Store form size.
intClientWidth := ClientWidth;
Left := screen.width - width;
Top := 0;
end;
procedure TfrmFinancialStmtLine.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin //Enter key: advance to next control.
if not (ActiveControl is TDBGrid) and (ActiveControl.ClassType <> TDBMemo) and (ActiveControl.ClassType <> TDBLookupCombobox) then begin
Key := #0;
Perform(WM_NEXTDLGCTL, 0, 0);
end else if (ActiveControl.ClassType = TDBLookupComboBox) and (TDBLookupComboBox(ActiveControl).ListVisible = false) then begin
Key := #0;
Perform(WM_NEXTDLGCTL, 0, 0);
end else if (ActiveControl is TDBGrid) then begin
key := #0;
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount - 1) then //Increment the field.
selectedindex := selectedindex + 1
else begin //Move to next record.
selectedindex := 0;
if screen.ActiveControl = gridAccounts then begin
frmFinancialStmt.tblFStmtLAc.next;
if frmFinancialStmt.tblFStmtLAc.eof = true then frmFinancialStmt.tblFStmtLAc.append;
end else begin
frmFinancialStmt.tblFStmtLTo.next;
if frmFinancialStmt.tblFStmtLTo.eof = true then frmFinancialStmt.tblFStmtLTo.append;
end;
end;
end;
end;
end;
procedure TfrmFinancialStmtLine.btnCancelClick(Sender: TObject);
begin
frmFinancialStmt.tblFStmtLAc.cancel;
frmFinancialStmt.tblFStmtLTo.cancel;
Close;
end;
procedure TfrmFinancialStmtLine.btnOKClick(Sender: TObject);
begin
if frmFinancialStmt.tblFStmtLAc.State in [dsInsert, dsEdit] then frmFinancialStmt.tblFStmtLAc.post;
if (frmFinancialStmt.tblFStmtLTo.State in [dsInsert, dsEdit]) then begin
if (frmFinancialStmt.tblFStmtLToTotalLineSeq.AsVariant = null) then frmFinancialStmt.tblFStmtLTo.cancel //Bypass if TotalLineSeq null ...can happen if no total lines yet.
else frmFinancialStmt.tblFStmtLTo.post;
end;
Close;
end;
procedure TfrmFinancialStmtLine.popNewClick(Sender: TObject);
begin
if screen.ActiveControl = gridAccounts then begin
frmFinancialStmt.tblFStmtLAc.append;
gridAccounts.SelectedIndex := 0;
end else begin
frmFinancialStmt.tblFStmtLTo.append;
gridTotals.SelectedIndex := 0;
end;
end;
procedure TfrmFinancialStmtLine.popDeleteClick(Sender: TObject);
begin
if screen.ActiveControl = gridAccounts then begin
try frmFinancialStmt.tblFStmtLAc.delete; except; end;
end else begin
try frmFinancialStmt.tblFStmtLTo.delete; except; end;
end;
end;
procedure TfrmFinancialStmtLine.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if (frmFinancialStmt.tblFStmtLAc.State in [dsInsert, dsEdit]) or (frmFinancialStmt.tblFStmtLTo.State in [dsInsert, dsEdit])
then btnOKClick(sender);
end;
procedure TfrmFinancialStmtLine.gridAccountsExit(Sender: TObject);
begin
//frmFinancialStmt.tblFStmtLAc.First; //Causes post which then disables btnCancel, even if exit caused by clicking on btnCancel.
gridAccounts.SelectedIndex := 0;
end;
procedure TfrmFinancialStmtLine.gridTotalsExit(Sender: TObject);
begin
//frmFinancialStmt.tblFStmtLTo.First; //Causes post which then disables btnCancel, even if exit caused by clicking on btnCancel.
gridTotals.SelectedIndex := 0;
end;
procedure TfrmFinancialStmtLine.gridAccountsEditButtonClick(
Sender: TObject);
var
aComponent: TComponent;
begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmGLAccountSearch');
if not Assigned (aComponent) then frmGLAccountSearch := TfrmGLAccountSearch.Create(Application);
if gridAccounts.SelectedField = frmFinancialStmt.tblFStmtLAcAccountFrom then begin
frmGLAccountSearch.GLAccount := frmFinancialStmt.tblFStmtLAcAccountFrom.value;
screen.cursor := crDefault;
if frmGLAccountSearch.ShowModal = mrOk then begin
frmFinancialStmt.tblFStmtLAc.Edit;
frmFinancialStmt.tblFStmtLAcAccountFrom.value := frmGLAccountSearch.GLAccount;
end;
end else begin
frmGLAccountSearch.GLAccount := frmFinancialStmt.tblFStmtLAcAccountTo.value;
screen.cursor := crDefault;
if frmGLAccountSearch.ShowModal = mrOk then begin
frmFinancialStmt.tblFStmtLAc.Edit;
frmFinancialStmt.tblFStmtLAcAccountTo.value := frmGLAccountSearch.GLAccount;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -