📄 teainfomana.cpp
字号:
// TeaInfoMana.cpp : implementation file
//
#include "stdafx.h"
#include "教学管理系统.h"
#include "TeaInfoMana.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TeaInfoMana dialog
TeaInfoMana::TeaInfoMana(CWnd* pParent /*=NULL*/)
: CDialog(TeaInfoMana::IDD, pParent)
{
//{{AFX_DATA_INIT(TeaInfoMana)
number = _T("");
direct = _T("");
sdeptnumber = _T("");
sex = _T("");
post = _T("");
name = _T("");
speciality = _T("");
birth = _T("");
inputnumber = _T("");
//}}AFX_DATA_INIT
}
void TeaInfoMana::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TeaInfoMana)
DDX_Text(pDX, IDC_TEAINFOMANA_NO, number);
DDX_Text(pDX, IDC_TEAINFOMANA_POSITION, direct);
DDX_Text(pDX, IDC_TEAINFOMANA_SDEPT, sdeptnumber);
DDX_Text(pDX, IDC_TEAINFOMANA_SEX, sex);
DDX_Text(pDX, IDC_TEAINFOMANA_WORK, post);
DDX_Text(pDX, IDC_TEAINFOMANA_NAME, name);
DDX_Text(pDX, IDC_TEAINFOMANA_MAJOR, speciality);
DDX_Text(pDX, IDC_TEAINFOMANA_DATE, birth);
DDX_Text(pDX, IDC_TEAINFOMANA_INPUT, inputnumber);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(TeaInfoMana, CDialog)
//{{AFX_MSG_MAP(TeaInfoMana)
ON_BN_CLICKED(IDC_TEAINFOMANA_QUERY, OnTeainfomanaQuery)
ON_BN_CLICKED(IDC_TEAINFOMANA_ADD, OnTeainfomanaAdd)
ON_BN_CLICKED(IDC_TEAINFOMANA_MODIFY, OnTeainfomanaModify)
ON_BN_CLICKED(IDC_TEAINFOMANA_DELETE, OnTeainfomanaDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TeaInfoMana message handlers
void TeaInfoMana::OnTeainfomanaQuery()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(inputnumber.IsEmpty())
{
AfxMessageBox("请输入职工号");
return;
}
connection.Initialize();
CString teacher;
teacher.Format("select * from 教职工 where 职工号='%s'",inputnumber);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{
AfxMessageBox("没有该职工的资料");
number="";
name="";
sex="";
birth="";
post="";
sdeptnumber="";
speciality="";
direct="";
UpdateData(FALSE);
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;
sex=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("出生日期")->Value;
birth=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("职称")->Value;
post=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("所在系号")->Value;
sdeptnumber=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("专业")->Value;
speciality=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("教学方向")->Value;
direct=TheValue.bstrVal;
UpdateData(FALSE);
connection.m_pRecordset->MoveNext();
}
connection.Unitialize();
}
void TeaInfoMana::OnTeainfomanaAdd()
{
// TODO: Add your control notification handler code here
CString teacher;
UpdateData(TRUE);
if(number.IsEmpty())
{
AfxMessageBox("请输入职工号");
return;
}
if(name.IsEmpty())
{
name="空";
}
if(sex.IsEmpty())
sex="空";
if(birth.IsEmpty())
birth="空";
if(post.IsEmpty())
post="空";
if(sdeptnumber.IsEmpty())
sdeptnumber="空";
if(speciality.IsEmpty())
speciality="空";
if(direct.IsEmpty())
direct="空";
connection.Initialize();
teacher.Format("select * from 系 where 系号='%s'",sdeptnumber);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{
AfxMessageBox("没有该系资料");
connection.Unitialize();
return;
}
connection.Unitialize();
connection.Initialize();
teacher.Format("select * from 教职工 where 职工号='%s'",number);
connection.Connect(teacher);
if(!(connection.m_pRecordset->adoEOF))
{
AfxMessageBox("已有该职工号的资料,不可重复录入");
connection.Unitialize();
return;
}
connection.m_pRecordset->AddNew();///添加新记录
connection.m_pRecordset->PutCollect("职工号",_variant_t(number));
connection.m_pRecordset->PutCollect("姓名",_variant_t(name));
connection.m_pRecordset->PutCollect("性别",_variant_t(sex));
connection.m_pRecordset->PutCollect("出生日期",_variant_t(birth));
connection.m_pRecordset->PutCollect("职称",_variant_t(post));
connection.m_pRecordset->PutCollect("所在系号",_variant_t(sdeptnumber));
connection.m_pRecordset->PutCollect("专业",_variant_t(speciality));
connection.m_pRecordset->PutCollect("教学方向",_variant_t(direct));
connection.m_pRecordset->Update();
connection.Unitialize();
MessageBox("职工录入成功");
}
void TeaInfoMana::OnTeainfomanaModify()
{
// TODO: Add your control notification handler code here
CString teacher;
UpdateData(TRUE);
if(number.IsEmpty())
{
AfxMessageBox("请输入职工号");
return;
}
if(name.IsEmpty())
{
AfxMessageBox("请输入职工姓名");
return;
}
if(sex.IsEmpty())
{
AfxMessageBox("请输入职工性别");
return;
}
if(birth.IsEmpty())
{
AfxMessageBox("请输入职工出生日期");
return;
}
if(post.IsEmpty())
{
AfxMessageBox("请输入职称");
return;
}
if(sdeptnumber.IsEmpty())
{
AfxMessageBox("请输入所在系号");
return;
}
if(speciality.IsEmpty())
{
AfxMessageBox("请输入专业");
return;
}
if(direct.IsEmpty())
{
AfxMessageBox("请输入教学方向");
return;
}
connection.Initialize();
teacher.Format("select * from 系 where 系号='%s'",sdeptnumber);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{
AfxMessageBox("没有该系资料");
connection.Unitialize();
return;
}
connection.Unitialize();
connection.Initialize();
teacher.Format("select * from 教职工 where 职工号='%s'",number);
connection.Connect(teacher);
if(connection.m_pRecordset->adoEOF)
{
AfxMessageBox("没有该职工的资料,修改失败");
connection.Unitialize();
return;
}
connection1.Initialize();
teacher.Format("select * from 系 where 系号='%s'",sdeptnumber);
connection1.Connect(teacher);
if(connection1.m_pRecordset->adoEOF)
{
AfxMessageBox("没有该系资料");
connection1.Unitialize();
return;
}
connection1.Unitialize();
connection.m_pRecordset->Fields->GetItem(_variant_t("职工号"))->Value=_bstr_t(number);
connection.m_pRecordset->Fields->GetItem(_variant_t("姓名"))->Value=_bstr_t(name);
connection.m_pRecordset->Fields->GetItem(_variant_t("性别"))->Value=_bstr_t(sex);
connection.m_pRecordset->Fields->GetItem(_variant_t("出生日期"))->Value=_bstr_t(birth);
connection.m_pRecordset->Fields->GetItem(_variant_t("职称"))->Value=_bstr_t(post);
connection.m_pRecordset->Fields->GetItem(_variant_t("所在系号"))->Value=_bstr_t(sdeptnumber);
connection.m_pRecordset->Fields->GetItem(_variant_t("专业"))->Value=_bstr_t(speciality);
connection.m_pRecordset->Fields->GetItem(_variant_t("教学方向"))->Value=_bstr_t(direct);
connection.m_pRecordset->Update();
MessageBox("资料修改成功");
connection.Unitialize();
}
void TeaInfoMana::OnTeainfomanaDelete()
{
// TODO: Add your control notification handler code here
CString sSql;
UpdateData(true);
if(inputnumber.IsEmpty())
{
AfxMessageBox("请输入职工号");
return;
}
connection.Initialize();
sSql.Format("select * from 教职工 where 职工号='%s'",number);
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'",number);
connection.Connect(sSql);
connection.m_pRecordset->MoveFirst();
while(!connection.m_pRecordset->adoEOF)
{
_variant_t TheValue;
CString num,coursenumber;
TheValue = connection.m_pRecordset->Fields->GetItem("课程号")->Value;
coursenumber=TheValue.bstrVal;
TheValue = connection.m_pRecordset->Fields->GetItem("学号")->Value;
num=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();
number="";
name="";
sex="";
birth="";
post="";
sdeptnumber="";
speciality="";
direct="";
UpdateData(FALSE);
MessageBox("职工删除成功");
}
void TeaInfoMana::OnCancel()
{
// TODO: Add extra cleanup here
EndDialog(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -