-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeDefaultsUnit.pas
433 lines (378 loc) · 13.9 KB
/
ChangeDefaultsUnit.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
unit ChangeDefaultsUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxEdit,
DB, cxDBData, Buttons, StdCtrls, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGridCustomTableView, cxGridTableView,
cxGridDBTableView, cxGrid, ADODB, DataModuleUnit, AddValueUnit, addWeightUnit;
type
TChangeDefaultsForm = class(TForm)
GroupBox1: TGroupBox;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
ageAddBtn: TButton;
ageEditBtn: TButton;
ageDeleteBtn: TButton;
GroupBox2: TGroupBox;
cxGrid2: TcxGrid;
cxGridDBTableView1: TcxGridDBTableView;
cxGridLevel1: TcxGridLevel;
beltAddBtn: TButton;
beltEditBtn: TButton;
beltDeleteBtn: TButton;
GroupBox3: TGroupBox;
cxGrid3: TcxGrid;
cxGridDBTableView2: TcxGridDBTableView;
cxGridLevel2: TcxGridLevel;
CityAddBtn: TButton;
CityEditBtn: TButton;
CityDeleteBtn: TButton;
GroupBox4: TGroupBox;
cxGrid4: TcxGrid;
cxGridDBTableView3: TcxGridDBTableView;
cxGridLevel3: TcxGridLevel;
ClubAddBtn: TButton;
ClubEditBtn: TButton;
ClubDeleteBtn: TButton;
GroupBox5: TGroupBox;
cxGrid5: TcxGrid;
cxGridDBTableView4: TcxGridDBTableView;
cxGridLevel4: TcxGridLevel;
weightAddBtn: TButton;
weightEditBtn: TButton;
weightDeleteBtn: TButton;
CloseBtn: TBitBtn;
ageQuery: TADOQuery;
beltQuery: TADOQuery;
cityQuery: TADOQuery;
clubQuery: TADOQuery;
weightQuery: TADOQuery;
ageSource: TDataSource;
beltSource: TDataSource;
citySource: TDataSource;
clubSource: TDataSource;
weightSource: TDataSource;
cxGrid1DBTableView1DBColumn1: TcxGridDBColumn;
cxGrid1DBTableView1DBColumn2: TcxGridDBColumn;
cxGridDBTableView1DBColumn1: TcxGridDBColumn;
cxGridDBTableView1DBColumn2: TcxGridDBColumn;
cxGridDBTableView2DBColumn1: TcxGridDBColumn;
cxGridDBTableView2DBColumn2: TcxGridDBColumn;
cxGridDBTableView3DBColumn1: TcxGridDBColumn;
cxGridDBTableView3DBColumn2: TcxGridDBColumn;
cxGridDBTableView4DBColumn1: TcxGridDBColumn;
cxGridDBTableView4DBColumn2: TcxGridDBColumn;
cxGridDBTableView4DBColumn3: TcxGridDBColumn;
cxGrid1DBTableView1DBColumn3: TcxGridDBColumn;
cxGridDBTableView1DBColumn3: TcxGridDBColumn;
cxGridDBTableView2DBColumn3: TcxGridDBColumn;
cxGridDBTableView3DBColumn3: TcxGridDBColumn;
cxGridDBTableView4DBColumn4: TcxGridDBColumn;
procedure FormCreate(Sender: TObject);
procedure ageAddBtnClick(Sender: TObject);
procedure beltAddBtnClick(Sender: TObject);
procedure CityAddBtnClick(Sender: TObject);
procedure ClubAddBtnClick(Sender: TObject);
procedure ageEditBtnClick(Sender: TObject);
procedure beltEditBtnClick(Sender: TObject);
procedure CityEditBtnClick(Sender: TObject);
procedure ClubEditBtnClick(Sender: TObject);
procedure ageDeleteBtnClick(Sender: TObject);
procedure beltDeleteBtnClick(Sender: TObject);
procedure CityDeleteBtnClick(Sender: TObject);
procedure ClubDeleteBtnClick(Sender: TObject);
procedure cxGrid1DBTableView1DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
procedure cxGridDBTableView1DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
procedure cxGridDBTableView2DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
procedure cxGridDBTableView3DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
procedure cxGridDBTableView4DBColumn4GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
procedure weightAddBtnClick(Sender: TObject);
procedure weightEditBtnClick(Sender: TObject);
procedure weightDeleteBtnClick(Sender: TObject);
private
{ Private declarations }
//addWeightForm: TaddWeightForm;
//AddValueForm: TAddValueForm;
procedure add_new_value(formName,labelName,mask,colName:string;var query:TADOQuery); //äîáàâëåíèå íîâîãî çíà÷åíèÿ â òàáëèöû èñõîäíûõ äàííûõ(êðîìå âåñà, îí îòäåëüíûé)
//formName-èìÿ îêíà,labelName-èìÿ ìåòêè,mask-ìàñêà ââîäà,colName - èìÿ ñòîëáöà èçìåíåíèé; query -èìÿ çàïðîñà, ñ êîòîðûì ñâÿçàíà òàáëèöà
procedure edit_value(formName,labelName,mask,colName:string;var query:TADOQuery);
public
{ Public declarations }
end;
var
ChangeDefaultsForm: TChangeDefaultsForm;
implementation
{$R *.dfm}
procedure TChangeDefaultsForm.add_new_value(formName, labelName, mask,
colName: string; var query:TAdoQuery);
var str: string; //ââåäåííîå çíà÷åíèå
begin
AddValueForm := TAddValueForm.Create(self);
//óñòàíàâëèâàåì íà÷àëüíûå çíà÷åíèÿ
AddValueForm.set_values(formName,labelName,mask);
While AddValueForm.ShowModal = mrOK do //ïîëüçîâàòåëü ïîäòâåðäèë ââîä
begin
str := trim(AddValueForm.ValueEdit.Text);
//Äîáàâëÿåì çíà÷åíèå
query.Insert;
query.FieldByName(colName).AsString := str;
query.Post;
//îáíîâëÿåì ñîäåðæèìîå òàáëèöû
Query.close;
query.open;
end;
AddValueForm.Destroy;
end;
procedure TChangeDefaultsForm.FormCreate(Sender: TObject);
begin
//ñòàâèì ôîðìó ïî öåíòðó ýêðàíà
self.Left := (screen.Width - self.Width) div 2;
self.Top := (screen.Height - self.Height) div 2;
//âêëþ÷àåì âñå çàïðîñû
ageQuery.Open;
beltQuery.Open;
cityQuery.Open;
clubQuery.Open;
weightQuery.Open;
//âûðàâíèâàíèå ñòîëáöîâ
//ïîäñòðàèâàåì ÿ÷åéêè òàáëèöû ïîä èçìåíåííûé ðàçìåð
cxGrid1DBTableView1.OptionsView.ColumnAutoWidth := true;
cxGrid1DBTableView1.OptionsView.CellAutoHeight := true;
cxGridDBTableView1.OptionsView.ColumnAutoWidth := true;
cxGridDBTableView1.OptionsView.CellAutoHeight := true;
cxGridDBTableView2.OptionsView.ColumnAutoWidth := true;
cxGridDBTableView2.OptionsView.CellAutoHeight := true;
cxGridDBTableView3.OptionsView.ColumnAutoWidth := true;
cxGridDBTableView3.OptionsView.CellAutoHeight := true;
cxGridDBTableView4.OptionsView.ColumnAutoWidth := true;
cxGridDBTableView4.OptionsView.CellAutoHeight := true;
end;
procedure TChangeDefaultsForm.ageAddBtnClick(Sender: TObject);
begin
add_new_value('Äîáàâèòü âîçðàñòíóþ êàòåãîðèþ','Âîçðàñòíàÿ êàòåãîðèÿ','','age',ageQuery);
end;
procedure TChangeDefaultsForm.beltAddBtnClick(Sender: TObject);
begin
add_new_value('Äîáàâèòü ïîÿñ','Öâåò ïîÿñà','','belt',beltQuery);
end;
procedure TChangeDefaultsForm.CityAddBtnClick(Sender: TObject);
begin
add_new_value('Äîáàâèòü ãîðîä','Íàçâàíèå ãîðîäà','','city',cityQuery);
end;
procedure TChangeDefaultsForm.ClubAddBtnClick(Sender: TObject);
begin
add_new_value('Äîáàâèòü êëóá/òðåíåðà','Êëóá/òðåíåð','','club',clubQuery);
end;
procedure TChangeDefaultsForm.edit_value(formName, labelName, mask,
colName: string; var query: TADOQuery);
var str: string; //ââåäåííîå çíà÷åíèå
begin
AddValueForm := TAddValueForm.Create(self);
//óñòàíàâëèâàåì íà÷àëüíûå çíà÷åíèÿ
AddValueForm.set_values(formName,labelName,mask);
AddValueForm.ValueEdit.Text := query.fieldByName(colName).AsString;
if AddValueForm.ShowModal = mrOK then //ïîëüçîâàòåëü ïîäòâåðäèë ââîä
begin
str := trim(AddValueForm.ValueEdit.Text);
query.Edit;
query.FieldByName(colName).AsString := str;
query.Post;
//îáíîâëÿåì ñîäåðæèìîå òàáëèöû
Query.close;
query.open;
end;
AddValueForm.Destroy;
end;
procedure TChangeDefaultsForm.ageEditBtnClick(Sender: TObject);
begin
edit_value('Èçìåíèòü âîçðàñòíóþ êàòåãîðèþ','Âîçðàñòíàÿ êàòåãîðèÿ','','age',ageQuery);
end;
procedure TChangeDefaultsForm.beltEditBtnClick(Sender: TObject);
begin
edit_value('Èçìåíèòü ïîÿñ','Öâåò ïîÿñà','','belt',beltQuery);
end;
procedure TChangeDefaultsForm.CityEditBtnClick(Sender: TObject);
begin
edit_value('Èçìåíèòü ãîðîä','Íàçâàíèå ãîðîäà','','city',cityQuery);
end;
procedure TChangeDefaultsForm.ClubEditBtnClick(Sender: TObject);
begin
edit_value('Äîáàâèòü êëóá/òðåíåðà','Êëóá/òðåíåð','','club',clubQuery);
end;
procedure TChangeDefaultsForm.ageDeleteBtnClick(Sender: TObject);
begin
//çàùèòà îò äóðàêà
if ageQuery.RecordCount <= 0 then
begin
ShowMessage('Ñïèñîê âîçðàñòîâ ïóñò. Óäàëåíèå íåâîçìîæíî.');
Exit;
end;
if MessageDlg('Äàííîå äåéñòâèå ïðèâåäåò ê áåçâîçâðàòíîìó óäàëåíèþ çàïèñè èç ÁÄ. Âû óâåðåíû, ÷òî õîòèòå óäàëèòü åå?',
mtWarning,mbOKCancel,0) = mrOk then
ageQuery.Delete;
//îáíîâëÿåì òàáëèöó
ageQuery.close;
ageQuery.open;
//îáíîâëÿåì âåñà
weightQuery.Open;
weightQuery.Close;
end;
procedure TChangeDefaultsForm.beltDeleteBtnClick(Sender: TObject);
begin
//çàùèòà îò äóðàêà
if beltQuery.RecordCount <= 0 then
begin
ShowMessage('Ñïèñîê âîçðàñòîâ ïóñò. Óäàëåíèå íåâîçìîæíî.');
Exit;
end;
if MessageDlg('Äàííîå äåéñòâèå ïðèâåäåò ê áåçâîçâðàòíîìó óäàëåíèþ çàïèñè èç ÁÄ. Âû óâåðåíû, ÷òî õîòèòå óäàëèòü åå?',
mtWarning,mbOKCancel,0) = mrOk then
beltQuery.Delete;
//îáíîâëÿåì òàáëèöó
beltQuery.close;
beltQuery.open;
end;
procedure TChangeDefaultsForm.CityDeleteBtnClick(Sender: TObject);
begin
//çàùèòà îò äóðàêà
if cityQuery.RecordCount <= 0 then
begin
ShowMessage('Ñïèñîê âîçðàñòîâ ïóñò. Óäàëåíèå íåâîçìîæíî.');
Exit;
end;
if MessageDlg('Äàííîå äåéñòâèå ïðèâåäåò ê áåçâîçâðàòíîìó óäàëåíèþ çàïèñè èç ÁÄ. Âû óâåðåíû, ÷òî õîòèòå óäàëèòü åå?',
mtWarning,mbOKCancel,0) = mrOk then
cityQuery.Delete;
//îáíîâëÿåì òàáëèöó
cityQuery.close;
cityQuery.open;
end;
procedure TChangeDefaultsForm.ClubDeleteBtnClick(Sender: TObject);
begin
//çàùèòà îò äóðàêà
if clubQuery.RecordCount <= 0 then
begin
ShowMessage('Ñïèñîê âîçðàñòîâ ïóñò. Óäàëåíèå íåâîçìîæíî.');
Exit;
end;
if MessageDlg('Äàííîå äåéñòâèå ïðèâåäåò ê áåçâîçâðàòíîìó óäàëåíèþ çàïèñè èç ÁÄ. Âû óâåðåíû, ÷òî õîòèòå óäàëèòü åå?',
mtWarning,mbOKCancel,0) = mrOk then
clubQuery.Delete;
//îáíîâëÿåì òàáëèöó
clubQuery.close;
clubQuery.open;
end;
//*********** ñòîëáèêè ¹ ï/ï*********************
procedure TChangeDefaultsForm.cxGrid1DBTableView1DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
begin
AText := IntToStr(Sender.GridView.DataController.GetRowIndexByRecordIndex(ARecord.RecordIndex, false)+1);
end;
procedure TChangeDefaultsForm.cxGridDBTableView1DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
begin
AText := IntToStr(Sender.GridView.DataController.GetRowIndexByRecordIndex(ARecord.RecordIndex, false)+1);
end;
procedure TChangeDefaultsForm.cxGridDBTableView2DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
begin
AText := IntToStr(Sender.GridView.DataController.GetRowIndexByRecordIndex(ARecord.RecordIndex, false)+1);
end;
procedure TChangeDefaultsForm.cxGridDBTableView3DBColumn3GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
begin
AText := IntToStr(Sender.GridView.DataController.GetRowIndexByRecordIndex(ARecord.RecordIndex, false)+1);
end;
procedure TChangeDefaultsForm.cxGridDBTableView4DBColumn4GetDisplayText(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);
begin
AText := IntToStr(Sender.GridView.DataController.GetRowIndexByRecordIndex(ARecord.RecordIndex, false)+1);
end;
//***********************************************
procedure TChangeDefaultsForm.weightAddBtnClick(Sender: TObject);
var str:string;
begin
addWeightForm := TaddWeightForm.Create(self);
//ãðóçèì ñïèñîê âîçðàñòîâ
if DataModule1.fulfill_list('t_ages', 'age', DataModule1.ages_list) <> 0 then
ShowMessage('Òàáëèöà âîçðàñòîâ ïóñòà ëèáî îòñóòñòâóåò');
addWeightForm.ageBox.Items.Text := DataModule1.ages_list.Text;
//äîáàâëÿåì âåñ
while addWeightForm.ShowModal = mrOK do
begin
str := trim(addWeightForm.weightEdit.Text);
if DataModule1.add_weight_query(str,addWeightForm.AgeBox.Text) <> 0 then
ShowMessage('Íå óäàëîñü äîáàâèòü çíà÷åíèå â áàçó. Ïîïðîáóéòå åùå ðàç.');
weightQuery.Close;
weightQuery.Open;
end;
addWeightForm.Destroy;
end;
procedure TChangeDefaultsForm.weightEditBtnClick(Sender: TObject);
var id:variant;
r:integer;
str:string;
begin
addWeightForm := TaddWeightForm.Create(self);
//ãðóçèì ñïèñîê âîçðàñòîâ
if DataModule1.fulfill_list('t_ages', 'age', DataModule1.ages_list) <> 0 then
ShowMessage('Òàáëèöà âîçðàñòîâ ïóñòà ëèáî îòñóòñòâóåò');
addWeightForm.ageBox.Items.Text := DataModule1.ages_list.Text;
//ñòàâèì âåñ è âîçðàñò
addWeightForm.weightEdit.Text := weightQuery.FieldByName('weight').AsString;
addWeightForm.ageBox.ItemIndex := addWeightForm.ageBox.Items.IndexOf(weightQuery.FieldByName('t_ages.age').AsString);
//äîáàâëÿåì âåñ
if addWeightForm.ShowModal = mrOK then
begin
str := trim(addWeightForm.weightEdit.Text);
r := datamodule1.find_value_querry('t_ages','age','id',addWeightForm.ageBox.Text, id);
if r <> 0 then ShowMessage('Íå ïîëó÷èëè id âåñà.Èçìåíåíèÿ íå âíåñåíû')
else
begin
weightQuery.Edit;
weightQuery.FieldByName('weight').AsString := str;
weightQuery.FieldByName('t_weights.age').AsVariant := id;
weightQuery.Post;
end;
weightQuery.Close;
weightQuery.Open;
end;
addWeightForm.Destroy;
end;
procedure TChangeDefaultsForm.weightDeleteBtnClick(Sender: TObject);
begin
if weightQuery.RecordCount <= 0 then
begin
ShowMessage('Ñïèñîê âåñîâûõ ïóñò. Óäàëåíèå íåâîçìîæíî.');
Exit;
end;
if MessageDlg('Äàííîå äåéñòâèå ïðèâåäåò ê áåçâîçâðàòíîìó óäàëåíèþ çàïèñè èç ÁÄ. Âû óâåðåíû, ÷òî õîòèòå óäàëèòü åå?',
mtWarning,mbOKCancel,0) = mrOk then
with DataModule1 do
begin
DBQuery.Close;
DBQuery.SQL.Text := 'DELETE FROM t_weights where id = ' + weightQuery.FieldByName('t_weights.id').AsString;
DBQuery.ExecSQL;
//îáíîâëÿåì
weightQuery.Close;
weightQuery.Open;
end;
end;
end.