// CrowdMsgItem.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbamdb.h"
|
#include "CrowdMsg.h"
|
#include "MBAMDBFun.h"
|
#include "PerfTimer.h"
|
|
|
#define LISTMSG_TYPE_NONE ( 0 ) // ĬÈÏÏÔʾµÄÏûÏ¢
|
#define LISTMSG_TYPE_MAGADMIN ( 3 ) // ÁгöÏûÏ¢ID
|
|
|
// CCrowdMsgItem
|
extern CCriticalSection m_csConnectDB;
|
CCrowdMsgItem::CCrowdMsgItem()
|
{
|
m_nRowType = ROWTYPE_CROWDMSG;
|
Clear();
|
}
|
|
CCrowdMsgItem::~CCrowdMsgItem()
|
{
|
}
|
|
|
// CCrowdMsgItem member functions
|
void CCrowdMsgItem::Clear()
|
{
|
m_strID = GUID_EMPTY;
|
m_strSender = _T("");
|
m_strSenderName = _T("");
|
m_strCrowdID = _T("");
|
m_strCrowdName = _T("");
|
m_tmDate = COleDateTime::GetCurrentTime( );
|
m_nMsgFlag = 0;
|
m_nReadState = 0;
|
m_strContentType = _T("");
|
m_strContent = _T("");
|
m_nContentSize = 0;
|
m_strContentText = _T("");
|
}
|
|
BOOL CCrowdMsgItem::GetItemValue( CString strName, COleVariant &varData )
|
{
|
varData.Clear();
|
if ( strName.IsEmpty() )
|
return false;
|
|
if ( strName.CompareNoCase( _T( "ID" ) ) == 0 )
|
varData = m_strID;
|
else if ( strName.CompareNoCase( _T("CrowdID") ) == 0 )
|
varData = m_strCrowdID;
|
else if ( strName.CompareNoCase( _T("CrowdName") ) == 0 )
|
varData = m_strCrowdName;
|
else if ( strName.CompareNoCase( _T( "Sender" ) ) == 0 )
|
varData = m_strSender;
|
else if ( strName.CompareNoCase( _T( "SenderName" ) ) == 0 )
|
varData = m_strSenderName;
|
else if ( strName.CompareNoCase( _T( "SendDate" ) ) == 0 )
|
{
|
if( !( m_tmDate.GetStatus() == COleDateTime::valid ) )
|
{
|
COleDateTime temptime(2000,1,1, 0, 0, 0);
|
m_tmDate = temptime;
|
}
|
|
COleDateTime oleDate( m_tmDate.GetYear(), m_tmDate.GetMonth(), m_tmDate.GetDay(), m_tmDate.GetHour(),
|
m_tmDate.GetMinute(), m_tmDate.GetSecond() );
|
varData = oleDate;
|
}
|
else if ( strName.CompareNoCase( _T( "ReadState" ) ) == 0 )
|
varData = m_nReadState;
|
else if ( strName.CompareNoCase( _T( "MsgFlag" ) ) == 0 )
|
varData = m_nMsgFlag;
|
else if ( strName.CompareNoCase( _T( "SenderName" ) ) == 0 )
|
varData = m_strSenderName;
|
if ( strName.CompareNoCase( _T( "ContentType" ) ) == 0 )
|
varData = m_strContentType;
|
else if ( strName.CompareNoCase( _T( "ContentSize" ) ) == 0 )
|
varData = (long)m_nContentSize;
|
else if ( strName.CompareNoCase( _T( "Content" ) ) == 0 )
|
varData = m_strContent;
|
else
|
return false;
|
|
return true;
|
}
|
|
BOOL CCrowdMsgItem::InsertRecord( CDBConnect *pAConnect)
|
{
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("INSERT INTO TN_STK_CROWDMSG(G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 ) VALUES ( \
|
'%s', '%s', '%s', '%s', '%s','%s', %d, %d,'%s', %d,'%s','%s' )"),
|
m_strID, m_strCrowdID,m_strCrowdName, CMBAMDBFun::GetDBReplaceStr( m_strSender ),
|
CMBAMDBFun::GetDBReplaceStr( m_strSenderName ), CMBAMDBFun::FormatDBTIMEToStr( m_tmDate ),
|
m_nReadState, m_nMsgFlag, CMBAMDBFun::GetDBReplaceStr( m_strContentType), m_nContentSize ,
|
CMBAMDBFun::GetDBReplaceStr( m_strContent ),CMBAMDBFun::GetDBReplaceStr( m_strContentText) );
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("InsertRecord - CrowdMsg- ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
BOOL CCrowdMsgItem::UpdateRecord( CDBConnect *pAConnect )
|
{
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("UPDATE TN_STK_CROWDMSG SET G_C2 = '%s' ,S_C3= '%s', S_C4 = '%s', S_C5 = '%s', T_C6 = '%s',\
|
N_C7 = %d, N_C8 =%d , S_C9 ='%s', N_C10 =%d, S_C11 ='%s',S_C12 ='%s' WHERE G_C1 = '%s'"),
|
m_strCrowdID,m_strCrowdName, CMBAMDBFun::GetDBReplaceStr( m_strSender ), CMBAMDBFun::GetDBReplaceStr( m_strSenderName ),
|
CMBAMDBFun::FormatDBTIMEToStr( m_tmDate ),m_nReadState, m_nMsgFlag, CMBAMDBFun::GetDBReplaceStr( m_strContentType ),
|
m_nContentSize,CMBAMDBFun::GetDBReplaceStr( m_strContent ),CMBAMDBFun::GetDBReplaceStr( m_strContentText ), m_strID );
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format( _T("UpdateRecord(%s) - CrowdMsg - %s "),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
|
CCrowdMsgs::CCrowdMsgs(CMBAMDBConnect *pAConnect)
|
{
|
m_pAConnect = pAConnect;
|
InitFilter();
|
|
}
|
|
CCrowdMsgs::~CCrowdMsgs()
|
{
|
|
}
|
void CCrowdMsgs::operator =( const CCrowdMsgs& item )
|
{
|
m_nListMsgType = item.m_nListMsgType;
|
m_tmStartDate = item.m_tmStartDate;
|
m_tmEndDate = item.m_tmEndDate;
|
m_nReaded = item.m_nReaded; // "-1"±íʾ²»Ö¸¶¨Õâ¸ö¹ýÂËÌõ¼þ
|
m_pAConnect = item.m_pAConnect;
|
m_strSQL = item.m_strSQL;
|
m_nRowType = item.m_nRowType;
|
m_strID = item.m_strID;
|
m_strCrowdID = item.m_strCrowdID;
|
m_strCrowdName = item.m_strCrowdName;
|
m_strSender = item.m_strSender;
|
m_strSenderName = item.m_strSenderName;
|
m_tmDate = item.m_tmDate;
|
m_nReadState = item.m_nReadState;
|
m_nMsgFlag = item.m_nMsgFlag;
|
m_strContentType = item.m_strContentType;
|
m_nContentSize = item.m_nContentSize;
|
m_strContent = item.m_strContent;
|
}
|
void CCrowdMsgs::InitFilter()
|
{
|
// ³õʼ»¯¹ýÂËÆ÷ʹȥ³ý¹ýÂË
|
m_tmStartDate = COleDateTime( 1970, 1, 1, 0, 0, 0 );
|
m_tmEndDate = COleDateTime( 1970, 1, 1, 0, 0, 0 );
|
m_nListMsgType = LISTMSG_TYPE_NONE;
|
m_nReaded = -1; // "-1"±íʾ²»Ö¸¶¨Õâ¸ö¹ýÂËÌõ¼þ
|
}
|
int CCrowdMsgs::ListUnreadMsg( )
|
{
|
CString strSQL;
|
int nCount;
|
// end modify
|
strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE N_C7 <= 1 ORDER BY T_C6 DESC") );
|
m_strSQL = strSQL; // 2: IOPEN , 1: InBox
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
nCount = ListRecordCount();
|
m_ARecordSet.Close();
|
m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
|
if(nCount >0)
|
m_ARecordSet.MoveFirst();
|
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo();
|
|
return 0;
|
}
|
|
if ( nCount > 0 )
|
GetData( );
|
|
return nCount;
|
}
|
void CCrowdMsgs::SetCrowdMsgReadState(CString strCrowdID )
|
{
|
CString strSQL;
|
// end modify
|
strSQL.Format(_T("UPDATE TN_STK_CROWDMSG SET N_C7=%d WHERE N_C7 <= 1 AND G_C2 ='%s'"), MSG_READSTATE_IOPEN,strCrowdID);
|
m_strSQL = strSQL; // 2: IOPEN , 1: InBox
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return;
|
try
|
{
|
CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,m_pAConnect->GetDBConnect());
|
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo();
|
|
return ;
|
}
|
return ;
|
}
|
|
int CCrowdMsgs::ListCrowdAll2(CString strCrowdID,long nLimitCount, BOOL bTimeAsc /*= FALSE*/ )
|
{ // ʹÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
|
CString strSQL;
|
int nCount = 0;
|
CString strStartDate;
|
CString strEndDate;
|
CString strSQLTempM;
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
|
{
|
if ( m_tmEndDate.GetYear() == 1970 )
|
m_tmEndDate = COleDateTime::GetCurrentTime( );
|
|
strStartDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
|
strEndDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
|
|
strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
|
}
|
CString strLimitSQL = _T("");
|
if(nLimitCount > 0)
|
strLimitSQL.Format( _T("limit 0,%d"), nLimitCount);
|
if( bTimeAsc)
|
strSQL.Format(_T("SELECT T.* FROM ( \
|
SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 DESC %s)T ORDER BY T.T_C6 ASC "), strCrowdID, strSQLTempM,strLimitSQL);
|
else
|
strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 DESC %s"), strCrowdID, strSQLTempM,strLimitSQL);
|
m_strSQL = strSQL;
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
nCount = ListRecordCount();
|
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 CCrowdMsgs::ListCrowdAll(CString strCrowdID, BOOL bTimeAsc /*= FALSE*/ )
|
{ // ʹÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
|
CString strSQL;
|
int nCount = 0;
|
CString strStartDate;
|
CString strEndDate;
|
CString strSQLTempM;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
|
{
|
if ( m_tmEndDate.GetYear() == 1970 )
|
m_tmEndDate = COleDateTime::GetCurrentTime( );
|
|
strStartDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
|
strEndDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
|
|
strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
|
}
|
if( bTimeAsc)
|
strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 ASC "), strCrowdID,strSQLTempM);
|
else
|
strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 DESC "), strCrowdID,strSQLTempM);
|
m_strSQL = strSQL;
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
nCount = ListRecordCount();
|
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 CCrowdMsgs::GetMsgData( )
|
{
|
CString strFieldName;
|
CString strTempValue;
|
|
try
|
{
|
m_ARecordSet.GetValue( 1, strTempValue, true );
|
m_strID = strTempValue;
|
|
m_ARecordSet.GetValue( 2, strTempValue, true );
|
m_strCrowdID = strTempValue;
|
|
m_ARecordSet.GetValue( 3, strTempValue, true );
|
m_strCrowdName = strTempValue;
|
|
m_ARecordSet.GetValue( 4, strTempValue, true );
|
m_strSender = strTempValue;
|
|
m_ARecordSet.GetValue( 5, strTempValue, true );
|
m_strSenderName = strTempValue;
|
|
m_ARecordSet.GetValue( 6, m_tmDate);
|
m_ARecordSet.GetValue( 7, m_nReadState );
|
m_ARecordSet.GetValue( 8, m_nMsgFlag );
|
|
m_ARecordSet.GetValue( 9, strTempValue, true );
|
m_strContentType = strTempValue;
|
m_ARecordSet.GetValue( 10, m_nContentSize );
|
m_ARecordSet.GetValue( 11, strTempValue, true );
|
m_strContent = strTempValue;
|
m_ARecordSet.GetValue( 12, strTempValue, true );
|
m_strContentText = strTempValue;
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return false;
|
}
|
|
return true;
|
}
|
bool CCrowdMsgs::GetMsgAdminData( )
|
{
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
CDBRecord ARecordset;
|
CString strTempValue;
|
try
|
{
|
m_ARecordSet.GetValue( 1, strTempValue, true );
|
m_strID = strTempValue;
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo();
|
return false;
|
}
|
|
return true;
|
}
|
bool CCrowdMsgs::GetData( )
|
{
|
InitMsgData( );
|
if(m_nListMsgType == LISTMSG_TYPE_MAGADMIN)
|
{
|
GetMsgAdminData( );
|
}
|
else
|
GetMsgData( );
|
return true;
|
}
|
void CCrowdMsgs::InitMsgData( )
|
{
|
Clear( );
|
}
|
int CCrowdMsgs::ListSpMsgID( LPCTSTR lpszMsgID )
|
{ // ʹÓÃÕâ¸öº¯Êý£¬¹ýÂËÌõ¼þÎÞЧ
|
if ( lpszMsgID == NULL )
|
return 0;
|
|
CString strSQL;
|
int nCount;
|
strSQL.Format( _T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C1 = '%s'"), lpszMsgID);
|
m_strSQL = strSQL;
|
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
m_ARecordSet.Close();
|
m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
|
m_ARecordSet.MoveFirst();
|
nCount = m_ARecordSet.GetRecordCount( );
|
m_strID = lpszMsgID;
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
|
return 0;
|
}
|
|
return nCount;
|
}
|
|
int CCrowdMsgs::ListSearchCrowdAll(CString strCrowdID, CString strKey, BOOL bTimeAsc /*= FALSE*/ )
|
{ // ʹÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
|
CString strSQL;
|
int nCount = 0;
|
CString strTemp;
|
CString strStartDate;
|
CString strEndDate;
|
CString strSQLTempM;
|
|
|
if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
|
{
|
if ( m_tmEndDate.GetYear() == 1970 )
|
m_tmEndDate = COleDateTime::GetCurrentTime( );
|
|
strStartDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
|
strEndDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
|
|
strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
|
}
|
if( !strKey.IsEmpty() )
|
strTemp.Format( _T("AND S_C12 LIKE '%%%s%%' "), strKey );
|
|
if( bTimeAsc)
|
strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 ASC "), strCrowdID, strSQLTempM, strTemp);
|
else
|
strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
|
N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
|
FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 DESC "), strCrowdID,strSQLTempM, strTemp);
|
m_strSQL = strSQL;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
nCount = ListRecordCount();
|
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 CCrowdMsgs::DoSaveCrowdMsg( CCrowdMsgItem *pMsg )
|
{
|
if ( !pMsg || pMsg->m_strID.IsEmpty() )
|
return false;
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
CDBConnect *pAConnect = m_pAConnect->GetDBConnect();
|
long nMsgIndex(0);
|
BOOL bRetValue = false;
|
CPerfTimer pt;
|
CString strMsgID;
|
|
strMsgID = pMsg->m_strID;
|
m_strID = pMsg->m_strID;
|
m_strCrowdID = pMsg->m_strCrowdID;
|
m_strCrowdName = pMsg->m_strCrowdName;
|
m_strSender = pMsg->m_strSender;
|
m_strSenderName = pMsg->m_strSenderName;
|
m_tmDate = pMsg->m_tmDate;;
|
m_nMsgFlag = pMsg->m_nMsgFlag;
|
m_nReadState = pMsg->m_nReadState;
|
m_strContentType = pMsg->m_strContentType;
|
m_nContentSize = pMsg->m_strContent.GetLength();
|
m_strContent = pMsg->m_strContent;
|
m_strContentText = pMsg->m_strContentText;
|
|
{
|
pt.Start();
|
InsertRecord( pAConnect );
|
pt.Stop();
|
pt.Trace( _T("DoSaveCrowdMsg\r\n") );
|
}
|
CString strSubject,strTempData;
|
strTempData = CMBAMDBFun::GetSubjectFromFormatText(m_strContent);
|
strTempData = CMBAMDBFun::GetRelSubject(strTempData, 64);
|
|
strSubject.Format(_T("%s:%s"),m_strSenderName,strTempData);
|
UpldateLastContactDate( m_strCrowdID,m_strCrowdName, CMBAMDBFun::FormatDBTIMEToStr( m_tmDate ),strSubject );
|
return true;
|
}
|
|
long CCrowdMsgs::ListRecordCount( )
|
{
|
CString strTempSQL;
|
if(m_strSQL.IsEmpty())
|
return m_ARecordSet.GetRecordCount( );
|
else
|
{
|
strTempSQL.Format(_T(" SELECT COUNT(*) FROM ( %s)T"), m_strSQL);
|
long nTempValue = 0;
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return nTempValue;
|
CDBRecord ARecordset;
|
try
|
{
|
ARecordset.Open( m_pAConnect->GetDBConnect(), strTempSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
ARecordset.GetValue( 1, nTempValue );
|
break;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
return nTempValue;
|
}
|
return nTempValue;
|
}
|
}
|
BOOL CCrowdMsgs::UpldateLastContactDate( CString strID, CString strName, CString strLastDate, CString strSubject)
|
{
|
CString strSQL;
|
CDBRecord ARecordset;
|
BOOL bReturn = FALSE;
|
int nVaule = 0;
|
CString strSubSQL = _T("");
|
CHighTime dtCurrent = CHighTime::GetPresentTime();
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
CDBConnect *pAConnect = m_pAConnect->GetDBConnect();
|
|
if( strID.IsEmpty() )
|
return TRUE;
|
if( !strName.IsEmpty() && strName.CompareNoCase(strID) != 0)
|
{
|
strSubSQL.Format( _T("S_C2 ='%s',"), CMBAMDBFun::GetDBReplaceStr( strName));
|
}
|
strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_LASTCONTACT WHERE S_C1='%s' AND N_C4=%d "),CMBAMDBFun::GetDBReplaceStr( strID),AM_VIEWITEMTYPE_CROWD);
|
try
|
{
|
ARecordset.Open( pAConnect,strSQL );
|
while ( S_OK == ARecordset.MoveNext() )
|
{
|
nVaule = 0;
|
ARecordset.GetValue( 1, nVaule );
|
bReturn = TRUE;
|
break;
|
}
|
if( nVaule > 1 )
|
{
|
strSQL.Format( _T("DELETE FROM TN_STK_LASTCONTACT WHERE S_C1= '%s' AND N_C4=%d "), CMBAMDBFun::GetDBReplaceStr( strID),AM_VIEWITEMTYPE_CROWD );
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
|
if( !bReturn)
|
return false;
|
strSQL.Format( _T("INSERT INTO TN_STK_LASTCONTACT(S_C1, S_C2 ,T_C3, N_C4, S_C5 ) VALUES ( \
|
'%s', '%s', '%s', %d, '%s' )"), CMBAMDBFun::GetDBReplaceStr( strID), CMBAMDBFun::GetDBReplaceStr( strName),strLastDate,AM_VIEWITEMTYPE_CROWD,CMBAMDBFun::GetDBReplaceStr( strSubject) );
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
|
return bReturn;
|
}
|
else if( nVaule == 1 )
|
{
|
strSQL.Format( _T("UPDATE TN_STK_LASTCONTACT SET S_C2='%s', T_C3 ='%s', S_C5 ='%s' WHERE S_C1= '%s' AND N_C4=%d AND (T_C3<= '%s' OR T_C3 > '%s')"), CMBAMDBFun::GetDBReplaceStr( strName),strLastDate, CMBAMDBFun::GetDBReplaceStr( strSubject), CMBAMDBFun::GetDBReplaceStr( strID),AM_VIEWITEMTYPE_CROWD, strLastDate, CMBAMDBFun::FormatDBTIMEToStr( dtCurrent ) );
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
|
return bReturn;
|
}
|
else
|
{
|
strSQL.Format( _T("INSERT INTO TN_STK_LASTCONTACT(S_C1, S_C2 ,T_C3, N_C4, S_C5 ) VALUES ( \
|
'%s', '%s', '%s', %d, '%s' )"), CMBAMDBFun::GetDBReplaceStr( strID), CMBAMDBFun::GetDBReplaceStr( strName),strLastDate,AM_VIEWITEMTYPE_CROWD,CMBAMDBFun::GetDBReplaceStr( strSubject) );
|
bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
|
return bReturn;
|
}
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError, strErrInfo;
|
|
strError = ex.GetErrInfo();
|
strErrInfo = _T("CCrowdMsgs UpldateLastContactDate - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return FALSE;
|
}
|
return bReturn;
|
}
|
|
int CCrowdMsgs::ListSearchCrowdMsgBox(CString strCrowdID, CString strKey, BOOL bTimeAsc /*= FALSE*/ )
|
{ // ʹÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
|
CString strSQL;
|
int nCount = 0;
|
CString strTemp;
|
CString strStartDate;
|
CString strEndDate;
|
CString strSQLTempM;
|
|
|
if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
|
{
|
if ( m_tmEndDate.GetYear() == 1970 )
|
m_tmEndDate = COleDateTime::GetCurrentTime( );
|
|
strStartDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
|
strEndDate = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
|
|
strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
|
}
|
if( !strKey.IsEmpty() )
|
strTemp.Format( _T("AND S_C12 LIKE '%%%s%%' "), strKey );
|
|
if( bTimeAsc)
|
strSQL.Format(_T("SELECT G_C1,T_C6 FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 ASC "), strCrowdID, strSQLTempM, strTemp);
|
else
|
strSQL.Format(_T("SELECT G_C1,T_C6 FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 DESC "), strCrowdID,strSQLTempM, strTemp);
|
m_strSQL = strSQL;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
try
|
{
|
nCount = ListRecordCount();
|
m_ARecordSet.Close();
|
m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = (LPCTSTR)ex.GetErrInfo( );
|
|
return 0;
|
}
|
m_nListMsgType = LISTMSG_TYPE_MAGADMIN;
|
return nCount;
|
}
|