#include "StdAfx.h" #include "MBTNXXXObjMgr.h" CMBTNXXXObjMgr::CMBTNXXXObjMgr(void) { RemoveAllObj(); m_nRecords = 0; m_nTotalPages = 0; m_nCurPage = 0; m_nPageSize = 0; } CMBTNXXXObjMgr::~CMBTNXXXObjMgr(void) { RemoveAllObj(); } void CMBTNXXXObjMgr::GetObjMap( CMBTNXXXObjMap &mapObj) { mapObj.clear(); mapObj = m_mapObj; } // µÃµ½vector void CMBTNXXXObjMgr::GetObjVector( CMBTNXXXObjVector &vectorObj) { vectorObj.clear(); vectorObj = m_vectorObj; } CMBTNXXXObj *CMBTNXXXObjMgr::GetObjLastVerByFilter( CString strFilter,CString strFilterValue ) { CMBTNXXXObj *pRetTNXXXObj = NULL; CString strVer,strTmpVer; CMBTNXXXObjMap mapObj; CMBTNXXXObjMap::iterator it1; CMBTNXXXObj *pObj = NULL; //CMBTNXXXAttrMap::iterator it2; //CMBTNXXXAttr *pAttr = NULL; CMBTNXXXAttrMap mapAttr; for( it1 = m_mapObj.begin();it1 != m_mapObj.end();it1++ ) { pObj = it1->second; pObj->GetAttrMap( mapAttr); // ¹ýÂË if( !strFilter.IsEmpty() && !strFilterValue.IsEmpty() ) { CMBTNXXXAttr *pTn3XAttr = pObj->GetAttr(strFilter); if( NULL != pTn3XAttr ) { if(pTn3XAttr->m_strValue != strFilterValue) { continue; } } } CMBTNXXXAttr *pVerTn3XAttr = pObj->GetAttr(_T("S_VER")); if( NULL != pVerTn3XAttr ) { strTmpVer = pVerTn3XAttr->m_strValue; strTmpVer = strTmpVer.MakeLower(); if(strVer < strTmpVer ) { strVer = strTmpVer; pRetTNXXXObj = pObj; } } } // end for( it1 = m_mapObj.begin();it1 != m_mapObj.end();it1++ ) return pRetTNXXXObj; } CMBTNXXXObj *CMBTNXXXObjMgr::GetObj( CString strObjID ) { if( strObjID.IsEmpty() ) return NULL; CMBTNXXXObjMap::iterator it; CMBTNXXXObj *pObj = NULL; it = m_mapObj.find(strObjID); if( it!= m_mapObj.end() ) pObj = it->second; return pObj; } bool CMBTNXXXObjMgr::AddObj( CMBTNXXXObj *pObj ) { if( NULL == pObj || pObj->m_strObjID.IsEmpty() ) return false; CMBTNXXXObjMap::iterator it; CString strObjID; strObjID = pObj->m_strObjID; it = m_mapObj.find(strObjID); // Èç¹ûÕҵõ½ ·µ»Ø if( it != m_mapObj.end() ) return false; m_mapObj[strObjID] = pObj; m_vectorObj.push_back(pObj); return true; } bool CMBTNXXXObjMgr::RemoveAllObj() { CMBTNXXXObjMap::iterator it; CMBTNXXXObj *pObj = NULL; for( it = m_mapObj.begin();it != m_mapObj.end();it++ ) { pObj = it->second; delete pObj; pObj = NULL; } m_vectorObj.clear(); m_mapObj.clear(); return true; } // // // // // //.... // // bool CMBTNXXXObjMgr::ParseXml(CString strXml,CString &strErrInfo) { if( strXml.IsEmpty() ) return true; CString strRecords,strTotalPages, strCurPage,strPageSize; CString strVaule,strName; pugi::xml_document xmlDoc; if (!xmlDoc.load(strXml)) { return false; } pugi::xml_node bodyNode = xmlDoc.child(_T("Body")); m_strSessionID = bodyNode.child_value(_T("SessionID")); strRecords = bodyNode.child_value(_T("Records")); strTotalPages = bodyNode.child_value(_T("TotalPages")); strCurPage = bodyNode.child_value(_T("CurPage")); strPageSize = bodyNode.child_value(_T("PageSize")); m_nRecords = _ttoi(strRecords); m_nTotalPages = _ttoi(strTotalPages); m_nCurPage = _ttoi(strCurPage); m_nPageSize = _ttoi(strPageSize); pugi::xml_node objNode = xmlDoc.child(_T("Body")).child(_T("ObjList")).child(_T("Obj")); for(pugi::xml_node node = objNode; node; node = node.next_sibling(_T("Obj"))) { CMBTNXXXObj *pObj = new CMBTNXXXObj(); pObj->m_strObjID = node.attribute(_T("ID")).value(); pugi::xml_node nodeAttr = node.child(_T("ObjAttr")).child(_T("Attr")); for(pugi::xml_node nodeTmp = nodeAttr; nodeTmp; nodeTmp = nodeTmp.next_sibling(_T("Attr"))) { CMBTNXXXAttr *pAttr = new CMBTNXXXAttr(); pAttr->m_strName = nodeTmp.attribute(_T("Name")).value(); pAttr->m_strType = nodeTmp.attribute(_T("Type")).value(); pAttr->m_strDispName = nodeTmp.child_value(_T("DispName")); pAttr->m_strValue = nodeTmp.child_value(_T("Value")); if( !pObj->AddAttr(pAttr) ) { delete pAttr; pAttr = NULL; } } if( !AddObj( pObj ) ) { delete pObj; pObj = NULL; } } return true; } CString CMBTNXXXObjMgr::GenXml() { return _T(""); } void CMBTNXXXObjMgr::GetGroupSetLst(CStringArray &arRet, CString strGroupSetAttr ) { arRet.RemoveAll(); CMBTNXXXObjVector::iterator it; CMBTNXXXObj *pObj = NULL; CMBTNXXXAttr *pAttr = NULL; for( it = m_vectorObj.begin();it != m_vectorObj.end();it++ ) { pObj = *it; pAttr = pObj->GetAttr(strGroupSetAttr); if( !CStrFileUtils::IsStrInAr( pAttr->m_strValue,arRet ) ){ arRet.Add(pAttr->m_strValue); } } }