/// <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; }
internal bool IsMainStoreRelation(_EmployeeRelation relation) { if (relation == null) { throw new ArgumentNullException("relation"); } return(MainStoreID == relation.StoreID); }
public _EmployeeRelation CopyToRange(_EmployeeRelation datesHolder) { _EmployeeRelation result = new _EmployeeRelation(CreateCopy()); result.BeginTime = datesHolder.BeginTime; result.EndTime = datesHolder.EndTime; return(result); }
public void TrimTo(_EmployeeRelation relation) { if (BeginTime > relation.BeginTime) { BeginTime = relation.EndTime.AddDays(1); } if (EndTime < relation.EndTime) { EndTime = relation.BeginTime.AddDays(-1); } }
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); }
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); } }
/// <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); } }
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); }
public bool IsEqualByData(_EmployeeRelation rel) { return(EmployeeID == rel.EmployeeID && StoreID == rel.StoreID && WorldID == rel.WorldID); }
public bool IsIntersectOrNeighborRelation(_EmployeeRelation relation) { return(IsIntersectRelation(relation) || IsNeighborRelation(relation)); }
public bool IsNeighborRelation(_EmployeeRelation relation) { return(EndTime.AddDays(1) == relation.BeginTime || relation.EndTime == BeginTime.AddDays(-1)); }
public bool IsIntersectRelation(_EmployeeRelation newitem) { return(!((EndTime < newitem.BeginTime) || (newitem.EndTime < BeginTime))); }
public bool Covers(_EmployeeRelation rel) { return(BeginTime <= rel.BeginTime && EndTime >= rel.EndTime); }
public bool IsTailIntersection(_EmployeeRelation relation) { return(EndTime > relation.BeginTime && EndTime <= relation.EndTime); }
public bool IsEqualByStore(_EmployeeRelation relation) { return(EmployeeID == relation.EmployeeID && StoreID == relation.StoreID); }
public bool CanMerge(_EmployeeRelation rel) { return((BeginTime >= rel.BeginTime && EndTime >= rel.EndTime) || (BeginTime <= rel.BeginTime && EndTime <= rel.EndTime)); }
public bool IsHeadIntersection(_EmployeeRelation relation) { return(BeginTime >= relation.BeginTime && BeginTime < relation.EndTime); }