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

📄 deptdlg.cpp

📁 直接打开
💻 CPP
字号:
// DeptDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AssetsMan.h"
#include "DeptDlg.h"
#include "Departments.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDeptDlg dialog


CDeptDlg::CDeptDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDeptDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDeptDlg)
	m_DeptName = _T("");
	//}}AFX_DATA_INIT
}


void CDeptDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDeptDlg)
	DDX_Control(pDX, IDC_ADODC1, m_AdoDept);
	DDX_Text(pDX, IDC_EDIT1, m_DeptName);
	DDX_Control(pDX, IDC_DATALIST1, m_DataDept);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDeptDlg, CDialog)
	//{{AFX_MSG_MAP(CDeptDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
	ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDeptDlg message handlers

BEGIN_EVENTSINK_MAP(CDeptDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CDeptDlg)
	ON_EVENT(CDeptDlg, IDC_DATALIST1, -600 /* Click */, OnClickDatalist1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CDeptDlg::OnClickDatalist1() 
{
	// 点击部门信息后将部门名称放入编辑框中
	m_DeptName = m_DataDept.GetText();		//从列表框中读取部门名称
	cDeptId = m_DataDept.GetBoundText();	//读取部门编号
	cDeptNameOld = m_DataDept.GetText();	//保存部门名称
	UpdateData(FALSE);						//更新显示
}

void CDeptDlg::OnAddButton() 
{
	// 将用户输入数据读取到成员变量中
	UpdateData(TRUE);
	//判断部门名称是否为空
	if (m_DeptName == "")
	{
		MessageBox("请输入部门名称");
		return;
	}
	//保存数据
	CDepartments cDept;
	cDept.SetDeptName(m_DeptName);
	// 如果没有同样的部门名称则插入数据库
	if (cDept.HaveName(m_DeptName) == 1)
		MessageBox("已经存在此部门信息!");
	else
	{
		cDept.sql_Insert();
		m_AdoDept.Refresh();
	}
}

void CDeptDlg::OnModiButton() 
{
	// 查看新的部门名称是否和原来的相同
	UpdateData(TRUE);
	//判断是否选择了要修改的部门
	if (m_DataDept.GetText() == "")
	{
		MessageBox("请选择要修改的部门名称");
		return;
	}
	//判断部门名称是否为空
	if (m_DeptName == "")
	{
		MessageBox("请输入部门名称");
		return;
	}

	// 如果不同则查看数据库是否已经存在新的部门名称
	if(cDeptNameOld != m_DeptName)
	{
		CDepartments cDept;
		cDept.SetDeptName(m_DeptName);
		if (cDept.HaveName(m_DeptName) == 1)
			MessageBox("新的部门名称已经存在!");
		else
		{
			cDept.sql_Update(cDeptId);
			m_AdoDept.Refresh();
		}
	}
}

void CDeptDlg::OnDelButton() 
{
	//判断是否选择了要修改的部门
	if (m_DataDept.GetText() == "")
	{
		MessageBox("请选择要删除的部门名称");
		return;
	}
	// 删除部门信息
	CDepartments cDept;
	cDept.sql_Delete(cDeptId);
	m_AdoDept.Refresh();	
}

⌨️ 快捷键说明

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