// MBAMDBConnect.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbamdb.h"
|
#include "MBAMDBConnect.h"
|
#include "MBAMDBFun.h"
|
#include "MBAMDBDef.h"
|
#include "msg.h"
|
|
// CMBAMDBConnect
|
CCriticalSection m_csConnectDB;
|
|
CMBAMDBConnect::CMBAMDBConnect()
|
{
|
m_nAddRef = 0;
|
m_strLogin = _T("");
|
m_strServerID = _T("");
|
m_strDBFile = _T("");
|
m_bOpenDB = FALSE;
|
}
|
|
CMBAMDBConnect::~CMBAMDBConnect()
|
{
|
}
|
|
|
// CMBAMDBConnect member functions
|
void CMBAMDBConnect::AddRef()
|
{
|
m_nAddRef++;
|
//CMBAMDBFun::WriteDBErrToFile(strLog);
|
}
|
void CMBAMDBConnect::Release()
|
{
|
m_nAddRef--;
|
if(m_nAddRef < 1 )
|
{
|
if( CloseDB() )
|
delete this;
|
}
|
}
|
int CMBAMDBConnect::OpenDB( CString strLogin, CString strServerID, BOOL &bFirstDB )
|
{
|
bFirstDB = TRUE;
|
if ( strLogin.IsEmpty() || strServerID.IsEmpty() )
|
{
|
return STKERR_DB_NOLOGINSERVER;
|
}
|
CloseDB();
|
m_nAddRef = 0;
|
CString strPathName, strFileName;
|
CString strTemplateDBFile;
|
CString strDBPassword;
|
BOOL bExistFile = false;
|
|
strTemplateDBFile.Format( _T("%s\\stkclient.db3"),CBaseCommFun::GetAMDataDir( ));
|
strFileName.Format( _T("%s\\STKClient.db3"), CBaseCommFun::GetAMUserDataDir(strLogin,strServerID ) );
|
bExistFile = CBaseCommFun::ExistFile( strFileName );
|
if ( bExistFile )
|
{
|
bFirstDB = FALSE;
|
}
|
else
|
{
|
if ( strTemplateDBFile.IsEmpty() )
|
return STKERR_DB_NOTEMPLETFILE;
|
if ( !CopyFile( strTemplateDBFile, strFileName, false ) )
|
{
|
return STKERR_DB_COYPTEMPLETFAILED;
|
}
|
}
|
GetDBPassword( strDBPassword );
|
if ( !m_AConnect.Open( strFileName ,strDBPassword ) )
|
return STKERR_DB_OPENFAILED;
|
AddRef();
|
m_strLogin = strLogin;
|
m_strServerID = strServerID;
|
m_strDBFile = strFileName;
|
m_bOpenDB = TRUE;
|
return 0;
|
}
|
int CMBAMDBConnect::OpenDB( CString strDBFile)
|
{
|
if ( strDBFile.IsEmpty())
|
{
|
return STKERR_DB_NOLOGINSERVER;
|
}
|
CloseDB();
|
m_nAddRef = 0;
|
CString strDBPassword;
|
if ( !CBaseCommFun::ExistFile( strDBFile ) )
|
{
|
return STKERR_DB_NODBFILE;
|
}
|
GetDBPassword( strDBPassword );
|
if ( !m_AConnect.Open( strDBFile ,strDBPassword ) )
|
return STKERR_DB_OPENFAILED;
|
AddRef();
|
m_strDBFile = strDBFile;
|
m_bOpenDB = TRUE;
|
return 0;
|
}
|
|
BOOL CMBAMDBConnect::CloseDB()
|
{
|
if ( m_bOpenDB )
|
{
|
m_AConnect.Close();
|
m_bOpenDB = FALSE;
|
m_strDBFile = _T( "" );
|
m_strLogin = _T("");
|
m_strServerID = _T("");
|
return TRUE;
|
}
|
return FALSE;
|
}
|
CDBConnect* CMBAMDBConnect::GetDBConnect( )
|
{
|
return &m_AConnect;
|
}
|
|
BOOL CMBAMDBConnect::IsThisDB( CString strLogin, CString strServerID )
|
{
|
if ( strLogin.CompareNoCase( m_strLogin ) == 0
|
&& strServerID.CompareNoCase( m_strServerID ) == 0 )
|
{
|
return true;
|
}
|
|
return false;
|
}
|
BOOL CMBAMDBConnect::IsOpenDB( )
|
{
|
return m_bOpenDB;
|
}
|
void CMBAMDBConnect::GetDBPassword( CString &strDBPassword )
|
{
|
CString strInitFile;
|
TCHAR szValue[256] = { 0 };
|
|
strInitFile = CMBAMDBFun::GetDefaultIniFile();
|
GetPrivateProfileString(SYSSET_STK_SECTION, SYSSET_STK_SECTION_DBPASSWORD,_T(""),szValue,256, strInitFile );
|
strDBPassword = szValue;
|
CEncrypt::Decrypt( strDBPassword, PSW_EMKEY );
|
}
|
|
BOOL CMBAMDBConnect::StartTransaction()
|
{
|
return m_AConnect.StartTransaction();
|
}
|
BOOL CMBAMDBConnect::Commit()
|
{
|
return m_AConnect.Commit();
|
}
|
BOOL CMBAMDBConnect::Abort()
|
{
|
return m_AConnect.Abort();
|
}
|
BOOL CMBAMDBConnect::InsertPropStringData( CString strPropClass,
|
CString strPropName, int nPropVer,CString strPropValue, CString strPropExtValue )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
BOOL bReturn = TRUE;
|
CString strWhere;
|
|
strSQL.Format( _T("INSERT INTO TN_STK_USEREXTPROPERTY(S_C1 , S_C2 , N_C3 , S_C4, B_C5) VALUES ( \
|
'%s', '%s', %d, '%s', ?)"), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ), nPropVer, CMBAMDBFun::GetDBReplaceStr( strPropValue ));
|
try
|
{
|
|
bReturn = CDBBlob::SaveString(&m_AConnect,strSQL, strPropExtValue);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("InsertPropStringData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
|
return bReturn;
|
}
|
BOOL CMBAMDBConnect::UpdatePropStringData( CString strPropClass,
|
CString strPropName, int nPropVer,CString strPropValue, CString strPropExtValue )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
// CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
|
CString strSQL, strWhere;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
int nCount = 0;
|
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while (S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0 )
|
{
|
strSQL.Format( _T("UPDATE TN_STK_USEREXTPROPERTY SET N_C3 = %d,S_C4 = '%s',B_C5=? WHERE S_C1='%s' AND S_C2='%s'"),
|
nPropVer,CMBAMDBFun::GetDBReplaceStr( strPropValue ),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ) );
|
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_USEREXTPROPERTY(S_C1 , S_C2 , N_C3 , S_C4, B_C5) VALUES ( \
|
'%s', '%s', %d, '%s', ?)"), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ), nPropVer, CMBAMDBFun::GetDBReplaceStr( strPropValue ));
|
}
|
bReturn = CDBBlob::SaveString(&m_AConnect,strSQL, strPropExtValue);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo.Format(_T("UpdatePropData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::InsertPropFileData( CString strPropClass,
|
CString strPropName, int nPropVer, CString strPropValue, CString strPropDataFile )
|
{
|
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
BOOL bReturn = TRUE;
|
CString strWhere;
|
|
strSQL.Format( _T("INSERT INTO TN_STK_USEREXTPROPERTY(S_C1 , S_C2 , N_C3 , S_C4, B_C5) VALUES ( \
|
'%s', '%s', %d, '%s', ?)"), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ), nPropVer, CMBAMDBFun::GetDBReplaceStr( strPropValue ));
|
try
|
{
|
if(CBaseCommFun::ExistFile(strPropDataFile))
|
{
|
bReturn = CDBBlob::SaveFile(&m_AConnect,strSQL, strPropDataFile);
|
}
|
else
|
{
|
bReturn = CDBBlob::SaveString(&m_AConnect,strSQL, _T(""));
|
}
|
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("InsertPropFileData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
BOOL CMBAMDBConnect::UpdatePropFileData( CString strPropClass,
|
CString strPropName, int nPropVer,CString strPropValue, CString strPropDataFile )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
int nCount = 0;
|
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0 )
|
{
|
strSQL.Format( _T("UPDATE TN_STK_USEREXTPROPERTY SET N_C3 = %d, S_C4='%s', B_C5=? WHERE S_C1='%s' AND S_C2='%s'"),
|
nPropVer, CMBAMDBFun::GetDBReplaceStr( strPropValue ), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ) );
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_USEREXTPROPERTY(S_C1 , S_C2 , N_C3, S_C4,B_C5) VALUES ( \
|
'%s', '%s', %d,'%s',?)"), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ), nPropVer, CMBAMDBFun::GetDBReplaceStr( strPropValue ));
|
|
}
|
if(CBaseCommFun::ExistFile(strPropDataFile))
|
{
|
bReturn = CDBBlob::SaveFile(&m_AConnect,strSQL, strPropDataFile);
|
}
|
else
|
{
|
bReturn = CDBBlob::SaveString(&m_AConnect,strSQL, _T(""));
|
}
|
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("UpdatePropFileData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::GetPropFileData( CString strPropClass,
|
CString strPropName, int &nPropVer,CString &strPropValue, CString strPropDataFile )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
BOOL bFlag = FALSE;
|
CString strVaule;
|
int nVaule;
|
|
nPropVer = 0;
|
strPropValue = _T("");
|
strSQL.Format( _T("SELECT N_C3, S_C4 FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
nVaule = 0;
|
ARecordset.GetValue( 1, nVaule );
|
nPropVer = nVaule;
|
strVaule = _T("");
|
ARecordset.GetValue( 2, strVaule );
|
strPropValue = strVaule;
|
bFlag = TRUE;
|
break;
|
}
|
if( bFlag )
|
{
|
if( !strPropDataFile.IsEmpty())
|
{
|
strSQL.Format( _T("SELECT B_C5 FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
bReturn = CDBBlob::ReadFile(&m_AConnect, strSQL, strPropDataFile);
|
}
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("GetPropFileData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
|
return bReturn;
|
}
|
BOOL CMBAMDBConnect::GetPropStringData(CString strPropClass,
|
CString strPropName, int &nPropVer,CString &strPropValue, CString &strPropExtValue )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
BOOL bFlag = FALSE;
|
CString strVaule;
|
int nVaule;
|
|
nPropVer = 0;
|
strPropValue = _T("");
|
strPropExtValue = _T("");
|
strSQL.Format( _T("SELECT N_C3, S_C4 FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
nVaule = 0;
|
ARecordset.GetValue( 1, nVaule );
|
nPropVer = nVaule;
|
strVaule = _T("");
|
ARecordset.GetValue( 2, strVaule );
|
strPropValue = strVaule;
|
bFlag = TRUE;
|
break;
|
}
|
if( bFlag )
|
{
|
strSQL.Format( _T("SELECT B_C5 FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
bReturn = CDBBlob::ReadString(&m_AConnect, strSQL, strPropExtValue);
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("GetPropStringData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::GetPropVersion(CString strPropClass, CString strPropName, int &nPropVer )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
int nVaule;
|
|
nPropVer =0;
|
strSQL.Format( _T("SELECT N_C3 FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
nVaule = 0;
|
ARecordset.GetValue( 1, nVaule );
|
nPropVer = nVaule;
|
bReturn = TRUE;
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("GetPropVersion(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::SetPropVersion(CString strPropClass, CString strPropName, int nPropVer )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
int nCount = 0;
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0 )
|
{
|
strSQL.Format( _T("UPDATE TN_STK_USEREXTPROPERTY SET N_C3 = %d WHERE S_C1='%s' AND S_C2='%s'"),
|
nPropVer,CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ) );
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_USEREXTPROPERTY(S_C1 , S_C2 , N_C3) VALUES ( '%s', '%s', %d)"),
|
CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ),nPropVer );
|
}
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("SetPropVersion(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::GetPropertyData(CString strPropClass, CString strPropName, CString &strPropValue )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
CString strVaule;
|
|
strPropValue = _T("");
|
strSQL.Format( _T("SELECT S_C3 FROM TN_STK_EXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strVaule );
|
strPropValue = strVaule;
|
bReturn = TRUE;
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("GetPropertyData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::SetPropertyData(CString strPropClass, CString strPropName, CString strPropValue )
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
int nCount = 0;
|
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_EXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0 )
|
{
|
strSQL.Format( _T("UPDATE TN_STK_EXTPROPERTY SET S_C3 = %d WHERE S_C1='%s' AND S_C2='%s'"),
|
strPropValue,CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ) );
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_EXTPROPERTY(S_C1 , S_C2 , S_C3) VALUES ( '%s', '%s', '%s')"),
|
CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ),strPropValue );
|
}
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format(_T("SetPropertyData(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::RemoveLastContact( CString strID, int nType)
|
{
|
if ( strID.IsEmpty() )
|
return FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
BOOL bReturn = FALSE;
|
|
if(nType != AM_VIEWITEMTYPE_USER && nType != AM_VIEWITEMTYPE_CROWD )
|
return TRUE;
|
strSQL.Format( _T("DELETE FROM TN_STK_LASTCONTACT WHERE S_C1= '%s' AND N_C4 =%d"), CMBAMDBFun::GetDBReplaceStr( strID), nType );
|
try
|
{
|
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,&m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("RemoveLastContact - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
BOOL CMBAMDBConnect::LoadLastContact(CArraySTKLastContact &arLastContact, int nLimitCount )
|
{
|
CString strID, strName;
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
COleDateTime aDate;
|
CString strSubject;
|
int nType = AM_VIEWITEMTYPE_NONE;
|
stSTKLastContact itemLastContact;
|
CMapStringToString mapLastContact;
|
CString strLastOldDate= _T("");
|
arLastContact.RemoveAll();
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strLimitSQL = _T("");
|
if(nLimitCount > 0)
|
strLimitSQL.Format( _T("limit 0,%d"), nLimitCount);
|
strSQL.Format( _T("SELECT S_C1, S_C2, T_C3,N_C4, S_C5 ")
|
_T("FROM TN_STK_LASTCONTACT ")
|
_T(" ORDER BY T_C3 DESC %s"), strLimitSQL);
|
|
try
|
{
|
mapLastContact.RemoveAll();
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strID = strValue;
|
strValue = _T("");
|
|
if(mapLastContact.Lookup(strID,strValue))
|
{
|
continue;
|
}
|
nType = AM_VIEWITEMTYPE_USER;
|
mapLastContact.SetAt(strID,strID);
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
strValue = _T("");
|
ARecordset.GetValue( 3, aDate );
|
ARecordset.GetValue( 4, nType );
|
ARecordset.GetValue( 5, strValue, true );
|
strSubject = strValue;
|
itemLastContact.strID = strID;
|
itemLastContact.strName = strName;
|
itemLastContact.nType = nType;
|
itemLastContact.dtDate = aDate;
|
itemLastContact.strSubject = strSubject;
|
arLastContact.Add(itemLastContact);
|
strLastOldDate = CMBAMDBFun::FormatDBTIMEToStr( aDate );
|
}
|
if( !strLastOldDate.IsEmpty())
|
{
|
strSQL.Format( _T("DELETE FROM TN_STK_LASTCONTACT WHERE T_C3<'%s'"), strLastOldDate );
|
CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,&m_AConnect);
|
}
|
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadLastContact - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::GetLastContactItem(CString strID, int nType,stSTKLastContact &itemLastContact )
|
{
|
CString strName;
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
CString strSubject;
|
COleDateTime aDate;
|
BOOL bRet = FALSE ;
|
if ( !m_bOpenDB )
|
return FALSE;
|
strSQL.Format( _T("SELECT S_C1, S_C2, T_C3,N_C4, S_C5 ")
|
_T("FROM TN_STK_LASTCONTACT WHERE S_C1='%s' AND N_C4=%d"), strID,nType);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
strValue = _T("");
|
ARecordset.GetValue( 3, aDate );
|
ARecordset.GetValue( 5, strValue, true );
|
strSubject = strValue;
|
itemLastContact.strID = strID;
|
itemLastContact.strName = strName;
|
itemLastContact.nType = nType;
|
itemLastContact.dtDate = aDate;
|
itemLastContact.strSubject = strSubject;
|
bRet = TRUE ;
|
break;
|
}
|
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetLastContactItem - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
|
return FALSE;
|
}
|
return bRet;
|
}
|
int CMBAMDBConnect::GetUnreadMsgCount( CString strID, int nType)
|
{
|
if ( !m_bOpenDB )
|
return 0;
|
CString strSQL;
|
CDBRecord ARecordset;
|
int nRecordCount = 0;
|
|
if(nType == AM_VIEWITEMTYPE_USER)
|
{
|
strSQL.Format(_T("SELECT COUNT(G_C1) FROM TN_STK_UNREADMSG WHERE S_C2='%s'"),strID);
|
}
|
else if(nType == AM_VIEWITEMTYPE_CROWD)
|
strSQL.Format(_T("SELECT COUNT(G_C1) FROM TN_STK_CROWDMSG WHERE G_C2='%s' AND N_C7 <= 1 "),strID);
|
else
|
return 0;
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nRecordCount );
|
break;
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetUnreadMsgCount - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return 0;
|
}
|
return nRecordCount;
|
}
|
int CMBAMDBConnect::GetUnreadMsgCount()
|
{
|
if ( !m_bOpenDB )
|
return 0;
|
CString strSQL,strSQL2;
|
CDBRecord ARecordset;
|
int nRecordCount = 0;
|
int nValue = 0;
|
|
strSQL.Format(_T("SELECT COUNT(G_C1) FROM TN_STK_UNREADMSG"));
|
strSQL2.Format(_T("SELECT COUNT(G_C1) FROM TN_STK_CROWDMSG WHERE N_C7 <= 1 "));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nValue );
|
nRecordCount += nValue;
|
break;
|
}
|
ARecordset.Close();
|
ARecordset.Open( &m_AConnect,strSQL2 );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nValue );
|
nRecordCount += nValue;
|
break;
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetUnreadMsgCount - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return 0;
|
}
|
return nRecordCount;
|
}
|
BOOL CMBAMDBConnect::RemoveUnreadMsg(CString strMsgID)
|
{
|
//return true;
|
CString strSQL;
|
BOOL bReturn = true;
|
if ( !m_bOpenDB )
|
return FALSE;
|
strSQL.Format( _T("DELETE FROM TN_STK_UNREADMSG WHERE G_C1='%s'"), strMsgID);
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("RemoveUnreadMsg - Msg- ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
int CMBAMDBConnect::CheckMsgExist( LPCTSTR lpszMsgID )
|
{ // ʹÓÃÕâ¸öº¯Êý£¬¹ýÂËÌõ¼þÎÞЧ
|
if ( lpszMsgID == NULL )
|
return 0;
|
CDBRecord ARecordset;
|
CString strSQL;
|
int nCount = 0;
|
if ( !m_bOpenDB )
|
return 0;
|
strSQL.Format( _T("SELECT COUNT(G_C1) FROM TN_STK_MSG WHERE G_C1 = '%s'"), lpszMsgID);
|
try
|
{
|
ARecordset.Close( );
|
ARecordset.Open(&m_AConnect, strSQL );
|
while(S_OK == ARecordset.MoveNext())
|
{
|
ARecordset.GetValue(1,nCount );
|
break;
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return 0;
|
}
|
return nCount;
|
}
|
|
BOOL CMBAMDBConnect::GetMsgFileInfo(CString strMsgID, CString strFileID, CString &strFileName,
|
CString &strFileSflag, __int64 &nFileSize )
|
{
|
strFileName = _T("");
|
strFileSflag = _T("");
|
nFileSize = 0;
|
if(strFileID.IsEmpty())
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL, strTemp;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
|
strFileName = _T("");
|
strSQL.Format( _T("SELECT S_C2, S_C6, N_C3 FROM TN_STK_ATTACHMENT WHERE G_C5 ='%s' AND G_C1 ='%s'"), strFileID,strMsgID);
|
try
|
{
|
|
ARecordset.Open( &m_AConnect, strSQL );
|
if ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strTemp, true );
|
strFileName = strTemp;
|
ARecordset.GetValue( 2, strTemp, true );
|
strFileSflag = strTemp;
|
nFileSize = 0;
|
ARecordset.GetValue( 3,nFileSize);
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo = _T("GetMsgFileInfo - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
|
return false;
|
}
|
|
return true;
|
}
|
|
BOOL CMBAMDBConnect::GetMsgFilesInfo( CString strMsgID,CStringArray &arAttachID/*, CString &strFileSflag*/)
|
{
|
arAttachID.RemoveAll();
|
//strFileSflag = _T("");
|
if(strMsgID.IsEmpty())
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL, strTemp;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("SELECT G_C5 FROM TN_STK_ATTACHMENT WHERE G_C1 ='%s'"), strMsgID);
|
try
|
{
|
|
ARecordset.Open( &m_AConnect ,strSQL);
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strTemp, true );
|
arAttachID.Add((LPCTSTR)strTemp);
|
//ARecordset.GetValue( 2, strTemp, true );
|
//strFileSflag = (LPCTSTR)strTemp;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo = _T("GetMsgFilesInfo - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
|
BOOL CMBAMDBConnect::GetMsgFilePath(CString strMsgID, CString strFileID, CString &strFilePath )
|
{
|
strFilePath = _T("");
|
if(strFileID.IsEmpty())
|
return FALSE;
|
// CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL, strTemp;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
|
strFilePath = _T("");
|
strSQL.Format( _T("SELECT S_C8 FROM TN_STK_ATTACHMENT WHERE G_C5 ='%s' AND G_C1 ='%s'"), strFileID,strMsgID);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
if ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strTemp, true );
|
strFilePath = (LPCTSTR)strTemp;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo = _T("GetMsgFilePath - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
|
return false;
|
}
|
|
return true;
|
}
|
|
//=========================================================
|
// Ö»ÄÜÊǸüÐÂÒ»Ìõ¼Ç¼,²»¿ÉÄÜÊǶàÌõµÄ¼Ç¼
|
//=========================================================
|
BOOL CMBAMDBConnect::SetMsgFilePath(CString strMsgID, CString strFileID, CString strFilePath )
|
{
|
if(strFileID.IsEmpty())
|
return FALSE;
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("UPDATE TN_STK_ATTACHMENT SET S_C8 = '%s' WHERE G_C5 = '%s' AND G_C1 ='%s'"), CMBAMDBFun::GetDBReplaceStr( strFilePath ), strFileID,strMsgID);
|
|
try
|
{
|
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("SetMsgFilePath - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
|
return true;
|
}
|
BOOL CMBAMDBConnect::ListUnReadMsg( CObList &listMsg )
|
{
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
CMsgItem *pMsg;
|
if ( !m_bOpenDB )
|
return FALSE;
|
strSQL.Format( _T("SELECT G_C1,S_C2 ,S_C3,S_C4 ,T_C5 FROM TN_STK_UNREADMSG "));
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
pMsg = new CMsgItem;
|
ARecordset.GetValue( 1, strValue, true );
|
pMsg->m_strID = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
pMsg->m_strSender = strValue;
|
ARecordset.GetValue( 3, strValue, true );
|
pMsg->m_strSenderName = strValue;
|
ARecordset.GetValue( 4, strValue, true );
|
pMsg->m_strSubject = strValue;
|
ARecordset.GetValue( 5, pMsg->m_tmDate );
|
listMsg.AddTail( (CObject*)pMsg );
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ListUnReadMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::DeletCrowdMsg( CString strMsgID,CString strGroupID)
|
{
|
CDBRecord ARecordset;
|
CString strSQL;
|
BOOL bReturn = true;
|
int nCount = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strMsgID.IsEmpty() || strGroupID.IsEmpty() )
|
return FALSE;
|
try
|
{
|
strSQL.Format( _T("DELETE FROM TN_STK_CROWDMSG WHERE G_C1='%s' AND G_C2='%s'"),strMsgID,strGroupID);
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("DeletCrowdMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::DeleteGroupFileInfo( CString strGroupID, CString strShareID)
|
{
|
CDBRecord ARecordset;
|
CString strSQL;
|
BOOL bReturn = true;
|
int nCount = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strShareID.IsEmpty())
|
return FALSE;
|
try
|
{
|
strSQL.Format( _T("DELETE FROM TN_STK_GROUPFILE WHERE G_C1='%s' AND G_C2='%s'"),strGroupID,strShareID);
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("DeleteGroupFileInfo - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::UpdateGroupFileInfo( CString strGroupID, CString strShareID, CString strFilePath, CString strFileName, __int64 nFileSize )
|
{
|
CDBRecord ARecordset;
|
CString strSQL;
|
BOOL bReturn = true;
|
int nCount = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strShareID.IsEmpty())
|
return FALSE;
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_GROUPFILE WHERE G_C1='%s' AND G_C2='%s'"),strGroupID,strShareID);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0)
|
{
|
strSQL.Format( _T("UPDATE TN_STK_GROUPFILE SET S_C3='%s' WHERE G_C1='%s' AND G_C2='%s'"),strFilePath,strGroupID,strShareID);
|
}
|
else
|
{
|
if(strFileName.IsEmpty())
|
strFileName = CBaseCommFun::GetFileName( strFilePath);
|
strSQL.Format( _T("INSERT INTO TN_STK_GROUPFILE (G_C1,G_C2,S_C3,S_C4,N_C5) VALUES('%s', '%s','%s','%s',%I64d)"),strGroupID,strShareID,strFilePath,strFileName,nFileSize);
|
}
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("UpdateGroupFileInfo - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::AddGroupFileInfo( CString strGroupID, CString strShareID, CString strFileName, __int64 nFileSize )
|
{
|
CDBRecord ARecordset;
|
CString strSQL;
|
BOOL bReturn = true;
|
int nCount = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strShareID.IsEmpty())
|
return FALSE;
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_GROUPFILE WHERE G_C1='%s' AND G_C2='%s'"),strGroupID,strShareID);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0)
|
{
|
strSQL.Format( _T("UPDATE TN_STK_GROUPFILE SET S_C4='%s',N_C5=%I64d WHERE G_C1='%s' AND G_C2='%s'"),strFileName,nFileSize,strGroupID,strShareID);
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_GROUPFILE (G_C1,G_C2,S_C4,N_C5) VALUES('%s', '%s','%s',%I64d)"),strGroupID,strShareID,strFileName,nFileSize);
|
}
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("AddGroupFileInfo - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::LoadGroupFilePath( CString strGroupID, CString strShareID, CString &strFilePath )
|
{
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
|
strFilePath = _T("");
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strShareID.IsEmpty())
|
return FALSE;
|
strSQL.Format( _T("SELECT S_C3 FROM TN_STK_GROUPFILE WHERE G_C1='%s' AND G_C2='%s'"),strGroupID,strShareID);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strFilePath = strValue;
|
break;
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadGroupFilePath - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::LoadGroupFileInfo( CString strGroupID, CString strShareID, CString &strFileName, __int64 &nFileSize )
|
{
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
|
strFileName = _T("");
|
nFileSize = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strShareID.IsEmpty())
|
return FALSE;
|
strSQL.Format( _T("SELECT S_C4,N_C5 FROM TN_STK_GROUPFILE WHERE G_C1='%s' AND G_C2='%s'"),strGroupID,strShareID);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strFileName = strValue;
|
ARecordset.GetValue(2, nFileSize );
|
break;
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadGroupFileInfo - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::LoadGroupFileInfo2( CString strGroupID, CString strShareID, CString &strFileName, CString &strFilePath, __int64 &nFileSize )
|
{
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
|
strFileName = _T("");
|
strFilePath = _T("");
|
nFileSize = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strShareID.IsEmpty())
|
return FALSE;
|
strSQL.Format( _T("SELECT S_C4,S_C3,N_C5 FROM TN_STK_GROUPFILE WHERE G_C1='%s' AND G_C2='%s'"),strGroupID,strShareID);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strFileName = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
strFilePath = strValue;
|
ARecordset.GetValue(3, nFileSize );
|
break;
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadGroupFileInfo2 - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::ListMsg(CString strDate,CString strSender,long nLimitCount,CArrayShortMsg &arUserMsg,BOOL bTimeAsc)
|
{
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
stSTKShortMsg itemMsg;
|
arUserMsg.RemoveAll();
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strLimitSQL = _T("");
|
if(nLimitCount > 0)
|
strLimitSQL.Format( _T("limit 0,%d"), nLimitCount);
|
if(bTimeAsc)
|
strSQL.Format( _T("SELECT ST.G_C1,ST.S_C3 FROM(SELECT M1.G_C1,M1.S_C3,M1.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C4='%s' AND T_C6<='%s' ORDER BY T_C6 DESC limit 0,%d)M1 UNION SELECT M2.G_C1,M2.S_C3,M2.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C4='%s' AND T_C6>'%s' ORDER BY T_C6 ASC %s)M2)ST ORDER BY ST.T_C6 ASC"),strSender,strDate,nLimitCount,strSender,strDate,strLimitSQL);
|
else
|
strSQL.Format( _T("SELECT ST.G_C1,ST.S_C3 FROM(SELECT M1.G_C1,M1.S_C3,M1.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C4='%s' AND T_C6<='%s' ORDER BY T_C6 DESC limit 0,%d)M1 UNION SELECT M2.G_C1,M2.S_C3,M2.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C4='%s' AND T_C6>'%s' ORDER BY T_C6 ASC %s)M2)ST ORDER BY ST.T_C6 DESC"),strSender,strDate,nLimitCount,strSender,strDate,strLimitSQL);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
itemMsg.strMsgID = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
itemMsg.strSubject = strValue;
|
arUserMsg.Add(itemMsg);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ListMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
|
BOOL CMBAMDBConnect::ListMsg2(CString strDate,CString strExtType,long nLimitCount,CArrayShortMsg &arUserMsg,BOOL bTimeAsc)
|
{
|
CString strSQL, strValue;
|
CDBRecord ARecordset;
|
stSTKShortMsg itemMsg;
|
arUserMsg.RemoveAll();
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strLimitSQL = _T("");
|
if(nLimitCount > 0)
|
strLimitSQL.Format( _T("limit 0,%d"), nLimitCount);
|
if(bTimeAsc)
|
strSQL.Format( _T("SELECT ST.G_C1,ST.S_C3 FROM(SELECT M1.G_C1,M1.S_C3,M1.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C10='%s' AND T_C6<='%s' ORDER BY T_C6 DESC limit 0,%d)M1 UNION SELECT M2.G_C1,M2.S_C3,M2.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C10='%s' AND T_C6>'%s' ORDER BY T_C6 ASC %s)M2)ST ORDER BY ST.T_C6 ASC"),strExtType,strDate,nLimitCount,strExtType,strDate,strLimitSQL);
|
else
|
strSQL.Format( _T("SELECT ST.G_C1,ST.S_C3 FROM(SELECT M1.G_C1,M1.S_C3,M1.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C10='%s' AND T_C6<='%s' ORDER BY T_C6 DESC limit 0,%d)M1 UNION SELECT M2.G_C1,M2.S_C3,M2.T_C6 FROM(SELECT G_C1,S_C3,T_C6 FROM TN_STK_MSG WHERE S_C10='%s' AND T_C6>'%s' ORDER BY T_C6 ASC %s)M2)ST ORDER BY ST.T_C6 DESC"),strExtType,strDate,nLimitCount,strExtType,strDate,strLimitSQL);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
itemMsg.strMsgID = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
itemMsg.strSubject = strValue;
|
arUserMsg.Add(itemMsg);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ListMsg2 - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::ClearReceiveBoxMsg(CString strStartDate,CString strEndDate, CString strUser,CString strUserName,CString strContentKey, int nAttach)
|
{
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strMsgSQL;
|
CString strMsgSQL2;
|
CString strMsgSQL3;
|
CString strMsgSQL4;
|
CString strMsgSQL5;
|
CString strSQLWhere = _T("");
|
CString strValue;
|
CString strSQLTemp;
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
|
strUser.MakeLower();
|
strSQLWhere.Format(_T(" N_C8=%d "), MANAGER_FOLDER_BOX_IN );
|
if( !strContentKey.IsEmpty())
|
{
|
strSQLTemp.Format( _T(" AND (S_C3 LIKE '%%%s%%' OR S_C25 LIKE '%%%s%%') "), strContentKey,strContentKey );
|
strSQLWhere += strSQLTemp;
|
}
|
// Set Filter
|
if ( !strStartDate.IsEmpty() && tmHigh.ParseDateTime( strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 >='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
if ( !strEndDate.IsEmpty() && tmHigh.ParseDateTime( strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 <='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
if(nAttach > 0)
|
{
|
strSQLTemp.Format( _T(" AND N_C12>0") );
|
strSQLWhere += strSQLTemp;
|
}
|
else if(nAttach == 0)
|
{
|
strSQLTemp.Format( _T(" AND N_C12=0") );
|
strSQLWhere += strSQLTemp;
|
}
|
strSQLTemp.Format( _T(" AND S_C10='' ") );
|
strSQLWhere += strSQLTemp;
|
if( !strUser.IsEmpty())
|
{
|
if(strUserName.IsEmpty() )
|
{
|
strSQLTemp.Format( _T("AND (S_C4 LIKE '%s%%' OR S_C5 LIKE '%s%%') "), strUser,strUser );
|
}
|
else
|
strSQLTemp.Format( _T("AND S_C4='%s' "), strUser );
|
strSQLWhere += strSQLTemp;
|
}
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE %s"),strSQLWhere );
|
strMsgSQL2.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere );
|
strMsgSQL3.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere );
|
strMsgSQL4.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere );
|
strMsgSQL5.Format( _T("DELETE FROM TN_STK_UNREADMSG WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s ) "), strSQLWhere );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL(strMsgSQL2, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL3, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL4, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL5, &m_AConnect);
|
bReturn = CDBSQLiteCommFun::RunSQL(strMsgSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ClearReceiveBoxMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::ClearSendBoxMsg(CString strStartDate,CString strEndDate, CString strUser,CString strUserName,CString strContentKey, int nAttach)
|
{
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strMsgSQL;
|
CString strMsgSQL2;
|
CString strMsgSQL3;
|
CString strMsgSQL4;
|
CString strSelectSQL;
|
CString strSQLWhere = _T("");
|
CString strValue;
|
CString strSQLTemp;
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
|
strUser.MakeLower();
|
strSQLWhere.Format(_T(" N_C8=%d "), MANAGER_FOLDER_BOX_OUT );
|
if( !strContentKey.IsEmpty())
|
{
|
strSQLTemp.Format( _T(" AND (S_C3 LIKE '%%%s%%' OR S_C25 LIKE '%%%s%%') "), strContentKey,strContentKey );
|
strSQLWhere += strSQLTemp;
|
}
|
// Set Filter
|
if ( !strStartDate.IsEmpty() && tmHigh.ParseDateTime( strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 >='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
if ( !strEndDate.IsEmpty() && tmHigh.ParseDateTime( strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 <='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
if(nAttach > 0)
|
{
|
strSQLTemp.Format( _T(" AND N_C12>0") );
|
strSQLWhere += strSQLTemp;
|
}
|
else if(nAttach == 0)
|
{
|
strSQLTemp.Format( _T(" AND N_C12=0") );
|
strSQLWhere += strSQLTemp;
|
}
|
strSQLTemp.Format( _T(" AND S_C10='' ") );
|
strSQLWhere += strSQLTemp;
|
if( !strUser.IsEmpty())
|
{
|
if(strUserName.IsEmpty() )
|
{
|
strSelectSQL.Format( _T("SELECT A.G_C1 ")
|
_T("FROM TN_STK_MSG A ")
|
_T("INNER JOIN (")
|
_T("SELECT AA.G_C1 ")
|
_T("FROM ( ")
|
_T("SELECT G_C1, C_C17,S_C18,S_C19 ")
|
_T("FROM TN_STK_MSG Where %s ")
|
_T(") AA ")
|
_T("LEFT JOIN TN_STK_MSGOWNER BB ")
|
_T("ON AA.G_C1 = BB.G_C1 ")
|
_T("WHERE (AA.C_C17='0' AND (AA.S_C18 LIKE '%s%%' OR AA.S_C19 LIKE '%s%%') ) ")
|
_T("OR ( AA.C_C17='1' AND (BB.S_C2 LIKE '%s%%' OR BB.S_C3 LIKE '%s%%') ) ")
|
_T("GROUP BY AA.G_C1 ")
|
_T(") B ")
|
_T("ON A.G_C1 = B.G_C1 "),
|
strSQLWhere, strUser,strUser, strUser,strUser );
|
}
|
else
|
{
|
strSelectSQL.Format( _T("SELECT A.G_C1 ")
|
_T("FROM TN_STK_MSG A ")
|
_T("INNER JOIN (")
|
_T("SELECT AA.G_C1 ")
|
_T("FROM ( ")
|
_T("SELECT G_C1, C_C17,S_C18 ")
|
_T("FROM TN_STK_MSG Where %s ")
|
_T(") AA ")
|
_T("LEFT JOIN TN_STK_MSGOWNER BB ")
|
_T("ON AA.G_C1 = BB.G_C1 ")
|
_T("WHERE (AA.C_C17='0' AND AA.S_C18='%s' ) ")
|
_T("OR ( AA.C_C17='1' AND BB.S_C2='%s' ) ")
|
_T("GROUP BY AA.G_C1 ")
|
_T(") B ")
|
_T("ON A.G_C1 = B.G_C1 "),
|
strSQLWhere, strUser, strUser );
|
}
|
}
|
else
|
{
|
strSelectSQL.Format( _T("SELECT G_C1 FROM TN_STK_MSG Where %s "),strSQLWhere );
|
}
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE G_C1 IN ( %s)"),strSelectSQL );
|
strMsgSQL2.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( %s) "), strSelectSQL );
|
strMsgSQL3.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( %s) "), strSelectSQL );
|
strMsgSQL4.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( %s) "), strSelectSQL );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL(strMsgSQL2, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL3, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL4, &m_AConnect);
|
bReturn = CDBSQLiteCommFun::RunSQL(strMsgSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ClearSendBoxMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::ClearSysBoxMsg(CString strStartDate,CString strEndDate)
|
{
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strMsgSQL;
|
CString strMsgSQL2;
|
CString strMsgSQL3;
|
CString strMsgSQL4;
|
CString strSQLWhere = _T("");
|
CString strValue;
|
CString strSubSQL;
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
strSQLWhere.Format( _T("N_C7=%d OR N_C7=%d"), AM_MSGTYPE_BROADCAST ,AM_MSGTYPE_GUNGHO );
|
if ( !strStartDate.IsEmpty() && tmHigh.ParseDateTime( strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSubSQL.Format(_T(" AND T_C6 >='%s'"),strValue);
|
strSQLWhere += strSubSQL;
|
}
|
if ( !strEndDate.IsEmpty() && tmHigh.ParseDateTime( strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSubSQL.Format(_T(" AND T_C6 <='%s'"),strValue);
|
strSQLWhere += strSubSQL;
|
}
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE %s"), strSQLWhere );
|
strMsgSQL2.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "),strSQLWhere );
|
strMsgSQL3.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere);
|
strMsgSQL4.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL(strMsgSQL2, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL3, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL4, &m_AConnect);
|
bReturn = CDBSQLiteCommFun::RunSQL(strMsgSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ClearSysBoxMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::ClearFavBoxMsg(CString strStartDate,CString strEndDate, CString strContentKey, int nFavFolder)
|
{
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strMsgSQL;
|
CString strMsgSQL2;
|
CString strMsgSQL3;
|
CString strMsgSQL4;
|
CString strSQLWhere = _T("");
|
CString strValue;
|
CString strSQLTemp;
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
strSQLWhere.Format(_T("N_C8=%d "), nFavFolder );
|
if( !strContentKey.IsEmpty())
|
{
|
strSQLTemp.Format( _T(" AND (S_C3 LIKE '%%%s%%' OR S_C25 LIKE '%%%s%%') "), strContentKey ,strContentKey );
|
strSQLWhere += strSQLTemp;
|
}
|
if ( !strStartDate.IsEmpty() && tmHigh.ParseDateTime( strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 >='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
if ( !strEndDate.IsEmpty() && tmHigh.ParseDateTime( strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 <='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
strSQLTemp.Format( _T(" AND S_C10='' ") );
|
strSQLWhere += strSQLTemp;
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE %s"), strSQLWhere );
|
strMsgSQL2.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "),strSQLWhere );
|
strMsgSQL3.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere);
|
strMsgSQL4.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE %s) "), strSQLWhere );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL(strMsgSQL2, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL3, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strMsgSQL4, &m_AConnect);
|
bReturn = CDBSQLiteCommFun::RunSQL(strMsgSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ClearFavBoxMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
|
BOOL CMBAMDBConnect::ClearCrowdMsgBox(CString strStartDate,CString strEndDate, CString strCrowdID, CString strKey)
|
{
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if ( strCrowdID.IsEmpty() )
|
return FALSE;
|
CString strMsgSQL;
|
CString strSQLWhere = _T("");
|
CString strValue;
|
CString strSQLTemp;
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
strSQLWhere.Format(_T("G_C2='%s' "), strCrowdID );
|
if( !strKey.IsEmpty())
|
{
|
strSQLTemp.Format( _T(" AND S_C12 LIKE '%%%s%%' "), strKey );
|
strSQLWhere += strSQLTemp;
|
}
|
if ( !strStartDate.IsEmpty() && tmHigh.ParseDateTime( strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 >='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
if ( !strEndDate.IsEmpty() && tmHigh.ParseDateTime( strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
strValue.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
strSQLTemp.Format(_T(" AND T_C6 <='%s'"),strValue);
|
strSQLWhere += strSQLTemp;
|
}
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_CROWDMSG WHERE %s"), strSQLWhere );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
bReturn = CDBSQLiteCommFun::RunSQL(strMsgSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("ClearCrowdMsgBox - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
/******************************************
|
Ãû³Æ£º
|
»ñÈ¡ÁªÏµÈË
|
|
²ÎÊý£ºCArrayAMObject &arAMObject
|
|
|
·µ»ØÖµ£º
|
false - ×°ÔØÊ§°Ü true - ×°ÔØ³É¹¦
|
******************************************/
|
bool CMBAMDBConnect::GetSendPerson(CArrayAMObject &arAMObject)
|
{
|
CString strSQL, strValue, strLogin, strName;
|
CDBRecord ARecordset;
|
CMapStringToString mapUser;
|
stAMObject itemObj;
|
arAMObject.RemoveAll();
|
strSQL.Format( _T("SELECT S_C4 AS SLOGIN, S_C5 AS SNAME FROM TN_STK_MSG WHERE N_C7=0 AND N_C8=%d AND S_C10='' GROUP BY S_C4 ORDER BY S_C5 ASC"), MANAGER_FOLDER_BOX_IN);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strLogin = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
if ( mapUser.Lookup(strLogin,strName))
|
{
|
continue;
|
}
|
mapUser.SetAt(strLogin,strLogin);
|
itemObj.strID = strLogin;
|
if ( strName.IsEmpty() )
|
itemObj.strName = strLogin;
|
else
|
itemObj.strName = strName;
|
arAMObject.Add(itemObj);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetSendPerson - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return true;
|
}
|
bool CMBAMDBConnect::GetReceivePerson(CArrayAMObject &arAMObject)
|
{
|
CString strSQL, strValue, strLogin, strName;
|
CDBRecord ARecordset;
|
CMapStringToString mapUser;
|
stAMObject itemObj;
|
arAMObject.RemoveAll();
|
strSQL.Format( _T("SELECT DISTINCT S_C18 AS SLOGIN, S_C19 AS SNAME FROM TN_STK_MSG WHERE C_C17=0 AND N_C7=0 AND N_C8=%d AND S_C10='' GROUP BY S_C18 ORDER BY S_C19 ASC "),MANAGER_FOLDER_BOX_OUT);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strLogin = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
if ( mapUser.Lookup(strLogin,strName))
|
{
|
continue;
|
}
|
mapUser.SetAt(strLogin,strLogin);
|
itemObj.strID = strLogin;
|
if ( strName.IsEmpty() )
|
itemObj.strName = strLogin;
|
else
|
itemObj.strName = strName;
|
arAMObject.Add(itemObj);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetReceivePerson - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
strSQL.Format( _T("SELECT AA.S_C2,AA.S_C3 FROM TN_STK_MSGOWNER AA INNER JOIN TN_STK_MSG BB ON AA.G_C1 = BB.G_C1 WHERE BB.C_C17=1 AND BB.N_C7=0 AND BB.N_C8=%d AND BB.S_C10='' GROUP BY AA.S_C2 ORDER BY AA.S_C3 ASC"), MANAGER_FOLDER_BOX_OUT);
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strLogin = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
if ( mapUser.Lookup(strLogin,strName))
|
{
|
continue;
|
}
|
mapUser.SetAt(strLogin,strLogin);
|
itemObj.strID = strLogin;
|
if ( strName.IsEmpty() )
|
itemObj.strName = strLogin;
|
else
|
itemObj.strName = strName;
|
arAMObject.Add(itemObj);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetReceivePerson - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return true;
|
}
|
/******************************************
|
Ãû³Æ£º
|
»ñÈ¡¸øµ±Ç°Óû§·¢Ë͹ý¸½¼þµÄÓû§
|
|
²ÎÊý£º
|
|
|
·µ»ØÖµ£º
|
false - ×°ÔØÊ§°Ü true - ×°ÔØ³É¹¦
|
******************************************/
|
bool CMBAMDBConnect::GetSendAttachPerson(CArrayAMObject &arAMObject)
|
{
|
CString strSQL, strValue, strLogin, strName;
|
CDBRecord ARecordset;
|
CMapStringToString mapUser;
|
stAMObject itemObj;
|
arAMObject.RemoveAll();
|
strSQL.Format( _T("SELECT DISTINCT S_C4 AS SLOGIN, S_C5 AS SNAME FROM TN_STK_MSG WHERE N_C12>0 ORDER BY S_C5 ASC"));
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strLogin = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
if ( mapUser.Lookup(strLogin,strName))
|
{
|
continue;
|
}
|
mapUser.SetAt(strLogin,strLogin);
|
itemObj.strID = strLogin;
|
if ( strName.IsEmpty() )
|
itemObj.strName = strLogin;
|
else
|
itemObj.strName = strName;
|
arAMObject.Add(itemObj);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetSendAttachPerson - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return true;
|
}
|
|
/******************************************
|
Ãû³Æ£º
|
»ñȡȺ
|
|
²ÎÊý£º
|
|
|
·µ»ØÖµ£º
|
false - ×°ÔØÊ§°Ü true - ×°ÔØ³É¹¦
|
******************************************/
|
bool CMBAMDBConnect::GetCrowds(CArrayAMObject &arAMObject)
|
{
|
CString strSQL, strValue, strLogin, strName;
|
CDBRecord ARecordset;
|
CMapStringToString mapUser;
|
stAMObject itemObj;
|
arAMObject.RemoveAll();
|
strSQL.Format( _T("SELECT G_C2, S_C3 FROM TN_STK_CROWDMSG GROUP BY G_C2 ORDER BY S_C3 ASC") );
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue, true );
|
strLogin = strValue;
|
ARecordset.GetValue( 2, strValue, true );
|
strName = strValue;
|
if ( mapUser.Lookup(strLogin,strName))
|
{
|
continue;
|
}
|
mapUser.SetAt(strLogin,strLogin);
|
itemObj.strID = strLogin;
|
if ( strName.IsEmpty() )
|
itemObj.strName = strLogin;
|
else
|
itemObj.strName = strName;
|
arAMObject.Add(itemObj);
|
}
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("GetSendAttachPerson - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return true;
|
}
|
|
BOOL CMBAMDBConnect::LoadPropStringValue( CString strPropClass,CString strPropName, int &nPropVer,CString &strPropValue)
|
{
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strName;
|
CString strValue = _T("");
|
CDBRecord ARecordset;
|
CString strSQL;
|
|
if(strPropClass.IsEmpty() || strPropName.IsEmpty())
|
return FALSE;
|
nPropVer = 0;
|
strPropValue = _T("");
|
strSQL.Format( _T("SELECT N_C3, S_C4 FROM TN_STK_USEREXTPROPERTY WHERE S_C1 ='%s' AND S_C2= '%s'"), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nPropVer );
|
ARecordset.GetValue( 2, strValue );
|
strPropValue = strValue;
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadPropStringValue - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::UpdatePropStringValue( CString strPropClass,CString strPropName, int nPropVer,CString strPropValue)
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL, strWhere;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
int nCount = 0;
|
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ));
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while (S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nCount );
|
break;
|
}
|
if(nCount > 0 )
|
{
|
strSQL.Format( _T("UPDATE TN_STK_USEREXTPROPERTY SET N_C3 = %d,S_C4 = '%s' WHERE S_C1='%s' AND S_C2='%s'"),
|
nPropVer,CMBAMDBFun::GetDBReplaceStr( strPropValue ),CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ) );
|
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_USEREXTPROPERTY(S_C1 , S_C2 , N_C3 , S_C4) VALUES ( '%s', '%s', %d, '%s')"),
|
CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ), nPropVer, CMBAMDBFun::GetDBReplaceStr( strPropValue ));
|
}
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,&m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo.Format(_T("UpdatePropStringValue(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
BOOL CMBAMDBConnect::RemovePropStringValue( CString strPropClass,CString strPropName)
|
{
|
if ( strPropClass.IsEmpty() || strPropName.IsEmpty() )
|
return FALSE;
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strSQL, strWhere;
|
CDBRecord ARecordset;
|
BOOL bReturn = true;
|
int nCount = 0;
|
|
strSQL.Format( _T("DELETE FROM TN_STK_USEREXTPROPERTY WHERE S_C1='%s' AND S_C2='%s'"), CMBAMDBFun::GetDBReplaceStr( strPropClass ),CMBAMDBFun::GetDBReplaceStr( strPropName ) );
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,&m_AConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo.Format(_T("RemovePropStringValue(%s) - %s"),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
BOOL CMBAMDBConnect::LoadUsersPropValue(CString strClass, CMapStringToString &mapPropValue)
|
{
|
//CSingleLock lock( &m_csConnectDB, true );
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strName;
|
CString strValue = _T("");
|
CDBRecord ARecordset;
|
CString strSQL;
|
|
mapPropValue.RemoveAll();
|
strSQL.Format( _T("SELECT S_C2, S_C4 FROM TN_STK_USEREXTPROPERTY WHERE S_C1 ='%s'"), strClass );
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue );
|
strName = strValue;
|
ARecordset.GetValue( 2, strValue );
|
mapPropValue.SetAt(strName, strValue);
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadUsersPropValue - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
}
|
return TRUE;
|
}
|
|
CString CMBAMDBConnect::GetOldestMsg()
|
{
|
CString strDate = _T("");
|
CString strSQL;
|
if ( !m_bOpenDB )
|
return strDate;
|
strSQL.Format(_T("SELECT T_C6 FROM TN_STK_MSG ORDER BY T_C6 ASC LIMIT 0,1 "));
|
CString strTempValue;
|
CDBRecord ARecordset;
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strTempValue );
|
strDate = strTempValue ;
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
CString strErrInfo;
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
strErrInfo = _T("GetOldestMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return strDate;
|
}
|
return strDate;
|
}
|
CString CMBAMDBConnect::GetUpToDateMsg()
|
{
|
CString strDate = _T("");
|
CString strSQL;
|
if ( !m_bOpenDB )
|
return strDate;
|
strSQL.Format(_T("SELECT T_C6 FROM TN_STK_MSG ORDER BY T_C6 DESC LIMIT 0,1 "));
|
CString strTempValue;
|
CDBRecord ARecordset;
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strTempValue );
|
strDate = strTempValue ;
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
CString strErrInfo;
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
strErrInfo = _T("GetUpToDateMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return strDate;
|
}
|
return strDate;
|
}
|
BOOL CMBAMDBConnect::GetMsgDataCount(long &nMsgCount,long &nRelatedCount)
|
{
|
nMsgCount = 0;
|
nRelatedCount = 0;
|
CString strSQL;
|
if ( !m_bOpenDB )
|
return FALSE;
|
strSQL.Format(_T(" SELECT COUNT(*) FROM TN_STK_MSG"));
|
long nTempValue = 0;
|
CDBRecord ARecordset;
|
try
|
{
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nTempValue );
|
nMsgCount += nTempValue ;
|
break;
|
}
|
ARecordset.Close();
|
strSQL.Format(_T("SELECT COUNT(*) FROM TN_STK_CROWDMSG"));
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nTempValue );
|
nMsgCount += nTempValue ;
|
break;
|
}
|
ARecordset.Close();
|
strSQL.Format(_T("SELECT COUNT(*) FROM TN_STK_MSGOWNER"));
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nTempValue );
|
nRelatedCount += nTempValue ;
|
break;
|
}
|
ARecordset.Close();
|
strSQL.Format(_T("SELECT COUNT(*) FROM TN_STK_ATTACHMENT"));
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nTempValue );
|
nRelatedCount += nTempValue ;
|
break;
|
}
|
ARecordset.Close();
|
strSQL.Format(_T("SELECT COUNT(*) FROM TN_STK_MSGPROPERTY"));
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nTempValue );
|
nRelatedCount += nTempValue ;
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
CString strErrInfo;
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
strErrInfo = _T("GetMsgDataCount - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::CleanDateBeforeMsg(CString strDate)
|
{
|
CString strMsgSQL;
|
CString strAttachSQL;
|
CString strOwnerSQL;
|
CString strPropertySQL;
|
CString strCrowdMsgSQL;
|
if ( !m_bOpenDB )
|
return FALSE;
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE T_C6 <='%s' "),strDate );
|
strAttachSQL.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE T_C6 <='%s') "), strDate );
|
strOwnerSQL.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE T_C6 <='%s' ) "), strDate );
|
strPropertySQL.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE T_C6 <='%s' ) "), strDate );
|
strCrowdMsgSQL.Format( _T("DELETE FROM TN_STK_CROWDMSG WHERE T_C6 <='%s' "),strDate );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL( strAttachSQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strOwnerSQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strPropertySQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strMsgSQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strCrowdMsgSQL, &m_AConnect );
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
CString strErrInfo;
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
strErrInfo = _T("CleanDateBeforeMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::CleanDateAfterMsg(CString strDate)
|
{
|
CString strMsgSQL;
|
CString strAttachSQL;
|
CString strOwnerSQL;
|
CString strPropertySQL;
|
CString strCrowdMsgSQL;
|
if ( !m_bOpenDB )
|
return FALSE;
|
strMsgSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE T_C6 >'%s' "),strDate );
|
strAttachSQL.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE T_C6 >'%s') "), strDate );
|
strOwnerSQL.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE T_C6 >'%s' ) "), strDate );
|
strPropertySQL.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( SELECT G_C1 FROM TN_STK_MSG WHERE T_C6 >'%s' ) "), strDate );
|
strCrowdMsgSQL.Format( _T("DELETE FROM TN_STK_CROWDMSG WHERE T_C6 >'%s' "),strDate );
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL( strAttachSQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strOwnerSQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strPropertySQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strMsgSQL, &m_AConnect );
|
CDBSQLiteCommFun::RunSQL( strCrowdMsgSQL, &m_AConnect );
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
CString strErrInfo;
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
strErrInfo = _T("CleanDateAfterMsg - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
|
BOOL CMBAMDBConnect::CleanAMExtraData()
|
{
|
CString strSQL;
|
if ( !m_bOpenDB )
|
return FALSE;
|
try
|
{
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
strSQL = _T("DELETE FROM TN_STK_LASTCONTACT ") ;
|
CDBSQLiteCommFun::RunSQL( strSQL, &m_AConnect );
|
strSQL = _T("DELETE FROM TN_STK_SYSMSG ") ;
|
CDBSQLiteCommFun::RunSQL( strSQL, &m_AConnect );
|
strSQL = _T("DELETE FROM TN_STK_USEREXTPROPERTY ") ;
|
CDBSQLiteCommFun::RunSQL( strSQL, &m_AConnect );
|
strSQL = _T("DELETE FROM TN_STK_UNREADMSG ") ;
|
CDBSQLiteCommFun::RunSQL( strSQL, &m_AConnect );
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
CString strErrInfo;
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
strErrInfo = _T("CleanAMExtraData - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
BOOL CMBAMDBConnect::DeleteMsgFromDB( CString strMsgID)
|
{
|
CString strSQL;
|
CString strSQL2;
|
CString strSQL3;
|
CString strSQL4;
|
CString strSQL5;
|
BOOL bReturn = true;
|
int nCount = 0;
|
if ( !m_bOpenDB )
|
return FALSE;
|
if(strMsgID.IsEmpty())
|
return FALSE;
|
try
|
{
|
strSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE G_C1='%s'"),strMsgID);
|
strSQL2.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1='%s'"),strMsgID);
|
strSQL3.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1='%s'"),strMsgID);
|
strSQL4.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1='%s'"),strMsgID);
|
strSQL5.Format( _T("DELETE FROM TN_STK_UNREADMSG WHERE G_C1='%s'"),strMsgID);
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
CDBSQLiteCommFun::RunSQL(strSQL2, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strSQL3, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strSQL4, &m_AConnect);
|
CDBSQLiteCommFun::RunSQL(strSQL5, &m_AConnect);
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("DeleteMsgFromDB - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
|
//==============================================
|
// ɾ³ýÊղؼÐ
|
//==============================================
|
BOOL CMBAMDBConnect::DeleteFolder(long nFolderID,int nMoveMsg)
|
{
|
if(nFolderID < FOLDERID_BASE)
|
return FALSE;
|
CString strFolderSQL;
|
CString strSQL;
|
CString strSQL2;
|
CString strSQL3;
|
CString strSQL4;
|
CString strSQL5;
|
CString strSelectSQL;
|
BOOL bReturn = true;
|
int nCount = 0;
|
CString strSubFonderSQL = _T("");
|
CString strWhereSQL= _T("");
|
CString strMsgWhereSQL= _T("");
|
if ( !m_bOpenDB )
|
return FALSE;
|
try
|
{
|
|
strSQL.Format(_T("SELECT N_C1 FROM TN_STK_MSGFOLDER WHERE N_C3 = %d "),nFolderID);
|
CString strTempValue;
|
CDBRecord ARecordset;
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strTempValue );
|
strFolderSQL.Format(_T("%s,"),strTempValue);
|
strSubFonderSQL +=strFolderSQL;
|
}
|
if(strSubFonderSQL.IsEmpty())
|
{
|
strMsgWhereSQL.Format( _T(" N_C8=%d "), nFolderID );
|
strWhereSQL.Format( _T(" N_C1=%d "), nFolderID );
|
}
|
else
|
{
|
strMsgWhereSQL.Format( _T(" N_C8 IN(%s%d)"), strSubFonderSQL,nFolderID );
|
strWhereSQL.Format( _T(" N_C1 IN(%s%d)"), strSubFonderSQL,nFolderID );
|
}
|
strFolderSQL.Format(_T("DELETE FROM TN_STK_MSGFOLDER WHERE %s"),strWhereSQL );
|
if(nMoveMsg == 0) //ÏûÏ¢ÒÆ»ØÔÀ´·¢¼þÏä»òÊÕ¼þÏä
|
{
|
strSQL.Format( _T("UPDATE TN_STK_MSG SET N_C8 = %d WHERE %s AND S_C4='%s'"),MANAGER_FOLDER_BOX_OUT, strMsgWhereSQL,m_strLogin );
|
strSQL2.Format( _T("UPDATE TN_STK_MSG SET N_C8 = %d WHERE %s AND S_C4<>'%s'"),MANAGER_FOLDER_BOX_IN, strMsgWhereSQL,m_strLogin );
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
bReturn |=CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
bReturn |=CDBSQLiteCommFun::RunSQL(strSQL2, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
}
|
else if(nMoveMsg == 1) //ɾ³ýÕâЩÏûÏ¢
|
{
|
strSelectSQL.Format( _T("SELECT G_C1 FROM TN_STK_MSG Where %s "),strMsgWhereSQL );
|
strSQL.Format( _T("DELETE FROM TN_STK_MSG WHERE Where %s "),strMsgWhereSQL );
|
strSQL2.Format( _T("DELETE FROM TN_STK_ATTACHMENT WHERE G_C1 IN ( %s) "), strSelectSQL );
|
strSQL3.Format( _T("DELETE FROM TN_STK_MSGOWNER WHERE G_C1 IN ( %s) "), strSelectSQL );
|
strSQL4.Format( _T("DELETE FROM TN_STK_MSGPROPERTY WHERE G_C1 IN ( %s) "), strSelectSQL );
|
strSQL5.Format( _T("DELETE FROM TN_STK_UNREADMSG WHERE G_C1 IN ( %s) "), strSelectSQL );
|
m_AConnect.StartTransaction(); // Æô¶¯ÊÂÎñ
|
bReturn |=CDBSQLiteCommFun::RunSQL(strSQL2, &m_AConnect);
|
bReturn |=CDBSQLiteCommFun::RunSQL(strSQL3, &m_AConnect);
|
bReturn |=CDBSQLiteCommFun::RunSQL(strSQL4, &m_AConnect);
|
bReturn |=CDBSQLiteCommFun::RunSQL(strSQL5, &m_AConnect);
|
bReturn |= CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
m_AConnect.Commit(); // Ìá½»ÊÂÎñ
|
bReturn |= CDBSQLiteCommFun::RunSQL(strSQL, &m_AConnect);
|
}
|
bReturn |= CDBSQLiteCommFun::RunSQL(strFolderSQL, &m_AConnect);
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("DeleteFolder - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return TRUE;
|
}
|
//==============================================
|
// ×°ÔØÖ¸¶¨ÀàÐÍÁªÏµÈ˵ÄÏûÏ¢ÏÔʾȨÏÞ
|
//==============================================
|
BOOL CMBAMDBConnect::LoadContactMsgRight( CString strClass, CMapStringToInt &mapMsgRight)
|
{
|
if ( !m_bOpenDB )
|
return FALSE;
|
CString strName;
|
CString strValue = _T("");
|
CDBRecord ARecordset;
|
CString strSQL;
|
int nRight;
|
|
mapMsgRight.RemoveAll();
|
strSQL.Format( _T("SELECT S_C2, S_C4 FROM TN_STK_USEREXTPROPERTY WHERE S_C1 ='%s' AND S_C4 <> '0'"), strClass );
|
try
|
{
|
|
ARecordset.Open( &m_AConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, strValue );
|
strName = strValue;
|
ARecordset.GetValue( 2, strValue );
|
nRight = _tstol(strValue);
|
if(nRight > 0)
|
mapMsgRight.SetAt(strName, nRight);
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("LoadUserMsgRight - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
}
|
return TRUE;
|
}
|