Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8925651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:45:24+00:00 2026-06-15T07:45:24+00:00

How would I go about changing to code to eliminate the textbox that takes

  • 0

How would I go about changing to code to eliminate the textbox that takes the value of the seatnumber and makes the reservation they can simply select which seat they want from the seating chart in the listbox and click make reservation. I know there’s some unused code in here that needs cleaned up just ignore it i’ve been playing around with different ways to do this.

Heres the form code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Reservations
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Flight curFlight;
        List<Flight> flightlist = new List<Flight>();

        Flight flight1 = new Flight("Cessna Citation X", "10:00AM", "Denver", 6, 2);
        Flight flight2 = new Flight("Piper Mirage", "10:00PM", "Kansas City", 3, 2);

        private void Form1_Load(object sender, EventArgs e)
        {
            MakeReservations();
            DisplayFlights();
            SetupFlights();


        }

        private void lstFlights_SelectedIndexChanged(object sender, EventArgs e)
        {
            curFlight = (Flight)lstFlights.SelectedItem;
            txtDepart.Text = curFlight.DepartureTime;
            txtDestination.Text = curFlight.Destination;
            string[] seatChart = curFlight.SeatChart;
            DisplaySeatChart(seatChart);
        }

        private void DisplaySeatChart(string[] seating)
        {
            lstSeatChart.Items.Clear();
            for (int seat = 0; seat <= seating.GetUpperBound(0); seat++)
            {
                lstSeatChart.Items.Add("Seat: " + (seat + 1) + "       " + seating[seat]);
            }
        }

        private void SetupFlights()
        {


            //flightlist.Add(flight1);
            //flightlist.Add(flight2);


        }

        private void MakeReservations()
        {
            flight1.MakeReservation("Dill", 12);
            flight1.MakeReservation("Deenda", 3);
            flight1.MakeReservation("Schmanda", 11);
            flight2.MakeReservation("Dill", 4);
            flight2.MakeReservation("Deenda", 2);
        }

        private void DisplayFlights()
        {
            lstFlights.Items.Clear();
            lstFlights.Items.Add(flight1);
            lstFlights.Items.Add(flight2);
        }

        private void btnMakeReservation_Click(object sender, EventArgs e)
        {
            string name;
            int seatNum;
            string[] seatChart = curFlight.SeatChart;

            if (txtCustomerName.Text != "" && txtSeatNum.Text != "")
            {
                name = txtCustomerName.Text;
                seatNum = Convert.ToInt16(txtSeatNum.Text);
                curFlight.MakeReservation(name, seatNum);

                lstSeatChart.Items.Clear();

                DisplaySeatChart(seatChart);
            }
            else
            {
                MessageBox.Show("Please Fill out Name and Seat Number.", "Reservation Error");
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            string name;
            int seatNum;
            string[] seatChart = curFlight.SeatChart;

            if (txtCustomerName.Text != "" && txtSeatNum.Text != "")
            {
                name = txtCustomerName.Text;
                seatNum = Convert.ToInt16(txtSeatNum.Text);
                curFlight.EditReservation(name, seatNum);

                lstSeatChart.Items.Clear();

                DisplaySeatChart(seatChart);
            }
            else
            {
                MessageBox.Show("Please Fill out Name and Seat Number.", "Reservation Error");
            }
        }
    }
}

HERES THE CLASS CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Reservations
{
    class Flight
    {
        private string mPlane;
        private string mDepartureTime;
        private string mDestination;
        private int mRows;
        private int mSeats;
        private string[] mSeatChart;

        public Flight()
        {
        }

        public Flight(string planeType, string departureTime, string destination, int numRows, int numSeatsPerRow)
        {
            this.Plane = planeType;
            this.DepartureTime = departureTime;
            this.Destination = destination;
            this.Rows = numRows;
            this.Seats = numSeatsPerRow;

            // create the seat chart array
            mSeatChart = new string[Rows * Seats];

            for (int seat = 0; seat <= mSeatChart.GetUpperBound(0); seat++)
            {
                mSeatChart[seat] = "Open";
            }
        }

        public string Plane
        {
            get { return mPlane; }
            set { mPlane = value; }
        }

        public string DepartureTime
        {
            get { return mDepartureTime; }
            set { mDepartureTime = value; }
        }

        public string Destination
        {
            get { return mDestination; }
            set { mDestination = value; }
        }

        public int Rows
        {
            get { return mRows; }
            set { mRows = value; }
        }

        public int Seats
        {
            get { return mSeats; }
            set { mSeats = value; }
        }

        public string[] SeatChart
        {
            get { return mSeatChart; }
            set { mSeatChart = value; }
        }

        public override string ToString()
        {
            return this.Plane;
        }


        public void MakeReservation(string name, int seat)
        {
            if (IsFull(seat) == false)
            {
                if (seat <= (Rows * Seats) && mSeatChart[seat - 1] == "Open")
                {
                    mSeatChart[seat - 1] = name;
                }
                else
                {
                    MessageBox.Show("Seat is taken.", "Reservation Error");

                }

            }
            else
            {
                MessageBox.Show("Plane is full please choose another flight.", "Reservation Error");
            }
        }

        public void EditReservation(string name, int seat)
        {
            if (seat <= (Rows * Seats) && mSeatChart[seat - 1] != "Open")
            {
                mSeatChart[seat - 1] = name;
            }
            if (seat > mSeatChart.GetUpperBound(0))
            {
                MessageBox.Show("Invalid seat number.", "Reservation Error");
            }
            else
            {
                if (mSeatChart[seat - 1] == "Open")
                {
                    MessageBox.Show("No such reservation exists.", "Reservation Error");
                }
            }

        }

        public bool IsFull(int seat)
        {
            if (seat >= (Rows * Seats) && mSeatChart[seat - 1] != "Open")
            {
                return true;
            }
            return false;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:45:26+00:00Added an answer on June 15, 2026 at 7:45 am

    Answer is simple rather than

    seatNum = Convert.ToInt16(txtSeatNum.Text);
    

    use

    seatNum = lst.SeatChart.SelectedIndex + 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I go about changing points that are 'near' linear (within a threshold),
Does anyone know how I would go about changing (transforming) an image based on
I would like to know how I would go about altering the HTML that
I was wondering how i would go about changing image.src in the javascript without
Using the WCF Web API how would I go about changing a response's content
I'm trying to build a GraphBot class that can answer different questions about about
I would like to code a shelf and I don't want to think about
I was wonder how you would go about changing the selected tab of a
I would like 'about' to route to 'abouts/1' I tried this: match 'about' =>
Any ideas how I would go about writing a javascript method to insert an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.