#include "StdAfx.h" #include "MBFireMasterClsAttrMgr.h" CMBFireMasterClsAttrMgr::CMBFireMasterClsAttrMgr(void) { RemoveAllAttr(); } CMBFireMasterClsAttrMgr::~CMBFireMasterClsAttrMgr(void) { RemoveAllAttr(); } void CMBFireMasterClsAttrMgr::GetVector( CMBFireMasterClsAttrVector &vectorAttr) { vectorAttr.clear(); vectorAttr = m_vectorAttr; } CMBFireMasterClsAttr *CMBFireMasterClsAttrMgr::GetAttr( CString strAttr ) { if( strAttr.IsEmpty() ) return NULL; CMBFireMasterClsAttrMap::iterator it; CMBFireMasterClsAttr *pAttr = NULL; it = m_mapAttr.find(strAttr); if( it!= m_mapAttr.end() ) pAttr = it->second; return pAttr; } bool CMBFireMasterClsAttrMgr::AddAttr( CMBFireMasterClsAttr *pAttr ) { if( NULL == pAttr || pAttr->m_strAttr.IsEmpty() ) return false; CMBFireMasterClsAttrMap::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 CMBFireMasterClsAttrMgr::RemoveAllAttr() { CMBFireMasterClsAttrMap::iterator it; CMBFireMasterClsAttr *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 CMBFireMasterClsAttrMgr::GetAllAttr() { CString strAttrs; CMBFireMasterClsAttrMap::iterator it; CMBFireMasterClsAttr *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 CMBFireMasterClsAttrMgr::GetAttrSql() { CString strSql,strAttrSql; CMBFireMasterClsAttrMap::iterator it; CMBFireMasterClsAttr *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; } int CMBFireMasterClsAttrMgr::GetIndex( CString strField ) { CMBFireMasterClsAttrVector::iterator it; CMBFireMasterClsAttr *pAttr = NULL; int nIndex = 0; for( it = m_vectorAttr.begin();it != m_vectorAttr.end();it++ ) { pAttr = *it; if( pAttr->m_strAttr == strField ) return nIndex; nIndex++; } return -1; } int CMBFireMasterClsAttrMgr::GetCount() { return m_vectorAttr.size(); }