Esempio n. 1
0
        public void Login_Click(object sender, RoutedEventArgs e)
        {
            string user   = UserLogintxt.Text;
            string passwd = UserPassword.Password;

            SqlConnection conn = new SqlConnection
            {
                ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=F:\FIRMAAPPEXE\FIRMAAPP\BIN\DEBUG\SMADB.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
            };

            conn.Open();
            SqlDataReader read;
            string        query2 = ("SELECT Id from Uzytkownicy WHERE Login=@user");

            SqlCommand com = new SqlCommand(query2, conn);

            com.Parameters.AddWithValue("@user", user);
            read = com.ExecuteReader();
            if (read.Read())
            {
                id = read.GetInt32(0);
            }
            read.Close();
            conn.Close();

            conn.Open();
            string     query3 = ("SELECT Stanowiska.Stanowisko from Stanowiska INNER JOIN Uzytkownicy ON  Stanowiska.Id_stanowiska=Uzytkownicy.Id WHERE Uzytkownicy.Login=@user");
            SqlCommand com2   = new SqlCommand(query3, conn);

            com2.Parameters.AddWithValue("@user", user);
            read = com2.ExecuteReader();
            if (read.Read())
            {
                Stanowisko = read.GetString(0);
            }
            read.Close();
            conn.Close();

            conn.Open();
            string     query = "SELECT * FROM Uzytkownicy WHERE Login=@user AND Haslo=@passwd";
            SqlCommand cmd   = new SqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@passwd", passwd);
            cmd.Parameters.AddWithValue("@user", user);

            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows == true)
            {
                MessageBox.Show("Zalogowano poprawnie \n Stanowisko: " + Stanowisko + "\n Twoje id : " + id);
                Panel_glowny menu = new Panel_glowny();
                menu.Show();
                this.Close();
            }

            else
            {
                FailMsg.Visibility = Visibility.Visible;
            }
        }
        private void Back_Click(object sender, RoutedEventArgs e)
        {
            Panel_glowny back = new Panel_glowny();

            back.Show();
            this.Close();
        }
Esempio n. 3
0
        public void Login_Click(object sender, RoutedEventArgs e)
        {
            string user   = UserLogintxt.Text;
            string passwd = UserPassword.Password;

            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|SMA.mdf;Integrated Security=True;Connect Timeout=30";
            conn.Open();
            SqlDataReader read   = (null);
            string        query2 = ("SELECT Stanowisko,Id from Uzytkownicy WHERE Login=@user");
            SqlCommand    com    = new SqlCommand(query2, conn);

            com.Parameters.AddWithValue("@user", user);
            read = com.ExecuteReader();
            if (read.Read())
            {
                Stanowisko = read.GetString(0);
                id         = read.GetInt32(1);
            }

            read.Close();
            conn.Close();
            conn.Open();
            string     query = "SELECT * FROM Uzytkownicy WHERE Login=@user AND Haslo=@passwd";
            SqlCommand cmd   = new SqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@passwd", passwd);
            cmd.Parameters.AddWithValue("@user", user);

            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows == true)
            {
                MessageBox.Show("Zalogowano poprawnie \n Stanowisko: " + Stanowisko + "\n Twoje id : " + id);
                Panel_glowny menu = new Panel_glowny();
                menu.Show();
                this.Close();
            }

            else
            {
                FailMsg.Visibility = Visibility.Visible;
            }
        }