public void Update(CombinedTaskHistory task) { if (task.Id == -1) // not in the DB { m_db.Insert(new TaskHistory() { TaskId = task.TaskId [0], Begin = task.Begin, End = task.End }); // } else if (task.Id != -1 && task.TaskId[0] == -1) { // to rest // m_db.Delete (task.Id); } else { m_db.Update(new TaskHistory() { Id = task.Id, TaskId = task.TaskId[0], Begin = task.Begin, End = task.End }); } if (State == 1 && m_data.current_exec.Id == task.Id) // working { m_data.current_exec.TaskId = task.TaskId[0]; m_data.current_exec.Begin = task.Begin; } UpdateTaskHistoryList(); }
private void UpdateTaskHistoryList() { m_histories.Clear(); m_raw_histories.Clear(); // var resulth = m_db.Table<TaskHistory> (); var today_day = new DateTime(ShowDate.Year, ShowDate.Month, ShowDate.Day); var next_day = new DateTime(ShowDate.Year, ShowDate.Month, ShowDate.Day); next_day = next_day.AddDays(1.0); // var resulth = from x in m_db.Table<TaskHistory> () where x.End >= today_day || x.Begin >= today_day orderby x.Begin select x; var resulth = from x in m_db.Table <TaskHistory> () where (x.End >= today_day && x.End < next_day) || (x.Begin >= today_day && x.Begin < next_day) orderby x.Begin select x; CombinedTaskHistory current = null; foreach (var i in resulth) { if (current == null) // first // raw task { m_raw_histories.Add(new CombinedTaskHistory() { Id = i.Id, TaskId = new ObservableCollection <int> () { i.TaskId }, Begin = i.Begin, End = i.End, Rest = new TimeSpan(0) }); // combind task current = new CombinedTaskHistory() { TaskId = new ObservableCollection <int> () { i.TaskId }, Begin = i.Begin, End = i.End, Rest = new TimeSpan(0) }; m_histories.Add(current); } else { ///////////////////////////////////////////////////////// // raw task if (i.Begin - current.End >= new TimeSpan(0, 5, 0)) // more than 5 min rest { m_raw_histories.Add(new CombinedTaskHistory() { Id = -1, // not in DB TaskId = new ObservableCollection <int> () { -1 }, Begin = current.End, End = i.Begin, Rest = new TimeSpan(0) }); } m_raw_histories.Add(new CombinedTaskHistory() { Id = i.Id, TaskId = new ObservableCollection <int>() { i.TaskId }, Begin = i.Begin, End = i.End, Rest = new TimeSpan(0) }); //////////////////////////////////////////////////////// // combind task if ((from x in current.TaskId where x == i.TaskId select x).Count() != 0) // same task // combind task { current.Rest += i.Begin - current.End; current.End = i.End; } else // different task { if (i.End - i.Begin <= new TimeSpan(0, 30, 0) && // 30 minutes or less working time current.End - current.Begin <= new TimeSpan(1, 0, 0) && // 1hour or less combined tasks i.Begin - current.End <= new TimeSpan(0, 15, 0)) // 15min or less rest time // combine two different task when execution time is less { current.TaskId.Add(i.TaskId); current.Rest += i.Begin - current.End; current.End = i.End; } else // new combined task { if (i.Begin - current.End >= new TimeSpan(0, 5, 0)) // have 5 minutes span between two tasks // insert { current = new CombinedTaskHistory() { TaskId = new ObservableCollection <int> () { -1 }, Begin = current.End, End = i.Begin, Rest = new TimeSpan(0) }; m_histories.Add(current); } // Add New TaskHistory current = new CombinedTaskHistory() { TaskId = new ObservableCollection <int> (), Begin = i.Begin, End = i.End, Rest = new TimeSpan(0) }; current.TaskId.Add(i.TaskId); m_histories.Add(current); } } } } }
private void UpdateTaskHistoryList() { m_histories.Clear (); m_raw_histories.Clear (); // var resulth = m_db.Table<TaskHistory> (); var today_day = new DateTime (ShowDate.Year, ShowDate.Month, ShowDate.Day); var next_day = new DateTime (ShowDate.Year, ShowDate.Month, ShowDate.Day); next_day = next_day.AddDays (1.0); // var resulth = from x in m_db.Table<TaskHistory> () where x.End >= today_day || x.Begin >= today_day orderby x.Begin select x; var resulth = from x in m_db.Table<TaskHistory> () where (x.End >= today_day && x.End < next_day) || (x.Begin >= today_day && x.Begin < next_day) orderby x.Begin select x; CombinedTaskHistory current = null; foreach (var i in resulth) { if (current == null) { // first // raw task m_raw_histories.Add (new CombinedTaskHistory () { Id = i.Id, TaskId = new ObservableCollection<int> () { i.TaskId }, Begin = i.Begin, End = i.End, Rest = new TimeSpan (0) }); // combind task current = new CombinedTaskHistory () { TaskId = new ObservableCollection<int> () { i.TaskId }, Begin = i.Begin, End = i.End, Rest = new TimeSpan (0) }; m_histories.Add (current); } else { ///////////////////////////////////////////////////////// // raw task if (i.Begin - current.End >= new TimeSpan (0, 5, 0)) { // more than 5 min rest m_raw_histories.Add (new CombinedTaskHistory () { Id = -1, // not in DB TaskId = new ObservableCollection<int> () { -1 }, Begin = current.End, End = i.Begin, Rest = new TimeSpan (0) }); } m_raw_histories.Add (new CombinedTaskHistory () { Id = i.Id, TaskId = new ObservableCollection<int>() { i.TaskId }, Begin = i.Begin, End = i.End, Rest = new TimeSpan(0) }); //////////////////////////////////////////////////////// // combind task if ((from x in current.TaskId where x == i.TaskId select x).Count() != 0) { // same task // combind task current.Rest += i.Begin - current.End; current.End = i.End; } else { // different task if (i.End - i.Begin <= new TimeSpan (0, 30, 0) && // 30 minutes or less working time current.End - current.Begin <= new TimeSpan (1, 0, 0) && // 1hour or less combined tasks i.Begin - current.End <= new TimeSpan (0, 15, 0)) { // 15min or less rest time // combine two different task when execution time is less current.TaskId.Add (i.TaskId); current.Rest += i.Begin - current.End; current.End = i.End; } else { // new combined task if (i.Begin - current.End >= new TimeSpan (0, 5, 0)) { // have 5 minutes span between two tasks // insert current = new CombinedTaskHistory () { TaskId = new ObservableCollection<int> () { -1 }, Begin = current.End, End = i.Begin, Rest = new TimeSpan (0) }; m_histories.Add (current); } // Add New TaskHistory current = new CombinedTaskHistory () { TaskId = new ObservableCollection<int> (), Begin = i.Begin, End = i.End, Rest = new TimeSpan (0) }; current.TaskId.Add (i.TaskId); m_histories.Add (current); } } } } }
public void Update(CombinedTaskHistory task) { if (task.Id == -1) { // not in the DB m_db.Insert (new TaskHistory () { TaskId = task.TaskId [0], Begin = task.Begin, End = task.End }); // } else if (task.Id != -1 && task.TaskId[0] == -1) { // to rest // m_db.Delete (task.Id); } else { m_db.Update (new TaskHistory () { Id = task.Id, TaskId = task.TaskId[0], Begin = task.Begin, End = task.End }); } if (State == 1 && m_data.current_exec.Id == task.Id) { // working m_data.current_exec.TaskId = task.TaskId[0]; m_data.current_exec.Begin = task.Begin; } UpdateTaskHistoryList (); }