protected void ctlDelete_Click(object sender, EventArgs e) { foreach (GridViewRow row in ctlUserGrid.Rows) { if ((row.RowType == DataControlRowType.DataRow) && (((CheckBox)row.FindControl("ctlSelect")).Checked)) { try { long userId = UIHelper.ParseLong(ctlUserGrid.DataKeys[row.RowIndex].Value.ToString()); SuUser user = SuUserService.FindProxyByIdentity(userId); SuUserService.Delete(user); } catch (Exception ex) { if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertInUseData", "alert('This data is now in use.');", true); } } } } // Bind Grid After Delete User Successful. ctlUserGrid.DataBind(); }
protected void ctlConfirm_Click(object sender, EventArgs e) { //Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); try { SuUser user = new SuUser(); user.UserName = ctlUserName.Text; string realPassword = SuUserService.Forgetpassword(ctlUserName.Text); user = SuUserService.FindByUserName(ctlUserName.Text).First <SuUser>(); if (user != null) { UserEngine.SyncUpdateUserData(user.UserName); } SCGEmailService.SendEmailEM12(user.Userid, realPassword.ToString()); //Alert(GetMessage("ForgetPasswordIsComplete")); this.ModalPopupMsg.Show(); HidePopup(); } catch (ServiceValidationException ex) { ValidationErrors.MergeErrors(ex.ValidationErrors); } }
protected void ctlUserForm_ItemInserting(object sender, FormViewInsertEventArgs e) { SuUser user = new SuUser(); user = GetSuUserInfo(user); SuUserService.Save(user); // Cancel insert with DataSource. e.Cancel = true; ctlUserGrid.DataBind(); }
protected void ctlUserForm_ItemUpdating(object sender, FormViewUpdateEventArgs e) { long userId = UIHelper.ParseLong(ctlUserForm.DataKey["UserId"].ToString()); SuUser user = SuUserService.FindByIdentity(userId); user = GetSuUserInfo(user); SuUserService.SaveOrUpdate(user); // Cancel insert with DataSource. e.Cancel = true; ctlUserGrid.DataBind(); }
protected void ctlResetPassword_Click(object sender, EventArgs e) { try { SuUser user = new SuUser(); user = SuUserService.FindByIdentity(UserID); if (user != null) { string realPassword = SuUserService.Forgetpassword(user.UserName); SCGEmailService.SendEmailEM12(user.Userid, realPassword.ToString()); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), string.Empty, string.Format("alert('{0}');", GetProgramMessage("ResetPasswordSuccess")), true); } } catch (ServiceValidationException ex) { ValidationErrors.MergeErrors(ex.ValidationErrors); } }
public static string GetFixedPostingAccountReturnCr(long UserID) { SuUserService suUserService = new SuUserService(); SuUser suUser = suUserService.FindByIdentity(UserID); DbCompanyService dbComService = new DbCompanyService(); DbCompany dbCompany = dbComService.FindByIdentity(suUser.Company.CompanyID); string fixedadvanceAcc = ""; if (dbCompany != null) { //fixedadvanceAcc = "113220"; fixedadvanceAcc = "111250"; } else { //fixedadvanceAcc = "111250"; fixedadvanceAcc = "113220"; } return(fixedadvanceAcc); }
protected void ctlUserGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "UserEdit") { int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; long userId = UIHelper.ParseLong(ctlUserGrid.DataKeys[rowIndex].Value.ToString()); IList <SuUser> userList = new List <SuUser>(); SuUser user = SuUserService.FindByIdentity(userId); userList.Add(user); ctlUserForm.DataSource = userList; ctlUserForm.PageIndex = 0; ctlUserForm.ChangeMode(FormViewMode.Edit); ctlUserForm.DataBind(); UpdatePanelUserForm.Update(); ctlUserModalPopupExtender.Show(); } }
public static Employee GetEmployee(long UserID) { SuUserService suUserService = new SuUserService(); SuUser suUser = suUserService.FindByIdentity(UserID); DbCompanyService dbComService = new DbCompanyService(); DbCompany dbCompany = dbComService.FindByIdentity(suUser.Company.CompanyID); Employee emp = new Employee(); if (suUser != null) { emp.EmployeeID = suUser.EmployeeCode; emp.EmployeeName = suUser.EmployeeName; emp.UserName = suUser.UserName; emp.CostCenterCode = suUser.CostCenterCode; emp.VendorCode = suUser.VendorCode; } else { emp.EmployeeID = string.Empty; emp.EmployeeName = string.Empty; emp.UserName = string.Empty; emp.CostCenterCode = string.Empty; emp.VendorCode = string.Empty; } if (dbCompany != null) { emp.CompanyID = dbCompany.CompanyCode; emp.CompanyName = dbCompany.CompanyName; } else { emp.CompanyID = ""; emp.CompanyName = ""; } return(emp); }
protected void ctlInsert_Click1(object sender, ImageClickEventArgs e) { try { if (Mode == FlagEnum.NewFlag) { #region Insert user = new SuUser(); user.UserName = ctlUserProfileId.Text; user.PeopleID = ctlUserProfilePeopleId.Text; user.SetFailTime = UIHelper.ParseShort(ctlSetFailTime.Text); user.EmployeeCode = ctlUserProfileEmployeeCode.Text; user.EmployeeName = ctlUserProfileEmployeeName.Text; user.SMSApproveOrReject = ctlApproveRecject.Checked; user.SMSReadyToReceive = ctlToReceive.Checked; user.MobilePhoneNo = ctlUserProfileMobilePhoneNo.Text; user.SectionName = ctlUserProfileSectionName.Text; user.PersonalLevel = ctlUserProfilePersonalLevel.Text; user.PersonalDescription = ctlUserProfilePersonalLevelDescription.Text; user.PersonalGroup = ctlUserProfilePersonalGroup.Text; user.PersonalLevelGroupDescription = ctlUserProfilePersonalGroupDescription.Text; user.PositionName = ctlUserProfilePositionName.Text; user.PhoneNo = ctlUserProfilePhoneNo.Text; user.Email = ctlUserProfileEmail.Text; user.ApprovalFlag = ctlUserProfileApprovalFlag.Checked; user.Active = ctlUserProfileActive.Checked; user.Language = new SS.DB.DTO.DbLanguage(UIHelper.ParseShort(ctlCmbLanguage.SelectedValue)); user.ChangePassword = ctlChangePassword.Checked; user.IsAdUser = ctlIsAdUser.Checked; user.VendorCode = ctlVendorCode.Text; user.EmailActive = ctlEmailActive.Checked; DbCompany com = ScgDbQueryProvider.DbCompanyQuery.FindByIdentity(UIHelper.ParseLong(ctlCompanyField.CompanyID)); if (com != null) { user.CompanyCode = com.CompanyCode; user.Company = com; } if (ctlLocationField.LocationID != null) { DbLocation location = ScgDbQueryProvider.DbLocationQuery.FindProxyByIdentity(ctlLocationField.LocationID.Value); if (location != null) { user.LocationCode = location.LocationCode; user.Location = location; } } DbCostCenter cost = ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(UIHelper.ParseLong(ctlCostCenterField.CostCenterId)); if (cost != null) { user.CostCenter = cost; user.CostCenterCode = cost.CostCenterCode; } if (ctlSupervisor.UserID != null) { SuUser su = QueryProvider.SuUserQuery.FindProxyByIdentity(ctlSupervisor.UserID.Value); if (su != null) { user.Supervisor = su.Userid; } } user.UpdBy = UserAccount.UserID; user.UpdDate = DateTime.Now; user.CreBy = UserAccount.UserID; user.CreDate = DateTime.Now; user.UpdPgm = UserAccount.CurrentProgramCode; // ========== Add code for control password same as Password Policy by Anuwat S on 23/04/2009 ========== if (!string.IsNullOrEmpty(ctlUserPassword.Text)) { user.Password = Encryption.Md5Hash(ctlUserPassword.Text); } user.AllowPasswordChangeDate = DateTime.Now.AddDays(ParameterServices.MinPasswordAge); user.PasswordExpiryDate = DateTime.Now.AddDays(ParameterServices.MaxPasswordAge); if (ctlLockUser.Checked) { user.FailTime = user.SetFailTime; } else { user.FailTime = 0; } // ======== End add code for control password same as Password Policy by Anuwat S on 23/04/2009 ======== SuUserService.SaveUserProfile(user); // ========== Add code for control password same as Password Policy by Anuwat S on 23/04/2009 ========== SCGEmailService.SendEmailEM08(user.Userid, ctlUserPassword.Text); #endregion Insert } else if (Mode == FlagEnum.EditFlag) { #region Edit user = QueryProvider.SuUserQuery.FindByIdentity(UserID); user.UserName = ctlUserProfileId.Text; user.PeopleID = ctlUserProfilePeopleId.Text; user.SetFailTime = UIHelper.ParseShort(ctlSetFailTime.Text); user.EmployeeCode = ctlUserProfileEmployeeCode.Text; user.EmployeeName = ctlUserProfileEmployeeName.Text; user.SMSApproveOrReject = ctlApproveRecject.Checked; user.SMSReadyToReceive = ctlToReceive.Checked; user.MobilePhoneNo = ctlUserProfileMobilePhoneNo.Text; user.SectionName = ctlUserProfileSectionName.Text; user.PersonalLevel = ctlUserProfilePersonalLevel.Text; user.PersonalDescription = ctlUserProfilePersonalLevelDescription.Text; user.PersonalGroup = ctlUserProfilePersonalGroup.Text; user.PersonalLevelGroupDescription = ctlUserProfilePersonalGroupDescription.Text; user.PositionName = ctlUserProfilePositionName.Text; user.PhoneNo = ctlUserProfilePhoneNo.Text; user.Email = ctlUserProfileEmail.Text; user.ApprovalFlag = ctlUserProfileApprovalFlag.Checked; user.Active = ctlUserProfileActive.Checked; user.Language = new SS.DB.DTO.DbLanguage(UIHelper.ParseShort(ctlCmbLanguage.SelectedValue)); user.ChangePassword = ctlChangePassword.Checked; user.IsAdUser = ctlIsAdUser.Checked; user.VendorCode = ctlVendorCode.Text; user.EmailActive = ctlEmailActive.Checked; DbCompany com = ScgDbQueryProvider.DbCompanyQuery.FindByIdentity(UIHelper.ParseLong(ctlCompanyField.CompanyID)); if (com != null) { user.CompanyCode = com.CompanyCode; user.Company = com; } if (ctlLocationField.LocationID != null) { DbLocation location = ScgDbQueryProvider.DbLocationQuery.FindProxyByIdentity(ctlLocationField.LocationID.Value); if (location != null) { user.LocationCode = location.LocationCode; user.Location = location; } } DbCostCenter cost = ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(UIHelper.ParseLong(ctlCostCenterField.CostCenterId)); if (cost != null) { user.CostCenter = cost; user.CostCenterCode = cost.CostCenterCode; } if (ctlSupervisor.UserID != null) { SuUser su = QueryProvider.SuUserQuery.FindProxyByIdentity(ctlSupervisor.UserID.Value); if (su != null) { user.Supervisor = su.Userid; } } user.UpdBy = UserAccount.UserID; user.UpdDate = DateTime.Now; user.CreBy = UserAccount.UserID; user.CreDate = DateTime.Now; user.UpdPgm = UserAccount.CurrentProgramCode; // ========== Add code for control password same as Password Policy by Anuwat S on 23/04/2009 ========== if ((int.Parse(ctlOriginFailTime.Value) <= (user.FailTime) && !ctlLockUser.Checked) || !user.SetFailTime.Equals(short.Parse(ctlOriginFailTime.Value))) { user.FailTime = 0; // Unlock user } else if (ctlLockUser.Checked) { user.FailTime = user.SetFailTime; // Still lock user } // ========== Add code for control password same as Password Policy by Anuwat S on 23/04/2009 ========== //SuUserService.SaveOrUpdate(user); SuUserService.UpdateUserProfile(user); #endregion Edit } // ========== Add code for control password same as Password Policy by Anuwat S on 23/04/2009 ========== IList <SuPasswordHistory> passwordHistoryList = QueryProvider.SuPasswordHistoryQuery.FindActiveByUserId(user.Userid); foreach (SuPasswordHistory passwordHist in passwordHistoryList) { passwordHist.Active = false; passwordHist.UpdBy = UserAccount.UserID; passwordHist.UpdDate = DateTime.Now; passwordHist.UpdPgm = ProgramCode; SuPasswordHistoryService.SaveOrUpdate(passwordHist); } // ========== Add code for control password same as Password Policy by Anuwat S on 23/04/2009 ========== if (Notify_Ok != null) { Notify_Ok(sender, e); } Alert(GetMessage("SaveSuccessFully")); } catch (ServiceValidationException ex) { ValidationErrors.MergeErrors(ex.ValidationErrors); ctlUpdatePanelUserProfileForm.Update(); } }
protected void ctlUserProfile_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = 0; InvisibleAllPopUpcontrol(); if (e.CommandName.Equals("Approver")) { rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; UId = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString()); Approver.Initialize(UId); Approver.ShowDetail(); // แก้ไขการกด link ในกริด ที่จะเป็น Editor มาในหน้าเดียวกัน ไม่ต้องทำการ CountAndBind จะทำให้ไม่เกิด Event ในการกด Link ครั้งต่อไป //ctlUserProfileGrid.DataCountAndBind(); } if (e.CommandName.Equals("Initiator")) { rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; UId = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString()); Initiator.Initialize(UId); Initiator.ShowDetail(); //Approver.CloseApproverGrid(); } if (e.CommandName.Equals("Group")) { rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; UId = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString()); UserGroup.Initialize(UId); UserGroup.ShowDetail(); ctlUpdatePanelInformation.Update(); } if (e.CommandName.Equals("UserProfileMethodEdit")) { rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; UId = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString()); ctlAddEditPopup.Initialize(FlagEnum.EditFlag, UId); //ctlAddEditPopup.ShowPopUp(); ShowPopUp(); } if (e.CommandName.Equals("UserProfileMethodDelete")) { try { rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; UId = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString()); SuUser userprofile = QueryProvider.SuUserQuery.FindByIdentity(UId); SuUserService.DeleteUser(userprofile); } catch (Exception ex) { if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertInUseData", "alert('This data is now in use.');", true); ctlUserProfileGrid.DataCountAndBind(); } } ctlUserProfileGrid.DataCountAndBind(); } ctlUserProfileGrid.SelectedIndex = rowIndex; ctlUserGridUpdatePanel.Update(); ctlUpdatePanelInformation.Update(); }
public string SignIn(string userName, string password) { SuUser user = QueryProvider.SuUserQuery.GetSuUserByUserName(userName); if (user == null) { SaveTosuUserLog(userName, "Invalid UserName", null); return("InvalidUserIdOrPassword"); } Dictionary <string, DateTime> dict = GetUserDict(); if (!SuUserService.IsPrivilege(user)) { if ((dict.Count) >= ParameterServices.LimitLoginUserAmount) { if (UserSession.CurrentUserLanguageID.Equals(1)) { return("ขณะนี้ ผู้ใช้งานบนระบบมีจำนวนเกินกว่าที่กำหนดไว้ กรุณารอสักครู่ และทำการ login ใหม่อีกครั้ง."); } else { return("The number of concurrent users is exceeds the configured value. Please wait for a while and login again."); } } } int returnValue = 0; if (user.SetFailTime < user.FailTime) { SaveTosuUserLog(userName, "Account Locked", null); return("UserAccountIsLocked"); } else if (user.IsAdUser) { returnValue = LoginWithActiveDirectory(userName, password); if (returnValue == 0) { ResetFailTime(user.Userid); return(SignIn(user)); } else if (returnValue == 1) { return(LoginFail(user)); } else if (returnValue == 3) { SaveTosuUserLog(userName, "Invalid UserName", null); return("InvalidUserIdOrPassword");; } else if (returnValue == 4) { return("UnableToLogin_FoundMultipleAccount"); } } else { if (LoginWithDataBase(user, password)) { ResetFailTime(user.Userid); return(SignIn(user)); } else { return(LoginFail(user)); } } return(string.Empty); }
string SignIn(SuUser user) { string strResult = string.Empty; if (user == null) { return(strResult); } if (!user.IsAdUser && user.PasswordExpiryDate.HasValue) { if (user.PasswordExpiryDate.Value <= DateTime.Today) { strResult = "PasswordExpired"; SaveTosuUserLog(user.UserName, "Password Expired", null); return(strResult); } } if (!user.IsAdUser && user.ChangePassword) { strResult = "RequiredChangePassword"; } if (string.IsNullOrEmpty(strResult)) { strResult = "success"; bool IsPrivilege = SuUserService.IsPrivilege(user); Dictionary <string, DateTime> dict = GetUserDict(); if (System.Web.HttpContext.Current != null) { if (!dict.ContainsKey(System.Web.HttpContext.Current.Session.SessionID)) { lock (dict) { dict.Add(System.Web.HttpContext.Current.Session.SessionID, DateTime.Now); } } } } UserSession userSession = getUserSessionList(user.Userid, user.Language.Languageid); // Create SessoinID move to setUserSession this.DeleteUserSession(user.Userid); DateTime TimeStamp = DateTime.Now; //string SessoinId1 = SS.Standard.Utilities.Encryption.Md5Hash(user.Userid + TimeStamp.ToString()); string SessoinId = string.Empty; if (System.Web.HttpContext.Current != null) { SessoinId = System.Web.HttpContext.Current.Session.SessionID; //insert & update sessionID setUserSession(user.Userid, SessoinId, TimeStamp); userSession.SessionID = SessoinId; } //clear oldsession timeout (move to job) //this.SessionTimeOut(); bool isApproveVerifyPayment = false; bool isApproveVerifyDocument = false; bool isVerifyDocument = false; bool isVerifyPayment = false; bool isCounterCashier = false; bool isReceiveDocument = false; List <UserRoles> userRoles = userSession.UserRole; #region Set isApproveVerifyDocument //isApproveVerifyDocument foreach (UserRoles item in userRoles) { if (item.ApproveVerifyDocument) { isApproveVerifyDocument = item.ApproveVerifyDocument; break; } } userSession.IsApproveVerifyDocument = isApproveVerifyDocument; #endregion #region Set isApproveVerifyPayment foreach (UserRoles item in userRoles) { if (item.ApproveVerifyPayment) { isApproveVerifyPayment = item.ApproveVerifyPayment; break; } } userSession.IsApproveVerifyPayment = isApproveVerifyPayment; #endregion #region Set isVerifyDocument foreach (UserRoles item in userRoles) { if (item.VerifyDocument) { isVerifyDocument = item.VerifyDocument; break; } } userSession.IsVerifyDocument = isVerifyDocument; #endregion #region Set isVerifyPayment foreach (UserRoles item in userRoles) { if (item.VerifyPayment) { isVerifyPayment = item.VerifyPayment; break; } } userSession.IsVerifyPayment = isVerifyPayment; #endregion #region Set isReceiveDocument foreach (UserRoles item in userRoles) { if (item.ReceiveDocument) { isReceiveDocument = item.ReceiveDocument; break; } } userSession.IsReceiveDocument = isReceiveDocument; #endregion #region Set isCounterCashier foreach (UserRoles item in userRoles) { if (item.CounterCashier) { isCounterCashier = item.CounterCashier; break; } } userSession.IsCounterCashier = isCounterCashier; #endregion userSession.IsAccountant = false; userSession.IsPayment = false; #region Set IsAccountant if (isVerifyDocument || isReceiveDocument || isApproveVerifyDocument) { userSession.IsAccountant = true; } #endregion #region Set IsPayment if (isApproveVerifyPayment || isVerifyPayment || isCounterCashier) { userSession.IsPayment = true; } #endregion userSession.IsAuthenticated = true; UserSession = userSession; #region Set IsAdmin foreach (UserRoles item in userRoles) { if (item.RoleID.Equals(1)) { userSession.IsAdmin = true; break; } } #endregion #region Set IsAllowMultipleApprovePayment foreach (UserRoles item in userRoles) { if (item.AllowMultipleApprovePayment) { userSession.IsAllowMultipleApprovePayment = item.AllowMultipleApprovePayment; break; } } userSession.IsVerifyPayment = isVerifyPayment; #endregion #region Set IsAllowMultipleApproveAccountant foreach (UserRoles item in userRoles) { if (item.AllowMultipleApproveAccountant) { userSession.IsAllowMultipleApproveAccountant = item.AllowMultipleApproveAccountant; break; } } userSession.IsVerifyPayment = isVerifyPayment; #endregion // set usersession to HttpContext/Thread if (System.Web.HttpContext.Current != null) { System.Web.HttpContext.Current.Session[SessionEnum.WebSession.UserProfiles.ToString()] = userSession; // Edit By Kookkla // For Insert Data To SuUserLog System.Web.HttpRequest currentRequest = System.Web.HttpContext.Current.Request; string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipAddress == null || ipAddress.ToLower() == "unknown") { ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"]; } SuUser suUser = new SuUserService().FindByIdentity(userSession.UserID); SaveTosuUserLog(user.UserName, "Success", userSession.SessionID); SuStatisticService.IncreaseUser(); //Dictionary<string, DateTime> dict = GetUserDict(); //if (!SuUserService.IsPrivilege(user)) //{ // if ((dict.Count) > ParameterServices.LimitLoginUserAmount) // { // RemoveUserDict(); // if (UserSession.CurrentUserLanguageID.Equals(1)) // { // strResult = "ขณะนี้ ผู้ใช้งานบนระบบมีจำนวนเกินกว่าที่กำหนดไว้ กรุณารอสักครู่ และทำการ login ใหม่อีกครั้ง."; // } // else // { // strResult = "The number of concurrent users is exceeds the configured value. Please wait for a while and login again."; // } // } //} } return(strResult); }