Example #1
0
        /// <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);
                }
            }
        }
Example #2
0
        /// <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);
            }
        }