コード例 #1
0
ファイル: FrontEndHelper.cs プロジェクト: YosefAhmed/Trivago
        private static void ConfirmReserveButton_Click(object sender, RoutedEventArgs e)
        {
            DataModels          database             = DataModels.GetInstance();
            Button              button               = (Button)sender;
            List <Object>       data                 = (List <Object>)button.Tag;
            Calendar            datePicker           = (Calendar)data[0];
            TextBox             numberofGuestTextBox = (TextBox)data[1];
            RoomsListShowCanvas roomListShowCanvas   = (RoomsListShowCanvas)data[2];
            int index = (int)data[3];

            DateTime startDate = datePicker.SelectedDates[0];
            DateTime endDate   = datePicker.SelectedDates[datePicker.SelectedDates.Count - 1];

            if (!BackEndHelper.IsNumber(numberofGuestTextBox.Text))
            {
                MessageBox.Show("Number of guests must be a number");
                return;
            }
            int  numberOfGuests = int.Parse(numberofGuestTextBox.Text);
            Room room           = roomListShowCanvas.GetSelectedRoom(index);

            if (numberOfGuests > room.type.maxGuests)
            {
                MessageBox.Show("Number of Guests bigger than room capacity");
                return;
            }

            Booking booking = new Booking(database.GetBookingId(), startDate, endDate, numberOfGuests,
                                          GetMainWindow().ActiveUser, roomListShowCanvas.GetSelectedMealPlan(index),
                                          room, new Review(database.GetBookingId()), roomListShowCanvas.GetSelectedWebsite(index));

            if (database.AddBooking(booking))
            {
                MessageBox.Show("You Booked the room !");
            }
            else
            {
                MessageBox.Show("Error");
            }
        }
コード例 #2
0
ファイル: FrontEndHelper.cs プロジェクト: YosefAhmed/Trivago
        public static void CreateReservePopupWindow(RoomsListShowCanvas roomListShowCanvas, int index)
        {
            DataModels database = DataModels.GetInstance();

            Window popup = new Window
            {
                Width  = 350,
                Height = 500,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
                Title = "Confirm Booking"
            };

            Grid popupGrid = new Grid
            {
                Background = new SolidColorBrush(Color.FromRgb(255, 255, 255))
            };

            popup.Content = popupGrid;

            StackPanel reservePopupStackPanel = new StackPanel
            {
                Background = new SolidColorBrush(Color.FromRgb(255, 255, 255)),
                Margin     = new Thickness(10, 10, 10, 10)
            };

            popupGrid.Children.Add(reservePopupStackPanel);

            Grid numberofGuestsGrid = new Grid
            {
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    }
                }
            };

            reservePopupStackPanel.Children.Add(numberofGuestsGrid);

            Label numberofGuestsLabel = new Label
            {
                Content  = "Number of Guests : ",
                FontSize = 22
            };

            Grid.SetColumn(numberofGuestsLabel, 0);
            numberofGuestsGrid.Children.Add(numberofGuestsLabel);

            TextBox numberofGuestTextBox = new TextBox
            {
                Width    = 50,
                FontSize = 22
            };

            Grid.SetColumn(numberofGuestTextBox, 1);
            numberofGuestsGrid.Children.Add(numberofGuestTextBox);

            Label mealLabel = new Label
            {
                Content  = "Meal Plan : " + roomListShowCanvas.GetSelectedMealPlan(index).name,
                FontSize = 22,
                Margin   = new Thickness(0, 10, 0, 0)
            };

            reservePopupStackPanel.Children.Add(mealLabel);

            Label websiteLabel = new Label
            {
                Content  = "Website : " + roomListShowCanvas.GetSelectedWebsite(index).name,
                FontSize = 22,
                Margin   = new Thickness(0, 10, 0, 0)
            };

            reservePopupStackPanel.Children.Add(websiteLabel);

            Label priceLabel = new Label
            {
                Content  = "Price : ",
                FontSize = 22,
                Margin   = new Thickness(0, 10, 0, 0)
            };

            reservePopupStackPanel.Children.Add(priceLabel);

            Calendar datePicker = new Calendar
            {
                SelectionMode = CalendarSelectionMode.SingleRange,
                Margin        = new Thickness(0, 10, 0, 0)
            };

            datePicker.SelectedDate     = DateTime.Now;
            datePicker.DisplayDateStart = DateTime.Today;
            List <Booking> bookings = database.GetRoomBookings(roomListShowCanvas.GetSelectedRoom(index));

            foreach (Booking booking in bookings)
            {
                datePicker.BlackoutDates.Add(new CalendarDateRange(booking.startDate, booking.endDate));
            }
            reservePopupStackPanel.Children.Add(datePicker);

            Button confirmReserveButton = FrontEndHelper.CreateButton(80, 40, "Confirm");

            confirmReserveButton.Margin = new Thickness(0, 10, 0, 0);
            confirmReserveButton.Click += ConfirmReserveButton_Click;
            reservePopupStackPanel.Children.Add(confirmReserveButton);
            List <object> data = new List <object>();

            data.Add(datePicker);
            data.Add(numberofGuestTextBox);
            data.Add(roomListShowCanvas);
            data.Add(index);
            confirmReserveButton.Tag = data;

            popup.Owner = GetMainWindow();
            popup.ShowDialog();
        }