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

📄 matchdlg.cpp

📁 基于指纹技术的学生考勤系统
💻 CPP
字号:
// MatchDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FPSys.h"
#include "MatchDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMatchDlg dialog
extern int m_iConnDes;
extern CDatabase m_db;

CString sID,sAttendID;

CMatchDlg::CMatchDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMatchDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMatchDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CMatchDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMatchDlg)
	DDX_Control(pDX, IDC_CHECK_SHOWALL, m_Check);
	DDX_Control(pDX, IDC_COMBO_ATT, m_cAtt);
	DDX_Control(pDX, IDC_COMBO_STUDENT, m_cStudent);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMatchDlg, CDialog)
	//{{AFX_MSG_MAP(CMatchDlg)
	ON_BN_CLICKED(IDC_BTN_READ, OnBtnRead)
	ON_BN_CLICKED(IDC_CHECK_SHOWALL, OnCheckShowall)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMatchDlg message handlers

void CMatchDlg::OnOK() 
{
	// TODO: Add extra validation here
	if(m_cStudent.GetCurSel()==-1||m_cAtt.GetCurSel()==-1)
	{
		MessageBox("请建立完整的对应关系!");
		return;
	}
	m_cAtt.GetLBText(m_cAtt.GetCurSel(),sAttendID);
	m_cStudent.GetLBText(m_cStudent.GetCurSel(),sID);

	CString sql;
	sql.Format("select *from tab_student where AttendID='%s'",sAttendID);
	TRY{
		CRecordset rs(&m_db);
		rs.Open(CRecordset::dynaset,sql);
		if(!rs.IsEOF())
		{
			MessageBox("此考勤号已经匹配!");
			return;
		}
	}
	CATCH(CDBException,ex)
	{
		AfxMessageBox(ex->m_strError);
		AfxMessageBox(ex->m_strStateNativeOrigin);
	}
	AND_CATCH(CMemoryException,pEx)
	{
		pEx->ReportError();
		AfxMessageBox("memory exception");
	}
	AND_CATCH(CException,e)
	{
		TCHAR szError[100];
		e->GetErrorMessage(szError,100);
		AfxMessageBox(szError);
	}
	END_CATCH
	CDialog::OnOK();
}

void CMatchDlg::OnBtnRead() 
{
	// TODO: Add your control notification handler code here
		CDevConnectDlg dlg;
	m_iConnDes=3;
	dlg.DoModal();
	
	int iCount=m_cAtt.GetCount();
	for(int i=0;i<iCount;i++)
		m_cAtt.DeleteString(0);
	InitCtrlData();
}

void CMatchDlg::InitCtrlData()
{
	if(!m_db.IsOpen())
	{
		MessageBox("数据库未打开!");
		return;
	}
	int i;
	for(i=0;i<m_cStudent.GetCount();i++);
	{
		m_cStudent.DeleteString(0);
	}
	for(i=0;i<m_cAtt.GetCount();i++);
	{
		m_cAtt.DeleteString(0);
	}
	CRecordset rs(&m_db);
	CString sql;
	if(bShow)
		sql.Format("Select distinct *from tab_Student order by SId");
	else
		sql.Format("Select distinct *from tab_Student where AttendID=0 order by SId");

	rs.Open(CRecordset::dynaset,sql);	//查找还没有匹配过考勤号的学生的学号
	while(!rs.IsEOF())
	{
		int id;
		CString temp;
		CDBVariant var;
		rs.GetFieldValue((short)0,var,SQL_C_SLONG);
		if(var.m_dwType!=DBVT_NULL)
			id=var.m_lVal;
		var.Clear();
		temp.Format("%d",id);
		m_cStudent.AddString(temp);
		rs.MoveNext();
	}
	rs.Close();

	BOOL bFind=FALSE;
	CString tmp;
	for(i=0;i<m_cStudent.GetCount();i++)
	{
		m_cStudent.GetLBText(i,tmp);
		if(strcmp(sID,tmp)==0)
		{
			bFind=TRUE;
			break;
		}
	}
	if(bFind)
		m_cStudent.SetCurSel(i);

//	sql.Format("Select *from tab_Att where Att not in "
//			"(select AttendID from tab_student) order by Att");
	if(bShow)
		sql.Format("Select *from tab_Att order by Att");
	else				//未做处理:给学生匹配的不列出来
		sql.Format("Select *from tab_Att order by Att");	
	rs.Open(CRecordset::dynaset,sql);
	while(!rs.IsEOF())
	{
		int id;
		CString temp;
		CDBVariant var;
		rs.GetFieldValue((short)0,var,SQL_C_SLONG);
		if(var.m_dwType!=DBVT_NULL)
			id=var.m_lVal;
		var.Clear();
		temp.Format("%d",id);
		m_cAtt.AddString(temp);
		rs.MoveNext();
	}
	rs.Close();
}

BOOL CMatchDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	bShow=FALSE;
	InitCtrlData();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMatchDlg::OnCheckShowall() 
{
	// TODO: Add your control notification handler code here
	if(1==m_Check.GetCheck())
		bShow=TRUE;
	else
		bShow=FALSE;
	int iCount=m_cStudent.GetCount();
	int i=0;
	while(i<iCount)
	{
		m_cStudent.DeleteString(0);
		i++;
	}
	iCount=m_cAtt.GetCount();
	i=0;
	while(i<iCount)
	{
		m_cAtt.DeleteString(0);
		i++;
	}
	InitCtrlData();
}

⌨️ 快捷键说明

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