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
| #include <vcl.h>
#include <stdio.h>
#include <io.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
#define FILE_BD "Employees.txt"
#define LEN_FNAME 32
#define LEN_NAME 16
#define LEN_ONAME 32
#define LEN_PLACE 256
#define LEN_DAY 15
#define USE_BUFF_LEN 512
//---------------------------------------------------------------------------
// Структура записи
struct RECORD_TXT
{
char FName[LEN_FNAME];
char Name[LEN_NAME];
char OName[LEN_ONAME];
char Place[LEN_PLACE];
char Day[LEN_DAY];
void Clear(void)
{
memset(this,' ',sizeof(RECORD_TXT));
};
};
//---------------------------------------------------------------------------
TForm1 *Form1;
int ARow_cursor = 1;
int Sor_CL = 1;
//---------------------------------------------------------------------------
void __fastcall TForm1::ClearStringGrid(TStringGrid *StringGrid)
{
for (int i = 1; i < StringGrid->ColCount; i++)
for (int j = 1; j < StringGrid->RowCount; j++)
StringGrid->Cells[i][j] = "";
StringGrid1->Cells[0][0] = "№"; //название колонок
StringGrid1->Cells[1][0] = "Фамилия";
StringGrid1->Cells[2][0] = "Имя";
StringGrid1->Cells[3][0] = "Отчество";
StringGrid1->Cells[4][0] = "Дата Рождения";
StringGrid1->Cells[5][0] = "Место Рождения";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TableStatistic() //Обновление статистики
{
int d_s,d_s1,lin_s,lin_s1; //переменные для старого сотрудника
int d_m,d_m1,lin_m,lin_m1; //переменные для молодого сотрудника
int z=0,v=0,l=0,o=0,s; //переменные пор года
String fam_z,fam_v,fam_l,fam_o,fam; //записывает Фамилии
Memo1->Clear();
Memo2->Clear();
Memo3->Clear();
if (StringGrid1->Cells[1][1]!="") {
SpeedButton2->Enabled=true;
SpeedButton3->Enabled=true;
for (int i=1; i<StringGrid1->RowCount; i++)
{
d_s = Date() - StringGrid1->Cells[4][i];
d_m = Date() - StringGrid1->Cells[4][i];
lin_s = i;
lin_m = i;
if (i == 1) {d_s1 = d_s; lin_s1 = lin_s;} //старый сотрудник
else if (d_s1<d_s) {d_s1 = d_s; lin_s1 = lin_s;}
if (i == 1) {d_m1 = d_m; lin_m1 = lin_m;} //молодой сотрудник
else if (d_m1>d_m) {d_m1 = d_m; lin_m1 = lin_m;}
String k = StringGrid1->Cells[4][i][4]; //больше все сотрудников в поре года
String k1= StringGrid1->Cells[4][i][5];
k = k + k1;
if (StrToInt(k)==12 || StrToInt(k)==1 || StrToInt(k)==2) {z++; fam_z=fam_z+StringGrid1->Cells[1][i]+"; ";}
else if (StrToInt(k)==3 || StrToInt(k)==4 || StrToInt(k)==5) {v++; fam_v=fam_v+StringGrid1->Cells[1][i]+"; ";}
else if (StrToInt(k)==6 || StrToInt(k)==7 || StrToInt(k)==8) {l++; fam_l=fam_l+StringGrid1->Cells[1][i]+"; ";}
else if (StrToInt(k)==9 || StrToInt(k)==10 || StrToInt(k)==11) {o++; fam_o=fam_o+StringGrid1->Cells[1][i]+"; ";}
}
String key;
if (z >= v && z >= l && z >= o) {s = z; key = "Зима"; fam = fam_z;}
else if (v >= z && v >= l && v >= o) {s = v; key = "Весна"; fam = fam_v;}
else if (l >= z && l >= v && l >= o) {s = l; key = "Лето"; fam = fam_l;}
else if (o >= z && o >= v && o >= l) {s = o; key = "Осень"; fam = fam_o;}
Memo1->Lines->Add(StringGrid1->Cells[0][lin_s1]+". "+
StringGrid1->Cells[1][lin_s1]+" "+
StringGrid1->Cells[2][lin_s1]+" "+
StringGrid1->Cells[3][lin_s1]);
Memo1->Lines->Add(StringGrid1->Cells[4][lin_s1]);
Memo1->Lines->Add(StringGrid1->Cells[5][lin_s1]);
Memo2->Lines->Add(StringGrid1->Cells[0][lin_m1]+". "+
StringGrid1->Cells[1][lin_m1]+" "+
StringGrid1->Cells[2][lin_m1]+" "+
StringGrid1->Cells[3][lin_m1]);
Memo2->Lines->Add(StringGrid1->Cells[4][lin_m1]);
Memo2->Lines->Add(StringGrid1->Cells[5][lin_m1]);
Memo3->Lines->Add("Пора года: "+key+".");
Memo3->Lines->Add("Кол-во: "+IntToStr(s)+".");
Memo3->Lines->Add("Фамилии: "+fam);
}
else {
SpeedButton2->Enabled=false;
SpeedButton3->Enabled=false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TableSorting(int ColN) //сортировка
{
int i,j,minInd;
AnsiString minVal;
TStringList *TempList=new TStringList;
for (i=1;i<this->StringGrid1->RowCount;i++)
{
minInd=i;
minVal=this->StringGrid1->Cells[ColN][i];
for (j=i+1;j<this->StringGrid1->RowCount;j++)
{
if (minVal>this->StringGrid1->Cells[ColN][j])
{
minInd=j;
minVal=this->StringGrid1->Cells[ColN][j];
};
};
TempList->Text=this->StringGrid1->Rows[minInd]->Text;
this->StringGrid1->Rows[minInd]->Text=this->StringGrid1->Rows[i]->Text;
this->StringGrid1->Rows[i]->Text=TempList->Text;
};
delete TempList;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TableUpdate() //обновление записей в таблице
{
FILE *BD = NULL;
RECORD_TXT rec;
char buff[USE_BUFF_LEN];
int y=1,x=1;
int xx,yy; //курсор
ClearStringGrid(StringGrid1);
if(FileExists(FILE_BD)){
if((BD=fopen(FILE_BD,"r"))!=NULL){
for (int i = 1; i < StringGrid1->ColCount; i++)
for (int j = 1; j < StringGrid1->RowCount; j++)
StringGrid1->Cells[i][j] = "";
rec.Clear();
while(fread(&rec,1,sizeof(RECORD_TXT),BD)){
memset(buff,0x00,USE_BUFF_LEN);
sprintf(buff,"%s",rec.FName);
StringGrid1->Cells[x][y]=buff;
memset(buff,0x00,USE_BUFF_LEN);
sprintf(buff,"%s",rec.Name);
StringGrid1->Cells[x+1][y]=buff;
memset(buff,0x00,USE_BUFF_LEN);
sprintf(buff,"%s",rec.OName);
StringGrid1->Cells[x+2][y]=buff;
memset(buff,0x00,USE_BUFF_LEN);
sprintf(buff,"%s",rec.Place);
StringGrid1->Cells[x+4][y]=buff;
memset(buff,0x00,USE_BUFF_LEN);
sprintf(buff,"%s",rec.Day);
StringGrid1->Cells[x+3][y]=buff;
StringGrid1->RowCount=y+1;
rec.Clear();
y++;
};
fclose(BD);
}
}
TableSorting(Sor_CL); //сортировка по Фамилии
for (int i=1; i<StringGrid1->RowCount; i++)
StringGrid1->Cells[0][i]=i;
TableStatistic(); //Обновление статистики
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TableRecord() //запись в конец файла
{
FILE *BD = NULL;
RECORD_TXT rec;
if((BD=fopen(FILE_BD,"a"))!=NULL){
rec.Clear();
sprintf(rec.FName,"%s",Form2->Edit1->Text.data());
sprintf(rec.Name,"%s",Form2->Edit3->Text.data());
sprintf(rec.OName,"%s",Form2->Edit4->Text.data());
sprintf(rec.Place,"%s",Form2->Edit2->Text.data());
sprintf(rec.Day,"%s",Form2->DateTimePicker1->Date.DateString());
fwrite(&rec,1,sizeof(RECORD_TXT),BD);
fclose(BD);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TableDelete() //удаление выделеной записи
{
FILE *BD = NULL;
RECORD_TXT rec;
class TProxyGrid : public TStringGrid
{
public:
using TStringGrid::DeleteRow;
};
((TProxyGrid*)StringGrid1)->DeleteRow(StringGrid1->Row);
int j1=1;
DeleteFile(FILE_BD);
if((BD=fopen(FILE_BD,"a"))!=NULL)
for (int i1=1; i1<StringGrid1->RowCount; i1++)
{
rec.Clear();
sprintf(rec.FName,"%s",StringGrid1->Cells[j1][i1].data());
sprintf(rec.Name,"%s",StringGrid1->Cells[j1+1][i1].data());
sprintf(rec.OName,"%s",StringGrid1->Cells[j1+2][i1].data());
sprintf(rec.Place,"%s",StringGrid1->Cells[j1+4][i1].data());
sprintf(rec.Day,"%s",StringGrid1->Cells[j1+3][i1].data());
fwrite(&rec,1,sizeof(RECORD_TXT),BD);
}
fclose(BD);
if (StringGrid1->RowCount<2) {
StringGrid1->RowCount++;
StringGrid1->FixedRows = 1;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TableRemove() //редактирование выделеной записи
{
FILE *BD = NULL;
RECORD_TXT rec;
StringGrid1->Cells[1][ARow_cursor] = Form4->Edit1->Text;
StringGrid1->Cells[2][ARow_cursor] = Form4->Edit3->Text;
StringGrid1->Cells[3][ARow_cursor] = Form4->Edit4->Text;
StringGrid1->Cells[5][ARow_cursor] = Form4->Edit2->Text;
StringGrid1->Cells[4][ARow_cursor] = Form4->DateTimePicker1->Date.DateString();
int j1 = 1;
DeleteFile(FILE_BD);
if((BD=fopen(FILE_BD,"a"))!=NULL)
for (int i1=1; i1<StringGrid1->RowCount; i1++)
{
rec.Clear();
sprintf(rec.FName,"%s",StringGrid1->Cells[j1][i1].data());
sprintf(rec.Name,"%s",StringGrid1->Cells[j1+1][i1].data());
sprintf(rec.OName,"%s",StringGrid1->Cells[j1+2][i1].data());
sprintf(rec.Place,"%s",StringGrid1->Cells[j1+4][i1].data());
sprintf(rec.Day,"%s",StringGrid1->Cells[j1+3][i1].data());
fwrite(&rec,1,sizeof(RECORD_TXT),BD);
}
fclose(BD);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TRect Rect;
TSpeedButton *Check1 = new TSpeedButton(this); //SP1
Check1->Visible = false;
Check1->Width =0;
Check1->Parent = StringGrid1;
Check1->Enabled = true;
Rect = StringGrid1->CellRect(1, 0);
Check1->Left = Rect.Left;
Check1->Top = Rect.Top;
Check1->Height = Rect.Bottom - Rect.Top;
Check1->Width = 120;
Check1->Left=21;
Check1->Transparent = true;
Check1->Flat = true;
Check1->OnClick = ClickCheck;
Check1->Visible = true;
StringGrid1->Objects[1][1] = Check1;
TSpeedButton *Check2 = new TSpeedButton(this); //SP2
Check2->Visible = false;
Check2->Width =0;
Check2->Parent = StringGrid1;
Check2->Enabled = true;
Rect = StringGrid1->CellRect(1, 0);
Check2->Left = Rect.Left;
Check2->Top = Rect.Top;
Check2->Height = Rect.Bottom - Rect.Top;
Check2->Width = 100;
Check2->Left=142;
Check2->Transparent = true;
Check2->Flat = true;
Check2->OnClick = ClickCheck1;
Check2->Visible = true;
StringGrid1->Objects[1][1] = Check2;
TSpeedButton *Check3 = new TSpeedButton(this); //SP3
Check3->Visible = false;
Check3->Width =0;
Check3->Parent = StringGrid1;
Check3->Enabled = true;
Rect = StringGrid1->CellRect(1, 0);
Check3->Left = Rect.Left;
Check3->Top = Rect.Top;
Check3->Height = Rect.Bottom - Rect.Top;
Check3->Width = 120;
Check3->Left=243;
Check3->Transparent = true;
Check3->Flat = true;
Check3->OnClick = ClickCheck2;
Check3->Visible = true;
StringGrid1->Objects[1][1] = Check3;
StringGrid1->FixedColor = clBlack; //цвет фиксированных ячеек
StringGrid1->ColWidths[0] = 20; //размер колонок
StringGrid1->ColWidths[1] = 120;
StringGrid1->ColWidths[2] = 100;
StringGrid1->ColWidths[3] = 120;
StringGrid1->ColWidths[4] = 91;
StringGrid1->ColWidths[5] = 140;
ClearStringGrid(StringGrid1);
TableUpdate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClickCheck(TObject *Sender)
{
TableSorting(Sor_CL=1);
for (int i=1; i<StringGrid1->RowCount; i++)
StringGrid1->Cells[0][i]=i;
TableStatistic(); //Обновление статистики
}
void __fastcall TForm1::ClickCheck1(TObject *Sender)
{
TableSorting(Sor_CL=2);
for (int i=1; i<StringGrid1->RowCount; i++)
StringGrid1->Cells[0][i]=i;
TableStatistic(); //Обновление статистики
}
void __fastcall TForm1::ClickCheck2(TObject *Sender)
{
TableSorting(Sor_CL=3);
for (int i=1; i<StringGrid1->RowCount; i++)
StringGrid1->Cells[0][i]=i;
TableStatistic(); //Обновление статистики
}
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(ARow == StringGrid1->Row)
{
StringGrid1->Canvas->Brush->Color = clSilver;
StringGrid1->Canvas->FillRect(Rect);
StringGrid1->Canvas->TextRect(Rect, Rect.Left + 2, Rect.Top + 2,
StringGrid1->Cells[ACol][ARow]);
}
if (State.Contains(gdFixed))
{
StringGrid1->Canvas->Font->Color = clWhite;
StringGrid1->Canvas->FillRect(Rect);
}
AnsiString text = StringGrid1->Cells[ACol][ARow];
StringGrid1->Canvas->TextRect(Rect,Rect.Left,Rect.Top, text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
Form2->Show();
Form1->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
StringGrid1->Invalidate();
ARow_cursor = ARow;
StringGrid1->Hint = StringGrid1->Cells[ACol][ARow];
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject *Sender) //удаление записи
{
if (Form3->CheckBox1->Checked == false) {
Form3->Memo1->Lines->Add(StringGrid1->Cells[1][ARow_cursor]+' '+
StringGrid1->Cells[2][ARow_cursor]+' '+
StringGrid1->Cells[3][ARow_cursor]+',');
Form3->Memo1->Lines->Add(StringGrid1->Cells[4][ARow_cursor]+" года рождения,");
Form3->Memo1->Lines->Add("Проживает по адресу: "+StringGrid1->Cells[5][ARow_cursor]);
Form3->Show();
Form1->Enabled=false;
}
else Form3->SpeedButton1->Click();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton3Click(TObject *Sender)
{
Form4->Edit1->Text = StringGrid1->Cells[1][ARow_cursor];
Form4->Edit3->Text = StringGrid1->Cells[2][ARow_cursor];
Form4->Edit4->Text = StringGrid1->Cells[3][ARow_cursor];
Form4->Edit2->Text = StringGrid1->Cells[5][ARow_cursor];
Form4->DateTimePicker1->Date = StringGrid1->Cells[4][ARow_cursor];
Form4->Show();
Form1->Enabled=false;
}
//--------------------------------------------------------------------------- |