private void Button_Click(object sender, RoutedEventArgs e)
        {
            string password = ChangeToString.SecureStringToString(MyPasswordBox.SecurePassword);


            string connectionString = "Data Source=DESKTOP-IURIS93\\MSSQL;Initial Catalog = Bank;User ID=sa;Password=yxofton1;Connect Timeout = 30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";


            SqlConnection connection = new SqlConnection(connectionString);

            connection.Open();

            var        query = "INSERT INTO Klient(Imię,Nazwisko,Hasło) VALUES (@Imię, @Nazwisko, @Hasło)";
            SqlCommand cmd   = new SqlCommand(query, connection);

            cmd.Parameters.AddWithValue("Imię", MyNameTextbox.Text);
            cmd.Parameters.AddWithValue("Nazwisko", MySurnameTextbox.Text);
            cmd.Parameters.AddWithValue("Hasło", password);


            int d = cmd.ExecuteNonQuery();



            if (d != 0)
            {
                MessageBox.Show("Zarejestrowano użytkownika!");
            }
            else
            {
                MessageBox.Show("Błąd");
            }
        }
예제 #2
0
        private void LoginButoon_Click(object sender, RoutedEventArgs e)
        {
            string connectionString = "Data Source=DESKTOP-IURIS93\\MSSQL;Initial Catalog = Bank;User ID=sa;Password=yxofton1;Connect Timeout = 30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";


            string password = ChangeToString.SecureStringToString(LoginPasswordBox.SecurePassword);


            SqlConnection loginconnection = new SqlConnection(connectionString);

            try
            {
                if (loginconnection.State == ConnectionState.Closed)
                {
                    loginconnection.Open();
                    string     query = "SELECT COUNT(1) FROM Klient WHERE Imię=@Imię AND Nazwisko=@Nazwisko AND Hasło=@Hasło";
                    SqlCommand cma   = new SqlCommand(query, loginconnection);
                    cma.CommandType = CommandType.Text;
                    cma.Parameters.AddWithValue("@Imię", LoginNameBox.Text);
                    cma.Parameters.AddWithValue("@Nazwisko", LoginSurnameBox.Text);
                    cma.Parameters.AddWithValue("@Hasło", password);

                    int check = Convert.ToInt32(cma.ExecuteScalar());
                    if (check == 1)
                    {
                        text  = LoginNameBox.Text;
                        textt = LoginSurnameBox.Text;

                        AccountWindow aw = new AccountWindow(text, textt);
                        aw.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Wpisano niepoprawne dane");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                loginconnection.Close();
            }
        }