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

📄 apchequeform.pas

📁 功能全面的商业财会系统源码,清晰,很有参考价值.扩展性强.
💻 PAS
📖 第 1 页 / 共 3 页
字号:
begin   //Exit grid if leaving 1st column on a new record & no data.  Actually if leaving column 1 (to another cell in the grid), and target cell is a record with no Seq (new record) or GLAmount.
  if (TDBGrid(ActiveControl).SelectedIndex = 0) and (tblAPInvChqAPInvoiceID.AsVariant = Null) and (tblAPInvChqPaymentAmount.AsVariant = Null) and (tblAPInvChq.RecordCount > 0) then btnOK.setfocus;
end;

procedure TfrmAPCheque.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (key = VK_Next) then begin   //PageDown
    key := 0;
    if not (ActiveControl is TDBGrid) then begin   //Move to 1st record on grid.
      DBGrid1.Setfocus;
      tblAPInvChq.First;
      DBGrid1.SelectedIndex := 0;
    end else begin
      tblAPInvChq.append;   //Move to new record on grid.
      DBGrid1.SelectedIndex := 0;
    end;  
  end;
end;

procedure TfrmAPCheque.DBGrid1Exit(Sender: TObject);
begin
  tblAPInvChq.First;
  DBGrid1.SelectedIndex := 0;
end;

procedure TfrmAPCheque.DBGrid1Enter(Sender: TObject);
begin
  DBGrid1.SelectedIndex := 0;   //Fix problem caused when ColExit event causes exit from grid with pending Enter setting selected index to 2nd column.
end;

procedure TfrmAPCheque.tblVendorCalcFields(DataSet: TDataSet);
begin
  tblVendorAddress.value := tblVendorAddressLine1.value;
  if tblVendorAddressLine2.value <> '' then tblVendorAddress.value := tblVendorAddress.value + ', ' + tblVendorAddressLine2.value;
  if tblVendorCity.value <> '' then tblVendorAddress.value := tblVendorAddress.value + ', ' + tblVendorCity.value;
  if tblVendorStateProv.value <> '' then tblVendorAddress.value := tblVendorAddress.value + ', ' + tblVendorStateProv.value;
  if tblVendorZipCode.value <> '' then tblVendorAddress.value := tblVendorAddress.value + ', ' + tblVendorZipCode.value;
  if tblVendorCountry.value <> '' then tblVendorAddress.value := tblVendorAddress.value + ', ' + tblVendorCountry.value;

  tblVendorTerms.AsString := 'Terms: ';
  if tblVendorDiscPC.value >0 then
    if tblVendorDiscDays.AsVariant = null then tblVendorTerms.AsString := tblVendorTerms.AsString + tblVendorDiscPC.AsString + '% ' + '0' + '   '
    else                                       tblVendorTerms.AsString := tblVendorTerms.AsString + tblVendorDiscPC.AsString + '% ' + tblVendorDiscDays.AsString + '   ';
  if tblVendorNetDays.AsVariant = null then tblVendorTerms.AsString := tblVendorTerms.AsString + 'Net 0'
  else                                      tblVendorTerms.AsString := tblVendorTerms.AsString + 'Net ' + tblVendorNetDays.AsString;
  if tblVendorDelayDays.AsVariant = null then tblVendorTerms.AsString := tblVendorTerms.AsString + '   Delay 0'
  else                                        tblVendorTerms.AsString := tblVendorTerms.AsString + '   Delay ' + tblVendorDelayDays.AsString;
end;

procedure TfrmAPCheque.editChequeDateKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = ^J then begin   //Ctrl+Enter show calendar.
    btnChequeDateClick(sender);
    Key := #0;
  end else if Key = '+' then begin   //Increase/decrease date via +/- keys.
    tblAPCheq.Edit;
    if editChequeDate.field.AsVariant = null then editChequeDate.field.AsDateTime := Date;
    editChequeDate.field.AsDateTime := editChequeDate.field.AsDateTime + 1;
    key := #0;
  end else if Key = '-' then begin
    tblAPCheq.Edit;
    if editChequeDate.field.AsVariant = null then editChequeDate.field.AsDateTime := Date;
    editChequeDate.field.AsDateTime := editChequeDate.field.AsDateTime - 1;
    key := #0;
  end;
end;

procedure TfrmAPCheque.dsAPCheqDataChange(Sender: TObject; Field: TField);
begin
  //if (tblAPCheq.state = dsInsert) and (tblAPCheqChequeNo.Value = 0) then self.Caption := 'New Cheque'
  //else self.Caption := 'Cheque ' + tblAPCheqChequeNo.AsString;
  ///if (tblAPCheq.state = dsInsert) and (tblAPCheqVendorID.Value = 0) and (tblAPCheqChequeNo.Value = 0) then self.Caption := 'New Cheque'
  ///else if tblAPCheqChequeNo.Value > 0 then self.Caption := 'Cheque ' + tblAPCheqChequeNo.AsString
  ///else                                     self.Caption := 'Cheque (Not Printed)';
  if (tblAPCheq.state = dsInsert) and (tblAPCheqVendorID.Value = 0) and (tblAPCheqChequeNo.AsVariant = null) then self.Caption := 'New Cheque'   //Cheque no. 0 used for clearing out debits and credits.
  else if tblAPCheqChequeNo.AsVariant <> null then self.Caption := 'Cheque ' + tblAPCheqChequeNo.AsString
  else                                             self.Caption := 'Cheque (Not Printed)';

  editVendorNo.text := tblAPCheqVendorNo.value;
  editVendorNo.ReadOnly := tblAPCheqPosted.value;
  lblPosted.visible := tblAPCheqPosted.value;
  lblReconciled.visible := tblAPCheqReconciled.value;
  if tblAPCheqPosted.value = true then DBGrid1.Options := [dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit]   //If posted: set dgAlwaysShowEditor to false.
  else DBGrid1.Options := [dgEditing,dgAlwaysShowEditor,dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit];

  if tblAPCheqVendorID.AsVariant = null then begin
    txtAddress.visible := false;
    txtTerms.visible := false;
  end else begin
    txtAddress.visible := true;
    txtTerms.visible := true;
  end;
end;

procedure TfrmAPCheque.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (shift = [ssShift]) and (key = VK_Tab) and (DBGrid1.SelectedIndex = 0) then begin
    if (tblAPInvChq.bof = true) or (tblAPInvChq.Recno = 1) then chkVoid.setfocus;
  end;
end;

procedure TfrmAPCheque.tblAPInvChqNewRecord(DataSet: TDataSet);
begin
  tblAPInvChqChequeID.value := tblAPCheqChequeID.value;
end;

procedure TfrmAPCheque.tblAPCheqNewRecord(DataSet: TDataSet);
var
  Year, Month, Day: word;
begin
  with tblAPChqCtl do begin
      Open;
      try
        Edit;
        tblAPCheqChequeID.Value := tblAPChqCtlNextChequeID.Value;
        tblAPChqCtlNextChequeID.Value := tblAPChqCtlNextChequeID.Value + 1;
        Post;
      finally
        DbiSaveChanges(tblAPChqCtl.handle);
        Close;
      end;
    end;
  tblAPCheqChequeDate.value := Date;
  tblAPCheqReconciled.value := false;
  tblAPCheqPosted.value := false;
  tblAPCheqVoid.value := false;
  DecodeDate(Date, Year, Month, Day);
  if frmBS1.tblCompanyDefaultPeriodPP.value > 0 then tblAPCheqGLPeriod.value := frmBS1.tblCompanyDefaultPeriodPP.value
  else                                               tblAPCheqGLPeriod.value := Month;
  if frmBS1.tblCompanyDefaultPeriodYYYY.value > 0 then tblAPCheqGLYear.value := frmBS1.tblCompanyDefaultPeriodYYYY.value
  else                                                 tblAPCheqGLYear.value := Year;
end;

procedure TfrmAPCheque.tblAPCheqUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
  if E is EDBEngineError then
    with EDBEngineError(E) do
    begin
      //if Errors[ErrorCount - 1].ErrorCode = 9729 then begin   //Key violation (key already exists).
        //with editChequeNo do begin Show; SetFocus; end;
        //Application.MessageBox(PChar('Cheque no. already exists.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);   //Suppressed: cheque no. isn't unique.
        //UpdateAction := uaAbort;
      //end else begin
        Application.MessageBox(PChar(IntToStr(Errors[ErrorCount - 1].ErrorCode) + ': ' + E.Message + '.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);
        UpdateAction := uaAbort;
      //end;
    end;
end;

procedure TfrmAPCheque.tblAPInvChqUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
  if (tblAPCheq.UpdatesPending = true) then UpdateAction := uaAbort   //Master record not posted yet (had error).
  else if E is EDBEngineError then
    with EDBEngineError(E) do begin
      if (Errors[ErrorCount - 1].ErrorCode = 9729) then begin   //Key violation (key already exists).
        Application.MessageBox(PChar('An invoice is specified more than once on this cheque.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);
        UpdateAction := uaAbort;
      end else if (Errors[ErrorCount - 1].ErrorCode = 9733) then begin    //Master record missing.
        Application.MessageBox(PChar('Invoice does not exist.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);
        UpdateAction := uaAbort;
      end else begin
        Application.MessageBox(PChar(IntToStr(Errors[ErrorCount - 1].ErrorCode) + ': ' + E.Message + '.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);
        UpdateAction := uaSkip;
      end;
    end;
end;

procedure TfrmAPCheque.tblAPCheqBeforeEdit(DataSet: TDataSet);
begin
  if (tblAPCheqPosted.value = true) then raise(EAbort.create(''));  //Silent Exception: "abort;" replaced by "raise etc" since abort conflicts with BDE (required by DbiSaveChanges).   //Make tables read-only without having to reset "active".

  qryLastDetailLineNo.close;
  qryLastDetailLineNo.open;
  with qryLastDetailLineNo.Fields[0] do
    if IsNull then NextDetailLineNo := 1
    else NextDetailLineNo := AsInteger + 1;

  APInvoiceIDs.Clear;
  Seqs.Clear;
  if NextDetailLineNo > 1 then begin
    tblAPInvChq2.Active := true;
    tblAPInvChq2.First;
    while not tblAPInvChq2.EOF do begin
      APInvoiceIDs.Add(tblAPInvChq2['APInvoiceID']);
      Seqs.Add(tblAPInvChq2['Seq']);
      tblAPInvChq2.Next;
    end;
  end;
end;

procedure TfrmAPCheque.tblAPInvChqBeforeEdit(DataSet: TDataSet);
begin
  tblAPCheq.edit;   //Put lock on master table (if not already in dsInsert or dsEdit state).
  OldPaymentAmount := tblAPInvChqPaymentAmount.value;
end;

procedure TfrmAPCheque.tblAPInvChqBeforeInsert(DataSet: TDataSet);
begin
  tblAPCheq.edit;   //Put lock on master table (if not already in dsInsert or dsEdit state) & get next detail line no (if not already got).
  OldPaymentAmount := 0;
end;

procedure TfrmAPCheque.tblAPInvChqBeforeDelete(DataSet: TDataSet);
begin
  tblAPCheq.edit;   //Put lock on master table (if not already in dsInsert or dsEdit state).
  if not (tblAPInvChq.state in [dsInsert, dsEdit]) then OldPaymentAmount := tblAPInvChqPaymentAmount.value;
  OldSeq := tblAPInvChqSeq.value;
end;

procedure TfrmAPCheque.tblAPCheqGLYearGetText(Sender: TField;
  var Text: string; DisplayText: Boolean);
begin
  if DisplayText = false then Text := Copy(tblAPCheqGLYear.AsString,3,2)   //If editing, show last 2 digits of year.
  else Text := tblAPCheqGLYear.AsString;
end;

procedure TfrmAPCheque.tblAPCheqGLYearSetText(Sender: TField;
  const Text: string);
begin
  if Text = '' then tblAPCheqGLYear.AsVariant := null else begin   //Convert 2 digit year to 4.
    if (StrToInt(Text) < 0) or (StrToInt(Text) > 99) then raise(exception.create('Period invalid...' + #13 + 'Enter year as 2 digits'));
    if StrToInt(Text) < 50 then tblAPCheqGLYear.value := StrToInt(Text) + 2000
    else tblAPCheqGLYear.value := StrToInt(Text) + 1900;
  end;
end;

procedure TfrmAPCheque.tblAPCheqBeforePost(DataSet: TDataSet);
var
  GLNet: currency;
  JVGLPeriodYYYYPP, EPeriodFromYYYYPP, EPeriodToYYYYPP, WPeriodFromYYYYPP, WPeriodToYYYYPP: integer;
begin
  if tblAPCheqPosted.value = false then begin
    if tblAPCheqVoid.value = true then begin
      if tblAPInvChq.RecordCount > 0 then begin
        with DBGrid1 do begin Show; SetFocus; end;
        raise(exception.create('Invoices must not be entered if "Void" selected'));
      end;
      if tblAPCheqVendorID.AsVariant <> null then begin
        with editVendorNo do begin Show; SetFocus; end;
        raise(exception.create('Vendor must not be entered if "Void" selected'));
      end;
      if tblAPCheqChequeNo.value = 0 then begin
        with editChequeNo do begin Show; SetFocus; end;
        raise(exception.create('Cheque no. must be entered if "Void" selected'));
      end;
      if tblAPCheqChequeDate.AsVariant <> null then begin
        with editChequeDate do begin Show; SetFocus; end;
        raise(exception.create('Cheque Date must not be entered if "Void" selected'));
      end;
      if (tblAPCheqGLYear.AsVariant <> null) or (tblAPCheqGLPeriod.AsVariant <> null) then begin
        with editGLPeriod do begin Show; SetFocus; end;
        raise(exception.create('GL Period must not be entered if "Void" selected'));
      end;
    end else begin
      if tblAPCheqVendorID.AsVariant = null then begin
        with editVendorNo do begin Show; SetFocus; end;
        raise(exception.create('Field ' + '''Vendor''' + ' must have a value'));
      end;
      dmLookUps.tblBank.Active := true;
      if dmLookUps.tblBank.Locate('BankID', tblAPCheqBankID.value, []) <> true then begin
        with cboBank do begin Show; SetFocus; end;
        raise(exception.create('Bank no longer exists'));   //Deleted by another user since this user selected.
      end;
      if (tblAPCheqBankID.AsVariant <> null) and (tblAPCheqCurrencyIDofBank.value <> tblAPCheqCurrencyIDofVendor.value) then begin
        cboBank.SetFocus;
        raise(exception.create('Bank must be same currency as vendor'));
      end;
      if tblAPCheqChequeDate.AsVariant = null then begin
        with editChequeDate do begin Show; SetFocus; end;
        raise(exception.create('Field ' + '''Cheque Date''' + ' must have a value'));
      end;
      JVGLPeriodYYYYPP := (tblAPCheqGLYear.value * 100) + tblAPCheqGLPeriod.value;
      EPeriodFromYYYYPP := (frmBS1.tblCompanyEPeriodFromYYYY.value * 100) + frmBS1.tblCompanyEPeriodFromPP.value;
      EPeriodToYYYYPP := (frmBS1.tblCompanyEPeriodToYYYY.value * 100) + frmBS1.tblCompanyEPeriodToPP.value;
      WPeriodFromYYYYPP := (frmBS1.tblCompanyWPeriodFromYYYY.value * 100) + frmBS1.tblCompanyWPeriodFromPP.value;
      WPeriodToYYYYPP := (frmBS1.tblCompanyWPeriodToYYYY.value * 100) + frmBS1.tblCompanyWPeriodToPP.value;
      if frmBS1.tblCompanyFiscalYear.value = 0 then begin
        with editGLPeriod do begin Show; SetFocus; end;
        raise(exception.create('Current fiscal year is not yet defined...' + #13 + 'See "Your Company"'));
      end;
      if tblAPCheqGLYear.AsVariant = null then begin
        with editGLYear do begin Show; SetFocus; end;
        raise(exception.create('Field ' + '''' + 'Year of Period' + '''' + ' must have a value'));
      end;
      if tblAPCheqGLYear.value < frmBS1.tblCompanyFiscalYear.value then begin

⌨️ 快捷键说明

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