设为首页 加入收藏

TOP

3.8.4 用户管理模块
2013-10-07 14:28:43 来源: 作者: 【 】 浏览:70
Tags:3.8.4 用户 管理 模块

3.8.4  用户管理模块

用户管理模块的功能是对系统内的用户信息进行管理。具体实现流程如下。

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

 
图3-15  用户管理设计界面
(2) 双击对话框,创建一个新类CUserManageDlg,对应代码如下:
  1. class CUserManageDlg : public CDialog  
  2. {  
  3. // Construction  
  4. public:  
  5.     CUserManageDlg(CWnd* pParent = NULL);  
    // standard constructor  
  6.     _RecordsetPtr m_pRecordset;  
  7.     void RefushListBox();  

(3) 给"添加"按钮添加消息响应函数,该函数的功能是向系统内添加新的用户信息。具体实现代码如下:

  1. void CUserManageDlg::OnAdd()   
  2. {  
  3.     UpdateData();                   //数据的更新  
  4.     if(m_strUsers == "")            //条件的判断  
  5.     {  
  6.         MessageBox("请输入用户名!");  
  7.         return ;  
  8.     }  
  9.     if(m_strPwd1 == "")  
  10.     {  
  11.         MessageBox("请输入密码!");  
  12.         return ;  
  13.     }  
  14.     if(m_strPwd1 != m_strPwd2)  
  15.     {  
  16.         MessageBox("两次密码输入的不一致!");  
  17.         return ;  
  18.     }  
  19.     int nType = m_TyprCtrl.GetCurSel();//获取选中的索引  
  20.     CString strSQL;//定义字符串变量  
  21.     strSQL.Format("insert into users values ('%s', 
    '%s', %d)", m_strUsers, m_strPwd1, nType);  
  22.     try  
  23.     {  
  24.         theApp.m_pConnection->Execute((_bstr_t)strSQL,
    NULL, adCmdText);  
  25.     }  
  26.     catch(...)  
  27.     {  
  28.         MessageBox("用户名已经存在!");  
  29.         return ;  
  30.     }  
  31.     RefushListBox();  
  32.     OnClean();  
  33. }  

(4) 给"注销"按钮添加消息响应函数,该函数的功能是注销某登录用户的信息。具体实现代码如下:

  1. void CUserManageDlg::OnDel()   
  2. {  
  3.     UpdateData();           //数据的更新  
  4.     if(m_strUsers == "")  
  5.     {  
  6.         MessageBox("请选择一个用户!");  
  7.         return ;  
  8.     }  
  9.     CString strSQL;         //定义字符串变量  
  10.     strSQL.Format("delete from users where users = '%s'", m_strUsers);  
  11.     if(MessageBox("确定删除吗?", "注意", MB_YESNO) == IDYES)  
  12.     {  
  13.         try  
  14.         {  
  15.             theApp.m_pConnection->Execute((_bstr_t)
    strSQL, NULL, adCmdText);  
  16.         }  
  17.         CATCH_ERROR;  
  18.         RefushListBox();  
  19.         OnClean();  
  20.     }  
  21. }  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇3.8.7 用户登录模块 下一篇3.12 谈试用期的表现

评论

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