HERM/HERM_CFG.CPP
2021-09-12 20:06:36 +02:00

411 lines
12 KiB
C++
Raw 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.

/*************************************************************************\
|* *|
|* HERM_CFG *|
|* *|
|* Descripci¢n: *|
|* M¢dulo para mantener la configuraci¢n. *|
|* *|
|* Fecha: 21-07-96 14.34 / 18.00 *|
|* 23.13 / 00.30 *|
\*************************************************************************/
#include <stdlib.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
#include <graphics.h>
#include "..\libs\make_bot\make_bot.h"
#include "..\libs\bdatos\bdatos.hh"
#include "Herm.h"
extern int far Espera_TeclaRaton(void);
CONFIG Config;
BDatos BConfig;
extern int DifDate( struct date FechaF, struct date FechaO, struct date *FechaD );
extern struct date FechaActual;
extern char FICHA_REGISTRO;
extern int ComparaRegistros( const void *A, const void *B );
void CompruebaTiempoBorrados( char *File );
void MarcaConfig( int item, int como );
void EditConfig( int item );
void LeeConfiguracion(void)
{
long i;
BDatos GHtmp;
if ( BConfig.AbrirReg( "hermandad.cfg", sizeof( Config ) ) != OK )
Error(BConfig.cError);
if ( BConfig.Registros() == 0 )
{
// Ponemos a por defecto la configuraci¢n
Config.config_color = 0; // Configura que paleta usa
Config.item_ordenado[0]= 0; // item por el que esta ordenado
Config.item_ordenado[1]= 0; // item por el que esta ordenado
Config.TiempoBorrados = 6; // Tiempo que hay que mantener los items, borrados
// en meses...
GHtmp.AbrirReg( "datos\\hermanos.dbf", sizeof( HermStruct ) );
Config.NHnoHna[0] = GHtmp.NRegTotal(); // Numero de Hermanos, Hermanas
GHtmp.CerrarReg();
GHtmp.AbrirReg( "datos\\hermanas.dbf", sizeof( HermStruct ) );
Config.NHnoHna[1] = GHtmp.NRegTotal();
Config.TiempoBorrados = 6;
Config.CuotaBaseFam[0] = 0;
Config.CuotaBaseFam[1] = 0;
Config.LineasImpresion = 60;
Config.ImpNormal[0]='\0';
Config.ImpCompr[0]='\0';
GHtmp.CerrarReg();
Config.LineasImpresion = 60;
for ( i=0; i < 40; i++ )
{
strcpy( Config.Insignia[i].NInsignia, "ninguna" );
Config.Insignia[i].Suplemento = 0;
}
// Inserta un Reg por arriba de pos.
if ( BConfig.InsReg( (void *)&Config, BConfig.Registros(), ARRIBA ) != OK )
Error(BConfig.cError);
} else
BConfig.LeeReg( (void *)&Config, 0 );
// Chequeamos el tiempo permitido en hermanos borrados
CompruebaTiempoBorrados( "datos\\hnos_brr.dbf" );
CompruebaTiempoBorrados( "datos\\hnas_brr.dbf" );
}
void CompruebaTiempoBorrados( char *File )
{
BDatos Borr;
HERMBORRADOS HB;
long i;
int enc;
struct date d;
getdate(&d);
if ( Borr.AbrirReg( File, sizeof( HERMBORRADOS ) ) == OK )
{
for ( i = 0; i < Borr.Registros() && enc == OK; )
{
enc = Borr.LeeReg( (void *)&HB, i );
// Si se cumple...
if ( ( ( ( HB.FechaBorrado.da_year - d.da_year - 1 ) * 12 ) < 0 ? 0 : ( ( HB.FechaBorrado.da_year - d.da_year - 1 ) * 12 ) ) + abs(d.da_mon - HB.FechaBorrado.da_mon) >= Config.TiempoBorrados )
{
Borr.DelReg( Borr.RegActual() );
} else i++;
}
}
Borr.CerrarReg();
}
void ConfiguracionGlobal(void)
{
int ok, item = 0, dev, key;
long i;
struct date d;
getdate(&d);
BDatos Herm;
HermStruct HermS;
Imprime_Estaticos( 70, "herm.img" );
for ( ok = 0; ok < 10; ok++ )
MarcaConfig( ok, NORMAL );
ok = 0;
do{
MarcaConfig( item, INTENSO );
dev = Espera_TeclaRaton();
MarcaConfig( item, NORMAL );
if ( dev == 0 )
{
if ( kbhit() )
switch( key = getch() )
{
case 27:
ok = 1;
break;
case 0:
switch( getch() )
{
//ARRIBA -- IZQUIERDA
case 72:
case 75:
case 15:
item--; if ( item<0 ) item = 9;
break;
// ABAJO -- DERECHA
case 80:
case 77:
case 9:
item++; if ( item>9 ) item = 0;
break;
}
break;
default:
ungetch( key );
case 13:
EditConfig(item);
break;
}
} else {
if ( x_raton > 380 && x_raton < 630 && y_raton > 95 && y_raton < 125 )
{
if ( Optar( 1, "FIN REGISTRO Borrados", "Seguro que desea eliminar", "el registro de n§ eliminados", NULL ) )
{
remove( "datos\\hnos_brr.dbf" );
remove( "datos\\hnas_brr.dbf" );
}
} else
if ( x_raton > 15 && x_raton < 345 && y_raton > 315 && y_raton < 350 )
{
if ( Optar( 1, "CONFIRME OPERACION", "La reinicializaci¢n es", "irreversible. ­­ CONFIRME !!", "Se recalcularan las posiciones", NULL ) )
{
unlink( "datos\\hnos_brr.dbf" );
unlink( "datos\\hnas_brr.dbf" );
Herm.AbrirReg( "datos\\hermanos.dbf", sizeof( HermStruct ) );
// Ordenamos por n§ de hermanos
Config.NHnoHna[0] = Herm.Registros(); // Numero de Hermanos, Hermanas
Config.item_ordenado[0] = 0;
Config.item_ordenado[1] = 0;
if ( BConfig.EscribeReg((void *)&Config, 0) != OK )
Error(BConfig.cError);
if ( Herm.SortReg(ComparaRegistros) == OK )
{
Herm.SortReg(ComparaRegistros);
for ( i=0; i < Herm.Registros(); i++ )
{
Herm.LeeReg( (void *)&HermS, i );
HermS.Varios.RealPenit = 0;
if ( // Mayor de 18 a¤os
DifDate( d, HermS.FechaN, NULL ) > 18 &&
DifDate( d, HermS.Antig, NULL ) > 1 &&
/*
( d.da_year - HermS.FechaN.da_year ) > 18 &&
// Mas de un a¤o de antiguedad
( d.da_year - HermS.Antig.da_year ) > 1 &&
*/
HermS.FechaN.da_year != 0
)
{
HermS.Varios.PuedVotar = 1;
} else {
HermS.Varios.PuedVotar = 0;
}
HermS.NHno = i+1;
Herm.EscribeReg( (void *)&HermS, i );
}
} else Error( Herm.cError );
Herm.CerrarReg();
Herm.AbrirReg( "datos\\hermanas.dbf", sizeof( HermStruct ) );
Config.NHnoHna[1] = Herm.Registros();
Config.item_ordenado[0] = 0;
Config.item_ordenado[1] = 0;
if ( BConfig.EscribeReg((void *)&Config, 0) != OK )
Error(BConfig.cError);
if ( Herm.SortReg(ComparaRegistros) == OK )
{
for ( i=0; i < Herm.Registros(); i++ )
{
Herm.LeeReg( (void *)&HermS, i );
HermS.Varios.RealPenit = 0;
if ( // Mayor de 18 a¤os
DifDate( d, HermS.FechaN, NULL ) > 18 &&
DifDate( d, HermS.Antig, NULL ) > 1 &&
/*
( d.da_year - HermS.FechaN.da_year ) > 18 &&
// Mas de un a¤o de antiguedad
( d.da_year - HermS.Antig.da_year ) > 1 &&
*/
HermS.FechaN.da_year != 0
)
{
HermS.Varios.PuedVotar = 1;
} else {
HermS.Varios.PuedVotar = 0;
}
HermS.NHno = i+1;
Herm.EscribeReg( (void *)&HermS, i );
}
} else Error( Herm.cError );
Herm.CerrarReg();
}
}
}
}while( !ok );
// Guardamos configuraci¢n
BConfig.EscribeReg( (void *)&Config, 0 );
}
void MarcaConfig( int item, int como )
{
char buffer[80];
if ( como == INTENSO )
setfillstyle( SOLID_FILL, ROJO );
else
setfillstyle( SOLID_FILL, BLANCO );
setcolor( NEGRO );
switch( item )
{
// Ultimo hermano
case 0:
bar ( 270, 60, 350, 78 );
sprintf( buffer, " %04ld", Config.NHnoHna[0] );
outtextxy( 270, 60, buffer );
break;
// Ultima hermana
case 1:
bar ( 270, 80, 350, 98 );
sprintf( buffer, " %04ld", Config.NHnoHna[1] );
outtextxy( 270, 80, buffer );
break;
// Tiempo ha mantener los hermanos borrados
case 2:
bar ( 270, 100, 350, 118 );
sprintf( buffer, " %4d", Config.TiempoBorrados );
outtextxy( 270, 100, buffer );
break;
// Cadena imprimir normal
case 3:
bar ( 270, 150, 460, 168 );
outtextxy( 270, 150, Config.ImpNormal );
break;
// Cadena imprimir comprimido
case 4:
bar ( 270, 170, 460, 188 );
outtextxy( 270, 170, Config.ImpCompr );
break;
// N§ de lineas
case 5:
bar ( 270, 190, 350, 208 );
sprintf( buffer, " %4d", Config.LineasImpresion );
outtextxy( 270, 190, buffer );
break;
// Couta Base
case 6:
bar ( 270, 220, 350, 238 );
sprintf( buffer, " %4ld", Config.CuotaBaseFam[0] );
outtextxy( 270, 220, buffer );
break;
// Couta Familiar
case 7:
bar ( 550, 220, 630, 238 );
sprintf( buffer, " %4ld", Config.CuotaBaseFam[1] );
outtextxy( 550, 220, buffer );
break;
// Mes de las votaciones
case 8:
bar ( 270, 250, 350, 268 );
sprintf( buffer, " %4d", Config.MesVotacion );
outtextxy( 270, 250, buffer );
break;
// Hora de Salida
case 9:
bar ( 550, 250, 630, 268 );
sprintf( buffer, " %5s", Config.HoraSalida );
outtextxy( 550, 250, buffer );
break;
}
}
void EditConfig( int item )
{
char buffer[80];
switch( item )
{
// Ultimo hermano
case 0:
sprintf( buffer, "%ld", Config.NHnoHna[0] );
if ( !( InputCadenaG_T5( buffer, 1, 5, BLANCO, AZUL, 270, 60, 350, 78 ) >> 8 ) )
Config.NHnoHna[0] = atol ( buffer );
break;
// Ultima hermana
case 1:
sprintf( buffer, "%ld", Config.NHnoHna[1] );
if ( !( InputCadenaG_T5( buffer, 1, 5, BLANCO, AZUL, 270, 80, 350, 98 ) >> 8 ) )
Config.NHnoHna[1] = atol ( buffer );
break;
// Tiempo ha mantener los hermanos borrados
case 2:
sprintf( buffer, "%d", Config.TiempoBorrados );
if ( !( InputCadenaG_T5( buffer, 1, 3, BLANCO, AZUL, 270, 100, 350, 118 ) >> 8 ) )
Config.TiempoBorrados = atoi ( buffer );
break;
// Cadena imprimir normal
case 3:
sprintf( buffer, "%s", Config.ImpNormal );
if ( !( InputCadenaG_T5( buffer, 0, 19, BLANCO, AZUL, 270, 150, 460, 168 ) >> 8 ) )
strcpy( Config.ImpNormal, buffer );
break;
// Cadena imprimir comprimido
case 4:
sprintf( buffer, "%s", Config.ImpCompr );
if ( !( InputCadenaG_T5( buffer, 0, 19, BLANCO, AZUL, 270, 170, 460, 188 ) >> 8 ) )
strcpy( Config.ImpCompr, buffer );
break;
// N§ de lineas
case 5:
sprintf( buffer, "%d", Config.LineasImpresion );
if ( !( InputCadenaG_T5( buffer, 1, 2, BLANCO, AZUL, 270, 190, 350, 208 ) >> 8 ) )
Config.LineasImpresion = atoi( buffer );
break;
// Couta Base
case 6:
sprintf( buffer, "%ld", Config.CuotaBaseFam[0] );
if ( !( InputCadenaG_T5( buffer, 1, 5, BLANCO, AZUL, 270, 220, 350, 238 ) >> 8 ) )
Config.CuotaBaseFam[0] = atol( buffer );
break;
// Couta Familiar
case 7:
sprintf( buffer, "%ld", Config.CuotaBaseFam[1] );
if ( !( InputCadenaG_T5( buffer, 1, 5, BLANCO, AZUL, 550, 220, 630, 238 ) >> 8 ) )
Config.CuotaBaseFam[1] = atol( buffer );
break;
// Mes votacion
case 8:
sprintf( buffer, "%d", Config.MesVotacion );
if ( !( InputCadenaG_T5( buffer, 1, 2, BLANCO, AZUL, 270, 250, 350, 268 ) >> 8 ) )
Config.MesVotacion = atoi( buffer );
break;
// HoraSalida
case 9:
sprintf( buffer, "%s", Config.HoraSalida );
if ( !( InputCadenaG_T5( buffer, 0, 5, BLANCO, AZUL, 550, 250, 630, 268 ) >> 8 ) )
strcpy( Config.HoraSalida, buffer );
break;
}
}