private void GetTrainingItems() { TrainingItem season = new TrainingItem(DateTime.Today.AddMonths(-1).AddHours(9), DateTime.Today.AddMonths(6).AddHours(23).AddMinutes(59), TrainingSchedule.TrainingEvent.Season); season.Objective = "Here goes the athlete's objective for this season"; TrainingItem macrocycle = new TrainingItem(DateTime.Today.AddMonths(-1).AddHours(9), DateTime.Today.AddMonths(6).AddHours(23).AddMinutes(59), "Macrocycle", TrainingSchedule.TrainingEvent.Macrocycle); TrainingItem mesocycle = new TrainingItem(DateTime.Today.AddMonths(-1).AddHours(9), DateTime.Today.AddHours(23).AddMinutes(59), "Mesocycle", TrainingSchedule.TrainingEvent.Mesocycle); mesocycle.Objective = "Since a objective has been defined, the mesocycle bar is coloured"; mesocycle.Orientation = "Realization"; TrainingItem microcycle = new TrainingItem(DateTime.Today.AddMonths(-1).AddHours(9), DateTime.Today.AddDays(-23).AddHours(21), "Microcycle", TrainingSchedule.TrainingEvent.Microcycle); microcycle.Objective = "Since a objective has been defined, the microcycle bar is coloured"; microcycle.Orientation = "Competition"; TrainingItem trainingSession1 = new TrainingItem(DateTime.Today.AddMonths(-1).AddHours(9), DateTime.Today.AddMonths(-1).AddHours(14), "Training session #1", TrainingEvent.TrainingSession); trainingSession1.Objective = "here goes the objective for this training session"; TrainingItem trainingSession2 = new TrainingItem(DateTime.Today.AddMonths(-1).AddHours(18), DateTime.Today.AddMonths(-1).AddHours(23), "Training session #2", TrainingEvent.TrainingSession); trainingSession2.Objective = "here goes the objective for this training session"; TrainingItem trainingSession3 = new TrainingItem(DateTime.Today.AddDays(-23).AddHours(10), DateTime.Today.AddDays(-23).AddHours(20), "Training session #3", TrainingEvent.TrainingSession); trainingSession3.Objective = "here goes the objective for this training session"; gantt1.Items.Add(season); gantt1.Items.Add(macrocycle); gantt1.Items.Add(mesocycle); gantt1.Items.Add(microcycle); gantt1.Items.Add(trainingSession1); gantt1.Items.Add(trainingSession2); gantt1.Items.Add(trainingSession3); }
private int GetIntersectionsCount(List<TrainingItem> sessions, TrainingItem session) { int intersections = 0; foreach (TrainingItem sessionItem in sessions) { //if (session.Bounds.IntersectsWith(sessionItem.Bounds)) intersections++; if (session.StartDate >= sessionItem.StartDate && session.StartDate <= sessionItem.EndDate || session.EndDate >= sessionItem.StartDate && session.EndDate <= sessionItem.EndDate || session.StartDate <= sessionItem.StartDate && session.EndDate >= sessionItem.EndDate) intersections++; } return intersections; }
private int GetBarX(TrainingItem item, Area chart, DateTime chartStart, double totalMinutes) { return chart.Bounds.X + BARS_X + GetWidth(item.StartDate.Subtract(chartStart), chart, totalMinutes); }
private int GetBarWidth(TrainingItem item, Area chart, double totalMinutes) { return GetWidth(item.EndDate.Subtract(item.StartDate), chart, totalMinutes); }
internal ChartEventArgs(TrainingItem item) { _item = item; }
internal CalendarEventArgs(TrainingItem item) { _item = item; }
/// <summary> /// Determines if the note belongs to a given day /// </summary> /// <param name="item"></param> /// <returns></returns> internal bool TrainingNoteInDay(TrainingItem note, DateTime day) { return note.StartDate.Date == day.Date; }
private void onTrainingItemEdit(TrainingItem item) { CalendarEventArgs evt = new CalendarEventArgs(item); if (EditButtonClick != null) EditButtonClick(this, evt); }
private void TextBox_KeyDown(object sender, KeyEventArgs e) { TextBox textBox = (TextBox)sender; Area note = (Area)textBox.Tag; TrainingItem removedItem = null; if (e.KeyCode == Keys.Escape) { note.Text = textBox.Text; foreach (TrainingItem item in _items) { if (ItemInSelection(item) && item.Type == TrainingEvent.TrainingNote && item.StartDate.Date == note.Date.Date) { _isAddingNote = false; item.Text = note.Text; if (item.Text.Length > 0) OnTrainingNoteChanged(new CalendarEventArgs(item)); else { removedItem = item; } } } if (removedItem != null) { _items.Remove(removedItem); OnTrainingNoteDeleted(new CalendarEventArgs(removedItem)); } if (_isAddingNote && note.Text.Length>0) { TrainingItem newItem = new TrainingItem(note.Date, note.Date, note.Text, TrainingEvent.TrainingNote); _items.Add(newItem); _isAddingNote = false; OnTrainingNoteCreated(new CalendarEventArgs(newItem)); } this.Controls.Remove(textBox); } }
private void HighLightSession(TrainingItem item) { if (item.Type == TrainingEvent.TrainingSession) { for (int i = 0; i < _months.Length; i++) { for (int day = 0; day < _months[i].Days.Length; day++) { if (_months[i].Days[day].Date.Date == item.StartDate.Date && day >= 7) { _months[i].Days[day].Font = new Font(Font.FontFamily, Font.Size, FontStyle.Bold); } } } } }
private void onTrainingItemDelete(TrainingItem item) { CalendarEventArgs evt = new CalendarEventArgs(item); if (DeleteButtonClick != null) DeleteButtonClick(this, evt); _selectedItem = null; }
private bool CheckDates(TrainingItem cycle, TrainingEvent type) { bool inUpperCycle = false, intersects = false, newMacros = false, newMesos = false, newMicros = false; foreach (TrainingItem item in _items) { if (item == cycle && _items.Count == 1) { inUpperCycle = true; continue; } else if (item == cycle) continue; if (cycle.Type == TrainingEvent.Season) inUpperCycle = true; else if (cycle.Type == TrainingEvent.Macrocycle && item.Type == TrainingEvent.Season) newMacros = true; else if (cycle.Type == TrainingEvent.Mesocycle && item.Type == TrainingEvent.Macrocycle) newMesos = true; else if (cycle.Type == TrainingEvent.Microcycle && item.Type == TrainingEvent.Mesocycle) newMicros = true; if (cycle.Type == TrainingEvent.TrainingSession && item.Type == type && cycle.StartDate >= item.StartDate && cycle.StartDate < item.EndDate) inUpperCycle = true; // distingo entre sesiones y resto de ciclos, comprobando en éstas solo la fecha de inicio else if (cycle.Type != TrainingEvent.TrainingSession && item.Type == type && cycle.StartDate >= item.StartDate && cycle.EndDate <= item.EndDate) inUpperCycle = true; // en el resto de ciclos compruebo que se encuentre desde el inicio al fin dentro del ciclo superior if (item.Type == cycle.Type && item.Type != TrainingEvent.TrainingSession && cycle.StartDate <= item.EndDate && item.StartDate <= cycle.EndDate) { if (item.isValid) intersects = true; } } if (cycle.Type == TrainingEvent.Macrocycle && !newMacros) return false; if (cycle.Type == TrainingEvent.Mesocycle && !newMesos) return false; if (cycle.Type == TrainingEvent.Microcycle && !newMicros) return false; return inUpperCycle && !intersects; }
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()); } } } } }
protected override void OnMouseDoubleClick(MouseEventArgs e) { base.OnMouseDoubleClick(e); Area note = PointerOnCalendarNote(e.Location); if (note != null) { _calendarNote = new System.Windows.Forms.TextBox(); _calendarNote.KeyDown += new KeyEventHandler(TextBox_KeyDown); _calendarNote.MouseLeave += new EventHandler(TextBox_LostFocus); Rectangle r = note.Bounds; r.Inflate(-2, -2); _calendarNote.Bounds = r; _calendarNote.BorderStyle = BorderStyle.None; _calendarNote.Text = note.Text; _calendarNote.Multiline = true; _calendarNote.Tag = note; Controls.Add(_calendarNote); _calendarNote.Visible = true; _calendarNote.Focus(); _isAddingNote = true; } else { _selectedItem = null; foreach (TrainingItem item in _items) { if (ItemInSelection(item) && PointerOnArea(e.Location, item.Bounds)) { _selectedItem = item; if (ItemDoubleClick != null) ItemDoubleClick(this, new CalendarEventArgs(_selectedItem)); onTrainingItemEdit(_selectedItem); return; } } } }
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; }*/ } }
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 }
private bool ItemInChart(TrainingItem item, DateTime chartStartDate, DateTime chartEndDate) { return chartStartDate.Date <= item.EndDate.Date && item.StartDate.Date <= chartEndDate.Date; }
/// <summary> /// Determines if the item is in the current selection /// </summary> /// <param name="item"></param> /// <returns></returns> internal bool ItemInSelection(TrainingItem item) { return _selectionStart.Date <= item.EndDate.Date && item.StartDate.Date <= _selectionEnd.Date; }