private void Btnzaloguj_Click(object sender, RoutedEventArgs e) { PanelAdmin pane = new PanelAdmin(); MessageBox.Show("Cześć Admin!", "Zalogowano"); pane.ShowDialog(); this.Close(); }
private void Btnzaloguj_Click(object sender, RoutedEventArgs e) { try { if (txtboxlog.Text == "Admin" && txtboxpsw.Password == "patrykszymon") { PanelAdmin pane = new PanelAdmin(datasource, catalog); MessageBox.Show("Cześć Admin!", "Zalogowano"); pane.ShowDialog(); this.Close(); } else { SqlConnectionStringBuilder pol = new SqlConnectionStringBuilder(); pol.DataSource = datasource; pol.InitialCatalog = catalog; pol.IntegratedSecurity = true; con = new SqlConnection(pol.ConnectionString); SqlParameter login = new SqlParameter("@login", txtboxlog.Text); string zapytanie = "select logg,haslo from Osoby where logg=@login and Ranga='Admin'"; com = new SqlCommand(zapytanie, con); com.Parameters.Add(login); con.Open(); SqlDataReader red = com.ExecuteReader(); if (red.HasRows) { while (red.Read()) { if (red.GetValue(0).ToString() == txtboxlog.Text && red.GetValue(1).ToString() == txtboxpsw.Password) { con.Close(); PanelAdmin pane = new PanelAdmin(datasource, catalog); MessageBox.Show("Cześć Admin!", "Zalogowano"); pane.ShowDialog(); this.Close(); break; } else { MessageBox.Show("Błędne hasło", "Błąd logowania"); } } } else { MessageBox.Show("Błędny login"); } con.Close(); } } catch (Exception exc) { MessageBox.Show(exc.Message, "xx"); } }