#include "StdAfx.h"
|
#include "MBTransMgr.h"
|
|
////////////////////////////////////////
|
CMBTransMgr::CMBTransMgr(void)
|
{
|
m_bInit = false;
|
|
m_pUploadQueue = new CMBUploadQueue();
|
m_pDownloadQueue = new CMBDownloadQueue();
|
|
m_pTileUploadMgr = new CMBTileUploadMgr();
|
m_pHistoryTransMgr = new CMBHistoryTransMgr();
|
m_pErrTransMgr = new CMBErrTransMgr();
|
// ÏÔʾÊý
|
m_nDisplayUploadCount = 0; // ÏÔʾÉÏ´«Êý
|
m_nDisplayDownloadCount = 0; // ÏÔʾÏÂÔØÊý
|
m_nDisplayHistoryCount = 0; // ÏÔʾÀúÊ·Êý
|
m_nDisplayErrorCount = 0; // ÏÔʾ´íÎóÊý
|
|
m_nLoadUploadCount = 0; // ¼ÓÔØ ÉÏ´«Êý
|
m_nLoadDownloadCount = 0; // ¼ÓÔØ ÏÂÔØÊý
|
m_nHistoryRecordCount = 0; // ÀúÊ·Êý¾Ý
|
|
// ¼ÆËã×ܼǼ
|
m_nDownloadFileSize = 0; // Îļþ´óС
|
m_nDownloadTranferedSize = 0; // ´«Êä´óС
|
m_nUploadFileSize = 0; // Îļþ´óС
|
m_nUploadTranferedSize = 0; // ´«Êä´óС
|
}
|
|
|
CMBTransMgr::~CMBTransMgr(void)
|
{
|
// ɾ³ý¶ÓÁÐ
|
MBSAFE_DELETE( m_pUploadQueue )
|
MBSAFE_DELETE( m_pDownloadQueue )
|
MBSAFE_DELETE( m_pTileUploadMgr )
|
MBSAFE_DELETE( m_pHistoryTransMgr )
|
MBSAFE_DELETE( m_pErrTransMgr )
|
}
|
|
|
bool CMBTransMgr::InitPreDefDisplay( UINT nDisplayUploadCount,UINT nDisplayDownloadCount,UINT nDisplayHistoryCount,UINT nDisplayErrorCount )
|
{
|
m_nDisplayUploadCount = nDisplayUploadCount; // ÏÔʾÉÏ´«Êý
|
m_nDisplayDownloadCount = nDisplayDownloadCount; // ÏÔʾÏÂÔØÊý
|
m_nDisplayHistoryCount = nDisplayHistoryCount; // ÏÔʾÀúÊ·Êý
|
m_nDisplayErrorCount = nDisplayErrorCount;
|
|
m_nLoadUploadCount = m_nDisplayUploadCount + 50; // ¼ÓÔØ ÉÏ´«Êý
|
m_nLoadDownloadCount = m_nDisplayDownloadCount + 50; // ¼ÓÔØ ÏÂÔØÊý
|
|
m_pHistoryTransMgr->Init(m_nDisplayUploadCount);
|
m_pErrTransMgr->Init(nDisplayErrorCount);
|
|
return true;
|
}
|
|
CMBUploadQueue *CMBTransMgr::GetUploadQueue()
|
{
|
return m_pUploadQueue;
|
}
|
|
CMBDownloadQueue *CMBTransMgr::GetDownloadQueue()
|
{
|
return m_pDownloadQueue;
|
}
|
|
CMBTileUploadMgr *CMBTransMgr::GetTileUploadMgr()
|
{
|
return m_pTileUploadMgr;
|
}
|
|
CMBHistoryTransMgr *CMBTransMgr::GetHistoryTransMgr()
|
{
|
return m_pHistoryTransMgr;
|
}
|
|
CMBErrTransMgr *CMBTransMgr::GetErrTransMgr()
|
{
|
return m_pErrTransMgr;
|
}
|
|
void CMBTransMgr::SetHistoryRecordCount(int nRecordCount)
|
{
|
CSingleLock lock( &m_cs, true );
|
|
m_nHistoryRecordCount = nRecordCount;
|
}
|
|
int CMBTransMgr::GetHistoryRecordCount()
|
{
|
CSingleLock lock( &m_cs, true );
|
|
return m_nHistoryRecordCount;
|
}
|
|
void CMBTransMgr::IncrementHistoryRecordCount()
|
{
|
CSingleLock lock( &m_cs, true );
|
m_nHistoryRecordCount++;
|
}
|
|
void CMBTransMgr::DecrementHistoryRecordCount()
|
{
|
CSingleLock lock( &m_cs, true );
|
if( m_nHistoryRecordCount > 0 )
|
m_nHistoryRecordCount--;
|
}
|
|
__int64 CMBTransMgr::GetDownloadFileSize()
|
{
|
CSingleLock lock( &m_cs, true );
|
return m_nDownloadFileSize;
|
}
|
|
__int64 CMBTransMgr::GetDownloadTranferedSize()
|
{
|
CSingleLock lock( &m_cs, true );
|
return m_nDownloadTranferedSize;
|
}
|
|
__int64 CMBTransMgr::GetUploadFileSize()
|
{
|
CSingleLock lock( &m_cs, true );
|
return m_nUploadFileSize;
|
}
|
|
__int64 CMBTransMgr::GetUploadTranferedSize()
|
{
|
CSingleLock lock( &m_cs, true );
|
return m_nUploadTranferedSize;
|
}
|
|
UINT CMBTransMgr::GetTransCount()
|
{
|
CSingleLock lock( &m_cs, true );
|
return m_pUploadQueue->GetWaitingUserCount() + m_pDownloadQueue->GetWaitingUserCount();
|
}
|
|
void CMBTransMgr::AddDownloadFileSize(__int64 nAddFileSize)
|
{
|
CSingleLock lock( &m_cs, true );
|
m_nDownloadFileSize += nAddFileSize;
|
}
|
|
void CMBTransMgr::AddDownloadTranferedSize(__int64 nAddFileSize)
|
{
|
CSingleLock lock( &m_cs, true );
|
m_nDownloadTranferedSize += nAddFileSize;
|
}
|
|
void CMBTransMgr::AddUploadFileSize(__int64 nAddFileSize)
|
{
|
CSingleLock lock( &m_cs, true );
|
m_nUploadFileSize += nAddFileSize;
|
}
|
|
void CMBTransMgr::AddUploadTranferedSize(__int64 nAddFileSize)
|
{
|
CSingleLock lock( &m_cs, true );
|
m_nUploadTranferedSize += nAddFileSize;
|
}
|
|
bool CMBTransMgr::InitDownloadRecordCount(CString &strErrInfo)
|
{
|
try{
|
CString strSql;
|
CDBRecord dbRecord;
|
|
strSql.Format(_T("select sum(CN_N_FILE_SIZE) as ALLFILESIZE from OI_MBC_DOWNLOAD_FILE where CN_N_STATUS!=%d"),CMBDownloadFileInfo::Status_Err);
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_DOWNLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
dbRecord.GetValue(_T("ALLFILESIZE"),m_nDownloadFileSize);
|
hR = dbRecord.MoveNext();
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::InitUploadRecordCount(CString &strErrInfo)
|
{
|
try{
|
CString strSql;
|
CDBRecord dbRecord;
|
|
strSql.Format(_T("select sum(CN_N_FILE_SIZE) as ALLFILESIZE from OI_MBC_UPLOAD_FILE where CN_N_STATUS!=%d"),CMBUploadFileInfo::Status_Err);
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
dbRecord.GetValue(_T("ALLFILESIZE"),m_nUploadFileSize);
|
hR = dbRecord.MoveNext();
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::Init( BOOL & bThreadStop,CString strSqliteDBPath,CString &strErrInfo )
|
{
|
try{
|
m_db.Close();
|
// ´ò¿ªÊý¾Ý¿â
|
if( !m_db.Open( strSqliteDBPath ))
|
{
|
strErrInfo = _T("´ò¿ªsqliteʧ°Ü£¡");
|
return false;
|
}
|
|
// ´®ÐÐģʽ
|
// int n = sqlite3_threadsafe();
|
|
// ÖØÖÃÊý¾Ý¿âÖÐµÄ CN_C_LOADÖµ
|
if(!UpdataLoadOnUploadFile(_T("N"),strErrInfo))
|
{
|
return false;
|
}
|
if(!UpdataLoadOnDownloadFile(_T("N"),strErrInfo))
|
{
|
return false;
|
}
|
|
// ³õʼ»¯ÉÏ´«Êý¾Ý
|
if(!InitUploadData(bThreadStop,strErrInfo))
|
{
|
return false;
|
}
|
|
// ³õʼ»¯ÏÂÔØÊý¾Ý
|
if(!InitDownloadData(bThreadStop,strErrInfo))
|
{
|
return false;
|
}
|
|
// ³õʼ»¯ÀúÊ·Êý¾Ý
|
if(!InitHistoryData(bThreadStop,strErrInfo))
|
{
|
return false;
|
}
|
|
// ³õʼ»¯´íÎóÐÅÏ¢
|
if(!InitErrData(bThreadStop,strErrInfo))
|
{
|
return false;
|
}
|
|
// ³õʼÀúÊ·ÌõÊý
|
if(!InitHistoryRecordCount(strErrInfo))
|
{
|
return false;
|
}
|
|
// ³õʼ»¯ÏÂÔØ×Ü´óС
|
if(!InitDownloadRecordCount(strErrInfo))
|
{
|
return false;
|
}
|
// ³õʼ»¯ÉÏ´«×Ü´óС
|
if(!InitUploadRecordCount(strErrInfo))
|
{
|
return false;
|
}
|
|
//sqlite3_exec(m_db.m_pDB,"PRAGMA synchronous = OFF; ",0,0,0);
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
m_bInit = true;
|
return true;
|
}
|
|
// ³õʼ»¯ÉÏ´«Êý¾Ý
|
bool CMBTransMgr::InitUploadData(BOOL &bThreadStop,CString &strErrInfo)
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
CString strIDS;
|
|
strSql.Format(_T("select * from OI_MBC_UPLOAD_FILE where CN_N_STATUS!='%d' and CN_C_LOAD='N' order by CN_T_CREATE asc limit 0,%d"),
|
CMBUploadFileInfo::Status_Err,m_nLoadUploadCount);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadUploadRecord(dbRecord,bThreadStop,strIDS, strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
// ¸üÐÂÒ»ÏÂÊý¾Ý¿â£¬±íʾÕýÔÚ´¦Àí
|
if(!UpdataLoadOnUploadWaitingQueue( _T("Y"),strIDS,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
// ¶ÔOI_MBC_UPLOAD_FILEÊý¾Ý±íµÄ²Ù×÷
|
bool CMBTransMgr::InsertSqliteUploadFile( CMBUploadFileInfo *pUploadFileInfo,CString &strErrInfo )
|
{
|
if( !m_bInit )
|
return true;
|
|
if( NULL == pUploadFileInfo )
|
return false;
|
|
CString strSql;
|
|
strSql.Format(_T("insert into OI_MBC_UPLOAD_FILE(CN_G_ID,CN_S_SERVER_PATH,CN_S_LOCAL_PATH,CN_N_STATUS,CN_N_FILE_SIZE, \
|
CN_N_ISDIR,CN_G_FILE_ID,CN_S_FILE_SVR,CN_S_FILE_NAME,CN_S_MD5,CN_T_CREATE,CN_G_CABINET_ID,CN_N_CABINET_TYPE,CN_N_COVERMODE,CN_S_FROM) \
|
VALUES(\"%s\",\"%s\",\"%s\",'%d','%lld','%d',\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",'%d','%d','%s')"),
|
pUploadFileInfo->m_strID,pUploadFileInfo->m_strServerPath,pUploadFileInfo->GetLocalPath(),
|
pUploadFileInfo->GetStatus(),pUploadFileInfo->m_nFileSize,pUploadFileInfo->m_nIsDir,pUploadFileInfo->m_strFileID,
|
pUploadFileInfo->m_strFileSvr,pUploadFileInfo->m_strFileName,pUploadFileInfo->GetMD5(),
|
pUploadFileInfo->m_strTAddTime,pUploadFileInfo->m_strCabinetID,pUploadFileInfo->m_nCabinetType,pUploadFileInfo->m_nCoverMode,pUploadFileInfo->m_strFrom);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataLoadOnUploadFile( CString strLoadValue,CString &strErrInfo )
|
{
|
CString strSql;
|
strSql.Format(_T("UPDATE OI_MBC_UPLOAD_FILE SET CN_C_LOAD='%s'"),strLoadValue);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataLoadOnUploadWaitingQueue( CString strLoadValue,CString strIDS,CString &strErrInfo )
|
{
|
//CString strIDS;
|
CString strSql;
|
//strIDS = m_pUploadQueue->GetWaitingTransIDS();
|
if( strIDS.IsEmpty() )
|
return true;
|
try{
|
strSql.Format(_T("UPDATE OI_MBC_UPLOAD_FILE SET CN_C_LOAD='%s' where CN_G_ID in(%s)"),strLoadValue,strIDS);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
|
bool CMBTransMgr::LoadUploadRecord( CDBRecord &dbRecord,BOOL &bThreadStop,CString &strIDS, CString &strErrInfo )
|
{
|
int nStatus = CMBUploadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
|
strIDS.Empty();
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
if( bThreadStop )
|
return false;
|
|
CAutoRefPtr<CMBUploadFileInfo> pUploadFileInfo(new CMBUploadFileInfo());
|
pUploadFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pUploadFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_S_SERVER_PATH"),pUploadFileInfo->m_strServerPath);
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),strLocalPath);
|
pUploadFileInfo->SetLocalPath(strLocalPath);
|
dbRecord.GetValue(_T("CN_N_STATUS"),nStatus);
|
pUploadFileInfo->SetStatus(nStatus);
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pUploadFileInfo->m_nFileSize);
|
dbRecord.GetValue(_T("CN_N_ISDIR"),pUploadFileInfo->m_nIsDir);
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pUploadFileInfo->m_strFileSvr);
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pUploadFileInfo->m_strFileID);
|
dbRecord.GetValue(_T("CN_S_FILE_NAME"),pUploadFileInfo->m_strFileName);
|
dbRecord.GetValue(_T("CN_S_MD5"),strMD5);
|
pUploadFileInfo->SetMD5(strMD5);
|
dbRecord.GetValue(_T("CN_S_ERR"),strErr);
|
pUploadFileInfo->SetErr(strErr);
|
dbRecord.GetValue(_T("CN_T_CREATE"),pUploadFileInfo->m_strTAddTime);
|
dbRecord.GetValue(_T("CN_G_CABINET_ID"),pUploadFileInfo->m_strCabinetID);
|
dbRecord.GetValue(_T("CN_S_CABINET_NAME"),pUploadFileInfo->m_strCabinetName);
|
dbRecord.GetValue(_T("CN_N_CABINET_TYPE"),pUploadFileInfo->m_nCabinetType);
|
dbRecord.GetValue(_T("CN_N_COVERMODE"),pUploadFileInfo->m_nCoverMode);
|
dbRecord.GetValue(_T("CN_S_FROM"),pUploadFileInfo->m_strFrom);
|
|
m_pUploadQueue->AddClientToWaitingList(pUploadFileInfo);
|
|
strIDS += _T("'") + pUploadFileInfo->m_strID + _T("'") ;
|
strIDS += _T(",");
|
|
|
hR = dbRecord.MoveNext();
|
}
|
if( !strIDS.IsEmpty() )
|
{
|
strIDS = strIDS.Left(strIDS.GetLength() -1);
|
}
|
|
return true;
|
}
|
|
// ÖØÐ¼ÓÔØÉÏ´«µÈ´ý¶ÓÁÐ
|
bool CMBTransMgr::ReUploadToWaitingList( BOOL &bThreadStop,CString &strErrInfo )
|
{
|
int nCurWaitingUserCount = m_pUploadQueue->GetWaitingUserCount();
|
if(nCurWaitingUserCount >= m_nDisplayUploadCount ) // Èç¹û±ÈÔ¤¶¨ÒåµÄÒª´ó£¬Ôò²»ÓùÜ
|
return true;
|
|
CString strSql;
|
CString strIDS;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("select * from OI_MBC_UPLOAD_FILE where CN_N_STATUS!='%d' and CN_C_LOAD='N' order by CN_T_CREATE asc limit 0,%d"),
|
CMBUploadFileInfo::Status_Err,m_nLoadUploadCount - nCurWaitingUserCount);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadUploadRecord(dbRecord,bThreadStop,strIDS,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
// ¸üÐÂÒ»ÏÂÊý¾Ý¿â£¬±íʾÕýÔÚ´¦Àí
|
if(!UpdataLoadOnUploadWaitingQueue( _T("Y"),strIDS,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::DelUploadFileOnTabUploadFile( CString strID,CString &strErrInfo )
|
{
|
CString strSql;
|
try{
|
strSql.Format(_T("DELETE FROM OI_MBC_UPLOAD_FILE where CN_G_ID='%s'"),strID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::InsertSqliteUploadHistoryFile( CMBUploadFileInfo *pUploadFileInfo,CString &strErrInfo )
|
{
|
if( NULL == pUploadFileInfo )
|
return false;
|
|
CString strSql;
|
|
strSql.Format(_T("insert into OI_MBC_UPLOAD_HISTORY_FILE(CN_G_ID,CN_S_SERVER_PATH,CN_S_LOCAL_PATH,CN_N_FILE_SIZE, \
|
CN_N_ISDIR,CN_S_FILE_SVR,CN_S_FILE_NAME,CN_T_OP_STARTTIME,CN_T_OP_ENDTTIME,CN_G_CABINET_ID,CN_N_CABINET_TYPE) \
|
VALUES(\"%s\",\"%s\",\"%s\",'%lld','%d',\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",'%d')"),
|
pUploadFileInfo->m_strID,pUploadFileInfo->m_strServerPath,pUploadFileInfo->GetLocalPath(),
|
pUploadFileInfo->m_nFileSize,pUploadFileInfo->m_nIsDir,
|
pUploadFileInfo->m_strFileSvr,pUploadFileInfo->m_strFileName,
|
pUploadFileInfo->m_strTAddTime,pUploadFileInfo->m_strTEndTime,pUploadFileInfo->m_strCabinetID,pUploadFileInfo->m_nCabinetType);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::AdjustUploadFileToHistory( CMBUploadFileInfo *pUploadFileInfo,CString &strErrInfo )
|
{
|
StartTransaction();
|
|
if(!DelUploadFileOnTabUploadFile(pUploadFileInfo->m_strID,strErrInfo))
|
{
|
return false;
|
}
|
if(!InsertSqliteUploadHistoryFile(pUploadFileInfo,strErrInfo))
|
{
|
return false;
|
}
|
|
Commit();
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataSqliteUploadFileForErr( CMBUploadFileInfo *pUploadFileInfo,CString strTErrTime,CString &strErrInfo,CString strLoad )
|
{
|
CString strSql;
|
strSql.Format(_T("UPDATE OI_MBC_UPLOAD_FILE SET CN_N_STATUS='%d',CN_S_ERR='%s',CN_C_LOAD='%s',CN_T_ERRTIME='%s' where CN_G_ID='%s'"),
|
CMBUploadFileInfo::Status_Err,pUploadFileInfo->GetErr(),strLoad,strTErrTime,pUploadFileInfo->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 CMBTransMgr::UpdataSqliteUploadFileForStatus( CString strID,int nStatus,CString &strErrInfo)
|
{
|
CString strSql;
|
strSql.Format(_T("UPDATE OI_MBC_UPLOAD_FILE SET CN_N_STATUS='%d' where CN_G_ID='%s'"),
|
nStatus,strID);
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ¸üÐÂStatus
|
bool CMBTransMgr::UpdataSqliteUploadFileForStatus( int nStatus,CString &strErrInfo)
|
{
|
CString strSql;
|
strSql.Format(_T("UPDATE OI_MBC_UPLOAD_FILE SET CN_N_STATUS='%d'"),
|
nStatus);
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
|
|
// Çå¿Õ±í
|
bool CMBTransMgr::DeleteSqliteOnUploadFile( CString &strErrInfo )
|
{
|
CString strSql;
|
|
try{
|
// ´Ó±í OI_MBC_UPLOAD_FILE Çå³ý
|
strSql.Format(_T("DELETE FROM OI_MBC_UPLOAD_FILE"));
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
|
}
|
|
// ¶ÔOI_MBC_DOWNLOAD_FILE Êý¾Ý±íµÄ²Ù×÷
|
bool CMBTransMgr::InsertSqliteDownloadFile( CMBDownloadFileInfo *pDownloadFileInfo,CString &strErrInfo )
|
{
|
if( !m_bInit )
|
return true;
|
|
if( NULL == pDownloadFileInfo )
|
return false;
|
|
CString strSql;
|
|
strSql.Format(_T("insert into OI_MBC_DOWNLOAD_FILE(CN_G_ID,CN_S_SERVER_PATH,CN_S_LOCAL_PATH,CN_N_STATUS,CN_N_FILE_SIZE, \
|
CN_N_ISDIR,CN_G_FILE_ID,CN_S_FILE_SVR,CN_S_FILE_NAME,CN_T_CREATE,CN_G_CABINET_ID,CN_S_CABINET_NAME,CN_N_CABINET_TYPE,CN_S_FROM) \
|
VALUES(\"%s\",\"%s\",\"%s\",'%d','%lld','%d',\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",'%d',\"%s\")"),
|
pDownloadFileInfo->m_strID,pDownloadFileInfo->m_strServerPath,pDownloadFileInfo->GetLocalPath(),
|
pDownloadFileInfo->GetStatus(),pDownloadFileInfo->m_nFileSize,pDownloadFileInfo->m_nIsDir,pDownloadFileInfo->m_strFileID,
|
pDownloadFileInfo->m_strFileSvr,pDownloadFileInfo->m_strFileName,
|
pDownloadFileInfo->m_strTAddTime,pDownloadFileInfo->m_strCabinetID,pDownloadFileInfo->m_strCabinetName,pDownloadFileInfo->m_nCabinetType,pDownloadFileInfo->m_strFrom);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::IsFireInSqliteDownloadFile( CString strFileName,CString strFileID,CString strFrom,bool &bExsit,CString &strErrInfo )
|
{
|
if( !m_bInit )
|
return true;
|
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
bExsit = false;
|
|
CString strSql;
|
|
//strSql.Format(_T("select * from OI_MBC_DOWNLOAD_FILE where CN_S_FILE_NAME='%s' and CN_G_FILE_ID='%s' and CN_S_FROM='%s'"),strFileName,strFileID,strFrom);
|
strSql.Format(_T("select * from OI_MBC_DOWNLOAD_FILE where CN_G_FILE_ID='%s' and CN_S_FROM='%s'"),strFileID,strFrom);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_DOWNLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
bExsit = true;
|
}
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataLoadOnDownloadFile( CString strLoadValue,CString &strErrInfo )
|
{
|
CString strSql;
|
strSql.Format(_T("UPDATE OI_MBC_DOWNLOAD_FILE SET CN_C_LOAD='%s'"),strLoadValue);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ³õʼ»¯ÏÂÔØÊý¾Ý
|
bool CMBTransMgr::InitDownloadData(BOOL &bThreadStop,CString &strErrInfo)
|
{
|
// m_nLoadDownloadCount
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
CString strIDS;
|
|
strSql.Format(_T("select * from OI_MBC_DOWNLOAD_FILE where CN_N_STATUS!='%d' and CN_C_LOAD='N' order by CN_T_CREATE asc limit 0,%d"),
|
CMBDownloadFileInfo::Status_Err,m_nLoadDownloadCount);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_DOWNLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadDownloadRecord(dbRecord,bThreadStop,strIDS, strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
// ¸üÐÂÒ»ÏÂÊý¾Ý¿â£¬±íʾÕýÔÚ´¦Àí
|
if(!UpdataLoadOnDownloadWaitingQueue( _T("Y"),strIDS,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
// ³õʼ»¯ÀúÊ·Êý¾Ý
|
bool CMBTransMgr::InitHistoryData(BOOL &bThreadStop,CString &strErrInfo)
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("select CN_G_ID,CN_N_ISDIR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_OP_STARTTIME,CN_T_OP_ENDTTIME,CN_S_LOCAL_PATH,'1' as t_type \
|
from OI_MBC_UPLOAD_HISTORY_FILE \
|
UNION all \
|
select CN_G_ID,CN_N_ISDIR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_OP_STARTTIME,CN_T_OP_ENDTTIME,CN_S_LOCAL_PATH,'0' as t_type \
|
from OI_MBC_DOWNLOAD_HISTORY_FILE \
|
order by CN_T_OP_ENDTTIME desc limit 0,%d"), m_nDisplayHistoryCount);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_HISTORY_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadHistoryFileRecord(dbRecord,bThreadStop,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ¹ö¶¯¼ÓÔØÊý¾Ý
|
bool CMBTransMgr::ScrollLoadHistoryData(int nCount,CString &strErrInfo)
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
int nStart = m_pHistoryTransMgr->GetHistoryCount();
|
|
strSql.Format(_T("select CN_G_ID,CN_N_ISDIR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_OP_STARTTIME,CN_T_OP_ENDTTIME,CN_S_LOCAL_PATH,'1' as t_type \
|
from OI_MBC_UPLOAD_HISTORY_FILE \
|
UNION all \
|
select CN_G_ID,CN_N_ISDIR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_OP_STARTTIME,CN_T_OP_ENDTTIME,CN_S_LOCAL_PATH,'0' as t_type \
|
from OI_MBC_DOWNLOAD_HISTORY_FILE \
|
order by CN_T_OP_ENDTTIME desc LIMIT %d OFFSET %d"),nCount,nStart);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_HISTORY_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadHistoryFileRecord(dbRecord,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
|
// ³õʼ»¯´íÎóÐÅÏ¢
|
bool CMBTransMgr::InitErrData(BOOL &bThreadStop,CString &strErrInfo)
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("select CN_G_ID,CN_S_ERR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_CREATE,CN_T_ERRTIME,CN_S_LOCAL_PATH,CN_N_STATUS,'1' as t_type \
|
from OI_MBC_UPLOAD_FILE where CN_N_STATUS='%d' \
|
UNION all \
|
select CN_G_ID,CN_S_ERR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_CREATE,CN_T_ERRTIME,CN_S_LOCAL_PATH,CN_N_STATUS,'0' as t_type \
|
from OI_MBC_DOWNLOAD_FILE where CN_N_STATUS='%d' \
|
order by CN_T_ERRTIME desc limit 0,%d"),CMBUploadFileInfo::Status_Err,CMBDownloadFileInfo::Status_Err,m_nDisplayErrorCount);
|
|
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_FILE»òÕß±íOI_MBC_DOWNLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadErrFileRecord(dbRecord,bThreadStop,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
|
return true;
|
}
|
|
// ³õʼ»¯ÀúÊ·ÌõÊý
|
bool CMBTransMgr::InitHistoryRecordCount(CString &strErrInfo)
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("SELECT (select count(1) from OI_MBC_DOWNLOAD_HISTORY_FILE)+(select count(1) from OI_MBC_UPLOAD_HISTORY_FILE) AS SumCount"));
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_DOWNLOAD_HISTORY_FILE»òÕßOI_MBC_UPLOAD_HISTORY_FILEʧ°Ü£¡");
|
return false;
|
}
|
HRESULT hR = dbRecord.MoveFirst();
|
if(S_OK== hR )
|
{
|
dbRecord.GetValue(_T("SumCount"),nRecordCount);
|
SetHistoryRecordCount(nRecordCount);
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
|
bool CMBTransMgr::LoadDownloadRecord( CDBRecord &dbRecord,BOOL &bThreadStop,CString &strIDS, CString &strErrInfo )
|
{
|
int nStatus = CMBDownloadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
|
strIDS.Empty();
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
if( bThreadStop )
|
return false;
|
CAutoRefPtr<CMBDownloadFileInfo> pDownloadFileInfo(new CMBDownloadFileInfo());
|
pDownloadFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pDownloadFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_S_SERVER_PATH"),pDownloadFileInfo->m_strServerPath);
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),strLocalPath);
|
pDownloadFileInfo->SetLocalPath(strLocalPath);
|
|
dbRecord.GetValue(_T("CN_N_STATUS"),nStatus);
|
pDownloadFileInfo->SetStatus(nStatus);
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pDownloadFileInfo->m_nFileSize);
|
dbRecord.GetValue(_T("CN_N_ISDIR"),pDownloadFileInfo->m_nIsDir);
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pDownloadFileInfo->m_strFileSvr);
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pDownloadFileInfo->m_strFileID);
|
dbRecord.GetValue(_T("CN_S_FILE_NAME"),pDownloadFileInfo->m_strFileName);
|
//dbRecord.GetValue(_T("CN_S_MD5"),strMD5);
|
//pDownloadFileInfo->SetMD5(strMD5);
|
|
dbRecord.GetValue(_T("CN_S_ERR"),strErr);
|
pDownloadFileInfo->SetErr(strErr);
|
|
dbRecord.GetValue(_T("CN_T_CREATE"),pDownloadFileInfo->m_strTAddTime);
|
dbRecord.GetValue(_T("CN_G_CABINET_ID"),pDownloadFileInfo->m_strCabinetID);
|
dbRecord.GetValue(_T("CN_S_CABINET_NAME"),pDownloadFileInfo->m_strCabinetName);
|
dbRecord.GetValue(_T("CN_N_CABINET_TYPE"),pDownloadFileInfo->m_nCabinetType);
|
dbRecord.GetValue(_T("CN_S_FROM"),pDownloadFileInfo->m_strFrom);
|
|
m_pDownloadQueue->AddClientToWaitingList(pDownloadFileInfo);
|
|
strIDS += _T("'") + pDownloadFileInfo->m_strID + _T("'") ;
|
strIDS += _T(",");
|
|
|
hR = dbRecord.MoveNext();
|
}
|
if( !strIDS.IsEmpty() )
|
{
|
strIDS = strIDS.Left(strIDS.GetLength() -1);
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataLoadOnDownloadWaitingQueue( CString strLoadValue,CString strIDS,CString &strErrInfo )
|
{
|
CString strSql;
|
|
if( strIDS.IsEmpty() )
|
return true;
|
try{
|
strSql.Format(_T("UPDATE OI_MBC_DOWNLOAD_FILE SET CN_C_LOAD='%s' where CN_G_ID in(%s)"),strLoadValue,strIDS);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::ReDownloadToWaitingList( BOOL &bThreadStop,CString &strErrInfo )
|
{
|
int nCurWaitingUserCount = m_pDownloadQueue->GetWaitingUserCount();
|
if(nCurWaitingUserCount >= m_nDisplayDownloadCount ) // Èç¹û±ÈÔ¤¶¨ÒåµÄÒª´ó£¬Ôò²»ÓùÜ
|
return true;
|
|
CString strSql;
|
CString strIDS;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
strSql.Format(_T("select * from OI_MBC_DOWNLOAD_FILE where CN_N_STATUS!='%d' and CN_C_LOAD='N' order by CN_T_CREATE asc limit 0,%d"),
|
CMBDownloadFileInfo::Status_Err,m_nLoadDownloadCount - nCurWaitingUserCount);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_DOWNLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadDownloadRecord(dbRecord,bThreadStop,strIDS,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
// ¸üÐÂÒ»ÏÂÊý¾Ý¿â£¬±íʾÕýÔÚ´¦Àí
|
if(!UpdataLoadOnDownloadWaitingQueue( _T("Y"),strIDS,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::DelDownloadFileOnTabUploadFile( CString strID,CString &strErrInfo )
|
{
|
CString strSql;
|
try{
|
strSql.Format(_T("DELETE FROM OI_MBC_DOWNLOAD_FILE where CN_G_ID='%s'"),strID);
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::InsertSqliteDownloadHistoryFile( CMBDownloadFileInfo *pDownloadFileInfo,CString &strErrInfo )
|
{
|
if( NULL == pDownloadFileInfo )
|
return false;
|
|
CString strSql;
|
|
strSql.Format(_T("insert into OI_MBC_DOWNLOAD_HISTORY_FILE(CN_G_ID,CN_S_SERVER_PATH,CN_S_LOCAL_PATH,CN_N_FILE_SIZE, \
|
CN_N_ISDIR,CN_G_FILE_ID,CN_S_FILE_SVR,CN_S_FILE_NAME,CN_T_OP_STARTTIME,CN_T_OP_ENDTTIME,CN_G_CABINET_ID,CN_N_CABINET_TYPE) \
|
VALUES('%s','%s','%s','%lld','%d','%s','%s','%s','%s','%s','%s','%d')"),
|
pDownloadFileInfo->m_strID,pDownloadFileInfo->m_strServerPath,pDownloadFileInfo->GetLocalPath(),
|
pDownloadFileInfo->m_nFileSize,pDownloadFileInfo->m_nIsDir,pDownloadFileInfo->m_strFileID,
|
pDownloadFileInfo->m_strFileSvr,pDownloadFileInfo->m_strFileName,
|
pDownloadFileInfo->m_strTAddTime,pDownloadFileInfo->m_strTEndTime,pDownloadFileInfo->m_strCabinetID,pDownloadFileInfo->m_nCabinetType);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::AdjustDownloadFileToHistory( CMBDownloadFileInfo *pDownloadFileInfo,CString &strErrInfo )
|
{
|
StartTransaction();
|
|
if(!DelDownloadFileOnTabUploadFile(pDownloadFileInfo->m_strID,strErrInfo))
|
{
|
return false;
|
}
|
if(!InsertSqliteDownloadHistoryFile(pDownloadFileInfo,strErrInfo))
|
{
|
return false;
|
}
|
|
Commit();
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataSqliteDownloadFileForErr( CMBDownloadFileInfo *pDownloadFileInfo,CString strTErrTime,CString &strErrInfo,CString strLoad )
|
{
|
CString strSql;
|
strSql.Format(_T("UPDATE OI_MBC_DOWNLOAD_FILE SET CN_N_STATUS='%d',CN_S_ERR='%s',CN_C_LOAD='%s',CN_T_ERRTIME='%s' where CN_G_ID='%s'"),
|
CMBDownloadFileInfo::Status_Err,pDownloadFileInfo->GetErr(),strLoad,strTErrTime,pDownloadFileInfo->m_strID);
|
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ¸üÐÂStatus
|
bool CMBTransMgr::UpdataSqliteDownloadFileForStatus( CString strID,int nStatus,CString &strErrInfo)
|
{
|
CString strSql;
|
|
strSql.Format(_T("UPDATE OI_MBC_DOWNLOAD_FILE SET CN_N_STATUS='%d' where CN_G_ID='%s'"),
|
nStatus,strID);
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// ¸üÐÂStatus
|
bool CMBTransMgr::UpdataSqliteDownloadFileForStatus( int nStatus,CString &strErrInfo)
|
{
|
CString strSql;
|
|
strSql.Format(_T("UPDATE OI_MBC_DOWNLOAD_FILE SET CN_N_STATUS='%d'"),
|
nStatus);
|
try{
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
return true;
|
}
|
|
// Çå¿Õ±í
|
bool CMBTransMgr::DeleteSqliteOnDownloadFile( CString &strErrInfo )
|
{
|
CString strSql;
|
|
try{
|
// ´Ó±í OI_MBC_DOWNLOAD_FILE Çå³ý
|
strSql.Format(_T("DELETE FROM OI_MBC_DOWNLOAD_FILE"));
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
// ´íÎóÐÅÏ¢
|
bool CMBTransMgr::LoadErrFileRecord( CDBRecord &dbRecord,BOOL &bThreadStop,CString &strErrInfo )
|
{
|
int nStatus = CMBDownloadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
if( bThreadStop )
|
return false;
|
CAutoRefPtr<CMBErrFileInfo> pErrFileInfo(new CMBErrFileInfo());
|
pErrFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pErrFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pErrFileInfo->m_strFileID); // Îļþid
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),pErrFileInfo->m_strLocalPath); // µ±Ç°Â·¾¶
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pErrFileInfo->m_nFileSize); // Îļþ´óС
|
dbRecord.GetValue(_T("CN_N_STATUS"),pErrFileInfo->m_nStatus);
|
dbRecord.GetValue(_T("t_type"),pErrFileInfo->m_nType);
|
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pErrFileInfo->m_strFileSvr); // ·þÎñÆ÷±êʶ
|
dbRecord.GetValue(_T("CN_S_ERR"),pErrFileInfo->m_strErr); // ´íÎóÐÅÏ¢
|
dbRecord.GetValue(_T("CN_T_CREATE"),pErrFileInfo->m_strTAddTime); // ½áÊøÊ±¼ä
|
dbRecord.GetValue(_T("CN_T_ERRTIME"),pErrFileInfo->m_strTErrTime); // ½áÊøÊ±¼ä
|
|
m_pErrTransMgr->AddErrFile(pErrFileInfo);
|
|
hR = dbRecord.MoveNext();
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::LoadErrFileRecord( CDBRecord &dbRecord,CString &strErrInfo )
|
{
|
int nStatus = CMBDownloadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
CAutoRefPtr<CMBErrFileInfo> pErrFileInfo(new CMBErrFileInfo());
|
pErrFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pErrFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pErrFileInfo->m_strFileID); // Îļþid
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),pErrFileInfo->m_strLocalPath); // µ±Ç°Â·¾¶
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pErrFileInfo->m_nFileSize); // Îļþ´óС
|
dbRecord.GetValue(_T("CN_N_STATUS"),pErrFileInfo->m_nStatus);
|
dbRecord.GetValue(_T("t_type"),pErrFileInfo->m_nType);
|
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pErrFileInfo->m_strFileSvr); // ·þÎñÆ÷±êʶ
|
dbRecord.GetValue(_T("CN_S_ERR"),pErrFileInfo->m_strErr); // ´íÎóÐÅÏ¢
|
dbRecord.GetValue(_T("CN_T_CREATE"),pErrFileInfo->m_strTAddTime); // ½áÊøÊ±¼ä
|
dbRecord.GetValue(_T("CN_T_ERRTIME"),pErrFileInfo->m_strTErrTime); // ½áÊøÊ±¼ä
|
|
m_pErrTransMgr->AddErrFile(pErrFileInfo);
|
|
hR = dbRecord.MoveNext();
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::ScrollLoadErrData(int nCount,CString &strErrInfo)
|
{
|
CString strSql;
|
CDBRecord dbRecord;
|
long nRecordCount = 0;
|
|
int nStart = m_pErrTransMgr->GetCount();
|
|
strSql.Format(_T("select CN_G_ID,CN_S_ERR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_CREATE,CN_T_ERRTIME,CN_S_LOCAL_PATH,CN_N_STATUS,'1' as t_type \
|
from OI_MBC_UPLOAD_FILE where CN_N_STATUS='%d' \
|
UNION all \
|
select CN_G_ID,CN_S_ERR,CN_S_FILE_SVR,CN_G_FILE_ID,CN_N_FILE_SIZE,CN_T_CREATE,CN_T_ERRTIME,CN_S_LOCAL_PATH,CN_N_STATUS,'0' as t_type \
|
from OI_MBC_DOWNLOAD_FILE where CN_N_STATUS='%d' \
|
order by CN_T_ERRTIME desc LIMIT %d OFFSET %d"),CMBUploadFileInfo::Status_Err,CMBDownloadFileInfo::Status_Err,nCount,nStart);
|
|
try{
|
if(!dbRecord.Open(&m_db,strSql))
|
{
|
strErrInfo = _T("´ò¿ª±íOI_MBC_UPLOAD_FILE»òÕß±íOI_MBC_DOWNLOAD_FILEʧ°Ü£¡");
|
return false;
|
}
|
nRecordCount = dbRecord.GetRecordCount();
|
if( nRecordCount != 0 )
|
{
|
if(!LoadErrFileRecord(dbRecord,strErrInfo ))
|
{
|
return false;
|
}
|
}
|
dbRecord.Close();
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
|
// ɾ³ý´íÎó
|
bool CMBTransMgr::DeleteSqliteOnUploadOrDownload( CMBErrFileInfo *pErrFileInfo, CString &strErrInfo )
|
{
|
CString strSql;
|
|
if( NULL == pErrFileInfo )
|
return false;
|
|
try{
|
// m_nType; // ÀàÐÍ 1 OI_MBC_UPLOAD_HISTORY_FILE; 0 OI_MBC_DOWNLOAD_HISTORY_FILE
|
if( pErrFileInfo->m_nType == 1 )
|
{
|
strSql.Format(_T("DELETE FROM OI_MBC_UPLOAD_FILE where CN_G_ID='%s'"),pErrFileInfo->m_strID);
|
}else
|
{
|
strSql.Format(_T("DELETE FROM OI_MBC_DOWNLOAD_FILE where CN_G_ID='%s'"),pErrFileInfo->m_strID);
|
}
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::DeleteSqliteOnUploadOrDownload( CString &strErrInfo )
|
{
|
CString strSql;
|
|
try{
|
strSql.Format(_T("DELETE FROM OI_MBC_UPLOAD_FILE where CN_N_STATUS='%d'"),CMBUploadFileInfo::Status_Err);
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
|
strSql.Format(_T("DELETE FROM OI_MBC_DOWNLOAD_FILE where CN_N_STATUS='%d'"),CMBDownloadFileInfo::Status_Err);
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::UpdataSqliteOnUploadOrDownload(CString &strErrInfo)
|
{
|
CString strUploadIDS;
|
CString strDownLoadIDS;
|
CString strSql;
|
|
m_pErrTransMgr->GetErrFileIDS( strUploadIDS,strDownLoadIDS );
|
|
|
try{
|
if( !strUploadIDS.IsEmpty() ){
|
strSql.Format(_T("UPDATE OI_MBC_UPLOAD_FILE SET CN_C_LOAD='%s',CN_N_STATUS='%d' where CN_G_ID in(%s)"),
|
_T("N"),CMBUploadFileInfo::Status_NoFinish,strUploadIDS);
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
if( !strDownLoadIDS.IsEmpty() ){
|
strSql.Format(_T("UPDATE OI_MBC_DOWNLOAD_FILE SET CN_C_LOAD='%s',CN_N_STATUS='%d' where CN_G_ID in(%s)"),
|
_T("N"),CMBDownloadFileInfo::Status_NoFinish,strDownLoadIDS);
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
|
return true;
|
}
|
|
// ÀúÊ·ÐÅÏ¢
|
bool CMBTransMgr::LoadHistoryFileRecord( CDBRecord &dbRecord,BOOL &bThreadStop,CString &strErrInfo )
|
{
|
int nStatus = CMBDownloadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
if( bThreadStop )
|
return false;
|
CAutoRefPtr<CMBHistoryFileInfo> pHistoryFileInfo(new CMBHistoryFileInfo());
|
pHistoryFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pHistoryFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_N_ISDIR"),pHistoryFileInfo->m_nIsDir); // id
|
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pHistoryFileInfo->m_strFileID); // Îļþid
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),pHistoryFileInfo->m_strLocalPath); // µ±Ç°Â·¾¶
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pHistoryFileInfo->m_nFileSize); // Îļþ´óС
|
//dbRecord.GetValue(_T("CN_N_STATUS"),pHistoryFileInfo->m_nStatus);
|
dbRecord.GetValue(_T("t_type"),pHistoryFileInfo->m_nType);
|
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pHistoryFileInfo->m_strFileSvr); // ·þÎñÆ÷±êʶ
|
dbRecord.GetValue(_T("CN_T_OP_STARTTIME"),pHistoryFileInfo->m_strTStartTime); // ¿ªÊ¼Ê±¼ä
|
dbRecord.GetValue(_T("CN_T_OP_ENDTTIME"),pHistoryFileInfo->m_strTEndTime); // ½áÊøÊ±¼ä
|
|
m_pHistoryTransMgr->AddHistoryFile(pHistoryFileInfo);
|
|
hR = dbRecord.MoveNext();
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::LoadHistoryFileRecord( CDBRecord &dbRecord,CString &strErrInfo )
|
{
|
int nStatus = CMBDownloadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
CAutoRefPtr<CMBHistoryFileInfo> pHistoryFileInfo(new CMBHistoryFileInfo());
|
pHistoryFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pHistoryFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_N_ISDIR"),pHistoryFileInfo->m_nIsDir); // id
|
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pHistoryFileInfo->m_strFileID); // Îļþid
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),pHistoryFileInfo->m_strLocalPath); // µ±Ç°Â·¾¶
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pHistoryFileInfo->m_nFileSize); // Îļþ´óС
|
// dbRecord.GetValue(_T("CN_N_STATUS"),pHistoryFileInfo->m_nStatus);
|
dbRecord.GetValue(_T("t_type"),pHistoryFileInfo->m_nType);
|
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pHistoryFileInfo->m_strFileSvr); // ·þÎñÆ÷±êʶ
|
dbRecord.GetValue(_T("CN_T_OP_STARTTIME"),pHistoryFileInfo->m_strTStartTime); // ¿ªÊ¼Ê±¼ä
|
dbRecord.GetValue(_T("CN_T_OP_ENDTTIME"),pHistoryFileInfo->m_strTEndTime); // ½áÊøÊ±¼ä
|
|
m_pHistoryTransMgr->AddHistoryFile(pHistoryFileInfo);
|
|
hR = dbRecord.MoveNext();
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::DeleteSqliteOnHistory( CMBHistoryFileInfo *pHistoryFileInfo, CString &strErrInfo )
|
{
|
CString strSql;
|
if( NULL == pHistoryFileInfo )
|
return false;
|
|
try{
|
// m_nType; // ÀàÐÍ 1 OI_MBC_UPLOAD_HISTORY_FILE; 0 OI_MBC_DOWNLOAD_HISTORY_FILE
|
if( pHistoryFileInfo->m_nType == 1 )
|
{
|
strSql.Format(_T("DELETE FROM OI_MBC_UPLOAD_HISTORY_FILE where CN_G_ID='%s'"),pHistoryFileInfo->m_strID);
|
}else
|
{
|
strSql.Format(_T("DELETE FROM OI_MBC_DOWNLOAD_HISTORY_FILE where CN_G_ID='%s'"),pHistoryFileInfo->m_strID);
|
}
|
int nRet = CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::DeleteSqliteOnHistory( CString &strErrInfo )
|
{
|
CString strSql;
|
|
try{
|
// ´Ó±í OI_MBC_UPLOAD_HISTORY_FILE Çå³ý
|
strSql.Format(_T("DELETE FROM OI_MBC_UPLOAD_HISTORY_FILE"));
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
// ´Ó±í OI_MBC_DOWNLOAD_HISTORY_FILE Çå³ý
|
strSql.Format(_T("DELETE FROM OI_MBC_DOWNLOAD_HISTORY_FILE"));
|
CDBSQLiteCommFun::RunSQL(strSql, &m_db );
|
}
|
catch(...)
|
{
|
CDBSQliteException sqliteException(m_db.m_pDB);
|
strErrInfo = sqliteException.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
|
}
|
|
bool CMBTransMgr::ReTileUploadMgr( CString strCabinetID,CString strServerPath,CString &strErrInfo )
|
{
|
if( NULL == m_pUploadQueue)
|
return false;
|
|
CString strLocalPath;
|
int nStatus = 0;
|
|
CUpClientAutoPtrList::iterator it;
|
CAutoRefPtr<CMBUploadFileInfo> curClient = NULL;
|
|
CUpClientAutoPtrList lstClient;
|
m_pUploadQueue->GetWaitingQueue( strCabinetID,strServerPath,lstClient );
|
|
for( it = lstClient.begin();it != lstClient.end();it++ )
|
{
|
curClient = *it;
|
if( curClient->m_strFrom == FCTN_ED ) // ÊDZ༣¬²»Òª¼ÓÔÚÁбíÖÐÁË
|
continue;
|
|
m_pTileUploadMgr->AddUploadFileInfo(curClient);
|
}
|
|
if( lstClient.size() == 0 )
|
{
|
m_pTileUploadMgr->RemoveAllTUploadFileInfo();
|
}
|
|
lstClient.clear();
|
|
return true;
|
}
|
|
bool CMBTransMgr::LoadTileUpload( CDBRecord &dbRecord,CString &strErrInfo )
|
{
|
int nStatus = CMBUploadFileInfo::Status_None; // ״̬
|
CString strMD5,strLocalPath,strErr;
|
// ÏÈÇå¿Õ
|
m_pTileUploadMgr->RemoveAllTUploadFileInfo();
|
|
HRESULT hR = dbRecord.MoveFirst();
|
while(S_OK== hR )
|
{
|
CAutoRefPtr<CMBUploadFileInfo> pUploadFileInfo(new CMBUploadFileInfo());
|
pUploadFileInfo->Release();
|
|
dbRecord.GetValue(_T("CN_G_ID"),pUploadFileInfo->m_strID); // id
|
dbRecord.GetValue(_T("CN_S_SERVER_PATH"),pUploadFileInfo->m_strServerPath);
|
dbRecord.GetValue(_T("CN_S_LOCAL_PATH"),strLocalPath);
|
pUploadFileInfo->SetLocalPath(strLocalPath);
|
dbRecord.GetValue(_T("CN_N_STATUS"),nStatus);
|
pUploadFileInfo->SetStatus(nStatus);
|
dbRecord.GetValue(_T("CN_N_FILE_SIZE"),pUploadFileInfo->m_nFileSize);
|
dbRecord.GetValue(_T("CN_N_ISDIR"),pUploadFileInfo->m_nIsDir);
|
dbRecord.GetValue(_T("CN_S_FILE_SVR"),pUploadFileInfo->m_strFileSvr);
|
dbRecord.GetValue(_T("CN_G_FILE_ID"),pUploadFileInfo->m_strFileID);
|
dbRecord.GetValue(_T("CN_S_FILE_NAME"),pUploadFileInfo->m_strFileName);
|
dbRecord.GetValue(_T("CN_S_MD5"),strMD5);
|
pUploadFileInfo->SetMD5(strMD5);
|
dbRecord.GetValue(_T("CN_S_ERR"),strErr);
|
pUploadFileInfo->SetErr(strErr);
|
dbRecord.GetValue(_T("CN_T_CREATE"),pUploadFileInfo->m_strTAddTime);
|
dbRecord.GetValue(_T("CN_G_CABINET_ID"),pUploadFileInfo->m_strCabinetID);
|
dbRecord.GetValue(_T("CN_S_CABINET_NAME"),pUploadFileInfo->m_strCabinetName);
|
dbRecord.GetValue(_T("CN_N_CABINET_TYPE"),pUploadFileInfo->m_nCabinetType);
|
|
m_pTileUploadMgr->AddUploadFileInfo(pUploadFileInfo);
|
|
hR = dbRecord.MoveNext();
|
}
|
return true;
|
}
|
|
bool CMBTransMgr::StartTransaction()
|
{
|
try{
|
m_db.StartTransaction();
|
}catch(...)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
bool CMBTransMgr::Commit()
|
{
|
try{
|
m_db.Commit();
|
}
|
catch(...)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
// ÖØÖÃÉÏ´«Áбí
|
void CMBTransMgr::CopyUploadLst( CMBUploadFileAutoPtrVector &vectorUploadLst )
|
{
|
m_pUploadQueue->ReUploadVector(m_nDisplayUploadCount,vectorUploadLst);
|
}
|
|
// ÖØÖÃÏÂÔØÁбí
|
void CMBTransMgr::CopyDownloadLst(CMBDownloadFileAutoPtrVector &vectorDownloadLst)
|
{
|
m_pDownloadQueue->ReDownloadVector(m_nDisplayDownloadCount,vectorDownloadLst);
|
}
|
|
|