1 | unit FormDatabases;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
7 | Menus, ActnList, DbEngine, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormDatabases }
|
---|
12 |
|
---|
13 | TFormDatabases = class(TFormEx)
|
---|
14 | AAdd: TAction;
|
---|
15 | AOpen: TAction;
|
---|
16 | AModify: TAction;
|
---|
17 | ARemove: TAction;
|
---|
18 | ActionList1: TActionList;
|
---|
19 | ListView1: TListView;
|
---|
20 | MenuItem1: TMenuItem;
|
---|
21 | MenuItem2: TMenuItem;
|
---|
22 | MenuItem3: TMenuItem;
|
---|
23 | MenuItem4: TMenuItem;
|
---|
24 | PopupMenu1: TPopupMenu;
|
---|
25 | ToolBar1: TToolBar;
|
---|
26 | ToolButton1: TToolButton;
|
---|
27 | ToolButton2: TToolButton;
|
---|
28 | ToolButton3: TToolButton;
|
---|
29 | ToolButton4: TToolButton;
|
---|
30 | procedure AAddExecute(Sender: TObject);
|
---|
31 | procedure AModifyExecute(Sender: TObject);
|
---|
32 | procedure AOpenExecute(Sender: TObject);
|
---|
33 | procedure ARemoveExecute(Sender: TObject);
|
---|
34 | procedure FormShow(Sender: TObject);
|
---|
35 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
36 | procedure ListView1DblClick(Sender: TObject);
|
---|
37 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
38 | Selected: Boolean);
|
---|
39 | public
|
---|
40 | SelectedProfile: TDbConnectProfile;
|
---|
41 | DbManager: TDbManager;
|
---|
42 | procedure ReloadList;
|
---|
43 | procedure UpdateInterface;
|
---|
44 | end;
|
---|
45 |
|
---|
46 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | {$R *.lfm}
|
---|
50 |
|
---|
51 | uses
|
---|
52 | FormConnect;
|
---|
53 |
|
---|
54 | resourcestring
|
---|
55 | SRemoveDatabaseConnection = 'Remove database connection';
|
---|
56 | SRemoveDatabaseConnectionQuery = 'Do you want to really remove database connection %s?';
|
---|
57 | SNewDatabase = 'New database';
|
---|
58 |
|
---|
59 | { TFormDatabases }
|
---|
60 |
|
---|
61 | procedure TFormDatabases.ListView1DblClick(Sender: TObject);
|
---|
62 | begin
|
---|
63 | AOpen.Execute;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure TFormDatabases.AOpenExecute(Sender: TObject);
|
---|
67 | begin
|
---|
68 | if Assigned(ListView1.Selected) then begin
|
---|
69 | SelectedProfile := TDbConnectProfile(ListView1.Selected.Data);
|
---|
70 | ModalResult := mrOk;
|
---|
71 | end;
|
---|
72 | end;
|
---|
73 |
|
---|
74 | procedure TFormDatabases.ARemoveExecute(Sender: TObject);
|
---|
75 | begin
|
---|
76 | if Assigned(ListView1.Selected) then begin
|
---|
77 | if MessageDlg(SRemoveDatabaseConnection, Format(SRemoveDatabaseConnectionQuery, [
|
---|
78 | TDbConnectProfile(ListView1.Selected.Data).Name]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
|
---|
79 | DbManager.ConnectProfiles.Remove(ListView1.Selected.Data);
|
---|
80 | ReloadList;
|
---|
81 | end;
|
---|
82 | end;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TFormDatabases.AAddExecute(Sender: TObject);
|
---|
86 | var
|
---|
87 | NewConnectProfile: TDbConnectProfile;
|
---|
88 | begin
|
---|
89 | NewConnectProfile := TDbConnectProfile.Create;
|
---|
90 | NewConnectProfile.Name := SNewDatabase;
|
---|
91 | with TFormConnect.Create(nil) do
|
---|
92 | try
|
---|
93 | DbManager := Self.DbManager;
|
---|
94 | Load(NewConnectProfile);
|
---|
95 | if ShowModal = mrOk then begin
|
---|
96 | Save(NewConnectProfile);
|
---|
97 | DbManager.ConnectProfiles.Add(NewConnectProfile);
|
---|
98 | ReloadList;
|
---|
99 | end else NewConnectProfile.Free;
|
---|
100 | finally
|
---|
101 | Free;
|
---|
102 | end;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TFormDatabases.AModifyExecute(Sender: TObject);
|
---|
106 | begin
|
---|
107 | if Assigned(ListView1.Selected) then begin
|
---|
108 | DbManager := Self.DbManager;
|
---|
109 | with TFormConnect.Create(nil) do
|
---|
110 | try
|
---|
111 | DbManager := Self.DbManager;
|
---|
112 | Load(TDbConnectProfile(ListView1.Selected.Data));
|
---|
113 | if ShowModal = mrOk then begin
|
---|
114 | Save(TDbConnectProfile(ListView1.Selected.Data));
|
---|
115 | ReloadList;
|
---|
116 | end;
|
---|
117 | finally
|
---|
118 | Free;
|
---|
119 | end;
|
---|
120 | end;
|
---|
121 | end;
|
---|
122 |
|
---|
123 | procedure TFormDatabases.FormShow(Sender: TObject);
|
---|
124 | var
|
---|
125 | I: Integer;
|
---|
126 | begin
|
---|
127 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
---|
128 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
---|
129 | ReloadList;
|
---|
130 | end;
|
---|
131 |
|
---|
132 | procedure TFormDatabases.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
133 | begin
|
---|
134 | if (Item.Index >= 0) and (Item.Index < DbManager.ConnectProfiles.Count) then
|
---|
135 | with TDbConnectProfile(DbManager.ConnectProfiles[Item.Index]) do begin
|
---|
136 | Item.Caption := Name;
|
---|
137 | Item.SubItems.Add(ClientType.Name);
|
---|
138 | Item.SubItems.Add(Params.ConnectionString);
|
---|
139 | Item.Data := DbManager.ConnectProfiles[Item.Index];
|
---|
140 | end
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TFormDatabases.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
144 | Selected: Boolean);
|
---|
145 | begin
|
---|
146 | UpdateInterface;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TFormDatabases.ReloadList;
|
---|
150 | begin
|
---|
151 | ListView1.Items.Count := DbManager.ConnectProfiles.Count;
|
---|
152 | ListView1.Repaint;
|
---|
153 | UpdateInterface;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | procedure TFormDatabases.UpdateInterface;
|
---|
157 | begin
|
---|
158 | AModify.Enabled := Assigned(ListView1.Selected);
|
---|
159 | ARemove.Enabled := Assigned(ListView1.Selected);
|
---|
160 | AOpen.Enabled := Assigned(ListView1.Selected);
|
---|
161 | end;
|
---|
162 |
|
---|
163 | end.
|
---|
164 |
|
---|