private void loadUserTypes() { IUserService userService = new UserService(); cmbUserRole.DataSource = userService.GetAllUserTypes(); cmbUserRole.DisplayMember = "UsersType"; cmbUserRole.ValueMember = "UserTypeCode"; }
private void butLogin_Click(object sender, EventArgs e) { try { IUserService userService = new UserService(); string message = String.Empty; if (txtPassword.Text.Equals("Enter Password") || txtPassword.Text.Equals(String.Empty) || txtUsername.Text.Equals("Enter Username") || txtUsername.Text.Equals(String.Empty)) { MessageBox.Show(this, "Username and Password is Required", "Required Fields"); } else { if (userService.AuthenticateUser(txtUsername.Text, txtPassword.Text, ref message)) { User u = new User(); u = userService.GetUser(txtUsername.Text); LoggedUser lu = new LoggedUser(); lu.UserId = u.UserId; lu.UserName = u.UserName; lu.LastName = u.LastName; lu.FirstName = u.FirstName; lu.MiddleName = u.MiddleName; lu.UserType = u.UserTypeCode; GlobalClass.UserLoggedIn = true; GlobalClass.user = lu; GlobalClass.currentsy = userService.GetCurrentSy(); GlobalClass.userTypeCode = lu.UserType; ILogService logService = new LogService(); string json = JsonConvert.SerializeObject(lu); Log log = new Log { CLUD = "L", LogDate = DateTime.Now, TableName = "Users", UserId = GlobalClass.user.UserId, UserName = GlobalClass.user.UserName, PassedData = json }; logService.AddLogs(log); Close(); } else MessageBox.Show(this, message, "Login Failed"); } }catch(Exception ex) { MessageBox.Show("Unable to Establish the network connection. Please check if network is connected.", "LogIn Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
private void btnDelete_Click(object sender, EventArgs e) { if (userSelected != null) { IUserService userService = new UserService(); string message = String.Empty; if (!userService.DeleteUser(userSelected.UserId, ref message)) { MessageBox.Show("Deletion of User Failed"); } else { userSelected.Deactivated = true; Log("D", "Users", userSelected); MessageBox.Show("Deleted succesfully!"); } } }
public void LoadUsers() { IUserService userService = new UserService(); string message = String.Empty; try { var users = userService.GetAllUsers(); userList = new List<User>(users); gvUser.DataSource = users; gvUser.Refresh(); if (gvUser.RowCount != 0) gvUser.Rows[0].IsSelected = true; } catch (Exception ex) { message = "Error Loading UserList"; MessageBox.Show(ex.ToString()); } }
private void SaveUser() { try { Boolean ret = false; string message = String.Empty; if (Op.Equals("edit")) { if (!ComparePasswords(oldPassword, txtOldPWD.Text)) { message = "Passwords do not match"; MessageBox.Show("Incorrect old password entered", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (!txtPassword.Text.ToString().Equals(txtRetypePWD.Text.ToString())) { message = "Passwords did not match"; MessageBox.Show("Password did not match"); return; } else { string hashPWD = GenerateKeyHash(txtPassword.Text); IUserService userService = new UserService(); User user = new User() { UserName = txtUsername.Text, FirstName = txtFirstName.Text, LastName = txtLastName.Text, MiddleName = txtMiddleName.Text, Password = hashPWD, UserTypeCode = cmbUserRole.SelectedValue.ToString() }; if (Op.Equals("edit")) { user.UserId = SelectedUser.UserId; if (!String.IsNullOrEmpty(txtPassword.Text)) user.Password = hashPWD; else user.Password = oldPassword; ret = userService.UpdateUser(ref user, ref message); Log("U", "Users", user); } else { ret = userService.CreateUser(ref user, ref message); Log("C", "Users", user); } } MessageBox.Show("Saved Successfully!"); Close(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } }