📄 glbalancesform.pas
字号:
unit GLBalancesForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBCtrls, Grids, DBGrids, DB, DBTables, Menus, ExtCtrls, StdCtrls, Buttons;
type
TfrmGLBalances = class(TForm)
Panel1: TPanel;
MainMenu1: TMainMenu;
tblGLAccnt: TTable;
dsGLAccnt: TDataSource;
DBGrid1: TDBGrid;
cboFind: TComboBox;
Label1: TLabel;
mnuFile: TMenuItem;
mnuView: TMenuItem;
mnuHelp: TMenuItem;
mnuFilter: TMenuItem;
mnuSortBy: TMenuItem;
mnuRefresh: TMenuItem;
mnuGLAccountsHelp: TMenuItem;
mnuPrint: TMenuItem;
N2: TMenuItem;
mnuExit: TMenuItem;
Bevel1: TBevel;
mnuSortName: TMenuItem;
mnuSortAccountno: TMenuItem;
mnuHistory: TMenuItem;
N4: TMenuItem;
editFind: TEdit;
tblGLAccntGLAccount: TStringField;
tblGLAccntAccountName: TStringField;
qryGLAccnt: TQuery;
qryGLAccntGLAccount: TStringField;
qryGLAccntAccountName: TStringField;
tblGLAccntSuspended: TBooleanField;
tblGLAccntAccountType: TSmallintField;
PopupMenu1: TPopupMenu;
popHistory: TMenuItem;
qryGLAccntGLYear: TSmallintField;
qryGLAccntOpeningBal: TCurrencyField;
qryGLAccntAmount1: TCurrencyField;
qryGLAccntAmount2: TCurrencyField;
qryGLAccntAmount3: TCurrencyField;
qryGLAccntAmount4: TCurrencyField;
qryGLAccntAmount5: TCurrencyField;
qryGLAccntAmount6: TCurrencyField;
qryGLAccntAmount7: TCurrencyField;
qryGLAccntAmount8: TCurrencyField;
qryGLAccntAmount9: TCurrencyField;
qryGLAccntAmount10: TCurrencyField;
qryGLAccntAmount11: TCurrencyField;
qryGLAccntAmount12: TCurrencyField;
qryGLAccntAccountType: TSmallintField;
N3: TMenuItem;
mnuBudget: TMenuItem;
popBudget: TMenuItem;
btnFilter: TSpeedButton;
procedure mnuRefreshClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Panel1DblClick(Sender: TObject);
procedure cboFindDropDown(Sender: TObject);
procedure cboFindKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cboFindClick(Sender: TObject);
procedure cboFindKeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure editFindKeyPress(Sender: TObject; var Key: Char);
procedure mnuExitClick(Sender: TObject);
procedure mnuSortAccountnoClick(Sender: TObject);
procedure mnuSortNameClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure mnuPrintClick(Sender: TObject);
procedure mnuFilterClick(Sender: TObject);
procedure qryGLAccntFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
procedure tblGLAccntFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
procedure mnuHistoryClick(Sender: TObject);
procedure mnuGLAccountsHelpClick(Sender: TObject);
procedure mnuBudgetClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmGLBalances: TfrmGLBalances;
implementation
uses BS1Form, GLBalancesFilterForm, GLHistoryForm, GLHistoryFilterForm,
GLBalancesReport, GLBudgetForm, GLBudgetFilterForm;
var
intClientHeight, intClientWidth: Integer;
cboFind_GLAccounts: TStringList;
OldWindowState: TWindowState;
{$R *.DFM}
procedure cboFind_Load(const Tbl: TTable; const Cbo: TCombobox);
begin
Cbo.Items.Clear; //Populate "find" combobox.
cboFind_GLAccounts.Clear;
Tbl.First;
while not Tbl.EOF do begin
Cbo.Items.Add(Tbl['AccountName']);
cboFind_GLAccounts.Add(Tbl['GLAccount']);
Tbl.Next;
end;
frmGLBalances_cboFind_RequeryRequired := false;
end;
procedure TfrmGLBalances.mnuRefreshClick(Sender: TObject);
var
Bookmark: TBookmark;
begin
screen.cursor := crHourglass;
Bookmark := qryGLAccnt.GetBookmark;
with qryGLAccnt do begin close; open; end; //Refresh.
try qryGLAccnt.GotoBookmark(Bookmark); except; end;
qryGLAccnt.FreeBookmark(BookMark);
screen.cursor := crDefault;
end;
procedure TfrmGLBalances.FormCreate(Sender: TObject);
var
x: integer;
begin
qryGLAccnt.DatabaseName := strDatabaseName;
tblGLAccnt.DatabaseName := strDatabaseName;
qryGLAccnt.Active := true;
tblGLAccnt.Active := true;
cboFind_GLAccounts := TStringList.create; //Create a TStringList to store Accounts for the "find" combobox.
cboFind_Load(tblGLAccnt, cboFind); //Populate "find" combobox.
Width := screen.width;
if FontFactor <> 1 then begin //If using large fonts, resize grid columns.
for x := 0 to DBGrid1.Columns.Count - 1 do DBGrid1.Columns[x].width := Trunc(DBGrid1.Columns[x].width*FontFactor);
end;
intClientHeight := ClientHeight; //Store form size.
intClientWidth := ClientWidth;
end;
procedure TfrmGLBalances.Panel1DblClick(Sender: TObject);
begin
ClientHeight := intClientHeight; //Resize form.
ClientWidth := intClientWidth;
end;
procedure TfrmGLBalances.cboFindDropDown(Sender: TObject);
begin
if frmGLBalances_cboFind_RequeryRequired = true then cboFind_Load(tblGLAccnt, cboFind); //Populate "find" combobox.
end;
procedure TfrmGLBalances.cboFindKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if frmGLBalances_cboFind_RequeryRequired = true then cboFind_Load(tblGLAccnt, cboFind); //Populate "find" combobox.
end;
procedure TfrmGLBalances.cboFindClick(Sender: TObject);
begin
if cboFind.Text = '' then exit;
editFind.text := '';
if cboFind.Items.IndexOf(cboFind.Text) < 0 then raise(Exception.Create('Choose an item from the list'));
if qryGLAccnt.Locate('GLAccount', cboFind_GLAccounts[cboFind.ItemIndex], []) <> true then raise(Exception.Create('''' + cboFind.Text + '''' + ' not found'));
end;
procedure TfrmGLBalances.cboFindKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin
Key := #0; //Cancel Enter key.
if (cboFind.Text = '') or (cboFind.Text = '<Account name>') then begin
Perform(WM_NEXTDLGCTL, 0, 0); //Advance to next control.
exit;
end;
cboFindClick(Sender); //Trigger click event (in case partial text was entered then combobox opened: item would show as selected, but Enter wouldn't process it).
Perform(WM_NEXTDLGCTL, 0, 0); //Advance to next control.
end;
end;
procedure TfrmGLBalances.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin
mnuHistoryClick(Sender);
Key := #0; //Cancel Enter key.
end;
end;
procedure TfrmGLBalances.FormShow(Sender: TObject);
begin
cboFind.ItemIndex := 0; //Reset selected item to 1st (so down arrow scrolls from start).
cboFind.text := '<Account name>'; //Clear selection.
editFind.text := '<Account no.>';
editFind.setfocus;
editFind.SelectAll;
qryGLAccnt.First; //Reset grid to start at 1st record.
if mnuFilter.checked = true then caption := 'GL Balances (Filtered)'
else caption := 'GL Balances';
end;
procedure TfrmGLBalances.editFindKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin
Key := #0; //Cancel Enter key.
if (editFind.Text = '') or (editFind.Text = '<Account no.>') then begin
Perform(WM_NEXTDLGCTL, 0, 0); //Advance to next control.
exit;
end;
cboFind.text := '';
if qryGLAccnt.Locate('GLAccount', editFind.Text, []) <> true then begin
editFind.SelectAll;
raise(Exception.Create('Account ' + '''' + editFind.Text + '''' + ' not found'));
end else DBGrid1.setfocus;
end;
end;
procedure TfrmGLBalances.mnuExitClick(Sender: TObject);
begin
Close;
end;
procedure TfrmGLBalances.mnuSortAccountnoClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortAccountno.checked := true;
qryGLAccnt.close;
qryGLAccnt.sql.clear;
qryGLAccnt.sql.add('SELECT G.GLAccount, G.AccountName, G.AccountType, A.* FROM GLAccnt G LEFT OUTER JOIN GLActual A ON G.GLAccount = A.GLAccount');
qryGLAccnt.sql.add('ORDER BY G.GLAccount, A.GLYear');
qryGLAccnt.open;
screen.cursor := crDefault;
end;
procedure TfrmGLBalances.mnuSortNameClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortName.checked := true;
qryGLAccnt.close;
qryGLAccnt.sql.clear;
qryGLAccnt.sql.add('SELECT G.GLAccount, G.AccountName, G.AccountType, A.* FROM GLAccnt G LEFT OUTER JOIN GLActual A ON G.GLAccount = A.GLAccount');
qryGLAccnt.sql.add('ORDER BY G.AccountName, A.GLYear');
qryGLAccnt.open;
screen.cursor := crDefault;
end;
procedure TfrmGLBalances.FormResize(Sender: TObject);
begin
if (WindowState <> OldWindowState) //Prevent grid resize bugs.
and (WindowState <> wsMinimized)
and (OldWindowState <> wsMinimized)
then mnuRefreshClick(sender);
OldWindowState := WindowState;
end;
procedure TfrmGLBalances.mnuPrintClick(Sender: TObject);
var
strWHERE: string;
begin
//if license = '' then begin frmBS1.FreewareMessage; exit; end;
screen.cursor := crHourglass;
application.createform (TrptGLBalances,rptGLBalances);
rptGLBalances.qryGLAccnt.SQL := frmGLBalances.qryGLAccnt.SQL;
if mnuFilter.checked = true then begin
strWHERE := ' WHERE (1 = 1)';
try //Try in case filter form not loaded.
if (frmGLBalancesFilter.chkYearAll.checked <> true) then strWHERE := strWHERE + ' AND (GLYear = ' + frmGLBalancesFilter.editYear.text + ')';
if (frmGLBalancesFilter.cboAccountType.text <> '<All>') then strWHERE := strWHERE + ' AND (AccountType = ' + IntToStr(frmGLBalancesFilter.cboAccountType.ItemIndex) + ')';
except; end;
rptGLBalances.qryGLAccnt.SQL[0] := rptGLBalances.qryGLAccnt.SQL[0] + strWHERE;
end;
rptGLBalances.qryGLAccnt.Active := true;
screen.cursor := crDefault;
rptGLBalances.QuickReport.Preview;
end;
procedure TfrmGLBalances.mnuFilterClick(Sender: TObject);
var
aComponent: TComponent;
begin
aComponent := Application.FindComponent('frmGLBalancesFilter');
if not Assigned (aComponent) then frmGLBalancesFilter := TfrmGLBalancesFilter.Create(Application);
frmGLBalancesFilter.ShowModal;
end;
procedure TfrmGLBalances.qryGLAccntFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
Accept := true; //Default.
try //Try in case filter form not loaded.
if (frmGLBalancesFilter.chkYearAll.checked <> true) and (qryGLAccntGLYear.AsString <> frmGLBalancesFilter.editYear.text) then Accept := false;
if (frmGLBalancesFilter.cboAccountType.text <> '<All>') and (qryGLAccntAccountType.value <> frmGLBalancesFilter.cboAccountType.ItemIndex) then Accept := false;
except; end;
end;
procedure TfrmGLBalances.tblGLAccntFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
Accept := true; //Default.
try //Try in case filter form not loaded.
if (frmGLBalancesFilter.cboAccountType.text <> '<All>') and (tblGLAccntAccountType.value <> frmGLBalancesFilter.cboAccountType.ItemIndex) then Accept := false;
except; end;
end;
procedure TfrmGLBalances.mnuHistoryClick(Sender: TObject);
var
aComponent: TComponent;
begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmGLHistory');
if not Assigned (aComponent) then frmGLHistory := TfrmGLHistory.Create(Application);
aComponent := Application.FindComponent('frmGLHistoryFilter');
if Assigned (aComponent) then try frmGLHistoryFilter.btnResetClick(sender); except; end
else begin
frmGLHistoryFilter := TfrmGLHistoryFilter.Create(Application);
frmGLHistoryFilter.FormShow(sender); //Set up cboGLAccounts so SetGLAccount will work.
end;
frmGLHistoryFilter.GLAccount := qryGLAccntGLAccount.value;
frmGLHistoryFilter.editGLAccount.text := qryGLAccntGLAccount.value;
frmGLHistory.mnuFilter.Checked := true;
frmGLHistory.qryGLHist.Filtered := true;
frmGLHistory.tblGLAccnt.Filtered := false;
frmGLHistory.qryGLHist.close; frmGLHistory.qryGLHist.open;
if frmGLHistory.WindowState = wsMinimized then frmGLHistory.WindowState := wsNormal;
if frmGLHistory.visible = true then frmGLHistory.FormShow(sender)
else frmGLHistory.Show;
if not frmGLHistory.qryGLHist.Locate('GLAccount', qryGLAccntGLAccount.value, []) then frmGLHistory.qryGLHist.First;
screen.cursor := crDefault;
end;
procedure TfrmGLBalances.mnuGLAccountsHelpClick(Sender: TObject);
begin
Application.HelpContext(340);
end;
procedure TfrmGLBalances.mnuBudgetClick(Sender: TObject);
var
aComponent: TComponent;
begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmGLBudget');
if Assigned (aComponent) then try frmGLBudget.qryGLAccnt.close; frmGLBudget.qryGLAccnt.open; except; end
else frmGLBudget := TfrmGLBudget.Create(Application);
aComponent := Application.FindComponent('frmGLBudgetFilter');
if Assigned (aComponent) then try frmGLBudgetFilter.btnResetClick(sender); except; end;
frmGLBudget.mnuFilter.Checked := false;
frmGLBudget.qryGLAccnt.Filtered := false;
frmGLBudget.tblGLAccnt.Filtered := false;
if frmGLBudget.WindowState = wsMinimized then frmGLBudget.WindowState := wsNormal;
if frmGLBudget.visible = true then frmGLBudget.FormShow(sender)
else frmGLBudget.Show;
if not frmGLBudget.qryGLAccnt.Locate('GLAccount', qryGLAccntGLAccount.value, []) then frmGLBudget.qryGLAccnt.First;
screen.cursor := crDefault;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -