示例#1
0
 //Home button
 private void BackToHomePage_Click(object sender, RoutedEventArgs e)
 {
     Switcher.BackToHomePage(AccessLevel, FullName, MemberId);
 }
 private void BackToHomePage_Click(object sender, RoutedEventArgs e)
 {
     WebBrowser?.Dispose();
     Switcher.BackToHomePage(AccessLevel, FullName, MemberId);
 }
        private void ReservationButton_Click(object sender, RoutedEventArgs e)
        {
            //Check if there is already a batchreservation in the database. If not, assign 1 to reservationbatch number.
            using (var context = new BootDB())
            {
                var highestBatchCount = context.Reservations.Where(c => c.reservationBatch != 0).Max(x => (int?)x.reservationBatch) ?? 0;

                if (!highestBatchCount.Equals(0))
                {
                    BatchCount = highestBatchCount + 1;
                }
                else
                {
                    BatchCount = 1;
                }
            }

            //check if selected times are possible
            foreach (var boat in SelectionList)
            {
                //getting the selected begin and end time
                try
                {
                    selectedBeginTime = (beginTimePicker.SelectedTime.Value).TimeOfDay;
                    selectedEndTime   = (endTimePicker.SelectedTime.Value).TimeOfDay;
                }
                catch (Exception)
                {
                    ErrorLabel.Content = "Geen geldige invoer";
                    return;
                }
                var check = reservation.CheckTime(selectedBeginTime, selectedEndTime, beginTime, endTime, sunUp, sunDown, false);

                //this will be executed when the selected times are not correct
                if (!check)
                {
                    ErrorLabel.Content = "Deze tijden zijn niet mogelijk";
                }
                else //when it is possible to add reservation
                {
                    using (var context = new BootDB())
                    {
                        var reservation = new Reservations
                        {
                            memberId         = MemberId,
                            date             = selectedDate,
                            beginTime        = selectedBeginTime,
                            endTime          = selectedEndTime,
                            reservationBatch = BatchCount
                        };

                        context.Reservations.Add(reservation);
                        context.SaveChanges();

                        //getting the last reservation id to add that to other table
                        var data = (from r in context.Reservations
                                    orderby r.reservationId descending
                                    select r.reservationId).First().ToString();

                        var id = int.Parse(data);

                        var reservationBoat = new Reservation_Boats
                        {
                            reservationId = id,
                            boatId        = boat.boatId
                        };

                        context.Reservation_Boats.Add(reservationBoat);
                        context.SaveChanges();
                    }
                }
            }

            if (!reservation.CheckTime(selectedBeginTime, selectedEndTime, beginTime, endTime, sunUp, sunDown, false))
            {
                return;
            }
            //show message when reservation is added to screen
            MessageBox.Show("Reservering is gelukt!", "Gelukt", MessageBoxButton.OK, MessageBoxImage.Information);

            Switcher.BackToHomePage(AccessLevel, FullName, MemberId);
        }