Ejemplo n.º 1
0
 private void Menu_Click(object sender, RoutedEventArgs e)
 {
     if (MainWindow.DefinerMenu)
     {
         UserMenu user = new UserMenu();
         user.Show();
         this.Close();
     }
     else if (!MainWindow.DefinerMenu)
     {
         AdminMenu admin = new AdminMenu();
         admin.Show();
         this.Close();
     }
 }
Ejemplo n.º 2
0
        private void Login_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection  connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=FoodShop;Integrated Security=True");
            SqlDataAdapter sda        = new SqlDataAdapter($"SELECT * FROM REGISTRATION WHERE LOGIN = '******' AND PASSWORD = '******'", connection);
            DataTable      data       = new DataTable();

            sda.Fill(data);

            if (LoginBox.Text == "admin777" && PassBox.Password == "admin777")
            {
                AdminMenu admin = new AdminMenu();
                DefinerMenu = false;
                User        = "******";
                Id          = "77";
                admin.Show();
                this.Close();
            }
            else
            {
                string sqlExpression  = $"SELECT NAME FROM REGISTRATION WHERE LOGIN='******'";
                string sqlExpression2 = $"SELECT ID FROM REGISTRATION WHERE LOGIN='******'";

                using (connection)
                {
                    connection.Open();
                    SqlCommand sqlCommand = new SqlCommand(sqlExpression, connection);
                    User = Convert.ToString(sqlCommand.ExecuteScalar());
                    SqlCommand sqlCommand2 = new SqlCommand(sqlExpression2, connection);
                    Id = Convert.ToString(sqlCommand2.ExecuteScalar());
                }

                if (data.Rows.Count == 1)
                {
                    UserMenu user = new UserMenu();
                    DefinerMenu = true;
                    user.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Неверный логин или пароль!");
                }
            }
        }