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; } }
private void frmMainUser_FormClosing(object sender, FormClosingEventArgs e) { Log log = userLogBus.getUserLog(userStatic).Last(); TimeSpan t = DateTime.Now - log.LoginTime.Value; double time = Convert.ToDouble(t.TotalHours); Log newLog = new Log() { ID = log.ID, LogOutTime = DateTime.Now, LoginTime = log.LoginTime, IDUser = log.IDUser, }; DialogResult dr = MessageBox.Show("Exit", "Are you exit?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { userLogBus.updateLog(newLog); frmMainUser mainUser = new frmMainUser(); mainUser.Close(); } }