public MainWindow() { InitializeComponent(); _bookingManager = new BookingSystemManager(); Switcher.pageSwitcher = this; Loaded += MainWindow_Loaded; Switcher.Switch(new ChooseCategoryScreen()); }
private void submitButton_Click(object sender, RoutedEventArgs e) { //Set reference to the MainWindow instance MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; //Set reference to the _currentOrder which belongs to the MainWindow instance Order order = mainWindow._currentOrder; BookingSystemManager bookingManager = mainWindow._bookingManager; bookingManager.SaveOrderAndOrderDetails(order); MessageBox.Show("You have successfully reserved your bikes. Have a great time."); }//End of submitButton_Click
private void UserControl_Loaded(object sender, RoutedEventArgs e) { //(MainWindow) this.Parent = Means I telling the .NET engine that //this.Parent is actually a MainWindow class instance. //So that I can use with the MainWindow instance's bookingManager object. // The following code works to get the MainWindow instance. The following code // was used when I quickily whip out the code during lesson without any thoughts of refining it. // var bookingManager = ((MainWindow)((Grid)((ContentControl)this.Parent).Parent).Parent).bookingManager; //http://stackoverflow.com/questions/22856745/wpf-get-parent-window MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; BookingSystemManager bookingManager = mainWindow._bookingManager; foreach (Item oneItem in bookingManager.Items) { if (oneItem.CategoryId == _categoryId) { Button button = new Button() { Tag = oneItem.ItemId };//end of button creation button.Click += new RoutedEventHandler(button_Click); StackPanel stackPanel = new StackPanel(); //http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code // var uriSource = new Uri("/BookingSystemCA1;component/" + data.ItemTypes[itemTypeIndex].ItemTypeImageFileName, UriKind.Relative); Image image = new Image() { Width = 200, Height = 100, //http://stackoverflow.com/questions/14337071/convert-array-of-bytes-to-bitmapimage Source = (BitmapSource) new ImageSourceConverter().ConvertFrom(oneItem.Photo), Stretch = Stretch.UniformToFill }; TextBlock textBlock = new TextBlock() { Text = string.Format("{0}", oneItem.ItemName), HorizontalAlignment = HorizontalAlignment.Center }; stackPanel.Children.Add(image); stackPanel.Children.Add(textBlock); button.Content = stackPanel; //I anyhow trial and error. Mouse hover the Margin property gave me a lot of hints on how to set //margin. button.Margin = new System.Windows.Thickness { Top = 3, Bottom = 3, Left = 3, Right = 3 }; this.itemButtonsUniformGrid.Children.Add(button); }//end of for loop } }
private void submitButton_Click(object sender, RoutedEventArgs e) { MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; Order order = mainWindow._currentOrder; BookingSystemManager bookingManager = mainWindow._bookingManager; Boolean isAllUserEntryOkay = true; if (this.reserveDatePickerInput.SelectedDate == null) { MessageBox.Show("You need to specify the reserve date."); isAllUserEntryOkay = false; } if (this.pickUpTimeComboBoxInput.SelectedValue == null) { MessageBox.Show("You need to specify the pick up time slot."); isAllUserEntryOkay = false; } if (this.rentalOptionComboBoxInput.SelectedItem == null) { MessageBox.Show("You need to specify the rental option."); isAllUserEntryOkay = false; } if (isAllUserEntryOkay == true) { if (order == null) { order = new Order(); order.OrderedBy = 2; //Assume that CINDY logon to place this order. } OrderDetail orderDetail = new OrderDetail(); orderDetail.RentalId = ((Rental)this.rentalOptionComboBoxInput.SelectedItem).RentalId; orderDetail.PickupTimeSlot = this.pickUpTimeComboBoxInput.SelectedValue.ToString(); orderDetail.ReserveDate = this.reserveDatePickerInput.SelectedDate; orderDetail.ItemId = _itemId; order.OrderDetails.Add(orderDetail); mainWindow._currentOrder = order; MessageBox.Show("You have added one reservation into your cart"); } //if isAllUserEntryOkay is true } //End of submitButton_Click
public ReserveScreen(int inItemId) { _itemId = inItemId; //Set reference to the MainWindow instance MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; //Set reference to the _currentOrder which belongs to the MainWindow instance Order order = mainWindow._currentOrder; InitializeComponent(); //Set reference to the MainWindow instance's _bookingManager variable for cleaner code BookingSystemManager bookingManager = mainWindow._bookingManager; List <Rental> rentalOptionListForComboBox = bookingManager.Rentals.Where(input => input.ItemId == _itemId).ToList(); List <object> timeSlotListForComboBox = bookingManager.TimeSlots; this.rentalOptionComboBoxInput.ItemsSource = rentalOptionListForComboBox; this.pickUpTimeComboBoxInput.ItemsSource = timeSlotListForComboBox; _itemName = bookingManager.Items .Where(input => input.ItemId == _itemId) .Single() .ItemName; this.itemNameTextBlock.Text = _itemName; }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { //(MainWindow) this.Parent = Means I telling the .NET engine that //this.Parent is actually a MainWindow class instance. //So that I can use with the MainWindow instance's bookingManager object. // The following code works to get the MainWindow instance. The following code // was used when I quickily whip out the code during lesson without any thoughts of refining it. // var bookingManager = ((MainWindow)((Grid)((ContentControl)this.Parent).Parent).Parent).bookingManager; //http://stackoverflow.com/questions/22856745/wpf-get-parent-window MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; BookingSystemManager bookingManager = mainWindow._bookingManager; foreach (Category oneCategory in bookingManager.Categories) { Button button = new Button() { Tag = oneCategory.CategoryId };//end of button creation button.Click += new RoutedEventHandler(button_Click); StackPanel stackPanel = new StackPanel(); //http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code TextBlock textBlock = new TextBlock() { Text = string.Format("{0}", oneCategory.CategoryName), HorizontalAlignment = HorizontalAlignment.Center }; stackPanel.Children.Add(textBlock); button.Content = stackPanel; //I anyhow trial and error. Mouse hover the Margin property gave me a lot of hints on how to set //margin. button.Margin = new System.Windows.Thickness { Top = 3, Bottom = 3, Left = 3, Right = 3 }; this.itemButtonsUniformGrid.Children.Add(button); }//end of for loop }
public ShoppingCartScreen() { //Set reference to the MainWindow instance MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; //Set reference to the _currentOrder which belongs to the MainWindow instance Order order = mainWindow._currentOrder; BookingSystemManager bookingManager = mainWindow._bookingManager; InitializeComponent(); if (order == null) { TextBlock messageTextBlock = new TextBlock(); messageTextBlock.Text = "You have not selected any bikes yet."; this.contentStackPanel.Children.Add(messageTextBlock); } else { foreach (var orderDetail in order.OrderDetails) { string itemName = bookingManager.Items .Where(input => input.ItemId == orderDetail.ItemId) .Single() .ItemName; Rental rental = bookingManager.Rentals .Where(input => input.RentalId == orderDetail.RentalId) .Single(); TextBlock itemReservationDescriptionTextBlock = new TextBlock(); string description = "Bike : " + itemName + "\n"; description += "Rental Option : " + rental.RentalType + "\n"; description += "Pikcup Time : " + orderDetail.PickupTimeSlot + "\n"; itemReservationDescriptionTextBlock.Text = description; itemReservationDescriptionTextBlock.Margin = new Thickness(4, 4, 4, 4); this.contentStackPanel.Children.Add(itemReservationDescriptionTextBlock); }//End of foreach } }