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

📄 collegemdlg.cpp

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

#include "stdafx.h"
#include "Student.h"
#include "CollegeMdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCollegeMdlg dialog


CCollegeMdlg::CCollegeMdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCollegeMdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCollegeMdlg)
	m_coll_no = _T("");
	m_intro = _T("");
	m_name = _T("");
	m_phone = _T("");
	m_president = _T("");
	//}}AFX_DATA_INIT
}


void CCollegeMdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCollegeMdlg)
	DDX_Text(pDX, IDC_EDIT_COLL_NO, m_coll_no);
	DDV_MaxChars(pDX, m_coll_no, 2);
	DDX_Text(pDX, IDC_EDIT_INTRODC, m_intro);
	DDV_MaxChars(pDX, m_intro, 1024);
	DDX_Text(pDX, IDC_EDIT_NAME, m_name);
	DDV_MaxChars(pDX, m_name, 40);
	DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
	DDV_MaxChars(pDX, m_phone, 7);
	DDX_Text(pDX, IDC_EDIT_PRESIDET, m_president);
	DDV_MaxChars(pDX, m_president, 4);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCollegeMdlg, CDialog)
	//{{AFX_MSG_MAP(CCollegeMdlg)
	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()

/////////////////////////////////////////////////////////////////////////////
// CCollegeMdlg message handlers

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

void CCollegeMdlg::OnBtnPrev() 
{
	// TODO: Add your control notification handler code here
	m_pCollege->MovePrev();
	UpdateField(FALSE);
}

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

void CCollegeMdlg::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 CCollegeMdlg::OnBtnReturn() 
{
	// TODO: Add your control notification handler code here
	UpdateField(FALSE);
}

BOOL CCollegeMdlg::OnInitDialog() //**
{
	CString strSQL;
	BOOL Success;
	CCollegeSet rs;

	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	try{
		strSQL="select college_no,name,phone,president,introduction from College";
		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 CCollegeMdlg::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.College set "+strExpress;
		strExpress.Format("College_no=\'%s\'",m_coll_no);
		strSQL+=","+strExpress;
		strExpress.Format("President=\'%s\'",m_president);
		strSQL+=","+strExpress;
		strExpress.Format("Phone=\'%s\'",m_phone);
		strSQL+=","+strExpress;
		strExpress.Format("Introduction=\'%s\'",m_intro);
		strSQL+=","+strExpress;
		m_pDB->ExecuteSQL(strSQL);
		m_pCollege->Requery();
		UpdateField(FALSE);
	}
	else
	{
		m_pCollege->GetFieldValue("COLLEGE_NO",m_coll_no);
		m_pCollege->GetFieldValue("NAME",m_name);
		//m_name.TrimRight();

		m_pCollege->GetFieldValue("PHONE",m_phone);
		m_pCollege->GetFieldValue("PRESIDENT",m_president);
		m_pCollege->GetFieldValue("INTRODUCTION",m_intro);
		this->UpdateData(bSave);
	}
}

⌨️ 快捷键说明

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