Exemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Bookings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBookings(Booking booking)
 {
     base.AddObject("Bookings", booking);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Booking object.
 /// </summary>
 /// <param name="bookingId">Initial value of the BookingId property.</param>
 /// <param name="employeeId">Initial value of the EmployeeId property.</param>
 /// <param name="passengerId">Initial value of the PassengerId property.</param>
 /// <param name="bookingDate">Initial value of the BookingDate property.</param>
 /// <param name="paymentType">Initial value of the PaymentType property.</param>
 public static Booking CreateBooking(global::System.Int32 bookingId, global::System.String employeeId, global::System.String passengerId, global::System.DateTime bookingDate, global::System.String paymentType)
 {
     Booking booking = new Booking();
     booking.BookingId = bookingId;
     booking.EmployeeId = employeeId;
     booking.PassengerId = passengerId;
     booking.BookingDate = bookingDate;
     booking.PaymentType = paymentType;
     return booking;
 }
        private void btnFinish_Click(object sender, EventArgs e)
        {
            //validasikan user sudah memilih passengerId dan paymentType
            if (cmbId.SelectedIndex < 0)
            {
                MessageBox.Show("Please select passenger id");
            }
            else if (cmbType.SelectedIndex < 0)
            {
                MessageBox.Show("Please select payment type");
            }
            else
            {
                //tampilkan dialog konfirmasi
                DialogResult res = MessageBox.Show(this,"Are you sure?","Confirmation",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    //apabila user memilih yes, maka insert data ke Booking dan DetailBooking
                    Ticket.payment = cmbType.SelectedItem.ToString();
                    int newId = generateId();
                    Booking obj = new Booking();
                    obj.BookingId = newId;
                    obj.BookingDate = DateTime.Now.Date;
                    obj.PaymentType = cmbType.SelectedItem.ToString();
                    obj.PassengerId = cmbId.SelectedItem.ToString();
                    obj.EmployeeId = Form1.userLogin.EmployeeId;

                    ent.AddToBookings(obj);
                    ent.SaveChanges();

                    DetailBooking obj2 = new DetailBooking();
                    obj2.BookingId = newId;
                    obj2.FlightId = Ticket.flight1;

                    ent.AddToDetailBookings(obj2);
                    ent.SaveChanges();

                    if (Ticket.returned)
                    {
                        DetailBooking obj3 = new DetailBooking();
                        obj3.BookingId = newId;
                        obj3.FlightId = Ticket.flight2;

                        ent.AddToDetailBookings(obj3);
                        ent.SaveChanges();
                    }

                    BookTicketStep3Form final = new BookTicketStep3Form();
                    final.Show();
                    this.Dispose();
                }
            }
        }