Beispiel #1
0
        private void Admin_Button_Click(object sender, RoutedEventArgs e)
        {
            // Create a login window
            LoginWindowViewModel viewmodel   = new LoginWindowViewModel();
            LoginWindow          loginWindow = new LoginWindow(viewmodel)
            {
                Owner = this
            };

            loginWindow.ShowDialog();

            if (viewmodel.Admin == null)
            {
                return;
            }

            // If login was successful then create the adminwindow
            AdminMainWindow adminWindow = new AdminMainWindow(viewmodel.Admin.UserId.Value)
            {
                Owner = this
            };

            adminWindow.Closed += (sender2, e2) => { Show(); };

            Hide();
            adminWindow.Show();
        }
Beispiel #2
0
        private void Admin_Button_Click(object sender, RoutedEventArgs e)
        {
            // Create a login window
            LoginWindowViewModel loginVM;
            LoginWindow          loginWindow = new LoginWindow(loginVM = new LoginWindowViewModel())
            {
                Owner = this
            };

            loginWindow.ShowDialog();

            // Check if a valid username and password was set in the view model by the login window
            if (loginVM.UserName != null && loginVM.PassWord != null)
            {
                // Get the admin employee with such username and password
                Admin admin = GetAdmin(loginVM.UserName, loginVM.PassWord);

                // Check such admin exist
                if (admin == null)
                {
                    MessageBox.Show("Incorrect login information", "Error", MessageBoxButton.OK);
                    return;
                }

                // Create a new admin window
                AdminMainWindow adminWindow = new AdminMainWindow(admin.UserId.Value);

                // handle the closed event of the admin window to restore the main window
                adminWindow.Closed += (sender2, e2) => { Show(); };

                // hide main window, and show admin window
                Hide();
                adminWindow.Show();
            }
        }