📄 apinvoiceform.pas
字号:
procedure TfrmAPInvoice.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin //Enter key: advance to next control.
if not (ActiveControl is TDBGrid) and (ActiveControl.ClassType <> TDBMemo) and (ActiveControl.ClassType <> TDBLookupCombobox) then begin
Key := #0;
if (ActiveControl.name = 'editVendorNo') and (editVendorNo.text <> '') then editInvoiceNo.setfocus
else 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 else if (ActiveControl is TDBGrid) then begin
key := #0;
//Exit grid if on a new record & no data... replaced by ColExit event (as this event can't see whether data is being entered in the current cell).
//if (TDBGrid(ActiveControl).selectedindex = 1) and (tblAPInvDetSeq.AsVariant = Null) and (tblAPInvDetGLAmount.AsVariant = Null) then Perform(WM_NEXTDLGCTL, 0, 0)
//else}
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount - 1) then //Increment the field.
//if selectedindex < 1 then //Increment the field + skip AccountName.
selectedindex := selectedindex + 1
else begin //Move to next record.
selectedindex := 0;
tblAPInvDet.next;
if tblAPInvDet.eof = true then tblAPInvDet.append;
end;
end;
end;
end;
procedure TfrmAPInvoice.DBGrid1ColExit(Sender: TObject);
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 (tblAPInvDetSeq.AsVariant = Null) and (tblAPInvDetGLAmount.AsVariant = Null) and (tblAPInvDet.RecordCount > 0) then btnOK.setfocus;
end;
procedure TfrmAPInvoice.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;
tblAPInvDet.First;
DBGrid1.SelectedIndex := 0;
end else begin
tblAPInvDet.append; //Move to new record on grid.
DBGrid1.SelectedIndex := 0;
end;
end;
end;
procedure TfrmAPInvoice.DBGrid1Exit(Sender: TObject);
begin
DBGrid1.Options := [dgEditing,dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit]; //Toggle dgAlwaysShowEditor to prevent 1st field from being left-justified if always dgAlwaysShowEditor.
tblAPInvDet.First;
DBGrid1.SelectedIndex := 0;
end;
procedure TfrmAPInvoice.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 TfrmAPInvoice.dsAPInvUpdateData(Sender: TObject);
begin
if tblAPInvVendorID.AsVariant = null then begin
with editVendorNo do begin Show; SetFocus; end;
raise(exception.create('Field ' + '''Vendor''' + ' must have a value'));
end;
end;
procedure TfrmAPInvoice.editInvoiceDateKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = ^J then begin //Ctrl+Enter show calendar.
btnInvoiceDateClick(sender);
Key := #0;
end else if Key = '+' then begin //Increase/decrease date via +/- keys.
tblAPInv.Edit;
if editInvoiceDate.field.AsVariant = null then editInvoiceDate.field.AsDateTime := Date;
editInvoiceDate.field.AsDateTime := editInvoiceDate.field.AsDateTime + 1;
key := #0;
end else if Key = '-' then begin
tblAPInv.Edit;
if editInvoiceDate.field.AsVariant = null then editInvoiceDate.field.AsDateTime := Date;
editInvoiceDate.field.AsDateTime := editInvoiceDate.field.AsDateTime - 1;
key := #0;
end;
end;
procedure TfrmAPInvoice.tblAPInvInvoiceDateChange(Sender: TField);
begin
if tblAPInvVendorID.AsVariant <> null then begin
tblAPInvDueDate.AsDateTime := tblAPInvInvoiceDate.AsDateTime + tblAPInvDelayDays.value;
if tblAPInvDiscDays.value > 0 then tblAPInvDiscountDate.AsDateTime := tblAPInvInvoiceDate.AsDateTime + tblAPInvDiscDays.value;
end;
end;
procedure TfrmAPInvoice.editDueDateKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = ^J then begin //Ctrl+Enter show calendar.
btnDueDateClick(sender);
Key := #0;
end else if Key = '+' then begin //Increase/decrease date via +/- keys.
tblAPInv.Edit;
if editDueDate.field.AsVariant = null then editDueDate.field.AsDateTime := Date;
editDueDate.field.AsDateTime := editDueDate.field.AsDateTime + 1;
key := #0;
end else if Key = '-' then begin
tblAPInv.Edit;
if editDueDate.field.AsVariant = null then editDueDate.field.AsDateTime := Date;
editDueDate.field.AsDateTime := editDueDate.field.AsDateTime - 1;
key := #0;
end;
end;
procedure TfrmAPInvoice.editDiscountDateKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = ^J then begin //Ctrl+Enter show calendar.
btnDiscountDateClick(sender);
Key := #0;
end else if Key = '+' then begin //Increase/decrease date via +/- keys.
tblAPInv.Edit;
if editDiscountDate.field.AsVariant = null then editDiscountDate.field.AsDateTime := Date;
editDiscountDate.field.AsDateTime := editDiscountDate.field.AsDateTime + 1;
key := #0;
end else if Key = '-' then begin
tblAPInv.Edit;
if editDiscountDate.field.AsVariant = null then editDiscountDate.field.AsDateTime := Date;
editDiscountDate.field.AsDateTime := editDiscountDate.field.AsDateTime - 1;
key := #0;
end;
end;
procedure TfrmAPInvoice.tblAPInvVendorIDChange(Sender: TField);
begin
if (tblAPInvVendorID.AsVariant <> null) then begin
txtAddress.Visible := true;
tblAPInvDescription.value := dmLookUps.tblVendorDefaultInvDescription.value;
if dmLookUps.tblVendorDiscPC.value > 0 then tblAPInvDiscPC.value := dmLookUps.tblVendorDiscPC.value
else tblAPInvDiscPC.AsVariant := null;
tblAPInvDueDate.AsDateTime := tblAPInvInvoiceDate.AsDateTime + dmLookUps.tblVendorDelayDays.value;
if dmLookUps.tblVendorDiscDays.value > 0 then tblAPInvDiscountDate.AsDateTime := tblAPInvInvoiceDate.AsDateTime + dmLookUps.tblVendorDiscDays.value
else tblAPInvDiscountDate.AsVariant := null;
end else begin
txtAddress.Visible := false;
tblAPInvDescription.AsVariant := null;
tblAPInvDiscPC.AsVariant := null;
tblAPInvDiscountAmount.AsVariant := null;
tblAPInvDueDate.AsVariant := null;
tblAPInvDiscountDate.AsVariant := null;
tblAPInvDiscPC.AsVariant := null;
end;
end;
procedure TfrmAPInvoice.cboVendorKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_Delete then begin
tblAPInv.Edit;
tblAPInvVendorID.AsVariant := null;
end;
end;
procedure TfrmAPInvoice.dsAPInvDataChange(Sender: TObject; Field: TField);
begin
if (tblAPInv.state = dsInsert) and (tblAPInvInvoiceNo.Value = '') then self.Caption := 'New Invoice'
else self.Caption := 'Invoice ' + tblAPInvInvoiceNo.Value;
editVendorNo.text := tblAPInvVendorNo.value;
editVendorNo.ReadOnly := tblAPInvPosted.value;
lblPosted.visible := tblAPInvPosted.value;
if tblAPInvVendorID.AsVariant = null then begin
txtAddress.visible := false;
txtTerms.visible := false;
end else begin
txtAddress.visible := true;
txtTerms.visible := true;
end;
if (tblAPInvVendorID.AsVariant = null) or (tblAPInvDiscPC.AsVariant <> null) or (tblAPInvDiscDays.AsVariant <> null) then begin
//editDiscountDate.color := clWindow;
//editDiscountDate.enabled := true;
//btnDiscountDate.enabled := true;
editDiscPC.color := clWindow;
editDiscPC.enabled := true;
editDiscPC.ReadOnly := false;
editDiscPC.TabStop := true;
//editDiscountAmount.color := clWindow;
//editDiscountAmount.enabled := true;
end else begin
//editDiscountDate.color := clSilver;
//editDiscountDate.enabled := false;
//btnDiscountDate.enabled := false;
editDiscPC.color := clSilver;
editDiscPC.enabled := false;
editDiscPC.ReadOnly := true;
editDiscPC.TabStop := false;
//editDiscountAmount.color := clSilver;
//editDiscountAmount.enabled := false;
end;
end;
procedure TfrmAPInvoice.tblAPInvInvoiceAmountChange(Sender: TField);
begin
tblAPInvOwing.AsCurrency := tblAPInvInvoiceAmount.value - tblAPInvPaidAmount.value;
if tblAPInvDiscountTaken.value = true then tblAPInvOwing.AsCurrency := tblAPInvOwing.value - tblAPInvDiscountAmount.value;
if (tblAPInvInvoiceAmount.value <> 0) and (tblAPInvDiscPC.value > 0) then tblAPInvDiscountAmount.AsCurrency := frmBS1.RoundIt(tblAPInvDiscPC.value * tblAPInvInvoiceAmount.value)/100
else if tblAPInvDiscPC.value > 0 then tblAPInvDiscountAmount.AsVariant := null; //If amount zero: reset discount amount to null if disc% present, otherwise leave keyed discount amount.
end;
procedure TfrmAPInvoice.tblAPInvDiscPCChange(Sender: TField);
begin
if (tblAPInvInvoiceAmount.value <> 0) and (tblAPInvDiscPC.value > 0) then tblAPInvDiscountAmount.AsCurrency := frmBS1.RoundIt(tblAPInvDiscPC.value * tblAPInvInvoiceAmount.value)/100
else tblAPInvDiscountAmount.AsVariant := null;
end;
procedure TfrmAPInvoice.editDiscountAmountKeyPress(Sender: TObject;
var Key: Char);
begin
if tblAPInvDiscPC.AsVariant <> null then tblAPInvDiscPC.AsVariant := null;
end;
procedure TfrmAPInvoice.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (shift = [ssShift]) and (key = VK_Tab) and (DBGrid1.SelectedIndex = 0) then begin
//if (tblAPInvDet.bof = true) or (tblAPInvDet.Recno = 1) then editDiscountAmount.setfocus;
if (tblAPInvDet.bof = true) or (tblAPInvDet.Recno = 1) then begin
if editDiscPC.enabled = true then editDiscPC.setfocus
else editDueDate.setfocus;
end;
end;
end;
procedure TfrmAPInvoice.tblAPInvDetNewRecord(DataSet: TDataSet);
begin
tblAPInvDetAPInvoiceID.value := tblAPInvAPInvoiceID.value;
end;
procedure TfrmAPInvoice.tblAPInvNewRecord(DataSet: TDataSet);
var
Year, Month, Day: word;
begin
with tblAPInvCtl do begin
Open;
try
Edit;
tblAPInvAPInvoiceID.Value := tblAPInvCtlNextInvoiceID.Value;
tblAPInvCtlNextInvoiceID.Value := tblAPInvCtlNextInvoiceID.Value + 1;
Post;
finally
DbiSaveChanges(tblAPInvCtl.handle);
Close;
end;
end;
tblAPInvInvoiceDate.value := Date;
tblAPInvPosted.value := false;
DecodeDate(Date, Year, Month, Day);
if frmBS1.tblCompanyDefaultPeriodPP.value > 0 then tblAPInvGLPeriod.value := frmBS1.tblCompanyDefaultPeriodPP.value
else tblAPInvGLPeriod.value := Month;
if frmBS1.tblCompanyDefaultPeriodYYYY.value > 0 then tblAPInvGLYear.value := frmBS1.tblCompanyDefaultPeriodYYYY.value
else tblAPInvGLYear.value := Year;
end;
procedure TfrmAPInvoice.tblAPInvUpdateError(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 editInvoiceNo do begin Show; SetFocus; end;
Application.MessageBox(PChar('Invoice no. already exists for this vendor.'), 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 := uaAbort;
end;
end;
end;
procedure TfrmAPInvoice.tblAPInvDetUpdateError(DataSet: TDataSet;
E: EDatabaseError; UpdateKind: TUpdateKind;
var UpdateAction: TUpdateAction);
begin
if (tblAPInv.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 = 9733) then begin //Master record missing.
Application.MessageBox(PChar('GL Account does not exist.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -