/// <summary> /// Triggered when Update button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (Int32.Parse(txtDelegates.Text) < 0 || Int32.Parse(txtCompetitors.Text) < 0) { MessageBox.Show("Number of competitors or delegates cannot be less than 0!", "Invalid number of attendees", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var dl = MessageBox.Show("Are you sure you want to update your info and bookings?", "Update details", MessageBoxButtons.YesNo, MessageBoxIcon.Question); ///If user click Yes response in MessageBox, run update to DB if (dl == DialogResult.Yes) { var getComparisonSingle = Convert.ToInt32(dataGridView1.Rows[0].Cells[4].Value) - Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value); var getComparisonDouble = Convert.ToInt32(dataGridView1.Rows[1].Cells[4].Value) - Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value); using (var context = new Session3Entities()) { var getDetails = (from x in context.Hotel_Booking where x.userIdFK == _userID join y in context.Hotels on x.hotelIdFK equals y.hotelId join z in context.Arrivals on x.userIdFK equals z.userIdFK select new { x, y, z }).First(); getDetails.x.numSingleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[0].Cells[4].Value); getDetails.x.numDoubleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[1].Cells[4].Value); getDetails.z.numberHead = Convert.ToInt32(numHeadOfDelegation.Value); getDetails.z.numberDelegate = Int32.Parse(txtDelegates.Text); getDetails.z.numberCompetitors = Int32.Parse(txtCompetitors.Text); if (getComparisonSingle < 0) { getDetails.y.numSingleRoomsBooked += getComparisonSingle; context.SaveChanges(); } else { getDetails.y.numSingleRoomsBooked -= getComparisonSingle; context.SaveChanges(); } if (getComparisonDouble < 0) { getDetails.y.numDoubleRoomsBooked += getComparisonDouble; context.SaveChanges(); } else { getDetails.y.numDoubleRoomsBooked -= getComparisonDouble; context.SaveChanges(); } context.SaveChanges(); dataGridView1.Rows.Clear(); Update_Load(null, null); } } } }
private void Done_button_Click(object sender, EventArgs e) { using (var db = new Session3Entities()) { if (!(dgvlist[0].NewNoOfRoomsRequired > dgvlist[0].AvailableNoOfRooms)) { if (!(dgvlist[1].NewNoOfRoomsRequired > dgvlist[1].AvailableNoOfRooms)) { if (((dgvlist[1].NewNoOfRoomsRequired * 2) + dgvlist[0].NewNoOfRoomsRequired) >= delegates_updown.Value + competitors_updown.Value) { var arrivals = (from a in db.Arrivals where a.userIdFK == LoggedIn.userId select a).First(); var booking = (from b in db.Hotel_Booking where b.userIdFK == LoggedIn.userId select b).First(); arrivals.numberCars = (int)delegates_updown.Value; int numSmallBus = 0; int numBigBus = 0; decimal numPeople = delegates_updown.Value + competitors_updown.Value; if (numPeople > 38) { decimal bigbusraw = numPeople / 42; numBigBus = (int)Math.Floor(bigbusraw); numPeople -= (numBigBus * 42); decimal smallbusraw = numPeople / 19; numSmallBus = (int)Math.Ceiling(smallbusraw); } else { //if below 38, only calculate number of 19 seaters numSmallBus = (int)Math.Ceiling(numPeople / 19); } arrivals.number42seat = numBigBus; arrivals.number19seat = numSmallBus; arrivals.numberCompetitors = (int)competitors_updown.Value; arrivals.numberHead = (int)head_updown.Value; arrivals.numberDelegate = (int)delegates_updown.Value; booking.numDoubleRoomsRequired = dgvlist[1].NewNoOfRoomsRequired; booking.numSingleRoomsRequired = dgvlist[0].NewNoOfRoomsRequired; db.SaveChanges(); } else { MessageBox.Show("Not Enough Rooms for arrivals"); } } else { MessageBox.Show("Error, more rooms requested than available"); } } else { MessageBox.Show("Error, more rooms requested than available"); } } }
/// <summary> /// Triggered when the Book button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bookBtn_Click(object sender, EventArgs e) { //Check if the two rows have any invalid entries like booking more than available rooms availble in the hotel if ((Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value) > Convert.ToInt32(dataGridView1.Rows[0].Cells[2].Value)) || (Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value) > Convert.ToInt32(dataGridView1.Rows[1].Cells[2].Value))) { MessageBox.Show("Unable to book more rooms than available rooms!", "Insufficient rooms", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (var context = new Session3Entities()) { var checkBooking = (from x in context.Hotel_Booking where x.userIdFK == _userID select x).ToList(); //If any instance of booking of hotel of the country exist, delete the previous booking details to prevent double booking foreach (var item in checkBooking) { context.Hotel_Booking.Remove(item); context.SaveChanges(); } context.Hotel_Booking.Add(new Hotel_Booking() { hotelIdFK = _hotelID, numSingleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value), userIdFK = _userID, numDoubleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value) }); var getUpdate = (from x in context.Hotels where x.hotelId == _hotelID select x).First(); getUpdate.numDoubleRoomsBooked += Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value); getUpdate.numSingleRoomsBooked += Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value); context.SaveChanges(); this.Close(); } } }
/// <summary> /// Triggered when the Confirm button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void confirmBtn_Click(object sender, EventArgs e) { //Check if there is even a dell selected for timing or if the cell backcolor is black. If so, prompts error message if (dataGridView1.CurrentCell == null || dataGridView1.CurrentCell.Style.BackColor == Color.Black) { MessageBox.Show("Please select a timing that is not blacked out!"); } else { using (var context = new Session3Entities()) { var checkIfBookingExist = (from x in context.Arrivals where x.userIdFK == _userID select x).FirstOrDefault(); //If booking does not exist in DB, add details to DB if (checkIfBookingExist == null) { //If 22nd July is checked, then add date as 22 July 2020 if (twentysecondBtn.Checked) { context.Arrivals.Add(new Arrival() { arrivalDate = DateTime.Parse("22 July"), arrivalTime = dataGridView1.CurrentCell.Value.ToString(), numberHead = Convert.ToInt32(headBox.Value), userIdFK = _userID, numberDelegate = Int32.Parse(delegateBox.Text), numberCompetitors = Int32.Parse(competitorBox.Text), number19seat = Int32.Parse(smallBusLbl.Text), numberCars = Int32.Parse(carLbl.Text), number42seat = Int32.Parse(bigBusLbl.Text) }); context.SaveChanges(); } //If 23rd July is checked, then add date as 23 July 2020 else { context.Arrivals.Add(new Arrival() { arrivalDate = DateTime.Parse("23 July"), arrivalTime = dataGridView1.CurrentCell.Value.ToString(), numberHead = Convert.ToInt32(headBox.Value), userIdFK = _userID, numberDelegate = Int32.Parse(delegateBox.Text), numberCompetitors = Int32.Parse(competitorBox.Text), number19seat = Int32.Parse(smallBusLbl.Text), numberCars = Int32.Parse(carLbl.Text), number42seat = Int32.Parse(bigBusLbl.Text) }); context.SaveChanges(); } } //Else, if booking already exist in DB, update details to DB else { //If 22nd July is checked, then update date as 22 July 2020 if (twentysecondBtn.Checked) { checkIfBookingExist.arrivalDate = DateTime.Parse("22 July"); checkIfBookingExist.arrivalTime = dataGridView1.CurrentCell.Value.ToString(); checkIfBookingExist.numberHead = Convert.ToInt32(headBox.Value); checkIfBookingExist.numberDelegate = Int32.Parse(delegateBox.Text); checkIfBookingExist.numberCompetitors = Int32.Parse(competitorBox.Text); checkIfBookingExist.number19seat = Int32.Parse(smallBusLbl.Text); checkIfBookingExist.numberCars = Int32.Parse(carLbl.Text); checkIfBookingExist.number42seat = Int32.Parse(bigBusLbl.Text); context.SaveChanges(); } //If 23rd July is checked, then update date as 23 July 2020 else { checkIfBookingExist.arrivalDate = DateTime.Parse("23 July"); checkIfBookingExist.arrivalTime = dataGridView1.CurrentCell.Value.ToString(); checkIfBookingExist.numberHead = Convert.ToInt32(headBox.Value); checkIfBookingExist.numberDelegate = Int32.Parse(delegateBox.Text); checkIfBookingExist.numberCompetitors = Int32.Parse(competitorBox.Text); checkIfBookingExist.number19seat = Int32.Parse(smallBusLbl.Text); checkIfBookingExist.numberCars = Int32.Parse(carLbl.Text); checkIfBookingExist.number42seat = Int32.Parse(bigBusLbl.Text); context.SaveChanges(); } } } this.Hide(); (new RepresentativeMain(_userID)).ShowDialog(); this.Close(); } }
private void book_Click(object sender, EventArgs e) { using (var db = new Session3Entities()) { var q = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); //If user first time creating arrivals if (q == null) { Arrival arrival = new Arrival(); if (jul22.Checked == true) { arrival.arrivalDate = DateTime.Parse("22 July 2020"); } else if (jul23.Checked == true) { arrival.arrivalDate = DateTime.Parse("23 July 2020"); } else { MessageBox.Show("Choose Date!"); return; } arrival.userIdFK = users.userId; if (time == null) { MessageBox.Show("You have chosen an invalid timing!"); return; } arrival.arrivalTime = time; if (numericUpDown1.Value > 1) { MessageBox.Show("Invalid Head of Deligates!"); return; } arrival.numberHead = (int)numericUpDown1.Value; try { arrival.numberDelegate = int.Parse(Dels.Text); arrival.numberCompetitors = int.Parse(Comps.Text); } catch { MessageBox.Show("Invalid Deligates or competitors"); return; } arrival.numberCars = int.Parse(carHeadDel.Text); arrival.number19seat = int.Parse(seat19.Text); arrival.number42seat = int.Parse(seat42.Text); db.Arrivals.Add(arrival); try { db.SaveChanges(); MessageBox.Show("Success!"); this.Hide(); CountryRepresentativeMainMenu countryRepresentativeMainMenu = new CountryRepresentativeMainMenu(users); countryRepresentativeMainMenu.Show(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } //User has created and come back to change else { if (jul22.Checked == true) { q.arrivalDate = DateTime.Parse("22 July 2020"); } else if (jul23.Checked == true) { q.arrivalDate = DateTime.Parse("23 July 2020"); } else { MessageBox.Show("Choose Date!"); return; } if (time == null) { MessageBox.Show("You have chosen an invalid timing!"); return; } q.arrivalTime = time; if (numericUpDown1.Value > 1) { MessageBox.Show("Invalid Head of Deligates!"); return; } q.numberHead = (int)numericUpDown1.Value; try { q.numberDelegate = int.Parse(Dels.Text); q.numberCompetitors = int.Parse(Comps.Text); } catch { MessageBox.Show("Invalid Deligates or competitors"); return; } q.numberCars = int.Parse(carHeadDel.Text); q.number19seat = int.Parse(seat19.Text); q.number42seat = int.Parse(seat42.Text); try { db.SaveChanges(); MessageBox.Show("Success!"); this.Hide(); CountryRepresentativeMainMenu countryRepresentativeMainMenu = new CountryRepresentativeMainMenu(users); countryRepresentativeMainMenu.Show(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } } }
private void button2_Click(object sender, EventArgs e) { using (var db = new Session3Entities()) { User user = new User(); var val = UserId.Text; //The user ID should consist of a minimum of 8 characters. if (val.Length < 8) { MessageBox.Show("Invalid User ID! User ID should consist of a minimum of 8 characters"); return; } else { var q = db.Users.Where(x => x.userId == val).FirstOrDefault(); if (q == null) { if (val.Any(char.IsSymbol)) { MessageBox.Show("The ID should only include Upper case letters, Lower case letters and numbers 0 – 9."); return; } else { user.userId = val; } } else { MessageBox.Show("User ID Taken!"); return; } } var val2 = Country.Text; user.countryName = val2; if (Pass.Text != PassC.Text) { MessageBox.Show("Password Not match!"); return; } else { user.passwd = Pass.Text; } user.userTypeIdFK = 2; db.Users.Add(user); try { db.SaveChanges(); MessageBox.Show("Success!"); this.Hide(); Form1 form = new Form1(); form.Show(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } }
/// <summary> /// When the create button is clicked, this method is called and executed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createBtn_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var checkForSame = (from x in context.Users where x.userId == userIDBox.Text select x).FirstOrDefault(); //RegEx string pattern to check for 1 upper, 1 lower and at least 1 numeric Regex regex = new Regex(@"[A-Z]{1,}[a-z]{1,}[0-9]{1,}"); if (!regex.Match(userIDBox.Text).Success) { MessageBox.Show("User ID must be at least 8 characters long, containing 1 upper and lower case with at least 1 number!", "Invalid User ID", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Check if User ID length is less than 8 else if (userIDBox.Text.Length < 8) { MessageBox.Show("User ID must be at least 8 characters long!", "Invalid User ID", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Check if User ID has already been used in DB else if (checkForSame != null) { MessageBox.Show("User ID has been used!", "Invalid User ID", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Checks if password is empty else if (passwordBox.Text.Trim() == "") { MessageBox.Show("Password is empty!!", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Checks if password field and Re-enter password field matches else if (passwordBox.Text != rePasswordBox.Text) { MessageBox.Show("Passwords do not match!", "Mismatched Passwords", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var dl = MessageBox.Show("Are you sure you want to create an account?", "Create Account", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); //If user clicks yes, adds new User to DB if (DialogResult.Yes == dl) { context.Users.Add(new User() { countryName = countryBox.SelectedItem.ToString(), passwd = passwordBox.Text, userId = userIDBox.Text, userTypeIdFK = 2 }); context.SaveChanges(); this.Hide(); (new Login()).ShowDialog(); this.Hide(); } } } }
private void button1_Click(object sender, EventArgs e) { string selectedTime = null; for (int i = 0; i < dataGridView1.Columns.Count; i++) { if (dataGridView1.Rows[0].Cells[i].Style.BackColor == Color.Yellow) { switch (i) { case 0: selectedTime = "9am"; break; case 1: selectedTime = "10am"; break; case 2: selectedTime = "11am"; break; case 3: selectedTime = "12pm"; break; case 4: selectedTime = "1pm"; break; case 5: selectedTime = "2pm"; break; case 6: selectedTime = "3pm"; break; case 7: selectedTime = "4pm"; break; default: break; } } } if (selectedTime != null) { if (delegates_updown.Value != 0) { if (competitors_updown.Value != 0) { using (var db = new Session3Entities()) { Arrival an = new Arrival() { arrivalDate = jul22.Checked ? DateTime.Parse("Jul 22 2020") : DateTime.Parse("Jul 23 2020"), number19seat = int.Parse(bigbus_label.Text), number42seat = int.Parse(smallbus_label.Text), numberCars = (int)head_updown.Value, numberCompetitors = (int)competitors_updown.Value, numberDelegate = (int)delegates_updown.Value, userIdFK = LoggedIn.userId, arrivalTime = selectedTime, numberHead = (int)head_updown.Value }; db.Arrivals.Add(an); db.SaveChanges(); } } else { MessageBox.Show("Number of competitors must be > 0!!"); } } else { MessageBox.Show("Number of delegates must be > 0!!"); } } else { MessageBox.Show("Please Select a Valid Time!"); } }
private void update_Click(object sender, EventArgs e) { if (dataGridView1.Rows[0].Cells["Rooms Required"].Value != null && dataGridView1.Rows[1].Cells["Rooms Required"].Value != null) { var singleR = dataGridView1.Rows[0].Cells["Rooms Required"].Value.ToString(); var doubleR = dataGridView1.Rows[1].Cells["Rooms Required"].Value.ToString(); using (var db = new Session3Entities()) { var q2 = db.Hotel_Booking.Where(x => x.userIdFK == users.userId).FirstOrDefault(); oldD = q2.numDoubleRoomsRequired; oldS = q2.numSingleRoomsRequired; if (int.Parse(singleR) <= q2.Hotel.numSingleRoomsTotal - q2.Hotel.numSingleRoomsBooked) { q2.numSingleRoomsRequired = int.Parse(singleR); q2.Hotel.numSingleRoomsBooked -= oldS; q2.Hotel.numSingleRoomsBooked += int.Parse(singleR); } else { MessageBox.Show("Invalid Amount of Single Rooms!"); return; } if (int.Parse(doubleR) <= q2.Hotel.numDoubleRoomsTotal - q2.Hotel.numDoubleRoomsBooked) { q2.numDoubleRoomsRequired = int.Parse(doubleR); q2.Hotel.numDoubleRoomsBooked -= oldD; q2.Hotel.numDoubleRoomsBooked += int.Parse(doubleR); } else { MessageBox.Show("Invalid Amount of Double Rooms!"); return; } var q = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); if (HOD.Value > 1) { MessageBox.Show("Invalid Head of Delegate"); return; } q.numberHead = (int)HOD.Value; try { q.numberDelegate = int.Parse(Dels.Text); q.numberCompetitors = int.Parse(Comps.Text); } catch { MessageBox.Show("Invalid Delegates or Competitors"); return; } try { db.SaveChanges(); MessageBox.Show("Success!"); this.Hide(); CountryRepresentativeMainMenu countryRepresentativeMainMenu = new CountryRepresentativeMainMenu(users); countryRepresentativeMainMenu.Show(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } } }
private void book_Click(object sender, EventArgs e) { if (dataGridView1.Rows[0].Cells["Rooms Required"].Value != null && dataGridView1.Rows[1].Cells["Rooms Required"].Value != null) { var singleR = dataGridView1.Rows[0].Cells["Rooms Required"].Value.ToString(); var doubleR = dataGridView1.Rows[1].Cells["Rooms Required"].Value.ToString(); using (var db = new Session3Entities()) { var q2 = db.Hotel_Booking.Where(x => x.userIdFK == users.userId).FirstOrDefault(); oldD = q2.numDoubleRoomsRequired; oldS = q2.numSingleRoomsRequired; if (q2 == null) { var q = db.Hotels.Where(x => x.hotelId == hotels).FirstOrDefault(); Hotel_Booking hotel_Booking = new Hotel_Booking(); hotel_Booking.hotelIdFK = hotels; hotel_Booking.userIdFK = users.userId; if (int.Parse(singleR) <= q.numSingleRoomsTotal - q.numSingleRoomsBooked) { hotel_Booking.numSingleRoomsRequired = int.Parse(singleR); q.numSingleRoomsBooked -= oldS; q.numSingleRoomsBooked += int.Parse(singleR); } else { MessageBox.Show("Invalid Amount of Single Rooms!"); return; } if (int.Parse(doubleR) <= q.numDoubleRoomsTotal - q.numDoubleRoomsBooked) { hotel_Booking.numDoubleRoomsRequired = int.Parse(doubleR); q.numDoubleRoomsBooked -= oldD; q.numDoubleRoomsBooked += int.Parse(doubleR); } else { MessageBox.Show("Invalid Amount of Double Rooms!"); return; } db.Hotel_Booking.Add(hotel_Booking); try { db.SaveChanges(); MessageBox.Show("Success!"); this.Hide(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } else { if (int.Parse(singleR) <= q2.Hotel.numSingleRoomsTotal - q2.Hotel.numSingleRoomsBooked) { q2.numSingleRoomsRequired = int.Parse(singleR); q2.Hotel.numSingleRoomsBooked += int.Parse(singleR); } else { MessageBox.Show("Invalid Amount of Single Rooms!"); return; } if (int.Parse(doubleR) <= q2.Hotel.numDoubleRoomsTotal - q2.Hotel.numDoubleRoomsBooked) { q2.numDoubleRoomsRequired = int.Parse(doubleR); q2.Hotel.numDoubleRoomsBooked += int.Parse(doubleR); } else { MessageBox.Show("Invalid Amount of Double Rooms!"); return; } try { db.SaveChanges(); MessageBox.Show("Success!"); this.Hide(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } } } }