📄 studentinfodlg.cpp
字号:
// StudentInfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "school.h"
#include "StudentInfoDlg.h"
#include "departmentset.h"
#include "majorset.h"
#include "classset.h"
#include "studentset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStudentInfoDlg dialog
CStudentInfoDlg::CStudentInfoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStudentInfoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudentInfoDlg)
m_strClass = _T("");
m_strDept = _T("");
m_strSex = _T("");
m_strMajor = _T("");
m_tmBirth = 0;
m_tmEnroll = 0;
m_tmGraduate = 0;
m_strAddress = _T("");
m_strDept1 = _T("");
m_strDept2 = _T("");
m_strDept3 = _T("");
m_strDuty1 = _T("");
m_strDuty2 = _T("");
m_strDuty3 = _T("");
m_strEdusys = _T("");
m_strFamily = _T("");
m_strFolk = _T("");
m_strIDCard = _T("");
m_strName1 = _T("");
m_strName2 = _T("");
m_strName3 = _T("");
m_strNative = _T("");
m_strOldName = _T("");
m_strPhone = _T("");
m_strDegist1 = _T("");
m_strDegist2 = _T("");
m_strDegist3 = _T("");
m_strDegist4 = _T("");
m_strDegist5 = _T("");
m_strDegist6 = _T("");
m_strHonorDate1 = _T("");
m_strHonorDate2 = _T("");
m_strHonorDate3 = _T("");
m_strHonorDate4 = _T("");
m_strHonorDate5 = _T("");
m_strHonorDate6 = _T("");
m_strPhone1 = _T("");
m_strPhone2 = _T("");
m_strPhone3 = _T("");
m_strPolitical = _T("");
m_strPolitical1 = _T("");
m_strPolitical3 = _T("");
m_strPolitical2 = _T("");
m_strPostCode = _T("");
m_strRelation1 = _T("");
m_strRelation2 = _T("");
m_strRelation3 = _T("");
m_strRemark1 = _T("");
m_strRemark2 = _T("");
m_strRemark3 = _T("");
m_strRemark4 = _T("");
m_strRemark5 = _T("");
m_strRemark6 = _T("");
m_strScore1 = _T("");
m_strScore10 = _T("");
m_strScore2 = _T("");
m_strScore3 = _T("");
m_strScore4 = _T("");
m_strScore5 = _T("");
m_strScore6 = _T("");
m_strScore7 = _T("");
m_strScore8 = _T("");
m_strScore9 = _T("");
m_strCode = _T("");
m_strName = _T("");
//}}AFX_DATA_INIT
m_bNew = TRUE;
}
void CStudentInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentInfoDlg)
DDX_Control(pDX, IDC_EDIT_STUDENTCODE, m_ctrCode);
DDX_Control(pDX, IDC_COMBO_SMAJOR, m_ctrMajor);
DDX_Control(pDX, IDC_COMBO_SDEPARTMENT, m_ctrDept);
DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
DDX_CBString(pDX, IDC_COMBO_SDEPARTMENT, m_strDept);
DDX_CBString(pDX, IDC_COMBO_SEX, m_strSex);
DDX_CBString(pDX, IDC_COMBO_SMAJOR, m_strMajor);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_BIRTH, m_tmBirth);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ENROLL, m_tmEnroll);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_GRADUATE, m_tmGraduate);
DDX_Text(pDX, IDC_EDIT_ADDRESS, m_strAddress);
DDX_Text(pDX, IDC_EDIT_DEPT1, m_strDept1);
DDX_Text(pDX, IDC_EDIT_DEPT2, m_strDept2);
DDX_Text(pDX, IDC_EDIT_DEPT3, m_strDept3);
DDX_Text(pDX, IDC_EDIT_DUTY1, m_strDuty1);
DDX_Text(pDX, IDC_EDIT_DUTY2, m_strDuty2);
DDX_Text(pDX, IDC_EDIT_DUTY3, m_strDuty3);
DDX_Text(pDX, IDC_EDIT_EDUSYS, m_strEdusys);
DDX_Text(pDX, IDC_EDIT_FAMILY, m_strFamily);
DDX_Text(pDX, IDC_EDIT_FOLK, m_strFolk);
DDX_Text(pDX, IDC_EDIT_IDCARD, m_strIDCard);
DDX_Text(pDX, IDC_EDIT_NAME1, m_strName1);
DDX_Text(pDX, IDC_EDIT_NAME2, m_strName2);
DDX_Text(pDX, IDC_EDIT_NAME3, m_strName3);
DDX_Text(pDX, IDC_EDIT_NATIVE, m_strNative);
DDX_Text(pDX, IDC_EDIT_OLDNAME, m_strOldName);
DDX_Text(pDX, IDC_EDIT_PHONE, m_strPhone);
DDX_Text(pDX, IDC_EDIT_DEGIST1, m_strDegist1);
DDX_Text(pDX, IDC_EDIT_DEGIST2, m_strDegist2);
DDX_Text(pDX, IDC_EDIT_DEGIST3, m_strDegist3);
DDX_Text(pDX, IDC_EDIT_DEGIST4, m_strDegist4);
DDX_Text(pDX, IDC_EDIT_DEGIST5, m_strDegist5);
DDX_Text(pDX, IDC_EDIT_DEGIST6, m_strDegist6);
DDX_Text(pDX, IDC_EDIT_HONORDATE1, m_strHonorDate1);
DDX_Text(pDX, IDC_EDIT_HONORDATE2, m_strHonorDate2);
DDX_Text(pDX, IDC_EDIT_HONORDATE3, m_strHonorDate3);
DDX_Text(pDX, IDC_EDIT_HONORDATE4, m_strHonorDate4);
DDX_Text(pDX, IDC_EDIT_HONORDATE5, m_strHonorDate5);
DDX_Text(pDX, IDC_EDIT_HONORDATE6, m_strHonorDate6);
DDX_Text(pDX, IDC_EDIT_PHONE1, m_strPhone1);
DDX_Text(pDX, IDC_EDIT_PHONE2, m_strPhone2);
DDX_Text(pDX, IDC_EDIT_PHONE3, m_strPhone3);
DDX_Text(pDX, IDC_EDIT_POLITICAL, m_strPolitical);
DDX_Text(pDX, IDC_EDIT_POLITICAL1, m_strPolitical1);
DDX_Text(pDX, IDC_EDIT_POLITICAL3, m_strPolitical3);
DDX_Text(pDX, IDC_EDIT_POLITICAL2, m_strPolitical2);
DDX_Text(pDX, IDC_EDIT_POSTCODE, m_strPostCode);
DDX_Text(pDX, IDC_EDIT_RELATION1, m_strRelation1);
DDX_Text(pDX, IDC_EDIT_RELATION2, m_strRelation2);
DDX_Text(pDX, IDC_EDIT_RELATION3, m_strRelation3);
DDX_Text(pDX, IDC_EDIT_REMARK1, m_strRemark1);
DDX_Text(pDX, IDC_EDIT_REMARK2, m_strRemark2);
DDX_Text(pDX, IDC_EDIT_REMARK3, m_strRemark3);
DDX_Text(pDX, IDC_EDIT_REMARK4, m_strRemark4);
DDX_Text(pDX, IDC_EDIT_REMARK5, m_strRemark5);
DDX_Text(pDX, IDC_EDIT_REMARK6, m_strRemark6);
DDX_Text(pDX, IDC_EDIT_SCORE1, m_strScore1);
DDX_Text(pDX, IDC_EDIT_SCORE10, m_strScore10);
DDX_Text(pDX, IDC_EDIT_SCORE2, m_strScore2);
DDX_Text(pDX, IDC_EDIT_SCORE3, m_strScore3);
DDX_Text(pDX, IDC_EDIT_SCORE4, m_strScore4);
DDX_Text(pDX, IDC_EDIT_SCORE5, m_strScore5);
DDX_Text(pDX, IDC_EDIT_SCORE6, m_strScore6);
DDX_Text(pDX, IDC_EDIT_SCORE7, m_strScore7);
DDX_Text(pDX, IDC_EDIT_SCORE8, m_strScore8);
DDX_Text(pDX, IDC_EDIT_SCORE9, m_strScore9);
DDX_Text(pDX, IDC_EDIT_STUDENTCODE, m_strCode);
DDX_Text(pDX, IDC_EDIT_STUNAME, m_strName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudentInfoDlg, CDialog)
//{{AFX_MSG_MAP(CStudentInfoDlg)
ON_CBN_SELCHANGE(IDC_COMBO_SDEPARTMENT, OnSelchangeComboSdepartment)
ON_CBN_SELCHANGE(IDC_COMBO_SMAJOR, OnSelchangeComboSmajor)
ON_CBN_SETFOCUS(IDC_COMBO_SMAJOR, OnSetfocusComboSmajor)
ON_CBN_SETFOCUS(IDC_COMBO_CLASS, OnSetfocusComboClass)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentInfoDlg message handlers
BOOL CStudentInfoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CDepartmentSet DeptSet ;
CString strSQL;
strSQL="select * from department";
if(!DeptSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
}
while(!DeptSet.IsEOF())
{
m_ctrDept.AddString(DeptSet.m_name);
DeptSet.MoveNext();
}
DeptSet.Close();
if(!m_strCode.IsEmpty())
{//初始化文本框中得内容
m_bNew = FALSE;
m_ctrCode.EnableWindow(FALSE);
CStudentSet StudentSet ;
strSQL.Format( "select * from student where code = '%s' ",m_strCode);
if(!StudentSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
AfxMessageBox("打开数据库失败!");
return FALSE;
}
m_strClass = StudentSet.m_class ;
m_strDept = StudentSet.m_department ;
m_strSex = StudentSet.m_sex ;
m_strMajor = StudentSet.m_major ;
m_tmBirth = StudentSet.m_birthday ;
m_tmEnroll = StudentSet.m_enroll_date ;
m_tmGraduate = StudentSet.m_graduate_date ;
m_strAddress = StudentSet.m_address ;
m_strDept1 = StudentSet.m_family_dept1 ;
m_strDept2 = StudentSet.m_family_dept2 ;
m_strDept3 = StudentSet.m_family_dept3 ;
m_strDuty1 = StudentSet.m_family_duty1 ;
m_strDuty2 = StudentSet.m_family_duty2 ;
m_strDuty3 = StudentSet.m_family_dept3 ;
m_strEdusys = StudentSet.m_edu_sys ;
m_strFamily = StudentSet.m_family ;
m_strFolk = StudentSet.m_folk ;
m_strIDCard = StudentSet.m_IDCard ;
m_strName1 = StudentSet.m_family_name1 ;
m_strName2 = StudentSet.m_family_name2 ;
m_strName3 = StudentSet.m_family_name3 ;
m_strNative = StudentSet.m_native ;
m_strOldName = StudentSet.m_oldname ;
m_strPhone = StudentSet.m_phone ;
m_strDegist1 = StudentSet.m_honor_digiest1 ;
m_strDegist2 = StudentSet.m_honor_digiest2 ;
m_strDegist3 = StudentSet.m_honor_digiest3 ;
m_strDegist4 = StudentSet.m_honor_digiest4 ;
m_strDegist5 = StudentSet.m_honor_digiest5 ;
m_strDegist6 = StudentSet.m_honor_digiest6 ;
m_strHonorDate1 = StudentSet.m_honor_date1 ;
m_strHonorDate2 = StudentSet.m_honor_date2 ;
m_strHonorDate3 = StudentSet.m_honor_date3 ;
m_strHonorDate4 = StudentSet.m_honor_date4 ;
m_strHonorDate5 = StudentSet.m_honor_date5 ;
m_strHonorDate6 = StudentSet.m_honor_date6 ;
m_strPhone1 = StudentSet.m_family_phone1 ;
m_strPhone2 = StudentSet.m_family_phone2 ;
m_strPhone3 = StudentSet.m_family_phone3 ;
m_strPolitical = StudentSet.m_political ;
m_strPolitical1 = StudentSet.m_family_political1 ;
m_strPolitical3 = StudentSet.m_family_political2 ;
m_strPolitical2 = StudentSet.m_family_political3 ;
m_strPostCode = StudentSet.m_postcode ;
m_strRelation1 = StudentSet.m_family_relation1 ;
m_strRelation2 = StudentSet.m_family_relation2 ;
m_strRelation3 = StudentSet.m_family_relation3 ;
m_strRemark1 = StudentSet.m_honor_remark1 ;
m_strRemark2 = StudentSet.m_honor_remark2 ;
m_strRemark3 = StudentSet.m_honor_remark3 ;
m_strRemark4 = StudentSet.m_honor_remark4 ;
m_strRemark5 = StudentSet.m_honor_remark5 ;
m_strRemark6 = StudentSet.m_honor_remark6 ;
m_strScore1 = StudentSet.m_term1 ;
m_strScore10 = StudentSet.m_term10 ;
m_strScore2 = StudentSet.m_term2 ;
m_strScore3 = StudentSet.m_term3 ;
m_strScore4 = StudentSet.m_term4 ;
m_strScore5 = StudentSet.m_term5 ;
m_strScore6 = StudentSet.m_term6 ;
m_strScore7 = StudentSet.m_term7 ;
m_strScore8 = StudentSet.m_term8 ;
m_strScore9 = StudentSet.m_term9 ;
m_strCode = StudentSet.m_code ;
m_strName = StudentSet.m_name ;
StudentSet.Close();
}
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStudentInfoDlg::OnSelchangeComboSdepartment()
{
// TODO: Add your control notification handler code here
UpdateData();
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrMajor.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrMajor.DeleteString(0);
}
nCount=m_ctrClass.GetCount();
for(i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
//////////////////////////////////////////
}
void CStudentInfoDlg::OnSelchangeComboSmajor()
{
// TODO: Add your control notification handler code here
UpdateData();
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrClass.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
}
void CStudentInfoDlg::OnSetfocusComboSmajor()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strSQL;
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrMajor.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrMajor.DeleteString(0);
}
nCount=m_ctrClass.GetCount();
for(i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
CMajorSet recordset ;
strSQL.Format( "select * from major where department = '%s'",m_strDept);
if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
while(!recordset.IsEOF())
{
m_ctrMajor.AddString(recordset.m_name);
recordset.MoveNext();
}
recordset.Close();
}
void CStudentInfoDlg::OnSetfocusComboClass()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strSQL;
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrClass.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
CClassSet recordset ;
strSQL.Format( "select * from class where department = '%s' and major = '%s'",m_strDept,m_strMajor);
if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
while(!recordset.IsEOF())
{
m_ctrClass.AddString(recordset.m_name);
recordset.MoveNext();
}
recordset.Close();
}
void CStudentInfoDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
if(m_strCode.IsEmpty())
{
AfxMessageBox("学号不能为空!");
return;
}
if(m_strName.IsEmpty())
{
AfxMessageBox("姓名不能为空!");
return;
}
if(m_bNew)
{
CStudentSet StudentSet ;
CString strSQL;
strSQL.Format( "select * from student where code = '%s' ",m_strCode);
if(!StudentSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
AfxMessageBox("打开数据库失败!");
return ;
}
if(StudentSet.GetRecordCount()!=0)
{
AfxMessageBox("该学生已经存在!");
StudentSet.Close();
return;
}
StudentSet.Close();
}
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -