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

📄 student_dlg.cpp

📁 数据库编程
💻 CPP
字号:
// Student_dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Course.h"
#include "Student_dlg.h"
#include "Manager.h"
#include "Modify_dlg.h"
#include "SC.h"
#include "Id_dlg.h"
#include "StudentCourse_dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStudent_dlg dialog


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


void CStudent_dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudent_dlg)
	DDX_Control(pDX, IDC_COURSE_LIST, m_course_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStudent_dlg, CDialog)
	//{{AFX_MSG_MAP(CStudent_dlg)
	ON_BN_CLICKED(IDC_MODIFY_BUTTON, OnModifyButton)
	ON_BN_CLICKED(IDC_ELECT_BUTTON, OnElectButton)
	ON_BN_CLICKED(IDC_UNELECT_BUTTON, OnUnelectButton)
	ON_BN_CLICKED(IDC_VIEW_BUTTON, OnViewButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudent_dlg message handlers

BOOL CStudent_dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_course_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	//为了美观起见,显示纪录时需要表格线
	LV_COLUMN h;
	
	h.mask=LVCF_FMT|LVCF_TEXT|LVCF_WIDTH;
	h.fmt=LVCFMT_CENTER;
	h.cx=80;

	h.pszText="课程号";
	m_course_list.InsertColumn(0,&h);
	h.pszText="课程名";
	m_course_list.InsertColumn(1,&h);
	h.pszText="任课老师";
	m_course_list.InsertColumn(2,&h);
	h.pszText="已选人数";
	m_course_list.InsertColumn(3,&h);
	h.pszText="限选人数";
	m_course_list.InsertColumn(4,&h);
	UpdateData(true);
	View();
	UpdateData(false);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CStudent_dlg::View()
{
	CString s;
	_RecordsetPtr m_recordset;
	CManager manager;
	m_course_list.DeleteAllItems();
	m_recordset=manager.CourseView();
	
	_variant_t vnum,vname,vteacher,vrenum,vupnum;
	while(!m_recordset->adoEOF)
	{
		vnum=m_recordset->GetCollect("课程号");
		s=(LPCTSTR)_bstr_t(vnum);
		m_course_list.InsertItem(0,s);

		vname=m_recordset->GetCollect("课程名");
		s=(LPCTSTR)_bstr_t(vname);
		m_course_list.SetItemText(0,1,s);
				
		vteacher=m_recordset->GetCollect("任课老师");
		s=(LPCTSTR)_bstr_t(vteacher);
		m_course_list.SetItemText(0,2,s);

		vrenum=m_recordset->GetCollect("已选人数");
		s=(LPCTSTR)_bstr_t(vrenum);
		m_course_list.SetItemText(0,3,s);

		vupnum=m_recordset->GetCollect("限选人数");
		s=(LPCTSTR)_bstr_t(vupnum);
		m_course_list.SetItemText(0,4,s);

		m_recordset->MoveNext();
	}
}

void CStudent_dlg::OnModifyButton() 
{
	// TODO: Add your control notification handler code here
	CManager manager;
	CModify_dlg dlg;
	if(dlg.DoModal()==IDOK)
	{
		if(strcmp(dlg.m_password2,dlg.m_password3)!=0)
			AfxMessageBox("重新确认密码错误,密码更改失败!");
		else 
		{
			if(strcmp(dlg.m_password1,student.GetPassword())!=0)
				AfxMessageBox("原始密码输入错误!");
			else
			{
				student.SetPassword(dlg.m_password2);
				manager.Modify(student);
			}
		}
	}
}

void CStudent_dlg::OnElectButton() 
{
	// TODO: Add your control notification handler code here
	CSC sc;
	CId_dlg dlg;
	CManager manager;
	if(dlg.DoModal()==IDOK)
	{
		sc.Set(student.GetNum(),dlg.m_id);
		manager.Add(sc);
	}
	View();
}

void CStudent_dlg::OnUnelectButton() 
{
	// TODO: Add your control notification handler code here
	CSC sc;
	CId_dlg dlg;
	CManager manager;
	if(dlg.DoModal()==IDOK)
	{
		sc.Set(student.GetNum(),dlg.m_id);
		if(!manager.Search(sc))
		{
			AfxMessageBox("您好,你未选过此课程!");
			return ;
		}
		manager.Delete(sc);
	}
	View();
}

void CStudent_dlg::OnViewButton() 
{
	// TODO: Add your control notification handler code here
	CStudentCourse_dlg dlg;
	dlg.student.SetNum(student.GetNum());
	if(dlg.DoModal()==IDOK)
	{}
}

⌨️ 快捷键说明

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