{*******************************************************} { } { Responsive Software http://www.responsive.co.nz } { } { Copyright (c) 2003-2006 Responsive Software Limited } { } {*******************************************************} unit Cashbooks; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BaseFrameUnit, StdCtrls, Grids, ComCtrls, ExtCtrls, DatabaseObjects; type TCashbooksFrame = class(TBaseFrame) Label1: TLabel; CashbookComboBox: TComboBox; Bevel1: TBevel; CashbookEntriesStringGrid: TStringGrid; StatusLabel: TLabel; PrintButton: TButton; BalanceLabel: TLabel; BalanceHeadingLabel: TLabel; PeriodHeadingLabel: TLabel; PeriodLabel: TLabel; HeadingLabel: TLabel; HeadingShape: TShape; SaveButton: TButton; CancelButton: TButton; EditButton: TButton; NewButton: TButton; DeleteButton: TButton; Label5: TLabel; DateDateTimePicker: TDateTimePicker; Label10: TLabel; DescriptionEdit: TEdit; Label13: TLabel; AmountEdit: TEdit; DebitCreditRadioGroup: TRadioGroup; DebitRadioButton: TRadioButton; CreditRadioButton: TRadioButton; Label2: TLabel; OtherAccountComboBox: TComboBox; OnStatementCheckBox: TCheckBox; AccountBalanceHeadingLabel: TLabel; AccountBalanceLabel: TLabel; StatementBalanceHeadingLabel: TLabel; StatementBalanceLabel: TLabel; AccountLabel: TLabel; AccountHeadingLabel: TLabel; FindButton: TButton; NextButton: TButton; EntryButton: TButton; procedure PrintButtonClick(Sender: TObject); procedure CashbookEntriesStringGridClick(Sender: TObject); procedure CashbookComboBoxSelect(Sender: TObject); procedure CashbookEntriesStringGridDblClick(Sender: TObject); procedure CashbookEntriesStringGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure CashbookEntriesStringGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure DeleteButtonClick(Sender: TObject); procedure NewButtonClick(Sender: TObject); procedure EditButtonClick(Sender: TObject); procedure CancelButtonClick(Sender: TObject); procedure SaveButtonClick(Sender: TObject); procedure DateDateTimePickerKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure DateDateTimePickerEnter(Sender: TObject); procedure DateDateTimePickerChange(Sender: TObject); procedure DescriptionEditChange(Sender: TObject); procedure AmountEditChange(Sender: TObject); procedure DebitRadioButtonKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure DebitRadioButtonClick(Sender: TObject); procedure CreditRadioButtonKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure CreditRadioButtonClick(Sender: TObject); procedure OtherAccountComboBoxSelect(Sender: TObject); procedure OnStatementCheckBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure OnStatementCheckBoxClick(Sender: TObject); procedure DateDateTimePickerCloseUp(Sender: TObject); procedure CashbookComboBoxKeyPress(Sender: TObject; var Key: Char); procedure DescriptionEditKeyPress(Sender: TObject; var Key: Char); procedure AmountEditKeyPress(Sender: TObject; var Key: Char); procedure OtherAccountComboBoxKeyPress(Sender: TObject; var Key: Char); procedure FindButtonClick(Sender: TObject); procedure NextButtonClick(Sender: TObject); procedure EntryButtonClick(Sender: TObject); private { Private declarations } EditMode : boolean; // true if editing entries, otherwise view mode assumed IgnoreChangeEvents : boolean; // set this to true when updating controls in code FirstChangeEvent : boolean; // used to workaround bug in TDateTimePicker // Cashbook refers to the cashbook currently being viewed // it is a copy and not the one in the global Cashbooks collection Cashbook : TCashbook; // Entry refers to the entry currently being viewed or edited CashbookEntry : TCashbookEntry; DefaultNewEntryDate : TDateTime; DefaultDebit : boolean; FindText : string; procedure SetCashbookEntry; procedure UpdateHeaderControls; procedure UpdateDetailControls; procedure UpdateCashbookEntriesStringGrid; procedure UpdateControlStates; procedure CancelChanges; procedure SaveChanges; procedure DeleteCashbookEntry; function NewCashbookEntry : boolean; procedure SwitchToCombinedEntry; public { Public declarations } procedure UpdateDisplay; procedure UpdateComboBoxes (Full : boolean); override; procedure Setup; override; function CanClose : boolean; override; procedure HandleEscape; override; procedure HandleF6; override; procedure ClearDisplay; procedure ShowCashbook (CashbookId : int64); procedure PositionCashbookEntriesStringGrid (CashbookEntryId : int64); procedure UpdateCashbookEntry; end; implementation uses GeneralUtilities, DatabaseManager, Globals, Base, Utilities, Main, Entries, CommunicationsManager, PromptString; {$R *.dfm} function TCashbooksFrame.NewCashbookEntry : boolean; begin Result := (CashbookEntry <> nil) and (CashbookEntry.Id = 0); end; procedure TCashbooksFrame.CancelChanges; var TempCashbookEntry : TCashbookEntry; begin if NewCashbookEntry then begin // if new entry then delete this from the cashbook Cashbook.DeleteCashbookEntry(CashbookEntry); // this will destroy it so set it to nil CashbookEntry := nil; // update grid UpdateCashbookEntriesStringGrid; // determine new row in grid if WorkstationConfiguration.RecentEntryFirst then CashbookEntriesStringGrid.Row := 1 else begin if Cashbook.CashbookEntriesInPeriod.Count > 1 then CashbookEntriesStringGrid.Row := Cashbook.CashbookEntriesInPeriod.Count else CashbookEntriesStringGrid.Row := 1; end; end else begin // if editing existing entry then reload from database try TempCashbookEntry := TCashbookEntry(LoadDatabaseObject(TCashbookEntry,CashbookEntry.Id)); except TempCashbookEntry := nil; end; if TempCashbookEntry <> nil then begin if CashbookEntry <> nil then CashbookEntry.Assign(TempCashbookEntry); TempCashbookEntry.Free; end; UpdateCashbookEntriesStringGrid; end; // switch to view mode EditMode := false; SetCashbookEntry; UpdateDetailControls; UpdateControlStates; CashbookComboBox.SetFocus; end; procedure TCashbooksFrame.SaveChanges; begin if CashbookEntry = nil then Exit; // if this is a new entry then record date and // debit/credit to use as default on subsequent entries if NewCashbookEntry then begin DefaultNewEntryDate := CashbookEntry.Date; DefaultDebit := CashbookEntry.Debit; end; // before saving to the database if other account has been // specified then update the matching double // entry in the ledger and create one if it does not exist CashbookEntry.UpdateCombinedEntry; // save the new entry in the database CashbookEntry.FullSaveToDatabase(true); // update all workstations // note that this will also cover this workstation // and update the display so set to view mode first EditMode := false; UpdateDatabaseObjectOnLoggedOnWorkstations (TCashbookEntry,CashbookEntry); CashbookComboBox.SetFocus; end; procedure TCashbooksFrame.DeleteCashbookEntry; begin if CashbookEntry = nil then Exit; // before deleting from database delete any existing ledger entry CashbookEntry.DeleteCombinedEntry; // delete current entry from database CashbookEntry.DeleteFromDatabase(false); // delete from all workstations // note that this will also cover this workstation // and update the display so set to view mode first EditMode := false; DeleteDatabaseObjectFromLoggedOnWorkstations (TCashbookEntry,CashbookEntry.Id); CashbookComboBox.SetFocus; end; function TCashbooksFrame.CanClose : boolean; begin if EditMode then Result := false else Result := true; end; procedure TCashbooksFrame.HandleEscape; begin if EditMode then if MessageDlg('Do you wish to cancel changes to this cashbook entry?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then CancelChanges; end; procedure TCashbooksFrame.HandleF6; begin MainForm.SwitchToFrame('Entries'); end; procedure TCashbooksFrame.Setup; begin SetUpStringGrid(CashbookEntriesStringGrid,[ 'Date', 'Description', 'Debit', 'Credit', 'Other A/c', 'Stmt' ],[ 12, // Date 37, // Description 13, // Debit 13, // Credit 22, // Other A/c 4 // Stmt ]); // create and initialise objects CashbookEntriesStringGrid.Row := 1; UpdateComboBoxes(false); UpdateDisplay; end; procedure TCashbooksFrame.SetCashbookEntry; var Index : integer; begin if Cashbook = nil then begin CashbookEntry := nil; Exit; end; if WorkstationConfiguration.RecentEntryFirst then Index := Cashbook.CashbookEntriesInPeriod.Count - CashbookEntriesStringGrid.Row else Index := CashbookEntriesStringGrid.Row - 1; if Index < Cashbook.CashbookEntriesInPeriod.Count then CashbookEntry := TCashbookEntry(Cashbook.CashbookEntriesInPeriod[Index]) else CashbookEntry := nil; end; procedure TCashbooksFrame.UpdateComboBoxes (Full : boolean); var i : integer; begin // populate cashbook combo box CashbookComboBox.Items.Clear; for i := 0 to Globals.Cashbooks.Count - 1 do if (TCashbook(Globals.Cashbooks[i]).Account <> nil) and (TCashbook(Globals.Cashbooks[i]).Account.CompanyId = WorkstationConfiguration.CompanyId) then CashbookComboBox.Items.Add(TCashbook(Globals.Cashbooks[i]).ComboBoxDisplayString); // populate other account combo box OtherAccountComboBox.Items.Clear; OtherAccountComboBox.Items.Add(ComboBoxNoneIndicator); for i := 0 to Globals.Accounts.Count - 1 do if TAccount(Globals.Accounts[i]).CompanyId = WorkstationConfiguration.CompanyId then OtherAccountComboBox.Items.Add(TAccount(Globals.Accounts[i]).ComboBoxDisplayString); end; procedure TCashbooksFrame.UpdateHeaderControls; begin IgnoreChangeEvents := true; if Cashbook <> nil then begin CashbookComboBox.ItemIndex := CashbookComboBox.Items.IndexOf(Cashbook.ComboBoxDisplayString); PeriodLabel.Caption := WorkstationConfiguration.AccountingPeriodString; PeriodHeadingLabel.Visible := true; BalanceHeadingLabel.Visible := true; StatementBalanceHeadingLabel.Visible := true; AccountBalanceHeadingLabel.Visible := true; AccountHeadingLabel.Visible := true; if Cashbook.Account <> nil then AccountLabel.Caption := Cashbook.Account.ComboBoxDisplayString else AccountLabel.Caption := 'No matching account'; end else begin CashbookComboBox.ItemIndex := -1; PeriodLabel.Caption := ''; PeriodHeadingLabel.Visible := false; BalanceHeadingLabel.Visible := false; StatementBalanceHeadingLabel.Visible := false; AccountBalanceHeadingLabel.Visible := false; AccountHeadingLabel.Visible := false; AccountLabel.Caption := ''; end; IgnoreChangeEvents := false; end; procedure TCashbooksFrame.UpdateDetailControls; begin IgnoreChangeEvents := true; if CashbookEntry <> nil then begin DateDateTimePicker.DateTime := CashbookEntry.Date; DescriptionEdit.Text := CashbookEntry.Description; AmountEdit.Text := FormatCurrency(CashbookEntry.AbsoluteAmount); if CashbookEntry.Debit then DebitRadioButton.Checked := true else CreditRadioButton.Checked := true; OtherAccountComboBox.ItemIndex := OtherAccountComboBox.Items.IndexOf(CashbookEntry.OtherAccountComboBoxDisplayString); OnStatementCheckBox.Checked := CashbookEntry.OnStatement; end else begin DateDateTimePicker.DateTime := Date; DescriptionEdit.Text := ''; AmountEdit.Text := ''; DebitRadioButton.Checked := false; CreditRadioButton.Checked := false; OtherAccountComboBox.ItemIndex := -1; OnStatementCheckBox.Checked := false; end; IgnoreChangeEvents := false; end; procedure TCashbooksFrame.UpdateCashbookEntriesStringGrid; var i : integer; begin // display cashbook entries in string grid if Cashbook = nil then begin CashbookEntriesStringGrid.RowCount := 2; // clear details on last row for i := 0 to CashbookEntriesStringGrid.ColCount - 1 do CashbookEntriesStringGrid.Cells[i,1] := ''; // update balance labels BalanceLabel.Caption := ''; StatementBalanceLabel.Caption := ''; AccountBalanceLabel.Caption := ''; end else begin if Cashbook.CashbookEntriesInPeriod.Count = 0 then begin CashbookEntriesStringGrid.RowCount := 2; // clear details on last row for i := 0 to CashbookEntriesStringGrid.ColCount - 1 do CashbookEntriesStringGrid.Cells[i,Cashbook.CashbookEntriesInPeriod.Count+1] := ''; end else CashbookEntriesStringGrid.RowCount := Cashbook.CashbookEntriesInPeriod.Count + 1; // don't update string grid here but display info as required // directly from draw cell event to save time CashbookEntriesStringGrid.Repaint; // update balance labels BalanceLabel.Caption := Cashbook.AccountingPeriodBalanceString(false); StatementBalanceLabel.Caption := Cashbook.AccountingPeriodBalanceString(true); if Cashbook.CachedAccount <> nil then AccountBalanceLabel.Caption := Cashbook.CachedAccount.AccountingPeriodBalanceString else AccountBalanceLabel.Caption := 'No matching account'; end; end; procedure TCashbooksFrame.UpdateControlStates; begin CashbookComboBox.Enabled := not EditMode; CashbookEntriesStringGrid.Enabled := not EditMode; DateDateTimePicker.Enabled := EditMode; DescriptionEdit.Enabled := EditMode; AmountEdit.Enabled := EditMode; DebitRadioButton.Enabled := EditMode; CreditRadioButton.Enabled := EditMode; OtherAccountComboBox.Enabled := EditMode; OnStatementCheckBox.Enabled := EditMode; // display status label if EditMode then begin if NewCashbookEntry then StatusLabel.Caption := 'New Entry' else StatusLabel.Caption := 'Edit Mode' end else StatusLabel.Caption := ''; EntryButton.Enabled := (not EditMode) and (Cashbook <> nil) and (CashbookEntry <> nil) and (CashbookEntry.CombinedEntryId <> 0); FindButton.Enabled := (not EditMode) and (Cashbook <> nil) and (CashbookEntry <> nil); NextButton.Enabled := (not EditMode) and (Cashbook <> nil) and (CashbookEntry <> nil) and (FindText <> ''); PrintButton.Enabled := (not EditMode) and (Cashbook <> nil); DeleteButton.Enabled := EditMode and (not NewCashbookEntry); NewButton.Enabled := (not EditMode) and (Cashbook <> nil); EditButton.Enabled := (not EditMode) and (CashbookEntry <> nil) and (not NewCashbookEntry); CancelButton.Enabled := EditMode; SaveButton.Enabled := EditMode; end; procedure TCashbooksFrame.UpdateDisplay; begin UpdateHeaderControls; UpdateCashbookEntriesStringGrid; SetCashbookEntry; UpdateDetailControls; UpdateControlStates; end; procedure TCashbooksFrame.ClearDisplay; begin Cashbook := nil; CashbookEntriesStringGrid.Row := 1; UpdateDisplay; end; procedure TCashbooksFrame.SwitchToCombinedEntry; var EntriesFrame : TEntriesFrame; begin // switch to entries frame and allow user to edit combined entries EntriesFrame := MainForm.EntriesFrame; if EntriesFrame.CanClose then begin MainForm.SwitchToFrame('Entries'); EntriesFrame.ShowCombinedEntry(CashbookEntry.CombinedEntryId); end else MessageDlg('Entry in progress',mtError,[mbOk],0); end; procedure TCashbooksFrame.ShowCashbook (CashbookId : int64); begin if (Cashbook = nil) or (Cashbook.Id <> CashbookId) then begin Cashbook := CashbooksCache.GetCashbook(CashbookId); CashbookEntriesStringGrid.Row := 1; UpdateDisplay; end; end; procedure TCashbooksFrame.PositionCashbookEntriesStringGrid (CashbookEntryId : int64); var i : integer; begin for i := 0 to Cashbook.CashbookEntriesInPeriod.Count - 1 do begin if Cashbook.CashbookEntriesInPeriod[i].Id = CashbookEntryId then begin if WorkstationConfiguration.RecentEntryFirst then CashbookEntriesStringGrid.Row := Cashbook.CashbookEntriesInPeriod.Count - i else CashbookEntriesStringGrid.Row := i + 1; Exit; end; end; CashbookEntriesStringGrid.Row := 1; end; procedure TCashbooksFrame.UpdateCashbookEntry; begin // update display in response to an update from another workstation if not EditMode then UpdateDisplay; end; {******************************************************************************} procedure TCashbooksFrame.PrintButtonClick(Sender: TObject); begin if Cashbook <> nil then Cashbook.Print; end; procedure TCashbooksFrame.DeleteButtonClick(Sender: TObject); begin if MessageDlg('Are you sure you wish to delete this cashbook entry?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then DeleteCashbookEntry; end; procedure TCashbooksFrame.NewButtonClick(Sender: TObject); var TempCashbookEntry : TCashbookEntry; begin if Cashbook <> nil then begin TempCashbookEntry := TCashbookEntry.Create; TempCashbookEntry.CashbookId := Cashbook.Id; // if a default date has been set from a previous new entry // that was saved then use this if DefaultNewEntryDate <> 0 then TempCashbookEntry.Date := DefaultNewEntryDate else TempCashbookEntry.Date := Date; // add new entry to cashbook Cashbook.AddCashbookEntry(TempCashbookEntry); // update grid UpdateCashbookEntriesStringGrid; // determine new row in grid if WorkstationConfiguration.RecentEntryFirst then CashbookEntriesStringGrid.Row := 1 else CashbookEntriesStringGrid.Row := Cashbook.CashbookEntriesInPeriod.Count; // switch to edit mode EditMode := true; SetCashbookEntry; UpdateDetailControls; UpdateControlStates; if DateDateTimePicker.Enabled then DateDateTimePicker.SetFocus; end; end; procedure TCashbooksFrame.EditButtonClick(Sender: TObject); begin EditMode := true; // UpdateComboBoxes(false); UpdateDisplay; if DateDateTimePicker.Enabled then DateDateTimePicker.SetFocus; end; procedure TCashbooksFrame.CancelButtonClick(Sender: TObject); begin CancelChanges; end; procedure TCashbooksFrame.SaveButtonClick(Sender: TObject); begin SaveChanges; end; procedure TCashbooksFrame.FindButtonClick(Sender: TObject); var CashbookEntryId : int64; begin if PromptStringForm.Prompt(false,'Enter Search String','Description') then begin FindText := PromptStringForm.Value; CashbookEntryId := Cashbook.FindNextCashbookEntryInPeriod(FindText,CashbookEntry,WorkstationConfiguration.RecentEntryFirst); if CashbookEntryId <> 0 then PositionCashbookEntriesStringGrid(CashbookEntryId) else ShowMessage('Entry not found'); end; end; procedure TCashbooksFrame.NextButtonClick(Sender: TObject); var CashbookEntryId : int64; begin CashbookEntryId := Cashbook.FindNextCashbookEntryInPeriod(FindText,CashbookEntry,WorkstationConfiguration.RecentEntryFirst); if CashbookEntryId <> 0 then PositionCashbookEntriesStringGrid(CashbookEntryId) else ShowMessage('Entry not found'); end; procedure TCashbooksFrame.EntryButtonClick(Sender: TObject); begin if CashbookEntry <> nil then SwitchToCombinedEntry; end; procedure TCashbooksFrame.CashbookEntriesStringGridClick(Sender: TObject); begin SetCashbookEntry; UpdateDetailControls; UpdateControlStates; end; procedure TCashbooksFrame.CashbookEntriesStringGridDblClick(Sender: TObject); begin // toggle OnStatement flag if CashbookEntry <> nil then begin CashbookEntry.OnStatement := not CashbookEntry.OnStatement; CashbookEntry.FullSaveToDatabase(true); // update all workstations // note that this will also cover this workstation // and update the display UpdateDatabaseObjectOnLoggedOnWorkstations (TCashbookEntry,CashbookEntry); end; end; procedure TCashbooksFrame.CashbookEntriesStringGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin if CashbookEntry <> nil then SwitchToCombinedEntry; Key := 0; end; end; procedure TCashbooksFrame.CashbookEntriesStringGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var CashbookEntry : TCashbookEntry; Text : string; function NewMonth : boolean; var PreviousCashbookEntry : TCashbookEntry; ThisDay, ThisMonth, ThisYear : word; PreviousDay, PreviousMonth, PreviousYear : word; begin if WorkstationConfiguration.RecentEntryFirst then PreviousCashbookEntry := TCashbookEntry(Cashbook.CashbookEntriesInPeriod[Cashbook.CashbookEntriesInPeriod.Count - ARow - 1]) else PreviousCashbookEntry := TCashbookEntry(Cashbook.CashbookEntriesInPeriod[ARow - 2]); if PreviousCashbookEntry = nil then Result := true else begin DecodeDate(CashbookEntry.Date,ThisYear,ThisMonth,ThisDay); DecodeDate(PreviousCashbookEntry.Date,PreviousYear,PreviousMonth,PreviousDay); if (ThisMonth <> PreviousMonth) or (ThisYear <> PreviousYear) then Result := true else Result := false; end; end; begin if Cashbook <> nil then begin if WorkstationConfiguration.RecentEntryFirst then CashbookEntry := TCashbookEntry(Cashbook.CashbookEntriesInPeriod[Cashbook.CashbookEntriesInPeriod.Count - ARow]) else CashbookEntry := TCashbookEntry(Cashbook.CashbookEntriesInPeriod[ARow - 1]); if CashbookEntry <> nil then begin // set the brush color if gdSelected in State then CashbookEntriesStringGrid.Canvas.Brush.Color := clHighlight else if NewMonth then CashbookEntriesStringGrid.Canvas.Brush.Color := DarkenColor(CashbookEntriesStringGrid.Color) else CashbookEntriesStringGrid.Canvas.Brush.Color := CashbookEntriesStringGrid.Color; // format the text if ACol = 0 then Text := FormatDate(CashbookEntry.Date) else if ACol = 1 then Text := CashbookEntry.Description else if ACol = 2 then begin if CashbookEntry.Debit then Text := FormatCurrencyForDisplay(CashbookEntry.AbsoluteAmount) else Text := ''; end else if ACol = 3 then begin if CashbookEntry.Credit then Text := FormatCurrencyForDisplay(CashbookEntry.AbsoluteAmount) else Text := ''; end else if ACol = 4 then Text := CashbookEntry.OtherAccountName else if ACol = 5 then begin if CashbookEntry.OnStatement then Text := 'Y' else Text := ''; end; // output the text CashbookEntriesStringGrid.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Text); end; end; end; {***** CashbookComboBox event handling ****************************************} procedure TCashbooksFrame.CashbookComboBoxKeyPress(Sender: TObject; var Key: Char); begin if Key = Char(VK_RETURN) then begin if Trim(TComboBox(Sender).Text) = '' then Exit; TBaseForm(Parent).GoToNextControl; Key := Char(0); end; end; procedure TCashbooksFrame.CashbookComboBoxSelect(Sender: TObject); var CashbookId : int64; begin CashbookId := Globals.Cashbooks.GetIdFromComboBoxDisplayString(TComboBox(Sender).Text); if (Cashbook = nil) or (Cashbook.Id <> CashbookId) then begin Cashbook := CashbooksCache.GetCashbook(CashbookId); CashbookEntriesStringGrid.Row := 1; UpdateDisplay; end; end; {***** DateDateTimePicker event handling **************************************} procedure TCashbooksFrame.DateDateTimePickerKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin TBaseForm(Parent).GoToNextControl; Key := 0; end; FirstChangeEvent := true; end; procedure TCashbooksFrame.DateDateTimePickerEnter(Sender: TObject); begin FirstChangeEvent := true; end; procedure TCashbooksFrame.DateDateTimePickerCloseUp(Sender: TObject); begin keybd_event(VK_LEFT,0,0,0); keybd_event(VK_RIGHT,0,0,0); end; procedure TCashbooksFrame.DateDateTimePickerChange(Sender: TObject); begin if IgnoreChangeEvents then Exit; // there is a bug in the DateTimePicker where change events // fire twice so ignore the second one FirstChangeEvent := not FirstChangeEvent; if FirstChangeEvent then Exit; if CashbookEntry = nil then Exit; CashbookEntry.Date := Trunc(TDateTimePicker(Sender).Date); UpdateCashbookEntriesStringGrid; end; {***** DescriptionEdit event handling *****************************************} procedure TCashbooksFrame.DescriptionEditKeyPress(Sender: TObject; var Key: Char); begin if Key = Char(VK_RETURN) then begin // if Trim(TEdit(Sender).Text) = '' then // Exit; TBaseForm(Parent).GoToNextControl; Key := Char(0); end; end; procedure TCashbooksFrame.DescriptionEditChange(Sender: TObject); begin if IgnoreChangeEvents then Exit; if CashbookEntry = nil then Exit; CashbookEntry.Description := TEdit(Sender).Text; UpdateCashbookEntriesStringGrid; end; {***** AmountEdit event handling **********************************************} procedure TCashbooksFrame.AmountEditKeyPress(Sender: TObject; var Key: Char); begin if Key = Char(VK_RETURN) then begin if Trim(TEdit(Sender).Text) = '' then Exit; TBaseForm(Parent).GoToNextControl; Key := Char(0); end; end; procedure TCashbooksFrame.AmountEditChange(Sender: TObject); begin if IgnoreChangeEvents then Exit; if CashbookEntry = nil then Exit; // if it is a new entry and the amount is zero then use default setting if (CashbookEntry.Amount = 0) and (NewCashbookEntry) then begin if DefaultDebit then CashbookEntry.Amount := Abs(ConvertCurrencyStringToInt64(TEdit(Sender).Text)) else CashbookEntry.Amount := -Abs(ConvertCurrencyStringToInt64(TEdit(Sender).Text)); end else begin if CashbookEntry.Debit then CashbookEntry.Amount := Abs(ConvertCurrencyStringToInt64(TEdit(Sender).Text)) else CashbookEntry.Amount := -Abs(ConvertCurrencyStringToInt64(TEdit(Sender).Text)); end; if CashbookEntry.Debit then DebitRadioButton.Checked := true else CreditRadioButton.Checked := true; UpdateCashbookEntriesStringGrid; end; {***** DebitRadioButton event handling ****************************************} procedure TCashbooksFrame.DebitRadioButtonKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin TBaseForm(Parent).GoToNextControl; Key := 0; end; end; procedure TCashbooksFrame.DebitRadioButtonClick(Sender: TObject); begin if IgnoreChangeEvents then Exit; if CashbookEntry = nil then Exit; CashbookEntry.Amount := CashbookEntry.AbsoluteAmount; UpdateCashbookEntriesStringGrid; end; {***** CreditRadioButton event handling ***************************************} procedure TCashbooksFrame.CreditRadioButtonKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin TBaseForm(Parent).GoToNextControl; Key := 0; end; end; procedure TCashbooksFrame.CreditRadioButtonClick(Sender: TObject); begin if IgnoreChangeEvents then Exit; if CashbookEntry = nil then Exit; CashbookEntry.Amount := -CashbookEntry.AbsoluteAmount; UpdateCashbookEntriesStringGrid; end; {***** OtherAccountComboBox event handling ************************************} procedure TCashbooksFrame.OtherAccountComboBoxKeyPress(Sender: TObject; var Key: Char); begin if Key = Char(VK_RETURN) then begin if Trim(TComboBox(Sender).Text) = '' then Exit; TBaseForm(Parent).GoToNextControl; Key := Char(0); end; end; procedure TCashbooksFrame.OtherAccountComboBoxSelect(Sender: TObject); begin if CashbookEntry = nil then Exit; CashbookEntry.OtherAccountId := Globals.Accounts.GetIdFromComboBoxDisplayString(TComboBox(Sender).Text); UpdateCashbookEntriesStringGrid; end; {***** OnStatementCheckBox event handling *************************************} procedure TCashbooksFrame.OnStatementCheckBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin SaveChanges; NewButtonClick(nil); Key := 0; end; end; procedure TCashbooksFrame.OnStatementCheckBoxClick(Sender: TObject); begin if IgnoreChangeEvents then Exit; CashbookEntry.OnStatement := TCheckBox(Sender).Checked; UpdateCashbookEntriesStringGrid; end; {******************************************************************************} end.