Exemple #1
0
        public void StartNewActivity(string name, string comment, bool autoMatchLastComment = false)
        {
            // finish current activity:
            if (TodayCurrentActivity != null)
            {
                TodayCurrentActivity.End = GetNowTime();
            }

            // if no comment provided, automatically apply last comment:
            if (String.IsNullOrEmpty(comment) && autoMatchLastComment)
            {
                comment = Today.ActivityRecords.Where(r => r.Activity == name && !String.IsNullOrEmpty(r.Comment)).LastOrDefault()?.Comment;
            }

            // start new activity:
            TodayCurrentActivity = new ActivityRecord()
            {
                Activity = name, Begin = GetNowTime(), Comment = comment
            };
            Today.ActivityRecords.Add(TodayCurrentActivity);

            // has checked out already (e.g. by deleting last 'open end' activity) -> reopen day by removing end time
            // there shouldnt be any unrecoverable loss, as the end should be resembled by an according activity end time.
            if (Today.End != default(TimeSpan))
            {
                Today.End = default(TimeSpan);
                // it is also necessary to update the pause time:
                CalculatePauseFromActivities(Today);
            }

            CurrentActivityUpdated();
        }
Exemple #2
0
 public bool CanDeleteActivity(Stamp stamp, ActivityRecord activity)
 {
     if (stamp.ActivityRecords.Count <= 1)
     {
         return(false);
     }
     return(true);
 }
Exemple #3
0
        public static void SetActivityBegin(Stamp stamp, ActivityRecord activity, TimeSpan value)
        {
            // invalid action:
            if (value >= activity.End)
            {
                return;
            }

            // add new, pending activity entry if applicable:
            if (!stamp.ActivityRecords.Contains(activity))
            {
                stamp.ActivityRecords.Add(activity);
            }

            var ordered = stamp.ActivityRecords.OrderBy(r => r.Begin).ToList();

            // first activity start changed -> also change days start stamp
            if (activity.Begin == stamp.Begin)
            {
                stamp.Begin = value;
            }
            // in between start changed -> also change end of previous activity, if they previously matched
            else if (activity != ordered.FirstOrDefault())
            {
                int index = ordered.IndexOf(activity) - 1;

                bool isIterating;
                do
                {
                    isIterating = false;
                    var previousActivity = ordered.ElementAt(index); //grdActivities.Rows[index].Tag as ActivityRecord;
                    if (!previousActivity.End.HasValue || previousActivity.End.Value >= value)
                    {
                        previousActivity.End = value;
                        // activity is hidden / negative after change -> remove activity
                        if (Total(previousActivity) < TimeSpan.Zero)
                        {
                            stamp.ActivityRecords.Remove(previousActivity);
                            if (index == 0)
                            {
                                // removed first stamp -> also set stamp begin
                                stamp.Begin = value;
                            }
                            index--;
                            isIterating = true;
                        }
                    }
                } while (index >= 0 && isIterating);
            }

            activity.Begin = value;

            // pause interruption gap(s) is/are changed -> also change day pause stamp
            CalculatePauseFromActivities(stamp);
        }
Exemple #4
0
        public static TimeSpan Total(ActivityRecord activity)
        {
            if (!activity.Begin.HasValue)
            {
                return(TimeSpan.Zero);
            }

            if (!activity.End.HasValue) // assuming this can only happen if it is the today's stamp and not yet checked out...
            {
                return(GetNowTime() - activity.Begin.Value);
            }

            return(activity.End.Value - activity.Begin.Value);
        }
Exemple #5
0
        public static void SetActivityEnd(Stamp stamp, ActivityRecord activity, TimeSpan value)
        {
            // invalid action:
            if (value <= activity.Begin)
            {
                return;
            }

            var ordered = stamp.ActivityRecords.OrderBy(r => r.Begin).ToList();

            // last activity end changed -> also change days end stamp
            if (activity.End == stamp.End)
            {
                stamp.End = value;
            }
            // in between end changed -> also change start of next activity, if they previously matched
            else if (activity != ordered.LastOrDefault())
            {
                int index = ordered.IndexOf(activity) + 1;

                bool isIterating;
                do
                {
                    isIterating = false;
                    var nextActivity = ordered.ElementAt(index);
                    if (nextActivity.Begin <= value)
                    {
                        nextActivity.Begin = value;
                        // activity is hidden / negative after change -> remove activity
                        if (Total(nextActivity) < TimeSpan.Zero)
                        {
                            stamp.ActivityRecords.Remove(nextActivity);
                            if (index == ordered.Count - 1)
                            {
                                // removed last stamp -> also set stamp end
                                stamp.End = value;
                            }
                            index++;
                            isIterating = true;
                        }
                    }
                } while (index <= ordered.Count - 1 && isIterating);
            }
            activity.End = value;

            // pause interruption gap(s) is/are changed -> also change day pause stamp
            CalculatePauseFromActivities(stamp);
        }
Exemple #6
0
 public void DeleteActivity(Stamp stamp, ActivityRecord activity)
 {
     if (activity == TodayCurrentActivity)
     {
         // todays end auf neuen letzten zeitpunkt setzen, current activity clearen:
         stamp.ActivityRecords.Remove(activity);
         TodayCurrentActivity = null;
         var newLastActivity = stamp.GetLastActivity();
         stamp.End = newLastActivity.End.Value;
         // TODO: need to recalculate pause?
         TimeManager.CalculatePauseFromActivities(stamp);
     }
     else if (activity == stamp.GetFirstActivity())
     {
         // update todays start time:
         stamp.ActivityRecords.Remove(activity);
         var newFirstActivity = stamp.GetFirstActivity();
         stamp.Begin = newFirstActivity.Begin.Value;
         // TODO: need to recalculate pause?
         TimeManager.CalculatePauseFromActivities(stamp);
     }
     else if (activity == stamp.GetLastActivity())
     {
         // update todays end time:
         stamp.ActivityRecords.Remove(activity);
         var newLastActivity = stamp.GetLastActivity();
         stamp.End = newLastActivity.End.Value;
         // TODO: need to recalculate pause?
         TimeManager.CalculatePauseFromActivities(stamp);
     }
     else
     {
         // in between activity; update todays pause time:
         stamp.ActivityRecords.Remove(activity);
         TimeManager.CalculatePauseFromActivities(stamp);
     }
 }