public bool numberUser() { bool status = false; DataTable NumUser = new DataTable(); ACMSDAL.TblTerminalUser UserLog = new TblTerminalUser(); NumUser = UserLog.ValidLogin(); if (NumUser.Rows.Count < 100) { status = true; } else { //int Limit = 5; int Now = DateTime.Now.Minute; int Loged; //int DeathTime; for (int i = 0; i <= NumUser.Rows.Count - 1; i++) { Loged = Convert.ToDateTime(NumUser.Rows[i]["SessionTime"]).Minute; if ((Now > Loged && Now - Loged > 5) || (Loged > Now && (Now + 60 - Loged) > 5)) { UserLog.StrTerminalUserCode = NumUser.Rows[i]["strTerminalUserCode"].ToString(); UserLog.UpdateSession(false, DateTime.Now); status = true; } } } return(status); }
private void btnLogin_Click(System.Object sender, System.EventArgs e) { /* * MethodInvoker myProcessStarter = new MethodInvoker(InitialDigSignature); * * myProcessStarter.BeginInvoke(null, null); */ if (this.txtUsername.Text == "" | this.txtPassword.Text == "") { ACMS.Utils.UI.ShowErrorMessage(this, "Empty Username & Password!", "Error"); progressBar1.Value = 0; } else { try { ProgressBar(); ACMSLogic.Login.Login login = new ACMSLogic.Login.Login(); //Do.Employee emplogin = login.GetEmployeeByIdAndPassword(this.txtUsername.Text, this.txtPassword.Text); //MessageBox.Show(this, emplogin.Id.ToString()+" "+emplogin.Department.Id+" "+emplogin.RightsLevel.RightsLevelEntrys.Count.ToString()); //Rp.EmployeeRepository er = new Rp.EmployeeRepository(); Do.Employee emp = login.GetEmployeeByIdAndPassword(this.txtUsername.Text, this.txtPassword.Text);//er.GetEmployeeByIdAndPassword(this.txtUsername.Text, this.txtPassword.Text); System.Security.Principal.WindowsIdentity userLogin = System.Security.Principal.WindowsIdentity.GetCurrent(); //System.Security.Principal.WindowsIdentity userLogin = "******"; if (login.Check_Concurrent() == false) { ACMS.Utils.UI.ShowErrorMessage(this, "Number of Login Exceed Users Limit!", "Authorisation"); } else { //Rp.TerminalUserRepository tup = new Rp.TerminalUserRepository(); if (emp != null) { //userLogin.Name="AFPL\EdithGan"; //Rev 6.8.0.0 Determine whether is RoadShow or Terminal. Add in 2 config - RoadShow & RoadShowTerminal Acms.Core.Domain.TerminalUser tu = new Acms.Core.Domain.TerminalUser(); if (ConfigurationSettings.AppSettings["RoadShow"].ToString() == "1") { tu = login.GetTerminalUserByUserId(ConfigurationSettings.AppSettings["RoadShowTerminal"].ToString()) as Acms.Core.Domain.TerminalUser; ACMSLogic.User.RoadShow = "RS";//jackie 13032012 } else { tu = login.GetTerminalUserByUserId(userLogin.Name) as Acms.Core.Domain.TerminalUser; ACMSLogic.User.RoadShow = tu.Branch.Id; } //Acms.Core.Domain.TerminalUser tu = login.GetTerminalUserByUserId("AFPL\\TO-Terminal1") as Acms.Core.Domain.TerminalUser; //Acms.Core.Domain.TerminalUser tu = login.GetTerminalUserByUserId("AFPL\\TO-Terminal2") as Acms.Core.Domain.TerminalUser; //Show AMCS Branch bool Valid = numberUser(); //bool Valid = true; if (emp.CanAccess("AB_LOGIN", tu.Branch.Id) && Valid) { //smell tandas code ACMSDAL.TblTerminalUser UserLog = new TblTerminalUser(); UserLog.StrTerminalUserCode = userLogin.Name; UserLog.UpdateSession(true, DateTime.Now); modInitForms.fLogin.Hide(); ACMSLogic.User.BranchCode = tu.Branch.Id; ACMSLogic.User.EmployeeID = emp.Id; /* * //cbRoadShow.Checked = true; * if (cbRoadShow.Checked) * { * ACMSLogic.User.RoadShow = "RS";//jackie 13032012 * } * else * ACMSLogic.User.RoadShow = tu.Branch.Id;*/ if (emp.Department != null) { ACMSLogic.User.DepartmentID = emp.Department.Id; } if (emp.StrEmployeeName != null) { ACMSLogic.User.EmployeeName = emp.StrEmployeeName; } if (emp.JobPosition.Id != null) { ACMSLogic.User.JobPositionCode = emp.JobPosition.Id; } if (emp.RightsLevel != null) { ACMSLogic.User.RightsLevelID = emp.RightsLevel.Id; } try { //ClassAttendance.CreateClassInstance(); //PackageCode.CreateUnLinkPackage(); } catch (Exception ex) { return; } ACMSLogic.User oUser = new User(); if (modInitForms.fBranch != null) { modInitForms.fBranch.IsLogin = true; modInitForms.fBranch.Close(); modInitForms.fBranch.Dispose(); if (modInitForms.fStaff != null) { modInitForms.fStaff.Close(); modInitForms.fStaff.Dispose(); } if (modInitForms.fManager != null) { modInitForms.fManager.Close(); modInitForms.fManager.Dispose(); } } Thread.Sleep(1000); modInitForms.fBranch = new frmBranch(cmbLanguage.EditValue.ToString()); modInitForms.fBranch.SetEmployeeRecord(emp); modInitForms.fBranch.SetTerminalUser(tu); modInitForms.fBranch.OpenDayShift(); // if (UnclosedShift == true) // MessageBox.Show("There is unclosed shift. Please close the shift."); modInitForms.fBranch.initData(oUser); modInitForms.fBranch.Show(); //DateTime end = DateTime.Now; //TimeSpan diff = end.Subtract(start); //MessageBox.Show(diff.TotalSeconds.ToString(),"Time"); } else if (emp.CanAccess("AB_TIMECARD_LOGIN", tu.Branch.Id)) { modInitForms.fLogin.Hide(); //Show AMCS Time Card if (modInitForms.fTimeCard == null) { modInitForms.fTimeCard = new frmTimeCard(tu.Branch.Id); modInitForms.fTimeCard.Show(); } } else { MessageBox.Show(this, "Invalid username and password or you don't have access to this Branch, please try again"); } } else { MessageBox.Show(this, "Invalid username and password, Please try again"); } } } catch (Exception ex) { return; } } }
private void btnLogin_Click(System.Object sender, System.EventArgs e) { #region Disable Code //Check login information from database // ACMSLogic.User oUser = new User(); // bool chkUserLogin = false; // // chkUserLogin = System.Convert.ToBoolean(oUser.Login(txtUsername.Text, txtPassword.Text)); // // if (chkUserLogin) // { // if (cmbModule.Text == "ACMS Branch") // { // //Show AMCS Branch // if (modInitForms.fBranch == null) // { // modInitForms.fBranch = new frmBranch(); // modInitForms.fBranch.initData(oUser); // modInitForms.fBranch.Show(); // } // // modInitForms.fLogin.Hide(); // } // // if (cmbModule.Text == "ACMS POS") // { // //Show AMCS POS // if (modInitForms.fPOS == null) // { // modInitForms.fPOS = new frmPOS(); // modInitForms.fPOS.Show(); // } // // modInitForms.fLogin.Hide(); // } // // if (cmbModule.Text == "ACMS Staff") // { // //Show AMCS POS // if (modInitForms.fStaff == null) // { // modInitForms.fStaff = new frmStaff(); // modInitForms.fStaff.Show(); // } // // modInitForms.fLogin.Hide(); // } // } // else // { // MessageBox.Show(this, "Incorrect username and password, please try again"); // } #endregion //DateTime start = DateTime.Now; if (this.txtUsername.Text == "" | this.txtPassword.Text == "") { ACMS.Utils.UI.ShowErrorMessage(this, "Empty Username & Password!", "Error"); } else { try { ACMSLogic.Login.Login login = new ACMSLogic.Login.Login(); //Do.Employee emplogin = login.GetEmployeeByIdAndPassword(this.txtUsername.Text, this.txtPassword.Text); //MessageBox.Show(this, emplogin.Id.ToString()+" "+emplogin.Department.Id+" "+emplogin.RightsLevel.RightsLevelEntrys.Count.ToString()); //Rp.EmployeeRepository er = new Rp.EmployeeRepository(); Do.Employee emp = login.GetEmployeeByIdAndPassword(this.txtUsername.Text, this.txtPassword.Text); //er.GetEmployeeByIdAndPassword(this.txtUsername.Text, this.txtPassword.Text); System.Security.Principal.WindowsIdentity userLogin = System.Security.Principal.WindowsIdentity.GetCurrent(); if (login.Check_Concurrent() == false) { ACMS.Utils.UI.ShowErrorMessage(this, "Number of Login Exceed Users Limit!", "Authorisation"); } else { //Rp.TerminalUserRepository tup = new Rp.TerminalUserRepository(); if (emp != null) { Acms.Core.Domain.TerminalUser tu = login.GetTerminalUserByUserId(userLogin.Name) as Acms.Core.Domain.TerminalUser; //tup.GetTerminalUserByUserId(userLogin.Name) as Acms.Core.Domain.TerminalUser; //Show AMCS Branch bool Valid = numberUser(); //bool Valid = true; if (emp.CanAccess("AB_LOGIN", tu.Branch.Id) && Valid) { //smell tandas code ACMSDAL.TblTerminalUser UserLog = new TblTerminalUser(); UserLog.StrTerminalUserCode = userLogin.Name; UserLog.UpdateSession(true, DateTime.Now); modInitForms.fLogin.Hide(); ACMSLogic.User.BranchCode = tu.Branch.Id; ACMSLogic.User.EmployeeID = emp.Id; if (emp.Department != null) { ACMSLogic.User.DepartmentID = emp.Department.Id; } if (emp.StrEmployeeName != null) { ACMSLogic.User.EmployeeName = emp.StrEmployeeName; } if (emp.JobPosition.Id != null) { ACMSLogic.User.JobPositionCode = emp.JobPosition.Id; } if (emp.RightsLevel != null) { ACMSLogic.User.RightsLevelID = emp.RightsLevel.Id; } try { ClassAttendance.CreateClassInstance(); PackageCode.CreateUnLinkPackage(); } catch (Exception ex) { return; } ACMSLogic.User oUser = new User(); if (modInitForms.fBranch != null) { modInitForms.fBranch.IsLogin = true; modInitForms.fBranch.Close(); modInitForms.fBranch.Dispose(); if (modInitForms.fStaff != null) { modInitForms.fStaff.Close(); modInitForms.fStaff.Dispose(); } if (modInitForms.fManager != null) { modInitForms.fManager.Close(); modInitForms.fManager.Dispose(); } } modInitForms.fBranch = new frmBranch(cmbLanguage.EditValue.ToString()); modInitForms.fBranch.SetEmployeeRecord(emp); modInitForms.fBranch.SetTerminalUser(tu); modInitForms.fBranch.OpenDayShift(); // if (UnclosedShift == true) // MessageBox.Show("There is unclosed shift. Please close the shift."); modInitForms.fBranch.initData(oUser); modInitForms.fBranch.Show(); //DateTime end = DateTime.Now; //TimeSpan diff = end.Subtract(start); //MessageBox.Show(diff.TotalSeconds.ToString(),"Time"); } else if (emp.CanAccess("AB_TIMECARD_LOGIN", tu.Branch.Id)) { modInitForms.fLogin.Hide(); //Show AMCS Time Card if (modInitForms.fTimeCard == null) { modInitForms.fTimeCard = new frmTimeCard(tu.Branch.Id); modInitForms.fTimeCard.Show(); } } else { MessageBox.Show(this, "Invalid username and password or you don't have access to this Branch, please try again"); } } else { MessageBox.Show(this, "Invalid username and password, Please try again"); } } } catch (Exception ex) { return; } } }