ScoreClassStatDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:6k
源码类别:
数据库系统
开发平台:
Visual C++
- // ScoreClassStatDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ScoreClassStatDlg.h"
- #include "classset.h"
- #include "examtimeset.h"
- #include "examtypeset.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CScoreClassStatDlg dialog
- CScoreClassStatDlg::CScoreClassStatDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CScoreClassStatDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CScoreClassStatDlg)
- m_strClass = _T("");
- m_strTime = _T("");
- m_strType = _T("");
- //}}AFX_DATA_INIT
- }
- void CScoreClassStatDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CScoreClassStatDlg)
- 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_CLASS, m_ctrClass);
- DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
- DDX_CBString(pDX, IDC_COMBO_TIME, m_strTime);
- DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CScoreClassStatDlg, CDialog)
- //{{AFX_MSG_MAP(CScoreClassStatDlg)
- ON_BN_CLICKED(IDC_BUTTON_STAT, OnButtonStat)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScoreClassStatDlg message handlers
- BOOL CScoreClassStatDlg::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();
- //初始化成绩列表
- 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.SetColumnWidth(0,100);
- m_ctrList.SetColumnWidth(1,60);
- m_ctrList.SetColumnWidth(2,60);
- m_ctrList.SetColumnWidth(3,60);
- m_ctrList.SetColumnWidth(4,80);
- m_ctrList.SetColumnWidth(5,60);
- m_ctrList.SetColumnWidth(6,60);
- m_ctrList.SetColumnWidth(7,60);
- 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 CScoreClassStatDlg::OnButtonStat()
- {
- UpdateData();
- if(m_strClass.IsEmpty())
- {
- AfxMessageBox("请选择班级");
- return;
- }
- if(m_strTime.IsEmpty())
- {
- AfxMessageBox("请选择考试时间段");
- return;
- }
- if(m_strType.IsEmpty())
- {
- AfxMessageBox("请选择考试类型");
- return;
- }
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- CString strSQL;
- CString strValue="0";
- CDatabase db;
- db.Open(_T("school"));
- CRecordset rs1(&db);
- CRecordset rs2(&db);
- CRecordset rs3(&db);
- CRecordset rs4(&db);
- strSQL.Format("select subject,
- count(ID) as student ,
- sum(score) as total from score
- where class = '%s' and time = '%s'
- and type = '%s' group by subject"
- ,m_strClass,m_strTime,m_strType);
- if(!rs1.Open(CRecordset::forwardOnly,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- int nStudent =0,nPass=0,nTotal=0,nSuper;
- CString strSubject="";
- char buffer[20];
- while(!rs1.IsEOF())
- {
- //科目
- rs1.GetFieldValue("subject",strValue);
- m_ctrList.InsertItem(i,strValue);
- strSubject = strValue;
- //参考人数
- rs1.GetFieldValue("student",strValue);
- nStudent=atoi(strValue);
- m_ctrList.SetItemText(i,1,strValue);
- //缺考人数
- strSQL.Format("select count(ID) as nAbsent from score
- where class = '%s' and time = '%s'
- and type = '%s' and absent = '是'
- and subject = '%s' "
- ,m_strClass,m_strTime,m_strType,strSubject);
- if(!rs2.Open(CRecordset::forwardOnly,strSQL))
- {
- rs1.Close();
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- rs2.GetFieldValue("nAbsent",strValue);
- m_ctrList.SetItemText(i,2,strValue);
- rs2.Close();
- //平均成绩
- rs1.GetFieldValue("total",strValue);
- nTotal=atoi(strValue);
- _itoa(nTotal/nStudent,buffer,10);
- m_ctrList.SetItemText(i,3,buffer);
- //不及格人数
- strSQL.Format("select count(ID) as nPass from score
- where class = '%s' and time = '%s'
- and type = '%s' and score < 60
- and subject = '%s' "
- ,m_strClass,m_strTime,m_strType,strSubject);
- if(!rs3.Open(CRecordset::forwardOnly,strSQL))
- {
- rs1.Close();
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- rs3.GetFieldValue("nPass",strValue);
- m_ctrList.SetItemText(i,4,strValue);
- rs3.Close();
- //及格率
- nPass = nStudent - atoi(strValue);
- itoa( (int)(nPass*100/nStudent), buffer,10 );
- m_ctrList.SetItemText(i,5,buffer);
- //优秀率
- strSQL.Format("select count(ID) as nSuper from score
- where class = '%s' and time = '%s'
- and type = '%s' and score >= 60
- and subject = '%s' "
- ,m_strClass,m_strTime,m_strType,strSubject);
- if(!rs4.Open(CRecordset::forwardOnly,strSQL))
- {
- rs1.Close();
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- rs4.GetFieldValue("nSuper",strValue);
- m_ctrList.SetItemText(i,6,strValue);
- rs4.Close();
- //优秀率
- nSuper = atoi(strValue);
- itoa( (int)(nSuper*100/nStudent), buffer,10 );
- m_ctrList.SetItemText(i,7,buffer);
- i++;
- rs1.MoveNext();
- }
- rs1.Close();
- m_ctrList.SetRedraw(TRUE);
- }