private void ToolStripMenuItem4_Click(object sender, EventArgs e) { AuthorizationForm authorizationForm = new AuthorizationForm(); authorizationForm.Show(); this.Hide(); }
private async void RegistrationButton_Click(object sender, EventArgs e) { bool checkPassword = CheckPass(passwordTextBox.Text.ToString(), loginTextBox.Text.ToString()); if (checkPassword == true) { sqlConnection = new SqlConnection(connectionPathMain); await sqlConnection.OpenAsync(); SqlDataReader sdr = null; SqlCommand cmdSelect = new SqlCommand("SELECT * FROM [Users]", sqlConnection); SqlCommand cmdInsert = new SqlCommand("INSERT INTO [Users] (Login, Pass, Role, Id)VALUES(@Login, @Password, @Role, 10)", sqlConnection); cmdInsert.Parameters.AddWithValue("Login", loginTextBox.Text); cmdInsert.Parameters.AddWithValue("Password", passwordTextBox.Text); cmdInsert.Parameters.AddWithValue("Role", "Заказчик"); bool regCheck = true; //Проверка логина на повтор в базе данных. bool checkLogin = true; //Проверка логина на символы русского алфавита. char[] loginLetters = loginTextBox.Text.ToCharArray(); for (int i = 0; i < loginLetters.Length; i++) { if (loginLetters[i] >= 'А' && loginLetters[i] <= 'ё' && loginLetters.Length != 0) { checkLogin = false; MessageBox.Show("Логин не должен содержать символы русского алфавита!"); break; } } if (checkPassword == true && checkLogin == true) { try { sdr = await cmdSelect.ExecuteReaderAsync(); while (await sdr.ReadAsync()) { if (loginTextBox.Text == Convert.ToString(sdr["Login"])) { MessageBox.Show("Такой логин уже существует!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); regCheck = false; loginTextBox.Text = ""; passwordTextBox.Text = ""; break; } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sdr != null) { sdr.Close(); } if (regCheck == true) { //cmdInsert.Connection.Open(); await cmdInsert.ExecuteNonQueryAsync(); //cmdInsert.Connection.Close(); loginTextBox.Text = ""; passwordTextBox.Text = ""; //Здесь надо сделать выход!!!!!!!!!!!!!!!!!!!!!! } } sqlConnection.Close(); AuthorizationForm authorizationForm = new AuthorizationForm(); authorizationForm.Size = this.Size; authorizationForm.Left = this.Left; authorizationForm.Top = this.Top; authorizationForm.Show(); this.Hide(); } } }