protected void Page_Load(object sender, EventArgs e) { UserHelper userHelper = new UserHelper(); var currentEmployee = userHelper.GetCurrentLoginUser(); if (currentEmployee == null || currentEmployee.ID <= 0) { ParamShiftRequestIDHidden.Value = ""; ParamDepartmentIDHidden.Value = ""; } else { ParamShiftRequestIDHidden.Value = Convert.ToString(currentEmployee.ID); ParamDepartmentIDHidden.Value = Convert.ToString(currentEmployee.Department.LookupId); } // Set GUID for Web part var url = SPContext.Current.Web.Url; ShiftManagementDAL shiftManagementDal = new ShiftManagementDAL(url); var guidViews = shiftManagementDal.GetViewGuildID().Where(x => x.BaseViewID == BASE_VIEW_ID).FirstOrDefault(); ShiftRequestsWebPart.ViewGuid = guidViews.ID.ToString(); // Check shift create permission: btnAddNewOvertime.Visible = UserPermission.HasShiftCreation; }
protected void Page_Load(object sender, EventArgs e) { var url = SPContext.Current.Web.Url; ShiftManagementDAL shiftManagementDal = new ShiftManagementDAL(url); var guidViews = shiftManagementDal.GetViewGuildID().Where(x => x.BaseViewID == BASE_VIEW_ID).FirstOrDefault(); ShiftApproveWebPart.ViewGuid = guidViews.ID.ToString(); }
/// <summary> /// InitDALObject /// </summary> /// <param name="listUrl"></param> /// <param name="currentWeb"></param> /// <returns></returns> private static IDelegationManager InitDALObject(string listUrl, SPWeb currentWeb) { IDelegationManager moduleDAL = null; if (string.Compare(listUrl, ShiftManagementList.ListUrl, true) == 0) { moduleDAL = new ShiftManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, ChangeShiftList.ListUrl, true) == 0) { moduleDAL = new ChangeShiftManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, OverTimeManagementList.ListUrl, true) == 0) { moduleDAL = new OverTimeManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, NotOvertimeList.ListUrl, true) == 0) { moduleDAL = new NotOvertimeManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, VehicleManagementList.ListUrl, true) == 0) { moduleDAL = new VehicleManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, LeaveManagementList.ListUrl, true) == 0) { moduleDAL = new LeaveManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, FreightManagementList.ListUrl, true) == 0) { moduleDAL = new FreightManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, BusinessTripManagementList.Url, true) == 0) { moduleDAL = new BusinessTripManagementDAL(currentWeb.Url); } else if (string.Compare(listUrl, RequestsList.Url, true) == 0) { moduleDAL = new RequestsDAL(currentWeb.Url); } else if (string.Compare(listUrl, EmployeeRequirementSheetsList.Url, true) == 0) { moduleDAL = new EmployeeRequirementSheetDAL(currentWeb.Url); } else if (string.Compare(listUrl, RequestForDiplomaSuppliesList.Url, true) == 0) { moduleDAL = new RequestForDiplomaSupplyDAL(currentWeb.Url); } else if (string.Compare(listUrl, RequisitionOfMeetingRoomList.Url, true) == 0) { moduleDAL = new RequisitionOfMeetingRoomDAL(currentWeb.Url); } return(moduleDAL); }
//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 { } } } } } } } }
public MessageResult GetModifiedDate(string moduleId, string itemId) { string ret = string.Empty; try { SPWeb currentWeb = SPContext.Current.Web; int moduleIdendify = 0; int itemIdentify = 0; if (int.TryParse(moduleId, out moduleIdendify) && int.TryParse(itemId, out itemIdentify)) { SPListItemCollection itemCollection = null; SPQuery spQuery = new SPQuery() { Query = $"<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>{itemIdentify}</Value></Eq></Where>", RowLimit = 1 }; switch (moduleIdendify) { case (int)StepModuleList.ShiftManagement: ShiftManagementDAL _shiftManagementDAL = new ShiftManagementDAL(currentWeb.Url); itemCollection = _shiftManagementDAL.GetByQueryToSPListItemCollection(currentWeb, spQuery, new string[] { StringConstant.DefaultSPListField.ModifiedField }); break; case (int)StepModuleList.OvertimeManagement: OverTimeManagementDAL _overTimeManagementDAL = new OverTimeManagementDAL(currentWeb.Url); itemCollection = _overTimeManagementDAL.GetByQueryToSPListItemCollection(currentWeb, spQuery, new string[] { StringConstant.DefaultSPListField.ModifiedField }); break; default: break; } if (itemCollection != null && itemCollection.Count > 0) { DateTime modifiedField = (DateTime)itemCollection[0][StringConstant.DefaultSPListField.ModifiedField]; ret = modifiedField.ToString(StringConstant.DateFormatddMMyyyyHHmmss); } } } catch (Exception ex) { return(new MessageResult { Code = -1, Message = ex.Message }); } return(new MessageResult { Code = 0, Message = ret }); }
private void GetShiftTaskList(ShiftManagementDAL shiftManagementDAL) { int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; var query = $@"<Where> <And> <And> <Eq> <FieldRef Name='{StringConstant.ShiftManagementList.CommonAddApprover1Field}' LookupId='TRUE' /> <Value Type='User'>{_currentUserADId}</Value> </Eq> <Eq> <FieldRef Name='{StringConstant.DefaultSPListField.ModifiedByField}' LookupId='TRUE' /> <Value Type='User'>{_currentUserADId}</Value> </Eq> </And> <Eq> <FieldRef Name='{StringConstant.DefaultSPListField.ModifiedField}' /> <Value IncludeTimeValue='FALSE' Type='DateTime'>{DateTime.Now.ToString(StringConstant.DateFormatForCAML)}</Value> </Eq> </And> </Where>"; if (this.CountOnly) { TotalCount += shiftManagementDAL.CountByQuery(query); } else { var shiftManagementList = shiftManagementDAL.GetByQuery(query); if (shiftManagementList != null && shiftManagementList.Count > 0) { foreach (var shiftManagement in shiftManagementList) { var filterTask = new FilterTask(shiftManagement); filterTask.ApprovalStatusId = ApprovedStatusId; FilterTaskList.Add(filterTask); } } } }
public void Visit(ShiftManagementDAL shiftManagementDAL) { // DO NOTHING }
public void Visit(ShiftManagementDAL shiftManagementDAL) { GetShiftTaskList(shiftManagementDAL); }
private void GetShiftTaskList(ShiftManagementDAL shiftManagementDAL) { int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; List <int> delegatedItemIDs = this.DelegationList.Where(d => d.ListUrl == ShiftManagementList.ListUrl).Select(d => d.ListItemID).ToList(); var delegationQuery = _filterTaskManager.BuildApprovedByDelegationQuery(_currentUserADId, ShiftManagementList.ApprovedByField, "User", delegatedItemIDs); var query = $@"<Where> <And> {delegationQuery} <Or> <And> <Eq> <FieldRef Name='{ShiftManagementList.YearField}' /> <Value Type='Number'>{year}</Value> </Eq> <Geq> <FieldRef Name='{ShiftManagementList.MonthField}' /> <Value Type='Number'>{month}</Value> </Geq> </And> <Gt> <FieldRef Name='{ShiftManagementList.YearField}' /> <Value Type='Number'>{year}</Value> </Gt> </Or> </And> </Where>"; var shiftManagementList = shiftManagementDAL.GetByQuery(query); if (shiftManagementList != null && shiftManagementList.Count > 0) { var isValid = false; Type typeShiftManagementDetail = typeof(ShiftManagementDetail); BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public; foreach (var shiftManagement in shiftManagementList) { isValid = true; if (shiftManagement.Year == year) { if (shiftManagement.Month == month) // VALID: Current Day <= 20 { if (day > 20) { isValid = false; } } else if (shiftManagement.Month - 1 == month) // VALID: >=21. Shif Thang 12: 21/11 -> 20/12 -> Thang hien tai 11: >= 21/11 { if (day < 21) { isValid = false; } } } //else if (year == shiftManagement.Year - 1) //{ // if (month == 12) // 21/12/2016 -> 20/1/2017: Shift Thang 1/2017 0> Thang hien tai: 12/2016 // if (day < 21) // isValid = false; //} if (isValid) { var isApproved = true; var shiftManagementDetails = _shiftManagementDetailDAL.GetByShiftManagementID(shiftManagement.ID); if (shiftManagementDetails != null && shiftManagementDetails.Any()) { foreach (var shiftManagementDetail in shiftManagementDetails) { if (!isApproved) { break; } for (int i = 1; i <= 31; i++) { PropertyInfo shiftTimeInfo = typeShiftManagementDetail.GetProperty(string.Format("ShiftTime{0}", i), bindingFlags); object shiftTimeValue = shiftTimeInfo.GetValue(shiftManagementDetail, null); if (shiftTimeValue != null) { LookupItem shiftTimeValueObj = shiftTimeValue as LookupItem; if (!string.IsNullOrEmpty(shiftTimeValueObj.LookupValue)) { PropertyInfo shiftTimeApprovalInfo = typeShiftManagementDetail.GetProperty(string.Format("ShiftTime{0}Approval", i), bindingFlags); object shiftTimeApprovalValue = shiftTimeApprovalInfo.GetValue(shiftManagementDetail, null); if (shiftTimeApprovalValue != null && Convert.ToBoolean(shiftTimeApprovalValue) == false) { isApproved = false; } } } } } } if (!isApproved) { var filterTask = new FilterTask(shiftManagement); filterTask.ApprovalStatusId = ApprovalStatusId; FilterTaskList.Add(filterTask); // Count tasks this.TotalCount++; } } } } }
public void ImportExcel() { ExcelShiftsOfDepartment excelShiftsOfDepartment = ReadExcelShiftData(); excelShiftsOfDepartment.DepartmentId = 2; //HR excelShiftsOfDepartment.Location = 2; excelShiftsOfDepartment.Month = 7; excelShiftsOfDepartment.Year = 2017; Dictionary <string, int> duplicatedEmployees = ValidateDuplicatedData(excelShiftsOfDepartment); string siteUrl = "http://rbvhspdev01:81/"; ShiftManagementDAL _shiftManagementDAL = new ShiftManagementDAL(siteUrl); ShiftManagementDetailDAL _shiftManagementDetailDAL = new ShiftManagementDetailDAL(siteUrl); List <ShiftManagement> shiftManagements = _shiftManagementDAL.GetByMonthYearDepartment(excelShiftsOfDepartment.Month, excelShiftsOfDepartment.Year, excelShiftsOfDepartment.DepartmentId, excelShiftsOfDepartment.Location); List <ShiftManagementDetail> shiftManagementDetails = new List <ShiftManagementDetail>(); if (shiftManagements != null && shiftManagements.Count > 0) { shiftManagementDetails = _shiftManagementDetailDAL.GetByShiftManagementID(shiftManagements[0].ID); } EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(siteUrl); List <EmployeeInfo> employeesOfDepartment = _employeeInfoDAL.GetByLocationAndDepartment(2, excelShiftsOfDepartment.DepartmentId, true, 4, StringConstant.EmployeeInfoList.EmployeeIDField); if (shiftManagementDetails != null && shiftManagementDetails.Count > 0) { foreach (var employeeShift in excelShiftsOfDepartment.EmployeeShifts) { EmployeeInfo employeeInfo = employeesOfDepartment.Where(e => e.EmployeeID == employeeShift.EmployeeID).FirstOrDefault(); if (employeeInfo != null) { employeeShift.EmployeeLookupID = employeeInfo.ID; } } List <int> employeeLookupIds = excelShiftsOfDepartment.EmployeeShifts.Select(e => e.EmployeeLookupID).ToList(); shiftManagementDetails = shiftManagementDetails.Where(e => employeeLookupIds.Contains(e.Employee.LookupId)).ToList(); } foreach (ExcelEmployeeShift excelEmployeeShift in excelShiftsOfDepartment.EmployeeShifts) { ShiftManagementDetail shiftManagementDetail = shiftManagementDetails.Where(e => e.Employee.LookupId == excelEmployeeShift.EmployeeLookupID).FirstOrDefault(); if (shiftManagementDetail == null) { shiftManagementDetail = new ShiftManagementDetail(); EmployeeInfo employeeInfo = employeesOfDepartment.Where(e => e.EmployeeID == excelEmployeeShift.EmployeeID).FirstOrDefault(); shiftManagementDetail.Employee = new LookupItem() { LookupId = employeeInfo.ID, LookupValue = employeeInfo.FullName }; shiftManagementDetails.Add(shiftManagementDetail); } ShiftTimeDAL _shiftTimeDAL = new ShiftTimeDAL(siteUrl); List <ShiftTime> shiftTimes = _shiftTimeDAL.GetAll(); for (int i = 0; i < 11; i++) { ShiftTime shiftTime = shiftTimes.Where(e => e.Code.ToUpper() == excelEmployeeShift.ShiftCodes[i].ToUpper()).FirstOrDefault(); if (shiftTime != null) { Type type = typeof(ShiftManagementDetail); PropertyInfo shiftApprovalInfo = type.GetProperty(string.Format("ShiftTime{0}Approval", i + 21)); object shiftApprovalValue = shiftApprovalInfo.GetValue(shiftManagementDetail, null); if (shiftApprovalValue != null && Convert.ToBoolean(shiftApprovalValue) == false) { PropertyInfo shiftInfo = type.GetProperty(string.Format("ShiftTime{0}", i + 21)); LookupItem shiftValue = shiftInfo.GetValue(shiftManagementDetail, null) as LookupItem; if (shiftValue == null) { shiftValue = new LookupItem(); } shiftValue.LookupId = shiftTime.ID; shiftValue.LookupValue = shiftTime.Code; } } } for (int i = 11; i < 31; i++) { ShiftTime shiftTime = shiftTimes.Where(e => e.Code.ToUpper() == excelEmployeeShift.ShiftCodes[i].ToUpper()).FirstOrDefault(); if (shiftTime != null) { Type type = typeof(ShiftManagementDetail); PropertyInfo shiftApprovalInfo = type.GetProperty(string.Format("ShiftTime{0}Approval", i - 10)); object shiftApprovalValue = shiftApprovalInfo.GetValue(shiftManagementDetail, null); if (shiftApprovalValue != null && Convert.ToBoolean(shiftApprovalValue) == false) { PropertyInfo shiftInfo = type.GetProperty(string.Format("ShiftTime{0}", i - 10)); LookupItem shiftValue = shiftInfo.GetValue(shiftManagementDetail, null) as LookupItem; if (shiftValue == null) { shiftValue = new LookupItem(); } shiftValue.LookupId = shiftTime.ID; shiftValue.LookupValue = shiftTime.Code; } } } } int shiftId = 0; if (shiftManagements == null || shiftManagements.Count == 0) { Biz.Models.ShiftManagement shiftManagement = new Biz.Models.ShiftManagement(); shiftManagement.Department = new LookupItem() { LookupId = excelShiftsOfDepartment.DepartmentId, LookupValue = excelShiftsOfDepartment.DepartmentId.ToString() }; shiftManagement.Location = new LookupItem() { LookupId = excelShiftsOfDepartment.Location, LookupValue = excelShiftsOfDepartment.Location.ToString() }; shiftManagement.Month = excelShiftsOfDepartment.Month; shiftManagement.Year = excelShiftsOfDepartment.Year; EmployeeInfo requester = _employeeInfoDAL.GetByADAccount(122); shiftManagement.Requester = new LookupItem() { LookupId = requester.ID, LookupValue = requester.FullName }; EmployeeInfo approvedBy = _employeeInfoDAL.GetByPositionDepartment(StringConstant.EmployeePosition.DepartmentHead, excelShiftsOfDepartment.DepartmentId, excelShiftsOfDepartment.Location).FirstOrDefault(); shiftManagement.ApprovedBy = new User() { ID = approvedBy.ADAccount.ID, UserName = approvedBy.ADAccount.UserName, FullName = approvedBy.FullName, IsGroup = false }; shiftId = _shiftManagementDAL.SaveOrUpdate(shiftManagement); } else { shiftId = shiftManagements[0].ID; } if (shiftId > 0) { foreach (ShiftManagementDetail shiftManagementDetail in shiftManagementDetails) { shiftManagementDetail.ShiftManagementID = new LookupItem() { LookupId = shiftId, LookupValue = shiftId.ToString() }; int shiftDetailId = _shiftManagementDetailDAL.SaveOrUpdate(shiftManagementDetail); } } }
public void Visit(ShiftManagementDAL shiftManagementDAL) { // Do nothing }