Exemplo n.º 1
0
        //Add or edit calendar day
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            ClassCalendar    calendar;
            ClassCalendarDay day;

            try
            {
                calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase();
                if (calendar.Status.StatusId != sql.SelectStatusId(EnumStatus.New))
                {
                    throw new Exception("Calendar status must be new");
                }
                day = GetCalendarDayOrGenerateIt(sender, calendar);
                WindowCalendarDayEdition window = new WindowCalendarDayEdition(day, calendar.Year, calendar.Month, sql.ListOfCalendarDays(calendar.CalendarId));
                if (!(sender is Button))
                {
                    window.createNew = false;
                }
                bool update = (bool)window.ShowDialog();
                if (!update)
                {
                    throw new Exception("Operation canceled");
                }
                if (sender is Button)
                {
                    sql.CreateCalendarDay(day.Day, calendar.CalendarId, day.StartTime, day.EndTime);
                    MessageBox.Show("Calendar day succesfully added");
                    ReloadData();
                    return;
                }
                sql.UpdateCalendarDay(day.Day, day.CalendarDayId, day.StartTime, day.EndTime);
                MessageBox.Show("Calendar day succesfully edited");
                ReloadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
                return;
            }
        }