⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 examtypedlg.cpp

📁 一个由MFC做的学生信息管理系统
💻 CPP
字号:
// ExamtypeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SSF.h"
#include "ExamtypeDlg.h"
#include"ExamtypeSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CExamtypeDlg dialog


CExamtypeDlg::CExamtypeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CExamtypeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CExamtypeDlg)
	m_strCode = _T("");
	m_strName = _T("");
	//}}AFX_DATA_INIT
}


void CExamtypeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExamtypeDlg)
	DDX_Control(pDX, IDC_modify, m_bntModify);
	DDX_Control(pDX, 1003, m_bntDelete);
	DDX_Control(pDX, 1002, m_bntSave);
	DDX_Control(pDX, 1001, m_bntNew);
	DDX_Control(pDX, 1000, m_ctrList);
	DDX_Text(pDX, IDC_EDIT1code, m_strCode);
	DDX_Text(pDX, IDC_EDIT2Type, m_strName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CExamtypeDlg, CDialog)
	//{{AFX_MSG_MAP(CExamtypeDlg)
	ON_BN_CLICKED(1001, On1001)
	ON_BN_CLICKED(1002, On1002)
	ON_BN_CLICKED(1003, On1003)
	ON_BN_CLICKED(IDC_modify, Onmodify)
	ON_NOTIFY(NM_CLICK, 1000, OnClick1000)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExamtypeDlg message handlers

void CExamtypeDlg::On1001() 
{
	// 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 CExamtypeDlg::On1002() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your control notification handler code here
	CExamtypeSet 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 examtype 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.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_strCode= _T("");
    m_strName= _T("");
    //m_strDepartment= _T("");           
                            
	UpdateData(FALSE);


	
}

void CExamtypeDlg::On1003() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your control notification handler code here
	 CExamtypeSet 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 examtype 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="";
	
	UpdateData(FALSE);
}

void CExamtypeDlg::Onmodify() 
{
	// TODO: Add your control notification handler code here
	 CExamtypeSet 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 examtype 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.Update();
	m_recordset.Close();
	m_ctrList.DeleteItem(i);
	m_ctrList.InsertItem(i,m_strCode);
    m_ctrList.SetItemText(i,1,m_strName);
   
}

BOOL CExamtypeDlg::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 CExamtypeDlg::OnClick1000(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	CExamtypeSet m_recordset;
	// TODO: Add your control notification handler code here
	CString strSQL;
	UpdateData(TRUE);
	int i=m_ctrList.GetSelectionMark();
    strSQL.Format("select * from examtype 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_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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -