// CrowdMsgRowSet.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbamdb.h"
|
#include "CrowdMsgRowSet.h"
|
|
|
// CCrowdMsgRowSet
|
|
CCrowdMsgRowSet::CCrowdMsgRowSet()
|
{
|
m_pDBConnect = NULL;
|
m_pMsgs = NULL;
|
m_nType = ROWTYPE_NONE;
|
}
|
|
CCrowdMsgRowSet::~CCrowdMsgRowSet()
|
{
|
CleanDataSet( );
|
}
|
|
|
// CCrowdMsgRowSet member functions
|
void CCrowdMsgRowSet::operator = ( const CCrowdMsgRowSet &Item )
|
{
|
m_strStartDate = Item.m_strStartDate;
|
m_strEndDate = Item.m_strEndDate;
|
m_pDBConnect = Item.m_pDBConnect;
|
m_pMsgs = Item.m_pMsgs;
|
m_nType = Item.m_nType;
|
}
|
|
void CCrowdMsgRowSet::CleanDataSet( )
|
{
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
if(m_pMsgs)
|
delete m_pMsgs;
|
m_pMsgs = NULL;
|
break;
|
default:
|
break;
|
}
|
|
m_nType = ROWTYPE_NONE;
|
}
|
|
bool CCrowdMsgRowSet::SetDBConnect( CMBAMDBConnect *pDBConnect )
|
{
|
m_pDBConnect = pDBConnect;
|
|
return true;
|
}
|
bool CCrowdMsgRowSet::ListCrowdMsg2( CString strCrowdID, long nLimitCount, long &nCount, BOOL bTimeAsc/* = FALSE */ )
|
{
|
nCount = 0;
|
if ( strCrowdID.IsEmpty() )
|
return false;
|
if ( !m_pDBConnect || !m_pDBConnect->IsOpenDB() )
|
return false;
|
CleanDataSet();
|
|
m_pDBConnect->AddRef();
|
m_pMsgs = new CCrowdMsgs( m_pDBConnect );
|
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
if ( !m_strStartDate.IsEmpty() && tmHigh.ParseDateTime( m_strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmStartDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
if ( !m_strEndDate.IsEmpty() && tmHigh.ParseDateTime( m_strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmEndDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
|
int nMsgCount(0);
|
nMsgCount = m_pMsgs->ListCrowdAll2( strCrowdID,nLimitCount, bTimeAsc);
|
if ( nMsgCount <= 0 )
|
{
|
delete m_pMsgs;
|
m_pMsgs = NULL;
|
return true;
|
}
|
|
m_pMsgs->GetData( );
|
m_nType = ROWTYPE_CROWDMSG;
|
nCount = nMsgCount;
|
return true;
|
}
|
bool CCrowdMsgRowSet::ListCrowdMsg( CString strCrowdID, long &nCount, BOOL bTimeAsc/* = FALSE */ )
|
{
|
nCount = 0;
|
if ( strCrowdID.IsEmpty() )
|
return false;
|
if ( !m_pDBConnect || !m_pDBConnect->IsOpenDB() )
|
return false;
|
CleanDataSet();
|
|
m_pDBConnect->AddRef();
|
m_pMsgs = new CCrowdMsgs( m_pDBConnect );
|
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
if ( !m_strStartDate.IsEmpty() && tmHigh.ParseDateTime( m_strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmStartDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
if ( !m_strEndDate.IsEmpty() && tmHigh.ParseDateTime( m_strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmEndDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
|
int nMsgCount(0);
|
nMsgCount = m_pMsgs->ListCrowdAll( strCrowdID, bTimeAsc);
|
if ( nMsgCount <= 0 )
|
{
|
delete m_pMsgs;
|
m_pMsgs = NULL;
|
return true;
|
}
|
|
m_pMsgs->GetData( );
|
m_nType = ROWTYPE_CROWDMSG;
|
nCount = nMsgCount;
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::SetMsgFilterDate( CString strStartDate, CString strEndDate )
|
{
|
m_strStartDate = strStartDate;
|
m_strEndDate = strEndDate;
|
|
return true;
|
}
|
bool CCrowdMsgRowSet::Top( )
|
{
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
if ( !m_pMsgs->MoveFirst() )
|
return false;
|
break;
|
default:
|
return false;
|
break;
|
}
|
return true;
|
}
|
|
|
bool CCrowdMsgRowSet::Prev()
|
{
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
if ( !m_pMsgs->MovePrev() )
|
return false;
|
break;
|
default:
|
return false;
|
break;
|
}
|
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::Next( )
|
{
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
if ( !m_pMsgs->MoveNext() )
|
return false;
|
break;
|
default:
|
return false;
|
break;
|
}
|
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::MoveTo( long nPos )
|
{
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
if ( !m_pMsgs->MoveTo( nPos ) )
|
return false;
|
break;
|
|
default:
|
return false;
|
break;
|
}
|
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::GetRow( CCrowdMsgRow *pCrowdRow )
|
{
|
if ( !pCrowdRow )
|
return false;
|
pCrowdRow->m_pCursor = m_pMsgs;
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::GetItemValue( CString strItemName, VARIANT &vData )
|
{
|
vData.vt = VT_EMPTY;
|
|
CString strName = strItemName;
|
if ( strName.IsEmpty() )
|
return false;
|
|
COleVariant oleData;
|
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
{
|
if ( !m_pMsgs )
|
return false;
|
|
m_pMsgs->GetData( );
|
if ( !((*m_pMsgs).GetItemValue( strName, oleData )) )
|
return false;
|
}
|
break;
|
default:
|
return false;
|
break;
|
}
|
|
vData = oleData;
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::GetItemValueStr( CString strItemName, CString &strData )
|
{
|
CString strValue = _T( "" );
|
CString strName = strItemName;
|
if ( strName.IsEmpty() )
|
return false;
|
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
{
|
if ( !m_pMsgs )
|
return false;
|
|
m_pMsgs->GetData( );
|
if ( !((*m_pMsgs).GetItemValue( strName, strValue )) )
|
return false;
|
}
|
break;
|
default:
|
return false;
|
break;
|
}
|
|
strData = strValue;
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::ListSearchCrowdMsg( CString strCrowdID, CString strKey, long &nCount, BOOL bTimeAsc/* = FALSE */ )
|
{
|
nCount = 0;
|
if ( strCrowdID.IsEmpty() )
|
return false;
|
if ( !m_pDBConnect || !m_pDBConnect->IsOpenDB() )
|
return false;
|
CleanDataSet();
|
|
m_pDBConnect->AddRef();
|
m_pMsgs = new CCrowdMsgs( m_pDBConnect );
|
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
if ( !m_strStartDate.IsEmpty() && tmHigh.ParseDateTime( m_strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmStartDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
if ( !m_strEndDate.IsEmpty() && tmHigh.ParseDateTime( m_strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmEndDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
|
int nMsgCount(0);
|
nMsgCount = m_pMsgs->ListSearchCrowdAll( strCrowdID,strKey, bTimeAsc);
|
if ( nMsgCount <= 0 )
|
{
|
delete m_pMsgs;
|
m_pMsgs = NULL;
|
return true;
|
}
|
m_pMsgs->GetData( );
|
m_nType = ROWTYPE_CROWDMSG;
|
nCount = nMsgCount;
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::ListRecordCount( long &nCount )
|
{
|
nCount = 0;
|
switch ( m_nType )
|
{
|
case ROWTYPE_CROWDMSG:
|
if ( m_pMsgs )
|
nCount = m_pMsgs->ListRecordCount();
|
break;
|
default:
|
return false;
|
break;
|
}
|
|
return true;
|
}
|
|
bool CCrowdMsgRowSet::ListSearchCrowdMsgBox( CString strCrowdID, CString strKey, long &nCount, BOOL bTimeAsc/* = FALSE */ )
|
{
|
nCount = 0;
|
if ( strCrowdID.IsEmpty() )
|
return false;
|
if ( !m_pDBConnect || !m_pDBConnect->IsOpenDB() )
|
return false;
|
CleanDataSet();
|
|
m_pDBConnect->AddRef();
|
m_pMsgs = new CCrowdMsgs( m_pDBConnect );
|
|
CHighTime tmHigh;
|
SYSTEMTIME tmSystem;
|
// Set Filter
|
if ( !m_strStartDate.IsEmpty() && tmHigh.ParseDateTime( m_strStartDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmStartDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
if ( !m_strEndDate.IsEmpty() && tmHigh.ParseDateTime( m_strEndDate ) )
|
{
|
tmHigh.GetAsSystemTime( tmSystem );
|
if ( tmSystem.wSecond < 0 )
|
tmSystem.wSecond = 0;
|
|
m_pMsgs->m_tmEndDate = COleDateTime( tmSystem.wYear, tmSystem.wMonth, tmSystem.wDay,
|
tmSystem.wHour, tmSystem.wMinute, tmSystem.wSecond );
|
}
|
|
int nMsgCount(0);
|
nMsgCount = m_pMsgs->ListSearchCrowdMsgBox( strCrowdID,strKey, bTimeAsc);
|
if ( nMsgCount <= 0 )
|
{
|
delete m_pMsgs;
|
m_pMsgs = NULL;
|
return true;
|
}
|
m_pMsgs->GetData( );
|
m_nType = ROWTYPE_CROWDMSG;
|
nCount = nMsgCount;
|
return true;
|
}
|