#include #include #include #include #include #include #include #include #include "..\libs\make_bot\make_bot.h" #include "sv_graph.h" #include "sv_util.h" #define Letra_Boton setcolor(1); #define Azul 2 #define Texto_Normal setcolor(63); #define Texto_Negrita setcolor(0); extern int x_raton, y_raton;extern char raton; extern int boton_izq, boton_der; extern void desactiva_raton(void); extern void activa_raton(void); extern void Anclar_Raton(void); extern void inicializa_raton_grafico(int x1, int y1, int x2, int y2, int px, int py); extern int Espera_Tecla_o_Raton(void); extern void BEEP(void); extern void textxy(int x, int y, char *text); extern int InputCadenaG(char *s, int numalp, int lmax, int cc, int cf, struct Make_Boton Campo); extern int InputCadenaG_l(char *s, int numalp, int lmax, int cc, int cf, struct Make_Boton Campo, int Row); extern void Abre_Ficha_Clientes(void); void Menu_de_Vendedores (void); void Mueve_Arriba(void); void Mueve_Abajo(void); void EditCursorVend(int ShowHide); void PrintLineVend(int Rapida_Completa); void PrintWholeScreenVend(void); void Edit_Item_Vend(void); void Abre_Ficha_Vendedores(void); void DeleteRecordVend(void); void AddRecordVend(void); void PutLineVend(void); void GetLineVend(void); void Poner_a_cero_estructura_actual_vend(void); void Coloca_Nombres_a_botones(void); void Imprimir_Vendedores(void); void Imprime_Ficha(void); void Imprime_Lista_Rapida(void); void CompruebaLineasVend(void); //int Confirma(char *f1, char *f2, char *f3); extern int Comprueba_Impresora(void); struct JD { char esc; char color[8]; char prog[40]; char nl; char rt; char autor[36]; char pt; char ef; }; struct Vend_inx { unsigned int Fin; }; struct Vendedores { int Num_V; char Nombre[15+1]; char Apellido1[15+1]; char Apellido2[15+1]; char DNI[15+1]; unsigned long Telefono1; unsigned long Telefono2; char Calle[30+1]; char Num[3+1]; char Piso[3+1]; char Poblacion[18+1]; char Provincia[16+1]; unsigned long CP; unsigned long CC; unsigned int PP; unsigned int Cr; }; /*extern*/ struct Clientes_inx { char Ncontrato_ocupado_SN[10000]; unsigned int Fin; }; /*extern*/ struct Clientes { int Address; char Nombre[15+1]; char Apellido1[15+1]; char Apellido2[15+1]; char DNI[15+1]; unsigned long Telefono1; char Calle1[30+1]; char Num1[5+1]; char Local[30+1]; unsigned long Telefono2; char Calle2[30+1]; char Num2[5+1]; char Poblacion[18+1]; char Provincia[16+1]; unsigned long CP; unsigned char GC; unsigned char MR; unsigned char SP; unsigned char DP; unsigned int MA; struct date Fecha; int Vend; int NContrato; }; struct JD cabecera; struct Vendedores Vend1; struct Vend_inx Vend1_inx; extern struct Clientes Clientes1; extern struct Clientes_inx Clientes1_inx; struct Make_Boton *PV; //[19] extern struct Make_Boton Comunes[9]; FILE *Vend; // Fichero Vendedores extern FILE *Clientes; // Fichero Clientes int CurrRow1, CurrRow2; int CurrCol1, CurrCol2; int CurrTopLine; int SWAP = 1; void Menu_de_Vendedores (void) { int finished = 0, key, bpush; CurrRow1 = 1; CurrCol1 = 1; CurrRow2 = 1; CurrCol2 = 1; CurrTopLine = 1; inicializa_raton_grafico(0, 0, 624, 464, 320, 240); if(raton!=0) desactiva_raton(); if( ( PV = (struct Make_Boton *) malloc( sizeof(struct Make_Boton)*20 ) ) == NULL ) { Confirma("Memoria insuficiente", "para crear tablas de", "posisi¢n PV."); return ; } cleardevice(); Dibuja_Pantalla_Vendedores(PV); Fuente(SMALL_FONT, 5); Coloca_Nombres_a_botones(); Fuente(SMALL_FONT, 6); Abre_Ficha_Vendedores(); Abre_Ficha_Clientes(); PrintWholeScreenVend(); GetLineVend(); PrintLineVend(0); PrintLineVend(1); int oldCR1=0, oldCR2=0, oldCC1=0, oldCC2=0; do{ if(oldCR1!=CurrRow1 || oldCC1!=CurrCol1 || oldCR2!=CurrRow2 || oldCC2!=CurrCol2 ) EditCursorVend(0); oldCR1 = CurrRow1; oldCC1 = CurrCol1; oldCR2 = CurrRow2; oldCC2 = CurrCol2; if(raton!=0) activa_raton(); Espera_Tecla_o_Raton(); if(raton!=0) desactiva_raton(); if(kbhit()){ EditCursorVend(1); key = getch(); if( isprint(key) || isspace(key) ) { EditCursorVend(0); if(key!=13) ungetch(key); Edit_Item_Vend(); EditCursorVend(0); } else if( key == 0 ) { switch( (key=getch()) ){ // Flecha Arriba case 72: if(SWAP) Mueve_Arriba(); else { CurrCol2--; if ( CurrCol2 < 1 ) CurrCol2=14; } break; // Flecha Izquierda case 75: case 15: if(SWAP) { CurrCol1--; if ( CurrCol1<1 ) CurrCol1=4; } else { CurrCol2--; if ( CurrCol2 < 1 ) CurrCol2=14; } break; // Flecha Derecha case 77: case 9: if(SWAP) { CurrCol1++; if ( CurrCol1>4 ) CurrCol1=1; } else { CurrCol2++; if ( CurrCol2 > 14 ) CurrCol2=1; } break; // Flecha Abajo case 80: if(SWAP) { Mueve_Abajo(); } else { CurrCol2++; if ( CurrCol2 > 14 ) CurrCol2=1; } break; // Buscar F2 case 60: //BuscarVend(); break; // Imprimir Vendedores (incluye men£ desplegable) F5 case 63: Imprimir_Vendedores(); break; // SWAP (la parte de edici¢n) F6 case 64: if(SWAP){ SWAP=0; /* Fuente(SMALL_FONT, 5); */} else { SWAP=1; /* Fuente(SMALL_FONT, 6); */} EditCursorVend(0); break; // F9 --> A¥ADIR case 67: AddRecordVend(); break; // F10 -> BORRAR case 68: if( Confirma("Desea eliminar al", "Vendedor Actual", "") ) DeleteRecordVend(); break; // INICIO case 71: if(SWAP) CurrCol1 = 1; else CurrCol2 = 1; break; // FIN case 79: if(SWAP) CurrCol1 = 4; else CurrCol2 = 14; break; // ReP g case 73: // CurrRow = 1; if(SWAP) { if( CurrTopLine > 11 ) { CurrTopLine -= /*12*/11; } else { CurrTopLine = 1; } if( CurrTopLine < 1 ) { CurrTopLine = 1; } PrintWholeScreenVend(); GetLineVend(); PrintLineVend(1); EditCursorVend(0); } break; // AvP g case 81: // CurrRow = 1; if(SWAP) { CurrTopLine += /*12*/11; if ( (CurrTopLine+CurrRow1) > Vend1_inx.Fin) { CurrTopLine = Vend1_inx.Fin; CurrRow1 = 1; } if (CurrTopLine==0) CurrTopLine = 1; PrintWholeScreenVend(); GetLineVend(); PrintLineVend(1); EditCursorVend(0); } break; // Salir F1 case 59: finished = 1; break; default: break; } EditCursorVend(0); } } else if(raton!=0 && ( boton_izq==1 || boton_der==1 ) ) if( (bpush = CheckButon( 9, Comunes))>0 ) { EditCursorVend(1); switch(bpush){ // Flecha Arriba case 1: if(SWAP) Mueve_Arriba(); else { CurrCol2--; if ( CurrCol2 < 1 ) CurrCol2=14; } break; // Buscar case 2: //BuscarVend(); break; // Flecha Abajo case 3: if(SWAP) Mueve_Abajo(); else { CurrCol2++; if ( CurrCol2 > 14 ) CurrCol2=1; } break; case 4: if(SWAP){ SWAP=0; /* Fuente(SMALL_FONT, 5); */ } else { SWAP=1; /* Fuente(SMALL_FONT, 6); */ } EditCursorVend(0); break; // Imprimir case 5: Imprimir_Vendedores(); break; // A¤adir case 6: AddRecordVend(); break; // Borrar case 7: if( Confirma("Desea eliminar al", "Vendedor Actual", "") ) DeleteRecordVend(); break; // Salir case 9: finished = 1; break; default: break; } EditCursorVend(0); } else CompruebaLineasVend(); }while(!finished); fclose(Vend); // Fichero Vendedores free(PV); } void Mueve_Abajo(void){ int CurrRecord = CurrTopLine + CurrRow1 - 1; if (CurrRow1==/*12*/11) { if ( (CurrRecord - 1) >= Vend1_inx.Fin) BEEP(); else { CurrTopLine++; PrintWholeScreenVend(); //ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß //ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß //ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß GetLineVend(); // PrintLineVend(0); PrintLineVend(1); } } else { if( (CurrRecord - 1) >= Vend1_inx.Fin) BEEP(); else { CurrRow1++; GetLineVend(); PrintLineVend(1); } } } void Mueve_Arriba(void){ int CurrRecord = CurrTopLine + CurrRow1 - 1; if (CurrRow1==1) { if ((CurrRecord - 1) <= 0) BEEP(); else { CurrTopLine--; PrintWholeScreenVend(); //ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß //ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß //ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß GetLineVend(); // PrintLineVend(0); PrintLineVend(1); } } else { if( (CurrRecord - 1) <= 0) BEEP(); else { CurrRow1--; GetLineVend(); PrintLineVend(1); } } } void EditCursorVend(int ShowHide) { char Buffer[80]; setcolor(GRIS_C); setfillstyle(SOLID_FILL, GRIS_C); bar(10, 455, 545, 473); /* PR[0].Up = 450; PR[0].Down = 475; PR[0].Left = 5; PR[0].Right = 549; */ if(SWAP==0) { if (!ShowHide) { ImprimeBoton (0, GRIS_C, ROJO, ROJO, PV[CurrCol2+3]); setcolor(63); setfillstyle(SOLID_FILL, 63); bar(PV[CurrCol2+3].Left+2, PV[CurrCol2+3].Up+2, PV[CurrCol2+3].Right-2, PV[CurrCol2+3].Down-2); setcolor(0); } else { ImprimeBoton (0, GRIS_C, GRIS_O, BLANCO, PV[CurrCol2+3]); setcolor(0); setfillstyle(SOLID_FILL, 0); bar(PV[CurrCol2+3].Left+2, PV[CurrCol2+3].Up+2, PV[CurrCol2+3].Right-2, PV[CurrCol2+3].Down-2); Texto_Normal } Fuente(SMALL_FONT, 5); switch(CurrCol2) { case 1: outtextxy( PV[4].Left+2, PV[4].Up+2, Vend1.Nombre ); outtextxy( 15, 455, "Nombre del Vendedor. 15 digitos maximo."); break; case 2: outtextxy( PV[5].Left+2, PV[5].Up+2, Vend1.Apellido1 ); outtextxy( 15, 455, "1er. Apellido. 15 digitos m ximo."); break; case 3: outtextxy( PV[6].Left+2, PV[6].Up+2, Vend1.Apellido2 ); outtextxy( 15, 455, "2§ Apellido. 15 digitos m ximo."); break; case 4: outtextxy( PV[7].Left+2, PV[7].Up+2, Vend1.DNI ); outtextxy( 15, 455, "D.N.I. 15 digitos m ximo."); break; case 5: sprintf(Buffer, "%ld", Vend1.Telefono1); outtextxy( PV[8].Left+2, PV[8].Up+2, Buffer ); outtextxy( 15, 455, "Telefono 1. 12 digitos m ximo."); break; case 6: sprintf(Buffer, "%ld", Vend1.Telefono2); outtextxy( PV[9].Left+2, PV[9].Up+2, Buffer ); outtextxy( 15, 455, "Telefono 2. 12 digitos m ximo."); break; case 7: outtextxy( PV[10].Left+2, PV[10].Up+2, Vend1.Calle ); outtextxy( 15, 455, "Calle. 30 digitos m ximo."); break; case 8: outtextxy( PV[11].Left+2, PV[11].Up+2, Vend1.Num ); outtextxy( 15, 455, "N£mero de Calle. 3 digitos m ximo."); break; case 9: outtextxy( PV[12].Left+2, PV[12].Up+2, Vend1.Piso ); outtextxy( 15, 455, "N£m. de Piso, Letra... 3 digitos m ximo."); break; case 10:outtextxy( PV[13].Left+2, PV[13].Up+2, Vend1.Poblacion ); outtextxy( 15, 455, "Poblaci¢n. 18 digitos m ximo."); break; case 11:outtextxy( PV[14].Left+2, PV[14].Up+2, Vend1.Provincia ); outtextxy( 15, 455, "Provincia. 16 digitos m ximo."); break; case 12:sprintf(Buffer, "%ld", Vend1.CP); outtextxy( PV[15].Left+2, PV[15].Up+2, Buffer ); outtextxy( 15, 455, "C¢digo Postal. 5 digitos m ximo."); break; case 13:sprintf(Buffer, "%ld", Vend1.CC); outtextxy( PV[16].Left+2, PV[16].Up+2, Buffer ); outtextxy( 15, 455, "Comisi¢n por contrato. 5 digitos m ximo."); break; case 14:sprintf(Buffer, "%d", Vend1.PP); outtextxy( PV[17].Left+2, PV[17].Up+2, Buffer ); outtextxy( 15, 455, "Porcentaje por Producto. 2 digitos maximo."); break; /* case 15:sprintf(Buffer, "%d", Vend1.Cr); outtextxy( PV[18].Left+2, PV[18].Up+2, Buffer ); break; */ } } else { if (!ShowHide) { setcolor(63); setfillstyle(SOLID_FILL, 63); bar((PV[(CurrCol1)-1].Left+2), PV[(CurrCol1)-1].Up+4+(CurrRow1-1)*/*9*//*14*/15+2, PV[(CurrCol1)-1].Right-2, PV[(CurrCol1)-1].Up+/*3*/4+((CurrRow1)-1)*/*9*//*14*/15+/*9*/16); setcolor(0); } else { setcolor(0); setfillstyle(SOLID_FILL, 0); bar((PV[(CurrCol1)-1].Left+2), PV[(CurrCol1)-1].Up+4+(CurrRow1-1)*/*9*//*14*/15+2, PV[(CurrCol1)-1].Right-2, PV[(CurrCol1)-1].Up+/*3*/4+((CurrRow1)-1)*/*9*//*14*/15+/*9*/16); Texto_Normal } Fuente(SMALL_FONT, 6); switch(CurrCol1){ case 1: sprintf(Buffer, "%03d", Vend1.Num_V); outtextxy( PV[0].Left+2, (PV[0].Up+2)+(CurrRow1-1)*/*9*//*14*/15, Buffer ); outtextxy( 15, 455, "N£mero de vendedor. 3 digitos m ximo."); break; case 2: outtextxy( PV[1].Left+2, (PV[1].Up+2)+(CurrRow1-1)*/*9*//*14*/15,Vend1.Nombre ); outtextxy( 15, 455, "Nombre del Vendedor. 15 digitos m ximo."); break; case 3: outtextxy( PV[2].Left+2, (PV[2].Up+2)+(CurrRow1-1)*/*9*//*14*/15, Vend1.Apellido1 ); outtextxy( 15, 455, "1er. Apellido. 15 digitos m ximo."); break; case 4: sprintf(Buffer, "%ld", Vend1.Telefono1 ); outtextxy( PV[3].Left+2, (PV[3].Up+2)+(CurrRow1-1)*/*9*//*14*/15,Buffer ); outtextxy( 15, 455, "Telefono1. 12 digitos m ximo."); break; } } } void PrintLineVend(int Rapida_Completa){ char Buffer[80]; if(Rapida_Completa) { // Completa Fuente(SMALL_FONT, 5); for(int i=4; i<19; i++) ImprimeBoton (1, NEGRO, GRIS_O, BLANCO, PV[i]); Texto_Normal outtextxy( PV[4].Left+2, PV[4].Up+2, Vend1.Nombre ); outtextxy( PV[5].Left+2, PV[5].Up+2, Vend1.Apellido1 ); outtextxy( PV[6].Left+2, PV[6].Up+2, Vend1.Apellido2 ); outtextxy( PV[7].Left+2, PV[7].Up+2, Vend1.DNI ); sprintf(Buffer, "%ld", Vend1.Telefono1); outtextxy( PV[8].Left+2, PV[8].Up+2, Buffer ); sprintf(Buffer, "%ld", Vend1.Telefono2); outtextxy( PV[9].Left+2, PV[9].Up+2, Buffer ); outtextxy( PV[10].Left+2, PV[10].Up+2, Vend1.Calle ); outtextxy( PV[11].Left+2, PV[11].Up+2, Vend1.Num ); outtextxy( PV[12].Left+2, PV[12].Up+2, Vend1.Piso ); outtextxy( PV[13].Left+2, PV[13].Up+2, Vend1.Poblacion ); outtextxy( PV[14].Left+2, PV[14].Up+2, Vend1.Provincia ); sprintf(Buffer, "%ld", Vend1.CP); outtextxy( PV[15].Left+2, PV[15].Up+2, Buffer ); sprintf(Buffer, "%ld", Vend1.CC); outtextxy( PV[16].Left+2, PV[16].Up+2, Buffer ); sprintf(Buffer, "%d", Vend1.PP); outtextxy( PV[17].Left+2, PV[17].Up+2, Buffer ); setcolor(ROJO); sprintf(Buffer, " %03d", Vend1.Cr); outtextxy( PV[18].Left+2, PV[18].Up+2, Buffer ); } else { // Rapida Fuente(SMALL_FONT, 6); /* for(int i=0; i<4; i++) ImprimeBoton (1, NEGRO, GRIS_O, BLANCO, PV[i]); */ // outtextxy(20,15, "N§ Nombre 1er. Apellido Telf."); Texto_Normal sprintf(Buffer, "%03d", Vend1.Num_V); outtextxy( PV[0].Left+2, PV[0].Up+2+(CurrRow1-1)*/*9*//*14*/15, Buffer ); outtextxy( PV[1].Left+2, PV[1].Up+2+(CurrRow1-1)*/*9*//*14*/15, Vend1.Nombre ); outtextxy( PV[2].Left+2, PV[2].Up+2+(CurrRow1-1)*/*9*//*14*/15, Vend1.Apellido1 ); sprintf(Buffer, "%ld", Vend1.Telefono1 ); outtextxy( PV[3].Left+2, PV[3].Up+2+(CurrRow1-1)*/*9*//*14*/15, Buffer ); } } void PrintWholeScreenVend(void){ int tmp = CurrRow1; for(int i=0; i<19; i++) ImprimeBoton (1, NEGRO, GRIS_O, BLANCO, PV[i]); for(CurrRow1 = 1; CurrRow1 < (/*12*/11+1); CurrRow1++) if ( (CurrTopLine + CurrRow1 - 1) <= (Vend1_inx.Fin + 1) ) { GetLineVend(); PrintLineVend(0); } CurrRow1 = tmp; } void Edit_Item_Vend(void){ char buffer[80]; if(SWAP){ Fuente(SMALL_FONT, 6); switch (CurrCol1) { case 1: sprintf( buffer, "%d", Vend1.Num_V); InputCadenaG_l( buffer, 1, 3, 63, 57, PV[0], CurrRow1-1); Vend1.Num_V = atoi(buffer); break; case 2: InputCadenaG_l( Vend1.Nombre, 0, 15, 63, 57, PV[1], CurrRow1-1); break; case 3: InputCadenaG_l( Vend1.Apellido1, 0, 14, 63, 57, PV[2], CurrRow1-1); break; case 4: sprintf( buffer, "%ld", Vend1.Telefono1 ); InputCadenaG_l( buffer, 1, 12, 63, 57, PV[3], CurrRow1-1); Vend1.Telefono1 = atol( buffer ); break; default: return; } PutLineVend(); /*ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ*/ /*Û*/ GetLineVend(); /*Û*/ /*ßßßßßßßßßßßßßßßßßßßßßß*/ PrintLineVend(1); } else { Fuente(SMALL_FONT, 5); switch (CurrCol2) { case 1: InputCadenaG( Vend1.Nombre, 0, 15, 63, 57, PV[4] ); //PV[4] break; case 2: InputCadenaG( Vend1.Apellido1, 0, 14, 63, 57, PV[5] ); //PV[5] break; case 3: InputCadenaG( Vend1.Apellido2, 0, 15, 63, 57, PV[6] ); //PV[6] break; case 4: InputCadenaG( Vend1.DNI, 0, 15, 63, 57, PV[7] ); //PV[7] break; case 5: sprintf(buffer, "%ld", Vend1.Telefono1); InputCadenaG( buffer, 0, /*12*/9, 63, 57, PV[8] ); Vend1.Telefono1 = atol( buffer ); //PV[8] break; case 6: sprintf(buffer, "%ld", Vend1.Telefono2); InputCadenaG( buffer, 0, /*12*/9, 63, 57, PV[9] ); Vend1.Telefono2 = atol( buffer ); //PV[9] break; case 7: InputCadenaG( Vend1.Calle, 0, 30, 63, 57, PV[10] ); //PV[10] break; case 8: InputCadenaG( Vend1.Num, 0, 3, 63, 57, PV[11] ); //PV[11] break; case 9: InputCadenaG( Vend1.Piso, 0, 3, 63, 57, PV[12] ); //PV[12] break; case 10:InputCadenaG( Vend1.Poblacion, 0, 18, 63, 57, PV[13] ); //PV[13] break; case 11:InputCadenaG( Vend1.Provincia, 0, 16, 63, 57, PV[14] ); //PV[14] break; case 12:sprintf(buffer, "%ld", Vend1.CP); InputCadenaG( buffer, 0, 5, 63, 57, PV[15] ); Vend1.CP = atol( buffer ); //PV[15] break; case 13:sprintf(buffer, "%ld", Vend1.CC); InputCadenaG( buffer, 0, 5, 63, 57, PV[16] ); Vend1.CC = atol( buffer ); //PV[16] break; case 14:sprintf(buffer, "%d", Vend1.PP); InputCadenaG( buffer, 0, 2, 63, 57, PV[17] ); Vend1.PP = atoi( buffer ); //PV[17] break; default: return; } PutLineVend(); /*ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ*/ /*Û*/ GetLineVend(); /*Û*/ /*ßßßßßßßßßßßßßßßßßßßßßß*/ PrintLineVend(0); } } void Abre_Ficha_Vendedores(void){ char ArchivoDatos[]="SV_VEND.DAT"; //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ// //Û Comprueba apertura correcta de Indice, y Datos y creaci¢n... Û// //ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß// int LSJ = sizeof(struct JD); int LSI = sizeof(struct Vend_inx); int LSC = sizeof(struct Vendedores); if ( (Vend = fopen( ArchivoDatos, "r+b"))==NULL) { FILE *fa; if ( (fa = fopen( ArchivoDatos, "wb" ) )!=NULL ) { Poner_a_cero_estructura_actual_vend(); Vend1_inx.Fin = 0; rewind(fa); fwrite(&cabecera, LSJ, 1, fa); fseek(fa, (long)LSJ, SEEK_SET); fwrite(&Vend1_inx, LSI, 1, fa); fseek(fa, (long)LSJ+LSI, SEEK_SET); fwrite(&Vend1, LSC, 1, fa); if (fclose(fa) == EOF ) exit(1); } if ( (Vend = fopen( ArchivoDatos, "r+b"))==NULL) { restorecrtmode(); printf("NO SE PUDO ABRIR EL FICHERO INDICE EN LA 2§ PASADA"); exit(1); } } fseek(Vend, (long)LSJ, SEEK_SET); if ( fread(&Vend1_inx, LSI, 1, Vend) != 1 ) { restorecrtmode(); printf("NO SE PUDO LEER EN EL FICHERO: INDICE"); exit(1); } fseek(Vend, (long)LSJ+LSI, SEEK_SET); if ( fread(&Vend1, LSC, 1, Vend) != 1 ) { restorecrtmode(); printf("NO SE PUDO LEER EN EL FICHERO: DATOS"); exit(1); } } void DeleteRecordVend(void) { unsigned int CurrRecord; int LSJ = sizeof(struct JD); int LSI = sizeof(struct Vend_inx); int LSC = sizeof(struct Vendedores); int LSCl = sizeof(struct Clientes); int ok = 0; int Count=0, CF = 0; CurrRecord = CurrTopLine + CurrRow1 - 1; if ( Vend1_inx.Fin == 0 ) { //þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ Poner_a_cero_estructura_actual_vend(); PutLineVend(); PrintLineVend(1); BEEP(); //þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ } else { if ( Vend1.Cr > 0 ) do{ fseek(Clientes, (long)LSJ + LSI + LSCl*Count, SEEK_SET); // Se coloca fread(&Clientes1, LSCl, 1, Clientes); // Y lee if(Clientes1.Vend == Vend1.Num_V ) { Clientes1.Vend = -1; // El contrato es para la empresa fseek(Clientes, (long)LSJ + LSI + LSCl*Count, SEEK_SET); // Se coloca fwrite(&Clientes1, LSCl, 1, Clientes); // Y lee CF++; if(CF == Vend1.Cr) ok = 1; } Count++; }while(!ok || Count<= Clientes1_inx.Fin); Vend1_inx.Fin -= 1; unsigned int p = CurrRecord - 1; while( p <= Vend1_inx.Fin ) { fseek(Vend, (long)LSJ + LSI + ( LSC * ( p + 1 ) ), SEEK_SET); // Se coloca fread(&Vend1, LSC, 1, Vend); // Y lee fseek(Vend, (long)LSJ + LSI + ( LSC * p ), SEEK_SET); // Se coloca fwrite(&Vend1, LSC, 1, Vend); // Y escribe p++; }; fseek(Vend, (long)LSJ, SEEK_SET); fwrite(&Vend1_inx, LSI, 1, Vend); // Acualiza n§ de registros PrintWholeScreenVend(); if ((CurrRecord - 1) == Vend1_inx.Fin + 1) CurrRow1--; if( Vend1_inx.Fin == 0 ) CurrRow1 = 1; GetLineVend(); PrintLineVend(1); } } void AddRecordVend(void){ unsigned int CurrRecord= CurrTopLine + CurrRow1 - 1; int LSJ = sizeof(struct JD); int LSI = sizeof(struct Vend_inx); int LSC = sizeof(struct Vendedores); if(CurrRecord < 1000 ) { long avance = Vend1_inx.Fin /*+ 1*/; while( avance >= (CurrRecord-1) ) { fseek(Vend, (long)LSJ + LSI + ( LSC * avance ), SEEK_SET); // Se coloca fread(&Vend1, LSC, 1, Vend); // Y lee fseek(Vend, (long)LSJ + LSI + ( LSC * (avance + 1) ), SEEK_SET); // Se coloca fwrite(&Vend1, LSC, 1, Vend); // Y escribe avance--; }; // Vend1_inx.Fin = Vend1_inx.Fin + 1; Vend1_inx.Fin++; fseek(Vend, (long)LSJ, SEEK_SET); fwrite(&Vend1_inx, LSI, 1, Vend); // Acualiza n§ de registros Poner_a_cero_estructura_actual_vend(); fseek(Vend, (long)LSJ + LSI + ( LSC * ( CurrTopLine + CurrRow1 - 1) ), SEEK_SET); // Se coloca fwrite(&Vend1, LSC, 1, Vend); // Y escribe CurrRow1++; if (CurrRow1>/*12*/11) { CurrTopLine++; CurrRow1--; } PrintWholeScreenVend(); GetLineVend(); PrintLineVend(1); } } void PutLineVend(void){ int LSJ = sizeof(struct JD); int LSI = sizeof(struct Vend_inx); int LSC = sizeof(struct Vendedores); int CurrRecord = CurrTopLine + CurrRow1 - 1; fseek(Vend, (long)LSJ + LSI + ( LSC * CurrRecord ) - LSC, SEEK_SET); // Se coloca fwrite(&Vend1, LSC, 1, Vend); // Y escribe } void GetLineVend(void){ int LSJ = sizeof(struct JD); int LSI = sizeof(struct Vend_inx); int LSC = sizeof(struct Vendedores); int CurrRecord = CurrTopLine + CurrRow1 - 1; fseek(Vend, (long)LSJ + LSI + ( LSC * CurrRecord ) - LSC, SEEK_SET); // Se coloca fread(&Vend1, LSC, 1, Vend); // Y lee } void Poner_a_cero_estructura_actual_vend(void){ cabecera.esc = 27; strcpy(cabecera.color, "[31;40m"); strcpy(cabecera.prog, "Jos‚ David Guill‚n Dominguez"); cabecera.nl = 13; cabecera.rt = 10; strcpy(cabecera.autor, " 31 / Abril / 1995 "); cabecera.pt = 7; cabecera.ef = 26; // Vend1_inx.Fin = 0; Vend1.Num_V = 0; strcpy(Vend1.Nombre, "\0"); strcpy(Vend1.Apellido1, "\0"); strcpy(Vend1.Apellido2, "\0"); strcpy(Vend1.DNI, "\0"); Vend1.Telefono1 = 0; Vend1.Telefono2 = 0; strcpy(Vend1.Calle, "\0"); strcpy(Vend1.Num, "\0"); strcpy(Vend1.Piso, "\0"); strcpy(Vend1.Poblacion, "\0"); strcpy(Vend1.Provincia, "\0"); Vend1.CP = 41; Vend1.CC = 0; Vend1.PP = 0; Vend1.Cr = 0; } void Coloca_Nombres_a_botones(void){ Letra_Boton /*out*/textxy(Comunes[0].Left, Comunes[0].Up, " Subir" ); //out*/text(Comunes[0].Left, Comunes[0].Up+18, " -----" ); /*out*/textxy(Comunes[1].Left, Comunes[1].Up, " Buscar" ); /*out*/textxy(Comunes[1].Left, Comunes[1].Up+18, " F2 " ); /*out*/textxy(Comunes[2].Left, Comunes[2].Up, " Bajar" ); //out*/textxy(Comunes[2].Left, Comunes[2].Up+18, " -----" ); /*out*/textxy(Comunes[3].Left, Comunes[3].Up, " SWAP" ); /*out*/textxy(Comunes[3].Left, Comunes[3].Up+18, " F6 " ); /*out*/textxy(Comunes[4].Left, Comunes[4].Up, " Imprimir" ); /*out*/textxy(Comunes[4].Left, Comunes[4].Up+18, " F5 " ); /*out*/textxy(Comunes[5].Left, Comunes[5].Up, " A¤adir" ); /*out*/textxy(Comunes[5].Left, Comunes[5].Up+18, " F9 " ); /*out*/textxy(Comunes[6].Left, Comunes[6].Up, " SUpr." ); /*out*/textxy(Comunes[6].Left, Comunes[6].Up+18, " F10 " ); /*out*/textxy(Comunes[8].Left, Comunes[8].Up, " Salir" ); /*out*/textxy(Comunes[8].Left, Comunes[8].Up+18, " F1 " ); } void Imprimir_Vendedores(void){ int Where_Ask = 1; int fins_print= 0, key_print, bpush; void far *ptr; unsigned size; struct Make_Boton pregunta[3]; size = imagesize(198, 138, 372, 257); /* get byte size of image */ if ( (ptr = farmalloc(size)) != NULL) { getimage(198, 138, 372, 257, ptr); pregunta[0].Up = 140; pregunta[0].Down = 255; pregunta[0].Left= 200; pregunta[0].Right= 370; ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]); pregunta[0].Up = 150; pregunta[0].Down = 175; pregunta[0].Left= 210; pregunta[0].Right= 360; ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[0]); pregunta[1].Up = 185; pregunta[1].Down = 210; pregunta[1].Left= 210; pregunta[1].Right= 360; ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[1]); pregunta[2].Up = 220; pregunta[2].Down = 245; pregunta[2].Left= 210; pregunta[2].Right= 360; ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[2]); Fuente(SMALL_FONT, 4); } else { Where_Ask = 0; pregunta[0].Up = 450; pregunta[0].Down = 475; pregunta[0].Left= 5; pregunta[0].Right= 152; ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[0]); pregunta[1].Up = 450; pregunta[1].Down = 475; pregunta[1].Left= 155; pregunta[1].Right= 309; ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[1]); pregunta[2].Up = 450; pregunta[2].Down = 475; pregunta[2].Left= 312; pregunta[2].Right= 549; ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[2]); Fuente(SMALL_FONT, 4); } Letra_Boton outtextxy(pregunta[0].Left+2, pregunta[0].Up+2, "F3 Imprimir Ficha Actual"); outtextxy(pregunta[1].Left+2, pregunta[1].Up+2, "F2 Imprimir Lista R pida"); outtextxy(pregunta[2].Left+2, pregunta[2].Up+2, "F1 CANCELAR IMPRESION"); //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ do{ if(raton!=0) activa_raton(); Espera_Tecla_o_Raton(); if(raton!=0) desactiva_raton(); if(kbhit()){ key_print = getch(); if( key_print == 0 ) { switch( (key_print=getch()) ){ // F1 Cancelar case 59: fins_print = 1; break; // F3 Imprimir Ficha case 61: if(Where_Ask){ pregunta[0].Up = 140; pregunta[0].Down = 255; pregunta[0].Left= 200; pregunta[0].Right= 370; } else { pregunta[0].Up = 450; pregunta[0].Down = 475; pregunta[0].Left= 5; pregunta[0].Right= 549; } ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]); //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ if( Comprueba_Impresora() ) { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Imprimiendo."); outtextxy(210,170, "Por Favor, espere..."); } else outtextxy(10,452, "Imprimiendo. Por Favor, espere..."); Imprime_Ficha(); } else { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Impresora no preparada."); outtextxy(210,170, "Impresion Cancelada"); } else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); } Espera_Tecla_o_Raton(); } fins_print = 1; //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ break; // F2 Imprimir lista r pida case 60: if(Where_Ask){ pregunta[0].Up = 140; pregunta[0].Down = 255; pregunta[0].Left= 200; pregunta[0].Right= 370; } else { pregunta[0].Up = 450; pregunta[0].Down = 475; pregunta[0].Left= 5; pregunta[0].Right= 549; } ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]); //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ if(Comprueba_Impresora()) { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Imprimiendo."); outtextxy(210,170, "Por Favor, espere..."); } else outtextxy(10,452, "Imprimiendo. Por Favor, espere..."); Imprime_Lista_Rapida(); } else { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Impresora no preparada."); outtextxy(210,170, "Impresion Cancelada"); } else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); } Espera_Tecla_o_Raton(); } fins_print = 1; //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ break; default: fins_print = 1; } } } else if(raton!=0 && boton_izq==1 || boton_der==1) { if( (bpush = CheckButon( 3, pregunta))>0 ) { if(Where_Ask){ pregunta[0].Up = 140; pregunta[0].Down = 255; pregunta[0].Left= 200; pregunta[0].Right= 370; } else { pregunta[0].Up = 450; pregunta[0].Down = 475; pregunta[0].Left= 5; pregunta[0].Right= 549; } ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]); switch(bpush){ // Imprimir Ficha case 1: //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ if(Comprueba_Impresora()) { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Imprimiendo."); outtextxy(210,170, "Por Favor, espere..."); } else outtextxy(10,452, "Imprimiendo. Por Favor, espere..."); Imprime_Ficha(); } else { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Impresora no preparada."); outtextxy(210,170, "Impresion Cancelada"); } else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); } Espera_Tecla_o_Raton(); } fins_print = 1; //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ break; // Imprime Lista R pida case 2: //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ if(Comprueba_Impresora()) { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Imprimiendo."); outtextxy(210,170, "Por Favor, espere..."); } else outtextxy(10,452, "Imprimiendo. Por Favor, espere..."); Imprime_Lista_Rapida(); } else { Letra_Boton if(Where_Ask){ outtextxy(210,150, "Impresora no preparada."); outtextxy(210,170, "Impresion Cancelada"); } else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); } Espera_Tecla_o_Raton(); } fins_print = 1; //ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ break; // Cancelar case 3: fins_print=1; break; default: fins_print = 1; } } } }while(!fins_print); //ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß if(Where_Ask == 1) { putimage(198, 138, ptr, COPY_PUT); farfree(ptr); } else { struct Make_Boton help; help.Up = 450; help.Down = 475; help.Left = 5; help.Right = 549; ImprimeBoton (1, GRIS_C, GRIS_O, BLANCO, help); } } void Imprime_Ficha(void){ fprintf( stdprn, "\n\r"); fprintf( stdprn, "N£mero Vendedor: %03d\n\r", Vend1.Num_V); fprintf( stdprn, "\n\r\n\r"); fprintf( stdprn, "Nombre: %s %s, %s\n\r", Vend1.Apellido1, Vend1.Apellido2, Vend1.Nombre ); fprintf( stdprn, "\n\r"); fprintf( stdprn, "D.N.I.: %-15s \n\r\n\rTel‚fono(s): %12ld %12ld\n\r", Vend1.DNI, Vend1.Telefono1, Vend1.Telefono2 ); fprintf( stdprn, "\n\r"); fprintf( stdprn, "Calle: %-30s, %-3s, %-3s\n\r", Vend1.Calle, Vend1.Num, Vend1.Piso ); fprintf( stdprn, "\n\r"); fprintf( stdprn, "Poblaci¢n: %-18s Provincia: %-16s C.P.: %ld\n\r", Vend1.Poblacion, Vend1.Provincia, Vend1.CP ); fprintf( stdprn, "\n\r"); fprintf( stdprn, "\n\r"); fprintf( stdprn, "Comisi¢n por Contrato: %05ld Porcentaje por producto: %03d\n\r", Vend1.CC, Vend1.PP); fprintf( stdprn, "\n\r"); fprintf( stdprn, "\n\r"); fprintf( stdprn, "CONTRATOS REALIZADOS (y aun activos) ---> %04d <---", Vend1.Cr); fputc(12, stdprn); } void Imprime_Lista_Rapida(void){ int LSJ = sizeof(struct JD); int LSI = sizeof(struct Vend_inx); int LSC = sizeof(struct Vendedores); int lprint = 3; // 1 2 3 4 5 6 7 8 // 123456789þ123456789þ123456789þ123456789þ123456789þ123456789þ123456789þ123456789þ int Curr_Vend = 0; fprintf( stdprn, "\n\r"); fprintf( stdprn, " Num_V Nombre Apellido Tel‚fono Contratos Activos\n\r"); fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r"); while(Curr_Vend <= Vend1_inx.Fin ){ fseek(Vend, (long)LSJ + LSI + ( LSC * Curr_Vend ), SEEK_SET); // Se coloca fread(&Vend1, LSC, 1, Vend); // Y lee fprintf( stdprn, " %03d %-15s %-15s % 12ld % 12ld %04d\n\r", Vend1.Num_V, Vend1.Nombre, Vend1.Apellido1, Vend1.Telefono1, Vend1.Telefono2, Vend1.Cr); lprint++; if (lprint==55) { lprint = 3; fputc(12, stdprn); fprintf( stdprn, " Num_V Nombre Apellido Tel‚fono Contratos Activos\n\r"); fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r"); } Curr_Vend++; } fputc(12, stdprn); } void CompruebaLineasVend(void){ // Check una pulsacion sobre un campo, y se situa, si es posible int ok_p=0, inc=0, md=0; int oldr, oldc; // if(SWAP) Anclar_Raton(); do{ inc++; if(x_raton >= (PV[(inc)-1].Left+2) && x_raton <= (PV[inc-1].Right-2) ) { ok_p=1; md = 1; oldc=inc; } if(inc==4) ok_p=1; }while(!ok_p); if(md==1){ inc=0; ok_p=0; md = 0; do{ inc++; if( (y_raton >= (PV[(oldc)-1].Up+4+(inc-1)*15+2)) && (y_raton <= (PV[oldc-1].Up+4+(inc-1)*15+16)) ) { ok_p=1; oldr=inc; md = 1;} if(inc==11) ok_p=1; }while(!ok_p); } if( (md==1) && ((CurrCol1!=oldc) || (CurrRow1!=oldr)) ) { if( (CurrTopLine + oldr - 2 )<= Vend1_inx.Fin ){ EditCursorVend(1); SWAP = 1; CurrCol1 = oldc; CurrRow1 = oldr; GetLineVend(); PrintLineVend(1); } } if( (md==0) && (inc = CheckButon_S( 19, 4, PV))>4 && (inc <=18) ) { EditCursorVend(1); SWAP = 0; CurrCol2 = (inc - 4); } } /* int Confirma(char *f1, char *f2, char *f3){ return 1; } */ /* int comprueba_impresora(void){ return 1; } */