Ejemplo n.º 1
0
 private void DrawHeader(Graphics g, int x, int y, int width, DateTime start, string dateTimeFormat)
 {
     Area monthHeader = new Area(g, new Rectangle(x, y, width, 20));
     monthHeader.Text = start.ToString(dateTimeFormat);
     monthHeader.TextColor = SystemColors.AppWorkspace;
     monthHeader.Font = base.Font;
     monthHeader.TextFlags = System.Windows.Forms.TextFormatFlags.Top | System.Windows.Forms.TextFormatFlags.HorizontalCenter
         | System.Windows.Forms.TextFormatFlags.WordEllipsis;
     monthHeader.Draw();
 }
Ejemplo n.º 2
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);

            if (_onGotFocus)
            {
                LoadCharts();
                _onGotFocus = false;
            }
            try
            {
                e.Graphics.Clear(SystemColors.Window);

                _bars.Clear();

                // draws title and options
                string title;
                if (_chart1Start != DateTime.MinValue && _chart1End != DateTime.MinValue)
                    title = spanish ? ("Temporada en curso de " + _athleteOrTeamName) : (_athleteOrTeamName + "'s current season");
                else
                    title = spanish ? ("No hay ninguna temporada en curso para " + _athleteOrTeamName) : ("No " + _athleteOrTeamName + "'s running seasons have been created yet");
                System.Windows.Forms.TextRenderer.DrawText(e.Graphics, title, new Font("Georgia", 10, FontStyle.Bold),
                    new Rectangle(0, 0, this.Width, 70), SystemColors.InfoText);
                string options = spanish ? "F1 - Ayuda, S - Guardar imagen" : "F1 - Help, S - Save as image";
                System.Windows.Forms.TextRenderer.DrawText(e.Graphics, options, new Font("Georgia", 9),
                    new Rectangle(this.Width - 400, 5, 400, 50), SystemColors.GrayText, System.Windows.Forms.TextFormatFlags.Right);

                // creates chart1 area, if season running, draws chart
                _chart1 = new Area(e.Graphics, new Rectangle(CHART_X, 90, this.Width - CHART_X - CHART_X, 210));

                if (_chart1Start != DateTime.MinValue && _chart1End != DateTime.MinValue)
                {
                    int months = MonthsDifference(_chart1Start, _chart1End);
                    double minutesChart1 = _chart1End.Subtract(_chart1Start).TotalMinutes;
                    int x = _chart1.Bounds.X + BARS_X;
                    using (Pen p = new Pen(SystemColors.AppWorkspace))
                    {
                        e.Graphics.DrawLine(p, new Point(x, _chart1.Bounds.Y - 30), new Point(x, _chart1.Bounds.Height));
                    }
                    DateTime start = _chart1Start;
                    for (int i = 0; i < months; i++)
                    {
                        TimeSpan ts = start.AddDays(DateTime.DaysInMonth(start.Year, start.Month)).Subtract(start);
                        int monthWidth = GetWidth(ts, _chart1, minutesChart1);
                        DrawHeader(e.Graphics, x, _chart1.Bounds.Y - 20, monthWidth, start, "MMMM");
                        start = start.AddMonths(1);
                        x += monthWidth;
                        using (Pen p = new Pen(SystemColors.AppWorkspace))
                        {
                            e.Graphics.DrawLine(p, new Point(x, _chart1.Bounds.Y - 20), new Point(x, _chart1.Bounds.Height));
                        }
                    }

                    // draws info row
                    int y = 25;
                    for (int i = 2; i < 6; i++)
                    {
                        Area row = new Area(e.Graphics, new Rectangle(_chart1.Bounds.X, _chart1.Bounds.Y + y, 65, 25));
                        row.Text = TrainingItem.ToString((TrainingEvent)i, spanish) + ": ";
                        row.TextFlags = System.Windows.Forms.TextFormatFlags.VerticalCenter | System.Windows.Forms.TextFormatFlags.Right;
                        row.TextColor = Color.Gray;
                        row.Font = base.Font;
                        row.Draw();
                        y += 25;
                    }
                    // draws bars
                    List<TrainingItem> sessions = new List<TrainingItem>();
                    foreach (TrainingItem item in _items)
                    {
                        if (ItemInChart(item, _chart1Start, _chart1End) && item.Type != TrainingEvent.TrainingNote)
                        {
                            Area itemArea = new Area(e.Graphics, item.Bounds);

                            int itemX = GetBarX(item, _chart1, _chart1Start, minutesChart1);
                            int itemY = 0;
                            int itemW;
                            int itemH = 20;
                            if (item.Type == TrainingEvent.TrainingSession) // sessions last an entire day in order to be more visible in the chart
                            {
                                DateTime sessionStart = new DateTime(item.StartDate.Year, item.StartDate.Month, item.StartDate.Day, 0, 0, 0);
                                DateTime sessionEnd = new DateTime(item.EndDate.Year, item.EndDate.Month, item.EndDate.Day, 23, 59, 0);
                                itemW = GetWidth(sessionEnd.Subtract(sessionStart), _chart1, minutesChart1);
                            }
                            else itemW = GetBarWidth(item, _chart1, minutesChart1);

                            switch (item.Type)
                            {
                                case TrainingEvent.Season: itemY = _chart1.Bounds.Y;
                                    itemArea.Text = (spanish ? "temporada " : "season ") + item.StartDate.Year.ToString();
                                    if (item.EndDate.Year != item.StartDate.Year) itemArea.Text += "/"+item.EndDate.Year.ToString(); break;
                                case TrainingEvent.Macrocycle: itemY = _chart1.Bounds.Y + 25;
                                    itemArea.Text = item.Text; break;
                                case TrainingEvent.Mesocycle: itemY = _chart1.Bounds.Y + 50;
                                    itemArea.Text = item.Orientation != null ? item.Orientation : ""; break;
                                case TrainingEvent.Microcycle: itemY = _chart1.Bounds.Y + 75;
                                    itemArea.Text = item.Orientation != null ? item.Orientation : ""; break;
                                case TrainingEvent.TrainingSession:
                                    int intersections = GetIntersectionsCount(sessions, item); if (intersections > 5) continue;
                                    itemY = _chart1.Bounds.Y + 100 + 5 * intersections + intersections * (25 - intersections - 5);
                                    //itemY = _chart1.Bounds.Y + 100 +  intersections * 25;
                                    sessions.Add(item);
                                    itemH -= intersections * 3; itemArea.Text = ""; break;
                            }

                            item.Bounds = new Rectangle(itemX, itemY, itemW, itemH);
                            itemArea.Bounds = item.Bounds;
                            GetItemColor(item, itemArea);
                            itemArea.Font = base.Font;
                            itemArea.TextFlags |= System.Windows.Forms.TextFormatFlags.WordEllipsis;
                            itemArea.Draw();

                            itemArea.Tag = item;
                            _bars.Add(itemArea);
                        }
                    }

                    // creates chart2 and chart3 area
                    _chart2 = new Area(e.Graphics, new Rectangle(CHART_X, _chart1.Bounds.Y + _chart1.Bounds.Height + 70, this.Width - CHART_X * 2, this.Height / 6));
                    _chart3 = new Area(e.Graphics, new Rectangle(CHART_X, _chart2.Bounds.Y + _chart2.Bounds.Height + 60, this.Width - CHART_X * 2, this.Height / 6));

                    // draws chart2 & chart3 title
                    string title2 = spanish ? "Últimas sesiones realizadas dentro de la temporada en curso:" : "Latest training sessions performed (shown in monthly and weekly view charts)";
                    System.Windows.Forms.TextRenderer.DrawText(e.Graphics, title2, new Font("Georgia", 10, FontStyle.Bold),
                        new Rectangle(0, _chart2.Bounds.Y - 90, this.Width, 70), SystemColors.InfoText);

                    // draws chart2
                    double minutesChart2 = _chart2End.Subtract(_chart2Start).TotalMinutes;
                    int x2 = _chart2.Bounds.X + BARS_X;
                    using (Pen p = new Pen(SystemColors.AppWorkspace))
                    {
                        e.Graphics.DrawLine(p, new Point(x2, _chart2.Bounds.Y - 30), new Point(x2, _chart2.Bounds.Y + _chart2.Bounds.Height));
                    }
                    DateTime start2 = _chart2Start;
                    for (int i = 0; i < 2; i++)
                    {
                        TimeSpan ts = start2.AddDays(DateTime.DaysInMonth(start2.Year, start2.Month)).Subtract(start2);
                        int monthWidth = GetWidth(ts, _chart2, minutesChart2);
                        DrawHeader(e.Graphics, x2, _chart2.Bounds.Y - 20, monthWidth, start2, "MMMM");
                        start2 = start2.AddMonths(1);
                        x2 += monthWidth;
                        using (Pen p = new Pen(SystemColors.AppWorkspace))
                        {
                            e.Graphics.DrawLine(p, new Point(x2, _chart2.Bounds.Y - 20), new Point(x2, _chart2.Bounds.Y + _chart2.Bounds.Height));
                        }
                    }
                    // draws info rows
                    // draws bars
                    sessions = new List<TrainingItem>();
                    foreach (TrainingItem item in _items)
                    {
                        if (ItemInChart(item, _chart2Start, _chart2End) && item.Type == TrainingEvent.TrainingSession)
                        {
                            Area itemArea = new Area(e.Graphics, item.Bounds);

                            int itemX = GetBarX(item, _chart2, _chart2Start, minutesChart2);
                            int itemW = GetBarWidth(item, _chart2, minutesChart2);
                            int itemH = 30;

                            int intersections = GetIntersectionsCount(sessions, item); if (intersections > 5) continue;
                            int itemY = _chart2.Bounds.Y + 5 * intersections + intersections * (30 - intersections - 2);

                            sessions.Add(item);
                            itemH -= intersections * 3;
                            //itemArea.Text = item.Objective!=null?item.Objective:(spanish?"Objetivo sin definir": "Objective not defined yet");
                            item.Bounds = new Rectangle(itemX, itemY, itemW, itemH);
                            itemArea.Bounds = item.Bounds;
                            GetItemColor(item, itemArea);
                            itemArea.BorderColor = Color.Black;

                            itemArea.Draw();

                            itemArea.Tag = item;
                            _bars.Add(itemArea);

                        }
                    }
                    // draws chart3
                    double minutesChart3 = _chart3End.Subtract(_chart3Start).TotalMinutes;
                    int x3 = _chart3.Bounds.X + BARS_X;
                    using (Pen p = new Pen(SystemColors.AppWorkspace))
                    {
                        e.Graphics.DrawLine(p, new Point(x3, _chart3.Bounds.Y - 30), new Point(x3, _chart3.Bounds.Y + _chart3.Bounds.Height));
                    }
                    DateTime start3 = _chart3Start;
                    for (int i = 0; i < 7; i++)
                    {
                        TimeSpan ts = start3.AddDays(1).Subtract(start3);
                        int dayWidth = GetWidth(ts, _chart3, minutesChart3);
                        DrawHeader(e.Graphics, x3, _chart3.Bounds.Y - 20, dayWidth, start3, "dd MMMM");
                        start3 = start3.AddDays(1);
                        x3 += dayWidth;
                        using (Pen p = new Pen(SystemColors.AppWorkspace))
                        {
                            e.Graphics.DrawLine(p, new Point(x3, _chart3.Bounds.Y - 20), new Point(x3, _chart3.Bounds.Y + _chart3.Bounds.Height));
                        }
                    }
                    // draws bars
                    sessions = new List<TrainingItem>();
                    foreach (TrainingItem item in _items)
                    {
                        if (ItemInChart(item, _chart3Start, _chart3End) && item.Type == TrainingEvent.TrainingSession)
                        {
                            Area itemArea = new Area(e.Graphics, item.Bounds);

                            int itemX = GetBarX(item, _chart3, _chart3Start, minutesChart3);
                            int itemW = GetBarWidth(item, _chart3, minutesChart3);
                            int itemH = 30;

                            int intersections = GetIntersectionsCount(sessions, item); if (intersections > 5) continue;
                            itemH -= intersections * 3;
                            int itemY = _chart3.Bounds.Y + 5 * intersections + intersections * (30 - intersections - 2);
                            sessions.Add(item);
                            itemArea.Text = item.Objective != null ? item.Objective : (spanish ? "Objetivo sin definir" : "Objective not defined yet");
                            item.Bounds = new Rectangle(itemX, itemY, itemW, itemH);
                            itemArea.Bounds = item.Bounds;
                            GetItemColor(item, itemArea);
                            itemArea.Font = base.Font;
                            itemArea.TextFlags = System.Windows.Forms.TextFormatFlags.TextBoxControl |
                                System.Windows.Forms.TextFormatFlags.WordBreak | System.Windows.Forms.TextFormatFlags.EndEllipsis;

                            itemArea.Draw();

                            itemArea.Tag = item;
                            _bars.Add(itemArea);

                        }
                    }
                }
            }
            catch { }
        }