Пример #1
0
        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");
            }
        }
Пример #2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //take flight id from comboBox selection
                int f = int.Parse(cbFlightID.Text);

                // Load the seats for the selected flights
                stClass.loadSeats(f);
                for (int i = 0; i < stClass.seatCount; i++)
                {                                 //gettinig seatrow, seatnum and available
                    char c         = stClass.seatObject[i].SeatRow;
                    int  r         = (int)c - 64; //subtract 64 and change back to integer,eg A = 65-64= 1
                    int  s         = stClass.seatObject[i].SeatNumber;
                    int  available = stClass.seatObject[i].Available;
                    seatStatus[s, r] = available; //integer available assigned to array we declare top
                }

                int totalButtons = pnlPlane.Controls.Count; //now to remove the extra buttons that we have offset or removed from above
                for (int i = 0; i < totalButtons; i++)
                {                                           //existing seatbuttons removed from panel when selectedindex change
                    pnlPlane.Controls.RemoveAt(0);
                }


                //DISPLAY PRICE FROM BOOK CLASS
                bookClass.getFlightDetails(Convert.ToString(f));
                label4.Text = Convert.ToString(bookClass.TotalFare);

                drawPlan();//call the draw plan method for each flight changed
            }
            catch (NullReferenceException ex0)
            {
                MessageBox.Show("Error! Please select a valid flight from dropdown box  \r\nException Error : " + ex0.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex1)
            {
                MessageBox.Show("Error!  \r\nException Error : " + ex1.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        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();
        }