Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <DOS.H>
  7.  
  8. // Definicion de Constantes
  9. #define FILE_CLIENTES "clientes.dat"
  10. #define FILE_PELICULAS "cula.dat"
  11. #define FILE_CLAVES "claves.dat"
  12. #define FILE_ALQUILER "Alquila.dat"
  13. #define FILE_CONFIG "config.dat"
  14. #define FILE_PELICULAS_INDICE "peli_ind.dat"
  15. #define FILE_LOG_BAJAS "bajas_pelis.log"
  16. #define FILE_ESTADISTICA "estadistica.dat"
  17. #define p printf
  18. #define s scanf
  19. #define g getch
  20.  
  21.  
  22. // Declaracion de Estructuras
  23. typedef struct
  24. {
  25. int codigo_pel;
  26. char comentario[200];
  27. }comen;
  28.  
  29. typedef struct
  30. {
  31. int cod_cli;
  32. int cod_pel;
  33. } devolucion;
  34.  
  35.  
  36. typedef struct {
  37. char propiedad[30];
  38. char valor[30];
  39. } Config;
  40.  
  41. typedef struct {
  42. int codigo;
  43. char nombre[30];
  44. char apellido[30];
  45. char direccion[30];
  46. char telefono[20];
  47. char estado; // Admite A (Activo) D(desactivado)
  48. int alquileresrealizados;
  49. } Cliente;
  50.  
  51. typedef struct {
  52. int codigo;
  53. char titulo[30];
  54. int copias;
  55. int alquiladas;
  56. char descripcion[100];
  57. int vecesalquilada;
  58. int estado;
  59. } Pelicula;
  60.  
  61. typedef struct {
  62. int valido;
  63. char clave[11];
  64. } Validacion;
  65.  
  66. typedef struct
  67. {
  68. char nombre[11];
  69. char clave[11];
  70. }Usuario;
  71.  
  72. typedef struct {
  73. int codigo;
  74. long posicion;
  75. }Indice;
  76.  
  77. typedef struct date dia;
  78.  
  79. typedef struct
  80. {
  81. int codcli;
  82. int codpel;
  83. dia fecha;
  84. char estado;
  85. }Alquiler;
  86.  
  87. typedef struct
  88. {
  89. int anio;
  90. float contmeses[12];
  91. float porcmeses[12];
  92. float max;
  93. }Estadistica;
  94.  
  95. typedef struct
  96. {
  97. int codpel;
  98. dia fecha;
  99. }peli_baja;
  100.  
  101.  
  102. // Funcion Helper
  103. int ExisteArchivo(char* FileName) ;
  104. // Archivo de configuracion
  105. Config LeerPropiedad(char* propiedad);
  106. void EscribirPropiedad(char* propiedad, char* valor);
  107. // Validacion de Usuario
  108. void AgregarUsuario(void);
  109. void alta_usuario(void);
  110. int RealizarValidacion(void);
  111. void ingreso_de_clave();
  112. char menu(void);
  113. Validacion validar_usuario(char*);
  114. // Funciones para Manejo de Clientes
  115. Cliente* ObtenerCliente_MemoriaDinamica(Cliente,int);
  116. void ConsultarCliente_MemoriaDinamica(void);
  117. long ObtenerPosicionCliente(int); // Recibe el codigo de cliente y devuelve el numero de registro en el archivo o -1
  118. Cliente ObtenerCliente(Cliente,int);
  119. void AgregarCliente(void);
  120. void EliminarFisicaCliente(int);
  121. void ModificarCliente(void);
  122. void EliminarCliente(void); // Se encarga de la baja logica y fisica, cuando si pide la baja de un cliente Activo hace baja logica, y cuando se pide baja de un Cliente Desactivado hace baja fisica.
  123. void ListarClientes(void);
  124. void ConsultarCliente(void);
  125. // Funciones de Menu para Peliculas
  126. void AgregarPelicula(void);
  127. void EliminarPelicula(void);
  128. void EliminarFisicaPelicula(int);
  129. void ModificarPelicula(void);
  130. long ObtenerPosicionPelicula(int);
  131. void ListarPeliculas(void);
  132. //void ListarClientes(void);
  133. void ConsultarPelicula(void);
  134. void Listar_EncaClientes(void);
  135. // Funciones para Manejo de Alquileres
  136. int Menu_Alquiler(void);
  137. void RegistrarAlquiler(void);
  138. void ListarAlquileres(void);
  139. void PeliculasAlquiladas(void);
  140. int Menu_Devolucion(void);
  141. void cargar(void);
  142. void mostrar(void);
  143. // Funciones para Menues
  144. int Menu_Reporte(void);
  145. int Menu_Principal(void);
  146. int Menu_Clientes(void);
  147. int Menu_Peliculas(void);
  148. int Menu_Busqueda_NomApeCodigo(void);
  149. // Funciones para Registro de Bajas
  150. void registrar_bajas (int);
  151. void ListarBajas(void);
  152. // Funciones para información estadística
  153. void Crear_Estad_Alq (void);
  154. Pelicula ObtenerPelicula(Pelicula,int);
  155. void ListarEstadistica(void);
  156.  
  157. // MAIN - Inicio
  158. void main()
  159. {
  160. int op, opsubmenu;
  161.  
  162. // Parte de validacion
  163. int intentosFallidos = 0;
  164. do
  165. {
  166. if (RealizarValidacion() == 0)
  167. break;
  168. else
  169. intentosFallidos++;
  170.  
  171. if (intentosFallidos == 3) exit(0);
  172. }
  173. while (intentosFallidos < 3);
  174.  
  175. if(ExisteArchivo(FILE_CONFIG)==0)
  176. {
  177. EscribirPropiedad("codclien","1");
  178. EscribirPropiedad("codpeli","1");
  179. }
  180.  
  181. do
  182. {
  183. op=Menu_Principal();
  184. switch(op)
  185. {
  186. case 1:
  187. do
  188. {
  189. opsubmenu = Menu_Clientes();
  190. if (opsubmenu == 1) AgregarCliente();
  191. if (opsubmenu == 2) EliminarCliente();
  192. if (opsubmenu == 3) ModificarCliente();
  193. if (opsubmenu == 4) ConsultarCliente_MemoriaDinamica();//ConsultarCliente();
  194. }
  195. while(opsubmenu!=5);
  196. break;
  197. case 2:
  198. do
  199. {
  200. opsubmenu = Menu_Peliculas();
  201. if (opsubmenu == 1) AgregarPelicula();
  202. if (opsubmenu == 2) EliminarPelicula();
  203. if (opsubmenu == 3) ModificarPelicula();
  204. break;
  205.  
  206. }
  207. while(opsubmenu!=4);
  208. break;
  209. case 3:
  210. opsubmenu = Menu_Alquiler();
  211. if (opsubmenu == 1) RegistrarAlquiler();
  212. if (opsubmenu == 2) ListarAlquileres();
  213. break;
  214. case 4:
  215. Menu_Devolucion();
  216. break;
  217. case 5:
  218. do
  219. {
  220. opsubmenu = Menu_Reporte();
  221. if (opsubmenu == 1) ListarClientes();
  222. if (opsubmenu == 2) ListarPeliculas();
  223. if (opsubmenu == 3) PeliculasAlquiladas();
  224. if (opsubmenu == 4) ListarBajas();
  225. if (opsubmenu == 5) ListarEstadistica();
  226. }
  227. while(opsubmenu<6);//AGREGAR
  228. break;
  229. case 6:
  230. if (RealizarValidacion() == 0)
  231. {
  232. alta_usuario();
  233. break;
  234. }
  235. else
  236. break;
  237. case 7:
  238. Crear_Estad_Alq();
  239. break;
  240. }
  241. }while(op<8);
  242.  
  243. return;
  244. }
  245.  
  246. // MAIN - Fin
  247.  
  248. // INICIO - Manejo de Claves
  249. int RealizarValidacion()
  250. {
  251.  
  252. // 0 Usuario OK, 1 - Clave Incorrecta - 1 Usuario Inexistente
  253. char pass[11],car;
  254. char usu[11];
  255. int i=0;
  256. Validacion x;
  257. clrscr();
  258. printf("Usuario: ");
  259. fflush(stdin);
  260. gets(usu);
  261.  
  262.  
  263. x=validar_usuario(usu);
  264. if(x.valido==1)
  265. {
  266. printf("Ingrese la clave: ");
  267. while((car=getch())!='\r'&&i<10)
  268. {
  269. pass[i++]=car;
  270. printf("%c",'*');
  271. }
  272. pass[i]=NULL;
  273. if(strcmp(x.clave,pass)==0)
  274. return 0;
  275. else
  276. return 1;
  277. }
  278. else
  279. return -1;
  280. }
  281.  
  282. void alta_usuario(void)
  283. {
  284. FILE *ptr;
  285. char aux[200],cla1[11],cla2[11];
  286. Usuario reg;
  287. ptr=fopen(FILE_CLAVES,"a+b");
  288. clrscr();
  289. printf("Ingrese nombre de usuario: ");
  290. fflush(stdin);
  291. gets(aux);
  292. aux[10]=NULL;
  293. strcpy(reg.nombre,aux);
  294. printf("Ingrese clave: ");
  295. gets(cla1);
  296. printf("Confirme clave: ");
  297. gets(cla2);
  298. if(strcmp(cla1,cla2)==0)
  299. {
  300. strcpy(reg.clave,cla1);
  301. fwrite(&reg,sizeof(reg),1,ptr);
  302. }
  303. fclose(ptr);
  304. }
  305.  
  306. Validacion validar_usuario(char*usu)
  307. {
  308. FILE *ptr;
  309. Usuario reg;
  310. Validacion reg1;
  311. int x=0;
  312.  
  313.  
  314. if ( strcmpi(usu,"admin") == 0)
  315. {
  316. reg1.valido = 1;
  317. strcpy(reg1.clave,"admin123");
  318. }
  319. else
  320. {
  321. ptr=fopen(FILE_CLAVES,"rb");
  322. fread(&reg,sizeof(reg),1,ptr);
  323. while(!feof(ptr))
  324. {
  325. if(strcmp(reg.nombre,usu)==0)
  326. {
  327. strcpy(reg1.clave,reg.clave);
  328. x=1;
  329. break;
  330. }
  331. fread(&reg,sizeof(reg),1,ptr);
  332. }
  333.  
  334. reg1.valido=x;
  335. fclose(ptr);
  336. }
  337. return reg1;
  338. }
  339. // FIN - Manejo de Claves
  340.  
  341. // Menu_Principal - Inicio
  342. int Menu_Principal(void)
  343. {
  344. int op;
  345. do
  346. {
  347. clrscr();
  348. gotoxy(38,5);
  349. p("Video Club El LP3");
  350. gotoxy(36,8);
  351. p("1 - Admistracion de Clientes");
  352. gotoxy(36,9);
  353. p("2 - Administracion de Peliculas");
  354. gotoxy(36,10);
  355. p("3 - Alquileres");
  356. gotoxy(36,11);
  357. p("4 - Devoluciones");
  358. gotoxy(36,12);
  359. p("5 - Reportes");
  360. gotoxy(36,13);
  361. p("6 - Usuarios");
  362. gotoxy(36,14);
  363. p("7 - Crear Estadistica"); //AGREGAR
  364. gotoxy(36,15);
  365. p("8 - Salir");
  366. gotoxy(36,17); //AGREGAR
  367. p("Ingrese una opcion: ");
  368. s("%d",&op);
  369. }while(op<1||op>8);
  370. return op;
  371. }
  372.  
  373. // Menu_Principal - Fin
  374. // Menu_Clientes - Inicio
  375. int Menu_Clientes(void)
  376. {
  377. int op;
  378. flushall();
  379. do
  380. {
  381. clrscr();
  382. gotoxy(38,5);
  383. printf("Administracion de Clientes");
  384. gotoxy(36,8);
  385. printf("1 - Altas");
  386. gotoxy(36,9);
  387. printf("2 - Bajas");
  388. gotoxy(36,10);
  389. printf("3 - Modificaciones");
  390. gotoxy(36,11);
  391. printf("4 - Consultas");
  392. gotoxy(36,12);
  393. printf("5 - Salir");
  394. gotoxy(36,13);
  395. printf("Ingrese una opcion: ");
  396. scanf("%d",&op);
  397. }while(op<1||op>5);
  398. return op;
  399. }
  400. // Menu_Clientes - Fin
  401. // Menu_Peliculas - Inicio
  402. int Menu_Peliculas(void)
  403. {
  404. int op;
  405.  
  406. do
  407. {
  408. clrscr();
  409. gotoxy(38,5);
  410. printf("Administracion de Peliculas");
  411. gotoxy(36,8);
  412. printf("1- Altas");
  413. gotoxy(36,9);
  414. printf("2- Bajas");
  415. gotoxy(36,10);
  416. printf("3- Modificaciones");
  417. gotoxy(36,11);
  418. printf("4- Consultas");
  419. gotoxy(36,12);
  420. printf("5- Salir");
  421. gotoxy(36,13);
  422. printf("Ingrese una opcion: ");
  423. scanf("%d",&op);
  424. }while(op<1||op>5);
  425. return op;
  426. }
  427. // Menu_Peliculas - Fin
  428. // Menu_Alquiler - Inicio
  429. int Menu_Alquiler(void)
  430. {
  431. int op;
  432.  
  433. do
  434. {
  435. clrscr();
  436. gotoxy(38,5);
  437. p("Registro del Alquiler");
  438. gotoxy(36,9);
  439. p("1 - Registro de Alquiler");
  440. gotoxy(36,10);
  441. p("2 - Listado de Alquileres");
  442. gotoxy(36,11);
  443. p("3 - Salir");
  444. gotoxy(36,13);
  445. p("Ingrese una opcion: ");
  446. s("%d",&op);
  447. }while(op<1||op>3);
  448. return op;
  449. }
  450. // Menu_Alquiler - Fin
  451. // Menu_Devolucion - Inicio
  452. int Menu_Devolucion(void)
  453. {
  454. int cond;
  455. // char op;
  456. clrscr();
  457.  
  458. {
  459. devolucion reg;
  460.  
  461. FILE *pf;
  462. pf = fopen("c:\\devoluciones.txt","wb");
  463. if (pf==NULL)
  464. {
  465. clrscr();
  466. printf("error de apertura");
  467. getch();
  468. exit(1);
  469. }
  470.  
  471. //carga del archivo
  472. clrscr();
  473. gotoxy(20,10);
  474. p("SELECCIONO INGRESAR UNA DEVOLUCION");
  475.  
  476.  
  477. printf("\n\n\n\nIngrese el c¢digo de la pelicula devuelta: ");
  478. scanf("%d", &reg.cod_pel);
  479.  
  480. while (reg.cod_pel)
  481. {
  482. printf("\n\nIngrese el c¢digo del cliente: ");
  483. fflush(stdin);
  484. scanf("%d",&reg.cod_cli);
  485. fwrite(&reg,sizeof(reg),1,pf);
  486. clrscr();
  487.  
  488. printf("Ingrese el c¢digo de la pelicula devuelta<0= salir>: ");
  489. scanf("%d", &reg.cod_pel);
  490.  
  491. }
  492. fclose(pf);
  493. }
  494.  
  495. printf("\n \nDesea agregar un comentario? \n SI=1, NO=2 ->");
  496. fflush(stdin);
  497. scanf("%d",&cond);
  498. if (cond==1)
  499. {
  500. cargar();
  501. }
  502. // mostrar();
  503.  
  504. return 0;
  505. }
  506.  
  507. // Menu_Devolucion - Fin
  508. // Menu_Reporte - Inicio
  509. int Menu_Reporte(void)
  510. {
  511. int op;
  512.  
  513. do
  514. {
  515. clrscr();
  516. gotoxy(38,5);
  517. printf("Reportes");
  518. gotoxy(36,8);
  519. printf("1 - Listado de Clientes");
  520. gotoxy(36,9);
  521. printf("2 - Listado de Peliculas");
  522. gotoxy(36,10);
  523. printf("3 - Peliculas Alquiladas");
  524. gotoxy(36,11);
  525. printf("4 - Listar Peliculas Dadas de Baja"); //AGREGAR
  526. gotoxy(36,12);
  527. printf("5 - Listar Informacion Estadistica"); //AGREGAR
  528. gotoxy(36,13);
  529. printf("6 - Salir");
  530. gotoxy(36,14);
  531. printf("Ingrese una opcion: ");
  532. scanf("%d",&op);
  533. }while(op<1||op>6); //AGREGAR
  534. return op;
  535. }
  536.  
  537. // Menu_Reporte - Fin
  538. void ModificarCliente(void)
  539. {
  540. int codigo;
  541. char continua,otro,conf;
  542. Cliente cliente,cliente_NuevosDatos,aux;
  543. long posicion;
  544. FILE *p1;
  545.  
  546. clrscr();
  547. gotoxy(24,1);
  548. printf("Ingrese el Codigo del Cliente a Buscar: ");
  549. scanf("%d",&codigo);
  550. posicion=ObtenerPosicionCliente(codigo);
  551.  
  552. clrscr();
  553. if(posicion == -1)
  554. {
  555. gotoxy(25,20);
  556. printf("CLIENTE NO ENCONTRADO");
  557. getch();
  558. return;
  559. }
  560.  
  561. // Cargamos el cliente para mostrarlo antes de pedir los nuevos datos
  562. if((p1 = fopen(FILE_CLIENTES,"r+b")) == NULL)
  563. {
  564. gotoxy(25,13);
  565. printf("ERROR AL GENERAR ARCHIVO DE CLIENTE %s",FILE_CLIENTES);
  566. getch();
  567. return;
  568. }
  569.  
  570. fseek(p1,posicion,SEEK_SET);
  571. if (fread(&cliente,sizeof(Cliente),1,p1) != 1)
  572. {
  573. clreol();
  574. printf("\aERROR AL LEER ARCHIVO!!!!");
  575. getch();
  576. return;
  577. }
  578.  
  579. clrscr();
  580. gotoxy(25,2);
  581. printf("DATOS DEL REGISTRO ENCONTRADO");
  582. gotoxy(25,3);
  583. printf("Codigo : %d ",cliente.codigo);
  584. gotoxy(25,4);
  585. printf("Nombre : %s ",cliente.nombre);
  586. gotoxy(25,5);
  587. printf("Apellido : %s ",cliente.apellido);
  588. gotoxy(25,6);
  589. printf("Direccion : %s ",cliente.direccion);
  590. gotoxy(25,7);
  591. printf("Telefono : %s ",cliente.telefono);
  592. gotoxy(25,8);
  593. printf("Alquileres : %d ",cliente.alquileresrealizados);
  594. gotoxy(25,9);
  595. printf("Estado : %c ",cliente.estado);
  596. getch();
  597.  
  598. /////////////////////////////////////////////
  599. // Pido los nuevos datos para el cliente
  600. /////////////////////////////////////////////
  601. do
  602. {
  603. gotoxy(25,10);
  604. printf("====================");
  605. do
  606. {
  607. gotoxy(25,11);
  608. printf("NOMBRE: ");
  609. fflush(stdin);
  610. gets(cliente_NuevosDatos.nombre);
  611. }
  612. while(strlen(cliente_NuevosDatos.nombre)==0);
  613.  
  614. do
  615. {
  616. gotoxy(25,12);
  617. printf("APELLIDO: ");
  618. fflush(stdin);
  619. gets(cliente_NuevosDatos.apellido);
  620. }
  621. while(strlen(cliente_NuevosDatos.apellido)==0);
  622. //VALIDA QUE EL NOMBRE NO SE REPITA
  623. aux = ObtenerCliente(cliente_NuevosDatos,2);
  624. if(aux.codigo!=-1)
  625. {
  626. gotoxy(25,20);
  627. printf("YA HAY UN CLIENTE CON ESE NOMBRE");
  628. gotoxy(25,21);
  629. printf("DESEA CONTINUAR? (S/N)");
  630. continua = getch();
  631. continua = toupper(continua);
  632. if (continua!='S')return;
  633. }
  634. //FIN DE VALIDACION
  635. cliente_NuevosDatos.codigo = cliente.codigo;
  636. gotoxy(25,13);
  637. printf("CODIGO: %d", cliente.codigo);
  638. gotoxy(25,14);
  639. printf("DIRECCION: ");
  640. fflush(stdin);
  641. gets(cliente_NuevosDatos.direccion);
  642. gotoxy(25,15);
  643. printf("TELEFONO: ");
  644. fflush(stdin);
  645. gets(cliente_NuevosDatos.telefono);
  646. // Inicializa Estado y Alquileres Realizados
  647. gotoxy(25,16);
  648. printf("ESTADO (A/D):");
  649. scanf("%c",&cliente_NuevosDatos.estado);
  650. cliente_NuevosDatos.estado=toupper(cliente_NuevosDatos.estado);
  651. cliente_NuevosDatos.alquileresrealizados=cliente.alquileresrealizados;
  652. do
  653. {
  654. gotoxy(25,20);
  655. printf("1-CONFIRMA ");
  656. gotoxy(25,21);
  657. printf("2-REINGRESA");
  658. gotoxy(25,22);
  659. printf("3-CANCELA ");
  660. conf=getch();
  661. if(conf<49 || conf>51) gotoxy(9,10);
  662. }
  663. while(conf<49 || conf>51);
  664.  
  665.  
  666. if (conf==49)
  667. { // Si de decidio grabar y nadie se llama igual...
  668. fseek(p1,posicion,SEEK_SET);
  669. if (fwrite(&cliente_NuevosDatos,sizeof(Cliente),1,p1)!=1)
  670. {
  671. gotoxy(25,24);
  672. printf("ERROR DE ESCRITURA");
  673. getch();
  674. return;
  675. }
  676. else
  677. {
  678. gotoxy(25,24);
  679. printf("EL CLIENTE SE ACTUALIZO");
  680. }
  681. }
  682. do
  683. {
  684. if(conf==51)
  685. {
  686. conf=50;//sino si cancela y sigue ingresando apareceria de vuelta
  687. gotoxy(25,24);
  688. printf("INGRESO CANCELADO");
  689. }
  690. gotoxy(25,25);
  691. printf("INGRESAR OTRO (S/N)? ");
  692. otro='s';//por las dudas
  693. otro=getch();
  694. otro=toupper(otro);
  695. }
  696. while(otro!='S' && otro!='N');
  697. }
  698. while(otro=='S');
  699. fclose(p1);
  700. }
  701. // Agregar Cliente - INICIO
  702. void AgregarCliente(void)
  703. {
  704. FILE *ARCHIVO;
  705. int valida;
  706. int siguienteCodigo;
  707. char siguienteCodigoStr[30];
  708. char otro,conf;
  709. Cliente name,*pname,aux,*paux;
  710. Config config;
  711.  
  712. paux=&aux;
  713. pname=&name;
  714.  
  715. if((ARCHIVO = fopen(FILE_CLIENTES,"a+b")) == NULL)
  716. {
  717. gotoxy(25,13);
  718. printf("ERROR AL ABRIR ARCHIVO");
  719. getch();
  720. return;
  721. }
  722. do
  723. {
  724. do
  725. {
  726. clrscr();
  727. gotoxy(25,4);
  728. printf("Ingreso de Clientes");
  729. gotoxy(25,5);
  730. printf("====================");
  731. do
  732. {
  733. gotoxy(25,6);
  734. printf("NOMBRE: ");
  735. fflush(stdin);
  736. gets(pname->nombre);
  737. }
  738. while(strlen(pname->nombre)==0);
  739. do
  740. {
  741. gotoxy(25,7);
  742. printf("APELLIDO: ");
  743. fflush(stdin);
  744. gets(pname->apellido);
  745. }
  746. while(strlen(pname->apellido)==0);
  747. //VALIDA QUE EL NOMBRE NO SE REPITA
  748. valida=1;
  749. rewind(ARCHIVO);
  750. while(!feof(ARCHIVO))
  751. {
  752. if(!feof(ARCHIVO))
  753. {
  754. flushall();
  755. if(fread(&aux,sizeof(Cliente),1,ARCHIVO)!=1 && (!feof(ARCHIVO)))exit(1);
  756. if(strcmpi(paux->nombre,pname->nombre)==0 && strcmpi(paux->apellido,pname->apellido)==0)
  757. {
  758. valida=0;
  759. break;
  760. }
  761. }
  762. }
  763. if(valida==0)
  764. {
  765. gotoxy(25,17);
  766. printf("YA HAY UN CLIENTE CON ESE NOMBRE");
  767. break;
  768. }
  769. //FIN DE VALIDACION
  770. gotoxy(25,8);
  771. printf("CODIGO: ");
  772.  
  773. config = LeerPropiedad("codclien");
  774. gotoxy(35,8);
  775. printf(config.valor);
  776.  
  777. siguienteCodigo = atoi(config.valor);
  778.  
  779. pname->codigo = siguienteCodigo;
  780. gotoxy(25,9);
  781. printf("DIRECCION: ");
  782. fflush(stdin);
  783. gets(pname->direccion);
  784. gotoxy(25,10);
  785. printf("TELEFONO: ");
  786. fflush(stdin);
  787. gets(pname->telefono);
  788. // Inicializa Estado y Alquileres Realizados
  789. pname->estado='A';
  790. pname->alquileresrealizados=0;
  791. do
  792. {
  793. gotoxy(25,11);
  794. printf("1-CONFIRMA ");
  795. gotoxy(25,12);
  796. printf("2-REINGRESA");
  797. gotoxy(25,13);
  798. printf("3-CANCELA ");
  799. conf=getch();
  800. if(conf<49 || conf>51) gotoxy(9,10);
  801. }
  802. while(conf<49 || conf>51);
  803. }
  804. while(conf==50);
  805.  
  806. if (conf==49 && valida==1)
  807. { // Si de decidio grabar y nadie se llama igual...
  808. if (fwrite(&name,sizeof(Cliente),1,ARCHIVO)!=1)
  809. {
  810. gotoxy(25,16);
  811. printf("ERROR DE ESCRITURA");
  812. }
  813. else
  814. {
  815. gotoxy(25,17);
  816. printf("EL DATO SE ALMACENO");
  817. // Actualizamos el codigo de cliente en el archivo de Configuracion
  818. siguienteCodigo++;
  819. EscribirPropiedad("codclien",itoa(siguienteCodigo,siguienteCodigoStr, 10));
  820.  
  821. }
  822. }
  823. do
  824. {
  825. if(conf==51)
  826. {
  827. conf=50;//sino si cancela y sigue ingresando apareceria de vuelta
  828. gotoxy(25,17);
  829. printf("INGRESO CANCELADO");
  830. }
  831. gotoxy(25,18);
  832. printf("INGRESAR OTRO (S/N)? ");
  833. otro='s';//por las dudas
  834. otro=getch();
  835. otro=toupper(otro);
  836. }
  837. while(otro!='S' && otro!='N');
  838. }
  839. while(otro=='S');
  840. fclose(ARCHIVO);
  841. }
  842. // Agregar Cliente - FIN
  843. int Menu_Busqueda_NomApeCodigo(void)
  844. {
  845. int op;
  846. do
  847. {
  848. clrscr();
  849. gotoxy(38,5);
  850. printf("MENU TIPO DE BUSQUEDA");
  851. gotoxy(24,8);
  852. printf("1- Buscar por Apellido y Apellido");
  853. gotoxy(24,9);
  854. printf("2- Buscar por Codigo");
  855. gotoxy(24,10);
  856. printf("3- Salir");
  857. gotoxy(24,12);
  858. printf("Ingrese una opcion: ");
  859. scanf("%d",&op);
  860. }while(op<1||op>3);
  861. return op;
  862. }
  863.  
  864. void ConsultarCliente(void)
  865. {
  866. int op,codigo;
  867. Cliente buscadoCliente;
  868.  
  869. op=Menu_Busqueda_NomApeCodigo();
  870. clrscr();
  871. switch(op)
  872. {
  873. case 1:
  874. gotoxy(24,8);
  875. printf("Ingrese el Nombre y Apellido de Cliente a Buscar");
  876. gotoxy(24,9);
  877. printf("Apellido: ");
  878. fflush(stdin);
  879. gets(buscadoCliente.apellido);
  880. gotoxy(24,10);
  881. printf("Nombre: ");
  882. fflush(stdin);
  883. gets(buscadoCliente.nombre);
  884. buscadoCliente= ObtenerCliente(buscadoCliente,2);
  885. break;
  886. case 2:
  887. gotoxy(24,8);
  888. printf("Ingrese el Codigo del Cliente a Buscar: ");
  889. scanf("%d",&codigo);
  890. buscadoCliente.codigo = codigo;
  891. buscadoCliente=ObtenerCliente(buscadoCliente,1);
  892. break;
  893. case 3:
  894. return;
  895. }
  896.  
  897. if(buscadoCliente.codigo != -1)
  898. {
  899. clrscr();
  900. gotoxy(24,8);
  901. printf("DATOS DEL REGISTRO ENCONTRADO");
  902. gotoxy(24,9);
  903. printf("Codigo : %d ",buscadoCliente.codigo);
  904. gotoxy(24,10);
  905. printf("Nombre : %s ",buscadoCliente.nombre);
  906. gotoxy(24,11);
  907. printf("Apellido : %s ",buscadoCliente.apellido);
  908. gotoxy(24,12);
  909. printf("Direccion : %s ",buscadoCliente.direccion);
  910. gotoxy(24,13);
  911. printf("Telefono : %s ",buscadoCliente.telefono);
  912. gotoxy(24,14);
  913. printf("Alquileres : %d ",buscadoCliente.alquileresrealizados);
  914. gotoxy(24,15);
  915. printf("Estado : %c ",buscadoCliente.estado);
  916. getch();
  917. }
  918. else
  919. {
  920. gotoxy(24,18);
  921. printf("CLIENTE NO ENCONTRADO");
  922. getch();
  923. }
  924. }
  925.  
  926. long ObtenerPosicionCliente(int codigo)
  927. {
  928. Cliente reg;
  929. FILE *p1;
  930. int ss;
  931. long ret;
  932.  
  933. p1=fopen(FILE_CLIENTES,"rb");
  934. if(p1==NULL)
  935. {
  936. clrscr();
  937. gotoxy(22,10);
  938. printf("ERROR EN APERTURA DE ARCHIVO");
  939. getch();
  940. exit(1);
  941. }
  942.  
  943. rewind(p1);
  944. while(!feof(p1))
  945. {
  946. flushall();
  947. ret = ftell(p1);
  948. if(fread(&reg,sizeof(Cliente),1,p1)!=1 && (!feof(p1)))exit(1);
  949.  
  950. ss=0;
  951. if(codigo == reg.codigo)
  952. {
  953. ss=1;
  954. break;
  955. }
  956. }
  957. fclose(p1);
  958. if(ss==0)
  959. {
  960. // Cliente No Encontrado
  961. ret = -1;
  962. }
  963. return ret;
  964. }
  965.  
  966. Cliente ObtenerCliente(Cliente cliente, int formaBusqueda)
  967. {
  968. Cliente reg;
  969. FILE *p1;
  970. int ss;
  971.  
  972. p1=fopen(FILE_CLIENTES,"rb");
  973. if(p1==NULL)
  974. {
  975. clrscr();
  976. gotoxy(22,10);
  977. printf("ERROR EN APERTURA DE ARCHIVO");
  978. getch();
  979. exit(1);
  980. }
  981.  
  982. rewind(p1);
  983. while(!feof(p1))
  984. {
  985. flushall();
  986. if(fread(&reg,sizeof(Cliente),1,p1)!=1 && (!feof(p1)))exit(1);
  987.  
  988. ss=0;
  989. switch(formaBusqueda)
  990. {
  991. case 1:
  992. if(cliente.codigo == reg.codigo)
  993. ss=1;
  994. break;
  995.  
  996. case 2:
  997. if((strcmp(strlwr(cliente.apellido),strlwr(reg.apellido))==0)
  998. &&
  999. (strcmp(strlwr(cliente.nombre),strlwr(reg.nombre))==0))
  1000. ss=1;
  1001. break;
  1002. }
  1003. if (ss==1) break;
  1004. }
  1005. fclose(p1);
  1006. if(ss==0)
  1007. {
  1008. // Cliente No Encontrado
  1009. reg.codigo = -1;
  1010. }
  1011. return reg;
  1012. }
  1013.  
  1014. void Listar_EncaClientes(void)
  1015. {
  1016. clrscr();
  1017. gotoxy(25,3);
  1018. printf("LISTADO DE CONTACTOS");
  1019. gotoxy(5,5);
  1020. printf("COD EST CLIENTE DIRECCION TELEFONO ");
  1021. gotoxy(5,6);
  1022. printf("=======================================================================");
  1023. }
  1024.  
  1025. Config LeerPropiedad(char* propiedad)
  1026. {
  1027. Config reg;
  1028. FILE *p1;
  1029. int s = 0;
  1030.  
  1031. p1=fopen(FILE_CONFIG,"rb");
  1032. if(p1==NULL)
  1033. {
  1034. clrscr();
  1035. gotoxy(22,10);
  1036. printf("ERROR EN APERTURA DE ARCHIVO");
  1037. getch();
  1038. exit(1);
  1039. }
  1040.  
  1041. rewind(p1);
  1042. while(!feof(p1))
  1043. {
  1044. if(!feof(p1))
  1045. {
  1046. flushall();
  1047. if(fread(&reg,sizeof(Config),1,p1)!=1 && (!feof(p1)))exit(1);
  1048.  
  1049. if (strcmp(strlwr(propiedad),strlwr(reg.propiedad))==0)
  1050. {
  1051. s = 1;
  1052. break;
  1053. }
  1054. }
  1055. }
  1056. fclose(p1);
  1057. if(s==0)
  1058. {
  1059. strcpy(reg.valor,"");
  1060. strcpy(reg.propiedad,"");
  1061. }
  1062. return reg;
  1063. }
  1064.  
  1065. void EscribirPropiedad(char* propiedad, char* valor)
  1066. {
  1067. FILE *p1;
  1068. int existe,cant;
  1069. long posicion;
  1070. Config aux,*paux;
  1071.  
  1072. paux=&aux;
  1073.  
  1074. // Si el archivo no existe, lo crea
  1075. if (ExisteArchivo(FILE_CONFIG)==0)
  1076. {
  1077. if((p1 = fopen(FILE_CONFIG,"w+b")) == NULL)
  1078. {
  1079. gotoxy(25,13);
  1080. printf("ERROR AL GENERAR ARCHIVO DE CONFIGURACION");
  1081. getch();
  1082. return;
  1083. }
  1084. else
  1085. {
  1086. fclose(p1);
  1087. }
  1088. }
  1089.  
  1090. // Lo abro en modo lectura primero para buscar si la propiedad existe.
  1091. if((p1 = fopen(FILE_CONFIG,"r+b")) == NULL)
  1092. {
  1093. gotoxy(25,13);
  1094. printf("ERROR AL ABRIR ARCHIVO");
  1095. getch();
  1096. return;
  1097. }
  1098.  
  1099. for( ; ; )
  1100. {
  1101. posicion = ftell(p1);
  1102. cant = fread(&aux,sizeof(Config),1,p1);
  1103.  
  1104. if(cant!=1)
  1105. {
  1106. if(feof(p1)!=0)
  1107. {
  1108. existe = 0;
  1109. break;
  1110. }
  1111. else
  1112. {
  1113. clreol();
  1114. printf("\aERROR AL LEER ARCHIVO!!!!");
  1115. getch();
  1116. return;
  1117. }
  1118. }
  1119. else
  1120. {
  1121. if(strcmpi(paux->propiedad,propiedad)==0)
  1122. {
  1123. existe = 1;
  1124. break;
  1125. }
  1126. }
  1127. }
  1128.  
  1129. strcpy(paux->propiedad,propiedad);
  1130. strcpy(paux->valor,valor);
  1131.  
  1132. // Se posiciona el puntero o abre el archivo en modo Append segun corresponda
  1133. if (existe == 1)
  1134. {
  1135. fseek(p1,posicion,SEEK_SET);
  1136. }
  1137. else
  1138. {
  1139. fclose(p1);
  1140. if((p1 = fopen(FILE_CONFIG,"a+b")) == NULL)
  1141. {
  1142. gotoxy(25,13);
  1143. printf("ERROR AL ABRIR ARCHIVO");
  1144. getch();
  1145. return;
  1146. }
  1147. }
  1148. // Escribimos el dato
  1149. if (fwrite(&aux,sizeof(Config),1,p1)!=1)
  1150. {
  1151. gotoxy(25,16);
  1152. printf("ERROR DE ESCRITURA");
  1153. getch();
  1154. return;
  1155. }
  1156. fclose(p1);
  1157. }
  1158.  
  1159.  
  1160. int ExisteArchivo(char* FileName)
  1161. {
  1162. FILE *EXISTEARCHIVO;
  1163. if ((EXISTEARCHIVO=fopen(FileName,"rb"))==NULL)
  1164. {
  1165. return 0;
  1166. }
  1167. else
  1168. {
  1169. fclose(EXISTEARCHIVO);
  1170. return 1;
  1171. }
  1172. }
  1173.  
  1174.  
  1175. void AgregarPelicula(void)
  1176. {
  1177. long cantreg;
  1178. char titulo[30];
  1179. int cantidad;
  1180. int codigo=0;
  1181. char codigoStr[30];
  1182. char descripcion[100];
  1183. Config config;
  1184. FILE *p1,*p2;
  1185. //Creo las estructuras auxiliares
  1186. Pelicula reg;
  1187. Indice reg1;
  1188. p1=fopen(FILE_PELICULAS,"a+b");
  1189. p2=fopen(FILE_PELICULAS_INDICE,"a+b");
  1190. //los archivos donde se van a alnmacenar?
  1191. //Obtengo la cantidad de registros de "Datos"
  1192. fseek(p1,0l,SEEK_END);
  1193. cantreg=ftell(p1)/sizeof(reg);
  1194. clrscr();
  1195.  
  1196. //CARGA DE DATOS
  1197. //Hay que crear una función para obtener el código automáticamente
  1198. //codigo_pelicula(codigo);
  1199. printf("\n\n- CARGA DE DATOS DE PELICULAS -");
  1200.  
  1201. config = LeerPropiedad("codpeli");
  1202. printf("Codigo: ");
  1203. printf("%s",config.valor);
  1204. codigo = atoi(config.valor);
  1205. reg.codigo=codigo;
  1206.  
  1207. printf("\nTitulo: ");
  1208. fflush(stdin);
  1209. gets(titulo);
  1210. strcpy(reg.titulo,titulo);
  1211. printf("Cantidad de copias: ");
  1212. scanf("%d",&cantidad);
  1213. reg.copias=cantidad;
  1214. printf("Descripcion: ");
  1215. fflush(stdin);
  1216. gets(descripcion);
  1217. strcpy(reg.descripcion,descripcion);
  1218. printf("Automáticamente se asignará estado ACTIVO a la nueva pelicula"); //AGREGAR
  1219. reg.estado='A'; //AGREGAR
  1220. reg.vecesalquilada=0;
  1221. reg.alquiladas=0;
  1222.  
  1223.  
  1224. // Informacion para archivo "Indice"
  1225. reg1.codigo=reg.codigo;
  1226. reg1.posicion=cantreg;
  1227.  
  1228. //Grabamos archivo "Registro" e "Indice"
  1229. if (fwrite(&reg,sizeof(reg),1,p1) != 1 || fwrite(&reg1,sizeof(reg1),1,p2)!=1)
  1230. {
  1231. printf("ERROR DE ESCRITURA");
  1232. getch();
  1233. }
  1234. else
  1235. {
  1236. // Grabo bien y actualizamos el Codigo de Pelicula
  1237. codigo++;
  1238. EscribirPropiedad("codpeli",itoa(codigo,codigoStr, 10));
  1239.  
  1240. }
  1241. fclose(p1);
  1242. fclose(p2);
  1243. }
  1244.  
  1245. void ListarPeliculas(void)//Funcion beta de listar peliculas
  1246. {
  1247. FILE *p1,*p2;
  1248. Pelicula reg;
  1249. Indice reg1;
  1250. p1=fopen(FILE_PELICULAS,"rb");
  1251. p2=fopen(FILE_PELICULAS_INDICE,"rb");
  1252. clrscr();
  1253. printf("Contenido:\n");
  1254. fread(&reg,sizeof(reg),1,p1);
  1255. while(!feof(p1))
  1256. {
  1257. printf("%-10d %-30s %d %s\n",reg.codigo,reg.titulo,reg.copias,reg.descripcion);
  1258. fread(&reg,sizeof(reg),1,p1);
  1259. }
  1260. printf("\nContenido de indice\n");
  1261. fread(&reg1,sizeof(reg1),1,p2);
  1262. while(!feof(p2))
  1263. {
  1264. printf("%-10d %10d\n",reg1.codigo,reg1.posicion);
  1265. fread(&reg1,sizeof(reg1),1,p2);
  1266. }
  1267. getch();
  1268. fclose(p2);
  1269. fclose(p1);
  1270. }
  1271. //////////////////////////////////////////////////////////////
  1272.  
  1273. void EliminarCliente(void)
  1274. {
  1275. int codigo;
  1276. char otro,conf;
  1277. Cliente cliente;
  1278. long posicion;
  1279. FILE *p1;
  1280.  
  1281. do
  1282. {
  1283. clrscr();
  1284. gotoxy(24,1);
  1285. printf("Ingrese el Codigo del Cliente a Eliminar: ");
  1286. scanf("%d",&codigo);
  1287. posicion=ObtenerPosicionCliente(codigo);
  1288.  
  1289. clrscr();
  1290. if(posicion == -1)
  1291. {
  1292. gotoxy(25,20);
  1293. printf("CLIENTE NO ENCONTRADO");
  1294. getch();
  1295. return;
  1296. }
  1297.  
  1298. // Cargamos el cliente para mostrarlo antes de pedir los nuevos datos
  1299. if((p1 = fopen(FILE_CLIENTES,"r+b")) == NULL)
  1300. {
  1301. gotoxy(25,13);
  1302. printf("ERROR AL GENERAR ARCHIVO DE CLIENTE %s",FILE_CLIENTES);
  1303. getch();
  1304. return;
  1305. }
  1306.  
  1307. fseek(p1,posicion,SEEK_SET);
  1308. if (fread(&cliente,sizeof(Cliente),1,p1) != 1)
  1309. {
  1310. clreol();
  1311. printf("\aERROR AL LEER ARCHIVO!!!!");
  1312. getch();
  1313. return;
  1314. }
  1315.  
  1316. clrscr();
  1317. gotoxy(25,2);
  1318. printf("DATOS DEL REGISTRO ENCONTRADO");
  1319. gotoxy(25,3);
  1320. printf("Codigo : %d ",cliente.codigo);
  1321. gotoxy(25,4);
  1322. printf("Nombre : %s ",cliente.nombre);
  1323. gotoxy(25,5);
  1324. printf("Apellido : %s ",cliente.apellido);
  1325. gotoxy(25,6);
  1326. printf("Direccion : %s ",cliente.direccion);
  1327. gotoxy(25,7);
  1328. printf("Telefono : %s ",cliente.telefono);
  1329. gotoxy(25,8);
  1330. printf("Alquileres : %d ",cliente.alquileresrealizados);
  1331. gotoxy(25,9);
  1332. printf("Estado : %c ",cliente.estado);
  1333. getch();
  1334.  
  1335. //////////////////////////////////////////////////////////
  1336. // En Base al Estado se fija si es baja fisica o logica //
  1337. //////////////////////////////////////////////////////////
  1338. if(cliente.estado=='A')
  1339. {
  1340. gotoxy(25,10);
  1341. printf("BAJA LOGICA");
  1342. cliente.estado='D';
  1343. do
  1344. {
  1345. gotoxy(25,20);
  1346. printf("1-CONFIRMA ");
  1347. gotoxy(25,21);
  1348. printf("2-CANCELA ");
  1349. conf=getch();
  1350. if(conf<49 || conf>50) gotoxy(9,10);
  1351. }
  1352. while(conf<49 || conf>50);
  1353.  
  1354. if (conf==49)
  1355. { // Si de decidio grabar y nadie se llama igual...
  1356. fseek(p1,posicion,SEEK_SET);
  1357. if (fwrite(&cliente,sizeof(Cliente),1,p1)!=1)
  1358. {
  1359. gotoxy(25,22);
  1360. printf("ERROR DE ESCRITURA");
  1361. getch();
  1362. return;
  1363. }
  1364. else
  1365. {
  1366. gotoxy(25,22);
  1367. printf("EL CLIENTE SE DESACTIVO");
  1368. }
  1369. }
  1370. do
  1371. {
  1372. if(conf==50)
  1373. {
  1374. gotoxy(25,22);
  1375. printf("INGRESO CANCELADO");
  1376. }
  1377. gotoxy(25,23);
  1378. printf("INGRESAR OTRO (S/N)? ");
  1379. otro='s';//por las dudas
  1380. otro=getch();
  1381. otro=toupper(otro);
  1382. }
  1383. while(otro!='S' && otro!='N');
  1384. }
  1385. else
  1386. {
  1387. gotoxy(25,10);
  1388. printf("BAJA FISICA");
  1389. fcloseall();
  1390. EliminarFisicaCliente(cliente.codigo);
  1391. getch();
  1392. }
  1393. }
  1394. while (otro=='S');
  1395. fclose(p1);
  1396.  
  1397. }
  1398.  
  1399. void EliminarFisicaCliente(int codClien)
  1400. {
  1401. FILE *ARCHIVO,*COPIA;
  1402. Cliente dato,*pdato;
  1403. long cant;
  1404. char cop[]={"CLIENTES.TMP"};
  1405.  
  1406. pdato=&dato;
  1407.  
  1408. fcloseall();
  1409.  
  1410. if((ARCHIVO=fopen(FILE_CLIENTES,"rb"))==NULL)
  1411. {
  1412. gotoxy(25,14);
  1413. printf("ERROR EN APERTURA ARCHIVO");
  1414. printf("EL DATO NO SE PUEDE ELIMINAR");
  1415. getch();
  1416. return;
  1417. }
  1418. if((COPIA=fopen(cop,"wb"))==NULL)
  1419. {
  1420. gotoxy(25,14);
  1421. printf("ERROR EN APERTURA ARCHIVO");
  1422. gotoxy(25,15);
  1423. printf("EL DATO NO SE PUEDE ELIMINAR");
  1424. getch();
  1425. return;
  1426. }
  1427.  
  1428. //COMIENZA LA TRANSFERENCIA
  1429. rewind(ARCHIVO);
  1430. rewind(COPIA);
  1431. for( ; ; )
  1432. {
  1433. cant = fread(&dato,sizeof(Cliente),1,ARCHIVO);
  1434.  
  1435. if(cant!=1)
  1436. {
  1437. if(feof(ARCHIVO)!=0)
  1438. {
  1439. break;
  1440. }
  1441. else
  1442. {
  1443. clreol();
  1444. printf("\aERROR AL LEER ARCHIVO!!!!");
  1445. getch();
  1446. return;
  1447. }
  1448. }
  1449. else
  1450. {
  1451. if(codClien != pdato->codigo)//VERIFICO QUE NO SEA EL QUE QUIERO ELIMINAR
  1452. {
  1453. if(fwrite(&dato,sizeof(Cliente),1,COPIA)!=1)
  1454. {
  1455. gotoxy(25,14);
  1456. printf("ERROR AL ESCRIBIR");
  1457. getch();
  1458. return;
  1459. };
  1460. }
  1461. }
  1462. }
  1463. //FIN DE LA COPIA
  1464. fcloseall();
  1465. if(remove(FILE_CLIENTES)!=0)
  1466. {
  1467. gotoxy(25,13);
  1468. printf("EL ARCHIVO ORIGINAL NO SE PUEDE ELIMINAR");
  1469. getch();
  1470. return;
  1471. }
  1472. else
  1473. {
  1474. if(rename(cop,FILE_CLIENTES)!=0)
  1475. {
  1476. gotoxy(25,13);
  1477. printf("EL ARCHIVO COP NO SE PUDO RENOMBRAR");
  1478. getch();
  1479. return;
  1480. }
  1481. else
  1482. {
  1483. gotoxy(25,15);
  1484. printf("BAJA REALIZADA");
  1485. }
  1486. }
  1487. fcloseall();
  1488. }
  1489.  
  1490.  
  1491. ////////////////////////////////////////////////////////////////////////////////
  1492. // REGISTRACION DE ALQUILER //
  1493. ////////////////////////////////////////////////////////////////////////////////
  1494.  
  1495. void RegistrarAlquiler(void)
  1496. {
  1497. int cliente, pelicula;
  1498. int flagCliente=0,posPelicula=1, posCliente=1;//flagCliente y c son bandera!
  1499. Cliente regCliente;
  1500. Pelicula regPelicula;
  1501. Alquiler regAlquiler;
  1502. FILE *fileAlquiler, *fileCliente, *filePelicula;
  1503.  
  1504. fileAlquiler=fopen(FILE_ALQUILER,"a+b");
  1505. if(fileAlquiler==NULL)
  1506. {
  1507. clrscr();
  1508. gotoxy(22,10);
  1509. printf("ERROR EN APERTURA DE ARCHIVO");
  1510. getch();
  1511. exit(1);
  1512. }
  1513. fileCliente=fopen(FILE_CLIENTES,"r+b");
  1514. if(fileCliente==NULL)
  1515. {
  1516. clrscr();
  1517. gotoxy(22,10);
  1518. printf("ERROR EN APERTURA DE ARCHIVO");
  1519. getch();
  1520. exit(1);
  1521. }
  1522. filePelicula=fopen(FILE_PELICULAS,"r+b");
  1523. if(filePelicula==NULL)
  1524. {
  1525. clrscr();
  1526. gotoxy(22,10);
  1527. printf("ERROR EN APERTURA DE ARCHIVO");
  1528. getch();
  1529. exit(1);
  1530. }
  1531. clrscr();
  1532. gotoxy(1,3);
  1533. printf("Codigo Pelicula:");
  1534. gotoxy(1,4);
  1535. printf("Codigo Cliente:");
  1536. gotoxy(18,3);
  1537. scanf("%d",&pelicula);
  1538. gotoxy(17,4);
  1539. scanf("%d",&cliente);
  1540.  
  1541. //VERIFICA VALIDEZ DE CLIENTE!!
  1542. fread(&regCliente,sizeof(regCliente),1,fileCliente);
  1543. while(!feof(fileCliente))
  1544. {
  1545. if(regCliente.codigo==cliente) {flagCliente=1;break;}
  1546. posCliente++;
  1547. fread(&regCliente,sizeof(regCliente),1,fileCliente);
  1548. }
  1549.  
  1550. if(flagCliente==1)
  1551. {
  1552. fread(&regPelicula,sizeof(regPelicula),1,filePelicula);
  1553. while(!feof(filePelicula))
  1554. {
  1555. if(regPelicula.codigo==pelicula)
  1556. {
  1557. if((regPelicula.copias)>(regPelicula.alquiladas))
  1558. {
  1559. regPelicula.alquiladas++;
  1560. regPelicula.vecesalquilada++;
  1561. regCliente.alquileresrealizados++;
  1562. flagCliente=2;
  1563. break;
  1564. }
  1565. else {
  1566. printf("\nNo hay stock disponible para alquiler..");
  1567. getch();
  1568. break;
  1569. }
  1570. }
  1571. fread(&regPelicula,sizeof(regPelicula),1,filePelicula);
  1572. posPelicula++;
  1573. }
  1574. }
  1575. else {printf("El codigo de cliente ingresado es inexistente");
  1576. getch();
  1577. }
  1578. if (flagCliente==2)
  1579. {
  1580. // Actualizamos stock de peliculas alquiladas
  1581. fseek(filePelicula,(posPelicula-1)*sizeof(regPelicula),SEEK_SET);
  1582. // Escribimos el dato
  1583. if (fwrite(&regPelicula,sizeof(regPelicula),1,filePelicula)!=1)
  1584. {
  1585. gotoxy(25,16);
  1586. printf("ERROR DE ESCRITURA");
  1587. getch();
  1588. return;
  1589. }
  1590. // Actualizamos stock de peliculas alquiladas
  1591. fseek(fileCliente,(posCliente-1)*sizeof(regCliente),SEEK_SET);
  1592. // Escribimos el dato
  1593. if (fwrite(&regCliente,sizeof(regCliente),1,fileCliente)!=1)
  1594. {
  1595. gotoxy(25,16);
  1596. printf("ERROR DE ESCRITURA");
  1597. getch();
  1598. return;
  1599. }
  1600. regAlquiler.codpel=pelicula;
  1601. regAlquiler.codcli=cliente;
  1602. getdate(&regAlquiler.fecha);
  1603. regAlquiler.estado='A';
  1604. fwrite(&regAlquiler,sizeof(regAlquiler),1,fileAlquiler);
  1605. printf("\n\nAlquiler registrado..");
  1606. getch();
  1607. }
  1608. fclose(fileAlquiler);
  1609. fclose(fileCliente);
  1610. fclose(filePelicula);
  1611. }
  1612.  
  1613.  
  1614. ////////////////////////////////////////////////////////////////////////////
  1615. void ListarAlquileres(void)//Funcion beta de listar peliculas
  1616. {
  1617. FILE *p1;
  1618. dia f;
  1619. Alquiler reg;
  1620. p1=fopen(FILE_ALQUILER,"rb");
  1621. clrscr();
  1622. printf("Peliculas Actualmente Alquiladas:\n");
  1623. printf("Cliente Pelicula Fecha\n");
  1624. fread(&reg,sizeof(reg),1,p1);
  1625. while(!feof(p1))
  1626. {
  1627. f=reg.fecha;
  1628. printf(" %d %d %d/%d/%d\n",reg.codcli,reg.codpel,f.da_day,f.da_mon,f.da_year);
  1629. fread(&reg,sizeof(reg),1,p1);
  1630. }
  1631. getch();
  1632. }
  1633.  
  1634. void PeliculasAlquiladas(void)//Funcion reporte peliculas alquiladas
  1635. {
  1636. FILE *p1;
  1637. Alquiler reg;
  1638. p1=fopen(FILE_ALQUILER,"rb");
  1639. clrscr();
  1640. printf("Peliculas Actualmente Alquiladas:\n");
  1641. printf("Cliente Pelicula Fecha\n");
  1642. fread(&reg,sizeof(reg),1,p1);
  1643. while(!feof(p1))
  1644. {
  1645. if(reg.estado=='A')
  1646. {
  1647. printf(" %d %d %d/%d/%d\n",reg.codcli,reg.codpel,reg.fecha.da_day,reg.fecha.da_mon,reg.fecha.da_year);
  1648. }
  1649. fread(&reg,sizeof(reg),1,p1);
  1650. }
  1651. getch();
  1652. }
  1653.  
  1654. void EliminarPelicula(void)
  1655. {
  1656. /*
  1657. Para recordar la estructura de la struct pelicula
  1658. typedef struct {
  1659. int codigo;
  1660. char titulo[30];
  1661. int copias;
  1662. int alquiladas;
  1663. char descripcion[100];
  1664. int vecesalquilada;
  1665. int estado; /////// <----- AGREGAR !! MUY IMPORTANTE !!
  1666. } Pelicula;
  1667. */
  1668. int codigo;
  1669. char otro,conf;
  1670. Pelicula peli_aux;
  1671. long posicion;
  1672. FILE *p1;
  1673.  
  1674. do
  1675. {
  1676. clrscr();
  1677. gotoxy(24,1);
  1678. printf("Ingrese el Codigo de la Pelicula a Eliminar: ");
  1679. scanf("%d",&codigo);
  1680. posicion=ObtenerPosicionPelicula(codigo); // Modificar el codigo de esta funcion para que sirva a peliculas
  1681.  
  1682. clrscr();
  1683. if(posicion == -1)
  1684. {
  1685. gotoxy(25,20);
  1686. printf("PELICULA NO ENCONTRADA");
  1687. getch();
  1688. return;
  1689. }
  1690.  
  1691. // Carga previa de la pelicula antes de pedir los nuevos datos
  1692. if((p1 = fopen(FILE_PELICULAS,"r+b")) == NULL)
  1693. {
  1694. gotoxy(25,13);
  1695. printf("ERROR AL GENERAR ARCHIVO DE PELICULAS %s",FILE_CLIENTES);
  1696. getch();
  1697. return;
  1698. }
  1699.  
  1700. fseek(p1,posicion,SEEK_SET); //Cambiar nombre de funcion y modificar codigo
  1701.  
  1702. if (fread(&peli_aux,sizeof(Pelicula),1,p1) != 1)
  1703. {
  1704. clreol();
  1705. printf("\aERROR AL LEER ARCHIVO!!!!");
  1706. getch();
  1707. return;
  1708. }
  1709.  
  1710. clrscr();
  1711. gotoxy(25,2);
  1712. printf("DATOS DEL REGISTRO ENCONTRADO");
  1713. gotoxy(25,3);
  1714. printf("Codigo : %d ",peli_aux.codigo);
  1715. gotoxy(25,4);
  1716. printf("Titulo : %s ",peli_aux.titulo);
  1717. gotoxy(25,5);
  1718. printf("Cantidad de copias : %d ",peli_aux.copias);
  1719. gotoxy(25,6);
  1720. printf("Copias alquiladas : %d ",peli_aux.alquiladas);
  1721. gotoxy(25,7);
  1722. printf("Descripcion : %s ",peli_aux.descripcion);
  1723. gotoxy(25,8);
  1724. printf("Veces alquilada : %d ",peli_aux.vecesalquilada);
  1725. gotoxy(25,9);
  1726. printf("Estado : %c ",peli_aux.estado);
  1727. getch();
  1728.  
  1729. //////////////////////////////////////////////////////////
  1730. // En Base al Estado se fija si es baja fisica o logica //
  1731. //////////////////////////////////////////////////////////
  1732. if(peli_aux.estado=='A')
  1733. {
  1734. gotoxy(25,10);
  1735. printf("BAJA LOGICA");
  1736. peli_aux.estado='D';
  1737. do
  1738. {
  1739. gotoxy(25,20);
  1740. printf("1-CONFIRMA ");
  1741. gotoxy(25,21);
  1742. printf("2-CANCELA ");
  1743. conf=getch();
  1744. if(conf<49 || conf>50) gotoxy(9,10);
  1745. }
  1746. while(conf<49 || conf>50);
  1747.  
  1748. if (conf==49)
  1749. { // Si se decidio grabar y nadie se llama igual...
  1750. fseek(p1,posicion,SEEK_SET);
  1751. if (fwrite(&peli_aux,sizeof(Pelicula),1,p1)!=1)
  1752. {
  1753. gotoxy(25,22);
  1754. printf("ERROR DE ESCRITURA");
  1755. getch();
  1756. return;
  1757. }
  1758. else
  1759. {
  1760. gotoxy(25,22);
  1761. printf("PELICULA DESACTIVADA");
  1762. }
  1763. }
  1764. do
  1765. {
  1766. if(conf==50)
  1767. {
  1768. gotoxy(25,22);
  1769. printf("INGRESO CANCELADO");
  1770. }
  1771. gotoxy(25,23);
  1772. printf("INGRESAR OTRO (S/N)? ");
  1773. otro='s';//por las dudas
  1774. otro=getch();
  1775. otro=toupper(otro);
  1776. }
  1777. while(otro!='S' && otro!='N');
  1778. }
  1779. else
  1780. {
  1781. gotoxy(25,10);
  1782. printf("BAJA FISICA");
  1783. fcloseall();
  1784. EliminarFisicaPelicula(peli_aux.codigo); //Codigo de EliminarFisicaCliente adaptado para dar de baja fisica a las peliculas.
  1785. getch();
  1786. }
  1787. }
  1788. while (otro=='S');
  1789. fclose(p1);
  1790. }
  1791.  
  1792. void cargar (void)
  1793. {
  1794. comen reg;
  1795.  
  1796. FILE *pf;
  1797. pf = fopen("c:\\comentario.txt","wb");
  1798. if (pf==NULL)
  1799. {
  1800. clrscr();
  1801. printf("error de apertura");
  1802. getch();
  1803. exit(1);
  1804. }
  1805.  
  1806. //carga del archivo
  1807. clrscr();
  1808. printf("Codigo de Pelicula <0 para salir>: ");
  1809. scanf("%d", &reg.codigo_pel);
  1810.  
  1811. while (reg.codigo_pel)
  1812. {
  1813. printf("Comentario: ");
  1814. fflush(stdin);
  1815. gets(reg.comentario);
  1816. fwrite(&reg,sizeof(reg),1,pf);
  1817. clrscr();
  1818. printf("Codigo de Pelicula <0 para salir>: ");
  1819. scanf("%d", &reg.codigo_pel);
  1820. }
  1821. fclose(pf);
  1822. }
  1823.  
  1824. void mostrar(void)
  1825. {
  1826. comen reg;
  1827. FILE *pf;
  1828. pf = fopen("c:\\comentarios.txt","rb");
  1829. if (pf==NULL)
  1830. {
  1831. clrscr();
  1832. printf("error de apertura");
  1833. getch();
  1834. exit(1);
  1835. }
  1836. printf("Los comentarios son: \n\n");
  1837.  
  1838. fread(&reg,sizeof(reg),1,pf);
  1839. printf("Codigo Comentarios: \n");
  1840. while(!feof(pf))
  1841.  
  1842. {
  1843. printf(" %-10d %-20s \n", reg.codigo_pel, reg.comentario);
  1844. fread(&reg,sizeof(reg),1,pf);
  1845. }
  1846. fclose(pf);
  1847. getch();
  1848.  
  1849. }
  1850.  
  1851.  
  1852. long ObtenerPosicionPelicula(int codigo) //Por ahora utilizo esta funcion para probar. Luego reciclaré el codigo del indice de peliculas.
  1853. {
  1854. Pelicula reg;
  1855. FILE *p1;
  1856. int ss;
  1857. long ret;
  1858.  
  1859. p1=fopen(FILE_PELICULAS,"rb");
  1860. if(p1==NULL)
  1861. {
  1862. clrscr();
  1863. gotoxy(22,10);
  1864. printf("ERROR EN APERTURA DE ARCHIVO");
  1865. getch();
  1866. exit(1);
  1867. }
  1868.  
  1869. rewind(p1);
  1870. while(!feof(p1))
  1871. {
  1872. flushall();
  1873. ret = ftell(p1);
  1874. if(fread(&reg,sizeof(Pelicula),1,p1)!=1 && (!feof(p1)))exit(1);
  1875.  
  1876. ss=0;
  1877. if(codigo == reg.codigo)
  1878. {
  1879. ss=1;
  1880. break;
  1881. }
  1882. }
  1883. fclose(p1);
  1884. if(ss==0)
  1885. {
  1886. // Pelicula No Encontrada
  1887. ret = -1;
  1888. }
  1889. return ret;
  1890. }
  1891.  
  1892. void EliminarFisicaPelicula(int codPeli)
  1893. {
  1894. FILE *ARCHIVO,*COPIA, *log_bajas;
  1895. Pelicula dato,*pdato;
  1896. long cant;
  1897. char cop[]={"PELICULAS.TMP"};
  1898.  
  1899. pdato=&dato;
  1900.  
  1901. fcloseall();
  1902.  
  1903. if((ARCHIVO=fopen(FILE_PELICULAS,"rb"))==NULL)
  1904. {
  1905. gotoxy(25,14);
  1906. printf("ERROR EN APERTURA ARCHIVO");
  1907. printf("EL DATO NO SE PUEDE ELIMINAR");
  1908. getch();
  1909. return;
  1910. }
  1911. if((COPIA=fopen(cop,"wb"))==NULL)
  1912. {
  1913. gotoxy(25,14);
  1914. printf("ERROR EN APERTURA ARCHIVO");
  1915. gotoxy(25,15);
  1916. printf("EL DATO NO SE PUEDE ELIMINAR");
  1917. getch();
  1918. return;
  1919. }
  1920.  
  1921. //COMIENZA LA TRANSFERENCIA
  1922. rewind(ARCHIVO);
  1923. rewind(COPIA);
  1924. for( ; ; )
  1925. {
  1926. cant = fread(&dato,sizeof(Pelicula),1,ARCHIVO);
  1927.  
  1928. if(cant!=1)
  1929. {
  1930. if(feof(ARCHIVO)!=0)
  1931. {
  1932. break;
  1933. }
  1934. else
  1935. {
  1936. clreol();
  1937. printf("\aERROR AL LEER ARCHIVO!!!!");
  1938. getch();
  1939. return;
  1940. }
  1941. }
  1942. else
  1943. {
  1944. if(codPeli != pdato->codigo)//VERIFICO QUE NO SEA EL QUE QUIERO ELIMINAR
  1945. {
  1946. if(fwrite(&dato,sizeof(Pelicula),1,COPIA)!=1)
  1947. {
  1948. gotoxy(25,14);
  1949. printf("ERROR AL ESCRIBIR");
  1950. getch();
  1951. return;
  1952. };
  1953. }
  1954. }
  1955. }
  1956. //FIN DE LA COPIA
  1957. fcloseall();
  1958. if(remove(FILE_PELICULAS)!=0)
  1959. {
  1960. gotoxy(25,13);
  1961. printf("EL ARCHIVO ORIGINAL NO SE PUEDE ELIMINAR");
  1962. getch();
  1963. return;
  1964. }
  1965. else
  1966. {
  1967. if(rename(cop,FILE_PELICULAS)!=0)
  1968. {
  1969. gotoxy(25,13);
  1970. printf("EL ARCHIVO COP NO SE PUDO RENOMBRAR");
  1971. getch();
  1972. return;
  1973. }
  1974. else
  1975. {
  1976. gotoxy(25,15);
  1977. printf("BAJA REALIZADA");
  1978. registrar_bajas(codPeli);
  1979. }
  1980. }
  1981. fcloseall();
  1982. }
  1983.  
  1984.  
  1985. void ListarBajas(void)//Muestra Peliculas dadas de baja
  1986. {
  1987. FILE *p1;
  1988. dia fecha;
  1989. peli_baja reg;
  1990. p1=fopen(FILE_LOG_BAJAS,"r");
  1991. clrscr();
  1992. printf("- Peliculas Dadas de Baja: -\n");
  1993. fread(&reg,sizeof(reg),1,p1);
  1994. while(!feof(p1))
  1995. {
  1996. fecha=reg.fecha;
  1997. printf("Codigo de Pelicula: %d Dada de baja en la fecha: %d/%d/%d\n",reg.codpel,fecha.da_day,fecha.da_mon,fecha.da_year);
  1998. fread(&reg,sizeof(reg),1,p1);
  1999. }
  2000. getch();
  2001. }
  2002.  
  2003. /*FUNCION MODIFICAR PELICULAS
  2004. Necesito sólamente el código de la película que quiero modificar.
  2005. Recorro el archivo de la misma manera que lo hago para hacer la baja lógica. De hecho, puedo copiar la misma función...
  2006. Solicito los nuevos datos, los cuales serán almacenados un una estructura auxiliar del tipo Pelicula.
  2007. Grabo encima de la posición que me arrojó la función escrita por Adrián, verifico que la grabación haya sido exitosa (cosa que seguramente será asi)
  2008. y listo.
  2009. */
  2010.  
  2011. void ModificarPelicula(void) //AGREGAR
  2012. {
  2013. int codigo;
  2014. char continua,otro,conf,codSN;
  2015. Pelicula pelicula,pelicula_NuevosDatos,aux;
  2016. long posicion;
  2017. FILE *p1;
  2018.  
  2019. clrscr();
  2020. gotoxy(24,1);
  2021. printf("Ingrese el Codigo de la Pelicula a Buscar: ");
  2022. scanf("%d",&codigo);
  2023. posicion=ObtenerPosicionPelicula(codigo);
  2024.  
  2025. clrscr();
  2026. if(posicion == -1)
  2027. {
  2028. gotoxy(25,20);
  2029. printf("PELICULA NO ENCONTRADA");
  2030. getch();
  2031. return;
  2032. }
  2033.  
  2034. // Cargo los datos de la pelicula encontrada para mostrarlos antes de la modificación
  2035. if((p1 = fopen(FILE_PELICULAS,"r+b")) == NULL)
  2036. {
  2037. gotoxy(25,13);
  2038. printf("ERROR AL GENERAR ARCHIVO DE PELICULAS %s",FILE_PELICULAS);
  2039. getch();
  2040. return;
  2041. }
  2042.  
  2043. fseek(p1,posicion,SEEK_SET);
  2044. if (fread(&pelicula,sizeof(Pelicula),1,p1) != 1)
  2045. {
  2046. clreol();
  2047. printf("\aERROR AL LEER ARCHIVO!!!!");
  2048. getch();
  2049. return;
  2050. }
  2051.  
  2052. clrscr();
  2053. gotoxy(25,2);
  2054. printf("DATOS DEL REGISTRO ENCONTRADO");
  2055. gotoxy(25,3);
  2056. printf("Codigo : %d ",pelicula.codigo);
  2057. gotoxy(25,4);
  2058. printf("Titulo : %s ",pelicula.titulo);
  2059. gotoxy(25,5);
  2060. printf("Copias : %d ",pelicula.copias);
  2061. gotoxy(25,6);
  2062. printf("Alquiladas : %d ",pelicula.alquiladas);
  2063. gotoxy(25,7);
  2064. printf("Descripcion : %s ",pelicula.descripcion);
  2065. gotoxy(25,8);
  2066. printf("Veces alquilada : %d ",pelicula.vecesalquilada);
  2067. gotoxy(25,9);
  2068. printf("Estado : %c ",pelicula.estado); //EL ESTADO ES UN INT???
  2069. getch();
  2070.  
  2071. /////////////////////////////////////////////
  2072. // Pido los nuevos datos de la pelicula
  2073. /////////////////////////////////////////////
  2074. do
  2075. {
  2076. gotoxy(25,10);
  2077. printf("====================");
  2078. /*int codigo;
  2079. char titulo[30];
  2080. int copias;
  2081. int alquiladas;
  2082. char estado;*/
  2083.  
  2084. do
  2085. {
  2086. gotoxy(25,11);
  2087. printf("TITULO: ");
  2088. fflush(stdin);
  2089. gets(pelicula_NuevosDatos.titulo);
  2090. }
  2091. while(strlen(pelicula_NuevosDatos.titulo)==0);
  2092. //VALIDA QUE EL NOMBRE NO SE REPITA
  2093.  
  2094. aux = ObtenerPelicula(pelicula_NuevosDatos,2);
  2095. if(aux.codigo!=-1)
  2096. {
  2097. gotoxy(25,20);
  2098. printf("YA HAY UNA PELICULA CON ESE TITULO");
  2099. gotoxy(25,21);
  2100. printf("DESEA CONTINUAR? (S/N)");
  2101. continua = getch();
  2102. continua = toupper(continua);
  2103. if (continua!='S')return;
  2104. }
  2105. //FIN DE VALIDACION
  2106. gotoxy(25,12);
  2107. printf("CODIGO: %d",&pelicula.codigo);
  2108. gotoxy(25,13);
  2109. printf("INGRESARA UN NUEVO CODIGO? (S/N)");
  2110. scanf("%d",&codSN);
  2111. while(codSN=='S' || codSN=='N')
  2112. {
  2113. if(codSN=='S')
  2114. {
  2115. printf("\nIngrese nuevo codigo: ");
  2116. scanf("%d",&pelicula_NuevosDatos.codigo);
  2117. getch();
  2118. }
  2119. if(codSN=='N')
  2120. {
  2121. pelicula_NuevosDatos.codigo=pelicula.codigo;
  2122. }
  2123. }
  2124. gotoxy(25,14);
  2125. printf("COPIAS: ");
  2126. fflush(stdin);
  2127. scanf("%d",&pelicula_NuevosDatos.copias);
  2128. gotoxy(25,15);
  2129. printf("ALQUILADAS: ");
  2130. fflush(stdin);
  2131. scanf("%d",&pelicula_NuevosDatos.alquiladas);
  2132. gotoxy(25,16);
  2133. printf("DESCRIPCION: ");
  2134. fflush(stdin);
  2135. gets(pelicula_NuevosDatos.descripcion);
  2136. gotoxy(25,17);
  2137. printf("VECES ALQUILADA: ");
  2138. scanf("%d",&pelicula_NuevosDatos.vecesalquilada);
  2139. // Inicializa Estado y Alquileres Realizados
  2140. gotoxy(25,18);
  2141. printf("ESTADO (A/D):");
  2142. scanf("%c",&pelicula_NuevosDatos.estado);
  2143. pelicula_NuevosDatos.estado=toupper(pelicula_NuevosDatos.estado);
  2144. do
  2145. {
  2146. gotoxy(25,20);
  2147. printf("1-CONFIRMA ");
  2148. gotoxy(25,21);
  2149. printf("2-REINGRESA");
  2150. gotoxy(25,22);
  2151. printf("3-CANCELA ");
  2152. conf=getch();
  2153. if(conf<49 || conf>51) gotoxy(9,10);
  2154. }
  2155. while(conf<49 || conf>51);
  2156.  
  2157.  
  2158. if (conf==49)
  2159. { // Si de decidio grabar y no se repetia el titulo de la pelicula...
  2160. fseek(p1,posicion,SEEK_SET);
  2161. if (fwrite(&pelicula_NuevosDatos,sizeof(Pelicula),1,p1)!=1)
  2162. {
  2163. gotoxy(25,24);
  2164. printf("ERROR DE ESCRITURA");
  2165. getch();
  2166. return;
  2167. }
  2168. else
  2169. {
  2170. gotoxy(25,24);
  2171. printf("MODIFICACION REALIZADA SATISFACTORIAMENTE");
  2172. }
  2173. }
  2174. do
  2175. {
  2176. if(conf==51)
  2177. {
  2178. conf=50;//sino si cancela y sigue ingresando apareceria de vuelta
  2179. gotoxy(25,24);
  2180. printf("INGRESO CANCELADO");
  2181. }
  2182. gotoxy(25,25);
  2183. printf("INGRESAR OTRO (S/N)? ");
  2184. otro='s';//por las dudas
  2185. otro=getch();
  2186. otro=toupper(otro);
  2187. }
  2188. while(otro!='S' && otro!='N');
  2189. }
  2190. while(otro=='S');
  2191. fclose(p1);
  2192. }
  2193.  
  2194. /* FUNCION QUE ARROJE DATOS ESTADISTICOS
  2195. De acuerdo al "año" solicitado, la función recorrerá el archivo de alquileres en busca de los registros de "mes" en que son efectuados los alquileres y,
  2196. según el mes encontrado, se irá incrementando un contador para el mes correspondiente.
  2197. Esto lo voy a lograr obteniendo el mes actual con getdate, con un "case" de acuerdo al número de mes y con un contador en cada opción. Los contadores
  2198. podrían ser parte de un vector de 12 posiciones. (LISTO)
  2199. Finalmente, tengo que efectuar una función que recorra el vector en busca del mes con mayor número de alquileres (un max) y con un for tengo que hacer
  2200. otra función que compare cada mes con el mes anterior y arroje un porcentaje de variación.
  2201. Muestro la información cuantitativa y porcentual y c´est fini. */
  2202.  
  2203. void Crear_Estad_Alq (void) //AGREGAR
  2204. {
  2205. clrscr();
  2206. FILE *log_estadist;
  2207. Estadistica estadistica;
  2208. int mes, anio, i;
  2209. float max;
  2210. float contmeses[12]={0}; //contador de alquileres encontrados en cada mes
  2211. float porcmeses[12]={0}; //almacena los porcentajes de variación de alquileres mes a mes
  2212. fflush(stdin);
  2213. printf("\Ingrese el anio del que se desea obtener informacion estadistica sobre los alquileres efectuados: ");
  2214. scanf("%d",&anio);
  2215.  
  2216. //Comienzo a recorrer el archivo de alquileres en busca de alquileres efectuados en el anio.
  2217.  
  2218. FILE *p1;
  2219. dia fecha;
  2220. Alquiler reg;
  2221. p1=fopen(FILE_ALQUILER,"r");
  2222. clrscr();
  2223. fread(&reg,sizeof(Alquiler),1,p1);
  2224. while(!feof(p1))
  2225. {
  2226. if(reg.fecha.da_year==anio)
  2227. {
  2228. mes=reg.fecha.da_mon;
  2229.  
  2230. switch(mes) //de acuerdo al mes en que se realizó el alquiler, incremento un contador.
  2231. {
  2232. case 1:
  2233. contmeses[0]++;
  2234. break;
  2235. case 2:
  2236. contmeses[1]++;
  2237. break;
  2238. case 3:
  2239. contmeses[2]++;
  2240. break;
  2241. case 4:
  2242. contmeses[3]++;
  2243. break;
  2244. case 5:
  2245. contmeses[4]++;
  2246. break;
  2247. case 6:
  2248. contmeses[5]++;
  2249. break;
  2250. case 7:
  2251. contmeses[6]++;
  2252. break;
  2253. case 8:
  2254. contmeses[7]++;
  2255. break;
  2256. case 9:
  2257. contmeses[8]++;
  2258. break;
  2259. case 10:
  2260. contmeses[9]++;
  2261. break;
  2262. case 11:
  2263. contmeses[10]++;
  2264. break;
  2265. case 12:
  2266. contmeses[11]++;
  2267. break;
  2268. }
  2269. //Calculo la variación porcentual mes a mes. Enero vale 100% porque comienza el año a evaluar.
  2270. }
  2271. fread(&reg,sizeof(reg),1,p1);
  2272. }
  2273.  
  2274. for(i=0;i<12;i++)
  2275. {
  2276. if(i==0)
  2277. {
  2278. porcmeses[0]=100;
  2279. max=contmeses[0]; //inicio max en la primer posicion.
  2280. }
  2281. else
  2282. {
  2283. if (contmeses[i-1] == 0)
  2284. porcmeses[i] = 0;
  2285. else
  2286. porcmeses[i]=((contmeses[i]*100)/contmeses[i-1]);
  2287.  
  2288. if(contmeses[i]>max)
  2289. max=contmeses[i];
  2290. }
  2291. }
  2292. if((log_estadist = fopen(FILE_ESTADISTICA,"a+b")) == NULL)
  2293. {
  2294. gotoxy(25,13);
  2295. printf("ERROR AL ABRIR ARCHIVO");
  2296. getch();
  2297. return;
  2298. }
  2299. else
  2300. {
  2301. estadistica.anio=anio;
  2302. for(i=0;i<12;i++)
  2303. {
  2304. estadistica.contmeses[i]=contmeses[i];
  2305. estadistica.porcmeses[i]=porcmeses[i];
  2306. }
  2307. estadistica.max=max;
  2308. fwrite(&estadistica,sizeof(Estadistica),1,log_estadist);
  2309. }
  2310. fcloseall();
  2311. }
  2312.  
  2313. Pelicula ObtenerPelicula(Pelicula pelicula, int formaBusqueda) //AGREGAR
  2314. {
  2315. Pelicula reg;
  2316. FILE *p1;
  2317. int ss;
  2318.  
  2319. p1=fopen(FILE_PELICULAS,"rb");
  2320. if(p1==NULL)
  2321. {
  2322. clrscr();
  2323. gotoxy(22,10);
  2324. printf("ERROR EN APERTURA DE ARCHIVO");
  2325. getch();
  2326. exit(1);
  2327. }
  2328.  
  2329. rewind(p1);
  2330. while(!feof(p1))
  2331. {
  2332. flushall();
  2333. if(fread(&reg,sizeof(Pelicula),1,p1)!=1 && (!feof(p1)))exit(1);
  2334.  
  2335. ss=0;
  2336. switch(formaBusqueda)
  2337. {
  2338. case 1:
  2339. if(pelicula.codigo == reg.codigo)
  2340. ss=1;
  2341. break;
  2342.  
  2343. case 2:
  2344. if((strcmp(strlwr(pelicula.titulo),strlwr(reg.titulo))==0)
  2345. &&
  2346. (strcmp(strlwr(pelicula.descripcion),strlwr(reg.descripcion))==0))
  2347. ss=1;
  2348. break;
  2349. }
  2350. if (ss==1) break;
  2351. }
  2352. fclose(p1);
  2353. if(ss==0)
  2354. {
  2355. // pelicula No Encontrada
  2356. reg.codigo = -1;
  2357. }
  2358. return reg;
  2359. }
  2360.  
  2361. void ListarEstadistica(void)//Lista el contenido del archivo de información estadistica //AGREGAR
  2362. {
  2363. FILE *p1;
  2364. int i=0;
  2365. static char meses[12][4]={"ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT","NOV","DIC"};
  2366. Estadistica reg;
  2367. p1=fopen(FILE_ESTADISTICA,"r");
  2368. clrscr();
  2369. printf("- INFORMACION ESTADISTICA ALQUILERES -\n");
  2370. fread(&reg,sizeof(Estadistica),1,p1);
  2371. while(!feof(p1))
  2372. {
  2373. printf("\nAño: %d",reg.anio);
  2374. for(i=0;i<12;i++)
  2375. {
  2376. printf("\n%s Cant Alquileres: %.f Diferencia Porcentual Respecto Mes Anterior: %.2f",meses[i],reg.contmeses[i],reg.porcmeses[i]);
  2377. }
  2378. fread(&reg,sizeof(Estadistica),1,p1);
  2379. }
  2380. getch();
  2381. }
  2382.  
  2383.  
  2384.  
  2385.  
  2386. ///////////////////////////////////////////////////////////////////////////////
  2387. // Funcion de busqueda de cliente utilizando memeoria dinamica
  2388. ///////////////////////////////////////////////////////////////////////////////
  2389. Cliente* ObtenerCliente_MemoriaDinamica(Cliente cliente, int formaBusqueda)
  2390. {
  2391. Cliente reg, *ptr;
  2392. FILE *p1;
  2393. int ss;
  2394.  
  2395. p1=fopen(FILE_CLIENTES,"rb");
  2396. if(p1==NULL)
  2397. {
  2398. clrscr();
  2399. gotoxy(22,10);
  2400. printf("ERROR EN APERTURA DE ARCHIVO");
  2401. getch();
  2402. exit(1);
  2403. }
  2404.  
  2405. rewind(p1);
  2406. while(!feof(p1))
  2407. {
  2408. flushall();
  2409. if(fread(&reg,sizeof(Cliente),1,p1)!=1 && (!feof(p1)))exit(1);
  2410.  
  2411. ss=0;
  2412. switch(formaBusqueda)
  2413. {
  2414. case 1:
  2415. if(cliente.codigo == reg.codigo)
  2416. ss=1;
  2417. break;
  2418.  
  2419. case 2:
  2420. if((strcmp(strlwr(cliente.apellido),strlwr(reg.apellido))==0)
  2421. &&
  2422. (strcmp(strlwr(cliente.nombre),strlwr(reg.nombre))==0))
  2423. ss=1;
  2424. break;
  2425. }
  2426. if (ss==1) break;
  2427. }
  2428. fclose(p1);
  2429. if(ss==0)
  2430. {
  2431. // Cliente No Encontrado
  2432. reg.codigo = -1;
  2433. }
  2434. // Lo asignamos dinamicamente para devolverlo
  2435. ptr=(Cliente*)malloc(sizeof(reg));
  2436. if (ptr==NULL)
  2437. {
  2438. clrscr();
  2439. printf("Error en asignacion dinamica");
  2440. getch();
  2441. exit(1);
  2442. }
  2443. *ptr=reg;
  2444. return ptr;
  2445. }
  2446.  
  2447. ////////////////////////////////////////////////////////////////////////////////
  2448. void ConsultarCliente_MemoriaDinamica(void)
  2449. {
  2450. int op,codigo;
  2451. Cliente cliente, *buscadoCliente;
  2452.  
  2453. op=Menu_Busqueda_NomApeCodigo();
  2454. clrscr();
  2455. switch(op)
  2456. {
  2457. case 1:
  2458. gotoxy(24,8);
  2459. printf("Ingrese el Nombre y Apellido de Cliente a Buscar");
  2460. gotoxy(24,9);
  2461. printf("Apellido: ");
  2462. fflush(stdin);
  2463. gets(cliente.apellido);
  2464. gotoxy(24,10);
  2465. printf("Nombre: ");
  2466. fflush(stdin);
  2467. gets(cliente.nombre);
  2468.  
  2469. buscadoCliente= ObtenerCliente_MemoriaDinamica(cliente,2);
  2470. break;
  2471. case 2:
  2472. gotoxy(24,8);
  2473. printf("Ingrese el Codigo del Cliente a Buscar: ");
  2474. scanf("%d",&codigo);
  2475. cliente.codigo = codigo;
  2476. buscadoCliente=ObtenerCliente_MemoriaDinamica(cliente,1);
  2477. break;
  2478. case 3:
  2479. return;
  2480. }
  2481.  
  2482. if(buscadoCliente->codigo != -1)
  2483. {
  2484. clrscr();
  2485. gotoxy(24,8);
  2486. printf("DATOS DEL REGISTRO ENCONTRADO");
  2487. gotoxy(24,9);
  2488. printf("Codigo : %d ",buscadoCliente->codigo);
  2489. gotoxy(24,10);
  2490. printf("Nombre : %s ",buscadoCliente->nombre);
  2491. gotoxy(24,11);
  2492. printf("Apellido : %s ",buscadoCliente->apellido);
  2493. gotoxy(24,12);
  2494. printf("Direccion : %s ",buscadoCliente->direccion);
  2495. gotoxy(24,13);
  2496. printf("Telefono : %s ",buscadoCliente->telefono);
  2497. gotoxy(24,14);
  2498. printf("Alquileres : %d ",buscadoCliente->alquileresrealizados);
  2499. gotoxy(24,15);
  2500. printf("Estado : %c ",buscadoCliente->estado);
  2501. getch();
  2502. }
  2503. else
  2504. {
  2505. gotoxy(24,18);
  2506. printf("CLIENTE NO ENCONTRADO");
  2507. getch();
  2508. }
  2509. }
  2510.  
  2511. /////////////////////////////////////////////////////////////////////////////////
  2512.  
  2513. void ListarClientes(void)
  2514. {
  2515. FILE *ARCHIVO;
  2516. int i=7, posicion = 0;
  2517. long ultimo;
  2518. char letra;
  2519. Cliente aux,*paux,*v[500];
  2520. paux=&aux;
  2521. // Apertura del archivo
  2522. if((ARCHIVO=fopen(FILE_CLIENTES,"rb"))==NULL)
  2523. {
  2524. gotoxy(25,13);
  2525. printf("EL ARCHIVO NO SE ENCUENTRA");
  2526. gotoxy(25,14);
  2527. printf("DEBE CREARLO ENTRANDO A LA OPCION 1");
  2528. getch();
  2529. return;
  2530. }
  2531. // Se fija que el archivo tenga algo
  2532. fseek(ARCHIVO,0,SEEK_END);
  2533. ultimo=ftell(ARCHIVO);
  2534. if (ultimo==0)
  2535. {
  2536. gotoxy(25,20);
  2537. printf("EL ARCHIVO ESTA VACIO");
  2538. getch();
  2539. return;
  2540. }
  2541. gotoxy(20,14);
  2542. printf("CON \"*\" LISTA COMPLETA");
  2543. gotoxy(20,15);
  2544. printf("INGRESA LA LETRA POR LA QUE QUERES LISTAR: ");
  2545. letra=getch();
  2546. rewind(ARCHIVO);
  2547. Listar_EncaClientes();
  2548. do
  2549. {
  2550. if((fread(&aux,sizeof(Cliente),1,ARCHIVO)!=1))
  2551. {
  2552. if(!feof(ARCHIVO))
  2553. {
  2554. gotoxy(3,23);
  2555. printf("ERROR LISTANDO");
  2556. getch();
  2557. return;
  2558. }
  2559. }
  2560. else
  2561. {
  2562. paux=(Cliente*)malloc(sizeof(aux));
  2563. if (paux==NULL)
  2564. {
  2565. clrscr();
  2566. printf("Error en asignacion dinamica");
  2567. getch();
  2568. exit(1);
  2569. }
  2570. *paux=aux;
  2571. v[posicion] = paux;
  2572. posicion++;
  2573. }
  2574. }
  2575. while(!feof(ARCHIVO));
  2576. fclose(ARCHIVO);
  2577.  
  2578. // Terminamos de leer el archivo
  2579.  
  2580. // Mostramos el vector
  2581. for (int posActual = 0; posActual < posicion ; posActual++)
  2582. {
  2583. paux = v[posActual];
  2584. if(letra!='*') // Lista por letra
  2585. {
  2586. if((toupper(letra)==aux.apellido[0]) || (tolower(letra)==aux.apellido[0]))
  2587. {
  2588. i++;
  2589. gotoxy(5,i);
  2590. printf("%d",paux->codigo);
  2591. gotoxy(9,i);
  2592. printf("%c",paux->estado);
  2593. gotoxy(13,i);
  2594. printf("%s",paux->apellido);
  2595. gotoxy(32,i);
  2596. printf("%s",paux->direccion);
  2597. gotoxy(57,i);
  2598. printf("%s",paux->telefono);
  2599. if(i==18)
  2600. {
  2601. gotoxy(3,23);
  2602. printf("PRESIONE UNA TECLA PARA CONTINUAR");
  2603. getch();
  2604. clrscr();
  2605. Listar_EncaClientes();
  2606. i=7;
  2607. }
  2608. }
  2609. }
  2610. else // Lista todo
  2611. {
  2612. i++;
  2613. gotoxy(5,i);
  2614. printf("%d",paux->codigo);
  2615. gotoxy(10,i);
  2616. printf("%c",paux->estado);
  2617. gotoxy(13,i);
  2618. printf("%s",paux->apellido);
  2619. gotoxy(32,i);
  2620. printf("%s",paux->direccion);
  2621. gotoxy(57,i);
  2622. printf("%s",paux->telefono);
  2623. if(i==18)
  2624. {
  2625. if(feof(ARCHIVO))
  2626. {
  2627. gotoxy(3,23);
  2628. printf("LISTA COMPLETA");
  2629. getch();
  2630. return;
  2631. }
  2632. gotoxy(3,23);
  2633. printf("PRESIONE UNA TECLA PARA CONTINUAR");
  2634. getch();
  2635. clrscr();
  2636. Listar_EncaClientes();
  2637. i=7;
  2638. }
  2639. }
  2640. }
  2641.  
  2642. gotoxy(3,23);
  2643. printf("LISTA COMPLETA");
  2644. getch();
  2645. return;
  2646. }
  2647.  
  2648. void registrar_bajas (int codigo) //AGREGAR
  2649. {
  2650. //Creo una estructura auxiliar
  2651. peli_baja reg;
  2652. FILE *log_p_baja;
  2653. if((log_p_baja = fopen(FILE_LOG_BAJAS,"a")) == NULL)
  2654. {
  2655. gotoxy(25,13);
  2656. printf("ERROR AL ABRIR ARCHIVO");
  2657. getch();
  2658. return;
  2659. }
  2660. else
  2661. {
  2662. reg.codpel=codigo;
  2663. getdate(&reg.fecha);
  2664. fwrite(&reg,sizeof(reg),1,log_p_baja);
  2665. }
  2666. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement