private void comboBoxCalendarType_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxCalendarType.SelectedIndex == 0) { calendarTypes = Lifelength.CalendarTypes.Days; } else if (comboBoxCalendarType.SelectedIndex == 1) { calendarTypes = Lifelength.CalendarTypes.Months; } else { calendarTypes = Lifelength.CalendarTypes.Years; } if (readOnly) { //blockValidatindCalendar = true; SetTextBoxCalendarValue(Calendar.TotalDays); //blockValidatindCalendar = false; } else { double calendar; if (double.TryParse(textBoxCalendar.Text, out calendar)) { SetCalendarData(Lifelength.ParseCalendar(calendar, CalendarTypes), false); } } }
private void SetCalendarData(TimeSpan calendar, bool changeCalendarTypes) { int days = (int)Math.Round(calendar.TotalDays); if (readOnly || changeCalendarTypes) { if (!CalendarApplicable) { textBoxCalendar.Text = NotApplicableString; } else if (days % 365 == 0) { CalendarTypes = Lifelength.CalendarTypes.Years; textBoxCalendar.Text = (days / 365).ToString(); } else if (days % 360 == 0) { CalendarTypes = Lifelength.CalendarTypes.Years; textBoxCalendar.Text = (days / 360).ToString(); } else if (days % 30 == 0) { CalendarTypes = Lifelength.CalendarTypes.Months; textBoxCalendar.Text = (days / 30).ToString(); } else { CalendarTypes = Lifelength.CalendarTypes.Days; textBoxCalendar.Text = days.ToString(); } } else { SetTextBoxCalendarValue(days); } }