public override void OnShow()
        {
            Program      app          = Program.GetInstance();
            ChairService chairService = app.GetService <ChairService>("chairs");
            RoomService  roomService  = app.GetService <RoomService>("rooms");

            base.OnShow();
            subTitle.Text = "Zaal " + room.number;

            container.Controls.Clear();
            container.RowStyles.Clear();
            container.ColumnStyles.Clear();

            // Create grid
            List <Chair> chairs = chairService.GetChairsByRoom(room);

            int maximum       = chairs.Count;
            int highestRow    = 0;
            int highestColumn = 0;

            for (int x = 1; x < maximum; x++)
            {
                if (highestRow < chairs[x].row)
                {
                    highestRow = chairs[x].row;
                }

                if (highestColumn < chairs[x].number)
                {
                    highestColumn = chairs[x].number;
                }
            }

            container.ColumnCount = highestColumn;
            container.RowCount    = highestRow;

            for (int i = 0; i < highestColumn; i++)
            {
                container.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / highestColumn));
            }

            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 < highestColumn; j++)
                {
                    Button button = new Button();
                    bool   taken  = chairService.GetChairByRoomAndPosition(room, i + 1, j + 1) != null;

                    button.Text = string.Format(taken ? "{0}-{1}" : "Leeg", i + 1, j + 1);
                    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);
                }
            }
        }
Ejemplo n.º 2
0
        // Returns all chairs that belong to this Room
        public List <Chair> GetChairs()
        {
            ChairService chairService = Program.GetInstance().GetService <ChairService>("chairs");

            return(chairService.GetChairsByRoom(this));
        }
        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);
                    }
                }
            }
        }