Ejemplo n.º 1
0
        private bool IsShiftApproved(int shiftId)
        {
            bool ret = true;

            ShiftManagementDetailDAL     _shiftManagementDetailDAL = new ShiftManagementDetailDAL(SiteUrl);
            List <ShiftManagementDetail> shiftManagementDetails    = _shiftManagementDetailDAL.GetByShiftManagementID(shiftId);

            if (shiftManagementDetails != null && shiftManagementDetails.Count > 0)
            {
                ShiftTimeDAL _shiftTimeDAL             = new ShiftTimeDAL(SiteUrl);
                List <Biz.Models.ShiftTime> shiftTimes = _shiftTimeDAL.GetShiftTimes();
                List <string> shiftCodeList            = shiftTimes.Where(e => e.ShiftRequired == true).Select(e => e.Code.ToUpper()).ToList();

                Type         typeShiftManagementDetail = typeof(ShiftManagementDetail);
                BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public;
                foreach (var shiftManagementDetail in shiftManagementDetails)
                {
                    if (ret == false)
                    {
                        break;
                    }

                    for (int idx = 1; idx <= 31; idx++)
                    {
                        PropertyInfo shiftTimeInfo  = typeShiftManagementDetail.GetProperty(string.Format("ShiftTime{0}", idx), bindingFlags);
                        object       shiftTimeValue = shiftTimeInfo.GetValue(shiftManagementDetail, null);

                        if (shiftTimeValue != null)
                        {
                            LookupItem shiftTimeValueObj = shiftTimeValue as LookupItem;
                            if (!string.IsNullOrEmpty(shiftTimeValueObj.LookupValue) && shiftCodeList.Contains(shiftTimeValueObj.LookupValue))
                            {
                                PropertyInfo shiftTimeApprovalInfo  = typeShiftManagementDetail.GetProperty(string.Format("ShiftTime{0}Approval", idx), bindingFlags);
                                object       shiftTimeApprovalValue = shiftTimeApprovalInfo.GetValue(shiftManagementDetail, null);

                                if (shiftTimeApprovalValue != null && Convert.ToBoolean(shiftTimeApprovalValue) == true)
                                {
                                    ret = true;
                                }
                                else
                                {
                                    ret = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(ret);
        }
        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++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }