CATALOGO/ADDVIEW2.CPP
2021-09-03 17:43:05 +02:00

1458 lines
38 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//////////////////////////////////////////////////////////////////////////
///// Nombre: CAddView.CPP ///
///// Modulo: Perteneciente a Catalogo.C ///
//// Descripci¢n: M¢dulo para editar o modificar los programas ///
//// ///
//// Autor: Jos David Guilln Dominguez ///
//// Fecha: 20 - 07 - 1994 ///
//// ///
//// Comentario: Abandono de Punteros a estructuras... ///
//// Imposible SEEK a modo "a+b" (modo actual "r/w+b") ///
//// ///
//// Compilador Borland C++ 3.0 ///
///////////////////////////////////////////////////////////////////////////
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <graphics.h>
///////////////////////////////////////////////////////////////////////////
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
///////////////////////////////////////////////////////////////////////////
struct JD {
char esc;
char color[8];
char prog[14];
char nl; char rt;
char autor[36];
char pt; char ef;
};
struct caddview_inx {
unsigned int Fin[4]; unsigned int FinC;
};
struct caddview {
unsigned int record_zone ; int nombre_zona ;
char nombre[13+1] ; char zip[3+1] ; int kbytes ;
};
struct caddviewComentario {
int record_zone_init; // Zona de grabaci¢n interna
char linea[10][32 + 1]; // 32 digitos * 10 lineas
};
struct JD cabecera;
struct caddview JD;
struct caddview_inx JDn;
struct caddviewComentario JD_comment;
FILE *JD_f; // Fichero JD
FILE *JDc_f; // Fichero COMENTARIO
///////////////////////////////////////////////////////////////////////////
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
///////////////////////////////////////////////////////////////////////////
extern struct pedidos_descripcion {
unsigned int n_records; // n§ de grabaciones en el fichero
char nombre[24+1]; // Nombre 24 digitos + NULL
char apelli[21+1]; // Apellidos 21 digitos + NULL
char direcc[21+1]; // Direcci¢n 21 digitos + NULL
long telefono; // Telfono 5 digitos permitidos
char cpu[10 + 1]; // C.P.U. 10 digitos + NULL
int ram; // R.A.M 2 digitos permitidos
int hd; // HD. 4 digitos permitidos
};
extern struct pedidos_datos {
unsigned int record_zone ; int record_name;
char nombre[13+1] ; char zip[3+1] ; int kbytes ;
};
extern struct pedidos_descripcion JD_dp; // Descripci¢n...
extern struct pedidos_datos JD_dt; // Datos...
extern FILE *JD_p; // Fichero Pedidos
// Variables de posici¢n y registro
int CurrRow, CurrCol, x, pc;
unsigned int CurrTopLine; int n_registros=0;
int ilumina, M_M; int Registros[ 40 ]; int Dir_Registros[ 40 ];
int PWS, Zx;
char ArchivoDatos[13], ArchivoComentario[13];
union REGS ent, sal;
///////////////////////////////////////////////////////////////////////////
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
///////////////////////////////////////////////////////////////////////////
extern struct boton { int left; int up; int right; int down; };
extern int boton_izq; extern int boton_der;
extern int x_raton; extern int y_raton;
extern int raton;
extern int bpush;
extern int sb;
extern int InputCadenaG(char *s, int numalp, int lmax, int px, int py, int cc, int cf);
extern void inicializa_raton_grafico(int x1, int y1, int x2, int y2, int px, int py);
extern void ImprimeBoton2 (int fill, int cdf, int cs1, int cs2, struct boton parm);
extern int CheckButon(int nb, struct boton menu[]);
extern void Sound_SN(char *headfile);
extern void BorraViewPort(int view);
extern void desactiva_raton(void);
extern void activa_raton(void);
void Editar_Modificar(int Mirar_Modificar, int X);
void EditCursorC(int ShowHide, int y);
void EditCursorE(int ShowHide);
void EditCursor(int ShowHide);
void PrintLine(int permiso);
void PrintWholeScreen(void);
void PideComentario(void);
void Delete_Pedidos(void);
void DeleteRecord(void);
void Add_Pedidos(void);
void AddRecord(void);
void EditItem(void);
void MoveDown(void);
void GetLine(void);
void PutLine(void);
void MoveUp(void);
void Editar_Modificar(int Mirar_Modificar, int X)
{
// union REGS ent, sal;
char ArchivoPedidos[]="CPedidos.DAT";
int finished, key;
int inicio;
M_M = Mirar_Modificar;
Zx = X;
switch ( X ) {
case 1: case 2: case 3: case 4:
x = X - 1; break;
case 5: case 6: case 7: case 8:
x = X - 5; break;
case 9: case 10: case 11: case 12:
x = X - 9; break;
default:
printf("Salida por --DEFECTO-- %d", X);
exit(1);
break;
}
CurrRow = 1; CurrCol = 1; CurrTopLine = 1;
struct boton menu[8];
menu[0]. left = 217; menu[0]. up = 34; menu[0]. right = 297; menu[0]. down = 65;
menu[1]. left = 217; menu[1]. up = 66; menu[1]. right = 297; menu[1]. down = 97;
menu[2]. left = 217; menu[2]. up = 98; menu[2]. right = 297; menu[2]. down = 129;
menu[3]. left = 217; menu[3]. up = 130; menu[3]. right = 256; menu[3]. down = 149;
menu[4]. left = 258; menu[4]. up = 130; menu[4]. right = 297; menu[4]. down = 149;
menu[5]. left = 217; menu[5]. up = 150; menu[5]. right = 256; menu[5]. down = 171;
menu[6]. left = 258; menu[6]. up = 150; menu[6]. right = 297; menu[6]. down = 171;
menu[7]. left = 217; menu[7]. up = 172; menu[7]. right = 297; menu[7]. down = 204;
for(auto int i=0; i<8; i++) ImprimeBoton2 (1, 7, 63, 56, menu[i]);
setcolor(15);
outtextxy(222, 50 , "ADD F9 ");
outtextxy(222, 80 , "DEL F10");
if(Mirar_Modificar) {
outtextxy(223, 107, " Comment ");
outtextxy(223, 115," F3 ");
}
outtextxy(222, 136, " UP ");
outtextxy(263, 136, "DOWN");
outtextxy(222, 156, "RePg");
outtextxy(262, 156, "AvPg");
outtextxy(222, 180, "Salir F2");
setcolor(0);
outtextxy(221, 49 , "ADD F9 ");
outtextxy(221, 79 , "DEL F10");
if(Mirar_Modificar) {
outtextxy(222, 106, " Comment ");
outtextxy(222, 114," F3 ");
}
outtextxy(221, 135, " UP ");
outtextxy(262, 135, "DOWN");
outtextxy(221, 155, "RePg");
outtextxy(261, 155, "AvPg");
outtextxy(221, 179, "Salir F2");
switch (X) {
case 1: case 2: case 3: case 4:
strcpy(ArchivoDatos, "CATALOG1.DAT");
strcpy(ArchivoComentario, "CATALO11.DAT");
pc = 0;
break;
case 5: case 6: case 7: case 8:
strcpy(ArchivoDatos, "CATALOG2.DAT");
strcpy(ArchivoComentario, "CATALO21.DAT");
pc = 1;
break;
case 9: case 10: case 11: case 12:
default:
strcpy(ArchivoDatos, "CATALOG3.DAT");
strcpy(ArchivoComentario, "CATALO31.DAT");
pc = 2;
break;
}
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
//ÛÛ Comprueba apertura correcta de Indice, y Datos y creaci¢n... ÛÛ//
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
{
auto int LSJ = sizeof(struct JD);
auto int LSI = sizeof(struct caddview_inx);
auto int LSC = sizeof(struct caddview);
if ( (JD_f = fopen( ArchivoDatos, "r+b"))==NULL) {
FILE *fa;
auto int i;
if ( (fa = fopen( ArchivoDatos, "wb" ) )!=NULL ) {
cabecera.esc = 27;
strcpy(cabecera.color, "[31;40m");
strcpy(cabecera.prog, "Catalogo 4.0");
cabecera.nl = 13; cabecera.rt = 10;
strcpy(cabecera.autor, " Jos David Guilln");
cabecera.pt = 7; cabecera.ef = 26;
JDn.Fin[0] = 0; JDn.Fin[2] = 2;
JDn.Fin[1] = 1; JDn.Fin[3] = 3;
JDn.FinC = 1;
JD.record_zone = 0; JD.nombre_zona = x + 1;
strcpy(JD.nombre, "\0"); strcpy(JD.zip, "\0");
JD.kbytes = 0;
rewind(fa);
fwrite(&cabecera, LSJ, 1, fa);
fseek(fa, (long)LSJ, SEEK_SET);
fwrite(&JDn, LSI, 1, fa);
fseek(fa, (long)LSJ+LSI, SEEK_SET);
for (i = 0; i < 4; i++) fwrite(&JD, LSC, 1, fa);
if (fclose(fa) == EOF ) exit(1);
}
if ( (JD_f = fopen( ArchivoDatos, "r+b"))==NULL) {
printf("NO SE PUDO ABRIR EL FICHERO INDICE EN LA 2§ PASADA");
exit(1);
}
}
fseek(JD_f, (long)LSJ, SEEK_SET);
if ( fread(&JDn, LSI, 1, JD_f) != 1 ) {
printf("NO SE PUDO LEER EN EL FICHERO: INDICE");
exit(1);
}
fseek(JD_f, (long)LSJ+LSI, SEEK_SET);
if ( fread(&JD, LSC, 1, JD_f) != 1 ) {
printf("NO SE PUDO LEER EN EL FICHERO: DATOS");
exit(1);
}
}
if ( x==0 ) CurrTopLine = 0; else CurrTopLine = ( JDn.Fin[x - 1] + 1 );
inicio = CurrTopLine;
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
//ÛÛ Comprueba apertura correcta de COMENTARIO o creaci¢n... ÛÛ//
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
if ( (JDc_f = fopen( ArchivoComentario, "r+b"))==NULL) {
FILE *fa;
if ( (fa = fopen( ArchivoComentario, "wb" ) )!=NULL ) {
auto int i;
auto int LSC = sizeof(struct caddviewComentario);
JD_comment.record_zone_init = 0; // 0 => disponible para grabaci¢n
// 1 => datos importantes
for(i=0; i<10; i++)
strcpy(JD_comment. linea[i], "\0");
fwrite(&JD_comment, LSC, 1, fa);
if (fclose(fa) == EOF ) exit(1);
}
if ( (JDc_f = fopen( ArchivoComentario, "r+b"))==NULL) {
printf("NO SE PUDO ABRIR EL FICHERO COMENTARIO EN LA 2§ PASADA");
exit(1);
}
}
if ( fread(&JD_comment, sizeof(struct caddviewComentario), 1, JDc_f) != 1 ) {
printf("NO SE PUDO LEER EL FICHERO COMENTARIO");
exit(1);
}
if(!Mirar_Modificar) {
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
//ÛÛ Comprueba apertura correcta de Pedidos o creaci¢n... ÛÛ//
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
if ( (JD_p = fopen( ArchivoPedidos, "r+b"))==NULL) {
FILE *fa;
if ( (fa = fopen( ArchivoPedidos, "wb" ) )!=NULL ) {
JD_dp. n_records = 1;
strcpy(JD_dp. nombre, "\0"); strcpy(JD_dp. direcc, "\0");
strcpy(JD_dp. apelli, "\0"); strcpy(JD_dp. cpu, "\0");
JD_dp. telefono = 0; JD_dp. ram = 0; JD_dp. hd = 0;
rewind(fa);
fwrite(&JD_dp, sizeof(struct pedidos_descripcion), 1, fa);
JD_dt. record_zone = 0;
JD_dt. record_name = 0;
strcpy(JD_dt. nombre, "\0");
strcpy(JD_dt. zip, "\0");
JD_dt. kbytes = 0;
fwrite(&JD_dt, sizeof(struct pedidos_datos), 1, fa);
if (fclose(fa) == EOF ) exit(1);
}
if ( (JD_p = fopen( ArchivoPedidos, "r+b"))==NULL) {
printf("NO SE PUDO ABRIR EL FICHERO PEDIDOS EN LA 2§ PASADA");
exit(1);
}
}
if ( fread(&JD_dp, sizeof(struct pedidos_descripcion), 1, JD_p) != 1 ) { // Lee n§ de registros
printf("NO SE PUDO LEER EL FICHERO PEDIDOS");
exit(1);
}
//////////// Ahora se procedera a la lectura y asignaci¢n de las se¤alaciones
finished = 1;
{
auto int LSC = sizeof(struct pedidos_datos);
auto int LSCm = sizeof(struct pedidos_descripcion);
n_registros = 0;
while(finished<=JD_dp. n_records) {
fseek(JD_p, (long)LSCm + LSC * finished - LSC, SEEK_SET);
fread(&JD_dt, LSC, 1, JD_p);
if( JD_dt.record_name == Zx ) {
n_registros++;
Registros[ n_registros ] = JD_dt. record_zone;
Dir_Registros[ n_registros ] = finished;
}
finished++;
}
}
}
PrintWholeScreen();
GetLine();
if ( CurrRow >= 11 ) PrintLine(0); else PrintLine(1);
finished = 0;
if(raton) inicializa_raton_grafico(0, 0, 624, 464, 320, 240);
do{
if(Mirar_Modificar) EditCursor(0); else EditCursorE(0);
if(raton) activa_raton();
/////////////////////// Aqui va una pausa de TECLADO y RATON al mismo TIEMPO
do{
if(raton){
ent.x.ax = 3;
int86(0x33, &ent, &sal); // lee posici¢n y estados del bot¢n
boton_izq = sal.x.bx & 1;
boton_der = (sal.x.bx >> 1) & 1;
x_raton = sal.x.cx;
y_raton = sal.x.dx;
} else boton_izq = 0;
}while( !boton_izq && !kbhit() );
if(raton) desactiva_raton();
if( kbhit() ) {
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// ¨ Hay una tecla en buffer ...
key = getch();
if(Mirar_Modificar) EditCursor(1); else EditCursorE(1);
if( ( isprint(key) || isspace(key) ) && Mirar_Modificar ) {
if(key!=13) ungetch(key);
EditItem();
} else {
if( key == 0 ) {
key = getch();
switch ( key ) {
// INICIO
case 71:
CurrCol = 1;
break;
// FIN
case 79:
CurrCol = 3;
break;
// FLECHA ARRIBA
case 72:
MoveUp();
break;
// FLECHA ABAJO
case 80:
MoveDown();
break;
// FLECHA IZQUIERDA
case 75:
case 15:
CurrCol--;
if (CurrCol == 0) CurrCol = 3;
break;
// FLECHA DERECHA
case 77:
case 9:
CurrCol++;
if (CurrCol == 4) CurrCol = 1;
break;
// F3 ---> A¥ADE COMENTARIO
case 61:
if(Mirar_Modificar) {
EditCursor(0);
PideComentario();
PutLine();
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//Û Redise¤a botones Û
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
for(auto int i=0; i<8; i++) ImprimeBoton2 (1, 7, 63, 56, menu[i]);
setcolor(15);
outtextxy(222, 50 , "ADD F9 ");
outtextxy(222, 80 , "DEL F10");
outtextxy(223, 107, " Comment ");
outtextxy(223, 115," F3 ");
outtextxy(222, 136, " UP ");
outtextxy(263, 136, "DOWN");
outtextxy(222, 156, "RePg");
outtextxy(262, 156, "AvPg");
outtextxy(222, 180, "Salir F2");
setcolor(0);
outtextxy(221, 49 , "ADD F9 ");
outtextxy(221, 79 , "DEL F10");
outtextxy(222, 106, " Comment ");
outtextxy(222, 114," F3 ");
outtextxy(221, 135, " UP ");
outtextxy(262, 135, "DOWN");
outtextxy(221, 155, "RePg");
outtextxy(261, 155, "AvPg");
outtextxy(221, 179, "Salir F2");
}
break;
// ReP g
case 73:
CurrRow = 1;
if( CurrTopLine > 19 ) { CurrTopLine -= 19; } else { CurrTopLine = inicio; }
if(CurrTopLine < inicio ) { CurrTopLine = inicio; }
PrintWholeScreen();
GetLine();
break;
// AvP g
case 81:
CurrRow = 1;
CurrTopLine += 19;
if (CurrTopLine > JDn.Fin[x])
CurrTopLine = JDn.Fin[x];
PrintWholeScreen();
GetLine();
break;
// F2 --> PARA SALIR
case 60:
finished = 1;
break;
// F9 --> A¥ADIR
case 67:
if(Mirar_Modificar) AddRecord();
else Add_Pedidos();
break;
// F10 -> BORRAR
case 68:
if(Mirar_Modificar) DeleteRecord();
else Delete_Pedidos();
break;
default:
if (sb) Sound_SN("catalog3");
break;
} // Fin de Swicth
} // Fin Key = 0
} // Fin Is Print Key?
} // Fin Tecla en Buffer
/////////////////////////////////////////////////////////////////////////////
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ//
////////////////////////// Comprueba con rat¢n ( SI ) ///////////////////////
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß//
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////// ... o es el RATON ?
if(raton && boton_izq==1 || boton_der==1) {
if( CheckButon(8, menu) ) {
if(Mirar_Modificar) EditCursor(1); else EditCursorE(1);
switch ( bpush ) {
// F9 --> A¥ADIR
case 1:
if(Mirar_Modificar) AddRecord();
else Add_Pedidos();
break;
// F10 -> BORRAR
case 2:
if(Mirar_Modificar) DeleteRecord();
else Delete_Pedidos();
break;
// F3 ---> A¥ADE COMENTARIO
case 3:
if(Mirar_Modificar) {
EditCursor(0);
PideComentario();
PutLine();
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//Û Redise¤a botones Û
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
for(auto int i=0; i<8; i++) ImprimeBoton2 (1, 7, 63, 56, menu[i]);
setcolor(15);
outtextxy(222, 50 , "ADD F9 ");
outtextxy(222, 80 , "DEL F10");
outtextxy(223, 107, " Comment ");
outtextxy(223, 115," F3 ");
outtextxy(222, 136, " UP ");
outtextxy(263, 136, "DOWN");
outtextxy(222, 156, "RePg");
outtextxy(262, 156, "AvPg");
outtextxy(222, 180, "Salir F2");
setcolor(0);
outtextxy(221, 49 , "ADD F9 ");
outtextxy(221, 79 , "DEL F10");
outtextxy(222, 106, " Comment ");
outtextxy(222, 114," F3 ");
outtextxy(221, 135, " UP ");
outtextxy(262, 135, "DOWN");
outtextxy(221, 155, "RePg");
outtextxy(261, 155, "AvPg");
outtextxy(221, 179, "Salir F2");
}
break;
// FLECHA ARRIBA
case 4:
MoveUp();
break;
// FLECHA ABAJO
case 5:
MoveDown();
break;
// ReP g
case 6:
CurrRow = 1;
if(CurrTopLine > 19) { CurrTopLine = CurrTopLine - 19; } else { CurrTopLine = inicio; }
if(CurrTopLine < inicio ) { CurrTopLine = inicio; }
PrintWholeScreen();
GetLine();
break;
// AvP g
case 7:
CurrRow = 1;
CurrTopLine = CurrTopLine + 19;
if (CurrTopLine > JDn.Fin[x])
CurrTopLine = JDn.Fin[x];
PrintWholeScreen();
GetLine();
break;
// F2 --> PARA SALIR
case 8:
finished = 1;
break;
default:
if (sb) Sound_SN("catalog3");
break;
} // Fin de Swicth
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
}while( !finished );
fclose(JD_f); // Fichero JD
fclose(JDc_f); // Fichero COMENTARIO
if(!Mirar_Modificar) fclose(JD_p);
BorraViewPort(1);
BorraViewPort(2);
BorraViewPort(3);
} // End Function //
void EditCursor(int ShowHide) {
int cc, cf, lmax, i, py, pxx, Px;
// registro de color actual y de fondo
// Longitud M xima y contador de bucle
// desviaci¢n vertical y reajuste final
// desviaci¢n horizontal y "" ""
if( CurrRow >= 11 ) {
Px = CurrCol + 3;
py = 18 + (CurrRow) - 10; // 8 = 18 - 10
} else {
Px = CurrCol;
py = 18 + (CurrRow);
}
switch (Px) {
case 1: pxx = 28; lmax = 13;
break;
case 2: pxx = 42; lmax = 3; // 43 Retirado
break;
case 3: pxx = 46; lmax = 5; // 47 Retirado para lmax = 5
break;
case 4: pxx = 52; lmax = 13;
break;
case 5: pxx = 66; lmax = 3; // 67 Retirado
break;
case 6: pxx = 70; lmax = 5; // 71 Retirado para lmax = 5
break;
default: pxx = 1; lmax = 80;
break;
}
if (!ShowHide) {
cc = 63;
cf = 57;
} else {
cc = 14;
cf = 0;
}
setcolor(cf); // pone color de fondo '0' para borrar
for (i=0; i<lmax; i++) // limpia linea -imprimir sobre fondo-
outtextxy( ( pxx + i ) * 8 - 7, py * 16 - 16, "Û");
setcolor(cc); // devuelve el color a su estado
switch (Px) {
case 1:
case 4:
outtextxy( ( pxx ) * 8 - 7, py * 16 - 16, JD.nombre );
break;
case 2:
case 5:
outtextxy( ( pxx ) * 8 - 7, py * 16 - 16, JD.zip );
break;
case 3:
case 6:
char string[6];
sprintf(string, "%5d", JD.kbytes);
// itoa( ( JD.kbytes), string, 10 );
outtextxy( ( pxx ) * 8 - 7, py * 16 - 16, string );
break;
default:
outtextxy( ( pxx ) * 8 - 7, py * 16 - 16, "ERROR Modulo SHOW_HIDE-Cursor, secci¢n CADDVIEW, P_CATALOGO");
break;
}
}
void EditCursorE(int ShowHide) {
int cc, cf, lmax, i, py, pxx, Px;
// registro de color actual y de fondo
// Longitud M xima y contador de bucle
// desviaci¢n vertical y reajuste final
// desviaci¢n horizontal y "" ""
if( CurrRow >= 11 ) { Px = CurrCol + 3; py = 18 + (CurrRow) - 10;
} else { Px = CurrCol; py = 18 + (CurrRow); }
switch (Px) {
case 1: case 2: case 3:
pxx = 28; lmax = 23; break;
case 4: case 5: case 6:
pxx = 52; lmax = 23; break;
default: pxx = 1; lmax = 80; break;
}
if (!ShowHide) { cc = 63; cf = 57; } else if (ShowHide) { cc = 14; cf = 0; }
if (ilumina)
if(!ShowHide) { cc = 57; cf = 63; } else
if (ShowHide) { cc = 0; cf = 14; }
setcolor(cf); // pone color de fondo '0' para borrar
for (i=0; i<lmax; i++) // limpia linea -imprimir sobre fondo-
outtextxy( ( pxx + i ) * 8 - 7, py * 16 - 16, "Û");
setcolor(cc); // devuelve el color a su estado
outtextxy( ( pxx ) * 8 - 7, py * 16 - 16, JD.nombre );
outtextxy( ( pxx + 14) * 8 - 7, py * 16 - 16, JD.zip );
char string[6];
// itoa( ( JD.kbytes), string, 10 );
sprintf(string, "%5d", JD.kbytes);
outtextxy( ( pxx + 18) * 8 - 7, py * 16 - 16, string );
}
void EditItem(void) {
int lmax, pxx, py, Px;
if ( CurrRow >= 11 ) {
Px = CurrCol + 3;
py = 18 + (CurrRow) - 10;
} else {
Px = CurrCol;
py = 18 + (CurrRow);
}
switch (Px) {
case 1: pxx = 28; lmax = 13;
break;
case 2: pxx = 42; lmax = 3; // 43 Retirado
break;
case 3: pxx = 46; lmax = 5; // 47 Retirado para lmax = 5
break;
case 4: pxx = 52; lmax = 13;
break;
case 5: pxx = 66; lmax = 3; // 67 Retirado
break;
case 6: pxx = 70; lmax = 5; // 71 Retirado para lmax = 5
break;
default: pxx = 1; lmax = 80;
break;
}
switch (Px) {
case 1:
case 4:
InputCadenaG( JD.nombre, 0, lmax, pxx, py, 63, 57);
break;
case 2:
case 5:
InputCadenaG( JD.zip, 0, lmax, pxx, py, 63, 57);
break;
case 3:
case 6:
char cadena[] = "32766";
itoa( (JD.kbytes), cadena, 10 );
do{
if ( atoi(cadena) < 0 || atoi(cadena) > 32765 ) strcpy(cadena, "0");
InputCadenaG( cadena, 1, lmax, pxx, py, 63, 57);
}while( atoi(cadena) < 0 || atoi(cadena) > 32765);
JD.kbytes = atoi(cadena);
break;
}
PutLine();
GetLine();
if ( CurrRow >= 11 ) /* N£mero de lineas DISPONIBLES */
PrintLine(0);
else PrintLine(1);
}
void MoveUp(void) {
if(CurrRow==1) { if (sb) Sound_SN("catalog3"); } else {
CurrRow--;
GetLine();
if ( CurrRow >= 11 ) PrintLine(0); else PrintLine(1);
}
}
void MoveDown(void) {
if( (CurrRow + CurrTopLine - 1) >= (JDn.Fin[x]) || CurrRow == 20 ) { if (sb) Sound_SN("catalog3"); } else {
CurrRow++;
GetLine();
if ( CurrRow >= 11 ) PrintLine(0); else PrintLine(1);
}
}
void PrintLine( int permiso ) {
unsigned int CurrRecord = CurrTopLine + CurrRow - 1;
int py, i;
if ( CurrRow >= 11 ) py = 18 + (CurrRow) - 10; else py = 18 + (CurrRow);
BorraViewPort(2); // Para los mensajes...
if(!M_M && ilumina) {
auto int pxx;
switch (permiso) {
case 0:
pxx = 52; break;
case 1:
pxx = 28; break;
}
setcolor(14); // pone color de fondo '0' para borrar
for (i=0; i<23; i++) // limpia linea -imprimir sobre fondo-
outtextxy( ( pxx + i ) * 8 - 7, py * 16 - 16, "Û");
setcolor( 0); // devuelve el color a su estado
} else setcolor(14); // devuelve el color a su estado
if ( CurrRecord <= (JDn.Fin[x]) ) {
// | Me preparo para convertir
char kbytes[6]; // | los int a char
// para que puedan ser utilizados
// itoa( JD.kbytes, kbytes, 10); // por outtext y outtextxy...
sprintf(kbytes, "%5d", JD.kbytes);
switch(permiso) {
case 0:
outtextxy( ( 52 ) * 8 - 7, py * 16 - 16, JD.nombre);
outtextxy( ( 66 ) * 8 - 7, py * 16 - 16, JD.zip);
outtextxy( ( 70 ) * 8 - 7, py * 16 - 16, kbytes);
break;
case 1:
outtextxy( ( 28 ) * 8 - 7, py * 16 - 16, JD.nombre);
outtextxy( ( 42 ) * 8 - 7, py * 16 - 16, JD.zip);
outtextxy( ( 46 ) * 8 - 7, py * 16 - 16, kbytes);
break;
default:
outtextxy( ( 1 ) * 8 - 7, py * 16 - 16, "ERROR Modulo PrintLine, seccion CADDVIEW, P_CATALOGO _-JD-_");
break;
}
if(PWS) {
if(!M_M && ilumina) setcolor(14);
if (JD. record_zone == 0) {
outtextxy( 43 * 8 - 7, (4 + 4) * 16 - 16, " Sin comentario");
} else {
for(i=0; i<10; i++)
outtextxy( 42 * 8 - 7, (i + 4) * 16 - 16, JD_comment.linea[i] );
}
}
}
}
void DeleteRecord(void) {
unsigned int CurrRecord;
int LSCm = sizeof(struct caddviewComentario);
auto int LSJ = sizeof(struct JD);
auto int LSI = sizeof(struct caddview_inx);
auto int LSC = sizeof(struct caddview);
CurrRecord = CurrTopLine + CurrRow - 1;
if (CurrRecord == 1 || CurrRecord == (JDn.Fin[x - 1]+1) ) { if (sb) Sound_SN("catalog5"); } else {
for(int Rg=x; Rg< 4; Rg++) JDn.Fin[Rg] -= 1;
if (JD.record_zone != 0) {
JD_comment.record_zone_init = 0;
fseek(JDc_f, (long)( LSCm * (JD.record_zone - 1) ), SEEK_SET); // Se coloca
fwrite(&JD_comment, LSCm, 1, JDc_f); // Y escribe
}
unsigned int p = CurrRecord;
while(p <= JDn.Fin[3]) {
fseek(JD_f, (long)LSJ + LSI + ( LSC * ( p + 1 ) ), SEEK_SET); // Se coloca
fread(&JD, LSC, 1, JD_f); // Y lee
fseek(JD_f, (long)LSJ + LSI + ( LSC * p ), SEEK_SET); // Se coloca
fwrite(&JD, LSC, 1, JD_f); // Y escribe
p++;
};
fseek(JD_f, (long)LSJ, SEEK_SET);
fwrite(&JDn, LSI, 1, JD_f); // Acualiza n§ de registros
int TmpRow = CurrRow;
int TmpCol = CurrCol;
PrintWholeScreen();
CurrRow = TmpRow; CurrCol = TmpCol;
if ( (CurrTopLine + CurrRow - 1) > (JDn.Fin[x]) ) MoveUp();
GetLine();
if ( CurrRow >= 11 ) PrintLine(0); else PrintLine(1);
}
}
void AddRecord(void){
auto int LSJ = sizeof(struct JD);
auto int LSI = sizeof(struct caddview_inx);
auto int LSC = sizeof(struct caddview);
unsigned int CurrRecord= CurrTopLine + CurrRow - 1;
if(CurrRecord < 65530L) {
unsigned int avance = (JDn.Fin[3]);
while(avance > CurrRecord) {
fseek(JD_f, (long)LSJ + LSI + ( LSC * avance ), SEEK_SET); // Se coloca
fread(&JD, LSC, 1, JD_f); // Y lee
fseek(JD_f, (long)LSJ + LSI + ( LSC * (avance + 1) ), SEEK_SET); // Se coloca
fwrite(&JD, LSC, 1, JD_f); // Y escribe
avance--;
};
for(int Rg=x; Rg < 4; Rg++) JDn.Fin[Rg] ++;
fseek(JD_f, (long)LSJ, SEEK_SET);
fwrite(&JDn, LSI, 1, JD_f); // Acualiza n§ de registros
JD.record_zone = 0;
JD.nombre_zona = x + 1;
strcpy(JD.nombre, "\0");
strcpy(JD.zip, "\0");
JD.kbytes = 0;
fseek(JD_f, (long)LSJ + LSI + ( LSC * ( CurrTopLine + CurrRow ) ), SEEK_SET); // Se coloca
fwrite(&JD, LSC, 1, JD_f); // Y escribe
PrintWholeScreen();
if ( (CurrTopLine + CurrRow - 1) > (JDn.Fin[x]) ) MoveUp();
GetLine();
if ( CurrRow >= 11 ) PrintLine(0); else PrintLine(1);
}
}
void PrintWholeScreen(void){
int tmp = CurrRow;
PWS=0;
BorraViewPort(3);
for(CurrRow = 1; CurrRow < 21; CurrRow++) {
if ( (CurrTopLine + CurrRow - 1) <= (JDn.Fin[x]) ) {
GetLine();
if ( CurrRow >= 11 ) PrintLine(0); else PrintLine(1);
}
}
CurrRow = tmp;
PWS=1;
}
void PutLine(void){
auto int LSJ = sizeof(struct JD);
auto int LSI = sizeof(struct caddview_inx);
auto int LSC = sizeof(struct caddview);
int CurrRecord = CurrTopLine + CurrRow - 1;
fseek(JD_f, (long)LSJ + LSI + ( LSC * CurrRecord ), SEEK_SET); // Se coloca
fwrite(&JD, LSC, 1, JD_f); // Y escribe
}
void GetLine(void){
auto int LSJ = sizeof(struct JD);
auto int LSI = sizeof(struct caddview_inx);
auto int LSC = sizeof(struct caddview);
int LSCm = sizeof(struct caddviewComentario);
int CurrRecord = CurrTopLine + CurrRow - 1;
fseek(JD_f, (long)LSJ + LSI + ( LSC * CurrRecord ), SEEK_SET); // Se coloca
fread(&JD, LSC, 1, JD_f); // Y lee
if( JD.record_zone != 0 ) {
fseek(JDc_f, (long)( LSCm * ( JD.record_zone - 1) ), SEEK_SET); // Se coloca
fread(&JD_comment, LSCm, 1, JDc_f); // Y lee
}
if(!M_M) {
ilumina = 0;
if(n_registros != 0 )
for(int cont = 1; cont <= n_registros; cont++ )
if(Registros[ cont ] == CurrRecord) ilumina = 1;
}
}
////// Funci¢n para el comentario, casi independiente al resto...
void PideComentario(void){
////////////////////////////// Translaci¢n de funciones a ViewPort #2
int i, key;
int Linea_c=1;
int finc = 0;
////////////////////////////// Ahora se abrir  un nuevo men£ para el raton:
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
struct boton comment[4];
comment[0]. left = 217; comment[0]. up = 34; comment[0]. right = 297; comment[0]. down = 75;
comment[1]. left = 217; comment[1]. up = 76; comment[1]. right = 297; comment[1]. down = 117;
comment[2]. left = 217; comment[2]. up = 118; comment[2]. right = 297; comment[2]. down = 159;
comment[3]. left = 217; comment[3]. up = 160; comment[3]. right = 297; comment[3]. down = 204;
for(i=0; i<4; i++) ImprimeBoton2 (1, 7, 63, 56, comment[i]);
setcolor(15);
outtextxy(222, 49 , " Supr. ");
outtextxy(222, 58, " Linea");
outtextxy(222, 96 , " UP ");
outtextxy(222, 138, " DOWN ");
outtextxy(224, 179, "Anterior ");
outtextxy(222, 189, " F2");
setcolor(0);
outtextxy(221, 48 , " Supr. ");
outtextxy(221, 57, " Linea");
outtextxy(221, 95 , " UP ");
outtextxy(221, 137, " DOWN ");
outtextxy(223, 178, "Anterior ");
outtextxy(221, 188, " F2");
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
if(JD. record_zone == 0) {
setcolor(0);
outtextxy( 43 * 8 - 7, (4 + 4) * 16 - 16, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛ");
for(i=0; i<10; i++)
strcpy(JD_comment. linea[i], "\0");
}
do{
EditCursorC(0, Linea_c);
if(raton) activa_raton();
/////////////////////// Aqui va una pausa de TECLADO y RATON al mismo TIEMPO
do{
if(raton){
ent.x.ax = 3;
int86(0x33, &ent, &sal); // lee posici¢n y estados del bot¢n
boton_izq = sal.x.bx & 1;
boton_der = (sal.x.bx >> 1) & 1;
x_raton = sal.x.cx;
y_raton = sal.x.dx;
} else boton_izq = 1;
}while( !boton_izq && !kbhit() );
if(raton) desactiva_raton();
if( kbhit() ) {
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// ¨ Hay una tecla en buffer ...
key = getch();
EditCursorC(1, Linea_c);
if( isprint(key) || isspace(key) ) {
if(key != 13) ungetch(key);
InputCadenaG( JD_comment. linea[Linea_c - 1], 0, 32, 42, Linea_c + 3, 63, 57);
// outtextxy( 43 * 8 - 7, (i + 4) * 16 - 16, JD_comment.linea[i] );
} else {
if( key == 0 ) {
key = getch();
switch ( key ) {
// DEL --- Borra Linea
case 83:
strcpy(JD_comment. linea[Linea_c - 1], "\0");
break;
// FLECHA ARRIBA
case 72:
Linea_c--;
if (Linea_c < 1) Linea_c = 10;
break;
// FLECHA ABAJO
case 80:
Linea_c++;
if (Linea_c > 10) Linea_c = 1;
break;
// FLECHA IZQUIERDA
case 75:
case 15:
Linea_c--;
if (Linea_c < 1) Linea_c = 10;
break;
// FLECHA DERECHA
case 77:
case 9:
Linea_c++;
if (Linea_c > 10) Linea_c = 1;
break;
// F2 --> PARA SALIR
case 60:
finc = 1;
break;
default:
if (sb) Sound_SN("catalog3");
break;
} // Fin de Swicth
} // Fin Key = 0
} // Fin Is Print Key?
} // Fin Tecla en Buffer
/////////////////////////////////////////////////////////////////////////////
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ//
////////////////////////// Comprueba con rat¢n ( SI ) ///////////////////////
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß//
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////// ... o es el RATON ?
if(raton && boton_izq==1 || boton_der==1) {
if( CheckButon(4, comment) ) {
EditCursorC(1, Linea_c);
switch ( bpush ) {
// Suprimir Linea
case 1:
strcpy(JD_comment. linea[Linea_c - 1], "\0");
break;
// FLECHA ARRIBA
case 72:
Linea_c--;
if (Linea_c < 1) Linea_c = 10;
break;
// FLECHA ABAJO
case 80:
Linea_c++;
if (Linea_c > 10) Linea_c = 1;
break;
// FLECHA IZQUIERDA
case 75:
case 15:
Linea_c--;
if (Linea_c < 1) Linea_c = 10;
break;
// FLECHA DERECHA
case 77:
case 9:
Linea_c++;
if (Linea_c > 10) Linea_c = 1;
break;
// F2 --> PARA SALIR
case 60:
finc = 1;
break;
default:
if (sb) Sound_SN("catalog3");
break;
} // Fin de Swicth
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
}while( !finc );
//////////////////////////////// Comienza analisis de Comentario
//////////////////////////////// para su correcto enlace con los DATOS
////// 1§ Si ya ten¡a posici¢n en ArchivoComentario, simplemente graba
////// 2§ si no 1§, Busca una posici¢n libre o al final
int LSCm = sizeof(struct caddviewComentario);
if(JD. record_zone == 0) {
struct caddviewComentario coment;
for(i=0; i <= JDn.FinC && finc ; i++) {
fseek(JDc_f, (long)( LSCm * i ) , SEEK_SET); // Se coloca
fread(&coment, LSCm, 1, JDc_f); // Y lee
if(finc && coment. record_zone_init == 0) {
JD. record_zone = i + 1;
finc = 0;
}
}
/////////// Si no hay fichas disponibles, habra que crearla, con
/////////// la consiguiente actualizaci¢n del indice...
if(JD. record_zone == 0) {
auto int LSJ = sizeof(struct JD);
auto int LSI = sizeof(struct caddview_inx);
JDn. FinC ++;
JD. record_zone = JDn. FinC + 1;
fseek(JD_f, (long)LSJ, SEEK_SET);
fwrite(&JDn, LSI, 1, JD_f);
}
}
JD_comment. record_zone_init = 1; // La ficha ya no esta disponible
fseek(JDc_f, (long)( LSCm * (JD.record_zone - 1) ), SEEK_SET); // Se coloca
fwrite(&JD_comment, LSCm, 1, JDc_f); // Y escribe
}
void EditCursorC(int ShowHide, int y) {
int cc, cf, i;
if (!ShowHide) {
cc = 63; cf = 57;
} else {
cc = 14; cf = 0;
}
setcolor(cf); // pone color de fondo '0' para borrar
for (i=0; i<32; i++) // limpia linea -imprimir sobre fondo-
outtextxy( ( 42 + i ) * 8 - 7, (y + 3) * 16 - 16, "Û");
setcolor(cc); // devuelve el color a su estado
outtextxy( 42 * 8 - 7, (y + 3) * 16 - 16, JD_comment.linea[y - 1] );
}
void Delete_Pedidos(void) {
if (ilumina) {
int LSC = sizeof(struct pedidos_datos);
int LSCm = sizeof(struct pedidos_descripcion);
if (JD_dp. n_records == 1) {
n_registros = 0;
JD_dt. record_zone = 0; strcpy(JD_dt. nombre, "\0");
JD_dt. record_name = 0; strcpy(JD_dt. zip, "\0");
JD_dt. kbytes = 0;
fseek(JD_p, (long)LSCm, SEEK_SET); // Se coloca
fwrite(&JD_dt, LSC, 1, JD_p); // Y escribe
ilumina = 0;
} else {
unsigned int CurrRecord = CurrTopLine + CurrRow - 1;
int ok = 0;
for(int cont = 1; cont <= n_registros && !ok; cont++ )
if(Registros[ cont ] == CurrRecord) { CurrRecord = Dir_Registros[ cont ]; ok=1; }
JD_dp. n_records --;
n_registros--;
unsigned int p = CurrRecord;
while(p <= JD_dp. n_records) {
fseek(JD_p, (long)LSCm + ( LSC * ( p + 1 ) - LSC ), SEEK_SET); // Se coloca
fread(&JD_dt, LSC, 1, JD_p); // Y lee
fseek(JD_p, (long)LSCm + ( LSC * p - LSC ), SEEK_SET); // Se coloca
fwrite(&JD_dt, LSC, 1, JD_p); // Y escribe
p++;
};
p = cont - 1;
while(p <= n_registros ) {
Registros[ p ] = Registros[ p + 1 ];
Dir_Registros[ p ] = Dir_Registros[ p + 1 ];
p++;
}
rewind(JD_p);
fwrite(&JD_dp, LSCm, 1, JD_p); // Acualiza n§ de registros
ilumina = 0;
}
}
}
void Add_Pedidos(void){
if(!ilumina) {
if(n_registros < 40) {
int LSC = sizeof(struct pedidos_datos);
int LSCm = sizeof(struct pedidos_descripcion);
JD_dp. n_records ++;
n_registros++;
rewind(JD_p);
fwrite(&JD_dp, LSCm, 1, JD_p); // Acualiza n§ de registros
Registros[ n_registros ] = CurrTopLine + CurrRow - 1;
Dir_Registros[ n_registros ] = JD_dp. n_records;
JD_dt.record_zone = CurrTopLine + CurrRow - 1;
JD_dt.record_name = Zx;
strcpy(JD_dt.nombre, JD.nombre); strcpy(JD_dt.zip, JD.zip);
JD_dt.kbytes = JD.kbytes;
fseek(JD_p, (long)LSCm + ( LSC * ( JD_dp. n_records ) - LSC ), SEEK_SET);
fwrite(&JD_dt, LSC, 1, JD_p);
ilumina = 1;
}
}
}