示例#1
0
        private void SelectionAcceptButton_Click(object sender, EventArgs e)
        {
            if (SubjectCombobox.SelectedIndex == -1 ||
                HallCombobox.SelectedIndex == -1)
            {
                CustomMessages.ChooseBeforeCarryOn(this, "subject and hall");
                return;
            }

            if (New)
            {
                //databinding by hand
                selection.HallId    = Convert.ToInt32(HallCombobox.SelectedValue);
                selection.SubjectId = Convert.ToInt32(SubjectCombobox.SelectedValue);

                int selection_id = (int)controller.Insert(selection);
                selection.Id = selection_id;
                if (selection_id > 0)
                {
                    selection_time_controller.InsertTimes(selection_id,
                                                          TimetableControl.GetLectureTimes(TimetableControl.IsSelectedCell));
                    selection_lecturer_controller.InsertLecturers(selection_id,
                                                                  checked_lecturers_id.ToList());
                    CustomMessages.Inserted(this, "selection");

                    InsertedSelections.Add(selection);
                    SetAfterInsert();
                }
            }
            else
            {
                //quite the horrible way as I delete everything and re-insert them
                if (controller.Update(selection))
                {
                    selection_time_controller.DeleteBySelection(selection.Id);
                    selection_lecturer_controller.DeleteBySelection(selection.Id);

                    selection_time_controller.InsertTimes(selection.Id,
                                                          TimetableControl.GetLectureTimes(TimetableControl.IsSelectedCell));
                    selection_lecturer_controller.InsertLecturers(selection.Id,
                                                                  checked_lecturers_id.ToList());

                    SetSelection(selection);
                    CustomMessages.Updated(this, "selection");
                    //TimetableControl.ResetLectureTimes();
                    Updated = true;
                }
            }
        }