// MsgOwner.cpp : implementation file // #include "stdafx.h" #include "mbamdb.h" #include "MsgOwner.h" #include "MBAMDBFun.h" #include "Msg.h" extern CCriticalSection m_csConnectDB; IMPLEMENT_DYNAMIC( CMsgOwnerItem, CObject ) // CMsgOwner CMsgOwnerItem::CMsgOwnerItem() { m_nRowType = ROWTYPE_MSG; Clear(); } CMsgOwnerItem::~CMsgOwnerItem() { } void CMsgOwnerItem::operator =( const CMsgOwnerItem& item ) { m_strOwner = item.m_strOwner; m_strOwnerName = item.m_strOwnerName; m_tmOpenDate = item.m_tmOpenDate; m_strAttitude = item.m_strAttitude; m_strMsgID = item.m_strMsgID; m_nOwnerType = item.m_nOwnerType; } void CMsgOwnerItem::Clear() { m_strOwner = _T(""); m_strOwnerName = _T(""); m_tmOpenDate = COleDateTime::GetCurrentTime( ); m_strAttitude = _T(""); m_strMsgID = GUID_EMPTY; m_nOwnerType = 0; } BOOL CMsgOwnerItem::GetItemValue( CString strName, COleVariant &varData ) { varData.Clear(); if ( strName.IsEmpty() ) return false; if ( strName.CompareNoCase( _T( "Owner" ) ) == 0 ) varData = m_strOwner; else if ( strName.CompareNoCase( _T( "OwnerName" ) ) == 0 ) varData = m_strOwnerName; else if ( strName.CompareNoCase( _T( "OpenDate" ) ) == 0 ) { COleDateTime oleDate( m_tmOpenDate.GetYear(), m_tmOpenDate.GetMonth(), m_tmOpenDate.GetDay(), m_tmOpenDate.GetHour(), m_tmOpenDate.GetMinute(), m_tmOpenDate.GetSecond() ); varData = oleDate; } else if ( strName.CompareNoCase( _T( "Attitude" ) ) == 0 ) varData = m_strAttitude; else if ( strName.CompareNoCase( _T( "OwnerType" ) ) == 0 ) varData = (long)m_nOwnerType; else return false; return true; } BOOL CMsgOwnerItem::InsertRecord( CDBConnect *pAConnect) { CString strSQL; BOOL bReturn = true; strSQL.Format( _T("INSERT INTO TN_STK_MSGOWNER(G_C1, S_C2, S_C3, T_C4, S_C5, N_C6 ) VALUES ( \ '%s', '%s', '%s', '%s', '%s', %d)"), m_strMsgID, CMBAMDBFun::GetDBReplaceStr( m_strOwner ), CMBAMDBFun::GetDBReplaceStr( m_strOwnerName ), CMBAMDBFun::FormatDBTIMEToStr(m_tmOpenDate), CMBAMDBFun::GetDBReplaceStr( m_strAttitude ), m_nOwnerType ); try { bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect); } catch ( CDBSQliteException ex ) { CString strError = ex.GetErrInfo(); CString strErrInfo; strErrInfo = _T("InsertRecord - MsgOwner- ") + strError; CMBAMDBFun::WriteDBErrToFile( strErrInfo ); return false; } return true; } BOOL CMsgOwnerItem::UpdateRecord( CDBConnect *pAConnect ) { CString strSQL; BOOL bReturn = true; strSQL.Format( _T("UPDATE TN_STK_MSGOWNER SET S_C3 = '%s', T_C4 = '%s', S_C5 = '%s' WHERE S_C2 = '%s' AND N_C6 = %d AND G_C1 = '%s'"), CMBAMDBFun::GetDBReplaceStr( m_strOwnerName ), CMBAMDBFun::FormatDBTIMEToStr(m_tmOpenDate), CMBAMDBFun::GetDBReplaceStr( m_strAttitude ), CMBAMDBFun::GetDBReplaceStr( m_strOwner ), m_nOwnerType, m_strMsgID ); try { bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect); } catch ( CDBSQliteException ex ) { CString strError = ex.GetErrInfo(); CString strErrInfo; strErrInfo.Format( _T("UpdateRecord(%s) - MsgOwner - %s "),strSQL, strError); CMBAMDBFun::WriteDBErrToFile( strErrInfo ); return false; } return true; } BOOL CMsgOwnerItem::UpdateUserAttitude( CDBConnect *pAConnect,CString strAttitude) { CString strSQL; BOOL bReturn = true; strSQL.Format( _T("UPDATE TN_STK_MSGOWNER S_C5 = '%s' WHERE S_C2 = '%s' AND N_C6 = %d AND G_C1 = '%s'"), CMBAMDBFun::GetDBReplaceStr( strAttitude ), CMBAMDBFun::GetDBReplaceStr( m_strOwner ), m_nOwnerType, m_strMsgID ); try { bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect); } catch ( CDBSQliteException ex ) { CString strError = ex.GetErrInfo(); CString strErrInfo; strErrInfo.Format( _T("UpdateRecord(%s) - InsertUserAttitude - %s "),strSQL, strError); CMBAMDBFun::WriteDBErrToFile( strErrInfo ); return false; } return true; } CMsgOwners::CMsgOwners(CMBAMDBConnect *pAConnect) { m_pMsgs = NULL; m_pAConnect = pAConnect; } CMsgOwners::~CMsgOwners() { } // CMsgOwner member functions void CMsgOwners::operator =( const CMsgOwners& item ) { m_pMsgs = item.m_pMsgs; m_pAConnect = item.m_pAConnect; m_strSQL = item.m_strSQL; m_nRowType = item.m_nRowType; m_strOwner = item.m_strOwner; m_strOwnerName = item.m_strOwnerName; m_tmOpenDate = item.m_tmOpenDate; m_strAttitude = item.m_strAttitude; m_strMsgID = item.m_strMsgID; m_nOwnerType = item.m_nOwnerType; } void CMsgOwners::LoadData( CMsgOwnerItem msgOwner ) { m_strOwner = msgOwner.m_strOwner; m_strOwnerName = msgOwner.m_strOwnerName; m_tmOpenDate = msgOwner.m_tmOpenDate; m_strAttitude = msgOwner.m_strAttitude; m_strMsgID = msgOwner.m_strMsgID; m_nOwnerType = msgOwner.m_nOwnerType; } int CMsgOwners::ListSpMsgID(LPCTSTR lpszMsgID, LPCTSTR lpszOwner/*=NULL*/, int nOwnerType/* = 0*/) { if ( lpszMsgID == NULL ) return 0; CString strSQL; int nCount; if ( lpszOwner == NULL ) { strSQL.Format( _T("SELECT S_C2, S_C3, T_C4, S_C5, N_C6, G_C1 \ FROM TN_STK_MSGOWNER WHERE G_C1 = '%s'"), lpszMsgID ); } else { strSQL.Format( _T("SELECT S_C2, S_C3, T_C4, S_C5, N_C6, G_C1 \ FROM TN_STK_MSGOWNER WHERE G_C1 = '%s' AND S_C2 = '%s' AND N_C6 = %d"), lpszMsgID, lpszOwner, nOwnerType ); } 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( ); } catch( CDBSQliteException ex ) { CString strError; strError = (LPCTSTR)ex.GetErrInfo( ); return 0; } return nCount; } bool CMsgOwners::GetMsg( CMsgs &msg ) { if ( m_pMsgs == NULL ) return false; msg = (*m_pMsgs); return true; } bool CMsgOwners::GetData( ) { CString strTempValue; int nTempValue; try { m_ARecordSet.GetValue( 1, strTempValue, true ); m_strOwner = (LPCTSTR)strTempValue; strTempValue= _T(""); m_ARecordSet.GetValue( 2, strTempValue, true ); m_strOwnerName = (LPCTSTR)strTempValue; strTempValue= _T(""); m_ARecordSet.GetValue( 3, m_tmOpenDate ); m_ARecordSet.GetValue( 4, strTempValue, true ); m_strAttitude = (LPCTSTR)strTempValue; nTempValue=0; m_ARecordSet.GetValue( 5, nTempValue ); m_nOwnerType = nTempValue; strTempValue= _T(""); m_ARecordSet.GetValue( 6, strTempValue, true ); m_strMsgID = (LPCTSTR)strTempValue; } catch ( CDBSQliteException ex ) { CString strError; strError = (LPCTSTR)ex.GetErrInfo( ); return false; } return true; }