/// <summary> /// Communicates with server and exchange login info. /// Upon successful login of normal user, it shows a popup /// Upon successful login of admin user, it shows a popup + load admin panel /// If login credentials are not correct, it shows a popup reporting this /// </summary> private void TryLogin() { try { ServiceReference.ServiceClient login = new ServiceReference.ServiceClient(); bool isFound = login.MakeLogin(UserNameTextBox.Text, EncodedPassword); if (isFound == false) { MessageBox.Show("User Not Found"); } else { if (isFound == true && UserNameTextBox.Text == "admin") { MessageBox.Show($"Successfull Login. Welcome {UserNameTextBox.Text}!"); AdminWindow adminWindow = new AdminWindow(); adminWindow.Show(); } if (isFound == true && UserNameTextBox.Text != "admin") { MessageBox.Show($"Successfull Login. Welcome {UserNameTextBox.Text}!"); } } } catch (Exception err) { MessageBox.Show($"Error while trying to login in client side: {err}"); } }
private void button_Click(object sender, RoutedEventArgs e) { mitoden_dbgr13Entities db = new mitoden_dbgr13Entities(); List<Person1> mylist = new List<Person1>(); try { mylist = db.Person1.ToList(); for (int i = 0; i < mylist.Count; i++) { if (UserNameTextBox.Text == mylist[i].PK_Username && PasswordBox.Password == mylist[i].Password) { if (mylist[i].trueorfalse == true) { AdminWindow adw = new AdminWindow(); adw.Show(); } if (mylist[i].trueorfalse == false) { StatisticsWindow stw = new StatisticsWindow(UserNameTextBox.Text); stw.Show(); } this.Hide(); UserNameTextBox.Text = ""; PasswordBox.Password = ""; return; } else { } } MessageBox.Show("Invalid Username or Password. Please try again."); } catch (Exception) { MessageBox.Show("Error"); } }
// Same as ShowMainWindow but for the AdminWindow private void ShowAdminWindow() { if (AdminWindow != null && !AdminWindow.Dispatcher.CheckAccess()) { AdminWindow.Dispatcher.BeginInvoke((Action)ShowAdminWindow); } else { if (!AdminWindowShown) { AdminWindow = new AdminWindow(Connection, CurrentUser); AdminWindow.Closed += (s, o) => AdminWindowShown = false; AdminWindow.Show(); AdminWindowShown = true; } else { AdminWindow.Activate(); } } }
// Same as ShowMainWindow but for the AdminWindow private void ShowAdminWindow() { if (AdminWindow != null && !AdminWindow.Dispatcher.CheckAccess()) AdminWindow.Dispatcher.BeginInvoke((Action)ShowAdminWindow); else { if (!AdminWindowShown) { AdminWindow = new AdminWindow(Connection, CurrentUser); AdminWindow.Closed += (s, o) => AdminWindowShown = false; AdminWindow.Show(); AdminWindowShown = true; } else AdminWindow.Activate(); } }
private void LogInAnswer(IAsyncResult ar) { networkStream.EndRead(ar); byte[] dataLogInAnswer = (byte[])ar.AsyncState; IFormatter formatter = new BinaryFormatter(); TrueMessage trueMessageFromServer = new TrueMessage(); using (MemoryStream memoryStream = new MemoryStream(dataLogInAnswer)) { trueMessageFromServer = (TrueMessage)formatter.Deserialize(memoryStream); } if (trueMessageFromServer.Command == Command.Approve) { Disconnect(); if ((string)trueMessageFromServer.Message == "Student") { Application.Current.Dispatcher.Invoke((Action) delegate { string login = UsernameTextBox.Text; StudentWindow dashBoard = new StudentWindow(login); dashBoard.Show(); this.Close(); }); } else if ((string)trueMessageFromServer.Message == "Teacher") { Application.Current.Dispatcher.Invoke((Action) delegate { string login = UsernameTextBox.Text; TeacherWindow dashBoard = new TeacherWindow(login); dashBoard.Show(); this.Close(); }); } else if ((string)trueMessageFromServer.Message == "Admin") { Application.Current.Dispatcher.Invoke((Action) delegate { string login = UsernameTextBox.Text; AdminWindow dashBoard = new AdminWindow(login); dashBoard.Show(); this.Close(); }); } else { MessageBox.Show($"Error message from server. Message: {(string)trueMessageFromServer.Message}", "Error"); } } else if (trueMessageFromServer.Command == Command.Reject) { MessageBox.Show((string)trueMessageFromServer.Message); } else { MessageBox.Show("Received message from server is incorrect.", "Error"); } }