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

📄 empinfo.cpp

📁 visual c++与sql Server数据库开发考勤管理系统
💻 CPP
字号:

#include "stdafx.h"
#include "CheckManage.h"
#include "EmpInfo.h"
#include "ADOConn.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CEmpInfo::CEmpInfo()
{
	EmpId = 0;
	Name = "";
	Sex = "";

	Birthday = "";
	IdCard = "";
	OfficePhone = "";
	Mobile = "";
	HireDate = "";
	DepId = 0;

	Mission = "";
	Duty = "";
	Memo = "";
}

CEmpInfo::~CEmpInfo()
{

}

// 根据员工编号得到其他信息
void CEmpInfo::GetInfo(CString paraId)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();

	//设置SELECT语句
	_bstr_t vSQL;
	vSQL = "SELECT * FROM EmpInfo WHERE EmpId = " + paraId;

	//执行SELETE语句
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

	//返回各列的值
	if (m_pRecordset->adoEOF)
		CEmpInfo();
	else
	{
		EmpId = atol(paraId);
		Name = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
		Sex = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sex");

		Birthday = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Birthday");
		IdCard = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("IdCard");
		OfficePhone = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("OfficePhone");

		Mobile = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Mobile");
		HireDate = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("HireDate");
		DepId = atol((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("DepId"));

		Mission = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Mission");
		Duty = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Duty");
		Memo = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Memo");
	}

	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

// 插入操作
void CEmpInfo::SqlInsert()
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();

	//设置INSERT语句
	CString strDepId;
	strDepId.Format("%d", DepId);
	_bstr_t vSQL;
	vSQL = "INSERT INTO EmpInfo (Name, Sex, Birthday, "
		" IdCard, OfficePhone, Mobile, HireDate, DepId, Mission, Duty, Memo)"
		" VALUES ('" + Name + "', '" + Sex + "','" + Birthday + "','" 
		+ IdCard + "','" + OfficePhone + "','" + Mobile + "','" 
		+ HireDate + "'," + strDepId + ",'" + Mission + "','" + Duty 
		+ "', '" + Memo + "')";
	//执行INSERT语句
	m_AdoConn.ExecuteSQL(vSQL);	
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

// 修改操作
void CEmpInfo::SqlUpdate(CString paraId)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();

	//设置UPDATE语句
	_bstr_t vSQL;
	vSQL = "UPDATE EmpInfo SET Name = '" + Name + "', Sex = '" + Sex
		+ "', Birthday = '" + Birthday + "', IdCard = '" + IdCard 
		+ "', OfficePhone = '" + OfficePhone + "', Mobile = '" + Mobile 
		+ "', HireDate = '" + HireDate + "', Mission = '" + Mission
		+ "', Duty = '" + Duty + "', Memo = '" + Memo
		+ "' WHERE EmpId = " + paraId;
	//执行UPDATE语句
	m_AdoConn.ExecuteSQL(vSQL);
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

// 删除指定员工信息
void CEmpInfo::SqlDelete(CString paraId)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();

	//设置DELETE语句
	_bstr_t vSQL;
	vSQL = "DELETE FROM EmpInfo WHERE EmpId = " + paraId;

	//执行DELETE语句
	m_AdoConn.ExecuteSQL(vSQL);	

	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

⌨️ 快捷键说明

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