-
Notifications
You must be signed in to change notification settings - Fork 1
/
USetting.pas
268 lines (234 loc) · 7.21 KB
/
USetting.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
266
267
unit USetting;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, Mask, Grids;
type
TFormSetting = class(TForm)
PageControl: TPageControl;
tsFactor: TTabSheet;
tsConnect: TTabSheet;
tsShift: TTabSheet;
tsResource: TTabSheet;
btnSave: TBitBtn;
BitBtnCancel: TBitBtn;
GroupBox1: TGroupBox;
lbl1: TLabel;
lbl2: TLabel;
edtCalcInput: TEdit;
edtCalcOut: TEdit;
lbl4: TLabel;
btnCalc: TBitBtn;
GroupBox2: TGroupBox;
lbl5: TLabel;
Label1: TLabel;
edtIdOpc: TEdit;
lbl6: TLabel;
edtTegWeight: TEdit;
lbl7: TLabel;
edtTagStatus: TEdit;
lbl8: TLabel;
edtOpcRate: TEdit;
lbl9: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
grp1: TGroupBox;
lbl10: TLabel;
lbl11: TLabel;
grp2: TGroupBox;
lbl12: TLabel;
lbl13: TLabel;
ListBoxWeight: TListBox;
edtFieldRes: TEdit;
BitBtn1: TBitBtn;
BitDelete: TBitBtn;
btnEdit: TBitBtn;
edtShift1Begin: TEdit;
edtShift1End: TEdit;
edtShift2Begin: TEdit;
edtShift2End: TEdit;
edtFactor: TEdit;
edtPassageTime: TEdit;
procedure edtFloatKeyPress(Sender: TObject; var Key: Char);
procedure edtIntKeyPress(Sender: TObject; var Key: Char);
procedure btnCalcClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edtShift1Begin1Exit(Sender: TObject);
procedure edtShift1End1Exit(Sender: TObject);
procedure edtShift2Begin1Exit(Sender: TObject);
procedure edtShift2End1Exit(Sender: TObject);
procedure ListBoxWeightDblClick(Sender: TObject);
procedure BitDeleteClick(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure btnEditClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormSetting: TFormSetting;
implementation
{$R *.dfm}
uses
UConfig, UMain, Math;
procedure TFormSetting.edtFloatKeyPress(Sender: TObject; var Key: Char);
var
k: integer;
begin
if TEdit(Sender).Text = '0' then
if not (key in [',', #8]) then
key := #0;
if key in ['0'..'9', ',', #8] then
begin
if key = ',' then
begin
if TEdit(Sender).Text = '' then
key := #0;
for k := 1 to Length(TEdit(Sender).Text) do
begin
if TEdit(Sender).Text[k] = ',' then
key := #0;
end;
end;
end
else
key := #0;
end;
procedure TFormSetting.edtIntKeyPress(Sender: TObject; var Key: Char);var
k: integer;
begin
if TEdit(Sender).Text = '0' then
if not (key in [#8]) then
key := #0;
if key in ['0'..'9', #8] then
begin
if key = ',' then
begin
if TEdit(Sender).Text = '' then
key := #0;
for k := 1 to Length(TEdit(Sender).Text) do
begin
if TEdit(Sender).Text[k] = ',' then
key := #0;
end;
end;
end
else
key := #0;
end;
procedure TFormSetting.btnCalcClick(Sender: TObject);
var
tfactor: Double;
valIn : Double;
valOut : Double;
begin
tfactor:= curConfig.weightFactor;
try
valIn := StrToFloat(edtCalcInput.Text);
valOut:= StrToFloat(edtCalcOut.Text);
tfactor:= RoundTo( (valOut / ( valIn / tfactor)) , -2);
except
MessageDlg('Îøèáêà âõîäíûõ äàííûõ', mtError, [mbOK], 0);
end;
edtFactor.Text:= FloatToStr(tfactor);
end;
procedure TFormSetting.FormShow(Sender: TObject);
var
i: Integer;
begin
PageControl.ActivePageIndex := 0;
edtFactor.Text := FloatToStr(curConfig.weightFactor);
edtCalcInput.Text := '1';
edtCalcOut.Text := '1';
edtPassageTime.Text := FloatToStr(curConfig.weightPassageTime);
edtIdOpc.Text := curConfig.ServerProgId;
edtTegWeight.Text := curConfig.OPCTagWeight;
edtTagStatus.Text := curConfig.OPCTagStatus;
edtOpcRate.Text := IntToStr(curConfig.OPCUpdateRate);
edtShift1Begin.Text := IntToStr(curConfig.workShifts[0].startHour);
edtShift1End.Text := IntToStr(curConfig.workShifts[0].endHour);
edtShift2Begin.Text := IntToStr(curConfig.workShifts[1].startHour);
edtShift2End.Text := IntToStr(curConfig.workShifts[1].endHour);
ListBoxWeight.Items.Clear;
for i:=0 to Length(curConfig.weightNames) - 1 do
begin
ListBoxWeight.Items.add(curConfig.weightNames[i]);
end;
end;
procedure TFormSetting.edtShift1Begin1Exit(Sender: TObject);
begin
if StrToInt(edtShift1Begin.Text) > 23 then
edtShift1Begin.Text:= IntToStr(curConfig.workShifts[0].startHour);
end;
procedure TFormSetting.edtShift1End1Exit(Sender: TObject);
begin
if StrToInt(edtShift1End.Text) > 23 then
edtShift1End.Text:= IntToStr(curConfig.workShifts[0].endHour);
edtShift2Begin.Text := edtShift1End.Text;
end;
procedure TFormSetting.edtShift2Begin1Exit(Sender: TObject);
begin
if StrToInt(edtShift2Begin.Text) > 23 then
edtShift2Begin.Text:= IntToStr(curConfig.workShifts[1].startHour);
edtShift1End.Text := edtShift2Begin.Text;
end;
procedure TFormSetting.edtShift2End1Exit(Sender: TObject);
begin
if StrToInt(edtShift2End.Text) > 23 then
edtShift2End.Text:= IntToStr(curConfig.workShifts[1].endHour);
end;
procedure TFormSetting.ListBoxWeightDblClick(Sender: TObject);
begin
edtFieldRes.Text := ListBoxWeight.Items[ListBoxWeight.ItemIndex];
if (ListBoxWeight.Items.Count - 1) = ListBoxWeight.ItemIndex then
BitDelete.Enabled := True
else
BitDelete.Enabled := False;
end;
procedure TFormSetting.BitDeleteClick(Sender: TObject);
begin
if MessageDlg('Âíèìàíèå! Óäàëåíèå ýëåìåíòà â ñåðåäèíå èëè â íà÷àëå ñïèñêà' + #13#10 +
'ïðèâåäåò ê èçìåíåíèþ èíäåêñîâ - ñîïîñòàâëåíèå ðåñóðñà è âåñà.' + #13#10 +
'Óäàëèòü?',
mtWarning, [mbYes, mbNo], 0) = mrYes then
begin
ListBoxWeight.Items.Delete(ListBoxWeight.ItemIndex);
end;
end;
procedure TFormSetting.BitBtn1Click(Sender: TObject);
begin
ListBoxWeight.Items.add(Trim(edtFieldRes.Text));
end;
procedure TFormSetting.btnEditClick(Sender: TObject);
begin
ListBoxWeight.Items[ListBoxWeight.ItemIndex] := edtFieldRes.Text;
end;
procedure TFormSetting.btnSaveClick(Sender: TObject);
var
i: Integer;
begin
PageControl.ActivePageIndex := 0;
curConfig.weightFactor:= StrToFloat(edtFactor.Text);
curWeightData.factor:= curConfig.weightFactor;
curConfig.weightPassageTime := StrToFloat(edtPassageTime.Text);
curConfig.ServerProgId := edtIdOpc.Text;
curConfig.OPCTagWeight := edtTegWeight.Text;
curConfig.OPCTagStatus := edtTagStatus.Text;
curConfig.OPCUpdateRate := StrToInt(edtOpcRate.Text);
curConfig.workShifts[0].startHour := StrToInt(edtShift1Begin.Text);
curConfig.workShifts[0].endHour := StrToInt(edtShift1End.Text);
curConfig.workShifts[1].startHour := StrToInt(edtShift2Begin.Text);
curConfig.workShifts[1].endHour := StrToInt(edtShift2End.Text);
SetLength(curConfig.weightNames, ListBoxWeight.Items.Count);
for i:=0 to ListBoxWeight.Items.Count - 1 do
begin
curConfig.weightNames[i] := ListBoxWeight.Items[i];
end;
end;
end.