Esempio n. 1
0
        /// <summary>
        /// Updates the current world assignment. BeginDate and EndDate should be EXACTLY THE SAME as of existing relation.
        /// </summary>
        /// <param name="newEmployeeRelation">The new employee relation.</param>
        /// acpro #122269
        public void UpdateAssignment(EmployeeRelation newEmployeeRelation)
        {
            DoValidate(newEmployeeRelation);

            _EmployeeRelation newRelation = new _EmployeeRelation(newEmployeeRelation);

            List <_EmployeeRelation> intersectedRelations = _commonList.FindAll(delegate(_EmployeeRelation relation)
            {
                if (relation.IsIntersectRelation(newRelation) || (relation.IsEqualByData(newRelation) && relation.IsNeighborRelation(newRelation)))
                {
                    if (!relation.IsEqualByStore(newRelation) && !IsMainStoreRelation(newRelation))
                    {
                        throw new ValidationException("ErrorAssignToWorldDateRangeIntersect", null);
                    }
                    return(true);
                }
                return(false);
            });

            //Debug.Assert(intersectedRelations.Count == 1);
            //Debug.Assert(intersectedRelations[0].BeginTime == newEmployeeRelation.BeginTime);
            //Debug.Assert(intersectedRelations[0].EndTime == newEmployeeRelation.EndTime);
            intersectedRelations[0].StoreID = newRelation.StoreID;
            intersectedRelations[0].WorldID = newRelation.WorldID;
            intersectedRelations[0].HWGR_ID = newRelation.HWGR_ID;
        }
Esempio n. 2
0
 internal bool IsMainStoreRelation(_EmployeeRelation relation)
 {
     if (relation == null)
     {
         throw new ArgumentNullException("relation");
     }
     return(MainStoreID == relation.StoreID);
 }
Esempio n. 3
0
        public _EmployeeRelation CopyToRange(_EmployeeRelation datesHolder)
        {
            _EmployeeRelation result = new _EmployeeRelation(CreateCopy());

            result.BeginTime = datesHolder.BeginTime;
            result.EndTime   = datesHolder.EndTime;

            return(result);
        }
Esempio n. 4
0
 public void TrimTo(_EmployeeRelation relation)
 {
     if (BeginTime > relation.BeginTime)
     {
         BeginTime = relation.EndTime.AddDays(1);
     }
     if (EndTime < relation.EndTime)
     {
         EndTime = relation.BeginTime.AddDays(-1);
     }
 }
Esempio n. 5
0
        public _EmployeeRelation Split(_EmployeeRelation relation)
        {
            if (Covers(relation))
            {
                _EmployeeRelation headPart = new _EmployeeRelation(CreateCopy());
                BeginTime = relation.EndTime.Date.AddDays(1);
                IsValid(true);
                headPart.EndTime = relation.BeginTime.AddDays(-1);

                return(headPart);
            }
            return(null);
        }
Esempio n. 6
0
        private void InsertRelation2(_EmployeeRelation newRelation, List <_EmployeeRelation> intersections)
        {
            int intersectionIndex = 0;

            foreach (_EmployeeRelation intersection in intersections)
            {
                intersectionIndex = _commonList.IndexOf(intersection);

                if (intersection.Covers(newRelation))
                {
                    if (intersection.IsEqualByData(newRelation))
                    {
                        newRelation.Deleted = true;
                    }
                    else
                    {
                        _EmployeeRelation leadingInsert = intersection.Split(newRelation);
                        if (intersection.IsValid(true))
                        {
                            _commonList.Insert(intersectionIndex, newRelation);
                        }
                        if (leadingInsert != null && leadingInsert.IsValid(true))
                        {
                            _commonList.Insert(intersectionIndex, leadingInsert);
                        }
                    }
                }
                else if (newRelation.Covers(intersection))
                {
                    intersection.Deleted = true;
                }
                else
                {
                    if (intersection.IsEqualByData(newRelation))
                    {
                        intersection.Merge(newRelation);
                        newRelation.Deleted = true;
                        newRelation         = intersection;
                    }
                    else if (intersection.IsIntersectRelation(newRelation))
                    {
                        intersection.TrimTo(newRelation);
                        intersection.IsValid(true);
                    }
                }
            }
            if (!_commonList.Contains(newRelation) && !newRelation.Deleted && newRelation.IsValid(true))
            {
                _commonList.Insert(intersectionIndex, newRelation);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Merge 2 relation ranges; REMARK: The method will modify the new range, so that a new relation will start next day after This
 /// </summary>
 /// <param name="rel">Relation to be merged</param>
 /// <returns>Boolean result means whether <paramref name="rel"/> should be inserted to relations list</returns>
 public bool Merge(_EmployeeRelation rel)
 {
     if (IsEqualByData(rel) && CanMerge(rel))
     {
         if (BeginTime > rel.BeginTime)
         {
             BeginTime = rel.BeginTime;
         }
         if (EndTime < rel.EndTime)
         {
             EndTime = rel.EndTime;
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 8
0
        public void InsertWorldAssignment(EmployeeRelation newEmployeeRelation)
        {
            DoValidate(newEmployeeRelation);

            _EmployeeRelation newRelation = new _EmployeeRelation(newEmployeeRelation);

            List <_EmployeeRelation> intersectedRelations = _commonList.FindAll(delegate(_EmployeeRelation relation)
            {
                if (relation.IsIntersectRelation(newRelation) || (relation.IsEqualByData(newRelation) && relation.IsNeighborRelation(newRelation)))
                {
                    if (!relation.IsEqualByStore(newRelation) && !IsMainStoreRelation(newRelation))
                    {
                        throw new ValidationException("ErrorAssignToWorldDateRangeIntersect", null);
                    }
                    return(true);
                }
                return(false);
            });

            intersectedRelations.Sort(_comparer);

            InsertRelation2(newRelation, intersectedRelations);
        }
Esempio n. 9
0
 public bool IsEqualByData(_EmployeeRelation rel)
 {
     return(EmployeeID == rel.EmployeeID && StoreID == rel.StoreID && WorldID == rel.WorldID);
 }
Esempio n. 10
0
 public bool IsIntersectOrNeighborRelation(_EmployeeRelation relation)
 {
     return(IsIntersectRelation(relation) || IsNeighborRelation(relation));
 }
Esempio n. 11
0
 public bool IsNeighborRelation(_EmployeeRelation relation)
 {
     return(EndTime.AddDays(1) == relation.BeginTime || relation.EndTime == BeginTime.AddDays(-1));
 }
Esempio n. 12
0
 public bool IsIntersectRelation(_EmployeeRelation newitem)
 {
     return(!((EndTime < newitem.BeginTime) || (newitem.EndTime < BeginTime)));
 }
Esempio n. 13
0
 public bool Covers(_EmployeeRelation rel)
 {
     return(BeginTime <= rel.BeginTime && EndTime >= rel.EndTime);
 }
Esempio n. 14
0
 public bool IsTailIntersection(_EmployeeRelation relation)
 {
     return(EndTime > relation.BeginTime && EndTime <= relation.EndTime);
 }
Esempio n. 15
0
 public bool IsEqualByStore(_EmployeeRelation relation)
 {
     return(EmployeeID == relation.EmployeeID && StoreID == relation.StoreID);
 }
Esempio n. 16
0
 public bool CanMerge(_EmployeeRelation rel)
 {
     return((BeginTime >= rel.BeginTime && EndTime >= rel.EndTime) || (BeginTime <= rel.BeginTime && EndTime <= rel.EndTime));
 }
Esempio n. 17
0
 public bool IsHeadIntersection(_EmployeeRelation relation)
 {
     return(BeginTime >= relation.BeginTime && BeginTime < relation.EndTime);
 }