#include "StdAfx.h"
|
#include "MBOnlineEdDBMgr.h"
|
|
|
CMBOnlineEdDBMgr::CMBOnlineEdDBMgr(void)
|
{
|
m_pOnlineEdMgr = new CMBOnlineEdMgr();
|
}
|
|
|
CMBOnlineEdDBMgr::~CMBOnlineEdDBMgr(void)
|
{
|
MBSAFE_DELETE(m_pOnlineEdMgr)
|
}
|
|
// µÃµ½ÔÚÏ༹߱ÜÀíÆ÷
|
CMBOnlineEdMgr *CMBOnlineEdDBMgr::GetOnlineEdMgr()
|
{
|
return m_pOnlineEdMgr;
|
}
|
|
bool CMBOnlineEdDBMgr::Init( BOOL & bThreadStop,CString strSqliteDBPath,CString &strErrInfo )
|
{
|
try{
|
m_db.Close();
|
// ´ò¿ªÊý¾Ý¿â
|
if( !m_db.Open( strSqliteDBPath ))
|
{
|
strErrInfo = _T("´ò¿ªsqliteʧ°Ü£¡");
|
return false;
|
}
|
// ³õʼ»¯ÔÚÏß±à¼Êý¾Ý¿â
|
if( !InitOnlineEdDb( bThreadStop,strErrInfo ) )
|
{
|
return false;
|
}
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
|
bool CMBOnlineEdDBMgr::InitOnlineEdDb( BOOL &bThreadStop,CString &strErrInfo )
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("select * from OI_MBC_EDIT_FILE"));
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
//nRecordCount = dbRecord.GetRecordCount();
|
if(!LoadOnlineEdDb(dbRecord,bThreadStop, strErrInfo ))
|
{
|
return false;
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
|
}
|
|
|
bool CMBOnlineEdDBMgr::LoadOnlineEdDb( CDBRecord &dbRecord,BOOL &bThreadStop, CString &strErrInfo )
|
{
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
if( bThreadStop )
|
return false;
|
|
CMBOnlineEdInfo *pOnlineEdInfo = new CMBOnlineEdInfo();
|
|
dbRecord.GetValue(_T("CN_G_DOC_ID"),pOnlineEdInfo->m_strDocID);
|
dbRecord.GetValue(_T("CN_S_SERVER_PATH"),pOnlineEdInfo->m_strSvrPath);
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),pOnlineEdInfo->m_strLocalPath);
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pOnlineEdInfo->m_strFileSvr);
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pOnlineEdInfo->m_strFileID);
|
dbRecord.GetValue(_T("CN_S_FILE_NAME"),pOnlineEdInfo->m_strFileName);
|
dbRecord.GetValue(_T("CN_S_CABINET_NAME"),pOnlineEdInfo->m_strCabinetName);
|
dbRecord.GetValue(_T("CN_G_CABINET_ID"),pOnlineEdInfo->m_strCabinetID);
|
dbRecord.GetValue(_T("CN_T_LAST_MODIFY"),pOnlineEdInfo->m_strTLastModify);
|
dbRecord.GetValue(_T("CN_T_CREATE"),pOnlineEdInfo->m_strTCreate);
|
dbRecord.GetValue(_T("CN_T_UPLOAD"),pOnlineEdInfo->m_strTUpload);
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pOnlineEdInfo->m_nFileSize);
|
dbRecord.GetValue(_T("CN_N_CABINET_TYPE"),pOnlineEdInfo->m_nCabinetType);
|
dbRecord.GetValue(_T("CN_N_SAVEMODE"),pOnlineEdInfo->m_nSaveMode);
|
|
if(!m_pOnlineEdMgr->AddOnlineEd(pOnlineEdInfo))
|
{
|
delete pOnlineEdInfo;
|
pOnlineEdInfo = NULL;
|
}
|
|
hR = dbRecord.MoveNext();
|
}
|
|
return true;
|
}
|
|
|
bool CMBOnlineEdDBMgr::InsertOnlineEdDB( CMBOnlineEdInfo *pOnlineEdInfo,CString &strErrInfo )
|
{
|
if( NULL == pOnlineEdInfo )
|
return false;
|
|
CString strSql;
|
|
if(IsInOnlineEdDB( pOnlineEdInfo->m_strDocID,strErrInfo ))
|
return true;
|
|
strSql.Format(_T("insert into OI_MBC_EDIT_FILE(CN_G_DOC_ID,CN_S_SERVER_PATH,CN_S_LOCAL_PATH,CN_S_FILE_SVR,CN_G_FILE_ID, \
|
CN_S_FILE_NAME,CN_N_FILE_SIZE,CN_S_CABINET_NAME,CN_G_CABINET_ID,CN_N_CABINET_TYPE,CN_T_LAST_MODIFY,CN_T_CREATE,CN_T_UPLOAD) \
|
VALUES(\"%s\",\"%s\",\"%s\",'%s','%s','%s',\"%I64d\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%s\")"),
|
pOnlineEdInfo->m_strDocID,pOnlineEdInfo->m_strSvrPath,pOnlineEdInfo->m_strLocalPath,pOnlineEdInfo->m_strFileSvr,pOnlineEdInfo->m_strFileID,
|
pOnlineEdInfo->m_strFileName,pOnlineEdInfo->m_nFileSize,pOnlineEdInfo->m_strCabinetName,pOnlineEdInfo->m_strCabinetID,
|
pOnlineEdInfo->m_nCabinetType,pOnlineEdInfo->m_strTLastModify,pOnlineEdInfo->m_strTCreate,pOnlineEdInfo->m_strTUpload);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ÅжÏÊÇ·ñÔÚÊý¾Ý¿â
|
bool CMBOnlineEdDBMgr::IsInOnlineEdDB( CString strDocID,CString &strErrInfo )
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("select *from OI_MBC_EDIT_FILE where CN_G_DOC_ID=\"%s\""),strDocID);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_EDIT_FILEʧ°Ü£¡");
|
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 CMBOnlineEdDBMgr::UpdateOnlineEdDb1(CString strDocID,CString strTLastMdyTime,CString strTUploadTime,CString &strErrInfo)
|
{
|
CString strSql;
|
try{
|
strSql.Format(_T("UPDATE OI_MBC_EDIT_FILE SET CN_T_LAST_MODIFY=\"%s\",CN_T_UPLOAD=\"%s\" where CN_G_DOC_ID=\"%s\""),strTLastMdyTime,strTUploadTime,strDocID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBOnlineEdDBMgr::UpdateOnlineEdDb2(CString strDocID,CString strTUploadTime,CString &strErrInfo)
|
{
|
CString strSql;
|
try{
|
strSql.Format(_T("UPDATE OI_MBC_EDIT_FILE SET CN_T_UPLOAD=\"%s\" where CN_G_DOC_ID=\"%s\""),strTUploadTime,strDocID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBOnlineEdDBMgr::UpdateOnlineEdDb3(CString strDocID,CString strTLastMdyTime,CString &strErrInfo)
|
{
|
CString strSql;
|
try{
|
strSql.Format(_T("UPDATE OI_MBC_EDIT_FILE SET CN_T_LAST_MODIFY=\"%s\" where CN_G_DOC_ID=\"%s\""),strTLastMdyTime,strDocID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ¸üб£´æÄ£Ê½
|
bool CMBOnlineEdDBMgr::UpdateSaveModToOnlineEdDb( CString strDocID,int nMode,CString &strErrInfo )
|
{
|
CString strSql;
|
try{
|
strSql.Format(_T("UPDATE OI_MBC_EDIT_FILE SET CN_N_SAVEMODE=\"%d\" where CN_G_DOC_ID=\"%s\""),nMode,strDocID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBOnlineEdDBMgr::DelOnlineEdDB( CString strDocID,CString &strErrInfo )
|
{
|
if( strDocID.IsEmpty() )
|
return false;
|
|
CString strSql;
|
|
try{
|
strSql.Format(_T("DELETE FROM OI_MBC_EDIT_FILE SET where CN_G_DOC_ID=\"%s\""),strDocID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
|
// ÖØÐÂдÈëÊý¾Ý
|
bool CMBOnlineEdDBMgr::ReInsertOnlineEd( CString strOldDocID,CString strNewDocID,CString &strErrInfo )
|
{
|
if( strOldDocID.IsEmpty() || strNewDocID.IsEmpty() )
|
return false;
|
|
CMBOnlineEdInfo *pOnlineEdInfo = m_pOnlineEdMgr->GetOnlineEd1(strOldDocID);
|
if( NULL == pOnlineEdInfo )
|
return false;
|
|
CMBOnlineEdInfo *pTmpOnlineEdInfo = new CMBOnlineEdInfo();
|
*pTmpOnlineEdInfo = *pOnlineEdInfo;
|
pTmpOnlineEdInfo->m_strDocID = strNewDocID;
|
|
// ÒÆ³ý¾ÉÊý¾Ý
|
if( !m_pOnlineEdMgr->RemoveOnlineEd(pOnlineEdInfo) )
|
{
|
delete pTmpOnlineEdInfo;
|
pTmpOnlineEdInfo = NULL;
|
return false;
|
}
|
// Ìí¼ÓеÄ
|
if( !m_pOnlineEdMgr->AddOnlineEd(pTmpOnlineEdInfo) )
|
{
|
delete pTmpOnlineEdInfo;
|
pTmpOnlineEdInfo = NULL;
|
return false;
|
}
|
// ´ÓDBÖÐɾ³ý
|
if( !DelOnlineEdDB( strOldDocID,strErrInfo ) )
|
return false;
|
// ÏòDBÖвåÈëÊý¾Ý
|
if( !InsertOnlineEdDB( pOnlineEdInfo,strErrInfo ) )
|
return false;
|
|
return true;
|
}
|