public void SendDelegationEmail(VehicleManagement model, EmailTemplate EmailTempalte, List <EmployeeInfo> toUsers, string webUrl) { var link = string.Format(@"{0}/Lists/VehicleManagement/EditForm.aspx?subSection=TransportationManagement&ID={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, model.ID); var department = DepartmentListSingleton.GetDepartmentByID(model.CommonDepartment.LookupId, this.SiteUrl); SendEmailActivity sendMailActivity = new SendEmailActivity(); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(EmailTempalte.MailBody); content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", model.Requester.LookupValue); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{4}", department.Name); content = content.Replace("{5}", department.VietnameseName); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, EmailTempalte.MailSubject, toUser.Email, true, false, content); } } catch { } } } }
private List <BusinessTripEmployeeModel> GetBusinessTripEmployeeByParentId(string parentId, int departmentId) { List <BusinessTripEmployeeModel> businessTripEmployeeModelCollection = new List <BusinessTripEmployeeModel>(); int parentIdOut; if (!string.IsNullOrEmpty(parentId) && int.TryParse(parentId, out parentIdOut)) { Department currentDept = DepartmentListSingleton.GetDepartmentByID(departmentId, SPContext.Current.Site.Url); string deptName = CultureInfo.CurrentUICulture.LCID == 1033 ? currentDept.Name : currentDept.VietnameseName; List <BusinessTripEmployeeDetail> businessTripEmployeeDetailCollection = _businessTripEmployeeDetailDAL.GetItemsByParentId(parentIdOut); if (businessTripEmployeeDetailCollection != null) { foreach (BusinessTripEmployeeDetail businessTripEmployeeDetail in businessTripEmployeeDetailCollection) { BusinessTripEmployeeModel businessTripEmployeeModel = ConvertToModel(businessTripEmployeeDetail); businessTripEmployeeModel.DepartmentName = deptName; businessTripEmployeeModelCollection.Add(businessTripEmployeeModel); } } } return(businessTripEmployeeModelCollection); }
/// <summary> /// RequestFormInfo /// </summary> /// <param name="requestItem">The Request SPListItem object.</param> public RequestFormInfo(SPListItem requestItem) { if (requestItem != null) { this.ID = requestItem.ID.ToString(); this.Title = requestItem.Title; #region TFS: 1943 SPFieldLookupValue department = ObjectHelper.GetSPFieldLookupValue(requestItem[StringConstant.RequestsList.CommonDepartmentField]); if (department != null) { var departmentObj = DepartmentListSingleton.GetDepartmentByID(department.LookupId, requestItem.ParentList.ParentWebUrl); this.RequestedBy = string.Format("{0} / {1}", departmentObj.VietnameseName, departmentObj.Name); } #endregion TFS: 1943 SPFieldLookupValue requestType = ObjectHelper.GetSPFieldLookupValue(requestItem[StringConstant.RequestsList.RequestTypeRefField]); if (requestType != null) { this.RequestType = requestType.LookupValue; } SPFieldLookupValue receivedBy = ObjectHelper.GetSPFieldLookupValue(requestItem[StringConstant.RequestsList.ReceviedByField]); if (receivedBy != null) { var receivedDepartmentObj = DepartmentListSingleton.GetDepartmentByID(receivedBy.LookupId, requestItem.ParentList.ParentWebUrl); this.ReceivedBy = string.Format("{0} / {1}", receivedDepartmentObj.VietnameseName, receivedDepartmentObj.Name); } } }
public static EmployeeRole GetCurrentUserRole(EmployeeInfo currentEmployee) { if (currentEmployee != null && currentEmployee.ID > 0) { var adminDept = DepartmentListSingleton.GetDepartmentByCode("HR", SPContext.Current.Web.Url); var adminDeptId = adminDept != null ? adminDept.ID : 0; // 2: Administration & Human Resource if (currentEmployee.Department != null && currentEmployee.Department.LookupId == adminDeptId) { if (currentEmployee.DepartmentPermission != null) { if (currentEmployee.DepartmentPermission.ToLower().Equals("administrators")) { return(EmployeeRole.AdminOfHR); } else if (currentEmployee.DepartmentPermission.ToLower().Equals("contributors")) { return(EmployeeRole.DepartmentHeadOfHR); } } } else if (currentEmployee.EmployeePosition.LookupValue == StringConstant.EmployeePositionName.DepartmentHead) { return(EmployeeRole.DepartmentHead); } else if (IsCurrentUserInGroup(StringConstant.BOD)) { return(EmployeeRole.BOD); } } return(EmployeeRole.Staff); }
private void LoadRqueterInfo() { try { if (ApprovalBaseManagerObject.Creator != null) { this.lblRequester.Text = this.ApprovalBaseManagerObject.Creator.FullName; if (ApprovalBaseManagerObject.Creator.Department != null) { var department = DepartmentListSingleton.GetDepartmentByID(ApprovalBaseManagerObject.Creator.Department.LookupId, this.SiteUrl); if (department != null) { this.lblDepartment.Text = (CultureInfo.CurrentUICulture.LCID == 1066) ? department.VietnameseName : department.Name; } } if (ApprovalBaseManagerObject.Creator.EmployeePosition != null) { var employeePosition = this.employeePositionDAL.GetByID(ApprovalBaseManagerObject.Creator.EmployeePosition.LookupId); if (employeePosition != null) { this.lblPosition.Text = (this.IsVietnameseLanguage) ? employeePosition.VietnameseName : employeePosition.Name; } } } } catch (Exception ex) { ULSLogging.LogError(ex); } }
private void GridTasks_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.DataRow) { var dataItem = e.Row.DataItem as Biz.Models.Delegation; #region Module var litModule = e.Row.FindControl("litModule") as Literal; if (isVietnameseLanguage) { litModule.Text = dataItem.VietnameseModuleName; } else { litModule.Text = dataItem.ModuleName; } #endregion #region Description var litDescription = e.Row.FindControl("litDescription") as Literal; litDescription.Text = dataItem.ListItemDescription; #endregion #region Requester var litRequester = e.Row.FindControl("litRequester") as Literal; litRequester.Text = dataItem.Requester.LookupValue; #endregion #region Department var department = DepartmentListSingleton.GetDepartmentByID(dataItem.Department.LookupId, this.SiteUrl); var litDepartment = e.Row.FindControl("litDepartment") as Literal; if (isVietnameseLanguage) { litDepartment.Text = department.VietnameseName; } else { litDepartment.Text = department.Name; } #endregion #region Created Date var litCreatedDate = e.Row.FindControl("litCreatedDate") as Literal; litCreatedDate.Text = dataItem.ListItemCreatedDate.ToString(StringConstant.DateFormatddMMyyyyhhmmssttt); #endregion } } catch (Exception ex) { ULSLogging.LogError(ex); } }
//public override void ItemUpdated(SPItemEventProperties properties) //{ // base.ItemUpdated(properties); // try // { // //_employeeInfoDAL = new EmployeeInfoDAL(properties.WebUrl); // //var itemId = properties.ListItem.ID; // //string modifiedByName = string.Empty; // //var modifiedByString = Convert.ToString(properties.ListItem["Modified By"]); // //SPFieldUser spUserField = (SPFieldUser)properties.ListItem.Fields.GetField("Modified By"); // //if (spUserField != null) // //{ // // SPFieldUserValue spNewUserFieldValue = (SPFieldUserValue)spUserField.GetFieldValue(modifiedByString); // // SPUser spModifiedByUser = properties.Web.EnsureUser(spNewUserFieldValue.LookupValue); // // var modifiedBy = _employeeInfoDAL.GetByADAccount(spModifiedByUser.ID); // // modifiedByName = modifiedBy != null ? modifiedBy.FullName : string.Empty; // //} // //SendEmailToApprover(properties.Web, itemId, modifiedByName); // } // catch (Exception ex) // { // ULSLogging.Log(new SPDiagnosticsCategory("STADA - Shift Management Event Receiver - ItemUpdated fn", // TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, // string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); // } //} private void SendEmailToApprover(SPWeb web, int itemId, string modifiedBy = "") { EmployeeInfoDAL employeeInfoDAL = new EmployeeInfoDAL(web.Url); EmailTemplateDAL emailTemplateDAL = new EmailTemplateDAL(web.Url); ShiftManagementDAL shiftManagementDAL = new ShiftManagementDAL(web.Url); var shiftManagementItem = shiftManagementDAL.GetByID(itemId); if (shiftManagementItem != null) { SPUser departmentHeadSPUser = web.EnsureUser(shiftManagementItem.ApprovedBy.UserName); var departmentHead = employeeInfoDAL.GetByADAccount(departmentHeadSPUser.ID); if (departmentHead != null) { var requestEmailItem = emailTemplateDAL.GetByKey("ShiftManagement_Request"); if (requestEmailItem != null) { string emailBody = HTTPUtility.HtmlDecode(requestEmailItem.MailBody); if (!string.IsNullOrEmpty(departmentHead.Email) && !string.IsNullOrEmpty(emailBody)) { string link = string.Format("{0}/SitePages/ShiftApproval.aspx?itemId={1}&Source={0}/_layouts/15/RBVH.Stada.Intranet.WebPages/ShiftManagement/ShiftManagementManager.aspx", web.Url, shiftManagementItem.ID); var department = DepartmentListSingleton.GetDepartmentByID(shiftManagementItem.Department.LookupId, web.Url); emailBody = string.Format(emailBody, departmentHead.FullName, string.IsNullOrEmpty(modifiedBy) ? shiftManagementItem.Requester.LookupValue : modifiedBy, shiftManagementItem.Month, shiftManagementItem.Year, shiftManagementItem.Department.LookupValue, department.VietnameseName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(web.Url, requestEmailItem.MailSubject, departmentHead.Email, true, false, emailBody); List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(web.Url, departmentHead.ID, StringConstant.ShiftManagementList.ListUrl, shiftManagementItem.ID); link = string.Format("{0}/SitePages/ShiftApproval.aspx?subSection=ShiftManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", web.Url, shiftManagementItem.ID); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { emailBody = HTTPUtility.HtmlDecode(requestEmailItem.MailBody); emailBody = string.Format(emailBody, toUser.FullName, string.IsNullOrEmpty(modifiedBy) ? shiftManagementItem.Requester.LookupValue : modifiedBy, shiftManagementItem.Month, shiftManagementItem.Year, shiftManagementItem.Department.LookupValue, department.VietnameseName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(web.Url, requestEmailItem.MailSubject, toUser.Email, true, false, emailBody); } } catch { } } } } } } } }
/// <summary> /// Loading requester info /// </summary> private void LoadRqueterInfo() { if (ApprovalBaseManagerObject.Creator != null) { this.lblRequester.Text = this.ApprovalBaseManagerObject.Creator.FullName; var department = DepartmentListSingleton.GetDepartmentByID(ApprovalBaseManagerObject.Creator.Department.LookupId, this.SiteUrl); if (department != null) { this.lblDepartment.Text = this.IsVietnameseLanguage ? department.VietnameseName : department.Name; } } }
public BusinessTripManagementApprover CreateApprovalList(int departmentId, int locationId) { BusinessTripManagementApprover businessTripManagementApprover = new BusinessTripManagementApprover(); EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(this.SiteUrl); // Department Head var departmentHead = _employeeInfoDAL.GetByPositionDepartment(Constants.StringConstant.EmployeePosition.DepartmentHead, departmentId, locationId); if (departmentHead.Count > 0) { businessTripManagementApprover.Approver1 = departmentHead[0]; } // Direct BOD if (businessTripManagementApprover.Approver1 != null && businessTripManagementApprover.Approver1.Manager != null && businessTripManagementApprover.Approver1.Manager.LookupId > 0) { var directBODInfo = _employeeInfoDAL.GetByID(businessTripManagementApprover.Approver1.Manager.LookupId); if (directBODInfo != null) { businessTripManagementApprover.Approver2 = directBODInfo; } } // BOD var bodImployeeInfo = _employeeInfoDAL.GetByEmployeeID("11009"); // Ms. Su if (bodImployeeInfo != null) { businessTripManagementApprover.Approver3 = bodImployeeInfo; } // Department Head of HC int departmentIdHC = DepartmentListSingleton.GetDepartmentByCode("HR", SiteUrl).ID; if (departmentIdHC != departmentId) { var departmentHeadOfHC = _employeeInfoDAL.GetByPositionDepartment(Constants.StringConstant.EmployeePosition.DepartmentHead, departmentIdHC, locationId); if (departmentHeadOfHC.Count > 0) { businessTripManagementApprover.Approver4 = departmentHeadOfHC[0]; } } if (businessTripManagementApprover.Approver2 == null) { businessTripManagementApprover.Approver2 = businessTripManagementApprover.Approver3; } return(businessTripManagementApprover); }
private void CheckCurrentUser(string currentWebURL, int departmentId) { if (UserPermission.IsCurrentUserInGroup(StringConstant.BOD)) { isBOD = true; } else { var currentDepartment = DepartmentListSingleton.GetDepartmentByID(departmentId, currentWebURL); if (currentDepartment != null) { if (currentDepartment.Code == HR_DEPARTMENT_CODE) { isBOD = false; } } } }
private void CheckCurrentUser(string currentWebURL) { if (UserPermission.IsCurrentUserInGroup(StringConstant.BOD)) { isBOD = true; } else { UserHelper userHelper = new UserHelper(); var currentEmployee = userHelper.GetCurrentLoginUser(); var currentDepartment = DepartmentListSingleton.GetDepartmentByID(currentEmployee.Department.LookupId, currentWebURL); if (currentDepartment != null) { if (currentDepartment.Code == HR_DEPARTMENT_CODE) { isBOD = false; } } } }
/// <summary> /// An item is deleting. /// </summary> public override void ItemDeleting(SPItemEventProperties properties) { try { SPListItem curItem = properties.ListItem; var departmentRepo = new DepartmentDAL(properties.Site.Url); var department = departmentRepo.ParseToEntity(curItem); //delete Site departmentRepo.DeleteSite(properties.SiteId, properties.Web.ID, department); DepartmentListSingleton.ResetDepartmentListInstance(); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Department Event Receiver - ItemDeleting fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); } base.ItemDeleted(properties); }
/// <summary> /// Get employee list in department /// </summary> /// <param name="departmentId"></param> /// <returns></returns> /// CALL URL: _vti_bin/Services/Employee/EmployeeService.svc/GetEmployeeListInCurrentDepartment/3/2 public List <EmployeeDepartmentModel> GetEmployeeListInCurrentDepartment(string departmentId, string locationIds) { List <EmployeeDepartmentModel> employeeInDepartmentList = new List <EmployeeDepartmentModel>(); List <EmployeeInfo> employeeInfoList = new List <EmployeeInfo>(); try { int currentDepartmentId = int.Parse(departmentId); var lcid = CultureInfo.CurrentUICulture.LCID; //Prepare employee list if (currentDepartmentId > 0) { string[] viewFields = new string[] { EmployeeInfoList.EmployeeIDField, EmployeeInfoList.FullNameField, EmployeeInfoList.DepartmentField, EmployeeInfoList.FactoryLocationField }; var employees = _employeeInfoDAL.GetByDepartment(currentDepartmentId, locationIds.SplitStringOfLocations().ConvertAll(e => Convert.ToInt32(e)), viewFields); Department department = DepartmentListSingleton.GetDepartmentByID(currentDepartmentId, SPContext.Current.Site.Url); string departmentName = lcid == 1066 ? department.VietnameseName : department.Name; foreach (var item in employees) { employeeInDepartmentList.Add(new EmployeeDepartmentModel { ID = item.ID, DepartmentId = item.Department.LookupId, FullName = item.FullName, LocationId = item.FactoryLocation.LookupId, EmployeeId = item.EmployeeID, DepartmentName = departmentName }); } } return(employeeInDepartmentList); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("STADA -Employee Service - GetEmployeeListInCurrentDepartment fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); return(null); } }
/// <summary> /// An item is updating. /// </summary> /// <param name="properties"></param> public override void ItemUpdating(SPItemEventProperties properties) { base.ItemUpdating(properties); try { string currentNameValue = Convert.ToString(properties.ListItem[StringConstant.DepartmentList.NameField]); string newName = Convert.ToString(properties.AfterProperties[StringConstant.DepartmentList.NameField]); string currentVnNameValue = Convert.ToString(properties.ListItem[StringConstant.DepartmentList.VietnameseNameField]); string newVnName = Convert.ToString(properties.AfterProperties[StringConstant.DepartmentList.VietnameseNameField]); //Update sub site title if changed if (!currentNameValue.Equals(newName) || !currentVnNameValue.Equals(newVnName)) { var departmentRepo = new DepartmentDAL(properties.Site.Url); SPListItem curItem = properties.ListItem; departmentRepo.UpdateSubSiteTitle(properties.SiteId, properties.Web.ID, curItem, newName, newVnName); } // Update bod approver to BOD group var bodUserString = Convert.ToString(properties.AfterProperties[StringConstant.DepartmentList.BODField]); if (!string.IsNullOrEmpty(bodUserString)) { SPListItem curItem = properties.ListItem; var employeeInfoRepo = new EmployeeInfoDAL(properties.Site.Url); employeeInfoRepo.AddUserToGroup(properties.Site.ID, properties.Web.ID, curItem, StringConstant.Group.BODGroupName, bodUserString); } DepartmentListSingleton.ResetDepartmentListInstance(); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Department Event Receiver - ItemUpdating fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); } }
public CommonApproverModel CreateApprovalList(int departmentId, int locationId) { EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(this.SiteUrl); CommonApproverModel commonApproverModel = new CommonApproverModel(); // Department Head var departmentHead = _employeeInfoDAL.GetByPositionDepartment(Constants.StringConstant.EmployeePosition.DepartmentHead, departmentId, locationId); if (departmentHead.Count > 0) { commonApproverModel.Approver1 = departmentHead[0]; } // BOD var bodUser = DepartmentListSingleton.GetDepartmentByID(departmentId, SiteUrl).BOD; if (bodUser != null && bodUser.ID > 0) { var bodImployeeInfo = _employeeInfoDAL.GetByADAccount(bodUser.UserName); commonApproverModel.Approver2 = bodImployeeInfo; } // Department Head of HC int departmentIdHC = DepartmentListSingleton.GetDepartmentByCode("HR", SiteUrl).ID; if (departmentIdHC != departmentId) { var departmentHeadOfHC = _employeeInfoDAL.GetByPositionDepartment(Constants.StringConstant.EmployeePosition.DepartmentHead, departmentIdHC, locationId); if (departmentHeadOfHC.Count > 0) { commonApproverModel.Approver3 = departmentHeadOfHC[0]; } } return(commonApproverModel); }
private string GetNewFreightCode(int departmentId, DateTime date) { string code = string.Empty; var department = DepartmentListSingleton.GetDepartmentByID(departmentId, this.SiteUrl); if (department != null) { var items = this.GetByDepartment(departmentId, date); int newRequestNumber = 0; if (items != null && items.Count > 0) { string requestNo = items[0].RequestNo; if (!string.IsNullOrEmpty(requestNo)) { int.TryParse(requestNo.Substring(requestNo.Length - 2, 2), out newRequestNumber); } } newRequestNumber += 1; code = GetCodePattern(department.DepartmentNo, date, newRequestNumber); } return(code); }
public void SendEmail(VehicleManagement model, EmailTemplate EmailTempalte, EmployeeInfo approver, EmployeeInfo toUser, VehicleTypeOfEmail typeOfEmail, string webUrl) { var sendToEmail = string.Empty; var receiverName = string.Empty; var link = string.Empty; var approveLinkFormat = "{0}/Lists/VehicleManagement/EditForm.aspx?subSection=TransportationManagement&ID={1}&Source={2}"; switch (toUser.EmployeePosition.LookupId) { case (int)StringConstant.EmployeePosition.Administrator: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementAdmin"); break; case (int)StringConstant.EmployeePosition.DepartmentHead: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementManager"); break; case (int)StringConstant.EmployeePosition.BOD: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementBOD"); break; default: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementMember"); break; } if (typeOfEmail == VehicleTypeOfEmail.Request) { link = string.Format(approveLinkFormat, webUrl, model.ID, HttpUtility.UrlEncode(link + "#tab2")); } else { link = string.Format(approveLinkFormat, webUrl, model.ID, HttpUtility.UrlEncode(link)); } sendToEmail = toUser.Email; receiverName = toUser.FullName; var content = HTTPUtility.HtmlDecode(EmailTempalte.MailBody); var department = DepartmentListSingleton.GetDepartmentByID(model.CommonDepartment.LookupId, this.SiteUrl); switch (typeOfEmail) { case VehicleTypeOfEmail.Request: content = content.Replace("{0}", receiverName); content = content.Replace("{1}", model.Requester.LookupValue); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{4}", department.Name); content = content.Replace("{5}", department.VietnameseName); break; case VehicleTypeOfEmail.Approve: case VehicleTypeOfEmail.Reject: content = content.Replace("{0}", model.Requester.LookupValue); content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); break; default: break; } content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, EmailTempalte.MailSubject, sendToEmail, true, false, content); }