ChangeInsideDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:7k
源码类别:
数据库系统
开发平台:
Visual C++
- // ChangeInsideDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ChangeInsideDlg.h"
- #include "ChangeInsideInfoDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CChangeInsideDlg dialog
- CChangeInsideDlg::CChangeInsideDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CChangeInsideDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CChangeInsideDlg)
- //}}AFX_DATA_INIT
- }
- void CChangeInsideDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CChangeInsideDlg)
- DDX_Control(pDX, IDC_LIST1, m_ctrList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CChangeInsideDlg, CDialog)
- //{{AFX_MSG_MAP(CChangeInsideDlg)
- ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
- ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
- ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CChangeInsideDlg message handlers
- BOOL CChangeInsideDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_ctrList.InsertColumn(0,"申请编号");
- m_ctrList.InsertColumn(1,"申请人");
- m_ctrList.InsertColumn(2,"申请学院");
- m_ctrList.InsertColumn(3,"申请专业");
- m_ctrList.InsertColumn(4,"申请班级");
- m_ctrList.InsertColumn(5,"办理日期");
- m_ctrList.InsertColumn(6,"说明");
- m_ctrList.SetColumnWidth(0,80);
- m_ctrList.SetColumnWidth(1,80);
- m_ctrList.SetColumnWidth(2,80);
- m_ctrList.SetColumnWidth(3,80);
- m_ctrList.SetColumnWidth(4,80);
- m_ctrList.SetColumnWidth(5,80);
- m_ctrList.SetColumnWidth(6,120);
- m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- RefreshData();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CChangeInsideDlg::RefreshData()
- {
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- UpdateData(TRUE);
- CString strSQL;
- strSQL="select * from outgrade";
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- while(!m_recordset.IsEOF())
- {
- m_ctrList.InsertItem(i,m_recordset.m_code);
- m_ctrList.SetItemText(i,1,m_recordset.m_name);
- m_ctrList.SetItemText(i,2,m_recordset.m_department);
- m_ctrList.SetItemText(i,3,m_recordset.m_major);
- m_ctrList.SetItemText(i,4,m_recordset.m_class);
- m_ctrList.SetItemText(i,5,m_recordset.m_date);
- m_ctrList.SetItemText(i,6,m_recordset.m_brief);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- }
- void CChangeInsideDlg::OnButtonNew()
- {
- // TODO: Add your control notification handler code here
- CString strSQL;
- CChangeInsideInfoDlg Dlg;
- while(1)
- {
- if(IDOK==Dlg.DoModal())
- {
- strSQL.Format("select * from outgrade where code = '%s'",Dlg.m_strCode);
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- if(m_recordset.GetRecordCount()!=0)
- {
- AfxMessageBox("该编号已经存在!请重新输入!");
- m_recordset.Close();
- continue;
- }
- m_recordset.AddNew();
- m_recordset.m_name = Dlg.m_strName ;
- m_recordset.m_brief = Dlg.m_strBrief ;
- m_recordset.m_date = Dlg.m_strDate ;
- m_recordset.m_class = Dlg.m_strClass ;
- m_recordset.m_code = Dlg.m_strCode ;
- m_recordset.m_major = Dlg.m_strSubject ;
- m_recordset.m_department= Dlg.m_strDepartment ;
- m_recordset.Update();
- m_recordset.Close();
- RefreshData();
- }
- break;
- }
- }
- void CChangeInsideDlg::OnButtonModify()
- {
- // TODO: Add your control notification handler code here
- CChangeInsideInfoDlg Dlg;
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行修改!");
- return;
- }
- Dlg.m_strName = m_ctrList.GetItemText(i,1);
- Dlg.m_strBrief = m_ctrList.GetItemText(i,6);
- Dlg.m_strDate = m_ctrList.GetItemText(i,5);
- Dlg.m_strClass = m_ctrList.GetItemText(i,4);
- Dlg.m_strCode = m_ctrList.GetItemText(i,0);
- Dlg.m_strSubject = m_ctrList.GetItemText(i,3);
- Dlg.m_strDepartment = m_ctrList.GetItemText(i,2);
- if(IDOK==Dlg.DoModal())
- {//修改记录
- CString strSQL;
- strSQL.Format("select * from outgrade where code = '%s'",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Edit();
- m_recordset.m_name = Dlg.m_strName ;
- m_recordset.m_brief = Dlg.m_strBrief ;
- m_recordset.m_date = Dlg.m_strDate ;
- m_recordset.m_class = Dlg.m_strClass ;
- m_recordset.m_code = Dlg.m_strCode ;
- m_recordset.m_major = Dlg.m_strSubject ;
- m_recordset.m_department= Dlg.m_strDepartment ;
- m_recordset.Update();
- m_recordset.Close();
- RefreshData();
- }
- }
- void CChangeInsideDlg::OnButtonDelete()
- {
- // TODO: Add your control notification handler code here
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行查看!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from outgrade where code = '%s' ",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Delete();
- m_recordset.Close();
- RefreshData();
- }
- void CChangeInsideDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CChangeInsideInfoDlg Dlg;
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行修改!");
- return;
- }
- Dlg.m_strName = m_ctrList.GetItemText(i,1);
- Dlg.m_strBrief = m_ctrList.GetItemText(i,6);
- Dlg.m_strDate = m_ctrList.GetItemText(i,5);
- Dlg.m_strClass = m_ctrList.GetItemText(i,4);
- Dlg.m_strCode = m_ctrList.GetItemText(i,0);
- Dlg.m_strSubject = m_ctrList.GetItemText(i,3);
- Dlg.m_strDepartment = m_ctrList.GetItemText(i,2);
- if(IDOK==Dlg.DoModal())
- {//修改记录
- CString strSQL;
- strSQL.Format("select * from outgrade where code = '%s'",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Edit();
- m_recordset.m_name = Dlg.m_strName ;
- m_recordset.m_brief = Dlg.m_strBrief ;
- m_recordset.m_date = Dlg.m_strDate ;
- m_recordset.m_class = Dlg.m_strClass ;
- m_recordset.m_code = Dlg.m_strCode ;
- m_recordset.m_major = Dlg.m_strSubject ;
- m_recordset.m_department= Dlg.m_strDepartment ;
- m_recordset.Update();
- m_recordset.Close();
- RefreshData();
- }
- *pResult = 0;
- }