414 lines
14 KiB
C++
414 lines
14 KiB
C++
//---------------------------------------------------------------------------
|
|
#define BarraEstado2 StatusBar1->Panels->Items[1]->Text
|
|
|
|
//---------------------------------------------------------------------------
|
|
#include <io.h>
|
|
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "CfgTurnos.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma resource "*.dfm"
|
|
TTurnos *Turnos;
|
|
//---------------------------------------------------------------------------
|
|
__fastcall TTurnos::TTurnos(TComponent* Owner)
|
|
: TForm(Owner)
|
|
{
|
|
unsigned short year, month, day;
|
|
TDateTime::CurrentDate().DecodeDate( &year, &month, &day );
|
|
Meses->ItemIndex = month-1;
|
|
if ( year>=1999 && year<=2001 )
|
|
Anyos->ItemIndex = (1999-year);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::TbTurnosBeforeOpen(TDataSet *DataSet)
|
|
{
|
|
if ( access( (TbTurnos -> TableName).c_str(), 0 ) != 0 )
|
|
{
|
|
// Usamos la propiedad FielDefs para definir
|
|
// las columnas que contendrá la tabla
|
|
TbTurnos -> FieldDefs -> Clear();
|
|
|
|
/********************\
|
|
|* Datos Básicos *|
|
|
\********************/
|
|
TbTurnos -> FieldDefs -> Add("idTurno", ftAutoInc, 0, false );
|
|
TbTurnos -> FieldDefs -> Add("idSector", ftInteger, 0, false );
|
|
TbTurnos -> FieldDefs -> Add("NTurno", ftString, 15, false );
|
|
|
|
TbTurnos -> FieldDefs -> Add("HTurnoP0", ftFloat, 0, false );
|
|
TbTurnos -> FieldDefs -> Add("HTurnoP1", ftFloat, 0, false );
|
|
TbTurnos -> FieldDefs -> Add("HTurnoP2", ftFloat, 0, false );
|
|
|
|
|
|
|
|
TbTurnos -> IndexDefs-> Clear();
|
|
|
|
TIndexOptions MyIndexOptions;
|
|
MyIndexOptions << ixPrimary << ixUnique;
|
|
TbTurnos->IndexDefs->Add("Primary", "idTurno;idSector", MyIndexOptions);
|
|
TbTurnos->IndexDefs->Add("IdxSector", "idSector", TIndexOptions() << ixCaseInsensitive );
|
|
|
|
// Creamos la base...
|
|
TbTurnos -> CreateTable();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::TbSectoresBeforeOpen(TDataSet *DataSet)
|
|
{
|
|
if ( access( (TbSectores -> TableName).c_str(), 0 ) != 0 )
|
|
{
|
|
// Usamos la propiedad FielDefs para definir
|
|
// las columnas que contendrá la tabla
|
|
TbSectores -> FieldDefs -> Clear();
|
|
|
|
/********************\
|
|
|* Datos Básicos *|
|
|
\********************/
|
|
TbSectores -> FieldDefs -> Add("idSector", ftAutoInc, 0, false );
|
|
TbSectores -> FieldDefs -> Add("NSector", ftString, 15, false );
|
|
|
|
|
|
TbSectores -> IndexDefs-> Clear();
|
|
|
|
TIndexOptions MyIndexOptions;
|
|
MyIndexOptions << ixPrimary << ixUnique;
|
|
TbSectores->IndexDefs->Add("Primary", "idSector", MyIndexOptions);
|
|
|
|
// Creamos la base...
|
|
TbSectores -> CreateTable();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::TbPersonalBeforeOpen(TDataSet *DataSet)
|
|
{
|
|
if ( access( (TbPersonal -> TableName).c_str(), 0 ) != 0 )
|
|
{
|
|
// Usamos la propiedad FielDefs para definir
|
|
// las columnas que contendrá la tabla
|
|
TbPersonal -> FieldDefs -> Clear();
|
|
|
|
/********************\
|
|
|* Datos Básicos *|
|
|
\********************/
|
|
TbPersonal -> FieldDefs -> Add("idPersonal", ftAutoInc, 0, false );
|
|
TbPersonal -> FieldDefs -> Add("idSector", ftInteger, 0, false );
|
|
TbPersonal -> FieldDefs -> Add("Nombre", ftString, 15, false );
|
|
TbPersonal -> FieldDefs -> Add("Apellidos", ftString, 30, false );
|
|
TbPersonal -> FieldDefs -> Add("Tlfs", ftString, 30, false );
|
|
|
|
TbPersonal -> IndexDefs-> Clear();
|
|
|
|
TIndexOptions MyIndexOptions;
|
|
MyIndexOptions << ixPrimary << ixUnique;
|
|
TbPersonal->IndexDefs->Add("Primary", "idPersonal", MyIndexOptions);
|
|
TbPersonal->IndexDefs->Add("IdxSector", "idSector", TIndexOptions() << ixCaseInsensitive );
|
|
|
|
// Creamos la base...
|
|
TbPersonal -> CreateTable();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::TbHorariaBeforeOpen(TDataSet *DataSet)
|
|
{
|
|
if ( access( (TbHoraria -> TableName).c_str(), 0 ) != 0 )
|
|
{
|
|
// Usamos la propiedad FielDefs para definir
|
|
// las columnas que contendrá la tabla
|
|
TbHoraria -> FieldDefs -> Clear();
|
|
|
|
/********************\
|
|
|* Datos Básicos *|
|
|
\********************/
|
|
TbHoraria -> FieldDefs -> Add("idHorario", ftAutoInc, 0, false );
|
|
TbHoraria -> FieldDefs -> Add("Mes", ftSmallint, 0, false );
|
|
TbHoraria -> FieldDefs -> Add("Anyo", ftSmallint, 0, false );
|
|
|
|
TbHoraria -> FieldDefs -> Add("idSector", ftInteger, 0, false );
|
|
TbHoraria -> FieldDefs -> Add("idPersonal", ftInteger, 0, false );
|
|
|
|
|
|
for( int i=1; i<=31; i++ )
|
|
TbHoraria -> FieldDefs -> Add(AnsiString("idTurno_Dia"+AnsiString( i )), ftInteger, 0, false );
|
|
|
|
TbHoraria -> IndexDefs-> Clear();
|
|
|
|
TIndexOptions MyIndexOptions;
|
|
MyIndexOptions << ixPrimary << ixUnique;
|
|
TbHoraria->IndexDefs->Add("Primary", "idHorario;Mes;Anyo", MyIndexOptions);
|
|
TbHoraria->IndexDefs->Add("IdxSector", "idSector", TIndexOptions() << ixCaseInsensitive );
|
|
|
|
// Creamos la base...
|
|
TbHoraria -> CreateTable();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::FormCreate(TObject *Sender)
|
|
{
|
|
int i;
|
|
for ( i=0; i<96; i++ )
|
|
{
|
|
// TSpeedButton *CfgTurnos[96];
|
|
CfgTurnos[i] = new TShape(this);
|
|
|
|
CfgTurnos[i]->Width = 9;
|
|
CfgTurnos[i]->Height = 16;
|
|
|
|
CfgTurnos[i]->Top = 40 + ( i < 48 ? 0 : CfgTurnos[i]->Height + 5 );
|
|
CfgTurnos[i]->Left = ( i < 48 ? i : i-48 )*(CfgTurnos[i]->Width - 1) + 24;
|
|
|
|
CfgTurnos[i]->OnMouseDown = CfgTurnosMouseUp;
|
|
|
|
Pizarra->InsertControl( CfgTurnos[i] );
|
|
|
|
// TLabel *LblTurnos[96];
|
|
if ( i < 48 && (i%4)==0 )
|
|
{
|
|
LblTurnos[i/4] = new TLabel(this);
|
|
|
|
LblTurnos[i/4]->Top = 24 + ( i < 48 ? 0 : CfgTurnos[i]->Height + 5 );
|
|
LblTurnos[i/4]->Left = ( i < 48 ? i : i-48 )*(CfgTurnos[i]->Width - 1) + 24 - ( (i/4)<9 ? 0 : 5 );
|
|
|
|
LblTurnos[i/4]->Caption = AnsiString( (i/4)+1 );
|
|
|
|
Pizarra->InsertControl( LblTurnos[i/4] );
|
|
}
|
|
|
|
}
|
|
|
|
TbSectores->Active = true;
|
|
TbTurnos->Active = true;
|
|
TbPersonal->Active = true;
|
|
TbHoraria->Active = true;
|
|
/*
|
|
try {
|
|
DBLookupComboBox1->Text = TbSectores->FieldByName( "NSector" )->AsString;
|
|
}catch(...)
|
|
{
|
|
// do nothing...
|
|
}
|
|
*/
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::FormDestroy(TObject *Sender)
|
|
{
|
|
int i;
|
|
for ( i=0; i<96; i++ )
|
|
delete CfgTurnos[i];
|
|
|
|
for ( i=0; i<12; i++ )
|
|
delete LblTurnos[i];
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::CfgTurnosMouseUp(TObject *Sender,
|
|
TMouseButton Button, TShiftState Shift, int X, int Y)
|
|
{
|
|
int i;
|
|
for ( i=0; i<96; i++ )
|
|
{
|
|
if ( Sender == CfgTurnos[i] )
|
|
{
|
|
#define TurnoX TbTurnos->FieldByName( "HTurnoP" + AnsiString( i / 32 ) )->AsInteger
|
|
#define Mask ( 0x01 << ( i % 32 ) )
|
|
#define TurnoX1 TbTurnos->FieldByName( "HTurnoP" + AnsiString( i / 32 ) )->AsFloat
|
|
TbTurnos->Edit();
|
|
TurnoX1 = ( (TurnoX & ~Mask ) | ( !( TurnoX & Mask ) << ( i % 32 ) ) );
|
|
TbTurnos->Post();
|
|
// CfgTurnos[i]->Brush->Color = ( TurnoX & Mask ) ? clRed : clWhite;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TTurnos::DsTurnosDataChange(TObject *Sender, TField *Field)
|
|
{
|
|
int i;
|
|
|
|
if ( PageControl1->ActivePage == TabSheet2 )
|
|
{
|
|
// Indicador de FichaActual / Num.Fichas
|
|
if ( TbTurnos -> RecNo > 0 && TbTurnos -> RecordCount > 0 )
|
|
{
|
|
BarraEstado2 = Format( "C: %d / %d", OPENARRAY(TVarRec, (TbTurnos -> RecNo, TbTurnos -> RecordCount)) );
|
|
for ( i=0; i<96; i++ )
|
|
CfgTurnos[i]->Brush->Color = ( TurnoX & Mask ) ? clRed : clWhite;
|
|
} else {
|
|
BarraEstado2 = Format( "C: ¿Nuevo? / %d", OPENARRAY(TVarRec, (TbTurnos -> RecordCount) ) );
|
|
}
|
|
}
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::DsSectoresDataChange(TObject *Sender,
|
|
TField *Field)
|
|
{
|
|
// Indicador de FichaActual / Num.Fichas
|
|
if ( TbSectores -> RecNo > 0 && TbSectores -> RecordCount > 0 )
|
|
{
|
|
BarraEstado2 = Format( "C: %d / %d", OPENARRAY(TVarRec, (TbSectores -> RecNo, TbSectores -> RecordCount)) );
|
|
} else {
|
|
BarraEstado2 = Format( "C: ¿Nuevo? / %d", OPENARRAY(TVarRec, (TbSectores -> RecordCount) ) );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::TbTurnosBeforeInsert(TDataSet *DataSet)
|
|
{
|
|
if ( !( TbSectores -> RecNo > 0 && TbSectores -> RecordCount > 0 ) )
|
|
{
|
|
// MessageBox( 0, "¿ No cree que debería crear,\no seleccionar una factura nueva,\nantes de agregar datos de compra?.", "¡ Atención !", MB_OK );
|
|
Abort();
|
|
} else {
|
|
for (int i=0; i<96; i++)
|
|
CfgTurnos[i]->Brush->Color = clWhite;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::DBGrid2DrawColumnCell(TObject *Sender,
|
|
const TRect &Rect, int DataCol, TColumn *Column,
|
|
TGridDrawState State)
|
|
{
|
|
// Precisa seguimiento ¿?
|
|
if ( Column -> ID == 2 )
|
|
{
|
|
int i, AnchoT, AltoT;
|
|
TRect RectT;
|
|
|
|
|
|
AnchoT = ((Rect.Right-Rect.Left) / 48);
|
|
#define DESPLAZAM_CENTRO ((Rect.Right-Rect.Left)-(AnchoT*48))/2
|
|
|
|
RectT = Rect;
|
|
RectT.Top++;
|
|
RectT.Left += DESPLAZAM_CENTRO;
|
|
RectT.Right+= DESPLAZAM_CENTRO;
|
|
|
|
|
|
RectT.Right = RectT.Left;
|
|
AltoT = (Rect.Bottom-Rect.Top-1)/2;
|
|
RectT.Bottom -= AltoT;
|
|
|
|
DBGrid2 -> Canvas -> Pen -> Color = clBlack;
|
|
|
|
if ( AnchoT > 0 )
|
|
{
|
|
for ( i=0; i<96; i++ )
|
|
{
|
|
if ( i == 48 ) { RectT.Top = RectT.Bottom; RectT.Bottom = Rect.Bottom; RectT.Left = Rect.Left+DESPLAZAM_CENTRO;RectT.Right = Rect.Left+DESPLAZAM_CENTRO; }
|
|
RectT.Left = RectT.Right;
|
|
RectT.Right += AnchoT;
|
|
DBGrid2 -> Canvas -> Brush -> Color = ( TurnoX & Mask ) ? clRed : clWhite;
|
|
DBGrid2 -> Canvas -> FillRect( RectT );
|
|
// Dibujamos las marcas horarias...
|
|
if ( (i%4)==0 )
|
|
{
|
|
DBGrid2 -> Canvas -> MoveTo( RectT.Left, RectT.Top+1 );
|
|
DBGrid2 -> Canvas -> LineTo( RectT.Left, RectT.Bottom );
|
|
}
|
|
if ( (i%24)==0 && i!=0 && i!=48 )
|
|
{
|
|
DBGrid2 -> Canvas -> MoveTo( RectT.Left+1, RectT.Top+1 );
|
|
DBGrid2 -> Canvas -> LineTo( RectT.Left+1, RectT.Bottom );
|
|
}
|
|
}
|
|
DBGrid2 -> Canvas -> MoveTo( Rect.Left+DESPLAZAM_CENTRO, RectT.Top );
|
|
DBGrid2 -> Canvas -> LineTo( RectT.Right,RectT.Top );
|
|
|
|
DBGrid2 -> Canvas -> MoveTo( Rect.Left+DESPLAZAM_CENTRO, Rect.Top+1 );
|
|
DBGrid2 -> Canvas -> LineTo( RectT.Right,Rect.Top+1 );
|
|
DBGrid2 -> Canvas -> LineTo( RectT.Right,RectT.Bottom );
|
|
DBGrid2 -> Canvas -> LineTo( Rect.Left+DESPLAZAM_CENTRO,RectT.Bottom );
|
|
DBGrid2 -> Canvas -> LineTo( Rect.Left+DESPLAZAM_CENTRO,Rect.Top+1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
// DBGrid1 -> Canvas -> StretchDraw( Rect, BtmOK );
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::FormResize(TObject *Sender)
|
|
{
|
|
int Separacion;
|
|
|
|
Separacion = ((Pizarra->Width - (47*(Shape1->Width - 1) + Shape1->Left))/12)-1;
|
|
|
|
|
|
|
|
for ( int i = 0; i < 96; i++ )
|
|
{
|
|
CfgTurnos[i]->Width = Shape1->Width;
|
|
CfgTurnos[i]->Height = Shape1->Height;
|
|
|
|
CfgTurnos[i]->Top = (i<48?Shape1->Top:Shape2->Top);//Shape1->Top + ( i < 48 ? 0 : CfgTurnos[i]->Height + 5 );
|
|
CfgTurnos[i]->Left = ( i < 48 ? i : i-48 )*(CfgTurnos[i]->Width - 1) + Shape1->Left + (((i%48)/4)*Separacion);
|
|
|
|
if ( i < 48 && (i%4)==0 )
|
|
{
|
|
LblTurnos[i/4]->Top = Label3->Top;
|
|
LblTurnos[i/4]->Left = i *(CfgTurnos[i]->Width - 1) + Label3->Left - ( (i/4)<9 ? 0 : ((Label3->Width*5)/CfgTurnos[i]->Width) ) + (((i%48)/4)*Separacion);
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::TbPersonalBeforeInsert(TDataSet *DataSet)
|
|
{
|
|
if ( !( TbSectores -> RecNo > 0 && TbSectores -> RecordCount > 0 ) )
|
|
{
|
|
// MessageBox( 0, "¿ No cree que debería crear,\no seleccionar una factura nueva,\nantes de agregar datos de compra?.", "¡ Atención !", MB_OK );
|
|
Abort();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
void __fastcall TTurnos::PageControl1Change(TObject *Sender)
|
|
{
|
|
TWinControl *HookP;
|
|
|
|
// Reasignamos los marcadores de hora...
|
|
if ( PageControl1->ActivePage == TabSheet1 ||
|
|
PageControl1->ActivePage == TabSheet2 )
|
|
{
|
|
HookP = PageControl1->ActivePage == TabSheet1 ? Pizarra2 : Pizarra;
|
|
for ( int i = 0; i < 96; i++ )
|
|
{
|
|
CfgTurnos[i]->Parent = HookP;
|
|
if ( i < 48 && (i%4)==0 )
|
|
LblTurnos[i/4]->Parent = HookP;
|
|
}
|
|
|
|
for ( int i=0; i<96; i++ )
|
|
CfgTurnos[i]->Brush->Color = clWhite;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::TbHorariaCalcFields(TDataSet *DataSet)
|
|
{
|
|
TbHoraria->FieldByName("Prsnl_CltNombApll")->AsString =
|
|
TbHoraria->FieldByName("Prsnl_Nombre")->AsString +
|
|
TbHoraria->FieldByName("Prsnl_Apellidos")->AsString;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TTurnos::DBGrid4DrawColumnCell(TObject *Sender,
|
|
const TRect &Rect, int DataCol, TColumn *Column,
|
|
TGridDrawState State)
|
|
{
|
|
if ( State.Contains(gdFixed) && Column->ID > 1 )
|
|
{
|
|
Column->Title->Caption = "Día "+Column->ID;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|