📄 stucoursemdlg.cpp
字号:
// StuCourseMdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "StuCourseMdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStuCourseMdlg dialog
CStuCourseMdlg::CStuCourseMdlg(CWnd* pParent /*=NULL*/)
: CDialog(CStuCourseMdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStuCourseMdlg)
m_course = _T("");
m_stu_no = _T("");
m_score = 0;
//}}AFX_DATA_INIT
}
void CStuCourseMdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStuCourseMdlg)
DDX_Text(pDX, IDC_EDIT_COURSE_NO, m_course);
DDV_MaxChars(pDX, m_course, 13);
DDX_Text(pDX, IDC_EDIT_NO, m_stu_no);
DDV_MaxChars(pDX, m_stu_no, 8);
DDX_Text(pDX, IDC_EDIT_SCORE, m_score);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStuCourseMdlg, CDialog)
//{{AFX_MSG_MAP(CStuCourseMdlg)
ON_BN_CLICKED(IDC_BTN_NEXTI, OnBtnNexti)
ON_BN_CLICKED(IDC_BTN_PREV, OnBtnPrev)
ON_BN_CLICKED(IDC_BTN_RETURN, OnBtnReturn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStuCourseMdlg message handlers
void CStuCourseMdlg::OnBtnNexti()
{
// TODO: Add your control notification handler code here
m_pStu_course->MoveNext();
if(m_pStu_course->IsEOF())
m_pStu_course->MoveLast();
UpdateField(FALSE);
}
void CStuCourseMdlg::OnBtnPrev()
{
// TODO: Add your control notification handler code here
m_pStu_course->MovePrev();
UpdateField(FALSE);
}
void CStuCourseMdlg::OnBtnReturn()
{
// TODO: Add your control notification handler code here
UpdateField(FALSE);
}
void CStuCourseMdlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CStuCourseMdlg::OnOK()
{
// TODO: Add extra validation here
CModifydlg modify;
int result=modify.DoModal();
if(result == IDCANCEL)
return;
if(m_kind == 1)//教师
UpdateField(true);
else MessageBox("你无权修改数据!");
CDialog::OnOK();
}
BOOL CStuCourseMdlg::OnInitDialog()
{
CString strSQL;
BOOL Success;
CStuCourseSet rs;
CDialog::OnInitDialog();
// TODO: Add extra initialization here
try{
strSQL="select Stu_no,Course_no,Score from Stu_course";
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(!Success)
{
MessageBox("学生选课表打开失败!");
this->OnCancel();
return TRUE;
}
UpdateField(FALSE);
rs.Close();
}
catch(CDBException *pe){
AfxMessageBox(pe->m_strError);
pe->Delete();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStuCourseMdlg::UpdateField(BOOL bSave)
{
CString strTemp;
CString strExpress,strSQL,strField;
CMyRecord mr;
if(bSave)
{
this->UpdateData(true);
strExpress.Format("stu_no=\'%s\'",m_stu_no);
strSQL="update group1.Stu_course set "+strExpress;
strExpress.Format("Course_no=\'%s\'",m_course);
strSQL+=","+strExpress;
m_pStu_course->GetFieldValue("INPUTTIMT",strTemp);
int Inputyear=atoi(strTemp.Left(4));
int Inputmonth=atoi(strTemp.Mid(5,2));
int Inputday=atoi(strTemp.Right(2));
if(mr.IsDate(Inputyear,Inputmonth,Inputday,2)) //两周后不能改
{
strExpress.Format("Score=\'%d\'",m_score);
strSQL+=","+strExpress;
}
m_pDB->ExecuteSQL(strSQL);
m_pStu_course->Requery();
UpdateField(FALSE);
}
else
{
m_pStu_course->GetFieldValue("STU_NO",m_stu_no);
m_pStu_course->GetFieldValue("COURSE_NO",m_course);
m_pStu_course->GetFieldValue("SCORE",strTemp);
m_score=atoi(strTemp);
this->UpdateData(bSave);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -