/// <summary> /// loadSection loads on ComboBox with an specific DateSection ( Year , Month , Day ) /// </summary> /// <param name="time">The time to display</param> /// <param name="section">The ComboBox position</param> /// <param name="kindOfDisplay">The DateSection to display</param> /// <param name="additionalZero">Display Day and Month with addition Zero (02 / 2) and the Year long or short ( 13 / 2013 )</param> private void loadSection(DateTime time, section section, kindOfDisplay kindOfDisplay, bool additionalZero = false) { ///For the correct ComboBox or TextBlock ComboBox sectionBox = null; TextBlock sectionText = null; ///ComboBox Item for adding new Items to the list ComboBoxItem item = null; ///The Selection Changed Event Handler to delete and add again ///so the Event is not raised while adding items and set the ///selected item SelectionChangedEventHandler handler = null; ///Each section has its own ComboBox, TextBox and Selection Changed Handler ///The switch ensures getting the wright one switch (section) { case section.first: sectionBox = firstSectionComboBox; sectionText = firstSectionTextBlock; handler = firstSectionComboBox_SelectionChanged; sectionBox.SelectionChanged -= handler; break; case section.second: sectionBox = secondSectionComboBox; sectionText = secondSectionTextBlock; handler = secondSectionComboBox_SelectionChanged; sectionBox.SelectionChanged -= handler; break; case section.third: sectionBox = thirdSectionComboBox; sectionText = thirdSectionTextBlock; handler = thirdSectionComboBox_SelectionChanged; sectionBox.SelectionChanged -= handler; break; } ///Clears the sectionBox before recreating sectionBox.Items.Clear(); ///Creates different items for different Date Sections switch (kindOfDisplay) { case kindOfDisplay.day: ///Creates the Days for the Month ( 31 , 30 , 29 , 28 ) for (int i = 1; i <= DateTime.DaysInMonth(time.Year, time.Month); i++) { item = new ComboBoxItem(); ///Displayes a Day with an addition Zero or not ( 8 , 08 ) if (additionalZero && i < 10) item.Content += "0"; item.Content += i.ToString(); ///marks the correct day as selected if (i == time.Day) item.IsSelected = true; ///Adds the item sectionBox.Items.Add(item); } ///Adds the Day of the Week ( Monday ... ) sectionText.Text = time.DayOfWeek.ToString(); break; case kindOfDisplay.month: ///Creats the different Month for (int i = 1; i <= 12; i++) { item = new ComboBoxItem(); ///Displayes a Month with an addition Zero or not ( 8 , 08 ) if (additionalZero && i < 10) item.Content += "0"; item.Content += i.ToString(); ///marks the correct month as selected if (i == time.Month) item.IsSelected = true; ///Adds the item sectionBox.Items.Add(item); } ///Adds the Month as its long form ( January ) sectionText.Text = time.ToString("MMM"); break; case kindOfDisplay.year: ///Creates the Yearitems for (int i = MinYear; i <= MaxYear; i++) { item = new ComboBoxItem(); ///Displayes a Year in two different ways ( 13 , 2013 ) if (additionalZero) item.Content += i.ToString().Substring(3); else item.Content += i.ToString(); ///marks the correct year as selected if (i == time.Year) item.IsSelected = true; ///Adds the item sectionBox.Items.Add(item); } ///Clears the sectionText sectionText.Text = ""; ///Adds the DayLightSaving Flag if (DaylightSavingFlag) { if (time.IsDaylightSavingTime()) sectionText.Text += "S"; else sectionText.Text += "N"; } ///Adds the Leap Year Flag if it is a LeapYear if (LeapYearFlag && DateTime.IsLeapYear(time.Year)) sectionText.Text += " L"; break; } sectionBox.SelectionChanged += handler; }
/// <summary> /// loadSection loads on ComboBox with an specific DateSection ( Year , Month , Day ) /// </summary> /// <param name="time">The time to display</param> /// <param name="section">The ComboBox position</param> /// <param name="kindOfDisplay">The DateSection to display</param> /// <param name="additionalZero">Display Day and Month with addition Zero (02 / 2) and the Year long or short ( 13 / 2013 )</param> private void loadSection(DateTime time, section section, kindOfDisplay kindOfDisplay, bool additionalZero = false) { ///For the correct ComboBox or TextBlock ComboBox sectionBox = null; TextBlock sectionText = null; ///ComboBox Item for adding new Items to the list ComboBoxItem item = null; ///The Selection Changed Event Handler to delete and add again ///so the Event is not raised while adding items and set the ///selected item SelectionChangedEventHandler handler = null; ///Each section has its own ComboBox, TextBox and Selection Changed Handler ///The switch ensures getting the wright one switch (section) { case section.first: sectionBox = firstSectionComboBox; sectionText = firstSectionTextBlock; handler = firstSectionComboBox_SelectionChanged; sectionBox.SelectionChanged -= handler; break; case section.second: sectionBox = secondSectionComboBox; sectionText = secondSectionTextBlock; handler = secondSectionComboBox_SelectionChanged; sectionBox.SelectionChanged -= handler; break; case section.third: sectionBox = thirdSectionComboBox; sectionText = thirdSectionTextBlock; handler = thirdSectionComboBox_SelectionChanged; sectionBox.SelectionChanged -= handler; break; } ///Clears the sectionBox before recreating sectionBox.Items.Clear(); ///Creates different items for different Date Sections switch (kindOfDisplay) { case kindOfDisplay.day: ///Creates the Days for the Month ( 31 , 30 , 29 , 28 ) for (int i = 1; i <= DateTime.DaysInMonth(time.Year, time.Month); i++) { item = new ComboBoxItem(); ///Displayes a Day with an addition Zero or not ( 8 , 08 ) if (additionalZero && i < 10) { item.Content += "0"; } item.Content += i.ToString(); ///marks the correct day as selected if (i == time.Day) { item.IsSelected = true; } ///Adds the item sectionBox.Items.Add(item); } ///Adds the Day of the Week ( Monday ... ) sectionText.Text = time.DayOfWeek.ToString(); break; case kindOfDisplay.month: ///Creats the different Month for (int i = 1; i <= 12; i++) { item = new ComboBoxItem(); ///Displayes a Month with an addition Zero or not ( 8 , 08 ) if (additionalZero && i < 10) { item.Content += "0"; } item.Content += i.ToString(); ///marks the correct month as selected if (i == time.Month) { item.IsSelected = true; } ///Adds the item sectionBox.Items.Add(item); } ///Adds the Month as its long form ( January ) sectionText.Text = time.ToString("MMM"); break; case kindOfDisplay.year: ///Creates the Yearitems for (int i = MinYear; i <= MaxYear; i++) { item = new ComboBoxItem(); ///Displayes a Year in two different ways ( 13 , 2013 ) if (additionalZero) { item.Content += i.ToString().Substring(3); } else { item.Content += i.ToString(); } ///marks the correct year as selected if (i == time.Year) { item.IsSelected = true; } ///Adds the item sectionBox.Items.Add(item); } ///Clears the sectionText sectionText.Text = ""; ///Adds the DayLightSaving Flag if (DaylightSavingFlag) { if (time.IsDaylightSavingTime()) { sectionText.Text += "S"; } else { sectionText.Text += "N"; } } ///Adds the Leap Year Flag if it is a LeapYear if (LeapYearFlag && DateTime.IsLeapYear(time.Year)) { sectionText.Text += " L"; } break; } sectionBox.SelectionChanged += handler; }