Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <Validador.h>
- #include <windows.h>
- #include <time.h>
- #define LENISBN 14
- #define LENTITULO 51
- #define LENEDIT 81
- #define LENIDAUTOR 11
- #define LENNOMB 41
- #define LENAPEL 36
- #define LENIDDOC 21
- #define LENTELEFONO 11
- typedef struct
- {
- unsigned short int dd, mm, yyy;
- } FECHA;
- typedef struct
- {
- char ISBN[LENISBN];
- char titulo[LENTITULO];
- char editora[LENEDIT];
- char idautor[LENIDAUTOR];
- FECHA fechaedicion;
- int edicion;
- } LIBRO;
- typedef struct
- {
- char idautor[LENIDAUTOR];
- char nombres[LENNOMB];
- char apellidos[LENAPEL];
- FECHA fechanacimiento;
- } AUTOR;
- typedef struct
- {
- char iddocumento[LENIDDOC];
- char telefono[LENTELEFONO];
- char nombres[LENNOMB];
- char apellidos[LENAPEL];
- } USUARIO;
- typedef struct
- {
- char iddocumento[LENIDDOC];
- char ISBN[LENISBN];
- FECHA fecprestamo;
- FECHA fecdevolucion;
- int diasprestamo;
- float recargodiario;
- } PRESTAMOS;
- typedef struct nodoU
- {
- USUARIO user;
- struct nodoU *sig,*ant;
- }NODOU;
- typedef struct nodoA
- {
- AUTOR autor;
- struct nodoA *sig,*ant;
- }NODOA;
- typedef struct nodoL
- {
- LIBRO libro;
- struct nodoL* sig;
- struct nodoL* ant;
- }NODOL;
- typedef struct nodoP
- {
- PRESTAMOS prestamos;
- struct nodoP *sig,*ant;
- }NODOP;
- // Asignacion de listas
- // Funciones para el usuario
- void nodoUSER(NODOU **,NODOU **,USUARIO );
- USUARIO capuser(void);
- USUARIO ExisteUser(NODOU *cab, char* Busq);
- USUARIO capuser();
- int EliminarUsuario(NODOU **cabeza,NODOU **cola,int Dato);
- // Funciones para el Prestamo
- PRESTAMOS SolicitarPrestamo(USUARIO *Infouser, LIBRO InfoLibro );
- void ScrollingPRESTAMO(NODOP **cab, NODOP **cola, int *n);
- void impuPRESTAMO(int y,NODOP *cabactual, NODOP **cola, int CFS, int CTS, int *sel, int Num);
- void nodoPRESTAMO(NODOP **cab, NODOP **cola,PRESTAMOS prestamo);
- int EliminarPrestamo(NODOP **cabeza, NODOP **cola, int Dato);
- //Funciones para el Autor
- int BuscarAutor(NODOA *, char *);
- void nodoAUTOR(NODOA **,NODOA **, AUTOR );
- AUTOR capautor(int );
- AUTOR capautor(int Nautores);
- int EliminarAutor(NODOA **cabeza,NODOA **cola,int Dato);
- // Funciones para Libro
- LIBRO caplibro(NODOA *);
- LIBRO existeLIBRO(NODOL *cab, char *Busq);
- void nodoLIBRO(NODOL **, NODOL **, LIBRO);
- LIBRO caplibro(NODOA *cab);
- int EliminarLibro(NODOL **cabeza,NODOL **cola,int Dato);
- LIBRO existeLIBRO(NODOL *cab, char *Busq);
- // Otros
- int Comparar(char *str1, char *str2);
- void Limpiar();
- void IDasig(char *, int);
- int BuscarAutor(NODOA *cab, char *busq);
- int ValidaFechas(int D1, int M1, int Y1, int D2, int M2, int Y2);
- void SeguroBorrar(char *tecla);
- int Comparar(char *str1, char *str2);
- void SeguroBorrar(char *tecla);
- int PalabraG(char *aux);
- int main(){
- char Mensaje[CANT][LEN] = {"Libros ",
- "Usuarios ",
- "Autores ",
- "Salir "
- };
- char opcionLibro[CANT][LEN] = {"Prestamo ",
- "Agregar Libro ",
- "Editar libro ",
- "Volver "
- };
- char opcionUser[CANT][LEN] = {"Registrar Usuario",
- "Editar usuario ",
- "Volver "};
- char opcionAutor[CANT][LEN] = {"Registrar Autor",
- "Editar Autor ",
- "Volver "};
- char opcionPrestamo[CANT][LEN] = {"Solicitar Prestamo",
- "Prestamos Actuales",
- "Volver "};
- int accion,indAutor = 0,indDoc = 1,accionLib,accionUser,accionAutor,accionPrestamo,CL=0,CU=0,CP=0,comp;
- char userB[LENNOMB],libroB[LENNOMB], resp;
- NODOA *cabezaA,*colaA;
- cabezaA = colaA = NULL;
- NODOL *cabezaL,*colaL;
- cabezaL = colaL = NULL;
- NODOU *cabezaU,*colaU,*nom;
- cabezaU = colaU = NULL;
- NODOP *cabezaP,*colaP;
- cabezaP = colaP = NULL;
- USUARIO userP,let = {ENTER,ENTER,ENTER,ENTER};;
- LIBRO libroP,letN = {ENTER,ENTER,ENTER,ENTER,ENTER,ENTER};;
- accion = Menu(Mensaje,4,40,5,LIGHTBLUE,WHITE,YELLOW,RED);
- Limpiar();
- while(accion != 3){
- switch(accion){
- case 0 :
- accionLib = Menu(opcionLibro,4,40,4,LIGHTBLUE,WHITE,YELLOW,RED);
- Limpiar();
- switch(accionLib){
- case 0 :
- Limpiar();
- if(CL > 0 && CU > 0){
- accionPrestamo = Menu(opcionPrestamo,3,40,4,LIGHTBLUE,WHITE,YELLOW,RED);
- Limpiar();
- switch(accionPrestamo){
- case 0 :
- Colores(WHITE,BLACK);
- gotoxy(40,4);
- printf("Introduce Informacion del usuario (Nombres,telefonos ETC).");
- CapChar(userB,1,'!',55,7,15);
- do{userP = ExisteUser(cabezaU,userB);
- comp = Comparar(userP.nombres,let.nombres);
- if(comp == 1){
- printf("\n Usuario no existe, %cDesea continuar?",168);
- do{
- resp = toupper(getch());
- if(resp == 'N'){
- comp = 2;
- }
- if(resp == 'S'){
- Colores(BLACK,BLACK);
- gotoxy(40,4);printf("\n ");
- CapChar(userB,1,'!',55,7,15);
- }
- }while(resp != 'N' && resp != 'S');
- }
- }while(comp == 1);
- if(comp != 2){
- gotoxy(60,7);
- printf("Introduce Informacion del Libro.");
- CapChar(libroB,1,'!',55,10,15);
- do{libroP = existeLIBRO(cabezaL,libroB);
- comp = Comparar(libroP.editora,letN.editora);
- if(comp == 1){
- printf("\n Libro no existe, %cDesea continuar?",168);
- do{
- resp = toupper(getch());
- if(resp == 'N'){
- comp = 2;
- }
- if(resp == 'S'){
- Colores(BLACK,BLACK);
- gotoxy(60,7);printf("\n ");
- CapChar(libroB,1,'!',55,10,15);
- }
- }while(resp != 'N' && resp != 'S');
- }
- }while(comp == 1);
- if(comp != 2)
- {IDasig(userP.iddocumento,CP+1);
- nodoPRESTAMO(&cabezaP,&colaP,SolicitarPrestamo(&userP,libroP));
- CP++;
- Limpiar();
- }
- }
- else{
- Limpiar(); Sleep(500);
- Colores(BLACK,LIGHTRED); gotoxy(40,5);
- printf("Debes ingresar un libro primero o un usuario"); Sleep(1000);
- }
- break;
- case 1 :
- if(CP > 0){
- ScrollingPRESTAMO(&cabezaP,&colaP,&CP);
- Limpiar();}
- }
- break;
- }
- else{
- Limpiar(); Sleep(500);
- Colores(BLACK,LIGHTRED); gotoxy(40,5);
- printf("Debes registrar un prestamo primero"); Sleep(1000);
- }
- break;
- case 1 :
- nodoLIBRO(&cabezaL,&colaL,caplibro(cabezaA));
- CL++;
- break;
- case 2 :
- if(CL > 0){
- ScrollingLIBRO(&cabezaL,&colaL,&CL,cabezaA,cabezaP);
- Limpiar();}
- else{
- Limpiar(); Sleep(500);
- Colores(BLACK,LIGHTRED); gotoxy(40,5);
- printf("Debes ingresar un libro primero"); Sleep(1000);
- }
- }
- break;
- case 1 :
- accionUser = Menu(opcionUser,3,40,5,LIGHTBLUE,WHITE,YELLOW,RED);
- Limpiar();
- switch(accionUser){
- case 0 :
- gotoxy(45,5);
- Colores(WHITE,LIGHTGRAY);
- nodoUSER(&cabezaU,&colaU,capuser());
- CU++;
- break;
- case 1 :
- if(CU > 0){
- ScrollingUSER(&cabezaU,&colaU,&CU,cabezaP);
- Limpiar();}
- else{
- Limpiar(); Sleep(500);
- Colores(BLACK,LIGHTMAGENTA); gotoxy(40,5);
- printf("Debes ingresar un usuario primero"); Sleep(1000);
- }
- }
- break;
- case 2 :
- accionAutor = Menu(opcionAutor,3,40,5,LIGHTBLUE,WHITE,YELLOW,RED);
- Limpiar();
- switch(accionAutor){
- case 0 :
- nodoAUTOR(&cabezaA,&colaA,capautor(indAutor));
- indAutor++;
- break;
- case 1 :
- if(indAutor > 0){
- ScrollingAUTOR(&cabezaA,&colaA,&indAutor,cabezaL);
- Limpiar();
- }
- else{
- Limpiar(); Sleep(500);
- Colores(BLACK,YELLOW); gotoxy(40,5);
- printf("Debes ingresar un autor primero"); Sleep(1000);
- }
- }
- break;
- }
- Limpiar();
- accion = Menu(Mensaje,4,40,5,LIGHTBLUE,WHITE,YELLOW,RED);
- Limpiar();
- }// while
- }
- /// Prestamos
- /*
- Funcion: "ScrollingPrestamo"
- Argumento: NODOP **cab = "cabeza la lista", NODOP **cola = "Cola de la lista" int *n = "Cantidad de prestamos actuales",
- Es un puntero porque su valore puede modificarse.
- Objetivo: "Desplazar todos los prestamos actuales"
- Retorno: "Nada"
- */
- void ScrollingPRESTAMO(NODOP **cab, NODOP **cola, int *n){
- Limpiar();
- NODOP *IND,*CabezaActual;
- CabezaActual = *cab;
- int indy = 6,indice = 1;
- char letra,teclaBorrar;
- Colores(BLACK,WHITE);
- indy = 6;
- int select = 0,Turno = 0,busqueda = 0;
- char tecla;
- _setcursortype(0);
- do{
- impuPRESTAMO(indy,CabezaActual,cola,BLACK,LIGHTRED,&select,*n);
- tecla = getch();
- if ( tecla == ARRIBA)
- {
- if(CabezaActual != *cab){
- select--;
- Turno--;
- }
- }
- if ( tecla == ABAJO )
- {
- select++;
- Turno++;
- if(Turno >= 4){
- CabezaActual = CabezaActual->sig;
- select = 3;
- }
- if ( Turno == *n )
- { select = 0;
- CabezaActual = *cab;
- Turno = 0;
- }
- }
- if(tecla == ENTER){
- for (IND = *cab; IND; IND = IND->sig){
- if(busqueda == Turno){
- PagarPrestamo(cab,cola,Turno);
- EliminarPrestamo(cab,cola,Turno);
- break;
- }
- busqueda++;
- }
- tecla = ESP;
- }
- }while ( tecla != ESP && tecla != ENTER );
- if ( tecla == ESP )
- select = -1;
- }
- /*
- Funcion: "impuPRESTAMO"
- Argumento: NODOP *cabactual = "Nodo que varia mediante el scrolling", NODOP **cola = "Cola de la lista, para saber su valor debe ser **",
- int y = "Coordenada en el eje y, (de 6 a 9)", int CFS = "Color de fonddo seleccionado del scrolling", int CTS = "Color de texto seleccionado,
- del scrolling", int *sel = "Numero de seleccion actual en el scrlling", int Num = cantidad de elementos en la lista
- Es un puntero porque su valore puede modificarse.
- Objetivo: "imprimir todos los prestamos actuales"
- Retorno: "Nada"
- */
- void impuPRESTAMO(int y,NODOP *cabactual, NODOP **cola, int CFS, int CTS, int *sel, int Num){
- int indice = 0,info,mayor = 25,x,cont,MayorindN=6,MayorindA = 8,MayorindT = 8,posy,mayorNAT=10;
- NODOP *IND;
- // Evaluar impresion tabulada
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->prestamos.iddocumento);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- info = PalabraG(IND->prestamos.ISBN);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- }
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->prestamos.iddocumento);
- if(info > MayorindN)
- {
- MayorindN = info;
- }
- info = PalabraG(IND->prestamos.ISBN);
- if(info > MayorindA)
- {
- MayorindA = info;
- }
- }
- if(cabactual != *cola){
- for (IND = cabactual; IND; IND = IND->sig,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- printf("%s",IND->prestamos.iddocumento);
- // evalua nombres denuevo para saber la posision del apellido
- info = PalabraG(IND);
- x = 41 + MayorindN;
- gotoxy(x,y);
- printf(" %s",IND->prestamos.ISBN);
- }
- y++;
- }
- }
- else{
- for (IND = cabactual; IND; IND = IND->ant,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- printf("%s",IND->prestamos.iddocumento);
- x = 41 + MayorindN;
- gotoxy(x,y);
- printf(" %s",IND->prestamos.ISBN );
- }
- y++;
- }
- }
- gotoxy(40,5);
- Colores(WHITE,BLACK);
- printf("USUARIO");
- cont = 7;
- if(MayorindN > 7)
- for(cont;cont<MayorindN;cont++){
- printf(" ");
- }
- printf("|");
- x = 41 + MayorindN;
- gotoxy(x,5);
- printf(" ISBN");
- cont = 5;
- for(cont;cont<MayorindA;cont++){
- printf(" ");
- }
- printf("|");
- return;
- }
- /*
- Funcion: IDasig
- Argumento: char *ID = "Variable a modificar con el ID", int Numemp= "Cantidad de repeticiones en funcion de elementos"
- Objetivo: "Asignar el ID del documento y de el autor"
- Retorno: "Nada"
- */
- void IDasig(char *ID, int Numemp){
- int ind;
- for(ind=0;ind<Numemp;){
- ind++;
- }
- if(ind<=9){
- sprintf(ID,"000000000%d%c",ind,ENTER);
- }
- else if(ind > 9 && ind <= 99){
- sprintf(ID,"00000000%d%c",ind,ENTER);
- }
- else if(ind > 99 && ind <= 999 ){
- sprintf(ID,"0000000%d%c",ind,ENTER);
- }
- else if(ind > 999 && ind <= 9999){
- sprintf(ID,"000000%d%c",ind,ENTER);
- }
- else if(ind > 9999 && ind <= 99999){
- sprintf(ID,"00000%d%c",ind,ENTER);
- }
- else if(ind > 99999 && ind <= 999999){
- sprintf(ID,"0000%d%c",ind,ENTER);
- }
- else if(ind > 999999 && ind <= 9999999){
- sprintf(ID,"000%d%c",ind,ENTER);
- }
- else if(ind > 9999999 && ind <= 99999999){
- sprintf(ID,"00%d%c",ind,ENTER);
- }
- else if(ind > 99999999 && ind <= 999999999){
- sprintf(ID,"0%d%c",ind,ENTER);
- }
- else if(ind > 99999999 && ind <= 999999999){
- sprintf(ID,"00%d%c",ind,ENTER);
- }
- else if(ind > 999999999 && ind <= 9999999999){
- sprintf(ID,"0%d%c",ind,ENTER);
- }
- else{
- sprintf(ID,"%d%c",ind,ENTER);
- }
- }
- /*
- Funcion: nodoPRESTAMO
- Argumento: NODOP **cab = "Cabeza que se asignara en la lista, NODOP **cola = "Cola que se modificarra en la lista"
- Objetivo: "Enlazar nodos en la lista en el inicio"
- Retorno: "Nada"
- */
- void nodoPRESTAMO(NODOP **cab, NODOP **cola,PRESTAMOS prestamo){
- NODOP *Colector;
- Colector = (NODOP *) malloc(sizeof(NODOP));
- Colector->prestamos = prestamo;
- Colector->ant = NULL;
- Colector->sig = *cab;
- if(*cab != NULL)
- (*cab)->ant = Colector;
- *cab = Colector;
- return;
- }
- /*
- Funcion: PagarPrestamo
- Argumento: NODOP **cab = "Cabeza que se asignara en la lista, NODOP **cola = "Cola que se modificarra en la lista", int turno = indice de
- valor de empleado.
- Objetivo: "Enlazar nodos en la lista en el inicio"
- Retorno: "Nada"
- */
- void PagarPrestamo(NODOP **cab, NODOP **cola, int Turno){
- int indice = 0,x = 64,y = 6,num = 0,selec,Mora = 0,cargos;
- unsigned short int Dia = 0,Mes = 0,Year = 0;
- char tecla;
- NODOP *IND;
- PRESTAMOS actual;
- for(IND = *cab;IND;IND=IND->sig){
- if(indice == Turno){
- actual = IND->prestamos;
- break;
- }
- indice++;
- Turno++;
- }
- Limpiar();
- gotoxy(45,5);
- Colores(WHITE,BLACK);
- IND = *cab;
- printf("Hola: %s, seleccione libro a devolver",actual.iddocumento);
- while(IND != *cola){
- indice = Comparar(actual.ISBN,IND->prestamos.ISBN);
- if(indice == 1){
- gotoxy(x,y);
- printf("%s",IND->prestamos.ISBN);
- y++;
- }
- IND = IND->sig;
- num++;
- }
- _setcursortype(1);
- for(indice=0;indice<num;){
- tecla = getch();
- if(tecla == ARRIBA && indice != 0){
- y--;
- gotoxy(30,y);
- indice--;
- }
- if(tecla == ABAJO && indice != num-1){
- y++;
- gotoxy(30,y);
- indice++;
- }
- if(tecla == ENTER){
- selec = indice;
- indice = num+1;
- }
- }
- _setcursortype(0); indice = 0;
- for(IND = *cab;IND;IND=IND->sig){
- if(indice == selec){
- Limpiar();
- Colores(WHITE,BLACK);
- gotoxy(35,4);
- printf("Fecha limite de pago:");
- Colores(RED,BLACK);
- printf("%02d/%02d/%d",IND->prestamos.fecdevolucion.dd,IND->prestamos.fecdevolucion.mm,IND->prestamos.fecdevolucion.yyy);
- gotoxy(35,6);
- Colores(WHITE,BLACK);
- _setcursortype(1);
- printf("Introduce fecha de devoluci%cn:",162);
- do{
- Fechas(&Dia,&Mes,&Year,65,6);
- }while(ValidaFechas(Dia,Mes,Year,IND->prestamos.fecprestamo.dd,IND->prestamos.fecprestamo.mm,IND->prestamos.fecprestamo.yyy) == 2);
- if(ValidaFechas(Dia,Mes,Year,IND->prestamos.fecdevolucion.dd,IND->prestamos.fecdevolucion.mm,IND->prestamos.fecdevolucion.yyy) == 1){
- for(indice=IND->prestamos.fecdevolucion.dd;Mora<IND->prestamos.diasprestamo;){
- Mora++;
- cargos = Mora * 10;
- }
- gotoxy(35,7); Colores(YELLOW,LIGHTRED);
- printf("Entrega tarde, Cargos por mora: %d",cargos);
- }
- gotoxy(35,8);
- Colores(WHITE,LIGHTGREEN);
- printf("Prestamo pagado, libro devuelto :)");
- tecla = getch();
- break;
- }
- indice++;
- }
- }
- /*
- Funcion: EliminarPrestamo
- Argumento: NODOA **cabeza = "Cabeza que se asignara en la lista, NODOA **colaola = "Cola que se modificarra en la lista", int Dato = " Opcion
- De prestamo registrada,
- autor que se unira a la lista.
- Objetivo: "Eliminar prestamo pagado"
- Retorno: "Nada"
- */
- int EliminarPrestamo(NODOP **cabeza, NODOP **cola, int Dato){
- NODOP *actual = *cabeza,*anteriot,*siguiente;
- char *NomBuscar;
- NomBuscar = (char *)malloc(sizeof(char));
- int indice = 0;
- while(actual != NULL)
- {
- if(indice == Dato)
- {
- if( actual == *cabeza)
- {
- *cabeza = actual->sig;
- }
- else if( actual->sig == NULL)
- {
- anteriot = actual->ant;
- *cola = anteriot;
- anteriot->sig = NULL;
- }
- else
- {
- anteriot = actual->ant;
- actual->ant = NULL;
- siguiente = actual->sig;
- actual->sig = NULL;
- anteriot->sig = siguiente;
- siguiente->ant = anteriot;
- }
- free(actual);
- return 1;
- }
- }
- }
- /// usuario
- /*
- Funcion: nodoUSER
- Argumento: NODOU **cab = "Cabeza que se asignara en la lista, NODOU **cola = "Cola que se modificarra en la lista", USUARIO usuario ,
- Usuario que se unira a la lista.
- Objetivo: "Enlazar nodos en la lista en el inicio"
- Retorno: "Nada"
- */
- void nodoUSER(NODOU **cab,NODOU **cola,USUARIO usuario)
- {
- NODOU *lector;
- //FILE *UsuarioF;
- //UsuarioF = fopen("C:\\Users\\r_rok\\Desktop\\Biblioteca\\Archivos.dat","ab");
- lector = (NODOU *) malloc(sizeof(NODOU));
- lector->user = usuario;
- lector->ant = NULL;
- lector->sig = *cab;
- if(*cab != NULL)
- (*cab)->ant = lector;
- *cab = lector;
- return;
- /*fwrite(lector,sizeof(USUARIO),sizeof(USUARIO),UsuarioF);
- fclose(UsuarioF);*/
- }
- /*
- Funcion: capuser
- Argumento: ninguno
- Objetivo: "Crear nuveo usuario a la estructura"
- Retorno: "Un nuevo usuario"
- */
- USUARIO capuser(){
- USUARIO user;
- // user = (USUARIO *) malloc(sizeof(USUARIO));
- strcpy(user.iddocumento," ");
- printf("Nombre");
- CapChar(&user.nombres,1,'A',42,7,15);
- gotoxy(45,7);
- Colores(WHITE,LIGHTGRAY);
- printf("Apellido");
- CapChar(&user.apellidos,1,'A',42,9,15 );
- gotoxy(45,9);
- Colores(WHITE,LIGHTGRAY);
- printf("Telefono");
- CapChar(&user.telefono,1,'8',42,11,15 );
- return user;
- }
- void ScrollingUSER(NODOU **cab, NODOU **cola, int *n, NODOP *cabezaP)
- {
- NODOU *IND,*CabezaActual;
- NODOP *INDP;
- CabezaActual = *cab;
- int indy = 6,indice = 1;
- char letra,teclaBorrar;
- Colores(BLACK,WHITE);
- indy = 6;
- int select = 0,Turno = 0,busqueda = 0,res;
- char tecla;
- _setcursortype(0);
- do{
- impusuario(indy,CabezaActual,cola,YELLOW,BLACK,&select,*n);
- tecla = getch();
- if ( tecla == ARRIBA)
- {
- if(CabezaActual != *cab){
- select--;
- Turno--;
- }
- }
- if ( tecla == ABAJO )
- {
- select++;
- Turno++;
- if(Turno >= 4){
- CabezaActual = CabezaActual->sig;
- select = 3;
- }
- if ( Turno == *n )
- { select = 0;
- CabezaActual = *cab;
- Turno = 0;
- }
- }
- if(tecla == BORRAR){
- for(IND = *cab;IND;IND = IND->sig){
- if(busqueda == Turno)
- { for(INDP=cabezaP;INDP;INDP = INDP->sig){
- res = Comparar(IND->user.nombres,INDP->prestamos.iddocumento);
- if(res == 1){
- break;
- }
- }
- break;
- }
- busqueda++;
- }
- if(res != 1){
- SeguroBorrar(&teclaBorrar);
- if(teclaBorrar == 's'){
- EliminarUsuario(cab,cola,Turno);
- (*n)--;
- tecla = ESP;
- }
- }
- else if(res == 1){
- gotoxy(40,15);
- Colores(WHITE,LIGHTRED);
- printf("El usuario tiene un prestamo...");
- Sleep(1500);
- gotoxy(40,15); Colores(BLACK,BLACK);
- printf(" ");
- }
- }
- if(tecla == ENTER){
- for (IND = *cab; IND; IND = IND->sig){
- if(busqueda == Turno){
- EditorUSER(cab,cola,&IND);
- break;
- }
- busqueda++;
- }
- tecla = ESP;
- }
- }while ( tecla != ESP && tecla != ENTER );
- if ( tecla == ESP )
- select = -1;
- }
- void impusuario(int y,NODOU *cabactual, NODOU **cola, int CFS, int CTS, int *sel, int Num)
- {
- int indice = 0,info,mayor = 25,x,cont,MayorindN=6,MayorindA = 8,MayorindT = 8,posy,mayorNAT=10,ind2;
- NODOU *IND;
- // Evaluar impresion tabulada
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->user.nombres);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- info = PalabraG(IND->user.apellidos);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- info = PalabraG(IND->user.telefono);
- if(info > mayor)
- {
- mayor = info;
- }
- }
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->user.nombres);
- if(info > MayorindN)
- {
- MayorindN = info;
- }
- info = PalabraG(IND->user.apellidos);
- if(info > MayorindA)
- {
- MayorindA = info;
- }
- info = PalabraG(IND->user.telefono);
- if(info > MayorindT)
- {
- MayorindT = info;
- }
- }
- if(cabactual != *cola){
- for (IND = cabactual; IND; IND = IND->sig,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- for(ind2=0;ind2<MayorindN;ind2++)
- printf("%c",IND->user.nombres[ind2]);
- // evalua nombres denuevo para saber la posision del apellido
- info = PalabraG(IND->user.nombres);
- x = 41 + MayorindN;
- gotoxy(x,y);
- for(ind2=0;ind2<MayorindA;ind2++)
- printf("%c",IND->user.apellidos[ind2]);
- gotoxy(x+MayorindA+1,y);
- for(ind2=0;ind2<MayorindT;ind2++)
- printf("%c",IND->user.telefono[ind2]);
- }
- y++;
- }
- }
- else{
- for (IND = cabactual; IND; IND = IND->ant,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- for(ind2=0;ind2<MayorindN;ind2++)
- printf("%c",IND->user.nombres[ind2]);
- // evalua nombres denuevo para saber la posision del apellido
- info = PalabraG(IND->user.nombres);
- x = 41 + MayorindN;
- gotoxy(x,y);
- for(ind2=0;ind2<MayorindA;ind2++)
- printf("%c",IND->user.apellidos[ind2]);
- gotoxy(x+MayorindA+2,y);
- for(ind2=0;ind2<MayorindT;ind2++)
- printf("%c",IND->user.telefono[ind2]);
- }
- y++;
- }
- }
- gotoxy(40,5);
- Colores(WHITE,BLACK);
- printf("NOMBRE");
- cont = 6;
- if(MayorindN > 6)
- for(cont;cont<MayorindN;cont++){
- printf(" ");
- }
- printf("|");
- x = 41 + MayorindN;
- gotoxy(x,5);
- printf(" APELLIDO");
- cont = 8;
- for(cont;cont<MayorindA;cont++){
- printf(" ");
- }
- printf("|");
- if(MayorindA > 8 || MayorindN > 6){
- x = 56 + MayorindA;}
- else{
- x = 57;
- }
- gotoxy(x,5);
- printf(" Telefono ");
- return;
- }
- /*
- Funcion: Eliminarusuario
- Argumento: NODOA **cabeza = "Cabeza que se asignara en la lista, NODOA **colaola = "Cola que se modificarra en la lista", int Dato = " Opcion
- De prestamo registrada,
- autor que se unira a la lista.
- Objetivo: "Eliminar usuario seleccionado"
- Retorno: "Nada"
- */
- int EliminarUsuario(NODOU **cabeza,NODOU **cola,int Dato)
- {
- NODOU *actual = *cabeza,*anteriot,*siguiente;
- int indice = 0;
- while(actual != NULL)
- {
- if(indice == Dato)
- {
- if( actual == *cabeza)
- {
- *cabeza = actual->sig;
- }
- else if( actual->sig == NULL)
- {
- anteriot = actual->ant;
- *cola = anteriot;
- anteriot->sig = NULL;
- }
- else
- {
- anteriot = actual->ant;
- actual->ant = NULL;
- siguiente = actual->sig;
- actual->sig = NULL;
- anteriot->sig = siguiente;
- siguiente->ant = anteriot;
- }
- free(actual);
- return 1;
- }
- actual = actual->sig;
- indice++;
- }
- return 0;
- }
- void EditorUSER(NODOU **cabeza,NODOU **cola,NODOU **actual){
- Limpiar();
- gotoxy(15,2);
- Colores(WHITE,RED);
- printf("Presione (ENTER) si no desea editar nada\n (Espacio en las fechas)");
- gotoxy(25,4);
- Colores(WHITE,BLACK);
- printf("Nombre: ");
- gotoxy(70,3); Colores(LIGHTGRAY,BLACK);
- printf("Apellido: ");
- gotoxy(60,9); Colores(LIGHTGRAY,BLACK);
- printf("Telefono");
- // Primer nombre
- gotoxy(25,4);
- Colores(WHITE,BLACK);
- printf("Nombre: ");
- CapChar((*actual)->user.nombres,1,'A',40,7,16);
- // Apellido
- gotoxy(70,3); Colores(WHITE,BLACK);
- printf("Apellido: ");
- CapChar((*actual)->user.apellidos,1,'A',85,7,16);
- // Telefono
- gotoxy(60,9); Colores(WHITE,BLACK);
- printf("Telefono");
- CapChar((*actual)->user.telefono,1,'3',70,12,16);
- }
- USUARIO ExisteUser(NODOU *cab, char* Busq){
- NODOU *IND;
- USUARIO Encontrado,Ninguno = {ENTER,ENTER,ENTER,ENTER};
- int result;
- for(IND=cab;IND;IND=IND->sig){
- Encontrado = IND->user;
- result = Comparar(IND->user.apellidos,Busq);
- if(result == 1){
- Encontrado = IND->user;
- return Encontrado;
- }
- result = Comparar(IND->user.iddocumento,Busq) ;
- if(result == 1){
- Encontrado = IND->user;
- return Encontrado;
- }
- result = Comparar(IND->user.nombres,Busq);
- if(result == 1){
- Encontrado = IND->user;
- return Encontrado;
- }
- result = Comparar(IND->user.telefono,Busq);
- if(result == 1){
- Encontrado = IND->user;
- return Encontrado;
- }
- }
- return Ninguno;
- }
- /// Autor
- /*
- Funcion: nodoAUTOR
- Argumento: NODOA **cab = "Cabeza que se asignara en la lista, NODOA **cola = "Cola que se modificarra en la lista", AUTOR autor,
- autor que se unira a la lista.
- Objetivo: "Enlazar nodos en la lista en el inicio"
- Retorno: "Nada"
- */
- void nodoAUTOR(NODOA **cab,NODOA **cola, AUTOR autor){
- NODOA *creador;
- creador = (NODOA *) malloc(sizeof(NODOA));
- creador->autor = autor;
- creador->ant = NULL;
- creador->sig = *cab;
- if(*cab != NULL)
- (*cab)->ant = creador;
- *cab = creador;
- return;
- }
- /*
- Funcion: capautor
- Argumento: int Nautores = "Cantidad de autores actuales para asignat el nuevo ID del autor"
- Objetivo: "obtenet datos para los Autores"
- Retorno: "Un nuevo Autor"
- */
- AUTOR capautor(int Nautores){
- AUTOR autor;
- IDasig(&autor.idautor,Nautores+1);
- Colores(WHITE,BLACK);
- gotoxy(43,2);
- printf("ID");
- gotoxy(39,3);
- printf(autor.idautor);
- gotoxy(45,5);
- Colores(WHITE,LIGHTGRAY);
- printf("Nombre");
- CapChar(&autor.nombres,1,'A',42,7,15);
- gotoxy(45,7);
- Colores(WHITE,LIGHTGRAY);
- printf("Apellido");
- CapChar(&autor.apellidos,1,'A',42,9,15 );
- gotoxy(45,9);
- Colores(WHITE,LIGHTGRAY);
- printf("Fecha de nacimiento");
- autor.fechanacimiento.dd = 0;
- autor.fechanacimiento.mm = 0;
- autor.fechanacimiento.yyy = 0;
- do{
- Fechas(&autor.fechanacimiento.dd,&autor.fechanacimiento.mm,&autor.fechanacimiento.yyy,30,9);
- }while(autor.fechanacimiento.yyy > 1999);
- return autor;
- }
- void ScrollingAUTOR(NODOA **cab, NODOA **cola, int *n, NODOL *cabezaL)
- {
- NODOA *IND,*CabezaActual;
- NODOL *INDL;
- CabezaActual = *cab;
- int indy = 6,indice = 1,busqueda=0,res;
- char letra,teclaBorrar;
- Colores(BLACK,WHITE);
- indy = 6;
- int select = 0,Turno = 0;
- char tecla;
- _setcursortype(0);
- do{
- impautor(indy,CabezaActual,cola,YELLOW,BLACK,&select,*n,Turno);
- tecla = getch();
- if ( tecla == ARRIBA)
- {
- if(CabezaActual != *cab){
- select--;
- Turno--;
- }
- }
- if ( tecla == ABAJO )
- {
- select++;
- Turno++;
- if(Turno >= 4){
- CabezaActual = CabezaActual->sig;
- select = 3;
- }
- if ( Turno == *n )
- { select = 0;
- CabezaActual = *cab;
- Turno = 0;
- }
- }
- if(tecla == BORRAR){
- for(IND = *cab;IND;IND = IND->sig){
- if(busqueda == Turno)
- { for(INDL=cabezaL;INDL;INDL = INDL->sig){
- res = Comparar(IND->autor.idautor,INDL->libro.idautor);
- if(res == 1){
- break;
- }
- }
- break;
- }
- busqueda++;
- }
- if(res != 1){
- SeguroBorrar(&teclaBorrar);
- if(teclaBorrar == 's'){
- EliminarAutor(cab,cola,Turno);
- (*n)--;
- tecla = ESP;
- }
- }
- else if(res == 1){
- gotoxy(40,15);
- Colores(WHITE,LIGHTRED);
- printf("El autor esta asignado a un libro...");
- Sleep(1500);
- gotoxy(40,15); Colores(BLACK,BLACK);
- printf(" ");
- }
- }
- if(tecla == ENTER)
- {
- for (IND = *cab; IND; IND = IND->sig)
- {
- if(busqueda == Turno)
- {
- EditorAUTOR(cab,cola,&IND);
- IND = cola;
- busqueda++;
- }
- }
- tecla = ESP;
- }
- }while ( tecla != ESP && tecla != ENTER );
- if ( tecla == ESP )
- select = -1;
- }
- void impautor(int y,NODOA *cabactual, NODOA **cola, int CFS, int CTS, int *sel, int Num, int Pfalsos)
- {
- int indice = 0,info,mayor = 25,x,cont,MayorindN=6,MayorindA = 8,MayorindT = 8,posy,mayorNAT=10,ind2;
- NODOA *IND;
- // Evaluar impresion tabulada
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->autor.nombres);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- info = PalabraG(IND->autor.apellidos);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- }
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->autor.nombres);
- if(info > MayorindN)
- {
- MayorindN = info;
- }
- info = PalabraG(IND->autor.apellidos);
- if(info > MayorindA)
- {
- MayorindA = info;
- }
- }
- if(cabactual != *cola){
- for (IND = cabactual; IND; IND = IND->sig,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(GREEN,BLACK);
- if(y == 7 || y == 9)
- Colores(LIGHTGREEN,BLACK);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- for(ind2=0;ind2<MayorindN;ind2++)
- printf("%c",IND->autor.nombres[ind2]);
- // evalua nombres denuevo para saber la posision del apellido
- info = PalabraG(IND->autor.nombres);
- x = 41 + MayorindN;
- gotoxy(x,y);
- for(ind2=0;ind2<MayorindA;ind2++)
- printf("%c",IND->autor.apellidos[ind2]);
- info = PalabraG(IND->autor.apellidos);
- gotoxy(x+MayorindA+1,y);
- printf(" %02d/%02d/%d",IND->autor.fechanacimiento.dd,IND->autor.fechanacimiento.mm,IND->autor.fechanacimiento.yyy);
- }
- y++;
- }
- }
- else{
- for (IND = cabactual; IND; IND = IND->ant,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- for(ind2=0;ind2<MayorindN;ind2++)
- printf("%c",IND->autor.nombres[ind2]);
- // evalua nombres denuevo para saber la posision del apellido
- info = PalabraG(IND->autor.nombres);
- x = 41 + MayorindN;
- gotoxy(x,y);
- for(ind2=0;ind2<MayorindA;ind2++)
- printf("%c",IND->autor.apellidos[ind2]);
- info = PalabraG(IND->autor.apellidos);
- printf(" %02d/%02d/%d",IND->autor.fechanacimiento.dd,IND->autor.fechanacimiento.mm,IND->autor.fechanacimiento.yyy);
- }
- y++;
- }
- }
- gotoxy(40,5);
- Colores(WHITE,BLACK);
- printf("NOMBRE");
- cont = 6;
- if(MayorindN > 6)
- for(cont;cont<MayorindN;cont++){
- printf(" ");
- }
- printf("|");
- x = 41 + MayorindN;
- gotoxy(x,5);
- printf(" APELLIDO");
- cont = 8;
- for(cont;cont<MayorindA;cont++){
- printf(" ");
- }
- printf("|");
- if(MayorindN > 6 || MayorindA > 8){
- x = 42+mayorNAT+MayorindA;}
- else{
- x = 56;
- }
- if(MayorindA > 8 || MayorindN > 6){
- x = 56 + MayorindA;}
- else{
- x = 57;
- }
- gotoxy(x,5);
- printf(" NACIMIENTO ");
- return;
- }
- void EditorAUTOR(NODOA **cabeza,NODOA **cola,NODOA **actual){
- unsigned short int Dia,Mes,year;
- Limpiar();
- gotoxy(15,2);
- Colores(WHITE,RED);
- printf("Presione (ENTER) si no desea editar nada\n (Espacio en las fechas)");
- gotoxy(25,4);
- Colores(WHITE,BLACK);
- printf("Nombre: ");
- gotoxy(70,3); Colores(LIGHTGRAY,BLACK);
- printf("Apellido: ");
- gotoxy(60,9); Colores(LIGHTGRAY,BLACK);
- printf("Fecha De nacimiento");
- // Primer nombre
- gotoxy(25,4);
- Colores(WHITE,BLACK);
- printf("Nombre: ");
- CapChar((*actual)->autor.nombres,1,'A',40,7,16);
- // Apellido
- gotoxy(70,3); Colores(WHITE,BLACK);
- printf("Apellido: ");
- CapChar((*actual)->autor.apellidos,1,'A',85,7,16);
- // Telefono
- gotoxy(60,9); Colores(WHITE,BLACK);
- printf("Fecha De nacimiento");
- Fechas(&Dia,&Mes,&year,60,10);
- (*actual)->autor.fechanacimiento.dd = Dia;
- (*actual)->autor.fechanacimiento.mm = Mes;
- (*actual)->autor.fechanacimiento.yyy = year;
- }
- int EliminarAutor(NODOA **cabeza,NODOA **cola,int Dato)
- {
- NODOA *actual = *cabeza,*anteriot,*siguiente;
- char *NomBuscar;
- NomBuscar = (char *)malloc(sizeof(char));
- int indice = 0;
- while(actual != NULL)
- {
- if(indice == Dato)
- {
- if( actual == *cabeza)
- {
- *cabeza = actual->sig;
- }
- else if( actual->sig == NULL)
- {
- anteriot = actual->ant;
- *cola = anteriot;
- anteriot->sig = NULL;
- }
- else
- {
- anteriot = actual->ant;
- actual->ant = NULL;
- siguiente = actual->sig;
- actual->sig = NULL;
- anteriot->sig = siguiente;
- siguiente->ant = anteriot;
- }
- free(actual);
- return 1;
- }
- actual = actual->sig;
- indice++;
- }
- return 0;
- }
- /// Libro
- /*
- Funcion: nodoLIBRO
- Argumento: NODOA **cab = "Cabeza que se asignara en la lista, NODOA **cola = "Cola que se modificarra en la lista", LIBRO libro,
- libro que se unira a la lista.
- Objetivo: "Enlazar nodos en la lista en el inicio"
- Retorno: "Nada"
- */
- void nodoLIBRO(NODOL **cab, NODOL **cola, LIBRO libro){
- NODOL *livre;
- //FILE *Libro;
- //Libro = fopen("C:\\Users\\r_rok\\Desktop\\Biblioteca\\Archivos.dat","ab");
- livre = (NODOL *) malloc(sizeof(NODOL));
- livre->libro = libro;
- livre->ant = NULL;
- livre->sig = *cab;
- if(*cab != NULL)
- (*cab)->ant = livre;
- *cab = livre;
- return;
- /*fwrite(livre,sizeof(LIBRO),sizeof(LIBRO),Libro);
- fclose(Libro);*/
- }
- /*
- Funcion: capLIBRO
- Argumento: NODOA *cab = "Cabeza que se asignara en la lista del autor para identificar el ID
- Objetivo: "obtenet datos para los libros"
- Retorno: "Un nuevo Libro"
- */
- LIBRO caplibro(NODOA *cab){
- LIBRO livre;
- char idAutor[LENIDAUTOR],resp = 'n';
- int Busqueda;
- Colores(WHITE,BLACK);
- gotoxy(45,4);
- printf("ISBN");
- CapChar(&livre.ISBN,1,'7',42,6,15);
- gotoxy(45,7);
- printf("Titulo");
- CapChar(&livre.titulo,1,'!',42,9,15);
- gotoxy(45,9);
- printf("ID del autor (si no tiene precione ENTER)");
- do{
- CapChar(idAutor,1,'5',42,11,16);
- Busqueda = BuscarAutor(cab,idAutor);
- if(idAutor[0] == '\r'){
- Busqueda = 2;
- }
- if(Busqueda == 1){
- gotoxy(45,3);
- Colores(WHITE,LIGHTGREEN);
- printf("ID asignado de forma correcta");
- strcpy(livre.idautor,idAutor);
- Sleep(1000); gotoxy(45,3); Colores(BLACK,BLACK);
- printf(" ");
- }
- else if(Busqueda == 0){
- gotoxy(45,3);Colores(WHITE,LIGHTGREEN);
- printf("ID no existe, %cdesea ingresar otro? Si o No",168);
- do{
- resp = toupper(getch());
- if(resp == 'N'){
- Busqueda = 2;
- }
- }while(resp != 'N' && resp != 'S');
- gotoxy(45,3);Colores(BLACK,BLACK);
- printf(" ");
- }
- }while(Busqueda == 0);
- Colores(WHITE,BLACK);
- gotoxy(45,11);
- printf("Editora");
- CapChar(&livre.editora,1,'!',42,13,15);
- gotoxy(45,13);
- printf("Fecha de publicacion");
- livre.fechaedicion.dd = 0;
- livre.fechaedicion.mm = 0;
- livre.fechaedicion.yyy = 0;
- Fechas(&livre.fechaedicion.dd,&livre.fechaedicion.mm,&livre.fechaedicion.yyy,30,13);
- return livre;
- }
- void ScrollingLIBRO(NODOL **cab, NODOL **cola, int *n, NODOA *cabA, NODOP *cabezaP)
- {
- NODOL *IND,*CabezaActual;
- NODOP *INDP;
- CabezaActual = *cab;
- int indy = 6,indice = 1,busqueda=0;
- char letra,teclaBorrar;
- Colores(BLACK,WHITE);
- indy = 6;
- int select = 0,Turno = 0,res;
- char tecla;
- _setcursortype(0);
- do{
- impLibro(indy,CabezaActual,cola,YELLOW,BLACK,&select,*n);
- tecla = getch();
- if ( tecla == ARRIBA)
- {
- if(CabezaActual != *cab){
- select--;
- Turno--;
- }
- }
- if ( tecla == ABAJO )
- {
- select++;
- Turno++;
- if(Turno >= 4){
- CabezaActual = CabezaActual->sig;
- select = 3;
- }
- if ( Turno == (*n) )
- { select = 0;
- CabezaActual = *cab;
- Turno = 0;
- }
- }
- if(tecla == BORRAR){
- for(IND = *cab;IND;IND = IND->sig){
- if(busqueda == Turno)
- { for(INDP=cabezaP;INDP;INDP = INDP->sig){
- res = Comparar(IND->libro.ISBN,INDP->prestamos.ISBN);
- if(res == 1){
- break;
- }
- }
- break;
- }
- busqueda++;
- }
- if(res != 1){
- SeguroBorrar(&teclaBorrar);
- if(teclaBorrar == 's'){
- EliminarAutor(cab,cola,Turno);
- (*n)--;
- tecla = ESP;
- }
- }
- else if(res == 1){
- gotoxy(40,15);
- Colores(WHITE,LIGHTRED);
- printf("Libro esta prestado...");
- Sleep(1500);
- gotoxy(40,15); Colores(BLACK,BLACK);
- printf(" ");
- }
- }
- if(tecla == ENTER)
- {
- for (IND = *cab; IND; IND = IND->sig)
- {
- if(busqueda == Turno)
- {
- EditorLIBRO(cab,cola,&IND,cabA);
- break;
- }
- busqueda++;
- }
- tecla = ESP;
- }
- }while ( tecla != ESP && tecla != ENTER );
- if ( tecla == ESP )
- select = -1;
- }
- void impLibro(int y,NODOL *cabactual, NODOL **cola, int CFS, int CTS, int *sel, int Num)
- {
- int indice = 0,info,mayor = 25,x,cont,MayorindN=6,MayorindA = 8,MayorindT = 8,posy,mayorNAT=10;
- NODOL *IND;
- // Evaluar impresion tabulada
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->libro.titulo);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- info = PalabraG(IND->libro.editora);
- if(info > mayor)
- {
- mayor = info;
- }
- if(info > mayorNAT)
- {
- mayorNAT = info;
- }
- }
- for (IND = cabactual; IND; IND = IND->sig){
- info = PalabraG(IND->libro.titulo);
- if(info > MayorindN)
- {
- MayorindN = info;
- }
- info = PalabraG(IND->libro.editora);
- if(info > MayorindA)
- {
- MayorindA = info;
- }
- }
- if( cabactual != *cola){
- for (IND = cabactual; IND; IND = IND->sig,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- printf("%s",IND->libro.editora);
- // evalua nombres denuevo para saber la posision del apellido
- x = 41 + MayorindN;
- gotoxy(x,y);
- printf(" %s",IND->libro.titulo);
- gotoxy(x+MayorindA+1,y);
- printf(" %02d/%02d/%d",IND->libro.fechaedicion.dd,IND->libro.fechaedicion.mm,IND->libro.fechaedicion.yyy);
- }
- y++;
- }
- }
- else{
- for (IND = cabactual; IND; IND = IND->ant,indice++){
- if(y <= 9){
- // imprimir tabla
- gotoxy(40,y);
- if(y == 6 || y == 8)
- Colores(BLUE,LIGHTCYAN);
- if(y == 7 || y == 9)
- Colores(LIGHTCYAN,BLUE);
- if ( indice == *sel )
- {Colores(CFS,CTS);}
- x = 40;
- for(cont=0; cont<mayor;cont++)
- {
- gotoxy(x,y);
- printf(" ");
- x++;
- }
- gotoxy(40,y);
- printf("%s",IND->libro.titulo);
- // evalua titulo denuevo para saber la posision del apellido
- x = 41 + MayorindN;
- gotoxy(x,y);
- printf(" %s",IND->libro.editora);
- gotoxy(x+MayorindA+1,y);
- printf("%02d/%02d/%d",IND->libro.fechaedicion.dd,IND->libro.fechaedicion.mm,IND->libro.fechaedicion.yyy);
- }
- y++;
- }
- }
- gotoxy(40,5);
- Colores(WHITE,BLACK);
- printf("EDITORA");
- cont = 6;
- if(MayorindN > 6)
- for(cont;cont<MayorindN;cont++){
- printf(" ");
- }
- printf("|");
- x = 41 + MayorindN;
- gotoxy(x,5);
- printf(" TITULO");
- cont = 8;
- for(cont;cont<MayorindA;cont++){
- printf(" ");
- }
- printf("|");
- if(MayorindN > 6 || MayorindA > 8){
- x = 42+mayorNAT+MayorindA;}
- else{
- x = 56;
- }
- /*for(posy=6;posy<Num+6;posy++){
- gotoxy(x,posy);
- printf("|");
- }*/
- if(MayorindA > 8 || MayorindN > 6){
- x = 56 + MayorindA;}
- else{
- x = 57;
- }
- gotoxy(x,5);
- printf(" FECHA ");
- return;
- }
- int EliminarLibro(NODOL **cabeza,NODOL **cola,int Dato)
- {
- NODOL *actual = *cabeza,*anteriot,*siguiente;
- char *NomBuscar;
- NomBuscar = (char *)malloc(sizeof(char));
- int indice = 0;
- while(actual != NULL)
- {
- if(indice == Dato)
- {
- if( actual == *cabeza)
- {
- *cabeza = actual->sig;
- }
- else if( actual->sig == NULL)
- {
- anteriot = actual->ant;
- *cola = anteriot;
- anteriot->sig = NULL;
- }
- else
- {
- anteriot = actual->ant;
- actual->ant = NULL;
- siguiente = actual->sig;
- actual->sig = NULL;
- anteriot->sig = siguiente;
- siguiente->ant = anteriot;
- }
- free(actual);
- return 1;
- }
- actual = actual->sig;
- indice++;
- }
- return 0;
- }
- void EditorLIBRO(NODOL **cabeza,NODOL **cola,NODOL **actual, NODOA *cabA){
- char idAutor[LENIDAUTOR],resp;
- int Busqueda;
- Limpiar();
- gotoxy(15,2);
- Colores(WHITE,RED);
- printf("Presione (ENTER) si no desea editar nada\n (Espacio en las fechas)");
- gotoxy(25,4);
- Colores(WHITE,BLACK);
- printf("Titulo: ");
- gotoxy(70,3);
- printf("Editorial: ");
- gotoxy(60,9);
- printf("ISBM");
- gotoxy(25,4);
- printf("Titulo: ");
- CapChar((*actual)->libro.titulo,1,'A',40,7,16);
- gotoxy(70,3);
- printf("Editorial: ");
- CapChar((*actual)->libro.editora,1,'A',85,7,16);
- gotoxy(60,9);
- printf("ISBM");
- CapChar((*actual)->libro.ISBN,1,'3',70,12,16);
- gotoxy(45,9);
- printf("ID del autor (si no tiene precione ENTER)");
- do{
- CapChar(idAutor,1,'5',42,11,16);
- Busqueda = BuscarAutor(cabA,idAutor);
- if(idAutor[0] == '\r'){
- Busqueda = 2;
- }
- if(Busqueda == 1){
- gotoxy(45,3);
- Colores(WHITE,LIGHTGREEN);
- printf("ID asignado de forma correcta");
- strcpy((*actual)->libro.idautor,idAutor);
- Sleep(1000); gotoxy(45,3); Colores(BLACK,BLACK);
- printf(" ");
- }
- else if(Busqueda == 0){
- gotoxy(45,3);Colores(WHITE,LIGHTGREEN);
- printf("ID no existe, %cdesea ingresar otro? Si o No",168);
- do{
- resp = toupper(getch());
- if(resp == 'N'){
- Busqueda = 2;
- }
- }while(resp != 'N' && resp != 'S');
- gotoxy(45,3);Colores(BLACK,BLACK);
- printf(" ");
- }
- }while(Busqueda == 0);
- }
- LIBRO existeLIBRO(NODOL *cab, char *Busq){
- NODOL *IND;
- int retorno;
- LIBRO Encontrado,Ninguno = {ENTER,ENTER,ENTER,ENTER,ENTER,ENTER};
- for(IND=cab;IND;IND=IND->sig){
- retorno = Comparar(IND->libro.editora,Busq);
- if(retorno == 1){
- Encontrado = IND->libro;
- return Encontrado;
- }
- retorno = Comparar(IND->libro.idautor,Busq);
- if(retorno == 1){
- Encontrado = IND->libro;
- return Encontrado;
- }
- retorno = Comparar(IND->libro.ISBN,Busq);
- if(retorno == 1){
- Encontrado = IND->libro;
- return Encontrado;
- }
- retorno = Comparar(IND->libro.titulo,Busq);
- if(retorno == 1){
- Encontrado = IND->libro;
- return Encontrado;
- }
- }
- return Ninguno;
- }
- /// Utiles
- void Limpiar()
- {
- Colores(BLACK,BLACK);
- system("CLS");
- }
- int PalabraG(char *aux){
- int ind = 0,PMayor = 0;
- while(aux[ind] != ENTER){
- PMayor++;
- ind++;
- }
- return PMayor;
- }
- void SeguroBorrar(char *tecla){
- char resp;
- gotoxy(40,15);
- printf("%cSegur%c que desea eliminar?",168,64);
- *tecla = 'n';
- _setcursortype(1);
- gotoxy(50,16);
- printf("Si");
- gotoxy(55,16);
- printf("No");
- do{
- resp = getch();
- if(resp == DERECHA){
- gotoxy(55,16);
- *tecla = 'n';
- }
- if(resp == IZQUIERDA){
- gotoxy(50,16);
- *tecla = 's';
- }
- }while(resp != ENTER);
- }
- int BuscarAutor(NODOA *cab, char *busq){
- NODOA *IND;
- int res;
- for(IND=cab;IND;IND = IND->sig){
- res = Comparar(IND->autor.idautor,busq);
- if(res == 1){
- return 1;
- }
- }
- return 0;
- }
- PRESTAMOS SolicitarPrestamo(USUARIO *Infouser, LIBRO InfoLibro ){
- time_t t;
- struct tm *tm;
- t = time(NULL);
- tm = localtime(&t);
- PRESTAMOS NPrestamo;
- Limpiar();
- int NDias,ind;
- Colores(WHITE,BLACK);
- strcpy(NPrestamo.iddocumento,Infouser->nombres);
- strcpy(NPrestamo.ISBN,InfoLibro.ISBN);
- gotoxy(40,2);
- printf("Libro: %s",InfoLibro.titulo);
- gotoxy(40,5);
- printf("Fecha Del Prestamo: ");
- NPrestamo.fecprestamo.dd = tm->tm_mday;
- NPrestamo.fecprestamo.mm = tm->tm_mon+1;
- NPrestamo.fecprestamo.yyy = 1900+tm->tm_year;
- //Fechas(&NPrestamo.fecprestamo.dd,&NPrestamo.fecprestamo.mm,&NPrestamo.fecprestamo.yyy,62,5);
- gotoxy(62,5); Colores(LIGHTRED,WHITE);
- printf("%02d/%02d/%d",NPrestamo.fecprestamo.dd,NPrestamo.fecprestamo.mm,NPrestamo.fecprestamo.yyy);
- gotoxy(40,7); Colores(YELLOW,LIGHTRED);
- printf("Ingrese la cantidad de dias del prestamo\nRecargo diario: 100RD$");
- gotoxy(40,8);
- printf("(Mayor que 4 d%cas, Menor que 1 mes)",161);
- NDias = NumerosC(2,0,45,9);
- NPrestamo.diasprestamo = NDias;
- gotoxy(40,10);
- printf("Mantenga pendiente la fecha de devoluci%cn: ",162);
- NPrestamo.fecdevolucion.dd = NPrestamo.fecprestamo.dd;
- NPrestamo.fecdevolucion.mm = NPrestamo.fecprestamo.mm;
- NPrestamo.fecdevolucion.yyy = NPrestamo.fecprestamo.yyy;
- for(ind=0;ind<NDias;ind++){
- NPrestamo.fecdevolucion.dd++;
- if(NPrestamo.fecdevolucion.dd >= 31){
- NPrestamo.fecdevolucion.dd = 1;
- NPrestamo.fecdevolucion.mm++;
- if(NPrestamo.fecdevolucion.mm > 12 ){
- NPrestamo.fecdevolucion.mm = 1;
- NPrestamo.fecdevolucion.yyy++;
- }
- }
- else if(NPrestamo.fecdevolucion.dd > 29 && NPrestamo.fecdevolucion.mm == 2){
- NPrestamo.fecdevolucion.dd = 28;
- }
- }
- Colores(YELLOW,LIGHTRED);
- gotoxy(85,10);
- printf("%d/%d/%d",NPrestamo.fecdevolucion.dd,NPrestamo.fecdevolucion.mm,NPrestamo.fecdevolucion.yyy);
- NPrestamo.recargodiario = 100;
- printf("\nPrecio total: [%d]",NDias*100);
- _setcursortype(0);
- char l = getch();
- return NPrestamo;
- }
- int Comparar(char *str1, char *str2){
- int ind=0,TamL1=0,TamL2=0,cmp=0;
- while(str1[ind] != '\r'){
- TamL1++;ind++;
- if(str1[ind] == '\0'){
- break;
- }
- }
- ind = 0;
- while(str2[ind] != '\r'){
- TamL2++;ind++;
- if(str2[ind] == '\0'){
- break;
- }
- }
- if(TamL1 == TamL2){
- for(ind=0;ind<TamL1;ind++){
- if(toupper(str1[ind]) == toupper(str2[ind])){
- cmp++;
- }
- }
- if(cmp == TamL1){
- return 1;
- }
- }
- return 0;
- }
- int ValidaFechas(int D1, int M1, int Y1, int D2, int M2, int Y2){
- if(Y2 > Y1){
- return 2;
- }
- else if( Y1 > Y2){
- return 1;
- }
- else{
- if( M1 > M2 ){
- return 1;
- }
- if(M2 > M1){
- return 2;
- }
- if(D1 > D2){
- return 1;
- }
- if(D2 > D1){
- return 2;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement