UserList.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:6k
- using System;
- using System.Data;
- using System.Web.UI.WebControls;
- using qminoa.BLL.PM;
- using qminoa.DA;
- namespace qminoa.Webs.PM
- {
- public class UserList : qminoa.Webs.PageBase
- {
- protected System.Web.UI.WebControls.DropDownList BranchDropList;
- protected System.Web.UI.WebControls.DropDownList DepartmentDropList;
- protected System.Web.UI.WebControls.DataGrid Users;
- private string temp_rolename = string.Empty;
- private PMUser _user;
- public const string UserRoleAdministrator = "1";
- private void Page_Load(object sender, System.EventArgs e)
- {
- this.PageBegin("项目角色管理",true);
- _user = new PMUser(Convert.ToInt16(this.Empid));
- if(_user.Role != UserRoleAdministrator)
- {
- Response.Redirect(Application["vRoot"]+"/login.aspx");
- }
- if (!Page.IsPostBack)
- {
- LoadBraDep();
- LoadUsers();
- }
- }
-
- protected RolesCollection GetRoles()
- {
- return Roles.GetRoles();
- }
- private void LoadBraDep()
- {
- AdminDB admin = new AdminDB();
- BranchDropList.DataSource=admin.GetAllBranch();
- BranchDropList.DataBind();
- BranchDropList.Items[0].Selected=true;
- DepartmentDropList.DataSource=admin.GetDepByBranch(Int32.Parse(BranchDropList.SelectedItem.Value));
- DepartmentDropList.DataBind();
- }
- private void LoadUsers()
- {
- UsersCollection users = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
- SortGridData(users, SortField, SortAscending);
- Users.DataSource = users;
- Users.DataKeyField = "UserID";
- Users.DataBind();
- }
- private void SortGridData(UsersCollection list, string sortField, bool asc)
- {
- UsersCollection.UserFields sortCol = UsersCollection.UserFields.InitValue;
- switch(sortField)
- {
- case "UserName":
- sortCol = UsersCollection.UserFields.UserName;
- break;
- case "RoleName":
- sortCol = UsersCollection.UserFields.RoleName;
- break;
- }
- list.Sort(sortCol, asc);
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.BranchDropList.SelectedIndexChanged += new System.EventHandler(this.BranchDropList_SelectedIndexChanged);
- this.DepartmentDropList.SelectedIndexChanged += new System.EventHandler(this.DepartmentDropList_SelectedIndexChanged);
- this.Users.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.Users_PageIndexChanged);
- this.Users.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Users_CancelCommand);
- this.Users.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Users_EditCommand);
- this.Users.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.Users_Sort);
- this.Users.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Users_UpdateCommand);
- this.Users.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.Users_ItemDataBound);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void Users_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
- {
- SortField = e.SortExpression;
- LoadUsers();
- }
- private void Users_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
- {
- Users.EditItemIndex= -1;
- Users.CurrentPageIndex = e.NewPageIndex;
- LoadUsers();
- }
- private void Users_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
- {
- Users.EditItemIndex = e.Item.ItemIndex;
- temp_rolename = ((Label) e.Item.FindControl("lblGridRoleName")).Text.Trim();
- LoadUsers();
- }
- private void Users_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
- {
- int _userid;
- int _roleid;
- _userid = Convert.ToInt32(Users.DataKeys[e.Item.ItemIndex].ToString());
- DropDownList currentRoleNameList = (DropDownList) e.Item.FindControl("ddlRoles");
- _roleid = Convert.ToInt16(currentRoleNameList.SelectedItem.Value);
- PMUser.UpdateUserRole(_userid,_roleid);
- Users.EditItemIndex = -1;
- LoadUsers();
- }
- private void Users_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
- {
- Users.EditItemIndex = -1;
- LoadUsers();
- }
- private void Users_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- if (e.Item.ItemType == ListItemType.EditItem)
- {
- DropDownList currentRoleNameList = (DropDownList) e.Item.FindControl("ddlRoles");
- currentRoleNameList.SelectedIndex = currentRoleNameList.Items.IndexOf(currentRoleNameList.Items.FindByText(temp_rolename));
- }
- }
- private void BranchDropList_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- AdminDB admin = new AdminDB();
- DepartmentDropList.DataSource=admin.GetDepByBranch(Int32.Parse(BranchDropList.SelectedItem.Value));
- DepartmentDropList.DataBind();
- if(DepartmentDropList.Items.Count !=0)
- {
- Users.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
- Users.DataBind();
- }
- else
- {
- Users.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,0);
- Users.DataBind();
- }
- }
- private void DepartmentDropList_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- Users.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
- Users.DataBind();
- }
- string SortField
- {
- get
- {
- object o = ViewState["SortField"];
- if (o == null)
- return string.Empty;
- return (string)o;
- }
- set
- {
- if (value == SortField)
- SortAscending = !SortAscending;
- ViewState["SortField"] = value;
- }
- }
- bool SortAscending
- {
- get
- {
- object o = ViewState["SortAscending"];
- if (o == null)
- return true;
- return (bool)o;
- }
- set
- {
- ViewState["SortAscending"] = value;
- }
- }
- }
- }