private void bunifuThinButton21_Click(object sender, EventArgs e) { oldEmailTextbox.LineIdleColor = Color.Gray; newEmailTextBox.LineIdleColor = Color.Gray; if (String.IsNullOrEmpty(oldEmailTextbox.Text)) { oldEmailTextbox.LineIdleColor = Color.Red; return; } if (String.IsNullOrEmpty(newEmailTextBox.Text)) { newEmailTextBox.LineIdleColor = Color.Red; return; } #region Изменить емейл using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); if (user.UserEmail == oldEmailTextbox.Text) { oldEmailTextbox.LineIdleColor = Color.Red; return; } else { user.UserEmail = newEmailTextBox.Text; db.SaveChanges(); label3.Visible = true; } } #endregion }
private void ChangePasswordButton_Click(object sender, EventArgs e) { oldPsswordTextBox.BorderColorIdle = Color.Gray; newPasswordTextBox.BorderColorIdle = Color.Gray; confirmNewPasswordTextBox.BorderColorIdle = Color.Gray; if (String.IsNullOrEmpty(oldPsswordTextBox.Text)) { oldPsswordTextBox.BorderColorIdle = Color.Red; return; } if (String.IsNullOrEmpty(newPasswordTextBox.Text)) { newPasswordTextBox.BorderColorIdle = Color.Red; return; } #region Изменить пароль using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); if (String.Compare(user.UserPassword, Crypto.Hash(oldPsswordTextBox.Text)) == 0) { if (newPasswordTextBox.Text.Length < 6) { newPasswordTextBox.BorderColorIdle = Color.Red; return; } if (confirmNewPasswordTextBox.Text != newPasswordTextBox.Text) { confirmNewPasswordTextBox.BorderColorIdle = Color.Red; return; } else { user.UserPassword = Crypto.Hash(newPasswordTextBox.Text); db.SaveChanges(); label2.Visible = true; } } else { oldPsswordTextBox.BorderColorIdle = Color.Red; } } #endregion }
private void AddPhoto(object ofds) { OpenFileDialog ofd = (OpenFileDialog)ofds; try { #region Добавить в базу фото using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); user.UserPhoto = ImageConvertion.ConvertToByteArray(Image.FromFile(ofd.FileName)); db.SaveChanges(); // circularPictureBox1.Image = ImageConvertion.RetriveImage(user.UserPhoto); } #endregion } catch (OutOfMemoryException ex) { MessageBox.Show(ex.Message); } }
private void saveChangesButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(changedNameTextbox.Text)) { changedNameTextbox.LineIdleColor = Color.Red; return; } #region Изменить информацию using (SearchProductsEntities db = new SearchProductsEntities()) { Users user = db.Users.Where(x => x.UserLogin == CUser.CurrentUser).FirstOrDefault(); user.UserName = changedNameTextbox.Text; user.UserSecondName = changedSNameTextbox.Text; user.UserCity = ChangedCityTextBox.Text; db.SaveChanges(); label1.Visible = true; nameTextBox.Text = user.UserName; SecondNameTextBox.Text = user.UserSecondName; CityTextBox.Text = user.UserCity; } #endregion }
private void bunifuThinButton21_Click(object sender, EventArgs e) { ClearErrors(); #region Проверка полей if (Password2TextBox.Text != PasswordTextBox.Text) { passwordMatchErrorLabel.Text = "Пароли должны совпадать"; passwordErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(NameTextBox.Text)) { nameErrorLabel.Text = "Необходимо указать имя"; nameErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(LoginTextBox.Text)) { loginErrorLabel.Text = "Необходимо указать логин"; loginErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(EmailTextBox.Text)) { emailErrorLabel.Text = "Необходимо указать почту"; emailErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(PasswordTextBox.Text)) { passwordErrorLabel.Text = "Необходимо указать пароль"; passwordErrorLabel.Visible = true; return; } if (String.IsNullOrEmpty(Password2TextBox.Text)) { passwordMatchErrorLabel.Text = "Необходимо указать пароль"; passwordMatchErrorLabel.Visible = true; return; } if (!EmailExists(EmailTextBox.Text)) //Почта совпадает { emailErrorLabel.Text = "Указанный адресс уже используется"; emailErrorLabel.Visible = true; return; } if (!LoginExists(LoginTextBox.Text)) //Логин совпадает { loginErrorLabel.Text = "Указанный логин уже используется"; loginErrorLabel.Visible = true; return; } if (PasswordTextBox.Text.Length < 6) { passwordErrorLabel.Text = "Минимальная длина пароля 6 символов"; passwordErrorLabel.Visible = true; return; } #endregion Users user = new Users(); user.UserName = NameTextBox.Text; user.UserLogin = LoginTextBox.Text; user.UserEmail = EmailTextBox.Text; user.UserEmailConfirmed = false; user.UserAdminRights = false; user.UserCity = "Пермь"; user.UserRegistrationDate = DateTime.Now.ToString(); #region Хэширование пароля user.UserPassword = Crypto.Hash(PasswordTextBox.Text); #endregion #region Добавление в базу using (SearchProductsEntities db = new SearchProductsEntities()) { db.Users.Add(user); db.SaveChanges(); } #endregion panel1.Visible = true; }