Example #1
0
        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);
                    }
                }
            }
        }
        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++;
                        }
                    }
                }
            }
        }