private void ConfirmCancelBookingButton_Click(object sender, EventArgs e) { List <DataGridViewRow> cancelledBookings = new List <DataGridViewRow>(); foreach (DataGridViewRow row in BookedDataGridView.Rows) //foreach (Transaction t in tList) { if ((string)row.Cells["ToCancel"].Value == "Cancel") { int transId = Int32.Parse(row.Cells["TransactionID"].Value.ToString()); Transaction t = context.Transactions.First(x => x.TransactionID == transId); string slotNumber = t.Slot; // Availability = 1 is place is available UpdateAvailabilityTable(t.FacilityID, slotNumber, 1); //context.Transactions.Remove(t); //t.BookingStatus = "Cancelled"; context.SaveChanges(); //tList.Remove(t); doesnot work. seems to interfer with BookedDataGridView.Rows cancelledBookings.Add(row); } } foreach (DataGridViewRow row in cancelledBookings) { BookedDataGridView.Rows.Remove(row); } }
private void ConfirmBooking(Transaction t) { //string to store the input string bookingDetails = ""; //Get Booking details foreach (PropertyInfo propertyInfo in t.GetType().GetProperties()) { if (propertyInfo.Name.ToString() != "Facility" && propertyInfo.Name.ToString() != "Member") { bookingDetails += propertyInfo.Name.ToString() + " : " + propertyInfo.GetValue(t, null) + Environment.NewLine; } } //Confirm Booking DialogResult dialogResult = MessageBox.Show(bookingDetails, "Confirm Booking", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { //Update Availability Table---Availability = 1 is place is available (inherit from templateform) UpdateAvailabilityTable(t.FacilityID, t.Slot, 0); //Save Changes in database context.Transactions.Add(t); context.SaveChanges(); } }
private void DeleteButton_Click(object sender, EventArgs e) { try { SA46Team05BESNETProjectEntities context = new SA46Team05BESNETProjectEntities(); Member M = context.Members.Where(x => x.NRIC == NRICTextBox.Text).First(); context.Members.Remove(M); context.SaveChanges(); } catch { MessageBox.Show("Error!\nPlease try again."); } }
private void UpdateAvailiabilityButton_Click(object sender, EventArgs e) { string s = FacilityIDComboBox.Text; Availability a = context.Availabilities.First(x => x.FacilityID == s); a.Slot1 = (int)FacilitiesDataGridView.Rows[0].Cells["Availability"].Value; a.Slot2 = (int)FacilitiesDataGridView.Rows[1].Cells["Availability"].Value; a.Slot3 = (int)FacilitiesDataGridView.Rows[2].Cells["Availability"].Value; a.Slot4 = (int)FacilitiesDataGridView.Rows[3].Cells["Availability"].Value; a.Slot5 = (int)FacilitiesDataGridView.Rows[4].Cells["Availability"].Value; a.Slot6 = (int)FacilitiesDataGridView.Rows[5].Cells["Availability"].Value; a.Slot7 = (int)FacilitiesDataGridView.Rows[6].Cells["Availability"].Value; a.Slot8 = (int)FacilitiesDataGridView.Rows[7].Cells["Availability"].Value; context.SaveChanges(); }
private void UpdateButton_Click(object sender, EventArgs e) { try { SA46Team05BESNETProjectEntities context = new SA46Team05BESNETProjectEntities(); Member M = context.Members.Where(X => X.NRIC == NRICTextBox.Text).First(); M.MemberName = MemberNameTextBox.Text; M.Gender = GenderComboBox.Text; M.Age = Convert.ToInt32(AgeTextBox.Text); M.Phone = PhoneNumberTextBox.Text; context.SaveChanges(); } catch { MessageBox.Show("Error!\nPlease try again."); } }
private void ConfirmCancelBookingButton_Click(object sender, EventArgs e) { List <DataGridViewRow> cancelledBookings = new List <DataGridViewRow>(); foreach (DataGridViewRow row in BookedDataGridView.Rows) //foreach (Transaction t in tList) { if ((string)row.Cells["ToCancel"].Value == "Cancel") { int transId = Int32.Parse(row.Cells["TransactionID"].Value.ToString()); Transaction t = context.Transactions.First(x => x.TransactionID == transId); string slotNumber = t.Slot; switch (slotNumber) { case "Slot1": t.Facility.Availability.Slot1 = 1; break; case "Slot2": t.Facility.Availability.Slot2 = 1; break; case "Slot3": t.Facility.Availability.Slot3 = 1; break; case "Slot4": t.Facility.Availability.Slot4 = 1; break; case "Slot5": t.Facility.Availability.Slot5 = 1; break; case "Slot6": t.Facility.Availability.Slot6 = 1; break; case "Slot7": t.Facility.Availability.Slot7 = 1; break; case "Slot8": t.Facility.Availability.Slot8 = 1; break; } //context.Transactions.Remove(t); //t.BookingStatus = "Cancelled"; context.SaveChanges(); //tList.Remove(t); doesnot work. seems to interfer with BookedDataGridView.Rows cancelledBookings.Add(row); } } foreach (DataGridViewRow row in cancelledBookings) { BookedDataGridView.Rows.Remove(row); } }
private void BookButton_Click(object sender, EventArgs e) { //check for empty fields and valid member entries bool fieldsEmpty = false; bool correctMember = false; List <Member> mCorrect = context.Members.Where(x => x.NRIC != String.Empty).ToList(); foreach (Control g in this.Controls) { if (g is GroupBox) { foreach (Control c in g.Controls) { if (c is TextBox && c.Text.Equals(String.Empty)) { fieldsEmpty = true; } if (c is ComboBox && c.Text.Equals(String.Empty)) { fieldsEmpty = true; } } } } foreach (Member m in mCorrect) { if (m.NRIC.ToString() == MemberFINTextBox.Text && m.MemberName.ToString() == MemberNameTextBox.Text) { correctMember = true; } } //Add entry into Transactions Table if all fields are filled if (!fieldsEmpty && correctMember == true) { //string to store the input string bookingDetails = ""; //Get last Transaction ID int lastID = int.Parse(context.Transactions.OrderByDescending(x => x.TransactionID).Select(y => y.TransactionID).First().ToString()); //Create new Transaction Transaction t = new Transaction(); t.TransactionID = lastID + 1; t.NRIC = MemberFINTextBox.Text; t.FacilityID = FacilityIDComboBox.Text; t.BookingDate = DateTime.Today.AddDays(1); t.Timeslot = TimeSlotComboBox.Text; Facility f = context.Facilities.Where(x => x.FacilityID == t.FacilityID).FirstOrDefault(); t.Price = f.Price; //Get SlotNumber from the selected time option in combobox switch (TimeSlotComboBox.Text) { case "09:00-10:00": t.Slot = "Slot1"; break; case "10:00-11:00": t.Slot = "Slot2"; break; case "11:00-12:00": t.Slot = "Slot3"; break; case "12:00-13:00": t.Slot = "Slot4"; break; case "13:00-14:00": t.Slot = "Slot5"; break; case "14:00-15:00": t.Slot = "Slot6"; break; case "15:00-16:00": t.Slot = "Slot7"; break; case "16:00-17:00": t.Slot = "Slot8"; break; } foreach (PropertyInfo propertyInfo in t.GetType().GetProperties()) { if (propertyInfo.Name.ToString() != "Facility" && propertyInfo.Name.ToString() != "Member") { bookingDetails += propertyInfo.Name.ToString() + " : " + propertyInfo.GetValue(t, null) + Environment.NewLine; } } DialogResult dialogResult = MessageBox.Show(bookingDetails, "Confirm Booking", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { //Update Availability Table---Availability = 1 is place is available UpdateAvailabilityTable(t.FacilityID, t.Slot, 0); //Save Changes in database context.Transactions.Add(t); context.SaveChanges(); } } else if (fieldsEmpty && correctMember == true) { //If there are empty fields, remind user MessageBox.Show("Please fill in all fields before booking"); } else { MessageBox.Show("Please key in correct member details"); } }