#include "StdAfx.h" #include "MBMasterClsAttrMgr.h" CMBMasterClsAttrMgr::CMBMasterClsAttrMgr(void) { RemoveAllAttr(); } CMBMasterClsAttrMgr::~CMBMasterClsAttrMgr(void) { RemoveAllAttr(); } void CMBMasterClsAttrMgr::GetVector( CMBMasterClsAttrVector &vectorAttr) { vectorAttr.clear(); vectorAttr = m_vectorAttr; } CMBMasterClsAttr *CMBMasterClsAttrMgr::GetAttr( CString strAttr ) { if( strAttr.IsEmpty() ) return NULL; CMBMasterClsAttrMap::iterator it; CMBMasterClsAttr *pAttr = NULL; it = m_mapAttr.find(strAttr); if( it!= m_mapAttr.end() ) pAttr = it->second; return pAttr; } bool CMBMasterClsAttrMgr::AddAttr( CMBMasterClsAttr *pAttr ) { if( NULL == pAttr || pAttr->m_strAttr.IsEmpty() ) return false; CMBMasterClsAttrMap::iterator it; CString strAttr; strAttr = pAttr->m_strAttr; it = m_mapAttr.find(strAttr); // Èç¹ûÕҵõ½ ·µ»Ø if( it != m_mapAttr.end() ) return false; m_mapAttr[strAttr] = pAttr; m_vectorAttr.push_back(pAttr); return true; } bool CMBMasterClsAttrMgr::RemoveAllAttr() { CMBMasterClsAttrMap::iterator it; CMBMasterClsAttr *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; } CString CMBMasterClsAttrMgr::GetAllAttr() { CString strAttrs; CMBMasterClsAttrMap::iterator it; CMBMasterClsAttr *pAttr = NULL; for( it = m_mapAttr.begin();it != m_mapAttr.end();it++ ) { pAttr = it->second; strAttrs += pAttr->m_strAttr; strAttrs += _T(";"); } strAttrs = strAttrs.Left(strAttrs.GetLength()-1); return strAttrs; } CString CMBMasterClsAttrMgr::GetAttrSql() { CString strSql,strAttrSql; CMBMasterClsAttrMap::iterator it; CMBMasterClsAttr *pAttr = NULL; for( it = m_mapAttr.begin();it != m_mapAttr.end();it++ ) { pAttr = it->second; strAttrSql.Format(_T("%s varchar(%s),"),pAttr->m_strAttr,pAttr->m_strSize); strSql += strAttrSql; } strSql = strSql.Left(strSql.GetLength()-1); return strSql; }