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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703 | uses
crt;
const
F_nombres='nombres.txt';
F_dependencias='dependencias.txt'; F_control='control.txt';
type
item_nombres = record
id:string;
nombre:string; apellido:string;
telefono:string;
calle:string;
borrado:boolean;
end; item_dependencias = record
id:string;
nombre:string;
telefono: string;
borrado:boolean; end;
item_control = record
id:string;
id_nombre:string;
id_dependencia:string; borrado:boolean;
end;
archivo_nombres = file of item_nombres;
archivo_dependencias = file of item_dependencias;
archivo_control = file of item_control; array_n=array [1..100] of item_nombres;
array_d=array [1..100] of item_dependencias;
var
elemento_nombres,aux_n:item_nombres;
elemento_dependencias,aux_d:item_dependencias; elemento_control,aux_c:item_control;
tecla:char;
File_nombres,fnaux:archivo_nombres;
File_dependencias,fdaux:archivo_dependencias;
File_control,fcaux:archivo_control; opc:char;
palabra:string;
c:integer;
d:char;
posicion:integer; insertar:boolean;
id:string;
a_n:array_n;
a_d:array_d;
cantidad:integer; borrado:boolean;
encontrado:boolean;
procedure quitar_eliminados;
begin assign(Fnaux,'fnaux');
rewrite(Fnaux);
close(Fnaux);
assign(File_nombres,F_nombres);
{$i-} reset(File_nombres);
{$i+}
if IOResult<>0 then
rewrite(File_nombres);
while not(eof(File_nombres)) do begin
read(File_nombres,elemento_nombres);
if elemento_nombres.borrado = false then
begin
assign(Fnaux,'fnaux'); {$i-}
reset(Fnaux);
{$i+}
if IOResult<>0 then
rewrite(Fnaux); seek(Fnaux,FileSize(Fnaux));
write(Fnaux,elemento_nombres);
close(Fnaux);
end;
end; rewrite(File_nombres);
assign(fnaux,'fnaux');
{$i-}
reset(fnaux);
{$i+} if IOResult<>0 then
rewrite(fnaux);
seek(Fnaux,0);
while not(eof(fnaux)) do
begin read(fnaux,elemento_nombres);
write(File_nombres,elemento_nombres);
end;
close(fnaux);
close(File_nombres);
assign(Fdaux,'fdaux');
rewrite(Fdaux);
close(Fdaux);
assign(File_dependencias,F_dependencias); {$i-}
reset(File_dependencias);
{$i+}
if IOResult<>0 then
rewrite(File_dependencias); while not(eof(File_dependencias)) do
begin
read(File_dependencias,elemento_dependencias);
if elemento_dependencias.borrado = false then
begin assign(Fdaux,'fdaux');
{$i-}
reset(Fdaux);
{$i+}
if IOResult<>0 then rewrite(Fdaux);
seek(Fdaux,FileSize(Fdaux));
write(Fdaux,elemento_dependencias);
close(Fdaux);
end; end;
rewrite(File_dependencias);
assign(fdaux,'fdaux');
{$i-}
reset(fdaux); {$i+}
if IOResult<>0 then
rewrite(fdaux);
seek(Fdaux,0);
while not(eof(fdaux)) do begin
read(fdaux,elemento_dependencias);
write(File_dependencias,elemento_dependencias);
end;
close(fdaux); close(File_dependencias);
assign(Fcaux,'fcaux');
rewrite(Fcaux);
close(Fcaux); assign(File_control,F_control);
{$i-}
reset(File_control);
{$i+}
if IOResult<>0 then rewrite(File_control);
while not(eof(File_control)) do
begin
read(File_control,elemento_control);
if elemento_control.borrado = false then begin
assign(Fcaux,'fcaux');
{$i-}
reset(Fcaux);
{$i+} if IOResult<>0 then
rewrite(Fcaux);
seek(Fcaux,FileSize(Fcaux));
write(Fcaux,elemento_control);
close(Fcaux); end;
end;
rewrite(File_control);
assign(fcaux,'fcaux');
{$i-} reset(fcaux);
{$i+}
if IOResult<>0 then
rewrite(fcaux);
seek(Fcaux,0); while not(eof(fcaux)) do
begin
read(fcaux,elemento_control);
write(File_control,elemento_control);
end; close(fcaux);
close(File_control);
end;
begin
textcolor(white);
palabra:='';
repeat
clrscr; quitar_eliminados;
writeln('1.- Insertar nombre ');
writeln('2.- Insertar dependencia ');
writeln;
writeln('3.- Busqueda por nombre');textcolor(white); writeln('4.- Busqueda por dependencia');
writeln;
writeln('5.- Modificar nombre');
writeln('6.- Modificar dependencia');
writeln; writeln('7.- Eliminar nombre');
writeln('8.- Eliminar dependencia');
writeln;
opc:=readkey; case opc of
'1':
begin
assign(File_dependencias,F_dependencias);
{$i-} reset(File_dependencias);
{$i+}
if IOResult<>0 then
rewrite(File_dependencias);
if FileSize(File_dependencias) > 0 then begin
assign(File_nombres,F_nombres);
{$i-}
reset(File_nombres);
{$i+} if IOResult<>0 then
rewrite(File_nombres);
with elemento_nombres do
repeat
clrscr; write('nombre: ');readln(nombre);
write('apellido: ');readln(apellido);
write('telefono: ');readln(telefono);
write('direccion: ');readln(calle);
str(FileSize(File_nombres)+1,id); seek(File_nombres,FileSize(File_nombres));
elemento_nombres.borrado:=false;
write(File_nombres,elemento_nombres);
posicion:=0;
Repeat Repeat
clrscr;
read(File_dependencias,elemento_dependencias);
write(elemento_dependencias.id,' - ',elemento_dependencias.nombre);
seek(File_dependencias,posicion); d:=readkey;
if(d='-') AND (FilePos(File_dependencias) > 0)then
begin
posicion:=posicion-1;
seek(File_dependencias,posicion) end;
if(d='+') AND (FilePos(File_dependencias) < FileSize(File_dependencias)-1)then
begin
posicion:=posicion+1;
seek(File_dependencias,posicion) end;
until (ord(d)=27)OR(ord(d)=13);
assign(File_control,F_control);
{$i-}
reset(File_control); {$i+}
if IOResult<>0 then
rewrite(File_control);
insertar:=true;
while not(eof(File_control)) do begin
read(File_control,elemento_control);
if (elemento_nombres.id = elemento_control.id_nombre) AND
(elemento_dependencias.id = elemento_control.id_dependencia)
then begin
insertar:=false;
break;
end
else begin
insertar:=true;
end;
end;
if insertar=true then begin
str(FileSize(File_control),elemento_control.id);
elemento_control.id_nombre:=elemento_nombres.id;
elemento_control.id_dependencia:=elemento_dependencias.id;
seek(File_control,FileSize(File_control)); elemento_control.borrado:=false;
write(File_control,elemento_control);
end;
writeln;
if insertar=false then writeln('Esta persona ya pertenecia a esta dependencia');
writeln('¨Deseas asignarle otra dependencia? s/n');
tecla:=upcase(readkey);
close(File_control);
until tecla='N'; writeln('Desea introducir otra persona? s/n');
tecla:=upcase(readkey);
until tecla='N';
close(File_nombres);
end else
begin
write('ERROR: Debe haber al menos una dependencia antes!');
readkey;
end; close(File_dependencias);
end;
'2':
begin
assign(File_dependencias,F_dependencias); {$i-}
reset(File_dependencias);
{$i+}
if IOResult<>0 then
rewrite(File_dependencias); with elemento_dependencias do
repeat
clrscr;
write('dependencia: ');readln(nombre);
write('telefono: ');readln(telefono); str(FileSize(File_dependencias)+1,id);
seek(File_dependencias,FileSize(File_dependencias));
elemento_dependencias.borrado:=false;
write(File_dependencias,elemento_dependencias);
writeln; writeln('Desea introducir otra dependencia? s/n');
tecla:=upcase(readkey);
until tecla='N';
close(File_dependencias);
end;
'3':
begin
clrscr;
repeat tecla:=readkey;
clrscr;
case ord(tecla) of
8:
begin delete(palabra,length(palabra),1);
end;
else
begin
palabra:=concat(palabra,tecla); end;
end;
gotoxy(1,1);writeln(palabra);
assign(File_nombres,F_nombres);
{$i-} reset(File_nombres);
{$i+}
if IOResult<>0 then
rewrite(File_nombres);
c:=0; while not(eof(File_nombres)) do
begin
read(File_nombres,elemento_nombres);
if
(pos(upcase(palabra),upcase(elemento_nombres.id)) > 0) OR (pos(upcase(palabra),upcase(elemento_nombres.nombre)) > 0) OR
(pos(upcase(palabra),upcase(elemento_nombres.apellido)) > 0)
then
begin
c:=c+1; write(elemento_nombres.id,'.- ');
write(elemento_nombres.nombre,' ');
write(elemento_nombres.apellido);
writeln;
writeln(' -Calle: ',elemento_nombres.calle); writeln(' -Telefono: ',elemento_nombres.telefono);
writeln;
assign(File_control,F_control);
{$i-}
reset(File_control); {$i+}
if IOResult<>0 then
rewrite(File_control);
while not(eof(File_control)) do
begin read(File_control,aux_c);
if elemento_nombres.id = aux_c.id_nombre then
begin
{}
assign(File_dependencias,F_dependencias); {$i-}
reset(File_dependencias);
{$i+}
if IOResult<>0 then
rewrite(File_dependencias); while not(eof(file_dependencias)) do
begin
read(file_dependencias,aux_d);
if aux_d.id = aux_c.id_dependencia then
begin textcolor(Green);
writeln(' -',aux_d.nombre);
writeln(' -Telefono: ',aux_d.telefono);
textcolor(White);
break; end;
end;
close(File_dependencias);
{}
end; end;
close(File_control);
end;
end;
close(File_nombres); until ord(tecla)=27;
palabra:='';
end;
'4': begin
clrscr;
repeat
tecla:=readkey;
clrscr; case ord(tecla) of
8:
begin
delete(palabra,length(palabra),1);
end; else
begin
palabra:=concat(palabra,tecla);
end;
end; gotoxy(1,1);writeln(palabra);
assign(File_dependencias,F_dependencias);
{$i-}
reset(File_dependencias);
{$i+} if IOResult<>0 then
rewrite(File_dependencias);
c:=0;
while not(eof(File_dependencias)) do
begin read(File_dependencias,elemento_dependencias);
if
(pos(upcase(palabra),upcase(elemento_dependencias.id)) > 0) OR
(pos(upcase(palabra),upcase(elemento_dependencias.nombre)) > 0)
then begin
c:=c+1;
write(elemento_dependencias.id,'.- ');
write(elemento_dependencias.nombre);
writeln; writeln(' -Telefono: ',elemento_dependencias.telefono);
writeln;
assign(File_control,F_control);
{$i-}
reset(File_control); {$i+}
if IOResult<>0 then
rewrite(File_control);
while not(eof(File_control)) do
begin read(File_control,aux_c);
if elemento_dependencias.id = aux_c.id_dependencia then
begin
{}
assign(File_nombres,F_nombres); {$i-}
reset(File_nombres);
{$i+}
if IOResult<>0 then
rewrite(File_nombres); while not(eof(file_nombres)) do
begin
read(file_nombres,aux_n);
if aux_c.id_nombre = aux_n.id then
begin textcolor(Green);
writeln(' -',aux_n.nombre);
writeln(' -direccion: ',aux_n.calle);
writeln(' -telefono: ',aux_n.telefono);
textcolor(White); break;
end;
end;
close(File_nombres);
{} end;
end;
close(File_control);
end;
end; close(File_dependencias);
until ord(tecla)=27;
palabra:='';
end;
'5': begin
clrscr;
write('Id nombre a modificar: ');readln(id);
assign(File_nombres,F_nombres);
{$i-} reset(File_nombres);
{$i+}
if IOResult<>0 then
rewrite(File_nombres);
while not(eof(file_nombres)) do begin
read(file_nombres,elemento_nombres);
if elemento_nombres.id = id then
begin
aux_n.id:=id; aux_n.borrado:=false;
textcolor(green);writeln('Nombre actual: ',elemento_nombres.nombre);textcolor(white);
write('Nombre nuevo: ');readln(aux_n.nombre);
textcolor(green);writeln('Apellido actual: ',elemento_nombres.apellido);textcolor(white);
write('Apellido nuevo: ');readln(aux_n.apellido); textcolor(green);writeln('Telefono actual: ',elemento_nombres.telefono);textcolor(white);
write('Telefono nuevo: ');readln(aux_n.telefono);
textcolor(green);writeln('Direccion nueva: ',elemento_nombres.calle);textcolor(white);
write('Direccion nueva: ');readln(aux_n.calle);
seek(File_nombres,FilePos(File_nombres)-1); write(File_nombres,aux_n);
encontrado:=true;
break;
end
else begin
encontrado:=false;
end;
end;
close(File_nombres); repeat
clrscr;
if encontrado=true then
begin
writeln('Registro modificado satisfactoriamente'); write('Presione Esc para continuar');
end
else
begin
textcolor(red);write('ERROR');textcolor(white);write(': No existe el registro con id ');textcolor(green);write(id);textcolor(white);writeln('.'); write('Presione Esc para continuar');
end;
tecla:=readkey;
until ord(tecla)=27;
end; '6':
begin
clrscr;
write('Id nombre a modificar: ');readln(id);
assign(File_dependencias,F_dependencias); {$i-}
reset(File_dependencias);
{$i+}
if IOResult<>0 then
rewrite(File_dependencias); while not(eof(file_dependencias)) do
begin
read(file_dependencias,elemento_dependencias);
if elemento_dependencias.id = id then
begin aux_d.id:=id;
aux_d.borrado:=false;
textcolor(green);writeln('Nombre actual: ',elemento_dependencias.nombre);textcolor(white);
write('Nombre nuevo: ');readln(aux_d.nombre);
textcolor(green);writeln('Telefono actual: ',elemento_dependencias.telefono);textcolor(white); write('Telefono nuevo: ');readln(aux_d.telefono);
seek(File_dependencias,FilePos(File_dependencias)-1);
write(File_dependencias,aux_d);
encontrado:=true;
break; end
else
begin
encontrado:=false;
end; end;
close(File_dependencias);
repeat
clrscr;
if encontrado=true then begin
writeln('Registro modificado satisfactoriamente');
write('Presione Esc para continuar');
end
else begin
textcolor(red);write('ERROR');textcolor(white);write(': No existe el registro con id ');textcolor(green);write(id);textcolor(white);writeln('.');
write('Presione Esc para continuar');
end;
tecla:=readkey; until ord(tecla)=27;
end;
'7':
begin
clrscr; write('Id nombre a eliminar: ');readln(id);
assign(File_nombres,F_nombres);
{$i-}
reset(File_nombres);
{$i+} if IOResult<>0 then
rewrite(File_nombres);
while not(eof(file_nombres)) do
begin
read(file_nombres,elemento_nombres); if elemento_nombres.id = id then
begin
elemento_nombres.borrado:=true;
seek(file_nombres,FilePos(File_nombres)-1);
write(file_nombres,elemento_nombres); borrado:=true;
assign(File_control,F_control);
{$i-}
reset(File_control);
{$i+} if IOResult<>0 then
rewrite(File_control);
while not(eof(File_control)) do
begin
read(File_control,elemento_control); if elemento_control.id_nombre = id then
begin
elemento_control.borrado:=true;
seek(File_control,FilePos(File_control)-1);
write(File_control,elemento_control); end;
end;
close(File_control);
break;
end else
begin
borrado:=false;
end;
end; close(File_nombres);
repeat
clrscr;
if borrado=true then
begin writeln('Registro eliminado');
write('Presione Esc para continuar');
end
else
begin textcolor(red);write('ERROR');textcolor(white);write(': No existe el registro con id ');textcolor(green);write(id);textcolor(white);writeln('.');
write('Presione Esc para continuar');
end;
tecla:=readkey;
until ord(tecla)=27; end;
'8':
begin
clrscr;
write('Id dependencia a eliminar: ');readln(id); assign(File_dependencias,F_dependencias);
{$i-}
reset(File_dependencias);
{$i+}
if IOResult<>0 then rewrite(File_dependencias);
while not(eof(file_dependencias)) do
begin
read(file_dependencias,elemento_dependencias);
if elemento_dependencias.id = id then begin
elemento_dependencias.borrado:=true;
seek(file_dependencias,FilePos(File_dependencias)-1);
write(file_dependencias,elemento_dependencias);
borrado:=true; assign(File_control,F_control);
{$i-}
reset(File_control);
{$i+}
if IOResult<>0 then rewrite(File_control);
while not(eof(File_control)) do
begin
read(File_control,elemento_control);
if elemento_control.id_dependencia = id then begin
elemento_control.borrado:=true;
seek(File_control,FilePos(File_control)-1);
write(File_control,elemento_control);
end; end;
close(File_control);
break;
end
else begin
borrado:=false;
end;
end;
close(File_dependencias); repeat
clrscr;
if borrado=true then
begin
writeln('Registro eliminado'); write('Presione Esc para continuar');
end
else
begin
textcolor(red);write('ERROR');textcolor(white);write(': No existe el registro con id ');textcolor(green);write(id);textcolor(white);writeln('.'); write('Presione Esc para continuar');
end;
tecla:=readkey;
until ord(tecla)=27;
end; end;
until ord(opc)=27;
end. |