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

#ifndef CDSFacilityFH
#define CDSFacilityFH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
#include "cxCustomData.hpp"
#include "ITSLibF.h"
#include "ITSDbF.h"
#include "CDSDsrcF.h"
#include "CDSVdsCtlrF.h"
#include "CDSAviF.h"
//#include "CDSParkingF.h"
#include "CDSEventF.h"
#include "CDSVmsCtlrF.h"
#include "CDSPrltCtlrF.h"
#include "CDSCctvCtlrF.h"
#include "CDSWCamCtlrF.h"
#include "CDSCCamCtlrF.h"
//---------------------------------------------------------------------------

#define state_normal    "0"
#define state_error     "1"
#define state_module    "2"
#define state_unknown   "3"
#define state_collect   "4"
#define state_default   "5"

/*
*  Rse class
*/
class TItsRse
{
public:
    TItsRse(){}
    virtual ~TItsRse(){}

    String RSEID;
    String INSTDT;
    String CITYCD;
    String REGIONCD;
    String AREACD;
    String RSEIP;
    String COORDX;
    String COORDY;
    String RADIUS1;
    String RADIUS2;
    String COMPCD;
    String LOCATION;
    String RSECONFIGID;
    String OBEPARAMID;
    String PORT;
    String BRIDGE;
    String COMYN;
};
//---------------------------------------------------------------------------

/*
*  Avi class
*/
class TItsFAvi
{
public:
    TItsFAvi(){}
    virtual ~TItsFAvi(){}

    String AVI_CTLR_MNGM_NMBR;  //VARCHAR2(20)	N			AVI 제어기 관리 번호
    String AVI_ID;              //VARCHAR2(10)	Y			AVI ID
    String LINK_ID;             //NUMBER(10)	Y			링크 ID
    String AVI_LCTN_NM;         //VARCHAR2(60)	Y			AVI 위치 명
    String AVI_VALD_YN;         //CHAR(1)	Y	'N'		AVI 유효 여부
    String AVI_CTLR_IP;         //VARCHAR2(20)	Y			AVI 제어기 아이피
    String AVI_CTLR_CMNC_PORT;  //VARCHAR2(5)	Y			AVI 제어기 통신 포트
    String AVI_MAIN_CTLR_YN;    //CHAR(1)	Y	'N'		AVI 주 제어기 여부
    String AVI_MNGM_LANE_NUM;   //NUMBER(2)	Y			AVI 관리 차로 개수
    String AVI_CMRA_NUM;        //NUMBER(2)	Y			AVI 카메라 개수
    String AVI_DTCT_NUM;        //NUMBER(2)	Y			AVI 검지기 개수
    String AVI_DTCT_NM;         //VARCHAR2(60)	Y			AVI 검지기 명
    String AVI_CLCT_CYCL;       //NUMBER(3)	Y			AVI 수집 주기
    String AVI_LAMP_AUTO_YN;    //CHAR(1)	Y	'N'		AVI 조명장치 자동 여부
    String AVI_LAMP_ON_HMS;     //VARCHAR2(6)	Y			AVI 조명장치 ON 시각
    String AVI_LAMP_OFF_HMS;    //VARCHAR2(6)	Y			AVI 조명장치 OFF 시각
    String AVI_LAMP_ON_YN;      //CHAR(1)	Y	'N'		AVI 조명장치 ON 여부
    String X_CRDN;              //NUMBER(11,8)	Y			X 좌표
    String Y_CRDN;              //NUMBER(10,8)	Y			Y 좌표
    String RMRK;                //VARCHAR2(600)	Y			비고
    String DEL_YN;              //CHAR(1)	Y	'N'		삭제 여부
};
//---------------------------------------------------------------------------

/*
*  Dsrc class
*/
class TItsFDsrc
{
public:
    TItsFDsrc(){}
    virtual ~TItsFDsrc(){}

    String ID;              //VARCHAR2(3)	N			아이디
    String RSE_ID;          //VARCHAR2(8)	N			RSE 아이디
    String ROAD_SPOT_ID;    //VARCHAR2(30)	N			도로 지점 아이디
    String LOG_CNNC_ID;     //VARCHAR2(64)	Y			로그 접속 아이디
    String LOG_CNNC_PW;     //VARCHAR2(64)	Y			로그 접속 비밀번호
    String ISTL_LCTN_NM;    //VARCHAR2(40)	Y			설치 위치 명
    String LCTN_X;          //NUMBER(11,8)	Y			위치 X
    String LCTN_Y;          //NUMBER(10,8)	Y			위치 Y
    String IP;              //VARCHAR2(20)	Y			IP
    String PORT;            //VARCHAR2(5)	Y			PORT
    String MNFC_CMPY_CD;    //NUMBER(5)	Y			제조 업체 코드
    String DEL_YN;          //CHAR(1)	Y	'N'		삭제 여부
};
//---------------------------------------------------------------------------

/*
*  EtcFacility class
*/
class TItsRegFacility
{
public:
    TItsRegFacility();
    virtual ~TItsRegFacility();
    void Clear();
private:
public:
    String  Type;
    String  Id;
    String  Name;
    String  DelYn;
    String  UnRegisterd;
    int     GridIndex;
};
//---------------------------------------------------------------------------

/*
*  Facility class
*/
class TItsFacility
{
public:
    TItsFacility();
    virtual ~TItsFacility();
    void Clear();
private:
    int     FEditMode;
    bool    FModified;
    bool    FCompleted;

public:
    String FCLT_ID;		    // FCLT_ID VARCHAR(50 BYTE) NOT NULL,	'시설물 ID';
    String RFID_ID;		    // RFID_ID VARCHAR(50 BYTE) NOT NULL,	'시설물 ID';
    String FCLT_TYPE;		// FCLT_TYPE VARCHAR(7 BYTE) NOT NULL, '시설물유형';
    String FCLT_LCTN;		// FCLT_LCTN VARCHAR(100 BYTE),        '시설물 위치';
    String RSCE_YN;		    // RSCE_YN CHAR(1 BYTE) DEFAULT 'N',   '현장자산유무';
    String MDL_NM;          // MDL_NM VARCHAR(30 BYTE),            '모델명';
    String USE_YEAR;		// USE_YEAR NUMBER(3),                 '사용년수';
    String INWR_DT;		    // INWR_DT VARCHAR(14 BYTE),           '입고일시';
    String OTWR_DT;		    // OTWR_DT VARCHAR(14 BYTE),           '출고일시';
    String ISTL_DT;		    // ISTL_DT VARCHAR(14 BYTE),           '설치일시';
    String TAKT_DT;		    // TAKT_DT VARCHAR(14 BYTE),           '반출일시';
    String TAKT_RESN;		// TAKT_RESN VARCHAR(100 BYTE),        '반출사유';
    String TAKN_DT;		    // TAKN_DT VARCHAR(14 BYTE),           '반입일시';
    String ABDN_DT;		    // ABDN_DT VARCHAR(14 BYTE),           '폐기일시';
    String ADTN_NM;		    // ADTN_NM VARCHAR(30 BYTE),           '추가자명';
    String ADTN_DT;		    // ADTN_DT VARCHAR(14 BYTE),           '추가일시';
    String CHNG_NM;		    // CHNG_NM VARCHAR(30 BYTE),           '변경자명';
    String CHNG_DT;		    // CHNG_DT VARCHAR(14 BYTE),           '변경일시';
    String AMT;			    // AMT NUMBER(15),                     '금액';
    String DEL_YN;		    // DEL_YN CHAR(1 BYTE) DEFAULT 'N',    '삭제여부';
    String ISTL_CMPY_ID;	// ISTL_CMPY_ID VARCHAR(30 BYTE),      '설치업체ID';
    String MNFC_CMPY_ID;	// PRDC_CMPY_ID VARCHAR(30 BYTE)       '제조업체ID';

    String ISTL_LCTN_ADDR;  // '설치 위치 주소'

    String FCommStatus;     // 장비 통신상태값
    String FDoorStatus;     // 장비 Door상태값
    String FComm;
    String FDoor;
    String FCBoxTmpr;

    int    FCollCntBase;
    int    FCollCntCurr;
    bool   FCollError;

    String FCLT_KIND;

    String Sts00;
    String Sts01;
    String Sts02;
    String Sts03;
    String Sts04;
    String Sts05;
    String Sts06;
    String Sts07;
    String Sts08;
    String Sts09;
    String Sts10;

    String Deleted;         // 마스터정보가 삭제된것
	int    GridIndex;	    // 메인폼에 뿌려지는 그리드 인덱스
    int    StatusGridIndex;

    TCDSObject *Object;
    String      FOldComm;

protected:

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

class TFacilityStatus
{
public:
    TFacilityStatus()
    {
        Type   = "";
        Total  = 0;
        Normal = 0;
        Error  = 0;
        Module = 0;
        Collect= 0;
    };
    virtual ~TFacilityStatus() {};

    String Type;
    int    Total;
    int    Normal;
    int    Error;
    int    Module;
    int    Collect;
};
//---------------------------------------------------------------------------


class TItsBit
{
public:
    TItsBit(){}
    virtual ~TItsBit(){}

    String FCLT_ID;
    String FCLT_LCTN;
    String BIT_ID;
    String X_CRDN;
    String Y_CRDN;

    String STOP_ID;
    String STOP_EXPLAIN;
    String LINK_ID;

    String BIT_TYPE;
    int    FAN_MIN_TEMPERATURE;
    int    FAN_MAX_TEMPERATURE;
    int    HEATER_MIN_TEMPERATURE;
    int    HEATER_MAX_TEMPERATURE;
    String INSTALL_STOP_ID;
    String SERVICE_ID;
    String STOP_TYPE;
    String STOP_NAME;
    String STOP_SHORTNAME;

    String DEL_YN;
};
//---------------------------------------------------------------------------

class TItsSig
{
public:
    TItsSig(){}
    virtual ~TItsSig(){}

    String FCLT_ID;
    String FCLT_LCTN;
    String SIG_ID;
    String X_CRDN;
    String Y_CRDN;

    String MDL_NM;
    String DEL_YN;
};
//---------------------------------------------------------------------------

class TItsSigDet
{
public:
    TItsSigDet(){}
    virtual ~TItsSigDet(){}

    String FCLT_ID;
    String FCLT_LCTN;
    String SDET_ID;
    String X_CRDN;
    String Y_CRDN;
    String SIG_ID;

    String MDL_NM;
    String DEL_YN;
};
//---------------------------------------------------------------------------

class TItsPis
{
public:
    TItsPis(){}
    virtual ~TItsPis(){}

    String FCLT_ID;
    String FCLT_LCTN;
    String PIS_ID;
    String X_CRDN;
    String Y_CRDN;
    String SIG_ID;

    String MDL_NM;
    String DEL_YN;
};
//---------------------------------------------------------------------------

class TItsPcs
{
public:
    TItsPcs(){}
    virtual ~TItsPcs(){}

    String FCLT_ID;
    String FCLT_LCTN;
    String PCS_ID;
    String X_CRDN;
    String Y_CRDN;
    String SIG_ID;

    String MDL_NM;
    String DEL_YN;
};
//---------------------------------------------------------------------------

/*
* Facility Manager
*/
class TItsFacilityManager
{
public:
    TItsFacilityManager();
    virtual ~TItsFacilityManager();

public:
    String                      CenterId;
    int                         FLocalCctvCnt;

    TItsMap<String, TItsFacility*>       FLists;

    TItsMap<String, TItsRse*>            FRseLists;

    TItsMap<String, TItsAvi*>            FAviLists;
    TItsMap<String, TItsDsrc*>           FDsrcLists;

    TItsMap<String, TItsBit*>            FBitLists;
    TItsMap<String, TItsSig*>            FSigLists;
    TItsMap<String, TItsSigDet*>         FSigDetLists;

    TItsMap<String, TItsPis*>            FPisLists;
    TItsMap<String, TItsPcs*>            FPcsLists;

    TItsMap<String, TItsRegFacility*>    FRegLists;

    TItsMap<String, TFacilityStatus*>    FListStatus;

public:
    void SetCenterId(String ACenterId);
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    
    bool LoadFacilityReg(TADOConnection *ADbConn=NULL);
    bool LoadFacilityMaster(TADOConnection *ADbConn=NULL);

    bool LoadFacilityWebCam(TADOConnection *ADbConn=NULL);
    bool LoadFacilityCrsCam(TADOConnection *ADbConn=NULL);
    bool LoadFacilityCctv(TADOConnection *ADbConn=NULL);
    bool LoadFacilityVms(TADOConnection *ADbConn=NULL);
    bool LoadFacilityRse(TADOConnection *ADbConn=NULL);

    bool LoadFacilityVds(TADOConnection *ADbConn=NULL);
    bool LoadFacilityAvi(TADOConnection *ADbConn=NULL);
    bool LoadFacilityDsrc(TADOConnection *ADbConn=NULL);

    bool LoadFacilityBit(TADOConnection *ADbConn=NULL);
    bool LoadFacilitySig(TADOConnection *ADbConn=NULL);
    bool LoadFacilitySigDet(TADOConnection *ADbConn=NULL);

    bool LoadFacilityPvms(TADOConnection *ADbConn=NULL);
    bool LoadFacilityPvds(TADOConnection *ADbConn=NULL);
    bool LoadFacilityPark(TADOConnection *ADbConn=NULL);

    bool CheckFacility();

    bool LoadFacilityStatusFromDb(TADOConnection *ADbConn=NULL);
    bool LoadDsrcCollectStatusFromDb(TADOConnection *ADbConn=NULL);
    bool LoadVdsCollectStatusFromDb(TADOConnection *ADbConn=NULL);
    bool LoadAviCollectStatusFromDb(TADOConnection *ADbConn=NULL);

    bool LoadDsrcCollectStatusFromDb_OLD(TADOConnection *ADbConn=NULL);
    bool LoadAviCollectStatusFromDb_OLD(TADOConnection *ADbConn=NULL);
};
//---------------------------------------------------------------------------
extern TItsFacilityManager *ItsFacilityManager;
//---------------------------------------------------------------------------

#endif

