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

📄 dlgempinfo.cpp

📁 航空公司简单考勤系统:主要运用指纹管理深圳航空公司的会议签到管理系统
💻 CPP
字号:
// DlgEmpInfo.cpp : implementation file
//

#include "stdafx.h"
#include "Demo_airline.h"
#include "DlgEmpInfo.h"
#include "OT_DLL.h"

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

//临时的指纹图像;
char FingerBmp[256]="Finger.bmp";
//指纹图像缓冲区;
unsigned char USBFingerBuf[304][256];
//特征数据缓冲区;
unsigned char SrcFeatureBuf[2*1024];
CString CurUser;
CString g_strFingerPath;
CDlgEmpInfo *pMainDlg;


/////////////////////////////////////////////////////////////////////////////
// CDlgEmpInfo dialog
extern CDemo_airlineApp theApp;

CDlgEmpInfo::CDlgEmpInfo(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgEmpInfo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgEmpInfo)
	m_strEmpID = _T("");
	m_strEmpName = _T("");
	m_strEmpSex = _T("");
	m_strDepartID = _T("");
	m_strNation = _T("");
	m_strPosition = _T("");
	m_strPicPath = _T("");
	m_bDepartShow = FALSE;
	m_hTreeItem = NULL;
	//}}AFX_DATA_INIT
}


void CDlgEmpInfo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgEmpInfo)
	DDX_Control(pDX, IDC_PIC, m_Pic);
	DDX_Control(pDX, IDC_TREEDEPART, m_treeDepart);
	DDX_Text(pDX, IDC_EDT_ID, m_strEmpID);
	DDV_MaxChars(pDX, m_strEmpID, 6);
	DDX_Text(pDX, IDC_EDT_NAME, m_strEmpName);
	DDV_MaxChars(pDX, m_strEmpName, 30);
	DDX_CBString(pDX, IDC_COMBO_SEX, m_strEmpSex);
	DDV_MaxChars(pDX, m_strEmpSex, 4);
	DDX_Text(pDX, IDC_EDT_DEPART, m_strDepartID);
	DDV_MaxChars(pDX, m_strDepartID, 4);
	DDX_Text(pDX, IDC_EDT_NATION, m_strNation);
	DDV_MaxChars(pDX, m_strNation, 10);
	DDX_Text(pDX, IDC_EDT_POSITION, m_strPosition);
	DDV_MaxChars(pDX, m_strPosition, 30);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgEmpInfo, CDialog)
	//{{AFX_MSG_MAP(CDlgEmpInfo)
	ON_BN_CLICKED(IDC_BTN_UPLOADPIC, OnBtnUploadpic)
	ON_BN_CLICKED(IDC_BTN_DEPART, OnBtnDepart)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREEDEPART, OnDblclkTreedepart)
	ON_BN_CLICKED(IDC_BTN_FINGER1, OnBtnFinger)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgEmpInfo message handlers

BOOL CDlgEmpInfo::OnInitDialog() 
{
	CDialog::OnInitDialog();

	m_pRecordEmp.CreateInstance(__uuidof(Recordset));
    //m_pRecordDepart.CreateInstance(__uuidof(Recordset));

    m_oDepartmentTree.InitImageList(&m_treeDepart);
	m_oDepartmentTree.ReadDepartment(&m_treeDepart);
	if(!MXInitDev(NULL))
	{
		AfxMessageBox("采集仪打开失败,请检查是否正确连接!");
	}
	m_treeDepart.ShowWindow(SW_HIDE);
	pMainDlg = this;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgEmpInfo::OnOK() 
{
	UpdateData(TRUE);
    int nCount = 0;
	//判断是否存在该主键
	try
	{
	   CString strSql;
	   strSql.Format("select count(*) as amount from Employee where EmployeeID = '%s'",m_strEmpID);
       m_pRecordEmp->Open(strSql.AllocSysString(),
				theApp.m_pConnection.GetInterfacePtr(),
				adOpenDynamic,
				adLockOptimistic,
				adCmdText);

	   _variant_t var = m_pRecordEmp->GetCollect("amount");
	   if(VT_NULL != var.vt)
	   {
         nCount = atoi((char*)_bstr_t(var));
	   }

	}
	catch(_com_error e)
	{
		e.Description();
	}
    m_pRecordEmp->Close();

	if(nCount > 0)
		MessageBox("数据库已存在该员工编号",NULL,MB_OK);
	else
	{
		//插入人员信息
		if(!m_strPicPath.IsEmpty() || (FALSE == g_strFingerPath.IsEmpty() ))
		{
			
			try
			{
				m_pRecordEmp->Open("select * from Employee",
					theApp.m_pConnection.GetInterfacePtr(),
					adOpenDynamic,
					adLockOptimistic,
					adCmdText);
				
				m_pRecordEmp->AddNew();
				m_pRecordEmp->PutCollect("EmployeeID",_bstr_t(m_strEmpID));
				m_pRecordEmp->PutCollect("EmployeeName",_bstr_t(m_strEmpName));
				m_pRecordEmp->PutCollect("Sex",_bstr_t(m_strEmpSex));
				m_pRecordEmp->PutCollect("Position",_bstr_t(m_strPosition));
				m_pRecordEmp->PutCollect("Nationality",_bstr_t(m_strNation));
				m_pRecordEmp->PutCollect("DepartmentID",_bstr_t(m_strDepartID));
				m_pRecordEmp->PutCollect("PicPath",_bstr_t(m_strPicPath));
				m_pRecordEmp->PutCollect("FingerData",_bstr_t(g_strFingerPath));
				m_pRecordEmp->Update();
				
				m_pRecordEmp->Close();
				MessageBox("添加人员成功",NULL,MB_OK);
			}
			catch(_com_error e)
			{
				e.Description();
			}		
		}
		else
		{
			AfxMessageBox("请检查是否上传照片或录入指纹");
		}
	}

	CDialog::OnOK();
}

void CDlgEmpInfo::OnBtnUploadpic() 
{
	CFileDialog filePic(TRUE);
    filePic.DoModal();
	m_strPicPath = filePic.GetPathName();
	if(m_Pic.Load(m_strPicPath))
		m_Pic.Draw();
}

void CDlgEmpInfo::OnBtnDepart() 
{
	// TODO: Add your control notification handler code here
	m_bDepartShow = ~m_bDepartShow;
	if(m_bDepartShow)
       m_treeDepart.ShowWindow(SW_SHOW);
	else
		m_treeDepart.ShowWindow(SW_HIDE);
	
}

void CDlgEmpInfo::OnDblclkTreedepart(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	char* pszDepartID = new char[10];
	memset(pszDepartID,0,4);
	
	LPNMTREEVIEW temp = (LPNMTREEVIEW)pNMHDR;
    HTREEITEM hTreeItem = temp->itemNew.hItem;

	m_oDepartmentTree.GetDepartmentID(&m_treeDepart,hTreeItem,pszDepartID);
	m_strDepartID = pszDepartID;
	
	UpdateData(FALSE);
	m_treeDepart.ShowWindow(SW_HIDE);
	delete []pszDepartID;
	*pResult = 0;
}

void CDlgEmpInfo::EnableBtn(bool b)
{
    
}

int  CDlgEmpInfo::GetFinger(char *szPath)//获取指纹图象;
{   
	char szFilePath[MAX_PATH] = {0};
	BOOL IsDefault = TRUE;

	strcpy(szFilePath, FingerBmp);
	
    (CButton*)GetDlgItem(IDC_BTN_FINGER1)->EnableWindow(false);
	//ShowInfo("请按手指!");
	//AfxMessageBox("请按手指");
 
	while(true)
	{
		if(!MXIsFingerOn())
			continue;
		if(!MXReadFingerFromSensor(USBFingerBuf[0]))
		{
			
			AfxMessageBox("指纹失败!");
 			return 0;
		}
 		if(MXDetectFinger(&USBFingerBuf[0][0]))
		{        
			 
			if(!MXSaveFingerToFile(USBFingerBuf[0],szFilePath))
			{
				::AfxMessageBox("指纹失败");
 				EnableBtn(true);
				return 0;
			}
			/*if(IsDefault)
				ShowBMP(IDC_FINGER);
			else
				ShowBMP(IDC_FINGER, szFilePath);*/
			
			//ShowInfo("请拿起手指!");
			//AfxMessageBox("请拿起手指");
			(CButton*)GetDlgItem(IDC_BTN_FINGER1)->EnableWindow(true);
			//(CButton*)GetDlgItem(IDC_BTN_FINGER1)->SetDlgItemText("指纹录入成功");
			::SetWindowText(((CButton*)GetDlgItem(IDC_BTN_FINGER1))->m_hWnd,"指纹录入成功");
			Sleep(2000);
			::SetWindowText(((CButton*)GetDlgItem(IDC_BTN_FINGER1))->m_hWnd,"指纹录入");
			//EnableBtn(true);
			return 1;			
		}
	} 
	
	return 0;	
}

//录入指纹
UINT EnrollT(LPVOID pParam)
{
	//CShowInfo dlg;
	int maxret=0,count=0;
 
	//pMainDlg->m_Progress.SetPos(0);
	char buf[256] = {0};
	GetModuleFileName(NULL,buf,256);
	int nStep = 0;
    for ( int nIndex = 0; nIndex < strlen(buf); nIndex++)
	{
		if (buf[nIndex] == '\\')
			nStep = nIndex;
	}
	char caPath[256] = {0};
	memcpy(caPath,buf,nStep);
	int nLen = strlen(caPath);
	nLen++;
	caPath[nLen]='\0';

	CString sDir;
	sDir.Format("%s\\data\\", caPath);

	CString sFile=sDir+CurUser+".mia";
	g_strFingerPath.Empty();

	g_strFingerPath = sFile;
 
	if(!pMainDlg->GetFinger())
		return 0;

	CString sInfo = " ";//./
	if (!MXExtract(USBFingerBuf[0], SrcFeatureBuf))//录入成功
	{	
		MXSaveFeatureToFile(SrcFeatureBuf,(char*)(LPCSTR)sFile);
		return 1;
		
	}
	else 
		AfxMessageBox("指纹录入失败!");
	return 0;//./
	
}

void CDlgEmpInfo::OnBtnFinger() 
{
	UpdateData(TRUE);
    CurUser = m_strEmpID;
	if(FALSE == CurUser.IsEmpty())
    	AfxBeginThread(EnrollT,NULL);	
	else
		AfxMessageBox("员工编号不能为空!");
}

⌨️ 快捷键说明

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