?? adduser.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 AddUser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
///綁定控件的數據
BindRoleData();
}
///設置按鈕的可用性
AddBtn.Enabled = RoleList.Items.Count > 0 ? true : false;
}
private void BindRoleData()
{
///獲取數據源
OfficeAutomatization.Role role = new Role();
SqlDataReader recr = role.GetRoles();
///設定控件的數據源,Text域屬性、value域屬性
RoleList.DataSource = recr;
RoleList.DataTextField = "RoleName";
RoleList.DataValueField = "RoleID";
///綁定控件的數據
RoleList.DataBind();
///關閉數據源和數據庫的鏈接
recr.Close();
}
protected void AddBtn_Click(object sender, EventArgs e)
{
///如果頁面輸入內容合法
if (Page.IsValid == true)
{
///定義類User
OfficeAutomatization.User user = new User();
try
{
///添加新用戶
user.AddUser(UserName.Text.Trim(),RealName.Text.Trim(),
OfficeAutomatization.User.Encrypt(Password.Text.Trim()),
Address.Text.Trim(),Phone.Text.Trim(),Email.Text.Trim(),
Int32.Parse(RoleList.SelectedValue));
///顯示操作結果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///顯示添加操作中的失敗、錯誤信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
}
protected void ReturnBtn_Click(object sender, EventArgs e)
{
///返回管理頁面
Response.Redirect("~/DesktopModules/User/UserManage.aspx");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -