📄 stucou.cpp
字号:
// StuCou.cpp : implementation file
//
#include "stdafx.h"
#include "教学管理系统.h"
#include "StuCou.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// StuCou dialog
StuCou::StuCou(CWnd* pParent /*=NULL*/)
: CDialog(StuCou::IDD, pParent)
{
//{{AFX_DATA_INIT(StuCou)
//}}AFX_DATA_INIT
}
void StuCou::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(StuCou)
DDX_Control(pDX, IDC_LIST1, list);
//}}AFX_DATA_MAP
}
BOOL StuCou::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD dwExStyle=LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP ;
list.SetExtendedStyle(dwExStyle);
list.InsertColumn(0,"考试时间",LVCFMT_CENTER,100);
list.InsertColumn(0,"上课地点",LVCFMT_CENTER,100);
list.InsertColumn(0,"上课时间",LVCFMT_CENTER,100);
list.InsertColumn(0,"教师号",LVCFMT_CENTER,70);
list.InsertColumn(0,"学分",LVCFMT_CENTER,50);
list.InsertColumn(0,"学时",LVCFMT_CENTER,50);
list.InsertColumn(0,"课程名称",LVCFMT_CENTER,120);
list.InsertColumn(0,"课程号",LVCFMT_CENTER,70);
listclicked=0;
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
BEGIN_MESSAGE_MAP(StuCou, CDialog)
//{{AFX_MSG_MAP(StuCou)
ON_BN_CLICKED(IDC_BUTTON_ALLCOURSE, OnButtonAllcourse)
ON_BN_CLICKED(IDC_BUTTON_PERCOURSE, OnButtonPercourse)
ON_BN_CLICKED(IDC_BUTTON_CHOICE, OnButtonChoice)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
ON_BN_CLICKED(IDC_BUTTON_RECHOICE, OnButtonRechoice)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// StuCou message handlers
void StuCou::OnCancel()
{
// TODO: Add extra cleanup here
EndDialog(0);
}
void StuCou::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
int nItem=list.GetNextItem(-1,LVNI_SELECTED);
if (nItem!=-1)
{
coursenumber=list.GetItemText(nItem,0);
credit=list.GetItemText(nItem,3);
teachernumber=list.GetItemText(nItem,4);
listclicked=1;
}
*pResult = 0;
}
void StuCou::OnButtonAllcourse()
{
// TODO: Add your control notification handler code here
int flag;
list.DeleteAllItems();
connection.Initialize();
float s1;
CString student,s,number,name,period,a,b,c,d;
student.Format("select * from 课程 order by 课程号 desc");
connection.Connect(student);
if(connection.m_pRecordset->adoEOF)
{
AfxMessageBox("没有课程资料");
connection.Unitialize();
return;
}
connection.m_pRecordset->MoveFirst();
while(!connection.m_pRecordset->adoEOF)
{
_variant_t TheValue;
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);
connection1.Initialize();
flag=0;
student.Format("select * from 教学 where 课程号='%s'" ,number);
connection1.Connect(student);
if(connection1.m_pRecordset->adoEOF)
{
flag=1;
}
if(flag==0)
{
connection1.m_pRecordset->MoveFirst();
while(!connection1.m_pRecordset->adoEOF)
{
TheValue = connection1.m_pRecordset->Fields->GetItem("职工号")->Value;
a=TheValue.bstrVal;
TheValue = connection1.m_pRecordset->Fields->GetItem("上课时间")->Value;
b=TheValue.bstrVal;
TheValue=connection1.m_pRecordset->Fields->GetItem("上课地点")->Value;
c=TheValue.bstrVal;
TheValue=connection1.m_pRecordset->Fields->GetItem("考试时间")->Value;
d=TheValue.bstrVal;
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,b);
list.SetItemText(nIndex,6,c);
list.SetItemText(nIndex,7,d);
connection1.m_pRecordset->MoveNext();
}
}
connection1.Unitialize();
connection.m_pRecordset->MoveNext();
}
connection.Unitialize();
}
void StuCou::OnButtonPercourse()
{
// TODO: Add your control notification handler code here
int flag,tag;
list.DeleteAllItems();
tag=0;
connection2.Initialize();
float s1;
CString student,s,number,name,period,a,b,c,d,teachernumber;
student.Format("select * from 选修 where 学号='%s' order by 课程号 desc",ID);
connection2.Connect(student);
if(connection2.m_pRecordset->adoEOF)
{
tag=1;
AfxMessageBox("你尚未选课!");
}
if(tag==0)
{//学生有选课信息
connection2.m_pRecordset->MoveFirst();
while(!connection2.m_pRecordset->adoEOF)
{
_variant_t TheValue;
TheValue = connection2.m_pRecordset->Fields->GetItem("课程号")->Value;
number=TheValue.bstrVal;
TheValue = connection2.m_pRecordset->Fields->GetItem("教师号")->Value;
teachernumber=TheValue.bstrVal;
connection.Initialize();
student.Format("select * from 课程 where 课程号='%s' ",number);
connection.Connect(student);
if(connection.m_pRecordset->adoEOF)
{
AfxMessageBox("没有课程资料");
connection.Unitialize();
return;
}
connection.m_pRecordset->MoveFirst();
while(!connection.m_pRecordset->adoEOF)
{
_variant_t TheValue;
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);
connection1.Initialize();
flag=0;
student.Format("select * from 教学 where 课程号='%s'and 职工号='%s'" ,number,teachernumber);
connection1.Connect(student);
if(connection1.m_pRecordset->adoEOF)
{
flag=1;
}
if(flag==0)
{
connection1.m_pRecordset->MoveFirst();
while(!connection1.m_pRecordset->adoEOF)
{
TheValue = connection1.m_pRecordset->Fields->GetItem("职工号")->Value;
a=TheValue.bstrVal;
TheValue = connection1.m_pRecordset->Fields->GetItem("上课时间")->Value;
b=TheValue.bstrVal;
TheValue=connection1.m_pRecordset->Fields->GetItem("上课地点")->Value;
c=TheValue.bstrVal;
TheValue=connection1.m_pRecordset->Fields->GetItem("考试时间")->Value;
d=TheValue.bstrVal;
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,b);
list.SetItemText(nIndex,6,c);
list.SetItemText(nIndex,7,d);
connection1.m_pRecordset->MoveNext();
}
} //if(flag==0)
connection1.Unitialize();
connection.m_pRecordset->MoveNext();
}
connection.Unitialize();
connection2.m_pRecordset->MoveNext();
}
} //if(flag==0)
connection2.Unitialize();
}
void StuCou::OnButtonChoice()
{
// TODO: Add your control notification handler code here
if(listclicked==0)
{
AfxMessageBox("请在列表中选择课程");
return;
}
CString student,sSql;
connection2.Initialize();
student.Format("select * from 选修 where 学号='%s' and 课程号='%s'",ID,coursenumber);
connection2.Connect(student);
if(!connection2.m_pRecordset->adoEOF)
{
AfxMessageBox("你已选过这门课程!");
connection2.Unitialize();
listclicked=0;
return;
}
else
{
connection2.Unitialize();
float sum=0,fen;
CString counum;
connection2.Initialize();
student.Format("select * from 选修 where 学号='%s'",ID);
connection2.Connect(student);
if(!connection2.m_pRecordset->adoEOF)
{
_variant_t TheValue;
connection2.m_pRecordset->MoveFirst();
while(!connection2.m_pRecordset->adoEOF)
{
TheValue=connection2.m_pRecordset->Fields->GetItem("课程号")->Value;
counum=TheValue.bstrVal;
connection1.Initialize();
student.Format("select * from 课程 where 课程号='%s'",counum);
connection1.Connect(student);
if(!connection1.m_pRecordset->adoEOF)
{
TheValue=connection1.m_pRecordset->Fields->GetItem("学分")->Value;
fen=TheValue.fltVal;
sum+=fen;
}
connection1.Unitialize();
connection2.m_pRecordset->MoveNext();
}
}
connection2.Unitialize();
fen=atof(credit);
if((sum+fen)>15)
{
AfxMessageBox("选修这门课程学分将超过15分!选修失败");
return;
}
connection.Initialize();
sSql.Format("select * from 选修 ");
connection.Connect(sSql);
connection.m_pRecordset->AddNew();///添加新记录
connection.m_pRecordset->PutCollect("课程号",_variant_t(coursenumber));
connection.m_pRecordset->PutCollect("学号",_variant_t(ID));
connection.m_pRecordset->PutCollect("教师号",_variant_t(teachernumber));
connection.m_pRecordset->Update();///
connection.Unitialize();
connection.Initialize();
sSql.Format("select * from 成绩");
connection.Connect(sSql);
connection.m_pRecordset->AddNew();///添加新记录
connection.m_pRecordset->PutCollect("课程号",_variant_t(coursenumber));
connection.m_pRecordset->PutCollect("学号",_variant_t(ID));
connection.m_pRecordset->PutCollect("考试成绩",_variant_t("0"));
connection.m_pRecordset->PutCollect("平时成绩",variant_t("0"));
connection.m_pRecordset->PutCollect("总评成绩",_variant_t("0"));
connection.m_pRecordset->Update();
connection.Unitialize();
MessageBox("选修 "+coursenumber+" 课程成功!");
OnButtonPercourse();
}
listclicked=0;
}
void StuCou::OnButtonRechoice()
{
// TODO: Add your control notification handler code here
CString student;
if(listclicked==0)
{
AfxMessageBox("请在列表中选择课程");
return;
}
connection2.Initialize();
student.Format("select * from 选修 where 学号='%s' and 课程号='%s'",ID,coursenumber);
connection2.Connect(student);
if(connection2.m_pRecordset->adoEOF)
{
AfxMessageBox("你没选修这门课程");
connection2.Unitialize();
listclicked=0;
return;
}
else
{
if(AfxMessageBox("确定退选该课程吗?",MB_YESNO) == IDYES)
{
connection2.m_pRecordset->Delete(adAffectCurrent);///删除当前记录
connection2.m_pRecordset->Update();
connection2.Unitialize();
connection2.Initialize();
student.Format("select * from 成绩 where 学号='%s' and 课程号='%s'",ID,coursenumber);
connection2.Connect(student);
connection2.m_pRecordset->Delete(adAffectCurrent);///删除当前记录
connection2.m_pRecordset->Update();
connection2.Unitialize();
MessageBox("退选 "+coursenumber+" 课程成功!");listclicked=0;
OnButtonPercourse();
}
listclicked=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -