Example #1
0
        private void Save()
        {
            Task task = new Task()
            {
                APS         = APSHours.Checked,
                Date        = Date.Value.ToLongDateString(),
                ElapsedTime = ElapsedTime.Value.ToString("HH:mm:ss") + ".00",
                StartTime   = StartTime.Value.ToLongTimeString(),
                EndTime     = EndTime.Value.ToLongTimeString(),
                IssueNumber = IssueNumber.Text,
                TimeUsed    = TimeUsed.Value.ToString(),
                TaskID      = Setting.Value.Log_CurrentTaskID++
            };

            Setting.Save();
            bool isToday = false;

            if (task.Date == DateTime.Today.ToShortDateString())
            {
                isToday = true;
            }
            if (isToday)
            {
                TaskTracker.AddTask(task);
            }
            else
            {
                var path = Program.DataPath + "\\TaskData\\" + task.Date.Replace('/', '-') + ".json";
                Day day;
                if (!File.Exists(path))
                {
                    day = new Day()
                    {
                        Date             = task.Date,
                        DayID            = Setting.Value.Log_CurrentDayID++,
                        EndTime          = task.EndTime,
                        LongDate         = DateTime.Parse(task.Date).ToLongDateString(),
                        StartTime        = task.StartTime,
                        Tasks            = new List <Task>(),
                        TotalTime        = task.ElapsedTime,
                        TotalTimeOnTasks = task.ElapsedTime,
                        TotalUsedTime    = task.TimeUsed
                    };
                    day.Tasks.Add(task);
                }
                else
                {
                    day = Serializer <Day> .LoadFromJSONFile(path);

                    day.Tasks.Add(task);
                    day.TotalTimeOnTasks = TaskTracker.RecursionElapsedTime(day, 0);
                    day.TotalUsedTime    = TaskTracker.GetTotalTimeUsed(day);
                }
                TaskTracker.ExportDay(day);
            }
        }