#include "StdAfx.h"
|
#include "MBGridStyleMgr.h"
|
#include "json.h"
|
|
CMBGridStyleMgr::CMBGridStyleMgr(void)
|
{
|
RemoveAllGridStyle();
|
}
|
|
|
CMBGridStyleMgr::~CMBGridStyleMgr(void)
|
{
|
RemoveAllGridStyle();
|
}
|
|
void CMBGridStyleMgr::GetGridStyleMap( CMBGridStyleAttrMgrMap &map)
|
{
|
map.clear();
|
map = m_map;
|
}
|
|
CMBGridStyleAttrMgr *CMBGridStyleMgr::GetGridStyle( CString strVaultID )
|
{
|
if( strVaultID.IsEmpty() )
|
return NULL;
|
|
CMBGridStyleAttrMgrMap::iterator it;
|
CMBGridStyleAttrMgr *pObj = NULL;
|
|
it = m_map.find(strVaultID);
|
|
if( it!= m_map.end() )
|
pObj = it->second;
|
|
return pObj;
|
}
|
|
bool CMBGridStyleMgr::AddGridStyle( CMBGridStyleAttrMgr *pObj )
|
{
|
if( NULL == pObj || pObj->m_strVaultID.IsEmpty() )
|
return false;
|
|
CMBGridStyleAttrMgrMap::iterator it;
|
CString strVaultID;
|
|
|
strVaultID = pObj->m_strVaultID;
|
it = m_map.find(strVaultID);
|
|
// Èç¹ûÕҵõ½ ·µ»Ø
|
if( it != m_map.end() )
|
return false;
|
|
m_map[strVaultID] = pObj;
|
|
return true;
|
|
}
|
|
bool CMBGridStyleMgr::RemoveAllGridStyle()
|
{
|
CMBGridStyleAttrMgrMap::iterator it;
|
CMBGridStyleAttrMgr *pObj = NULL;
|
|
for( it = m_map.begin();it != m_map.end();it++ )
|
{
|
pObj = it->second;
|
delete pObj;
|
pObj = NULL;
|
}
|
|
m_map.clear();
|
|
return true;
|
}
|
|
|
bool CMBGridStyleMgr::AddGridStyle(CString strVaultID,CString strExePath,CString &strErrInfo)
|
{
|
CString strGridStyle,strJsonContent,strWidth;
|
Json::Reader reader;
|
Json::Value json_object;
|
Json::Value json_cell;
|
Json::Value json_attr;
|
string json,attr,showName,width;
|
|
strGridStyle.Format(_T("%svalut\\%s\\GridStyle.json"),strExePath,strVaultID);
|
// ¶ÁÎļþÄÚÈÝ
|
if(! CStrFileUtils::GetStrFromFile(strGridStyle,strJsonContent))
|
{
|
strErrInfo = _T("¶ÁÎļþ ") + strGridStyle + _T(" ʧ°Ü£¡");
|
return false;
|
}
|
|
json = CT2A(strJsonContent);
|
|
if (!reader.parse(json, json_object)){
|
strErrInfo = strGridStyle+ _T(" ·Çjson¸ñʽ£¡");
|
return false;
|
}
|
|
json_cell = json_object["Cell"] ;
|
if( json_cell.isArray() )
|
{
|
CMBGridStyleAttrMgr *pObj = new CMBGridStyleAttrMgr();
|
pObj->m_strVaultID = strVaultID;
|
|
int nSize = json_cell.size();
|
for( int i =0;i<nSize;i++ )
|
{
|
json_attr = json_cell[i];
|
|
CMBGridStyleAttr *pAttr = new CMBGridStyleAttr();
|
attr = json_attr["Attr"].asString();
|
showName = json_attr["ShowName"].asString();
|
width = json_attr["Width"].asString();
|
|
pAttr->m_strAttr = CA2T(attr.c_str());
|
pAttr->m_strShowName = CA2T(showName.c_str());
|
strWidth = CA2T(width.c_str());
|
pAttr->m_nWidth = _ttoi(strWidth);
|
|
if( !pObj->AddAttr(pAttr) )
|
{
|
delete pAttr;
|
pAttr = NULL;
|
}
|
}// end for
|
|
if(!AddGridStyle( pObj ) )
|
{
|
delete pObj;
|
pObj = NULL;
|
}
|
}
|
|
|
return true;
|
}
|
|
|