public IEnumerable<Task> LoadTasks() { XmlSerializer xmlSerializer = new XmlSerializer (typeof(DataSet)); DataSet ds; var tasks = new List<Task> (); try { FileStream readStream = new FileStream (path, FileMode.Open); ds = (DataSet)xmlSerializer.Deserialize (readStream); readStream.Close (); } catch (IOException) { return tasks; } foreach (var row in ds.Tables [0].AsEnumerable ()) { var task = new Task { CreateDate = DateTime.Parse (row ["Task_CreateDate"].ToString ()), Description = row ["Task_Description"].ToString (), Title = row ["Task_Title"].ToString (), IsDone = Boolean.Parse (row ["Task_IsDone"].ToString ()), Priority = (Priority) Int32.Parse (row ["Task_Priority"].ToString ()) }; if (row ["Task_Deadline"] is DBNull) { task.Deadline = null; } else { task.Deadline = DateTime.Parse(row ["Task_Deadline"].ToString ()); } tasks.Add (task); } return tasks; }
void AppendTask(Task task) { tasksList.AppendValues (task, task.IsDone, task.Title, task.Deadline.HasValue ? task.Deadline.Value.ToShortDateString () : "infinity", task.Priority.ToString ()); var iter = FindTask (task, filter); if (!iter.Equals (TreeIter.Zero)) { tasksTreeView.Selection.SelectIter (iter); } else { tasksTreeView.Selection.UnselectAll (); } }
void RemoveTask(Task task) { TreeIter iter = FindTask (task, tasksList); if (iter.Equals (TreeIter.Zero)) { return; } tasksList.Remove (ref iter); tasksTreeView.Selection.UnselectAll (); }
public void UpdateTask(Task task) { TreeIter iter = FindTask (task, tasksList); if (iter.Equals (TreeIter.Zero)) { return; } if (tasksList.GetValue (iter, 0) == task) { tasksList.SetValue (iter, 1, task.IsDone); tasksList.SetValue (iter, 2, task.Title); tasksList.SetValue (iter, 3, task.Deadline.HasValue ? task.Deadline.Value.ToShortDateString () : "infinity"); tasksList.SetValue (iter, 4, task.Priority.ToString ()); } }
static TreeIter FindTask(Task task, ITreeModel model) { TreeIter iter; model.GetIterFirst (out iter); if (iter.Equals (TreeIter.Zero)) { return TreeIter.Zero; } do { if (model.GetValue (iter, 0) == task) { return iter; } } while (model.IterNext (ref iter)); return TreeIter.Zero; }
public TaskEventArgs(Task task, TaskStatus status) { Task = task; Status = status; }
private void OnTaskChanged(Task task, TaskStatus status) { if (TaskChanged != null) { TaskChanged (this, new TaskEventArgs (task, status)); } }
public void RemoveTask(Task task) { if (tasks.Exists (t => t == task)) { tasks.Remove (task); OnTaskChanged (task, TaskStatus.Remove); OnModelStateModified (true); } }
public void AddTask(Task task) { bool taskExists = tasks.Exists (t => t == task); if (!taskExists) { tasks.Add (task); } OnTaskChanged (task, taskExists ? TaskStatus.Update : TaskStatus.Add); OnModelStateModified (true); }
public void SetCurrentTask(Task task) { currentTask = task; if (task == null) { removeTaskButton.Sensitive = false; saveTaskButton.Label = "Add new task"; } else { removeTaskButton.Sensitive = true; saveTaskButton.Label = "Save"; } }