Пример #1
0
        internal static byte[] Render(GanttView ganttView, bool generateDataXml, string styleFilePath, int portionX, int portionY, int portionWidth, int portionHeight, int itemsPerPage, int pageNumber)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                if (generateDataXml)
                {
                    ganttView.GenerateDataXml(Encoding.UTF8, stream);
                }
                else
                {
                    ganttView.LoadStyleSheetFromFile(styleFilePath);
                    ganttView.ApplyStyleSheet();

                    if (portionY < 0)
                    {
                        portionHeight = Convert.ToInt32(ganttView.CalculateHeadHeight());
                    }

                    if (portionHeight > 0 && portionWidth > 0)
                    {
                        ganttView.RenderPortion(new Point(portionX, portionY), new Size(portionWidth, portionHeight), itemsPerPage, pageNumber, ImageFormat.Png, stream);
                    }
                }
                return(stream.ToArray());
            }
        }
Пример #2
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);
        }
Пример #3
0
        private static Element AddInterval2(GanttView gantt, Element parent, DateTime?start, DateTime?finish, string id, string type, string tag)
        {
            Element child = null;

            if (start != null && finish != null)
            {
                child = gantt.CreateIntervalElement(parent, start.Value, finish.Value, id, type, tag);
                if (type == "Summary")
                {
                    gantt.CreatePointElement(child, start.Value, null, type + "Start", tag);
                    gantt.CreatePointElement(child, finish.Value, null, type + "Finish", tag);
                }
            }
            else
            {
                if (start != null)
                {
                    child = gantt.CreatePointElement(parent, start.Value, id, type + "Start", tag);
                }
                if (finish != null)
                {
                    child = gantt.CreatePointElement(parent, finish.Value, id, type + "Finish", tag);
                }
            }

            return(child);
        }
Пример #4
0
        private static GanttView CreateGanttView(DateTime startDate, bool vastScale, DayOfWeek firstDayOfWeek, float headerItemHeight, float itemHeight)
        {
            GanttView gantt = new GanttView(headerItemHeight, itemHeight);

            gantt.CreateDataElement(startDate);

            AxisElement topAxis    = gantt.CreateAxisElement(ScaleLevel.Week, 1, string.Empty, firstDayOfWeek);
            AxisElement bottomAxis = gantt.CreateAxisElement(ScaleLevel.Day, 1, string.Empty, null);

            if (vastScale)
            {
                topAxis.TitleType = TitleType.StartEnd;
                topAxis.Format    = "d MMMM yyyy";

                bottomAxis.TitleType = TitleType.Start;
                bottomAxis.Format    = "ddd, d MMM";
                bottomAxis.Width     = 72;
            }
            else
            {
                topAxis.TitleType = TitleType.Start;
                topAxis.Format    = "d MMMM yyyy";

                bottomAxis.TitleType = TitleType.Start;
                bottomAxis.Format    = "dd";
                bottomAxis.Width     = 24;
            }

            return(gantt);
        }
Пример #5
0
 protected override void OnMenuButtonClick()
 {
     if (GanttView != null)
     {
         using (SaveFileDialog dlg = new SaveFileDialog())
         {
             dlg.DefaultExt = ".xml";
             dlg.Filter     = "XML files|*.xml|All files|*.*";
             dlg.Title      = "Save To XML File";
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 try
                 {
                     GanttView.SaveXml(dlg.FileName);
                     var item = new Item();
                     item.Date    = DateTime.Now;
                     item.Text    = Path.GetFileName(dlg.FileName);
                     item.SubText = Path.GetDirectoryName(dlg.FileName);
                     if (Items.FirstOrDefault(x => x.Text == item.Text && x.SubText == item.SubText) == null)
                     {
                         Items.Add(item);
                     }
                 }
                 catch
                 {
                 }
             }
         }
     }
 }
Пример #6
0
        private static GanttView CreateGanttView(DateTime startDate, DayOfWeek firstDayOfWeek, float headerItemHeight, float itemHeight)
        {
            GanttView gantt = new GanttView(headerItemHeight, itemHeight);

            gantt.CreateDataElement(startDate);
            gantt.CreateAxisElement(ScaleLevel.Week, 1, "dd MMMM yyyy", firstDayOfWeek);
            gantt.CreateAxisElement(ScaleLevel.Day, 1, "dd", null);

            return(gantt);
        }
Пример #7
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));
        }
Пример #8
0
        //=======
        //        GanttView _gantView;
        //public DateTime dateTime;
        //>>>>>>> 15e4197158387a14fb3e1114550e2ff780f71c62

        public GanttPage()
        {
            this.InitializeComponent();
//<<<<<<< HEAD
            GantView = new GanttView(_srollViewer);
//=======
//            _gantView = new GanttView(_srollViewer);
            GantView.DateTime = DateTime.Now;
//>>>>>>> 15e4197158387a14fb3e1114550e2ff780f71c62
            App.AgendasModel.PropertyChanged += AgendasModel_PropertyChanged;
            Window.Current.CoreWindow.PointerWheelChanged += new TypedEventHandler <Windows.UI.Core.CoreWindow, Windows.UI.Core.PointerEventArgs>(ChangedCoreWindowPointerWheel);
        }
Пример #9
0
        private static void AddMilestone(GanttView gantt, Element parent, DateTime date, DateTime?basePlanDate, string id, string tag)
        {
            string type = "Milestone";

            gantt.CreatePointElement(parent, date, id, type, tag);

            if (basePlanDate != null && basePlanDate.Value != date)
            {
                string direction = basePlanDate.Value > date ? "Right" : "Left";

                PointElement small = gantt.CreatePointElement(parent, date, null, type, "BasePlanSmall");
                small.AddAttribute("direction", direction);

                PointElement large = gantt.CreatePointElement(parent, basePlanDate.Value, null, type, "BasePlanLarge");
                large.AddAttribute("direction", direction);
            }
        }
Пример #10
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);
        }
Пример #11
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));
        }
Пример #12
0
        public override void DrawScaleHeaderLabel(Graphics g, Rectangle rect, DateTime startTime, int scale, GanttView view)
        {
            DateTime date;
            int i;
            if (view == GanttView.HourView)
            {
                date = startTime.AddHours(scale);
                i = date.Hour;
            }
            else
            {
                date = startTime.AddHours(scale * 24);
                i = date.Day;
                var days = (new DateTime(date.Year, date.Month, 1).AddMonths(1) - new DateTime(date.Year, date.Month, 1)).Days;
            }

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (view == GanttView.HourView)
            {
                if (i == 0)
                {
                    using (Pen pen = new Pen(_LabelColor))
                        g.DrawLine(pen, rect.X, rect.Top, rect.X, rect.Height);
                }
                else if (i == 11)
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Near;
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        using (Font fntDayDate = new Font("Segoe UI", 9, FontStyle.Bold))
                        {
                            var str = date.Date.ToString("yyyy年MM月dd日");
                            g.DrawString(str, fntDayDate, SystemBrushes.WindowText, rect, sf);
                        }
                    }
                }
            }
            else if (view == GanttView.DayView)
            {
                if (i == 1)
                {
                    using (Pen pen = new Pen(_LabelColor))
                        g.DrawLine(pen, rect.X, rect.Top, rect.X, rect.Height);
                }
                else if (i == 14)
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Near;
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        using (Font fntDayDate = new Font("Segoe UI", 9, FontStyle.Bold))
                        {
                            var str = date.Date.ToString("yyyy年MM月");
                            g.DrawString(str, fntDayDate, SystemBrushes.WindowText, rect, sf);
                        }
                    }
                }
            }
        }
Пример #13
0
 public abstract void DrawScaleHeaderLabel(Graphics g, Rectangle rect, DateTime startTime, int scale, GanttView view);
Пример #14
0
 protected override void OnMenuItemClick(MenuItem mi)
 {
     GanttView.SaveXml(System.IO.Path.Combine(mi.Item.SubText, mi.Item.Text));
     mi.Item.Date = DateTime.Now;
 }
Пример #15
0
        private GanttViewBuilder Add(GanttViewType type)
        {
            var view = new GanttView { Type = type };

            container.Add(view);

            return new GanttViewBuilder(view);
        }
Пример #16
0
 private static Element AddInterval(DataRow dr, GanttView gantt, Element parent, string startName, string finishName, string id, string type, string tag)
 {
     return(AddInterval2(gantt, parent, GetDate(dr, startName), GetDate(dr, finishName), id, type, tag));
 }
Пример #17
0
 public GanttViewBuilder(GanttView settings)
 {
     container = settings;
 }
Пример #18
0
        public static int GetPortionX(int projectId, DateTime date)
        {
            GanttView gantt = CreateGanttView(projectId, 0, 0);

            return(gantt.GetPortionX(date, PortionWidth));
        }
Пример #19
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);
        }
Пример #20
0
 public abstract void DrawScaleLabel(Graphics graphics, Rectangle hourRectangle, DateTime dateTime, int hour, bool drawContent, GanttView view, int scaleWidth);
Пример #21
0
        public override void DrawScaleLabel(Graphics g, Rectangle rect, DateTime startTime, int scale, bool drawContent, GanttView view, int scaleWidth)
        {
            using (Pen pen = new Pen(_LabelColor))
            {
                g.DrawLine(pen, rect.X, rect.Top, rect.X, rect.Height);
                g.DrawLine(pen, rect.X, rect.Height, rect.Right, rect.Height);
            }

            if (drawContent)
            {
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                using (SolidBrush brush = new SolidBrush(Color.Black))
                {
                    var str = string.Empty;

                    if (view == GanttView.HourView)
                        str = startTime.AddHours(scale).Hour.ToString();
                    else
                    {
                        var dt = startTime.AddDays(scale);
                        if (scaleWidth >= 120)
                            str = dt.ToString("yyyy-MM-dd");
                        else if (scaleWidth >= 72)
                            str = dt.ToString("MM-dd");
                        else
                            str = dt.Day.ToString();
                    }

                    using (var sf = new StringFormat())
                    {
                        var rect2 = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
                        rect2.Width = scaleWidth;
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString(str, ScaleFont, brush, rect2, sf);
                    }
                }
            }
        }