public EmployeeAuthorizationsWithOwnerInfoOfDataExamined InitialAuthorizationResult(bool isTopPageOfOperation, EmployeeAuthorizations authorizations) { EmployeeAuthorizationsWithOwnerInfoOfDataExamined authAndOwner = new EmployeeAuthorizationsWithOwnerInfoOfDataExamined(authorizations); if (!isTopPageOfOperation) { // get owner info for config-form using (EmployeeAuthorityDataAccess empAuthDao = new EmployeeAuthorityDataAccess()) { string empAccount = empAuthDao.GetEmployeeAccountOfId(qsEmpId); string dbErrMsg = empAuthDao.GetErrMsg(); if (!string.IsNullOrEmpty(empAccount)) { accountOfData = empAccount; EmployeeForBackend empData = empAuthDao.GetEmployeeDataForBackend(empAccount); dbErrMsg = empAuthDao.GetErrMsg(); if (empData != null) { authAndOwner.OwnerAccountOfDataExamined = empData.OwnerAccount; authAndOwner.OwnerDeptIdOfDataExamined = empData.OwnerDeptId; } } } } return(authAndOwner); }
/// <summary> /// 取得員工資料 /// </summary> public EmployeeForBackend GetEmployeeData(int empId) { EmployeeForBackend entity = null; using (EmployeeAuthorityDataAccess empAuthDao = new EmployeeAuthorityDataAccess()) { entity = empAuthDao.GetEmployeeDataForBackend(empId); dbErrMsg = empAuthDao.GetErrMsg(); } return(entity); }
protected void btnSubmit_Click(object sender, EventArgs e) { Master.ShowErrorMsg(""); txtCheckCode.Text = ""; if (!IsValid) { return; } txtAccount.Text = txtAccount.Text.Trim(); txtEmail.Text = txtEmail.Text.Trim(); // check account EmployeeForBackend emp = empAuth.GetEmployeeData(txtAccount.Text); if (emp == null) { Master.ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(要求重置密碼)帳號不存在,輸入帳號[{0}] .(requires reset password)Account doesn't exist! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } //擋 role-guest if (emp.RoleName == "guest") { Master.ShowErrorMsg(Resources.Lang.ErrMsg_RoleGuestIsNotAllowedToUse); return; } //檢查是否停權 if (emp.IsAccessDenied) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_AccountUnavailable); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(要求重置密碼)帳號停用,帳號[{0}] .(requires reset password)Account is denied! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } //檢查上架日期 if (string.Compare(txtAccount.Text, "admin", true) != 0) // 不檢查帳號 admin { DateTime startDate = emp.StartDate.Value.Date; DateTime endDate = emp.EndDate.Value.Date; DateTime today = DateTime.Today; if (today < startDate || endDate < today) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_AccountUnavailable); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(要求重置密碼)帳號超出有效範圍,帳號[{0}] .(requires reset password)Account validation date is out of range! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } } string empAccount = emp.EmpAccount; string empName = emp.EmpName; string email = emp.Email; // check email if (string.Compare(txtEmail.Text, email, true) != 0) { Master.ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(要求重置密碼)Email 不正確,輸入帳號[{0}] Email[{1}] .(requires reset password)Wrong Email! Account[{0}] Email[{1}]", txtAccount.Text, txtEmail.Text), IP = c.GetClientIP() }); return; } //產生驗證用唯一值 string passwordResetKey = Guid.NewGuid().ToString(); bool result = false; result = empAuth.UpdateEmployeePasswordResetKey(empAccount, passwordResetKey); if (result) { //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = empAccount, Description = ".要求重置密碼 .Requires reset password", IP = c.GetClientIP() }); // Email notice if (empName.Trim() == "") { empName = empAccount; } UserInfo userInfo = new UserInfo() { EmpAccount = empAccount, EmpName = empName, Email = email, EmailConfirmKey = passwordResetKey }; bool sentResult = false; if (LangManager.Instance.GetCultureName(c.qsLangNo.ToString()) == LangManager.CultureNameZHTW) { sentResult = SendNoticeMailToUserZhTw(userInfo); } else { sentResult = SendNoticeMailToUserEn(userInfo); } if (sentResult) { StringBuilder sbScript = new StringBuilder(200); sbScript.AppendFormat("window.alert('{0}!');", Resources.Lang.PswRequire_Success).AppendLine(); sbScript.AppendFormat("window.location='{0}?l={1}';", FormsAuthentication.LoginUrl, c.qsLangNo).AppendLine(); ClientScript.RegisterStartupScript(GetType(), "", sbScript.ToString(), true); } else { c.LoggerOfUI.Error(string.Format("Account[{0}] Email[{1}] send notice mail to user failed.", empAccount, email)); Master.ShowErrorMsg(Resources.Lang.ErrMsg_PswRequireSendFailed); } } else { Master.ShowErrorMsg(Resources.Lang.ErrMsg_PrepareEmailException); } }
protected void btnSubmit_Click(object sender, EventArgs e) { Master.ShowErrorMsg(""); txtCheckCode.Text = ""; if (!IsValid) { return; } txtAccount.Text = txtAccount.Text.Trim(); txtPassword.Text = txtPassword.Text.Trim(); txtNewPsw.Text = txtNewPsw.Text.Trim(); if (string.IsNullOrEmpty(hidEmpAccountOfToken.Text)) { //登入驗證 EmployeeToLogin empVerify = empAuth.GetEmployeeDataToLogin(txtAccount.Text); if (empVerify == null && empAuth.GetDbErrMsg() != "") { //異常錯誤 Master.ShowErrorMsg(string.Format("{0}: {1}", Resources.Lang.ErrMsg_Exception, empAuth.GetDbErrMsg())); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".變更密碼驗證時發生異常錯誤,帳號[{0}] .An exception error occurred during change password verification! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } //判斷是否有資料 if (empVerify == null) { //沒資料 Master.ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(變更密碼)帳號不存在,輸入帳號[{0}] .(change password)Account doesn't exist! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } //有資料 //擋 role-guest if (empVerify.RoleName == "guest") { Master.ShowErrorMsg(Resources.Lang.ErrMsg_RoleGuestIsNotAllowedToUse); return; } //檢查密碼 string passwordHash = HashUtility.GetPasswordHash(txtPassword.Text); string empPassword = empVerify.EmpPassword; bool isPasswordCorrect = false; if (empVerify.PasswordHashed) { isPasswordCorrect = (passwordHash == empPassword); } else { isPasswordCorrect = (txtPassword.Text == empPassword); } if (!isPasswordCorrect) { Master.ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(變更密碼)密碼錯誤,帳號[{0}] .(change password)Password is incorrect! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } //檢查是否停權 if (empVerify.IsAccessDenied) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_AccountUnavailable); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(變更密碼)帳號停用,帳號[{0}] .(change password)Account is denied! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } //檢查上架日期 if (string.Compare(txtAccount.Text, "admin", true) != 0) // 不檢查帳號 admin { DateTime startDate = empVerify.StartDate.Value.Date; DateTime endDate = empVerify.EndDate.Value.Date; DateTime today = DateTime.Today; if (today < startDate || endDate < today) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_AccountUnavailable); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(變更密碼)帳號超出有效範圍,帳號[{0}] .(change password)Account validation date is out of range! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } } } else if (string.Compare(txtAccount.Text, hidEmpAccountOfToken.Text.Trim(), true) != 0) { Master.ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 string description = string.Format(".(變更密碼)來自[{0}]重置密碼連結但是輸入錯誤帳號,輸入值[{1}] .(change password)From [{0}] reset password link but enter the wrong account! Input[{1}]", hidEmpAccountOfToken.Text, txtAccount.Text); empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = description, IP = c.GetClientIP() }); return; } //記錄登入時間與IP empAuth.UpdateEmployeeLoginInfo(txtAccount.Text, c.GetClientIP()); //確認可登入後,取得員工資料 EmployeeForBackend emp = empAuth.GetEmployeeData(txtAccount.Text); if (emp == null && empAuth.GetDbErrMsg() != "") { //異常錯誤 Master.ShowErrorMsg(string.Format("{0}: {1}", Resources.Lang.ErrMsg_Exception, empAuth.GetDbErrMsg())); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".(變更密碼)帳號登入取得使用者資料時發生異常錯誤,帳號[{0}] .(change password)An exception error occurred during obtaining user profile! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); return; } string empAccount = emp.EmpAccount; string empName = emp.EmpName; string email = emp.Email; bool result = empAuth.UpdateEmployeePassword(empAccount, HashUtility.GetPasswordHash(txtNewPsw.Text)); if (result) { if (!string.IsNullOrEmpty(hidEmpAccountOfToken.Text)) { //清除Email驗證用唯一值 empAuth.UpdateEmployeePasswordResetKey(hidEmpAccountOfToken.Text, ""); } //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = empAccount, Description = ".變更密碼 .Change password", IP = c.GetClientIP() }); // Email notice if (empName.Trim() == "") { empName = empAccount; } UserInfo userInfo = new UserInfo() { EmpAccount = empAccount, EmpName = empName, Email = email }; bool sentResult = false; if (LangManager.Instance.GetCultureName(c.qsLangNo.ToString()) == LangManager.CultureNameZHTW) { sentResult = SendNoticeMailToUserZhTw(userInfo); } else { sentResult = SendNoticeMailToUserEn(userInfo); } if (!sentResult) { c.LoggerOfUI.Error(string.Format("Account[{0}] Email[{1}] send notice mail to user failed.", empAccount, email)); } StringBuilder sbScript = new StringBuilder(200); sbScript.AppendFormat("window.alert('{0}!');", Resources.Lang.PswChange_Success).AppendLine(); sbScript.AppendFormat("window.location='{0}?l={1}';", FormsAuthentication.LoginUrl, c.qsLangNo).AppendLine(); ClientScript.RegisterStartupScript(GetType(), "", sbScript.ToString(), true); } else { Master.ShowErrorMsg(Resources.Lang.ErrMsg_ChangePasswordException); } }
protected void rptAccounts_ItemDataBound(object sender, RepeaterItemEventArgs e) { EmployeeForBackend empData = (EmployeeForBackend)e.Item.DataItem; int empId = empData.EmpId; string empAccount = empData.EmpAccount; string roleName = empData.RoleName; bool isAccessDenied = empData.IsAccessDenied; DateTime startDate = empData.StartDate.Value; DateTime endDate = empData.EndDate.Value; string remarks = (empData.Remarks ?? "").Trim(); HtmlGenericControl ctlRoleDisplayName = (HtmlGenericControl)e.Item.FindControl("ctlRoleDisplayName"); ctlRoleDisplayName.InnerHtml = empData.RoleDisplayName; ctlRoleDisplayName.Attributes["class"] = "RoleDisplay-" + roleName; HtmlTableRow EmpArea = (HtmlTableRow)e.Item.FindControl("EmpArea"); if (isAccessDenied) { HtmlGenericControl ctlIsAccessDenied = (HtmlGenericControl)e.Item.FindControl("ctlIsAccessDenied"); ctlIsAccessDenied.Attributes["title"] = Resources.Lang.Status_AccessDenied; ctlIsAccessDenied.Visible = true; EmpArea.Attributes["class"] = "table-danger"; } HtmlGenericControl ctlAccountState = (HtmlGenericControl)e.Item.FindControl("ctlAccountState"); if (DateTime.Today < startDate && empAccount != "admin") { // on schedule ctlAccountState.Attributes["class"] = "fa fa-hourglass-start fa-lg text-info"; ctlAccountState.Attributes["title"] = Resources.Lang.Status_OnSchedule; } else if (endDate < DateTime.Today && empAccount != "admin" || isAccessDenied) { // offline ctlAccountState.Attributes["class"] = "fa fa-ban fa-lg text-danger"; ctlAccountState.Attributes["title"] = Resources.Lang.Status_AccessDeniedOrExpired; EmpArea.Attributes["class"] = "table-danger"; } else { // online ctlAccountState.Attributes["title"] = Resources.Lang.Status_Normal; } Literal ltrValidDateRange = (Literal)e.Item.FindControl("ltrValidDateRange"); ltrValidDateRange.Text = string.Format("{0:yyyy-MM-dd} ~ {1:yyyy-MM-dd}", startDate, endDate); if (remarks != "") { HtmlGenericControl ctlRemarks = (HtmlGenericControl)e.Item.FindControl("ctlRemarks"); ctlRemarks.Attributes["title"] = remarks; ctlRemarks.Visible = true; } HtmlAnchor btnEdit = (HtmlAnchor)e.Item.FindControl("btnEdit"); btnEdit.Attributes["onclick"] = string.Format("popWin('Account-Config.aspx?act={0}&empid={1}', 700, 600); return false;", ConfigFormAction.edit, empId); btnEdit.Title = Resources.Lang.Main_btnEdit_Hint; Literal ltrEdit = (Literal)e.Item.FindControl("ltrEdit"); ltrEdit.Text = Resources.Lang.Main_btnEdit; LinkButton btnDelete = (LinkButton)e.Item.FindControl("btnDelete"); btnDelete.CommandArgument = string.Join(",", empId.ToString(), empAccount); btnDelete.Text = "<i class='fa fa-trash-o'></i> " + Resources.Lang.Main_btnDelete; btnDelete.ToolTip = Resources.Lang.Main_btnDelete_Hint; btnDelete.OnClientClick = string.Format("return confirm('" + Resources.Lang.Account_ConfirmDelete_Format + "');", empData.EmpName, empData.EmpAccount); string ownerAccount = empData.OwnerAccount; int ownerDeptId = empData.OwnerDeptId; btnEdit.Visible = (empAuth.CanEditThisPage(false, ownerAccount, ownerDeptId) || c.IsMyAccount(empAccount)); if (!empAuth.CanDelThisPage(ownerAccount, ownerDeptId) || empAccount == "admin" || empAccount == c.GetEmpAccount()) { btnDelete.Visible = false; } }
protected void btnLogin_Click(object sender, EventArgs e) { txtCheckCode.Text = ""; if (!IsValid) { return; } txtAccount.Text = txtAccount.Text.Trim(); txtPassword.Text = txtPassword.Text.Trim(); //登入驗證 EmployeeToLogin empVerify = empAuth.GetEmployeeDataToLogin(txtAccount.Text); if (empVerify == null && empAuth.GetDbErrMsg() != "") { //異常錯誤 ShowErrorMsg(string.Format("{0}: {1}", Resources.Lang.ErrMsg_Exception, empAuth.GetDbErrMsg())); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".帳號登入驗證時發生異常錯誤,帳號[{0}] .An exception error occurred during login verification! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); //檢查登入失敗次數,是否顯示驗證圖 CheckLoginFailedCountToShowCaptcha(true); return; } //判斷是否有資料 if (empVerify == null) { //沒資料 ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".帳號不存在,輸入帳號[{0}] .Account doesn't exist! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); //檢查登入失敗次數,是否顯示驗證圖 CheckLoginFailedCountToShowCaptcha(true); return; } //有資料 //檢查密碼 string passwordHash = HashUtility.GetPasswordHash(txtPassword.Text); string empPassword = empVerify.EmpPassword; bool isPasswordCorrect = false; if (empVerify.PasswordHashed) { isPasswordCorrect = (passwordHash == empPassword); } else { isPasswordCorrect = (txtPassword.Text == empPassword); } if (!isPasswordCorrect) { ShowErrorMsg(ACCOUNT_FAILED_ERRMSG); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".密碼錯誤,帳號[{0}] .Password is incorrect! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); //檢查登入失敗次數,是否顯示驗證圖 CheckLoginFailedCountToShowCaptcha(true); return; } //檢查是否停權 if (empVerify.IsAccessDenied) { ShowErrorMsg(Resources.Lang.ErrMsg_AccountUnavailable); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".帳號停用,帳號[{0}] .Account is denied! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); //檢查登入失敗次數,是否顯示驗證圖 CheckLoginFailedCountToShowCaptcha(true); return; } //檢查上架日期 if (string.Compare(txtAccount.Text, "admin", true) != 0) // 不檢查帳號 admin { DateTime startDate = empVerify.StartDate.Value.Date; DateTime endDate = empVerify.EndDate.Value.Date; DateTime today = DateTime.Today; if (today < startDate || endDate < today) { ShowErrorMsg(Resources.Lang.ErrMsg_AccountUnavailable); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".帳號超出有效範圍,帳號[{0}] .Account validation date is out of range! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); //檢查登入失敗次數,是否顯示驗證圖 CheckLoginFailedCountToShowCaptcha(true); return; } } //記錄登入時間與IP empAuth.UpdateEmployeeLoginInfo(txtAccount.Text, c.GetClientIP()); //確認可登入後,取得員工資料 EmployeeForBackend emp = empAuth.GetEmployeeData(txtAccount.Text); if (emp == null && empAuth.GetDbErrMsg() != "") { //異常錯誤 ShowErrorMsg(string.Format("{0}: {1}", Resources.Lang.ErrMsg_Exception, empAuth.GetDbErrMsg())); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = "", Description = string.Format(".帳號登入取得使用者資料時發生異常錯誤,帳號[{0}] .An exception error occurred during obtaining user profile! Account[{0}]", txtAccount.Text), IP = c.GetClientIP() }); //檢查登入失敗次數,是否顯示驗證圖 CheckLoginFailedCountToShowCaptcha(true); return; } //清除登入失敗次數 c.seLoginFailedCount = 0; DateTime thisLoginTime = DateTime.MinValue, lastLoginTime = DateTime.MinValue; if (emp.ThisLoginTime.HasValue) { thisLoginTime = emp.ThisLoginTime.Value; } if (emp.LastLoginTime.HasValue) { lastLoginTime = emp.LastLoginTime.Value; } LoginEmployeeData loginEmpData = new LoginEmployeeData() { EmpId = emp.EmpId, EmpName = emp.EmpName, Email = emp.Email, DeptId = emp.DeptId, DeptName = emp.DeptName, RoleId = emp.RoleId, RoleName = emp.RoleName, RoleDisplayName = emp.RoleDisplayName, StartDate = emp.StartDate.Value, EndDate = emp.EndDate.Value, EmpAccount = emp.EmpAccount, ThisLoginTime = thisLoginTime, ThisLoginIP = emp.ThisLoginIP, LastLoginTime = lastLoginTime, LastLoginIP = emp.LastLoginIP }; c.SaveLoginEmployeeDataIntoSession(loginEmpData); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = c.GetEmpAccount(), Description = ".登入系統! .Logged in!", IP = c.GetClientIP() }); //記錄指定語系 c.seLangNoOfBackend = c.qsLangNo; //設定已登入 FormsAuthentication.RedirectFromLoginPage(c.seLoginEmpData.EmpAccount, false); /* 需要帶入額外參數時使用 * if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) * { * FormsAuthentication.SetAuthCookie(c.seLoginEmpData.EmpAccount, false); * Response.Redirect(FormsAuthentication.DefaultUrl + "?l=" + c.qsLangNo.ToString()); * } */ }
private void DisplayAccountData() { bool isOwner = false; int curRoleId = 0; if (c.qsAct == ConfigFormAction.edit) { EmployeeForBackend account = empAuth.GetEmployeeData(c.qsEmpId); if (account != null) { string empAccount = account.EmpAccount; //account txtEmpAccount.Text = account.EmpAccount; txtEmpAccount.Enabled = false; //name txtEmpName.Text = account.EmpName; //password rfvPsw.Enabled = false; hidEmpPasswordOri.Text = account.EmpPassword; hidPasswordHashed.Text = account.PasswordHashed.ToString(); hidDefaultRandomPassword.Text = account.DefaultRandomPassword; //email txtEmail.Text = account.Email; //remarks txtRemarks.Text = account.Remarks; // is access denied chkIsAccessDenied.Checked = account.IsAccessDenied; ltrIsAccessDenied.Text = chkIsAccessDenied.Checked ? Resources.Lang.Account_IsAccessDenied_Checked : Resources.Lang.Account_IsAccessDenied_Unchecked; //valid date txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", account.StartDate.Value); txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", account.EndDate.Value); ltrDateRange.Text = txtStartDate.Text + " ~ " + txtEndDate.Text; if (empAccount == "admin") { DateRangeArea.Visible = false; } //department ddlDept.SelectedValue = account.DeptId.ToString(); if (ddlDept.SelectedItem != null) { ltrDept.Text = ddlDept.SelectedItem.Text; } //role curRoleId = account.RoleId; ddlRoles.SelectedValue = curRoleId.ToString(); ltrRoles.Text = account.RoleDisplayText; //owner txtOwnerAccount.Text = account.OwnerAccount; ltrOwnerAccount.Text = txtOwnerAccount.Text; isOwner = empAuth.CanEditThisPage(false, account.OwnerAccount, account.OwnerDeptId); //modification info ltrPostAccount.Text = account.PostAccount; ltrPostDate.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", account.PostDate); if (account.MdfDate.HasValue) { ltrMdfAccount.Text = account.MdfAccount; ltrMdfDate.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", account.MdfDate.Value); } btnSave.Visible = true; } } else { //add txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Today); DateTime endDate = DateTime.Today.AddYears(10); txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", endDate); txtOwnerAccount.Text = c.GetEmpAccount(); ltrOwnerAccount.Text = txtOwnerAccount.Text; isOwner = true; btnSave.Visible = true; } // owner privilege if (isOwner) { chkIsAccessDenied.Visible = true; ltrIsAccessDenied.Visible = false; DateRangeEditCtrl.Visible = true; ltrDateRange.Visible = false; ddlDept.Visible = true; ltrDept.Visible = false; ddlRoles.Visible = true; ltrRoles.Visible = false; } // role-admin privilege if (c.IsInRole("admin")) { //owner txtOwnerAccount.Visible = true; ltrOwnerAccount.Visible = false; } else { // only role-admin can assigns role-admin to another (但是,保留已經是role-admin的選項) if (curRoleId != 1) { ListItem liAdmin = ddlRoles.Items.FindByValue("1"); if (liAdmin != null) { ddlRoles.Items.Remove(liAdmin); } } } }