private void btnSelect_Click(object sender, EventArgs e) { this.groupBox.Controls.Clear(); int top = 20; string projectTitle = (string)this.ProjectsDropDown.SelectedValue; System.Collections.ObjectModel.Collection <ProjectComponent> projectAndPhases = new System.Collections.ObjectModel.Collection <ProjectComponent>(); if (projectTitle.Trim().Length == 0) { MessageBox.Show("You must supply a Project Title"); } else { Project myProject = Project.ProjectByTitle(projectTitle); projectAndPhases.Add(myProject); Phases = new List <ProjectComponentFormControl>(); Tasks = new List <ProjectComponentFormControl>(); SelectedProject = new ProjectComponentFormControl(myProject.Id, myProject.Title, myProject.EstimatedHours, 10, top, "", SharePointActionMode.Import); this.groupBox.Controls.Add(SelectedProject.Include); this.groupBox.Controls.Add(SelectedProject.Title); this.groupBox.Controls.Add(SelectedProject.EstimatedHours); top += 22; // Add the phases this.SelectedProject.Children = new List <ProjectComponentFormControl>(); foreach (Phase phase in myProject.Children) { ProjectComponentFormControl phaseComponet = new ProjectComponentFormControl(phase.Id, phase.Title, phase.EstimatedHours, 20, top, myProject.Title, SharePointActionMode.Import); this.SelectedProject.Children.Add(phaseComponet); //Phases.Add(phaseComponet); this.groupBox.Controls.Add(phaseComponet.Include); this.groupBox.Controls.Add(phaseComponet.Title); this.groupBox.Controls.Add(phaseComponet.EstimatedHours); top += 22; projectAndPhases.Add(phase); // Add the tasks this.SelectedProject.Children[this.SelectedProject.Children.Count - 1].Children = new List <ProjectComponentFormControl>(); foreach (DowCorning.Applications.EstimationListUtilities.Task task in phase.Children) { ProjectComponentFormControl taskComponent = new ProjectComponentFormControl(task.Id, task.Title, task.EstimatedHours, 30, top, phase.Title, SharePointActionMode.Import); this.SelectedProject.Children[this.SelectedProject.Children.Count - 1].Children.Add(taskComponent); //Phases.Add(taskComponent); this.groupBox.Controls.Add(taskComponent.Include); this.groupBox.Controls.Add(taskComponent.Title); this.groupBox.Controls.Add(taskComponent.EstimatedHours); top += 22; } } } }
/// <summary> /// Populates the form with the different phases and tasks associated to the project selected. /// </summary> /// <param name="sender">Select button</param> /// <param name="e">Any event arguments</param> private void btnSelect_Click(object sender, EventArgs e) { this.groupBox.Controls.Clear(); int top = 20; string typeId = this.ProjectsDropDown.SelectedValue.ToString(); System.Collections.ObjectModel.Collection <ProjectComponent> projectAndPhases = new System.Collections.ObjectModel.Collection <ProjectComponent>(); if (string.IsNullOrEmpty(typeId)) { MessageBox.Show("You must supply a Project Title"); } else { DataRow[] typeRow = this.Info.Types.Select("type_id = " + typeId); TaskInfo selectedType = new TaskInfo() { TaskType = TaskType.Type, Type_Id = typeRow[0]["type_id"].ToString(), Type_Name = typeRow[0]["type_name"].ToString(), SharePointId = typeRow[0]["SharePoint_Id"].ToString() }; selectedType.GetTime(); int sharepointId; if (!int.TryParse(selectedType.SharePointId, out sharepointId)) { sharepointId = -1; } SelectedProject = new ProjectComponentFormControl(sharepointId, selectedType.Type_Name, selectedType.OverallTotal.TotalHours, 10, top, "", SharePointActionMode.Export); this.groupBox.Controls.Add(SelectedProject.Include); this.groupBox.Controls.Add(SelectedProject.Title); this.groupBox.Controls.Add(SelectedProject.EstimatedHours); top += 22; // Add the phases this.SelectedProject.Children = new List <ProjectComponentFormControl>(); DataRow[] taskRows = this.Info.Tasks.Select("type_id = " + typeId); foreach (DataRow taskDR in taskRows) { TaskInfo task = new TaskInfo() { TaskType = TaskType.Task, Type_Id = selectedType.Type_Id, Task_Id = taskDR["task_id"].ToString(), Task_Name = taskDR["task_name"].ToString(), Link_Id = taskDR["link_id"].ToString(), SharePointId = taskDR["sharePoint_id"].ToString() }; task.GetTime(); ProjectComponentFormControl phaseComponet = new ProjectComponentFormControl(int.Parse(string.IsNullOrEmpty(task.SharePointId) ? "-1" : task.SharePointId), task.Task_Name, task.OverallTotal.TotalHours, 20, top, selectedType.Name, SharePointActionMode.Export); this.SelectedProject.Children.Add(phaseComponet); this.groupBox.Controls.Add(phaseComponet.Include); this.groupBox.Controls.Add(phaseComponet.Title); this.groupBox.Controls.Add(phaseComponet.EstimatedHours); top += 22; this.SelectedProject.Children[this.SelectedProject.Children.Count - 1].Children = new List <ProjectComponentFormControl>(); // Add the tasks DataRow[] subTaskRows = this.Info.SubTask.Select("link_id = " + task.Link_Id); foreach (DataRow subTaskDR in subTaskRows) { TaskInfo subTask = new TaskInfo() { Type_Id = selectedType.Type_Id, Task_Id = task.Task_Id, Link_Id = task.Link_Id, Sub_Task_Name = subTaskDR["sub_task_name"].ToString(), SharePointId = subTaskDR["sharePoint_id"].ToString(), Sub_Task_Id = subTaskDR["sub_task_id"].ToString(), TaskType = TaskType.SubTask }; subTask.GetTime(); ProjectComponentFormControl taskComponent = new ProjectComponentFormControl(int.Parse(string.IsNullOrEmpty(subTask.SharePointId) ? "-1" : subTask.SharePointId), subTask.Sub_Task_Name, subTask.OverallTotal.TotalHours, 30, top, task.Name, SharePointActionMode.Export); this.SelectedProject.Children[this.SelectedProject.Children.Count - 1].Children.Add(taskComponent); this.groupBox.Controls.Add(taskComponent.Include); this.groupBox.Controls.Add(taskComponent.Title); this.groupBox.Controls.Add(taskComponent.EstimatedHours); top += 22; } } } }