| 1 | unit FormConnect;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|---|
| 7 | ComCtrls, Spin, DbEngine, FormEx;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormConnect }
|
|---|
| 12 |
|
|---|
| 13 | TFormConnect = class(TFormEx)
|
|---|
| 14 | ButtonXmlBrowse: TButton;
|
|---|
| 15 | ButtonOk: TButton;
|
|---|
| 16 | ButtonCancel: TButton;
|
|---|
| 17 | ComboBoxDbEngines: TComboBox;
|
|---|
| 18 | EditHost: TEdit;
|
|---|
| 19 | EditXml: TEdit;
|
|---|
| 20 | EditName: TEdit;
|
|---|
| 21 | Label1: TLabel;
|
|---|
| 22 | Label2: TLabel;
|
|---|
| 23 | Label3: TLabel;
|
|---|
| 24 | Label4: TLabel;
|
|---|
| 25 | Label5: TLabel;
|
|---|
| 26 | OpenDialog1: TOpenDialog;
|
|---|
| 27 | PageControl1: TPageControl;
|
|---|
| 28 | SpinEditPort: TSpinEdit;
|
|---|
| 29 | TabSheetSqlite: TTabSheet;
|
|---|
| 30 | TabSheetRegistry: TTabSheet;
|
|---|
| 31 | TabSheetXml: TTabSheet;
|
|---|
| 32 | TabSheetSql: TTabSheet;
|
|---|
| 33 | procedure ButtonXmlBrowseClick(Sender: TObject);
|
|---|
| 34 | procedure ComboBoxDbEnginesChange(Sender: TObject);
|
|---|
| 35 | private
|
|---|
| 36 | FDbManager: TDbManager;
|
|---|
| 37 | procedure SetDbManager(AValue: TDbManager);
|
|---|
| 38 | public
|
|---|
| 39 | procedure Load(ConnectProfile: TDbConnectProfile);
|
|---|
| 40 | procedure Save(ConnectProfile: TDbConnectProfile);
|
|---|
| 41 | procedure ReloadDbEngines;
|
|---|
| 42 | procedure UpdateInterface;
|
|---|
| 43 | property DbManager: TDbManager read FDbManager write SetDbManager;
|
|---|
| 44 | end;
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | implementation
|
|---|
| 48 |
|
|---|
| 49 | {$R *.lfm}
|
|---|
| 50 |
|
|---|
| 51 | uses
|
|---|
| 52 | EngineXML, EngineMySQL;
|
|---|
| 53 |
|
|---|
| 54 | resourcestring
|
|---|
| 55 | SAnyFile = 'Any file';
|
|---|
| 56 | SXmlFiles = 'XML files';
|
|---|
| 57 |
|
|---|
| 58 | { TFormConnect }
|
|---|
| 59 |
|
|---|
| 60 | procedure TFormConnect.ButtonXmlBrowseClick(Sender: TObject);
|
|---|
| 61 | begin
|
|---|
| 62 | OpenDialog1.Filter := SXmlFiles + ' (.xml)|*.xml|' + SAnyFile + '|*.*';
|
|---|
| 63 | OpenDialog1.InitialDir := ExtractFileDir(EditXml.Text);
|
|---|
| 64 | OpenDialog1.FileName := ExtractFileName(EditXml.Text);
|
|---|
| 65 | if OpenDialog1.Execute then
|
|---|
| 66 | EditXml.Text := OpenDialog1.FileName;
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 | procedure TFormConnect.ComboBoxDbEnginesChange(Sender: TObject);
|
|---|
| 70 | begin
|
|---|
| 71 | UpdateInterface;
|
|---|
| 72 | end;
|
|---|
| 73 |
|
|---|
| 74 | procedure TFormConnect.SetDbManager(AValue: TDbManager);
|
|---|
| 75 | begin
|
|---|
| 76 | if FDbManager = AValue then Exit;
|
|---|
| 77 | FDbManager := AValue;
|
|---|
| 78 | ReloadDbEngines;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | procedure TFormConnect.Load(ConnectProfile: TDbConnectProfile);
|
|---|
| 82 | begin
|
|---|
| 83 | EditName.Text := ConnectProfile.Name;
|
|---|
| 84 | //EditConnectionString.Text := Database.ConnectionString;
|
|---|
| 85 | ComboBoxDbEngines.ItemIndex := ComboBoxDbEngines.Items.IndexOfObject(ConnectProfile.ClientType);
|
|---|
| 86 | if (ComboBoxDbEngines.ItemIndex = -1) and (ComboBoxDbEngines.Items.Count > 0) then
|
|---|
| 87 | ComboBoxDbEngines.ItemIndex := 0;
|
|---|
| 88 | if ConnectProfile.Params is TDbConnectParamsXml then
|
|---|
| 89 | EditXml.Text := TDbConnectParamsXml(ConnectProfile.Params).FileName;
|
|---|
| 90 | if ConnectProfile.Params is TDbConnectParamsMysql then begin
|
|---|
| 91 | EditHost.Text := TDbConnectParamsMysql(ConnectProfile.Params).Host;
|
|---|
| 92 | SpinEditPort.Value := TDbConnectParamsMysql(ConnectProfile.Params).Port;
|
|---|
| 93 | end;
|
|---|
| 94 | UpdateInterface;
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TFormConnect.Save(ConnectProfile: TDbConnectProfile);
|
|---|
| 98 | begin
|
|---|
| 99 | ConnectProfile.Name := EditName.Text;
|
|---|
| 100 | //DatabaseClient.ConnectionString := EditConnectionString.Text;
|
|---|
| 101 | ConnectProfile.ClientType := TDbClientType(ComboBoxDbEngines.Items.Objects[ComboBoxDbEngines.ItemIndex]);
|
|---|
| 102 | if ConnectProfile.Params is TDbConnectParamsXml then
|
|---|
| 103 | TDbConnectParamsXml(ConnectProfile.Params).FileName := EditXml.Text;
|
|---|
| 104 | if ConnectProfile.Params is TDbConnectParamsMysql then begin
|
|---|
| 105 | TDbConnectParamsMysql(ConnectProfile.Params).Host := EditHost.Text;
|
|---|
| 106 | TDbConnectParamsMysql(ConnectProfile.Params).Port := SpinEditPort.Value;
|
|---|
| 107 | end;
|
|---|
| 108 | end;
|
|---|
| 109 |
|
|---|
| 110 | procedure TFormConnect.ReloadDbEngines;
|
|---|
| 111 | var
|
|---|
| 112 | I: Integer;
|
|---|
| 113 | begin
|
|---|
| 114 | ComboBoxDbEngines.Items.BeginUpdate;
|
|---|
| 115 | try
|
|---|
| 116 | ComboBoxDbEngines.Items.Clear;
|
|---|
| 117 | for I := 0 to DbManager.ClientTypes.Count - 1 do
|
|---|
| 118 | ComboBoxDbEngines.Items.AddObject(DbManager.ClientTypes[I].Name,
|
|---|
| 119 | DbManager.ClientTypes[I]);
|
|---|
| 120 | finally
|
|---|
| 121 | ComboBoxDbEngines.Items.Endupdate;
|
|---|
| 122 | end;
|
|---|
| 123 | end;
|
|---|
| 124 |
|
|---|
| 125 | procedure TFormConnect.UpdateInterface;
|
|---|
| 126 | begin
|
|---|
| 127 | PageControl1.TabIndex := ComboBoxDbEngines.ItemIndex;
|
|---|
| 128 | end;
|
|---|
| 129 |
|
|---|
| 130 | end.
|
|---|
| 131 |
|
|---|