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

数据库系统

开发平台:

Visual C++

  1. // ScoreQueryDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "school.h"
  5. #include "ScoreQueryDlg.h"
  6. #include "classset.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CScoreQueryDlg dialog
  14. CScoreQueryDlg::CScoreQueryDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CScoreQueryDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CScoreQueryDlg)
  18. m_strClass = _T("");
  19. m_strName = _T("");
  20. //}}AFX_DATA_INIT
  21. }
  22. void CScoreQueryDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CScoreQueryDlg)
  26. DDX_Control(pDX, IDC_LIST2, m_ctrScoreList);
  27. DDX_Control(pDX, IDC_LIST1, m_ctrStuList);
  28. DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
  29. DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
  30. DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CScoreQueryDlg, CDialog)
  34. //{{AFX_MSG_MAP(CScoreQueryDlg)
  35. ON_BN_CLICKED(IDC_BUTTON_LIST, OnButtonList)
  36. ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
  37. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CScoreQueryDlg message handlers
  42. BOOL CScoreQueryDlg::OnInitDialog() 
  43. {
  44. CDialog::OnInitDialog();
  45. CString strSQL;
  46. //初始化班级
  47. CClassSet ClassSet ;
  48. strSQL="select * from class";
  49. if(!ClassSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  50. {
  51. AfxMessageBox("打开数据库失败!");
  52. }
  53. while(!ClassSet.IsEOF())
  54. {
  55. m_ctrClass.AddString(ClassSet.m_code);
  56. ClassSet.MoveNext();
  57. }
  58. ClassSet.Close();
  59. //初始化成绩列表
  60. m_ctrStuList.InsertColumn(0,"学号");
  61. m_ctrStuList.InsertColumn(1,"姓名");
  62. m_ctrStuList.SetColumnWidth(0,60);
  63. m_ctrStuList.SetColumnWidth(1,80);
  64. m_ctrStuList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  65. m_ctrScoreList.InsertColumn(0,"时间段");
  66. m_ctrScoreList.InsertColumn(1,"科目");
  67. m_ctrScoreList.InsertColumn(2,"考试类型");
  68. m_ctrScoreList.InsertColumn(3,"成绩");
  69. m_ctrScoreList.InsertColumn(4,"补考成绩");
  70. m_ctrScoreList.SetColumnWidth(0,100);
  71. m_ctrScoreList.SetColumnWidth(1,80);
  72. m_ctrScoreList.SetColumnWidth(2,80);
  73. m_ctrScoreList.SetColumnWidth(3,80);
  74. m_ctrScoreList.SetColumnWidth(4,80);
  75. m_ctrScoreList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  76. return TRUE;  // return TRUE unless you set the focus to a control
  77.               // EXCEPTION: OCX Property Pages should return FALSE
  78. }
  79. void CScoreQueryDlg::OnButtonList() 
  80. {
  81. // TODO: Add your control notification handler code here
  82. UpdateData();
  83. if(m_strClass.IsEmpty())
  84. {
  85. AfxMessageBox("请选择班级!");
  86. return;
  87. }
  88. CString strSQL;
  89. m_ctrStuList.DeleteAllItems();
  90. m_ctrStuList.SetRedraw(FALSE);
  91. UpdateData(TRUE);
  92. strSQL.Format("select * from student where class = '%s'",m_strClass);
  93. if(!m_studentSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  94. {
  95. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  96. return ;
  97. }
  98. int i=0;
  99. while(!m_studentSet.IsEOF())
  100. {
  101. m_ctrStuList.InsertItem(i,m_studentSet.m_code);
  102. m_ctrStuList.SetItemText(i,1,m_studentSet.m_name);
  103. i++;
  104. m_studentSet.MoveNext();
  105. }
  106. m_studentSet.Close();
  107. m_ctrStuList.SetRedraw(TRUE);
  108. }
  109. void CScoreQueryDlg::OnButtonSearch() 
  110. {
  111. UpdateData(TRUE);
  112. if(m_strName.IsEmpty())
  113. {
  114. AfxMessageBox("请输入学生姓名!");
  115. return;
  116. }
  117. CString strSQL;
  118. strSQL.Format("select * from score where name like '%s'",m_strName);
  119. RefreshData(strSQL);
  120. }
  121. void CScoreQueryDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
  122. {
  123. // TODO: Add your control notification handler code here
  124. CString strSQL;
  125. UpdateData(TRUE);
  126. int i = m_ctrStuList.GetSelectionMark();
  127. strSQL.Format("select * from score where code='%s'",m_ctrStuList.GetItemText(i,0));
  128. RefreshData(strSQL);
  129. *pResult = 0;
  130. }
  131. void CScoreQueryDlg::RefreshData(CString strSQL)
  132. {
  133. m_ctrScoreList.DeleteAllItems();
  134. m_ctrScoreList.SetRedraw(FALSE);
  135. UpdateData(TRUE);
  136. if(!m_scoreSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  137. {
  138. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  139. return ;
  140. }
  141. int i=0;
  142. char buffer[20];
  143. while(!m_scoreSet.IsEOF())
  144. {
  145. _ltoa(m_scoreSet.m_ID,buffer,10);
  146. m_ctrScoreList.InsertItem(i,m_scoreSet.m_time);
  147. m_ctrScoreList.SetItemText(i,1,m_scoreSet.m_subject);
  148. m_ctrScoreList.SetItemText(i,2,m_scoreSet.m_type);
  149. _ltoa(m_scoreSet.m_score,buffer,10);
  150. m_ctrScoreList.SetItemText(i,3,buffer);
  151. _ltoa(m_scoreSet.m_makeup_score,buffer,10);
  152. m_ctrScoreList.SetItemText(i,4,buffer);
  153. i++;
  154. m_scoreSet.MoveNext();
  155. }
  156. m_scoreSet.Close();
  157. m_ctrScoreList.SetRedraw(TRUE);
  158. }