📄 userpermissionsearch.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Botheighten.Yanghui.BusinessFacade;
using Botheighten.Yanghui.Framework;
using Botheighten.Yanghui.BusinessRules;
namespace Botheighten.Yanghui.Web
{
/// <summary>
/// UserPermissionSearch 的摘要说明。
/// </summary>
public class UserPermissionSearch : BasePage
{
protected System.Web.UI.WebControls.Label lblTitle;
protected System.Web.UI.WebControls.DropDownList ddlUser;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Button btnSave;
protected System.Web.UI.WebControls.Button btnGoBack;
protected System.Web.UI.WebControls.Table tablePermission;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
// 在此处放置用户代码以初始化页面
Principal p=this.CurrentUser();
this.CheckPermissionPage(p.Id,"","304");
this.ReponseWriteDeleteScript ();
this.lblMessage.Visible=false;
this.GoBackFunction(this.btnGoBack);
if(!Page.IsPostBack)
{
DataTable dv=LoginSystem.AllUser("","","","Y");
DropDownList lc=this.ddlUser;
//Common.BindDrop(this.ddlUser,dv,BusinessRules.User.NAME,BusinessRules.User.ID);
lc.Items.Clear();
foreach(DataRow myRow in dv.Rows)
{
lc.Items.Add(new ListItem(myRow[BusinessRules.User.ID].ToString()+"["+myRow[BusinessRules.User.NAME].ToString()+"]",myRow[BusinessRules.User.ID].ToString()));
}
lc.DataBind();
if(Request.QueryString["UserID"]!=null && Request.QueryString["UserID"].ToString()!="")
Common.SelectFlg(this.ddlUser,Request.QueryString["UserID"].ToString());
InitPageContent();
}
if (this.IsPostBack)
{
this.InitPageContentAgain();
}
}
private void InitPageContent()
{
if(this.ddlUser.Items.Count>0)
{
string userid=this.ddlUser.SelectedItem.Value;
DataView dvAllCat=LoginSystem.GetCatalog("Y").DefaultView;
int i=0;
foreach(DataRowView CatItem in dvAllCat)
{
if (dvAllCat.Count>0)
{
TableRow TRow=new TableRow();
//TRow.CssClass="Table_Header";
TableCell TCell=new TableCell();
CheckBox CBoxSelect=new CheckBox();
CBoxSelect.ID="Cat"+i.ToString();
CBoxSelect.AutoPostBack=false;
CBoxSelect.Style.Add("width","90%");
CBoxSelect.Checked=false;
CBoxSelect.Text=CatItem[Catalog.NAME].ToString();
CBoxSelect.ToolTip=CatItem[Catalog.ID].ToString();
//CBoxSelect.CheckedChanged+=new System.EventHandler(this.CBoxSelect_CheckedChanged);
CBoxSelect.Attributes.Add("onClick","ChangeAll('"+i.ToString()+"')");
//this.UserDropList.SelectedIndexChanged += new System.EventHandler(this.UserDropList_SelectedIndexChanged);
//TCell.HorizontalAlign=HorizontalAlign.Center;
TCell.Controls.Add(CBoxSelect);
TRow.Cells.Add(TCell);
tablePermission.Rows.Add(TRow);
CheckBoxList CBoxList= new CheckBoxList();
CBoxList.ID ="List"+i.ToString();
CBoxList.RepeatColumns = 4;
CBoxList.Enabled=false;
CBoxList.RepeatDirection=RepeatDirection.Horizontal;
CBoxList.Style.Add("width","90%");
DataView dvPermit=LoginSystem.GetPage(CatItem[Catalog.ID].ToString(),"Y").DefaultView;
int permitCount=dvPermit.Count;
for (int permitOrd=0;permitOrd<permitCount;permitOrd++)
{
string strPermitName=dvPermit[permitOrd][BusinessRules.Page.NAME].ToString();
string strPermitId=dvPermit[permitOrd][BusinessRules.Page.CODE].ToString();
ListItem CBox=new ListItem(strPermitName,strPermitId);
if (LoginSystem.CheckPermission(userid,"",strPermitId))
{
CBox.Selected =true;
}
else
{
CBox.Selected =false;
}
CBoxList.Items.Add(CBox);
}
TableRow TRow1=new TableRow();
TableCell TCell1=new TableCell();
TRow1.CssClass="Table_General";
TCell1.HorizontalAlign=HorizontalAlign.Center;
TCell1.Controls.Add(CBoxList);
TRow1.Cells.Add(TCell1);
tablePermission.Rows.Add(TRow1);
}
i++;
}
}
}
private void InitPageContentAgain()
{
string userid=this.ddlUser.SelectedItem.Value;
DataView dvAllCat=LoginSystem.GetCatalog("Y").DefaultView;
int i=0;
foreach(DataRowView CatItem in dvAllCat)
{
if (dvAllCat.Count!=0)
{
TableRow TRow=new TableRow();
//TRow.CssClass="Table_Header";
TableCell TCell=new TableCell();
CheckBox CBoxSelect=new CheckBox();
CBoxSelect.ID="Cat"+i.ToString();
CBoxSelect.Style.Add("width","90%");
CBoxSelect.Checked=false;
CBoxSelect.Text=CatItem[Catalog.NAME].ToString();
CBoxSelect.ToolTip=CatItem[Catalog.ID].ToString();
CBoxSelect.AutoPostBack=false;
//CBoxSelect.CheckedChanged+=new System.EventHandler(this.CBoxSelect_CheckedChanged);
CBoxSelect.Attributes.Add("onClick","ChangeAll('"+i.ToString()+"')");
//this.UserDropList.SelectedIndexChanged += new System.EventHandler(this.UserDropList_SelectedIndexChanged);
//TCell.HorizontalAlign=HorizontalAlign.Center;
TCell.Controls.Add(CBoxSelect);
TRow.Cells.Add(TCell);
tablePermission.Rows.Add(TRow);
CheckBoxList CBoxList= new CheckBoxList();
CBoxList.ID ="List"+i.ToString();
CBoxList.RepeatColumns = 4;
CBoxList.Enabled=false;
CBoxList.RepeatDirection=RepeatDirection.Horizontal;
CBoxList.Style.Add("width","90%");
DataView dvPermit=LoginSystem.GetPage(CatItem[Catalog.ID].ToString(),"Y").DefaultView;
int permitCount=dvPermit.Count;
for (int permitOrd=0;permitOrd<permitCount;permitOrd++)
{
string strPermitName=dvPermit[permitOrd][BusinessRules.Page.NAME].ToString();
string strPermitId=dvPermit[permitOrd][BusinessRules.Page.CODE].ToString();
ListItem CBox=new ListItem(strPermitName,strPermitId);
CBoxList.Items.Add(CBox);
}
TableRow TRow1=new TableRow();
TableCell TCell1=new TableCell();
TRow1.CssClass="Table_General";
TCell1.HorizontalAlign=HorizontalAlign.Center;
TCell1.Controls.Add(CBoxList);
TRow1.Cells.Add(TCell1);
tablePermission.Rows.Add(TRow1);
}
i++;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ddlUser.SelectedIndexChanged += new System.EventHandler(this.ddlUser_SelectedIndexChanged);
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ddlUser_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.BindDrop();
}
private void BindDrop()
{
if(!(this.ddlUser.Items.Count>0))
this.btnSave.Enabled=false;
else
{
foreach (TableRow Rows in tablePermission.Rows)
foreach (TableCell Cells in Rows.Cells)
{
if (Cells.Controls[0].GetType().Name=="CheckBox")
{
((CheckBox)(Cells.Controls[0])).Checked=false;
continue;
}
foreach (CheckBoxList CheckBoxLists in Cells.Controls)
foreach (ListItem Items in CheckBoxLists.Items)
{
if (LoginSystem.CheckPermission(this.ddlUser.SelectedItem.Value,"",Items.Value))
Items.Selected =true;
else
Items.Selected =false;
}
}
}
}
private void btnSave_Click(object sender, System.EventArgs e)
{
ArrayList RolePermit=new ArrayList();
foreach (TableRow Rows in tablePermission.Rows)
{
foreach (TableCell Cells in Rows.Cells)
{
if (Cells.Controls[0].GetType().Name=="CheckBox")
{
((CheckBox)(Cells.Controls[0])).Checked=false;
continue;
}
foreach (CheckBoxList CheckBoxLists in Cells.Controls)
foreach (ListItem Items in CheckBoxLists.Items)
if (Items.Selected)
RolePermit.Add(Items.Value);
}
}
if(LoginSystem.SavePermission(this.ddlUser.SelectedItem.Value,RolePermit))
{
this.lblMessage.Text ="成功:修改用户权限成功";
this.lblMessage.Visible=true;
}
else
{
this.lblMessage.Text ="失败:在修改用户权限中遇到错误";
this.lblMessage.Visible=true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -