//---------------------------------------------------------------------------

#ifndef CDSVdsCtlrFH
#define CDSVdsCtlrFH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
#include "ITSLibF.h"
#include "CDSObjectF.h"
//---------------------------------------------------------------------------
#include "CenterCommF.h"
//---------------------------------------------------------------------------

#define YONGIN_VDS

class TVdsDtctLink
{
public:
    TVdsDtctLink();
    virtual ~TVdsDtctLink();

private:
    bool    FCompleted;
    int     FEditMode;
	int     FGridIndex;

public:

    String VDS_CTLR_NMBR;   //VARCHAR2(20)	Y			제어기 관리 번호
    String VDS_DTCT_NMBR;   //VARCHAR2(8)	N			검지기 번호
    String LINK_ID;         //NUMBER(10)	N			링크ID
    String MEM_DEL;
    
public:
    __property bool   Completed = {read = FCompleted, write = FCompleted};
	__property int    EditMode  = {read = FEditMode,  write = FEditMode };
	__property int    GridIndex = {read = FGridIndex, write = FGridIndex };
};
//---------------------------------------------------------------------------

/*
*  VdsDtct class
*/
class TVdsDtct
{
public:
    TVdsDtct();
    virtual ~TVdsDtct();

private:
    bool    FCompleted;
    int     FEditMode;
	int     FGridIndex;

public:

    String  VDS_DTCT_NMBR;  //	N	NUMBER(10)	    N			VDS 검지기 번호
    String  VDS_DTCT_ID;    //	N	VARCHAR2(10)	N			VDS 검지기 ID
    String  VDS_DTCT_NM;    //	N	VARCHAR2(40)	Y			VDS 검지기 명칭
    String  VDS_CTLR_NMBR;  //	N	NUMBER(10)	    N			VDS 제어기 번호
    int     VDS_CMRA_NO;    //	N	NUMBER(1)	    N			VDS 카메라 번호
    String  DTCT_TYPE;      //	N	VARCHAR2(7)	    Y			검지기 유형('DTT')
    String  DTCT_DIR;       //	N	VARCHAR2(7)	    N	0		검지기 방향('VCD')
    int     DETECT_LANE;    //	N	NUMBER(2)	    Y			감지차로(제어기설치차로)
    int     ISTL_LANE;      //	N	NUMBER(2)	    Y	1		설치 차로
    String  SPED_CLCT_YN;   //	N	CHAR(1)	        Y	'Y'		속도수집여부
    String  TFVL_CLCT_YN;   //	N	CHAR(1)	        Y	'Y'		교통량수집여부
    String  OCPY_CLCT_YN;   //	N	CHAR(1)	        Y	'Y'		점유율수집여부
    int     MAX_TFVL;       //	N	NUMBER(6)	    Y	250		최대 교통량
    int     MIN_TFVL;       //	N	NUMBER(6)	    Y	1		최소 교통량
    float   MAX_OCPY_RATE;  //	N	NUMBER(6,2)	    Y	100		최대 점유 율
    float   MIN_OCPY_RATE;  //	N	NUMBER(6,2)	    Y	0		최소 점유 율
    int     MAX_SPED;       //	N	NUMBER(3)	    Y	140		최대 속도
    int     MIN_SPED;       //	N	NUMBER(3)	    Y	1		최소 속도
    String  USE_YN;         //	N	CHAR(1)	        Y	'Y'		사용여부
    String  DEL_YN;         //	N	CHAR(1)	        Y	'N'		삭제 여부

    String MEM_DEL;

    TItsMap<String, TVdsDtctLink*>  FLinks;

public:
    __property bool   Completed = {read = FCompleted, write = FCompleted};
	__property int    EditMode  = {read = FEditMode,  write = FEditMode };
	__property int    GridIndex = {read = FGridIndex, write = FGridIndex };
};
//---------------------------------------------------------------------------

/*
* Vds camera class
*/
class TVdsCmra
{
public:
    TVdsCmra(){}
    virtual ~TVdsCmra(){}

public:
    String  VDS_CTLR_NMBR;      //	N	NUMBER(10)	    N			VDS 제어기 번호
    int     VDS_CMRA_NO;        //	N	NUMBER(1)	    N			VDS 카메라 번호
    String  VDS_CMRA_NM;        //	N	VARCHAR2(40)	N			VDS 카메라명칭
    int     DETECT_LANE;        //	N	NUMBER(2)	    Y			감지 차로
    String  CMRA_DRCT_CD;       //	N	VARCHAR2(7)	    Y			카메라 방향 코드
    String  DEL_YN;             //	N	CHAR(1)	        Y	'N'		삭제 여부
    String  CCAM_CTLR_NMBR;     //	N	NUMBER(10)	    Y			교차로감시 카메라 제어기 번호
    String  ROAD_NAME;          //	N	VARCHAR2(50)	Y			도로명
    String  CROSS_NAME;         //	N	VARCHAR2(50)	Y			교차로명
    String  DIR_NAME;           //	N	VARCHAR2(50)	Y			방향명
    String  VDS_CMRA_IP;        //	N	VARCHAR2(20)	Y			VDS 카메라 아이피
};
//---------------------------------------------------------------------------

/*
*  Vds class
*/
class TVdsCtlr : public TCDSObject
{
public:
    TVdsCtlr();
    virtual ~TVdsCtlr();

public:

    int     GROUP_NO;           //	N	NUMBER(5)	Y	0		그룹번호
    int     FAN_MODE;           //	N	NUMBER(3)	Y	2		FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     FAN_RUN_TMPR;       //	N	NUMBER(3)	Y	30		팬 동작 온도
    int     HETR_MODE;          //	N	NUMBER(3)	Y	2		히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     HETR_RUN_TMPR;      //	N	NUMBER(3)	Y	0		히터 동작 온도
    int     DETECT_LANES;       //	N	NUMBER(2)	Y	0		검지 전체 차로수
    int     TRAF_CLCT_CYCL;     //	N	NUMBER(3)	Y	60		교통정보수집주기
    int     STTS_CLCT_CYCL;     //	N	NUMBER(3)	Y	0		상태정보수집주기

public:
    INT_VDS_STATE   STATE;

    TItsMap<int,    TVdsCmra*>    FCmras;
    TItsMap<String, TVdsDtct*>    FDtcts;

public:
    __property String  VDS_CTLR_NMBR     = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  VDS_CTLR_ID       = { read = CTLR_ID,       write = CTLR_ID       };
    __property String  VDS_NM            = { read = NAME,          write = NAME          };
    __property String  VDS_CTLR_IP       = { read = CTLR_IP,       write = CTLR_IP       };
    __property int     VDS_CTLR_PORT     = { read = CTLR_PORT,     write = CTLR_PORT     };
    __property int     VDS_CTLR_LOCAL_NO = { read = CTLR_LOCAL_NO, write = CTLR_LOCAL_NO };
    __property String  VDS_TYPE_CD       = { read = TYPE_CD,       write = TYPE_CD       };

};
//---------------------------------------------------------------------------

class TVdsLink
{
public:
    TVdsLink() {};
    virtual ~TVdsLink() {};
public:
    String  LINK_ID;
    String  STR_NAME;
    String  END_NAME;
    String  VDS_CTLR_NMBR;
    String  VDS_NM;
    bool    IsSelected;
};

/*
* Vds Manager
*/
class TVdsCtlrManager
{
public:
    TVdsCtlrManager();
    virtual ~TVdsCtlrManager();

public:
    TItsMap<String, TVdsCtlr*>    FLists;
    TItsMap<String, TVdsLink*>    FLinkLists;
    int                           FLinkSelCnt;

public:
    bool LoadFromDbVdsLink(TADOConnection *ADbConn=NULL);
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    bool LoadStatusFromDb(TADOConnection *ADbConn=NULL);
    bool LoadFromCmraDb(TADOConnection *ADbConn=NULL);
    bool LoadFromDtctDb(TADOConnection *ADbConn=NULL);
    bool LoadFromDtctLinkDb(TADOConnection *ADbConn=NULL);

    bool GetNextVdsId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);
    bool GetNextVdsDtctId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);

    bool DeleteVds(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool InsertVds(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool UpdateVds(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeVds(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeFcltInfo(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);

    bool DeleteVdsCmra(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool InsertVdsCmra(TVdsCtlr *AObj, TADOConnection *ADbConn=NULL);

    bool DeleteVdsDtctSubTable(TVdsDtct *AObj, TADOConnection *ADbConn=NULL);
    bool DeleteVdsDtct(TVdsDtct *AObj, TADOConnection *ADbConn=NULL);
    bool SaveVdsDtct(TVdsDtct *AObj, TADOConnection *ADbConn=NULL);
};
//---------------------------------------------------------------------------
extern TVdsCtlrManager *VdsCtlrManager;
//---------------------------------------------------------------------------

#endif

