XEIM 用户管理源代码

// xiemUsersDlg.cpp : implementation file
//

#include "stdafx.h"
#include "xiemUsers.h"
#include "xiemUsersDlg.h"
#include "XEIM_Add_Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// 参考飞鸽传书:http://www.freeeim.com

/
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
 CAboutDlg();

// Dialog Data
 //{{AFX_DATA(CAboutDlg)
 enum { IDD = IDD_ABOUTBOX };
 //}}AFX_DATA

 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CAboutDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL

// Implementation
protected:
 //{{AFX_MSG(CAboutDlg)
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
 //{{AFX_DATA_INIT(CAboutDlg)
 //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CAboutDlg)
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 //{{AFX_MSG_MAP(CAboutDlg)
  // No message handlers
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CXiemUsersDlg dialog

CXiemUsersDlg::CXiemUsersDlg(CWnd* pParent /*=NULL*/)
 : CDialog(CXiemUsersDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CXiemUsersDlg)
  // NOTE: the ClassWizard will add member initialization here
 //}}AFX_DATA_INIT
 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CXiemUsersDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CXiemUsersDlg)
 DDX_Control(pDX, IDC_LIST1, m_lcUserList);
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CXiemUsersDlg, CDialog)
 //{{AFX_MSG_MAP(CXiemUsersDlg)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_BN_CLICKED(IDC_BTNADD, OnBtnadd)
 ON_NOTIFY(LVN_GETDISPINFO, IDC_LIST1, OnGetdispinfoList1)
 ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnRclickList1)
 ON_COMMAND(ID_MENU_DELETE, OnMenuDelete)
 ON_COMMAND(ID_MENU_MODIFY, OnMenuModify)
 ON_COMMAND(ID_MENUADDNEW, OnMenuaddnew)
 ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CXiemUsersDlg message handlers

BOOL CXiemUsersDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 // Add "About..." menu item to system menu.

 // IDM_ABOUTBOX must be in the system command range.
 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 ASSERT(IDM_ABOUTBOX < 0xF000);

 CMenu* pSysMenu = GetSystemMenu(FALSE);
 if (pSysMenu != NULL)
 {
  CString strAboutMenu;
  strAboutMenu.LoadString(IDS_ABOUTBOX);
  if (!strAboutMenu.IsEmpty())
  {
   pSysMenu->AppendMenu(MF_SEPARATOR);
   pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  }
 }

 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE);   // Set big icon
 SetIcon(m_hIcon, FALSE);  // Set small icon

 // TODO: Add extra initialization here
 UI_InitList();
 UI_InitReportHeader();
 if (m_xUser.IsConnected())
 {
  AddLog("已连接服务器!/r/n");
  m_xUser.ReadUsers();
 }

 return TRUE;  // return TRUE  unless you set the focus to a control
}

void CXiemUsersDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
 {
  CAboutDlg dlgAbout;
  dlgAbout.DoModal();
 }
 else
 {
  CDialog::OnSysCommand(nID, lParam);
 }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CXiemUsersDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting

  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CDialog::OnPaint();
 }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CXiemUsersDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;
}

void CXiemUsersDlg::OnBtnadd()
{
 // TODO: Add your control notification handler code here
/* if (m_xUser.SaveUser())
  AddLog("用户添加成功。/r/n");
 SetDlgItemText(IDC_EDIT1, "");*/
 XEIM_Add_Dlg dlg;
 if (IDOK == dlg.DoModal())
 {
  if (m_xUser.SaveUser(dlg.m_userID, dlg.m_password, dlg.m_group, dlg.m_display))
  {
   AddUserToList(dlg.m_userID, dlg.m_password, dlg.m_group, dlg.m_display);
  }
 }
}

void CXiemUsersDlg::UI_InitReportHeader()
{
 // Initial extended style for the list control on this dialog
 DWORD dwStyle = m_lcUserList.GetExtendedStyle();
 dwStyle |= LVS_EX_FULLROWSELECT;
 m_lcUserList.SetExtendedStyle(dwStyle);

 m_lcUserList.InsertColumn(0, "ID", LVCFMT_LEFT, 88);
 m_lcUserList.InsertColumn(1, "用户名", LVCFMT_LEFT, 88);
 m_lcUserList.InsertColumn(2, "昵称", LVCFMT_LEFT, 88);
 m_lcUserList.InsertColumn(3, "密码", LVCFMT_LEFT, 55);
 m_lcUserList.InsertColumn(7, "版本", LVCFMT_LEFT, 80);
 m_lcUserList.InsertColumn(8, "状态", LVCFMT_LEFT, 80);
}


void CXiemUsersDlg::AddLog(const char *szLog)
{
 CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT5);
 pEdit->SetSel(-1); // 光标定位到尾部
 pEdit->ReplaceSel(szLog);
 pEdit->PostMessage(WM_VSCROLL, SB_BOTTOM); // 滚动到光标*/
}

void CXiemUsersDlg::UI_InitList()
{
 // *****************************************************************
 // 用户 UI 初始化设置
 // *****************************************************************
 // 设置在线用户列表------------------------------------------------------------------
 CBitmap bm;
 m_ilUser.Create (16, 16, ILC_COLOR24 | ILC_MASK , 5,5);
 bm.LoadBitmap(IDB_BITMAP1);
 m_ilUser.Add(& bm, RGB(255,0,255));
 m_lcUserList.SetImageList(& m_ilUser, LVSIL_SMALL);

 // Initial extended style for the list control on this dialog
 DWORD dwStyle = m_lcUserList.GetExtendedStyle();
 dwStyle |= LVS_EX_FULLROWSELECT;
 m_lcUserList.SetExtendedStyle(dwStyle);
}

void CXiemUsersDlg::OnGetdispinfoList1(NMHDR* pnmhdr, LRESULT* pResult)
{
 LV_DISPINFO* pdi = (LV_DISPINFO *) pnmhdr;
 // Fill in the LV_ITEM structure with the image info.
 // When an item is selected, the image is set to the first
 // image (the new bitmap on the toolbar).
 // When it is not selected, the image index is equal to the
 // item number (that is, 0=new, 1=open, 2=save, and so on.)
 CString str;
 str = m_lcUserList.GetItemText(pdi->item.iItem, 3);
 if (strcmp((LPCTSTR)str, "离线"))
  pdi->item.iImage = 4;
 else
  pdi->item.iImage = 3;

 *pResult = 0;
}

void CXiemUsersDlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here
 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
 CPoint pt(pNMListView->ptAction);

 CMenu menu;
 int nID;

 POINT p;
 p.x = pt.x;
 p.y = pt.y;

 char szUID[256];
 m_lcUserList.GetItemText(pNMListView->iItem, 1, szUID, 256);

 char szUStatus[16];
 m_lcUserList.GetItemText(pNMListView->iItem, 3, szUStatus, 16);

 POSITION pos = m_lcUserList.GetFirstSelectedItemPosition();
 if (pos != NULL)     //判断是否选种了某一行
 {
  menu.LoadMenu(IDM_LISTCTRL);    // our context menu
  CMenu* pContextMenu = menu.GetSubMenu(0);
  if (! strcmp(szUStatus, "在线"))
   pContextMenu->EnableMenuItem(1, MF_BYPOSITION|MF_GRAYED);

  ::ClientToScreen(pNMHDR->hwndFrom, &p);
  nID = pContextMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
  p.x, p.y, this);
 }
 else
 {
  menu.LoadMenu(IDM_LISTAddNEW);    // our context menu
  CMenu* pContextMenu = menu.GetSubMenu(0);

  ::ClientToScreen(pNMHDR->hwndFrom, &p);
  nID = pContextMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
  p.x, p.y, this);
 }

 switch (nID)
 {
 case ID_MENUADDNEW:     // 添加用户
  OnMenuaddnew();
  break;

 case ID_MENU_MODIFY:    // 修改用户
  OnDblclkList1(pNMHDR, pResult);
  break;

 case ID_MENU_DELETE:    // 删除用户
  {
   char *sql="DELETE FROM userinfo WHERE uid='%s'";
   char szAlert[272];
   CString strSQL;
   strSQL.Format(sql, szUID);
   sprintf(szAlert, "确定要删除用户 %s 吗?", szUID);
   if (IDYES == ::MessageBox(m_hWnd, szAlert, "删除用户", MB_YESNO|MB_ICONQUESTION))
   {
//    try
//    {
//     _variant_t vAffected;
//     m_pConn->CursorLocation = adUseClient;
//     m_pConn->Execute((LPCTSTR)strSQL, &vAffected, adExecuteNoRecords);
//    }
//    catch(_com_error e)
//    {
//     MessageBox(e.Description());
//    }
    m_lcUserList.DeleteItem(pNMListView->iItem); 
//    list<XUserDetail>::iterator iUserDetail =
//     find(m_listUserDetail.begin(), m_listUserDetail.end(), strlwr(szUID));
//    m_listUserDetail.remove(*iUserDetail);
   }
  }
  break; // End 删除用户
 }
 // Now, based on the nID value, decide what to do with the menu selection
 // The menu is a temporary MFC object, no need to delete it.
 *pResult = 0;
}

void CXiemUsersDlg::OnMenuDelete()
{
 // TODO: Add your command handler code here
 
}

void CXiemUsersDlg::OnMenuModify()
{
 // TODO: Add your command handler code here
 
}

void CXiemUsersDlg::OnMenuaddnew()
{
 // TODO: Add your command handler code here
 
}

void CXiemUsersDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here
 POSITION pos = m_lcUserList.GetFirstSelectedItemPosition();

 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

 if (NULL != pos)
 {
  char szUID[256];
  m_lcUserList.GetItemText(pNMListView->iItem, 1, szUID, 256);

  list<XUserDetail>::iterator iUserDetail =
     find(m_listUserDetail.begin(), m_listUserDetail.end(), strlwr(szUID));

  // 打开修改对话框
  CXUserEditorDlg dlg;
  dlg.SetData((*iUserDetail));
  CString strMobile;
  GetUIDMobileNUM((*iUserDetail).GetUID(), strMobile);
  dlg.SetMobile(strMobile);
 // AfxMessageBox(strMobile);
  if (IDOK == dlg.DoModal())
  {
   m_lcUserList.SetItemText(pNMListView->iItem, 0, dlg.m_strNickName);
   m_lcUserList.SetItemText(pNMListView->iItem, 2, dlg.m_strPassword);
   m_lcUserList.SetItemText(pNMListView->iItem, 4, dlg.m_strGroup);

   // 更新内存中的用户列表
   list<XUserDetail>::iterator iUserDetail =
    find(m_listUserDetail.begin(), m_listUserDetail.end(), strlwr(szUID));

   iUserDetail->SetUNickName(dlg.m_strNickName);
   iUserDetail->SetUPassword(dlg.m_strPassword);
   iUserDetail->SetUGroup(dlg.m_strGroup);
  }
 }
 *pResult = 0;
}

void CXiemUsersDlg::AddUserToList(LPCTSTR szID, LPCTSTR szPW, LPCTSTR szGP, LPCTSTR szNN)
{
 LVITEM lvi;
 int nIdx;

 lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
 lvi.iItem = 0xff;
 lvi.iSubItem = 0;
 lvi.pszText = (char*)szID;
 lvi.iImage = I_IMAGECALLBACK;  // There are 8 images in the image list

 nIdx = m_lcUserList.InsertItem(&lvi);

 m_lcUserList.SetItemText(nIdx, 1, szID);
 m_lcUserList.SetItemText(nIdx, 2, szNN);
 m_lcUserList.SetItemText(nIdx, 3, szPW);
 m_lcUserList.SetItemText(nIdx, 6, "NULL");
 m_lcUserList.SetItemText(nIdx, 7, "NULL");
 m_lcUserList.SetItemText(nIdx, 8, "NULL");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通用权限管理框架源码 2013-5-15更新功能: 1、菜单导航管理 2、操作按钮 3、角色管理 4、部门管理 5、用户管理用户权限) 6、用户管理(设置成员,用户组权限) 7、系统配置(动态配置系统参数) 8、附加属性(自定义属性) 9、系统日志(异常记录) 10、数据库备份/还原 11、资源管理,(动态数据库) 12、个人信息(基本信息,附加信息,用户角色,拥有权限) 13、首页快捷 14、数据回收站(业务功能删除过数据,全部保留在回收站) 15、系统个性化设置(切换菜单导航) 2012-9-10更新内容: 系统UI,给人感觉非常好,体积小巧,速度快 该源码是适用用于应用系统后台模块的管理(可扩展至支持集中化的权限管理平台), 0.支持N级菜单导航,菜单显示方式支持目前支持2种模式分别:菜单(无限级),横向(2级) 1.动态切换皮肤,目前有两狂UI 蓝色,咖啡色 2.表单验证,文本框高亮起来 3.可以动态分配权限按钮,分配角色权限,目录结构,栏目的链接都可以修改。权限管理非常灵活, 4.可以隐藏左侧导航栏,打开左侧导航栏,默认是打开,table表格都自应大小的 5.动态创建数据表,删除用户表,点击数据 表 可以查询字段信息 6.可以直接执行sql脚本 7.兼容 IE6,7,8,9 /Firefox /Google Chrome 这些浏览器都测试过 8.批量删除,自定义复选框样式,可以全选/反选 9.角色分级,集团和分公司的关系 10.权限 横向就是业务部分,具体负责哪块业务,纵向是级别 11.动态报表设置,并且可以导出Excel 12.登陆日记,操作日记,异常日记 13.海量批量删除数据库,调用公共存储过程,参数,表明,主键 特点: UI:传统html css,美观 漂亮 大方 实用 js框架:jquery 系统大部分使用AJAX操作。大大提高了用户体验 功能描述: 1.支持N级菜单导航,菜单显示方式支持目前支持2种模式分别: 菜单(无限级),横向(2级) 2.表单验证,文本框高亮起来 3.可以动态分配权限按钮,分配角色权限,目录结构,栏目的链接都可以修改。 4.可以隐藏左侧导航栏,打开左侧导航栏,默认是打开,table表格都自应大小的 5.动态创建数据表,删除用户表,点击数据 表 可以查询字段信息 6.可以直接执行sql脚本
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值