📄 stuinfo.cpp
字号:
// StuInfo.cpp : implementation file
//
#include "stdafx.h"
#include "EduAdministration.h"
#include "StuInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStuInfo dialog
CStuInfo::CStuInfo(CWnd* pParent /*=NULL*/)
: CDialog(CStuInfo::IDD, pParent)
{
//{{AFX_DATA_INIT(CStuInfo)
m_polity = _T("");
m_sex = _T("");
m_bornDate = _T("");
m_class = _T("");
m_contact = _T("");
m_grade = _T("");
m_identNum = _T("");
m_institute = _T("");
m_matriDate = _T("");
m_matriScore = _T("");
m_postalCode = _T("");
m_schLength = _T("");
m_specialty = _T("");
m_name = _T("");
m_num = _T("");
//}}AFX_DATA_INIT
}
void CStuInfo::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStuInfo)
DDX_Control(pDX, IDC_COMBOPOLITY, m_ctlPolity);
DDX_Control(pDX, IDC_COMBOSEX, m_ctlSex);
DDX_Control(pDX, IDC_LISTSTUDENT, m_stuList);
DDX_Control(pDX, IDC_EDTSTUNUM, m_ctlNum);
DDX_Control(pDX, IDC_EDTSTUNAME, m_ctlName);
DDX_Control(pDX, IDC_EDTSPECIALTY, m_ctlSpecialty);
DDX_Control(pDX, IDC_EDTSCHLENGTH, m_ctlSchLength);
DDX_Control(pDX, IDC_EDTPOSTALCODE, m_ctlPostalCode);
DDX_Control(pDX, IDC_EDTMATRISCORE, m_ctlMatriScore);
DDX_Control(pDX, IDC_EDTMATRIDATE, m_ctlMatriDate);
DDX_Control(pDX, IDC_EDTINSTITUTE, m_ctlInstitute);
DDX_Control(pDX, IDC_EDTIDENTNUM, m_ctlIdentNum);
DDX_Control(pDX, IDC_EDTGRADE, m_ctlGrade);
DDX_Control(pDX, IDC_EDTCONTACT, m_ctlContact);
DDX_Control(pDX, IDC_EDTCLASS, m_ctlClass);
DDX_Control(pDX, IDC_EDTBORNDATE, m_ctlBornDate);
DDX_Control(pDX, IDC_BTNSEARCH, m_btnSearch);
DDX_Control(pDX, IDC_BTNNEW, m_btnNew);
DDX_Control(pDX, IDC_BTNEDIT, m_btnEdit);
DDX_CBString(pDX, IDC_COMBOPOLITY, m_polity);
DDX_CBString(pDX, IDC_COMBOSEX, m_sex);
DDX_Text(pDX, IDC_EDTBORNDATE, m_bornDate);
DDX_Text(pDX, IDC_EDTCLASS, m_class);
DDX_Text(pDX, IDC_EDTCONTACT, m_contact);
DDX_Text(pDX, IDC_EDTGRADE, m_grade);
DDX_Text(pDX, IDC_EDTIDENTNUM, m_identNum);
DDX_Text(pDX, IDC_EDTINSTITUTE, m_institute);
DDX_Text(pDX, IDC_EDTMATRIDATE, m_matriDate);
DDX_Text(pDX, IDC_EDTMATRISCORE, m_matriScore);
DDX_Text(pDX, IDC_EDTPOSTALCODE, m_postalCode);
DDX_Text(pDX, IDC_EDTSCHLENGTH, m_schLength);
DDX_Text(pDX, IDC_EDTSPECIALTY, m_specialty);
DDX_Text(pDX, IDC_EDTSTUNAME, m_name);
DDX_Text(pDX, IDC_EDTSTUNUM, m_num);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStuInfo, CDialog)
//{{AFX_MSG_MAP(CStuInfo)
ON_BN_CLICKED(IDC_BTNNEW, OnBtnnew)
ON_BN_CLICKED(IDC_BTNEDIT, OnBtnedit)
ON_NOTIFY(NM_CLICK, IDC_LISTSTUDENT, OnClickListstudent)
ON_BN_CLICKED(IDC_BTNSEARCH, OnBtnsearch)
ON_WM_SHOWWINDOW()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStuInfo message handlers
BOOL CStuInfo::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_bEditMode = false;
m_bAddMode= false;
m_bFindMode = false;
m_stuList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_stuList.InsertColumn(0,"学号",LVCFMT_LEFT,180);
m_stuList.InsertColumn(1,"姓名",LVCFMT_LEFT,150);
m_stuList.InsertColumn(2,"性别",LVCFMT_LEFT,50);
m_stuList.InsertColumn(3,"学院",LVCFMT_LEFT,100);
m_stuList.InsertColumn(4,"专业",LVCFMT_LEFT,100);
m_stuList.InsertColumn(5,"年级",LVCFMT_LEFT,100);
m_stuList.InsertColumn(6,"班级",LVCFMT_LEFT,100);
if(!m_Students.IsOpen())
m_Students.Open();
if(!m_Students.IsEOF())
setFields();
m_Students.Close();
m_btnNew.SetIcon(IDI_ICONNEW);
m_btnEdit.SetIcon(IDI_ICONEDIT);
m_btnSearch.SetIcon(IDI_ICONSEARCH);
m_btnSearch.SetTooltipText("全部留空则显示所有");
setFiledReadOnly();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStuInfo::setFiledReadOnly()
{
m_ctlBornDate.SetReadOnly(true);
m_ctlClass.SetReadOnly(true);
m_ctlContact.SetReadOnly(true);
m_ctlGrade.SetReadOnly(true);
m_ctlIdentNum.SetReadOnly(true);
m_ctlInstitute.SetReadOnly(true);
m_ctlMatriDate.SetReadOnly(true);
m_ctlMatriScore.SetReadOnly(true);
m_ctlName.SetReadOnly(true);
m_ctlNum.SetReadOnly(true);
m_ctlPostalCode.SetReadOnly(true);
m_ctlSchLength.SetReadOnly(true);
m_ctlSpecialty.SetReadOnly(true);
m_ctlPolity.EnableWindow(false);
m_ctlSex.EnableWindow(false);
}
void CStuInfo::setFieldReadWrite()
{
m_ctlBornDate.SetReadOnly(false);
m_ctlClass.SetReadOnly(false);
m_ctlContact.SetReadOnly(false);
m_ctlGrade.SetReadOnly(false);
m_ctlIdentNum.SetReadOnly(false);
m_ctlInstitute.SetReadOnly(false);
m_ctlMatriDate.SetReadOnly(false);
m_ctlMatriScore.SetReadOnly(false);
m_ctlName.SetReadOnly(false);
m_ctlNum.SetReadOnly(false);
m_ctlPostalCode.SetReadOnly(false);
m_ctlSchLength.SetReadOnly(false);
m_ctlSpecialty.SetReadOnly(false);
m_ctlPolity.EnableWindow(true);
m_ctlSex.EnableWindow(true);
}
void CStuInfo::OnBtnnew()
{
// TODO: Add your control notification handler code here
if(!m_bAddMode)
{
m_bAddMode = true;
setFieldNull();
setFieldReadWrite();
m_btnSearch.EnableWindow(false);
m_btnEdit.EnableWindow(false);
m_btnNew.SetWindowText("保存");
m_btnNew.SetIcon(IDI_ICONSAVE);
m_ctlNum.SetFocus();
}
else
{
UpdateData();
if(m_name == ""){
AfxMessageBox("请输入姓名");
return;
}
if(m_num == ""){
AfxMessageBox("请输入学号");
return;
}
if(m_sex == ""){
AfxMessageBox("请选择性别");
return;
}
if(m_grade == ""){
AfxMessageBox("请输入年级");
return;
}
if(m_institute == ""){
AfxMessageBox("请输入学院");
return;
}
if(m_specialty == ""){
AfxMessageBox("请输入专业");
return;
}
if(!m_Students.IsOpen())
m_Students.Open();
m_Students.m_strFilter.Format("stuNum='%s'",m_num);
m_Students.Requery();
if(!m_Students.IsEOF()){
AfxMessageBox("此学号已存在");
m_Students.Close();
return;
}
m_Students.AddNew();
saveFields();
m_Students.m_strFilter.Format("stuNum='%s'",m_num);
m_Students.Requery();
if(!m_Students.IsEOF())
setStudentList();
m_Students.Close();
setCourses();
setFiledReadOnly();
m_btnNew.SetWindowText("新增");
m_btnNew.SetIcon(IDI_ICONNEW);
m_btnSearch.EnableWindow(true);
m_btnEdit.EnableWindow(true);
m_bAddMode = false;
}
}
void CStuInfo::saveFields()
{
m_Students.m_stuNum = m_num;
m_Students.m_stuName = m_name;
m_Students.m_bornDate = m_bornDate;
m_Students.m_class = m_class;
m_Students.m_contact = m_contact;
m_Students.m_grade = m_grade;
m_Students.m_identityNum = m_identNum;
m_Students.m_institute = m_institute;
m_Students.m_matriculateDate = m_matriDate;
m_Students.m_matriculateScore = m_matriScore;
m_Students.m_polity = m_polity;
m_Students.m_postalcode = m_postalCode;
m_Students.m_schoollength = m_schLength;
m_Students.m_sex = m_sex;
m_Students.m_specialty = m_specialty;
m_Students.Update();
}
void CStuInfo::setCourses()
{
if(!m_Course.IsOpen())
m_Course.Open();
m_Course.m_strFilter.Format("institute='%s' and specialty='%s'",m_institute,m_specialty);
m_Course.Requery();
if(m_Course.IsEOF()){
m_Course.Close();
return;
}
CString stucourse="";
while (!m_Course.IsEOF())
{
stucourse +=m_Course.m_couID + " ";
m_Course.MoveNext();
}
m_Course.Close();
if(!m_StuCourse.IsOpen())
m_StuCourse.Open();
m_StuCourse.AddNew();
m_StuCourse.m_ID = m_num;
m_StuCourse.m_stuNum = m_num;
m_StuCourse.m_courseIDs = stucourse;
m_StuCourse.Update();
m_StuCourse.Close();
}
void CStuInfo::OnBtnedit()
{
// TODO: Add your control notification handler code here
UpdateData();
if(!m_bEditMode)
{
if(m_num == "")
return;
setFieldReadWrite();
m_btnNew.EnableWindow(false);
m_btnSearch.EnableWindow(false);
m_btnEdit.SetIcon(IDI_ICONSAVE);
m_ctlNum.SetReadOnly(true);
m_ctlInstitute.EnableWindow(false);
m_ctlSpecialty.EnableWindow(false);
m_ctlName.SetFocus();
m_bEditMode = true;
}
else
{
if(m_name == ""){
AfxMessageBox("请输入姓名");
return;
}
if(m_sex == ""){
AfxMessageBox("请选择性别");
return;
}
if(m_grade == ""){
AfxMessageBox("请输入年级");
return;
}
if(!m_Students.IsOpen())
m_Students.Open();
m_Students.m_strFilter.Format("stuNum='%s'",m_num);
m_Students.Requery();
if(m_Students.IsEOF()){
AfxMessageBox("Error");
m_Students.Close();
}
m_Students.Edit();
saveFields();
setStudentList();
m_Students.Close();
setFiledReadOnly();
m_btnEdit.SetIcon(IDI_ICONEDIT);
m_btnNew.EnableWindow(true);
m_btnSearch.EnableWindow(true);
m_bEditMode = false;
}
}
BEGIN_EVENTSINK_MAP(CStuInfo, CDialog)
//{{AFX_EVENTSINK_MAP(CStuInfo)
// ON_EVENT(CStuInfo, IDC_DATAGRID1, -600 /* Click */, OnClickDatagrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CStuInfo::setFields()
{
m_bornDate = m_Students.m_bornDate;
m_class = m_Students.m_class;
m_contact = m_Students.m_contact;
m_grade = m_Students.m_grade;
m_identNum = m_Students.m_identityNum;
m_institute = m_Students.m_institute;
m_matriDate = m_Students.m_matriculateDate;
m_matriScore = m_Students.m_matriculateScore;
m_polity = m_Students.m_polity;
m_postalCode = m_Students.m_postalcode;
m_schLength = m_Students.m_schoollength;
m_sex = m_Students.m_sex;
m_specialty = m_Students.m_specialty;
m_num = m_Students.m_stuNum;
m_name = m_Students.m_stuName;
UpdateData(false);
}
void CStuInfo::setStudentList()
{
int i=0;
m_stuList.DeleteAllItems();
while (!m_Students.IsEOF())
{
m_stuList.InsertItem(i,m_Students.m_stuNum);
m_stuList.SetItemText(i,1,m_Students.m_stuName);
m_stuList.SetItemText(i,2,m_Students.m_sex);
m_stuList.SetItemText(i,3,m_Students.m_institute);
m_stuList.SetItemText(i,4,m_Students.m_specialty);
m_stuList.SetItemText(i,5,m_Students.m_grade);
m_stuList.SetItemText(i,6,m_Students.m_class);
i++;
m_Students.MoveNext();
}
}
void CStuInfo::OnClickListstudent(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if(m_bAddMode)
{
if(AfxMessageBox("取消添加新学生吗?",MB_YESNO)==IDYES)
{
setFiledReadOnly();
m_btnNew.SetWindowText("新增");
m_btnNew.SetIcon(IDI_ICONNEW);
m_btnSearch.EnableWindow(true);
m_btnEdit.EnableWindow(true);
m_bAddMode = false;
}
else
return;
}
if(m_bEditMode)
{
if(AfxMessageBox("取消修改?",MB_YESNO)==IDYES)
{
setFiledReadOnly();
m_btnEdit.SetIcon(IDI_ICONEDIT);
m_btnNew.EnableWindow(true);
m_btnSearch.EnableWindow(true);
m_bEditMode = false;
}
else
return;
}
if(m_bFindMode)
{
if(AfxMessageBox("退出查找?",MB_YESNO)==IDYES)
{
m_bFindMode = false;
m_btnNew.EnableWindow(true);
m_btnEdit.EnableWindow(true);
setFiledReadOnly();
m_btnSearch.SetIcon(IDI_ICONSEARCH);
}
else
return;
}
char s[20];
m_stuList.GetItemText(m_stuList.GetSelectionMark(),0,s,19);
if(s=="")
return;
if(!m_Students.IsOpen())
m_Students.Open();
m_Students.m_strFilter.Format("stuNum='%s'",s);
m_Students.Requery();
if(m_Students.IsEOF())
{
m_Students.Close();
return;
}
setFields();
m_Students.Close();
*pResult = 0;
}
void CStuInfo::setFieldNull()
{
m_name = "";
m_num = "";
m_bornDate = "";
m_class = "";
m_contact = "";
m_grade = "";
m_identNum = "";
m_institute = "";
m_matriScore = "";
m_matriDate = "";
m_polity = "";
m_postalCode = "";
m_schLength = "";
m_sex = "";
m_specialty = "";
UpdateData(false);
}
void CStuInfo::OnBtnsearch()
{
// TODO: Add your control notification handler code here
if(!m_bFindMode)
{
setFieldNull();
setFieldReadWrite();
m_btnNew.EnableWindow(false);
m_btnEdit.EnableWindow(false);
m_btnSearch.SetIcon(IDI_ICONSQLSEARCH);
m_ctlNum.SetFocus();
m_bFindMode = true;
}
else
{
UpdateData();
setFiledReadOnly();
CString s,st="";
if(m_num!=""){
s.Format("stuNum='%s'",m_num);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_name!=""){
s.Format("stuName='%s'",m_name);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_bornDate!=""){
s.Format("bornDate='%s'",m_bornDate);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_class!=""){
s.Format("class='%s'",m_class);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_contact!=""){
s.Format("contact='%s'",m_contact);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_grade!=""){
s.Format("grade='%s'",m_grade);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_identNum!=""){
s.Format("identityNum='%s'",m_identNum);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_institute!=""){
s.Format("institute='%s'",m_institute);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_matriDate!=""){
s.Format("matriculateDate='%s'",m_matriDate);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_matriScore!=""){
s.Format("matriculateScore='%s'",m_matriScore);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_polity!=""){
s.Format("polity='%s'",m_polity);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_postalCode!=""){
s.Format("postalcode='%s'",m_postalCode);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_schLength!=""){
s.Format("schoollength='%s'",m_schLength);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_sex!=""){
s.Format("sex='%s'",m_sex);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(m_specialty!=""){
s.Format("specialty='%s'",m_specialty);
if(st=="")
st=s;
else
st+=" and "+s;
}
if(!m_Students.IsOpen())
m_Students.Open();
m_Students.m_strFilter = st;
m_Students.Requery();
if(m_Students.IsEOF())
setFieldNull();
else
setFields();
setStudentList();
m_Students.Close();
m_bFindMode = false;
m_btnNew.EnableWindow(true);
m_btnEdit.EnableWindow(true);
m_btnSearch.SetIcon(IDI_ICONSEARCH);
}
}
void CStuInfo::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
if(!m_Students.IsOpen())
m_Students.Open();
if(!m_Students.IsEOF())
{
setStudentList();
}
m_Students.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -