winform权限管理实现【转】
Posted on 2010-04-29 17:05 Happy Coding阅读(876) 评论(1) 编辑收藏
winform权限管理实现
效果图:
技术实现:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
南师附中江宁分校using System.Text;
using System.Windows.Forms;
namespace HHLInfoManage
{
public partial class frmQuanXGL : Form
{
public frmQuanXGL()
{
InitializeComponent();
//设置权限树展开
this.QuanXtreeView.ExpandAll();
//绑定角色
Common.AccessDataOperation Data = new
HHLInfoManage.Common.AccessDataOperation();
DataTable table = Data.GetDataTable("lect distinct Role from QuanX");
this.RoletreeView.Nodes[0].Nodes.Clear();
for (int n = 0; n < table.Rows.Count; n++)
{
this.RoletreeView.Nodes[0].Nodes.Add(table.Rows[n][0].ToStrin g());
}
this.RoletreeView.ExpandAll();
}
private void ExitbuttonX_Click(object nder, EventArgs e)
{
公主与美洲狮//关闭窗体
this.Clo();
}
private void 删除ToolStripMenuItem_Click(object nder, EventArgs e)
{
//删除角色
if (this.RoletreeView.SelectedNode != null &&
this.RoletreeView.SelectedNode.Text!="所有角色")
{
if (MessageBox.Show("你确实要删除该角色吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Common.AccessDataOperation Data = new HHLInfoManage.Common.AccessDataOperation();
//删除角色
string comText = "delete from QuanX where
Role='"+this.RoletreeView.SelectedNode.Text+"'";
Data.ExecSql(comText);
MessageBox.Show("删除成功!","提示");
//重新绑定角色
DataTable table = Data.GetDataTable("lect distinct Role from QuanX");
this.RoletreeView.Nodes[0].Nodes.Clear();
for (int n = 0; n < table.Rows.Count; n++)
busting{
this.RoletreeView.Nodes[0].Nodes.Add(table.Ro
ws[n][0].ToString());
}
}
this.RoletreeView.ExpandAll();
}
el
{
MessageBox.Show("请选择角色!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);adult movie
}
江南大学怎么样}
void AllTreeView(TreeNodeCollection node, bool check)
{
/*递归,为选中的父节点选中子节点*/
foreach (System.Windows.Forms.TreeNode node1 in node)
{
if (node1.Nodes.Count != 0)
{
node1.Checked = check;
this.AllTreeView(node1.Nodes, node1.Checked);
}
el
{
node1.Checked = check;
}
}
}
private void QuanXtreeView_BeforeCheck(object nder, TreeViewCancelEventArgs e)
{
/*为选中的父节点选中子节点*/
this.AllTreeView(e.Node.Nodes, !(e.Node.Checked));
平台上的孩子}
private void SavebuttonX_Click(object nder, EventArgs e)
{
//保存数据
if (this.AddRoletextBoxX.Text.Trim().Length == 0)
{
MessageBox.Show("角色名称不能为空!","提示");
return;
impress
}bored怎么读
string Role=this.AddRoletextBoxX.Text.Trim();
//验证权限
List<string> List=new List<string>();
foreach (TreeNode Node1 in this.QuanXtreeView.Nodes[0].Nodes)
{
if (Node1.Checked)
{
List.Add(Node1.Tag.ToString());
}
foreach (TreeNode Node2 in Node1.Nodes)
{
if (Node2.Checked)
{
List.Add(Node2.Tag.ToString());
}
}
}
if (List.Count == 0)
{
MessageBox.Show("请选择权限!", "提示");
return;
}
Common.AccessDataOperation DataOperation = new
HHLInfoManage.Common.AccessDataOperation();
string comText = "";
comText = "delete from QuanX where Role='"+Role+"'";
DataOperation.ExecSql(comText);
for (int n = 0; n < List.Count; n++)
{
comText = "inrt into QuanX(Role,QuanX) values
('"+Role+"','"+List[n]+"')";
DataOperation.ExecSql(comText);
}
MessageBox.Show("保存成功!","提示");
//重新绑定数据
DataTable table = DataOperation.GetDataTable("lect distinct Role from QuanX");
this.RoletreeView.Nodes[0].Nodes.Clear();
for (int n = 0; n < table.Rows.Count; n++)
{
this.RoletreeView.Nodes[0].Nodes.Add(table.Rows[n][0].ToStrin g());
}
this.RoletreeView.ExpandAll();
prosperity
}
private void RoletreeView_AfterSelect(object nder, TreeViewEventArgs e)
{
//给角色赋权
Common.AccessDataOperation Data=new
HHLInfoManage.Common.AccessDataOperation();
DataTable table = Data.GetDataTable("lect QuanX from QuanX where Role='" + this.RoletreeView.SelectedNode.Text + "'");
foreach (TreeNode Node1 in this.QuanXtreeView.Nodes[0].Nodes)
{
Node1.Checked = fal;
foreach (TreeNode Node2 in Node1.Nodes)
{
Node2.Checked = fal;
}
}
for (int n = 0; n < table.Rows.Count; n++)
{
foreach (TreeNode Node1 in this.QuanXtreeView.Nodes[0].Nodes)
{
if (table.Rows[n][0].Equals(Node1.Tag))
{
Node1.Checked = true;
}
foreach (TreeNode Node2 in Node1.Nodes)
{
if (table.Rows[n][0].Equals(Node2.Tag))
{
残念是什么意思
Node2.Checked = true;
}
}
}
}
}
}
}
调用:
//进行权限设置
public void SetQuanX()
{
ToolStripMenuItem[] items = new ToolStripMenuItem[]
{
mnuMemberMamang,mnuMemberRegister,mnuMemberRevi,mnuMemberSel ect,mnuMemberReviNext,mnuMemberLogout,mnuSelectRoster,