#include "StdAfx.h"
|
#include "MBGridStyleAttrMgr2.h"
|
|
#include "json.h"
|
|
IMPLEMENT_DYNAMIC(CMBGridStyleAttrMgr2, CMBAbstBaseObj)
|
|
CMBGridStyleAttrMgr2::CMBGridStyleAttrMgr2(void)
|
{
|
RemoveAllAttr();
|
}
|
|
|
CMBGridStyleAttrMgr2::~CMBGridStyleAttrMgr2(void)
|
{
|
RemoveAllAttr();
|
}
|
|
|
void CMBGridStyleAttrMgr2::GetAttrMap( CMBGridStyleAttrMap &mapAttr)
|
{
|
mapAttr.clear();
|
mapAttr = m_mapAttr;
|
}
|
|
void CMBGridStyleAttrMgr2::GetAttrVector( CMBGridStyleAttrVector &vectorAttr)
|
{
|
vectorAttr.clear();
|
vectorAttr = m_vectorAttr;
|
}
|
|
CMBGridStyleAttr *CMBGridStyleAttrMgr2::GetAttr( CString strAttr )
|
{
|
if( strAttr.IsEmpty() )
|
return NULL;
|
|
CMBGridStyleAttrMap::iterator it;
|
CMBGridStyleAttr *pAttr = NULL;
|
|
it = m_mapAttr.find(strAttr);
|
|
if( it!= m_mapAttr.end() )
|
pAttr = it->second;
|
|
return pAttr;
|
}
|
|
bool CMBGridStyleAttrMgr2::AddAttr( CMBGridStyleAttr *pAttr )
|
{
|
if( NULL == pAttr || pAttr->m_strAttr.IsEmpty() )
|
return false;
|
|
CMBGridStyleAttrMap::iterator it;
|
CString strName;
|
|
strName = pAttr->m_strAttr;
|
it = m_mapAttr.find(strName);
|
|
// Èç¹ûÕҵõ½ ·µ»Ø
|
if( it != m_mapAttr.end() )
|
return false;
|
|
m_mapAttr[strName] = pAttr;
|
|
m_vectorAttr.push_back(pAttr);
|
|
return true;
|
}
|
|
bool CMBGridStyleAttrMgr2::RemoveAllAttr()
|
{
|
CMBGridStyleAttrMap::iterator it;
|
CMBGridStyleAttr *pAttr = NULL;
|
|
for( it = m_mapAttr.begin();it != m_mapAttr.end();it++ )
|
{
|
pAttr = it->second;
|
delete pAttr;
|
pAttr = NULL;
|
}
|
|
m_mapAttr.clear();
|
m_vectorAttr.clear();
|
|
return true;
|
}
|
|
|
int CMBGridStyleAttrMgr2::GetIndex( CString strAttr )
|
{
|
int nSize = m_vectorAttr.size();
|
for( int i= 0;i < nSize;i++ )
|
{
|
CMBGridStyleAttr *pAttr = m_vectorAttr[i];
|
if( pAttr->m_strAttr == strAttr )
|
return i;
|
}
|
return -1;
|
}
|
|
bool CMBGridStyleAttrMgr2::ParseJson( CString strCfgPath,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("%s\\GridStyle.json"),strCfgPath);
|
// ¶ÁÎļþÄÚÈÝ
|
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() )
|
{
|
|
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( !AddAttr(pAttr) )
|
{
|
delete pAttr;
|
pAttr = NULL;
|
}
|
}// end for
|
}
|
return true;
|
}
|