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

📄 coursedlg.cpp

📁 此程序是一个简单的学生管理系统
💻 CPP
字号:
// CourseDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StuManage.h"
#include "CourseDlg.h"
#include "Columns.h"
#include "Column.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCourseDlg dialog

extern CStuManageApp theApp;

CCourseDlg::CCourseDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCourseDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCourseDlg)
	m_strCourseHour = _T("");
	m_strCourseId = _T("");
	m_strCourseName = _T("");
	m_strCoursePeriod = _T("");
	m_strCoursePlace = _T("");
	m_strCourseTeacher = _T("");
	//}}AFX_DATA_INIT
}

void CCourseDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCourseDlg)
	DDX_Control(pDX, IDC_DATAGRID_COURSE, m_dgCourse);
	DDX_Text(pDX, IDC_EDIT_COURSE_CREDITHOUR, m_strCourseHour);
	DDX_Text(pDX, IDC_EDIT_COURSE_ID, m_strCourseId);
	DDX_Text(pDX, IDC_EDIT_COURSE_NAME, m_strCourseName);
	DDX_Text(pDX, IDC_EDIT_COURSE_PERIOD, m_strCoursePeriod);
	DDX_Text(pDX, IDC_EDIT_COURSE_PLACE, m_strCoursePlace);
	DDX_Text(pDX, IDC_EDIT_COURSE_TEACHER, m_strCourseTeacher);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCourseDlg, CDialog)
	//{{AFX_MSG_MAP(CCourseDlg)
	ON_BN_CLICKED(IDC_ADD_COURSE_BTN, OnAddCourseBtn)
	ON_BN_CLICKED(ID_COURSE_EXECUTE, OnCourseExecute)
	ON_BN_CLICKED(IDC_DEL_COURSE_BTN, OnDelCourseBtn)
	ON_BN_CLICKED(IDC_MODIFY_COURSE_BTN, OnModifyCourseBtn)
	ON_EN_CHANGE(IDC_EDIT_COURSE_ID, OnChangeEditCourseId)
	ON_BN_CLICKED(IDC_LOOKFOR_COURSE_BTN, OnLookforCourseBtn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCourseDlg message handlers

BOOL CCourseDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	type = 0;
	
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open("SELECT * FROM Course",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       
	
	m_dgCourse.SetRefDataSource(NULL);
	m_dgCourse.SetRefDataSource((LPUNKNOWN)m_pRecordset);
	m_dgCourse.SetColumnHeaders(2) ;
	
	_variant_t var;
	var = long(0);
	m_dgCourse.GetColumns().GetItem(var).SetCaption("课程编号");
	m_dgCourse.GetColumns().GetItem(var).SetWidth(60);
	var = long(1);
	m_dgCourse.GetColumns().GetItem(var).SetCaption("课程名称");
	m_dgCourse.GetColumns().GetItem(var).SetWidth(50);
	var = long(2);
	m_dgCourse.GetColumns().GetItem(var).SetCaption("学时");
	m_dgCourse.GetColumns().GetItem(var).SetWidth(30);
	var = long(3);
	m_dgCourse.GetColumns().GetItem(var).SetCaption("学分");
	m_dgCourse.GetColumns().GetItem(var).SetWidth(30);
	var = long(4);
	m_dgCourse.GetColumns().GetItem(var).SetCaption("任课教师");
	m_dgCourse.GetColumns().GetItem(var).SetWidth(50);
	var = long(5);
	m_dgCourse.GetColumns().GetItem(var).SetCaption("上课地点");
	m_dgCourse.GetColumns().GetItem(var).SetWidth(100);

	m_dgCourse.Refresh();

/*	if(m_pRecordset->GetRecordCount()!=0)
	{
		m_pRecordset->MoveFirst();
		m_strCourseId = m_pRecordset->GetCollect("CourseId").bstrVal;
		m_strCourseName = m_pRecordset->GetCollect("CourseName").bstrVal;
		m_strCoursePeriod = m_pRecordset->GetCollect("Period").bstrVal;
		m_strCourseHour = m_pRecordset->GetCollect("CreditHour").bstrVal;
		m_strCourseTeacher = m_pRecordset->GetCollect("Teacher").bstrVal;
		m_strCoursePlace = m_pRecordset->GetCollect("ClassPlace").bstrVal;	
	}*/
	
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BEGIN_EVENTSINK_MAP(CCourseDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CCourseDlg)
	ON_EVENT(CCourseDlg, IDC_DATAGRID_COURSE, 221 /* SelChange */, OnSelChangeDatagridCourse, VTS_PI2)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CCourseDlg::OnAddCourseBtn() 
{
	// TODO: Add your control notification handler code here
	if(theApp.m_Level != 2)
	{
		AfxMessageBox("您无权添加课程");
		return;
	}
	m_strCourseId = "";
	m_strCourseName = "";
	m_strCoursePeriod = "";
	m_strCourseHour = "";
	m_strCourseTeacher = "";
	m_strCoursePlace = "";	

	UpdateData(FALSE);
	AfxMessageBox("请输入新课程的信息");
	type = 1;
}

void CCourseDlg::OnDelCourseBtn() 
{
	// TODO: Add your control notification handler code here
	if(theApp.m_Level != 2)
	{
		AfxMessageBox("您无权删减课程");
		return;
	}
	if(AfxMessageBox("确定删除此课程吗?",MB_YESNO)==IDYES)
		type = 2;
}

void CCourseDlg::OnModifyCourseBtn() 
{
	// TODO: Add your control notification handler code here
	if(theApp.m_Level != 2)
	{
		AfxMessageBox("您无权修改课程");
		return;
	}
	if(AfxMessageBox("确定修改此课程吗?",MB_YESNO)==IDYES)	
		type = 3;
}


void CCourseDlg::OnCourseExecute() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	CString id;
	CString sql;
	sql = "select * from Course ";
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);      

	switch(type)
	{
	case 1:		
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("CourseId",(_variant_t)m_strCourseId);
		m_pRecordset->PutCollect("CourseName",(_variant_t)m_strCourseName);
		m_pRecordset->PutCollect("Period",(_variant_t)m_strCoursePeriod);
		m_pRecordset->PutCollect("CreditHour",(_variant_t)m_strCourseHour);
		m_pRecordset->PutCollect("Teacher",(_variant_t)m_strCourseTeacher);
		m_pRecordset->PutCollect("ClassPlace",(_variant_t)m_strCoursePlace);		
		m_pRecordset->Update();
		break;
	case 2:	
		if(m_pRecordset->GetRecordCount()!=0)
		{
			m_pRecordset->MoveFirst();
			while(!m_pRecordset->adoEOF)
			{
				id=m_pRecordset->GetCollect("CourseId").bstrVal;
				if(id.CompareNoCase(m_strCourseId) == 0)
					m_pRecordset->Delete(adAffectCurrent);
				m_pRecordset->MoveNext();			
			}
		}
		break;
	case 3:			
		if(m_pRecordset->GetRecordCount()!=0)
		{
			m_pRecordset->MoveFirst();
			while(!m_pRecordset->adoEOF)
			{
				id=m_pRecordset->GetCollect("CourseId").bstrVal;
				if(id.CompareNoCase(m_strCourseId) == 0)
				{
					m_pRecordset->PutCollect("CourseName",(_variant_t)m_strCourseName);
					m_pRecordset->PutCollect("Period",(_variant_t)m_strCoursePeriod);
					m_pRecordset->PutCollect("CreditHour",(_variant_t)m_strCourseHour);
					m_pRecordset->PutCollect("Teacher",(_variant_t)m_strCourseTeacher);
					m_pRecordset->PutCollect("ClassPlace",(_variant_t)m_strCoursePlace);					
				}
				m_pRecordset->MoveNext();			
			}
		}		
		break;		
	default:
		break;
	}
	type = 0;
	m_pRecordset->Close();
	OnInitDialog();
}


void CCourseDlg::OnSelChangeDatagridCourse(short FAR* Cancel) 
{
	// TODO: Add your control notification handler code here
	CString str=m_dgCourse.GetText();//表示第一列的数据

	CString sql;
	sql = "select * from Course where CourseID = '"+str+"'";
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);      

	if(m_pRecordset->GetRecordCount()!=0)
	{
		m_strCourseId = m_pRecordset->GetCollect("CourseId").bstrVal;
		m_strCourseName = m_pRecordset->GetCollect("CourseName").bstrVal;
		m_strCoursePeriod = m_pRecordset->GetCollect("Period").bstrVal;
		m_strCourseHour = m_pRecordset->GetCollect("CreditHour").bstrVal;
		m_strCourseTeacher = m_pRecordset->GetCollect("Teacher").bstrVal;
		m_strCoursePlace = m_pRecordset->GetCollect("ClassPlace").bstrVal;
	}
	
	UpdateData(FALSE);
	m_pRecordset->Close();
}

void CCourseDlg::OnChangeEditCourseId() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	CString sql;
	sql = "select * from Course where CourseID = '"+m_strCourseId+"'";
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);      

	if(m_pRecordset->GetRecordCount()!=0)
	{
		m_strCourseName = m_pRecordset->GetCollect("CourseName").bstrVal;
		m_strCoursePeriod = m_pRecordset->GetCollect("Period").bstrVal;
		m_strCourseHour = m_pRecordset->GetCollect("CreditHour").bstrVal;
		m_strCourseTeacher = m_pRecordset->GetCollect("Teacher").bstrVal;
		m_strCoursePlace = m_pRecordset->GetCollect("ClassPlace").bstrVal;
	}
	
	UpdateData(FALSE);
	m_pRecordset->Close();
}

void CCourseDlg::OnLookforCourseBtn() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("请输入您要查找的课程编号");
}

⌨️ 快捷键说明

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