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

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

#include <map.h>
#include "ITSDbF.h"
#include "ITSLogF.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 struct tag_AppConfig
{
    String      sConfigFile;
    bool        bAppClose;
    long        lMainWinHandle;     /* Main Window Handle */
    String      sTitle;
    String      sProcessId;       	/* 프로세스 ID */
    String      sSkinName;
    bool        bSaveForm;
    bool        bLoginPrompt;
    String      sDefUseId;

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

    String      sLang;

    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;

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

    struct
    {
        String  sComModel;
        String  sDevModel;
    } vmscam;
} APP_CONFIG;

/*
******************************************************************************
* Global variable definitions
******************************************************************************
*/
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_sLangDir;

extern APP_CONFIG       g_AppCfg;

extern LOGININFO       *g_pLOGIN;
extern LOG_INFO         g_LogCfg;
extern TITSLog         *ITSLog;

/*
******************************************************************************
* PlugIn Global variables
******************************************************************************
*/


/*
******************************************************************************
* Global function definitios
******************************************************************************
*/
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_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   22
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);

//////////////////////////////////////////////////////////////////////////////////
class TVmsSizeType : public TObject
{
public:	// User declarations
    String TypeCd;
    String TypeNm;
    int    Width;
    int    Height;

public:		// User declarations
    __fastcall TVmsSizeType(String ATypeCd,
                            String ATypeNm,
                            int    AWidth,
                            int    AHeight)
    {
        TypeCd = ATypeCd;
        TypeNm = ATypeNm;
        Width  = AWidth;
        Height = AHeight;
    }
};
//////////////////////////////////////////////////////////////////////////////////
void APP_DelVmsSizeCombo(TcxComboBox *cboBox);
TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox);

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

#endif

