设为首页 加入收藏

TOP

3.8.3 设计工资模块
2013-10-07 14:27:46 来源: 作者: 【 】 浏览:53
Tags:3.8.3 设计 工资 模块

3.8.3  设计工资模块

2006年10月22日,上午

今天开始进行工资模块的设计工作。此模块主要实现对员工工资的各项组成部分所占比例大小、基本信息进行设置,实现员工工资月统计汇总计算。我是这样想的:员工工资的计算结果保存在相应的数据表中,当涉及工资的计算时,只需从表中读取对应数据即可。另外,也实现了根据员工的编号、月份、所在部门等来查询员工的详细工资情况。

1. 工资计算

(1) 创建一个对话框,资源ID为IDD_WAGE_CAL_DLG,添加的控件如图3-13所示。

 
图3-13  工资管理界面
(2) 双击对话框,创建一个新类CWageDlg,对应代码如下:
  1. class CWageDlg : public CDialog  
  2. {  
  3. // Construction  
  4. public:  
  5.     CWageDlg(CWnd* pParent = NULL);   // standard constructor  
  6.     _RecordsetPtr m_pRecordset;  
  7.     _RecordsetPtr m_pRecordset1;  
  8.     void ShowListData(const CString& sql);  

(3) 给"确定"按钮添加消息响应函数,该函数的功能是显示计算后的工资。具体实现代码如下:

  1. void CWageCalDlg::OnSure()   
  2. {  
  3.     UpdateData();                   //数据的更新  
  4.     CString strSQL;                 //定义字符串变量  
  5.     strSQL.Format("update wagecal set chuchai = %d,
    bingjia = %d, shijia = %d, pingshi = %d, shuangxiu = %d, fading = %d",   
  6.         m_chuchai, m_bingjia, m_shijia, m_pingshi, 
    m_shuangxiu, m_fading);  
  7.     try  
  8.     {  
  9.         m_pRecordset = theApp.m_pConnection->Execute
    ((_bstr_t)strSQL, NULL, adCmdText);  
  10.         MessageBox("设置成功!");//执行SQL语句  
  11.     }  
  12.     CATCH_ERROR;  
  13. }  

2. 工资统计

(1) 创建一个对话框资源ID为IDD_WAGE_DLG,添加的控件如图3-14所示。

 
图3-14  工资统计设计界面

(2) 双击对话框,创建一个新类CWageDlg,对应代码如下:

  1. class CWageCalDlg : public CDialog  
  2. {  
  3. // Construction  
  4. public:  
  5.     CWageCalDlg(CWnd* pParent = NULL);   // standard constructor  
  6.     _RecordsetPtr m_pRecordset;  

(3) 给"查询"按钮添加消息响应函数,该函数的功能是查询某员工的工资信息。具体实现代码如下:

  1. void CWageDlg::OnButton1()   
  2. {  
  3.     UpdateData();                     //数据的更新  
  4.     CString strSQL, strMonth;  
  5.     int nIndex = m_Month.GetCurSel();//月份的获取  
  6.     m_Month.GetLBText(nIndex, strMonth);  
  7.     strSQL.Format("select * from temp where id = 
    %s and 
    ym = '%s'", m_strID, strMonth);  
  8.     ShowListData(strSQL);  
  9. }  

(4) 工资计算功能由CWageDlg实现的,具体实现代码如下:

  1. BOOL CWageDlg::OnInitDialog()   
  2. {  
  3.     CDialog::OnInitDialog();  
  4.     m_pRecordset.CreateInstance("ADODB.Recordset");   
  5.     m_pRecordset1.CreateInstance("ADODB.Recordset");      
  6.     m_ListCrtl.SetExtendedStyle(LVS_EX_GRIDLINES 
    | LVS_EX_FULLROWSELECT );//风格的设定。整行选择  
  7.     m_ListCrtl.InsertColumn(0, "员工ID", LVCFMT_CENTER, 60);  
  8.     m_ListCrtl.InsertColumn(1, "月薪(元)", LVCFMT_CENTER, 60);  
  9.     m_ListCrtl.InsertColumn(2, "月份", LVCFMT_CENTER, 60);  
  10.     m_ListCrtl.InsertColumn(3, "出差(天)", LVCFMT_CENTER, 60);  
  11.     m_ListCrtl.InsertColumn(4, "病假(天)", LVCFMT_CENTER, 60);  
  12.     m_ListCrtl.InsertColumn(5, "事假(天)", LVCFMT_CENTER, 60);  
  13.     m_ListCrtl.InsertColumn(6, "平时加班(小时)", LVCFMT_CENTER, 100);  
  14.     m_ListCrtl.InsertColumn(7, "双休日加班(小时)", LVCFMT_CENTER, 120);  
  15.     m_ListCrtl.InsertColumn(8, "法定假日加班(小时)", LVCFMT_CENTER, 120);  
  16.     m_ListCrtl.InsertColumn(9, "应发工资(元)", LVCFMT_CENTER, 100);  
  17.     CString strSQL; //创建临时表  
  18.     strSQL.Format("create table temp (id int, wage
    int, ym varchar(20), chuchai int, bingjia int, shijia
    int, pingshi int, shuangxiu int, fading int, waged int)");  
  19.     try  
  20.     {  
  21.         theApp.m_pConnection->Execute((_bstr_t)strSQL,
    NULL, adCmdText);  
  22.     }  
  23.     catch(...)  
  24.     {  
  25.         strSQL.Format("drop table temp");  
  26.         theApp.m_pConnection->Execute((_bstr_t)strSQL, 
    NULL, adCmdText);  
  27.         strSQL.Format("create table temp (id int, wage 
    int, ym varchar(20), chuchai int, bingjia int, shijia
    int, pingshi int, shuangxiu int, fading int, waged int)");  
  28.         theApp.m_pConnection->Execute((_bstr_t)strSQL,
    NULL, adCmdText);  
  29.     }  
  30.     try//临时表中添加数据  
  31.     {  
  32.         CString SQL[9];  
  33.         strSQL = "insert into temp (id) select id from emp ;";  
  34.         //从员工表中读取员工ID  
  35.         SQL[0] = "update temp set wage = 0ym =
    2008-01, chuchai = 0bingjia = 0shijia = 0
    pingshi = 0shuangxiu = 0fading = 0waged = 0;";  
  36.         //月薪的更新  
  37.         SQL[1] = "update temp set wage = wageinfo.
    wage from wageinfo where 
    temp.id = wageinfo.id;";  
  38.         //从考勤表中读取月份  
  39.         SQL[2] = "update temp set ym = checkinfo.ym 
    from checkinfo where 
    temp.id = checkinfo.id;";  
  40.         //根据月份从考勤表中统计考勤信息  
  41.         SQL[3] = "update temp set chuchai = (select 
    count(*) from checkinfo where 
    temp.ym = checkinfo.ym
    and 
    checkinfo.chuchai = '是' and temp.id = checkinfo.id);";  
  42.         SQL[4] = "update temp set bingjia = (select 
    count(*) from checkinfo where 
    temp.ym = checkinfo.ym
    and 
    checkinfo.bingjia = '是' and temp.id = checkinfo.id);";  
  43.         SQL[5] = "update temp set shijia = (select 
    count(*) from checkinfo where 
    temp.ym = checkinfo.ym 
    and 
    checkinfo.shijia = '是' and temp.id = checkinfo.id);";  
  44.         SQL[6] = "update temp set pingshi = (select 
    sum(ot1) from checkinfo where 
    temp.ym = checkinfo.ym 
    and 
    temp.id = checkinfo.id) ;";  
  45.         SQL[7] = "update temp set shuangxiu = (select 
    sum(ot2) from checkinfo where 
    temp.ym = checkinfo.ym 
    and 
    temp.id = checkinfo.id) ;";  
  46.         SQL[8] = "update temp set fading = (select 
    sum(ot3) from checkinfo where 
    temp.ym = checkinfo.ym 
    and 
    temp.id = checkinfo.id) ;";  
  47.         for(int i = 0; i < 9; i++)  
  48.             strSQL += SQL[i];  
  49.         theApp.m_pConnection->Execute((_bstr_t)strSQL, 
    NULL, adCmdText);  
  50.     }  
  51.     CATCH_ERROR;  
  52.     float chuchai, bingjia, shijia, pingshi, shuangxiu, fading;  
  53.     //读取工资的计算公式  
  54.     _variant_t va;  
  55.     strSQL = "select * from wagecal";  
  56.     try  
  57.     {  
  58.         m_pRecordset = theApp.m_pConnection->Execute
    ((_bstr_t)strSQL, NULL, adCmdText);  
  59.         va = m_pRecordset->GetCollect(_variant_t((long)0));  
  60.         chuchai = va.iVal;  
  61.         va = m_pRecordset->GetCollect(_variant_t((long)1));  
  62.         bingjia = va.iVal;  
  63.         va = m_pRecordset->GetCollect(_variant_t((long)2));  
  64.         shijia = va.iVal;  
  65.         va = m_pRecordset->GetCollect(_variant_t((long)3));  
  66.         pingshi = va.iVal;  
  67.         va = m_pRecordset->GetCollect(_variant_t((long)4));  
  68.         shuangxiu = va.iVal;  
  69.         va = m_pRecordset->GetCollect(_variant_t((long)5));  
  70.         fading = va.iVal;  
  71.     }  
  72.     CATCH_ERROR;  
  73.     strSQL.Format("update temp set waged = (wage / 23 
    * chuchai * %f / 100 + wage / 23 * bingjia * %f / 100 
    + wage / 23 * shijia * %f / 100 + wage / 23 / 8 * 
    pingshi * %f / 100 + wage / 23 / 8 * shuangxiu * %f / 
    100 + wage / 23 / 8 * fading * %f / 100 + wage / 23 *
    (23 - chuchai - bingjia - shijia))",  
  74.         chuchai, bingjia, shijia, pingshi, shuangxiu, fading);  
  75.     try//计算员工的工资  
  76.     {  
  77.         m_pRecordset = theApp.m_pConnection->Execute
    ((_bstr_t)strSQL, NULL, adCmdText);  
  78.     }  
  79.     CATCH_ERROR;  
  80.     strSQL = "select * from temp";//从temp表中查询数据填充在list中  
  81.     ShowListData(strSQL);  
  82.     strSQL = "select ym from temp group by ym";//填充月份combobox  
  83.     try  
  84.     {  
  85.         m_pRecordset = theApp.m_pConnection->Execute
    ((_bstr_t)strSQL, NULL, adCmdText);  
  86.         while(!m_pRecordset->adoEOF)  
  87.         {  
  88.             m_Month.AddString((char*)_bstr_t(m_
    pRecordset-
    >GetCollect(_variant_t((long)0))));  
  89.             m_pRecordset->MoveNext();  
  90.         }  
  91.     }  
  92.     CATCH_ERROR;  
  93.     m_Month.SetCurSel(0);  
  94.     return TRUE;  // return TRUE unless you set the focus to a control  
  95.                   // EXCEPTION: OCX Property Pages should return FALSE  
  96. }  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇3.8.1 设计员工模块(1) 下一篇3.8.2 考勤模块(3)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: