/// <summary> /// Method will use a dataset to insert all the values into a dataset /// and then grab them later for use in data grid view /// </summary> private void btnCreate_Click(object sender, EventArgs e) { TripDataSet2 td = new TripDataSet2(); TripDataSet2TableAdapters.TripTableAdapter tdTrip = new TripDataSet2TableAdapters.TripTableAdapter(); TripDataSet2.TripRow rowTrip = td.Trip.NewTripRow(); string insurance = "N"; if (cbInsurance.Text.Equals("YES")) { insurance = "Y"; } else { insurance = "N"; } rowTrip.BookingDate = null; rowTrip.TripStartDate = tripSD.Value.ToString(); rowTrip.TripEndDate = tripED.Value.ToString(); rowTrip.TotalPrice = Convert.ToDecimal(tbPrice.Text); rowTrip.Origin = tbOrigin.Text; rowTrip.Destination = tbDestination.Text; rowTrip.TripInsurance = insurance; td.Trip.Rows.Add(rowTrip); tdTrip.Update(td.Trip); MessageBox.Show("Query Successful!!!"); }
/// <summary> /// btnBookdeal method executes the code which will grab values /// from the prebooked deals and grabs the new information /// and sends it to the trip table /// </summary> private void btnBookdeal_Click(object sender, EventArgs e) { var dateAndTime = DateTime.Now.ToString("yyyy-MM-dd"); int tripId = ShowDeals.tripID; string tsd = ShowDeals.tsd; string ted = ShowDeals.ted; string origin = ShowDeals.tOrigin; string destination = ShowDeals.destination; decimal price = ShowDeals.price; string bookingDate = dateAndTime; System.Diagnostics.Debug.WriteLine("Trip ID: " + tripId); TripDataset td = new TripDataset(); TripDataSet2 td2 = new TripDataSet2(); TripDatasetTableAdapters.CustomerTableAdapter tdCustomer = new TripDatasetTableAdapters.CustomerTableAdapter(); TripDatasetTableAdapters.TripBookedTableAdapter tdBooked = new TripDatasetTableAdapters.TripBookedTableAdapter(); TripDatasetTableAdapters.TripTableAdapter tdTrip = new TripDatasetTableAdapters.TripTableAdapter(); TripDataset.TripBookedRow rowBook = td.TripBooked.NewTripBookedRow(); TripDataset.CustomerRow rowCust = td.Customer.NewCustomerRow(); //row[0]["BookingDate"] = bookingDate.ToString(); tdTrip.Update(td.Trip); rowCust.CName = tbName.Text; rowCust.CEmail = tbEmail.Text; rowCust.CPhone = Convert.ToDecimal(tbPhone.Text); td.Customer.Rows.Add(rowCust); tdCustomer.Update(td.Customer); DataRow[] dr = td.Tables[2].Select("CEmail=" + "'" + tbEmail.Text + "'"); int customerId = Convert.ToInt32(dr[0]["CustomerId"]); /// <summary> /// After inserting all the data into the dataset rows of different table /// we grab the ids from those tables and insdert into a /// new table /// The status which is pending is changed to approve and the gridview /// is updates in the finally block /// </summary> rowBook.TripID = tripId; rowBook.CustomerID = customerId; rowBook.HotelID = cbHotel.SelectedIndex; if (Convert.ToInt32(cbRooms.SelectedValue) == 0) { rowBook.RoomsBooked = 1; } else { rowBook.RoomsBooked = Convert.ToInt32(cbRooms.SelectedValue); } rowBook.Status = "Pending"; rowBook.CheckInDate = tsd; rowBook.CheckOutDate = ted; td.TripBooked.Rows.Add(rowBook); tdBooked.Update(td.TripBooked); System.Diagnostics.Debug.WriteLine("Rooms: " + cbRooms.SelectedValue); MessageBox.Show("Deal Made!!!"); this.Hide(); Form2 form2 = new Form2(); form2.Show(); }