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

📄 edituserprofile.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 2 页
字号:
            submit = (Button) skin.FindControl("Submit");
            submit.Click += new System.EventHandler(UpdateUserInfo_ButtonClick);
        }

        // *********************************************************************
        //  UpdateUserInfo_ButtonClick
        //
        /// <summary>
        /// This event is raised when the user clicks the submit button in the user
        /// control loaded in the DisplayEditMode function. This event is responsible
        /// for processing the form values and writing them back to the database if
        /// necessary.
        /// </summary>
        /// 
        // ********************************************************************/
        private void UpdateUserInfo_ButtonClick(Object sender, EventArgs e) {

            // Ensure the page is valid
            if (!Page.IsValid) 
                return;

            String password = null;
            Control skin;
            TextBox textbox;
            CheckBox checkbox;
            DropDownList dropdown;
            Control control;

            // Find the EditUserInformation user control
            skin = ((Control)sender).Parent;

/*
            // First get the user's password
            if (Mode == UserInfoEditMode.Admin) {
                password = user.Password;
            } else {
                password = ((TextBox) skin.FindControl("Password")).Text;
            }
*/
            // Get the values from the form
            ForumUser.Email = ((TextBox) skin.FindControl("Email")).Text;
            ForumUser.PublicEmail = ((TextBox) skin.FindControl("FakeEmail")).Text;
            
            textbox = (TextBox) skin.FindControl("WebSite");
            if (textbox != null)
                ForumUser.Url = textbox.Text;

            textbox = (TextBox) skin.FindControl("Signature");
            if (textbox != null)
                ForumUser.Signature = textbox.Text;

            checkbox = (CheckBox) skin.FindControl("EmailTracking");
            if (checkbox != null)
                ForumUser.TrackPosts = checkbox.Checked;
            
            ForumUser.Timezone = Convert.ToInt32(((DropDownList) skin.FindControl("Timezone")).SelectedItem.Value);

            // Do we require a password to perform the update?
            if (RequirePasswordForUpdate) {
                textbox = (TextBox) skin.FindControl("Password");
                if (textbox != null)
                    ForumUser.Password = textbox.Text;
            }
            
            textbox = (TextBox) skin.FindControl("Occupation");
            if (textbox != null)
                ForumUser.Occupation = textbox.Text;
            
            textbox = (TextBox) skin.FindControl("Location");
            if (textbox != null)
                ForumUser.Location = textbox.Text;
            
            textbox = (TextBox) skin.FindControl("Interests");
            if (textbox != null)
                ForumUser.Interests = textbox.Text;
            
            textbox = (TextBox) skin.FindControl("MsnIm");
            if (textbox != null)
                ForumUser.MsnIM = textbox.Text;
            
            textbox = (TextBox) skin.FindControl("YahooIm");
            if (textbox != null)
                ForumUser.YahooIM = textbox.Text;
            
            textbox = (TextBox) skin.FindControl("AolIm");
            if (textbox != null)
                ForumUser.AolIM = textbox.Text;
            
            textbox = (TextBox) skin.FindControl("ICQ");
            if (textbox != null)
                ForumUser.IcqIM = textbox.Text;
            
            checkbox = (CheckBox) skin.FindControl("UnreadThreadsOnly");
            if (checkbox != null)
                ForumUser.HideReadThreads = checkbox.Checked;
            
            checkbox = (CheckBox) skin.FindControl("ShowIcon");
            if (checkbox != null)
                ForumUser.ShowIcon = checkbox.Checked;

            dropdown = (DropDownList) skin.FindControl("SiteStyle");
            if (dropdown != null)
                ForumUser.SiteStyle = dropdown.SelectedItem.Value;

            dropdown = (DropDownList) skin.FindControl("DateFormat");
            if (dropdown != null)
                ForumUser.DateFormat = dropdown.SelectedItem.Value;

            dropdown = (DropDownList) skin.FindControl("PostViewOrder");
            if (dropdown != null)
                ForumUser.ShowPostsAscending = Convert.ToBoolean(Convert.ToInt32(dropdown.SelectedItem.Value));

            control = skin.FindControl("HasIcon");
            if (null != control) {
                if (control.Visible == true) {
                    ForumUser.HasIcon = true;
                }
            }
/*
            // If we're in admin mode we have a couple other options to handle
            if (Mode == UserInfoEditMode.Admin) {
                checkbox = (CheckBox) skin.FindControl("ProfileApproved");
                user.IsProfileApproved = checkbox.Checked;
                
                checkbox = (CheckBox) skin.FindControl("Banned");
                user.IsApproved = !checkbox.Checked;

                checkbox = (CheckBox) skin.FindControl("Trusted");
                user.IsTrusted = !checkbox.Checked;

            }
*/

            // Did the user send an icon?
            HtmlInputFile postedFile = (HtmlInputFile) skin.FindControl("Icon");
            if (postedFile != null) {

                if (postedFile.PostedFile.ContentLength != 0) {

                    if (postedFile.PostedFile.ContentType == "image/gif") {
                        postedFile.PostedFile.SaveAs(Page.Server.MapPath(Globals.ApplicationVRoot + "/UserIcons/" + ForumUser.Username + ".gif"));
                        ForumUser.IconExtension = "gif";
                        ForumUser.HasIcon = true;
                    } else if ((postedFile.PostedFile.ContentType == "image/jpg") || (postedFile.PostedFile.ContentType == "image/jpeg")) {
                        postedFile.PostedFile.SaveAs(Page.Server.MapPath(Globals.ApplicationVRoot + "/UserIcons/" + ForumUser.Username + ".jpg"));
                        ForumUser.IconExtension = "jpg";
                        ForumUser.HasIcon = true;
                    } else {
                        Label validatePostedFile = (Label) skin.FindControl("validatePostedFile");
                        validatePostedFile.Text = "File type must be .gif or .jpg";
                        return;
                    }
                }
            }

            // Do update
            try {
                bool updateResult;

                // Perform the actual update
                updateResult = Users.UpdateUserProfile(ForumUser);

                /*
                // If we're admin do another update
                if (Mode == UserInfoEditMode.Admin) {
                    Users.UpdateUserInfoFromAdminPage(user);
                }
                */

                if (updateResult) {
                    // the user was updated successfully, send an email if the password was changed
                    Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UserProfileUpdated));
                    Context.Response.End();
                }
                else {
                    RequiredFieldValidator validatePassword;
                    validatePassword = (RequiredFieldValidator) skin.FindControl("ValidatePassword");

                    validatePassword.Text = "Password is invalid";
                    validatePassword.IsValid = false;
                }

            } catch (Exception exception) {
                RequiredFieldValidator validateEmail;
                validateEmail = (RequiredFieldValidator) skin.FindControl("ValidateEmail");

                validateEmail.Text = "Email address exists";
                validateEmail.IsValid = false;

            }

        }

        public bool RequirePasswordForUpdate {
            get { return requirePasswordForUpdate; }
            set { requirePasswordForUpdate = value; }
        }
    }
}

⌨️ 快捷键说明

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