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

📄 employeeadd.cpp

📁 本人工作中的一个软件开发实例。里面包含了数据库
💻 CPP
字号:
// EmployeeAdd.cpp : implementation file
//

#include "stdafx.h"
#include "OIL.h"
#include "EmployeeAdd.h"

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

extern  COILApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CEmployeeAdd dialog


CEmployeeAdd::CEmployeeAdd(CWnd* pParent /*=NULL*/)
	: CDialog(CEmployeeAdd::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEmployeeAdd)
	m_strAddress = _T("");
	m_strDuty = _T("");
	m_strSex = _T("");
	m_strTitle = _T("");
	m_strEmpID = _T("");
	m_strEmpName = _T("");
	m_strTele = _T("");
	//}}AFX_DATA_INIT
}


void CEmployeeAdd::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEmployeeAdd)
	DDX_Text(pDX, IDC_ADDRESS, m_strAddress);
	DDX_CBString(pDX, IDC_COMBO_DUTY, m_strDuty);
	DDX_CBString(pDX, IDC_COMBO_SEX, m_strSex);
	DDX_Text(pDX, IDC_EDIT_TITLE, m_strTitle);
	DDX_Text(pDX, IDC_EMPID, m_strEmpID);
	DDX_Text(pDX, IDC_EMPNAME, m_strEmpName);
	DDX_Text(pDX, IDC_TELEPHONE, m_strTele);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEmployeeAdd, CDialog)
	//{{AFX_MSG_MAP(CEmployeeAdd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEmployeeAdd message handlers

void CEmployeeAdd::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();

	//检查数据完整性
	if(m_strEmpName.IsEmpty())
	{
		AfxMessageBox("员工名称不能为空!");
		GetDlgItem(IDC_CUSTOMERNAME)->SetFocus();
		return;
	}

	//根据实际情况插入或修改数据
	CString		sql;

	switch(m_nDoWhat)
	{
	case ADD:
        {
			//生成SQL语句
			sql="insert into \
			     employee(EmpID,EmpName,Sex,Title,Address,Telephone,Duty) \
				 values  ('"+m_strEmpID+"','"+m_strEmpName+"','"+m_strSex+"','"+m_strTitle+"','"+m_strAddress+"','"+m_strTele+"','"+m_strDuty+"')";

			//执行语句
			_variant_t RecordsAffected;
			theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
        }
		break;
	case EDIT:
        {
			//生成动态sql语句 Address,Telephone,Handler,Notes
			sql="update employee set EmpName='"+m_strEmpName+
				"',Sex='"+m_strSex+
				"',Title='"+m_strTitle+
				"',Address='"+m_strAddress+
				"',Telephone='"+m_strTele+
				"',Duty='"+m_strDuty+
				"' where EmpID='"+m_strEmpID+"' ";
	
			//执行语句
			_variant_t RecordsAffected;
			theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
		}
		break;
	default:
		AfxMessageBox("错误操作类型");
		break;
	}
	CDialog::OnOK();
}

void CEmployeeAdd::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CEmployeeAdd::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//初始化职责
	InitDutyComboBox((CComboBox *)GetDlgItem(IDC_COMBO_DUTY));
	InitSexComboBox((CComboBox *)GetDlgItem(IDC_COMBO_SEX));

	switch(m_nDoWhat)
	{
	case  ADD:
		{
			SetWindowText("增加员工");
			SetDlgItemText(IDOK,"增加");
        
			//得到自动ID
			(CEdit *)GetDlgItem(IDC_EMPID)->EnableWindow(false);
		    CString sql="select max(EmpID)+1 from employee";
			SetDlgItemText(IDC_EMPID,GetAutoID(sql,4));

		}
		 break;
	case EDIT:

			SetWindowText("修改员工");
			SetDlgItemText(IDOK,"修改");
			(CEdit *)GetDlgItem(IDC_EMPID)->EnableWindow(false);
            UpdateData(false);
		break;
	default:
		AfxMessageBox("错误操作类型");
		break;
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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