ScoreQueryDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:5k
源码类别:
数据库系统
开发平台:
Visual C++
- // ScoreQueryDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ScoreQueryDlg.h"
- #include "classset.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CScoreQueryDlg dialog
- CScoreQueryDlg::CScoreQueryDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CScoreQueryDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CScoreQueryDlg)
- m_strClass = _T("");
- m_strName = _T("");
- //}}AFX_DATA_INIT
- }
- void CScoreQueryDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CScoreQueryDlg)
- DDX_Control(pDX, IDC_LIST2, m_ctrScoreList);
- DDX_Control(pDX, IDC_LIST1, m_ctrStuList);
- DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
- DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
- DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CScoreQueryDlg, CDialog)
- //{{AFX_MSG_MAP(CScoreQueryDlg)
- ON_BN_CLICKED(IDC_BUTTON_LIST, OnButtonList)
- ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScoreQueryDlg message handlers
- BOOL CScoreQueryDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CString strSQL;
- //初始化班级
- CClassSet ClassSet ;
- strSQL="select * from class";
- if(!ClassSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!ClassSet.IsEOF())
- {
- m_ctrClass.AddString(ClassSet.m_code);
- ClassSet.MoveNext();
- }
- ClassSet.Close();
- //初始化成绩列表
- m_ctrStuList.InsertColumn(0,"学号");
- m_ctrStuList.InsertColumn(1,"姓名");
- m_ctrStuList.SetColumnWidth(0,60);
- m_ctrStuList.SetColumnWidth(1,80);
- m_ctrStuList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- m_ctrScoreList.InsertColumn(0,"时间段");
- m_ctrScoreList.InsertColumn(1,"科目");
- m_ctrScoreList.InsertColumn(2,"考试类型");
- m_ctrScoreList.InsertColumn(3,"成绩");
- m_ctrScoreList.InsertColumn(4,"补考成绩");
- m_ctrScoreList.SetColumnWidth(0,100);
- m_ctrScoreList.SetColumnWidth(1,80);
- m_ctrScoreList.SetColumnWidth(2,80);
- m_ctrScoreList.SetColumnWidth(3,80);
- m_ctrScoreList.SetColumnWidth(4,80);
- m_ctrScoreList.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 CScoreQueryDlg::OnButtonList()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(m_strClass.IsEmpty())
- {
- AfxMessageBox("请选择班级!");
- return;
- }
- CString strSQL;
- m_ctrStuList.DeleteAllItems();
- m_ctrStuList.SetRedraw(FALSE);
- UpdateData(TRUE);
- strSQL.Format("select * from student where class = '%s'",m_strClass);
- if(!m_studentSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- while(!m_studentSet.IsEOF())
- {
- m_ctrStuList.InsertItem(i,m_studentSet.m_code);
- m_ctrStuList.SetItemText(i,1,m_studentSet.m_name);
- i++;
- m_studentSet.MoveNext();
- }
- m_studentSet.Close();
- m_ctrStuList.SetRedraw(TRUE);
- }
- void CScoreQueryDlg::OnButtonSearch()
- {
- UpdateData(TRUE);
- if(m_strName.IsEmpty())
- {
- AfxMessageBox("请输入学生姓名!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from score where name like '%s'",m_strName);
- RefreshData(strSQL);
- }
- void CScoreQueryDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CString strSQL;
- UpdateData(TRUE);
- int i = m_ctrStuList.GetSelectionMark();
- strSQL.Format("select * from score where code='%s'",m_ctrStuList.GetItemText(i,0));
- RefreshData(strSQL);
- *pResult = 0;
- }
- void CScoreQueryDlg::RefreshData(CString strSQL)
- {
- m_ctrScoreList.DeleteAllItems();
- m_ctrScoreList.SetRedraw(FALSE);
- UpdateData(TRUE);
- if(!m_scoreSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- char buffer[20];
- while(!m_scoreSet.IsEOF())
- {
- _ltoa(m_scoreSet.m_ID,buffer,10);
- m_ctrScoreList.InsertItem(i,m_scoreSet.m_time);
- m_ctrScoreList.SetItemText(i,1,m_scoreSet.m_subject);
- m_ctrScoreList.SetItemText(i,2,m_scoreSet.m_type);
- _ltoa(m_scoreSet.m_score,buffer,10);
- m_ctrScoreList.SetItemText(i,3,buffer);
- _ltoa(m_scoreSet.m_makeup_score,buffer,10);
- m_ctrScoreList.SetItemText(i,4,buffer);
- i++;
- m_scoreSet.MoveNext();
- }
- m_scoreSet.Close();
- m_ctrScoreList.SetRedraw(TRUE);
- }