#include "StdAfx.h" #include "MBVaultDbMgr.h" #include "StrFileUtils.h" #include "MBStrObjMgr.h" CMBVaultDbMgr::CMBVaultDbMgr(void):m_hWnd(NULL) { m_bSyncInit = false; m_bDbInit = false; m_nPort = 0; m_pAppExtParm = new CMBFireAppExtParam(); m_pNDWebCMgr = NULL; m_pThreadSyncDb = new CMBThreadSyncDb(); m_pThreadFireSyncDb = new CMBThreadFireSyncDb(); } CMBVaultDbMgr::~CMBVaultDbMgr(void) { if( NULL != m_pThreadSyncDb ) { delete m_pThreadSyncDb; m_pThreadSyncDb = NULL; } if( NULL != m_pThreadFireSyncDb ) { delete m_pThreadFireSyncDb; m_pThreadFireSyncDb = NULL; } if( NULL != m_pAppExtParm ) { delete m_pAppExtParm; m_pAppExtParm = NULL; } } void CMBVaultDbMgr::SetUserSessionID( CString strUserSessionID ) { m_strUserSessionID = strUserSessionID; } void CMBVaultDbMgr::SetSvrInfo( CString strSvrIP,int nPort,CString strUserID,CString strUserName,CString strPwd ) { m_strUserID = strUserID; m_strUserName = strUserName; m_strPwd = strPwd; m_strSvrIP = strSvrIP; m_nPort = nPort; } // ÉèÖÃ×ÊԴ·¾¶ void CMBVaultDbMgr::SetDbPath(CString strExePath,CString strCfgPath) { m_strExePath = strExePath; m_strCfgPath = strCfgPath; CString strExtParamPath,strErrInfo; strExtParamPath.Format(_T("%s\\AreaExtParam.json"),m_strCfgPath); CStrFileUtils::GetStrFromFile( strExtParamPath, m_strParam ); m_pAppExtParm->ParseJson(m_strParam,strErrInfo); } CString CMBVaultDbMgr::GetExePath() { return m_strExePath; } CString CMBVaultDbMgr::GetCfgPath() { return m_strCfgPath; } void CMBVaultDbMgr::SetParam(CString strParam) { strParam.Replace(_T("\\"),_T("")); m_strParam = strParam; } CString CMBVaultDbMgr::GetFireParam() { return m_strParam; } bool CMBVaultDbMgr::DbInit(CString &strErrInfo) { if( m_bDbInit ) return true; CString strDBFile,strSrcFile,strSrcFireExeFile,strFireExeFile; strSrcFile.Format(_T("%s\\data\\mbc_vault.db"),m_strExePath); // Ô­Êý¾Ý²Ö¿âËùÔڵķ¾¶ strDBFile.Format(_T("%s\\mbc_vault.db"),m_strCfgPath); // Ä¿±êÊý¾Ý²Ö¿âËùÔڵķ¾¶ /*strSrcFireExeFile.Format(_T("%s\\data\\Hangcha_CDD20_AC1S_1298_1220_140117_12_0_1.exe"),m_strExePath); strFireExeFile.Format(_T("%s\\Hangcha_CDD20_AC1S_1298_1220_140117_12_0_1.exe"),m_strCfgPath); */ if( !CStrFileUtils::IsExist( strDBFile) ) CStrFileUtils::CopySqliteDb3(strSrcFile,strDBFile); /*if( !CStrFileUtils::IsExist( strFireExeFile) ) CStrFileUtils::CopySqliteDb3(strSrcFireExeFile,strFireExeFile); */ try{ m_db.Close(); // ´ò¿ªÊý¾Ý¿â if( !m_db.Open( strDBFile )) { strErrInfo = _T("´ò¿ªsqliteʧ°Ü£¡"); return false; } } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } m_bDbInit = true; return true; } // ɾ³ýÊý¾Ý bool CMBVaultDbMgr::DelDb( CString &strErrInfo ) { m_bDbInit = false; m_db.Close(); CString strExtendPath,strFileRootPath; strExtendPath = m_strExePath + _T("\\mbc_extend"); strFileRootPath = m_strExePath + _T("\\FileRoot"); CStrFileUtils::DoRemoveDirectory(strExtendPath); CStrFileUtils::DoRemoveDirectory(strFileRootPath); return true; } // ÉèÖòÎÊý void CMBVaultDbMgr::SetParam( HWND hWnd,CMBNetDiskWebCMgr *pNDWebCMgr ) { m_hWnd = hWnd; m_pNDWebCMgr = pNDWebCMgr; m_pThreadSyncDb->SetParam( hWnd,this,pNDWebCMgr ); m_pThreadFireSyncDb->SetParam( hWnd,this,pNDWebCMgr ); } bool CMBVaultDbMgr::SyncInit( CString &strErrInfo ) { CString strUserSessionID,strRootList; if( !m_strUserSessionID.IsEmpty() ) { m_pNDWebCMgr->SetUserInfo( m_strUserID, m_strUserName ); m_pNDWebCMgr->SetServerInfo( m_strSvrIP, m_nPort); m_pNDWebCMgr->SetUserSessionID( m_strUserSessionID ); if(!m_pNDWebCMgr->SignIn( strRootList,strErrInfo )) // SessionID return false; }else{ m_pNDWebCMgr->SetUserInfo( m_strUserID, m_strUserName ); m_pNDWebCMgr->SetServerInfo( m_strSvrIP, m_nPort); if(!m_pNDWebCMgr->SignIn(m_strPwd,strUserSessionID, strRootList,strErrInfo)) return false; } m_bSyncInit = true; return true; } bool CMBVaultDbMgr::SyncDb( CString &strErrInfo ) { if( !m_bSyncInit ) { strErrInfo = _T("ÇëÏȽøÐÐͬ²½³õʼ»¯£¡"); return false; } if( !m_bDbInit ) { strErrInfo = _T("ÇëÏȽøÐÐÊý¾Ý¿â³õʼ»¯£¡"); return false; } m_pThreadSyncDb->StartThread(); // ÓÃÒ»¸öÏß³ÌÀ´×ö return true; } // µ÷Óýӿڣ¬Í¬²½±¾µØÊý¾Ý¿â bool CMBVaultDbMgr::FireSyncDb( CString strParam,CString &strErrInfo ) { CString strExtParamPath; if( !m_bSyncInit ) { strErrInfo = _T("ÇëÏȽøÐÐͬ²½³õʼ»¯£¡"); return false; } if( !m_bDbInit ) { strErrInfo = _T("ÇëÏȽøÐÐÊý¾Ý¿â³õʼ»¯£¡"); return false; } SetParam(strParam); strExtParamPath.Format(_T("%s\\AreaExtParam.json"),m_strCfgPath); if(!CStrFileUtils::WriteFile(strExtParamPath,m_strParam,strErrInfo )) return false; if(!m_pAppExtParm->ParseJson(m_strParam,strErrInfo)) return false; m_pThreadFireSyncDb->SetJsonParm( strParam ); m_pThreadFireSyncDb->StartThread(); // ÓÃÒ»¸öÏß³ÌÀ´×ö return true; } // ÉèÖÃVaultµ½Db bool CMBVaultDbMgr::SetVaultToDb(CMBVault *pVault,CString &strErrInfo) { if( NULL == pVault ) return false; bool bExsit = IsExsitVaultInDb( pVault->m_strID,strErrInfo ); if( bExsit ) // ´æÔÚ¸üР{ if( !UpdateVaultToDb(pVault,strErrInfo) ) return false; } else // ²»´æÔÚ£¬´´½¨ { if(!InsertVaultToDb(pVault,strErrInfo) ) return false; } return true; } // ´æÔÚµç×Ó²Ö¿â bool CMBVaultDbMgr::IsExsitVaultInDb( CString strVaultID,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; try{ strSql.Format(_T("select * from OI_VAULT where CN_G_ID='%s'"),strVaultID); if(!dbRecord.Open(&m_db,strSql)) return false; nRecordCount = dbRecord.GetRecordCount(); if( 0 == nRecordCount ) return false; } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ²åÈëOI_VAULT bool CMBVaultDbMgr::InsertVaultToDb(CMBVault *pVault,CString &strErrInfo) { if( NULL == pVault ) return false; CString strSql; strSql.Format(_T("insert into OI_VAULT(CN_G_ID,CN_S_NAME,CN_S_BAK,CN_S_CLS_ID,CN_S_ADMINSTRATOR,CN_S_ADMINSTRATOR_ID, \ CN_C_ACE,CN_S_CREATOR_NAME,CN_T_CREATE,CN_S_P_NAME,CN_N_BK_COLOR,CN_S_IMG_FONT_STYLE, \ CN_S_QUERY_CLSATTR,CN_S_EXT_ADMIN, CN_S_EXTPARAMTER) \ VALUES(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\", \ \"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\", \ \"%s\",\"%s\",\"%s\")"), pVault->m_strID,pVault->m_strName,pVault->m_strBAK,pVault->m_strClsID,pVault->m_strAdminstrator, pVault->m_strAdminstratorID, pVault->m_strAce, pVault->m_strCreatorName,pVault->m_strTCreate, pVault->m_strPName, pVault->m_nBkColor, pVault->m_strImgFontStyle, pVault->m_strQueryClsAttr,pVault->m_strExtAdmin,pVault->m_strExtParamter); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ¸üÐÂOI_VAULT bool CMBVaultDbMgr::UpdateVaultToDb(CMBVault *pVault,CString &strErrInfo) { CString strSql; strSql.Format(_T("UPDATE OI_VAULT SET CN_S_NAME=\"%s\",CN_S_BAK=\"%s\",CN_S_CLS_ID=\"%s\",CN_S_ADMINSTRATOR=\"%s\",CN_S_ADMINSTRATOR_ID=\"%s\", \ CN_C_ACE=\"%s\",CN_S_CREATOR_NAME=\"%s\",CN_T_CREATE=\"%s\",CN_S_P_NAME=\"%s\",CN_N_BK_COLOR=\"%s\",CN_S_IMG_FONT_STYLE=\"%s\", \ CN_S_QUERY_CLSATTR=\"%s\",CN_S_EXT_ADMIN=\"%s\", CN_S_EXTPARAMTER=\"%s\" where CN_G_ID='%s'"), pVault->m_strName,pVault->m_strBAK,pVault->m_strClsID,pVault->m_strAdminstrator, pVault->m_strAdminstratorID, pVault->m_strAce, pVault->m_strCreatorName,pVault->m_strTCreate, pVault->m_strPName, pVault->m_nBkColor, pVault->m_strImgFontStyle, pVault->m_strQueryClsAttr,pVault->m_strExtAdmin,pVault->m_strExtParamter,pVault->m_strID); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ÉèÖÃVaultCatalogµ½Db bool CMBVaultDbMgr::SetVaultCatalogToDb(CMBVaultCatalog *pVaultCatalog,CString &strErrInfo) { if( NULL == pVaultCatalog ) return false; bool bExsit = IsExsitVaultCatalogInDb( pVaultCatalog->m_strID,strErrInfo ); if( bExsit ) // ´æÔÚ¸üР{ if( !UpdateVaultCatalogToDb(pVaultCatalog,strErrInfo) ) return false; } else // ²»´æÔÚ£¬´´½¨ { if(!InsertVaultCatalogToDb(pVaultCatalog,strErrInfo) ) return false; } return true; } bool CMBVaultDbMgr::IsExsitVaultCatalogInDb( CString strVaultCatalogID,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; try{ strSql.Format(_T("select * from OI_VAULT_CATALOG where CN_G_ID='%s'"),strVaultCatalogID); if(!dbRecord.Open(&m_db,strSql)) return false; nRecordCount = dbRecord.GetRecordCount(); if( 0 == nRecordCount ) return false; } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ²åÈëVaultCatalog bool CMBVaultDbMgr::InsertVaultCatalogToDb(CMBVaultCatalog *pVaultCatalog,CString &strErrInfo) { if( NULL == pVaultCatalog ) return false; CString strSql; strSql.Format(_T("insert into OI_VAULT_CATALOG(CN_G_ID,CN_S_NAME,CN_S_DESC,CN_S_CREATOR_NAME,CN_T_CREATE,CN_C_ACE, \ CN_N_ORDER,CN_S_MASTER_ID,CN_S_MASTER_NAME,CN_G_PARENT_ID,CN_G_VAULT_ID) VALUES(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\", \ \"%d\",\"%s\",\"%s\",\"%s\",\"%s\")"), pVaultCatalog->m_strID,pVaultCatalog->m_strName,pVaultCatalog->m_strDesc,pVaultCatalog->m_strCreatorName,pVaultCatalog->m_strTCreate, pVaultCatalog->m_strAce, pVaultCatalog->m_nOrder,pVaultCatalog->m_strMastrID,pVaultCatalog->m_strMastrName,pVaultCatalog->m_strParentID,pVaultCatalog->m_strVaultID ); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ¸üÐÂVaultCatalog bool CMBVaultDbMgr::UpdateVaultCatalogToDb(CMBVaultCatalog *pVaultCatalog,CString &strErrInfo) { CString strSql; strSql.Format(_T("UPDATE OI_VAULT_CATALOG SET CN_S_NAME=\"%s\",CN_S_DESC=\"%s\",CN_S_CREATOR_NAME=\"%s\",CN_T_CREATE=\"%s\",CN_C_ACE=\"%s\", \ CN_N_ORDER=\"%d\",CN_S_MASTER_ID=\"%s\",CN_S_MASTER_NAME=\"%s\",CN_G_PARENT_ID=\"%s\",CN_G_VAULT_ID=\"%s\" where CN_G_ID='%s'"), pVaultCatalog->m_strName,pVaultCatalog->m_strDesc,pVaultCatalog->m_strCreatorName,pVaultCatalog->m_strTCreate, pVaultCatalog->m_strAce, pVaultCatalog->m_nOrder,pVaultCatalog->m_strMastrID,pVaultCatalog->m_strMastrName,pVaultCatalog->m_strParentID,pVaultCatalog->m_strVaultID,pVaultCatalog->m_strID ); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ÅжϱíÊÇ·ñ´æÔÚ bool CMBVaultDbMgr::IsExsitTableInDb( CString strTableName,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; try{ strSql.Format(_T("SELECT * FROM sqlite_master WHERE type='table' and name='%s'"),strTableName); if(!dbRecord.Open(&m_db,strSql)) return false; nRecordCount = dbRecord.GetRecordCount(); if( 0 == nRecordCount ) return false; } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ɾ³ý±í bool CMBVaultDbMgr::DropTableInDb( CString strTableName,CString &strErrInfo ) { CString strSql; strSql.Format(_T("DROP TABLE %s"),strTableName ); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ´´½¨±í bool CMBVaultDbMgr::CreateTableInDb( CString strTableName,CString strTableSql,CString &strErrInfo ) { bool bExsit = IsExsitTableInDb(strTableName,strErrInfo); if( bExsit ) { /*if(!DropTableInDb( strTableName,strErrInfo )) return false; */ return true; } /// ´´½¨ if(!CreateTableInDb( strTableSql,strErrInfo )) return false; return true; } bool CMBVaultDbMgr::CreateTableInDb2( CString strTableName,CString strTableSql,CString &strErrInfo ) { bool bExsit = IsExsitTableInDb(strTableName,strErrInfo); if( bExsit ) { return true; } /// ´´½¨ if(!CreateTableInDb( strTableSql,strErrInfo )) return false; return true; } // ´´½¨±í bool CMBVaultDbMgr::CreateTableInDb( CString strTableSql,CString &strErrInfo ) { try{ int nRet = CDBSQLiteCommFun::RunSQL(strTableSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ²åÈë±í bool CMBVaultDbMgr::InsertTableInDb( CString strInsertSql,CString &strErrInfo ) { try{ int nRet = CDBSQLiteCommFun::RunSQL(strInsertSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::RunSQLInDb(CString strSql,CString &strErrInfo) { try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::IsExsitDataInDb(CString strSql,CString &strErrInfo) { CDBRecord dbRecord; long nRecordCount = 0; try{ if(!dbRecord.Open(&m_db,strSql)) return false; nRecordCount = dbRecord.GetRecordCount(); if( 0 == nRecordCount ) return false; } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::DelVaultCatalogHlink( CString &strErrInfo ) { CString strSql; try{ strSql.Format(_T("delete from OI_VAULT_CATALOG_HLINK")); int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::InsertVaultCatalogHlink( CMBVaultCatalogHlink *pVaultCatalogHlink,CString &strErrInfo ) { if( NULL == pVaultCatalogHlink ) return false; CString strSql; strSql.Format(_T("insert into OI_VAULT_CATALOG_HLINK(CN_G_CATALOG_ID,CN_S_CLS_ID,CN_G_OBJ_ID,CN_G_VID,CN_S_DISPLAY_NAME, \ CN_S_EXTATTR,CN_S_CREATOR,CN_T_LINK,CN_N_ORDER,CN_G_VAULT_ID, \ CN_S_TAGS) VALUES(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\", \ \"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\")"), pVaultCatalogHlink->m_strCatalogID,pVaultCatalogHlink->m_strClsID,pVaultCatalogHlink->m_strObjID,pVaultCatalogHlink->m_strVID, pVaultCatalogHlink->m_strDisplayName, pVaultCatalogHlink->m_strExtAttr, pVaultCatalogHlink->m_strCreator,pVaultCatalogHlink->m_strTLink,pVaultCatalogHlink->m_nOrder,pVaultCatalogHlink->m_strVaultID, pVaultCatalogHlink->m_strTags ); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } /////////////////////////////////////////////////////////////////////////////// bool CMBVaultDbMgr::VaultCatalogSubCount(CString strVaultID,CString strCatalogID,int &nSubCount,CString &strErrInfo) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strSql.Format(_T("select (select count(1) from OI_VAULT_CATALOG where CN_G_PARENT_ID='%s' and CN_G_VAULT_ID='%s') AS SumCount"),strCatalogID,strVaultID); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } HRESULT hR = dbRecord.MoveFirst(); if(S_OK== hR ) { dbRecord.GetValue(_T("SumCount"),nRecordCount); } nSubCount = nRecordCount; dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::VaultCatalogObjCount(CString strVaultID,CString strCatalogID,int &nObjCount,CString &strErrInfo) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strSql.Format(_T("select (select count(1) from OI_VAULT_CATALOG_HLINK where CN_G_CATALOG_ID='%s' and CN_G_VAULT_ID='%s') AS SumCount"),strCatalogID,strVaultID); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOG_HLINKʧ°Ü£¡"); return false; } HRESULT hR = dbRecord.MoveFirst(); if(S_OK== hR ) { dbRecord.GetValue(_T("SumCount"),nRecordCount); } nObjCount = nRecordCount; dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::VaultCatalogSubAndObjCount(CString strVaultID,CMBVaultCatalogMgr *pVaultCatalogMgr,CString &strErrInfo ) { if( NULL == pVaultCatalogMgr ) return false; int nSubCount = 0; int nObjCount = 0; CMBVaultCatalogVector::iterator it; CMBVaultCatalog *pVaultCatalog = NULL; CMBVaultCatalogVector vectorCatalog; pVaultCatalogMgr->GetVaultCatalogVector( vectorCatalog ); for( it = vectorCatalog.begin();it != vectorCatalog.end();it++ ) { pVaultCatalog = *it; VaultCatalogSubCount(strVaultID,pVaultCatalog->m_strID,nSubCount,strErrInfo); VaultCatalogObjCount(strVaultID,pVaultCatalog->m_strID,nObjCount,strErrInfo); pVaultCatalog->m_nSubCount = nSubCount; pVaultCatalog->m_nObjCount = nObjCount; } return true; } bool CMBVaultDbMgr::VaultSubAndObjCount(CMBVaultMgr *pVaultMgr,CString &strErrInfo ) { if( NULL == pVaultMgr ) return false; int nSubCount = 0; int nObjCount = 0; CMBVaultVector vector; CMBVaultVector::iterator it; CMBVault *pVault = NULL; pVaultMgr->GetVaultVector( vector ); for( it = vector.begin();it != vector.end();it++ ) { pVault = *it; VaultCatalogSubCount(pVault->m_strID,_T(""),nSubCount,strErrInfo); /*VaultCatalogObjCount(pVault->m_strID,_T(""),nObjCount,strErrInfo);*/ pVault->m_nSubCount = nSubCount; pVault->m_nObjCount = nObjCount; } return true; } bool CMBVaultDbMgr::LoadVaultCataLog( CDBRecord &dbRecord,CMBVaultCatalogMgr *pVaultCatalogMgr, CString &strErrInfo ) { if( pVaultCatalogMgr == NULL ){ strErrInfo = _T("CMBVaultCatalogMgr£¬¶ÔÏóδ³õʼ»¯"); return false; } int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { CMBVaultCatalog *pVaultCatalog = new CMBVaultCatalog(); dbRecord.GetValue(_T("CN_G_ID"),pVaultCatalog->m_strID); dbRecord.GetValue(_T("CN_S_NAME"),pVaultCatalog->m_strName); dbRecord.GetValue(_T("CN_S_DESC"),pVaultCatalog->m_strDesc); //dbRecord.GetValue(_T("CN_S_CREATOR_ID"),pVaultCatalog->m_strCreatorID); dbRecord.GetValue(_T("CN_S_CREATOR_NAME"),pVaultCatalog->m_strCreatorName); dbRecord.GetValue(_T("CN_T_CREATE"),pVaultCatalog->m_strTCreate); dbRecord.GetValue(_T("CN_C_ACE"),pVaultCatalog->m_strAce); dbRecord.GetValue(_T("CN_N_ORDER"),pVaultCatalog->m_nOrder); dbRecord.GetValue(_T("CN_S_MASTER_ID"),pVaultCatalog->m_strMastrID); dbRecord.GetValue(_T("CN_T_CREATE"),pVaultCatalog->m_strTCreate); dbRecord.GetValue(_T("CN_S_MASTER_NAME"),pVaultCatalog->m_strMastrName); dbRecord.GetValue(_T("CN_G_PARENT_ID"),pVaultCatalog->m_strParentID); dbRecord.GetValue(_T("CN_G_VAULT_ID"),pVaultCatalog->m_strVaultID); if(!pVaultCatalogMgr->AddVaultCatalog(pVaultCatalog)) { delete pVaultCatalog; pVaultCatalog = NULL; } hR = dbRecord.MoveNext(); } return true; } bool CMBVaultDbMgr::LoadVault( CDBRecord &dbRecord,CMBVault *pVault, CString &strErrInfo ) { if( pVault == NULL ){ strErrInfo = _T("CMBVault,¶ÔÏóδ³õʼ»¯"); return false; } int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { dbRecord.GetValue(_T("CN_G_ID"),pVault->m_strID); dbRecord.GetValue(_T("CN_S_NAME"),pVault->m_strName); dbRecord.GetValue(_T("CN_S_BAK"),pVault->m_strBAK); dbRecord.GetValue(_T("CN_S_CLS_ID"),pVault->m_strClsID); dbRecord.GetValue(_T("CN_S_ADMINSTRATOR"),pVault->m_strAdminstrator); dbRecord.GetValue(_T("CN_S_ADMINSTRATOR_ID"),pVault->m_strAdminstratorID); dbRecord.GetValue(_T("CN_C_ACE"),pVault->m_strAce); dbRecord.GetValue(_T("CN_S_CREATOR_NAME"),pVault->m_strCreatorName); dbRecord.GetValue(_T("CN_T_CREATE"),pVault->m_strTCreate); dbRecord.GetValue(_T("CN_S_P_NAME"),pVault->m_strPName); dbRecord.GetValue(_T("CN_N_BK_COLOR"),pVault->m_nBkColor); dbRecord.GetValue(_T("CN_S_IMG_FONT_STYLE"),pVault->m_strImgFontStyle); dbRecord.GetValue(_T("CN_S_QUERY_CLSATTR"),pVault->m_strQueryClsAttr); dbRecord.GetValue(_T("CN_S_EXT_ADMIN"),pVault->m_strExtAdmin); dbRecord.GetValue(_T("CN_S_EXTPARAMTER"),pVault->m_strExtParamter); hR = dbRecord.MoveNext(); } return true; } bool CMBVaultDbMgr::LoadVault( CDBRecord &dbRecord,CMBVaultMgr *pVaultMgr, CString &strErrInfo ) { if( pVaultMgr == NULL ){ strErrInfo = _T("CMBVault,¶ÔÏóδ³õʼ»¯"); return false; } int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { CMBVault *pVault = new CMBVault(); dbRecord.GetValue(_T("CN_G_ID"),pVault->m_strID); dbRecord.GetValue(_T("CN_S_NAME"),pVault->m_strName); dbRecord.GetValue(_T("CN_S_BAK"),pVault->m_strBAK); dbRecord.GetValue(_T("CN_S_CLS_ID"),pVault->m_strClsID); dbRecord.GetValue(_T("CN_S_ADMINSTRATOR"),pVault->m_strAdminstrator); dbRecord.GetValue(_T("CN_S_ADMINSTRATOR_ID"),pVault->m_strAdminstratorID); dbRecord.GetValue(_T("CN_C_ACE"),pVault->m_strAce); dbRecord.GetValue(_T("CN_S_CREATOR_NAME"),pVault->m_strCreatorName); dbRecord.GetValue(_T("CN_T_CREATE"),pVault->m_strTCreate); dbRecord.GetValue(_T("CN_S_P_NAME"),pVault->m_strPName); dbRecord.GetValue(_T("CN_N_BK_COLOR"),pVault->m_nBkColor); dbRecord.GetValue(_T("CN_S_IMG_FONT_STYLE"),pVault->m_strImgFontStyle); dbRecord.GetValue(_T("CN_S_QUERY_CLSATTR"),pVault->m_strQueryClsAttr); dbRecord.GetValue(_T("CN_S_EXT_ADMIN"),pVault->m_strExtAdmin); dbRecord.GetValue(_T("CN_S_EXTPARAMTER"),pVault->m_strExtParamter); if( !pVaultMgr->AddVault(pVault) ) { delete pVault; pVault = NULL; } hR = dbRecord.MoveNext(); } return true; } bool CMBVaultDbMgr::LoadTNXXXObj( CDBRecord &dbRecord,CString &strTNXXXXml, CString &strErrInfo ) { CString strFieldVaule,strFieldName,strIDFieldVaule; CString strObjXml,strObjsXml,strAttrXml,strAttrsXml; int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { int nColsCount = dbRecord.GetColsCount(); strAttrsXml = _T(""); for( int i = 1;i <= nColsCount;i++ ) { strFieldName = dbRecord.GetFieldName(i); dbRecord.GetValue( i, strFieldVaule); if( strFieldName == _T("S_ID") ) { strIDFieldVaule = strFieldVaule; }else{ strAttrXml.Format(_T(""),strFieldName,strFieldVaule); strAttrsXml += strAttrXml; } } strObjXml.Format(_T("%s"),strIDFieldVaule,strAttrsXml); strObjsXml += strObjXml; hR = dbRecord.MoveNext(); } strTNXXXXml.Format(_T("%s"),strObjsXml); return true; } bool CMBVaultDbMgr::LoadTNXXXObj2( CDBRecord &dbRecord,CString &strTNXXXXml, CString &strErrInfo ) { CString strFieldVaule,strFieldName,strIDFieldVaule; CString strObjXml,strObjsXml,strAttrXml,strAttrsXml,strState; int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { int nColsCount = dbRecord.GetColsCount(); strAttrsXml = _T(""); dbRecord.GetValue( _T("S_STATE"), strState ); strState = strState.Trim(); if( strState == _T("×÷·Ï") ){ hR = dbRecord.MoveNext(); continue; } for( int i = 1;i <= nColsCount;i++ ) { strFieldName = dbRecord.GetFieldName(i); dbRecord.GetValue( i, strFieldVaule); if( strFieldName == _T("S_ID") ) { strIDFieldVaule = strFieldVaule; }else{ strAttrXml.Format(_T(""),strFieldName,strFieldVaule); strAttrsXml += strAttrXml; } } strObjXml.Format(_T("%s"),strIDFieldVaule,strAttrsXml); strObjsXml += strObjXml; hR = dbRecord.MoveNext(); } strTNXXXXml.Format(_T("%s"),strObjsXml); return true; } bool CMBVaultDbMgr::LoadTNXXXObj2( CDBRecord &dbRecord,CString &strTNXXXXml,CStringArray &arIDs, CString &strErrInfo ) { CString strFieldVaule,strFieldName,strIDFieldVaule; CString strObjXml,strObjsXml,strAttrXml,strAttrsXml,strState; int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; CMBStrObjMgr *pStrObjMgr = new CMBStrObjMgr(); HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { int nColsCount = dbRecord.GetColsCount(); strAttrsXml = _T(""); dbRecord.GetValue( _T("S_STATE"), strState ); strState = strState.Trim(); if( strState == _T("×÷·Ï") ){ hR = dbRecord.MoveNext(); continue; } for( int i = 1;i <= nColsCount;i++ ) { strFieldName = dbRecord.GetFieldName(i); dbRecord.GetValue( i, strFieldVaule); if( strFieldName == _T("S_ID") ) { strIDFieldVaule = strFieldVaule; }else{ strAttrXml.Format(_T(""),strFieldName,strFieldVaule); strAttrsXml += strAttrXml; } } strObjXml.Format(_T("%s"),strIDFieldVaule,strAttrsXml); CMBStrObj *pObj = new CMBStrObj(); pObj->m_strID = strIDFieldVaule; pObj->m_strObjXml = strObjXml; if(!pStrObjMgr->Add(pObj)) { delete pObj; pObj = NULL; } //strObjsXml += strObjXml; hR = dbRecord.MoveNext(); } // ΪÁËÅÅÐò for( int i =0;i < arIDs.GetCount();i++ ) { CMBStrObj *pStrObj = pStrObjMgr->Get(arIDs[i]); if( pStrObj ) { strObjsXml += pStrObj->m_strObjXml; } } if( pStrObjMgr ) { delete pStrObjMgr; pStrObjMgr = NULL; } strTNXXXXml.Format(_T("%s"),strObjsXml); return true; } bool CMBVaultDbMgr::CreateTN_MClsID_DClsID( CString strTableName,CString strTableSql,CString &strErrInfo ) { if( IsExsitTableInDb( strTableName,strErrInfo ) ) return true; if( !CreateTableInDb( strTableName, strTableSql,strErrInfo ) ) return false; return true; } bool CMBVaultDbMgr::VaultGetList( CString &strVaultList,CString &strErrInfo,bool bNeedAce, short nVaultType ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strSql.Format(_T("select * from OI_VAULT")); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULTʧ°Ü£¡"); return false; } CMBVaultMgr *pVaultMgr = new CMBVaultMgr(); if( !LoadVault( dbRecord,pVaultMgr, strErrInfo )) { delete pVaultMgr; pVaultMgr = NULL; return false; } if(!VaultSubAndObjCount(pVaultMgr,strErrInfo )) { delete pVaultMgr; pVaultMgr = NULL; return false; } strVaultList = pVaultMgr->GenXml(); delete pVaultMgr; pVaultMgr = NULL; dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // µÃµ½Êý¾Ý²Ö¿âÐÅÏ¢ bool CMBVaultDbMgr::VaultGetInfo( CString strVaultID, CString &strVaultInfo,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strSql.Format(_T("select * from OI_VAULT where CN_G_ID='%s'"),strVaultID); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULTʧ°Ü£¡"); return false; } CMBVault *pVault = new CMBVault(); if(!LoadVault( dbRecord,pVault, strErrInfo )) { delete pVault; pVault = NULL; return false; } strVaultInfo = pVault->GenXml(); delete pVault; pVault = NULL; dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // µÃµ½Ï¼¶Ä¿Â¼Áбí bool CMBVaultDbMgr::VaultCatalogGetList( CString strVaultID, CString strParentID, CString &strCatalogList,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strSql.Format(_T("select *from OI_VAULT_CATALOG where CN_G_VAULT_ID='%s' and CN_G_PARENT_ID='%s'"),strVaultID,strParentID); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } CMBVaultCatalogMgr *pVaultCatalogMgr = new CMBVaultCatalogMgr(); if( !LoadVaultCataLog( dbRecord,pVaultCatalogMgr, strErrInfo ) ) { // ÊÍ·Å delete pVaultCatalogMgr; pVaultCatalogMgr = NULL; return false; } if(!VaultCatalogSubAndObjCount( strVaultID,pVaultCatalogMgr,strErrInfo )) { // ÊÍ·Å delete pVaultCatalogMgr; pVaultCatalogMgr = NULL; return false; } strCatalogList = pVaultCatalogMgr->GenXML(); // ÊÍ·Å delete pVaultCatalogMgr; pVaultCatalogMgr = NULL; dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // µÃµ½Ä¿Â¼ÏµÄÊý¾Ý¶ÔÏó bool CMBVaultDbMgr::VaultQueryCatalogObj( CString strClsID,CString strVaultID, CString strCatalogID, CString &strResult,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; if(strCatalogID.IsEmpty()) strSql.Format(_T("select *from TN_%s where S_ID in(select CN_G_OBJ_ID from OI_VAULT_CATALOG_HLINK where CN_G_VAULT_ID='%s')"),strClsID,strVaultID); else strSql.Format(_T("select *from TN_%s where S_ID in(select CN_G_OBJ_ID from OI_VAULT_CATALOG_HLINK where CN_G_VAULT_ID='%s' and CN_G_CATALOG_ID='%s')"),strClsID,strVaultID,strCatalogID); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULTʧ°Ü£¡"); return false; } if(!LoadTNXXXObj( dbRecord,strResult, strErrInfo )) { return false; } dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::VaultQueryCatalogList( CString strVaultID, CString strQueryContent, CString &strCatalogList,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strSql.Format(_T("select *from OI_VAULT_CATALOG where CN_G_VAULT_ID='%s' and CN_S_NAME like '%%%s%%'"),strVaultID,strQueryContent); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } CMBVaultCatalogMgr *pVaultCatalogMgr = new CMBVaultCatalogMgr(); if( !LoadVaultCataLog( dbRecord,pVaultCatalogMgr, strErrInfo ) ) { // ÊÍ·Å delete pVaultCatalogMgr; pVaultCatalogMgr = NULL; return false; } //if(!VaultCatalogSubAndObjCount( strVaultID,pVaultCatalogMgr,strErrInfo )) //{ // // ÊÍ·Å // delete pVaultCatalogMgr; // pVaultCatalogMgr = NULL; // return false; //} strCatalogList = pVaultCatalogMgr->GenXML(); // ÊÍ·Å delete pVaultCatalogMgr; pVaultCatalogMgr = NULL; dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // ´æÔÚÊý¾Ý bool CMBVaultDbMgr::IsExsitDataInTNXXXXXX(bool &bExsit,CString &strErrInfo) { bExsit = false; CString strSql; CDBRecord dbRecord; long nRecordCount = 0; CString strTNXXXXXXName = m_pAppExtParm->GetTN_XXX_XXXTableName(); if( !IsExsitTableInDb(strTNXXXXXXName,strErrInfo) ) return true; strSql.Format(_T("select (select count(1) from %s ) AS SumCount"),strTNXXXXXXName); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±í ") + strTNXXXXXXName + _T("ʧ°Ü£¡"); return false; } HRESULT hR = dbRecord.MoveFirst(); if(S_OK== hR ) { dbRecord.GetValue(_T("SumCount"),nRecordCount); } if( nRecordCount > 0 ) { bExsit = true; } dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::LoadTNXXXXXX( CDBRecord &dbRecord,CString strKeyFiledName,CMBTNXXXXXXMgr *pTN6XMgr, CString &strErrInfo) { if( pTN6XMgr == NULL ){ strErrInfo = _T("CMBTNXXXXXXMgr,¶ÔÏóδ³õʼ»¯"); return false; } CString strFieldName,strFieldVaule; int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { int nColsCount = dbRecord.GetColsCount(); CMBTNXXXXXX *pTNXXXXXX = new CMBTNXXXXXX(); for( int i = 1;i <= nColsCount;i++ ) { strFieldName = dbRecord.GetFieldName(i); dbRecord.GetValue( i, strFieldVaule); if( strFieldName == _T("G_MASTER_OBJ_ID") ){ pTNXXXXXX->m_strMID = strFieldVaule; } else if( strFieldName == _T("G_SLAVE_OBJ_ID") ){ pTNXXXXXX->m_strSID = strFieldVaule; } else if( strFieldName == _T("G_SLAVE_OBJ_VID") ){ pTNXXXXXX->m_strVID = strFieldVaule; } else if( strFieldName == _T("C_Order") ){ pTNXXXXXX->m_strOrder = strFieldVaule; } else if( strFieldName == _T("C_Effect") ){ pTNXXXXXX->m_strEffect = strFieldVaule; } else if( strFieldName == _T("C_Invalidate") ){ pTNXXXXXX->m_strInvalidate = strFieldVaule; } else if( strFieldName == _T("C_DisplayName") ){ pTNXXXXXX->m_strDisplayName = strFieldVaule; } else if( strFieldName == _T("C_JoinTime") ){ pTNXXXXXX->m_strJoinTime = strFieldVaule; } else{ CMBTNXXXXXXFiled *pFiled = new CMBTNXXXXXXFiled(); pFiled->m_strFiled = strFieldName; pFiled->m_strValue = strFieldVaule; if( !pTNXXXXXX->GetFieldMgr()->Add(pFiled) ) { MBSAFE_DELETE(pFiled) } } } if( !pTN6XMgr->Add(pTNXXXXXX) ) { MBSAFE_DELETE(pTNXXXXXX) } hR = dbRecord.MoveNext(); } return true; } bool CMBVaultDbMgr::LoadTNXXXXXX2( CDBRecord &dbRecord,CMBTNXXXXXXMgr *pTN6XMgr, CString &strErrInfo) { if( pTN6XMgr == NULL ){ strErrInfo = _T("CMBTNXXXXXXMgr2,¶ÔÏóδ³õʼ»¯"); return false; } CString strFieldName,strFieldVaule; int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { int nColsCount = dbRecord.GetColsCount(); CMBTNXXXXXX *pTNXXXXXX = new CMBTNXXXXXX(); for( int i = 1;i <= nColsCount;i++ ) { strFieldName = dbRecord.GetFieldName(i); dbRecord.GetValue( i, strFieldVaule); if( strFieldName == _T("G_MASTER_OBJ_ID") ){ pTNXXXXXX->m_strMID = strFieldVaule; } else if( strFieldName == _T("G_SLAVE_OBJ_ID") ){ pTNXXXXXX->m_strSID = strFieldVaule; } else if( strFieldName == _T("G_SLAVE_OBJ_VID") ){ pTNXXXXXX->m_strVID = strFieldVaule; } else if( strFieldName == _T("C_Order") ){ pTNXXXXXX->m_strOrder = strFieldVaule; } else if( strFieldName == _T("C_Effect") ){ pTNXXXXXX->m_strEffect = strFieldVaule; } else if( strFieldName == _T("C_Invalidate") ){ pTNXXXXXX->m_strInvalidate = strFieldVaule; } else if( strFieldName == _T("C_DisplayName") ){ pTNXXXXXX->m_strDisplayName = strFieldVaule; } else if( strFieldName == _T("C_JoinTime") ){ pTNXXXXXX->m_strJoinTime = strFieldVaule; } else{ CMBTNXXXXXXFiled *pFiled = new CMBTNXXXXXXFiled(); pFiled->m_strFiled = strFieldName; pFiled->m_strValue = strFieldVaule; if( !pTNXXXXXX->GetFieldMgr()->Add(pFiled) ) { MBSAFE_DELETE(pFiled) } } } if( !pTN6XMgr->Add(pTNXXXXXX) ) { MBSAFE_DELETE(pTNXXXXXX) } hR = dbRecord.MoveNext(); } return true; } bool CMBVaultDbMgr::TNXXXXXXQueryKey( CString strKey,CString &strResult,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; CString strTNXXXXXXName = m_pAppExtParm->GetTN_XXX_XXXTableName(); CString strKeyFiledName = m_pAppExtParm->GetMasterCls()->m_strKeyAttr; //strSql.Format(_T("select * from %s where %s like '%%%s%%' Group by %s"),strTNXXXXXXName,strKeyFiledName,strKey,strKeyFiledName); strSql.Format(_T("select * from %s where %s Group by %s"),strTNXXXXXXName,strKey,strKeyFiledName); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } CMBTNXXXXXXMgr *pTN6XMgr = new CMBTNXXXXXXMgr(); if( !LoadTNXXXXXX( dbRecord,strKeyFiledName,pTN6XMgr, strErrInfo) ){ MBSAFE_DELETE(pTN6XMgr) return false; } strResult = pTN6XMgr->GenXml(); MBSAFE_DELETE(pTN6XMgr) dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::TNXXXXXXQueryByID( CString strKeyValue,CStringArray &arID,CString &strErrInfo ) { CString strSql,strOrderBy; CDBRecord dbRecord; long nRecordCount = 0; CString strTN3XName = m_pAppExtParm->GetTN_XXXTableName(); CString strTN6XName = m_pAppExtParm->GetTN_XXX_XXXTableName(); strOrderBy = m_pAppExtParm->GetComposeCls()->GetOrderByDesc(); // дһÏÂÅÅÐò if(strOrderBy.IsEmpty() ) strSql.Format(_T("select G_SLAVE_OBJ_ID from %s where code='%s'"),strTN6XName,strKeyValue); else strSql.Format(_T("select G_SLAVE_OBJ_ID from %s where code='%s' order by %s"),strTN6XName,strKeyValue,strOrderBy); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } CMBTNXXXXXXMgr *pTN6XMgr = new CMBTNXXXXXXMgr(); if( !LoadTNXXXXXX2( dbRecord,pTN6XMgr, strErrInfo) ){ MBSAFE_DELETE(pTN6XMgr) return false; } pTN6XMgr->GetSID( arID ); MBSAFE_DELETE(pTN6XMgr) dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::TNXXXXXXQueryByID( CString strMID,CString strSID,CString &strResult,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; CString strTNXXXXXXName = m_pAppExtParm->GetTN_XXX_XXXTableName(); CString strKeyFiledName = m_pAppExtParm->GetMasterCls()->m_strKeyAttr; strSql.Format(_T("select * from %s where G_MASTER_OBJ_ID='%s' and G_SLAVE_OBJ_ID='%s'"),strTNXXXXXXName,strMID,strSID); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } CMBTNXXXXXXMgr *pTN6XMgr = new CMBTNXXXXXXMgr(); if( !LoadTNXXXXXX( dbRecord,strKeyFiledName,pTN6XMgr, strErrInfo) ){ MBSAFE_DELETE(pTN6XMgr) return false; } strResult = pTN6XMgr->GenXml(); MBSAFE_DELETE(pTN6XMgr) dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::TNXXXXXXQueryMID( int nCurPage,int nPageSize,CString &strMIDs,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; strMIDs = _T(""); CString strTNXXXXXXName = m_pAppExtParm->GetTN_XXX_XXXTableName(); strSql.Format(_T("select G_MASTER_OBJ_ID from %s Group By G_MASTER_OBJ_ID limit %d offset %d"),strTNXXXXXXName,nPageSize,nCurPage * nPageSize); try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULT_CATALOGʧ°Ü£¡"); return false; } CMBTNXXXXXXMgr *pTN6XMgr = new CMBTNXXXXXXMgr(); if( !LoadTNXXXXXX2( dbRecord,pTN6XMgr, strErrInfo) ){ MBSAFE_DELETE(pTN6XMgr) return false; } strMIDs = pTN6XMgr->GetMID(); MBSAFE_DELETE(pTN6XMgr) dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::TNXXXXXXDeleteByMID( CString strMIDs,CString &strErrInfo ) { if( strMIDs.IsEmpty() ) return true; CStringArray aryItem; CString strSql,strTmpMIDS; CString strTN6XName = m_pAppExtParm->GetTN_XXX_XXXTableName(); CMBStrOper::SplitString(strMIDs,_T(';'),aryItem); for( int i = 0;i < aryItem.GetCount();i++ ) { strTmpMIDS += _T("'") + aryItem[i] + _T("',"); } strTmpMIDS = strTmpMIDS.Left(strTmpMIDS.GetLength()-1); try{ strSql.Format(_T("delete from %s where G_MASTER_OBJ_ID in(%s)"),strTN6XName,strTmpMIDS); int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::TNXXXQueryByKeyValue( CString strKeyValue,CString &strResult,CString &strErrInfo ) { CString strSql,strOrderBy; CDBRecord dbRecord; long nRecordCount = 0; CStringArray arID; CString strTN3XName = m_pAppExtParm->GetTN_XXXTableName(); CString strTN6XName = m_pAppExtParm->GetTN_XXX_XXXTableName(); strOrderBy = m_pAppExtParm->GetComposeCls()->GetOrderByDesc(); strSql.Format(_T("select * from %s where S_ID in (select G_SLAVE_OBJ_ID from %s where code='%s')"),strTN3XName,strTN6XName,strKeyValue); // дһÏÂÅÅÐò if(!strOrderBy.IsEmpty() ) TNXXXXXXQueryByID( strKeyValue,arID,strErrInfo ); /* freopen( "CONOUT$","w",stdout); printf(CT2A(strSql+_T("\r\n")));*/ try{ if(!dbRecord.Open(&m_db,strSql)) { strErrInfo = _T("´ò¿ª±íOI_VAULTʧ°Ü£¡"); return false; } if(!strOrderBy.IsEmpty() ){ if(!LoadTNXXXObj2( dbRecord,strResult,arID,strErrInfo )) { return false; } dbRecord.Close(); return true; } if(!LoadTNXXXObj2( dbRecord,strResult, strErrInfo )) { return false; } /*freopen( "CONOUT$","w",stdout); printf(CT2A(strResult+_T("\r\n"))); */ dbRecord.Close(); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } // OI_VERSION bool CMBVaultDbMgr::SetVersionToDb( CString strType,CString strTime,CString &strErrInfo ) { if( strType.IsEmpty() ) return false; bool bExsit = false; if( !IsExsitVesionInDb(strType,bExsit,strErrInfo)) return false; if( bExsit ) // ´æÔÚ¸üР{ if( !UpdateVersionToDb(strType,strTime,strErrInfo) ) return false; } else // ²»´æÔÚ£¬´´½¨ { if(!InsertVersionToDb( strType,strTime,strErrInfo ) ) return false; } return true; } bool CMBVaultDbMgr::IsExsitVesionInDb(CString strType,bool &bExsit,CString &strErrInfo) { CString strSql; CDBRecord dbRecord; long nRecordCount = 0; bExsit = false; try{ strSql.Format(_T("select * from OI_VERSION where CN_S_TYPE='%s'"),strType); if(!dbRecord.Open(&m_db,strSql)) return false; nRecordCount = dbRecord.GetRecordCount(); if( 0 < nRecordCount ) { bExsit = true; } } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::InsertVersionToDb( CString strType,CString strTime,CString &strErrInfo ) { CString strSql; strSql.Format(_T("insert into OI_VERSION(CN_S_TYPE,CN_T_TIME) \ VALUES(\"%s\",\"%s\")"), strType,strTime ); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::UpdateVersionToDb( CString strType,CString strTime,CString &strErrInfo ) { CString strSql; strSql.Format(_T("UPDATE OI_VERSION SET CN_T_TIME=\"%s\" where CN_S_TYPE='%s'"), strTime,strType ); try{ int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db ); } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; } bool CMBVaultDbMgr::GetVersionFromDb( CString strType,CString &strTime,CString &strErrInfo ) { CString strSql; CDBRecord dbRecord; try{ strSql.Format(_T("select * from OI_VERSION where CN_S_TYPE='%s'"),strType); if(!dbRecord.Open(&m_db,strSql)) return false; int nCount = dbRecord.GetRecordCount(); if( 0 == nCount ) return true; HRESULT hR = dbRecord.MoveFirst(); while(S_OK== hR ) { dbRecord.GetValue(_T("CN_T_TIME"),strTime); hR = dbRecord.MoveNext(); } } catch(...) { CDBSQliteException sqliteException(m_db.m_pDB); strErrInfo = sqliteException.GetErrInfo(); return false; } return true; }