// Separates table by adding the two tables that were combined at first, // and adding them back to tableList. public void SeparateTables(CombinedTable <Table> combinedTable) { foreach (Table table in combinedTable.combinedTables) { TableList.Add(table); } TableList.Remove(combinedTable); }
private void DrawCombinedTable(CombinedTable <Table> combinedTable) { combinedTable.placementX = Canvas.GetLeft(sourceButton); combinedTable.placementY = Canvas.GetTop(sourceButton); double newX = Canvas.GetLeft(_hitRectangle); double newY = Canvas.GetTop(_hitRectangle); bool tableLocation = false; // Before the new, combined table is being drawn we hide the tables being combined. // This way, when we separate the tables again we change the visibility of the tables back to show, // and they're back to their original position. foreach (Table table in combinedTable.combinedTables) { if (Area.Children.OfType <Button>().ToList().Find(x => (string)x.Content == $"Table { table.tableNumber }") != null) { Area.Children.OfType <Button>().ToList().Find(x => (string)x.Content == $"Table {table.tableNumber}").Visibility = Visibility.Hidden; } } // Left if (combinedTable.placementX > newX && combinedTable.placementY == newY + 10) { Button button = new Button() { Content = $"*Table { combinedTable.tableNumber }", Width = tableSize + 100, Height = tableSize, Background = Brushes.White, BorderThickness = new Thickness(2), ToolTip = $"{ Content }" + $"\nSeats: { combinedTable.seats }" + $"\nStatus: { combinedTable.state }" + $"\nX: { newX + 10 }" + $"\nY: { newY + 10 }", }; button.Margin = new Thickness(10); Canvas.SetTop(button, newY); Canvas.SetLeft(button, newX); Area.Children.Add(button); button.Click += new RoutedEventHandler(Button_Click); } // Right else if (combinedTable.placementX < newX && combinedTable.placementY == newY + 10) { Button button = new Button() { Content = $"*Table { combinedTable.tableNumber }", Width = tableSize + 100, Height = tableSize, Background = Brushes.White, BorderThickness = new Thickness(2), ToolTip = $"{ Content }" + $"\nSeats: { combinedTable.seats }" + $"\nStatus: { combinedTable.state }" + $"\nX: { combinedTable.placementX }" + $"\nY: { combinedTable.placementY }", }; Canvas.SetTop(button, combinedTable.placementY); Canvas.SetLeft(button, combinedTable.placementX); Area.Children.Add(button); button.Click += new RoutedEventHandler(Button_Click); } // Bottom else if (combinedTable.placementY < newY && combinedTable.placementX == newX + 10) { Button button = new Button() { Content = $"*Table { combinedTable.tableNumber }", Width = tableSize, Height = tableSize + 100, Background = Brushes.White, BorderThickness = new Thickness(2), ToolTip = $"{ Content }" + $"\nSeats: { combinedTable.seats }" + $"\nStatus: { combinedTable.state }" + $"\nX: { combinedTable.placementX }" + $"\nY: { combinedTable.placementY }", }; Canvas.SetTop(button, combinedTable.placementY); Canvas.SetLeft(button, combinedTable.placementX); Area.Children.Add(button); button.Click += new RoutedEventHandler(Button_Click); } // Top else if (combinedTable.placementY > newY && combinedTable.placementX == newX + 10) { Button button = new Button() { Content = $"*Table { combinedTable.tableNumber }", Width = tableSize, Height = tableSize + 100, Background = Brushes.White, BorderThickness = new Thickness(2), ToolTip = $"{ Content }" + $"\nSeats: { combinedTable.seats }" + $"\nStatus: { combinedTable.state }" + $"\nX: { newX + 10 }" + $"\nY: { newY + 10 }", }; button.Margin = new Thickness(10); Canvas.SetTop(button, newY); Canvas.SetLeft(button, newX); Area.Children.Add(button); button.Click += new RoutedEventHandler(Button_Click); } }
// Button representing a table on the map, Event handler private void Button_Click(object sender, RoutedEventArgs e) { // We get the button we clicked on from the sender Button clickedButton = (Button)sender; // Assign event has been triggered if (assignEventActivated) { // If highlightedReservation hasn't been set its value is null, so we try to catch it try { Table table = tableManagementSystem.TableList.Find(x => $"Table { x.tableNumber }" == (string)clickedButton.Content); if (table == null) { table = tableManagementSystem.TableList.Find(x => $"*Table { x.tableNumber }" == (string)clickedButton.Content); if (table == null) { MessageBox.Show("Error: Could not find table"); return; } } //tableManagementSystem.TableList.Find(x => $"*Table { x.tableNumber }" == (string)clickedButton.Content).state == "Occupied" // Checks if the table is already occupied if (table.state == "Occupied") { //throw new TableAlreadyAssignedException("Error: Cannot assign an occupied table!"); MessageBox.Show("The table is already occupied and could not be assigned"); return; } // We assign the table with AssignTable else { tableManagementSystem.AssignTable(table, highlightedReservation); tableManagementSystem.AssignedReservationList.Add(highlightedReservation); tableManagementSystem.ReservationList.Remove(tableManagementSystem.ReservationList.Find(x => x.id == highlightedReservation.id)); ReservationListView.Items.Refresh(); AssignedReservationListView.Items.Refresh(); clickedButton.Background = Brushes.Orange; sourceButton = clickedButton; // Updates the button to now display it's updated state sourceButton.ToolTip = $"Table: { table.tableNumber }" + $"\nSeats: { table.seats }" + $"\nStatus: { table.state }" + $"\nX: { Canvas.GetLeft(sourceButton) }" + $"\nY: { Canvas.GetTop(sourceButton) }" + $"\nBookingID: { table.bookingID }"; // Reset... assignEventActivated = false; assignbtn.Background = Brushes.White; } } catch (NullReferenceException ex) { MessageBox.Show("A reservation has not been selected"); return; } } // Combine event has been triggered else if (combineEventActivated) { // Sets the second table and combines it with the source table if the source table already has been set and it isn't the one we clicked on if (combineTableSource != tableManagementSystem.TableList.Find(x => $"*Table { x.tableNumber }" == (string)clickedButton.Content) && combineTableSource != default) { secondButton = clickedButton; combineTableSecond = tableManagementSystem.TableList.Find(x => $"Table { x.tableNumber }" == (string)clickedButton.Content); MessageBox.Show($"Table { combineTableSecond.tableNumber } er nu Second table"); currentCombinedTable = tableManagementSystem.CombineTables(combineTableSource, combineTableSecond); AllCombinedTables.Add(currentCombinedTable); // Hjælpefunktion der tjekker SourceTable's naboer (rektangler) og farver dem som er ledige CheckNeighbours(sourceButton); tableManagementSystem.AddTableToList(currentCombinedTable); } else // Setting the Source table { sourceButton = clickedButton; combineTableSource = tableManagementSystem.TableList.Find(x => $"Table { x.tableNumber }" == (string)clickedButton.Content); if (combineTableSource is null) { combineTableSource = AllCombinedTables.Find(x => $"Table { x.tableNumber }" == (string)clickedButton.Content); } MessageBox.Show($"Table { combineTableSource.tableNumber } er nu source table"); } } }