?? usersmodule.ascx.cs
字號:
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;
//引用數據庫訪問層。
using qminoa.DA;
using qminoa.Common;
namespace qminoa.Webs.sysSecurity.module
{
/// <summary>
/// UsersModule1 的摘要說明。
/// 本頁面為一個用戶控件,作為SecurityRoles.aspx頁面的一部分來顯示。
/// 本模塊主要用來顯示系統管理中的所有用戶信息,可以查看用戶的詳細信息,添加和刪除用戶信息。
/// 模塊主要由一個DataList控件、一個LinkButton和兩個DropDownList組成。
/// </summary>
public abstract class UsersModule : System.Web.UI.UserControl
{
//定義一個DropDownList控件 UnitDrop用來顯示單位信息。
protected System.Web.UI.WebControls.DropDownList UnitDrop;
//定義一個DropDownList控件 BranchDrop用來顯示部門信息。
protected System.Web.UI.WebControls.DropDownList BranchDrop;
//定義一個DataList控件 UserList用來顯示用戶信息,包括查看和刪除按鈕。
protected System.Web.UI.WebControls.DataList UserList;
private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack == false)
{ //當第一次調用頁面時綁定數據庫數據。
BindData();
}
}
//從數據庫中取得所有的模塊信息數據,并顯示在頁面上。
private void BindData()
{
//引用數據庫訪問層中的系統管理類。
AdminDB admin = new AdminDB();
//用數據庫信息填充UnitDrop單位信息。
UnitDrop.DataSource=admin.GetAllBranch();
UnitDrop.DataBind();
//設置UnitDrop的默認選項為第一項。
UnitDrop.SelectedIndex=0;
//根據單位信息用數據庫信息填充BranchDrop部門信息。
BranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(UnitDrop.SelectedItem.Value));
BranchDrop.DataBind();
BranchDrop.SelectedIndex=0;
//根據單位信息用數據庫信息填充UserList用戶信息。
UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
UserList.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// 設計器支持所需的方法 - 不要使用
/// 代碼編輯器修改此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.UnitDrop.SelectedIndexChanged += new System.EventHandler(this.UnitDrop_SelectedIndexChanged);
this.BranchDrop.SelectedIndexChanged += new System.EventHandler(this.BranchDrop_SelectedIndexChanged);
this.UserList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.UserList_ItemCommand);
this.UserList.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.OnAttachScript);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void OnAttachScript (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
ImageButton button = (ImageButton) e.Item.FindControl("Imagebutton4");
button.Attributes.Add ("onclick",
"return confirm (\"確定要刪除此項記錄嗎?\");");
}
}
//單位信息列表選擇項改變事件函數。
private void UnitDrop_SelectedIndexChanged(object sender, System.EventArgs e)
{ //引用數據庫訪問層中的系統管理類。
AdminDB admin = new AdminDB();
//根據單位信息用數據庫信息填充BranchDrop部門信息。
BranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(UnitDrop.SelectedItem.Value));
BranchDrop.DataBind();
//根據單位信息用數據庫信息填充UserList用戶信息。
UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
UserList.DataBind();
}
//部門信息列表選擇項改變事件函數。
private void BranchDrop_SelectedIndexChanged(object sender, System.EventArgs e)
{ //引用數據庫訪問層中的系統管理類。
AdminDB admin = new AdminDB();
//根據部門信息用數據庫信息填充UserList用戶信息。
UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
UserList.DataBind();
}
//UserList中的ItemCommand事件函數,用來完成各元素中的按鈕事件。
private void UserList_ItemCommand(object sender, DataListCommandEventArgs e)
{
//引用數據庫訪問層中的系統管理類。
AdminDB admin = new AdminDB();
//取得單擊按鈕在UserList控件中的主鍵值,取得用戶號。
int UserID = (int) UserList.DataKeys[e.Item.ItemIndex];
//判斷事件的命令類型。
if (e.CommandName == "edit")
{
//轉到查看用戶詳細信息頁面。
Response.Redirect("UserRoles.aspx?userid=" + UserID,false);
}
else if (e.CommandName == "delete")
{
if(admin.DeleteFuncRoleUser(UserID,"emp"))
{
JScript.Alert("刪除成功!");
BindData();
}
else
JScript.Alert("刪除失??!");
}
}
//添加用戶信息按鈕事件函數。
private void AddUserBtn_Click(object sender, System.EventArgs e)
{ //轉到添加用戶信息頁面。
Response.Redirect("UserRoles.aspx",false);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -