// ExtProperty.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbamdb.h"
|
#include "ExtProperty.h"
|
#include "MBAMDBFun.h"
|
|
extern CCriticalSection m_csConnectDB;
|
// CExtProperty
|
CExtPropertyItem::CExtPropertyItem()
|
{
|
m_nRowType = ROWTYPE_EXTPROPERTY;
|
Clear();
|
}
|
|
CExtPropertyItem::~CExtPropertyItem()
|
{
|
|
}
|
|
void CExtPropertyItem::Clear()
|
{
|
m_strClass = _T("");
|
m_strName = _T("");
|
m_strValue = _T("");
|
}
|
|
BOOL CExtPropertyItem::GetItemValue( CString strName, COleVariant &varData )
|
{
|
varData.Clear();
|
if ( strName.IsEmpty() )
|
return false;
|
if ( strName.CompareNoCase( _T( "Class" ) ) == 0 )
|
varData = m_strClass;
|
else if ( strName.CompareNoCase( _T( "Name" ) ) == 0 )
|
varData = m_strName;
|
else if ( strName.CompareNoCase( _T( "Value" ) ) == 0 )
|
varData = m_strValue;
|
else
|
return false;
|
|
return true;
|
}
|
|
BOOL CExtPropertyItem::InsertRecord( CDBConnect *pAConnect)
|
{
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("INSERT INTO TN_STK_EXTPROPERTY( S_C1, S_C2, S_C3 ) VALUES ( \
|
'%s', '%s', '%s')"), CMBAMDBFun::GetDBReplaceStr( m_strClass ), CMBAMDBFun::GetDBReplaceStr( m_strName ), CMBAMDBFun::GetDBReplaceStr( m_strValue ) );
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo = _T("InsertRecord - ExtProperty - ") + strError;
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
BOOL CExtPropertyItem::UpdateRecord( CDBConnect *pAConnect )
|
{
|
CString strSQL;
|
BOOL bReturn = true;
|
|
strSQL.Format( _T("UPDATE TN_STK_EXTPROPERTY SET S_C3 = '%s' WHERE S_C1 = '%s' AND S_C2 = '%s'"),
|
CMBAMDBFun::GetDBReplaceStr( m_strValue ), CMBAMDBFun::GetDBReplaceStr( m_strClass ),
|
CMBAMDBFun::GetDBReplaceStr( m_strName ) );
|
try
|
{
|
bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
|
}
|
catch ( CDBSQliteException ex )
|
{
|
CString strError = ex.GetErrInfo();
|
CString strErrInfo;
|
|
strErrInfo.Format( _T("UpdateRecord(%s) - ExtProperty - %s "),strSQL, strError);
|
CMBAMDBFun::WriteDBErrToFile( strErrInfo );
|
return false;
|
}
|
return true;
|
}
|
|
CExtPropertys::CExtPropertys(CMBAMDBConnect *pAConnect)
|
{
|
m_pAConnect = pAConnect;
|
}
|
|
CExtPropertys::~CExtPropertys()
|
{
|
|
}
|
int CExtPropertys::LoadValue( LPCTSTR lpszClass, LPCTSTR lpszName )
|
{
|
if ( lpszClass == NULL || lpszName == NULL )
|
return 0;
|
|
CString strSQL;
|
int nCount;
|
|
strSQL.Format( _T("SELECT S_C1, S_C2, S_C3 FROM TN_STK_EXTPROPERTY WHERE S_C1 = '%s' AND \
|
S_C2 = '%s'"), lpszClass, lpszName );
|
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 = ex.GetErrInfo( );
|
|
return 0;
|
}
|
|
return nCount;
|
}
|
|
bool CExtPropertys::RemoveValue( LPCTSTR lpszClass, LPCTSTR lpszName )
|
{
|
if ( lpszClass == NULL || lpszName == NULL )
|
return 0;
|
|
CString strSQL;
|
BOOL bReturn = false;
|
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
strSQL.Format( _T("DELETE FROM TN_STK_EXTPROPERTY WHERE S_C1 = '%s' AND S_C2 = '%s'"), lpszClass, lpszName );
|
bReturn = CDBSQLiteCommFun::RunSQL( strSQL , m_pAConnect->GetDBConnect() );
|
|
return ( bReturn != 0 );
|
}
|
|
bool CExtPropertys::GetData( )
|
{
|
CString strTempValue;
|
|
try
|
{
|
strTempValue = _T("");
|
m_ARecordSet.GetValue( 1, strTempValue, true );
|
m_strClass = (LPCTSTR)strTempValue;
|
|
strTempValue = _T("");
|
m_ARecordSet.GetValue( 2, strTempValue, true );
|
m_strName = (LPCTSTR)strTempValue;
|
|
strTempValue = _T("");
|
m_ARecordSet.GetValue( 3, strTempValue, true );
|
m_strValue = (LPCTSTR)strTempValue;
|
}
|
catch( CDBSQliteException ex )
|
{
|
CString strError;
|
|
strError = ex.GetErrInfo( );
|
|
return false;
|
}
|
|
return true;
|
}
|
BOOL CExtPropertys::SaveData()
|
{
|
if( !m_pAConnect || !m_pAConnect->IsOpenDB())
|
return 0;
|
{
|
|
if ( LoadValue( m_strClass,m_strName ) > 0 )
|
{
|
UpdateRecord(m_pAConnect->GetDBConnect());
|
}
|
else
|
{
|
InsertRecord(m_pAConnect->GetDBConnect());
|
}
|
}
|
return TRUE;
|
}
|