private void button3_Click(object sender, EventArgs e) //btnBook { //if Book Ticket button is clicked try { //first validate and check if the class and payment methods are selected if ((cmbClass.Text == "") || (cmbPmt.Text == "")) { MessageBox.Show("Please make sure you choose a Payment Method and Flight Class", "Select Payment and Class", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else {//then save all to booking table //assigning the form detalis into class variable to store in database bookClass = new BookingClass(); bookClass.FlightID = txtFlight.Text; bookClass.CustomerID = txtCustomer.Text; bookClass.From = lblFrom.Text; bookClass.To = lblTo.Text; bookClass.PmtMetd = cmbPmt.Text; bookClass.NumSeats = Convert.ToInt32(lblSeat.Text); bookClass.TotalFare = Convert.ToDouble(txtFare.Text) * Convert.ToDouble(lblRate.Text); txtTotFare.Text = Convert.ToString(bookClass.TotalFare); bookClass.addBooking(); char seatRow; int seatNum; int rowNumber; //update seatRecords in database seatClass seatObj = new seatClass(); seatObj.loadSeats(Convert.ToInt32(bookClass.FlightID)); for (int i = 0; i < seatObj.seatCount; i++) { //get row and number from seat class and assign here seatRow = seatObj.seatObject[i].SeatRow; seatNum = seatObj.seatObject[i].SeatNumber; rowNumber = (int)seatRow - 64; //take seatrow above and subtract from 64 coz we added before to get ascii here we subtract if (seatStat[seatNum, rowNumber] == 2) //seatStat is just the array variable assigned top { //send to update seat class, which turns seat==2 into seat ==1 i.e.booked seatObj.updateSeat(Convert.ToInt32(bookClass.FlightID), seatRow, seatNum, Convert.ToInt32(bookClass.BookingID)); } } MessageBox.Show("Data added successfully! Booking Completed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show("Error: " + ex, "Exception Error"); } }
public void loadSeats(int f) { //this class is to load the seats for each flight seatCount = 0; dbcon = new DatabaseConnector(); //dbcon.dataSet; dbcon.OpenConnection(); //dbcon.InitSqlCommand("SELECT * FROM seat WHERE flightID=" + f + ""); dbcon.GetData("SELECT * FROM seat WHERE flightID=" + f + ""); seatCount = dbcon.dataSetMain.Tables[0].Rows.Count; for (int i = 0; i < seatCount; i++) {//load values from database for each seat seatObject[i] = new seatClass(); dbcon.dataRowMain = dbcon.dataSetMain.Tables[0].Rows[i]; seatObject[i].SeatRow = (Convert.ToChar(dbcon.dataRowMain[0])); seatObject[i].SeatNumber = (int)dbcon.dataRowMain[1]; seatObject[i].FlightID = (int)dbcon.dataRowMain[2]; seatObject[i].Available = (int)dbcon.dataRowMain[3]; seatObject[i].BookingID = (int)dbcon.dataRowMain[4]; } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //load the seat for the selected flight int f = Convert.ToInt32(comboBox1.Text); bookClass.getFlightDetails(Convert.ToString(f)); label3.Text = Convert.ToString(bookClass.TotalFare); seatClass stCl = new seatClass(); stCl.loadSeats(f); double totSales = 0; for (int i = 0; i < stCl.seatCount; i++) { char c = stCl.seatObject[i].SeatRow; int r = ((int)c) - 64; int s = stCl.seatObject[i].SeatNumber; int available = stCl.seatObject[i].Available; seatStatus[s, r] = available; if (available == 1) { totSales += Convert.ToInt32(label3.Text); //adding totSales with the fare for each seat } } int totalButtons = panel1.Controls.Count; for (int i = 0; i < totalButtons; i++) { panel1.Controls.RemoveAt(0); } //now drawPlan drawPlan(); textBox1.Text = totSales.ToString(); }