// MsgFolder.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbamdb.h"
|
#include "MsgFolder.h"
|
#include "MBAMDBFun.h"
|
|
|
extern CCriticalSection m_csConnectDB;
|
|
CMsgFolderItem::CMsgFolderItem()
|
{
|
m_nRowType = ROWTYPE_MSGFOLDER;
|
Clear();
|
}
|
|
CMsgFolderItem::~CMsgFolderItem()
|
{
|
|
}
|
|
void CMsgFolderItem::Clear()
|
{
|
m_nID = 0;
|
m_strName = _T("");
|
m_nParentID = 0;
|
}
|
|
BOOL CMsgFolderItem::GetItemValue( CString strName, COleVariant &varData )
|
{
|
varData.Clear();
|
if ( strName.IsEmpty() )
|
return false;
|
|
if ( strName.CompareNoCase( _T( "ID" ) ) == 0 )
|
varData = (long)m_nID;
|
else if ( strName.CompareNoCase( _T( "Name" ) ) == 0 )
|
varData = m_strName;
|
else if ( strName.CompareNoCase( _T( "ParentID" ) ) == 0 )
|
varData = (long)m_nParentID;
|
else
|
return false;
|
return true;
|
}
|
|
BOOL CMsgFolderItem::InsertRecord( CDBConnect *pAConnect)
|
{
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("INSERT INTO TN_STK_MSGFOLDER( N_C1, S_C2, N_C3 ) VALUES ( \
|
%d, '%s', %d)"), m_nID, CMBAMDBFun::GetDBReplaceStr( m_strName ), m_nParentID );
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("InsertRecord - MsgFolder- ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
BOOL CMsgFolderItem::UpdateRecord( CDBConnect *pAConnect )
|
{
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("UPDATE TN_STK_MSGFOLDER SET S_C2 = '%s', N_C3 = %d WHERE N_C1 = %d"),
|
CMBAMDBFun::GetDBReplaceStr( m_strName ), m_nParentID, m_nID );
|
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format( _T("UpdateRecord(%s) - MsgFolder - %s "),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
|
// CMsgFolder
|
|
CMsgFolders::CMsgFolders(CMBAMDBConnect *pAConnect)
|
{
|
m_pAConnect = pAConnect;
|
}
|
|
CMsgFolders::~CMsgFolders()
|
{
|
}
|
|
|
// CMsgFolder member functions
|
void CMsgFolders::operator =( const CMsgFolders& item )
|
{
|
// m_ARecordSet = item.m_ARecordSet;
|
m_pAConnect = item.m_pAConnect;
|
m_strSQL = item.m_strSQL;
|
m_nRowType = item.m_nRowType;
|
|
m_nID = item.m_nID;
|
m_strName = item.m_strName;
|
m_nParentID = item.m_nParentID;
|
m_pAConnect = item.m_pAConnect;
|
}
|
|
int CMsgFolders::ListFolder( long nParentFolderID )
|
{
|
CString strSQL;
|
int nCount;
|
if(nParentFolderID < 0)
|
strSQL.Format( _T("SELECT N_C1, S_C2, N_C3 FROM TN_STK_MSGFOLDER ORDER BY S_C2") );
|
else
|
strSQL.Format( _T("SELECT N_C1, S_C2, N_C3 FROM TN_STK_MSGFOLDER WHERE N_C3 = %d ORDER BY S_C2"), nParentFolderID );
|
m_strSQL = strSQL;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
m_ARecordSet.Open( m_pAConnect->GetDBConnect() ,strSQL );
|
m_ARecordSet.MoveFirst();
|
nCount = m_ARecordSet.GetRecordCount( );
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
|
return 0;
|
}
|
|
return nCount;
|
}
|
|
int CMsgFolders::ListSpFolder( long nFolderID )
|
{
|
//if ( nFolderID <= 0 )
|
// return 0;
|
|
CString strSQL;
|
int nCount;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
|
strSQL.Format( _T("SELECT N_C1, S_C2, N_C3 FROM TN_STK_MSGFOLDER WHERE N_C1 = %d"), nFolderID );
|
m_strSQL = strSQL;
|
|
try
|
{
|
m_ARecordSet.Close();
|
m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
|
m_ARecordSet.MoveFirst();
|
nCount = m_ARecordSet.GetRecordCount( );
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return 0;
|
}
|
|
return nCount;
|
}
|
|
int CMsgFolders::ListSpFolder( long nParentFolderID, LPCTSTR lpszFolderName )
|
{
|
if ( nParentFolderID < 0 || lpszFolderName == NULL )
|
return 0;
|
|
CString strSQL;
|
int nCount;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
strSQL.Format( _T("SELECT N_C1, S_C2, N_C3 FROM TN_STK_MSGFOLDER WHERE N_C3 = %d \
|
AND S_C2 = '%s'"), nParentFolderID, lpszFolderName );
|
m_strSQL = strSQL;
|
|
try
|
{
|
m_ARecordSet.Close();
|
m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
|
m_ARecordSet.MoveFirst();
|
nCount = m_ARecordSet.GetRecordCount( );
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return 0;
|
}
|
|
return nCount;
|
}
|
|
bool CMsgFolders::GetData( )
|
{
|
CString strTempValue;
|
|
try
|
{
|
m_ARecordSet.GetValue( 1, m_nID );
|
|
m_ARecordSet.GetValue( 2, strTempValue, true );
|
m_strName = (LPCTSTR)strTempValue;
|
|
m_ARecordSet.GetValue( 3, m_nParentID );
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return false;
|
}
|
|
return true;
|
}
|
|
long CMsgFolders::GetMaxFolderID( )
|
{
|
long nMax = 0;
|
int nData = 0;
|
CString strSQL;
|
CDBRecord ARecordset;
|
|
strSQL = _T("SELECT N_C1 FROM TN_STK_MSGFOLDER ORDER BY N_C1 DESC limit 0, 1");
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
ARecordset.Close();
|
ARecordset.Open( m_pAConnect->GetDBConnect(), strSQL );
|
if ( S_OK == ARecordset.MoveNext() )
|
ARecordset.GetValue( 1, nData );
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return 0;
|
}
|
nMax = nData;
|
|
return nMax;
|
}
|
void CMsgFolders::AddFloder( CMsgFolderItem *pItem )
|
{
|
if( !pItem )
|
return;
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return;
|
{
|
pItem->InsertRecord(m_pAConnect->GetDBConnect());
|
}
|
|
}
|
long CMsgFolders::ListRecordCount( )
|
{
|
return m_ARecordSet.GetRecordCount();
|
}
|