{*******************************************************} { } { Responsive Software http://www.responsive.co.nz } { } { Copyright (c) 2003-2006 Responsive Software Limited } { } {*******************************************************} unit Config; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Base, Buttons, StdCtrls, ExtCtrls, ComCtrls; type TConfigForm = class(TBaseForm) OkBitBtn: TBitBtn; CancelBitBtn: TBitBtn; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; Label12: TLabel; ColorButton: TButton; DefaultColorButton: TButton; MaximiseOnStartCheckBox: TCheckBox; ReportsPictureEdit: TEdit; BrowseReportsPictureButton: TButton; Label15: TLabel; QRPFileDirectoryEdit: TEdit; BrowseQRPFileDirectoryButton: TButton; Label13: TLabel; PortNumberEdit: TEdit; AccountsPanel: TPanel; CompanyLabel: TLabel; CompanyComboBox: TComboBox; RecentEntryFirstCheckBox: TCheckBox; BeginPeriodDateDateTimePicker: TDateTimePicker; EndPeriodDateDateTimePicker: TDateTimePicker; UseBeginPeriodCheckBox: TCheckBox; UseEndPeriodCheckBox: TCheckBox; POSPanel: TPanel; NoOfDaysSalesEdit: TEdit; Label1: TLabel; GlobalAccountsPanel: TPanel; Label4: TLabel; Label7: TLabel; Label9: TLabel; SalesAccountAbbreviationEdit: TEdit; BankAccountAbbreviationEdit: TEdit; Label2: TLabel; HTTPPortNumberEdit: TEdit; HTTPPageColorButton: TButton; HTTPPageDefaultColorButton: TButton; Label3: TLabel; GlobalAttachmentDirectoryEdit: TEdit; BrowseGlobalAttachmentDirectoryButton: TButton; Label5: TLabel; WorkstationAttachmentDirectoryEdit: TEdit; BrowseWorkstationAttachmentDirectoryButton: TButton; CacheAttachmentsCheckBox: TCheckBox; Label20: TLabel; WebsiteContentDirectoryEdit: TEdit; BrowseWebsiteContentDirectoryButton: TButton; procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure ColorButtonClick(Sender: TObject); procedure OkBitBtnClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure DefaultColorButtonClick(Sender: TObject); procedure BrowseReportsPictureButtonClick(Sender: TObject); procedure BrowseQRPFileDirectoryButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure UseBeginPeriodCheckBoxClick(Sender: TObject); procedure UseEndPeriodCheckBoxClick(Sender: TObject); procedure EndPeriodDateDateTimePickerChange(Sender: TObject); procedure BeginPeriodDateDateTimePickerChange(Sender: TObject); procedure PortNumberEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure HTTPPageColorButtonClick(Sender: TObject); procedure HTTPPageDefaultColorButtonClick(Sender: TObject); procedure BrowseGlobalAttachmentDirectoryButtonClick(Sender: TObject); procedure BrowseWorkstationAttachmentDirectoryButtonClick( Sender: TObject); procedure CacheAttachmentsCheckBoxClick(Sender: TObject); procedure BrowseWebsiteContentDirectoryButtonClick(Sender: TObject); private { Private declarations } Color : TColor; HTTPPageColor : TColor; public { Public declarations } procedure Configure; end; var ConfigForm: TConfigForm; implementation uses GeneralUtilities, Globals, Utilities, DatabaseManager, Main, DatabaseObjects, Entries, Accounts, BalanceSheet, IncomeStatement; {$R *.dfm} procedure TConfigForm.Configure; {$IFDEF ACCOUNTS} var i : integer; Company : TCompany; {$ENDIF} begin if not ServerMode then begin {$IFDEF ACCOUNTS} CompanyComboBox.Items.Clear; CompanyComboBox.Items.Add(ComboBoxDefaultIndicator); for i := 0 to Companies.Count - 1 do CompanyComboBox.Items.Add(TCompany(Companies[i]).ComboBoxDisplayString); {$ENDIF} // workstation settings Color := WorkstationConfiguration.ControlColor; MaximiseOnStartCheckBox.Checked := WorkstationConfiguration.MaximiseOnStart; ReportsPictureEdit.Text := WorkstationConfiguration.ReportsPicture; QRPFileDirectoryEdit.Text := WorkstationConfiguration.QRPFileDirectory; CacheAttachmentsCheckBox.Checked := WorkstationConfiguration.CacheAttachments; WorkstationAttachmentDirectoryEdit.Text := WorkstationConfiguration.AttachmentDirectory; WorkstationAttachmentDirectoryEdit.Enabled := CacheAttachmentsCheckBox.Checked; BrowseWorkstationAttachmentDirectoryButton.Enabled := CacheAttachmentsCheckBox.Checked; {$IFDEF POS} NoOfDaysSalesEdit.Text := IntToStr(WorkstationConfiguration.NoOfDaysSales); {$ENDIF} {$IFDEF ACCOUNTS} Company := TCompany(Companies.ObjectsById[WorkstationConfiguration.CompanyId]); if Company <> nil then CompanyComboBox.ItemIndex := CompanyComboBox.Items.IndexOf(Company.ComboBoxDisplayString) else CompanyComboBox.ItemIndex := -1; RecentEntryFirstCheckBox.Checked := WorkstationConfiguration.RecentEntryFirst; UseBeginPeriodCheckBox.Checked := WorkstationConfiguration.UseBeginPeriod; BeginPeriodDateDateTimePicker.Date := WorkstationConfiguration.BeginPeriodDate; BeginPeriodDateDateTimePicker.Enabled := UseBeginPeriodCheckBox.Checked; UseEndPeriodCheckBox.Checked := WorkstationConfiguration.UseEndPeriod; EndPeriodDateDateTimePicker.Date := WorkstationConfiguration.EndPeriodDate; EndPeriodDateDateTimePicker.Enabled := UseEndPeriodCheckBox.Checked; {$ENDIF} end; // global settings if not ClientMode then begin {$IFDEF ACCOUNTS} SalesAccountAbbreviationEdit.Text := GlobalConfiguration.SalesAccountAbbreviation; BankAccountAbbreviationEdit.Text := GlobalConfiguration.BankAccountAbbreviation; {$ENDIF} PortNumberEdit.Text := IntToStr(GlobalConfiguration.PortNumber); HTTPPortNumberEdit.Text := IntToStr(GlobalConfiguration.HTTPPortNumber); HTTPPageColor := GlobalConfiguration.HTTPPageColor; GlobalAttachmentDirectoryEdit.Text := GlobalConfiguration.AttachmentDirectory; WebsiteContentDirectoryEdit.Text := GlobalConfiguration.WebsiteContentDirectory; end; ShowModal; end; procedure TConfigForm.ColorButtonClick(Sender: TObject); begin if ChooseColor(Color, Color) then SetControlColors(Self,Color); end; procedure TConfigForm.DefaultColorButtonClick(Sender: TObject); begin Color := DefaultControlColor; SetControlColors(Self,Color); end; procedure TConfigForm.HTTPPageColorButtonClick(Sender: TObject); begin if ChooseColor(HTTPPageColor, HTTPPageColor) then SetControlColors(Self,HTTPPageColor); end; procedure TConfigForm.HTTPPageDefaultColorButtonClick(Sender: TObject); begin HTTPPageColor := DefaultControlColor; SetControlColors(Self,HTTPPageColor); end; procedure TConfigForm.OkBitBtnClick(Sender: TObject); {$IFDEF ACCOUNTS} var CompanyId : int64; CompanyChanged : boolean; {$ENDIF} begin {$IFDEF ACCOUNTS} CompanyChanged := false; {$ENDIF} if not ServerMode then begin // reload any pictures which have changed if ReportsPictureEdit.Text <> WorkstationConfiguration.ReportsPicture then try MainForm.ReportsFrame.Image.Picture.LoadFromFile(ReportsPictureEdit.Text); except // don't do anything if error occurs during loading end; // workstation settings WorkstationConfiguration.ControlColor := Color; WorkstationConfiguration.MaximiseOnStart := MaximiseOnStartCheckBox.Checked; WorkstationConfiguration.ReportsPicture := ReportsPictureEdit.Text; WorkstationConfiguration.QRPFileDirectory := QRPFileDirectoryEdit.Text; WorkstationConfiguration.CacheAttachments := CacheAttachmentsCheckBox.Checked; WorkstationConfiguration.AttachmentDirectory := WorkstationAttachmentDirectoryEdit.Text; {$IFDEF POS} WorkstationConfiguration.NoOfDaysSales := StrToIntDef(NoOfDaysSalesEdit.Text,7); {$ENDIF} {$IFDEF ACCOUNTS} CompanyId := Companies.GetIdFromComboBoxDisplayString(CompanyComboBox.Text); CompanyChanged := CompanyId <> WorkstationConfiguration.CompanyId; if CompanyChanged then begin if MainForm.EntriesFrame.CanClose and MainForm.CashbooksFrame.CanClose then WorkstationConfiguration.CompanyId := CompanyId else begin MessageDlg('Unable to switch company while entry is in progress',mtError,[mbOk],0); CompanyChanged := false; end; end; WorkstationConfiguration.RecentEntryFirst := RecentEntryFirstCheckBox.Checked; if (WorkstationConfiguration.UseBeginPeriod <> UseBeginPeriodCheckBox.Checked) or (WorkstationConfiguration.BeginPeriodDate <> Trunc(BeginPeriodDateDateTimePicker.Date)) or (WorkstationConfiguration.UseEndPeriod <> UseEndPeriodCheckBox.Checked) or (WorkstationConfiguration.EndPeriodDate <> Trunc(EndPeriodDateDateTimePicker.Date)) then begin WorkstationConfiguration.UseBeginPeriod := UseBeginPeriodCheckBox.Checked; WorkstationConfiguration.BeginPeriodDate := Trunc(BeginPeriodDateDateTimePicker.Date); WorkstationConfiguration.UseEndPeriod := UseEndPeriodCheckBox.Checked; WorkstationConfiguration.EndPeriodDate := Trunc(EndPeriodDateDateTimePicker.Date); // if period has changed then tell the accounts cache and the report screens AccountsCache.SetPeriod( WorkstationConfiguration.UseBeginPeriod, WorkstationConfiguration.BeginPeriodDate, WorkstationConfiguration.UseEndPeriod, WorkstationConfiguration.EndPeriodDate); CashbooksCache.SetPeriod( WorkstationConfiguration.UseBeginPeriod, WorkstationConfiguration.BeginPeriodDate, WorkstationConfiguration.UseEndPeriod, WorkstationConfiguration.EndPeriodDate); MainForm.BalanceSheetFrame.SetPeriod( WorkstationConfiguration.UseBeginPeriod, WorkstationConfiguration.BeginPeriodDate, WorkstationConfiguration.UseEndPeriod, WorkstationConfiguration.EndPeriodDate); MainForm.IncomeStatementFrame.SetPeriod( WorkstationConfiguration.UseBeginPeriod, WorkstationConfiguration.BeginPeriodDate, WorkstationConfiguration.UseEndPeriod, WorkstationConfiguration.EndPeriodDate); MainForm.GraphFrame.SetPeriod( WorkstationConfiguration.UseBeginPeriod, WorkstationConfiguration.BeginPeriodDate, WorkstationConfiguration.UseEndPeriod, WorkstationConfiguration.EndPeriodDate); end; {$ENDIF} end; // global settings if not ClientMode then begin {$IFDEF ACCOUNTS} GlobalConfiguration.SalesAccountAbbreviation := SalesAccountAbbreviationEdit.Text; GlobalConfiguration.BankAccountAbbreviation := BankAccountAbbreviationEdit.Text; {$ENDIF} GlobalConfiguration.PortNumber := StrToIntDef(PortNumberEdit.Text,DefaultPortNumber); GlobalConfiguration.HTTPPortNumber := StrToIntDef(HTTPPortNumberEdit.Text,DefaultHTTPPortNumber); GlobalConfiguration.HTTPPageColor := HTTPPageColor; GlobalConfiguration.AttachmentDirectory := GlobalAttachmentDirectoryEdit.Text; GlobalConfiguration.WebsiteContentDirectory := WebsiteContentDirectoryEdit.Text; end; if not ServerMode then begin // record workstation configuration and apply color changes SaveWorkstationConfiguration; SetControlColors(Application,WorkstationConfiguration.ControlColor); {$IFDEF ACCOUNTS} MainForm.EntriesFrame.UpdateComboBoxes(false); MainForm.AccountsFrame.UpdateComboBoxes(false); MainForm.CashbooksFrame.UpdateComboBoxes(false); if CompanyChanged then begin // if company has changed then clear display of accounts frames MainForm.EntriesFrame.ClearDisplay; MainForm.AccountsFrame.ClearDisplay; MainForm.CashbooksFrame.ClearDisplay; MainForm.BalanceSheetFrame.UpdateDisplay; MainForm.IncomeStatementFrame.UpdateDisplay; MainForm.GraphFrame.UpdateDisplay; end else begin // update the accounts and cashbooks display in case the order has changed or the period MainForm.EntriesFrame.UpdateDisplay; MainForm.AccountsFrame.UpdateDisplay; MainForm.CashbooksFrame.UpdateDisplay; end; {$ENDIF} end; // record global configuration if not ClientMode then SaveGlobalConfiguration; end; procedure TConfigForm.FormShow(Sender: TObject); begin if not ServerMode then begin PageControl1.ActivePage := TabSheet1; ColorButton.SetFocus; end else begin PageControl1.ActivePage := TabSheet2; PortNumberEdit.SetFocus; end; end; procedure TConfigForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_ESCAPE then begin Close; Key := 0; end; end; procedure TConfigForm.BrowseReportsPictureButtonClick(Sender: TObject); var FileName : string; begin FileName := ReportsPictureEdit.Text; if ChoosePicture(FileName) then ReportsPictureEdit.Text := FileName; end; procedure TConfigForm.BrowseQRPFileDirectoryButtonClick( Sender: TObject); var Directory : string; begin Directory := QRPFileDirectoryEdit.Text; if ChooseDirectory( Directory, 'Choose location for QRP files', 'Any file (*.*)|*.*') then QRPFileDirectoryEdit.Text := Directory; end; procedure TConfigForm.BrowseWorkstationAttachmentDirectoryButtonClick( Sender: TObject); var Directory : string; begin Directory := WorkstationAttachmentDirectoryEdit.Text; if ChooseDirectory( Directory, 'Choose location for attachment files', 'Any file (*.*)|*.*') then WorkstationAttachmentDirectoryEdit.Text := Directory; end; procedure TConfigForm.BrowseGlobalAttachmentDirectoryButtonClick( Sender: TObject); var Directory : string; begin Directory := GlobalAttachmentDirectoryEdit.Text; if ChooseDirectory( Directory, 'Choose location for attachment files', 'Any file (*.*)|*.*') then GlobalAttachmentDirectoryEdit.Text := Directory; end; procedure TConfigForm.BrowseWebsiteContentDirectoryButtonClick( Sender: TObject); var Directory : string; begin Directory := WebsiteContentDirectoryEdit.Text; if ChooseDirectory( Directory, 'Choose location for website content files', 'Any file (*.*)|*.*') then WebsiteContentDirectoryEdit.Text := Directory; end; procedure TConfigForm.FormCreate(Sender: TObject); begin if not GlobalConfiguration.Accounts then begin AccountsPanel.Visible := false; GlobalAccountsPanel.Visible := false; end; if not GlobalConfiguration.POS then POSPanel.Visible := false; if ServerMode then TabSheet1.TabVisible := false; if ClientMode then TabSheet2.TabVisible := false; Caption := 'Configure ' + ProgramName; end; procedure TConfigForm.UseBeginPeriodCheckBoxClick(Sender: TObject); begin BeginPeriodDateDateTimePicker.Enabled := UseBeginPeriodCheckBox.Checked; end; procedure TConfigForm.UseEndPeriodCheckBoxClick(Sender: TObject); begin EndPeriodDateDateTimePicker.Enabled := UseEndPeriodCheckBox.Checked; end; procedure TConfigForm.BeginPeriodDateDateTimePickerChange(Sender: TObject); var BeginDate, EndDate : TDateTime; EndDateDateTimePicker : TDateTimePicker; begin EndDateDateTimePicker := EndPeriodDateDateTimePicker; BeginDate := Trunc(TDateTimePicker(Sender).Date); EndDate := EndDateDateTimePicker.Date; // adjust end date if necessary if EndDate < BeginDate then begin EndDate := BeginDate; EndDateDateTimePicker.Date := EndDate; end; end; procedure TConfigForm.EndPeriodDateDateTimePickerChange(Sender: TObject); var BeginDate, EndDate : TDateTime; BeginDateDateTimePicker : TDateTimePicker; begin BeginDateDateTimePicker := BeginPeriodDateDateTimePicker; BeginDate := BeginDateDateTimePicker.Date; EndDate := Trunc(TDateTimePicker(Sender).Date); // adjust begin date if necessary if EndDate < BeginDate then begin BeginDate := EndDate; BeginDateDateTimePicker.Date := BeginDate; end; end; procedure TConfigForm.PortNumberEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin if Trim(TEdit(Sender).Text) = '' then Exit; GoToNextControl; Key := 0; end; end; procedure TConfigForm.CacheAttachmentsCheckBoxClick(Sender: TObject); begin WorkstationAttachmentDirectoryEdit.Enabled := CacheAttachmentsCheckBox.Checked; BrowseWorkstationAttachmentDirectoryButton.Enabled := CacheAttachmentsCheckBox.Checked; end; end.