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

#ifndef AppGlobalFH
#define AppGlobalFH
//---------------------------------------------------------------------------

#include <map.h>
#include "RestObjectF.h"
#include "ITSUtilF.h"
#include "DataTypesF.h"
#include "ITSLogF.h"

#include "CDSVmsFormEditF.h"
#include "CDSAtmpF.h"
#include "CDSParkF.h"
#include "CDSVmsIfscF.h"


/*
******************************************************************************
* Defines
******************************************************************************
*/

#define FORMSHOW(x)     if (x) \
                        { \
                            try { \
                            ShowWindow(x->Handle, SW_RESTORE); \
                            x->BringToFront(); \
                            } catch(...) {} \
                        } \
                        else \
                        { \
                            Application->CreateForm(__classid(T##x), &x); \
                            if (x) x->Show(); \
                        }

/*
******************************************************************************
* User Data Types
******************************************************************************
*/
#define     STR_DATETIME    "YYYY-MM-DD HH:NN:SS"
#define     STR_HHNN        "YYYY-MM-DD HH:NN"
#define     STR_DATEHOUR    "YYYY-MM-DD HH"
#define     STR_DATE        "YYYY-MM-DD"
#define     STR_MM          "YYYY-MM"

typedef enum
{
    icon_n = 0,
    icon_e,
    icon_m,
    icon_r,
    icon_s,
} facility_icon;

typedef struct
{
    String  ICON[5];
} FACILITY_ICON;

typedef struct tag_AppConfig
{
    String      sConfigFile;
    bool        bAppClose;
    long        lMainWinHandle;     /* Main Window Handle */
    String      sTitle;
    String      sProcessId;       	/* 프로세스 ID */
    int         nVmsServerPort;
    String      sSkinName;
    bool        bSaveForm;
    bool        bLoginPrompt;
    String      sDefUseId;

    int         nLogLevel;
    AnsiString  sLogDay;
    bool        bDebug;
    String      sAppPath;

    String      sLang;
    bool        isDispOfflineMsg;

    String      sUserId;
    String      sRestApiUri;


    struct
    {
        bool    Window;
        bool    Enabled;
        int     TimeOut;
    } Alarm;
    struct
    {
        bool    Window;
        bool    Enabled;
        int     TimeOut;
    } Incident;
    struct
    {
        int     AlarmValue;
    } Temp;

    struct
    {
        bool    Enabled;
        int     IntervalMin;
        bool    LogoutExit;
    } AutoLogout;

    FACILITY_ICON   vms;
    FACILITY_ICON   vds;

    struct
    {
        TThread     *pThread;
        DWORD        dwThreadId;
        unsigned int nHandle;
        bool         bRunning;
    } thr;
    struct
    {
        String  sProvider;
        String  sServerName;
        String  sUserName;
        String  sPassword;
        bool    bSqlLog;
    } itsdb;
    struct
    {
        String  sProvider;
        String  sServerName;
        String  sUserName;
        String  sPassword;
        bool    bSqlLog;
    } utisdb;
    struct
    {
        String  sMainMap;
        String  sLinkMap;
    } flashmap;

    struct
    {
        String  sComModel;
        String  sDevModel;
    } vmscam;

    struct
    {
        String  saveDir;
        String  viewer;
        String  server;
        int     port;
        String  user;
        String  pswd;
        String  dir;
    } blackbox;

    struct
    {
        String SERVER;
        int    PORT;
        String USER;
        String PSWD;
        bool   PASSIVE;
    } vmsFtp;

    bool bOnlyOneScreen;
    bool bTermChildProg;
} APP_CONFIG;

/*
******************************************************************************
* Global variable definitions
******************************************************************************
*/
extern ST_GISINFO       g_GisInfo;
extern ST_SELLINK       g_SelLink;

extern String           CenterCd;       // 지역센터 코드
extern String           CenterId;       // 지역센터 아이디
extern String           CenterName;     // 지역센터 명칭
extern int              g_nPid;         // Application Process ID
extern String           g_sAppDir;      // Application Directory
extern String           g_sAppName;     // Program name
extern String           g_sCfgDir;      // Config File Directory
extern String           g_sLogDir;      // Program Log Directory
extern String           g_sTempDir;     // Program Temp Directory
extern String           g_sFormsDir;    // Program Forms Directory
extern String           g_sBlackBox;
extern String           g_sLangDir;
extern String           g_sImageDir;
extern String           g_sVideoDir;
extern String           g_sMapDir;

extern APP_CONFIG       g_AppCfg;

extern LOG_INFO         g_LogCfg;
extern TITSLog         *ITSLog;
extern TITSLog         *FDbLog;
extern bool g_bControlAuth;
/*
******************************************************************************
* PlugIn Global variables
******************************************************************************
*/


/*
******************************************************************************
* Global function definitios
******************************************************************************
*/
void ActiveProgram();
bool CheckParamRandKey(String AParam);

bool LoadDefaultConfigInfo(String ACfgFile="");

bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue);
bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue);

bool DeleteLogFiles(PTCHAR pszPath, int nDays, PTCHAR pszFile);

void ShowErrorMsg(String ATitle, String AErrMsg);

#include "cxControls.hpp"
#include "cxDropDownEdit.hpp"

TDateTime APP_StrToDateTime(String AStrDateTime);

String APP_FillCode(TcxComboBox *ACombo, String ACode);
String APP_GetCode(TcxComboBox *ACombo);
String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode);
String APP_GetCodeName(TcxComboBox *ACombo, String ACode);
String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName);
String APP_GetCodeDefCode(TcxComboBox *ACombo);
String APP_GetCodeDefDesc(TcxComboBox *ACombo);
int APP_SetCode(TcxComboBox *ACombo, String ACode);
String ITSUtil_FormatStr(String AStrDateTime, String AFormat);

//----------------------------------------------------------------------------
#define MAX_DISPCOLOR   20
extern TColor  g_DispColor[MAX_DISPCOLOR];
void APP_InitDisplayColor();
TColor APP_GetDisplayColor(int ASeq);
void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color);

//----------------------------------------------------------------------------
ULONG ProcIDFromWnd(HWND hwnd);
HWND GetWinHandle(ULONG pid);

#endif

