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

📄 arinvoicesform.pas

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

interface

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

type
  TfrmARInvoices = class(TForm)
    Panel1: TPanel;
    MainMenu1: TMainMenu;
    tblARInv: TTable;
    dsARInv: TDataSource;
    DBGrid1: TDBGrid;
    cboFindCustomer: TComboBox;
    Label1: TLabel;
    mnuFile: TMenuItem;
    mnuView: TMenuItem;
    mnuHelp: TMenuItem;
    mnuFilter: TMenuItem;
    mnuSortBy: TMenuItem;
    N1: TMenuItem;
    mnuRefresh: TMenuItem;
    mnuARInvoicesHelp: TMenuItem;
    mnuPrint: TMenuItem;
    N2: TMenuItem;
    mnuExit: TMenuItem;
    Bevel1: TBevel;
    mnuSortAmount: TMenuItem;
    mnuSortDate: TMenuItem;
    mnuSortOwing: TMenuItem;
    mnuSortName: TMenuItem;
    mnuBillTo: TMenuItem;
    mnuPayments: TMenuItem;
    N4: TMenuItem;
    btnNew: TSpeedButton;
    btnEdit: TSpeedButton;
    btnDelete: TSpeedButton;
    editFindCustomer: TEdit;
    mnuRecords: TMenuItem;
    mnuNew: TMenuItem;
    mnuEdit: TMenuItem;
    mnuDelete: TMenuItem;
    qryARInv: TQuery;
    tblCustomer: TTable;
    tblARInvDet: TTable;
    tblARInvPmt: TTable;
    mnuSortDateAscending: TMenuItem;
    mnuSortDateDescending: TMenuItem;
    mnuSortBillToNo: TMenuItem;
    mnuSortInvoiceno: TMenuItem;
    PopupMenu1: TPopupMenu;
    popPayments: TMenuItem;
    popBillTo: TMenuItem;
    editFindInvoice: TEdit;
    N3: TMenuItem;
    mnuPost: TMenuItem;
    popNew: TMenuItem;
    popEdit: TMenuItem;
    popDelete: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    popPhone: TMenuItem;
    qryARInvARInvoiceID: TIntegerField;
    qryARInvCustomerID: TIntegerField;
    qryARInvBillToID: TIntegerField;
    qryARInvInvoiceNo: TStringField;
    qryARInvInvoiceDate: TDateField;
    qryARInvInvoiceAmount: TCurrencyField;
    qryARInvOwing: TCurrencyField;
    qryARInvGLPeriod: TSmallintField;
    qryARInvGLYear: TSmallintField;
    qryARInvPosted: TBooleanField;
    qryARInvCurrencyID: TIntegerField;
    qryARInvPhone: TStringField;
    tblARInvARInvoiceID: TIntegerField;
    tblARInvDetARInvoiceID: TIntegerField;
    tblARInvPmtARInvoiceID: TIntegerField;
    tblCustomerCustomerID: TAutoIncField;
    tblCustomerCustomerName: TStringField;
    mnuShipTo: TMenuItem;
    popShipTo: TMenuItem;
    qryARInvBillToNo: TStringField;
    qryARInvBillToName: TStringField;
    qryARInvPeriodppyyyy: TStringField;
    qryARInvAge: TIntegerField;
    qryARInvPrinted: TBooleanField;
    mnuPrintInvoices: TMenuItem;
    mnuOutstanding: TMenuItem;
    popEMail: TMenuItem;
    qryARInvEMail: TStringField;
    mnuPrintInvoice: TMenuItem;
    popPrintInvoice: TMenuItem;
    N7: TMenuItem;
    btnFilter: TSpeedButton;
    procedure mnuRefreshClick(Sender: TObject);
    procedure tblARInvBeforeDelete(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
    procedure Panel1DblClick(Sender: TObject);
    procedure cboFindCustomerDropDown(Sender: TObject);
    procedure cboFindCustomerKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cboFindCustomerClick(Sender: TObject);
    procedure cboFindCustomerKeyPress(Sender: TObject; var Key: Char);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure editFindCustomerKeyPress(Sender: TObject; var Key: Char);
    procedure mnuNewClick(Sender: TObject);
    procedure mnuEditClick(Sender: TObject);
    procedure mnuDeleteClick(Sender: TObject);
    procedure mnuExitClick(Sender: TObject);
    procedure qryARInvCalcFields(DataSet: TDataSet);
    procedure mnuSortDateAscendingClick(Sender: TObject);
    procedure mnuSortDateDescendingClick(Sender: TObject);
    procedure mnuSortNameClick(Sender: TObject);
    procedure mnuSortAmountClick(Sender: TObject);
    procedure mnuSortOwingClick(Sender: TObject);
    procedure mnuSortBillToNoClick(Sender: TObject);
    procedure mnuSortInvoicenoClick(Sender: TObject);
    procedure mnuBillToClick(Sender: TObject);
    procedure editFindInvoiceKeyPress(Sender: TObject; var Key: Char);
    procedure FormResize(Sender: TObject);
    procedure mnuPostClick(Sender: TObject);
    procedure mnuFilterClick(Sender: TObject);
    procedure qryARInvFilterRecord(DataSet: TDataSet; var Accept: Boolean);
    procedure mnuPrintClick(Sender: TObject);
    procedure mnuPaymentsClick(Sender: TObject);
    procedure popPhoneClick(Sender: TObject);
    procedure mnuShipToClick(Sender: TObject);
    procedure mnuPrintInvoicesClick(Sender: TObject);
    procedure mnuOutstandingClick(Sender: TObject);
    procedure mnuARInvoicesHelpClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure popEMailClick(Sender: TObject);
    procedure dsARInvDataChange(Sender: TObject; Field: TField);
    procedure mnuPrintInvoiceClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmARInvoices: TfrmARInvoices;

implementation

uses BS1Form, ARInvoicesFilterForm, ARInvoiceForm, CustomerForm, DialerForm,
  LookUpsData, ARInvoicesReport, ARInvoicesPostForm, ARInvoicesPrintForm,
  ARInvoicePaymentsForm, JVsPostForm;
//ARInvoicesPostForm, ARInvoicesReport

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;
  frmARInvoices_cboFindCustomer_RequeryRequired := false;
end;

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

procedure TfrmARInvoices.tblARInvBeforeDelete(DataSet: TDataSet);
begin
  tblARInvPmt.Active := true;
  if tblARInvPmt.RecordCount >0 then raise(Exception.Create('Unable to delete invoice ' + '''' + qryARInvInvoiceNo.AsString + '''' + '...' + #13 + 'Payment(s) exist'));
  if qryARInvPosted.value = true then raise(Exception.Create('Unable to delete invoice ' + '''' + qryARInvInvoiceNo.AsString + '''' + '...' + #13 + 'It has already been posted'));
  if MessageDlg('Delete invoice ' + '''' + qryARInvInvoiceNo.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;
  
  tblARInv.edit;   //Put lock on master table.
  with tblARInvDet do begin   //Delete detail for this invoice.
    Active := true;
    First;
    while not eof do Delete;
  end;
end;

procedure TfrmARInvoices.FormCreate(Sender: TObject);
var
  x: integer;
begin
  qryARInv.DatabaseName := strDatabaseName;
  tblARInv.DatabaseName := strDatabaseName;
  tblARInvDet.DatabaseName := strDatabaseName;
  tblARInvPmt.DatabaseName := strDatabaseName;
  tblCustomer.DatabaseName := strDatabaseName;
  qryARInv.Active := true;
  //tblARInv.Active := true;   ...pospone until required (delete).
  //tblARInvDet.Active := true;
  //tblARInvPmt.Active := true;
  //tblCustomer.Active := true;   //Data Module used instead.

  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.
    intClientWidth := Trunc(20*FontFactor) + 7;   //Scrollbar + grid lines.
    //for x := 0 to DBGrid1.Columns.Count - 1 do begin
    for x := 0 to 7 do begin   //Only 8 columns shown (0 to 7).
      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 TfrmARInvoices.Panel1DblClick(Sender: TObject);
begin
  ClientHeight := intClientHeight;   //Resize form.
  ClientWidth := intClientWidth;
end;

procedure TfrmARInvoices.cboFindCustomerDropDown(Sender: TObject);
begin
  if frmARInvoices_cboFindCustomer_RequeryRequired = true then cboFindCustomer_Load(dmLookUps.tblCustomer, cboFindCustomer);   //Populate "find" combobox.
end;

procedure TfrmARInvoices.cboFindCustomerKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if frmARInvoices_cboFindCustomer_RequeryRequired = true then cboFindCustomer_Load(dmLookUps.tblCustomer, cboFindCustomer);   //Populate "find" combobox.
end;

procedure TfrmARInvoices.cboFindCustomerClick(Sender: TObject);
begin
  if cboFindCustomer.Text = '' then exit;
  editFindCustomer.text := '';
  if cboFindCustomer.Items.IndexOf(cboFindCustomer.Text) < 0 then raise(Exception.Create('Choose an item from the list'));
end;

procedure TfrmARInvoices.cboFindCustomerKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    Key := #0;   //Cancel Enter key.
    if (cboFindCustomer.Text = '') or (cboFindCustomer.Text = '<Bill-to name>') then begin
      Perform(WM_NEXTDLGCTL, 0, 0);   //Advance to next control.
      exit;
    end;
    cboFindCustomerClick(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 TfrmARInvoices.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    mnuEditClick(Sender);
    Key := #0;   //Cancel Enter key.
  end;
end;

procedure TfrmARInvoices.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.>';
  editFindInvoice.text := '<Invoice no.>';
  editFindCustomer.setfocus;
  editFindCustomer.SelectAll;
  qryARInv.First;   //Reset grid to start at 1st record.
  if mnuOutstanding.checked = true then begin
    if mnuFilter.checked = true then caption := 'AR Invoices (Outstanding, Filtered)'
    else                             caption := 'AR Invoices (Outstanding)';
  end else begin
    if mnuFilter.checked = true then caption := 'AR Invoices (Filtered)'
    else                             caption := 'AR Invoices';
  end;
end;

procedure TfrmARInvoices.editFindCustomerKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    Key := #0;   //Cancel Enter key.
    if (editFindCustomer.Text = '') or (editFindCustomer.Text = '<Bill-to no.>') then begin
      Perform(WM_NEXTDLGCTL, 0, 0);   //Advance to next control.
      exit;
    end;
    cboFindCustomer.text := '';
    editFindInvoice.SetFocus;
  end;
end;

procedure TfrmARInvoices.mnuNewClick(Sender: TObject);
begin
  screen.cursor := crHourglass;
  application.createform (TfrmARInvoice,frmARInvoice);
  frmARInvoice.tblARInv.Insert;
  frmARInvoice.Show;
  screen.cursor := crDefault;
end;

procedure TfrmARInvoices.mnuEditClick(Sender: TObject);
begin
  if qryARInvARInvoiceID.AsVariant = null then mnuNewClick(sender)   //Can happen if no invoices yet.
  else begin
    screen.cursor := crHourglass;
    application.createform (TfrmARInvoice,frmARInvoice);
    frmARInvoice.tblARInv.Locate('ARInvoiceID', qryARInvARInvoiceID.value, []);
    frmARInvoice.GetBillToData;
    frmARInvoice.Show;
    screen.cursor := crDefault;
  end;
end;

procedure TfrmARInvoices.mnuDeleteClick(Sender: TObject);
var
  Bookmark: TBookmark;
begin

⌨️ 快捷键说明

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