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

📄 editprofile.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:

                isAnonymous = (YesNoRadioButtonList) skin.FindControl("IsAnonymous");
                isAnonymous.SelectedValue = userToEdit.IsAnonymous;

				forceLogin = (YesNoRadioButtonList) skin.FindControl("ForceLogin");
                forceLogin.SelectedValue = userToEdit.ForceLogin;

                isAvatarApproved = (YesNoRadioButtonList) skin.FindControl("IsAvatarApproved");
                isAvatarApproved.SelectedValue = userToEdit.IsAvatarApproved;
                
                // Account Status
                accountStatus = (AccountStatusDropDownList) skin.FindControl("AccountStatus");
                accountStatus.SelectedValue = userToEdit.AccountStatus;
                accountStatus.AutoPostBack = true;
                accountStatus.SelectedIndexChanged += new EventHandler(AccountStatus_Changed);

				// User Banning
				userBanSection = (HtmlTable) skin.FindControl("UserBanSection");
				userBanSection.Visible = (userToEdit.AccountStatus == UserAccountStatus.Banned) ? true : false;                                        
				bannedUntilDate = (Label) skin.FindControl("BannedUntilDate");
				bannedUntilDate.Text = this.GetBannedDateValue(ref userToEdit);
				// LN: 5/21/04 : Added to signal admin that a user's ban has expired.
				if (userToEdit.IsBanned && DateTime.Now > userToEdit.BannedUntil) {
					bannedUntilDate.Text += ResourceManager.GetString("EditProfile_BanExpired");
					bannedUntilDate.ForeColor = System.Drawing.Color.Red;
				}
				userBanPeriod = (UserBanDropDownList) skin.FindControl("UserBanPeriod");
				userBanPeriod.SelectedValue = this.GetRemainingBannedDays(userToEdit.BannedUntil);
                
                // User Approval
                userApprovalSection = (HtmlTable) skin.FindControl("UserApprovalSection");
                userApprovalSection.Visible = (userToEdit.AccountStatus == UserAccountStatus.ApprovalPending) ? true : false;                                        
                isApproved = (YesNoRadioButtonList) skin.FindControl("IsApproved");
                isApproved.SelectedValue = (userToEdit.AccountStatus == UserAccountStatus.Approved) ? true : false;
            }

		    // Give the update button some text
		    //
			updateButtonBottom.Text = CommunityServer.Components.ResourceManager.GetString("EditProfile_Update");

            // Set the avatar update button
            avatarUpdateButton.Text = CommunityServer.Components.ResourceManager.GetString("Update");

			// Set font size list
			fontsizeList.SelectedValue = userToEdit.Profile.FontSize.ToString();

		    // Wire-up any events
		    //
			updateButtonBottom.Click += new EventHandler(Update_Click);
			avatarUpdateButton.Click += new EventHandler(UpdateAvatar_Click);
		}
        #endregion

        #region Events
        /// <summary>
        /// Signals a change has been made to the current user and should be saved to the datastore.
        /// </summary>
        public void AccountStatus_Changed(Object sender, EventArgs e) {
            // User Approval
			if (userApprovalSection != null) {

				// show/hide the "Approve User" section
				//
				switch (userToEdit.AccountStatus) {
					case (UserAccountStatus.ApprovalPending):
						userApprovalSection.Visible = true;
						break;

					default:
						userApprovalSection.Visible = false;
						break;
				}


				// EAD 6/27/2004: this.PrevAccountStatus is Depreciated
				//
				//
					// Enable change back to pending but don't show the approve panel 
					// unless prevous account status was pending. 
					// Also preserve pending status untill it will be changed to 
					// Approved or Disapproved (other combinations are not allowed).
				//	if(this.PrevAccountStatus != UserAccountStatus.ApprovalPending)
				//		userApprovalSection.Visible = false;                                        
				//	else {
				//		accountStatus.SelectedValue = UserAccountStatus.ApprovalPending;
				//		userApprovalSection.Visible = true; //(accountStatus.SelectedValue == UserAccountStatus.ApprovalPending) ? true : false;                                        
				//	}
            }

            // User Banning (keep this code after Approval code)
            if (userBanSection != null)
                userBanSection.Visible = (accountStatus.SelectedValue == UserAccountStatus.Banned) ? true : false;
        }

        /// <summary>
        /// Save user image/avtar to the datastore
        /// </summary>
        public void UpdateAvatar_Click (Object sender, EventArgs e) {
            try {
                Resources.UpdateAvatar(csContext.User.UserID, uploadedAvatar.PostedFile.InputStream);

                avatarUrl.Text = "users/avatar.aspx?userid=" + csContext.User.UserID.ToString();

            } catch {
                throw new CSException(CSExceptionType.UnknownError);
            }

            Update_Click(sender, e);
        }

        /// <summary>
        /// Update the current user.
        /// </summary>
		public void Update_Click (Object sender, EventArgs e) {

			if (!Page.IsValid)
				return;

            // Check the max length on the signature
            //
            if (signature.Text.Length > csContext.SiteSettings.UserSignatureMaxLength) {
                signatureMaxLengthValidator.IsValid = false;
                return;
            }

			// Get the updated values from the form
			//
            if (csContext.SiteSettings.EnableUsernameChange)
                userToEdit.Username = usernameEdit.Text;

            // Update gender?
			// 修改为控件默认属性
            if (csContext.SiteSettings.AllowGender)
				userToEdit.Profile.Gender = gender.SelectedValue;

			userToEdit.Profile.CommonName = commonName.Text;
			userToEdit.Profile.Timezone = double.Parse(timezone.SelectedItem.Value);
			userToEdit.Profile.Location = location.Text;
			userToEdit.Profile.Occupation = occupation.Text;
			userToEdit.Profile.Interests = interests.Text;
			userToEdit.Profile.Signature = signature.Text;
			userToEdit.Profile.FontSize = int.Parse(fontsizeList.SelectedValue);
			userToEdit.Profile.WebAddress = webAddress.Text;
			userToEdit.Profile.WebLog = webLog.Text;

			if( csContext.SiteSettings.EnableCensorship ) {
				userToEdit.Profile.SignatureFormatted = Transforms.CensorPost( signature.Text );
			} else {
				userToEdit.Profile.SignatureFormatted = signature.Text;
			}	

			#region 新增内容
			userToEdit.Nickname = nickname.Text.Trim();
			userToEdit.Profile.QQIM = qq.Text.Trim();
			#endregion
			userToEdit.Email = privateEmail.Text;
			userToEdit.Profile.PublicEmail = publicEmail.Text;
			userToEdit.Profile.MsnIM = msnIM.Text;
			userToEdit.Profile.AolIM = aolIM.Text;
			userToEdit.Profile.YahooIM = yahooIM.Text;
			userToEdit.Profile.IcqIM = icq.Text;
			userToEdit.AvatarUrl = avatarUrl.Text;
			userToEdit.Profile.DateFormat = dateFormat.SelectedItem.Value;
			userToEdit.EnableAvatar = bool.Parse(enableAvatar.SelectedItem.Value);
			userToEdit.EnableThreadTracking = bool.Parse(enableEmailTracking.SelectedItem.Value);
			userToEdit.EnableDisplayInMemberList = bool.Parse(displayInMemberList.SelectedItem.Value);
			userToEdit.EnableHtmlEmail = bool.Parse(enableHtmlEmail.SelectedItem.Value);
			userToEdit.Profile.EnableEmoticons = EnableEmoticons.SelectedValue;
            
			if (int.Parse(sortOrder.SelectedItem.Value) == 1)
				userToEdit.PostSortOrder = SortOrder.Descending;
			else
				userToEdit.PostSortOrder = SortOrder.Ascending;

			userToEdit.EnableEmail = bool.Parse(enableEmail.SelectedItem.Value);
			if( !csContext.SiteSettings.EnableEmail )
				userToEdit.EnableEmail = false;

            userToEdit.Profile.Language = language.SelectedItem.Value;

            if (enablePostPreviewPopup != null &&
                csContext.SiteSettings.EnablePostPreviewPopup)  {  				
                userToEdit.Profile.EnablePostPreviewPopup = bool.Parse( enablePostPreviewPopup.SelectedItem.Value );
            }	
       
			if (birthday != null)
			{
				userToEdit.Profile.BirthDate = birthday.SelectedDate;
				userToEdit.Birthday = birthday.SelectedDate; // 修改
			}

            userToEdit.Theme = theme.SelectedValue;
			userToEdit.EnableCollapsingPanels = bool.Parse( enableCollapsingPanels.SelectedItem.Value );

            if ((Mode == ControlUserMode.Administrator) || (Mode == ControlUserMode.Moderator)) {
                userToEdit.ModerationLevel = moderationLevel.SelectedValue;
				userToEdit.AccountStatus = accountStatus.SelectedValue;
				userToEdit.IsAnonymous = isAnonymous.SelectedValue;
                userToEdit.IsAvatarApproved = isAvatarApproved.SelectedValue;
                userToEdit.ForceLogin = forceLogin.SelectedValue;
                
				// User Banning
				if (accountStatus.SelectedValue == UserAccountStatus.Banned) {
					userToEdit.BannedUntil = DateTime.Now.AddDays((int) userBanPeriod.SelectedValue);
				}
				else {
					userToEdit.BannedUntil = DateTime.Now;
				}
                
                // User Approval
                if (userApprovalSection.Visible == true && 
                    accountStatus.SelectedValue == UserAccountStatus.ApprovalPending) {

                    if (isApproved.SelectedValue == true) {
                        // Change status to Approved
                        userToEdit.AccountStatus = UserAccountStatus.Approved;

                        // Send email ( moved after update! )
                        //Emails.UserAccountApproved(userToEdit);
                    }

                    if (isApproved.SelectedValue == false) {
                        // Change status to Disapproved
                        userToEdit.AccountStatus = UserAccountStatus.Disapproved;

                        // Send email ( moved after update! )
                        //Emails.UserAccountRejected(userToEdit, CSContext.Current.User);
                    }
                }

            }

			// Update the user
			//
            try 
            {
                Users.UpdateUser(userToEdit);

            }
            catch (CSException ex) 
            {
                // Check to see if the MemberRole component threw a duplicate email exception. If so we want to handle it gracefully.
				if (ex.CreateUserStatus == CreateUserStatus.DuplicateEmailAddress)
				{
					// Notify that update was not successful because of duplicate email
					formStatus.Success = false;
					formStatus.Visible = true;
					formStatus.ResourceName = "EditProfile_DuplicateEmail";
					return;
				}
				// 昵称不能重复
				else if (ex.CreateUserStatus == CreateUserStatus.DuplicateNickname)
				{
					formStatus.Success = false;
					formStatus.Visible = true;
					formStatus.ResourceName = "EditProfile_DuplicateNickname";
					return;
				}

                throw;
            }

            // Send notification emails after the update took place
            //
            if ((Mode == ControlUserMode.Administrator) || (Mode == ControlUserMode.Moderator)) 
            {


                // User Approval
                if( this.PrevAccountStatus == UserAccountStatus.ApprovalPending &&
                    userToEdit.AccountStatus == UserAccountStatus.Approved )  {

                    Emails.UserAccountApproved(userToEdit);
                }

                if( this.PrevAccountStatus == UserAccountStatus.ApprovalPending &&
                    userToEdit.AccountStatus == UserAccountStatus.Disapproved ) {

                    Emails.UserAccountRejected(userToEdit, CSContext.Current.User);
                }
            }   
         
            // Notify the End of Update
            //
            formStatus.Success = true;
            formStatus.Visible = true;
			formStatus.ResourceName = "EditProfile_UpdateSuccess";

		}
        #endregion

        #region Helper Properties & Methods
        public UserAccountStatus PrevAccountStatus {

			get {
				Object state = ViewState["PrevAccountStatus"];
				if ( state != null ) {
					return (UserAccountStatus)state;
				}
				return UserAccountStatus.Approved;
			}
			set {
				ViewState["PrevAccountStatus"] = value;
			}
		}

        private UserBanPeriod GetRemainingBannedDays(DateTime bannedUntil) {

            UserBanPeriod daysNo = UserBanPeriod.Permanent;
            if(DateTime.Now > bannedUntil)
                return daysNo;

            int diff = ((TimeSpan) (bannedUntil - DateTime.Now)).Days;
            if(diff <= (int) UserBanPeriod.OneDay) {
                daysNo = UserBanPeriod.OneDay;
            }
            else if(diff > (int) UserBanPeriod.OneDay && diff <= (int) UserBanPeriod.ThreeDays) {
                daysNo = UserBanPeriod.ThreeDays;
            }
            else if(diff > (int) UserBanPeriod.ThreeDays && diff <= (int) UserBanPeriod.FiveDays) {
                daysNo = UserBanPeriod.FiveDays;
            }
            else if(diff > (int) UserBanPeriod.FiveDays && diff <= (int) UserBanPeriod.OneWeek) {
                daysNo = UserBanPeriod.OneWeek;
            }
            else if(diff > (int) UserBanPeriod.OneWeek && diff <= (int) UserBanPeriod.TwoWeeks) {
                daysNo = UserBanPeriod.TwoWeeks;
            }
            else if(diff > (int) UserBanPeriod.TwoWeeks && diff <= (int) UserBanPeriod.OneMonth) {
                daysNo = UserBanPeriod.OneMonth;
            }
            else if(diff > (int) UserBanPeriod.OneMonth && diff <= (int) UserBanPeriod.Permanent) {
                daysNo = UserBanPeriod.Permanent;
            }

            return daysNo;
        }

        private string GetBannedDateValue(ref User userToEdit) {

            if(userToEdit != null && userToEdit.IsBanned)
                return Formatter.FormatDate(userToEdit.BannedUntil, true);
            else
                return ResourceManager.GetString("NotSet");
        }
        #endregion
	}
}

⌨️ 快捷键说明

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