Advertisement
ronal2s

Tarea5

Jun 20th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 47.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <time.h>
  5. #include "conio.c"
  6. #include <math.h>
  7.  
  8. #define CANTOPC   5
  9. #define CANTOPC2  9
  10. #define CANTOPC3  11
  11. #define CANTOPC4  5
  12. #define CANTOPC5  7
  13. #define LENOPC   45
  14.  
  15. #define ENTER   13
  16. #define ESC     27
  17.  
  18. #define ARRIBA    72
  19. #define ABAJO     80
  20. #define DERECHA   77
  21. #define IZQUIERDA 75
  22.  
  23. #define CTOPCMEN  WHITE
  24. #define CFOPCMEN  BLUE
  25. #define CTSOPCMEN BLUE
  26. #define CFSOPCMEN WHITE
  27. #define MAXID 4
  28. #define LENNOM 41
  29. #define LENAPE 31
  30.  
  31. void mostraropcxy(char [][LENOPC],int,int,int,int);
  32. int menuxy(char [][LENOPC],int,int,int,int);
  33. void colordefault();
  34. void setcolor(int,int);
  35. float comprobarSalario(float salario);
  36. char getEmpleados(int indice);
  37. int cantidadDigitosNumero(float numero);
  38. void menuListar(int opcionSeleccionada, int posicionY, int cantidadDeOpciones);
  39.  
  40. typedef struct{
  41.  int dia,mes,agno;
  42. }FECHA;
  43. typedef struct{
  44.  char idemp[MAXID], nombre1[LENNOM], nombre2[LENNOM], apellido1[LENAPE], apellido2[LENAPE];
  45.  FECHA fnacim, fentrada;
  46.  float salario;
  47. }EMP;
  48.  
  49. int empleadoActual = 0, validarCampos, tamanoPuntero = 10, primerInicio=0, idBuscar = -1;
  50.  
  51. EMP *empleados; //= (EMP*) calloc(10, sizeof(EMP));
  52. int main(int opc)
  53. {
  54.    system("mode 120,30");
  55.    if(primerInicio==0)
  56.    {
  57.        empleados = (EMP*) calloc(tamanoPuntero, sizeof(EMP));
  58.        primerInicio=1; opc = 0;
  59.    }
  60.    clrscr();
  61.    /**Validar campos será 1 porque la fecha de entrada siempre estará validada**/
  62.    validarCampos = 0;
  63.    char opciones[CANTOPC][LENOPC] =
  64.         {
  65.         "Ingresar empleados ",
  66.         "Modificar empleados",
  67.         "Borrar empleados   ",
  68.         "Lista de empleados ",
  69.         "SALIR              "
  70.          };
  71.    char opciones2[CANTOPC2][LENOPC] =
  72.     {
  73.         "Primer nombre           *:",
  74.         "Segundo nombre           :",
  75.         "Primer apellido         *:",
  76.         "Segundo apellido         :",
  77.         "Salario                 *:",
  78.         "F. Entrada[DD/MM/AA]     :",
  79.         "F. Nacimiento[DD/MM/AA] *:",
  80.         "GUARDAR                   ",
  81.         "SALIR                     "
  82.     };
  83.  
  84.     char opciones5[CANTOPC5][LENOPC] =
  85.     {
  86.         "Listar Empleados Normal               ",
  87.         "Buscar Empleado by ID                :",
  88.         "Buscar Empleado by Nombre            :",
  89.         "Buscar Empleado by Apellido          :",
  90.         "Buscar Empleado by RangoEdad [18-25] :",
  91.         "Buscar Empleado RangoSalario [10-50] :",
  92.         "Salir                                 "
  93.     };
  94.     char opciones3[CANTOPC3][LENOPC] =
  95.     {
  96.         "Listar Empleados                        ",
  97.         "Verificar ID Empleado Ingresando Nombre:",
  98.         "Ingresar ID Verificado del Empleado    :",
  99.         "Modificar Primer Nombre                :",
  100.         "Modificar Segundo Nombre               :",
  101.         "Modificar Primer Apellido              :",
  102.         "Modificar Segundo Apellido             :",
  103.         "Modificar Fecha de Entrada             :",
  104.         "Modificar Fecha de Nacimiento          :",
  105.         "Modificar Salario                      :",
  106.         "Sair                                   "
  107.     };
  108.     char opciones4[CANTOPC4][LENOPC] =
  109.     {
  110.         "Listar Empleados                        ",
  111.         "Verificar ID Empleado Ingresando Nombre:",
  112.         "Ingresar ID Verificado del Empleado    :",
  113.         "BORRAR                                  ",
  114.         "Salir"
  115.     };
  116.    int opc1 = 0, opc5 = 0, opc2=0, opc4=0;
  117.  
  118.    srand(time(NULL));
  119.     do{
  120.     opc = menuxy(opciones,CANTOPC,opc,1,1);
  121.     while(opc == 0)
  122.       {
  123.          opc1 = menuxy(opciones2,CANTOPC2,opc1,17,opc+1);
  124.          agregarDatos(opc1, opc+1+opc1, CANTOPC2);
  125.       }
  126.     while(opc == 1)
  127.     {
  128.         opc2 = menuxy(opciones3, CANTOPC3, opc2, 17, opc+1);
  129.         menuModificar(opc2, opc+1+opc2, CANTOPC3);
  130.     }
  131.     while(opc == 3)
  132.     {
  133.         opc5 = menuxy(opciones5, CANTOPC5, opc5, 17, opc+1);
  134.         menuListar(opc5, opc+1+opc5, CANTOPC5);
  135.     }
  136.     while(opc == 2)
  137.     {
  138.         opc4 = menuxy(opciones4, CANTOPC4, opc4, 17, opc+1);
  139.         menuBorrar(opc4, opc+1+opc4, CANTOPC4);
  140.     }
  141.    }while(opc != CANTOPC - 1);
  142.    free(empleados);
  143.    exit(0);
  144.    return 0;
  145. }
  146.  
  147. void mostraropcxy(char opc[][LENOPC],int n,int sel,int px, int py)
  148. {
  149.    int ind;
  150.  
  151.    for (ind = 0; ind < n; ind ++ )
  152.    {
  153.       textcolor(LIGHTGRAY);
  154.       if ( ind == sel)
  155.          textcolor(LIGHTRED);
  156.  
  157.       gotoxy(px,py+ind);
  158.       printf(" %s \n",opc[ind]);
  159.    }
  160.  
  161.    colordefault();
  162.  
  163.    return;
  164. }
  165.  
  166.  
  167. int menuxy(char opc[][LENOPC],int n,int sel,int px, int py)
  168. {
  169.    char tecla;
  170.  
  171.    _setcursortype(0);
  172.    do
  173.    {
  174.       mostraropcxy(opc,n,sel,px,py);
  175.       tecla = getch();
  176.  
  177.       if ( tecla == ARRIBA )
  178.       {
  179.          sel --;
  180.          if ( sel < 0 )
  181.             sel = n - 1;
  182.       }
  183.  
  184.       if ( tecla == ABAJO )
  185.       {
  186.          sel ++;
  187.          if ( sel == n )
  188.             sel = 0;
  189.       }
  190.    }while ( tecla != ENTER && tecla != ESC );
  191.  
  192.    if ( tecla == ESC )
  193.       main(0);
  194.    return sel;
  195. }
  196.  
  197.  
  198. void colordefault()
  199. {
  200.    textcolor(LIGHTGRAY);
  201.    textbackground(BLACK);
  202. }
  203. /**
  204.     Función: AgregarDatos
  205.     Parámetros: opciónSeleccionada, posicionY y cantidadDeOpciones
  206.     Objetivo: Agregar los datos de los empleados de forma organizada conservando buen diseño
  207. **/
  208. void agregarDatos(int opcionSeleccionada, int posicionY, int cantidadDeOpciones)
  209. {
  210.     textcolor(GREEN);
  211.     int posicionX = 5+19+21, indice=0, posicionYdeError = cantidadDeOpciones+1;
  212.     char oracion[LENNOM], letra;
  213.     switch(opcionSeleccionada)
  214.     {
  215.     case 0:/**PRIMER NOMBRE**/
  216.         obtenerCaracteres(posicionX, posicionY, 10,empleados[empleadoActual].nombre1,0);
  217.         validarCampos++;
  218.         break;
  219.     case 1:/**SEGUNDO NOMBRE**/
  220.         obtenerCaracteres(posicionX, posicionY, 10,empleados[empleadoActual].nombre2,0);
  221.         //validarCampos++;
  222.         break;
  223.     case 2:/**PRIMER APELLIDO**/
  224.         obtenerCaracteres(posicionX, posicionY,10, empleados[empleadoActual].apellido1,1);
  225.         validarCampos++;
  226.         break;
  227.     case 3:/**SEGUNDO APELLIDO**/
  228.         obtenerCaracteres(posicionX, posicionY, 10,empleados[empleadoActual].apellido2,1);
  229.         //validarCampos++;
  230.         break;
  231.     case 4:/**SALARIO**/
  232.         obtenerSalario(posicionX, posicionY, posicionYdeError, empleadoActual);
  233.         validarCampos++;
  234.         break;
  235.     case 5:/**FECHA ENTRADA**/
  236.         obtenerFechaEntrada(posicionX, posicionY,10, empleadoActual);
  237.         //validarCampos++;
  238.         break;
  239.     case 6:/**FECHA NACIMIENTO**/
  240.         obtenerFechaNacimiento(posicionX, posicionY,10,empleadoActual);
  241.         validarCampos++;
  242.         break;
  243.     case 7:/**GUARDAR**/
  244.         guardar();
  245.         int c = comprobarSalida();
  246.         /**Si decide guardar y no es mayor de edad...**/
  247.         if(c>0)
  248.         {
  249.             if(comprobarMayorDeEdad() == 0)
  250.             {
  251.                 gotoxy(1,10);
  252.                 printf("Debe tener al menos 18 anios para entrar a la empresa");
  253.                 fflush(stdin); getch();
  254.                 gotoxy(1,10);
  255.                 printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\t");
  256.             }
  257.         }
  258.         /**Si decide guardar y es mayor de edad...**/
  259.        if(c>0)
  260.         {
  261.             if(comprobarMayorDeEdad() == 1)
  262.             {
  263.                 main(0);
  264.             }
  265.         }
  266.         /**Si decide guardar sin haber completado todo...**/
  267.         if(c>0 && validarCampos < 4)
  268.         {
  269.             /**Pues equivale a salir sin guardar en tal caso**/
  270.             salirSinGuardar();
  271.         }
  272.         /**Si no decide salir...**/
  273.         if(c==0)
  274.         {
  275.             gotoxy(1,10);
  276.             printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\t");
  277.         }
  278.         break;
  279.     case 8:
  280.         salirSinGuardar();
  281.         break;
  282.     }
  283.     colordefault();
  284.     fflush(stdin);
  285. }
  286. /**
  287.     Función: ObtenerCaracteres
  288.     Parámetros: PosicionX, PosicionY, PosicionYdeError, texto y apellidos
  289.     Objetivo: Evaluar si existe algún carácter no permitido por ejemplo números y espacios, a excepción de los apellidos que
  290.     pueden recibir espacios
  291. **/
  292. void obtenerCaracteres(int posicionX, int posicionY, int posicionYdeError, char texto[], int apellidos)
  293. {
  294.     gotoxy(posicionX, posicionY);
  295.     printf("\t\t\t\t\t\t");
  296.     gotoxy(posicionX, posicionY);
  297.     fflush(stdin);
  298.     textcolor(GREEN);
  299.     gets(texto);
  300.     int c = comprobarTexto(texto, apellidos);
  301.     if(c == 0)
  302.         {
  303.             textcolor(RED);
  304.             gotoxy(1,posicionYdeError);
  305.             printf("Solo se admite letras y guion en este campo, presione cualquier tecla para regresar nuevamente.");
  306.             fflush(stdin); getch();
  307.             limpiarArregloChar(texto);
  308.             obtenerCaracteres(posicionX, posicionY, posicionYdeError,texto,apellidos);
  309.         }
  310.     else
  311.     {
  312.         gotoxy(1,posicionYdeError);
  313.         printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
  314.     }
  315.     colordefault();
  316. }
  317. /**
  318.     Función: ObtenerSalario
  319.     Parámetros: PosicionX, PosicionY, PosicionYdeError, EmpleadoActual2
  320.     Objetivo: Evaluar si el salario es válido
  321. **/
  322. void obtenerSalario(int posicionX, int posicionY, int posicionYdeError, int empleadoActual2)
  323. {
  324.     textcolor(GREEN);
  325.     gotoxy(posicionX, posicionY);
  326.     printf("\t\t\t\t\t\t\t\t\t\t");
  327.     gotoxy(posicionX, posicionY);
  328.     scanf("%f", &empleados[empleadoActual2].salario);
  329.     if(comprobarSalario(empleados[empleadoActual2].salario) <= 0)
  330.     {
  331.         textcolor(RED);
  332.         gotoxy(1, posicionYdeError);
  333.         printf("El salario debe ser numerico y mayor a cero, presiona cualquier tecla para continuar...");
  334.         fflush(stdin);
  335.         getch();
  336.         gotoxy(1,10);
  337.         printf("\t\t\t\t\t\t\t\t\t\t\t\t");
  338.         obtenerSalario(posicionX, posicionY, posicionYdeError, empleadoActual2);
  339.     }
  340.     colordefault();
  341. }
  342. /**
  343.     Función: ObtenerFechaEntrada
  344.     Parámetros: PosicionX, PosicionY, PosicionYdeError y EmpleadoActual2
  345.     Objetivo: Obtener y evaluar la fecha de entrada, en caso de no ingresarse será el día de hoy
  346. **/
  347. void obtenerFechaEntrada(int posicionX, int posicionY, int posicionYdeError, int empleadoActual2)
  348. {
  349.     textcolor(GREEN);
  350.     gotoxy(posicionX, posicionY); printf("\t\t\t\t\t\t"); gotoxy(posicionX, posicionY);
  351.     scanf("%d/%d/%d", &empleados[empleadoActual2].fentrada.dia,&empleados[empleadoActual2].fentrada.mes, &empleados[empleadoActual2].fentrada.agno);
  352.     if(comprobarFecha(empleados[empleadoActual2].fentrada.dia, empleados[empleadoActual2].fentrada.mes, empleados[empleadoActual2].fentrada.agno) == 0)
  353.         {
  354.             textcolor(RED);
  355.             gotoxy(1,posicionYdeError); printf("Debes digitar la fecha como la entrada indica, presiona cualquier tecla para continuar...");
  356.             fflush(stdin);
  357.             getch();
  358.             gotoxy(1,posicionYdeError); printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
  359.             //gotoxy(posicionX, posicionY); printf("\t\t\t\t"); gotoxy(posicionX, posicionY);
  360.             obtenerFechaEntrada(posicionX, posicionY, posicionYdeError, empleadoActual2);
  361.         }
  362.         colordefault();
  363. }
  364. /**
  365.     Función: ObtenerFechaNacimiento
  366.     Parámetros: posicionX, posicionY, posicionYdeError, empleadoActual2
  367.     Objetivo: Validar que la fecha de nacimiento sea real
  368. **/
  369. void obtenerFechaNacimiento(int posicionX, int posicionY, int posicionYdeError, int empleadoActual2)
  370. {
  371.     textcolor(GREEN);
  372.     gotoxy(posicionX, posicionY); printf("\t\t\t\t\t\t"); gotoxy(posicionX, posicionY);
  373.     scanf("%d/%d/%d", &empleados[empleadoActual2].fnacim.dia,&empleados[empleadoActual2].fnacim.mes, &empleados[empleadoActual2].fnacim.agno);
  374.     if(comprobarFecha(empleados[empleadoActual2].fnacim.dia, empleados[empleadoActual2].fnacim.mes, empleados[empleadoActual2].fnacim.agno) == 0)
  375.         {
  376.             textcolor(RED);
  377.             gotoxy(1,posicionYdeError); printf("Fecha erronea, presiona cualquier tecla para reintentar...");
  378.             fflush(stdin);
  379.             getch();
  380.             gotoxy(1,posicionYdeError); printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
  381.             obtenerFechaNacimiento(posicionX, posicionY, posicionYdeError, empleadoActual2);
  382.         }
  383.         colordefault();
  384. }
  385. /**
  386.     Función     : comprobarFecha
  387.     Parámetros  : Dia, mes y Año
  388.     Objetivo    : Comprobar que el día/mes/año no sea menor que 0 y también comprueba si el año es bisiesto en otra función
  389. **/
  390. int comprobarFecha(int dia, int mes, int anio)
  391. {
  392.     int diasMeses[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  393.     int comprobarAnio = comprobarAnioBisiesto(anio);
  394.     if(dia <=0 || mes <=0 || anio <=0)
  395.         return 0;
  396.  
  397.  
  398.     if(comprobarAnio == 0)
  399.     {
  400.         if(mes == 1 || mes == 3 ||mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12)
  401.         {
  402.             if(dia > 31)
  403.             {
  404.                 return 0;
  405.             }
  406.             else
  407.             {
  408.                 return 1;
  409.             }
  410.         }
  411.         if(mes == 2 ||mes == 4 ||mes == 6 ||mes == 9 ||mes == 11)
  412.         {
  413.             if(mes == 2 && dia > 28)
  414.             {
  415.                 return 0;
  416.             }
  417.             if(mes != 2 && dia > 30)
  418.             {
  419.                 return 0;
  420.             }
  421.             else
  422.             {
  423.                 return 1;
  424.             }
  425.         }
  426.     }
  427.  
  428.     if(comprobarAnio == 1)
  429.     {
  430.         if(mes == 1 || mes == 3 ||mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12)
  431.         {
  432.             if(dia > 31)
  433.             {
  434.                 return 0;
  435.             }
  436.             else
  437.             {
  438.                 return 1;
  439.             }
  440.         }
  441.         if(mes == 2 ||mes == 4 ||mes == 6 ||mes == 9 ||mes == 11)
  442.         {
  443.             if(mes == 2 && dia > 29)
  444.             {
  445.                 return 0;
  446.             }
  447.             if(mes != 2 && dia > 30)
  448.             {
  449.                 return 0;
  450.             }
  451.             else
  452.             {
  453.                 return 1;
  454.             }
  455.         }
  456.     }
  457. }
  458. /**
  459.     Función     : ComprobarAnioBisiesto
  460.     Parámetros  : Año
  461.     Objetivo    : Comprobar si el año es bisiesto
  462. **/
  463. int comprobarAnioBisiesto(int anio)
  464. {
  465.      if ( anio % 4 == 0 && anio % 100 != 0 || anio % 400 == 0 )
  466.         return 1;
  467.     else
  468.         return 0;
  469. }
  470. /**
  471.     Función     : ComprobarSalario
  472.     Parámetro   : salario
  473.     Objetivo    : Comprobar si el salario es menor o igual a cero no es aceptable
  474. **/
  475. float comprobarSalario(float salario)
  476. {
  477.     if(salario <=0)
  478.         return 0;
  479.     else return 1;
  480. }
  481. /**
  482.     Función     : comprobarTexto
  483.     Parámetros  : texto y apellidos
  484.     Objetivo:     Comprobar que el texto sea letras y guión si se trata del nombre
  485.                   Y que acepte espacios si se trata del apellido
  486. **/
  487. int comprobarTexto(char texto[], int apellidos)
  488. {
  489.     int i=0, validar = 1;
  490.     gotoxy(1,8); //printf("entrp");
  491.     while(texto[i] != '\0')
  492.     {
  493.         texto[i] = toupper(texto[i]);
  494.         if(apellidos == 1)/**SI SE ESTÁ VALIDANDO APELLIDOS SI SE PERMITE ESPACIOS**/
  495.         {
  496.             if((texto[i] < 'A' || texto[i] > 'Z')&& texto[i] != '-' && texto[i] != ' ')
  497.             {
  498.                 //Hay numeros,espacios o caracteres extraños
  499.                 validar = 0;
  500.             }
  501.         }
  502.         if(apellidos == 0)/**SI SE VALIDAN NOMBRES SOLO SE PERMITE GUION Y LETRAS**/
  503.         {
  504.             if((texto[i] < 'A' || texto[i] > 'Z')&& texto[i] != '-')// && texto[i] != '-' && texto[i] != 32)
  505.             {
  506.                 //Hay numeros,espacios o caracteres extraños
  507.                 validar = 0;
  508.             }
  509.         }
  510.         i++;
  511.     }
  512.     return validar;
  513. }
  514. /**
  515.     Función     : comprobarMayorDeEdad
  516.     Parámetros  : ninguno
  517.     Objetivo    : Comprobar si el empleado es mayor de 18 años
  518. **/
  519. int comprobarMayorDeEdad()
  520. {
  521.     if(((empleados[empleadoActual].fentrada.agno-18) < empleados[empleadoActual].fnacim.agno))
  522.         return 0;
  523.     else return 1;
  524. }
  525. /**
  526.     Función     : LimpiarArregloChar
  527.     Parámetros  : arreglo
  528.     Objetivo    : Limpiar el texto que se mande
  529. **/
  530. void limpiarArregloChar(char arreglo[])
  531. {
  532.     int i=0;
  533.     while(arreglo[i] != '\0')
  534.     {
  535.         arreglo[i] = ' ';
  536.         i++;
  537.     }
  538. }
  539. /**
  540.     Función     : SalirSinGuardar
  541.     Parámetros  : Ninguno
  542.     Objetivo    : En caso de que el usuario salga sin guardar se limpian los arreglos con la función memset
  543. **/
  544. void salirSinGuardar()
  545. {
  546.     memset(empleados[empleadoActual].nombre1,0, sizeof(empleados[empleadoActual].nombre1));
  547.     memset(empleados[empleadoActual].nombre2,0, sizeof(empleados[empleadoActual].nombre2));
  548.     memset(empleados[empleadoActual].apellido1,0, sizeof(empleados[empleadoActual].apellido1));
  549.     memset(empleados[empleadoActual].apellido2,0, sizeof(empleados[empleadoActual].apellido2));
  550.     memset(empleados[empleadoActual].idemp,0, sizeof(empleados[empleadoActual].idemp));
  551.     empleados[empleadoActual].fentrada.dia =0;
  552.     empleados[empleadoActual].fentrada.mes=0;
  553.     empleados[empleadoActual].fentrada.agno=0;
  554.     empleados[empleadoActual].fnacim.dia =0;
  555.     empleados[empleadoActual].fnacim.mes=0;
  556.     empleados[empleadoActual].fnacim.agno=0;
  557.     empleados[empleadoActual].salario = 0;
  558.     main(0);
  559. }
  560. /**
  561.     Función     : Guardar
  562.     Parámetros  : ninguno
  563.     Objetivo    : Validar que se hayan escrito en los campos obligatorios y en caso de que la fecha de entrada no se haya digitado
  564.                     (ya que no es obligatorio) pues se pone la fecha actual
  565. **/
  566. void guardar()
  567. {
  568.     //Obteniendo fecha actual:
  569.     time_t t = time(NULL);
  570.     struct tm tm = *localtime(&t);
  571.     gotoxy(45,6);
  572.     char respuesta;
  573.     if(empleados[empleadoActual].fentrada.dia <= 0)
  574.     {
  575.         /**Si el usuario no quiso indicar la fecha de entrada, será por defecto**/
  576.         printf("%d/%d/%d", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
  577.         empleados[empleadoActual].fentrada.dia = tm.tm_mday;
  578.         empleados[empleadoActual].fentrada.mes = tm.tm_mon+1;
  579.         empleados[empleadoActual].fentrada.agno     = tm.tm_year + 1900;
  580.     }
  581.  
  582.     if(validarCampos >= 4 && comprobarMayorDeEdad() == 1)
  583.     {
  584.         if(empleadoActual == tamanoPuntero-1)
  585.         {
  586.             tamanoPuntero = tamanoPuntero + 10;
  587.             empleados = (EMP*) realloc(empleados, tamanoPuntero);
  588.             /**Se aumenta el tamaño al puntero**/
  589.         }
  590.         empleadoActual++;/**Se aumenta la cantidad de empleado**/
  591.         main(0);
  592.     }
  593.     gotoxy(1,10);
  594.     if(validarCampos < 4)
  595.     {
  596.         printf("Faltan campos por completar, en caso de salir se borrara todo...");
  597.     }
  598.     printf("\nEsta seguro que desea salir?\nSi [S]\nNo [N]\nRespuesta: ");
  599.  
  600. }
  601. /**
  602.     Función     : ComprobarSalida
  603.     Parámetros  : ninguno
  604.     Objetivo    : Comprobar si el usuario quiere salir o no, solo será usada en algunas circuntancias
  605. **/
  606. int comprobarSalida()
  607. {
  608.     char respuesta;
  609.     do
  610.     {
  611.         fflush(stdin);
  612.         respuesta = getch();
  613.         respuesta = toupper(respuesta);
  614.     }while(respuesta != 'S' && respuesta != 'N');
  615.         if(respuesta == 'S')
  616.                 return 1;
  617.  
  618.         if(respuesta == 'N')
  619.                 return 0;
  620. }
  621.  
  622. /**FUNCIONES DE LA SEGUNDA OPCIÓN DEL MENÚ**/
  623. /**
  624.     Función     : ListaEmpleados
  625.     Parámetros  : PosicionYLista, tipoDeBusqueda, IDBuscar, NombreBuscar, ApellidoBuscar, edadMinima,
  626.                     edadMaxima, salarioMinimo, salarioMaximo
  627.     Objetivo    : Listar los empleados dependiendo de qué forma se busquen, por ejemplo, 0 es listar todo sin importar nada
  628. **/
  629. void listaEmpleados(int posicionYLista,int tipoDeBusqueda, int IDBuscar, char nombreBuscar[LENNOM], char apellidoBuscar[LENAPE], int edadMinima, int edadMaxima, int salarioMinimo, int salarioMaximo)
  630. {
  631.     //int posicionY = 11;
  632.     int posicionY = posicionYLista;
  633.     int posicionX = 1;
  634.     int edadIndice;
  635.     /**Las variables aquí abajo representan la cantidad de carácteres que tiene la palabra**/
  636.     int nombres = 7, apellidos = 9, salario = 7, fechaEntrada = 13;
  637.     /****/
  638.     int xApellidos = obtenerPrimerNombreLargo() + obtenerSegundoNombreLargo() + 1;
  639.     int xSalario = obtenerPrimerApellidoLargo() + obtenerSegundoApellidoLargo() + 1; //obtenerSalarioMayor();
  640.     int xFechaEntrada = obtenerSalarioMayor();
  641.     int xEdad = xApellidos + xSalario + xFechaEntrada;
  642.     int indice=0;
  643.     gotoxy(posicionX, posicionY);
  644.     printf("ID");
  645.     posicionX = posicionX + 5;
  646.     gotoxy(posicionX, posicionY);
  647.     printf("NOMBRES");
  648.  
  649.     if(xApellidos < nombres)
  650.         xApellidos = xApellidos + nombres + 4;
  651.     else xApellidos = xApellidos + nombres;
  652.  
  653.     gotoxy(xApellidos, posicionY);
  654.     printf("APELLIDOS");
  655.  
  656.     if(xSalario < apellidos)
  657.         xSalario = xSalario + xApellidos + nombres;
  658.     else xSalario = xSalario + xApellidos + 1;
  659.  
  660.     gotoxy(xSalario, posicionY);
  661.     printf("SALARIO");
  662.  
  663.     if(xFechaEntrada < salario)
  664.         xFechaEntrada = xFechaEntrada + xSalario + 7;//+salario;
  665.     else xFechaEntrada = xFechaEntrada + xSalario + 2;/**4 espacios porque hay un .00 del salario**/
  666.  
  667.     gotoxy(xFechaEntrada, posicionY);
  668.     printf("FECHA ENTRADA");
  669.  
  670.     if(xEdad < fechaEntrada)
  671.         xEdad = xEdad + salario + nombres + apellidos + fechaEntrada + 3;
  672.     else xEdad = xEdad + fechaEntrada + salario + nombres +8;//+ apellidos;
  673.         gotoxy(xEdad, posicionY);
  674.     printf("EDAD");
  675.  
  676.     if(tipoDeBusqueda == 0)
  677.     {
  678.         while(indice < empleadoActual)
  679.         {
  680.             posicionY++;
  681.             gotoxy(1, posicionY);
  682.             imprimirID(indice);
  683.             gotoxy(posicionX, posicionY);
  684.             printf("%s %s", empleados[indice].nombre1, empleados[indice].nombre2);
  685.             gotoxy(xApellidos, posicionY);
  686.             printf("%s %s", empleados[indice].apellido1, empleados[indice].apellido2);
  687.             gotoxy(xSalario, posicionY);
  688.             printf("%1.2f", empleados[indice].salario);
  689.             gotoxy(xFechaEntrada, posicionY);
  690.             printf("%d/%d/%d", empleados[indice].fentrada.dia, empleados[indice].fentrada.mes, empleados[indice].fentrada.agno);
  691.             gotoxy(xEdad, posicionY);
  692.             printf("%d", obtenerEdad(indice));
  693.             indice++;
  694.         }
  695.     }
  696.     /**BUSQUEDA POR ID**/
  697.     if(tipoDeBusqueda == 1)
  698.     {
  699.         while(indice < empleadoActual)
  700.         {
  701.             //posicionY++;
  702.             //gotoxy(1, posicionY);
  703.             if(indice == IDBuscar)
  704.             {
  705.                 posicionY++;
  706.                 gotoxy(1, posicionY);
  707.                 imprimirID(indice);
  708.                 gotoxy(posicionX, posicionY);
  709.                 printf("%s %s", empleados[indice].nombre1, empleados[indice].nombre2);
  710.                 gotoxy(xApellidos, posicionY);
  711.                 printf("%s %s", empleados[indice].apellido1, empleados[indice].apellido2);
  712.                 gotoxy(xSalario, posicionY);
  713.                 printf("%1.2f", empleados[indice].salario);
  714.                 gotoxy(xFechaEntrada, posicionY);
  715.                 printf("%d/%d/%d", empleados[indice].fentrada.dia, empleados[indice].fentrada.mes, empleados[indice].fentrada.agno);
  716.                 gotoxy(xEdad, posicionY);
  717.                 printf("%d", obtenerEdad(indice));
  718.             }
  719.             indice++;
  720.         }
  721.     }
  722.     /**BUSQUEDA POR NOMBRE**/
  723.     if(tipoDeBusqueda == 2)
  724.     {
  725.         while(indice < empleadoActual)
  726.         {
  727.             if((strncmp(empleados[indice].nombre1, nombreBuscar,strlen(nombreBuscar)) == 0) || (strncmp(empleados[indice].nombre2, nombreBuscar,strlen(nombreBuscar)) == 0))
  728.             {
  729.                 posicionY++;
  730.                 gotoxy(1, posicionY);
  731.                 imprimirID(indice);
  732.                 gotoxy(posicionX, posicionY);
  733.                 printf("%s %s", empleados[indice].nombre1, empleados[indice].nombre2);
  734.                 gotoxy(xApellidos, posicionY);
  735.                 printf("%s %s", empleados[indice].apellido1, empleados[indice].apellido2);
  736.                 gotoxy(xSalario, posicionY);
  737.                 printf("%1.2f", empleados[indice].salario);
  738.                 gotoxy(xFechaEntrada, posicionY);
  739.                 printf("%d/%d/%d", empleados[indice].fentrada.dia, empleados[indice].fentrada.mes, empleados[indice].fentrada.agno);
  740.                 gotoxy(xEdad, posicionY);
  741.                 printf("%d", obtenerEdad(indice));
  742.             }
  743.             indice++;
  744.         }
  745.     }
  746.     /**BUSQUEDA POR APELLIDO**/
  747.     if(tipoDeBusqueda == 3)
  748.     {
  749.         while(indice < empleadoActual)
  750.         {
  751.             if((strcmp(empleados[indice].apellido1, apellidoBuscar) == 0) || (strcmp(empleados[indice].apellido2, apellidoBuscar) == 0))
  752.             {
  753.                 posicionY++;
  754.                 gotoxy(1, posicionY);
  755.                 imprimirID(indice);
  756.                 gotoxy(posicionX, posicionY);
  757.                 printf("%s %s", empleados[indice].nombre1, empleados[indice].nombre2);
  758.                 gotoxy(xApellidos, posicionY);
  759.                 printf("%s %s", empleados[indice].apellido1, empleados[indice].apellido2);
  760.                 gotoxy(xSalario, posicionY);
  761.                 printf("%1.2f", empleados[indice].salario);
  762.                 gotoxy(xFechaEntrada, posicionY);
  763.                 printf("%d/%d/%d", empleados[indice].fentrada.dia, empleados[indice].fentrada.mes, empleados[indice].fentrada.agno);
  764.                 gotoxy(xEdad, posicionY);
  765.                 printf("%d", obtenerEdad(indice));
  766.             }
  767.             indice++;
  768.         }
  769.     }
  770.     /**BUSQUEDA MEDIANTE RANGO DE EDAD**/
  771.     if(tipoDeBusqueda == 4)
  772.     {
  773.         while(indice < empleadoActual)
  774.         {
  775.             edadIndice = obtenerEdad(indice);
  776.             if((edadIndice >= edadMinima) && (edadIndice <= edadMaxima))
  777.             {
  778.                 posicionY++;
  779.                 gotoxy(1, posicionY);
  780.                 imprimirID(indice);
  781.                 gotoxy(posicionX, posicionY);
  782.                 printf("%s %s", empleados[indice].nombre1, empleados[indice].nombre2);
  783.                 gotoxy(xApellidos, posicionY);
  784.                 printf("%s %s", empleados[indice].apellido1, empleados[indice].apellido2);
  785.                 gotoxy(xSalario, posicionY);
  786.                 printf("%1.2f", empleados[indice].salario);
  787.                 gotoxy(xFechaEntrada, posicionY);
  788.                 printf("%d/%d/%d", empleados[indice].fentrada.dia, empleados[indice].fentrada.mes, empleados[indice].fentrada.agno);
  789.                 gotoxy(xEdad, posicionY);
  790.                 printf("%d", obtenerEdad(indice));
  791.             }
  792.             indice++;
  793.         }
  794.     }
  795.     /**BUSQUEDA POR RANGO SALARIAL**/
  796.     if(tipoDeBusqueda == 5)
  797.     {
  798.         while(indice < empleadoActual)
  799.         {
  800.             if((empleados[indice].salario >= salarioMinimo) && (empleados[indice].salario <= salarioMaximo))
  801.             {
  802.                 posicionY++;
  803.                 gotoxy(1, posicionY);
  804.                 imprimirID(indice);
  805.                 gotoxy(posicionX, posicionY);
  806.                 printf("%s %s", empleados[indice].nombre1, empleados[indice].nombre2);
  807.                 gotoxy(xApellidos, posicionY);
  808.                 printf("%s %s", empleados[indice].apellido1, empleados[indice].apellido2);
  809.                 gotoxy(xSalario, posicionY);
  810.                 printf("%1.2f", empleados[indice].salario);
  811.                 gotoxy(xFechaEntrada, posicionY);
  812.                 printf("%d/%d/%d", empleados[indice].fentrada.dia, empleados[indice].fentrada.mes, empleados[indice].fentrada.agno);
  813.                 gotoxy(xEdad, posicionY);
  814.                 printf("%d", obtenerEdad(indice));
  815.             }
  816.             indice++;
  817.         }
  818.     }
  819. }
  820. /**
  821.     Función     : ImprimirID
  822.     Parámetros  : Indice
  823.     Objetivo    : Imprimir el ID con los ceros correspondientes a la izquierda
  824. **/
  825. void imprimirID(int indice)
  826. {
  827.     indice++;
  828.     if(indice <= 9)
  829.     {
  830.         printf("000%d", indice);
  831.     }
  832.     if(indice > 9 && indice <= 99)
  833.     {
  834.         printf("00%d", indice);
  835.     }
  836.     if(indice > 99 && indice <= 999)
  837.     {
  838.         printf("0%d", indice);
  839.     }
  840.     if(indice > 999)
  841.     {
  842.         printf("%d",indice);
  843.     }
  844. }
  845. /**
  846.     Función     : ObtenerSalarioMayor
  847.     Parámetros  : ninguno
  848.     Objetivo    : Conocer cual es el salario mayor para así justificar la salida
  849. **/
  850. int obtenerSalarioMayor()
  851. {
  852.     int cantidadMayor=0, indiceEmpleado=0; float salarioActual;
  853.     while(indiceEmpleado < empleadoActual)
  854.     {
  855.         salarioActual = cantidadDigitosNumero(empleados[indiceEmpleado].salario);
  856.         if(salarioActual > cantidadMayor)
  857.         {
  858.             cantidadMayor = salarioActual;
  859.         }
  860.         indiceEmpleado++;
  861.     }
  862.     return cantidadMayor;
  863. }
  864. /**
  865.     Función     : cantidadDigitosNumero
  866.     Parámetros  : numero
  867.     Objetivo    : Devolver la cantidad de digitos que posee el salario
  868. **/
  869. int cantidadDigitosNumero(float numero)
  870. {
  871.     return (int) log10(numero) + 1;
  872. }
  873. /**
  874.     Función     : ObtenerPrimerNombreLargo
  875.     Parámetros  : ninguno
  876.     Objetivo    : Conocer la cantidad de carácteres que posee el nombre mas largo
  877. **/
  878. int obtenerPrimerNombreLargo()
  879. {
  880.     int mayorLetras=0;
  881.     int indiceEmpleado=0;
  882.     int indiceNombre=0;
  883.     int contadorLetras = 0;
  884.     while(indiceEmpleado < empleadoActual)
  885.     {
  886.         while(empleados[indiceEmpleado].nombre1[indiceNombre] != '\0')
  887.         {
  888.             if(contadorLetras > mayorLetras)
  889.             {
  890.                 mayorLetras = contadorLetras;
  891.             }
  892.             contadorLetras++;
  893.             indiceNombre++;
  894.         }
  895.         indiceEmpleado++;
  896.         //mayorLetras = contadorLetras;
  897.     }
  898.     return mayorLetras+1;
  899. }
  900. /**
  901.     Función     : obtenerSegundoNombreLargo
  902.     Parámetros  : ninguno
  903.     Objetivo    : Conocer la cantidad de carácteres que posee el segundo nombre mas largo
  904. **/
  905. int obtenerSegundoNombreLargo()
  906. {
  907.     int mayorLetras=0;
  908.     int indiceEmpleado=0;
  909.     int indiceNombre=0;
  910.     int contadorLetras = 0;
  911.     while(indiceEmpleado < empleadoActual)
  912.     {
  913.         while(empleados[indiceEmpleado].nombre2[indiceNombre] != '\0')
  914.         {
  915.             if(contadorLetras > mayorLetras)
  916.             {
  917.                 mayorLetras = contadorLetras;
  918.             }
  919.             contadorLetras++;
  920.             indiceNombre++;
  921.         }
  922.         indiceEmpleado++;
  923.         //mayorLetras = contadorLetras;
  924.     }
  925.     return mayorLetras+1;
  926. }
  927. /**
  928.     Función     : ObtenerPrimerApellidoLargo
  929.     Parámetros  : ninguno
  930.     Objetivo    : Conocer la cantidad de carácteres que posee el apellido mas largo
  931. **/
  932. int obtenerPrimerApellidoLargo()
  933. {
  934.     int mayorLetras=0;
  935.     int indiceEmpleado=0;
  936.     int indiceNombre=0;
  937.     int contadorLetras = 0;
  938.     while(indiceEmpleado < empleadoActual)
  939.     {
  940.         while(empleados[indiceEmpleado].apellido1[indiceNombre] != '\0')
  941.         {
  942.             if(contadorLetras > mayorLetras)
  943.             {
  944.                 mayorLetras = contadorLetras;
  945.             }
  946.             contadorLetras++;
  947.             indiceNombre++;
  948.         }
  949.         indiceEmpleado++;
  950.         //mayorLetras = contadorLetras;
  951.     }
  952.     return mayorLetras+1;
  953. }
  954. /**
  955.     Función     : ObtenerSegundoNombreLargo
  956.     Parámetros  : ninguno
  957.     Objetivo    : Conocer la cantidad de carácteres que posee el segundo nombre mas largo
  958. **/
  959. int obtenerSegundoApellidoLargo()
  960. {
  961.     int mayorLetras=0;
  962.     int indiceEmpleado=0;
  963.     int indiceNombre=0;
  964.     int contadorLetras = 0;
  965.     while(indiceEmpleado < empleadoActual)
  966.     {
  967.         while(empleados[indiceEmpleado].apellido2[indiceNombre] != '\0')
  968.         {
  969.             if(contadorLetras > mayorLetras)
  970.             {
  971.                 mayorLetras = contadorLetras;
  972.             }
  973.             contadorLetras++;
  974.             indiceNombre++;
  975.         }
  976.         indiceEmpleado++;
  977.         //mayorLetras = contadorLetras;
  978.     }
  979.     return mayorLetras+1;
  980. }
  981. /**
  982.     Función     : ObtenerEdad
  983.     Parámetros  : indice
  984.     Objetivo    : Devolver la edad de la persona dada su fecha
  985. **/
  986. int obtenerEdad(int indice)
  987. {
  988.     time_t t = time(NULL);
  989.     struct tm tm = *localtime(&t);
  990.     int edad = (tm.tm_year+1900) - empleados[indice].fnacim.agno;
  991.     return edad;
  992. }
  993. /**
  994.     Función     : menuListar
  995.     Parámetros  : opcionSeleccionada, posicionY, cantidadDeOpciones
  996.     Objetivo    : Manejar las opciones dentro del menú Lista
  997. **/
  998. void menuListar(int opcionSeleccionada, int posicionY, int cantidadDeOpciones)
  999. {
  1000.     int posicionX = 57, indice=0, posicionYdeError = cantidadDeOpciones+1;
  1001.     int idBuscar = -1, opc, opc5, edadMinima = -1, edadMaxima = -1,salarioMaximo=-1, salarioMinimo=-1;
  1002.     char enter, nombreBuscar[LENNOM], apellidoBuscar[LENNOM];
  1003.     switch(opcionSeleccionada)
  1004.     {
  1005.     case 0:
  1006.         listaEmpleados(11,0, -1, '0', '0', -1, -1, -1, -1);
  1007.         textcolor(RED);
  1008.         printf("\nPresione enter para regresar...");
  1009.         colordefault();
  1010.         do
  1011.         {
  1012.             fflush(stdin);
  1013.             enter = getch();
  1014.         }while(enter != 13);
  1015.         main(3);
  1016.         break;
  1017.     case 1:
  1018.         busquedaID(11,idBuscar, posicionX, posicionY,3);
  1019.         break;
  1020.     case 2:
  1021.         busquedaNombre(11,nombreBuscar, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones,3);
  1022.         break;
  1023.     case 3:
  1024.         busquedaApellido(11,apellidoBuscar,posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones,3);
  1025.         break;
  1026.     case 4:
  1027.         busquedaRangoEdad(11,edadMinima, edadMaxima, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones,3);
  1028.         break;
  1029.     case 5:
  1030.         busquedaRangoSalario(11,salarioMinimo, salarioMaximo, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones,3);
  1031.         break;
  1032.     case 6:
  1033.         main(3);
  1034.         break;
  1035.     }
  1036. }
  1037. /**
  1038.     Función     : menuModificar
  1039.     Parámetros  : opcionSeleccionada, posicionY, cantidadDeOpciones
  1040.     Objetivo    : Manejar las opciones dentro del menú Modificar
  1041. **/
  1042. void menuModificar(int opcionSeleccionada, int posicionY, int cantidadDeOpciones)
  1043. {
  1044.     int posicionX = 59, posicionYdeError = cantidadDeOpciones+2;
  1045.     char enter, nombreBuscar[LENNOM], apellidoBuscar[LENNOM];
  1046.     switch(opcionSeleccionada)
  1047.     {
  1048.     case 0:
  1049.         listaEmpleados(15,0, -1, '0', '0', -1, -1, -1, -1);
  1050.         textcolor(RED);
  1051.         printf("\nPresione enter para regresar...");
  1052.         colordefault();
  1053.         do
  1054.         {
  1055.             fflush(stdin);
  1056.             enter = getch();
  1057.         }while(enter != 13);
  1058.         main(1);
  1059.         break;
  1060.     case 1:
  1061.         busquedaNombre(15,nombreBuscar, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones,1);
  1062.         break;
  1063.     case 2:
  1064.         textcolor(GREEN);
  1065.         gotoxy(posicionX, posicionY);
  1066.         scanf("%d", &idBuscar);
  1067.         idBuscar = idBuscar - 1;
  1068.         if(idBuscar > empleadoActual || idBuscar < 0 || (idBuscar == 0 && empleados[idBuscar].salario == 0))
  1069.         {
  1070.             idBuscar = -1;
  1071.             gotoxy(1, posicionYdeError);
  1072.             textcolor(RED);
  1073.             printf("Empleado no existe");
  1074.             fflush(stdin);
  1075.             getch();
  1076.             gotoxy(1, posicionYdeError);
  1077.             printf("\t\t\t\t\t\t\t\t");
  1078.             colordefault();
  1079.             gotoxy(posicionX, posicionY); printf("\t\t\t\t");
  1080.         }
  1081.         else
  1082.         {
  1083.             textcolor(YELLOW);
  1084.             gotoxy(posicionX, posicionY+1);
  1085.             printf("%s", empleados[idBuscar].nombre1);
  1086.             gotoxy(posicionX, posicionY+2);
  1087.             printf("%s", empleados[idBuscar].nombre2);
  1088.             gotoxy(posicionX, posicionY+3);
  1089.             printf("%s", empleados[idBuscar].apellido1);
  1090.             gotoxy(posicionX, posicionY+4);
  1091.             printf("%s", empleados[idBuscar].apellido2);
  1092.             gotoxy(posicionX, posicionY+5);
  1093.             printf("%d/%d/%d", empleados[idBuscar].fentrada.dia, empleados[idBuscar].fentrada.mes, empleados[idBuscar].fentrada.agno);
  1094.             gotoxy(posicionX, posicionY+6);
  1095.             printf("%d/%d/%d", empleados[idBuscar].fnacim.dia, empleados[idBuscar].fnacim.mes, empleados[idBuscar].fnacim.agno);
  1096.             gotoxy(posicionX, posicionY+7);
  1097.             printf("%1.2f", empleados[idBuscar].salario);
  1098.         }
  1099.  
  1100.         break;
  1101.     case 3:/**Modificar primer nombre**/
  1102.         if(idBuscar == -1)
  1103.         {
  1104.             verificarIngresoID(idBuscar,posicionYdeError);
  1105.         }
  1106.         else
  1107.         {
  1108.             obtenerCaracteres(posicionX, posicionY, posicionYdeError, empleados[idBuscar].nombre1,0);
  1109.             gotoxy(1, posicionYdeError);
  1110.             textcolor(LIGHTGREEN);
  1111.             printf("Modificado correctamente\t\t\t\t");
  1112.             colordefault();
  1113.         }
  1114.         break;
  1115.     case 4:/**Modificar segundo nombre**/
  1116.         if(idBuscar == -1)
  1117.         {
  1118.             verificarIngresoID(idBuscar,posicionYdeError);
  1119.         }
  1120.         else
  1121.         {
  1122.             obtenerCaracteres(posicionX, posicionY,posicionYdeError, empleados[idBuscar].nombre2,0);
  1123.             gotoxy(1, posicionYdeError);
  1124.             textcolor(LIGHTGREEN);
  1125.             printf("Modificado correctamente\t\t\t\t");
  1126.             colordefault();
  1127.         }
  1128.  
  1129.         break;
  1130.     case 5:/**Modificar primer apellido**/
  1131.         if(idBuscar == -1)
  1132.         {
  1133.             verificarIngresoID(idBuscar,posicionYdeError);
  1134.         }
  1135.         else
  1136.         {
  1137.             obtenerCaracteres(posicionX, posicionY, posicionYdeError,empleados[idBuscar].apellido1,1);
  1138.             gotoxy(1, posicionYdeError);
  1139.             textcolor(LIGHTGREEN);
  1140.             printf("Modificado correctamente\t\t\t\t");
  1141.             colordefault();
  1142.         }
  1143.  
  1144.         break;
  1145.     case 6:/**Modificar segundo apellido**/
  1146.         if(idBuscar == -1)
  1147.         {
  1148.             verificarIngresoID(idBuscar,posicionYdeError);
  1149.         }
  1150.         else
  1151.         {
  1152.             obtenerCaracteres(posicionX, posicionY, posicionYdeError,empleados[idBuscar].apellido2,1);
  1153.             gotoxy(1, posicionYdeError);
  1154.             textcolor(LIGHTGREEN);
  1155.             printf("Modificado correctamente\t\t\t\t");
  1156.             colordefault();
  1157.         }
  1158.         break;
  1159.     case 7:/**Modificar fecha entrada**/
  1160.         if(idBuscar == -1)
  1161.         {
  1162.             verificarIngresoID(idBuscar,posicionYdeError);
  1163.         }
  1164.         else
  1165.         {
  1166.             empleados[idBuscar].fentrada.agno = -1;
  1167.             obtenerFechaEntrada(posicionX, posicionY,posicionYdeError, idBuscar);
  1168.             gotoxy(1, posicionYdeError);
  1169.             textcolor(LIGHTGREEN);
  1170.             printf("Modificado correctamente\t\t\t\t");
  1171.             colordefault();
  1172.         }
  1173.         break;
  1174.     case 8:/**Modificar fecha nacimiento**/
  1175.         if(idBuscar == -1)
  1176.         {
  1177.             verificarIngresoID(idBuscar,posicionYdeError);
  1178.         }
  1179.         else
  1180.         {
  1181.             empleados[idBuscar].fnacim.agno = -1;
  1182.             obtenerFechaNacimiento(posicionX, posicionY,posicionYdeError, idBuscar);
  1183.             gotoxy(1, posicionYdeError);
  1184.             textcolor(LIGHTGREEN);
  1185.             printf("Modificado correctamente\t\t\t\t");
  1186.             colordefault();
  1187.         }
  1188.         break;
  1189.     case 9:/**Modificar salario**/
  1190.         if(idBuscar == -1)
  1191.         {
  1192.             verificarIngresoID(idBuscar,posicionYdeError);
  1193.         }
  1194.         else
  1195.         {
  1196.             empleados[idBuscar].salario = -1;
  1197.             obtenerSalario(posicionX, posicionY, posicionYdeError, idBuscar);
  1198.             gotoxy(1, posicionYdeError);
  1199.             textcolor(LIGHTGREEN);
  1200.             printf("Modificado correctamente\t\t\t\t\t\t\t\t\t");
  1201.             colordefault();
  1202.         }
  1203.         break;
  1204.     case 10:
  1205.         main(1);
  1206.         break;
  1207.     }
  1208. }
  1209. /**
  1210.     Función     : verificarIngresoID
  1211.     Parámetros  : idBuscar, posicionYdeError
  1212.     Objetivo    : Verificar que el usuario quiera modificar un nombre/apellido,etc primero haya digitado un ID obviamente
  1213. **/
  1214. void verificarIngresoID(int idBuscar, int posicionYdeError)
  1215. {
  1216.     gotoxy(1, posicionYdeError);
  1217.     textcolor(RED);
  1218.     printf("Debe digitar un ID primero");
  1219.     fflush(stdin);
  1220.     getch();
  1221.     gotoxy(1, posicionYdeError);
  1222.     printf("\t\t\t\t\t\t\t\t\t\t");
  1223. }
  1224. /**
  1225.     Función     : menuBorrar
  1226.     Parámetros  : opcionSeleccionada, posicionY, cantidadDeOpciones
  1227.     Objetivo    : Manejar las opciones dentro del menú borrar
  1228. **/
  1229. void menuBorrar(int opcionSeleccionada, int posicionY, int cantidadDeOpciones)
  1230. {
  1231.     int posicionX = 59, posicionYdeError = cantidadDeOpciones+3, indice = 0;
  1232.     char enter, nombreBuscar[LENNOM];
  1233.     switch(opcionSeleccionada)
  1234.     {
  1235.     case 0:
  1236.         listaEmpleados(8,0, -1, '0', '0', -1, -1, -1, -1);
  1237.         textcolor(RED);
  1238.         printf("\nPresione enter para regresar...");
  1239.         colordefault();
  1240.         do
  1241.         {
  1242.             fflush(stdin);
  1243.             enter = getch();
  1244.         }while(enter != 13);
  1245.         main(2);
  1246.         break;
  1247.     case 1:
  1248.         busquedaNombre(8, nombreBuscar, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones, 2);
  1249.         break;
  1250.     case 2:
  1251.         textcolor(GREEN);
  1252.         gotoxy(posicionX, posicionY);
  1253.         scanf("%d", &idBuscar);
  1254.         idBuscar = idBuscar - 1;
  1255.         if((idBuscar) > empleadoActual)
  1256.         {
  1257.             gotoxy(1, posicionYdeError);
  1258.             textcolor(RED);
  1259.             printf("Empleado no existe");
  1260.             fflush(stdin);
  1261.             getch();
  1262.             gotoxy(1, posicionYdeError);
  1263.             printf("\t\t\t\t\t\t\t\t");
  1264.             colordefault();
  1265.             gotoxy(posicionX, posicionY); printf("\t\t\t\t");
  1266.         }
  1267.         break;
  1268.     case 3:
  1269.         while(idBuscar <= empleadoActual)
  1270.         {
  1271.             empleados[idBuscar] = empleados[idBuscar+1];
  1272.             idBuscar++;
  1273.         }
  1274.         empleadoActual--;/**Se elimina una posicion de los empleados**/
  1275.         gotoxy(1, posicionYdeError);
  1276.         textcolor(RED);
  1277.         printf("Eliminado correctamente... Presione cualquier tecla para regresar");
  1278.         fflush(stdin);
  1279.         getch();
  1280.         colordefault();
  1281.         main(2);
  1282.         break;
  1283.     case 4:
  1284.         main(2);
  1285.         break;
  1286.     }
  1287. }
  1288. /**
  1289.     Función     : busquedaID
  1290.     Parámetros  : posicionYLista, idBuscar, posicionX, posicionY, retornoMain
  1291.     Objetivo    : Buscar los empleados que sea igual al ID Digitado
  1292. **/
  1293. void busquedaID(int posicionYLista, int idBuscar, int posicionX, int posicionY, int retornoMain)
  1294. {
  1295.         char enter;
  1296.         gotoxy(posicionX, posicionY);
  1297.         scanf("%d", &idBuscar);
  1298.         listaEmpleados(posicionYLista, 1,idBuscar-1, '0', '0', -1, -1,-1,-1);
  1299.         textcolor(RED);
  1300.         printf("\nPresione enter para regresar...");
  1301.         colordefault();
  1302.         do
  1303.         {
  1304.             fflush(stdin);
  1305.             enter = getch();
  1306.         }while(enter != 13);
  1307.         main(retornoMain);
  1308. }
  1309. /**
  1310.     Función     : busquedaNombre
  1311.     Parámetros  : posicionYLista, nombreBuscar, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones, retornoMain
  1312.     Objetivo    : Buscar los empleados que sea igual al Nombre escrito
  1313. **/
  1314. void busquedaNombre(int posicionYLista, char nombreBuscar[LENNOM],int posicionX, int posicionY, int opcionSeleccionada, int cantidadDeOpciones, int retornoMain)
  1315. {
  1316.     char enter;
  1317.     gotoxy(posicionX, posicionY);
  1318.     fflush(stdin);
  1319.     textcolor(GREEN);
  1320.     gets(nombreBuscar);
  1321.     colordefault();
  1322.     if(comprobarTexto(nombreBuscar, 0) > 0)
  1323.     {
  1324.         listaEmpleados(posicionYLista,2,-1,nombreBuscar, '0', -1, -1, -1,-1);
  1325.         textcolor(RED);
  1326.         printf("\nPresione enter para regresar...");
  1327.         if(retornoMain == 2)/**Es decir si vengo desde el menú de Borrar**/
  1328.         {
  1329.             printf("Y borrar el ID ya visualizado");
  1330.         }
  1331.         colordefault();
  1332.         do
  1333.         {
  1334.             fflush(stdin);
  1335.             enter = getch();
  1336.         }while(enter != 13);
  1337.         main(retornoMain);
  1338.     }
  1339.     else
  1340.     {
  1341.         textcolor(RED);
  1342.         gotoxy(1,13);
  1343.         printf("El nombre no debe tener numeros u otros caracteres raros...");
  1344.         colordefault();
  1345.         fflush(stdin);
  1346.         getch();
  1347.         gotoxy(1,13);
  1348.         printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
  1349.         colordefault();
  1350.         gotoxy(posicionX,posicionY);
  1351.         printf("\t\t\t\t\t\t\t\t");
  1352.         busquedaNombre(posicionYLista,nombreBuscar,posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones, retornoMain);
  1353.     }
  1354. }
  1355. /**
  1356.     Función     : busquedaApellido
  1357.     Parámetros  : posicionYLista, apellidoBuscar, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones, retornoMain
  1358.     Objetivo    : Buscar los empleados que sea igual al Apellido escrito
  1359. **/
  1360. void busquedaApellido(int posicionYLista, char apellidoBuscar[LENAPE],int posicionX, int posicionY, int opcionSeleccionada, int cantidadDeOpciones, int retornoMain)
  1361. {
  1362.     char enter;
  1363.     gotoxy(posicionX, posicionY);
  1364.     fflush(stdin);
  1365.     gets(apellidoBuscar);
  1366.     if(comprobarTexto(apellidoBuscar,1) > 0)
  1367.     {
  1368.         listaEmpleados(posicionYLista,3,-1,'0', apellidoBuscar, -1, -1, -1,-1);
  1369.         textcolor(RED);
  1370.         printf("\nPresione enter para regresar...");
  1371.         colordefault();
  1372.         do
  1373.         {
  1374.             fflush(stdin);
  1375.             enter = getch();
  1376.         }while(enter != 13);
  1377.         main(retornoMain);
  1378.     }
  1379.     else
  1380.     {
  1381.         textcolor(RED);
  1382.         gotoxy(1,11);
  1383.         printf("El apellido no debe tener numeros u otros caracteres raros...");
  1384.         fflush(stdin);
  1385.         getch();
  1386.         gotoxy(1,11);
  1387.         printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
  1388.         colordefault();
  1389.         gotoxy(posicionX,posicionY);
  1390.         printf("\t\t\t\t\t\t\t\t");
  1391.         menuListar(opcionSeleccionada, posicionY, cantidadDeOpciones);
  1392.     }
  1393. }
  1394. /**
  1395.     Función     : busquedaRangoEdad
  1396.     Parámetros  : posicionYLista, edadMinima, edadMaxima, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones, retornoMain
  1397.     Objetivo    : Buscar los empleados que sea por rango de Edad
  1398. **/
  1399. void busquedaRangoEdad(int posicionYLista, int edadMinima, int edadMaxima, int posicionX, int posicionY, int opcionSeleccionada, int cantidadDeOpciones, int retornoMain)
  1400. {
  1401.     char enter;
  1402.     gotoxy(posicionX, posicionY);
  1403.     scanf("%d-%d", &edadMinima, &edadMaxima);
  1404.     if(edadMinima < 0 || edadMaxima < 0)
  1405.     {
  1406.         textcolor(RED);
  1407.         gotoxy(1,11);
  1408.         printf("Esta edad no existe o no se ha ingresado correctamente...");
  1409.         fflush(stdin);
  1410.         getch();
  1411.         gotoxy(1,11);
  1412.         printf("\t\t\t\t\t\t\t\t\t");
  1413.         colordefault();
  1414.         gotoxy(posicionX, posicionY);
  1415.         printf("\t\t\t\t\t\t\t");
  1416.         menuListar(opcionSeleccionada, posicionY, cantidadDeOpciones);
  1417.     }
  1418.     else
  1419.     {
  1420.         listaEmpleados(posicionYLista, 4, -1, '0','0', edadMinima, edadMaxima,-1,-1);
  1421.         textcolor(RED);
  1422.         printf("\nPresione enter para regresar...");
  1423.         colordefault();
  1424.         do
  1425.         {
  1426.             fflush(stdin);
  1427.             enter = getch();
  1428.         }while(enter != 13);
  1429.         main(retornoMain);
  1430.     }
  1431. }
  1432. /**
  1433.     Función     : busquedaRangoSalario
  1434.     Parámetros  : posicionYLista, salarioMinimo, salarioMaximo, posicionX, posicionY, opcionSeleccionada, cantidadDeOpciones, retornoMain
  1435.     Objetivo    : Buscar los empleados que sea por rango de salario
  1436. **/
  1437. void busquedaRangoSalario(int posicionYLista, int salarioMinimo, int salarioMaximo, int posicionX, int posicionY, int opcionSeleccionada, int cantidadDeOpciones, int retornoMain)
  1438. {
  1439.     char enter;
  1440.     gotoxy(posicionX, posicionY);
  1441.     scanf("%d-%d", &salarioMinimo, &salarioMaximo);
  1442.     if(salarioMinimo < 0 || salarioMaximo < 0)
  1443.     {
  1444.         textcolor(RED);
  1445.         gotoxy(1,11);
  1446.         printf("Esta edad no existe o no se ha ingresado correctamente...");
  1447.         fflush(stdin);
  1448.         getch();
  1449.         gotoxy(1,11);
  1450.         printf("\t\t\t\t\t\t\t\t\t");
  1451.         colordefault();
  1452.         gotoxy(posicionX, posicionY);
  1453.         printf("\t\t\t\t\t\t\t");
  1454.         menuListar(opcionSeleccionada, posicionY, cantidadDeOpciones);
  1455.     }
  1456.     else
  1457.     {
  1458.         listaEmpleados(posicionYLista, 5, -1, '0','0', -1, -1,salarioMinimo,salarioMaximo);
  1459.         textcolor(RED);
  1460.         printf("\nPresione enter para regresar...");
  1461.         colordefault();
  1462.         do
  1463.         {
  1464.             fflush(stdin);
  1465.             enter = getch();
  1466.         }while(enter != 13);
  1467.         main(retornoMain);
  1468.     }
  1469. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement