📄 global.cpp
字号:
// Global.cpp: implementation of the CGlobal class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GPMIS.h"
#include "Global.h"
#include "Student.h"
#include "Teacher.h"
#include "Theme.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CGPMISApp theApp;
CGlobal CGlobal::m_Instance; //static variable must been initailized
CGlobal& g_Utility = CGlobal::GetInstance();
CGlobal& CGlobal::GetInstance()
{
return m_Instance;
}
void CGlobal::RemoveClassList()
{
while( !m_classList.IsEmpty() )
{
char* pClass = (char*)m_classList.RemoveTail();
delete pClass;
}
}
void CGlobal::CreateClassList(int nYear)
{
char strSql[128];
CString strTableName;
_RecordsetPtr pStudentSet;
FieldsPtr pFields;
FieldPtr pField;
_variant_t vConn,vRowsAffected;
_variant_t vtClass;
vConn = (IDispatch*)theApp.GetConnect();
pStudentSet.CreateInstance(__uuidof(Recordset));
try
{
RemoveClassList();
strTableName.Format("Student");
switch(theApp.GetDBType())
{
case SQLSERVER_DB:
sprintf(strSql,"select distinct 班级 from %s where 届=%d order by 班级", strTableName, nYear);
break;
case MSACCESS_DB:
default:
sprintf(strSql,"select distinct 班级 from %s where 届=%d order by 班级", strTableName, nYear);
break;
}
pStudentSet->Open( strSql, vConn, adOpenStatic, adLockOptimistic, adCmdUnknown );
int i=0;
CString strClass;
while ( VARIANT_FALSE == pStudentSet->ADOEOF )
{
vtClass = pStudentSet->GetCollect( _variant_t("班级") );
if( vtClass.vt != VT_NULL )
{
vtClass.ChangeType( VT_BSTR );
strClass = vtClass.bstrVal;
strClass.TrimRight();
}
else
strClass = "";
char* szClass = new char[20];
strcpy(szClass, strClass);
m_classList.AddTail(szClass);
pStudentSet->MoveNext();
i++;
}
pStudentSet->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 );
}
}
void CGlobal::RemoveStudentList()
{
while( !m_studentList.IsEmpty() )
{
CStudent* pStudent = m_studentList.RemoveTail();
delete pStudent;
}
}
void CGlobal::CreateStudentList(int nYear)
{
char strSql[128];
CString strTableName;
_RecordsetPtr pStudentSet;
FieldsPtr pFields;
FieldPtr pField;
_variant_t vConn,vRowsAffected;
_variant_t vtID, vtYear;
_variant_t vtName, vtNumber;
_variant_t vtClass, vtSex;
_variant_t vtTeacher, vtContact;
_variant_t vtDistrict, vtPlace;
vConn = (IDispatch*)theApp.GetConnect();
pStudentSet.CreateInstance(__uuidof(Recordset));
try
{
RemoveStudentList();
strTableName.Format("Student");
switch(theApp.GetDBType())
{
case SQLSERVER_DB:
sprintf(strSql,"select * from %s where 届=%d order by 序号", strTableName, nYear);
break;
case MSACCESS_DB:
default:
sprintf(strSql,"select * from %s where 届=%d order by 序号", strTableName, nYear);
break;
}
pStudentSet->Open( strSql, vConn, adOpenStatic, adLockOptimistic, adCmdUnknown );
int i=0;
int nID;
int nYear;
CString strNumber;
CString strName;
CString strClass;
CString strSex;
CString strTeacher;
CString strContact;
CString strDistrict;
CString strPlace;
CString strTemp;
CStudent* pStudent;
while ( VARIANT_FALSE == pStudentSet->ADOEOF )
{
vtID = pStudentSet->GetCollect( _variant_t("序号") );
vtID.ChangeType( VT_I2 );
nID = vtID.iVal;
vtYear = pStudentSet->GetCollect( _variant_t("届") );
vtYear.ChangeType( VT_I2 );
nYear = vtYear.iVal;
vtNumber = pStudentSet->GetCollect( _variant_t("学号") );
if( vtNumber.vt != VT_NULL )
{
vtNumber.ChangeType( VT_BSTR );
strNumber = vtNumber.bstrVal;
strNumber.TrimRight();
}
else
strNumber = "";
vtName = pStudentSet->GetCollect( _variant_t("姓名") );
if( vtName.vt != VT_NULL )
{
vtName.ChangeType( VT_BSTR );
strName = vtName.bstrVal;
strName.TrimRight();
}
else
strName = "";
vtClass = pStudentSet->GetCollect( _variant_t("班级") );
if( vtClass.vt != VT_NULL )
{
vtClass.ChangeType( VT_BSTR );
strClass = vtClass.bstrVal;
strClass.TrimRight();
}
else
strClass = "";
vtSex = pStudentSet->GetCollect( _variant_t("性别") );
if( vtSex.vt != VT_NULL )
{
vtSex.ChangeType( VT_BSTR );
strSex = vtSex.bstrVal;
strSex.TrimRight();
}
else
strSex = "";
vtTeacher = pStudentSet->GetCollect( _variant_t("指导老师") );
if( vtTeacher.vt != VT_NULL )
{
vtTeacher.ChangeType( VT_BSTR );
strTeacher = vtTeacher.bstrVal;
strTeacher.TrimRight();
}
else
strTeacher = "";
vtContact = pStudentSet->GetCollect( _variant_t("联系方式") );
if( vtContact.vt != VT_NULL )
{
vtContact.ChangeType( VT_BSTR );
strContact = vtContact.bstrVal;
strContact.TrimRight();
}
else
strContact = "";
vtDistrict = pStudentSet->GetCollect( _variant_t("地区") );
if( vtDistrict.vt != VT_NULL )
{
vtDistrict.ChangeType( VT_BSTR );
strDistrict = vtDistrict.bstrVal;
strDistrict.TrimRight();
}
else
strDistrict = "";
vtPlace = pStudentSet->GetCollect( _variant_t("上机地点") );
if( vtPlace.vt != VT_NULL )
{
vtPlace.ChangeType( VT_BSTR );
strPlace = vtPlace.bstrVal;
strPlace.TrimRight();
}
else
strPlace = "";
pStudent = new CStudent(nID, nYear, strNumber, strClass, strName, strSex, strTeacher, strContact, strDistrict);
pStudent->SetPlace(strPlace);
CString strWhere;
strWhere.Format("学号='%s' and 届=%d", strNumber, nYear);
pStudent->SetTheme(CTheme::CreateInst(strWhere));
strWhere.Format("学号='%s' and 届=%d", strNumber, nYear);
CScore score = CScore::CreateInst(strWhere);
if( score.GetYear() == 0 )
score.SetYear(nYear);
if( score.GetNumber() == "" )
score.SetNumber(strNumber);
pStudent->SetScore(score);
m_studentList.AddTail(pStudent);
pStudentSet->MoveNext();
i++;
}
pStudentSet->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 );
}
}
void CGlobal::RemoveTeacherList()
{
while( !m_teacherList.IsEmpty() )
{
CTeacher* pTeacher = m_teacherList.RemoveTail();
delete pTeacher;
}
}
void CGlobal::CreateTeacherList(int nYear)
{
char strSql[128];
CString strTableName;
_RecordsetPtr pTeacherSet;
FieldsPtr pFields;
FieldPtr pField;
_variant_t vConn,vRowsAffected;
_variant_t vtName, vtTitle;
_variant_t vtPhone, vtSex;
_variant_t vtEMail, vtExperience;
vConn = (IDispatch*)theApp.GetConnect();
pTeacherSet.CreateInstance(__uuidof(Recordset));
try
{
RemoveTeacherList();
strTableName.Format("Teacher");
switch(theApp.GetDBType())
{
case SQLSERVER_DB:
sprintf(strSql,"select * from %s order by Name", strTableName);
break;
case MSACCESS_DB:
default:
sprintf(strSql,"select * from %s order by Name", strTableName);
break;
}
pTeacherSet->Open( strSql, vConn, adOpenStatic, adLockOptimistic, adCmdUnknown );
int i=0;
CString strName;
CString strSex;
int nTitleID;
CString strPhone;
CString strEMail;
CString strExperience;
CTeacher* pTeacher;
while ( VARIANT_FALSE == pTeacherSet->ADOEOF )
{
vtName = pTeacherSet->GetCollect( _variant_t("Name") );
if( vtName.vt != VT_NULL )
{
vtName.ChangeType( VT_BSTR );
strName = vtName.bstrVal;
strName.TrimRight();
}
else
strName = "";
vtTitle = pTeacherSet->GetCollect( _variant_t("titleid") );
nTitleID = vtTitle.iVal;
vtSex = pTeacherSet->GetCollect( _variant_t("Sex") );
if( vtSex.vt != VT_NULL )
{
vtSex.ChangeType( VT_BSTR );
strSex = vtSex.bstrVal;
strSex.TrimRight();
}
else
strSex = "";
vtPhone = pTeacherSet->GetCollect( _variant_t("Phone") );
if( vtPhone.vt != VT_NULL )
{
vtPhone.ChangeType( VT_BSTR );
strPhone = vtPhone.bstrVal;
strPhone.TrimRight();
}
else
strPhone = "";
vtEMail = pTeacherSet->GetCollect( _variant_t("EMail") );
if( vtEMail.vt != VT_NULL )
{
vtEMail.ChangeType( VT_BSTR );
strEMail = vtEMail.bstrVal;
strEMail.TrimRight();
}
else
strEMail = "";
vtExperience = pTeacherSet->GetCollect( _variant_t("Experience") );
if( vtExperience.vt != VT_NULL )
{
vtExperience.ChangeType( VT_BSTR );
strExperience = vtExperience.bstrVal;
strExperience.TrimRight();
}
else
strExperience = "";
pTeacher = new CTeacher(strName, strSex, nTitleID, strPhone, strEMail, strExperience);
m_teacherList.AddTail(pTeacher);
pTeacherSet->MoveNext();
i++;
}
pTeacherSet->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 );
}
}
void CGlobal::RemoveTitleMap()
{
for (POSITION pos = m_TitleMap.GetStartPosition(); pos != NULL; )
{
CString key;
CString name;
m_TitleMap.GetNextAssoc(pos, key, name);
}
m_TitleMap.RemoveAll();
m_LevelMap.RemoveAll();
}
void CGlobal::CreateTitleMap()
{
char strSql[128];
CString strTableName;
_RecordsetPtr pTitleSet;
FieldsPtr pFields;
FieldPtr pField;
_variant_t vConn,vRowsAffected;
_variant_t vtTitleID, vtTitle, vtLevel;
vConn = (IDispatch*)theApp.GetConnect();
pTitleSet.CreateInstance(__uuidof(Recordset));
try
{
RemoveTitleMap();
strTableName.Format("Title");
switch(theApp.GetDBType())
{
case SQLSERVER_DB:
sprintf(strSql,"select * from %s order by titleid", strTableName);
break;
case MSACCESS_DB:
default:
sprintf(strSql,"select * from %s order by titleid", strTableName);
break;
}
pTitleSet->Open( strSql, vConn, adOpenStatic, adLockOptimistic, adCmdUnknown );
int nTitleID;
CString strTitle;
CString strLevel;
while ( VARIANT_FALSE == pTitleSet->ADOEOF )
{
vtTitleID = pTitleSet->GetCollect( _variant_t("titleid") );
nTitleID = vtTitleID.iVal;
vtTitle = pTitleSet->GetCollect( _variant_t("title") );
if( vtTitle.vt != VT_NULL )
{
vtTitle.ChangeType( VT_BSTR );
strTitle = vtTitle.bstrVal;
strTitle.TrimRight();
}
else
strTitle = "";
vtLevel = pTitleSet->GetCollect( _variant_t("Level") );
if( vtLevel.vt != VT_NULL )
{
vtLevel.ChangeType( VT_BSTR );
strLevel = vtLevel.bstrVal;
strLevel.TrimRight();
}
else
strLevel = "";
CString key;
key.Format("%d", nTitleID);
m_TitleMap.SetAt(key, strTitle);
m_LevelMap.SetAt(key, strLevel);
pTitleSet->MoveNext();
}
pTitleSet->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 );
}
}
void CGlobal::RemoveOthersMap()
{
m_ThemeTypeMap.RemoveAll();
m_ThemeKindMap.RemoveAll();
m_ExperienceMap.RemoveAll();
}
void CGlobal::CreateOthersMap()
{
CString key;
key.Format("1");
m_ThemeTypeMap.SetAt(key, "工程设计");
key.Format("2");
m_ThemeTypeMap.SetAt(key, "应用研究或开发研究");
key.Format("3");
m_ThemeTypeMap.SetAt(key, "软件工程");
key.Format("4");
m_ThemeTypeMap.SetAt(key, "理论研究");
key.Format("5");
m_ThemeTypeMap.SetAt(key, "其它");
key.Format("a");
m_ThemeKindMap.SetAt(key, "真实(真题真做)即在有效合同期内的立项课题");
key.Format("b");
m_ThemeKindMap.SetAt(key, "模拟(真题假做)");
key.Format("c");
m_ThemeKindMap.SetAt(key, "虚拟(假题假做)");
key.Format("G");
m_ExperienceMap.SetAt(key, "国家级项目");
key.Format("S");
m_ExperienceMap.SetAt(key, "(省)市级项目");
key.Format("X");
m_ExperienceMap.SetAt(key, "校级项目");
}
CStudent* CGlobal::FindStudent(int nID, const CString& strNumber)
{
CStudent* pStudent = NULL;
POSITION pos = m_studentList.GetHeadPosition();
while( pos )
{
pStudent = m_studentList.GetNext(pos);
if( pStudent && pStudent->GetNumber() == strNumber && pStudent->GetID() == nID )
return pStudent;
}
return NULL;
}
CStudent* CGlobal::FindStudent(const CString& strNumber, int nYear)
{
CStudent* pStudent = NULL;
POSITION pos = m_studentList.GetHeadPosition();
while( pos )
{
pStudent = m_studentList.GetNext(pos);
if( pStudent && pStudent->GetNumber() == strNumber && pStudent->GetYear() == nYear )
return pStudent;
}
return NULL;
}
CTeacher* CGlobal::FindTeacher(const CString& strTeacher)
{
CTeacher* pTeacher = NULL;
POSITION pos = m_teacherList.GetHeadPosition();
while( pos )
{
pTeacher = m_teacherList.GetNext(pos);
if( pTeacher && pTeacher->GetName() == strTeacher )
return pTeacher;
}
return NULL;
}
BOOL CGlobal::IsIP(CString strData)
{
strData.MakeLower();
if( strData.Find("http://") >= 0 )
return false;
for(int i=0; i<strData.GetLength() ; i++)
{
char ch = strData.GetAt(i);
if(( ch >= '0' && ch <= '9') || ch == '.')
continue;
else
return false;
}
return true;
}
CString CGlobal::GetIPByUrl(CString strUrl, BOOL bHostName)
{
struct hostent FAR * host;
char *pcIP = NULL;
CString strIP = LOCAL_HOST;
if(strUrl.Find('.') == -1 && !bHostName)
return strIP;
strUrl.MakeLower();
if(strUrl.Find("http://")>=0)
{
strUrl = strUrl.Right(strUrl.GetLength()-7);
}
if(strUrl.Find('/')>=0)
{
strUrl.SetAt(strUrl.Find('/'),0);
}
if(strUrl.Find(':')>=0)
{
strUrl.SetAt(strUrl.Find(':'),0);
}
if(IsIP(strUrl)) // IP
{
return strUrl;
}
host = gethostbyname (strUrl);
if(host)
{
pcIP = inet_ntoa(*((struct in_addr *)host->h_addr_list[0]));
strIP.Format("%s",pcIP);
}
return strIP;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -