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

数据库系统

开发平台:

Visual C++

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