ExamtimeDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:5k
源码类别:
数据库系统
开发平台:
Visual C++
- // ExamtimeDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ExamtimeDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CExamtimeDlg dialog
- CExamtimeDlg::CExamtimeDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CExamtimeDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CExamtimeDlg)
- m_strName = _T("");
- //}}AFX_DATA_INIT
- }
- void CExamtimeDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CExamtimeDlg)
- DDX_Control(pDX, IDC_LIST1, m_ctrList);
- DDX_Control(pDX, IDC_BUTTON_SAVE, m_bntSave);
- DDX_Control(pDX, IDC_BUTTON_NEW, m_bntNew);
- DDX_Control(pDX, IDC_BUTTON_MODIFY, m_bntModify);
- DDX_Control(pDX, IDC_BUTTON_DELETE, m_bntDelete);
- DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CExamtimeDlg, CDialog)
- //{{AFX_MSG_MAP(CExamtimeDlg)
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
- ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
- ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
- ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CExamtimeDlg message handlers
- BOOL CExamtimeDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_ctrList.InsertColumn(0,"代码");
- m_ctrList.InsertColumn(1,"考试时间段");
- m_ctrList.SetColumnWidth(0,80);
- m_ctrList.SetColumnWidth(1,160);
- m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- //设置按钮状态
- m_bntSave.EnableWindow(FALSE);
- m_bntNew.EnableWindow(FALSE);
- m_bntDelete.EnableWindow(FALSE);
- m_bntModify.EnableWindow(FALSE);
- RefreshData();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CExamtimeDlg::RefreshData()
- {
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- UpdateData(TRUE);
- CString strSQL;
- strSQL.Format( "select * from examtime ");
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- char buffer[20];
- while(!m_recordset.IsEOF())
- {
- _ltoa(m_recordset.m_ID,buffer,10);
- m_ctrList.InsertItem(i,buffer);
- m_ctrList.SetItemText(i,1,m_recordset.m_time);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- //设置按钮状态
- m_bntSave.EnableWindow(FALSE);
- m_bntNew.EnableWindow();
- m_bntDelete.EnableWindow(FALSE);
- m_bntModify.EnableWindow(FALSE);
- }
- void CExamtimeDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CString strSQL;
- UpdateData(TRUE);
- int i = m_ctrList.GetSelectionMark();
- strSQL.Format("select * from examtime where code=%s",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- m_strName = m_recordset.m_time;
- m_recordset.Close();
- UpdateData(FALSE);
- m_bntSave.EnableWindow(FALSE);
- m_bntNew.EnableWindow();
- m_bntDelete.EnableWindow();
- m_bntModify.EnableWindow();
- *pResult = 0;
- }
- void CExamtimeDlg::OnButtonNew()
- {
- // TODO: Add your control notification handler code here
- m_strName = "";
- m_bntSave.EnableWindow();
- m_bntNew.EnableWindow(FALSE);
- m_bntDelete.EnableWindow(FALSE);
- m_bntModify.EnableWindow(FALSE);
- UpdateData(FALSE);
- }
- void CExamtimeDlg::OnButtonSave()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(m_strName=="")
- {
- AfxMessageBox("请输入考试时间段!");
- return;
- }
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- m_recordset.AddNew();
- m_recordset.m_time = m_strName ;
- m_recordset.Update();
- m_recordset.Close();
- RefreshData();
- }
- void CExamtimeDlg::OnButtonModify()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- MessageBox("请选择一条记录进行修改!");
- return;
- }
- if(m_strName=="")
- {
- AfxMessageBox("请输入考试科目!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from examtime where code= %s ",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- m_recordset.Edit();
- m_recordset.m_time = m_strName ;
- m_recordset.Update();
- m_recordset.Close();
- RefreshData();
- }
- void CExamtimeDlg::OnButtonDelete()
- {
- // TODO: Add your control notification handler code here
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- MessageBox("请选择一条记录进行删除!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from examtime where code= %s ",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- //删除该记录
- m_recordset.Delete();
- m_recordset.Close();
- //更新用户界面
- RefreshData();
- m_strName = "";
- UpdateData(FALSE);
- }