/// <summary> /// EditForm's Load event. /// </summary> private void EditForm_Load(object sender, EventArgs e) { if (!addMode) { taskNameTextBox.Text = currentTask.Name.Trim(); string date = currentTask.DueDate; dueDateTimePicker.Value = (date == null) ? DateTime.Now : DateTime.Parse(date); if (currentTask.IsDone) { doneCheckBox.Checked = true; } if (!String.IsNullOrEmpty(currentTask.Priority)) { string priority = currentTask.Priority; if (priority == "A") { priorityComboBox.SelectedIndex = 0; } else if (priority == "B") { priorityComboBox.SelectedIndex = 1; } else if (priority == "C") { priorityComboBox.SelectedIndex = 2; } else if (priority == "D") { priorityComboBox.SelectedIndex = 3; } else if (priority == "E") { priorityComboBox.SelectedIndex = 4; } } } else { Text = "Add a new task"; currentTask = new Task(); } // Contexts contextComboBox.Items.Add(""); foreach (var context in mainForm.oTaskCollection.GetContexts()) { contextComboBox.Items.Add(context); if ((!addMode) && (currentTask.Context == context)) { contextComboBox.SelectedIndex = contextComboBox.Items.Count - 1; } } // Projects projectComboBox.Items.Add(""); foreach (var project in mainForm.oTaskCollection.GetProjects()) { projectComboBox.Items.Add(project); if ((!addMode) && (currentTask.Project == project)) { projectComboBox.SelectedIndex = projectComboBox.Items.Count - 1; } } }
/// <summary> /// Removes a task /// </summary> /// <param name="p_oTask">Task</param> /// <returns>Boolean</returns> public bool Remove(Task p_oTask) { try { // Creating a fake collection containing the task for removal. TaskCollection oFakeTaskCollection = new TaskCollection(); oFakeTaskCollection.Items.Add(p_oTask); // Getting the new list of tasks without the removed one. IEnumerable<Task> oTasksWithoutException = new List<Task>(); oTasksWithoutException = this.Items.Except(oFakeTaskCollection.Items); // Setting the new list as the collection. this.Items = (List<Task>)oTasksWithoutException; return true; } catch (Exception) { return false; } }
/// <summary> /// Adds a new object to the ObjectListView. /// </summary> /// <param name="p_oNewTask">Task</param> public void AddObjectToObjectListView(Task p_oNewTask) { this.oTaskCollection.Items.Add(p_oNewTask); this.objectListView.AddObject(p_oNewTask); }
/// <summary> /// Parses the text file and creates Task for every lines. /// </summary> /// <param name="p_sFilePath">String</param> public void ParseTextFile(string p_sFilePath) { string[] todoContentLines = File.ReadAllLines(p_sFilePath); string date = String.Empty; string priority = String.Empty; string task = String.Empty; string context = String.Empty; string project = String.Empty; int lineNumber = 0; foreach (string line in todoContentLines) { Task oTask = new Task(); date = ""; priority = ""; context = ""; project = ""; task = line; if (priorityRegex.Match(line).Success) { priority = priorityRegex.Match(line).Value; task = task.Replace(priority + " ", ""); oTask.Priority = priority.Replace("(", "").Replace(")", ""); } if (dateRegex.Match(line).Success) { date = dateRegex.Match(line).Value; task = task.Replace(date + " ", ""); oTask.DueDate = date; } if (contextRegex.Match(line).Success) { context = contextRegex.Match(line).Value; task = task.Replace(context, ""); oTask.Context = context; } if (projectRegex.Match(line).Success) { project = projectRegex.Match(line).Value; task = task.Replace(project, ""); oTask.Project = project; } oTask.LineNumber = lineNumber; oTask.Name = task.Replace("x ", ""); oTask.IsDone = (doneRegex.Match(line).Success) ? true : false; this.Items.Add(oTask); lineNumber++; } }