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

数据库系统

开发平台:

Visual C++

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