📄 jijiangongzi.cpp
字号:
//
//
/*************************************
文件名:JiJianGongZi.cpp
文件类型:implementation file
功能描述:对计件工资信息进行录入
创建人:张国
版本号:1.0
**************************************/
#include "stdafx.h"
#include "salarymanagement.h"
#include "JiJianGongZi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJiJianGongZi dialog
CJiJianGongZi::CJiJianGongZi(CWnd* pParent /*=NULL*/)
: CDialog(CJiJianGongZi::IDD, pParent)
{
//{{AFX_DATA_INIT(CJiJianGongZi)
m_ID = _T("");
m_money = 0.0f;
m_name = _T("");
m_Pname = _T("");
m_Pnum = 0;
m_Pprice = 0.0f;
m_radio = 0;
m_time = COleDateTime::GetCurrentTime();
m_findID = _T("");
m_findName = _T("");
//}}AFX_DATA_INIT
m_ado.OnInitADOConn();
}
CJiJianGongZi::~CJiJianGongZi()
{
m_ado.ExitConnect();
}
void CJiJianGongZi::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJiJianGongZi)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_Gonghao, m_ID);
DDX_Text(pDX, IDC_Money, m_money);
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_Pname, m_Pname);
DDX_Text(pDX, IDC_Pnum, m_Pnum);
DDX_Text(pDX, IDC_Pprice, m_Pprice);
DDX_Radio(pDX, IDC_RADIOFindID, m_radio);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_time);
DDX_Text(pDX, IDC_FindID, m_findID);
DDX_Text(pDX, IDC_FindName, m_findName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJiJianGongZi, CDialog)
//{{AFX_MSG_MAP(CJiJianGongZi)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_EN_KILLFOCUS(IDC_Gonghao, OnKillfocusGonghao)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
ON_BN_CLICKED(IDC_Computing, OnComputing)
ON_BN_CLICKED(IDC_DEL, OnDel)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_Find, OnFind)
ON_BN_CLICKED(IDC_RADIOFindID, OnRADIOFindID)
ON_BN_CLICKED(IDC_RADIOFindIName, OnRADIOFindIName)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJiJianGongZi message handlers
void CJiJianGongZi::OnCancel()
{
((CDialog*)this->GetParent())->EndDialog(IDCANCEL);
CDialog::OnCancel();
}
BOOL CJiJianGongZi::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_list.InsertColumn(6,"应得金额",LVCFMT_CENTER,100);
m_recordset=m_ado.GetRecordSet("Select * From Piecework");
LoadData();
return TRUE;
}
void CJiJianGongZi::OnSave()
{
UpdateData();
if(m_ID=="")
{
AfxMessageBox("请输入员工ID");
return;
}
try{
CString sql;
//SQL语句,看计件工资记录是否已经存在。是,则修改;否,则添加
sql.Format("Select * From Piecework Where 员工ID='%s' and 加工日期='%s'",
m_ID,m_time.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;
}
//录集不存在,将其添加入新行
else
{
m_recordset->AddNew();
m_recordset->PutCollect("加工日期",_variant_t(m_time.Format("%Y- %m- %d")));
m_recordset->PutCollect("员工ID",(_variant_t)m_ID);
}
m_recordset->PutCollect("姓名",(_variant_t)m_name);
m_recordset->PutCollect("产品名称",(_variant_t)m_Pname);
m_recordset->PutCollect("加工数量",(_variant_t)(long)m_Pnum);
m_recordset->PutCollect("加工单价",(_variant_t)m_Pprice);
m_recordset->PutCollect("应得金额",(_variant_t)m_money);
m_recordset->Update();
//将计时工资应得金额添加到Wage数据库中的计时工资下
SaveToWage();
//将数据库数据重新载入到列表控件中
m_recordset=m_ado.GetRecordSet("Select * From Piecework");
LoadData();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
//清除编辑框中的数据
clean();
UpdateData(FALSE);
}
/***************************************
函数类型:事件响应函数
功能描述:当失去员工ID编辑框中的焦点时,
检查该员工ID是否存在
***************************************/
void CJiJianGongZi::OnKillfocusGonghao()
{
// TODO: Add your control notification handler code here
UpdateData();
CString str;
try{
//从数据库中人事基本信息表中查询对应m_ID的员工姓名
str.Format("Select * From BasicInfomation Where 员工ID='%s'",m_ID);
m_recordset=m_ado.GetRecordSet(str);
//如果不存在,说明输入的m_ID有错,提示错误信息并返回
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 CJiJianGongZi::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
//获得鼠标点击的行号
int nItem=pNMListView->iItem;
CurrentSelect=nItem;
CString str1;
//将对应行中各列的数据反馈到编辑框和列表框控件上
str1=m_list.GetItemText(nItem,0);
m_time.ParseDateTime(str1);
m_ID=m_list.GetItemText(nItem,1);
m_name=m_list.GetItemText(nItem,2);
m_Pname=m_list.GetItemText(nItem,3);
str1=m_list.GetItemText(nItem,4);
m_Pnum=atoi(str1);
str1=m_list.GetItemText(nItem,5);
m_Pprice=(float)atof(str1);
str1=m_list.GetItemText(nItem,6);
m_money=(float)atof(str1);
UpdateData(FALSE);
*pResult = 0;
}
/*************************************************
函数类型:自定义函数
功能描述:将数据库中计件工资数据显示在列表控件上
**************************************************/
void CJiJianGongZi::LoadData()
{
//将数据显示在列表控件上
m_list.DeleteAllItems();
m_CurrentRow=0;
//执行SQL语句获得数据库中的所有记录
try{
while(!m_recordset->adoEOF)
{
m_list.InsertItem(m_CurrentRow,(_bstr_t)m_recordset->GetCollect("加工日期"));
m_list.SetItem(m_CurrentRow,1,1,(_bstr_t)m_recordset->GetCollect("员工ID"),NULL,0,0,0);
m_list.SetItem(m_CurrentRow,2,1,(_bstr_t)m_recordset->GetCollect("姓名"),NULL,0,0,0);
m_list.SetItem(m_CurrentRow,3,1,(_bstr_t)m_recordset->GetCollect("产品名称"),NULL,0,0,0);
m_list.SetItem(m_CurrentRow,4,1,(_bstr_t)m_recordset->GetCollect("加工数量"),NULL,0,0,0);
m_list.SetItem(m_CurrentRow,5,1,(_bstr_t)m_recordset->GetCollect("加工单价"),NULL,0,0,0);
m_list.SetItem(m_CurrentRow,6,1,(_bstr_t)m_recordset->GetCollect("应得金额"),NULL,0,0,0);
m_recordset->MoveNext();
m_CurrentRow++;
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
/**********************
函数类型:事件响应函数
功能描述:计算计时工资
**********************/
void CJiJianGongZi::OnComputing()
{
UpdateData();
m_money=m_Pnum*m_Pprice;
UpdateData(false);
}
/***********************
函数类型:事件响应函数
功能描述:删除所选记录
***********************/
void CJiJianGongZi::OnDel()
{
UpdateData();
if(m_list.GetSelectedCount()==0||CurrentSelect>=m_list.GetItemCount())
{
AfxMessageBox("请选择您要删除的记录!");
return;
}
if(IDNO==AfxMessageBox("您确定要删除该记录吗?",MB_YESNO))
return;
//删除Wage表中相应的记录
additem=-1;
SaveToWage();
try{
//执行删除
CString sql="";
sql.Format("Delete From Piecework Where 员工ID='%s' and 加工日期='%s'",
m_ID,m_time.Format("%Y- %m- %d"));
m_ado.ExecuteSQL(sql);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_list.DeleteItem(CurrentSelect);
clean();
UpdateData(FALSE);
}
void CJiJianGongZi::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
//获得鼠标点击的行号
int nItem=pNMListView->iItem;
if (nItem==-1)
{
clean();
UpdateData(false);
}
*pResult = 0;
}
/*********************
函数类型:自定义函数
功能描述:重置编辑框
*********************/
void CJiJianGongZi::clean()
{
//清除编辑框中的数据
m_ID="";
m_name="";
m_Pname="";
m_Pprice=0.0;
m_Pnum=0;
m_money=0.0;
m_findName="";
m_findID="";
}
/**************************************
函数类型:事件函数
功能描述:搜索对应条件下的计件工资记录
**************************************/
void CJiJianGongZi::OnFind()
{
UpdateData();
CString str;
try{
if (m_radio==0)
{
str.Format("Select * From Piecework 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 Piecework Where 姓名='%s'",m_findName);
m_recordset=m_ado.GetRecordSet(str);
if(m_recordset->adoEOF)
{
str.Format("员工%s不存在!!!",m_findName);
AfxMessageBox(str);
return;
}
}
LoadData();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
UpdateData(FALSE);
}
void CJiJianGongZi::OnRADIOFindID()
{
//按员工ID搜索时,清空按姓名搜索编辑框
GetDlgItem(IDC_FindID)->EnableWindow(TRUE);
GetDlgItem(IDC_FindName)->EnableWindow(FALSE);
m_radio=0;
m_findName="";
UpdateData(FALSE);
}
void CJiJianGongZi::OnRADIOFindIName()
{
//按姓名搜索时,清空按员工ID搜索编辑框
GetDlgItem(IDC_FindID)->EnableWindow(FALSE);
GetDlgItem(IDC_FindName)->EnableWindow(TRUE);
m_radio=1;
m_findID="";
UpdateData(FALSE);
}
/********************************************
函数类型:自定义函数
功能描述:将计时工资信息写入到Wage数据库表中
********************************************/
void CJiJianGongZi::SaveToWage()
{
UpdateData();
CString sql;
try{
_RecordsetPtr pRecordset;
sql.Format("Select * From Wage Where 员工ID='%s' and 年份='%d' and 月份='%d'",
m_ID,m_time.GetYear(),m_time.GetMonth());
pRecordset=m_ado.GetRecordSet(sql);
if(pRecordset->adoEOF)
{
pRecordset->AddNew();
pRecordset->PutCollect("员工ID",_variant_t(m_ID));
pRecordset->PutCollect("年份",(_variant_t)(long)m_time.GetYear());
pRecordset->PutCollect("月份",(_variant_t)(long)m_time.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 + -