📄 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 + -