⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glaccountform.pas

📁 功能全面的商业财会系统源码,清晰,很有参考价值.扩展性强.
💻 PAS
字号:
unit GLAccountForm;

interface

uses Windows, Messages, SysUtils, Classes, Graphics, Forms, Dialogs, Controls, StdCtrls,
  Buttons, ComCtrls, ExtCtrls, Mask, DBCtrls, DB, DBTables, Menus, DBLookup, BDE;

type
  TfrmGLAccount = class(TForm)
    Panel1: TPanel;
    PageControl1: TPageControl;
    TabSheet2: TTabSheet;
    dsGLAccnt: TDataSource;
    memoNotes: TDBMemo;
    Panel3: TPanel;
    Panel2: TPanel;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    editAccountName: TDBEdit;
    Panel4: TPanel;
    btnOK: TButton;
    btnCancel: TButton;
    Label16: TLabel;
    editGLAccount: TDBEdit;
    tblGLAccnt: TTable;
    tblGLAccntGLAccount: TStringField;
    tblGLAccntAccountName: TStringField;
    tblGLAccntNotes: TMemoField;
    tblGLAccntAccountType: TSmallintField;
    chkSuspended: TDBCheckBox;
    tblGLAccntSuspended: TBooleanField;
    radioAccountType: TDBRadioGroup;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure dsGLAccntDataChange(Sender: TObject; Field: TField);
    procedure FormShow(Sender: TObject);
    procedure Panel2DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure dsGLAccntUpdateData(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure tblGLAccntAfterPost(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGLAccount: TfrmGLAccount;

implementation

uses BS1Form, GLAccountsForm;

var
  intClientHeight, intClientWidth: Integer;

{$R *.DFM}

procedure TfrmGLAccount.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if tblGLAccnt.State in [dsInsert, dsEdit] then btnOKClick(sender);
  try frmGLAccounts.DBGrid1.Setfocus; except; end;
  Action := caFree;
end;

procedure TfrmGLAccount.dsGLAccntDataChange(Sender: TObject;
  Field: TField);
begin
  if (tblGLAccnt.state = dsInsert) and (tblGLAccntAccountName.Value = '') then self.Caption := 'New Account'
  else self.Caption := tblGLAccntAccountName.value;
end;

procedure TfrmGLAccount.FormShow(Sender: TObject);
begin
  PageControl1.ActivePage := Tabsheet1;
  editGLAccount.setfocus;
end;

procedure TfrmGLAccount.Panel2DblClick(Sender: TObject);
begin
  ClientHeight := intClientHeight;   //Resize form.
  ClientWidth := intClientWidth;
end;

procedure TfrmGLAccount.FormCreate(Sender: TObject);
begin
  tblGLAccnt.DatabaseName := strDatabaseName;
  tblGLAccnt.Active := true;

  if FontFactor <> 1 then begin   //If using large fonts, resize form.
    ClientHeight := Trunc(ClientHeight*FontFactor);
    ClientWidth := Trunc(ClientWidth*FontFactor);
    PageControl1.TabWidth := Trunc(PageControl1.TabWidth*FontFactor);
  end;  
  intClientHeight := ClientHeight;   //Store form size.
  intClientWidth := ClientWidth;
end;

procedure TfrmGLAccount.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin   //Enter key: advance to next control.
    if (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;
  end;
end;

procedure TfrmGLAccount.dsGLAccntUpdateData(Sender: TObject);
begin
  if tblGLAccntGLAccount.AsString = '' then begin
    with editGLAccount do begin Show; SetFocus; end;
    raise(exception.create('Field ' + '''Account no.''' + ' must have a value'));
  end;

  if tblGLAccntAccountName.AsString = '' then begin
    with editAccountName do begin Show; SetFocus; end;
    raise(exception.create('Field ' + '''Account Name''' + ' must have a value'));
  end;

  if tblGLAccntAccountType.AsString = '' then begin
    with radioAccountType do begin Show; SetFocus; end;
    raise(exception.create('Field ' + '''Account Type''' + ' must have a value'));
  end;
end;

procedure TfrmGLAccount.btnOKClick(Sender: TObject);
begin
  if tblGLAccnt.State in [dsInsert, dsEdit] then begin
    try tblGLAccnt.post; DbiSaveChanges(tblGLAccnt.handle);
    except
      on E: EDBEngineError do
        if E.Errors[E.ErrorCount - 1].ErrorCode = 9729 then begin   //Key violation (key already exists).
          with editGLAccount do begin Show; SetFocus; end;
          raise(exception.create('Account no. already exists'));
        end else raise;
    end;
    try
      with frmGLAccounts.qryGLAccnt do begin close; open; end;   //Refresh.
      frmGLAccounts.qryGLAccnt.Locate('GLAccount', tblGLAccntGLAccount.AsString, []);
    except; end;
  end;
  Close;
end;

procedure TfrmGLAccount.btnCancelClick(Sender: TObject);
begin
  tblGLAccnt.DisableControls;
  tblGLAccnt.cancel;
  Close;
end;

procedure TfrmGLAccount.tblGLAccntAfterPost(DataSet: TDataSet);
begin
  frmGLAccounts_cboFind_RequeryRequired := true;
  frmGLBalances_cboFind_RequeryRequired := true;
  frmGLBudget_cboFind_RequeryRequired := true;
  frmGLHistory_cboFind_RequeryRequired := true;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -