-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionsModule.pas
executable file
·250 lines (220 loc) · 6.94 KB
/
OptionsModule.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
unit OptionsModule;
interface
uses
Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, Registry,
HeliumDataMgmt;
type
TModuleOptionForm = class(TForm)
addressLab: TLabel;
dNameLab: TLabel;
nameEd: TEdit;
addressCoBox: TComboBox;
curLab: TLabel;
newLab: TLabel;
cVoltMaxEd: TEdit;
cVoltMinEd: TEdit;
uVoltMaxEd: TEdit;
uVoltMinEd: TEdit;
VoltMaxChBox: TCheckBox;
VoltMinChBox: TCheckBox;
cVoltAlarmEd: TEdit;
uVoltAlarmEd: TEdit;
VoltAlarmBox: TCheckBox;
AcceptBtn: TButton;
DiscardBtn: TButton;
CancelBtn: TButton;
cVoltMaxLab: TLabel;
cVoltMinLab: TLabel;
cVoltAlarmLab: TLabel;
procedure addressCoBoxChange(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure DiscardBtnClick(Sender: TObject);
procedure AcceptBtnClick(Sender: TObject);
private
FDataMgmt: TDataMgmt;
id: integer;
procedure getNameList;
procedure clearAll;
function lastItem: boolean;
function fillParams: boolean;
public
constructor CreateWithProperties(ADataMgmt: TDataMgmt; AOwner: TComponent);
end;
implementation
uses HeliumFunctions;
{$R *.dfm}
constructor TModuleOptionForm.CreateWithProperties(ADataMgmt: TDataMgmt; AOwner: TComponent);
begin
create(AOwner);
FDataMgmt := ADataMgmt;
getNameList;
if (addressCoBox.Items.Count = 0) then
MessageDlg('There are no modified Module Options!', mtWarning, [mbOK], 0);
end;
procedure TModuleOptionForm.getNameList;
var LReg: TRegistry;
begin
addressCoBox.Clear;
addressCoBox.Text := 'select ...';
LReg := TRegistry.Create;
LReg.RootKey := HKEY_CURRENT_USER;
if LReg.KeyExists('Software\HZB_Helium\New_ModOptions\') then
try LReg.OpenKey('Software\HZB_Helium\New_ModOptions\', false);
LReg.GetKeyNames(addressCoBox.Items);
finally LReg.CloseKey;
end;
LReg.Free;
end;
procedure TModuleOptionForm.clearAll;
begin
id := 0;
nameEd.Text := '';
cVoltMaxEd.Text := '';
cVoltMinEd.Text := '';
cVoltAlarmEd.Text := '';
uVoltMaxEd.Text := '';
uVoltMinEd.Text := '';
uVoltAlarmEd.Text := '';
VoltMaxChBox.Checked := false;
VoltMinChBox.Checked := false;
VoltAlarmBox.Checked := false;
end;
function TModuleOptionForm.lastItem: boolean;
begin
Result := (addressCoBox.Items.Count = 0);
if Result then ModalResult := mrOk;
end;
function TModuleOptionForm.fillParams: boolean;
var LReg: TRegistry;
LModule: TModule;
begin
Result := false;
with FDataMgmt do
try
LockWhileWorkingWithList;
LModule := GetModItemByAddr(addressCoBox.Text);
if Assigned(LModule) then
begin
id := LModule.mod_id;
nameEd.Text := LModule.mod_name;
cVoltMaxEd.Text := floatToStr(LModule.mod_maxvoltage);
cVoltMinEd.Text := floatToStr(LModule.mod_minvoltage);
cVoltAlarmEd.Text := intToStr(LModule.mod_criticvoltage);
end;
finally
UnlockAfterWorkingWithList;
end;
if (id > 0) then
try
LReg := TRegistry.Create;
LReg.RootKey := HKEY_CURRENT_USER;
if LReg.KeyExists('Software\HZB_Helium\New_ModOptions\' + addressCoBox.Text + '\') then
try
LReg.OpenKey('Software\HZB_Helium\New_ModOptions\' + addressCoBox.Text + '\', false);
// Max Voltage
if LReg.ValueExists('voltage_max') then
begin
uVoltMaxEd.Text := floattostr(LReg.ReadFloat('voltage_max'));
VoltMaxChBox.Checked := true;
Result := true;
end;
// Min Voltage
if LReg.ValueExists('voltage_min') then
begin
uVoltMinEd.Text := floattostr(LReg.ReadFloat('voltage_min'));
VoltMinChBox.Checked := true;
Result := true;
end;
// Alarm Voltage
if LReg.ValueExists('voltage_alarm') then
begin
uVoltAlarmEd.Text := inttostr(LReg.ReadInteger('voltage_alarm'));
VoltAlarmBox.Checked := true;
Result := true;
end;
finally LReg.CloseKey;
end;
LReg.Free;
finally
end;
end;
procedure TModuleOptionForm.addressCoBoxChange(Sender: TObject);
begin
if (addressCoBox.ItemIndex > -1) then
begin
clearAll;
if not fillParams then
MessageDlg('No changed parameters for this Vessel!', mtWarning, [mbOK], 0);
end
else
addressCoBox.Text := 'select ...';
end;
procedure TModuleOptionForm.AcceptBtnClick(Sender: TObject);
var LModule: TModule;
s: string;
begin
s := '';
if (addressCoBox.ItemIndex > -1) and (id > 0) then
if (MessageDlg('Do you really want to save the marked Option Change(s) of Module ' + nameEd.Text + '?', mtCustom, [mbYes, mbNo], 0) = mrYes) then
begin
// Max Voltage
if VoltMaxChBox.checked
then s := 'MOD_MAXVOLTAGE = ' + StringReplace(uVoltMaxEd.Text, DecimalSeparator, '.', [rfReplaceAll]);
// Min Voltage
if VoltMinChBox.checked then
if (s = '')
then s := 'MOD_MINVOLTAGE = ' + StringReplace(uVoltMinEd.Text, DecimalSeparator, '.', [rfReplaceAll])
else s := s + ', MOD_MINVOLTAGE = ' + StringReplace(uVoltMinEd.Text, DecimalSeparator, '.', [rfReplaceAll]);
// Critical Voltage
if VoltAlarmBox.checked then
if (s = '')
then s := 'MOD_CRITICALVOLTAGE = ' + uVoltAlarmEd.Text
else s := s + ', MOD_CRITICALVOLTAGE = ' + uVoltAlarmEd.Text;
end;
if not (s = '') then
begin
deleteKey('Software\HZB_Helium\New_ModOptions\' + addressCoBox.Text);
addressCoBox.DeleteSelected;
with FDataMgmt do
try
LockWhileWorkingWithList;
LModule := GetModItem(id);
if Assigned(LModule) then
begin
if VoltMaxChBox.checked
then LModule.mod_maxvoltage := strToFloat(uVoltMaxEd.Text);
if VoltMinChBox.checked
then LModule.mod_minvoltage := strToFloat(uVoltMinEd.Text);
if VoltAlarmBox.checked
then LModule.mod_criticvoltage := strToInt(uVoltAlarmEd.Text);
end;
SqlCommand('UPDATE ' + db_t_module + ' SET ' + s + ' WHERE MOD_ID = ' + intToStr(id));
finally
UnlockAfterWorkingWithList;
end;
if not lastItem then
begin
clearAll;
addressCoBox.Text := 'select ...';
end;
end;
end;
procedure TModuleOptionForm.DiscardBtnClick(Sender: TObject);
begin
if (addressCoBox.ItemIndex > -1) then
if (MessageDlg('Do you really want to discard the Option Change(s) of Module ' + nameEd.Text + '?', mtCustom, [mbYes, mbNo], 0) = mrYes) then
begin
deleteKey('Software\HZB_Helium\New_ModOptions\' + addressCoBox.Text);
addressCoBox.DeleteSelected;
if not lastItem then
begin
clearAll;
addressCoBox.Text := 'select ...';
end;
end;
end;
procedure TModuleOptionForm.CancelBtnClick(Sender: TObject);
begin
if not lastItem then ModalResult := mrCancel;
end;
end.