El Guru Programador :: V A X N U :: Dominios - Hosting - Aplicaciones Web
Usuario DESCONOCIDO | Registrate Gratis | Usuarios Registrados
AGENDA
Autor [kecambas] Calificacion
Este programa se trata de una agenda personal, te envia alarmas, y te dice quien cumple años el dia en que abres la agenda. Usa archivos, structuras, graficos.

/*Autor: aLONSO mEDINA*/
/*mEXICO d.F. */
/*iNSTITUTO pOLITECNICO nACIONAL*/


#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<ctype.h>
#include<process.h>
#include<string.h>

// NOTA : Las funciones estan desarolladas en el
// mismo orden que fueron declaradas.

void valida_fecha(int *dato, int x, int y, char *tipo, int min, int max);
void valida_anio(int *dato, int tipo);
void valida_rangos(char *dato, int x, int y, char *tipo, int tama);
void valida_cambio_vec(char *vec, struct datos *dato, int tipo);
void valida_cambio_fechas(int *aux, struct datos *dato, int tipo);
int valida_nom_rep(char *nom, char *ape);
void alarma(void);
void cargar(void);
void aniversarios(void);
int modificar(void);
void backup(void);
void buscar(void);
void mostrar_resultado_busqueda (struct datos *dato);
int menu(void);
int ayuda_menu(void);
int acerca_de(void);
void poner_recuadro(char p);
void barra(void);

struct alarma { int dia, mes, anio; };
struct fecha { int dia, mes, anio; };
struct datos { char nombre[30];
char apell[20];
char direcc[40];
char local[40];
char tp[40];
char telef[30];
struct fecha f;
struct alarma a;
char observ[200];
};

/****************************************************************/
/* MAIN */
/****************************************************************/

void main(void){

int pos;

alarma();
for( ; ; ){
pos=menu();
switch(pos){
case 6 : cargar();
break;
case 8 : aniversarios();
break;
case 10 : modificar();
break;
case 12 : backup();
break;
case 14 : buscar();
break;
case 16 : exit(0);
}
}
}

/****************************************************************/
/* VALIDA_FECHA */
/****************************************************************/

void valida_fecha(int *dato, int x, int y, char *tipo, int min, int max){

while(*dato>max || *dato<min){
gotoxy(10,21);
textcolor(WHITE);
cprintf("Error, el %s debe estar entre %d y %d !!!",tipo,min,max);
getch();
gotoxy(10,21);
clreol();
gotoxy(x,y);
clreol();
gotoxy(x,y);
scanf("%d",dato);
fflush(stdin);
}

}
/****************************************************************/
/* VALIDA_ANIO */
/****************************************************************/

void valida_anio(int *dato, int tipo){

struct date date;
getdate(&date);

switch(tipo){
case 1 : while(*dato>date.da_year){
gotoxy(10,21);
textcolor(WHITE);
cprintf("Error, el a¤o debe ser menor a %d !!!",date.da_year);
getch();
gotoxy(10,21);
clreol();
gotoxy(46,13);
clreol();
gotoxy(46,13);
scanf("%d",dato);
fflush(stdin);
}
break;
case 2 : while(*dato<date.da_year){
gotoxy(10,21);
textcolor(WHITE);
cprintf("Error, el a¤o debe ser mayor o igual a %d !!!",date.da_year);
getch();
gotoxy(10,21);
clreol();
gotoxy(46,16);
clreol();
gotoxy(46,16);
scanf("%d",dato);
fflush(stdin);
}
break;
}
}

/****************************************************************/
/* VALIDA_RANGOS */
/****************************************************************/

void valida_rangos(char *dato,int x, int y, char *tipo, int tam){

while(strlen(dato)>(tam-1)){
gotoxy(x,y);
textcolor(WHITE);
cprintf("Error, %s demasiado largo (MAX %d) !!! ",tipo,(tam-1));
getch();
gotoxy(x,y);
clreol();
gotoxy(x,y);
gets(dato);
}
}
/****************************************************************/
/* VALIDA_CAMBIO_VEC */
/****************************************************************/

void valida_cambio_vec(char *vec, struct datos *dato, int tipo ){

char rta;

textcolor(WHITE);
gotoxy(10,22);
cprintf("¨¨ Esta seguro que desea realizar el cambio (S/N) ??? : ");
do{
rta=getche();
}while(rta!='s'&&rta!='n');
if(rta=='s'){
strlwr(vec);
vec[0]=toupper(vec[0]);
if(tipo==1) strcpy(dato->direcc,vec);
if(tipo==2) strcpy(dato->local,vec);
if(tipo==3) strcpy(dato->tp,vec);
if(tipo==4) strcpy(dato->telef,vec);
if(tipo==5) strcpy(dato->observ,vec);
}
}

/****************************************************************/
/* VALIDA_CAMBIO_FECHAS */
/****************************************************************/

void valida_cambio_fechas(int *aux, struct datos *dato, int tipo){

char rta;

textcolor(WHITE);
gotoxy(10,22);
cprintf("¨¨ Esta seguro que desea realizar el cambio (S/N) ??? : ");
do{
rta=getche();
}while(rta!='s'&&rta!='n');
if(rta=='s'){
if(tipo==1) dato->f.dia=*aux;
if(tipo==2) dato->f.mes=*aux;
if(tipo==3) dato->f.anio=*aux;
if(tipo==4) dato->a.dia=*aux;
if(tipo==5) dato->a.mes=*aux;
if(tipo==6) dato->a.anio=*aux;
}
}

/****************************************************************/
/* VALIDA_NOM_REP */
/****************************************************************/

int valida_nom_rep(char *nom, char *ape){
FILE *punt;
struct datos dato;

if((punt=fopen("a:\\agenda.dat","rb"))==NULL){
gotoxy(1,25);
printf("Error al abrir archivo para validacion");
getch();
gotoxy(1,25);
clreol();
return 0;
}
while(feof(punt)==0){
if(fread(&dato,sizeof(dato),1,punt)!=1){
if(feof(punt)!=0){
return 1;
}else{
gotoxy(1,25);
printf("Error al leer archivo para validacion");
getch();
gotoxy(1,25);
clreol();
return 1;
}
}
if(strcmp(nom,dato.nombre)==0)
if(strcmp(ape,dato.apell)==0){
gotoxy(28,5);
printf("Nombre y apellido existente.");
gotoxy(28,6);
printf("Por favor, reingrese los datos.");
getch();
gotoxy(28,5);
clreol();
gotoxy(28,6);
clreol();
fclose(punt);
return 0;
}
}
fclose(punt);
return 1;
}


/****************************************************************/
/* ALARMA */
/****************************************************************/

void alarma(void){
int cant;
struct date f;
struct datos dato;
FILE *punt;

getdate(&f);
if((punt=fopen("a:\\agenda.dat","rb"))==NULL){
clrscr();
gotoxy(1,25);
clreol();
printf("Error al abrir archivo !!!!");
}

for( ; ; ){
cant=fread(&dato,sizeof(dato),1,punt);
if(cant!=1){
if(feof(punt)){
break;
}else{
gotoxy(1,25);
clreol();
printf("\aError al leer archivo !!!!");
getch();
break;
}
}

if(f.da_year==dato.a.anio)
if(f.da_mon==dato.a.mes)
if(f.da_day==dato.a.dia){
textbackground(RED);
clrscr();
textbackground(BLUE);
textcolor(WHITE);
gotoxy(6,4);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(6,5);
cprintf(" º ESTAS SON LAS PERSONAS QUE TIENEN LA ALARMA PUESTA EN ESTE DIA º ");
gotoxy(6,6);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
gotoxy(12,10);
textbackground(RED);
cprintf(" NOMBRE : %s",dato.nombre);
gotoxy(12,11);
cprintf(" APELLIDO : %s",dato.apell);
gotoxy(12,13);
cprintf(" OBSERVACIONES : %s",dato.observ);
gotoxy(12,24);
textcolor(YELLOW);
cprintf(" Presione cualquier tecla para continuar ....");
getch();
}
}
clrscr();
fclose(punt);
}

/****************************************************************/
/* CARGA DE DATOS */
/****************************************************************/

void cargar(void){

int aux2=0,cant;
char rta,aux[20],aux1[20];
struct datos d;
FILE *punt;

if((punt=fopen("a:\\agenda.dat","ab"))==NULL){
if((punt=fopen("a:\\agenda.dat","wb"))==NULL){
clrscr();
textattr(WHITE+BLINK);
gotoxy(2,2);
cprintf("\nError al abrir archivo de datos !!!");
exit(0);
}
}


for( ; ; ){
textbackground(RED);
clrscr();
textbackground(BLACK);
textcolor(WHITE);
gotoxy(25,1);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(25,2);
cprintf(" º CARGA DE DATOS º ");
gotoxy(25,3);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
textcolor(YELLOW);
textbackground(RED);
gotoxy(1,5);
cprintf(" NOMBRE : \n\r");
cprintf(" APELLIDO : \n\r");
cprintf(" DIRECCION : \n\r");
cprintf(" LOCALIDAD : \n\r");
cprintf(" TRABAJO PARTICULAR : \n\r");
cprintf(" TELEFONO : \n\r");
cprintf(" FECHA DE NACIMIENTO : DIA (2 digitos) : \n\r");
cprintf(" MES (2 digitos) : \n\r");
cprintf(" A¥O (4 digitos) : \n\r");
cprintf(" ALARMA : DIA (2 digitos) : \n\r");
cprintf(" MES (2 digitos) : \n\r");
cprintf(" A¥O (4 digitos) : \n\r");
cprintf(" OBSERVACIONES : ");

do{
textcolor(WHITE);
gotoxy(28,5);
gets(aux);
valida_rangos(aux,28,5,"nombre",30);
strlwr(aux);
aux[0]=toupper(aux[0]);
strcpy(d.nombre,aux);

gotoxy(28,6);
gets(aux1);
valida_rangos(aux1,28,6,"apellido",20);
strlwr(aux1);
aux1[0]=toupper(aux1[0]);
strcpy(d.apell,aux1);
}while(valida_nom_rep(aux,aux1)==0);

gotoxy(28,7);
gets(aux);
valida_rangos(aux,28,7,"direccion",40);
strlwr(aux);
aux[0]=toupper(aux[0]);
strcpy(d.direcc,aux);

gotoxy(28,8);
gets(aux);
valida_rangos(aux,28,8,"localidad",40);
strlwr(aux);
aux[0]=toupper(aux[0]);
strcpy(d.local,aux);

gotoxy(28,9);
gets(aux);
valida_rangos(aux,28,9,"trabajo",40);
strlwr(aux);
aux[0]=toupper(aux[0]);
strcpy(d.tp,aux);

gotoxy(28,10);
gets(aux);
valida_rangos(aux,28,10,"telefono",30);
strcpy(d.telef,aux);

gotoxy(46,11);
scanf("%d",&aux2);
fflush(stdin);
valida_fecha(&aux2,46,11,"dia",1,31);
d.f.dia=aux2;

gotoxy(46,12);
scanf("%d",&aux2);
fflush(stdin);
valida_fecha(&aux2,46,12,"mes",1,12);
d.f.mes=aux2;

gotoxy(46,13);
scanf("%d",&aux2);
fflush(stdin);
valida_anio(&aux2,1);
d.f.anio=aux2;

gotoxy(46,14);
scanf("%d",&aux2);
fflush(stdin);
valida_fecha(&aux2,46,14,"dia",1,31);
d.a.dia=aux2;

gotoxy(46,15);
scanf("%d",&aux2);
fflush(stdin);
valida_fecha(&aux2,46,15,"mes",1,12);
d.a.mes=aux2;

gotoxy(46,16);
scanf("%d",&aux2);
fflush(stdin);
valida_anio(&aux2,2);
d.a.anio=aux2;

gotoxy(28,17);
gets(aux);
valida_rangos(aux,28,17,"observacion",200);
strlwr(aux);
aux[0]=toupper(aux[0]);
strcpy(d.observ,aux);

do{
textcolor(WHITE);
gotoxy(8,22);
cprintf("¨ Desea guardar los datos ingresados (S/N) ? : ");
rta=tolower(getche());
if(rta=='s'){
cant=fwrite(&d,sizeof(struct datos),1,punt);
if(cant!=1){
gotoxy(2,25);
printf("Error al guardar los datos en el archivo. ");
delline();
getch();
}
}
}while(rta!='s'&&rta!='n');
do{
textcolor(WHITE);
gotoxy(8,23);
cprintf("¨ Desea contiunuar con el ingreso de nuevos registros (S/N) ? ");
rta=tolower(getche());
}while(rta!='n'&& rta!='s');
if(rta=='n'){
fclose(punt);
break;
}
} // for infinito principal de la funci¢n

}

/****************************************************************/
/* ANIVERSARIOS */
/****************************************************************/

void aniversarios(void){

int cant,flag=0;
struct date d;
struct datos dato;
FILE *punt;


getdate(&d);
if ((punt=fopen("a:\\agenda.dat","rb"))==NULL){
clrscr();
gotoxy(1,25);
clreol();
printf("\aError al abrir archivo !!!!");
getch();
exit(0);
}

for( ; ; ){
cant=fread(&dato,sizeof(dato),1,punt);
if(cant!=1){
if(feof(punt)!=0){
break;
}else{
gotoxy(1,25);
clreol();
printf("\aError al leer archivo !!!!");
getch();
break;
}
}

if(dato.f.mes==d.da_mon && dato.f.dia==d.da_day){
flag=1;
textbackground(BLUE);
clrscr();
gotoxy(13,3);
textattr(YELLOW+BLINK);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(13,4);
cprintf(" º ESTAS SON LAS PERSONAS QUE HOY CUMPLEN A¥OS !!! º ");
gotoxy(13,5);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
textbackground(BLUE);
textcolor(WHITE);
gotoxy(1,8);
cprintf(" NOMBRE : %s \n\r",dato.nombre);
cprintf(" APELLIDO : %s \n\r",dato.apell);
cprintf(" DIRECCION : %s \n\r",dato.direcc);
cprintf(" LOCALIDAD : %s \n\r",dato.local);
cprintf(" TRABAJO PARTICULAR : %s \n\r",dato.tp);
cprintf(" TELEFONO : %s \n\r",dato.telef);
cprintf(" FECHA DE NACIMIENTO : %d / %d / %d \n\r",dato.f.dia,dato.f.mes,dato.f.anio);
cprintf(" ALARMA : %d / %d / %d \n\r",dato.a.dia,dato.a.mes,dato.a.anio);
cprintf(" OBSERVACIONES : %s \n\r",dato.observ);
gotoxy(15,24);
textcolor(YELLOW);
cprintf("Presione cualquier tecla para continuar ....");
getch();
}
}
if(flag==0){
textcolor(YELLOW);
textbackground(BLACK);
gotoxy(12,21);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(12,22);
cprintf(" º NO HAY NINGUNA PERSONA QUE CUMPLA A¥OS ESTE DIA ... º ");
gotoxy(12,23);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
sound(100);
delay(1000);
nosound();
getch();
}
fclose(punt);
}

/****************************************************************/
/* MODIFICAR */
/****************************************************************/

int modificar(void){

int cant,nc,aux;
char n[30],ap[20],nd[50],rta;
struct date d;
struct datos dato;
FILE *punt;
getdate(&d);

if((punt=fopen("a:\\agenda.dat","rb+"))==NULL){
gotoxy(1,25);
clreol();
printf("\aError, no se puede abrir el archivo");
getch();
}

for( ; ; ){
textbackground(RED);
clrscr();
textcolor(WHITE);
textbackground(BLACK);
gotoxy(25,4);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(25,5);
cprintf(" º MODIFICAR DATOS º ");
gotoxy(25,6);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
textcolor(WHITE);
textbackground(GREEN);
gotoxy(9,9);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(9,10);
cprintf(" º INGRESE NOMBRE DE LA PERSONA CUYOS DATOS DESEA º ");
gotoxy(9,11);
cprintf(" º MODIFICAR : º ");
gotoxy(9,12);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
gotoxy(25,11);
textbackground(BLUE);
cprintf(" ");
gotoxy(26,11);
gets(n);
strlwr(n);
n[0]=toupper(n[0]);

textcolor(WHITE);
textbackground(GREEN);
gotoxy(9,14);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(9,15);
cprintf(" º INGRESE APELLIDO DE LA PERSONA CUYOS DATOS DESEA º ");
gotoxy(9,16);
cprintf(" º MODIFICAR : º ");
gotoxy(9,17);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
gotoxy(25,16);
textbackground(BLUE);
cprintf(" ");
gotoxy(26,16);
gets(ap);
strlwr(ap);
ap[0]=toupper(ap[0]);

for( ; ; ){
cant=fread(&dato,sizeof(dato),1,punt);
if(cant != 1){
if(feof(punt)!=0){
break;
} else {
gotoxy(1,25);
clreol();
printf("\aError al leer el archivo.");
getch();
break;
}
}

if( strcmp( dato.nombre,n ) ==0 )
if( strcmp( dato.apell,ap ) ==0 ){
fseek(punt,(long)(-1)*sizeof(dato),SEEK_CUR);
for ( ; ; ) {
textbackground(RED);
clrscr();
textcolor(WHITE);
textbackground(BLUE);
cprintf(" %s %s \n\n\r",dato.nombre,dato.apell);
textbackground(RED);
cprintf(" 1) DIRECCION : %s\n\r",dato.direcc);
cprintf(" 2) LOCALIDAD : %s\n\r",dato.local);
cprintf(" 3) TRABAJO PARTICULAR : %s\n\r",dato.tp);
cprintf(" 4) TELEFONO : %s\n\r",dato.telef);
cprintf(" 5) FECHA DE NACIMIENTO DIA : %d\n\r",dato.f.dia);
cprintf(" 6) MES : %d\n\r",dato.f.mes);
cprintf(" 7) A¥O : %d\n\r",dato.f.anio);
cprintf(" 8) ALARMA DIA : %d\n\r",dato.a.dia);
cprintf(" 9) MES : %d\n\r",dato.a.mes);
cprintf(" 10) A¥O : %d\n\r",dato.a.anio);
cprintf(" 11) OBSERVACIONES : %s\n\r",dato.observ);
cprintf(" 12) Terminar las modificaciones.");
gotoxy(5,17);
textcolor(YELLOW);
cprintf("Ingrese el numero del campo a modificar : ");
do{
gotoxy(47,17);
printf(" ");
gotoxy(47,17);
scanf("%d",&nc);
fflush(stdin);
}while(nc<1||nc>12);

switch(nc){
case 1 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
gets(nd);
valida_rangos(nd,26,18,"direccion",40);
valida_cambio_vec(nd,&dato,1);
break;
case 2 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
gets(nd);
valida_rangos(nd,26,18,"localidad",40);
valida_cambio_vec(nd,&dato,2);
break;
case 3 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
gets(nd);
valida_rangos(nd,26,18,"trabajo",40);
valida_cambio_vec(nd,&dato,3);
break;
case 4: gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
gets(nd);
valida_rangos(nd,26,18,"telefono",30);
valida_cambio_vec(nd,&dato,4);
break;
case 5 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
scanf("%d",&aux);
fflush(stdin);
valida_fecha(&aux,26,18,"dia",1,31);
valida_cambio_fechas(&aux,&dato,1);
break;
case 6 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
scanf("%d",&aux);
fflush(stdin);
valida_fecha(&aux,26,18,"mes",1,12);
valida_cambio_fechas(&aux,&dato,2);
break;
case 7 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
scanf("%d",&aux);
fflush(stdin);
valida_anio(&aux,1);
valida_cambio_fechas(&aux,&dato,3);
break;
case 8 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
scanf("%d",&aux);
fflush(stdin);
valida_fecha(&aux,26,18,"dia",1,31);
valida_cambio_fechas(&aux,&dato,4);
break;
case 9 : gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
textcolor(WHITE);
scanf("%d",&aux);
fflush(stdin);
valida_fecha(&aux,26,18,"mes",1,12);
valida_cambio_fechas(&aux,&dato,5);
break;
case 10: gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
textcolor(WHITE);
scanf("%d",&aux);
fflush(stdin);
valida_anio(&aux,2);
valida_cambio_fechas(&aux,&dato,6);
break;
case 11: gotoxy(5,18);
textcolor(YELLOW);
cprintf("Ingrese Nuevo Dato : ");
textcolor(WHITE);
gets(nd);
valida_rangos(nd,26,18,"observacion",200);
valida_cambio_vec(nd,&dato,5);
break;
case 12: goto otra;

} /* switch */
textcolor(WHITE);
gotoxy(10,23);
cprintf("¨¨ Desea modificar otro dato (S/N) ?? : ");
do{
rta=tolower(getche());
if(rta=='n') {
cant=fwrite(&dato,sizeof(dato),1,punt);
if(cant!=1){
gotoxy(1,25);
printf("\aError al escribir archivo");
getch();
delline();
}
goto otra;
}
}while(rta!='s'&&rta!='n');
}
}
}
otra:
textcolor(WHITE);
textbackground(RED);
gotoxy(10,24);
cprintf("¨¨ Desea modificar algun dato de otra persona (S/N) ?? ");

do{
rta=tolower(getche());
if(rta=='s') {
rewind(punt);
}
if(rta=='n') {
fclose(punt);
return 0;
}
}while(rta!='s'&&rta!='n');
}
}

/****************************************************************/
/* BACKUP */
/****************************************************************/

void backup(void){
FILE *origen, *destino;
int cant;
struct datos d;

if((origen=fopen("a:\\agenda.dat","rb"))==NULL){
clrscr();
printf("Error al abrir archivo origen");
getch();
exit(1);
}
if((destino=fopen("C:\\backup.bak","wb"))==NULL){
clrscr();
printf("Error al abrir archivo destino");
getch();
exit(2);
}

textbackground(BLACK);
gotoxy(25,21);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(25,22);
cprintf(" º GENERANDO COPIA ... º ");
gotoxy(25,23);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
delay(1000);
while(feof(origen)==0){
cant=fread(&d,sizeof(d),1,origen);
if(cant != 1){
if(feof(origen)){
break;
} else {
gotoxy(1,25);
clreol();
printf("\aError al leer el £ltimo, no se pudo hacer la copia.");
getch();
break;
}
}
cant=fwrite(&d,sizeof(d),1,destino);
if(cant != 1){
if(feof(origen)){
break;
} else {
gotoxy(1,25);
clreol();
printf("\aError al escribir el £ltimo, no se pudo hacer la copia.");
getch();
break;
}
}
}
fcloseall();
gotoxy(25,22);
cprintf(" º LISTO º ");
delay(1000);

}

/****************************************************************/
/* BUSCAR */
/****************************************************************/

void buscar(void){

char aux,bus[30];
int cant,pos=9,flag=0;
FILE *punt;
struct datos dato;

for ( ; ; ){
poner_recuadro('b');

for( ; ; ){

switch(pos) {
case 9 : gotoxy(22,pos);
textcolor(WHITE);
textbackground(BLUE);
cprintf(" Buscar por Apellido ");
aux=getch();
textcolor(YELLOW);
textbackground(RED);
gotoxy(22,pos);
cprintf(" Buscar por Apellido ");
if(aux==0x0d) goto busqueda_apellido;
break;
case 11 : gotoxy(22,pos);
textcolor(WHITE);
textbackground(BLUE);
cprintf(" Buscar por Localidad ");
aux=getch();
textcolor(YELLOW);
textbackground(RED);
gotoxy(22,pos);
cprintf(" Buscar por Localidad ");
if(aux==0x0d) goto busqueda_localidad;
break;
case 13 : gotoxy(22,pos);
textcolor(WHITE);
textbackground(BLUE);
cprintf(" Volver al Men£ Principal ");
aux=getch();
textcolor(YELLOW);
textbackground(RED);
gotoxy(22,pos);
cprintf(" Volver al Men£ Principal ");
break;
}
switch(aux){
case 0x48 : pos=pos-2;
if(pos==7) pos=13;
break;
case 0x50 : pos=pos+2;
if(pos==15) pos=9;
break;
case 0x0d : return;

}
}

busqueda_localidad:

if ((punt=fopen("a:\\agenda.dat","rb"))==NULL){
clrscr();
gotoxy(1,25);
clreol();
printf("\aError al abrir archivo !!!!");
getch();
exit(0);
}

textcolor(YELLOW);
textbackground(RED);
gotoxy(10,18);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(10,19);
cprintf(" º INGRESE LOCALIDAD A BUSCAR : º ");
gotoxy(10,20);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
textcolor(WHITE);
textbackground(BLUE);
gotoxy(42,19);
cprintf(" ");
gotoxy(43,19);
gets(bus);
strlwr(bus);
bus[0]=toupper(bus[0]);

for( ; ; ){
cant=fread(&dato,sizeof(dato),1,punt);
if(cant!=1){
if(feof(punt)){
break;
}else{
gotoxy(1,25);
clreol();
printf("\aError al leer archivo !!!!");
getch();
break;
}
}
if(strcmp(dato.local,bus)==0){
flag=1;
mostrar_resultado_busqueda(&dato);
getch();
}
}

goto fin;

busqueda_apellido:

if ((punt=fopen("a:\\agenda.dat","rb"))==NULL){
clrscr();
gotoxy(1,25);
clreol();
printf("\aError al abrir archivo !!!!");
getch();
exit(0);
}

textcolor(YELLOW);
textbackground(RED);
gotoxy(10,18);
cprintf(" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ");
gotoxy(10,19);
cprintf(" º INGRESE APELLIDO A BUSCAR : º ");
gotoxy(10,20);
cprintf(" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ");
textcolor(WHITE);
textbackground(BLUE);
gotoxy(42,19);
cprintf(" ");
gotoxy(43,19);
gets(bus);
strlwr(bus);
bus[0]=toupper(bus[0]);

for( ; ; ){
cant=fread(&dato,sizeof(dato),1,punt);
if(cant!=1){
if(feof(punt)!=0){
break;
}else{
gotoxy(1,25);
clreol();
printf("\aError al leer archivo !!!!");
getch();
break;
}
}
if(strcmp(dato.apell,bus)==0){
flag=1;
mostrar_resultado_busqueda(&dato);
getch();
}
}

fin:
if(flag==0){
gotoxy(43,19);
cprintf("Persona no encontrada !!!");
getch();
}
flag=0;
fclose(punt);
}
}

/****************************************************************/
/* MOSTRAR_RESULTADO_BUSQUEDA */
/****************************************************************/

void mostrar_resultado_busqueda (struct datos *dato){

textcolor(YELLOW);
textbackground(RED);
clrscr();
gotoxy(1,5);
cprintf(" NOMBRE : %s\n\r",dato->nombre);
cprintf(" APELLIDO : %s\n\r",dato->apell);
cprintf(" DIRECCION : %s\n\r",dato->direcc);
cprintf(" LOCALIDAD : %s\n\r",dato->local);
cprintf(" TRABAJO PARTICULAR : %s\n\r",dato->tp);
cprintf(" TELEFONO : %s\n\r",dato->telef);
cprintf(" FECHA DE NACIMIENTO : %2d / %2d / %4d\n\r",dato->f.dia,dato->f.mes,dato->f.anio);
cprintf(" ALARMA : %2d / %2d / %4d\n\r",dato->a.dia,dato->a.mes,dato->a.anio);
cprintf(" OBSERVACIONES : %s\n\r",dato->observ);
gotoxy(10,23);
textcolor(WHITE);
cprintf("Presione cualquier tecla para continuar ... ");
}

/****************************************************************/
/* MENU PRINCIPAL */
/****************************************************************/

int menu(){

int pos=6;
char aux;

poner_recuadro('m');

for( ; ; ){

switch(pos){
case 6 : gotoxy(28,pos);
textcolor(YELLOW);
textbackground(BLACK);
cprintf(" Cargar ");
aux=getch();
textcolor(15);
textbackground(4);
gotoxy(28,pos);
cprintf(" Cargar ");
break;
case 8 : gotoxy(28,pos);
textcolor(YELLOW);
textbackground(BLACK);
cprintf(" Aniversarios ");
aux=getch();
textcolor(15);
textbackground(4);
gotoxy(28,pos);
cprintf(" Aniversarios ");
break;
case 10 : gotoxy(28,pos);
textcolor(YELLOW);
textbackground(BLACK);
cprintf(" Modificar datos ");
aux=getch();
textcolor(15);
textbackground(4);
gotoxy(28,pos);
cprintf(" Modificar datos ");
break;
case 12 : gotoxy(28,pos);
textcolor(YELLOW);
textbackground(BLACK);
cprintf(" Hacer Backup ");
aux=getch();
textcolor(15);
textbackground(4);
gotoxy(28,pos);
cprintf(" Hacer Backup ");
break;
case 14 : gotoxy(28,pos);
textcolor(YELLOW);
textbackground(BLACK);
cprintf(" Buscar ... ");
aux=getch();
textcolor(15);
textbackground(4);
gotoxy(28,pos);
cprintf(" Buscar ... ");
break;
case 16 : gotoxy(28,pos);
textcolor(YELLOW);
textbackground(BLACK);
cprintf(" Salir ");
aux=getch();
textcolor(15);
textbackground(4);
gotoxy(28,pos);
cprintf(" Salir ");
break;
}
switch(aux){
case 0x48 : pos=pos-2;
if(pos==4) pos=16;
break;
case 0x50 : pos=pos+2;
if(pos==17) pos=3;
break;
case 0x0d : return pos;
case 0x44 : exit(0);
case 0x3b : ayuda_menu();
break;
case 0x3c : acerca_de();
}
}
}

/****************************************************************/
/* AYUDA DEL MENU PRINCIPAL */
/****************************************************************/

int ayuda_menu(void){

window(4,3,77,23);
textcolor(RED);
textbackground(CYAN);
clrscr();
cprintf(" >>> AGENDA 1.0 <<<\n\r");
cprintf(" ÍÍÍÍÍÍÍÍÍÍ\n\r");
textcolor(BLACK);
cprintf(" CARGAR PERSONAS : Permite ingresar los datos de las personas que desea ");
cprintf(" agregar a la agenda.\n\r");
cprintf(" ANIVERSARIOS : Muestra en pantalla los datos de las personas que ");
cprintf(" cumplen a¤os este dia.\n\r");
cprintf(" MODIFICAR DATOS : Permite modificar los datos que han sido ingresados. \n\r");
cprintf(" HACER BACKUP : Realiza una copia de seguridad de sus archivos de ");
cprintf(" datos.\n\r");
cprintf(" BUSCAR : Mediante esta opcion usted puede realizar una ");
cprintf(" busqueda de una o varias personas. ");
cprintf(" Existen dos criterios de busqueda : por apellido o ");
cprintf(" localidad. En ambos se ingresa el dato y se obtienen ");
cprintf(" todas las personas que coincidan con el dato ");
cprintf(" ingresado.\n\r");
cprintf(" SALIR : Finaliza el programa.\n\n\r");
cprintf(" F1 : Muestra la ayuda.\n\r");
cprintf(" F2 : Autores y version del programa.\n\r");
cprintf(" F10 : Finaliza el programa.\n");
textcolor(RED);
cprintf(" Presione espacio para continuar ... ");
fflush(stdin);

do{
}while(getch()!=0x20);

window(1,1,80,25);
textbackground(BLACK);
clrscr();
fflush(stdin);
poner_recuadro('m');
return(0);
}

/****************************************************************/
/* ACERCA DE ... */
/****************************************************************/

int acerca_de(void){

window(8,6,72,18);
textcolor(BLACK);
textbackground(WHITE);
clrscr();
cprintf(" AGENDA 1.0 COPYRIGHT 2003");
cprintf("\n\n\r Autores : Alonso Medina.\n\r");
cprintf(" \n\n\r");
cprintf(" Este es un software que pretende ayudar a las personas \n\r");
cprintf(" a siempre tener\n\r");
cprintf(" a la mano su informacion y ser una guia para el usuario \n\r");
cprintf(" de la Agenda.\n\r");
cprintf(" \n\r");
cprintf(" No lo pienses demasiado que ya nos los estan quitando de \n\r");
cprintf(" las manos. ­­­­ APURATE !!!!");
window(1,1,80,25);
getch();
poner_recuadro('m');
return(0);
}
/****************************************************************/
/* PONER RECUADRO */
/****************************************************************/

void poner_recuadro(char p){
int i;

tolower(p);
if(p=='b') {
textbackground(BLUE);
clrscr();
for(i=0;i<80*25;i++){
textcolor(LIGHTGRAY);
putch('²');
}
textcolor(14);
textbackground(CYAN);
for(i=0;i<9;i++){
textcolor(BLACK);
gotoxy(22,i+8);
cprintf("ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ\n");
}
gotoxy(20,7);
cprintf("ÖÄÄÄÄį Men£ de B£squeda ®ÄÄÄÄÄ·");
for(i=0;i<7;i++){
gotoxy(20,i+8);
cprintf("º º");
}
gotoxy(20,15);
cprintf("ÓÄÄÄÄÄÄÄį Agenda 1.0 ®ÄÄÄÄÄÄÄĽ");
gotoxy(1,25);
textcolor(YELLOW);
textbackground(RED);
gotoxy(22,9);
cprintf(" Buscar por Apellido ");
gotoxy(22,11);
cprintf(" Buscar por Localidad ");
gotoxy(22,13);
cprintf(" Volver al Men£ Principal ");
gotoxy(50,9);
textcolor(WHITE);
textbackground(BLUE);
gotoxy(1,25);
cprintf(" MENU DE BUSQUEDA : 2 CRITERIOS -> POR APELLIDO O POR LOCALIDAD ");
}
if(p=='m'){
textbackground(RED);
clrscr();
clrscr();
for(i=0;i<80*25;i++){
textcolor(LIGHTGRAY);
putch('²');
}
textcolor(14);
textbackground(CYAN);
for(i=0;i<15;i++){
textcolor(BLACK);
gotoxy(25,i+5);
cprintf("ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ\n");
}

gotoxy(23,4);
cprintf("ÖÄÄÄį Men£ Principal ®ÄÄÄÄ·");
for(i=0;i<13;i++){
gotoxy(23,i+5);
textbackground(CYAN);
cprintf("º º");
}
gotoxy(23,18);
cprintf("ÓÄÄÄÄÄį Agenda 1.0 ®ÄÄÄÄÄĽ");
textcolor(WHITE);
textbackground(RED);
gotoxy(28,6);
cprintf(" Cargar ");
gotoxy(28,8);
cprintf(" Aniversarios ");
gotoxy(28,10);
cprintf(" Modificar datos ");
gotoxy(28,12);
cprintf(" Hacer Backup ");
gotoxy(28,14);
cprintf(" Buscar ... ");
gotoxy(28,16);
cprintf(" Salir ");
barra();

}
}

/****************************************************************/
/* BARRA INFERIOR */
/****************************************************************/

void barra(void){
gotoxy(1,25);
textattr(WHITE + BLINK);
textbackground(BLUE);
cprintf(" F1 -> AYUDA F2 -> ACERCA DE ... F10 -> SALIR ");
gotoxy(49,25);
textcolor(WHITE);
cprintf(" AGENDA 1.0 (C)opyright 2003");
gotoxy(1,1);
textcolor(WHITE);
textbackground(RED);
cprintf(" Utilize las flechas del cursor para desplazarse.");
gotoxy(50,1);
textcolor(WHITE);
cprintf(" Enter para aceptar su opci¢n.");
}
 
Terminos de Uso

1 - Copiar o Descargarse este contenido implica aceptar los terminos aqui detallados.

2 - Usted puede utilizar este contenido en sus propios programas y puede compilarlo en un programa y modificarlo a su gusto.

3 - Usted NO PUEDE redistribuir este contenido tal como se presenta aqui sin el permiso del autor original del mismo.

4 - Usted seguirá cualquier restricción adicional del copyright que el autor pudo haber puesto en la descripción del contenido.

 

Contactos myStudio Network