StudentDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:17k
源码类别:
数据库系统
开发平台:
Visual C++
- // StudentDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "StudentDlg.h"
- #include "departmentset.h"
- #include "majorset.h"
- #include "classset.h"
- #include "studentInfodlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CStudentDlg dialog
- CStudentDlg::CStudentDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CStudentDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CStudentDlg)
- m_strClass = _T("");
- m_strDepartment = _T("");
- m_strMajor = _T("");
- //}}AFX_DATA_INIT
- }
- void CStudentDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CStudentDlg)
- DDX_Control(pDX, IDC_LIST1, m_ctrList);
- DDX_Control(pDX, IDC_COMBO_MAJOR, m_ctrMajor);
- DDX_Control(pDX, IDC_COMBO_DEPARTMENT, m_ctrDepartment);
- DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
- DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
- DDX_CBString(pDX, IDC_COMBO_DEPARTMENT, m_strDepartment);
- DDX_CBString(pDX, IDC_COMBO_MAJOR, m_strMajor);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CStudentDlg, CDialog)
- //{{AFX_MSG_MAP(CStudentDlg)
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
- ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
- ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
- ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
- ON_CBN_SETFOCUS(IDC_COMBO_MAJOR, OnSetfocusComboMajor)
- ON_CBN_SETFOCUS(IDC_COMBO_CLASS, OnSetfocusComboClass)
- ON_CBN_SELCHANGE(IDC_COMBO_DEPARTMENT, OnSelchangeComboDepartment)
- ON_CBN_SELCHANGE(IDC_COMBO_MAJOR, OnSelchangeComboMajor)
- ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CStudentDlg message handlers
- BOOL CStudentDlg::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_ctrDepartment.AddString(DeptSet.m_name);
- DeptSet.MoveNext();
- }
- DeptSet.Close();
- m_ctrList.InsertColumn(0,"学号");
- m_ctrList.InsertColumn(1,"姓名");
- m_ctrList.InsertColumn(2,"曾用名");
- m_ctrList.InsertColumn(3,"性别");
- m_ctrList.InsertColumn(4,"出生年月");
- m_ctrList.InsertColumn(5,"民族");
- m_ctrList.InsertColumn(6,"政治面貌");
- m_ctrList.InsertColumn(7,"籍贯");
- m_ctrList.InsertColumn(8,"家庭出身");
- m_ctrList.InsertColumn(9,"联系电话");
- m_ctrList.InsertColumn(10,"邮政编码");
- m_ctrList.InsertColumn(11,"家庭地址");
- m_ctrList.InsertColumn(12,"身份证号");
- m_ctrList.InsertColumn(13,"入学时间");
- m_ctrList.InsertColumn(14,"毕业时间");
- m_ctrList.InsertColumn(15,"班级");
- m_ctrList.InsertColumn(16,"所在院系");
- m_ctrList.InsertColumn(17,"专业");
- m_ctrList.SetColumnWidth(0,60);
- m_ctrList.SetColumnWidth(1,80);
- m_ctrList.SetColumnWidth(2,80);
- m_ctrList.SetColumnWidth(3,60);
- m_ctrList.SetColumnWidth(4,60);
- m_ctrList.SetColumnWidth(5,60);
- m_ctrList.SetColumnWidth(6,100);
- m_ctrList.SetColumnWidth(7,60);
- m_ctrList.SetColumnWidth(8,100);
- m_ctrList.SetColumnWidth(9,100);
- m_ctrList.SetColumnWidth(10,100);
- m_ctrList.SetColumnWidth(11,100);
- m_ctrList.SetColumnWidth(12,100);
- m_ctrList.SetColumnWidth(13,100);
- m_ctrList.SetColumnWidth(14,100);
- m_ctrList.SetColumnWidth(15,100);
- m_ctrList.SetColumnWidth(16,100);
- m_ctrList.SetColumnWidth(17,100);
- m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CStudentDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- *pResult = 0;
- }
- void CStudentDlg::OnButtonNew()
- {
- // TODO: Add your control notification handler code here
- CStudentInfoDlg Dlg;
- if(IDOK==Dlg.DoModal())
- {//添加新记录
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.AddNew();
- m_recordset.m_class =Dlg.m_strClass ;
- m_recordset.m_department =Dlg.m_strDept ;
- m_recordset.m_sex =Dlg.m_strSex ;
- m_recordset.m_major =Dlg.m_strMajor ;
- m_recordset.m_birthday =Dlg.m_tmBirth ;
- m_recordset.m_enroll_date =Dlg.m_tmEnroll ;
- m_recordset.m_graduate_date =Dlg.m_tmGraduate ;
- m_recordset.m_address =Dlg.m_strAddress ;
- m_recordset.m_family_dept1 =Dlg.m_strDept1 ;
- m_recordset.m_family_dept2 =Dlg.m_strDept2 ;
- m_recordset.m_family_dept3 =Dlg.m_strDept3 ;
- m_recordset.m_family_duty1 =Dlg.m_strDuty1 ;
- m_recordset.m_family_duty2 =Dlg.m_strDuty2 ;
- m_recordset.m_family_dept3 =Dlg.m_strDuty3 ;
- m_recordset.m_edu_sys =Dlg.m_strEdusys ;
- m_recordset.m_family =Dlg.m_strFamily ;
- m_recordset.m_folk =Dlg.m_strFolk ;
- m_recordset.m_IDCard =Dlg.m_strIDCard ;
- m_recordset.m_family_name1 =Dlg.m_strName1 ;
- m_recordset.m_family_name2 =Dlg.m_strName2 ;
- m_recordset.m_family_name3 =Dlg.m_strName3 ;
- m_recordset.m_native =Dlg.m_strNative ;
- m_recordset.m_oldname =Dlg.m_strOldName ;
- m_recordset.m_phone =Dlg.m_strPhone ;
- m_recordset.m_honor_digiest1 =Dlg.m_strDegist1 ;
- m_recordset.m_honor_digiest2 =Dlg.m_strDegist2 ;
- m_recordset.m_honor_digiest3 =Dlg.m_strDegist3 ;
- m_recordset.m_honor_digiest4 =Dlg.m_strDegist4 ;
- m_recordset.m_honor_digiest5 =Dlg.m_strDegist5 ;
- m_recordset.m_honor_digiest6 =Dlg.m_strDegist6 ;
- m_recordset.m_honor_date1 =Dlg.m_strHonorDate1 ;
- m_recordset.m_honor_date2 =Dlg.m_strHonorDate2 ;
- m_recordset.m_honor_date3 =Dlg.m_strHonorDate3 ;
- m_recordset.m_honor_date4 =Dlg.m_strHonorDate4 ;
- m_recordset.m_honor_date5 =Dlg.m_strHonorDate5 ;
- m_recordset.m_honor_date6 =Dlg.m_strHonorDate6 ;
- m_recordset.m_family_phone1 =Dlg.m_strPhone1 ;
- m_recordset.m_family_phone2 =Dlg.m_strPhone2 ;
- m_recordset.m_family_phone3 =Dlg.m_strPhone3 ;
- m_recordset.m_political =Dlg.m_strPolitical ;
- m_recordset.m_family_political1 =Dlg.m_strPolitical1 ;
- m_recordset.m_family_political2 =Dlg.m_strPolitical3 ;
- m_recordset.m_family_political3 =Dlg.m_strPolitical2 ;
- m_recordset.m_postcode =Dlg.m_strPostCode ;
- m_recordset.m_family_relation1 =Dlg.m_strRelation1 ;
- m_recordset.m_family_relation2 =Dlg.m_strRelation2 ;
- m_recordset.m_family_relation3 =Dlg.m_strRelation3 ;
- m_recordset.m_honor_remark1 =Dlg.m_strRemark1 ;
- m_recordset.m_honor_remark2 =Dlg.m_strRemark2 ;
- m_recordset.m_honor_remark3 =Dlg.m_strRemark3 ;
- m_recordset.m_honor_remark4 =Dlg.m_strRemark4 ;
- m_recordset.m_honor_remark5 =Dlg.m_strRemark5 ;
- m_recordset.m_honor_remark6 =Dlg.m_strRemark6 ;
- m_recordset.m_term1 =Dlg.m_strScore1 ;
- m_recordset.m_term10 =Dlg.m_strScore10 ;
- m_recordset.m_term2 =Dlg.m_strScore2 ;
- m_recordset.m_term3 =Dlg.m_strScore3 ;
- m_recordset.m_term4 =Dlg.m_strScore4 ;
- m_recordset.m_term5 =Dlg.m_strScore5 ;
- m_recordset.m_term6 =Dlg.m_strScore6 ;
- m_recordset.m_term7 =Dlg.m_strScore7 ;
- m_recordset.m_term8 =Dlg.m_strScore8 ;
- m_recordset.m_term9 =Dlg.m_strScore9 ;
- m_recordset.m_code =Dlg.m_strCode ;
- m_recordset.m_name =Dlg.m_strName ;
- m_recordset.Update();
- m_recordset.Close();
- CString strSQL = "select * from student ";
- RefreshData(strSQL);
- }
- }
- void CStudentDlg::OnButtonModify()
- {
- // TODO: Add your control notification handler code here
- CStudentInfoDlg Dlg;
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行修改!");
- return;
- }
- Dlg.m_strCode=m_ctrList.GetItemText(i,0);
- if(IDOK==Dlg.DoModal())
- {//修改记录
- CString strSQL;
- strSQL.Format("select * from student where code = '%s'",Dlg.m_strCode);
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Edit();
- m_recordset.m_class =Dlg.m_strClass ;
- m_recordset.m_department =Dlg.m_strDept ;
- m_recordset.m_sex =Dlg.m_strSex ;
- m_recordset.m_major =Dlg.m_strMajor ;
- m_recordset.m_birthday =Dlg.m_tmBirth ;
- m_recordset.m_enroll_date =Dlg.m_tmEnroll ;
- m_recordset.m_graduate_date =Dlg.m_tmGraduate ;
- m_recordset.m_address =Dlg.m_strAddress ;
- m_recordset.m_family_dept1 =Dlg.m_strDept1 ;
- m_recordset.m_family_dept2 =Dlg.m_strDept2 ;
- m_recordset.m_family_dept3 =Dlg.m_strDept3 ;
- m_recordset.m_family_duty1 =Dlg.m_strDuty1 ;
- m_recordset.m_family_duty2 =Dlg.m_strDuty2 ;
- m_recordset.m_family_dept3 =Dlg.m_strDuty3 ;
- m_recordset.m_edu_sys =Dlg.m_strEdusys ;
- m_recordset.m_family =Dlg.m_strFamily ;
- m_recordset.m_folk =Dlg.m_strFolk ;
- m_recordset.m_IDCard =Dlg.m_strIDCard ;
- m_recordset.m_family_name1 =Dlg.m_strName1 ;
- m_recordset.m_family_name2 =Dlg.m_strName2 ;
- m_recordset.m_family_name3 =Dlg.m_strName3 ;
- m_recordset.m_native =Dlg.m_strNative ;
- m_recordset.m_oldname =Dlg.m_strOldName ;
- m_recordset.m_phone =Dlg.m_strPhone ;
- m_recordset.m_honor_digiest1 =Dlg.m_strDegist1 ;
- m_recordset.m_honor_digiest2 =Dlg.m_strDegist2 ;
- m_recordset.m_honor_digiest3 =Dlg.m_strDegist3 ;
- m_recordset.m_honor_digiest4 =Dlg.m_strDegist4 ;
- m_recordset.m_honor_digiest5 =Dlg.m_strDegist5 ;
- m_recordset.m_honor_digiest6 =Dlg.m_strDegist6 ;
- m_recordset.m_honor_date1 =Dlg.m_strHonorDate1 ;
- m_recordset.m_honor_date2 =Dlg.m_strHonorDate2 ;
- m_recordset.m_honor_date3 =Dlg.m_strHonorDate3 ;
- m_recordset.m_honor_date4 =Dlg.m_strHonorDate4 ;
- m_recordset.m_honor_date5 =Dlg.m_strHonorDate5 ;
- m_recordset.m_honor_date6 =Dlg.m_strHonorDate6 ;
- m_recordset.m_family_phone1 =Dlg.m_strPhone1 ;
- m_recordset.m_family_phone2 =Dlg.m_strPhone2 ;
- m_recordset.m_family_phone3 =Dlg.m_strPhone3 ;
- m_recordset.m_political =Dlg.m_strPolitical ;
- m_recordset.m_family_political1 =Dlg.m_strPolitical1 ;
- m_recordset.m_family_political2 =Dlg.m_strPolitical3 ;
- m_recordset.m_family_political3 =Dlg.m_strPolitical2 ;
- m_recordset.m_postcode =Dlg.m_strPostCode ;
- m_recordset.m_family_relation1 =Dlg.m_strRelation1 ;
- m_recordset.m_family_relation2 =Dlg.m_strRelation2 ;
- m_recordset.m_family_relation3 =Dlg.m_strRelation3 ;
- m_recordset.m_honor_remark1 =Dlg.m_strRemark1 ;
- m_recordset.m_honor_remark2 =Dlg.m_strRemark2 ;
- m_recordset.m_honor_remark3 =Dlg.m_strRemark3 ;
- m_recordset.m_honor_remark4 =Dlg.m_strRemark4 ;
- m_recordset.m_honor_remark5 =Dlg.m_strRemark5 ;
- m_recordset.m_honor_remark6 =Dlg.m_strRemark6 ;
- m_recordset.m_term1 =Dlg.m_strScore1 ;
- m_recordset.m_term10 =Dlg.m_strScore10 ;
- m_recordset.m_term2 =Dlg.m_strScore2 ;
- m_recordset.m_term3 =Dlg.m_strScore3 ;
- m_recordset.m_term4 =Dlg.m_strScore4 ;
- m_recordset.m_term5 =Dlg.m_strScore5 ;
- m_recordset.m_term6 =Dlg.m_strScore6 ;
- m_recordset.m_term7 =Dlg.m_strScore7 ;
- m_recordset.m_term8 =Dlg.m_strScore8 ;
- m_recordset.m_term9 =Dlg.m_strScore9 ;
- m_recordset.m_code =Dlg.m_strCode ;
- m_recordset.m_name =Dlg.m_strName ;
- m_recordset.Update();
- m_recordset.Close();
- strSQL = "select * from student ";
- RefreshData(strSQL);
- }
- }
- void CStudentDlg::OnButtonDelete()
- {
- // TODO: Add your control notification handler code here
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行查看!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from student where code = '%s'",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Delete();
- m_recordset.Close();
- strSQL = "select * from student";
- RefreshData(strSQL);
- }
- void CStudentDlg::OnButtonBrowse()
- {
- // TODO: Add your control notification handler code here
- CStudentInfoDlg Dlg;
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行查看!");
- return;
- }
- Dlg.m_strCode=m_ctrList.GetItemText(i,0);
- Dlg.DoModal();
- }
- void CStudentDlg::OnSetfocusComboMajor()
- {
- // 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_strDepartment);
- 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 CStudentDlg::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_strDepartment,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 CStudentDlg::OnSelchangeComboDepartment()
- {
- // 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 CStudentDlg::OnSelchangeComboMajor()
- {
- // 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 CStudentDlg::OnButtonSearch()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- CString strSQL,strTemp;
- strTemp="";
- BOOL bHaveCon = FALSE;
- if(m_strDepartment!="")
- {
- strSQL.Format("select * from student where department = '%s' ",m_strDepartment);
- bHaveCon = TRUE;
- }
- if(m_strMajor!="")
- {
- if(bHaveCon)
- {
- strTemp.Format(" major = '%s' ",m_strMajor);
- strSQL=strSQL + " and " + strTemp;
- }
- else
- {
- strSQL.Format("select * from student where major = '%s' ",m_strMajor);
- }
- bHaveCon=TRUE;
- }
- if(m_strClass!="")
- {
- if(bHaveCon)
- {
- strTemp.Format(" class = '%s' ",m_strClass);
- strSQL=strSQL + " and " + strTemp;
- }
- else
- {
- strSQL.Format("select * from student where class = '%s' ",m_strClass);
- }
- bHaveCon=TRUE;
- }
- if(!bHaveCon)
- {
- strSQL="select * from student";
- }
- RefreshData(strSQL);
- }
- void CStudentDlg::RefreshData(CString strSQL)
- {
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- UpdateData(TRUE);
- // strSQL="select * from dept";
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- CString strTime;
- while(!m_recordset.IsEOF())
- {
- m_ctrList.InsertItem(i,m_recordset.m_code);
- m_ctrList.SetItemText(i,1,m_recordset.m_name);
- m_ctrList.SetItemText(i,2,m_recordset.m_oldname);
- m_ctrList.SetItemText(i,3,m_recordset.m_sex);
- strTime.Format("%d-%d-%d",m_recordset.m_birthday.GetYear(),m_recordset.m_birthday.GetMonth(),m_recordset.m_birthday.GetDay());
- m_ctrList.SetItemText(i,4,strTime);
- m_ctrList.SetItemText(i,5,m_recordset.m_folk);
- m_ctrList.SetItemText(i,6,m_recordset.m_political);
- m_ctrList.SetItemText(i,7,m_recordset.m_native);
- m_ctrList.SetItemText(i,8,m_recordset.m_family);
- m_ctrList.SetItemText(i,9,m_recordset.m_phone);
- m_ctrList.SetItemText(i,10,m_recordset.m_postcode);
- m_ctrList.SetItemText(i,11,m_recordset.m_address);
- m_ctrList.SetItemText(i,12,m_recordset.m_IDCard);
- strTime.Format("%d-%d-%d",m_recordset.m_enroll_date.GetYear(),m_recordset.m_enroll_date.GetMonth(),m_recordset.m_enroll_date.GetDay());
- m_ctrList.SetItemText(i,13,strTime);
- strTime.Format("%d-%d-%d",m_recordset.m_graduate_date.GetYear(),m_recordset.m_graduate_date.GetMonth(),m_recordset.m_graduate_date.GetDay());
- m_ctrList.SetItemText(i,14,strTime);
- m_ctrList.SetItemText(i,15,m_recordset.m_class);
- m_ctrList.SetItemText(i,16,m_recordset.m_department);
- m_ctrList.SetItemText(i,17,m_recordset.m_major);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- }