Example #1
0
 private void btn_OK_Click(object sender, EventArgs e)
 {
     try
     {
         Reservation r;
         if (roomsListBox.CheckedItems.Count == 1)
         {
             r = new Single_Reservation {
                 ReservationID = uint.Parse(reservationIDTextBox.Text),
                 AgencyID      = (agencyIDComboBox.SelectedItem as Tour_Agency).AgencyID,
                 ArrivalDate   = arrivalDateDateTimePicker.Value,
                 Room          = (Room)roomsListBox.CheckedItems[0],
                 Days          = (uint)(leavingDateDateTimePicker.Value - arrivalDateDateTimePicker.Value).Days
             };
         }
         else
         {
             List <Room> checkedRooms = new List <Room>();
             checkedRooms.AddRange(from Room item in roomsListBox.CheckedItems select item);
             r = new Group_Reservation {
                 ReservationID = uint.Parse(reservationIDTextBox.Text),
                 AgencyID      = (agencyIDComboBox.SelectedItem as Tour_Agency).AgencyID,
                 ArrivalDate   = arrivalDateDateTimePicker.Value,
                 Rooms         = checkedRooms,
                 Days          = (uint)(leavingDateDateTimePicker.Value - arrivalDateDateTimePicker.Value).Days
             };
         }
         if (add)
         {
             if (!myBL.AddReservation(r))
             {
                 throw new Exception();
             }
         }
         else
         {
             if (r is Group_Reservation)
             {
                 if (!myBL.UpdateGroupReservation(r.ReservationID, ((Group_Reservation)r).Rooms, r.ArrivalDate, r.Days))
                 {
                     throw new Exception();
                 }
             }
             else if (r is Single_Reservation)
             {
                 if (!myBL.UpdateSingleReservation(r.ReservationID, ((Single_Reservation)r).Room, r.ArrivalDate, r.Days))
                 {
                     throw new Exception();
                 }
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("I am Error");
     }
 }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                Reservation r;
                if (roomsListBox.CheckedItems.Count == 1)
                {
                    r = new Single_Reservation {
                        ReservationID = uint.Parse(reservationIDTextBox.Text),
                        AgencyID = (agencyIDComboBox.SelectedItem as Tour_Agency).AgencyID,
                        ArrivalDate = arrivalDateDateTimePicker.Value,
                        Room = (Room)roomsListBox.CheckedItems[0],
                        Days = (uint)(leavingDateDateTimePicker.Value - arrivalDateDateTimePicker.Value).Days
                    };
                }
                else
                {
                    List<Room> checkedRooms = new List<Room>();
                    checkedRooms.AddRange(from Room item in roomsListBox.CheckedItems select item);
                    r = new Group_Reservation {
                        ReservationID = uint.Parse(reservationIDTextBox.Text),
                        AgencyID = (agencyIDComboBox.SelectedItem as Tour_Agency).AgencyID,
                        ArrivalDate = arrivalDateDateTimePicker.Value,
                        Rooms = checkedRooms,
                        Days = (uint)(leavingDateDateTimePicker.Value - arrivalDateDateTimePicker.Value).Days
                    };
                }
                if (add)
                {
                    if (!myBL.AddReservation(r)) throw new Exception();
                }
                else
                {
                    if (r is Group_Reservation)
                    {
                        if (!myBL.UpdateGroupReservation(r.ReservationID, ((Group_Reservation)r).Rooms, r.ArrivalDate, r.Days)) throw new Exception();
                    }
                    else if (r is Single_Reservation)
                    {
                        if (!myBL.UpdateSingleReservation(r.ReservationID, ((Single_Reservation)r).Room, r.ArrivalDate, r.Days)) throw new Exception();
                    }
                }

            }
            catch (Exception)
            {
                MessageBox.Show("I am Error");
            }
        }