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

数据库系统

开发平台:

Visual C++

  1. // ChangeInsideInfoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "school.h"
  5. #include "ChangeInsideInfoDlg.h"
  6. #include "departmentset.h"
  7. #include "majorset.h"
  8. #include "classset.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CChangeInsideInfoDlg dialog
  16. CChangeInsideInfoDlg::CChangeInsideInfoDlg(CWnd* pParent /*=NULL*/)
  17. : CDialog(CChangeInsideInfoDlg::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CChangeInsideInfoDlg)
  20. m_strDepartment = _T("");
  21. m_strSubject = _T("");
  22. m_strClass = _T("");
  23. m_strCode = _T("");
  24. m_strBrief = _T("");
  25. m_strName = _T("");
  26. m_strDate = _T("");
  27. //}}AFX_DATA_INIT
  28. }
  29. void CChangeInsideInfoDlg::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CChangeInsideInfoDlg)
  33. DDX_Control(pDX, IDC_COMBO3_CLASS, m_ctrClass);
  34. DDX_Control(pDX, IDC_COMBO2_SUBJECT, m_ctrSubject);
  35. DDX_Control(pDX, IDC_COMBO1_DEPARTMENT, m_ctrDepartment);
  36. DDX_CBString(pDX, IDC_COMBO1_DEPARTMENT, m_strDepartment);
  37. DDX_CBString(pDX, IDC_COMBO2_SUBJECT, m_strSubject);
  38. DDX_CBString(pDX, IDC_COMBO3_CLASS, m_strClass);
  39. DDX_Text(pDX, IDC_EDIT1_CODE, m_strCode);
  40. DDX_Text(pDX, IDC_EDIT2_BRIEF, m_strBrief);
  41. DDX_Text(pDX, IDC_EDIT4_NAME, m_strName);
  42. DDX_Text(pDX, IDC_EDIT5_DATE, m_strDate);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CChangeInsideInfoDlg, CDialog)
  46. //{{AFX_MSG_MAP(CChangeInsideInfoDlg)
  47. ON_CBN_SELCHANGE(IDC_COMBO1_DEPARTMENT, OnSelchangeCombo1Department)
  48. ON_CBN_SELCHANGE(IDC_COMBO2_SUBJECT, OnSelchangeCombo2Subject)
  49. ON_CBN_SETFOCUS(IDC_COMBO2_SUBJECT, OnSetfocusCombo2Subject)
  50. ON_CBN_SETFOCUS(IDC_COMBO3_CLASS, OnSetfocusCombo3Class)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CChangeInsideInfoDlg message handlers
  55. BOOL CChangeInsideInfoDlg::OnInitDialog() 
  56. {
  57. CDialog::OnInitDialog();
  58. CDepartmentSet DeptSet ;
  59. CString strSQL;
  60. strSQL="select * from department";
  61. if(!DeptSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  62. {
  63. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  64. }
  65. while(!DeptSet.IsEOF())
  66. {
  67. m_ctrDepartment.AddString(DeptSet.m_name);
  68. DeptSet.MoveNext();
  69. }
  70. DeptSet.Close();
  71. return TRUE;  // return TRUE unless you set the focus to a control
  72.               // EXCEPTION: OCX Property Pages should return FALSE
  73. }
  74. void CChangeInsideInfoDlg::OnOK() 
  75. {
  76. // TODO: Add extra validation here
  77. UpdateData();
  78. if(m_strDepartment.IsEmpty())
  79. {
  80. AfxMessageBox("请输入申请系别!");
  81. return;
  82. }
  83. if(m_strCode.IsEmpty())
  84. {
  85. AfxMessageBox("请输入编号!");
  86. return;
  87. }
  88. if(m_strClass.IsEmpty())
  89. {
  90. AfxMessageBox("请输入申请班级!");
  91. return;
  92. }
  93. if(m_strSubject.IsEmpty())
  94. {
  95. AfxMessageBox("请输入申请专业!");
  96. return;
  97. }
  98. if(m_strName.IsEmpty())
  99. {
  100. AfxMessageBox("请输入申请人姓名!");
  101. return;
  102. }
  103. CDialog::OnOK();
  104. }
  105. void CChangeInsideInfoDlg::OnSelchangeCombo1Department() 
  106. {
  107. // TODO: Add your control notification handler code here
  108. UpdateData();
  109. //清空ComboBox查询内容//////////////////////
  110. int nCount=m_ctrSubject.GetCount();
  111. for(int i=0;i<nCount;i++)
  112. {
  113. m_ctrSubject.DeleteString(0);
  114. }
  115. nCount=m_ctrClass.GetCount();
  116. for(i=0;i<nCount;i++)
  117. {
  118. m_ctrClass.DeleteString(0);
  119. }
  120. }
  121. void CChangeInsideInfoDlg::OnSelchangeCombo2Subject() 
  122. {
  123. // TODO: Add your control notification handler code here
  124. UpdateData();
  125. //清空ComboBox查询内容//////////////////////
  126. int nCount=m_ctrClass.GetCount();
  127. for(int i=0;i<nCount;i++)
  128. {
  129. m_ctrClass.DeleteString(0);
  130. }
  131. }
  132. void CChangeInsideInfoDlg::OnSetfocusCombo2Subject() 
  133. {
  134. // TODO: Add your control notification handler code here
  135. UpdateData();
  136. CString strSQL;
  137. //清空ComboBox查询内容//////////////////////
  138. int nCount=m_ctrSubject.GetCount();
  139. for(int i=0;i<nCount;i++)
  140. {
  141. m_ctrSubject.DeleteString(0);
  142. }
  143. nCount=m_ctrClass.GetCount();
  144. for(i=0;i<nCount;i++)
  145. {
  146. m_ctrClass.DeleteString(0);
  147. }
  148. ///////////////////////////////////////////
  149. CMajorSet recordset ;
  150. strSQL.Format( "select * from major where department = '%s'",m_strDepartment);
  151. if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  152. {
  153. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  154. return ;
  155. }
  156. while(!recordset.IsEOF())
  157. {
  158. m_ctrSubject.AddString(recordset.m_name);
  159. recordset.MoveNext();
  160. }
  161. recordset.Close();
  162. }
  163. void CChangeInsideInfoDlg::OnSetfocusCombo3Class() 
  164. {
  165. // TODO: Add your control notification handler code here
  166. UpdateData();
  167. CString strSQL;
  168. //清空ComboBox查询内容//////////////////////
  169. int nCount=m_ctrClass.GetCount();
  170. for(int i=0;i<nCount;i++)
  171. {
  172. m_ctrClass.DeleteString(0);
  173. }
  174. ///////////////////////////////////////////
  175. CClassSet recordset ;
  176. strSQL.Format( "select * from class where department = '%s' and major = '%s'",m_strDepartment,m_strSubject);
  177. if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  178. {
  179. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  180. return ;
  181. }
  182. while(!recordset.IsEOF())
  183. {
  184. m_ctrClass.AddString(recordset.m_name);
  185. recordset.MoveNext();
  186. }
  187. recordset.Close();
  188. }