ScoreSingleDlg.cpp
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:5k
源码类别:

数据库系统

开发平台:

Visual C++

  1. // ScoreSingleDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "school.h"
  5. #include "ScoreSingleDlg.h"
  6. #include "classset.h"
  7. #include "examtimeset.h"
  8. #include "examsubjectset.h"
  9. #include "examtypeset.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CScoreSingleDlg dialog
  17. CScoreSingleDlg::CScoreSingleDlg(CWnd* pParent /*=NULL*/)
  18. : CDialog(CScoreSingleDlg::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(CScoreSingleDlg)
  21. m_strClass = _T("");
  22. m_strSubject = _T("");
  23. m_strTime = _T("");
  24. m_strType = _T("");
  25. //}}AFX_DATA_INIT
  26. }
  27. void CScoreSingleDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CScoreSingleDlg)
  31. DDX_Control(pDX, IDC_LIST2, m_ctrList);
  32. DDX_Control(pDX, IDC_COMBO_TYPE, m_ctrType);
  33. DDX_Control(pDX, IDC_COMBO_TIME, m_ctrTime);
  34. DDX_Control(pDX, IDC_COMBO_SUBJECT, m_ctrSubject);
  35. DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
  36. DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
  37. DDX_CBString(pDX, IDC_COMBO_SUBJECT, m_strSubject);
  38. DDX_CBString(pDX, IDC_COMBO_TIME, m_strTime);
  39. DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CScoreSingleDlg, CDialog)
  43. //{{AFX_MSG_MAP(CScoreSingleDlg)
  44. ON_BN_CLICKED(IDC_BUTTON_STAT, OnButtonStat)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CScoreSingleDlg message handlers
  49. BOOL CScoreSingleDlg::OnInitDialog() 
  50. {
  51. CDialog::OnInitDialog();
  52. CString strSQL;
  53. //初始化班级
  54. CClassSet ClassSet ;
  55. strSQL="select * from class";
  56. if(!ClassSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  57. {
  58. AfxMessageBox("打开数据库失败!");
  59. }
  60. while(!ClassSet.IsEOF())
  61. {
  62. m_ctrClass.AddString(ClassSet.m_code);
  63. ClassSet.MoveNext();
  64. }
  65. ClassSet.Close();
  66. //初始化时间段
  67. CExamtimeSet TimeSet ;
  68. strSQL="select * from examtime";
  69. if(!TimeSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  70. {
  71. AfxMessageBox("打开数据库失败!");
  72. }
  73. while(!TimeSet.IsEOF())
  74. {
  75. m_ctrTime.AddString(TimeSet.m_time);
  76. TimeSet.MoveNext();
  77. }
  78. TimeSet.Close();
  79. //初始化考试类型
  80. CExamtypeSet TypeSet ;
  81. strSQL="select * from examtype";
  82. if(!TypeSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  83. {
  84. AfxMessageBox("打开数据库失败!");
  85. }
  86. while(!TypeSet.IsEOF())
  87. {
  88. m_ctrType.AddString(TypeSet.m_name);
  89. TypeSet.MoveNext();
  90. }
  91. TypeSet.Close();
  92. //初始化考试科目
  93. CExamSubjectSet SubjectSet ;
  94. strSQL="select * from examsubject";
  95. if(!SubjectSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  96. {
  97. AfxMessageBox("打开数据库失败!");
  98. }
  99. while(!SubjectSet.IsEOF())
  100. {
  101. m_ctrSubject.AddString(SubjectSet.m_name);
  102. SubjectSet.MoveNext();
  103. }
  104. SubjectSet.Close();
  105. //初始化成绩列表
  106. m_ctrList.InsertColumn(0,"学号");
  107. m_ctrList.InsertColumn(1,"姓名");
  108. m_ctrList.InsertColumn(2,"班级");
  109. m_ctrList.InsertColumn(3,"成绩");
  110. m_ctrList.InsertColumn(4,"名次");
  111. m_ctrList.SetColumnWidth(0,80);
  112. m_ctrList.SetColumnWidth(1,80);
  113. m_ctrList.SetColumnWidth(2,100);
  114. m_ctrList.SetColumnWidth(3,80);
  115. m_ctrList.SetColumnWidth(4,80);
  116. m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  117. return TRUE;  // return TRUE unless you set the focus to a control
  118.               // EXCEPTION: OCX Property Pages should return FALSE
  119. }
  120. void CScoreSingleDlg::OnButtonStat() 
  121. {
  122. // TODO: Add your control notification handler code here
  123. UpdateData();
  124. if(m_strClass.IsEmpty())
  125. {
  126. AfxMessageBox("请选择班级");
  127. return;
  128. }
  129. if(m_strTime.IsEmpty())
  130. {
  131. AfxMessageBox("请选择考试时间段");
  132. return;
  133. }
  134. if(m_strType.IsEmpty())
  135. {
  136. AfxMessageBox("请选择考试类型");
  137. return;
  138. }
  139. if(m_strSubject.IsEmpty())
  140. {
  141. AfxMessageBox("请选择考试科目");
  142. return;
  143. }
  144. m_ctrList.DeleteAllItems();
  145. m_ctrList.SetRedraw(FALSE);
  146. CString strSQL;
  147. strSQL.Format("select * from score 
  148. where class = '%s' and time = '%s' 
  149. and type = '%s' and subject = '%s'  
  150. order by score desc"
  151. ,m_strClass,m_strTime,m_strType,m_strSubject);
  152. if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  153. {
  154. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  155. return ;
  156. }
  157. int i=0;
  158. char buffer[20];
  159. while(!m_recordset.IsEOF())
  160. {
  161. //学号
  162. m_ctrList.InsertItem(i,m_recordset.m_code);
  163. //姓名
  164. m_ctrList.SetItemText(i,1,m_recordset.m_name);
  165. //班级
  166. m_ctrList.SetItemText(i,2,m_recordset.m_class);
  167. //成绩
  168. _ltoa(m_recordset.m_score,buffer,10);
  169. m_ctrList.SetItemText(i,3,buffer);
  170. //名次
  171. _itoa(i+1,buffer,10);
  172. m_ctrList.SetItemText(i,4,buffer);
  173. i++;
  174. m_recordset.MoveNext();
  175. }
  176. m_recordset.Close();
  177. m_ctrList.SetRedraw(TRUE);
  178. }