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

📄 arpaymentsform.pas

📁 功能全面的商业财会系统源码,清晰,很有参考价值.扩展性强.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit ARPaymentsForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DBCtrls, Grids, DBGrids, DB, DBTables, Menus, ExtCtrls, StdCtrls, Buttons, BDE, SHELLAPI;

type
  TfrmARPayments = class(TForm)
    Panel1: TPanel;
    MainMenu1: TMainMenu;
    tblARPmt: TTable;
    dsARPmt: TDataSource;
    DBGrid1: TDBGrid;
    Label1: TLabel;
    mnuFile: TMenuItem;
    mnuView: TMenuItem;
    mnuHelp: TMenuItem;
    mnuFilter: TMenuItem;
    mnuSortBy: TMenuItem;
    N1: TMenuItem;
    mnuRefresh: TMenuItem;
    mnuAPInvoicesHelp: TMenuItem;
    mnuPrint: TMenuItem;
    N2: TMenuItem;
    mnuExit: TMenuItem;
    Bevel1: TBevel;
    mnuSortAmount: TMenuItem;
    mnuSortDate: TMenuItem;
    mnuSortName: TMenuItem;
    mnuBillTo: TMenuItem;
    N4: TMenuItem;
    btnNew: TSpeedButton;
    btnEdit: TSpeedButton;
    btnDelete: TSpeedButton;
    mnuRecords: TMenuItem;
    mnuNew: TMenuItem;
    mnuEdit: TMenuItem;
    mnuDelete: TMenuItem;
    qryARPmt: TQuery;
    tblARInvPmt: TTable;
    mnuSortDateAscending: TMenuItem;
    mnuSortDateDescending: TMenuItem;
    mnuSortBillToNo: TMenuItem;
    mnuSortChequeno: TMenuItem;
    PopupMenu1: TPopupMenu;
    popBillTo: TMenuItem;
    editFindCheque: TEdit;
    N3: TMenuItem;
    mnuPost: TMenuItem;
    popNew: TMenuItem;
    popEdit: TMenuItem;
    popDelete: TMenuItem;
    N5: TMenuItem;
    popPhone: TMenuItem;
    qryARPmtPeriodppyyyy: TStringField;
    qryARPmtPaymentID: TIntegerField;
    qryARPmtBillToID: TIntegerField;
    qryARPmtBankID: TIntegerField;
    qryARPmtGLYear: TSmallintField;
    qryARPmtGLPeriod: TSmallintField;
    qryARPmtPaymentDate: TDateField;
    qryARPmtChequeAmount: TCurrencyField;
    qryARPmtPosted: TBooleanField;
    qryARPmtCustomerNo: TStringField;
    qryARPmtCustomerName: TStringField;
    qryARPmtCurrencyID: TIntegerField;
    qryARPmtPhone: TStringField;
    tblARPmtPaymentID: TIntegerField;
    tblARInvPmtPaymentID: TIntegerField;
    editFindCustomer: TEdit;
    cboFindCustomer: TComboBox;
    qryARPmtChequeNo: TStringField;
    popEMail: TMenuItem;
    N6: TMenuItem;
    qryARPmtEMail: TStringField;
    btnFilter: TSpeedButton;
    procedure mnuRefreshClick(Sender: TObject);
    procedure tblARPmtBeforeDelete(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
    procedure Panel1DblClick(Sender: TObject);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure mnuNewClick(Sender: TObject);
    procedure mnuEditClick(Sender: TObject);
    procedure mnuDeleteClick(Sender: TObject);
    procedure mnuExitClick(Sender: TObject);
    procedure qryARPmtCalcFields(DataSet: TDataSet);
    procedure mnuSortDateAscendingClick(Sender: TObject);
    procedure mnuSortDateDescendingClick(Sender: TObject);
    procedure mnuSortNameClick(Sender: TObject);
    procedure mnuSortAmountClick(Sender: TObject);
    procedure mnuSortBillToNoClick(Sender: TObject);
    procedure mnuSortChequenoClick(Sender: TObject);
    procedure mnuBillToClick(Sender: TObject);
    procedure editFindChequeKeyPress(Sender: TObject; var Key: Char);
    procedure FormResize(Sender: TObject);
    procedure mnuPostClick(Sender: TObject);
    procedure mnuFilterClick(Sender: TObject);
    procedure qryARPmtFilterRecord(DataSet: TDataSet; var Accept: Boolean);
    procedure mnuPrintClick(Sender: TObject);
    procedure popPhoneClick(Sender: TObject);
    procedure cboFindCustomerClick(Sender: TObject);
    procedure editFindCustomerKeyPress(Sender: TObject; var Key: Char);
    procedure cboFindCustomerDropDown(Sender: TObject);
    procedure cboFindCustomerKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cboFindCustomerKeyPress(Sender: TObject; var Key: Char);
    procedure mnuAPInvoicesHelpClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure popEMailClick(Sender: TObject);
    procedure dsARPmtDataChange(Sender: TObject; Field: TField);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmARPayments: TfrmARPayments;

implementation

uses BS1Form, ARPaymentsFilterForm, CustomerForm, DialerForm, LookUpsData,
  ARPaymentsReport, ARPaymentForm, ARPaymentsPostForm, JVsPostForm;

var
  intClientHeight, intClientWidth: Integer;
  cboFindCustomer_CustomerIDs: TStringList;
  OldWindowState: TWindowState;

{$R *.DFM}

procedure cboFindCustomer_Load(const Tbl: TTable; const Cbo: TCombobox);
begin
  Cbo.Items.Clear;   //Populate "find" combobox.
  cboFindCustomer_CustomerIDs.Clear;
  Tbl.First;
  while not Tbl.EOF do begin
    Cbo.Items.Add(Tbl['CustomerName']);
    cboFindCustomer_CustomerIDs.Add(Tbl['CustomerID']);
    Tbl.Next;
  end;
  frmARPayments_cboFindCustomer_RequeryRequired := false;
end;

procedure TfrmARPayments.mnuRefreshClick(Sender: TObject);
var
  Bookmark: TBookmark;
begin
  repaint;
  screen.cursor := crHourglass;
  Bookmark := qryARPmt.GetBookmark;
  with qryARPmt do begin close; open; end;   //Refresh.
  try qryARPmt.GotoBookmark(Bookmark); except; end;
  qryARPmt.FreeBookmark(BookMark);
  screen.cursor := crDefault;
end;

procedure TfrmARPayments.tblARPmtBeforeDelete(DataSet: TDataSet);
begin
  if qryARPmtPosted.value = true then raise(Exception.Create('Unable to delete cheque ' + '''' + qryARPmtChequeNo.AsString + '''' + '...' + #13 + 'It has already been posted'));
  if MessageDlg('Delete cheque ' + '''' + qryARPmtChequeNo.AsString + '''' + '?',mtConfirmation,mbOKCancel,0) <> mrOK then raise(EAbort.create(''));   //Silent Exception: "abort;" replaced by "raise etc" since abort conflicts with BDE (required by DbiSaveChanges).
  repaint;

  tblARPmt.edit;   //Put lock on master table.
  with tblARInvPmt do begin   //Delete detail for this payment.
    Active := true;
    First;
    while not eof do Delete;
  end;
end;

procedure TfrmARPayments.FormCreate(Sender: TObject);
var
  x: integer;
begin
  qryARPmt.DatabaseName := strDatabaseName;
  tblARPmt.DatabaseName := strDatabaseName;
  tblARInvPmt.DatabaseName := strDatabaseName;
  qryARPmt.Active := true;
  //tblARPmt.Active := true;   ...pospone until required (delete).
  //tblARInvPmt.Active := true;

  cboFindCustomer_CustomerIDs := TStringList.create;   //Create a TStringList to store CustomerIDs for the "find" combobox.
  cboFindCustomer_Load(dmLookUps.tblCustomer, cboFindCustomer);   //Populate "find" combobox.

  if FontFactor <> 1 then begin   //If using large fonts, resize grid columns.
    intClientWidth := Trunc(20*FontFactor) + DBGrid1.Columns.Count - 1;   //Scrollbar + grid lines.
    for x := 0 to DBGrid1.Columns.Count - 1 do begin
      DBGrid1.Columns[x].width := Trunc(DBGrid1.Columns[x].width*FontFactor);
      intClientWidth := intClientWidth + DBGrid1.Columns[x].width;
    end;
    ClientWidth := intClientWidth;
  end;
  intClientHeight := ClientHeight;   //Store form size.
  intClientWidth := ClientWidth;
end;

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

procedure TfrmARPayments.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    mnuEditClick(Sender);
    Key := #0;   //Cancel Enter key.
  end;
end;

procedure TfrmARPayments.FormShow(Sender: TObject);
begin
  cboFindCustomer.ItemIndex := 0;   //Reset selected item to 1st (so down arrow scrolls from start).
  cboFindCustomer.text := '<Bill-to name>';   //Clear selection.
  editFindCustomer.text := '<Bill-to no.>';
  editFindCheque.text := '<Cheque no.>';
  editFindCustomer.setfocus;
  editFindCustomer.SelectAll;
  qryARPmt.First;   //Reset grid to start at 1st record.
  if mnuFilter.checked = true then caption := 'AR Payments (Filtered)'
  else                             caption := 'AR Payments';
end;

procedure TfrmARPayments.mnuNewClick(Sender: TObject);
begin
  screen.cursor := crHourglass;
  application.createform (TfrmARPayment,frmARPayment);
  frmARPayment.tblARPmt.Insert;
  frmARPayment.Show;
  screen.cursor := crDefault;
end;

procedure TfrmARPayments.mnuEditClick(Sender: TObject);
begin
  if qryARPmtPaymentID.AsVariant = null then mnuNewClick(sender)   //Can happen if no payments yet.
  else begin
    screen.cursor := crHourglass;
    application.createform (TfrmARPayment,frmARPayment);
    frmARPayment.tblARPmt.Locate('PaymentID', qryARPmtPaymentID.value, []);
    frmARPayment.Show;
    screen.cursor := crDefault;
  end;
end;

procedure TfrmARPayments.mnuDeleteClick(Sender: TObject);
var
  Bookmark: TBookmark;
begin
  tblARPmt.Active := true;
  tblARPmt.Database.TransIsolation := tiDirtyRead;
  if tblARPmt.Locate('PaymentID', qryARPmtPaymentID.value, []) = true then begin
    tblARPmt.delete;   //Delete from table as query is read-only.
    tblARPmt.Database.ApplyUpdates([tblARInvPmt, tblARPmt]);
    DbiSaveChanges(tblARInvPmt.handle);
    DbiSaveChanges(tblARPmt.handle);
    Bookmark := qryARPmt.GetBookmark;
    with qryARPmt do begin close; open; end;   //Refresh.
    try qryARPmt.GotoBookmark(Bookmark); except; end;
    qryARPmt.FreeBookmark(BookMark);
    if qryARPmtPaymentID.AsVariant = null then qryARPmt.first;   //If deleting last record, prevent blank record with focus after last record (move to 1st record as per other grids).
  end;
end;

procedure TfrmARPayments.mnuExitClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmARPayments.qryARPmtCalcFields(DataSet: TDataSet);
begin
  if qryARPmtGLPeriod.AsVariant <> null then qryARPmtPeriodppyyyy.value := qryARPmtGLPeriod.AsString + '/' + qryARPmtGLYear.AsString
  else qryARPmtPeriodppyyyy.value := '';
end;

procedure TfrmARPayments.mnuSortDateAscendingClick(Sender: TObject);
begin

⌨️ 快捷键说明

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