📄 checkrecordset.cpp
字号:
// CheckRecordset.cpp : implementation file
//
#include "stdafx.h"
#include "CheckIn.h"
#include "CheckRecordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCheckRecordset
IMPLEMENT_DYNAMIC(CCheckRecordset, CRecordset)
CCheckRecordset::CCheckRecordset(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CCheckRecordset)
m_EmployeeID = _T("");
m_State = 0;
m_CheckInTime = NULL;
m_nFields = 3;
//}}AFX_FIELD_INIT
m_nDefaultType = dynaset;
}
CString CCheckRecordset::GetDefaultConnect()
{
return _T("ODBC;DSN=CheckIn");
}
CString CCheckRecordset::GetDefaultSQL()
{
return _T("[tbCheckIn]");
}
void CCheckRecordset::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CCheckRecordset)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, _T("[EmployeeID]"), m_EmployeeID);
RFX_Date(pFX, _T("[CheckInTime]"), m_CheckInTime);
RFX_Long(pFX, _T("[State]"), m_State);
//}}AFX_FIELD_MAP
}
/////////////////////////////////////////////////////////////////////////////
// CCheckRecordset diagnostics
#ifdef _DEBUG
void CCheckRecordset::AssertValid() const
{
CRecordset::AssertValid();
}
void CCheckRecordset::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
#endif //_DEBUG
BOOL CCheckRecordset::AddCheckRecord(CString EmployID, CTime &CheckTime, int state)
{
try
{
if(!IsOpen())
Open();
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError );
return false;
}
try
{
this->AddNew();
this->m_EmployeeID = EmployID;
this->m_CheckInTime = CheckTime;
this->m_State = state;
Update();
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return false;
}
return true;
}
void CCheckRecordset::DeleteEmpCheck(CString EmployId)
/*删除员工号为EmpoyId的员工在tbCheckIn表中的考勤记录*/
{
if (!IsOpen())
Open(CRecordset::dynaset,_T("select * from tbCheckIn where EmployeeID ='"+EmployId+"'"));
if(!IsBOF())
{
MoveFirst();
while(!IsEOF())
{
this->Delete();
MoveNext();
}
}
}
BOOL CCheckRecordset::IsTodayChecked(CTime TodayTime, CString EmployID)
{
CTime StartTime = CTime(TodayTime.GetYear(),TodayTime.GetMonth(),TodayTime.GetDay(),0,0,0);
CTime EndTime = CTime(TodayTime.GetYear(),TodayTime.GetMonth(),TodayTime.GetDay(),23,59,60);
/*
if (!IsOpen())
Open(CRecordset::dynaset,_T("select * from tbCheckIn where EmployeeID ='"+EmployID+"' and CheckInTime >='"+FmtStartTime+"'"+" and CheckInTime <='"+FmtEndTime+"'"));
if(!IsBOF())//EmployID员工TodayTime这天已经签到
{
return true;
}
else
{
return false;
}
*/
int yearInTable;
int monthInTable;
int dayInTable;
if (!IsOpen())
Open(CRecordset::dynaset,_T("select * from tbCheckIn where EmployeeID ='"+EmployID+"'"));
if(!IsBOF())
{
int count = this->MyGetRecordCount();
this->MoveFirst();
while(this->IsEOF())
{
yearInTable = this->m_CheckInTime.GetYear();
monthInTable = this->m_CheckInTime.GetMonth();
dayInTable = this->m_CheckInTime.GetDay();
if ((yearInTable == TodayTime.GetYear()) & (monthInTable == TodayTime.GetMonth()) & (dayInTable == TodayTime.GetDay()))
{
this->Close();
return true;
}
this->MoveNext();
}
this->Close();
return false;
}
else
{
this->Close();
return false;
}
}
long CCheckRecordset::MyGetRecordCount()
{
long iTmp;
if(!this->IsBOF())
this->MoveFirst();
while(!this->IsEOF ())
{
this->MoveNext ();
}
iTmp = this->GetRecordCount();
return iTmp;
}
BOOL CCheckRecordset::ChageEmpId(CString OldEmpID, CString NewEmpID)
{
try
{
if (!IsOpen())
Open(CRecordset::dynaset,_T("select * from tbCheckIn where EmployeeID ='"+OldEmpID+"'"));
while(!this->IsEOF ())
{
this->Edit();
this->m_EmployeeID = NewEmpID;
this->Update();
this->MoveNext ();
}
this->Close();
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return false;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -