Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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 ();
            }
        }
Ejemplo n.º 3
0
        void RemoveTask(Task task)
        {
            TreeIter iter = FindTask (task, tasksList);

            if (iter.Equals (TreeIter.Zero)) {
                return;
            }

            tasksList.Remove (ref iter);
            tasksTreeView.Selection.UnselectAll ();
        }
Ejemplo n.º 4
0
        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 ());
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 public TaskEventArgs(Task task, TaskStatus status)
 {
     Task = task;
     Status = status;
 }
Ejemplo n.º 7
0
 private void OnTaskChanged(Task task, TaskStatus status)
 {
     if (TaskChanged != null) {
         TaskChanged (this, new TaskEventArgs (task, status));
     }
 }
Ejemplo n.º 8
0
 public void RemoveTask(Task task)
 {
     if (tasks.Exists (t => t == task)) {
         tasks.Remove (task);
         OnTaskChanged (task, TaskStatus.Remove);
         OnModelStateModified (true);
     }
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
        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";
            }
        }