📄 examsubjectdlg.cpp
字号:
// ExamSubjectDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SSF.h"
#include "ExamSubjectDlg.h"
#include"ExamSubjectSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExamSubjectDlg dialog
CExamSubjectDlg::CExamSubjectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExamSubjectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExamSubjectDlg)
m_strCode = _T("");
m_strName = _T("");
//}}AFX_DATA_INIT
}
void CExamSubjectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExamSubjectDlg)
DDX_Control(pDX, IDC_modify, m_bntModify);
DDX_Control(pDX, 1003, m_bntDelete);
DDX_Control(pDX, 1002, m_bntSave);
DDX_Control(pDX, 1000, m_bntNew);
DDX_Control(pDX, IDC_LIST1, m_ctrList);
DDX_Text(pDX, IDC_EDIT1code, m_strCode);
DDX_Text(pDX, IDC_EDIT2name, m_strName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExamSubjectDlg, CDialog)
//{{AFX_MSG_MAP(CExamSubjectDlg)
ON_BN_CLICKED(1000, On1000)
ON_BN_CLICKED(1002, On1002)
ON_BN_CLICKED(1003, On1003)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_modify, Onmodify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExamSubjectDlg message handlers
void CExamSubjectDlg::On1000()
{
// TODO: Add your control notification handler code here
m_strName="";
m_strCode="";
//m_strDepartment="";
//m_trInfo="";
m_bntSave.EnableWindow();
m_bntNew.EnableWindow(FALSE);
m_bntDelete.EnableWindow(FALSE);
m_bntModify.EnableWindow(FALSE);
UpdateData(FALSE);
}
void CExamSubjectDlg::On1002()
{
// TODO: Add your control notification handler code here
CExamSubjectSet m_recordset;
// TODO: Add your control notification handler code here
UpdateData();
if(m_strName=="")
{
AfxMessageBox("请输入专业名称");
}
if(m_strCode=="")
{
AfxMessageBox("请输入专业代号");
}
//if(m_strDepartment=="")
// {
// AfxMessageBox("请输入所属系别");
//}
CString strSQL;
strSQL.Format("select * from examsubject where code='%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_code=m_strCode;
m_recordset.m_name=m_strName;
//m_recordset.m_department=m_strDepartment;
//m_recordset.m_brief=m_strInfo;
m_recordset.Update();
m_recordset.Close();
m_ctrList.InsertItem(0,m_strCode);
m_ctrList.SetItemText(0,1,m_strName);
//m_ctrList.SetItemText(0,2,m_strDepartment);
// m_ctrList.SetItemText(0,3,m_strInfo);
//更新界面显示
m_strCode= _T("");
m_strName= _T("");
//m_strDepartment= _T("");
//m_strInfo= _T("");
UpdateData(FALSE);
}
void CExamSubjectDlg::On1003()
{
// TODO: Add your control notification handler code here
CExamSubjectSet 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 examsubject 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();
m_ctrList.DeleteItem(i);
m_strName="";
m_strCode="";
//m_strDepartment="";
//m_strInfo="";
UpdateData(FALSE);
}
BOOL CExamSubjectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// TODO: Add extra initialization here
m_ctrList.InsertColumn(0,"专业代码");
m_ctrList.InsertColumn(1,"专业名称");
//m_ctrList.InsertColumn(2,"所属系别");
//m_ctrList.InsertColumn(3,"说明");
m_ctrList.SetColumnWidth(0,100);
m_ctrList.SetColumnWidth(1,100);
// m_ctrList.SetColumnWidth(2,100);
//m_ctrList.SetColumnWidth(3,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
}
void CExamSubjectDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CExamSubjectSet m_recordset;
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
int i=m_ctrList.GetSelectionMark();
strSQL.Format("select * from examsubject where code='%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_code;
m_strName=m_recordset.m_name;
//m_strInfo=m_recordset.m_brief;
//m_strDepartment=m_recordset.m_department;
m_recordset.Close();
UpdateData(FALSE);
m_bntSave.EnableWindow(FALSE);
m_bntNew.EnableWindow();
m_bntDelete.EnableWindow();
m_bntModify.EnableWindow();
*pResult = 0;
}
void CExamSubjectDlg::Onmodify()
{
// TODO: Add your control notification handler code here
CExamSubjectSet 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 examsubject 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_code=m_strCode;
m_recordset.m_name=m_strName;
//m_recordset.m_brief=m_strInfo;
//m_recordset.m_department=m_strDepartment;
m_recordset.Update();
m_recordset.Close();
m_ctrList.DeleteItem(i);
m_ctrList.InsertItem(i,m_strCode);
m_ctrList.SetItemText(i,1,m_strName);
//m_ctrList.SetItemText(i,2,m_strDepartment);
//m_ctrList.SetItemText(i,3,m_strInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -