Helllo

I'm doing a theatre booking system for an assignment. I have got to the stage where I can
generate the seating plan from the database. The problem that I am having is that the seats are running in the wrong direction.

I have swapped my x's and y's but it seems to make no difference.

Can anyone see what I am getting mixed up please?

Thank you ... John:S

private void Seating(DataSet dsTickets)
        {

            Button[,] seatButton = new Button[30, 30];//multidimensional array
            seatBox.Controls.Clear();
            //dsTickets

            int R = 30;
            int S = 30;


            for (int x = 0; x < R; x++)//loop for rows
            {
                for (int y = 0; y < S; y++)//loop for columns
                {

                    string seatNumber = Convert.ToChar(x + 65).ToString() + (y + 1).ToString();
                    foreach (DataRow drTickets in dsTickets.Tables[0].Rows)// loop through rows / seats and check 
                    {

                        //check if available

                        //

                        if (drTickets["SeatNumber"].ToString().TrimEnd() == seatNumber)// if the seat numbers in the database match the button I am about to create
                        {



                            seatButton[x, y] = new Button();//Create the Buttons
                            seatButton[x, y].Name = "seatButton" + seatNumber;//name and coordinates and set up number, number to show//name and coordinates and set up number, number to show
                            seatButton[x, y].Width = 15;//sizing
                            seatButton[x, y].Height = 15;//sizing
                            //seatButton[x, y].Left = seatButton[x, y].Left + seatButton[x, y].Width + (x * 15);
                            //seatButton[x, y].Top = seatButton[x, y].Top + seatButton[x, y].Top + 15 + (y * 15);//Centre the button
                            seatButton[x, y].Location = new Point(x * 15, y * 15);

                            seatButton[x, y].Text = " ";//declares text variable
                            seatButton[x, y].BackColor = Color.SlateGray;
                            seatButton[x, y].ForeColor = Color.AntiqueWhite;//set initial text colour to white
                            seatButton[x, y].Text = "A";//Set initial text A for available
                            seatBox.Controls.Add(seatButton[x, y]);//Add them to the panel
                            
                            seatButton[x, y].Tag = drTickets;
                            seatButton[x, y].Click += new System.EventHandler(Button_Click);



                            if (drTickets["AvailableOrsold"].ToString().TrimEnd() == "S")
                            {


                                if (drTickets["TicketType"].ToString() == "A")
                                {

                                    seatButton[x, y].BackColor = Color.Orange;
                                    seatButton[x, y].ForeColor = Color.Black;
                                    seatButton[x, y].Text = "S";

                                }

                                else if (drTickets["TicketType"].ToString() == "C")
                                {
                                    seatButton[x, y].BackColor = Color.SpringGreen;
                                    seatButton[x, y].ForeColor = Color.Black;
                                    seatButton[x, y].Text = "S";

                                }

                                else if (drTickets["TicketType"].ToString() == "F")
                                {
                                    seatButton[x, y].BackColor = Color.PaleGoldenrod;
                                    seatButton[x, y].ForeColor = Color.Black;
                                    seatButton[x, y].Text = "S";

                                }

                                seatBox.Controls.Add(seatButton[x, y]);//Add them to the panel

                                string toolTipText = Convert.ToChar(x + 65).ToString() + (x + 1).ToString();
                                ToolTip buttonTooltip = new ToolTip();
                                buttonTooltip.SetToolTip(seatButton[x, y], toolTipText);
       


                            }
                        }

                    }
                }
            }
        }

You have 3 loops here. It seems strange to me. 1st you loop through rows, and in eqach row you loop through columns, and in each column you loop again through rows od dataTable.
This has no point I would say.
Tell me one thing, what dataSet (dataTable at index 0) holds? Whats in it?
You could loop only through the dataTable, and not trought those two loops x and y.

Please write some of the logic you have there, so I can understand the code a bit better.

Comments
Thanks as always for the help

You have 3 loops here. It seems strange to me. 1st you loop through rows, and in eqach row you loop through columns, and in each column you loop again through rows od dataTable.
This has no point I would say.
Tell me one thing, what dataSet (dataTable at index 0) holds? Whats in it?
You could loop only through the dataTable, and not trought those two loops x and y.

Please write some of the logic you have there, so I can understand the code a bit better.

Hi Mitja

Thanks for that - the code is a mixture of tic tac toe game and theatre booking which may explain any anomolies.

Since yesterday I now have it working and displaying the correct way round ...

where I had

seatButton[x, y].Location = new Point(x * 15, y * 15);

I changed it to this:

seatButton[x, y].Location = new Point(y * 15, x * 15);

Then I kicked myself and banged my head against the wall for ten minutes ;0)

Thanks again .... John

Edited 5 Years Ago by johnt68: n/a

This question has already been answered. Start a new discussion instead.