示例#1
0
        private void UserRoutes_MouseDown(object sender, MouseEventArgs e)
        {
            var userRoutesPage = new UserRoutesPage();

            userRoutesPage.connectionString = connectionString;
            ContentFrame.Navigate(userRoutesPage);
        }
        private void LogInButton_Click(object sender, RoutedEventArgs e)
        {
            ErrorLabel.Content = "";
            string login    = LoginBox.Text;
            string password = PasswordBox.Password;

            if (login != "")
            {
                try
                {
                    connectionString       = "Server=(LocalDB)\\MSSQLLocalDB;Database=PassengerTransportationDB;User Id=" + login + ";Password="******";";
                    owner.connectionString = connectionString;
                    var    connection = new SqlConnection(connectionString);
                    string expression = "IF IS_MEMBER ('db_ddladmin') = 1 SELECT 1 ELSE SELECT 0";

                    connection.Open();
                    var command = new SqlCommand(expression, connection);
                    var isAdmin = command.ExecuteScalar();

                    if ((int)isAdmin == 1)
                    {
                        owner.ContentFrame.Navigate(new WelcomeAdminPage());
                        owner.AdminMenu.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        var userRoutesPage = new UserRoutesPage();
                        userRoutesPage.connectionString = connectionString;
                        owner.ContentFrame.Navigate(userRoutesPage);
                        owner.UserMenu.Visibility = Visibility.Visible;
                    }

                    connection.Close();
                }
                catch
                {
                    ErrorLabel.Content = "Неверный логин или пароль";
                }
            }
        }