private void ShowExistingBookingDetail()
 {
     btnCancel.Visible = true;
     btnBook.Visible   = false;
     btnPrint.Visible  = true;
     txtMemID.ReadOnly = true;
     lbSelSlotsFacility.Items.Clear();
     lbSelSlotsSF.Items.Clear();
     lbSelSlotsTiming.Items.Clear();
     trandetailid              = ucBooking.redButtonTransID;
     transid                   = cxt.TransactionDetails.First(x => x.transactiondetailid == trandetailid).transactionid;
     removetd                  = new TransactionDetail();
     removetd                  = cxt.TransactionDetails.First(x => x.transactiondetailid == trandetailid);
     dtpDate.Value             = ucBooking.getForDate();
     rt                        = new Transaction();
     rt                        = cxt.Transactions.First(x => x.transactionid == transid);
     txtMemID.Text             = rt.memberid.ToString();
     txtMemIDdisplay.Text      = rt.Member.name.ToString();
     dtpBookingDate.Value      = rt.systemtime;
     txtRemarks.Text           = rt.remark;
     txtTotalPrice.Text        = rt.total.ToString();
     txtFacilityID.Text        = removetd.facilityid.ToString();
     txtFacilityIDdisplay.Text = removetd.Facility.facilityname.ToString();
     txtRates.Text             = removetd.Facility.Rate.ratepertimeslot.ToString();
     lbSelSlotsFacility.Items.Add(removetd.Facility.facilityname);
     lbSelSlotsSF.Items.Add(removetd.SubFacility.subfacilityname);
     lbSelSlotsTiming.Items.Add(removetd.Timeslot.timeslot);
 }
 private void btnBook_Click(object sender, EventArgs e)
 {
     try
     {
         Transaction t = new Transaction();
         t.memberid   = Convert.ToInt32(txtMemID.Text);
         t.remark     = txtRemarks.Text;
         t.systemtime = DateTime.Now;
         t.total      = price;
         t.status     = "Confirmed";
         SportsFacilitiesEntities ctx = new SportsFacilitiesEntities();
         ctx.Transactions.Add(t);
         ctx.SaveChanges();
         int id = t.transactionid;
         TransactionDetail td;
         int subfacilityid;
         int timeslotid;
         foreach (BookingDetails bd in ucBooking.getSelectedSlots())
         {
             subfacilityid    = ctx.SubFacilities.First(x => x.facilityid == facilityID && x.subfacilityname == bd.subFacilityBooked).subfacilityid;
             timeslotid       = bd.slotBooked;
             td               = new TransactionDetail();
             td.transactionid = id;
             td.facilityid    = facilityID;
             td.timeslotid    = timeslotid;
             td.date          = dtpDate.Value;
             td.subfacilityid = subfacilityid;
             ctx.TransactionDetails.Add(td);
         }
         ctx.SaveChanges();
         MessageBox.Show("Booking Completed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
         DialogResult result = MessageBox.Show("Do you want to print the booking invoice?", "Print", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
         if (result == DialogResult.OK)
         {
             rptTransactionid = id;
             frmInvoiceReport frmIR = new frmInvoiceReport();
             frmIR.ShowDialog();
         }
     }
     catch
     {
         MessageBox.Show("You have encountered an error. Please Try Again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     this.Close();
 }