void ChairButton_Click(object sender, EventArgs e, string buttonString) { Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); ReservationService reservationService = app.GetService <ReservationService>("reservations"); ReservationCreate reservationScreen = app.GetScreen <ReservationCreate>("reservationCreate"); // Parse button data string[] parts = buttonString.Replace("button", "").Split('-'); int row = ValidationHelper.ParseInt(parts[0]); int col = ValidationHelper.ParseInt(parts[1]); // Get chair Chair chair = chairService.GetChairByRoomAndPosition(show.GetRoom(), row, col); if (reservationService.IsChairTaken(chair, show) || reservationScreen.ContainsChair(chair)) { GuiHelper.ShowError("Deze stoel is niet beschikbaar"); return; } reservationScreen.AddChair(chair); // Redirect to screen app.ShowScreen(reservationScreen); }
public override void OnShow() { Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); RoomService roomService = app.GetService <RoomService>("rooms"); ReservationService reservationService = app.GetService <ReservationService>("reservations"); ReservationCreate reservationCreate = app.GetScreen <ReservationCreate>("reservationCreate"); base.OnShow(); container.Controls.Clear(); container.RowStyles.Clear(); container.ColumnStyles.Clear(); // Get chairs and room size List <Chair> chairs = chairService.GetChairsByRoom(show.GetRoom()); int Maximum = chairs.Count; int highestRow = 0; int highestColum = 0; for (int x = 1; x < Maximum; x++) { if (highestRow < chairs[x].row) { highestRow = chairs[x].row; } if (highestColum < chairs[x].number) { highestColum = chairs[x].number; } } container.ColumnCount = highestColum; container.RowCount = highestRow; for (int i = 0; i < highestColum; i++) { container.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / highestColum)); } for (int i = 0; i < highestRow; i++) { container.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / highestRow)); } for (int i = 0; i < highestRow; i++) { for (int j = 0; j < highestColum; j++) { Chair chair = chairService.GetChairByRoomAndPosition(show.GetRoom(), i + 1, j + 1); // Ignore if chair doesn't exist if (chair == null) { continue; } if (reservationService.IsChairTaken(chair, show) || reservationCreate.ContainsChair(chair)) { Button button = new Button(); button.Text = string.Format("Niet beschikbaar"); button.BackColor = Color.Red; button.Name = string.Format("button" + (i + 1) + "-" + (j + 1)); button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ChairButton_Click(sender, e, button.Name); }; container.Controls.Add(button, j, i); } else { Button button = new Button(); button.Text = string.Format("R" + i + "-N" + j + " prijs: " + chair.price); button.BackColor = Color.Green; button.Name = string.Format("button" + (i + 1) + "-" + (j + 1)); button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ChairButton_Click(sender, e, button.Name); }; container.Controls.Add(button, j, i); } } } }