Example #1
0
 private void WykButt_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Global.liczba_probek = Int32.Parse(Liczba_probek_textbox.Text.ToString());
         Global.zakres_od     = Int32.Parse(Zakres_od_textbox.Text.ToString());
         Global.zakres_do     = Int32.Parse(Zakres_do_textbox.Text.ToString());
         Window3 wyk = new Window3();
         wyk.ShowDialog();
     }catch (Exception ex)
     {
         MessageBox.Show("Wypelnij wszystkie pola" + ex.Message);
     }
 }
        private void ZalogujBTN_Click(object sender, RoutedEventArgs e)
        {
            string        connection = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ProjektWPF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection sqlConn    = new SqlConnection(connection);

            try
            {
                if (sqlConn.State == ConnectionState.Closed)
                {
                    sqlConn.Open();

                    string     query   = "SELECT COUNT(1) FROM Użytkownik WHERE Loginx=@Loginx AND Passwordx=@Passwordx";
                    SqlCommand command = new SqlCommand(query, sqlConn);
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@Loginx", LoginTB.Text);
                    command.Parameters.AddWithValue("@Passwordx", PasswordTB.Text);
                    int count = Convert.ToInt32(command.ExecuteScalar());

                    if (count == 1)
                    {
                        Window3 wnd3 = new Window3();
                        wnd3.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Podany login lub hasło są nieprawidłowe. Spróbuj jeszcze raz!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                sqlConn.Close();
            }
        }