-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmuStart.pas
175 lines (139 loc) · 6.68 KB
/
fmuStart.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
unit fmuStart;
interface
uses
IBX.IBDatabase,
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.Buttons,
pafOtherFunction
;
type
TfmStart = class(TForm)
PageControl1: TPageControl;
TabEnter: TTabSheet;
BitBtn1: TBitBtn;
GroupBoxUser: TGroupBox;
ComboBoxUser: TComboBox;
GroupBoxPassword: TGroupBox;
EditPassword: TEdit;
TabDatabase: TTabSheet;
GroupBoxDatabasePath: TGroupBox;
EditDatabasePath: TEdit;
GroupBoxDatabaseLogin: TGroupBox;
EditDatabaseLogin: TEdit;
GroupBoxDatabasePassword: TGroupBox;
EditDatabasePassword: TEdit;
GroupBoxDatabaseIPaddress: TGroupBox;
EditDatabaseIPaddress: TEdit;
BitBtnSaveDatabase: TBitBtn;
TaskDialog1: TTaskDialog;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtnSaveDatabaseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fmStart: TfmStart;
implementation
uses System.Generics.Collections, //TDictionary
pafDatabase,
gVariables,
gVariablesLang,
pafLang, rtti,
pafIni
;
{$R *.dfm}
//******************************************************************************
//Ñîçäàåì ôàéë êîíôèãóðàöèè ïðîãðàììû ñ äåôîëòíûìè íàñòðîéêàìè
//******************************************************************************
function fCreateConfigFileWithDefaultSetings(varFile:string):boolean;
begin
Write_ini_str('GLOBAL', 'LANG', 'RUS', varFile);
Write_ini_str('DATABASE', 'PATH', ExtractFilePath(paramstr(0)) + 'base.fdb', varFile); //ïóòü äî ÁÄ
Write_ini_str('DATABASE', 'LOGIN', 'SYSDBA', varFile);
Write_ini_str('DATABASE', 'PASSWORD', 'masterkey', varFile);
Write_ini_str('DATABASE', 'IPADDRESS','127.0.0.1', varFile);
end;
//******************************************************************************
//******************************************************************************
procedure TfmStart.BitBtn1Click(Sender: TObject);
var
varControl:Tcontrol;
begin
{ gvarLangIni.Add('sdff', 'sdf');
gvarLangIni.Add('xcv', 'ggff') ;
gvarLangIni.Add('ghr', 'bnbn') ;
showmessage(gvarLangIni.Items['xcv']); }
// if gvarLangIni.ContainsKey('xcv') then
try
except
on E:Exception do
end;
end;
procedure TfmStart.BitBtnSaveDatabaseClick(Sender: TObject);
var
varErrMessage: RResult;
label
varGoToLabel1;
begin
inttostr(8) ;
gvarDatabaseParams.Path := EditDatabasePath.Text;
gvarDatabaseParams.Login := EditDatabaseLogin.Text;
gvarDatabaseParams.Password := EditDatabasePassword.Text;
gvarDatabaseParams.IP := EditDatabaseIPaddress.Text;
Write_ini_str('DATABASE', 'PATH', gvarDatabaseParams.Path, gvarPathConfigIni); //ïóòü äî ÁÄ
Write_ini_str('DATABASE', 'LOGIN', gvarDatabaseParams.Login, gvarPathConfigIni);
Write_ini_str('DATABASE', 'PASSWORD', gvarDatabaseParams.Password, gvarPathConfigIni);
Write_ini_str('DATABASE', 'IPADDRESS',gvarDatabaseParams.IP, gvarPathConfigIni);
gvarDatabaseParams.create:=true; //óêàçûâàåì ÷òî ìû íå ñîçäàåì ÁÄ
varGoToLabel1: //ìåòêà äëÿ GoTo
varErrMessage := fCreateIBDatabase(gIBDatabase, gvarDatabaseParams); //èíèöèàëèçèðóåì IBDatabase
if not varErrMessage.status then //åñëè íå ñìîãëè ñîçäàòü îáúåêò
with CreateTTaskDialog(varErrMessage) do //âûâîäèì äèàëîãîâå îêíî ñ ïðåäëîæåíèåì ðåøèòü ïðîáëåìó
begin
if Execute then
if ModalResult = mrYes then //òóò åñëè ìû íàæàëè äà ñîçäàòü ÁÄ
begin
gvarDatabaseParams.create:=true; //óêàçûâåì ÷òî íàì íàäî ñîçäàòü ÁÄ
goto varGoToLabel1 //ïåðåõîäèì íà ìåòêó
end;
end;
//ShowMessage(gIBDatabase.DatabaseName);
{
with fCreateIBDatabase(gIBDatabase, gvarDatabaseParams) do //èíèöèàëèçèðóåì IBDatabase
if not status then //åñëè íå ñìîãëè
CreateTTaskDialog();
showmessage(varMessage + #10#13 + #10#13 + errClass + #10#13 + #10#13 + errMessage); //âûâîäèì ïðè÷èíó îøèáêè
}
end;
procedure TfmStart.FormCreate(Sender: TObject);
begin
//ñòàðò ïðîãðàììû è òóò äåëàåì ïðîâåðêó
gvarLangIni:= TDictionary<String,String>.create; //ñîçäàåì ñëîâàðü äëÿ íàáîðà ïåðåâîäà ÿçûêà ïðîãðàììû
gvarPathApp := ExtractFilePath(paramstr(0)); //ïóòü äî ïàïêè ñ ïðîãðàììîé
gvarPathConfigIni := gvarPathApp + 'config.ini'; //óêàçûâàåì ïóòü äî ôàéëà ñ íàñòðîéêàìè ïðîãðàììû config.ini
if not FileExists(gvarPathConfigIni) then //ïðîâåðÿåì ñóùåñòâîâàíèå ôàéëà config.ini
begin
fCreateConfigFileWithDefaultSetings(gvarPathConfigIni); //ñîçäàåì ôàéë êîíôèãóðàöèè ñ äåôîëòíûìè íàñòðîéêàìè
end;
if not DirectoryExists(gvarPathApp + 'Lang') then //åñëè ïàïêà ñ ÿçûêîâûìè ôàéëàìè íå ñóùåñòâóåò òî //åñëè ïàïêè íåòó
if CreateDir(gvarPathApp + 'Lang') then //ñîçäàåì ïàïêó
begin
fCreateLangIniFiles(gvarPathApp + 'Lang'); //ñîçäàåì ôàéëû ini ñ ÿçûêàìè RUS è ENG
end;
gvarLANG := Read_ini_str('GLOBAL','LANG',gvarPathConfigIni); //ïîëó÷àåì ÿçûê ïðîãðàììû
fReadIniToVariable(gvarPathApp + 'Lang', gvarLANG) ; //çàãðóæàåì ÿçûê â ãëîáàëüíóþ ïåðåìåííóþ
//ñ÷èòûâàåì íàñòðîéêè ïîäêëþ÷åíèÿ ê ÁÄ + çàíîñèì èõ íà ôîðìó
gvarDatabaseParams.Path := Read_ini_str('DATABASE', 'PATH', gvarPathConfigIni); //ïóòü äî ÁÄ
gvarDatabaseParams.Login := Read_ini_str('DATABASE', 'LOGIN', gvarPathConfigIni);
gvarDatabaseParams.Password := Read_ini_str('DATABASE', 'PASSWORD', gvarPathConfigIni);
gvarDatabaseParams.IP := Read_ini_str('DATABASE', 'IPADDRESS',gvarPathConfigIni);
EditDatabasePath.Text := gvarDatabaseParams.Path;
EditDatabaseLogin.Text := gvarDatabaseParams.Login;
EditDatabasePassword.Text := gvarDatabaseParams.Password;
EditDatabaseIPaddress.Text := gvarDatabaseParams.IP;
fSetLangToForm(fmstart.Name, fmstart); //äåëàåì ïåðåâîä ïðîãðàììû (äàííîé ôîðìû)
end;
end.