?? scoreadddlg.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 + -