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

数据库系统

开发平台:

Visual C++

  1. // ChangeSuspandDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "school.h"
  5. #include "ChangeSuspandDlg.h"
  6. #include "ChangeSuspandInfoDlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CChangeSuspandDlg dialog
  14. CChangeSuspandDlg::CChangeSuspandDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CChangeSuspandDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CChangeSuspandDlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. }
  21. void CChangeSuspandDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CChangeSuspandDlg)
  25. DDX_Control(pDX, IDC_LIST1, m_ctrList);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CChangeSuspandDlg, CDialog)
  29. //{{AFX_MSG_MAP(CChangeSuspandDlg)
  30. ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
  31. ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
  32. ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
  33. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CChangeSuspandDlg message handlers
  38. BOOL CChangeSuspandDlg::OnInitDialog() 
  39. {
  40. CDialog::OnInitDialog();
  41. m_ctrList.InsertColumn(0,"编号");
  42. m_ctrList.InsertColumn(1,"休学人");
  43. m_ctrList.InsertColumn(2,"班级");
  44. m_ctrList.InsertColumn(3,"离校时间");
  45. m_ctrList.InsertColumn(4,"休学时间");
  46. m_ctrList.InsertColumn(5,"休学原因");
  47. m_ctrList.SetColumnWidth(0,80);
  48. m_ctrList.SetColumnWidth(1,80);
  49. m_ctrList.SetColumnWidth(2,80);
  50. m_ctrList.SetColumnWidth(3,80);
  51. m_ctrList.SetColumnWidth(4,80);
  52. m_ctrList.SetColumnWidth(5,120);
  53. m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  54. RefreshData();
  55. return TRUE;  // return TRUE unless you set the focus to a control
  56.               // EXCEPTION: OCX Property Pages should return FALSE
  57. }
  58. void CChangeSuspandDlg::RefreshData()
  59. {
  60. m_ctrList.DeleteAllItems();
  61. m_ctrList.SetRedraw(FALSE);
  62. UpdateData(TRUE);
  63. CString strSQL;
  64. strSQL="select * from suspand";
  65. if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  66. {
  67. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  68. return ;
  69. }
  70. int i=0;
  71. while(!m_recordset.IsEOF())
  72. {
  73. m_ctrList.InsertItem(i,m_recordset.m_code);
  74. m_ctrList.SetItemText(i,1,m_recordset.m_name);
  75. m_ctrList.SetItemText(i,2,m_recordset.m_class);
  76. m_ctrList.SetItemText(i,3,m_recordset.m_date);
  77. m_ctrList.SetItemText(i,4,m_recordset.m_time);
  78. m_ctrList.SetItemText(i,5,m_recordset.m_reason);
  79. i++;
  80. m_recordset.MoveNext();
  81. }
  82. m_recordset.Close();
  83. m_ctrList.SetRedraw(TRUE);
  84. }
  85. void CChangeSuspandDlg::OnButtonNew() 
  86. {
  87. // TODO: Add your control notification handler code here
  88. CString strSQL;
  89. CChangeSuspandInfoDlg   Dlg;
  90. while(1)
  91. {
  92. if(IDOK==Dlg.DoModal())
  93. {
  94. strSQL.Format("select * from suspand where code = '%s'",Dlg.m_strCode);
  95. if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  96. {
  97. AfxMessageBox("打开数据库失败!");
  98. return ;
  99. }
  100. if(m_recordset.GetRecordCount()!=0)
  101. {
  102. AfxMessageBox("该编号已经存在!请重新输入!");
  103. m_recordset.Close();
  104. continue;
  105. }
  106. m_recordset.AddNew();
  107. m_recordset.m_name = Dlg.m_strName ;
  108. m_recordset.m_reason = Dlg.m_strBrief ;
  109. m_recordset.m_date =   Dlg.m_strDate ;
  110. m_recordset.m_class = Dlg.m_strClass ;
  111. m_recordset.m_code = Dlg.m_strCode ;
  112. m_recordset.m_time = Dlg.m_strLong ;
  113. m_recordset.Update();
  114. m_recordset.Close();
  115. RefreshData();
  116. }
  117. break;
  118. }
  119. }
  120. void CChangeSuspandDlg::OnButtonModify() 
  121. {
  122. // TODO: Add your control notification handler code here
  123. CChangeSuspandInfoDlg Dlg;
  124. UpdateData();
  125. int i = m_ctrList.GetSelectionMark();
  126. if(0>i)
  127. {
  128. AfxMessageBox("请选择一条记录进行修改!");
  129. return;
  130. }
  131. Dlg.m_strName = m_ctrList.GetItemText(i,1);
  132. Dlg.m_strBrief = m_ctrList.GetItemText(i,5);
  133. Dlg.m_strDate = m_ctrList.GetItemText(i,3);
  134. Dlg.m_strClass = m_ctrList.GetItemText(i,2);
  135. Dlg.m_strCode = m_ctrList.GetItemText(i,0);
  136. Dlg.m_strLong = m_ctrList.GetItemText(i,4);
  137. if(IDOK==Dlg.DoModal())
  138. {//修改记录
  139. CString strSQL;
  140. strSQL.Format("select * from suspand where code = '%s'",m_ctrList.GetItemText(i,0));
  141. if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  142. {
  143. AfxMessageBox("打开数据库失败!");
  144. return ;
  145. }
  146. m_recordset.Edit();
  147. m_recordset.m_name = Dlg.m_strName ;
  148. m_recordset.m_reason = Dlg.m_strBrief ;
  149. m_recordset.m_date =   Dlg.m_strDate ;
  150. m_recordset.m_class = Dlg.m_strClass ;
  151. m_recordset.m_code = Dlg.m_strCode ;
  152. m_recordset.m_time = Dlg.m_strLong ;
  153. m_recordset.Update();
  154. m_recordset.Close();
  155. RefreshData();
  156. }
  157. }
  158. void CChangeSuspandDlg::OnButtonDelete() 
  159. {
  160. // TODO: Add your control notification handler code here
  161. int i = m_ctrList.GetSelectionMark();
  162. if(0>i)
  163. {
  164. AfxMessageBox("请选择一条记录进行查看!");
  165. return;
  166. }
  167. CString strSQL;
  168. strSQL.Format("select * from suspand where code = '%s' ",m_ctrList.GetItemText(i,0));
  169. if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  170. {
  171. AfxMessageBox("打开数据库失败!");
  172. return ;
  173. }
  174. m_recordset.Delete();
  175. m_recordset.Close();
  176. RefreshData();
  177. }
  178. void CChangeSuspandDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
  179. {
  180. // TODO: Add your control notification handler code here
  181. CChangeSuspandInfoDlg Dlg;
  182. UpdateData();
  183. int i = m_ctrList.GetSelectionMark();
  184. if(0>i)
  185. {
  186. AfxMessageBox("请选择一条记录进行修改!");
  187. return;
  188. }
  189. Dlg.m_strName = m_ctrList.GetItemText(i,1);
  190. Dlg.m_strBrief = m_ctrList.GetItemText(i,5);
  191. Dlg.m_strDate = m_ctrList.GetItemText(i,3);
  192. Dlg.m_strClass = m_ctrList.GetItemText(i,2);
  193. Dlg.m_strCode = m_ctrList.GetItemText(i,0);
  194. Dlg.m_strLong = m_ctrList.GetItemText(i,4);
  195. if(IDOK==Dlg.DoModal())
  196. {//修改记录
  197. CString strSQL;
  198. strSQL.Format("select * from suspand where code = '%s'",m_ctrList.GetItemText(i,0));
  199. if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
  200. {
  201. AfxMessageBox("打开数据库失败!");
  202. return ;
  203. }
  204. m_recordset.Edit();
  205. m_recordset.m_name = Dlg.m_strName ;
  206. m_recordset.m_reason = Dlg.m_strBrief ;
  207. m_recordset.m_date =   Dlg.m_strDate ;
  208. m_recordset.m_class = Dlg.m_strClass ;
  209. m_recordset.m_code = Dlg.m_strCode ;
  210. m_recordset.m_time = Dlg.m_strLong ;
  211. m_recordset.Update();
  212. m_recordset.Close();
  213. RefreshData();
  214. }
  215. *pResult = 0;
  216. }