source: trunk/Forms/FormDatabases.pas

Last change on this file was 32, checked in by chronos, 6 months ago
  • Modified: Removed U prefix from units names.
  • Modified: Use TFormEx for all forms.
File size: 4.1 KB
Line 
1unit FormDatabases;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 Menus, ActnList, DbEngine, FormEx;
8
9type
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
47implementation
48
49{$R *.lfm}
50
51uses
52 FormConnect;
53
54resourcestring
55 SRemoveDatabaseConnection = 'Remove database connection';
56 SRemoveDatabaseConnectionQuery = 'Do you want to really remove database connection %s?';
57 SNewDatabase = 'New database';
58
59{ TFormDatabases }
60
61procedure TFormDatabases.ListView1DblClick(Sender: TObject);
62begin
63 AOpen.Execute;
64end;
65
66procedure TFormDatabases.AOpenExecute(Sender: TObject);
67begin
68 if Assigned(ListView1.Selected) then begin
69 SelectedProfile := TDbConnectProfile(ListView1.Selected.Data);
70 ModalResult := mrOk;
71 end;
72end;
73
74procedure TFormDatabases.ARemoveExecute(Sender: TObject);
75begin
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;
83end;
84
85procedure TFormDatabases.AAddExecute(Sender: TObject);
86var
87 NewConnectProfile: TDbConnectProfile;
88begin
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;
103end;
104
105procedure TFormDatabases.AModifyExecute(Sender: TObject);
106begin
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;
121end;
122
123procedure TFormDatabases.FormShow(Sender: TObject);
124var
125 I: Integer;
126begin
127 for I := 0 to ToolBar1.ButtonCount - 1 do
128 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
129 ReloadList;
130end;
131
132procedure TFormDatabases.ListView1Data(Sender: TObject; Item: TListItem);
133begin
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
141end;
142
143procedure TFormDatabases.ListView1SelectItem(Sender: TObject; Item: TListItem;
144 Selected: Boolean);
145begin
146 UpdateInterface;
147end;
148
149procedure TFormDatabases.ReloadList;
150begin
151 ListView1.Items.Count := DbManager.ConnectProfiles.Count;
152 ListView1.Repaint;
153 UpdateInterface;
154end;
155
156procedure TFormDatabases.UpdateInterface;
157begin
158 AModify.Enabled := Assigned(ListView1.Selected);
159 ARemove.Enabled := Assigned(ListView1.Selected);
160 AOpen.Enabled := Assigned(ListView1.Selected);
161end;
162
163end.
164
Note: See TracBrowser for help on using the repository browser.