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

📄 scoresetdlg.cpp

📁 课程设计的简单Access学生数据库系统
💻 CPP
字号:
// ScoreSetDlg.cpp : implementation file
//

#include "stdafx.h"
#include "sm.h"
#include "ScoreSetDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CScoreSetDlg dialog


//##ModelId=40A481F40197
CScoreSetDlg::CScoreSetDlg(long class_id, COleDateTime *Date, long *student_id, long* subject_id, long* score, CWnd* pParent /*=NULL*/)
	: CDialog(CScoreSetDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScoreSetDlg)
	m_Score = 0;
	//}}AFX_DATA_INIT
	ClassID = class_id, pDate = Date, pStudentID = student_id, pSubjectID = subject_id, pScore = score;
	m_Score = *pScore;
}


//##ModelId=40A481F401E4
void CScoreSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScoreSetDlg)
	DDX_Control(pDX, IDC_LIST2, m_Subject);
	DDX_Control(pDX, IDC_LIST1, m_Student);
	DDX_Text(pDX, IDC_EDIT1, m_Score);
	DDV_MinMaxLong(pDX, m_Score, 0, 200);
	DDX_Control(pDX, IDC_DTPICKER1, m_Date);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScoreSetDlg, CDialog)
	//{{AFX_MSG_MAP(CScoreSetDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScoreSetDlg message handlers

//##ModelId=40A481F401F4
void CScoreSetDlg::OnOK() 
{
	if(m_Student.GetCurSel()==-1)
	{
		AfxMessageBox("必须选择一个学生");
		return;
	}
	if(m_Subject.GetCurSel()==-1)
	{
		AfxMessageBox("必须选择一个科目");
		return;
	}

	UpdateData();
	*pStudentID = m_Student.GetItemData(m_Student.GetCurSel());
	*pSubjectID = m_Subject.GetItemData(m_Subject.GetCurSel());
	*pScore = m_Score;
	
	CDialog::OnOK();
}

//##ModelId=40A481F401F6
void CScoreSetDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

//##ModelId=40A481F40189
void CScoreSetDlg::LoadStudent(long class_id)
{
	while(0!=m_Student.GetCount())
		m_Student.DeleteString(0);
	CString sql, s;
	s.Format("%ld", class_id);
	sql = "select * from student where class_id = " + s +" order by number";
	CDaoQueryDef QD(&theDatabase);
	QD.Create(NULL, sql);
	CDaoRecordset RS;
	RS.Open(&QD);
	int i=0;
	while(!RS.IsEOF())
	{
		s.Format("%3ld : ", RS.GetFieldValue("number").lVal);
		m_Student.AddString(s + V_BSTRT(&RS.GetFieldValue("name")));
		m_Student.SetItemData(i++, RS.GetFieldValue("id").lVal);
		RS.MoveNext();
	}
	RS.Close();
	QD.Close();
}

//##ModelId=40A481F40187
void CScoreSetDlg::LoadSubject(long class_id)
{
	while(0!=m_Subject.GetCount())
		m_Subject.DeleteString(0);
	CString sql = "SELECT subject_id, subject from teaching, subject \
				   where teaching.subject_id = subject.id and class_id = ", s;
	s.Format("%ld", class_id);
	sql += s;
	CDaoQueryDef tq(&theDatabase);
	tq.Create(NULL, sql);
	CDaoRecordset RS;
	RS.Open(&tq);
	int i=0;
	while(!RS.IsEOF())
	{
		m_Subject.AddString(V_BSTRT(&RS.GetFieldValue("subject")));
		m_Subject.SetItemData(i++, RS.GetFieldValue("subject_id").lVal);
		RS.MoveNext();
	}
	RS.Close();
	tq.Close();
}

//##ModelId=40A481F40204
BOOL CScoreSetDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	LoadStudent(ClassID);
	LoadSubject(ClassID);

	m_Student.SetCurSel(Search(m_Student, *pStudentID));
	m_Subject.SetCurSel(Search(m_Subject, *pSubjectID));

	m_Date.SetYear(COleVariant((short)pDate->GetYear()));
	m_Date.SetMonth(COleVariant((short)pDate->GetMonth()));
	m_Date.SetDay(COleVariant((short)pDate->GetDay()));

	UpdateData(false);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//##ModelId=40A481F40178
long CScoreSetDlg::Search(CListBox &list_box, long id)
{
	for(int i=0; i<list_box.GetCount(); i++)
	{
		if(id==list_box.GetItemData(i))
			return i;
	}
	return -1;
}



//##ModelId=40A481F40149
void CScoreSetDlg::SetSelectSubject(long id)
{
	long i;
	if((i=Search(m_Subject, id))!=-1)
		m_Subject.SetCurSel(i);
}

⌨️ 快捷键说明

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