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
| unit stud;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;
type
Student = record
fam,nam,otc : string[15];
sex : char;
datebd : TDateTime;
kurs : byte;
group : string[8];
spec : string[30];
end;
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Panel2: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
RadioGroup1: TRadioGroup;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
StatusBar1: TStatusBar;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
GroupBox1: TGroupBox;
BitBtn9: TBitBtn;
BitBtn10: TBitBtn;
BitBtn11: TBitBtn;
ComboBox1: TComboBox;
Edit9: TEdit;
SaveDialog1: TSaveDialog;
procedure VvodZap;
function Vozrast(v : TDateTime): string;
procedure FormCreate(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn8Click(Sender: TObject);
procedure BitBtn9Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Edit3Change(Sender: TObject);
procedure Edit4Change(Sender: TObject);
procedure Edit5Change(Sender: TObject);
procedure Edit8Change(Sender: TObject);
procedure Edit7Change(Sender: TObject);
procedure Edit6Change(Sender: TObject);
procedure BitBtn10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
std,st_temp: Student;
F,temp: file of student;
kol_zap,i,p,x,m:integer;
implementation
{$R *.dfm}
function TForm1.Vozrast(v : TDateTime): string;
var
g : TDateTime;
Year, Month, Day : word;
ss : string;
begin
g:=Date-v;
DecodeDate(g,Year,Month,Day);
Year:=Year-1900;
Month:=Month-1;
ss:=IntToStr(Year);
case Year of
1,21,31,41,51,61 : ss:=ss+' год ';
2,3,4,22,23,24,32,33,34,42,43,44,52,53,54,62,63,64 :
ss:=ss+' года ';
5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,25,26,27,28,29,30,35,36,
37,38,39,40,45,46,47,48,49,50,55,56,57,58,59,60,65,66,67,68,69,70 :
ss:=ss+' лет ';
end;
if Month <> 0 then
begin
ss:=ss+' '+IntToStr(Month);
case Month of
1 : ss:=ss+' месяц ';
2,3,4 : ss:=ss+' месяца ';
5,6,7,8,9,10,11,12 : ss:=ss+' месяцев ';
end;
end;
Vozrast:=ss;
end;
procedure tform1.VvodZap;
begin
read(f,std);
Edit1.Text:=std.fam;
Edit2.Text:=std.nam;
Edit3.Text:=std.otc;
Edit4.Text:=datetimetostr(std.datebd);
Edit5.Text:=Vozrast(std.datebd);
case std.sex of
'м': Radiogroup1.ItemIndex:=0;
'ж': Radiogroup1.ItemIndex:=1;
end;
case std.kurs of
1: Edit6.Text:='первый';
2: Edit6.Text:='второй';
3: Edit6.Text:='третий';
4: Edit6.Text:='четвертый';
5: Edit6.Text:='пятый';
end;
Edit7.Text:=std.group;
Edit8.Text:=std.spec;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bitbtn1.enabled:=false;
bitbtn2.enabled:=false;
Assignfile(f,'spis_rec.dat');
reset(f);
VvodZap;
kol_zap:=FileSize(F);
StatusBar1.Panels[0].Text:='В файле всего '+IntToStr(kol_Zap)+' записей';
//closefile(f);
i:=0;
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
bitbtn1.enabled:=true;
bitbtn2.enabled:=true;
if not eof(f) then begin
seek(f,i+1);
VvodZap;
i:=i+1; end;
if eof(f) then begin
bitbtn4.enabled:=false;
bitbtn5.enabled:=false; end
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
closefile(f);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if i<>0 then begin
seek(f,i-1);
VvodZap;
i:=i-1; end;
bitbtn4.enabled:=true;
bitbtn5.enabled:=true;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
seek(f,0);
VvodZap;
i:=0;
end;
procedure TForm1.BitBtn5Click(Sender: TObject);
begin
seek(f,kol_zap-1);
VvodZap;
i:=kol_zap-1;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
i:=strtoint(InputBox('Переход', 'Введите номер записи для перехода','0'));
seek(f,i);
VvodZap;
end;
procedure TForm1.BitBtn6Click(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.BitBtn7Click(Sender: TObject);
begin
//showmessage(inttostr(i));
if Application.MessageBox(PChar('Вы действительно хотите удалить текущую запись ?'),'Удаление строки',mb_YesNo) = id_Yes then
begin
Assignfile(temp,'spis_rec.tmp');
Rewrite(temp);
seek(f,0);
while not eof(f) do begin
read(f,std);
if std.fam<>Edit1.Text then
write (temp,std);
end;
closefile(f);
closefile(temp);
Deletefile('spis_rec.dat');
Renamefile('spis_rec.tmp','spis_rec.dat');
Assignfile(f,'spis_rec.dat');
reset(f);
if i=(kol_zap-1) then i:=i-1; //если была удалена последняя запись
seek(f,i);
VvodZap;
showmessage('Запись удалена');
end;
kol_zap:=FileSize(F);
StatusBar1.Panels[0].Text:='В файле всего '+IntToStr(kol_Zap)+' записей';
end;
procedure TForm1.BitBtn8Click(Sender: TObject);
begin
x:=2;
Edit9.Text:='2';
ComboBox1.Visible:=True;
BitBtn1.Enabled:=False;
BitBtn2.Enabled:=False;
BitBtn3.Enabled:=False;
BitBtn4.Enabled:=False;
BitBtn5.Enabled:=False;
BitBtn7.Enabled:=False;
BitBtn8.Enabled:=False;
edit1.ReadOnly:=False;
edit1.Text:='';
edit2.ReadOnly:=False;
edit2.Text:='';
edit3.ReadOnly:=False;
edit3.Text:='';
edit4.Text:='';
edit4.ReadOnly:=False;
edit5.Text:='';
edit5.ReadOnly:=False;
edit6.ReadOnly:=False;
edit7.Text:='';
edit7.ReadOnly:=False;
edit8.Text:='';
edit8.ReadOnly:=False;
BitBtn11.Visible:=True;
BitBtn9.Visible:=False;
edit6.Visible:=false;
end;
procedure TForm1.BitBtn9Click(Sender: TObject);
begin
x:=1;
edit9.Text:='1';
BitBtn1.Enabled:=False;
BitBtn2.Enabled:=False;
BitBtn3.Enabled:=False;
BitBtn4.Enabled:=False;
BitBtn5.Enabled:=False;
BitBtn7.Enabled:=False;
BitBtn8.Enabled:=False;
edit1.ReadOnly:=False;
edit2.ReadOnly:=False;
edit3.ReadOnly:=False;
edit4.ReadOnly:=False;
edit5.ReadOnly:=False;
edit6.ReadOnly:=False;
edit7.ReadOnly:=False;
edit8.ReadOnly:=False;
BitBtn11.Visible:=True;
BitBtn9.Visible:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ComboBox1.Visible:=False;
Edit6.Text:=ComboBox1.Text;
edit6.Visible:=true;
BitBtn1.Enabled:=true;
BitBtn2.Enabled:=true;
BitBtn3.Enabled:=true;
BitBtn4.Enabled:=true;
BitBtn5.Enabled:=true;
BitBtn7.Enabled:=true;
BitBtn8.Enabled:=true;
BitBtn9.Visible:=true;
BitBtn11.Visible:=false;
edit1.ReadOnly:=True;
edit2.ReadOnly:=True;
edit3.ReadOnly:=True;
edit4.ReadOnly:=True;
edit5.ReadOnly:=True;
edit6.ReadOnly:=True;
edit7.ReadOnly:=True;
edit8.ReadOnly:=True;
BitBtn10.Enabled:=False;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit3Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit4Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit5Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit8Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit7Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.Edit6Change(Sender: TObject);
begin
if edit1.Modified and edit2.Modified and edit3.Modified and Edit4.Modified and edit5.Modified and edit7.Modified then
BitBtn10.Enabled:=true
end;
procedure TForm1.BitBtn10Click(Sender: TObject);
var
L,OL: Student;
F,NF: file of Student;
begin
{if Edit9.text='1' then }
SetCurrentDir(ExtractFilePath(Application.exename)+'Spis_rec.dat');
AssignFile(NF,'Spis_recc.dat');
Rewrite(NF);
if FileExists('Spis_reс.dat') then
begin
Assignfile(F,'Spis_rec.dat');
Reset(F);
while not Eof (F) do
begin
read(F,OL);
write(NF,OL);
end;
CloseFile(F);
end;
write (NF,OL);
CloseFile(NF);
DeleteFile('Spis_rec.dat');
RenameFile('Spis_recc.dat','Spis_rec.dat');
end; |