?? usersmodule.ascx.cs
字號(hào):
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;
//引用數(shù)據(jù)庫(kù)訪問(wèn)層。
using qminoa.DA;
using qminoa.Common;
namespace qminoa.Webs.sysSecurity.module
{
/// <summary>
/// UsersModule1 的摘要說(shuō)明。
/// 本頁(yè)面為一個(gè)用戶(hù)控件,作為SecurityRoles.aspx頁(yè)面的一部分來(lái)顯示。
/// 本模塊主要用來(lái)顯示系統(tǒng)管理中的所有用戶(hù)信息,可以查看用戶(hù)的詳細(xì)信息,添加和刪除用戶(hù)信息。
/// 模塊主要由一個(gè)DataList控件、一個(gè)LinkButton和兩個(gè)DropDownList組成。
/// </summary>
public abstract class UsersModule : System.Web.UI.UserControl
{
//定義一個(gè)DropDownList控件 UnitDrop用來(lái)顯示單位信息。
protected System.Web.UI.WebControls.DropDownList UnitDrop;
//定義一個(gè)DropDownList控件 BranchDrop用來(lái)顯示部門(mén)信息。
protected System.Web.UI.WebControls.DropDownList BranchDrop;
//定義一個(gè)DataList控件 UserList用來(lái)顯示用戶(hù)信息,包括查看和刪除按鈕。
protected System.Web.UI.WebControls.DataList UserList;
private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack == false)
{ //當(dāng)?shù)谝淮握{(diào)用頁(yè)面時(shí)綁定數(shù)據(jù)庫(kù)數(shù)據(jù)。
BindData();
}
}
//從數(shù)據(jù)庫(kù)中取得所有的模塊信息數(shù)據(jù),并顯示在頁(yè)面上。
private void BindData()
{
//引用數(shù)據(jù)庫(kù)訪問(wèn)層中的系統(tǒng)管理類(lèi)。
AdminDB admin = new AdminDB();
//用數(shù)據(jù)庫(kù)信息填充UnitDrop單位信息。
UnitDrop.DataSource=admin.GetAllBranch();
UnitDrop.DataBind();
//設(shè)置UnitDrop的默認(rèn)選項(xiàng)為第一項(xiàng)。
UnitDrop.SelectedIndex=0;
//根據(jù)單位信息用數(shù)據(jù)庫(kù)信息填充BranchDrop部門(mén)信息。
BranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(UnitDrop.SelectedItem.Value));
BranchDrop.DataBind();
BranchDrop.SelectedIndex=0;
//根據(jù)單位信息用數(shù)據(jù)庫(kù)信息填充UserList用戶(hù)信息。
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:該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// 設(shè)計(jì)器支持所需的方法 - 不要使用
/// 代碼編輯器修改此方法的內(nèi)容。
/// </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 (\"確定要?jiǎng)h除此項(xiàng)記錄嗎?\");");
}
}
//單位信息列表選擇項(xiàng)改變事件函數(shù)。
private void UnitDrop_SelectedIndexChanged(object sender, System.EventArgs e)
{ //引用數(shù)據(jù)庫(kù)訪問(wèn)層中的系統(tǒng)管理類(lèi)。
AdminDB admin = new AdminDB();
//根據(jù)單位信息用數(shù)據(jù)庫(kù)信息填充BranchDrop部門(mén)信息。
BranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(UnitDrop.SelectedItem.Value));
BranchDrop.DataBind();
//根據(jù)單位信息用數(shù)據(jù)庫(kù)信息填充UserList用戶(hù)信息。
UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
UserList.DataBind();
}
//部門(mén)信息列表選擇項(xiàng)改變事件函數(shù)。
private void BranchDrop_SelectedIndexChanged(object sender, System.EventArgs e)
{ //引用數(shù)據(jù)庫(kù)訪問(wèn)層中的系統(tǒng)管理類(lèi)。
AdminDB admin = new AdminDB();
//根據(jù)部門(mén)信息用數(shù)據(jù)庫(kù)信息填充UserList用戶(hù)信息。
UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
UserList.DataBind();
}
//UserList中的ItemCommand事件函數(shù),用來(lái)完成各元素中的按鈕事件。
private void UserList_ItemCommand(object sender, DataListCommandEventArgs e)
{
//引用數(shù)據(jù)庫(kù)訪問(wèn)層中的系統(tǒng)管理類(lèi)。
AdminDB admin = new AdminDB();
//取得單擊按鈕在UserList控件中的主鍵值,取得用戶(hù)號(hào)。
int UserID = (int) UserList.DataKeys[e.Item.ItemIndex];
//判斷事件的命令類(lèi)型。
if (e.CommandName == "edit")
{
//轉(zhuǎn)到查看用戶(hù)詳細(xì)信息頁(yè)面。
Response.Redirect("UserRoles.aspx?userid=" + UserID,false);
}
else if (e.CommandName == "delete")
{
if(admin.DeleteFuncRoleUser(UserID,"emp"))
{
JScript.Alert("刪除成功!");
BindData();
}
else
JScript.Alert("刪除失敗!");
}
}
//添加用戶(hù)信息按鈕事件函數(shù)。
private void AddUserBtn_Click(object sender, System.EventArgs e)
{ //轉(zhuǎn)到添加用戶(hù)信息頁(yè)面。
Response.Redirect("UserRoles.aspx",false);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -