C#winform权限管理系统完整源码下载(含数据库)【实例截图】
⽂件:(访问密码:551685)
【核⼼代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IBLL = CodingMouse.CMCSharpSDK.IBLL;
using BLLFactory = CodingMouse.CMCSharpSDK.BLLFactory;
using Model = CodingMouse.CMCSharpSDK.Model;
using Common = CodingMouse.CMCSharpSDK.UI.Common;
namespace CodingMouse.CMCSharpSDK.UI.Forms
{
///
/// 权限管理界⾯
///
public partial class frmRightsManager : Form
{
#region Private Members
MenuStrip _msMain = null;
/
//
/// 主界⾯被管理的菜单对象
///
internal MenuStrip MsMain
{
get { return _msMain; }
frmMain _frmMain = null;
///
/// 主界⾯对象
///
public frmMain FrmMain
{
get { return _frmMain; }
set { _frmMain = value; }
}
///
/// 权限菜单界⾯管理类对象
///
Common.RightsMenuUIManager _rmuManager = null;
///
/// 权限菜单数据管理类对象
///
Common.RightsMenuDataManager _rmdManager = null; Model.Operator _currentOperator = null;
///
/// 保存当前登录的操作员对象
///
internal Model.Operator CurrentOperator
{
get { return _currentOperator; }
set { _currentOperator = value; }
}
Dictionary<string, Model.Operator> _operatorCollection = null; ///
/// 当前加载的所有操作员实体集合
/
//
internal Dictionary<string, Model.Operator> OperatorCollection {
get { return _operatorCollection; }
set { _operatorCollection = value; }
}
bool _isRelatingChooseCells = true;
///
/// 是否启⽤数据视图关联选择
///
internal bool IsRelatingChooseCells
{
get { return _isRelatingChooseCells; }
set { _isRelatingChooseCells = value; }
}
///
/// 是否启⽤树视图⼦节点关联选择
///
bool _isCheckedChildTreeNode = true;
///
/// 保存上⼀次被选中的操作员列表⾏
///
DataGridViewRow _dgvOldSelectedRow = null;
/
//
bool _rightsViewIsChecked = false;
#endregion
#region Public Methods
/// <summary>
/// 带参构造
/// </summary>
/// <param name="msMain">主界⾯待管理的菜单对象</param>
/// <param name="frmMain">主界⾯对象</param>
/// <param name="currentOperator">当前登录操作员对象</param>
public frmRightsManager(MenuStrip msMain, frmMain frmMain, Model.Operator currentOperator)    {
/
/ 构建设计器控件
InitializeComponent();
// 保存菜单对象
MsMain = msMain;
// 保存主界⾯对象
FrmMain = frmMain;
// 保存当前登录操作员对象
CurrentOperator = currentOperator;
// 创建权限菜单界⾯管理类实例
_rmuManager = new Common.RightsMenuUIManager();
// 赋予要操作的对象
_rmuManager.DgvOperatorList = this.dgvOperatorList;
_rmuManager.DgvRightsList = this.dgvRightsList;
_rmuManager.TvRightsView = this.tvRightsView;
_rmuManager.MsMain = _msMain;
_rmuManager.RightsManagerUI = this;
// 创建权限菜单数据管理类实例
_rmdManager = new Common.RightsMenuDataManager();
}
#endregion
#region Event Handlers
/// <summary>param name
/
// 窗体初始化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmRightsManager_Load(object sender, EventArgs e)
{
// 加载操作员列表
_rmuManager.LoadOperatorList();
// 默认为分组模式
tsbtnRightsMode.Text = tsmiGroupMode.Text;
}
/
// <summary>
/// 树形视图右键菜单公共点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiTreeViewContentMenuItem_Click(object sender, EventArgs e)
{
// 保存当前菜单项激发者
ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
// 勾选所有结点上的复选框
if (menuItem == tsmiSelectAll)
{
foreach (TreeNode treeNode in this.tvRightsView.Nodes)
treeNode.Checked = true;
// 禁⽤树视图重绘
tvRightsView.BeginUpdate();
// 选中/取消树节点及其⼦节点勾选状态
_rmuManager.CheckOrUnCheckTreeNode(treeNode);
// 启⽤树视图重绘
tvRightsView.EndUpdate();
}
}
/
/ 取消所有结点上的复选
if (menuItem == tsmiCancelAll)
{
foreach (TreeNode treeNode in this.tvRightsView.Nodes)
{
treeNode.Checked = false;
// 禁⽤树视图重绘
tvRightsView.BeginUpdate();
// 选中/取消树节点及其⼦节点勾选状态
_rmuManager.CheckOrUnCheckTreeNode(treeNode);
// 启⽤树视图重绘
tvRightsView.EndUpdate();
}
}
// 重新加载账户权限结构树
if (menuItem == tsmiReload)
{
// 如果有选中⾏
if (dgvOperatorList.SelectedCells.Count > 0)
{
// 保存当前选中⾏的操作员名称
string operatorName = _dgvOldSelectedRow.Cells["ModelName"].Value.ToString().Trim();                // 指定当前编辑的操作员对象
Model.Operator editOperator = _operatorCollection[operatorName];
// 将数据绑定加载到树形视图
_rmuManager.BindDataToTreeView(editOperator.RightsCollection);
}
}
// 将 TreeView 树结点全部展开
if (menuItem == tsmiExpandAll)
{
this.tvRightsView.ExpandAll();
}
// 将 TreeView 树结点全部折叠
if (menuItem == tsmiCollapseAll)
{
this.tvRightsView.CollapseAll();
}
}
/// <summary>
/// [保存更改]⼯具栏按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbtnSaveAllChanged_Click(object sender, EventArgs e)
{
// 提交并结束数据视图的单元格编辑
dgvRightsList.EndEdit();
dgvOperatorList.EndEdit();
// 如果有选中单元格
if (dgvOperatorList.SelectedCells.Count > 0)
{
{
// 创建业务逻辑层⼯⼚类实例
BLLFactory.BLLFactory bllFactory = new BLLFactory.BLLFactory();
// 调⽤⼯⼚类实例⽅法创建操作员管理类实例
IBLL.IOperatorManager operatorManager = bllFactory.BuildOperatorManager();
// 保存所有操作员权限信息
foreach (Model.Operator tmpOperator in _operatorCollection.Values)
{
// 保存当前操作员所做的修改
operatorManager.ModifyOperator(tmpOperator);
}
// 给出⽤户操作提⽰
MessageBox.Show(
"权限设置保存成功!",
"保存提⽰",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"保存失败",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
/// <summary>
/// [刷新权限]⼯具栏按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbtnRefreshRightsList_Click(object sender, EventArgs e)
{
// 如果是⾮超级管理员
if (_currentOperator.Id != 0)
{
// 将数据绑定显⽰到数据视图
_rmuManager.BindDataToDataGridView(_currentOperator.RightsCollection);
// 将数据绑定加载到树形视图
_rmuManager.BindDataToTreeView(_currentOperator.RightsCollection);
}
}
/// <summary>
/// [刷新⽤户]⼯具栏按钮点击事件
/// </summary>
/// <param name="sender"></param>
/
// <param name="e"></param>
private void tsbtnRefreshOperator_Click(object sender, EventArgs e)
{
// 将数据绑定显⽰到数据视图
_rmuManager.BindOperatorInfoToDataGridView(_operatorCollection);
}
/// <summary>
/// [关闭窗⼝]⼯具栏按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。