📄 public.cpp
字号:
// PersonInfo.cpp : implementation file
//
#include "stdafx.h"
#include "salarymanagement.h"
#include "Public.h"
#include "KaoqinDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPersonInfo
CPublic::CPublic()
{
m_ado.OnInitADOConn();
}
CPublic::~CPublic()
{
m_ado.ExitConnect();
}
BEGIN_MESSAGE_MAP(CPublic, CWnd)
//{{AFX_MSG_MAP(CPublic)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPublic message handlers
/***************************************************************
函数功能:将数据表DBtable中的数据显示到列表控件listCtrl中
参数信息:
listCtrl :[out] 要显示数据的列表控件
parameter:[in] 数据库表中的各属性名
nCount :[in] 数据库中属性的个数
DBtable :[in] 数据源,可获取数据的表
返回值 :[BOOL]有记录并显示,则返回TRUE,出现异常或无记录则返回FALSE
***************************************************************/
BOOL CPublic::LoadData(CListCtrl &listCtrl,const CString parameter[],UINT nCount,const CString &DBtable)
{
try{
//执行SQL语句获得数据库中的所有记录
_RecordsetPtr pRecordset=m_ado.GetRecordSet("Select * From "+DBtable);
//将数据显示在列表控件上
listCtrl.DeleteAllItems();
int m_CurrentRow=0;
if(pRecordset->adoEOF)
return FALSE;
while(!pRecordset->adoEOF)
{
listCtrl.InsertItem(m_CurrentRow,(_bstr_t)pRecordset->GetCollect((_variant_t)parameter[0]));
for(UINT i=1;i<nCount;i++)
listCtrl.SetItem(m_CurrentRow,i,1,(_bstr_t)pRecordset->GetCollect((_variant_t)parameter[i]),NULL,0,0,0);
pRecordset->MoveNext();
m_CurrentRow++;
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return FALSE;
}
return TRUE;
}
/**************************************************************
函数功能:当员工ID编辑框失去焦点时,检查员工ID是否存在,
若存在则得到员工姓名,否则提示错误
参数信息:
strID :[in] 要进行检查的员工ID,即从编辑框中获取的数据
strName :[out] 通过输入的员工ID获取的员工姓名
返回值 :[void] 空
**************************************************************/
void CPublic::OnKillfocusEdit( const CString &strID,CString &strName)
{
CString sql;
sql.Format("Select 员工姓名 From BasicInfomation Where 员工ID='%s'",strID);
_RecordsetPtr pRecordset=m_ado.GetRecordSet(sql);
if(pRecordset->adoEOF)
{
MessageBox("该用户ID不存在,请先添加基本信息");
return;
}
strName=(LPCTSTR)_bstr_t(pRecordset->GetCollect("员工姓名"));
}
/********************************************
函数功能:初始化列表控件
参数信息:
listCtrl:[out] 要进行初始化的列表控件对象
colTitle:[in] 要添加的列标题
width :[in] 要设置的列宽
nCount :[in] 列表控件的列数
返回值 :[BOOL] 正常设置返回TRUE,出现异常返回FALSE
********************************************/
BOOL CPublic::InitListCtrl(CListCtrl &listCtrl, const CString colTitle[], UINT width[],int nCount)
{
listCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES);
try{
int a=sizeof(colTitle);
for(int i=0;i<nCount;i++)
listCtrl.InsertColumn(i,colTitle[i],LVCFMT_CENTER,width[i]);
}
catch(...)
{
return FALSE;
}
return TRUE;
}
/****************************************************************
函数功能:将用户设置的数据写入数据库
参数信息:
table :[in] 要写入的数据库表名
main :[in] 要写入数据库的主键列的列名和值(属性结构体)
nCount :[in] 主键属性列的个数
prop :[in] 数据库表中其它非主键的属性(属性结构体)
propCount:[in] 数据库表中非主键属性列的个数
返回值 :[BOOL] 如果发生异常,则返回FALSE,否则返回TRUE
*****************************************************************/
BOOL CPublic::SavePersonData(const CString &table,const _property main[],UINT nCount,
const _property prop[],UINT propCount)
{
CString sql,temp;
_RecordsetPtr pRecordset;
try{
//SQL语句,看记录是否已经存在。是,则修改;否,则添加
sql.Format("Select * From %s Where ",table);
for(UINT i=0;i<nCount;i++)
{
if(i==0)
temp.Format("%s='%s' ",main[0].name,main[0].value);
else
temp.Format(" And %s='%s'",main[i].name,main[i].value);
sql+=temp;
}
//执行SQL语句,并获得结果
pRecordset=m_ado.GetRecordSet(sql);
//记录已经存在
if(!pRecordset->adoEOF)
{
CString str;
str.Format("该记录已经在%s表中存在,是否进行修改?",table);
if(IDNO==AfxMessageBox(str,MB_YESNO))
return FALSE;
}
else
{
//记录集不存在,则添加一条新纪录,并添加主键对应的值
pRecordset->AddNew();
for(i=0;i<nCount;i++)
pRecordset->PutCollect(_variant_t(main[i].name),_variant_t(main[i].value));
}
//添加其它属性对应的值
for(i=0;i<propCount;i++)
pRecordset->PutCollect(_variant_t(prop[i].name),_variant_t(prop[i].value));
//更新数据集
pRecordset->Update();
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
return FALSE;
}
return TRUE;
}
/****************************************************************
函数功能:将用户设置的考勤数据写入考勤相关数据库
参数信息:
record1 :[in] 要写入考勤相关数据库记录,包括主键数据和非主键数据
table1 :[in] 要写入的考勤相关的数据库表名
record2 :[in] 要写入考勤总体统计记录,包括主键数据和非主键数据
table2 :[in] 考勤总体统计表
返回值 :[BOOL] 如果发生异常,则返回FALSE,否则返回TRUE
*****************************************************************/
BOOL CPublic::SaveKaoqinData(const DataRecord &record1, const CString &table1,
const DataRecord &record2, const CString &table2)
{
//对相应的数据库表中的数据进行添加或修改
if(!SavePersonData(table1,record1.mainProp,record1.nCount,
record1.smpProp,record1.smpCount))
return FALSE;
//对数据库中考勤总体统计表(KaoQin表)中出差相关的记录进行更新
if(!SavePersonData(table2,record2.mainProp,record2.nCount,
record2.smpProp,record2.smpCount))
return FALSE;
CKaoqinDlg::s_SQL="Select * From "+table1;
CKaoqinDlg::s_bRefresh=TRUE;
return TRUE;
}
/****************************************************************
函数功能:设置对话框的背景,用图片填充
参数信息:
pParent :[in] 要填充的对话框的指针
nIDResource :[in] 用来填充的图片资源的ID
返回值 : [void] 空
*****************************************************************/
void CPublic::SetBkBitmap(CWnd *pParent, UINT nIDResource)
{
CPaintDC dc(pParent); // device context for painting
CRect rect;
pParent->GetClientRect(rect);
CBitmap bitmap;
bitmap.LoadBitmap (nIDResource);
CDC CompatibleDC;
CompatibleDC.CreateCompatibleDC(&dc);
CBitmap *pOldBitmap=CompatibleDC.SelectObject(&bitmap);
BITMAP bm;
bitmap.GetBitmap(&bm);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&CompatibleDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
dc.SelectObject(pOldBitmap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -