protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); if (e.CloseReason == CloseReason.WindowsShutDown) { return; } // Confirm user wants to close switch (MessageBox.Show(this, "Are you sure you want to close?", "Closing", MessageBoxButtons.YesNo)) { case DialogResult.No: e.Cancel = true; break; default: CurrentUser.Online = false; objUser_DL.Update_OnlineState(CurrentUser); if (Origin == 0) { Application.Exit(); } else { this.Close(); } break; } }
private void button1_Click(object sender, EventArgs e) { User objUser = new User(); User_BL objUserBL = new User_BL(ConnectionStringClass.GetConnection()); try { objUser = objUserBL.Login(txtUserName.Text, txtPassword.Text); if (objUser.UserID == 0) { MessageBox.Show(this, "Invalid User Name or Password,Contact System Administrator for more information", "Incorrect User Name or Password", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { if (objUser.LastLoggedIn.ToString() == "1/1/0001 12:00:00 AM") { frmChangePassword objFrm = new frmChangePassword(objUser, 0); //Production.BatchFile.frmBatchFile objFrm = new MRP_GUI.Production.BatchFile.frmBatchFile(objUser); objFrm.Show(); this.Hide(); } else { User_DL objUser_DL = new User_DL(ConnectionStringClass.GetConnection()); int y = objUser_DL.CheckForPasswordExpiry(objUser); if (y == 1) { frmChangePassword objFrm = new frmChangePassword(objUser, 0); //Production.BatchFile.frmBatchFile objFrm = new MRP_GUI.Production.BatchFile.frmBatchFile(objUser); objFrm.Show(); this.Hide(); } else { if (objUser.Online == true) { MessageBox.Show(this, "This User has already Logged-In. Please Contact System Administrator", "Already Logged-In", MessageBoxButtons.OK); } else { MRP_Main objFrm = new MRP_Main(objUser); //Production.BatchFile.frmBatchFile objFrm = new MRP_GUI.Production.BatchFile.frmBatchFile(objUser); objFrm.Show(); this.Hide(); objUser.Online = true; objUser_DL.Update_OnlineState(objUser); } } } } } catch (Exception ex) { MessageBox.Show(this, "Database error, " + ex.Message, "Logging Failure", MessageBoxButtons.OK, MessageBoxIcon.Information); } }