?? coursedlg.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 + -