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

📄 searchemployeeinfo.cpp

📁 企业办公管理系统
💻 CPP
字号:
// SearchEmployeeInfo.cpp : implementation file
//

#include "stdafx.h"
#include "office.h"
#include "SearchEmployeeInfo.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSearchEmployeeInfo dialog


CSearchEmployeeInfo::CSearchEmployeeInfo(CWnd* pParent /*=NULL*/)
 	: CDialog(CSearchEmployeeInfo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSearchEmployeeInfo)
	m_birthday = COleDateTime::GetCurrentTime();
	m_name = _T("");
	m_department = _T("");
	m_ID = _T("");
	m_num = 0;
	//}}AFX_DATA_INIT
 }


void CSearchEmployeeInfo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSearchEmployeeInfo)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_DateTimeCtrl(pDX, IDC_BIRTHDAY, m_birthday);
	DDX_Text(pDX, IDC_SEARCHNAME, m_name);
	DDV_MaxChars(pDX, m_name, 10);
	DDX_CBString(pDX, IDC_SEARCHDEPAR, m_department);
	DDX_CBString(pDX, IDC_SEARCHID, m_ID);
	DDX_Text(pDX, IDC_NUM, m_num);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSearchEmployeeInfo, CDialog)
	//{{AFX_MSG_MAP(CSearchEmployeeInfo)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
	ON_BN_CLICKED(IDC_SHOWALL, OnShowall)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSearchEmployeeInfo message handlers

BOOL CSearchEmployeeInfo::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	DWORD  style;
	style=m_list.GetExStyle();//读取样式;
	style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES);//设置样式;
	m_list.SetExtendedStyle(style);
	m_list.InsertColumn(0,"员工号",LVCFMT_LEFT,60);
	m_list.InsertColumn(1,"姓名",LVCFMT_LEFT,60);
	m_list.InsertColumn(2,"职务",LVCFMT_LEFT,100);
	m_list.InsertColumn(3,"部门",LVCFMT_LEFT,100);
	m_list.InsertColumn(4,"电话",LVCFMT_LEFT,150);
	m_list.InsertColumn(5,"注备",LVCFMT_LEFT,350);

	((CComboBox*)GetDlgItem(IDC_SEARCHDEPAR))->AddString("技术部");
	((CComboBox*)GetDlgItem(IDC_SEARCHDEPAR))->AddString("后勤集团");
	((CComboBox*)GetDlgItem(IDC_SEARCHDEPAR))->AddString("助理部");
	((CComboBox*)GetDlgItem(IDC_SEARCHDEPAR))->AddString("事务部");
	((CComboBox*)GetDlgItem(IDC_SEARCHDEPAR))->AddString("福利部");
	((CComboBox*)GetDlgItem(IDC_SEARCHDEPAR))->AddString("医药部");
/*
	CComboBox	m_ID;
	CComboBox	m_departmentName;
	CListCtrl	m_list;
	COleDateTime	m_birthday;
	CString	m_name;
*/  try
	{
		::CoInitialize(NULL);
		_ConnectionPtr m_pConn("ADODB.Connection");
		m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\DataSource\\office1.mdb;Persist Security Info=False","","",adConnectUnspecified);
		_RecordsetPtr m_set("ADODB.Recordset");//记录集
		//打开
		m_set->Open("Select *From 人员基本档案",_variant_t(m_pConn,true),adOpenDynamic,adLockPessimistic,adCmdText);
		int i=0;
		while(!m_set->EndOfFile)
		{
			//填充下拉列表框
           ((CComboBox*)GetDlgItem(IDC_SEARCHID))->AddString((_bstr_t)m_set->GetCollect("StaffID"));
 //           m_departmentName.AddString((_bstr_t)m_set->GetCollect("Department"));
			m_set->MoveNext();
		}
	}
	catch(_com_error&e)
	{
        MessageBox(e.ErrorMessage());
	}
    GetDlgItem(IDC_CLEAR)->EnableWindow(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
int opt1,opt2;
void CSearchEmployeeInfo::OnSearch() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_list.DeleteAllItems();
	CString strSQL;
	strSQL="Select*From 人员基本档案  ";
/*	int year=m_birthday.GetYear();
	int month=m_birthday.GetMonth();
	int day=m_birthday.GetDay();
	CString birth;
	birth.Format("'%d-%d-%d'",year,month,day);
	strSQL+="Birthday ="+birth;
*/	//列表框选项m_departmentName
    if(m_department==""&&m_ID==""&&m_name=="")
	{
		MessageBox("请输入查询条件,若想列出全部则单击'列出全部'按钮");
		return;
	}
    else if(m_department!=""&&m_ID==""&&m_name=="")
	{
       strSQL=strSQL+"where Department='"+m_department+"'";
	}
	//列表框选项m_departmentName
    else if(m_department==""&&m_ID!=""&&m_name=="")
	{      
		strSQL=strSQL+"where StaffID='"+m_ID+"'";
	}
	else if(m_department!=""&&m_ID!=""&&m_name=="")
	{   
		strSQL+="where Department='"+m_department+"'"+"or StaffID='"+m_ID+"'";
	}

    else if(m_department==""&&m_ID==""&&m_name!="")
	{
       strSQL=strSQL+"where StaffName='"+m_name+"'";
	}
	//列表框选项m_departmentName
    else if(m_department==""&&m_ID!=""&&m_name!="")
	{      
		strSQL=strSQL+"where StaffID='"+m_ID+"'"+"or StaffName='"+m_name+"'";
	}
	else if(m_department!=""&&m_ID==""&&m_name!="")
	{   
		strSQL+="where Department='"+m_department+"'"+"or StaffName='"+m_name+"'";
	}
	else
	{
		strSQL+="where Department='"+m_department+"'"+"or StaffName='"+m_name+"'"+"or StaffID = '"+m_ID+"'";
	}
	try
	{
		_ConnectionPtr m_pConn("ADODB.Connection");
		m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\DataSource\\office1.mdb;Persist Security Info=False","","",adConnectUnspecified);
	   _RecordsetPtr m_set("ADODB.Recordset");
		m_set->Open((_bstr_t)strSQL,_variant_t(m_pConn,true),adOpenDynamic,adLockPessimistic,adCmdText);
		//打开
	    int i=0;
        m_num=0;//注意:m_num可能在别处已经修改如OnShowAll()方法也用到m_num来记数
		while(!m_set->EndOfFile)
		{
			m_num++;
			m_list.InsertItem(i,_bstr_t(m_set->GetCollect("StaffID")));
			m_list.SetItemText(i,1,_bstr_t(m_set->GetCollect("StaffName")));
			m_list.SetItemText(i,2,_bstr_t(m_set->GetCollect("Duty")));
			m_list.SetItemText(i,3,_bstr_t(m_set->GetCollect("Department")));
			m_list.SetItemText(i,4,_bstr_t(m_set->GetCollect("Telephone")));
			m_list.SetItemText(i,5,_bstr_t(m_set->GetCollect("Remark")));
            m_set->MoveNext();
		}
	}
	catch(_com_error&e)
	{
        MessageBox(e.ErrorMessage());
	}
	GetDlgItem(IDC_CLEAR)->EnableWindow();
	UpdateData(false);
}


#include "staffdetailinfo.h"
void CSearchEmployeeInfo::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	POSITION pos=m_list.GetFirstSelectedItemPosition();//获得单击的位置
    CString option;
	if(pos)
	{
		int nFistSelItem=m_list.GetNextSelectedItem(pos);
		option=m_list.GetItemText(nFistSelItem,0);
	}
    
	try
	{
		::CoInitialize(NULL);
		_ConnectionPtr m_pConn("ADODB.Connection");
		m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\DataSource\\office1.mdb;Persist Security Info=False","","",adConnectUnspecified);
		_RecordsetPtr m_set("ADODB.Recordset");//记录集
		CString str;
		str="select * from 人员基本档案 where StaffID='"+option+"'";
		m_set->Open(_bstr_t(str),_variant_t(m_pConn,true),adOpenDynamic,adLockPessimistic,adCmdText);
	    if(!m_set->EndOfFile)
		{
			 CStaffDetailInfo detailInfo;
			detailInfo.m_birthday=(COleDateTime)(m_set->GetCollect("Birthday"));
			detailInfo.m_contractDeadline=(COleDateTime)(m_set->GetCollect("ContractTerm"));
			detailInfo.m_sex=(LPCSTR)((_bstr_t)m_set->GetCollect("Sex"));
			detailInfo.m_nationality=(LPCSTR)((_bstr_t)m_set->GetCollect("Nationality"));
			detailInfo.m_marriage=(LPCSTR)((_bstr_t)m_set->GetCollect("MarriageCondition"));
			detailInfo.m_educationLevel=(LPCSTR)((_bstr_t)m_set->GetCollect("EducationLevel"));
			detailInfo.m_duty=(LPCSTR)((_bstr_t)m_set->GetCollect("Duty"));
			detailInfo.m_department=(LPCSTR)((_bstr_t)m_set->GetCollect("Department"));
			detailInfo.m_address=(LPCSTR)((_bstr_t)m_set->GetCollect("Address"));
			detailInfo.m_contractCode=(LPCSTR)((_bstr_t)m_set->GetCollect("ContactID"));
			detailInfo.m_graduateSchool=(LPCSTR)((_bstr_t)m_set->GetCollect("GraduateSchool"));
			detailInfo.m_staffID=(LPCSTR)((_bstr_t)m_set->GetCollect("IdentityNO"));
			detailInfo.m_mailAddress=(LPCSTR)((_bstr_t)m_set->GetCollect("Email"));
			detailInfo.m_mayor=(LPCSTR)((_bstr_t)m_set->GetCollect("Mayor"));
			detailInfo.m_mobilephone=(LPCSTR)((_bstr_t)m_set->GetCollect("MobilePhone"));
			detailInfo.m_name=(LPCSTR)((_bstr_t)m_set->GetCollect("StaffName"));
			detailInfo.m_note=(LPCSTR)((_bstr_t)m_set->GetCollect("Remark"));
			detailInfo.m_phone=(LPCSTR)((_bstr_t)m_set->GetCollect("Telephone"));
			detailInfo.m_postcode=(LPCSTR)((_bstr_t)m_set->GetCollect("Postcode"));
			detailInfo.m_qq=(LPCSTR)((_bstr_t)m_set->GetCollect("QQ"));
			detailInfo.m_staffID=(LPCSTR)((_bstr_t)m_set->GetCollect("StaffID"));
			detailInfo.m_worktype=(LPCSTR)((_bstr_t)m_set->GetCollect("WorkType"));
			detailInfo.m_identityID=(LPCSTR)((_bstr_t)m_set->GetCollect("IdentityNO"));
			detailInfo.DoModal();
		}
	}
	//捕获异常
	catch(_com_error&e)
	{
		MessageBox(e.ErrorMessage());
	}
	*pResult = 0;
}


void CSearchEmployeeInfo::OnShowall() 
{
	// TODO: Add your control notification handler code here
	m_list.DeleteAllItems();
		try
	{
		_ConnectionPtr m_pConn("ADODB.Connection");
		m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\DataSource\\office1.mdb;Persist Security Info=False","","",adConnectUnspecified);
	   _RecordsetPtr m_set("ADODB.Recordset");
		m_set->Open("SELECT*FROM 人员基本档案",_variant_t(m_pConn,true),adOpenDynamic,adLockPessimistic,adCmdText);
		//打开
	    int i=0;
        m_num=0;//注意:m_num可能在别处已经修改如OnSearch()方法也用到m_num来记数
		while(!m_set->EndOfFile)
		{  
			m_num++;
			m_list.InsertItem(i,_bstr_t(m_set->GetCollect("StaffID")));
			m_list.SetItemText(i,1,_bstr_t(m_set->GetCollect("StaffName")));
			m_list.SetItemText(i,2,_bstr_t(m_set->GetCollect("Duty")));
			m_list.SetItemText(i,3,_bstr_t(m_set->GetCollect("Department")));
			m_list.SetItemText(i,4,_bstr_t(m_set->GetCollect("Telephone")));
			m_list.SetItemText(i,5,_bstr_t(m_set->GetCollect("Remark")));
            m_set->MoveNext();
		}
	}
	catch(_com_error&e)
	{
        MessageBox(e.ErrorMessage());
	}
	GetDlgItem(IDC_CLEAR)->EnableWindow();
	UpdateData(false);
}

//DEL void CSearchEmployeeInfo::OnOk() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	return;
//DEL }

void CSearchEmployeeInfo::OnClear() 
{
	// TODO: Add your control notification handler code here
	m_list.DeleteAllItems();
	m_num=0;
	GetDlgItem(IDC_CLEAR)->EnableWindow(false);
	UpdateData(false);
}

⌨️ 快捷键说明

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