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

📄 simsdlg.cpp

📁 学生信息管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SIMSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SIMS.h"
#include "SIMSDlg.h"
#include "Login.h"
#include "InformationSet.h"
#include "CountrySet.h"
#include "SpecializeSet.h"
#include "NationSet.h"
#include "Addition.h"
#include "ScoreDlg.h"
#include "ScoreSet.h"

extern CDatabase db;

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	CBrush m_brush;
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSIMSDlg dialog

CSIMSDlg::CSIMSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSIMSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSIMSDlg)
	m_strCombo1 = _T("");
	m_strCombo2 = _T("");
	m_strCombo3 = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSIMSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSIMSDlg)
	DDX_Control(pDX, IDC_LIST2, m_scoreResult);
	DDX_Control(pDX, IDC_LIST1, m_searchResult);
	DDX_Control(pDX, IDC_COMBO3, m_Combo3);
	DDX_Control(pDX, IDC_COMBO2, m_Combo2);
	DDX_Control(pDX, IDC_COMBO1, m_Combo1);
	DDX_CBString(pDX, IDC_COMBO1, m_strCombo1);
	DDX_CBString(pDX, IDC_COMBO2, m_strCombo2);
	DDX_CBString(pDX, IDC_COMBO3, m_strCombo3);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSIMSDlg, CDialog)
	//{{AFX_MSG_MAP(CSIMSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON1, OnButtonSearch)
	ON_BN_CLICKED(IDC_BUTTON2, OnButtonAddition)
	ON_BN_CLICKED(IDC_BUTTON3, OnButtonModify)
	ON_BN_CLICKED(IDC_BUTTON5, OnButtonAbout)
	ON_BN_CLICKED(IDC_BUTTON6, OnButtonHelp)
	ON_CBN_DROPDOWN(IDC_COMBO3, OnDropdownCombo3)
	ON_CBN_DROPDOWN(IDC_COMBO1, OnDropdownCombo1)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_CBN_DROPDOWN(IDC_COMBO2, OnDropdownCombo2)
	ON_BN_CLICKED(IDC_BUTTON4, OnButtonDelete)
	ON_CBN_CLOSEUP(IDC_COMBO1, OnCloseupCombo1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSIMSDlg message handlers

BOOL CSIMSDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	LOGFONT LogFont;
	GetFont()->GetLogFont(&LogFont);
	LogFont.lfHeight=LogFont.lfHeight*2;
	LogFont.lfWidth=LogFont.lfWidth*2;
	m_font.CreateFontIndirect(&LogFont);
	GetDlgItem(IDC_STATIC_HEAD)->SetFont(&m_font);
	m_brush.CreateSolidBrush(RGB(74,142,184));
	ShowWindow(SW_MINIMIZE);
	CLogin dlg;
	if(!(dlg.DoModal()==IDOK))
	{
		OnCancel();
		return false;
	}
	ShowWindow(SW_MAXIMIZE);
	initSearchList();
	initScoreList();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSIMSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSIMSDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CSIMSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

HBRUSH CSIMSDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	pDC->SetBkMode(TRANSPARENT);
	return m_brush;
}

void CSIMSDlg::OnButtonSearch() 
{
	UpdateData(true);
	TranslateChineseToEnglish(m_strCombo1);
	TranslateChineseToEnglish(m_strCombo2);
	TranslateChineseToEnglish(m_strCombo3);
	m_searchResult.DeleteAllItems();
	CString str;
	char buf[10];
	if(m_strCombo1.IsEmpty()||m_strCombo2.IsEmpty()||m_strCombo3.IsEmpty())
	{
		m_strSQL.Format("select* from STUDENT_INFORMATION");
		reFreshScoreList("select* from STUDENT_SCORE");
	}
	if(m_strCombo1=="SDT_COUNTRY")
	{
		CCountrySet* pCC=new CCountrySet(&db);
		str.Format("select* from COUNTRY_CODE where COUNTRY_NAME_CN='%s'",m_strCombo3);
		pCC->Open(CRecordset::forwardOnly,str);
		itoa(pCC->m_COUNTRY_CODE,buf,10);
		m_strCombo3=buf;
		delete pCC;
	}
	if(m_strCombo1=="SDT_NATION")
	{
		CNationSet* pCN=new CNationSet(&db);
		str.Format("select* from NATION_CODE where NATION_NAME='%s'",m_strCombo3);
		pCN->Open(CRecordset::forwardOnly,str);
		itoa(pCN->m_NATION_CODE,buf,10);
		m_strCombo3=buf;
		delete pCN;
	}
	if(m_strCombo1=="SDT_SPECIALIZE")
	{
		CSpecializeSet* pCS=new CSpecializeSet(&db);
		str.Format("select* from SPECIALIZE_CODE where SPECIALIZE_NAME='%s'",m_strCombo3);
		pCS->Open(CRecordset::forwardOnly,str);
		itoa(pCS->m_SPECIALIZE_NO,buf,10);
		m_strCombo3=buf;
		delete pCS;
		m_strSQL.Format("select* from STUDENT_INFORMATION where %s%s%s",m_strCombo1,m_strCombo2,m_strCombo3);
		reFreshSearchList();
		return;
	}
	if(!m_strCombo1.IsEmpty()&&!m_strCombo2.IsEmpty()&&!m_strCombo3.IsEmpty())
	{
		if(m_strCombo1=="SDT_STARTTIME")
		{
			m_strSQL.Format("select* from STUDENT_INFORMATION where %s%s%d-%d-%d",\
				m_strCombo1,m_strCombo2,\
				atoi(m_strCombo3.Left(4)),atoi(m_strCombo3.Mid(5,2)),atoi(m_strCombo3.Mid(8,2)));
		}
		else
		{
			m_strSQL.Format("select* from STUDENT_INFORMATION where %s%s'%s'",m_strCombo1,m_strCombo2,m_strCombo3);
		}
	}
	reFreshSearchList();
}

void CSIMSDlg::OnButtonAddition() 
{
	int choice=GetCheckedRadioButton(IDC_RADIO_INFORMATION,IDC_RADIO_SCORE);
	if(!choice)
	{
		MessageBox("请选择添加类型:\n基本信息或学生成绩","添加提示");
		return;
	}
	if(choice==IDC_RADIO_INFORMATION)
	{
		CAddition dlg;
		dlg.m_bMode=true;
		if(dlg.DoModal()==IDOK)
		{
			db.ExecuteSQL(dlg.m_strSQL);
			m_strSQL.Format("select* from STUDENT_INFORMATION");
			reFreshSearchList();
		}
	}
	if(choice==IDC_RADIO_SCORE)
	{
		CScoreDlg dlg;
		dlg.m_bMode=true;
		choice=m_searchResult.GetSelectionMark();
		m_choice=m_searchResult.GetItemText(choice,0);//MessageBox(m_choice);
		m_strSQL.Format("select* from STUDENT_SCORE where SDT_NO='%s'",m_choice);
		CScoreSet* pCS=new CScoreSet(&db);
		pCS->Open(CRecordset::forwardOnly,m_strSQL);
		if(choice==-1)
		{
			MessageBox("请选择添加的学生");
			return;
		}
		if(pCS->GetRecordCount()!=0)
		{
			MessageBox("成绩已经存在,请删除后再添加!","提示");
			return;
		}
		dlg.m_name=m_searchResult.GetItemText(choice,1);
		if(dlg.DoModal()==IDOK)
		{
			m_strSQL.Format("insert into STUDENT_SCORE values('%s','%s',%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",\
				m_searchResult.GetItemText(choice,0),m_searchResult.GetItemText(choice,1),\
				dlg.m_chinese,dlg.m_math,dlg.m_english,dlg.m_phisicis,dlg.m_chemistry,dlg.m_organism,\
				dlg.m_geography,dlg.m_history,dlg.m_politics,dlg.m_arts,dlg.m_music,dlg.m_sports,dlg.m_computer);
			db.ExecuteSQL(m_strSQL);
			m_strSQL.Format("select* from STUDENT_SCORE where SDT_NO='%s'",m_choice);
			reFreshScoreList(m_strSQL);
		}
	}
}

void CSIMSDlg::OnButtonModify() 
{
	int choice=GetCheckedRadioButton(IDC_RADIO_INFORMATION,IDC_RADIO_SCORE);
	if(!choice)
	{
		MessageBox("请选择修改类型:\n基本信息或学生成绩","修改提示");
		return;
	}
	if(choice==IDC_RADIO_INFORMATION)
	{
		int i=m_searchResult.GetSelectionMark();
		if(i==-1)
		{
			MessageBox("请选择一个学生再修改","提示");
			return;
		}
		CAddition dlg;
		dlg.mc_no=m_searchResult.GetItemText(i,0);
		dlg.mc_name=m_searchResult.GetItemText(i,1);
		dlg.mc_specialize=m_searchResult.GetItemText(i,2);
		dlg.mc_gender=m_searchResult.GetItemText(i,3);
		if(atoi(m_searchResult.GetItemText(i,4).Left(4))>=1970&&\
			atoi(m_searchResult.GetItemText(i,4).Mid(5,2))>=1&&\
			atoi(m_searchResult.GetItemText(i,4).Mid(8,2))>=1)
		{
			CTime birthday(atoi(m_searchResult.GetItemText(i,4).Left(4)),\
				atoi(m_searchResult.GetItemText(i,4).Mid(5,2)),\
				atoi(m_searchResult.GetItemText(i,4).Mid(8,2)),0,0,0);
			dlg.mc_birthday=birthday;
		}
		else
		{
			dlg.mc_birthday=CTime::GetCurrentTime();
		}
		dlg.mc_hometown=m_searchResult.GetItemText(i,5);
		dlg.mc_country=m_searchResult.GetItemText(i,6);
		dlg.mc_nation=m_searchResult.GetItemText(i,7);
		dlg.mc_id=m_searchResult.GetItemText(i,8);
		dlg.mc_health=m_searchResult.GetItemText(i,9);
		if(atoi(m_searchResult.GetItemText(i,10).Left(4))>=1970&&\
			atoi(m_searchResult.GetItemText(i,10).Mid(5,2))>=1&&\
			atoi(m_searchResult.GetItemText(i,10).Mid(8,2))>=1)
		{
			CTime starttime(atoi(m_searchResult.GetItemText(i,10).Left(4)),\
				atoi(m_searchResult.GetItemText(i,10).Mid(5,2)),\
				atoi(m_searchResult.GetItemText(i,10).Mid(8,2)),0,0,0);
			dlg.mc_starttime=starttime;
		}
		else
		{
			dlg.mc_starttime=CTime::GetCurrentTime();
		}
		dlg.mc_states=m_searchResult.GetItemText(i,11);
		dlg.mc_address=m_searchResult.GetItemText(i,12);
		dlg.mc_teleno=m_searchResult.GetItemText(i,13);
		dlg.mc_email=m_searchResult.GetItemText(i,14);
		dlg.mc_men=m_searchResult.GetItemText(i,15);
		dlg.m_bMode=false;
		if(dlg.DoModal()==IDOK)
		{
			m_strSQL.Format("delete from STUDENT_INFORMATION where SDT_NO='%s'",dlg.mc_no);
			db.ExecuteSQL(m_strSQL);
			db.ExecuteSQL(dlg.m_strSQL);
			m_strSQL.Format("select* from STUDENT_INFORMATION");
			reFreshSearchList();
		}
	}
	if(choice==IDC_RADIO_SCORE)
	{
		int i=m_searchResult.GetSelectionMark();
		CString str=m_searchResult.GetItemText(i,0);
		if(i==-1)
		{
			i=m_scoreResult.GetSelectionMark();
			str=m_scoreResult.GetItemText(i,0);
		}
		if(i==-1)
		{
			MessageBox("请选择一个学生或成绩再修改!","提示");
			return;
		}
		CString strSQL;
		CScoreSet* pCS=new CScoreSet(&db);
		strSQL.Format("select* from STUDENT_SCORE where SDT_NO='%s'",str);
		pCS->Open(CRecordset::forwardOnly,strSQL);
		if(pCS->GetRecordCount()==0)
		{
			MessageBox("该学生成绩不存在,不能修改!","提示");
			return;
		}
		CScoreDlg dlg;
		dlg.m_chinese=pCS->m_CHINESE;
		dlg.m_math=pCS->m_MATH;
		dlg.m_english=pCS->m_ENGLISH;
		dlg.m_phisicis=pCS->m_PHISICIS;
		dlg.m_chemistry=pCS->m_CHEMISTRY;
		dlg.m_organism=pCS->m_ORGANISM;
		dlg.m_geography=pCS->m_GEOGRAHPY;
		dlg.m_history=pCS->m_HISTORY;
		dlg.m_politics=pCS->m_POLITICS;
		dlg.m_arts=pCS->m_ATRS;

⌨️ 快捷键说明

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