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

📄 staffinformation.cpp

📁 基于VC+SQL SERVER环境开发的企业商品销售系统.完整的数据库和原代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// StaffInformation.cpp : implementation file
//

#include "stdafx.h"
#include "Sale.h"
#include "StaffInformation.h"
#include "Affirm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStaffInformation dialog


CStaffInformation::CStaffInformation(CWnd* pParent /*=NULL*/)
	: CDialog(CStaffInformation::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStaffInformation)
	m_department = _T("");
	m_address = _T("");
	m_birthday = COleDateTime::GetCurrentTime();
	m_postcode = _T("");
	m_marriageCondition = _T("");
	m_staffID = _T("");
	m_duty = _T("");
	m_sex = _T("");
	m_telephone = _T("");
	m_nationality = _T("");
	m_eMail = _T("");
	m_educationDegree = _T("");
	m_qqID = _T("");
	m_graduateSchool = _T("");
	m_major = _T("");
	m_identity = _T("");
	m_mobile = _T("");
	m_remark = _T("");
	m_workType = _T("");
	m_name = _T("");
	//}}AFX_DATA_INIT
}


void CStaffInformation::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStaffInformation)
	DDX_Control(pDX, IDC_department, m_departmentCombo);
	DDX_Control(pDX, IDC_duty, m_dutyCombo);
	DDX_Control(pDX, IDC_LIST2, m_staffList);
	DDX_CBString(pDX, IDC_department, m_department);
	DDX_Text(pDX, IDC_address, m_address);
	DDX_Text(pDX, IDC_birthday, m_birthday);
	DDX_Text(pDX, IDC_postcode, m_postcode);
	DDX_Text(pDX, IDC_marriageCondition, m_marriageCondition);
	DDX_Text(pDX, IDC_staffID, m_staffID);
	DDX_Text(pDX, IDC_duty, m_duty);
	DDX_Text(pDX, IDC_sex, m_sex);
	DDX_Text(pDX, IDC_telephone, m_telephone);
	DDX_Text(pDX, IDC_nationality, m_nationality);
	DDX_Text(pDX, IDC_eMail, m_eMail);
	DDX_Text(pDX, IDC_educationDegree, m_educationDegree);
	DDX_Text(pDX, IDC_qqID, m_qqID);
	DDX_Text(pDX, IDC_graduateSchool, m_graduateSchool);
	DDX_Text(pDX, IDC_major, m_major);
	DDX_Text(pDX, IDC_identity, m_identity);
	DDX_Text(pDX, IDC_mobile, m_mobile);
	DDX_Text(pDX, IDC_remark, m_remark);
	DDX_Text(pDX, IDC_workType, m_workType);
	DDX_Text(pDX, IDC_name, m_name);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStaffInformation, CDialog)
	//{{AFX_MSG_MAP(CStaffInformation)
	ON_BN_CLICKED(IDC_add, OnAdd)
	ON_BN_CLICKED(IDC_delete, OnDelete)
	ON_BN_CLICKED(IDC_modify, OnModify)
	ON_BN_CLICKED(IDC_save, OnSave)
	ON_BN_CLICKED(IDC_exit, OnExit)
	ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickStaffList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStaffInformation message handlers

void CStaffInformation::OnAdd() 
{
	UpdateData(true);	
	m_department = _T("");
	m_address = _T("");
	m_birthday = COleDateTime::GetCurrentTime();
	m_postcode = _T("");
	m_marriageCondition = _T("");
	int staffID=((CSaleApp*)AfxGetApp())->m_pIDRecordset->GetCollect("staffID").intVal;
	if(staffID<10)
		m_staffID.Format("staff0000%d",staffID);
	else if(staffID<100&&staffID>9)
		m_staffID.Format("staff000%d",staffID);
	else if(staffID<1000&&staffID>99)
		m_staffID.Format("staff00%d",staffID);

	CString str;
	str.Format("%d",staffID+1);
	((CSaleApp*)AfxGetApp())->m_pIDRecordset->PutCollect("staffID",_variant_t(str));
	((CSaleApp*)AfxGetApp())->m_pIDRecordset->Update();
	m_duty = _T("");
	m_name = _T("");
	m_sex = _T("");
	m_telephone = _T("");
	m_nationality = _T("");
	m_eMail = _T("");
	m_educationDegree = _T("");
	m_qqID = _T("");
	m_graduateSchool = _T("");
	m_major = _T("");
	m_identity = _T("");
	m_mobile = _T("");
	m_remark = _T("");
	m_workType=_T("");

	tx_department->EnableWindow(true);
	tx_address->EnableWindow(true);
	tx_birthday->EnableWindow(true);
	tx_postcode->EnableWindow(true);
	tx_marriageCondition->EnableWindow(true);
	tx_staffID->EnableWindow(false);
	tx_duty->EnableWindow(true);
	tx_name->EnableWindow(true);
	tx_sex->EnableWindow(true);
	tx_telephone->EnableWindow(true);
	tx_nationality->EnableWindow(true);
	tx_eMail->EnableWindow(true);
	tx_educationDegree->EnableWindow(true);
	tx_qqID->EnableWindow(true);
	tx_graduateSchool->EnableWindow(true);
	tx_major->EnableWindow(true);
	tx_identity->EnableWindow(true);
	tx_mobile->EnableWindow(true);
	tx_remark->EnableWindow(true);
	tx_workType->EnableWindow(true);
	
	flag=1;

	bt_save->EnableWindow(true);
	bt_add->EnableWindow(false);
	bt_modify->EnableWindow(false);
	bt_delete->EnableWindow(false);
	UpdateData(false);		
	
}

void CStaffInformation::OnDelete() 
{
	CAffirm dlg;
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}
	_variant_t RecordsAffected;
	CString strSQL;
	strSQL="delete from staff where staffID='";
	strSQL=strSQL+m_staffID+"'";
	(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
	
	POSITION pos = m_staffList.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_staffList.GetNextSelectedItem(pos);
		m_staffList.DeleteItem(nFirstSelItem);
	}	
	bt_delete->EnableWindow(false);
	
	m_department = _T("");
	m_address = _T("");
	m_birthday = COleDateTime::GetCurrentTime();
	m_postcode = _T("");
	m_marriageCondition = _T("");
	m_staffID = _T("");
	m_duty = _T("");
	m_name = _T("");
	m_sex = _T("");
	m_telephone = _T("");
	m_nationality = _T("");
	m_eMail = _T("");
	m_educationDegree = _T("");
	m_qqID = _T("");
	m_graduateSchool = _T("");
	m_major = _T("");
	m_identity = _T("");
	m_mobile = _T("");
	m_remark = _T("");

	Refresh();

	UpdateData(false);
	
}

void CStaffInformation::OnModify() 
{
	tx_department->EnableWindow(true);
	tx_address->EnableWindow(true);
	tx_birthday->EnableWindow(true);
	tx_postcode->EnableWindow(true);
	tx_marriageCondition->EnableWindow(true);
	tx_staffID->EnableWindow(false);
	tx_duty->EnableWindow(true);
	tx_name->EnableWindow(true);
	tx_sex->EnableWindow(true);
	tx_telephone->EnableWindow(true);
	tx_nationality->EnableWindow(true);
	tx_eMail->EnableWindow(true);
	tx_educationDegree->EnableWindow(true);
	tx_qqID->EnableWindow(true);
	tx_graduateSchool->EnableWindow(true);
	tx_major->EnableWindow(true);
	tx_identity->EnableWindow(true);
	tx_mobile->EnableWindow(true);
	tx_remark->EnableWindow(true);
	tx_workType->EnableWindow(true);
	flag=2;
	bt_save->EnableWindow(true);
	
}

void CStaffInformation::OnSave() 
{
	UpdateData(true);
	_RecordsetPtr m_pRecordset;    
	CString strSQL;
	if(flag==1)         //添加
	{
		strSQL="SELECT * FROM staff" ;	

		try
		{
			HRESULT hTRes;
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			if (SUCCEEDED(hTRes))
			{
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);
				if(SUCCEEDED(hTRes))
				{
					m_pRecordset->AddNew();
					m_pRecordset->PutCollect("staffID",_variant_t(m_staffID));
					m_pRecordset->PutCollect("staffName",_variant_t(m_name));
					m_pRecordset->PutCollect("duty",_variant_t(m_duty));
					m_pRecordset->PutCollect("department",_variant_t(m_department));
					m_pRecordset->PutCollect("sex",_variant_t(m_sex));
					m_pRecordset->PutCollect("address",_variant_t(m_address));
					m_pRecordset->PutCollect("birthday",_variant_t(m_birthday));
					m_pRecordset->PutCollect("postcode",_variant_t(m_postcode));
					m_pRecordset->PutCollect("marriageCondition",_variant_t(m_marriageCondition));
					m_pRecordset->PutCollect("telephone",_variant_t(m_telephone));
					m_pRecordset->PutCollect("nationality",_variant_t(m_nationality));
					m_pRecordset->PutCollect("eMail",_variant_t(m_eMail));
					m_pRecordset->PutCollect("educationLevel",_variant_t(m_educationDegree));
					m_pRecordset->PutCollect("QQ",_variant_t(m_qqID));
					m_pRecordset->PutCollect("graduateSchool",_variant_t(m_graduateSchool));
					m_pRecordset->PutCollect("major",_variant_t(m_major));
					m_pRecordset->PutCollect("identityNO",_variant_t(m_identity));
					m_pRecordset->PutCollect("mobile",_variant_t(m_mobile));
					m_pRecordset->PutCollect("workType",_variant_t(m_workType.Left(10)));
					m_pRecordset->PutCollect("remark",_variant_t(m_remark));
					m_pRecordset->Update();

					POSITION pos = m_staffList.GetFirstSelectedItemPosition();
					if(pos)
					{
						int nFirstSelItem = m_staffList.GetNextSelectedItem(pos);
						m_staffList.DeleteItem(nFirstSelItem);
					}
					int j;
					j=m_staffList.GetItemCount();
					m_staffList.InsertItem(j,m_staffID);
					m_staffList.SetItemText(j,1,m_name);
					m_staffList.SetItemText(j,2,m_duty);
					m_staffList.SetItemText(j,3,m_department);
					m_staffList.SetItemText(j,4,m_sex);
					m_staffList.SetItemText(j,5,m_address);
					CString str;
					str.Format("%d-%d-%d",m_birthday.GetYear(),m_birthday.GetMonth,m_birthday.GetDay());
					m_staffList.SetItemText(j,6,str);
					m_staffList.SetItemText(j,7,m_postcode);
					m_staffList.SetItemText(j,8,m_marriageCondition);
					m_staffList.SetItemText(j,9,m_telephone);
					m_staffList.SetItemText(j,10,m_nationality);
					m_staffList.SetItemText(j,11,m_eMail);
					m_staffList.SetItemText(j,12,m_educationDegree);
					m_staffList.SetItemText(j,13,m_qqID);
					m_staffList.SetItemText(j,14,m_graduateSchool);
					m_staffList.SetItemText(j,15,m_major);
					m_staffList.SetItemText(j,16,m_identity);
					m_staffList.SetItemText(j,17,m_mobile);
					m_staffList.SetItemText(j,18,m_workType);
					m_staffList.SetItemText(j,19,m_remark);

					AfxMessageBox("保存成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	else if(flag==2)      //修改
	{
		strSQL="SELECT * FROM staff where staffID='" ;
		strSQL=strSQL+m_staffID+"'";

		try
		{
			HRESULT hTRes;
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			if (SUCCEEDED(hTRes))
			{
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);
				if(SUCCEEDED(hTRes)&&!(m_pRecordset->adoEOF))
				{
					m_pRecordset->PutCollect("staffName",_variant_t(m_name));
					m_pRecordset->PutCollect("duty",_variant_t(m_duty));
					m_pRecordset->PutCollect("department",_variant_t(m_department));
					m_pRecordset->PutCollect("sex",_variant_t(m_sex));
					m_pRecordset->PutCollect("address",_variant_t(m_address));
					m_pRecordset->PutCollect("birthday",_variant_t(m_birthday));
					m_pRecordset->PutCollect("postcode",_variant_t(m_postcode));
					m_pRecordset->PutCollect("marriageCondition",_variant_t(m_marriageCondition));
					m_pRecordset->PutCollect("telephone",_variant_t(m_telephone));
					m_pRecordset->PutCollect("nationality",_variant_t(m_nationality));
					m_pRecordset->PutCollect("eMail",_variant_t(m_eMail));
					m_pRecordset->PutCollect("educationLevel",_variant_t(m_educationDegree));
					m_pRecordset->PutCollect("QQ",_variant_t(m_qqID));
					m_pRecordset->PutCollect("graduateSchool",_variant_t(m_graduateSchool));
					m_pRecordset->PutCollect("major",_variant_t(m_major));
					m_pRecordset->PutCollect("identityNO",_variant_t(m_identity));
					m_pRecordset->PutCollect("mobile",_variant_t(m_mobile));
					m_pRecordset->PutCollect("workType",_variant_t(m_workType.Left(10)));
					m_pRecordset->PutCollect("remark",_variant_t(m_remark));
					m_pRecordset->Update();
//					int j;
//					j=m_staffList.GetItemCount();
//					m_staffList.InsertItem(j,m_staffID);
//					m_staffList.SetItemText(j,1,m_name);
//					m_staffList.SetItemText(j,2,m_duty);
//					m_staffList.SetItemText(j,3,m_department);
//					m_staffList.SetItemText(j,4,m_sex);
//					m_staffList.SetItemText(j,5,m_address);
//					CString str;
//					str.Format("%d-%d-%d",m_birthday.GetYear(),m_birthday.GetMonth,m_birthday.GetDay());
//					m_staffList.SetItemText(j,6,str);
//					m_staffList.SetItemText(j,7,m_postcode);
//					m_staffList.SetItemText(j,8,m_marriageCondition);
//					m_staffList.SetItemText(j,9,m_telephone);
//					m_staffList.SetItemText(j,10,m_nationality);
//					m_staffList.SetItemText(j,11,m_eMail);
//					m_staffList.SetItemText(j,12,m_educationDegree);

⌨️ 快捷键说明

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