Hello:-/

I have a form that generates a multidimensional button array that represents theatre seating when I select an event in a list box ... so far so good.

I also have a database that I can get to return a list of tickets which relate to the buttons/seats ... very good.

The problem I have is that I haven't got a clue how to go about linking these two parts of the program together to select the seats by button click and then use those clicks to purchase tickets!!

Any ideas much appreciated. Thank you .... John.

How do the tickets relate to the seats/buttons? How are you generating the buttons? How do you know if a seat has already been sold? We need some code and details.

How do the tickets relate to the seats/buttons? How are you generating the buttons? How do you know if a seat has already been sold? We need some code and details.

Hi Momerath - thanks for the help

As far as I understand it ( so it may not be quite right) the tickets in the database have to relate to the seats.

I have put code in to identify the seats when clicked (or their position in the array). So, for example, if I click the first seat button, a message box shows 0,0 and if I click the last button a message box shows 29,14. So that's 30 columns and 15 rows in that theatre.

This is the code I am generating the buttons with:

private void lstEvents_SelectedIndexChanged(object sender, EventArgs e)
        {
            ScheduledEvent showEvent = new ScheduledEvent();
            string selectedEvent = allEvents.GetKey(lstEvents.SelectedIndex).ToString();
            showEvent.GetEventByID(int.Parse(selectedEvent));
            seatBox.Controls.Clear();


                if (showEvent.Confirmed == "Y")
                {

                    if (showEvent.Location == "Llandudno")
                    {
                        int rows = 15;
                        int seats = 30;
                        Seating(rows, seats);

                        lblTheatre.Text = "Welcome to Llandudno Theatre"; 
                        lblSeating.Text = "SeatingPlan:" + "\r\n" + "15 Rows" + "\r\n" + "30 Seats per Row" + "\r\n" + "Total Seats: 450"; 
                    }

                    else if (showEvent.Location == "Caernarfon")
                    {
                        int rows = 12;
                        int seats = 20;
                        Seating(rows, seats);

                        lblTheatre.Text = "Welcome to Caernarfon Theatre";
                        lblSeating.Text = "SeatingPlan:" + "\r\n" + "15 Rows" + "\r\n" + "30 Seats per Row" + "\r\n" + "Total Seats: 450";
                    }

                    else if (showEvent.Location == "Denbigh")
                    {
                        int rows = 10;
                        int seats = 20;
                        Seating(rows, seats);

                        lblTheatre.Text = "Welcome to Denbigh Theatre";
                        lblSeating.Text = "SeatingPlan:" + "\r\n" + "15 Rows" + "\r\n" + "30 Seats per Row" + "\r\n" + "Total Seats: 450";
                    }
                }
                else
                {
                    lstEvents.Items.Add("Unavailable");
                }
        }

        private void Seating(int R, int S)
        {

            Button[,] seatButton = new Button[S, R];//multidimensional array
            seatBox.Controls.Clear();
            for (int y = 0; y < R; y++)//loop for rows
            {
                for (int x = 0; x < S; x++)//loop for columns
                {
                    seatButton[x, y] = new Button();
                    seatButton[x, y].Name = "seatButton" + x + ", " + y;
                    seatButton[x, y].Width = 15;
                    seatButton[x, y].Height = 15;
                    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);
                    seatButton[x, y].Text = " ";
                    seatButton[x, y].BackColor = Color.SlateGray;

                    seatBox.Controls.Add(seatButton[x, y]);
                    seatButton[x, y].Click += new EventHandler(Button_Click);


                }
            }
        }


        private void Button_Click(object sender, EventArgs e)
        {
            Button clickedButton = (Button)sender;

            clickedButton.BackColor = Color.Orange;
        }

I have also been given some code and a dll file to say whether payment is accepted or not and am having a bit of trouble understanding it fully (although some of it makes sense to me thankfully). So I think I need an update tickets method, CreateBooking method etc. This is that code.

private void executePaymentBut_Click(object sender, EventArgs e)
        {
            int BucksPayReturnValue = 0;
            //BucksPay.MakePayment("AXC72937402", txtCardNumber.Text, txtStartDate.Text,  txtEndDate.Text, txtNameOnCard.Text, txtSecurityCode.Text,oCust.Address1, oCust.Address2,oCust.Town, oCust.County,oCust.PostCode);

//Note some of the data you are sending is from the card entry text boxes, the rest is picked up from the customer class object that you have already set.(oCust in this case)

            //Success?
            if (BucksPayReturnValue > 0)
            {
                //Create the booking record and update the Ticket records
                int BookingRef = 0;
                MessageBox.Show("Payment Reference: " + BucksPayReturnValue);
                //BookingRef = CreateBooking(oCust.CustomerNumber, DateTime.Today, DateTime.Now.ToShortTimeString(), 
                //BucksPayReturnValue);
                //UpdateTickets(BookingRef);
            }
            else
            {
                MessageBox.Show("Payment Failed!  Error Code is: " + BucksPayReturnValue.ToString());
            }

            //ResetDisplay();


        }

When it comes to knowing if a seat is sold - this is where I get stuck !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.