?? rolemanage.aspx.cs
字號:
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 OfficeAutomatization;
using System.Data.SqlClient;
public partial class RoleManage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
///綁定控件的數據
BindRoleData();
}
///添加刪除確認對話框
deleteBtn.Attributes.Add("onclick", "return confirm('" + ASPNET2System.OPERATIONDELETEMESSAGE + "');");
}
private void BindRoleData()
{
///定義獲取數據的類
Role role = new Role();
SqlDataReader recr = role.GetRoles();
///設定控件的數據源
RoleList.DataSource = recr;
///設定控件的Text屬性和Value屬性
RoleList.DataTextField = "RoleName";
RoleList.DataValueField = "RoleID";
///綁定控件的數據
RoleList.DataBind();
///關閉數據讀取器和數據庫的連接
recr.Close();
}
protected void AddBtn_Click(object sender, EventArgs e)
{
///跳轉到添加頁面
Response.Redirect("~/DesktopModules/Role/AddRole.aspx");
}
protected void updateBtn_Click(object sender, ImageClickEventArgs e)
{
if (RoleList.SelectedIndex > -1)
{
///跳轉到查看頁面
Response.Redirect("~/DesktopModules/Role/UpdateRole.aspx?RoleID=" + RoleList.SelectedValue);
}
else
{
///顯示操作結果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
protected void deleteBtn_Click(object sender, ImageClickEventArgs e)
{
if (RoleList.SelectedIndex > -1)
{
///定義類Role
Role role = new Role();
try
{
///刪除數據
role.DeleteRole(Int32.Parse(RoleList.SelectedValue));
///顯示操作結果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
///重新綁定數據
BindRoleData();
}
catch (Exception ex)
{
///顯示刪除操作中的失敗、錯誤信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
else
{
///顯示操作結果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -