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

📄 coursemdlg.cpp

📁 这是一个学生管理系统 包含学生基本信息 选课信息 宿舍信息 教师信息 课程信息 班机信息 教师信息等录入 查询 修改删除等强大功能
💻 CPP
字号:
// CourseMdlg.cpp : implementation file
//

#include "stdafx.h"
#include "Student.h"
#include "CourseMdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCourseMdlg dialog


CCourseMdlg::CCourseMdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCourseMdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCourseMdlg)
	m_course = _T("");
	m_name = _T("");
	m_kind = _T("");
	m_intro = _T("");
	m_credit = 0;
	//}}AFX_DATA_INIT
}


void CCourseMdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCourseMdlg)
	DDX_Text(pDX, IDC_EDIT_NO, m_course);
	DDV_MaxChars(pDX, m_course, 13);
	DDX_Text(pDX, IDC_EDIT_NAME, m_name);
	DDV_MaxChars(pDX, m_name, 20);
	DDX_Text(pDX, IDC_EDIT_KIND, m_kind);
	DDV_MaxChars(pDX, m_kind, 1);
	DDX_Text(pDX, IDC_EDIT_INTRODC, m_intro);
	DDV_MaxChars(pDX, m_intro, 1024);
	DDX_Text(pDX, IDC_EDIT_CREDIT, m_credit);
	DDV_MinMaxInt(pDX, m_credit, 0, 100);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCourseMdlg, CDialog)
	//{{AFX_MSG_MAP(CCourseMdlg)
	ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
	ON_BN_CLICKED(IDC_BTN_PREV, OnBtnPrev)
	ON_BN_CLICKED(IDC_BTN_RETURN, OnBtnReturn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCourseMdlg message handlers

void CCourseMdlg::OnBtnNext() 
{
	// TODO: Add your control notification handler code here
	m_pCourse->MovePrev();
	UpdateField(FALSE);
}

void CCourseMdlg::OnBtnPrev() 
{
	// TODO: Add your control notification handler code here
	m_pCourse->MoveNext();
	if(m_pCourse->IsEOF())
		m_pCourse->MoveLast();
	UpdateField(FALSE);
}

void CCourseMdlg::OnOK() 
{
	// TODO: Add extra validation here
	CModifydlg modify;
	int result=modify.DoModal();
	if(result == IDCANCEL)
		return;
	if(m_kind == 1)//教师
		UpdateField(true);
	else MessageBox("你无权修改数据!");
}

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

void CCourseMdlg::OnBtnReturn() 
{
	// TODO: Add your control notification handler code here
	UpdateField(FALSE);
}

BOOL CCourseMdlg::OnInitDialog() //**
{
	CString strSQL;
	BOOL Success;
	CCourseSet rs;
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	try{
		strSQL="select Course_no,name,kind,Introduction,Credit from Course";
		Success=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 CCourseMdlg::UpdateField(BOOL bSave)
{
	CString strTemp;
	CString strExpress,strSQL,strField;

	if(bSave)
	{
		this->UpdateData(bSave);

		m_name.TrimRight();
		strExpress.Format("name=\'%s\'",m_name);
		strSQL="update group1.Course set "+strExpress;
		strExpress.Format("course_no=\'%s\'",m_course);
		strSQL+=","+strExpress;
		strExpress.Format("Kind=\'%s\'",m_kind);
		strSQL+=","+strExpress;
		strExpress.Format("Credit=\'%d\'",m_credit);
		strSQL+=","+strExpress;
		strExpress.Format("score=%s",m_intro);
		strSQL+=","+strExpress;
		//MessageBox(strSQL);
		m_pDB->ExecuteSQL(strSQL);
		m_pCourse->Requery();
		UpdateField(FALSE);
	}
	else
	{
		m_pCourse->GetFieldValue("COURSE_NO",m_course);
		m_pCourse->GetFieldValue("NAME",m_name);
		m_name.TrimRight();

		m_pCourse->GetFieldValue("KIND",m_kind);
		m_pCourse->GetFieldValue("CREDIT",strTemp);
		m_pCourse->GetFieldValue("INTRODUCTION",m_intro);
        m_credit=atoi(strTemp);
		this->UpdateData(bSave);
	}
}


⌨️ 快捷键说明

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