ScoreSingleDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:5k
源码类别:
数据库系统
开发平台:
Visual C++
- // ScoreSingleDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ScoreSingleDlg.h"
- #include "classset.h"
- #include "examtimeset.h"
- #include "examsubjectset.h"
- #include "examtypeset.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CScoreSingleDlg dialog
- CScoreSingleDlg::CScoreSingleDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CScoreSingleDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CScoreSingleDlg)
- m_strClass = _T("");
- m_strSubject = _T("");
- m_strTime = _T("");
- m_strType = _T("");
- //}}AFX_DATA_INIT
- }
- void CScoreSingleDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CScoreSingleDlg)
- DDX_Control(pDX, IDC_LIST2, m_ctrList);
- DDX_Control(pDX, IDC_COMBO_TYPE, m_ctrType);
- DDX_Control(pDX, IDC_COMBO_TIME, m_ctrTime);
- DDX_Control(pDX, IDC_COMBO_SUBJECT, m_ctrSubject);
- DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
- DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
- DDX_CBString(pDX, IDC_COMBO_SUBJECT, m_strSubject);
- DDX_CBString(pDX, IDC_COMBO_TIME, m_strTime);
- DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CScoreSingleDlg, CDialog)
- //{{AFX_MSG_MAP(CScoreSingleDlg)
- ON_BN_CLICKED(IDC_BUTTON_STAT, OnButtonStat)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScoreSingleDlg message handlers
- BOOL CScoreSingleDlg::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();
- //初始化时间段
- CExamtimeSet TimeSet ;
- strSQL="select * from examtime";
- if(!TimeSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!TimeSet.IsEOF())
- {
- m_ctrTime.AddString(TimeSet.m_time);
- TimeSet.MoveNext();
- }
- TimeSet.Close();
- //初始化考试类型
- CExamtypeSet TypeSet ;
- strSQL="select * from examtype";
- if(!TypeSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!TypeSet.IsEOF())
- {
- m_ctrType.AddString(TypeSet.m_name);
- TypeSet.MoveNext();
- }
- TypeSet.Close();
- //初始化考试科目
- CExamSubjectSet SubjectSet ;
- strSQL="select * from examsubject";
- if(!SubjectSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!SubjectSet.IsEOF())
- {
- m_ctrSubject.AddString(SubjectSet.m_name);
- SubjectSet.MoveNext();
- }
- SubjectSet.Close();
- //初始化成绩列表
- m_ctrList.InsertColumn(0,"学号");
- m_ctrList.InsertColumn(1,"姓名");
- m_ctrList.InsertColumn(2,"班级");
- m_ctrList.InsertColumn(3,"成绩");
- m_ctrList.InsertColumn(4,"名次");
- m_ctrList.SetColumnWidth(0,80);
- m_ctrList.SetColumnWidth(1,80);
- m_ctrList.SetColumnWidth(2,100);
- m_ctrList.SetColumnWidth(3,80);
- m_ctrList.SetColumnWidth(4,80);
- 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 CScoreSingleDlg::OnButtonStat()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(m_strClass.IsEmpty())
- {
- AfxMessageBox("请选择班级");
- return;
- }
- if(m_strTime.IsEmpty())
- {
- AfxMessageBox("请选择考试时间段");
- return;
- }
- if(m_strType.IsEmpty())
- {
- AfxMessageBox("请选择考试类型");
- return;
- }
- if(m_strSubject.IsEmpty())
- {
- AfxMessageBox("请选择考试科目");
- return;
- }
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- CString strSQL;
- strSQL.Format("select * from score
- where class = '%s' and time = '%s'
- and type = '%s' and subject = '%s'
- order by score desc"
- ,m_strClass,m_strTime,m_strType,m_strSubject);
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- char buffer[20];
- 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_class);
- //成绩
- _ltoa(m_recordset.m_score,buffer,10);
- m_ctrList.SetItemText(i,3,buffer);
- //名次
- _itoa(i+1,buffer,10);
- m_ctrList.SetItemText(i,4,buffer);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- }