Ejemplo n.º 1
0
        internal MonthCalendar(DateTime date)
        {
            bool spanish = System.Threading.Thread.CurrentThread.CurrentUICulture.Name == "es-ES";

            if (date.Day != 1)
            {
                date = new DateTime(date.Year, date.Month, 1);
            }

            _date = date;
            _days = new Area[6 * 7];
            _firstDay = spanish ? DayOfWeek.Monday : DayOfWeek.Sunday;

            int[] dias = { 0, 1, 2, 3, 4, 5, 6 };
            int ds = (int)date.DayOfWeek;
            DateTime curDate = date.Subtract(new TimeSpan(dias[ds] - (int)_firstDay, 0, 0, 0));
            DateTime curDateTemp = curDate;
            for (int i = 0; i < 7; i++)
            {
                _days[i] = new Area(curDate);
                _days[i].Text = curDateTemp.ToString("ddd").Substring(0, 1).ToUpper();
                if (spanish && curDateTemp.DayOfWeek == DayOfWeek.Wednesday) _days[i].Text =  "X";
                _days[i].Font = Calendar.DefaultFont;
                _days[i].Selectable = false;
                _days[i].BackgroundColor = Color.Empty;
                curDateTemp = curDateTemp.AddDays(1);
            }
            for (int i = 7; i < _days.Length; i++)
            {
                _days[i] = new Area(curDate);
                _days[i].Text = curDate.Day.ToString();
                _days[i].Font = Calendar.DefaultFont;
                _days[i].Selectable = true;
                _days[i].BackgroundColor = SystemColors.ControlLight;
                if (_date.Month != _days[i].Date.Month) { _days[i].TextColor = SystemColors.GrayText; }
                curDate = curDate.AddDays(1);

            }
        }
Ejemplo n.º 2
0
        internal void SetCalendar(Point location)
        {
            int x = location.X;
            int y = location.Y;

            _location = location;

            _monthBar = new Rectangle(location, new Size(_size.Width, 20));

            y = location.Y + _daySize.Height+5;

            for (int i = 0; i < _days.Length; i++)
            {
                _days[i].Bounds =new Rectangle(new Point(x, y), _daySize);

                x += _daySize.Width;

                if ((i + 1) % 7 == 0)
                {
                    x = location.X;
                    y += _daySize.Height;
                }
            }

            _previousButton = new Area(new Rectangle(Bounds.Left + 2, Bounds.Top + 2, _daySize.Height - 2, _daySize.Height - 2));
            _nextButton = new Area(new Rectangle(Bounds.Right - 2 - _previousButton.Bounds.Width, Bounds.Top + 2, _previousButton.Bounds.Width, _previousButton.Bounds.Height));
        }
Ejemplo n.º 3
0
 private void GetItemColor(TrainingItem item, Area itemArea)
 {
     itemArea.Gradient = true;
     itemArea.BorderColor = Color.Black;
     if (item.Objective == null)
     {
         itemArea.BackgroundColor = Color.Gray;
         itemArea.BackgroundColorGradient = Color.LightGray;
     }
     else
     {
         itemArea.BackgroundColor = Color.Green;
         itemArea.BackgroundColorGradient = Color.LawnGreen;
         /*
         switch (item.Type)
         {
             case TrainingEvent.Season:
             case TrainingEvent.TrainingSession:
             case TrainingEvent.Macrocycle: itemArea.BackgroundColor = Color.Green;
                 itemArea.BackgroundColorGradient = Color.LawnGreen; break;
             case TrainingEvent.Mesocycle: itemArea.BackgroundColor = Color.Azure;
                 itemArea.BackgroundColorGradient = Color.LightBlue; break;
             case TrainingEvent.Microcycle:itemArea.BackgroundColor = Color.CadetBlue;
                 itemArea.BackgroundColorGradient = Color.LightBlue; break;
         }*/
     }
 }
Ejemplo n.º 4
0
 private int GetWidth(TimeSpan span, Area chart, double totalMinutes)
 {
     return (int)((span.TotalMinutes * (chart.Bounds.Width - BARS_X)) / totalMinutes);
 }
Ejemplo n.º 5
0
 private int GetBarWidth(TrainingItem item, Area chart, double totalMinutes)
 {
     return GetWidth(item.EndDate.Subtract(item.StartDate), chart, totalMinutes);
 }
Ejemplo n.º 6
0
 private int GetBarX(TrainingItem item, Area chart, DateTime chartStart, double totalMinutes)
 {
     return chart.Bounds.X + BARS_X + GetWidth(item.StartDate.Subtract(chartStart), chart, totalMinutes);
 }
Ejemplo n.º 7
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 { }
        }
Ejemplo n.º 8
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.º 9
0
        private void UpdateSelection()
        {
            _selectionEnd = new DateTime(_selectionEnd.Year, _selectionEnd.Month, _selectionEnd.Day, 23, 59, 59);
            TimeSpan span = _selectionEnd.Subtract(_selectionStart.Date);
            span = span.Add(new TimeSpan(0, 0, 0, 1, 0));

            _monthDays = new Area[span.Days];
            _calendarDays = new Area[span.Days];
            _calendarNotes = new Area[span.Days];

            bool spanish = System.Threading.Thread.CurrentThread.CurrentUICulture.Name == "es-ES";
            for (int i = 0; i < _monthDays.Length; i++)
            {
                _monthDays[i] = new Area(_selectionStart.AddDays(i));
                _calendarDays[i] = new Area(_selectionStart.AddDays(i));
                _calendarNotes[i] = new Area(_selectionStart.AddDays(i)); // los puedo crear en calendarrenderer
                _calendarNotes[i].Text = spanish?"doble clic para insertar una nota\n[ESC para guardarla]":"double click to add a note\n[ESC when finished]";
            }
            if (_selectionMode != CalendarSelectionMode.Manual) _selectedDay = null;
            _selectedItem = null; // think this goes here
        }
Ejemplo n.º 10
0
 private void ChangeSelection(Area day)
 {
     if (_selectionMode == CalendarSelectionMode.Week)
         SelectWeek(day.Date);
     else if (_selectionMode == CalendarSelectionMode.ThreeDays)
         SelectThreeDays(day.Date);
     else if (_selectionMode == CalendarSelectionMode.Manual || _selectionMode == CalendarSelectionMode.OneDay)
         _selectionStart = _selectionEnd = day.Date;
     //SelectionEnd = _selectionStart = day.Date;
     OnSelectionChanged(EventArgs.Empty);
 }
Ejemplo n.º 11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.Clear(SystemColors.Window);

            CalendarEventArgs evt = new CalendarEventArgs(this, e.Graphics);

            _renderer.DrawSelectionButtons(this, e.Graphics);

            _renderer.DrawMonthCalendars(this, e.Graphics);

            _calendarArea = new Area(e.Graphics, new Rectangle(MonthCalendar.Size.Width + 16, 30, this.Width - 500, this.Height));
            _trainingInfo = new Area(e.Graphics, new Rectangle(this.Width - 290, 5, 280, 200), SystemColors.Info, SystemColors.ActiveBorder);

            _renderer.DrawDays(evt);

            // draw items
            List<TrainingItem> sessions = new List<TrainingItem>();
            foreach (TrainingItem item in _items)
            {
                if (ItemInSelection(item))
                {
                    evt.Item = item;
                    //if (item.Type == TrainingEvent.TrainingSession || item.Type == TrainingEvent.Other /* e.g. training session in another training plan */)
                    //{
                    //}
                    _renderer.DrawItem(evt, sessions);
                }
            }

            _renderer.DrawCuadroInfo(evt);

            try
            {
                _renderer.DrawOpciones(evt);
            }
            catch (Exception Exception) { MessageBox.Show(Exception.Message); }
        }
Ejemplo n.º 12
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            _mouseDown = false;
            if (_mouseMove)
            {
                if (_selectionMode == CalendarSelectionMode.Manual) _selectedDay = null;
                Invalidate();
                _mouseMove = false;
            }

            if (_selectedButton != -1)
            {
                _selectedButton = -1;
                Invalidate();
            }
        }
Ejemplo n.º 13
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Area day = PointerOnDay(e.Location);
            if (e.Location.X < 200) // the pointer is on the month calendar area
            {
                for (int i = 0; i < 4; i++)
                {
                    if (PointerOnArea(e.Location, _selectionButtons[i].Bounds))
                    {
                        _selectionMode = (CalendarSelectionMode)i;
                        if (_lastDaySelected != null)
                            ChangeSelection(_lastDaySelected);
                    }
                }
                if (day != null)
                {
                    _lastDaySelected = day;
                    ChangeSelection(day);
                }

                for (int i = 0; i < Months.Length; i++)
                {
                    if (Months[i].NextButton.Bounds.Contains(e.Location))
                    {
                        GoForward();
                    }
                    if (Months[i].PreviousButton.Bounds.Contains(e.Location))
                    {
                        GoBackward();
                    }

                }
                if (_selectionMode == CalendarSelectionMode.Manual || _selectionMode == CalendarSelectionMode.OneDay) _selectedDay = day;
                _mouseDown = true;
            }
            else
            {
                if (day != null)
                {
                    _selectedItem = null;
                    foreach (TrainingItem item in _items)
                    {
                        if (ItemInSelection(item) && PointerOnArea(e.Location, item.Bounds))
                        {
                            _selectedItem = item;
                            if (ItemClick != null)
                                ItemClick(this, new CalendarEventArgs(_selectedItem));
                            if (item.Type != TrainingEvent.TrainingNote)
                            {
                                Invalidate();
                                return;
                            }
                        }
                    }
                    _selectedDay = day;
                    Invalidate();
                }

                if (_trainingButtons != null)
                {
                    for (int i = 0; i < _trainingButtons.Length; i++)
                    {

                        if (PointerOnArea(e.Location, _trainingButtons[i].Bounds))
                        {
                            _selectedButton = i;
                            Invalidate();
                            if (_selectedItem != null)
                            {
                                switch (i)
                                {
                                    case 0: onTrainingItemEdit(_selectedItem); break;
                                    case 1: onTrainingItemDelete(_selectedItem); break;
                                    case 2: if (ReportButtonClick != null) ReportButtonClick(this, new CalendarEventArgs(_selectedItem)); break;
                                    case 3: ChangeColor(); break;
                                }
                                if (i == _trainingButtons.Length - 1) if (ChartsClick != null) ChartsClick(this, new EventArgs());
                                return;
                            }
                            else if (_selectedDay != null)
                            {
                                object[] additionalInfo = (object[])_trainingButtons[i].Tag;
                                if (additionalInfo != null) TrainingItemCreate(additionalInfo);
                            }
                            if (i == _trainingButtons.Length - 1) if (ChartsClick != null) ChartsClick(this, new EventArgs());
                        }

                    }
                }
            }
        }