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

📄 configattendpage.cpp

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

#include "stdafx.h"
#include "FPSys.h"
#include "ConfigAttendPage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConfigAttendPage property page
extern CDatabase m_db;

IMPLEMENT_DYNCREATE(CConfigAttendPage, CPropertyPage)

CConfigAttendPage::CConfigAttendPage() : CPropertyPage(CConfigAttendPage::IDD)
{
	//{{AFX_DATA_INIT(CConfigAttendPage)
	m_strType = _T("");
	m_strSymbol = _T("");
	m_strLeave = _T("");
	m_strLate = _T("");
	m_strAbsent = _T("");
	//}}AFX_DATA_INIT
}

CConfigAttendPage::~CConfigAttendPage()
{
}

void CConfigAttendPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConfigAttendPage)
	DDX_Control(pDX, IDC_LIST_ATTEND, m_listAttend);
	DDX_Text(pDX, IDC_EDIT_TYPE, m_strType);
	DDX_Text(pDX, IDC_EDIT_SYMBOL, m_strSymbol);
	DDX_Text(pDX, IDC_EDIT_LEAVE, m_strLeave);
	DDX_Text(pDX, IDC_EDIT_LATE, m_strLate);
	DDX_Text(pDX, IDC_EDIT_ABSENT, m_strAbsent);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigAttendPage, CPropertyPage)
	//{{AFX_MSG_MAP(CConfigAttendPage)
	ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
	ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
	ON_BN_CLICKED(IDC_BTN_MOD, OnBtnMod)
	ON_NOTIFY(NM_CLICK, IDC_LIST_ATTEND, OnClickListAttend)
	ON_EN_CHANGE(IDC_EDIT_LATE, OnChangeEditLate)
	ON_EN_CHANGE(IDC_EDIT_LEAVE, OnChangeEditLeave)
	ON_EN_CHANGE(IDC_EDIT_ABSENT, OnChangeEditAbsent)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigAttendPage message handlers

void CConfigAttendPage::OnBtnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_strSymbol.IsEmpty()||m_strType.IsEmpty())
	{
		MessageBox("请完整填写信息!");
		return;
	}

	TRY{
		CString sql;
		sql.Format("Insert into tab_AttendType(AttendTypeID,AttendType) values(%d,'%s')",atoi(m_strSymbol),m_strType);
		TRACE(sql);
		m_db.ExecuteSQL(sql);
		InsertItemData(m_strSymbol,m_strType);
	}
	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
}

void CConfigAttendPage::OnBtnDel() 
{
	// TODO: Add your control notification handler code here
	int nItem=m_listAttend.GetNextItem(-1,LVNI_SELECTED);
	if(-1==nItem)
	{
		AfxMessageBox("请选择要删除的数据");
		return;
	}
	int id;
	id=atoi(m_listAttend.GetItemText(nItem,0));
	TRY{
		CString sql;
		sql.Format("delete from tab_AttendType where AttendTypeID=%d",id);
		TRACE(sql);
		m_db.ExecuteSQL(sql);
		m_strSymbol.Empty();
		m_strType.Empty();
		m_listAttend.DeleteItem(nItem);
		UpdateData(FALSE);
	}
	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
}

void CConfigAttendPage::OnBtnMod() 
{
	// TODO: Add your control notification handler code here
	int nItem=m_listAttend.GetNextItem(-1,LVNI_SELECTED);
	if(nItem==-1)
		return;
	UpdateData();
	if(strcmp(m_PreID,m_strSymbol)!=0)
	{
		MessageBox("编号不用修改,只能通过删除后再改!");
		m_strSymbol=m_PreID;
		UpdateData(FALSE);
		return;
	}
	TRY{
		CString sql;
		sql.Format("Update tab_AttendType set AttendType='%s' where AttendTypeID='%s'",
				m_strType,m_strSymbol);
		TRACE(sql);
		m_db.ExecuteSQL(sql);
		m_listAttend.SetItemText(nItem,1,m_strType);
	}
	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
}

BOOL CConfigAttendPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	LPCTSTR FILE_NAME=".\\time.ini";
	CString strCaption;
	GetPrivateProfileString("Time","Caption","Default Caption",
							strCaption.GetBuffer(MAX_PATH),MAX_PATH,FILE_NAME);

	int late=GetPrivateProfileInt("Time","Late",0,FILE_NAME);
	int absent=GetPrivateProfileInt("Time","Absent",0,FILE_NAME);
	int leave=GetPrivateProfileInt("Time","Leave",0,FILE_NAME);
	m_strLate.Format("%d",late);
	m_strAbsent.Format("%d",absent);
	m_strLeave.Format("%d",leave);
	UpdateData(FALSE);

	DWORD dwExStyle=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|
					LVS_EX_ONECLICKACTIVATE|LVS_EX_UNDERLINEHOT;
	m_listAttend.SetExtendedStyle(dwExStyle);
	m_listAttend.InsertColumn(0,"考勤代号",LVCFMT_CENTER,60);
	m_listAttend.InsertColumn(1,"考勤类型",LVCFMT_CENTER,90);

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

void CConfigAttendPage::InitCtrlData()
{
	CString sql;
	sql.Format("select *from tab_AttendType order by AttendTypeID");
	TRY{
		CRecordset rs(&m_db);
		rs.Open(CRecordset::dynaset,sql);
		while(!rs.IsEOF())
		{
			int id,nItem;
			CDBVariant var;
			CString temp,tempName;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				id=var.m_lVal;
			var.Clear();
			temp.Format("%d",id);
			rs.GetFieldValue(1,tempName);
			InsertItemData(temp,tempName);
			rs.MoveNext();
		}
	}
	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
}

void CConfigAttendPage::InsertItemData(CString AttendID, CString AttendType)
{
	int nIndex=m_listAttend.GetItemCount();
	LV_ITEM lvItem;
	lvItem.mask=LVIF_TEXT;
	lvItem.iItem=nIndex;
	lvItem.iSubItem=0;
	lvItem.pszText=(char*)(LPCTSTR)AttendID;
	m_listAttend.InsertItem(&lvItem);
	m_listAttend.SetItemText(nIndex,1,AttendType);
}

void CConfigAttendPage::OnClickListAttend(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nItem=m_listAttend.GetNextItem(-1,LVNI_SELECTED);
	if(nItem!=-1)
	{	
		CString id=m_listAttend.GetItemText(nItem,0);
		GetDlgItem(IDC_EDIT_SYMBOL)->SetWindowText(id);
		m_PreID=id;

		CString name=m_listAttend.GetItemText(nItem,1);
		GetDlgItem(IDC_EDIT_TYPE)->SetWindowText(name);
	}
	*pResult = 0;
}

void CConfigAttendPage::OnChangeEditLate() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CPropertyPage::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	LPCTSTR FILE_NAME=".\\time.ini";
	WritePrivateProfileString("Time","Caption","TimeSet",FILE_NAME);

	WritePrivateProfileString("Time","Late",m_strLate,FILE_NAME);
	WritePrivateProfileString("Time","AttendID1","1",FILE_NAME);
}

void CConfigAttendPage::OnChangeEditLeave() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CPropertyPage::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	LPCTSTR FILE_NAME=".\\time.ini";
	WritePrivateProfileString("Time","Caption","TimeSet",FILE_NAME);

	WritePrivateProfileString("Time","Leave",m_strLeave,FILE_NAME);
	WritePrivateProfileString("Time","AttendID3","3",FILE_NAME);
}

void CConfigAttendPage::OnChangeEditAbsent() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CPropertyPage::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	LPCTSTR FILE_NAME=".\\time.ini";
	WritePrivateProfileString("Time","Caption","TimeSet",FILE_NAME);

	WritePrivateProfileString("Time","Absent",m_strAbsent,FILE_NAME);
	WritePrivateProfileString("Time","AttendID2","2",FILE_NAME);
}

⌨️ 快捷键说明

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