📄 employeerecordset.cpp
字号:
// EmployeeRecordset.cpp : implementation file
//
#include "stdafx.h"
#include "CheckIn.h"
#include "EmployeeRecordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEmployeeRecordset
IMPLEMENT_DYNAMIC(CEmployeeRecordset, CRecordset)
CEmployeeRecordset::CEmployeeRecordset(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CEmployeeRecordset)
m_EmployeeID = _T("");
m_EmployeeName = _T("");
m_nFields = 2;
//}}AFX_FIELD_INIT
m_nDefaultType = dynaset;
}
CString CEmployeeRecordset::GetDefaultConnect()
{
return _T("ODBC;DSN=CheckIn");
}
CString CEmployeeRecordset::GetDefaultSQL()
{
return _T("[tbEmployee]");
}
void CEmployeeRecordset::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CEmployeeRecordset)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, _T("[EmployeeID]"), m_EmployeeID);
RFX_Text(pFX, _T("[EmployeeName]"), m_EmployeeName);
//}}AFX_FIELD_MAP
}
/////////////////////////////////////////////////////////////////////////////
// CEmployeeRecordset diagnostics
#ifdef _DEBUG
void CEmployeeRecordset::AssertValid() const
{
CRecordset::AssertValid();
}
void CEmployeeRecordset::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
BOOL CEmployeeRecordset::IsValidEmployee(CString EmployeeId)
/*判断员工号是否合法*/
/*检查EmployeeId是否在tbEmployee表中*/
{
CEmployeeRecordset rs;
try
{
if(rs.IsOpen())
{
rs.Close();
}
rs.Open(CRecordset::dynaset,_T("select * from tbEmployee where EmployeeID ='"+EmployeeId+"'"));
if (rs.MyGetRecordCount() <= 0)
{
rs.Close();
return false;
}
else
{
rs.Close();
return true;
}
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError );
return false;
}
}
#endif //_DEBUG
BOOL CEmployeeRecordset::AddEmployee(CString id, CString name)
{
try
{
if(!IsOpen())
Open();
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return false;
}
try
{
AddNew();
m_EmployeeID = id;
m_EmployeeName = name;
Update();
Close();
return true;
//MessageBox("增加成功!","提示",MB_ICONINFORMATION|MB_OK);
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return false;
}
}
BOOL CEmployeeRecordset::IsRepeatEmployeeID(CString EmployeeID)
{
try
{
if(!IsOpen())
Open(CRecordset::dynaset,_T("select * from tbEmployee where EmployeeID ='"+EmployeeID+"'"));
if (!(this->IsBOF()))//表明表中已经存在EmployeeID的记录
return true;
else
return false;
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
return true;
}
}
long CEmployeeRecordset::MyGetRecordCount()
{
long iTmp;
if(!this->IsBOF())
this->MoveFirst();
while(!this->IsEOF ())
{
this->MoveNext ();
}
iTmp = this->GetRecordCount();
return iTmp;
}
CString CEmployeeRecordset::GetEmployeeName(CString EmpID)
{
if(this->IsOpen())
{
this->Close();
}
this->Open(CRecordset::dynaset,_T("select * from tbEmployee where EmployeeID = '"+EmpID+"'"));
if (this->IsBOF())
{
this->Close();
return "";
}
CString tmpStr = this->m_EmployeeName;
this->Close();
return tmpStr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -