📄 role_update_ctrl.ascx.cs.svn-base
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Sovo.OA.BLL;
using Sovo.OA.BLL.Utils;
using Sovo.OA.Model;
public partial class Admin_System_Controls_role_update_ctrl : System.Web.UI.UserControl
{
List<Module> listModule = null;
List<String> listModuleID = null;
List<String> listOldModuleID = null;
Int32 roleID = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
roleID = Convert.ToInt32(Request.QueryString["roleID"]);
txtRoleName.Text = Request.QueryString["roleName"];
//填充TreeView
ModuleBLL aMBLL = new ModuleBLL();
listModule = aMBLL.getAllModules();
RoleBLL aRBLL = new RoleBLL();
listOldModuleID = aRBLL.getModulesOfRole(roleID);
//创建根节点
TreeNode rootNode = new TreeNode();
rootNode.Expanded = true;
rootNode.Text = "OA系统后台管理权限";
rootNode.Value = "100";
rootNode.ShowCheckBox = false;
TreeView1.Nodes.Clear();
TreeView1.Nodes.Add(rootNode);
CreateTree("100", rootNode);
TreeView1.Attributes.Add("OnClick", "OnTreeNodeChecked()");
}
}
private void CreateTree(String parentID, TreeNode rootNode)
{
List<Module> listSubModule = getSubModuleByParentID(parentID);
foreach (Module aModule in listSubModule)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = aModule.ModuleName;
treeNode.ShowCheckBox = true;
treeNode.Expanded = true;
treeNode.Value = aModule.ModuleID;
if (listOldModuleID.Contains(aModule.ModuleID))
treeNode.Checked = true;
else
treeNode.Checked = false;
rootNode.ChildNodes.Add(treeNode);
String id = aModule.ModuleID.Trim(); //
CreateTree(id, treeNode);
}
}
private List<Module> getSubModuleByParentID(String parentID)
{
List<Module> listSubModule = new List<Module>();
//Module m = new Module();
foreach (Module aModule in listModule)
{
if (aModule.ParentID == parentID)
{
listSubModule.Add(aModule);
}
}
return listSubModule;
}
private void GetAllChooseNodes(TreeNodeCollection tnc)
{
//得到用户的选择
foreach (TreeNode pNode in tnc)
{
if (pNode.Checked == true)
listModuleID.Add(pNode.Value);
if (pNode.ChildNodes.Count != 0)
GetAllChooseNodes(pNode.ChildNodes);
}
}
protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
/*
TreeNode currentNode = e.Node;
if (currentNode.Checked)
{
//选中状态--改变其父节点和相关所有子节点
currentNode.Parent.Checked = true;
foreach (TreeNode childNode in currentNode.ChildNodes)
{
childNode.Checked = true;
}
}*/
}
protected void btn_add_Click(object sender, EventArgs e)
{
listModuleID = new List<string>();
GetAllChooseNodes(TreeView1.Nodes);
listModuleID.Remove("0");
// ListBox1.DataSource = listModuleID;
// ListBox1.DataBind();
RoleBLL aRoleBLL = new RoleBLL();
roleID = Convert.ToInt32(Request.QueryString["roleID"]);
String roleNewName = txtRoleName.Text;
/*
//-- 角色名必须填写 --
if (txtRoleName.Text == "")
{
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('角色名必须填写')</script>";
//txtRoleName.Text = "";
Parent.Controls.Add(txtMsg);
return;
}
//-- 判断角色名在Role表中是否重复,如果重复要求用户重新输入 --
if (aRoleBLL.isExistInRole(txtRoleName.Text))
{
//有相同名字的角色,不能新增;提示用户输入新的用户名
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('角色名重复,请重新输入')</script>";
// txtRoleName.Text = "";
Parent.Controls.Add(txtMsg);
}
else
{
*/
//角色必须分配权限
if (listModuleID.Count == 0)
{
//显示错误信息
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('权限不能为空!')</script>";
//txtRoleName.Text = "";
Parent.Controls.Add(txtMsg);
return;
}
DBResult result = aRoleBLL.updateModulesOfRole(roleID, roleNewName, listModuleID);
OperationResult or = new OperationResult();
if (result == DBResult.Success)
{
//角色更新成功
or.IsSuccess = true;
or.ResultMsg = "更新角色成功!";
}
else
{
or.IsSuccess = false;
or.ResultMsg = "更新角色失败!";
}
String returnURL = "role_list.aspx";
or.ReturnURL = returnURL;
Session["orMsg"] = or;
Server.Transfer("Result.aspx");
// }
}
protected void Button1_Click(object sender, EventArgs e)
{
roleID = Convert.ToInt32(Request.QueryString["roleID"]);
txtRoleName.Text = Request.QueryString["roleName"];
//填充TreeView
ModuleBLL aMBLL = new ModuleBLL();
listModule = aMBLL.getAllModules();
RoleBLL aRBLL = new RoleBLL();
listOldModuleID = aRBLL.getModulesOfRole(roleID);
TreeView1.Nodes.Clear();
//创建根节点
TreeNode rootNode = new TreeNode();
rootNode.Expanded = true;
rootNode.Text = "OA系统后台管理权限";
rootNode.Value = "100";
rootNode.ShowCheckBox = false;
TreeView1.Nodes.Clear();
TreeView1.Nodes.Add(rootNode);
CreateTree("100", rootNode);
TreeView1.Attributes.Add("OnClick", "OnTreeNodeChecked()");
}
protected void Button2_Click(object sender, EventArgs e)
{
Server.Transfer("role_list.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -