⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edituser.aspx.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ASPNET.StarterKit.Communities.Admin.EditUsers
{
	/// <summary>
	/// Summary description for EditUser.
	/// </summary>
	public class EditUser : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
		protected System.Web.UI.WebControls.Panel pnlInvalidUsername;
		protected System.Web.UI.WebControls.Panel pnlInvalidEmail;
		protected ASPNET.StarterKit.Communities.RegisterForm ctlProfile;
		protected ASPNET.StarterKit.Communities.Admin.ListPicker ctlRoles;
		protected System.Web.UI.WebControls.TextBox txtUserQuota;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
		protected System.Web.UI.WebControls.Label lblUserQuotaUsed;
		protected System.Web.UI.WebControls.Button btnUpdate;


		#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.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion


		//*******************************************************
		//
		// Store the ID of the user being edited
		// in view state.
		//
		//*******************************************************
	    
		int UserID {
			get {return (int)ViewState["UserID"];}
			set {ViewState["UserID"] = value;}
	    
		}
	    
	    
		//*******************************************************
		//
		// When the page first loads, grab all the user
		// information from the database and display it
		// in a form.
		//
		//*******************************************************
	    
		void Page_Load(Object s, EventArgs e) {
			if (!Page.IsPostBack) {
				ProfileInfo objProfile = UserUtility.GetProfile(Request.QueryString["username"]);
	    
				UserID = objProfile.ID;
				ctlProfile.Username = objProfile.Username;
				ctlProfile.Password = objProfile.Password;
				ctlProfile.Email = objProfile.Email;
				ctlProfile.FirstName = objProfile.FirstName;
				ctlProfile.LastName = objProfile.LastName;
				ctlProfile.Timezone = objProfile.Timezone;
				ctlProfile.Occupation = objProfile.Occupation;
				ctlProfile.Location = objProfile.Location;
				ctlProfile.Interests = objProfile.Interests;
				ctlProfile.MSN = objProfile.MSN;
				ctlProfile.Yahoo = objProfile.Yahoo;
				ctlProfile.AIM = objProfile.AIM;
				ctlProfile.ICQ = objProfile.ICQ;
				ctlProfile.Url = objProfile.Url;
				ctlProfile.FakeEmail = objProfile.FakeEmail;
				ctlProfile.EnableNewsletter = objProfile.EnableNewsletter;
				ctlProfile.EnableNotifications = objProfile.EnableNotifications;
	    
				// Get roles
				ctlRoles.SelectedItems = UserUtility.GetUserRolesFromDB(objProfile.Username);
				ctlRoles.DataSource = UserUtility.GetAllUserRoles().Tables[0].DefaultView;
				ctlRoles.DataField = "Role_RoleName";
				ctlRoles.DataBind();
	    
				// Get Quota
				QuotaInfo quotaInfo = CommunityGlobals.GetQuotaInfo(objProfile.Username);
				txtUserQuota.Text = String.Format("{0}", quotaInfo.UserQuota / 1024);
				lblUserQuotaUsed.Text = String.Format("{0} KB", quotaInfo.UserQuotaUsed / 1024);
			}
		}
	    
	    
		//*******************************************************
		//
		// Update the user information in the database.
		//
		//*******************************************************
	    
		void btnUpdate_Click(Object s, EventArgs e) {
			if (Page.IsValid) {
				ProfileInfo objProfile = new ProfileInfo();
	    
				objProfile.ID = UserID;
				objProfile.Username = ctlProfile.Username;
				objProfile.Password = ctlProfile.Password;
				objProfile.Email = ctlProfile.Email;
				objProfile.FirstName = ctlProfile.FirstName;
				objProfile.LastName = ctlProfile.LastName;
				objProfile.Timezone = ctlProfile.Timezone;
				objProfile.Occupation = ctlProfile.Occupation;
				objProfile.Location = ctlProfile.Location;
				objProfile.Interests = ctlProfile.Interests;
				objProfile.MSN = ctlProfile.MSN;
				objProfile.Yahoo = ctlProfile.Yahoo;
				objProfile.AIM = ctlProfile.AIM;
				objProfile.ICQ = ctlProfile.ICQ;
				objProfile.Url = ctlProfile.Url;
				objProfile.FakeEmail = ctlProfile.FakeEmail;
				objProfile.EnableNewsletter = ctlProfile.EnableNewsletter;
				objProfile.EnableNotifications = ctlProfile.EnableNotifications;
	    
	    
				int result = UserUtility.UpdateProfile(objProfile);
	    
				// Either Update or display error message
				switch ( result ) {
					case 0: // Success!
						UserUtility.UpdateUserQuota(objProfile.Username, Int32.Parse(txtUserQuota.Text));
						UserUtility.UpdateUserRoles(objProfile.Username, ctlRoles.SelectedItems);
						Response.Redirect("Default.aspx");
						break;
					case 1: // Username already taken
						pnlInvalidUsername.Visible = true;
						pnlInvalidEmail.Visible = false;
						break;
					case 2: // Email address already taken
						pnlInvalidEmail.Visible = true;
						pnlInvalidUsername.Visible = false;
						break;
				}
	    
	    
			}
		}





	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -