//---------------------------------------------------------------------------
#pragma hdrstop

#include "CDSVmsFormEditF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

/////////////////////////////////////////////////////////////////////////////
TVmsSizeTypeManager *VmsSizeTypeManager = NULL;
//---------------------------------------------------------------------------
int TVmsSizeTypeManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-type";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sTypeCd = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_type_cd");
            String sTypeNm = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_type_nm");
            String sTypeDesc = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_type_desc");
            String sWidth  = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_wdth");
            String sHeight = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_hght");
            String sRows  = TRestObjectManager::GetValue(ObjList->Items[ii], "row_num");
            String sCols = TRestObjectManager::GetValue(ObjList->Items[ii], "col_num");
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            int nW = sWidth.ToIntDef(320);
            int nH = sHeight.ToIntDef(64);
            int nRows = sRows.ToIntDef(2);
            int nCols = sCols.ToIntDef(10);

            TVmsSizeType *Obj = new TVmsSizeType(sTypeCd, sTypeNm, sTypeDesc, nW, nH, nRows, nCols, sUseYn);
            FLists.Push(sTypeCd, Obj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
TVmsFormTypeManager *VmsFormTypeManager = NULL;
//---------------------------------------------------------------------------
int TVmsFormTypeManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-form-type";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") {
                continue;
            }

            String sCD = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_type_cd");
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_type_nm");

            TVmsCode *pObj = new TVmsCode(sCD.ToIntDef(0), sNM, sNM, sUseYn);
            FLists.Push(pObj->CODE, pObj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
TVmsFontNameManager *VmsFontNameManager = NULL;
//---------------------------------------------------------------------------
int TVmsFontNameManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-form-font";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") {
                continue;
            }

            String sCD = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_name_cd");
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_name");
            String sDESC = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_name_desc");

            TVmsCode *pObj = new TVmsCode(sCD.ToIntDef(0), sNM, sDESC, sUseYn);
            FLists.Push(pObj->CODE, pObj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
TVmsFontColrManager *VmsFontColrManager = NULL;
//---------------------------------------------------------------------------
int TVmsFontColrManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-form-font-colr";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") {
                continue;
            }

            String sCD = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_colr_cd");
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_colr_nm");
            String sDESC = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_colr_desc");
            String sVal  = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_colr_val");
            String sR = TRestObjectManager::GetValue(ObjList->Items[ii], "color_r");
            String sG  = TRestObjectManager::GetValue(ObjList->Items[ii], "color_g");
            String sB = TRestObjectManager::GetValue(ObjList->Items[ii], "color_b");

            TVmsFontColr *pObj = new TVmsFontColr(sCD.ToIntDef(0), sNM, sDESC, sUseYn, sVal.ToIntDef(0), sR.ToIntDef(0), sG.ToIntDef(0), sB.ToIntDef(0));
            FLists.Push(pObj->CODE, pObj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------
int TVmsFontColrManager::GetColorCode(int AColor)
{
    FOR_STL(TVmsFontColr*, pObj, FLists)
    {
        if (AColor == pObj->COLR_VAL) return pObj->CODE;
    }
    return 0;
}
//---------------------------------------------------------------------------
int TVmsFontColrManager::GetColorCodeIndex(int ACode)
{
    int nIdx = 0;
    FOR_STL(TVmsFontColr*, pObj, FLists)
    {
        if (ACode == pObj->CODE) return nIdx;
        nIdx++;
    }
    return 0;
}
//---------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
TVmsDsplDrctManager *VmsDsplDrctManager = NULL;
//---------------------------------------------------------------------------
int TVmsDsplDrctManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-form-dspl-drct";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") {
                continue;
            }

            String sCD = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_dspl_drct_cd");
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_dspl_drct_nm");
            String sDESC = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_dspl_drct_desc");

            TVmsCode *pObj = new TVmsCode(sCD.ToIntDef(0), sNM, sDESC, sUseYn);
            FLists.Push(pObj->CODE, pObj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////
TVmsDsplMthdManager *VmsDsplMthdManager = NULL;
//---------------------------------------------------------------------------
int TVmsDsplMthdManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-form-dspl-mthd";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") {
                continue;
            }

            String sCD = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_dspl_mthd_cd");
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_dspl_mthd_nm");
            String sDESC = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_dspl_mthd_desc");

            TVmsCode *pObj = new TVmsCode(sCD.ToIntDef(0), sNM, sDESC, sUseYn);
            FLists.Push(pObj->CODE, pObj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
TVmsFormObjTypeManager *VmsFormObjTypeManager = NULL;
//---------------------------------------------------------------------------
int TVmsFormObjTypeManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-form-object";
    TMcJsonItem *ObjList = NULL;
    try
    {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++)
        {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") continue;

            int nFormType = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_type_cd").ToIntDef(0);

            TVmsFormObjType *pObj = FLists.Find(nFormType);
            if (!pObj)
            {
                pObj = new TVmsFormObjType();
                FLists.Push(nFormType, pObj);
            }

            int nType = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_object_type_cd").ToIntDef(0);
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_object_type_nm");
            String sDESC = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_form_object_type_desc");

            TVmsCode *pType = pObj->FLists.Find(nType);
            if (!pType)
            {
                pType = new TVmsCode(nType, sNM, sDESC, sUseYn);
                pObj->FLists.Push(pType->CODE, pType);
            }
            pType->NAME = sNM;
            pType->DESC = sDESC;
        }
    }
    __finally
    {
        FLists.UnLock();
        if (ObjList) delete ObjList;
    }
    return FLists.Size();
}
//---------------------------------------------------------------------------




