Need some help with coding please!!!!!!!!!!
I am creating an Airline application with 90 seats. Information needs to be inserted into the database and then read it into the application so the button will display red and the enabled property will be disabled (enabled = false) so the button can’t be clicked again.
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;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Deployment;
using System.Diagnostics;
namespace Airline
{
public partial class Form1 : Form
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Airline;Integrated Security=True");
SqlCommand com = new SqlCommand();
DataTable dTable = new DataTable();
public Form1()
{
InitializeComponent();
}
private void btnBooking_Click(object sender, EventArgs e)
{
com.Connection = conn;
com.CommandText = "INSERT INTO AirlineTable Values ('" + txbName.Text + "' , '" + txbSurname.Text + "' , '" + txbId.Text + "' , '" + txbWeight.Text + "', '" + txbSeat.Text + "')";
conn.Open();
com.ExecuteNonQuery();
SqlDataAdapter dataA = new SqlDataAdapter("SELECT * FROM AirlineTable", conn);
DataTable dt = new DataTable();
dataA.Fill(dt);
dataGridView1.DataSource = dt;
conn.Close();
txbName.Clear();
txbSurname.Clear();
txbId.Clear();
txbWeight.Clear();
MessageBox.Show("Booking Made Succesfully");
}
private void Form1_Load(object sender, EventArgs e)
{
string seat = "";
DataTable newDataTable = new DataTable();
SqlDataAdapter NewDataA = new SqlDataAdapter("SELECT * FROM AirlineTable", conn);
NewDataA.Fill(newDataTable);
dataGridView1.DataSource = newDataTable;
for (int i = 0; i < 91; i++)
{
if (dataGridView1.SelectedRows[i].Cells[4].Value.ToString() != "")
{
seat = "btn" + dataGridView1.SelectedRows[i].Cells[4].Value.ToString();
Button ZZ = new Button();
btn1.BackColor = Color.Red;
}
}
}
private void btn1_MouseHover(object sender, EventArgs e)
{
ToolTip tt = new ToolTip();
tt.Show("Meiring", this.btn1, 10000);
}
private void btn1_Click(object sender, EventArgs e)
{
if (btn1.Enabled == true)
{
txbSeat.Text = btn1.Text;
btn1.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn2_Click(object sender, EventArgs e)
{
if (btn2.Enabled == true)
{
txbSeat.Text = btn2.Text;
btn2.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn3_Click(object sender, EventArgs e)
{
if (btn3.Enabled == true)
{
txbSeat.Text = btn3.Text;
btn3.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn4_Click(object sender, EventArgs e)
{
if (btn4.Enabled == true)
{
txbSeat.Text = btn4.Text;
btn4.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn5_Click(object sender, EventArgs e)
{
if (btn5.Enabled == true)
{
txbSeat.Text = btn5.Text;
btn5.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn6_Click(object sender, EventArgs e)
{
if (btn6.Enabled == true)
{
txbSeat.Text = btn6.Text;
btn6.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn7_Click(object sender, EventArgs e)
{
if (btn7.Enabled == true)
{
txbSeat.Text = btn7.Text;
btn7.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn8_Click(object sender, EventArgs e)
{
if (btn8.Enabled == true)
{
txbSeat.Text = btn8.Text;
btn8.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn9_Click(object sender, EventArgs e)
{
if (btn9.Enabled == true)
{
txbSeat.Text = btn9.Text;
btn9.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn10_Click(object sender, EventArgs e)
{
if (btn10.Enabled == true)
{
txbSeat.Text = btn10.Text;
btn10.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn11_Click(object sender, EventArgs e)
{
if (btn11.Enabled == true)
{
txbSeat.Text = btn11.Text;
btn11.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn12_Click(object sender, EventArgs e)
{
if (btn12.Enabled == true)
{
txbSeat.Text = btn12.Text;
btn12.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn13_Click(object sender, EventArgs e)
{
if (btn13.Enabled == true)
{
txbSeat.Text = btn13.Text;
btn13.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn14_Click(object sender, EventArgs e)
{
if (btn14.Enabled == true)
{
txbSeat.Text = btn14.Text;
btn14.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn15_Click(object sender, EventArgs e)
{
if (btn15.Enabled == true)
{
txbSeat.Text = btn15.Text;
btn15.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn16_Click(object sender, EventArgs e)
{
if (btn16.Enabled == true)
{
txbSeat.Text = btn16.Text;
btn16.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn17_Click(object sender, EventArgs e)
{
if (btn17.Enabled == true)
{
txbSeat.Text = btn17.Text;
btn17.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn18_Click(object sender, EventArgs e)
{
if (btn18.Enabled == true)
{
txbSeat.Text = btn18.Text;
btn18.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn19_Click(object sender, EventArgs e)
{
if (btn19.Enabled == true)
{
txbSeat.Text = btn19.Text;
btn19.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn20_Click(object sender, EventArgs e)
{
if (btn20.Enabled == true)
{
txbSeat.Text = btn20.Text;
btn20.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn21_Click(object sender, EventArgs e)
{
if (btn21.Enabled == true)
{
txbSeat.Text = btn21.Text;
btn21.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn22_Click(object sender, EventArgs e)
{
if (btn22.Enabled == true)
{
txbSeat.Text = btn22.Text;
btn22.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn23_Click(object sender, EventArgs e)
{
if (btn23.Enabled == true)
{
txbSeat.Text = btn23.Text;
btn23.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn24_Click(object sender, EventArgs e)
{
if (btn24.Enabled == true)
{
txbSeat.Text = btn24.Text;
btn24.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn25_Click(object sender, EventArgs e)
{
if (btn25.Enabled == true)
{
txbSeat.Text = btn25.Text;
btn25.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn26_Click(object sender, EventArgs e)
{
if (btn26.Enabled == true)
{
txbSeat.Text = btn26.Text;
btn26.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn27_Click(object sender, EventArgs e)
{
if (btn27.Enabled == true)
{
txbSeat.Text = btn27.Text;
btn27.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn28_Click(object sender, EventArgs e)
{
if (btn28.Enabled == true)
{
txbSeat.Text = btn28.Text;
btn28.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn29_Click(object sender, EventArgs e)
{
if (btn29.Enabled == true)
{
txbSeat.Text = btn29.Text;
btn29.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn30_Click(object sender, EventArgs e)
{
if (btn30.Enabled == true)
{
txbSeat.Text = btn30.Text;
btn30.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn31_Click(object sender, EventArgs e)
{
if (btn31.Enabled == true)
{
txbSeat.Text = btn31.Text;
btn31.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn32_Click(object sender, EventArgs e)
{
if (btn32.Enabled == true)
{
txbSeat.Text = btn32.Text;
btn32.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn33_Click(object sender, EventArgs e)
{
if (btn33.Enabled == true)
{
txbSeat.Text = btn33.Text;
btn33.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn34_Click(object sender, EventArgs e)
{
if (btn34.Enabled == true)
{
txbSeat.Text = btn34.Text;
btn34.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn35_Click(object sender, EventArgs e)
{
if (btn35.Enabled == true)
{
txbSeat.Text = btn35.Text;
btn35.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn36_Click(object sender, EventArgs e)
{
if (btn36.Enabled == true)
{
txbSeat.Text = btn36.Text;
btn36.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn37_Click(object sender, EventArgs e)
{
if (btn37.Enabled == true)
{
txbSeat.Text = btn37.Text;
btn37.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn38_Click(object sender, EventArgs e)
{
if (btn38.Enabled == true)
{
txbSeat.Text = btn38.Text;
btn38.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn39_Click(object sender, EventArgs e)
{
if (btn39.Enabled == true)
{
txbSeat.Text = btn39.Text;
btn39.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn40_Click(object sender, EventArgs e)
{
if (btn40.Enabled == true)
{
txbSeat.Text = btn40.Text;
btn40.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn41_Click(object sender, EventArgs e)
{
if (btn41.Enabled == true)
{
txbSeat.Text = btn41.Text;
btn41.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn42_Click(object sender, EventArgs e)
{
if (btn42.Enabled == true)
{
txbSeat.Text = btn42.Text;
btn42.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn43_Click(object sender, EventArgs e)
{
if (btn43.Enabled == true)
{
txbSeat.Text = btn43.Text;
btn43.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn44_Click(object sender, EventArgs e)
{
if (btn44.Enabled == true)
{
txbSeat.Text = btn44.Text;
btn44.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn45_Click(object sender, EventArgs e)
{
if (btn45.Enabled == true)
{
txbSeat.Text = btn45.Text;
btn45.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn46_Click(object sender, EventArgs e)
{
if (btn46.Enabled == true)
{
txbSeat.Text = btn46.Text;
btn46.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn47_Click(object sender, EventArgs e)
{
if (btn47.Enabled == true)
{
txbSeat.Text = btn47.Text;
btn47.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void btn48_Click(object sender, EventArgs e)
{
if (btn48.Enabled == true)
{
txbSeat.Text = btn48.Text;
btn48.BackColor = Color.Red;
//btn1.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedCells[4].Value.ToString() != "")
{
btn2.BackColor = Color.Red;
}
}
}
}
Take a look at my coding and please tell me where I went wrong. I will attach a picture to show you how the interface looks as well.
And if I try to run the application this is the Error that I get:
Index was out if range. Must be non-negative and less than the size of the collection.
Parameter name: index.

New Topic/Question
Reply



MultiQuote




|