private void btnSave_Click(object sender, EventArgs e) { User user = null; if (txtEmail != null || txtFirstName != null || txtLastName != null || txtPassword != null || dtpBirthDate != null) { int count = userBUS.countUser(); int id = count + 1; // string pass = encrypt.MD5Hash(txtPassword.Text); user = new User() { ID = id, Email = txtEmail.Text, LastName = txtLastName.Text, FirstName = txtFirstName.Text, Password = bcrypt.MD5Hash(txtPassword.Text), Birthdate = dtpBirthDate.Value, RoleID = 2, Active = true, OfficeID = Convert.ToInt32(cbbOffice.SelectedValue) }; try { userBUS.addUser(user); this.Hide(); MessageBox.Show("Insert new User is Suscces."); } catch (Exception ex) { MessageBox.Show("Insert new User is not Suscces."); } } }
private void btnLogin_Click(object sender, EventArgs e) { User user = null; try { string passs = bcrypt.MD5Hash(txtPassword.Text); user = userBUS.getUser(txtUserName.Text); if (user != null && user.Password == passs) { if (user.RoleID == 1) { frmMainAdmin mainAdmin = new frmMainAdmin(); this.Hide(); mainAdmin.Show(); } else { UserLogBUS userLog = new UserLogBUS(); this.Hide(); if (userLog.getUserLog(user).ToList().Count() > 0) { if (userLog.getUserLog(user).ToList()[userLog.getUserLog(user).ToList().Count() - 1].LogOutTime == null) { AswLog aswLog = new AswLog(userLog.getUserLog(user).ToList()[userLog.getUserLog(user).ToList().Count() - 1], user); aswLog.Show(); } else { frmMainUser mainUser = new frmMainUser(user); mainUser.Show(); } } else { frmMainUser mainUser = new frmMainUser(user); mainUser.Show(); } } } else { this.txtPassword.Text = ""; this.txtUserName.Text = ""; MessageBox.Show("User Name or Password incorrect."); } } catch (Exception ex) { throw ex; } }