设为首页 加入收藏

TOP

3.8.2 考勤模块(3)
2013-10-07 14:27:43 来源: 作者: 【 】 浏览:58
Tags:3.8.2 考勤 模块

3.8.2  考勤模块(3)

通过上述代码为初始化的设置,其中设定了列表控件的标题和风格,通过InsertItem( )函数设置列表控件第1列的数据、SetItemText()函数设置对其他列的数据。

(3) 通过类向导为列表控件添加LVN_ITEMCHANGED消息响应函数。OnItemchangedList1( )函数代码如下:

  1. void CCheckInfoDlg::OnItemchangedList1(NMHDR*   
  2.      pNMHDR, LRESULT* pResult)    
  3.  {    
  4.   NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;    
  5.   int nSelect = pNMListView->iItem;                  
  6.      //获取列表控件行索引    
  7.   m_strID = m_ListCrtl.GetItemText(nSelect, 1);        
  8.      //获取列表控件文本    
  9.   CString strDate = m_ListCrtl.GetItemText(nSelect, 0);    
  10.   int nIndex = strDate.Find('-');                     
  11.      //查找字符'-'的位置    
  12.   CString str = strDate.Left(nIndex);                 
  13.      //取索引左边的字符串    
  14.   int Year = atoi(str);                              
  15.      //字符型转换为整型    
  16.      strDatestrDate = strDate.Right(strDate.GetLength()   
  17.      - nIndex - 1);    
  18.      nIndex = strDate.Find('-');    
  19.      str = strDate.Left(nIndex);    
  20.      int Month = atoi(str);    
  21.      strDatestrDate = strDate.Right(strDate.GetLength()   
  22.      - nIndex - 1);    
  23.      int Day = atoi(strDate);    
  24.      m_Date.SetDate(Year, Month, Day);             
  25.      //设置时间    
  26.     UpdateData(FALSE);    
  27.      *pResult = 0;    
  28.  }  

在上述代码中,通过鼠标单击列表控件的位置获取员工的ID与时间,将数据显示在编辑框中,其中涉及DateTimePicker控件时间的设置。通过字符串的截取,把年月日放在三个整型变量中,再通过函数SetDate( )设置DateTimePicker控件的时间。

(4) 自定义函数ShowListData( )用来显示列表控件中的数据,代码如下:

  1. void CCheckInfoDlg::ShowListData(const CString& sql)    
  2.   {    
  3.    m_ListCrtl.DeleteAllItems();                    
  4.       //删除列表控件所有项    
  5.    try    
  6.    {    
  7.        m_pRecordset = theApp.m_pConnection->Execute  
  8.       ((_bstr_t)sql, NULL, adCmdText);    
  9.        int i = 0;    
  10.        while(!m_pRecordset->adoEOF)            
  11.       //如果记录没有到末尾    
  12.        {    
  13.             m_ListCrtl.InsertItem(i,(char*)_bstr_t  
  14.            (m_pRecordset->GetCollect (_variant_t((long)0))));    
  15.            for(int j = 1; j < 9; j++)    
  16.            m_ListCrtl.SetItemText(i,j,(char*)_bstr_t  
  17.            (m_pRecordset->GetCollect (_variant_t((long)j))));    
  18.            i++;    
  19.             m_pRecordset->MoveNext();               
  20.             //移动到下一条记录    
  21.           }    
  22.       }    
  23.       CATCH_ERROR;    
  24.   }  

在上述代码中,函数ShowListData( )的参数为SQL语句,根据SQL语句查询相应的数据,将数据插入到列表控件中。将参数设定为SQL语句可以满足从不同的表中查询数据添加到一个列表控件中。给"查询"按钮添加消息响应函数,完成数据的查询,代码如下:

  1. void CCheckInfoDlg::OnIndex()    
  2.  {    
  3.   UpdateData();                          
  4.      //数据的获取    
  5.   if(m_strID == "")                         
  6.      //条件的判断    
  7.   {    
  8.       MessageBox("请出入查询条件!");    
  9.       return ;    
  10.   }    
  11.   CString strSQL, strDate;                       
  12.      //定义字符串变量    
  13.      strDate.Format("%d-%d-%d", m_Date.GetYear(),   
  14.      m_Date.GetMonth(), m_Date. GetDay());    
  15.      strSQL.Format("select * from checkinfo where   
  16.      id = %s and date = '%s'", m_strID, strDate);    
  17.      ShowListData(strSQL);                         
  18.      //显示列表控件中的数据    
  19.  }  

在上述代码中,通过借助Format( )函数构造查询的SQL语句,将构造好的SQL语句通过参数的形式传递给ShowListData( ),将数据添加到列表控件中。

(5) 给"删除"按钮添加消息响应函数,该函数的功能是完成考勤记录的删除。具体实现代码如下所示:

  1. void CCheckInfoDlg::OnDel()    
  2.   {    
  3.    if(m_strID == "")                           
  4.       //条件的判断    
  5.    {    
  6.        MessageBox("请选择一条记录!");        
  7.       //信息提示    
  8.        return ;    
  9.    }    
  10.    if(MessageBox("确定删除吗?", "注意", MB_YESNO) == IDYES)    
  11.    {    
  12.           CString strSQL, strDate;             
  13.       //定义字符串变量    
  14.          strDate.Format("%d-%d-%d", m_Date.GetYear(),  
  15.       m_Date.GetMonth(), m_Date. GetDay());    
  16.           strSQL.Format("delete from checkinfo where   
  17.       id = %s and date = '%s'", m_strID, strDate);    
  18.           try    
  19.           {                                        
  20.           //执行删除记录操作    
  21.               theApp.m_pConnection->Execute  
  22.       ((_bstr_t)strSQL, NULL, adCmdText);    
  23.                 ShowListData("select * from checkinfo");    
  24.           //列表更新显示    
  25.           }    
  26.           CATCH_ERROR;    
  27.       }    
  28.   }  

在上述代码中,Format( )函数构造了删除SQL语句,通过Execute( )函数执行SQL语句删除选择的数据,重新构造查询的SQL语句将所有数据显示在列表控件中。

2006年10月21日,深夜

今天考勤模块的工作全部完成。考勤管理模块并没有涉及复杂的技术,对考勤的管理是通过对相应的数据表的插入数据来实现的。考勤的统计与查询也是通过SQL语句来实现的,具体是执行"insert into 表名 values(值)"语句实现插入操作。该界面采用了一组单选按钮来实现考勤人员考勤的各个环节设定,而具体缺勤情况则是通过复选框实现的。总结完毕之后,我决定早点休息,为接下来的工资模块做准备。

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

评论

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