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

📄 scoreadddlg.cpp

📁 student manage system
💻 CPP
字号:
// ScoreAddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StudentScore.h"
#include "ScoreAddDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CScoreAddDlg dialog


CScoreAddDlg::CScoreAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CScoreAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScoreAddDlg)
	//}}AFX_DATA_INIT
}


void CScoreAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScoreAddDlg)
	DDX_Control(pDX, IDC_SCORE_STUDENT, m_cStudent);
	DDX_Control(pDX, IDC_SCORE_SCORE, m_cScore);
	DDX_Control(pDX, IDC_SCORE_COURSE, m_cCourse);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CScoreAddDlg message handlers

void CScoreAddDlg::OnOK() //确定按钮事件
{
	CString student,course,score,student_no,course_no;
	//分别获得控件中的值
	m_cStudent.GetWindowText(student);
	m_cCourse.GetWindowText(course);
    m_cScore.GetWindowText(score);
	if(score=="")//如果输入的成绩为空,怎提示输入成绩
	{
		MessageBox("请输入成绩!");
	}
	else//成绩不为空
	{
		CString strSQL;
		//查出该学生的学号
		strSQL.Format("select * from student where active_status='Y' and student_name='%s'",student);
		CRecordset m_recordSet=&m_database;
		m_recordSet.Open(CRecordset::forwardOnly,strSQL);
        m_recordSet.GetFieldValue("student_no",student_no);
		m_recordSet.Close();
		//查出该课程的课程号 
        strSQL.Format("select * from course where active_status='Y' and course_name='%s'",course);
		m_recordSet.Open(CRecordset::forwardOnly,strSQL);
        m_recordSet.GetFieldValue("course_no",course_no);;
		m_recordSet.Close();
		//如果id为0,则认为是添加记录
		if(this->id=="0")
		{
			//添加SQL语句
			strSQL.Format("insert into score(student_no,course_no,score,active_status) values('%s','%s',%s,'Y')",student_no,course_no,score);
			//执行添加操作
			m_database.ExecuteSQL(strSQL);
		}
		else//否则为修改记录
		{
			//修改SQL语句
			strSQL.Format("update score set student_no='%s',course_no='%s',score=%s where score_id=%s",student_no,course_no,score,id);
			//执行修改操作
			m_database.ExecuteSQL(strSQL);
		}
		CDialog::OnOK();
	}
}

BOOL CScoreAddDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	//如果没有打开数据库,则打开数据库
	CRecordset m_recordSet;
	if(!m_database.IsOpen())
	{
		m_database.Open(_T("studentscore"));
	    m_recordSet.m_pDatabase=&m_database;
	}
    //初始化课程下拉列表数据
	CString strSQL;
	strSQL.Format("select course_name from course where active_status='Y'");
    m_recordSet.Open(CRecordset::forwardOnly,strSQL);
	for(int i=0;i<m_recordSet.GetRecordCount();i++){
		CString temp;
		m_recordSet.GetFieldValue("course_name",temp);
		m_cCourse.AddString(temp);
        m_recordSet.MoveNext();
	}
	m_recordSet.Close();
    m_cCourse.SetCurSel(1);
    //初始化学生下拉列表
	strSQL.Format("select student_name from student where active_status='Y'");
    m_recordSet.Open(CRecordset::forwardOnly,strSQL);
	for(int j=0;j<m_recordSet.GetRecordCount();j++){
		CString temp;
		m_recordSet.GetFieldValue("student_name",temp);
		m_cStudent.AddString(temp);
        m_recordSet.MoveNext();
	}
	m_recordSet.Close();
    m_cStudent.SetCurSel(1);
	//如果为修改状态
	if(id!="0")
	{
		this->SetWindowText("修改成绩窗口");//设置窗口标题为修改成绩窗口
		//并初始化控件中的值
		strSQL.Format("select course.course_name,student.student_name,score.score from student,course,score where score.active_status='Y' and score.student_no=student.student_no and course.course_no=score.course_no and score_id=%s",id);
        m_recordSet.Open(CRecordset::forwardOnly,strSQL);
		CString temp;
		m_recordSet.GetFieldValue("student_name",temp);
		m_cStudent.SelectString(0,temp);
        m_recordSet.GetFieldValue("course_name",temp);
        m_cCourse.SelectString(0,temp);
		m_recordSet.GetFieldValue("score",temp);
		m_cScore.SetWindowText(temp);
	}
	else//如果为添加状态
	{
		//设置窗口标题为添加窗口状态
		this->SetWindowText("添加成绩窗口");
	}
	return true;

}

void CScoreAddDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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