📄 jishigongzi.cpp
字号:
//
//
/*************************************
文件名:JiShiGongZi.cpp
文件类型:implementation file
功能描述:对计件工资信息进行录入
创建人:张国
版本号:1.0
**************************************/
#include "stdafx.h"
#include "salarymanagement.h"
#include "JiShiGongZi.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJiShiGongZi dialog
CJiShiGongZi::CJiShiGongZi(CWnd* pParent /*=NULL*/)
: CDialog(CJiShiGongZi::IDD, pParent)
{
//{{AFX_DATA_INIT(CJiShiGongZi)
m_wID = _T("");
m_Money = 0.0f;
m_Name = _T("");
m_Pmoney = 0.0f;
m_Worktime = 0.0f;
m_Date = COleDateTime::GetCurrentTime();
m_radio = 0;
m_FindID = _T("");
m_FindName = _T("");
//}}AFX_DATA_INIT
m_ado.OnInitADOConn();
}
CJiShiGongZi::~CJiShiGongZi()
{
m_ado.ExitConnect();
}
void CJiShiGongZi::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJiShiGongZi)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_Gonghao, m_wID);
DDX_Text(pDX, IDC_Money, m_Money);
DDX_Text(pDX, IDC_NAME, m_Name);
DDX_Text(pDX, IDC_Pmoney, m_Pmoney);
DDX_Text(pDX, IDC_WORKTIME, m_Worktime);
DDX_DateTimeCtrl(pDX, IDC_Date, m_Date);
DDX_Radio(pDX, IDC_RADIOID, m_radio);
DDX_Text(pDX, IDC_FindID, m_FindID);
DDX_Text(pDX, IDC_FindName, m_FindName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJiShiGongZi, CDialog)
//{{AFX_MSG_MAP(CJiShiGongZi)
ON_BN_CLICKED(IDC_Computing, OnComputing)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_EN_KILLFOCUS(IDC_Gonghao, OnKillfocusGonghao)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
ON_BN_CLICKED(IDC_DEL, OnDel)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_Find, OnFind)
ON_BN_CLICKED(IDC_RADIOName, OnRADIOName)
ON_BN_CLICKED(IDC_RADIOID, OnRadioid)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJiShiGongZi message handlers
void CJiShiGongZi::OnCancel()
{
((CDialog*)this->GetParent())->EndDialog(IDCANCEL);
CDialog::OnCancel();
}
void CJiShiGongZi::OnComputing()
{
// TODO: Add your control notification handler code here
UpdateData();
m_Money=m_Pmoney*m_Worktime;
UpdateData(false);
}
BOOL CJiShiGongZi::OnInitDialog()
{
CDialog::OnInitDialog();
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES |LVS_EX_INFOTIP );
m_list.InsertColumn(0,"加工日期",LVCFMT_CENTER,100);
m_list.InsertColumn(1,"员工ID",LVCFMT_CENTER,100);
m_list.InsertColumn(2,"姓名",LVCFMT_CENTER,100);
m_list.InsertColumn(3,"计时工作时间",LVCFMT_CENTER,100);
m_list.InsertColumn(4,"单位时间工资",LVCFMT_CENTER,100);
m_list.InsertColumn(5,"应得金额",LVCFMT_CENTER,100);
m_recordset=m_ado.GetRecordSet("Select * From TimeWage");
LoadData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CJiShiGongZi::OnSave()
{
UpdateData();
if(m_wID=="")
{
AfxMessageBox("请输入员工ID");
return;
}
try{
//SQL语句,看记录是否已经存在。是,则修改;否,则添加
CString sql;
sql.Format("Select * From TimeWage Where 员工ID='%s' and 日期='%s'",
m_wID,m_Date.Format("%Y- %m- %d"));
//执行SQL语句,获得结果
m_recordset=m_ado.GetRecordSet(sql);
//标记为添加一条新记录
additem=1;
//记录集已存在时为修改记
if(!m_recordset->adoEOF)
{
additem=0;//标记为修改一条已存在的记录
oldmoney=m_recordset->GetCollect("应得金额");
if(IDNO==AfxMessageBox("该记录已经存在,是否进行修改?",MB_YESNO))
{
return;
}
}
//录集不存在,将其添加入新行
if(m_recordset->adoEOF)
{
m_recordset->AddNew();
m_recordset->PutCollect("日期",_variant_t(m_Date.Format("%Y- %m- %d")));
m_recordset->PutCollect("员工ID",(_variant_t)m_wID);
}
m_recordset->PutCollect("姓名",(_variant_t)m_Name);
m_recordset->PutCollect("计时工作时间",(_variant_t)m_Worktime);
m_recordset->PutCollect("单位时间工资",(_variant_t)m_Pmoney);
m_recordset->PutCollect("应得金额",(_variant_t)m_Money);
//更新数据库
m_recordset->Update();
//将计时工资应得金额添加到Wage数据库中的计时工资下
SaveToWage();
//重新载入数据
m_recordset=m_ado.GetRecordSet("Select * From TimeWage");
LoadData();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
//清除编辑框中的数据
clean();
UpdateData(FALSE);
}
void CJiShiGongZi::OnKillfocusGonghao()
{
UpdateData();
try{
CString str;
str.Format("Select * From BasicInfomation Where 员工ID='%s'",m_wID);
m_recordset=m_ado.GetRecordSet(str);
if(m_recordset->adoEOF)
{
AfxMessageBox("员工ID不存在!!!");
return;
}
m_vName=m_recordset->GetCollect("员工姓名");
m_vDepartment=m_recordset->GetCollect("部门名称");
m_vPosition=m_recordset->GetCollect("职位");
m_Name=(LPCTSTR)(_bstr_t)m_vName;
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
UpdateData(FALSE);
}
void CJiShiGongZi::LoadData()
{
//将数据显示在列表控件上
m_list.DeleteAllItems();
int m_CuRow=0;
try{
while(!m_recordset->adoEOF)
{
m_list.InsertItem(m_CuRow,(_bstr_t)m_recordset->GetCollect("日期"));
m_list.SetItem(m_CuRow,1,1,(_bstr_t)m_recordset->GetCollect("员工ID"),NULL,0,0,0);
m_list.SetItem(m_CuRow,2,1,(_bstr_t)m_recordset->GetCollect("姓名"),NULL,0,0,0);
m_list.SetItem(m_CuRow,3,1,(_bstr_t)m_recordset->GetCollect("计时工作时间"),NULL,0,0,0);
m_list.SetItem(m_CuRow,4,1,(_bstr_t)m_recordset->GetCollect("单位时间工资"),NULL,0,0,0);
m_list.SetItem(m_CuRow,5,1,(_bstr_t)m_recordset->GetCollect("应得金额"),NULL,0,0,0);
m_recordset->MoveNext();
m_CuRow++;
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
void CJiShiGongZi::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
//获得鼠标点击的行号
int nItem=pNMListView->iItem;
m_CurrentSelect=nItem;
int m_t=m_list.GetItemCount();
if (nItem<0||nItem>m_t)
{
clean();
UpdateData(false);
return;
}
//定义一个Cstring的临时变量
CString str;
//将对应行中各列的数据反馈到编辑框和列表框控件上
str=m_list.GetItemText(nItem,0);
m_Date.ParseDateTime(str);//日期
m_wID=m_list.GetItemText(nItem,1);//员工ID
m_Name=m_list.GetItemText(nItem,2);//姓名
str=m_list.GetItemText(nItem,3);
m_Worktime=(float)atof(str);//计时工作时间
str=m_list.GetItemText(nItem,4);
m_Pmoney=(float)atof(str);//单位时间工资
str=m_list.GetItemText(nItem,5);
m_Money=(float)atof(str);//应得金额
UpdateData(FALSE);//更新数据
*pResult = 0;
}
void CJiShiGongZi::OnDel()
{
UpdateData();
if(m_list.GetSelectedCount()==0||m_CurrentSelect>=m_list.GetItemCount())
{
AfxMessageBox("请选择您要删除的记录!");
return;
}
if(IDNO==AfxMessageBox("您确定要删除该记录吗?",MB_YESNO))
return;
//删除Wage表中相应的记录
additem=-1;
SaveToWage();
try{
//执行删除
CString sql="";
sql.Format("Delete From TimeWage Where 员工ID='%s' and 日期='%s'",
m_wID,m_Date.Format("%Y- %m- %d"));
m_ado.ExecuteSQL(sql);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_list.DeleteItem(m_CurrentSelect);
clean();
UpdateData(FALSE);
}
void CJiShiGongZi::clean()
{
//清除编辑框中的数据
m_Money=0.0;
m_Pmoney=0.0;
m_wID="";
m_Name="";
m_Worktime=0.0;
m_FindID="";
m_FindName="";
}
void CJiShiGongZi::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
//获得鼠标点击的行号
int nItem=pNMListView->iItem;
if (nItem==-1)
{
clean();
UpdateData(false);
}
*pResult = 0;
}
void CJiShiGongZi::OnFind()
{
UpdateData();
CString str;
try{
if (m_radio==0)
{
str.Format("Select * From TimeWage Where 员工ID='%s'",m_FindID);
m_recordset=m_ado.GetRecordSet(str);
if(m_recordset->adoEOF)
{
AfxMessageBox("员工ID不存在!!!");
return;
}
}
if (m_radio==1)
{
str.Format("Select * From TimeWage Where 姓名='%s'",m_FindName);
m_recordset=m_ado.GetRecordSet(str);
if(m_recordset->adoEOF)
{
AfxMessageBox("员工姓名不存在!!!");
return;
}
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
LoadData();
UpdateData(FALSE);
}
void CJiShiGongZi::OnRADIOName()
{
//按姓名搜索时,清空按员工ID搜索编辑框
GetDlgItem(IDC_FindID)->EnableWindow(FALSE);
GetDlgItem(IDC_FindName)->EnableWindow(TRUE);
m_radio=1;
m_FindID="";
UpdateData(FALSE);
}
void CJiShiGongZi::OnRadioid()
{
//按员工ID搜索时,清空按姓名搜索编辑框
GetDlgItem(IDC_FindID)->EnableWindow(TRUE);
GetDlgItem(IDC_FindName)->EnableWindow(FALSE);
m_radio=0;
m_FindName="";
UpdateData(FALSE);
}
//计时工资保存到Wage表中
void CJiShiGongZi::SaveToWage()
{
UpdateData();
CString sql;
if(m_wID=="")
{
AfxMessageBox("用户名不能为空");
return;
}
try{
_RecordsetPtr pRecordset;
sql.Format("Select * From Wage Where 员工ID='%s' and 年份='%d' and 月份='%d'",
m_wID,m_Date.GetYear(),m_Date.GetMonth());
pRecordset=m_ado.GetRecordSet(sql);
if(pRecordset->adoEOF)
{
pRecordset->AddNew();
pRecordset->PutCollect("员工ID",_variant_t(m_wID));
pRecordset->PutCollect("年份",(_variant_t)(long)m_Date.GetYear());
pRecordset->PutCollect("月份",(_variant_t)(long)m_Date.GetMonth());
pRecordset->PutCollect("姓名",m_vName);
pRecordset->PutCollect("所属部门",m_vDepartment);
pRecordset->PutCollect("职位",m_vPosition);
}
_variant_t vMoney=pRecordset->GetCollect("计时工资");
CString tstr=(LPCTSTR)(_bstr_t)vMoney;
float tmoney=(float)atof(tstr);//原来Wage表中的计时工资
tstr=(LPCTSTR)(_bstr_t)oldmoney;
float toldmoney=(float)atof(tstr);//原来计时工资表中的应得金额
if (additem==1) tmoney+=m_Money;//添加新记录
if(additem==0) tmoney=tmoney-toldmoney+m_Money;//修改计时工资
if(additem==-1)tmoney-=m_Money;//删除记录
pRecordset->PutCollect("计时工资",(_variant_t)tmoney);
pRecordset->Update();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -