Exemplo n.º 1
0
 private void btnLogIn_Click(object sender, RoutedEventArgs e)
 {
     using (var ctx = new finalContext())
     {
         if (txtUsername.Text == "" || txtPassword.Password == "")
         {
             MessageBox.Show("Please input username/password");
             return;
         }
         var ctr = ctx.Users.Where(x => x.Username == txtUsername.Text).Count();
         if (ctr > 0)
         {
             var usr = ctx.Users.Where(x => x.Username == txtUsername.Text).First();
             if (usr.Employee.Position.PositionName != "Administrator")
             {
                 MessageBox.Show("Only the administrator is allowed to activate the system.");
                 return;
             }
             else
             {
                 var c = ctx.Users.Where(x => x.Username == txtUsername.Text && x.Password == txtPassword.Password).Count();
                 if (c > 0)
                 {
                     var st = ctx.State.Find(1);
                     st.iState = 0;
                     ctx.SaveChanges();
                     MessageBox.Show("System has been successfuly activated.");
                     wpfLogin frm = new wpfLogin();
                     frm.ShowDialog();
                     this.Close();
                 }
             }
         }
         else
         {
             MessageBox.Show("Incorrect admin information.");
             return;
         }
     }
 }
Exemplo n.º 2
0
 private void ListBoxItem_Selected_2(object sender, RoutedEventArgs e)
 {
     try
     {
         wpfLogin frm = new wpfLogin();
         frm.Show();
         this.Close();
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
 }