ChangeTranserDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:6k
源码类别:
数据库系统
开发平台:
Visual C++
- // ChangeTranserDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ChangeTranserDlg.h"
- #include "ChangeTransferInfoDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CChangeTranserDlg dialog
- CChangeTranserDlg::CChangeTranserDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CChangeTranserDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CChangeTranserDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CChangeTranserDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CChangeTranserDlg)
- DDX_Control(pDX, IDC_LIST1, m_ctrList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CChangeTranserDlg, CDialog)
- //{{AFX_MSG_MAP(CChangeTranserDlg)
- 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()
- /////////////////////////////////////////////////////////////////////////////
- // CChangeTranserDlg message handlers
- BOOL CChangeTranserDlg::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.SetColumnWidth(0,80);
- m_ctrList.SetColumnWidth(1,80);
- m_ctrList.SetColumnWidth(2,80);
- m_ctrList.SetColumnWidth(3,80);
- m_ctrList.SetColumnWidth(4,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 CChangeTranserDlg::RefreshData()
- {
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- UpdateData(TRUE);
- CString strSQL;
- strSQL="select * from transfer";
- 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_class);
- m_ctrList.SetItemText(i,3,m_recordset.m_date);
- m_ctrList.SetItemText(i,4,m_recordset.m_reason);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- }
- void CChangeTranserDlg::OnButtonNew()
- {
- // TODO: Add your control notification handler code here
- CString strSQL;
- CChangeTransferInfoDlg Dlg;
- while(1)
- {
- if(IDOK==Dlg.DoModal())
- {
- strSQL.Format("select * from transfer 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_reason = 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.Update();
- m_recordset.Close();
- RefreshData();
- }
- break;
- }
- }
- void CChangeTranserDlg::OnButtonModify()
- {
- // TODO: Add your control notification handler code here
- CChangeTransferInfoDlg 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,4);
- Dlg.m_strDate = m_ctrList.GetItemText(i,3);
- Dlg.m_strClass = m_ctrList.GetItemText(i,2);
- Dlg.m_strCode = m_ctrList.GetItemText(i,0);
- if(IDOK==Dlg.DoModal())
- {//修改记录
- CString strSQL;
- strSQL.Format("select * from transfer 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_reason = 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.Update();
- m_recordset.Close();
- RefreshData();
- }
- }
- void CChangeTranserDlg::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 transfer 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 CChangeTranserDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CChangeTransferInfoDlg 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,4);
- Dlg.m_strDate = m_ctrList.GetItemText(i,3);
- Dlg.m_strClass = m_ctrList.GetItemText(i,2);
- Dlg.m_strCode = m_ctrList.GetItemText(i,0);
- if(IDOK==Dlg.DoModal())
- {//修改记录
- CString strSQL;
- strSQL.Format("select * from transfer 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_reason = 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.Update();
- m_recordset.Close();
- RefreshData();
- }
- *pResult = 0;
- }