?? teachmana.cpp
字號:
// TeachMana.cpp : implementation file
//
#include "stdafx.h"
#include "教學管理系統.h"
#include "TeachMana.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TeachMana dialog
TeachMana::TeachMana(CWnd* pParent /*=NULL*/)
: CDialog(TeachMana::IDD, pParent)
{
//{{AFX_DATA_INIT(TeachMana)
coursenum = _T("");
coursename = _T("");
coursetime = _T("");
courseaddress = _T("");
teachernum = _T("");
testtime = _T("");
//}}AFX_DATA_INIT
}
void TeachMana::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TeachMana)
DDX_Control(pDX, IDC_LIST1, list);
DDX_Text(pDX, IDC_TEACHMANA_COUNO, coursenum);
DDX_Text(pDX, IDC_TEACHMANA_COUNAME, coursename);
DDX_Text(pDX, IDC_TEACHMANA_CLASSTIME, coursetime);
DDX_Text(pDX, IDC_TEACHMANA_PLACE, courseaddress);
DDX_Text(pDX, IDC_TEACHMANA_TEANO, teachernum);
DDX_Text(pDX, IDC_TEACHMANA_TESTTIME, testtime);
//}}AFX_DATA_MAP
}
BOOL TeachMana::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD dwExStyle=LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP ;
list.SetExtendedStyle(dwExStyle);
list.InsertColumn(0,"考試時間",LVCFMT_CENTER,80);
list.InsertColumn(0,"上課時間",LVCFMT_CENTER,80);
list.InsertColumn(0,"上課地點",LVCFMT_CENTER,80);
list.InsertColumn(0,"教師號",LVCFMT_CENTER,70);
list.InsertColumn(0,"學分",LVCFMT_CENTER,50);
list.InsertColumn(0,"學時",LVCFMT_CENTER,50);
list.InsertColumn(0,"課程名稱",LVCFMT_CENTER,150);
list.InsertColumn(0,"課程號",LVCFMT_CENTER,70);
// TODO: 在此添加額外的初始化
return TRUE; // return TRUE unless you set the focus to a control
// 異常: OCX 屬性頁應返回 FALSE
}
BEGIN_MESSAGE_MAP(TeachMana, CDialog)
//{{AFX_MSG_MAP(TeachMana)
ON_BN_CLICKED(IDC_TEACHMANA_COUQUERY, OnTeachmanaCouquery)
ON_BN_CLICKED(IDC_TEACHMANA_TEAQUERY, OnTeachmanaTeaquery)
ON_BN_CLICKED(IDC_TEACHMANA_TEAADD, OnTeachmanaTeaadd)
ON_BN_CLICKED(IDC_TEACHMANA_TEAMODIFY, OnTeachmanaTeamodify)
ON_BN_CLICKED(IDC_TEACHMANA_TEADEL, OnTeachmanaTeadel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TeachMana message handlers
void TeachMana::OnTeachmanaCouquery()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(coursenum.IsEmpty()&&coursename.IsEmpty()){AfxMessageBox("請輸入一個查詢內容");return;}
if(!coursenum.IsEmpty()&&!coursename.IsEmpty()){AfxMessageBox("請只輸入一個查詢內容");return;}
list.DeleteAllItems();
connection.Initialize();
CString student;
if(coursename.IsEmpty())
student.Format("select * from 課程 where 課程號='%s'",coursenum);
if(coursenum.IsEmpty())
student.Format("select * from 課程 where 課程名稱='%s'",coursename);
connection.Connect(student);
if(connection.m_pRecordset->adoEOF)
{AfxMessageBox("沒有該課程的資料");
coursenum="";
coursename="";
UpdateData(FALSE);
connection.Unitialize();
return;}
connection.m_pRecordset->MoveFirst();
while(!connection.m_pRecordset->adoEOF)
{ _variant_t TheValue;
float s1;
CString number,name,period,s;
TheValue = connection.m_pRecordset->Fields->GetItem("課程號")->Value;
number=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("課程名稱")->Value;
name=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("學時")->Value;
period=TheValue.bstrVal;
TheValue=connection.m_pRecordset->Fields->GetItem("學分")->Value;
s1=TheValue.fltVal;
s.Format("%.1f",s1);
int nIndex= list.InsertItem(0,number);
list.SetItemText(nIndex,1,name );
list.SetItemText(nIndex,2,period);
list.SetItemText(nIndex,3,s);
list.SetItemText(nIndex,4,"");
list.SetItemText(nIndex,5,"");
list.SetItemText(nIndex,6,"");
list.SetItemText(nIndex,7,"");
connection.m_pRecordset->MoveNext();
}
connection.Unitialize();
}
void TeachMana::OnTeachmanaTeaquery()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(teachernum.IsEmpty()){AfxMessageBox("請輸入教師號");return;}
list.DeleteAllItems();
connection.Initialize();
CString student;
student.Format("select * from 教學 where 職工號='%s'",teachernum);
connection.Connect(student);
if(connection.m_pRecordset->adoEOF)
{AfxMessageBox("該教師尚未有教學資料");
teachernum="";
courseaddress="";
coursetime="";
testtime="";
UpdateData(FALSE);
connection.Unitialize();
return;}
connection.m_pRecordset->MoveFirst();
while(!connection.m_pRecordset->adoEOF)
{ _variant_t TheValue;
CString a,b,c,d,e;
TheValue = connection.m_pRecordset->Fields->GetItem("職工號")->Value;
a=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("課程號")->Value;
b=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("上課時間")->Value;
c=TheValue.bstrVal;
TheValue=connection.m_pRecordset->Fields->GetItem("上課地點")->Value;
d=TheValue.bstrVal;
TheValue=connection.m_pRecordset->Fields->GetItem("考試時間")->Value;
e=TheValue.bstrVal;
connection1.Initialize();
student.Format("select * from 課程 where 課程號='%s'",b);
connection1.Connect(student);
connection1.m_pRecordset->MoveFirst();
while(!connection1.m_pRecordset->adoEOF)
{ _variant_t TheValue;
float s1;
CString number,name,period,s;
TheValue = connection1.m_pRecordset->Fields->GetItem("課程號")->Value;
number=TheValue.bstrVal;
TheValue = connection1.m_pRecordset->Fields->GetItem("課程名稱")->Value;
name=TheValue.bstrVal;
TheValue = connection1.m_pRecordset->Fields->GetItem("學時")->Value;
period=TheValue.bstrVal;
TheValue=connection.m_pRecordset->Fields->GetItem("學分")->Value;
s1=TheValue.fltVal;
s.Format("%.1f",s1);
int nIndex= list.InsertItem(0,number);
list.SetItemText(nIndex,1,name );
list.SetItemText(nIndex,2,period);
list.SetItemText(nIndex,3,s);
list.SetItemText(nIndex,4,a);
list.SetItemText(nIndex,5,d);
list.SetItemText(nIndex,6,c);
list.SetItemText(nIndex,7,e);
connection1.m_pRecordset->MoveNext();
}
connection1.Unitialize();
connection.m_pRecordset->MoveNext();
}
connection.Unitialize();
}
void TeachMana::OnTeachmanaTeaadd()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(teachernum.IsEmpty()){AfxMessageBox("請輸入教師號");return;}
if(coursenum.IsEmpty()){AfxMessageBox("請輸入課程號");return;}
if(courseaddress.IsEmpty()){AfxMessageBox("請輸入上課地點");return;}
if(coursetime.IsEmpty()){AfxMessageBox("請輸入上課時間");return;}
if(testtime.IsEmpty()){AfxMessageBox("請輸入考試時間");return;}
CString teacher;
connection.Initialize();
teacher.Format("select * from 課程 where 課程號='%s'",coursenum);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{AfxMessageBox("沒有該課程資料");
connection.Unitialize();
return;}
connection.Unitialize();
connection.Initialize();
teacher.Format("select * from 教職工 where 職工號='%s'",teachernum);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{AfxMessageBox("沒有該教師資料");
connection.Unitialize();
return;}
connection.Unitialize();
connection.Initialize();
teacher.Format("select * from 教學 where 職工號='%s' and 課程號='%s'",teachernum,coursenum);
connection.Connect(teacher);
if(!(connection.m_pRecordset->adoEOF))
{AfxMessageBox("已有該記錄,不可重復錄入");
connection.Unitialize();
return;}
connection.m_pRecordset->AddNew();///添加新記錄
connection.m_pRecordset->PutCollect("職工號",_variant_t(teachernum));
connection.m_pRecordset->PutCollect("課程號",_variant_t(coursenum));
connection.m_pRecordset->PutCollect("上課時間",_variant_t(coursetime));
connection.m_pRecordset->PutCollect("上課地點",_variant_t(courseaddress));
connection.m_pRecordset->PutCollect("考試時間",_variant_t(testtime));
connection.m_pRecordset->Update();///
connection.Unitialize();
MessageBox("錄入成功");
OnTeachmanaTeaquery();
}
void TeachMana::OnTeachmanaTeamodify()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(teachernum.IsEmpty()){AfxMessageBox("請輸入教師號");return;}
if(coursenum.IsEmpty()){AfxMessageBox("請輸入課程號");return;}
if(courseaddress.IsEmpty()){AfxMessageBox("請輸入上課地點");return;}
if(coursetime.IsEmpty()){AfxMessageBox("請輸入上課時間");return;}
if(testtime.IsEmpty()){AfxMessageBox("請輸入考試時間");return;}
CString teacher;
connection.Initialize();
teacher.Format("select * from 課程 where 課程號='%s'",coursenum);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{AfxMessageBox("沒有該課程資料");
connection.Unitialize();
return;}
connection.Unitialize();
connection.Initialize();
teacher.Format("select * from 教職工 where 職工號='%s'",teachernum);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{AfxMessageBox("沒有該教師資料");
connection.Unitialize();
return;}
connection.Unitialize();
connection.Initialize();
teacher.Format("select * from 教學 where 職工號='%s' and 課程號='%s'",teachernum,coursenum);
connection.Connect(teacher);
if((connection.m_pRecordset->adoEOF))
{AfxMessageBox("沒有該記錄,修改失敗");
connection.Unitialize();
return;}
connection.m_pRecordset->Fields->GetItem(_variant_t("上課地點"))->Value=_bstr_t(courseaddress);
connection.m_pRecordset->Fields->GetItem(_variant_t("上課時間"))->Value=_bstr_t(coursetime);
connection.m_pRecordset->Fields->GetItem(_variant_t("考試時間"))->Value=_bstr_t(testtime);
connection.m_pRecordset->Update();
connection.Unitialize();
MessageBox("資料修改成功");
OnTeachmanaTeaquery();
}
void TeachMana::OnTeachmanaTeadel()
{
// TODO: Add your control notification handler code here
CString sSql;
UpdateData(TRUE);
if(teachernum.IsEmpty())
{AfxMessageBox("請輸入教師號");return;}
if(coursenum.IsEmpty())
{AfxMessageBox("請輸入課程號");return;}
connection.Initialize();
sSql.Format("select * from 教學 where 職工號='%s'and 課程號='%s'",teachernum,coursenum);
connection.Connect(sSql);
if((connection.m_pRecordset->adoEOF))
{AfxMessageBox("沒有該資料,刪除失敗");
connection.Unitialize();
return;}
if(AfxMessageBox("確定刪除該記錄嗎?",MB_YESNO) == IDYES)
{connection.m_pRecordset->Delete(adAffectCurrent);///刪除當前記錄
connection.m_pRecordset->Update();///
connection.Unitialize();
connection.Initialize();
sSql.Format("select * from 選修 where 教師號='%s'and 課程號='%s'",teachernum,coursenum);
connection.Connect(sSql);
while(!connection.m_pRecordset->adoEOF)
{ _variant_t TheValue;
CString num,coursenumber;
TheValue = connection.m_pRecordset->Fields->GetItem("學號")->Value;
num=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("課程號")->Value;
coursenumber=TheValue.bstrVal;
connection.m_pRecordset->Delete(adAffectCurrent);///刪除當前記錄
connection.m_pRecordset->Update();
connection1.Initialize();
sSql.Format("select * from 成績 where 學號='%s'and 課程號='%s'",num,coursenumber);
connection1.Connect(sSql);
if(!(connection1.m_pRecordset->adoEOF))
{ connection1.m_pRecordset->Delete(adAffectCurrent);///刪除當前記錄
connection1.m_pRecordset->Update();///
}
connection1.Unitialize();
connection.m_pRecordset->MoveNext();
}
connection.Unitialize();
MessageBox("刪除成功");
OnTeachmanaTeaquery();
coursenum="";
coursename="";
teachernum="";
courseaddress="";
coursetime="";
testtime="";
UpdateData(FALSE);
}
}
void TeachMana::OnCancel()
{
// TODO: Add extra cleanup here
EndDialog(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -