Ignore:
Timestamp:
Mar 23, 2018, 1:59:25 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Database classes reorganized. Now TDbConnectProfile is class which holds information about connection to database.
  • Modified: TDbManager is top most class for managing other database classes.
  • Modified: TDbConnectParams class contains client specific parameters for connect profile.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormConnect.pas

    r6 r20  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, UDatabase;
     9  ComCtrls, Spin, UDatabase;
    1010
    1111type
     
    1414
    1515  TFormConnect = class(TForm)
     16    ButtonXmlBrowse: TButton;
    1617    ButtonOk: TButton;
    1718    ButtonCancel: TButton;
    1819    ComboBox1: TComboBox;
     20    EditHost: TEdit;
     21    EditXml: TEdit;
    1922    EditName: TEdit;
    20     EditConnectionString: TEdit;
    2123    Label1: TLabel;
    2224    Label2: TLabel;
    2325    Label3: TLabel;
     26    Label4: TLabel;
     27    Label5: TLabel;
     28    OpenDialog1: TOpenDialog;
     29    PageControl1: TPageControl;
     30    SpinEditPort: TSpinEdit;
     31    TabSheetSqlite: TTabSheet;
     32    TabSheetRegistry: TTabSheet;
     33    TabSheetXml: TTabSheet;
     34    TabSheetSql: TTabSheet;
     35    procedure ButtonXmlBrowseClick(Sender: TObject);
     36    procedure ComboBox1Change(Sender: TObject);
    2437    procedure FormShow(Sender: TObject);
    2538  private
    26     { private declarations }
    2739  public
    28     procedure Load(Database: TDatabase);
    29     procedure Save(Database: TDatabase);
     40    procedure Load(ConnectProfile: TDbConnectProfile);
     41    procedure Save(ConnectProfile: TDbConnectProfile);
    3042    procedure Init;
     43    procedure UpdateInterface;
    3144  end;
    3245
    3346var
    3447  FormConnect: TFormConnect;
     48
    3549
    3650implementation
     
    3953
    4054uses
    41   UCore;
     55  UCore, UEngineXML, UEngineMySQL;
    4256
    4357{ TFormConnect }
     
    4761end;
    4862
    49 procedure TFormConnect.Load(Database: TDatabase);
     63procedure TFormConnect.ButtonXmlBrowseClick(Sender: TObject);
    5064begin
    51   EditName.Text := Database.Name;
    52   EditConnectionString.Text := Database.ConnectionString;
    53   ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(Database.Engine);
     65  OpenDialog1.Filter := 'XML files (.xml)|*.xml|Any file|*.*';
     66  OpenDialog1.InitialDir := ExtractFileDir(EditXml.Text);
     67  OpenDialog1.FileName := ExtractFileName(EditXml.Text);
     68  if OpenDialog1.Execute then
     69    EditXml.Text := OpenDialog1.FileName;
     70end;
     71
     72procedure TFormConnect.ComboBox1Change(Sender: TObject);
     73begin
     74  UpdateInterface;
     75end;
     76
     77procedure TFormConnect.Load(ConnectProfile: TDbConnectProfile);
     78begin
     79  EditName.Text := ConnectProfile.Name;
     80  //EditConnectionString.Text := Database.ConnectionString;
     81  ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ConnectProfile.ClientType);
    5482  if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
    5583    ComboBox1.ItemIndex := 0;
     84  if ConnectProfile.Params is TDbConnectParamsXml then
     85    EditXml.Text := TDbConnectParamsXml(ConnectProfile.Params).FileName;
     86  if ConnectProfile.Params is TDbConnectParamsMysql then begin
     87    EditHost.Text := TDbConnectParamsMysql(ConnectProfile.Params).Host;
     88    SpinEditPort.Value := TDbConnectParamsMysql(ConnectProfile.Params).Port;
     89  end;
     90  UpdateInterface;
    5691end;
    5792
    58 procedure TFormConnect.Save(Database: TDatabase);
     93procedure TFormConnect.Save(ConnectProfile: TDbConnectProfile);
    5994begin
    60   Database.Name := EditName.Text;
    61   Database.ConnectionString := EditConnectionString.Text;
    62   Database.Engine := TDatabaseEngine(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
     95  ConnectProfile.Name := EditName.Text;
     96  //DatabaseClient.ConnectionString := EditConnectionString.Text;
     97  ConnectProfile.ClientType := TDbClientType(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
     98  if ConnectProfile.Params is TDbConnectParamsXml then
     99    TDbConnectParamsXml(ConnectProfile.Params).FileName := EditXml.Text;
     100  if ConnectProfile.Params is TDbConnectParamsMysql then begin
     101    TDbConnectParamsMysql(ConnectProfile.Params).Host := EditHost.Text;
     102    TDbConnectParamsMysql(ConnectProfile.Params).Port := SpinEditPort.Value;
     103  end;
    63104end;
    64105
     
    68109begin
    69110  ComboBox1.Items.Clear;
    70   for I := 0 to Core.Engines.Count - 1 do
    71     ComboBox1.Items.AddObject(TDatabaseEngine(Core.Engines[I]).Name, Core.Engines[I]);
     111  for I := 0 to Core.DbManager.ClientTypes.Count - 1 do
     112    ComboBox1.Items.AddObject(TDbClientType(Core.DbManager.ClientTypes[I]).Name,
     113      Core.DbManager.ClientTypes[I]);
     114end;
     115
     116procedure TFormConnect.UpdateInterface;
     117begin
     118  PageControl1.TabIndex := ComboBox1.ItemIndex;
    72119end;
    73120
Note: See TracChangeset for help on using the changeset viewer.