⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 score.cpp

📁 我上载了那么多怎么都说已经有上载的啦
💻 CPP
字号:
// Score.cpp: implementation of the CScore class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "gpmis.h"
#include "Score.h"
#include "global.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

extern CGPMISApp theApp;

CScore::CScore() : m_nYear(0), m_strNumber("")
{
	m_nTheme = 0;
	m_nCheck = 0;
	m_nTeacher = 0;
	m_nComment = 0;
	m_nAnswer = 0;
	m_nScore = 0;
}

CScore::CScore(int nYear, const CString& strNumber)
: m_nYear(nYear), m_strNumber(strNumber)
{
	m_nTheme = 0;
	m_nCheck = 0;
	m_nTeacher = 0;
	m_nComment = 0;
	m_nAnswer = 0;
	m_nScore = 0;
}

CScore::~CScore()
{

}

CScore::CScore(const CScore& rhs)
{
	*this = rhs;
}

CScore& CScore::operator = (const CScore& rhs)
{
	m_nYear = rhs.m_nYear;
	m_strNumber = rhs.m_strNumber;

	m_nTheme = rhs.m_nTheme;
	m_nCheck = rhs.m_nCheck;
	m_nTeacher = rhs.m_nTeacher;
	m_nComment = rhs.m_nComment;
	m_nAnswer = rhs.m_nAnswer;
	m_nScore = rhs.m_nScore;
	return *this;
}

/// create/update a record
BOOL CScore::Create(BOOL bUpdate)
{
	CString			strSQL;
	CString			strTableName;
	_RecordsetPtr   pSet;
		
	FieldsPtr		pFields;
	FieldPtr		pField;
	
	_variant_t		vConn,vRowsAffected;
	CString			strTmep;


	vConn = (IDispatch*)theApp.GetConnect();
	pSet.CreateInstance(__uuidof(Recordset));

	strTableName.Format("Score");

	time_t ltime;
	time( &ltime );

	switch(theApp.GetDBType())
	{
	case MSACCESS_DB:
	default:
		if( bUpdate )
			strSQL.Format("select * from %s where 届=%d and 学号='%s'", 
				strTableName, m_nYear, m_strNumber);
		else
			strSQL.Format("select * from %s",  strTableName);
		break;
	case SQLSERVER_DB:
		if( bUpdate )
			strSQL.Format("select * from %s where 届=%d and 学号='%s'", 
				strTableName, m_nYear, m_strNumber);
		else
			strSQL.Format("select * from %s",  strTableName);
		break;
	}
	try
	{
		pSet->Open((_variant_t)strSQL,vConn,adOpenStatic,adLockOptimistic,adCmdUnknown);

		if( !bUpdate )  //Create
		{
			pSet->AddNew();
		}
		else
		{
			if ( VARIANT_TRUE == pSet->ADOEOF )
			{
				pSet->AddNew();
			}
		}

		pFields			= pSet->Fields;
		pField			= pFields->Item["届"];
		strTmep.Format("%d",GetYear());
		pField->Value	= (_bstr_t)strTmep;
		
		pFields			= pSet->Fields;
		pField			= pFields->Item["学号"];
		strTmep.Format("%s",GetNumber());
		pField->Value	= (_bstr_t)strTmep;
		
		pFields			= pSet->Fields;
		pField			= pFields->Item["开题"];
		strTmep.Format("%d",GetTheme());
		pField->Value	= (_bstr_t)strTmep;

		pFields			= pSet->Fields;
		pField			= pFields->Item["中期"];
		strTmep.Format("%d",GetCheck());
		pField->Value	= (_bstr_t)strTmep;

		pFields			= pSet->Fields;
		pField			= pFields->Item["指导教师"];
		strTmep.Format("%d",GetTeacher());
		pField->Value	= (_bstr_t)strTmep;

		pFields			= pSet->Fields;
		pField			= pFields->Item["评阅人"];
		strTmep.Format("%d",GetComment());
		pField->Value	= (_bstr_t)strTmep;

		pFields			= pSet->Fields;
		pField			= pFields->Item["答辩"];
		strTmep.Format("%d",GetAnswer());
		pField->Value	= (_bstr_t)strTmep;

		pFields			= pSet->Fields;
		pField			= pFields->Item["总评"];
		strTmep.Format("%d",GetScore());
		pField->Value	= (_bstr_t)strTmep;

		pSet->Update(); 
		pSet->Close();
		
	}
	catch( _com_error& ce )
	{
		_bstr_t bstrDescription( ce.Description() );
		_bstr_t bstrSource( ce.Source() );
		TRACE( "HRESULT = 0x%08lx\n", ce.Error() );
		TRACE( "HRESULT description : %s\n", ce.ErrorMessage() );
		TRACE( "Description : %s\n", (LPCTSTR)bstrDescription );
		TRACE( "Source : %s\n", (LPCTSTR)bstrSource );
		return FALSE;
	}

	if( !bUpdate )  //Create
	{
		CString strWhere;
	}

	return TRUE;
}

// static method
CScore CScore::CreateInst(CString strWhere)
{
	char			strSql[256];
	CString			strTableName;
	_RecordsetPtr   pScoreSet;
		
	FieldsPtr		pFields;
	FieldPtr		pField;
	
	_variant_t		vConn,vRowsAffected;
	_variant_t		vtYear;
	_variant_t		vtNumber;
	_variant_t		vtTheme;
	_variant_t		vtCheck;
	_variant_t		vtTeacher;
	_variant_t		vtComment;
	_variant_t		vtAnswer, vtScore;

	CScore		Score;


	vConn = (IDispatch*)theApp.GetConnect();
	pScoreSet.CreateInstance(__uuidof(Recordset));

	try
	{
		strTableName.Format("Score");

		switch(theApp.GetDBType())
		{
		case SQLSERVER_DB:
			sprintf(strSql,"select * from %s where %s",	strTableName, strWhere);
			break;
		case MSACCESS_DB:
		default:
			sprintf(strSql,"select * from %s where %s",	strTableName, strWhere);
			break;
		}
		
		pScoreSet->Open( strSql, vConn, adOpenStatic, adLockOptimistic, adCmdUnknown );

		int nYear;
		CString strNumber;
		int		nTheme;
		int		nCheck;
		int		nTeacher;
		int		nComment;
		int		nAnswer;
		int		nScore;

		if ( VARIANT_FALSE == pScoreSet->ADOEOF )
		{
			vtYear = pScoreSet->GetCollect( _variant_t("届") );
			vtYear.ChangeType( VT_I2 );
			nYear = vtYear.iVal;

			vtNumber = pScoreSet->GetCollect( _variant_t("学号") );
			if( vtNumber.vt != VT_NULL )
			{
				vtNumber.ChangeType( VT_BSTR );
				strNumber = vtNumber.bstrVal;
				strNumber.TrimRight();
			}
			else
				strNumber = "";

			vtTheme = pScoreSet->GetCollect( _variant_t("开题") );
			vtTheme.ChangeType( VT_I2 );
			nTheme = vtTheme.iVal;

			vtCheck = pScoreSet->GetCollect( _variant_t("中期") );
			vtCheck.ChangeType( VT_I2 );
			nCheck = vtCheck.iVal;

			vtTeacher = pScoreSet->GetCollect( _variant_t("指导教师") );
			vtTeacher.ChangeType( VT_I2 );
			nTeacher = vtTeacher.iVal;

			vtComment = pScoreSet->GetCollect( _variant_t("评阅人") );
			vtComment.ChangeType( VT_I2 );
			nComment = vtComment.iVal;

			vtAnswer = pScoreSet->GetCollect( _variant_t("答辩") );
			vtAnswer.ChangeType( VT_I2 );
			nAnswer = vtAnswer.iVal;

			vtScore = pScoreSet->GetCollect( _variant_t("总评") );
			vtScore.ChangeType( VT_I2 );
			nScore = vtScore.iVal;

			Score = CScore(nYear, strNumber);
			Score.SetTheme(nTheme);
			Score.SetCheck(nCheck);
			Score.SetTeacher(nTeacher);
			Score.SetComment(nComment);
			Score.SetAnswer(nAnswer);
			Score.SetScore(nScore);
		}
		else
		{
			Score = CScore();
		}

		pScoreSet->Close();
	}
	catch( _com_error& ce )
	{
		_bstr_t bstrDescription( ce.Description() );
		_bstr_t bstrSource( ce.Source() );
		TRACE( "Description : %s\n", (LPCTSTR)bstrDescription );
		TRACE( "Source : %s\n", (LPCTSTR)bstrSource );
		return CScore();
	}

	return Score;
}

BOOL CScore::Create(CScore& score)
{
	return score.Create();
}

BOOL CScore::Update(CScore& score)
{
	CString strWhere;
	strWhere.Format("学号='%s' and 届=%d", score.GetNumber(), score.GetYear());
	CScore s = CScore::CreateInst(strWhere);
	if( s.GetYear() == 0 )
		return score.Create(FALSE);
	return score.Create(TRUE);
}

BOOL CScore::Delete(const CString& strWhere)
{
	CString			strSQL;
	_variant_t		vRowsAffected;
	CString			strTableName;

	strTableName.Format("Score");

	switch(theApp.GetDBType())
	{
	case MSACCESS_DB:
	default:
		strSQL.Format("delete * from %s where %s", strTableName, strWhere);
		break;
	case SQLSERVER_DB:
		strSQL.Format("delete * from %s where %s", strTableName, strWhere);
		break;
	}
	try
	{
		theApp.GetConnect()->Execute( (_bstr_t)strSQL, &vRowsAffected, adCmdText );

	}
	catch( _com_error& ce )
	{
		_bstr_t bstrDescription( ce.Description() );
		_bstr_t bstrSource( ce.Source() );
		TRACE( "HRESULT = 0x%08lx\n", ce.Error() );
		TRACE( "HRESULT description : %s\n", ce.ErrorMessage() );
		TRACE( "Description : %s\n", (LPCTSTR)bstrDescription );
		TRACE( "Source : %s\n", (LPCTSTR)bstrSource );
		return FALSE;
	}

	return TRUE;}

BOOL CScore::Delete(CScore& score)
{
	CString strWhere;

	strWhere.Format(" 届=%d and 学号='%s'", score.GetYear(), score.GetNumber());
	return Delete(strWhere);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -