public List <TaskClass> getGoogleTasks() //get all google upcoming tasks { List <TaskClass> googleTasks = new List <TaskClass>(); // Define parameters of request. EventsResource.ListRequest request = service.Events.List("primary"); request.TimeMin = DateTime.Now; request.ShowDeleted = false; request.SingleEvents = true; request.MaxResults = 10; request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; // List events. Events events = request.Execute(); if (events.Items != null && events.Items.Count > 0) { foreach (var eventItem in events.Items) { string whenString = eventItem.Start.DateTime.ToString(); //Setup time and date of google task if (String.IsNullOrEmpty(whenString)) { whenString = eventItem.Start.Date; } DateTime when = DateTime.Parse(whenString); TaskClass newTask = new TaskClass(eventItem.Summary, eventItem.Description, TaskImportance.Normal, when, true, eventItem); googleTasks.Add(newTask); } } return(googleTasks); }
public TaskButton(TaskClass _taskClass, int _index, TasksManager _tasksManager) { taskClass = _taskClass; Text = taskClass.taskName; index = _index; tasksManager = _tasksManager; numOfLines = taskClass.taskDescription.Split('\n').Length; this.Size = tasksManager.taskButtonSize; this.BackColor = System.Drawing.Color.LightGray; importanceComboBox = new ComboBox(); //Setum importance combo box this.Controls.Add(importanceComboBox); importanceComboBox.Location = new System.Drawing.Point(500, 6); importanceComboBox.Items.AddRange(new string[4] { "Not important", "Normal", "Important", "Extremely important" }); importanceComboBox.SelectedIndex = (int)taskClass.taskImportance; importanceComboBox.Enabled = false; taskDescriptionTextBox = new TextBox(); //Setup description this.Controls.Add(taskDescriptionTextBox); taskDescriptionTextBox.Location = new System.Drawing.Point(20, 30); taskDescriptionTextBox.Text = taskClass.taskDescription; taskDescriptionTextBox.Enabled = false; taskDescriptionTextBox.Multiline = true; taskDescriptionTextBox.Size = new System.Drawing.Size(450, 15 * numOfLines + 2); taskNametextBox = new TextBox(); //Setup name this.Controls.Add(taskNametextBox); taskNametextBox.Location = new System.Drawing.Point(20, 6); taskNametextBox.Text = taskClass.taskName; taskNametextBox.Enabled = false; taskNametextBox.Size = new System.Drawing.Size(300, 30); taskDateAndTime = new Label(); //Setup deadline text this.Controls.Add(taskDateAndTime); taskDateAndTime.Location = new System.Drawing.Point(500, 30); taskDateAndTime.Text = taskClass.taskDateAndTime.ToString(); taskDateAndTimeLeft = new Label(); //Setup time left this.Controls.Add(taskDateAndTimeLeft); taskDateAndTimeLeft.Location = new System.Drawing.Point(350, 9); taskDateAndTimeLeft.Text = (taskClass.taskDateAndTime - DateTime.Now).ToString(); taskDateAndTimeLeft.Click += TaskDateAndTimeLeftClicked; deleteTaskButton = new Button(); //Setup delete button this.Controls.Add(deleteTaskButton); deleteTaskButton.Location = new System.Drawing.Point(615, 30); deleteTaskButton.Size = new System.Drawing.Size(20, 20); deleteTaskButton.Text = "X"; deleteTaskButton.Click += DeleteButtonClicked; editTaskButton = new Button(); //Setup edit button this.Controls.Add(editTaskButton); editTaskButton.Location = new System.Drawing.Point(615, 55); editTaskButton.Size = new System.Drawing.Size(20, 20); editTaskButton.Text = "E"; editTaskButton.Click += EditTaskButtonClicked; }
private void AddNewTaskButton_Click(object sender, EventArgs e) //Add task completed { if (NewTaskImportanceComboBox.SelectedIndex != -1 && NewTaskNameTextBox.Text != "") { TaskImportance taskImportance = (TaskImportance)NewTaskImportanceComboBox.SelectedIndex; DateTime taskDateTime = TimeHelper.ChangeTime(NewTaskDatePicker.Value, newTaskTimePicker.Value.Hour, newTaskTimePicker.Value.Minute, newTaskTimePicker.Value.Second, newTaskTimePicker.Value.Millisecond); TaskClass newTask = new TaskClass(NewTaskNameTextBox.Text, NewTaskDescriptiontextBox.Text, taskImportance, taskDateTime); allTasks.Add(newTask); SortTaskList(); NewTaskPanel.Visible = false; SaveTasksToFile(); } }
void SortByImportance() { bool repeat = true; while (repeat) { repeat = false; for (int i = 0; i < allTasks.Count - 1; i++) { if (allTasks[i + 1].taskImportance > allTasks[i].taskImportance) //Swap by importance { TaskClass t = allTasks[i + 1]; allTasks[i + 1] = allTasks[i]; allTasks[i] = t; repeat = true; } } } }
void SortByTime() { bool repeat = true; while (repeat) { repeat = false; for (int i = 0; i < allTasks.Count - 1; i++) { if (allTasks[i].taskDateAndTime > allTasks[i + 1].taskDateAndTime) { TaskClass taskClass = allTasks[i + 1]; allTasks[i + 1] = allTasks[i]; allTasks[i] = taskClass; repeat = true; } } } }