private void acceptButton_Click(object sender, EventArgs e) { using (var db = new MyDbContext()) { string login = loginTextBox.Text; string firstName = firstNameTextBox.Text; string secondName = secondNameTextBox.Text; string email = emailTextBox.Text; string phone = phoneTextBox.Text; string imgPath = avatarPictureBox.ImageLocation; if (avatarPictureBox.ImageLocation == "") { imgPath = "D:\\Univer\\4sem\\practice\\computerShop\\ComputerShop\\img\\noAvatar.png"; } User editing = CurrentUser.Get(); // Error processing. Incorrectly entered data if (login == "") { // TODO: // Add empty login return; } if (firstName == "") { // TODO: // Add empty firstName return; } if (secondName == "") { // TODO: // Add empty secondName return; } if (email == "") { // TODO: // Add empty email return; } if (phone == "") { // TODO: // Add empty phone return; } editing.Login = login; editing.FirstName = firstName; editing.SecondName = secondName; editing.Email = email; editing.Phone = phone; editing.ImagePath = imgPath; db.SaveChanges(); } loginTextBox.ReadOnly = true; firstNameTextBox.ReadOnly = true; secondNameTextBox.ReadOnly = true; phoneTextBox.ReadOnly = true; emailTextBox.ReadOnly = true; acceptButton.Visible = false; declineButton.Visible = false; editButton.Visible = true; addPictureButton.Visible = false; return; }
private void bSignUp_Click(object sender, EventArgs e) { loginErrorLabel.Visible = false; nameErrorLabel.Visible = false; secnameErrorLabel.Visible = false; passwordErrorLabel.Visible = false; emailErrorLabel.Visible = false; phoneErrorLabel.Visible = false; rulesNotAcceptedLabel.Visible = false; regErrorLabel.Visible = false; using (var db = new MyDbContext()) { string login = LoginTextBox.Text; string firstName = FirstNameTextBox.Text; string secondName = SecondNameTextBox.Text; string passWord = PassWordTextBox.Text; string email = EmailTextBox.Text; string phone = PhoneTextBox.Text; string imgPath = avatarPictureBox.ImageLocation; bool allowReg = true; if (avatarPictureBox.ImageLocation == null) { imgPath = "D:\\Univer\\4sem\\practice\\computerShop\\ComputerShop\\img\\noAvatar.png"; } // Error processing. Incorrectly entered data Regex regexLogin = new Regex(".{3,}"); if (!regexLogin.IsMatch(login)) { loginErrorLabel.Visible = true; allowReg = false; } // Error processing. Incorrectly entered data Regex regexFN = new Regex(".[А-я]"); if (!regexFN.IsMatch(firstName)) { nameErrorLabel.Visible = true; allowReg = false; } // Error processing. Incorrectly entered data Regex regexSN = new Regex(".[А-я]"); if (!regexSN.IsMatch(secondName)) { secnameErrorLabel.Visible = true; allowReg = false; } // Error processing. Incorrectly entered data Regex regexPassword = new Regex(".{10,}"); if (!regexPassword.IsMatch(passWord)) { passwordErrorLabel.Visible = true; allowReg = false; } // Error processing. Incorrectly entered data Regex regexEmail = new Regex(".[[email protected]]+"); if (!regexEmail.IsMatch(email)) { emailErrorLabel.Visible = true; allowReg = false; } // Error processing. Incorrectly entered data Regex regexPhone = new Regex(".[0-9]"); Regex regexPhone2 = new Regex(".{10,}"); if (!regexPhone.IsMatch(phone) || !regexPhone2.IsMatch(phone)) { phoneErrorLabel.Visible = true; allowReg = false; } // Error processing. Is there such a user? User registration = db.Users.SingleOrDefault(u => u.Login == login); if (registration != null) { regErrorLabel.Visible = true; allowReg = false; } // Error processing. Is rules accepted? if (acceptCheckBox.Checked == false) { rulesNotAcceptedLabel.Visible = true; allowReg = false; } if (allowReg == false) { return; } // Registration processing. Registration allowed if (registration == null && acceptCheckBox.Checked == true && allowReg == true) { // Create new User var and add it to DataBase, then save DataBase var newUser = new User() { Login = login, FirstName = firstName, SecondName = secondName, PassWord = PasswordHasher.Hash(passWord), Email = email, Phone = phone, Status = "user", ImagePath = imgPath }; db.Users.Add(newUser); db.SaveChanges(); StartForm form = new StartForm(); form.Show(); Hide(); } } return; }
private void addButton_Click(object sender, EventArgs e) { using (var db = new MyDbContext()) { string login = loginTextBox.Text; string firstName = firstNameTextBox.Text; string secondName = secondNameTextBox.Text; string passWord = passwordTextBox.Text; string email = emailTextBox.Text; string phone = phoneTextBox.Text; string status = statusComboBox.Text; string imgPath = avatarPictureBox.ImageLocation; if (avatarPictureBox.ImageLocation == null) { imgPath = "D:\\Univer\\4sem\\practice\\computerShop\\ComputerShop\\img\\noAvatar.png"; } // Error processing. Incorrectly entered data if (login == "") { // TODO: // Add empty login return; } if (firstName == "") { // TODO: // Add empty firstName return; } if (secondName == "") { // TODO: // Add empty secondName return; } if (passWord == "") { // TODO: // Add empty passWord return; } if (email == "") { // TODO: // Add empty email return; } if (phone == "") { // TODO: // Add empty phone return; } // Error processing. Is there such a user? User registration = db.Users.SingleOrDefault(u => u.Login == login); if (registration != null) { // TODO: // Add "wrong login" error message return; } // Registration processing. Registration allowed if (registration == null) { var newUser = new User() { Login = login, FirstName = firstName, SecondName = secondName, PassWord = PasswordHasher.Hash(passWord), Email = email, Phone = phone, Status = status, ImagePath = imgPath }; db.Users.Add(newUser); db.SaveChanges(); } } this.Close(); return; }