1 | unit UFormConnect;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | ComCtrls, Spin, UDatabase;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormConnect }
|
---|
12 |
|
---|
13 | TFormConnect = class(TForm)
|
---|
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 | procedure FormCreate(Sender: TObject);
|
---|
36 | public
|
---|
37 | procedure Load(ConnectProfile: TDbConnectProfile);
|
---|
38 | procedure Save(ConnectProfile: TDbConnectProfile);
|
---|
39 | procedure ReloadDbEngines;
|
---|
40 | procedure UpdateInterface;
|
---|
41 | end;
|
---|
42 |
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | {$R *.lfm}
|
---|
47 |
|
---|
48 | uses
|
---|
49 | UCore, UEngineXML, UEngineMySQL;
|
---|
50 |
|
---|
51 | resourcestring
|
---|
52 | SAnyFile = 'Any file';
|
---|
53 | SXmlFiles = 'XML files';
|
---|
54 |
|
---|
55 | { TFormConnect }
|
---|
56 |
|
---|
57 | procedure TFormConnect.ButtonXmlBrowseClick(Sender: TObject);
|
---|
58 | begin
|
---|
59 | OpenDialog1.Filter := SXmlFiles + ' (.xml)|*.xml|' + SAnyFile + '|*.*';
|
---|
60 | OpenDialog1.InitialDir := ExtractFileDir(EditXml.Text);
|
---|
61 | OpenDialog1.FileName := ExtractFileName(EditXml.Text);
|
---|
62 | if OpenDialog1.Execute then
|
---|
63 | EditXml.Text := OpenDialog1.FileName;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure TFormConnect.ComboBoxDbEnginesChange(Sender: TObject);
|
---|
67 | begin
|
---|
68 | UpdateInterface;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TFormConnect.FormCreate(Sender: TObject);
|
---|
72 | begin
|
---|
73 | ReloadDbEngines;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | procedure TFormConnect.Load(ConnectProfile: TDbConnectProfile);
|
---|
77 | begin
|
---|
78 | EditName.Text := ConnectProfile.Name;
|
---|
79 | //EditConnectionString.Text := Database.ConnectionString;
|
---|
80 | ComboBoxDbEngines.ItemIndex := ComboBoxDbEngines.Items.IndexOfObject(ConnectProfile.ClientType);
|
---|
81 | if (ComboBoxDbEngines.ItemIndex = -1) and (ComboBoxDbEngines.Items.Count > 0) then
|
---|
82 | ComboBoxDbEngines.ItemIndex := 0;
|
---|
83 | if ConnectProfile.Params is TDbConnectParamsXml then
|
---|
84 | EditXml.Text := TDbConnectParamsXml(ConnectProfile.Params).FileName;
|
---|
85 | if ConnectProfile.Params is TDbConnectParamsMysql then begin
|
---|
86 | EditHost.Text := TDbConnectParamsMysql(ConnectProfile.Params).Host;
|
---|
87 | SpinEditPort.Value := TDbConnectParamsMysql(ConnectProfile.Params).Port;
|
---|
88 | end;
|
---|
89 | UpdateInterface;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TFormConnect.Save(ConnectProfile: TDbConnectProfile);
|
---|
93 | begin
|
---|
94 | ConnectProfile.Name := EditName.Text;
|
---|
95 | //DatabaseClient.ConnectionString := EditConnectionString.Text;
|
---|
96 | ConnectProfile.ClientType := TDbClientType(ComboBoxDbEngines.Items.Objects[ComboBoxDbEngines.ItemIndex]);
|
---|
97 | if ConnectProfile.Params is TDbConnectParamsXml then
|
---|
98 | TDbConnectParamsXml(ConnectProfile.Params).FileName := EditXml.Text;
|
---|
99 | if ConnectProfile.Params is TDbConnectParamsMysql then begin
|
---|
100 | TDbConnectParamsMysql(ConnectProfile.Params).Host := EditHost.Text;
|
---|
101 | TDbConnectParamsMysql(ConnectProfile.Params).Port := SpinEditPort.Value;
|
---|
102 | end;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TFormConnect.ReloadDbEngines;
|
---|
106 | var
|
---|
107 | I: Integer;
|
---|
108 | begin
|
---|
109 | ComboBoxDbEngines.Items.BeginUpdate;
|
---|
110 | try
|
---|
111 | ComboBoxDbEngines.Items.Clear;
|
---|
112 | for I := 0 to Core.DbManager.ClientTypes.Count - 1 do
|
---|
113 | ComboBoxDbEngines.Items.AddObject(Core.DbManager.ClientTypes[I].Name,
|
---|
114 | Core.DbManager.ClientTypes[I]);
|
---|
115 | finally
|
---|
116 | ComboBoxDbEngines.Items.Endupdate;
|
---|
117 | end;
|
---|
118 | end;
|
---|
119 |
|
---|
120 | procedure TFormConnect.UpdateInterface;
|
---|
121 | begin
|
---|
122 | PageControl1.TabIndex := ComboBoxDbEngines.ItemIndex;
|
---|
123 | end;
|
---|
124 |
|
---|
125 | end.
|
---|
126 |
|
---|