📄 examtimedlg.cpp
字号:
// ExamtimeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SSF.h"
#include "ExamtimeDlg.h"
#include"ExamtimeSet.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_strCode = _T("");
m_strName = _T("");
//}}AFX_DATA_INIT
}
void CExamtimeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExamtimeDlg)
DDX_Control(pDX, IDC_BUTTON4modify, m_bntModify);
DDX_Control(pDX, IDC_BUTTON3delete, m_bntDelete);
DDX_Control(pDX, IDC_BUTTON2save, m_bntSave);
DDX_Control(pDX, IDC_BUTTON1new, m_bntNew);
DDX_Control(pDX, 1006, m_ctrList);
DDX_Text(pDX, IDC_EDIT1, m_strCode);
DDX_Text(pDX, IDC_EDIT2, m_strName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExamtimeDlg, CDialog)
//{{AFX_MSG_MAP(CExamtimeDlg)
ON_NOTIFY(NM_CLICK, 1006, OnClick1006)
ON_BN_CLICKED(IDC_BUTTON1new, OnBUTTON1new)
ON_BN_CLICKED(IDC_BUTTON2save, OnBUTTON2save)
ON_BN_CLICKED(IDC_BUTTON3delete, OnBUTTON3delete)
ON_BN_CLICKED(IDC_BUTTON4modify, OnBUTTON4modify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExamtimeDlg message handlers
BOOL CExamtimeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_ctrList.InsertColumn(0,"代码");
m_ctrList.InsertColumn(1,"考试时间段");
m_ctrList.SetColumnWidth(0,100);
m_ctrList.SetColumnWidth(1,100);
m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_bntSave.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CExamtimeDlg::OnClick1006(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CExamtimeSet m_recordset;
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
int i=m_ctrList.GetSelectionMark();
strSQL.Format("select * from examtime where ID='%s'",m_ctrList.GetItemText(i,0));
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return;
}
m_strCode=m_recordset.m_ID;
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::OnBUTTON1new()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
m_strName="";
m_strCode="";
m_bntSave.EnableWindow();
m_bntNew.EnableWindow(FALSE);
m_bntDelete.EnableWindow(FALSE);
m_bntModify.EnableWindow(FALSE);
UpdateData(FALSE);
}
void CExamtimeDlg::OnBUTTON2save()
{
// TODO: Add your control notification handler code here
CExamtimeSet m_recordset;
// TODO: Add your control notification handler code here
UpdateData();
if(m_strName=="")
{
AfxMessageBox("请输入考试时间段");
}
if(m_strCode=="")
{
AfxMessageBox("请输入代码");
}
CString strSQL;
strSQL.Format("select * from examtime where ID='%s'",m_strCode);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return;
}
if(m_recordset.GetRecordCount()!=0)
{
m_recordset.Close();
AfxMessageBox("当前编码已经存在!请重新输入!");
m_strCode="";
UpdateData(FALSE);
return;
}
m_recordset.AddNew();
m_recordset.m_ID=m_strCode;
m_recordset.m_time=m_strName;
m_recordset.Update();
m_recordset.Close();
m_ctrList.InsertItem(0,m_strCode);
m_ctrList.SetItemText(0,1,m_strName);
//更新界面显示
m_strCode= _T("");
m_strName= _T("");
UpdateData(FALSE);
}
void CExamtimeDlg::OnBUTTON3delete()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
CExamtimeSet m_recordset;
// TODO: Add your control notification handler code here
int i=m_ctrList.GetSelectionMark();
if(0>i)
{
MessageBox("请选择一条记录进行修改");
return;
}
if(m_strName=="")
{
AfxMessageBox("请输入考试时间段");
}
if(m_strCode=="")
{
AfxMessageBox("请输入代码");
}
CString strSQL;
strSQL.Format("select * from examtime where ID='%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();
m_ctrList.DeleteItem(i);
m_strName="";
m_strCode="";
UpdateData(FALSE);
}
void CExamtimeDlg::OnBUTTON4modify()
{
// TODO: Add your control notification handler code here
CExamtimeSet m_recordset;
// TODO: Add your control notification handler code here
UpdateData();
int i=m_ctrList.GetSelectionMark();
if(0>i)
{
MessageBox("请选择一条记录进行修改");
return;
}
if(m_strName=="")
{
AfxMessageBox("请输入考试时间段");
}
if(m_strCode=="")
{
AfxMessageBox("请输入代码");
}
CString strSQL;
strSQL.Format("select * from examtime where ID='%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_ID=m_strCode;
m_recordset.m_time=m_strName;
m_recordset.Update();
m_recordset.Close();
m_ctrList.DeleteItem(i);
m_ctrList.InsertItem(i,m_strCode);
m_ctrList.SetItemText(i,1,m_strName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -