Пример #1
0
        public static byte[] RenderLegendItem(string styleFilePath, string type)
        {
            byte[] ret = null;

            DateTime  startDate = DateTime.Now.Date;
            GanttView gantt     = CreateGanttView(startDate, false, DayOfWeek.Monday, 0, ItemHeight);

            Element spanElement = gantt.CreateSpanElement(null, null, null);

            DateTime intervalStart  = startDate.AddHours(12);
            DateTime intervalFinish = intervalStart.AddDays(2);

            gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, type, null);

            #region Render

            using (MemoryStream stream = new MemoryStream())
            {
                gantt.LoadStyleSheetFromFile(styleFilePath);
                gantt.ApplyStyleSheet();

                gantt.RenderPortion(new Point(0, 0), new Size(24 * 3, Convert.ToInt32(ItemHeight)), 0, 0, ImageFormat.Png, stream);

                ret = stream.ToArray();
            }

            #endregion

            return(ret);
        }
Пример #2
0
        public static byte[] Render(bool vastScale,
                                    DateTime curDate,
                                    DateTime startDate,
                                    int[] users,
                                    ObjectTypes[] objectTypes,
                                    List <KeyValuePair <int, int> > highlightedItems,
                                    bool generateDataXml,
                                    string styleFilePath,
                                    int portionX,
                                    int portionY,
                                    int itemsPerPage,
                                    int pageNumber)
        {
            startDate = startDate.AddDays((vastScale ? 7 : 21) * portionX);
            DateTime finishDate = startDate.AddDays(vastScale ? 7 : 21);

            portionX = 0;

            GanttView gantt = CreateGanttView(startDate, vastScale, ConvertDayOfWeek(PortalConfig.PortalFirstDayOfWeek), HeaderItemHeight, ItemHeight);

            if (portionY >= 0)
            {
                #region Add data
                foreach (int userId in users)
                {
                    Element spanElement = gantt.CreateSpanElement(null, null, null);

                    DataTable table = Calendar.GetResourceUtilization(userId, curDate, startDate, finishDate, new ArrayList(objectTypes), highlightedItems, true, true, true, false);
                    table.AcceptChanges();

                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        DataRow row = table.Rows[i];

                        if (row.RowState != DataRowState.Deleted)
                        {
                            DateTime          intervalStart  = (DateTime)row["Start"];
                            DateTime          intervalFinish = ((DateTime)row["Finish"]);
                            Calendar.TimeType timeType       = (Calendar.TimeType)row["Type"];
                            bool highlight = (bool)row["Highlight"];

                            gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, timeType.ToString(), null);
                            if (highlight)
                            {
                                gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, "Highlight", null);
                            }
                        }
                    }
                }

                #endregion
            }

            return(GanttManager.Render(gantt, generateDataXml, styleFilePath, portionX, portionY, PortionWidth, users.Length * ItemHeight, itemsPerPage, pageNumber));
        }
Пример #3
0
        public static byte[] RenderAnalysisChart(int originalPlanSlotId, int basePlanSlotId, bool generateDataXml, string styleFilePath, int portionX, int portionY, int itemsPerPage, int pageNumber)
        {
            byte[] result = null;

            IList <GanttObject> items = GetAnalysisObjects(originalPlanSlotId, basePlanSlotId);

            if (items.Count > 0)
            {
                GanttView gantt = CreateGanttView(items[0].Id, HeaderItemHeight, ItemHeight);

                if (portionY >= 0)
                {
                    #region Add data

                    foreach (GanttObject item in items)
                    {
                        Element spanElement = gantt.CreateSpanElement(null, null, null);

                        string id  = string.Format(CultureInfo.InvariantCulture, "{0}{1}", item.IsProject ? "Project" : "Task", item.Id);
                        string tag = item.IsCompleted ? "Completed" : null;

                        if (item.IsProject)
                        {
                            AddInterval2(gantt, spanElement, item.Start, item.Finish, id, "Summary", tag);
                        }
                        else
                        {
                            AddMilestone(gantt, spanElement, item.Start, item.Finish, id, tag);
                        }
                    }

                    #endregion
                }

                result = Render(gantt, generateDataXml, styleFilePath, portionX, portionY, PortionWidth, PortionHeight, itemsPerPage, pageNumber);
            }

            return(result);
        }
Пример #4
0
        public static byte[] RenderChart(int projectId, int basePlanSlotId, bool generateDataXml, string styleFilePath, int portionX, int portionY, int itemsPerPage, int pageNumber)
        {
            GanttView gantt = CreateGanttView(projectId, HeaderItemHeight, ItemHeight);

            if (portionY >= 0)
            {
                #region Add data

                #region Load calendar

                int calendarId = -1;
                using (IDataReader reader = Project.GetProject(projectId))
                {
                    if (reader.Read())
                    {
                        calendarId = (int)reader["CalendarId"];
                    }
                }
                if (calendarId > 0)
                {
                    // Load rules by day of week
                    ArrayList days = new ArrayList();
                    for (byte i = 1; i <= 7; i++)
                    {
                        days.Add(i);
                    }
                    using (IDataReader reader = Mediachase.IBN.Business.Calendar.GetListWeekdayHours(calendarId))
                    {
                        while (reader.Read())
                        {
                            byte b = (byte)reader["DayOfWeek"];
                            days.Remove(b);
                        }
                    }
                    foreach (byte b in days)
                    {
                        gantt.CreateDayElement(ConvertDayOfWeek(b), true);
                    }

                    // Load exceptions
                    using (IDataReader reader = Mediachase.IBN.Business.Calendar.GetListExceptionHoursByCalendar(calendarId))
                    {
                        while (reader.Read())
                        {
                            DateTime fromDate = (DateTime)reader["FromDate"];
                            DateTime toDate   = (DateTime)reader["ToDate"];
                            bool     holiday  = (reader["FromTime"] == DBNull.Value && reader["ToTime"] == DBNull.Value);
                            for (DateTime date = fromDate.Date; date <= toDate.Date; date = date.AddDays(1))
                            {
                                gantt.CreateDateElement(date, holiday);
                            }
                        }
                    }
                }

                #endregion

                #region Load base plan

                Dictionary <int, DateTime> basePlanTaskHash = null;
                if (basePlanSlotId > 0)
                {
                    basePlanTaskHash = SpreadSheet.ProjectSpreadSheet.GetTaskHash(projectId, basePlanSlotId);
                }

                #endregion

                List <string> ids = new List <string>();

                #region Load tasks

                DataTable dt = Task.GetListTasksByProjectCollapsedDataTable(projectId);
                dt.AcceptChanges();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];

                    if (dr.RowState != DataRowState.Deleted)
                    {
                        Element spanElement = gantt.CreateSpanElement(null, null, null);

                        int    taskId = (int)dr["TaskId"];
                        string id     = taskId.ToString(CultureInfo.InvariantCulture);
                        ids.Add(id);
                        DateTime start       = (DateTime)dr["StartDate"];
                        bool     isMilestone = (bool)dr["IsMilestone"];
                        bool     isSummary   = (bool)dr["IsSummary"];
                        bool     isCompleted = (bool)dr["IsCompleted"];
                        string   type        = isSummary ? "Summary" : null;
                        string   tag         = isCompleted ? "Completed" : null;

                        if (isMilestone)
                        {
                            DateTime?basePlanDate = null;

                            if (basePlanTaskHash != null && basePlanTaskHash.ContainsKey(taskId))
                            {
                                basePlanDate = basePlanTaskHash[taskId];
                            }

                            AddMilestone(gantt, spanElement, start, basePlanDate, id, tag);
                        }
                        else
                        {
                            AddInterval(dr, gantt, spanElement, "StartDate", "FinishDate", id, type, tag);

                            if (!isSummary)
                            {
                                AddInterval(dr, gantt, spanElement, "ActualStartDate", "ActualFinishDate", null, "Actual", tag);

                                int progress = (int)dr["PercentCompleted"];
                                if (progress > 0)
                                {
                                    DateTime finish   = (DateTime)dr["FinishDate"];
                                    TimeSpan interval = finish - start;
                                    finish = start + new TimeSpan(interval.Ticks * progress / 100);
                                    AddInterval2(gantt, spanElement, start, finish, null, "Progress", tag);
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Load relations

                using (IDataReader reader = Project.GetListTaskLinksByProject(projectId))
                {
                    while (reader.Read())
                    {
                        //string linkId = reader["LinkId"].ToString();
                        string succId = reader["SuccId"].ToString();
                        string predId = reader["PredId"].ToString();

                        if (ids.Contains(succId) && ids.Contains(predId))
                        {
                            gantt.CreateRelationElement(null, null, null, predId, succId);
                        }
                    }
                }

                #endregion

                #endregion
            }

            return(Render(gantt, generateDataXml, styleFilePath, portionX, portionY, PortionWidth, PortionHeight, itemsPerPage, pageNumber));
        }
Пример #5
0
        public static byte[] RenderLegendItem(string styleFilePath, GanttItem item, bool completed)
        {
            byte[] ret = null;

            DateTime  startDate = DateTime.Now.Date;
            GanttView gantt     = CreateGanttView(startDate, DayOfWeek.Monday, 0, ItemHeight);

            Element spanElement = gantt.CreateSpanElement(null, null, null);

            DateTime pointDate      = startDate.AddHours(36);
            DateTime intervalStart  = startDate.AddHours(12);
            DateTime intervalFinish = intervalStart.AddDays(2);

            string tag = completed ? "Completed" : "";

            switch (item)
            {
            case GanttItem.PointStart:
                gantt.CreatePointElement(spanElement, pointDate, null, "Start", tag);
                break;

            case GanttItem.PointFinish:
                gantt.CreatePointElement(spanElement, pointDate, null, "Finish", tag);
                break;

            case GanttItem.PointActualStart:
                gantt.CreatePointElement(spanElement, pointDate, null, "ActualStart", tag);
                break;

            case GanttItem.PointActualFinish:
                gantt.CreatePointElement(spanElement, pointDate, null, "ActualFinish", tag);
                break;

            case GanttItem.Interval:
                gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, null, tag);
                break;

            case GanttItem.IntervalActual:
                gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, "Actual", tag);
                break;

            case GanttItem.IntervalProgress:
                gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, "Progress", tag);
                break;

            case GanttItem.IntervalSummary:
            case GanttItem.IntervalProject:
                Element interval = gantt.CreateIntervalElement(spanElement, intervalStart, intervalFinish, null, "Summary", tag);
                gantt.CreatePointElement(interval, intervalStart, null, "SummaryStart", tag);
                gantt.CreatePointElement(interval, intervalFinish, null, "SummaryFinish", tag);
                break;

            case GanttItem.PointMilestone:
                AddMilestone(gantt, spanElement, pointDate, null, null, tag);
                break;

            case GanttItem.PointMilestoneBasePlanRight:
                AddMilestone(gantt, spanElement, intervalStart, intervalFinish, null, tag);
                break;

            case GanttItem.PointMilestoneBasePlanLeft:
                AddMilestone(gantt, spanElement, intervalFinish, intervalStart, null, tag);
                break;
            }

            #region Render

            using (MemoryStream stream = new MemoryStream())
            {
                gantt.LoadStyleSheetFromFile(styleFilePath);
                gantt.ApplyStyleSheet();

                gantt.RenderPortion(new Point(0, 0), new Size(24 * 3, Convert.ToInt32(ItemHeight)), 0, 0, ImageFormat.Png, stream);

                ret = stream.ToArray();
            }

            #endregion

            return(ret);
        }