//---------------------------------------------------------------------------
#ifndef CtrlPPalH
#define CtrlPPalH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "CoolForm.hpp"
#include <ExtCtrls.hpp>
#include <Menus.hpp>
#include <Db.hpp>
#include <DBTables.hpp>
#include <Buttons.hpp>
#include "actimg.h"
#include <ScktComp.hpp>
#include "CtrlElemento.h"
#include <Graphics.hpp>


//---------------------------------------------------------------------------
class TCtrlPPal : public TForm
{
__published:	// IDE-managed Components
    TCoolForm *CoolForm1;
    TScrollBox *Pizarra;
    TImage *iElementoV;
    TImage *iElemento2;
    TPopupMenu *mElementoCFG;
    TMenuItem *Propiedades1;
    TMenuItem *N1;
    TMenuItem *Eliminar1;
    TTable *TbElementosCFG;
    TMenuItem *N2;
    TMenuItem *AsignarHora1;
    TMenuItem *Estado1;
    TActiveImage *iPosV;
    TActiveImage *iClose;
    TActiveImage *ActiveImage3;
    TActiveImage *iMin;
    TMemo *Memo1;
    TMenuItem *CerrarWindows1;
    TImage *iElemento3;
    TImage *iElemento4;
    TMenuItem *ActualizarEstado1;
    TMenuItem *N3;
    TMenuItem *SinTIEMPO1;
    TTable *TbHistorial;
    TImage *remoteBack;
    TActiveImage *RemoteStart;
    TActiveImage *remoteClose;
    TServerSocket *clientHook;
    TClientSocket *serverHook;
    TLabel *remoteLog;
    TImage *Image1;
        TTable *TbPersonas;
        TAutoIncField *TbPersonasCodCliente1;
        TStringField *TbPersonasNombre;
        TStringField *TbPersonasApellidos;
        TStringField *TbPersonasTelefono1;
        TStringField *TbPersonasDocumentoDNP;
        TDateTimeField *TbPersonasFAlta;
        TDateTimeField *TbPersonasFModif;
        TIntegerField *TbPersonasTiempoH;
        TIntegerField *TbPersonasTiempoM;
    void __fastcall iCloseDblClick(TObject *Sender);
    void __fastcall iMinClick(TObject *Sender);
    
    void __fastcall iPosVClick(TObject *Sender);
   
    void __fastcall FormDestroy(TObject *Sender);
    void __fastcall PizarraDblClick(TObject *Sender);
    void __fastcall EliminarElemento(TObject *Sender);

    void __fastcall TbElementosCFGBeforeOpen(TDataSet *DataSet);
    void __fastcall TbElementosCFGAfterOpen(TDataSet *DataSet);
    void __fastcall ElementoDblClick(TObject *Sender);
    void __fastcall Estado1Click(TObject *Sender);

    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormDeactivate(TObject *Sender);
    void __fastcall Propiedades1Click(TObject *Sender);
    void __fastcall CerrarWindows1Click(TObject *Sender);

    void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);

    void __fastcall ActualizarEstado1Click(TObject *Sender);
    void __fastcall SinTIEMPO1Click(TObject *Sender);

    void __fastcall TbHistorialBeforeOpen(TDataSet *DataSet);
    void __fastcall AsignarHora1Click(TObject *Sender);
    void __fastcall RemoteStartClick(TObject *Sender);
    void __fastcall remoteCloseDblClick(TObject *Sender);
    void __fastcall clientHookClientConnect(TObject *Sender,
          TCustomWinSocket *Socket);
    void __fastcall clientHookClientDisconnect(TObject *Sender,
          TCustomWinSocket *Socket);
    void __fastcall clientHookClientError(TObject *Sender,
          TCustomWinSocket *Socket, TErrorEvent ErrorEvent,
          int &ErrorCode);
    void __fastcall clientHookAccept(TObject *Sender,
          TCustomWinSocket *Socket);
    void __fastcall serverHookConnect(TObject *Sender,
          TCustomWinSocket *Socket);
    void __fastcall ActiveImage3Click(TObject *Sender);
    
    void __fastcall Image1Click(TObject *Sender);
        void __fastcall TbPersonasNewRecord(TDataSet *DataSet);
private:	// User declarations
    void __fastcall ElementoMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
    void __fastcall ElementoMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
    void __fastcall ElementoMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
                             // Obtiene el indice del elemento sobre el que esta el puntero del ratón.
    void __fastcall NewElementAt( int X, int Y, int NumEl, AnsiString IP, AnsiString Name );

    TDateTime HoraActual;    // Hora "ACTUAL" (se actualiza por minutos)

/**********************/
    int nElementosMAX;
    TList *Elementos;
    void __fastcall CheckAppIntegrity(void);
    void __fastcall StartEventRecorder(void);

/**********************/
    int ServerHookCode; int ServerHookElement; int ServerHookTime;
    double ServerTiempo; int ServerL_idc, ServerL_idtc; float ServerL_Precio;
    bool ClientHook;

    TElemento * __fastcall SearchElement( int NumElemento );

    void __fastcall LoadProtectedList(void);

public:		// User declarations

    bool __fastcall Manipula2(AnsiString Serial, AnsiString Image);
    bool __fastcall Manipula(AnsiString Serial, AnsiString Image);

    bool ServerHook;

    
    __fastcall TCtrlPPal(TComponent* Owner);

    void __fastcall SetActiveTimeElement( TElemento *Elemento, TDateTime Tiempo, int L_idc, int L_idtc, Currency L_Precio );
    TStringList *siMinimizar, *noMinimizar;
    TStringList *snMinimizar, *noAbrir;
    bool ChangePositionEnabled;

    //////////////////// MANTENIMIENTO DE LOS HILOS //////////////////////////
    TThread *GetThread(void);
    void __fastcall FreeThreads(void);
    int AnySocketActive;
    //////////////////// MANTENIMIENTO DE LOS HILOS //////////////////////////
};
//---------------------------------------------------------------------------
extern PACKAGE TCtrlPPal *CtrlPPal;
//---------------------------------------------------------------------------
#endif
