/// <summary> /// Builds a stage level Gant Chart where each item represents an event of the stage. /// </summary> /// <param name="chart"></param> /// <param name="stageId"></param> public static void BuildStageLevelGantChart(GantChart chart, int stageId) { chart.Controls.Clear(); ProjectStage stageBiz = new ProjectStage(); stageBiz.Get(stageId); string gantTitle = stageBiz[ProjectStage.Name].ToString() + " [Events]"; chart.GantTitle = gantTitle; string stageColor = stageBiz[ProjectStage.ColorCode].ToString(); //ProjectStageEvent biz = new ProjectStageEvent(); //biz.GetByParent(stageId); //foreach (DataRow stageEventRecord in biz.DataSourceView.Table.Rows) DataView view = BusinessObject.GetByParentAsDataView <ProjectStageEvent>(stageId); foreach (DataRow stageEventRecord in view.Table.Rows) { string stageEventName = stageEventRecord[ProjectStageEvent.Name].ToString(); DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MaxValue; if (stageEventRecord[ProjectStageEvent.EventStartDate] != null) { string dateString = stageEventRecord[ProjectStageEvent.EventStartDate].ToString(); if (!string.IsNullOrEmpty(dateString)) { startDate = DateTime.Parse(dateString); } } if (stageEventRecord[ProjectStageEvent.EventEndDate] != null) { string dateString = stageEventRecord[ProjectStageEvent.EventEndDate].ToString(); if (!string.IsNullOrEmpty(dateString)) { endDate = DateTime.Parse(dateString); } } if (!(startDate == DateTime.MinValue && endDate == DateTime.MaxValue)) { GantItem item = new GantItem(startDate, endDate); item.Description = stageEventName; string startText = startDate.ToShortDateString(); string endText = endDate.ToShortDateString(); item.ToolTip = "Start Date: " + startText + " - End Date: " + endText; // Color item based on it's parent stage. if (!string.IsNullOrEmpty(stageColor)) { item.Color = stageColor; } chart.Controls.Add(item); } } }
/// <summary> /// Builds an organzational level Gant Chart where items on chart represents each /// stage belonging to the organization /// </summary> /// <param name="chart"></param> /// <param name="projectId"></param> /// <param name="organizationId"></param> public static void BuildOrganizationLevelGantChart(GantChart chart, int projectId, int organizationId) { ProjectOrganization orgBiz = new ProjectOrganization(); orgBiz.Get(organizationId); string gantTitle = "Stages for [" + orgBiz[ProjectOrganization.Name].ToString() + "]"; chart.GantTitle = gantTitle; ProjectManagementDa da = new ProjectManagementDa(); DataTable orgStages = da.GetStagesByProjectAndOrganization(projectId, organizationId); // Loop through all stages in this organization foreach (DataRow orgStage in orgStages.Rows) { string stageName = orgStage[ProjectStage.Name].ToString(); string stageColor = orgStage[ProjectStage.ColorCode].ToString(); DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MaxValue; //ProjectStageEvent stageEventBiz = new ProjectStageEvent(); //stageEventBiz.GetByParent(int.Parse(orgStage[ProjectStage.StageId].ToString())); //DataTable orgStageEvents = stageEventBiz.DataSourceView.Table; DataView orgStageEventsView = BusinessObject.GetByParentAsDataView <ProjectStageEvent>((int)orgStage[ProjectStage.StageId]); DataTable orgStageEvents = orgStageEventsView.Table; // Increment total events by adding events in this stage int totalStageEventsForStage = orgStageEvents.Rows.Count; int totalCompletedStageEvents = 0; // Loop though all events in this stage foreach (DataRow orgStageEvent in orgStageEvents.Rows) { bool hasStart = false; bool hasEnd = false; if (orgStageEvent[ProjectStageEvent.EventStartDate] != null) { if (!string.IsNullOrEmpty(orgStageEvent[ProjectStageEvent.EventStartDate].ToString())) { DateTime recordStartDate = (DateTime)orgStageEvent[ProjectStageEvent.EventStartDate]; hasStart = true; if (startDate == DateTime.MinValue || recordStartDate < startDate) { startDate = recordStartDate; } } } if (orgStageEvent[ProjectStageEvent.EventEndDate] != null) { if (!string.IsNullOrEmpty(orgStageEvent[ProjectStageEvent.EventEndDate].ToString())) { DateTime recordEndDate = (DateTime)orgStageEvent[ProjectStageEvent.EventEndDate]; hasEnd = true; if (endDate == DateTime.MaxValue || recordEndDate > endDate) { endDate = recordEndDate; } } } if (hasStart && hasEnd) { totalCompletedStageEvents++; } } if (orgStageEvents.Rows.Count > 0) { string stageId = orgStage[ProjectStage.StageId].ToString(); string tableName = "ProjectStage"; GantItem gant = GetGantItem(startDate, endDate, totalStageEventsForStage, totalCompletedStageEvents, tableName, stageId, stageName); if (!string.IsNullOrEmpty(stageColor)) { gant.Color = stageColor; } chart.Controls.Add(gant); } } }
/// <summary> /// Bind Admin Level Gant Chart based on participating organizations. /// </summary> public static void BuildAdminLevelGantChart(GantChart chart, int projectId) { chart.GantTitle = "List Of Organizations"; List <GantItem> listGantItems = new List <GantItem>(); //ProjectGantChart.Controls.Clear(); ProjectManagementDa da = new ProjectManagementDa(); DataTable projectOrgs = da.GetAllOrganizationsByProjectId(projectId); // Loop through all organizations for this project foreach (DataRow projectOrg in projectOrgs.Rows) { int orgId = int.Parse(projectOrg[ProjectOrganization.OrganizationId].ToString()); string orgColor = projectOrg[ProjectOrganization.ColorCode].ToString(); DataTable orgStages = da.GetStagesByProjectAndOrganization(projectId, orgId); DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MaxValue; // Keep track of all the events over all the stages // and how many of then are completed int totalStageEventsForOrganization = 0; int totalCompletedStageEvents = 0; string orgName = projectOrg[ProjectOrganization.ShortName].ToString(); // Loop through each stage for an organization foreach (DataRow orgStage in orgStages.Rows) { int stageId = int.Parse(orgStage[ProjectStage.StageId].ToString()); //ProjectStageEvent biz = new ProjectStageEvent(); //biz.GetByParent(stageId); //DataView listOfStageEvents = biz.DataSourceView; DataView listOfStageEvents = BusinessObject.GetByParentAsDataView <ProjectStageEvent>(stageId); totalStageEventsForOrganization += listOfStageEvents.Count; // Loop through each event for a stage foreach (DataRow row in listOfStageEvents.Table.Rows) { bool hasStart = false; bool hasEnd = false; if (row[ProjectStageEvent.EventStartDate] != null && !string.IsNullOrEmpty(row[ProjectStageEvent.EventStartDate].ToString())) { hasStart = true; DateTime recordStartDate = (DateTime)row[ProjectStageEvent.EventStartDate]; if (startDate == DateTime.MinValue || recordStartDate < startDate) { startDate = recordStartDate; } } if (row[ProjectStageEvent.EventEndDate] != null && !string.IsNullOrEmpty(row[ProjectStageEvent.EventEndDate].ToString())) { hasEnd = true; DateTime recordEndDate = (DateTime)row[ProjectStageEvent.EventEndDate]; if (endDate == DateTime.MaxValue || recordEndDate > endDate) { endDate = recordEndDate; } } if (hasStart && hasEnd) { totalCompletedStageEvents++; } } // int hasStartEnd = listOfStageEvents.Table.Select("EventStartDate <> " + DBNull.Value.ToString() + " AND EventEndDate <> " + DBNull.Value.ToString()).Length; } string myOrgId = projectOrg[ProjectOrganization.OrganizationId].ToString(); string tableName = "ProjectOrganization"; // If this organization has no stages, and therefore no events, do not add to chart if (orgStages.Rows.Count > 0) { GantItem gant = GetGantItem(startDate, endDate, totalStageEventsForOrganization, totalCompletedStageEvents, tableName, myOrgId, orgName); listGantItems.Add(gant); // Set Color Code if Applicable if (!string.IsNullOrEmpty(orgColor)) { gant.Color = orgColor; } //chart.Controls.Add(gant); } } // sort in ascending order listGantItems.Sort(delegate(GantItem gant1, GantItem gant2) { return (gant1.StartDate.CompareTo(gant2.StartDate)); }); foreach (GantItem tempItem in listGantItems) { chart.Controls.Add(tempItem); } }