private void PBLogin_Click(object sender, System.EventArgs e) { timer1.Enabled = true; progressBar.Visible = true; progressBar.Maximum = 10; progressBar.Step = 1; if (Query.Check(tbLogin.Text, tbPassword.Text)) { this.Hide(); MainForm mainForm = new MainForm(); mainForm.ShowDialog(); this.Close(); } tbError.Visible = true; }
private void btnIn_Click(object sender, EventArgs e) { userName = tbName.Text; password = tbPassword.Text; prbControl.Visible = true; lbContol.Visible = true; SqlConnection connection = new SqlConnection(); try { connection.ConnectionString = @"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = Authorization; Integrated Security = True; Connect Timeout=5"; connection.Open(); string sql = string.Format("SELECT Id FROM Users WHERE Login = '******' AND Password='******'", userName, password); SqlCommand command = new SqlCommand(sql, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.Read() == false) { lbError.Visible = true; prbControl.Visible = false; lbContol.Visible = false; } else { lbError.Visible = false; prbControl.Visible = false; lbContol.Visible = false; Id = Convert.ToInt32(reader["Id"]); reader.Close(); MainForm mnForm = new MainForm(Id); mnForm.ShowDialog(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { // Закрываем соединение connection.Close(); } }
public static void CheckLoginPassword(string CurrentLogin, string CurrentPassword) { try { bool access_denied_1 = true; bool access_denied_2 = true; ConnectionToDB.Open(); string CommandString = @"SELECT Name,Password,InfoId FROM Users"; SqlCommand command_test = new SqlCommand(CommandString, ConnectionToDB); SqlDataReader reader = command_test.ExecuteReader(); while (reader.Read() != false) { string NameTemp = reader.GetString(0).Replace(" ", ""); string PasswordTemp = reader.GetString(1).Replace(" ", ""); if (CurrentLogin == NameTemp) { access_denied_1 = false; } if (CurrentPassword == PasswordTemp) { access_denied_2 = false; } if (!access_denied_1 && !access_denied_2) { string test_string = reader[2].ToString(); MessageBox.Show(Properties.Resources.Welcome + " " + NameTemp + "!"); command_test.CommandText = @"SELECT FirstName,LastName,Adres,Phone,Code FROM UsersInfo WHERE Id=" + reader[2].ToString(); reader.Close(); SqlDataReader reader_2 = command_test.ExecuteReader(); reader_2.Read(); string FirstNameBuf = @"Фамилия:" + reader_2.GetString(0).Replace(" ", ""); string LastNameBuf = @"Имя:" + reader_2.GetString(1).Replace(" ", ""); string AdressBuf = @"Адрес:"; if (!reader_2.IsDBNull(2)) { AdressBuf = AdressBuf + reader_2.GetString(2).Replace(" ", ""); } else { AdressBuf = AdressBuf + @" -"; } string PhoneBuf = @"Телефон:"; if (!reader_2.IsDBNull(3)) { PhoneBuf = PhoneBuf + reader_2.GetString(3).Replace(" ", ""); } else { PhoneBuf = PhoneBuf + @" -"; } string CodeBuf = @"Код:" + reader_2.GetInt32(4).ToString(); MainForm NewMainForm = new MainForm(LastNameBuf + "\r\n" + FirstNameBuf + "\r\n" + AdressBuf + "\r\n" + PhoneBuf + "\r\n" + CodeBuf); NewMainForm.ShowDialog(); break; } else { access_denied_1 = true; access_denied_2 = true; } } if (access_denied_1 && access_denied_2) { MessageBox.Show(@"Доступ запрещен!", @"Результат.", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show(@"Не удалось получить доступ к базе данных! Наиболее вероятная причина - неверная строка подключения или отсутствие таковой в конфигурационном файле приложения.", @"Ошибка.", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (ConnectionToDB.State == ConnectionState.Open) ConnectionToDB.Close(); } }