public Task Clone() { Task task = new Task(); task.id = this.id; task.parentId = this.parentId; task.description = this.description; task.iconId = this.iconId; task.isActive = this.isActive; task.estimation = this.estimation; task.hidden = this.hidden; task.priority = this.priority; task.notes = this.notes; return task; }
internal SummaryControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); InitializaInnerUserControls(); worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); //worker.OnBeforeDoWork += new AsyncWorker.OnBeforeDoWorkDelegate(worker_OnBeforeDoWork); //worker.OnWorkDone += new AsyncWorker.OnWorkDoneDelegate(worker_OnWorkDone); this.taskList.SmallImageList = IconsManager.IconsList; recentParentTasksList.Add(Tasks.RootTask); this.parentTaskComboBox.DisplayMember = "Description"; this.parentTaskComboBox.ValueMember = "Id"; this.parentTaskComboBox.DataSource = recentParentTasksList; this.fromDateTimePicker.Value = DateTime.Today; this.toDateTimePicker.Value = DateTime.Today; if (recentParentTasksList.Count > 0) { parentTask = (Task) recentParentTasksList[0]; this.parentTaskComboBox.SelectedValue = parentTask.Id; } this.fromDateTimePicker.ValueChanged += new EventHandler(this.dateTimePicker_ValueChanged); fromDateTimePicker.DropDown += new EventHandler(fromDateTimePicker_DropDown); fromDateTimePicker.CloseUp += new EventHandler(fromDateTimePicker_CloseUp); this.toDateTimePicker.ValueChanged += new EventHandler(this.dateTimePicker_ValueChanged); toDateTimePicker.DropDown += new EventHandler(toDateTimePicker_DropDown); toDateTimePicker.CloseUp += new EventHandler(toDateTimePicker_CloseUp); this.parentTaskComboBox.SelectedIndexChanged += new EventHandler(parentTaskComboBox_SelectedIndexChanged); Logs.CurrentLogDurationChanged += new ElapsedEventHandler(TaskLogTimer_Elapsed); this.taskList.DoubleClick += new EventHandler(taskList_DoubleClick); this.Status = "Ready"; }
private void parentTaskComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (parentTaskComboBox.SelectedIndex == -1) return; parentTask = FindOnRecentParentTaskById(Convert.ToInt32(parentTaskComboBox.SelectedValue)); if(this.allRadioButton.Checked) DoRangeSummarySearch(); else LaunchSummarySearch(); }
private void SetListItemValues(ListViewItem item, Log log, Task taskRow) { item.Tag = log; if (taskRow!=null) { if (this.pathCheckBox.Checked && taskRow.Id != Tasks.IdleTask.Id) item.Text = Tasks.GetFullPath(taskRow.Id); else item.Text = taskRow.Description; item.ImageIndex = taskRow.IconId; } item.SubItems[DurationTaskHeader.Index].Text = ViewHelper.Int32ToTimeString(log.Duration); //item.SubItems[StartTimeHeader.Index].Text = log.InsertTime.ToShortTimeString(); CultureInfo cultureInfo; cultureInfo = (CultureInfo) CultureInfo.CurrentCulture.Clone(); cultureInfo.DateTimeFormat.ShortTimePattern = "hh:mm tt"; cultureInfo.DateTimeFormat.AMDesignator = "a.m."; cultureInfo.DateTimeFormat.PMDesignator = "p.m."; item.SubItems[StartTimeHeader.Index].Text = log.InsertTime.ToString("t", cultureInfo); }
private void AddSubTasks(Task parentTask, TaskMenuItem menuItem, EventHandler handler) { //ArrayList a = new ArrayList(); Task[] tasks; tasks = Tasks.GetChildTasks(parentTask.Id); if (tasks.Length == 0) return; foreach (Task task in tasks) { TaskMenuItem subMenu = new TaskMenuItem(task.Id); subMenu.Text = task.Description; subMenu.Pick += handler; //a.Add(subMenu); menuItem.MenuItems.Add(subMenu); AddSubTasks(task, subMenu, handler); } //menuItem.MenuItems.AddRange((TaskMenuItem[]) a.ToArray(typeof (TaskMenuItem))); }
public static void Initialize() { rootTask = null; tasks = new ArrayList(); LoadAllTasks(); currentTask = null; Logs.LogChanged += new Logs.LogChangeEventHandler(TasksLog_LogChanged); }
private static TreeListViewItem CreateNode(Task task) { TreeListViewItem node; // = new TreeListViewItem(task.Description, task.IconId); string priority = task.Priority > 0 ? task.Priority.ToString() : String.Empty; node = new TreeListViewItem(task.Description, new string[] { priority }); node.ImageIndex = task.IconId; node.Tag = task.Id; return node; }
private static void SetIdleTask() { foreach (Task task in tasks) { if(string.Compare(task.Description, DEFAULT_IDLE_TASK_NAME) ==0) { idleTask = task; return; } } AddIdleTask(); SetIdleTask(); }
private static void SetRootTask() { foreach (Task task in tasks) { if (task.ParentId ==-1) { rootTask = task; break; } } }
private static void InsertTask(ref Task task) { task.Id = DbHelper.ExecuteInsert( "INSERT INTO Tasks(Description, IconId, IsActive, ParentId, Hidden, Priority, Notes) VALUES (?, ?, ?, ?, ?, ?, ?)", new string[] { "Description", "IconId", "IsActive", "ParentId", "Hidden", "Priority", "Notes" }, new object[] {task.Description, task.IconId, task.IsActive, task.ParentId, task.Hidden, task.Priority, task.Notes}); }
private static void LoadAllTasks() { ArrayList rows = DbHelper.ExecuteGetRows("Select * from Tasks"); foreach (ListDictionary row in rows) { Task task = new Task(); task.Id = (int) row["Id"]; task.Description = (string) row["Description"]; if(row["ParentId"]==DBNull.Value) task.ParentId = -1; else task.ParentId = (int) row["ParentId"]; task.IconId = (int) row["IconId"]; task.IsActive = (bool) row["IsActive"]; if (row["Estimation"] == DBNull.Value) task.Estimation = 0; else task.Estimation = (int) row["Estimation"]; if (row["Hidden"] == DBNull.Value) task.Hidden = false; else task.Hidden = (bool)row["Hidden"]; if (row["Priority"] == DBNull.Value) task.Priority = 0; else task.Priority = (int)row["Priority"]; if (row["Notes"] == DBNull.Value) task.Notes = String.Empty; else task.Notes = (string)row["Notes"]; tasks.Add(task); } if (tasks.Count == 0) { AddRootTask(); AddIdleTask(); } else { SetRootTask(); SetIdleTask(); } }
private static void AddRootTask() { Task task = new Task(); task.Description = DEFAULT_ROOT_TASK_NAME; task.IsActive = true; task.IconId = IconsManager.DefaultTaskIconId; task.ParentId = -1; task.Id = DbHelper.ExecuteInsert( "INSERT INTO Tasks(Description, IconId, IsActive, ParentId) VALUES (?, ?, ?, ?)", new string[] {"Description", "IconId", "IsActive", "ParentId"}, new object[] {task.Description, task.IconId, task.IsActive, DBNull.Value}); tasks.Add(task); rootTask = task; }
private static void AddIdleTask() { Task task = new Task(); task.Description = DEFAULT_IDLE_TASK_NAME; task.IsActive = false; task.ParentId = rootTask.Id; task.IconId = IconsManager.IdleTaskIconId; InsertTask(ref task); tasks.Add(task); idleTask = task; }
public static void UpdateTask(Task task) { task.Description = task.Description.Trim(); if (task.Id == rootTask.Id || task.Id == idleTask.Id) throw new ApplicationException("This task can't be updated."); ValidateTaskData(ref task); Task sameTaskByDescription; sameTaskByDescription = InternalFindByParentIdAndDescription(task.ParentId, task.Description); if (sameTaskByDescription != null && sameTaskByDescription.Id != task.Id) { //Task needs to be merged with sameTaskByDescription, task will be deleted Logs.ChangeLogsTaskId(task.Id, sameTaskByDescription.Id); DeleteTask(task.Id); return; } DbHelper.ExecuteNonQuery( "UPDATE Tasks SET Description = ?, IconId = ?, IsActive = ?, ParentId = ?, Estimation = ?, Hidden = ?, Priority = ?, Notes = ? WHERE (Id = ?)" , new string[]{"Description", "IconId", "IsActive", "ParentId", "Estimation", "Hidden", "Priority", "Notes", "Id"}, new object[]{task.Description, task.IconId, task.IsActive, task.ParentId,task.Estimation, task.Hidden, task.Priority, task.Notes, task.Id}); for(int i = 0;i <tasks.Count;i++) { if(((Task)tasks[i]).Id == task.Id) { tasks[i] = task; if (currentTask != null && currentTask.Id == task.Id) currentTask = task; break; } } if (TaskChanged != null) TaskChanged(new TaskChangeEventArgs(task, DataRowAction.Change)); }
private void SetParent(int parentId) { if (FindOnRecentParentTaskById(parentId) == null) { parentTask = Tasks.FindById(parentId); parentTask.Description = ViewHelper.FixTaskPath(Tasks.GetFullPath(parentTask.Id), this.parentTaskComboBox.MaxLength); this.recentParentTasksList.Insert(0, parentTask); this.parentTaskComboBox.BeginUpdate(); this.parentTaskComboBox.DataSource = null; this.parentTaskComboBox.DisplayMember = "Description"; this.parentTaskComboBox.ValueMember = "Id"; this.parentTaskComboBox.DataSource = recentParentTasksList; this.parentTaskComboBox.EndUpdate(); } this.parentTaskComboBox.SelectedValue = parentId; }
private static void TasksLog_LogChanged(Logs.LogChangeEventArgs e) { if (e.Log.Id == Logs.CurrentLog.Id) { if (currentTask == null || e.Log.TaskId != currentTask.Id) { foreach (Task task in tasks) { if(task.Id == e.Log.TaskId) { currentTask = task; break; } } } } }
public static ArrayList GetTaskSummary(Task parentTask, DateTime initialDate, DateTime finalDate) { Logs.UpdateCurrentLogDuration(); ArrayList summaryList; ArrayList returnList = new ArrayList(); summaryList = ExecuteTaskSummary(initialDate, finalDate); while (summaryList.Count > 0) { TaskSummary currentSum = (TaskSummary) summaryList[0]; Task currentTask = Tasks.FindById(currentSum.TaskId); currentSum.Description = currentTask.Description; currentSum.IsActive = currentTask.IsActive; currentSum.IconId = currentTask.IconId; if (!currentSum.IsActive) { currentSum.TotalInactiveTime = currentSum.TotalActiveTime; currentSum.TotalActiveTime = 0; } //if currentSum.TotalEstimation = currentTask.Estimation; if (currentSum.TotalEstimation != 0) currentSum.TotalTimeOverEstimation = currentSum.TotalActiveTime + currentSum.TotalInactiveTime; if (currentTask.Id != Tasks.IdleTask.Id) //ignore idle time { if (currentTask.Id != parentTask.Id) { if (currentTask.ParentId ==-1) { summaryList.Remove(currentSum); continue; } //if if (currentTask.ParentId == parentTask.Id) { TaskSummary retSum = FindTaskSummaryByTaskId(returnList, currentSum.TaskId); if (retSum == null) { returnList.Add(currentSum); } else { retSum.TotalInactiveTime += currentSum.TotalInactiveTime; retSum.TotalActiveTime += currentSum.TotalActiveTime; retSum.TotalEstimation += currentSum.TotalEstimation; retSum.TotalTimeOverEstimation += currentSum.TotalTimeOverEstimation; } } else { TaskSummary currentSumParent; //First look at the return list currentSumParent = FindTaskSummaryByTaskId(returnList, currentTask.ParentId); if (currentSumParent==null)//If not found look at the summaryList currentSumParent = FindTaskSummaryByTaskId(summaryList, currentTask.ParentId); if (currentSumParent == null) //If parent not in the summary list { currentSumParent = currentSum; currentSumParent.TaskId = currentTask.ParentId; //just swith to parent task continue; //continue without remove the current sum from list } else //else acum totals { currentSumParent.TotalInactiveTime += currentSum.TotalInactiveTime; currentSumParent.TotalActiveTime += currentSum.TotalActiveTime; currentSumParent.TotalEstimation += currentSum.TotalEstimation; currentSumParent.TotalTimeOverEstimation += currentSum.TotalTimeOverEstimation; } } } else { currentSum.Description = NOT_DETAILED; returnList.Add(currentSum); } } //if summaryList.Remove(currentSum); } //while return returnList; }
private static void ValidateTaskData(ref Task task) { if (task.Description == null) throw new ApplicationException("Description can't be null"); task.Description = task.Description.Trim(); if (task.Description.Length == 0) throw new ApplicationException("Description can't be empty"); }
private void browseButton_Click(object sender, EventArgs e) { TaskSelectForm tgForm = new TaskSelectForm(); if(tgForm.ShowDialog(this)==DialogResult.OK) { if (FindById(tgForm.SelectedTaskId) == null) { Task parentTask = new Task(); parentTask.Id = tgForm.SelectedTaskId; parentTask.Description = ViewHelper.FixTaskPath(Tasks.GetFullPath(parentTask.Id), this.parentTaskComboBox.MaxLength); this.parentTasksList.Insert(0, parentTask); this.parentTaskComboBox.BeginUpdate(); this.parentTaskComboBox.DataSource = null; this.parentTaskComboBox.DisplayMember = "Description"; this.parentTaskComboBox.ValueMember = "Id"; this.parentTaskComboBox.DataSource = parentTasksList; this.parentTaskComboBox.EndUpdate(); } this.parentTaskComboBox.SelectedValue = tgForm.SelectedTaskId; } }
public TaskChangeEventArgs(Task task, DataRowAction action) { this.task = task; this.action = action; }
private void AddChildNodes(Task parentRow, TreeListViewItem nodeParent) { Task[] childTasks = Tasks.GetChildTasks(parentRow.Id); foreach (Task task in childTasks) { if (task.Id == Tasks.IdleTask.Id) continue; if(task.Hidden && !this.showHidden) continue; TreeListViewItem nodeChild = CreateNode(task); nodeParent.Items.Add(nodeChild); AddChildNodes(task, nodeChild); } }
public static Task AddTask(string description, int parentId, bool isActive, int iconId) { Task task = new Task(); task.Description = description; task.ParentId = parentId; task.IsActive = isActive; task.IconId = iconId; ValidateTaskData(ref task); Task sameTaskByDescription; sameTaskByDescription = InternalFindByParentIdAndDescription(task.ParentId, task.Description); if (sameTaskByDescription != null) throw new ApplicationException("Task already exist"); InsertTask(ref task); tasks.Add(task); if (TaskChanged != null) { TaskChanged(new TaskChangeEventArgs(task.Clone(), DataRowAction.Add)); } return task.Clone(); }