First I have a table UserAccounts with Column LoginStatus if the user logged in the user loginstatus = 1 else if he logged out it is = 0
what code do you think that will handle if the user accidentally plug off the computer or a power failure occurs. i need to change the loginstatus = 0 or it will auto logout if those events occurs.
by the way im using sql server
i've used this code in form closing but it only change the loginstatus if i shutdown computer from start menu directly while the application is running
private void MPTestTablesFormClosing(object sender, FormClosingEventArgs e)
{
if(e.CloseReason == CloseReason.WindowsShutDown)
{
var repo = new UserAccountsRepo();
var backRepo = new UserLogRepo();
var logs = new UserLogs
{
UserAccount = Globals.UserAccount,
LogOutTime = DateTime.Now
};
Globals.UserAccount.LogStatus = 0;
repo.Update(Globals.UserAccount);
backRepo.Update(logs);
Globals.UserAccount = null;
}
}