-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_Main.pas
327 lines (300 loc) · 9.25 KB
/
f_Main.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
unit f_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,pngimage, ExtCtrls, acImage, StdCtrls, Buttons, sBitBtn,
sPanel, acPNG, sLabel, cxStyles, cxCustomData, cxGraphics, cxFilter,
cxData, cxEdit, DB, cxDBData, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGridCustomTableView, cxGridTableView,
cxGridDBTableView, cxGrid, CollapsePanel, sGroupBox, Mask, DBCtrls,
sDBEdit, acSlider,IniFiles;
type
TMain = class(TForm)
MenuMain: TMainMenu;
A1: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
IMGMainImg: TsImage;
B1: TMenuItem;
PANWork: TsPanel;
GRIDWorkDBTableView1: TcxGridDBTableView;
GRIDWorkLevel1: TcxGridLevel;
GRIDWork: TcxGrid;
GRIDWorkDBTableView1name_visitor: TcxGridDBColumn;
GRIDWorkDBTableView1begin_visit: TcxGridDBColumn;
GRIDWorkDBTableView1end_visit: TcxGridDBColumn;
GRIDWorkDBTableView1summ_visit: TcxGridDBColumn;
GRIDWorkDBTableView1discount_visit: TcxGridDBColumn;
GRIDWorkDBTableView1end_summ_visit: TcxGridDBColumn;
CPANMain: TCollapsePanel;
PANMain: TsPanel;
PANBTNOpenSession: TsPanel;
BTNOpenSession: TsBitBtn;
PANBTNCloseSession: TsPanel;
BTNCloseSession: TsBitBtn;
PANBTNExit: TsPanel;
BTNExit: TsBitBtn;
PANBTNSettings: TsPanel;
BTNSettings: TsBitBtn;
PANDateTime: TsPanel;
LBLDate: TsLabelFX;
LBLTime: TsLabelFX;
CPANActions: TCollapsePanel;
PANActions: TsPanel;
PANBTNAddVisitor: TsPanel;
BTNAddVisitor: TsBitBtn;
PANBTNPay: TsPanel;
BTNPay: TsBitBtn;
PANSessionInfo: TsPanel;
PANBTNChangeTime: TsPanel;
BTNChangeTime: TsBitBtn;
GRBSessionInfo: TsGroupBox;
GRIDWorkDBTableView1TimeVisit: TcxGridDBColumn;
LBLNow: TsLabel;
pmedit: TPopupMenu;
N8: TMenuItem;
edtid_visit: TsDBEdit;
SLIDENow: TsSlider;
N9: TMenuItem;
procedure N5Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure BTNExitClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure N2Click(Sender: TObject);
procedure B1Click(Sender: TObject);
procedure BTNAddVisitorClick(Sender: TObject);
procedure BTNPayClick(Sender: TObject);
procedure BTNChangeTimeClick(Sender: TObject);
procedure N8Click(Sender: TObject);
procedure edtid_visitChange(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure BTNOpenSessionClick(Sender: TObject);
procedure BTNCloseSessionClick(Sender: TObject);
procedure SLIDENowClick(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure BTNSettingsClick(Sender: TObject);
procedure BTNCheckClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Main: TMain;
config:TIniFile;
implementation
uses f_Login, s_Res, f_All_users, s_Base, s_constTeplo, s_procTeplo,
f_VisitorAdd,DateUtils, f_ChangeTime, f_CalculateUser, f_Settings;
{$R *.dfm}
procedure TMain.N5Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMain.N3Click(Sender: TObject);
begin
Application.CreateForm(TLogin,Login);
Login.ShowModal;
end;
procedure TMain.BTNExitClick(Sender: TObject);
begin
N5.Click;
end;
procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;
end;
procedure TMain.N2Click(Sender: TObject);
begin
Base.SQLAllUsers.Active:=True;
Application.CreateForm(TAll_users,All_users);
if Base.SQLAllUsers.RecordCount=0 then All_users.PANEditClient.Visible:=False
else All_users.PANEditClient.Visible:=True;
All_users.ShowModal;
end;
procedure TMain.B1Click(Sender: TObject);
var
FullProgPath: PChar;
pswd:string;
begin
pswd:=InputBox(Application.Title,'Ââåäèòå íîâûé ïàðîëü :',' ');
ChangeUserPwd(id_user,pswd);
ShowMessage('Ïðîãðàììà áóäåò ïåðåçàïóùåíà');
FullProgPath:=PChar(Application.ExeName);
WinExec(FullProgPath,SW_SHOW);
Application.Terminate;
end;
procedure TMain.BTNAddVisitorClick(Sender: TObject);
begin
ShowVisitorAdd;
end;
procedure TMain.BTNPayClick(Sender: TObject);
var
id_visitor:string;
a:int64;
i,sale,minute:integer;
pay:Real;
H, M: Integer;
begin
for i:=0 to GRIDWorkDBTableView1.Controller.SelectedRowCount-1 do
begin
GRIDWorkDBTableView1.DataController.FocusedRecordIndex:=GRIDWorkDBTableView1.Controller.SelectedRows[i].Index;
id_visitor:=GRIDWorkDBTableView1.DataController.DataSet.FieldValues['id_visitor'];
//-------------- Äëÿ ïðîâåðêè íà ïîâòîðíîå ïîñåùåíèå
Base.SQLPayClient.Active:=False;
Base.SQLPayClient.Parameters.ParamByName('idSession').Value:=id_current_session;
Base.SQLPayClient.Parameters.ParamByName('idVisitor').Value:=id_visitor;
Base.SQLPayClient.Active:=True;
//--------------
sale:=Base.SQLVisitCurrentSessiondiscount_visit.Value;
A:=SecondsBetween(Base.SQLVisitCurrentSessionbegin_visit.value,now);
end_user_visit:=DateTimeToStr(Now);
minute:=strtoint(FormatFloat('0',((a/3600)*60)));
if base.SQLPayClient.RecordCount=1 then
begin
if minute<=10 then
begin
pay:=0;
pay_user_visit:=(FormatFloat('0',(pay)));
end
else
if (minute>10) and (minute<=60) then
begin
pay:=StrToFloat(first_hour_pay);
pay_user_visit:=(FormatFloat('0',(pay)));
end
else
if minute>60 then
begin
pay:=StrToFloat(first_hour_pay)+((minute-60)*strtofloat(one_minute_pay));
pay_user_visit:=(FormatFloat('0',(pay)));
end;
end
else if Base.SQLPayClient.RecordCount>1 then
begin
pay:=minute*strtofloat(one_minute_pay);
pay_user_visit:=(FormatFloat('0',(pay)));
end;
pay:=pay-((pay/100)*sale);
paysale_user_visit:=(FormatFloat('0',(pay)));
minute_user_visit:=IntToStr(minute);
H:=(minute*60) div 3600;
M:=((minute*60)-H*3600) div 60;
if Base.SQLVisitCurrentSessiontime_visit.Value=0 then
begin
Base.SQLTemp.Active:=False;
Base.SQLEdit.Active:=False;
Base.SQLEdit.SQL.Clear;
Base.SQLEdit.SQL.Append('INSERT INTO Temp (date_finish,pay_visit,minute_visit,paysale_visit,id_visit,id_visitor,fio_visitor)');
Base.SQLEdit.SQL.Append('VALUES ( =:dateF,'+pay_user_visit+','+inttostr(minute)+','+paysale_user_visit+','+Base.SQLVisitCurrentSessionid_visit.AsString+','+id_visitor+','+#39+Base.SQLVisitCurrentSessionname_visitor.AsString+#39+')');
Base.SQLEdit.Parameters.ParamByName('dateF').Value:=end_user_visit;
Base.SQLEdit.ExecSQL;
end;
end;
Application.CreateForm(TCalculateUser,CalculateUser);
Base.SQLTemp.Active:=True;
CalculateUser.ShowModal;
end;
procedure TMain.BTNChangeTimeClick(Sender: TObject);
begin
Application.CreateForm(TChangeTime,ChangeTime);
ChangeTime.ShowModal;
end;
procedure TMain.N8Click(Sender: TObject);
begin
DeleteSelectedVisitor;
end;
procedure TMain.edtid_visitChange(Sender: TObject);
begin
if Base.SQLVisitCurrentSessiontime_visit.AsString<>'0' then
begin
BTNChangeTime.Enabled:=False;
BTNPay.Enabled:=False;
Main.N9.Enabled:=False;
end
else
begin
BTNChangeTime.Enabled:=True;
BTNPay.Enabled:=True;
Main.N9.Enabled:=True;
end;
end;
procedure TMain.N6Click(Sender: TObject);
var
FullProgPath: PChar;
begin
FullProgPath := PChar(Application.ExeName);
WinExec(FullProgPath, SW_SHOW);
Application.Terminate;
end;
procedure TMain.BTNOpenSessionClick(Sender: TObject);
begin
OpenNewSession;
end;
procedure TMain.BTNCloseSessionClick(Sender: TObject);
begin
if Application.MessageBox('Âû òî÷íî õîòèòå çàêðûòü ñìåíó?','Àíòèêàôå "Òåïëî!"', MB_YESNO + MB_ICONWARNING + MB_TOPMOST)=mrYes then
begin
Base.SQLCloseSession.Active:=False;
Base.SQLCloseSession.Parameters.ParamByName('endSession').Value:=Now;
Base.SQLCloseSession.Parameters.ParamByName('idSession').Value:=id_current_session;
Base.SQLCloseSession.ExecSQL;
config:=TIniFile.Create(patch_app+'\conf\settings.ini');
config.WriteString('APP','last_session_id','');
config.Destroy;
Main.N5.Click;
end;
end;
procedure TMain.SLIDENowClick(Sender: TObject);
begin
if SLIDENow.SliderOn=False then
begin
Base.SQLVisitCurrentSession.Filtered:=False;
end
else
begin
Base.SQLVisitCurrentSession.Filtered:=False;
Base.SQLVisitCurrentSession.Filter:='summ_visit=0';
Base.SQLVisitCurrentSession.Filtered:=True;
end;
end;
procedure TMain.N9Click(Sender: TObject);
var
sale,id:string;
begin
if Base.SQLVisitCurrentSessiondiscount_visitor.AsString='0' then
begin
sale:=InputBox(Application.Title,'Óñòàíîâèòü ñêèäêó íà ïîñåùåíèå (åäèíîðàçîâàÿ) :','0');
id:=Base.SQLVisitCurrentSessionid_visit.AsString;
with Base.SQLEdit do
begin
Active:=False;
SQL.Clear;
SQL.Append('UPDATE Visit');
SQL.Append('SET discount_visit='+sale);
SQL.Append('WHERE id_visit='+id);
ExecSQL;
end;
Base.SQLVisitCurrentSession.Active:=False;
Base.SQLVisitCurrentSession.Active:=True;
end
else
ShowMessage('Íåëüçÿ èçìåíÿòü ïîñòîÿííóþ ñêèäêó');
end;
procedure TMain.BTNSettingsClick(Sender: TObject);
begin
Application.CreateForm(TSettings,Settings);
Settings.ShowModal;
end;
procedure TMain.BTNCheckClick(Sender: TObject);
var
i:integer;
begin
for i:=0 to GRIDWorkDBTableView1.Controller.SelectedRowCount-1 do
begin
GRIDWorkDBTableView1.DataController.FocusedRecordIndex:=GRIDWorkDBTableView1.Controller.SelectedRows[i].Index;
ShowMessage(GRIDWorkDBTableView1.DataController.DataSet.FieldValues['id_visitor']);
end;
end;
end.