ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/IBDatabaseEdit.pas
Revision: 5
Committed: Fri Feb 18 16:26:16 2011 UTC (13 years, 8 months ago) by tony
Content type: text/x-pascal
File size: 10858 byte(s)
Log Message:
Committing updates for Release pre-release

File Contents

# User Rev Content
1 tony 1 {************************************************************************}
2     { }
3     { Borland Delphi Visual Component Library }
4     { InterBase Express core components }
5     { }
6     { Copyright (c) 1998-2000 Inprise Corporation }
7     { }
8     { InterBase Express is based in part on the product }
9     { Free IB Components, written by Gregory H. Deatz for }
10     { Hoagland, Longo, Moran, Dunst & Doukas Company. }
11     { Free IB Components is used under license. }
12     { }
13     { The contents of this file are subject to the InterBase }
14     { Public License Version 1.0 (the "License"); you may not }
15     { use this file except in compliance with the License. You }
16     { may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17     { Software distributed under the License is distributed on }
18     { an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
19     { express or implied. See the License for the specific language }
20     { governing rights and limitations under the License. }
21     { The Original Code was created by InterBase Software Corporation }
22     { and its successors. }
23     { Portions created by Inprise Corporation are Copyright (C) Inprise }
24     { Corporation. All Rights Reserved. }
25     { Contributor(s): Jeff Overcash }
26     { }
27     {************************************************************************}
28    
29     unit IBDatabaseEdit;
30    
31 tony 5 {$MODE Delphi} {$H-}
32    
33 tony 1 interface
34    
35     uses
36 tony 5 {Windows,} Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
37     StdCtrls, ExtCtrls, IBDataBase, IB, IBXConst, LResources;
38 tony 1
39     type
40 tony 5
41     { TIBDatabaseEditForm }
42    
43 tony 1 TIBDatabaseEditForm = class(TForm)
44     Panel1: TPanel;
45     DatabaseName: TEdit;
46     Label1: TLabel;
47     LocalRbtn: TRadioButton;
48     RemoteRbtn: TRadioButton;
49     Browse: TButton;
50     GroupBox1: TGroupBox;
51     UserName: TEdit;
52     Password: TEdit;
53     SQLRole: TEdit;
54     Label2: TLabel;
55     Label3: TLabel;
56     Label4: TLabel;
57     DatabaseParams: TMemo;
58     OKBtn: TButton;
59     CancelBtn: TButton;
60     HelpBtn: TButton;
61     Label5: TLabel;
62     LoginPrompt: TCheckBox;
63     Label6: TLabel;
64     CharacterSet: TComboBox;
65     ServerName: TEdit;
66     Protocol: TComboBox;
67     Label7: TLabel;
68     Label8: TLabel;
69     Test: TButton;
70 tony 5 procedure CharacterSetCloseUp(Sender: TObject);
71 tony 1 procedure RemoteRbtnClick(Sender: TObject);
72     procedure BrowseClick(Sender: TObject);
73     procedure LocalRbtnClick(Sender: TObject);
74     procedure OKBtnClick(Sender: TObject);
75     procedure FormCreate(Sender: TObject);
76     procedure HelpBtnClick(Sender: TObject);
77     procedure UserNameChange(Sender: TObject);
78     procedure PasswordChange(Sender: TObject);
79     procedure SQLRoleChange(Sender: TObject);
80     procedure CharacterSetChange(Sender: TObject);
81     procedure TestClick(Sender: TObject);
82     private
83     { Private declarations }
84     Database: TIBDatabase;
85     function Edit: Boolean;
86     function GetParam(Name: string): string;
87     procedure AddParam(Name, Value: string);
88     procedure DeleteParam(Name: string);
89     public
90     { Public declarations }
91     end;
92    
93     var
94     IBDatabaseEditForm: TIBDatabaseEditForm;
95    
96     function EditIBDatabase(ADatabase: TIBDatabase): Boolean;
97    
98     implementation
99    
100    
101 tony 5 uses {LibHelp,} TypInfo;
102 tony 1
103     function EditIBDatabase(ADatabase: TIBDatabase): Boolean;
104     begin
105     with TIBDatabaseEditForm.Create(Application) do
106     try
107     Database := ADatabase;
108     Result := Edit;
109     finally
110     Free;
111     end;
112     end;
113    
114     function TIBDatabaseEditForm.GetParam(Name: string): string;
115     var
116     i: Integer;
117     begin
118     Result := '';
119     for i := 0 to DatabaseParams.Lines.Count - 1 do
120     begin
121     if (Pos(Name, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok}
122     begin
123     Result := DatabaseParams.Lines.Values[DatabaseParams.Lines.Names[i]];
124     break;
125     end;
126     end;
127     end;
128    
129     procedure TIBDatabaseEditForm.AddParam(Name, Value: string);
130     var
131     i: Integer;
132     found: boolean;
133     begin
134     found := False;
135     if Trim(Value) <> '' then
136     begin
137     for i := 0 to DatabaseParams.Lines.Count - 1 do
138     begin
139     if (Pos(Name, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok}
140     begin
141     DatabaseParams.Lines.Values[DatabaseParams.Lines.Names[i]] := Value;
142     found := True;
143     break;
144     end;
145     end;
146     if not found then
147     DatabaseParams.Lines.Add(Name + '=' + Value);
148     end
149     else
150     DeleteParam(Name);
151     end;
152    
153     procedure TIBDatabaseEditForm.DeleteParam(Name: string);
154     var
155     i: Integer;
156     begin
157     for i := 0 to DatabaseParams.Lines.Count - 1 do
158     begin
159     if (Pos(Name, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok}
160     begin
161     DatabaseParams.Lines.Delete(i);
162     break;
163     end;
164     end;
165     end;
166    
167     function TIBDatabaseEditForm.Edit: Boolean;
168     var
169     st: string;
170    
171     procedure DecomposeDatabaseName;
172     var
173     Idx1, Idx2: Integer;
174     st: string;
175     begin
176     if Pos('\\', Database.DatabaseName) <> 0 then {do not localize}
177     begin
178     LocalRBtn.Checked := False;
179     RemoteRbtn.Checked := True;
180     Protocol.ItemIndex := 1;
181     st := copy(Database.DatabaseName, 3, Length(Database.DatabaseName));
182     Idx1 := Pos('\', st); {do not localize}
183     if Idx1 = 0 then
184     IBError(ibxeUnknownError, [nil])
185     else begin
186     ServerName.Text := Copy(st, 1, Idx1 - 1);
187     DatabaseName.Text:= Copy(st, Idx1 + 1, Length(st));
188     end;
189     end
190     else begin
191     Idx1 := Pos(':', Database.DatabaseName ); {do not localize}
192     If (Idx1 = 0) or (Idx1 = 2) then
193     begin
194     DatabaseName.Text := Database.DatabaseName;
195     end
196     else
197     begin
198     LocalRBtn.Checked := False;
199     RemoteRbtn.Checked := True;
200     Idx2 := Pos('@', Database.DatabaseName); {do not localize}
201     if Idx2 = 0 then
202     begin
203     Protocol.ItemIndex := 0;
204     ServerName.Text := copy(Database.DatabaseName, 1, Idx1 - 1);
205     DatabaseName.Text := copy(Database.DatabaseName, Idx1 + 1,
206     Length(Database.DatabaseName));
207     end
208     else begin
209     Protocol.ItemIndex := 2;
210     ServerName.Text := copy(Database.DatabaseName, 1, Idx2 - 1);
211     DatabaseName.Text := copy(Database.DatabaseName, Idx2 + 1,
212     Length(Database.DatabaseName));
213     end;
214     end;
215     end;
216     end;
217     begin
218     DecomposeDatabaseName;
219     DatabaseParams.Lines := Database.Params;
220     LoginPrompt.Checked := Database.LoginPrompt;
221     UserName.Text := GetParam('user_name');
222     Password.Text := GetParam('password');
223     SQLRole.Text := GetParam('sql_role');
224     st := GetParam('lc_ctype');
225     if (st <> '') then
226     CharacterSet.ItemIndex := CharacterSet.Items.IndexOf(st);
227     Result := False;
228     if ShowModal = mrOk then
229     begin
230     Database.DatabaseName := DatabaseName.Text;
231     if LocalRbtn.Checked then
232     DatabaseName.Text := Database.DatabaseName
233     else
234     case Protocol.ItemIndex of
235     0: Database.DatabaseName := Format('%s:%s', [ServerName.Text, DatabaseName.Text]); {do not localize}
236     1: Database.DatabaseName := Format('\\%s\%s', [ServerName.Text, DatabaseName.Text]); {do not localize}
237     2: Database.DatabaseName := Format('%s@%s', [ServerName.Text, DatabaseName.Text]); {do not localize}
238     end;
239     Database.Params := DatabaseParams.Lines;
240     Database.LoginPrompt := LoginPrompt.Checked;
241     Result := True;
242     end;
243     end;
244    
245     procedure TIBDatabaseEditForm.RemoteRbtnClick(Sender: TObject);
246     begin
247     Browse.Enabled := False;
248     Label7.Enabled := True;
249     Label8.Enabled := True;
250     Protocol.Enabled := True;
251     ServerName.Enabled := True;
252     end;
253    
254 tony 5 procedure TIBDatabaseEditForm.CharacterSetCloseUp(Sender: TObject);
255     begin
256     if (CharacterSet.Text <> 'None') then {do not localize}
257     AddParam('lc_ctype', CharacterSet.Text)
258     else
259     DeleteParam('lc_ctype');
260    
261     end;
262    
263 tony 1 procedure TIBDatabaseEditForm.BrowseClick(Sender: TObject);
264     begin
265     with TOpenDialog.Create(Application) do
266     try
267     InitialDir := ExtractFilePath(DatabaseName.Text);
268     Filter := SDatabaseFilter;
269     if Execute then
270     DatabaseName.Text := FileName;
271     finally
272     Free
273     end;
274     end;
275    
276     procedure TIBDatabaseEditForm.LocalRbtnClick(Sender: TObject);
277     begin
278     Browse.Enabled := True;
279     Label7.Enabled := False;
280     Label8.Enabled := False;
281     ServerName.Enabled := False;
282     Protocol.Enabled := False;
283     end;
284    
285     procedure TIBDatabaseEditForm.OKBtnClick(Sender: TObject);
286     begin
287     ModalResult := mrNone;
288     if Database.Connected then
289     begin
290     if MessageDlg(SDisconnectDatabase, mtConfirmation,
291     mbOkCancel, 0) <> mrOk then Exit;
292     Database.Close;
293     end;
294     ModalResult := mrOk;
295     end;
296    
297     procedure TIBDatabaseEditForm.FormCreate(Sender: TObject);
298     begin
299 tony 5 // HelpContext := hcDIBDataBaseEdit;
300 tony 1 end;
301    
302     procedure TIBDatabaseEditForm.HelpBtnClick(Sender: TObject);
303     begin
304     Application.HelpContext(HelpContext);
305     end;
306    
307     procedure TIBDatabaseEditForm.UserNameChange(Sender: TObject);
308     begin
309     AddParam('user_name', UserName.Text);
310     end;
311    
312     procedure TIBDatabaseEditForm.PasswordChange(Sender: TObject);
313     begin
314     AddParam('password', Password.Text);
315     end;
316    
317     procedure TIBDatabaseEditForm.SQLRoleChange(Sender: TObject);
318     begin
319     AddParam('sql_role_name', SQLRole.Text);
320     end;
321    
322     procedure TIBDatabaseEditForm.CharacterSetChange(Sender: TObject);
323     begin
324 tony 5 ShowMessage(CharacterSet.Text);
325 tony 1 if (CharacterSet.Text <> 'None') then {do not localize}
326     AddParam('lc_ctype', CharacterSet.Text)
327     else
328     DeleteParam('lc_ctype');
329     end;
330    
331     procedure TIBDatabaseEditForm.TestClick(Sender: TObject);
332     var
333     tempDB : TIBDatabase;
334     begin
335     Test.Enabled := false;
336     tempDB := TIBDatabase.Create(nil);
337     try
338     if LocalRbtn.Checked then
339     tempDB.DatabaseName := DatabaseName.Text
340     else
341     case Protocol.ItemIndex of
342     0: tempDB.DatabaseName := Format('%s:%s', [ServerName.Text, DatabaseName.Text]); {do not localize}
343     1: tempDB.DatabaseName := Format('\\%s\%s', [ServerName.Text, DatabaseName.Text]); {do not localize}
344     2: tempDB.DatabaseName := Format('%s@%s', [ServerName.Text, DatabaseName.Text]); {do not localize}
345     end;
346     tempDB.Params.Assign(DatabaseParams.Lines);
347     tempDB.LoginPrompt := LoginPrompt.Checked;
348     tempDB.Connected := true;
349     ShowMessage('Successful Connection');
350     finally
351     tempDB.Free;
352     Test.Enabled := true;
353     end;
354     end;
355    
356 tony 5 initialization
357     {$i IBDatabaseEdit.lrs}
358    
359 tony 1 end.