private void btLogin_Click(object sender, RoutedEventArgs e) { try { if (Globals.Validator.IsValidShortName(tbLoginName.Text) && Globals.Validator.LoginName_Check(tbLoginName.Text)) { loginUser = Globals.simpleJiraDB.Users.Where(u => u.LoginName == tbLoginName.Text).FirstOrDefault(); if (loginUser != null) { string pwd = SecurePassword.Decrypt(loginUser.PWDEncrypted); if (tbPassword.Password.Equals(pwd)) { LoginCallback?.Invoke(loginUser); this.Close(); new MainWindow(loginUser).ShowDialog(); } else { new MessageBoxCustom("Password Incorrect", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } } } else { new MessageBoxCustom("User not exist", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } } catch (SqlException ex) { new MessageBoxCustom("Error Login into system:\n" + ex.Message, MessageBoxCustom.MessageType.Error, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } }
private void btUpdateMyAccount_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(tbLoginName.Text) || string.IsNullOrEmpty(tbFirstName.Text) || string.IsNullOrEmpty(tbLastName.Text) || string.IsNullOrEmpty(tbRole.Text) || string.IsNullOrEmpty(tbEmail.Text) || string.IsNullOrEmpty(tbPassword.Password)) { new MessageBoxCustom("Please input value", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (!Globals.Validator.IsValidEmail(tbEmail.Text)) { new MessageBoxCustom("Please input correct email address", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (!Globals.Validator.IsValidPassword(tbPassword.Password)) { new MessageBoxCustom("Password length Must be 8-12 characters", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } User myAccount = Globals.simpleJiraDB.Users.Include("Team").Where(u => u.UserId == currentUserInDialog.UserId).FirstOrDefault <User>(); if (myAccount != null) { myAccount.LoginName = tbLoginName.Text; myAccount.FirstName = tbFirstName.Text; myAccount.LastName = tbLastName.Text; myAccount.EMAIL = tbEmail.Text; myAccount.Role = tbRole.Text; myAccount.PWDEncrypted = SecurePassword.Encrypt(tbPassword.Password); Globals.simpleJiraDB.SaveChanges(); new MessageBoxCustom("My Account Updated", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); ResetAndLoadDataFromDB(); //if (currentUserInDialog != null) //{ // this.DialogResult = true; //TeamUserUpdateCallback?.Invoke(currentUserInDialog); //} } else { new MessageBoxCustom("Cannot find this user to update", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } } catch (DbUpdateException ex) { new MessageBoxCustom("User Login Name must be unique", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); Debug.WriteLine(ex.ToString()); } catch (SqlException ex) { new MessageBoxCustom("Error Updating User into database:\n" + ex.Message, MessageBoxCustom.MessageType.Error, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } }
private void btSignup_Click(object sender, RoutedEventArgs e) { try { if (Blank_Check()) { new MessageBoxCustom("Please input all fields", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (Globals.Validator.LoginName_Check(tbLoginName.Text)) { new MessageBoxCustom("Login Name exists already, please choose another one", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (!Globals.Validator.IsValidEmail(tbEmail.Text)) { new MessageBoxCustom("Please input correct email address", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (!Globals.Validator.IsValidPassword(tbPassword.Password) || !Globals.Validator.IsValidPassword(tbConfirmPassword.Password)) { new MessageBoxCustom("Password length Must be 8-12 characters", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (!Globals.Validator.IsValidShortName(cmbTeamList.Text) || !Globals.Validator.IsValidShortName(cmbRoleList.Text) || !Globals.Validator.IsValidShortName(tbFirstName.Text) || !Globals.Validator.IsValidShortName(tbLastName.Text) || !Globals.Validator.IsValidShortName(tbLoginName.Text)) { new MessageBoxCustom("Length Must 1-50 Characters", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else if (!Globals.Validator.Password_Check(tbPassword.Password, tbConfirmPassword.Password)) { new MessageBoxCustom("Please confirm the same password", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); return; } else { signupUser = new User { LoginName = tbLoginName.Text, FirstName = tbFirstName.Text, LastName = tbLastName.Text, TeamId = Globals.Validator.Team_Check(cmbTeamList.Text), EMAIL = tbEmail.Text, PWDEncrypted = SecurePassword.Encrypt(tbConfirmPassword.Password), Role = cmbRoleList.Text }; Globals.simpleJiraDB.Users.Add(signupUser); Globals.simpleJiraDB.SaveChanges(); new MessageBoxCustom("New User Registered", MessageBoxCustom.MessageType.Info, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } if (signupUser != null) { this.DialogResult = true; SignupCallback?.Invoke(signupUser); this.Close(); } } catch (SqlException ex) { new MessageBoxCustom("Error saving data into database:\n" + ex.Message, MessageBoxCustom.MessageType.Error, MessageBoxCustom.MessageButtons.Ok).ShowDialog(); } }