Esempio n. 1
0
 /**
  * Will return true if given periods are in any ways overlapping
  */
 public static bool Intersects(Period left, Period right)
 {
     return Equals(left, right) ||
         left.Start == right.Start ||
         left.End == right.End ||
         (left.End > right.Start && left.End < right.End) ||
         (left.Start > right.Start && left.Start < right.End) ||
         (left.Start < right.Start && left.End > right.End) ||
         (right.Start < left.Start && right.End > left.End);
 }
Esempio n. 2
0
 /**
  * Returns true if the given periods have the same start and end values.
  * Periods are equal.
  */
 public static bool Equals(Period left, Period right)
 {
     return left.Start == right.Start && left.End == right.End;
 }
Esempio n. 3
0
        private void CreateOneActivityLabel(DateTime idxDate, int dayNo, PeriodCollection col, Activity idxActivity, bool isActive)
        {
            Period curDayPeriod = new Period(idxDate, idxDate.AddHours(23).AddMinutes(59));
            Period curActivityPeriod = new Period(idxActivity.Start, idxActivity.End);
            if (Period.Intersects(curDayPeriod, curActivityPeriod))
            {
                Label actLbl = new Label
                {
                    ID = "act" + idxActivity.ID + "x" + idxDate.DayOfYear,
                    Xtra = idxActivity.ID.ToString()
                };
                actLbl.Style[Styles.opacity] = "0.7";
                actLbl.CssClass = "activity";
                if (curActivityPeriod.End.Date != idxDate.Date)
                    actLbl.CssClass += " actOpenBottom";
                if (curActivityPeriod.Start.Date != idxDate.Date)
                    actLbl.CssClass += " actOpenTop";
                curActivityPeriod = CalculatePositionOfActivity(dayNo, col, idxActivity, curActivityPeriod, actLbl, curDayPeriod);

                // Checking to see if this actuvity is "selected"...
                if (!string.IsNullOrEmpty(CurrentActivityLabel) && 
                    actLbl.ID.IndexOf(CurrentActivityLabel.Substring(0, CurrentActivityLabel.IndexOf("x") + 1)) == 0)
                {
                    actLbl.Style[Styles.width] = "80px";
                    actLbl.Style[Styles.opacity] = "1.0";
                    actLbl.CssClass = actLbl.CssClass.Replace("activity", "activitySelected");
                    actLbl.Style[Styles.zIndex] = (int.Parse(actLbl.Style[Styles.zIndex]) + 10).ToString();
                }

                SetTextAndTooltipOfActivity(idxActivity, actLbl);

                // Trapping Click event to "bring to front"...
                actLbl.Click += acctLbl_Click;

                actWrp.Controls.Add(actLbl);

                if (isActive)
                    BringActivityToFront(new List<Label>(new Label[] {actLbl}),
                                         actLbl.ID.Substring(0, actLbl.ID.IndexOf("x") + 1).Replace("act", "").Replace(
                                             "x", ""));
            }
            col.Add(curActivityPeriod);
        }
Esempio n. 4
0
 public void NotOverlapFirstMore()
 {
     Period left = new Period(DateTime.Now.AddHours(3), DateTime.Now.AddHours(4));
     Period right = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(2));
     Assert.IsFalse(Period.Intersects(left, right));
 }
Esempio n. 5
0
 public void OverlapFirstMore()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(4));
     Period right = new Period(DateTime.Now, DateTime.Now.AddHours(3));
     Assert.IsTrue(Period.Intersects(left, right));
 }
Esempio n. 6
0
 public void XORSameEndThrows()
 {
     Period left = new Period(DateTime.Now.AddHours(2), DateTime.Now.AddHours(3));
     Period right = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(3));
     Tuple<Period, Period> xor = Period.XOR(left, right);
 }
Esempio n. 7
0
 public void XORIntersectingFirstSuperset()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(5));
     Period right = new Period(DateTime.Now.AddHours(2), DateTime.Now.AddHours(3));
     Tuple<Period, Period> xor = Period.XOR(left, right);
     Assert.IsTrue(Period.Equals(xor.Left, new Period(left.Start, right.Start)));
     Assert.IsTrue(Period.Equals(xor.Right, new Period(right.End, left.End)));
 }
Esempio n. 8
0
 public void XORNotIntersectingSecondLess()
 {
     Period left = new Period(DateTime.Now.AddHours(4), DateTime.Now.AddHours(6));
     Period right = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(3));
     Tuple<Period, Period> xor = Period.XOR(left, right);
     Assert.IsTrue(Period.Equals(xor.Left, left));
     Assert.IsTrue(Period.Equals(xor.Right, right));
 }
Esempio n. 9
0
 static Period()
 {
     Empty = new Period();
 }
Esempio n. 10
0
 /**
  * Returns a new period that is the overlapping parts of the given two periods. Periods MUST
  * overlap otherwise an exception will be thrown.
  */
 public static Period AND(Period left, Period right)
 {
     if (!Intersects(left, right))
         throw new Exception("Can't logically AND two periods that doesn't overlap");
     return new Period(left.Start > right.Start ? left.Start : right.Start, left.End < right.End ? left.End : right.End);
 }
Esempio n. 11
0
 /**
  * Returns the XOR values of two periods. This logically is two periods which are the places
  * that only one of them exists.
  */
 public static Tuple<Period, Period> XOR(Period left, Period right)
 {
     if (Equals(left, right))
         throw new Exception("Can't XOR two periods that are equal");
     if (left.Start == right.Start || left.End == right.End)
         throw new Exception("Can't XOR two periods that will not somehow create two periods");
     if (Subset(left, right))
     {
         // Left is subset of right
         return new Tuple<Period, Period>(
             new Period(right.Start, left.Start),
             new Period(left.End, right.End));
     }
     if (Subset(right, left))
     {
         // Right is subset of right
         return new Tuple<Period, Period>(
             new Period(left.Start, right.Start),
             new Period(right.End, left.End));
     }
     if (Intersects(left, right))
     {
         // Periods are overlapping
         return new Tuple<Period, Period>(
             new Period(
                 left.Start < right.Start ? left.Start : right.Start, 
                 left.Start > right.Start ? left.Start : right.Start),
             new Period(
                 left.End < right.End ? left.End : right.End,
                 left.End > right.End ? left.End : right.End));
     }
     // Periods are already "naturally" XORING eachother...
     return new Tuple<Period, Period>(left, right);
 }
Esempio n. 12
0
 /**
  * "Merges" two period into one. Periods MUST be either overlapping or continuing periods
  * otherwise an exception will be thrown.
  */
 public static Period OR(Period left, Period right)
 {
     if (!Intersects(left, right) && !Continues(left, right))
         throw new Exception("Can't logically OR two periods that doesn't 'touch' eachother");
     return new Period(left.Start < right.Start ? left.Start : right.Start, left.End > right.End ? left.End : right.End);
 }
Esempio n. 13
0
 /**
  * Returns true is the second period is "within" the first period
  */
 public static bool Superset(Period left, Period right)
 {
     return Subset(right, left);
 }
Esempio n. 14
0
 /**
  * Returns true is the first period is "within" the second period
  */
 public static bool Subset(Period left, Period right)
 {
     return left.Start > right.Start && left.End < right.End;
 }
Esempio n. 15
0
 public void ANDFirstLessFirstEndLess()
 {
     Period left = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(2));
     Period right = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(3));
     Period and = Period.AND(left, right);
     Assert.IsTrue(Period.Equals(and, new Period(right.Start, left.End)));
 }
Esempio n. 16
0
 /**
  * Will return true if the given two periods in any ways "continues"
  * and together creates a perfect longer period.
  */
 public static bool Continues(Period left, Period right)
 {
     return left.End == right.Start || left.Start == right.End;
 }
Esempio n. 17
0
 public void ANDNotIntersectingThrows()
 {
     Period left = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(2));
     Period right = new Period(DateTime.Now.AddHours(3), DateTime.Now.AddHours(5));
     Period and = Period.AND(left, right);
 }
Esempio n. 18
0
 public void ContinuesSecond()
 {
     Period left = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(4));
     Period right = new Period(left.End, left.End.AddHours(2));
     Assert.IsTrue(Period.Continues(right, left));
 }
Esempio n. 19
0
 public void NegativeLengthThrows()
 {
     DateTime now = DateTime.Now;
     Period left = new Period(now, now.AddMilliseconds(-1));
 }
Esempio n. 20
0
 public void ORBothEqual()
 {
     Period left = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(4));
     Period right = new Period(left.Start, left.End);
     Period or = Period.OR(left, right);
     Assert.IsTrue(Period.Equals(or, left));
 }
Esempio n. 21
0
 public void XOREqualsThrows()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(5));
     Period right = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(5));
     Tuple<Period, Period> xor = Period.XOR(left, right);
 }
Esempio n. 22
0
 public void ORSecondLessSameEnd()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(4));
     Period right = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(4));
     Period or = Period.OR(left, right);
     Assert.IsTrue(Period.Equals(or, right));
 }
Esempio n. 23
0
 public void TinyPeriod()
 {
     DateTime now = DateTime.Now;
     Period left = new Period(now, now.AddMilliseconds(1));
 }
Esempio n. 24
0
 public void ORFirstSubset()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(3));
     Period right = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(4));
     Period or = Period.OR(left, right);
     Assert.IsTrue(Period.Equals(or, new Period(right.Start, right.End)));
 }
Esempio n. 25
0
 public void OverlapSecondContains()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(3));
     Period right = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(4));
     Assert.IsTrue(Period.Intersects(left, right));
 }
Esempio n. 26
0
 public void ORNotIntersectingThrows()
 {
     Period left = new Period(DateTime.Now.AddHours(1), DateTime.Now.AddHours(3));
     Period right = new Period(DateTime.Now.AddHours(4), DateTime.Now.AddHours(5));
     Period or = Period.OR(left, right);
 }
Esempio n. 27
0
 public void NotOverlapSecondContinues()
 {
     Period left = new Period(DateTime.Now.AddHours(0), DateTime.Now.AddHours(4));
     Period right = new Period(left.End, left.End.AddHours(2));
     Assert.IsFalse(Period.Intersects(right, left));
 }
Esempio n. 28
0
 public void SameDatesThrows()
 {
     DateTime now = DateTime.Now;
     Period left = new Period(now, now);
 }
Esempio n. 29
0
        private static Period CalculatePositionOfActivity(int dayNo, IEnumerable<Period> col, Activity idxActivity, Period curActivityPeriod, RaWebControl actLbl, Period curDayPeriod)
        {
            if (_maxHeight == 0)
            {
                // Calculating max height...
                _maxHeight = (int)((((float)(DateTime.Now.Date.AddHours(23).AddMinutes(59) - DateTime.Now.Date).TotalMinutes) / 60F) * 15F) + 24;
            }
            // Current activity is intersecting with current rendering day
            int left = (dayNo * 105) + 10;
            int top;
            if (curDayPeriod.Start > idxActivity.Start)
                top = 29;
            else
                top = (int)((((float)(idxActivity.Start - curDayPeriod.Start).TotalMinutes) / 60F) * 15F) + 29;
            int height;
            if (idxActivity.Start.Date != curDayPeriod.Start)
                height = (int)((((float)(idxActivity.End - curDayPeriod.Start).TotalMinutes) / 60F) * 15F) - 6;
            else
                height = (int)((((float)(idxActivity.End - idxActivity.Start).TotalMinutes) / 60F) * 15F) - 6;
            height = Math.Min(height, _maxHeight - top);

            // Checking to see if it overlaps with a previously added activity
            int zIndex = 100;
            foreach (Period idxPreviouslyAdded in col)
            {
                if (!Period.Intersects(idxPreviouslyAdded, curActivityPeriod))
                    continue;
                zIndex += 1;
                left += 10;
            }
            actLbl.Style[Styles.left] = left + "px";
            actLbl.Style[Styles.top] = top + "px";
            actLbl.Style[Styles.height] = height + "px";
            actLbl.Style[Styles.zIndex] = zIndex.ToString();
            return curActivityPeriod;
        }
Esempio n. 30
0
 /**
  * Returns true if first period is a smaller period then second period
  */
 public static bool Shorter(Period left, Period right)
 {
     return left.Length < right.Length;
 }