设为首页 加入收藏

TOP

3.9.5 用户管理界面的实现(2)
2013-10-07 14:52:53 来源: 作者: 【 】 浏览:61
Tags:3.9.5 用户 管理 面的 实现

3.9.5  用户管理界面的实现(2)

第4行代码实现打开用户信息表。

第8~17行代码实现列表框数据的显示,显示样式为"用户名+权限"。

当用户选中列表框某一行记录后,单击【注销用户】按钮,可实现对该用户的删除操作。按钮实现代码参考如下:

代码位置:见光盘中本章源代码的SYSDLG类。

  1. 1  void SYSDLG::OnDeluser()  
  2. 2  {  
  3. 3   if(m_list.GetCurSel()==-1)                          //如果没有选中  
  4. 4   {  
  5. 5       AfxMessageBox("请选择要删除的记录!");  
  6. 6       return;  
  7. 7   }  
  8. 8   else  
  9. 9   {  
  10. 10          if(MessageBox("确定要删除吗?","提醒!",MB_YESNO)==IDYES)  
  11. 11          {  
  12. 12              CString tempstr;  
  13. 13              _variant_t va;  
  14. 14              m_list.GetText(m_list.GetCurSel(),tempstr);     //获取列表框选项  
  15. 15              CString temp=tempstr.Left(tempstr.GetLength()-8);                                                                           //获取固定长度字符  
  16. 16              CString str;  
  17. 17              str.Format("delete from tb_operator where opername like'%s%%'",temp);                                                           //删除语句  
  18. 18              m_pRecordset =m_pConnection->Execute(_bstr_t(str),&va,adCmdText);                                                           //执行删除  
  19. 19              AfxMessageBox("删除成功!!");  
  20. 20              ShowData();                                 //在列表框中显示数据  
  21. 21          }  
  22. 22          else  
  23. 23              return;  
  24. 24      }  
  25. 25  }  

第3~7行代码实现判断用户是否选中列表框,GetCurSel()返回值为 1表示没有选中记录。

第10行代码实现提醒对话框显示,让用户确认删除。

第11~21行代码实现根据用户名来删除用户。其中,第20行代码实现列表框中用户的更新显示。

用户选中列表框某一行记录后,输入原密码、新密码及确认密码也可以实现修改密码。实现代码参考如下:

代码位置:见光盘中本章源代码的SYSDLG类。

  1. 1  void SYSDLG::OnModipass()  
  2. 2  {  
  3. 3   UpdateData();                                           //保存数据  
  4. 4   CString tempstr;  
  5. 5   CString temp;  
  6. 6   CString oldpass;  
  7. 7   if(m_list.GetCurSel()==-1)                          //如果没有选中  
  8. 8   {  
  9. 9       MessageBox("请选择要修改的记录!");  
  10. 10          return;  
  11. 11      }  
  12. 12      else  
  13. 13      {  
  14. 14          m_list.GetText(m_list.GetCurSel(),tempstr);         //获取列表框选项  
  15. 15          temp=tempstr.Left(tempstr.GetLength()-8);           //取固定长度字符  
  16. 16          _variant_t va;  
  17. 17          m_pRecordset =m_pConnection->Execute("select * from tb_operator  
  18. 18                                     order by opername",&va,adCmdText);                                                                       //执行排序操作  
  19. 19          while(!m_pRecordset->_EOF)                      //记录没移动到最后  
  20. 20          {  
  21. 21              CString str1 = ((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect ("opername"));  
  22. 22              CString str2 = ((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("operlevel"));  
  23. 23              str1.TrimRight();                               //去掉字符右边空格  
  24. 24              str2.TrimRight();  
  25. 25              if(str1==temp)                              //查找到当前用户  
  26. 26              {  
  27. 27                  UpdateData();  
  28. 28                  oldpass = ((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect   
  29.                     ("operpassword"));  
  30. 29                  oldpass.TrimRight();                        //去掉字符右边的空格  
  31. 30                  UpdateData(false);  
  32. 31                  break;  
  33. 32  
  34. 33              }  
  35. 34              m_pRecordset->MoveNext();                       //记录后移  
  36. 35          }  
  37. 36      }  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇7.7.1 地图信息模块功能分析 下一篇3.9.5 用户管理界面的实现(1)

评论

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