-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_options.pas
266 lines (226 loc) · 8.68 KB
/
connection_options.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
unit connection_options;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, routine_strings, xmldom, XMLIntf, msxmldom, XMLDoc,
sButton, sCheckBox, sEdit, sLabel, sGroupBox, IdBaseComponent, IdComponent,
IdRawBase, IdRawClient, IdIcmpClient, dxBevel, Menus, JvMenus, JvExControls,
JvSpeedButton, Mask, AdvDropDown, AdvCustomGridDropDown, AdvGridDropDown, DB,
SqlExpr, ComObj, FMTBcd, DBXMSSQL;
type
Tconnection_options_form = class(TForm)
XMLDocument: TXMLDocument;
connect_btn: TsButton;
Button1: TsButton;
IdIcmpClient1: TIdIcmpClient;
CheckBox1: TsCheckBox;
cmb_remember_password: TsCheckBox;
autologon_box: TsCheckBox;
label_connected: TsLabel;
login_edit: TsEdit;
db_edit: TsEdit;
pc_edit: TsEdit;
dxBevel1: TdxBevel;
Image1: TImage;
JvSpeedButton1: TJvSpeedButton;
local_config_popup: TJvPopupMenu;
SQLConnection: TSQLConnection;
SQLQuery: TSQLQuery;
pass_edit: TsEdit;
db_params_delphi7: TMemo;
procedure connect_btnClick(Sender: TObject);
procedure pass_editKeyPress(Sender: TObject; var Key: Char);
procedure db_editKeyPress(Sender: TObject; var Key: Char);
procedure pc_editKeyPress(Sender: TObject; var Key: Char);
procedure login_editKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure autologon_boxClick(Sender: TObject);
procedure cmb_remember_passwordClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SelectConfigDatabase( Sender:TObject );
private
procedure ConnectToDirectumApplication;
{ Private declarations }
public
procedure OnRun();
procedure ConnectToDB();
{ Public declarations }
end;
var
connection_options_form: Tconnection_options_form;
servers:TStringList;
implementation
{$R *.dfm}
uses main;
function IPExists(IPAddr: String): Bool;
var
I: TIdIcmpClient;
Rec: Integer;
begin
Result:= False;
I:= TIdIcmpClient.Create(nil);
try
I.Host:= IPAddr;
I.Ping();
Sleep(2000);
Rec:= I.ReplyStatus.BytesReceived;
if Rec > 0 then Result:= True else Result:= False;
finally
I.Free;
end;
end;
procedure Tconnection_options_form.SelectConfigDatabase( Sender:TObject );
begin
pc_edit.Text := TRIM( SubString( ( Sender as TMenuItem ).Caption, 'íà', 2 ) );
db_edit.Text := SubString( ( Sender as TMenuItem ).Caption, 'íà', 1 );
db_edit.Text := TRIM(db_edit.Text);
db_edit.Text := Replace( db_edit.Text, '&', '')
end;
procedure Tconnection_options_form.OnRun();
var
i : integer;
Settings : IXMLNode;
Configurations : IXMLNode;
SettingGroup : IXMLNode;
menu_item : TMenuItem;
begin
login_edit.Text := configuration.ReadString('auth', 'login',login_edit.Text);
pass_edit.Text := configuration.ReadString('auth', 'pass', pass_edit.Text);
pc_edit.Text := configuration.ReadString('connection', 'pc', pc_edit.Text );
db_edit.Text := configuration.ReadString('connection', 'db', db_edit.Text );
cmb_remember_password.Checked := configuration.ReadBool('auth', 'remember_me', cmb_remember_password.checked );
autologon_box.Checked := configuration.ReadBool('auth', 'auto_connect', autologon_box.checked );
//Çàïîëíèòü âûáîð áàçû äàííûõ âîçìîæíûìè âàðèàíòàìè---------------------------
if FileExists( path_to_configurations_xml ) then
begin
XMLDocument.FileName := path_to_configurations_xml;
XMLDocument.LoadFromFile( path_to_configurations_xml );
Settings := XMLDocument.ChildNodes.Get(1);
Configurations := Settings.ChildNodes.Get(0);
servers.Clear;
for i:=0 to Configurations.ChildNodes.COunt - 1 do
begin
SettingGroup := Configurations.ChildNodes.Get( i );
servers.Add( SettingGroup.AttributeNodes['Server'].Text );
menu_item := TMenuItem.Create( local_config_popup );
menu_item.Caption := SettingGroup.AttributeNodes['Database'].Text + ' íà ' + SettingGroup.AttributeNodes['Server'].Text;
menu_item.OnClick := SelectConfigDatabase;
local_config_popup.Items.Add( menu_item );
end;
end;
//----------------------------------------------------------------------------
if autologon_box.Checked then
begin
IdIcmpClient1.Host := pc_edit.Text;
IdIcmpClient1.Ping();
if idICMPClient1.ReplyStatus.BytesReceived <> 0 then
connect_btn.Click;
end;
end;
procedure Tconnection_options_form.ConnectToDB();
var
connection_string:string;
begin
if StringAssigned( login_edit.Text ) and StringAssigned( db_edit.Text ) and StringAssigned( pc_edit.Text ) then
begin
configuration.WriteString('auth', 'login',login_edit.Text);
if cmb_remember_password.Checked then
configuration.WriteString('auth', 'pass', pass_edit.Text)
else
configuration.WriteString('auth', 'pass', '' );
configuration.WriteString('connection', 'pc', pc_edit.Text );
configuration.WriteString('connection', 'db', db_edit.Text );
configuration.WriteString('host', 'station', current_computer_name );
sqlconnection.Connected := false;
sqlconnection.Params.Clear;
sqlconnection.Params.AddStrings( db_params_delphi7.Lines );
sqlconnection.Params.ValueFromIndex[ sqlconnection.Params.IndexOfName('DataBase') ] := db_edit.Text;
sqlconnection.Params.ValueFromIndex[ sqlconnection.Params.IndexOfName('User_Name') ] := login_edit.Text;
sqlconnection.Params.ValueFromIndex[ sqlconnection.Params.IndexOfName('Password') ] := pass_edit.Text;
sqlconnection.Params.ValueFromIndex[ sqlconnection.Params.IndexOfName('HostName') ] := pc_edit.Text;
try
configuration.WriteString('auth','last_time_connect_attempt','1');
sqlconnection.Connected := true;
except
on E : Exception do
begin
sqlconnection.connected := false;
configuration.WriteString('auth','last_time_connect_attempt','0');
ShowMessage( E.Message );
end;
end;
end;
end;
procedure Tconnection_options_form.connect_btnClick(Sender: TObject);
var
ConnectionParams : string;
begin
if StringAssigned( login_edit.Text ) and
StringAssigned( db_edit.Text ) and
StringAssigned( pc_edit.Text ) then
begin
ConnectToDB();
if sqlconnection.Connected then
begin
label_connected.Caption := 'Ñîñòîÿíèå: ïîäêëþ÷åíû';
ConnectToDirectumApplication();
Close();
end
end
else
ShowMessage('Çàïîëíåíû íå âñå ïîëÿ àâòîðèçàöèè');
end;
procedure Tconnection_options_form.pass_editKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = #13 then connect_btn.Click;
end;
procedure Tconnection_options_form.db_editKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = #13 then login_edit.SetFocus;
end;
procedure Tconnection_options_form.pc_editKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = #13 then db_edit.SetFocus;
end;
procedure Tconnection_options_form.login_editKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = #13 then pass_edit.SetFocus;
end;
procedure Tconnection_options_form.autologon_boxClick(Sender: TObject);
begin
configuration.WriteBool('auth', 'auto_connect', autologon_box.Checked );
end;
procedure Tconnection_options_form.Button1Click(Sender: TObject);
begin
close;
end;
procedure Tconnection_options_form.cmb_remember_passwordClick(Sender: TObject);
begin
configuration.WriteBool('auth', 'remember_me', cmb_remember_password.Checked );
end;
procedure Tconnection_options_form.ConnectToDirectumApplication;
var
ConnectionParams: string;
begin
ConnectionParams := 'ServerName=%s;DBName=%s;UserName=%s;Password=%s';
ConnectionParams := Format( ConnectionParams, [ pc_edit.Text,db_edit.Text,login_edit.Text,pass_edit.Text] );
directumLoginPoint := CreateOleObject( 'SBLogon.LoginPoint' ); // ILoginPoint
DirectumApplication := directumLoginPoint.GetApplication( ConnectionParams ); // IApplication;
end;
procedure Tconnection_options_form.FormCreate(Sender: TObject);
begin
servers := TStringList.Create();
sqlconnection.LibraryName := 'dbxmss.dll';
sqlconnection.VendorLib := 'sqlncli10.dll';
end;
procedure Tconnection_options_form.FormShow(Sender: TObject);begin
{ if sqlconnection.Connected then label_connected.Caption := 'Ñîñòîÿíèå: ïîäêëþ÷åíû'
else label_connected.Caption := 'Ñîñòîÿíèå: íå ïîäêëþ÷åíû';}
end;
end.