private void btnCreate_Click(object sender, EventArgs e) { if (cbCountries.SelectedItem == null || string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtRePassword.Text)) { MessageBox.Show("Please ensure the field(s) are not empty!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtRePassword.Text != txtRePassword.Text) { MessageBox.Show("Passwords do not match!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtUserID.Text.Length < 8) { MessageBox.Show("User ID must be at least 8 characters long!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Regex.IsMatch(txtUserID.Text, "[a-zA-Z]+[0-9]+")) { MessageBox.Show("User ID must contain 1 upper and lower case with at least 1 numeric!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (var context = new Session3Entities()) { var checkID = (from x in context.Users where x.userId == txtUserID.Text select x).FirstOrDefault(); if (checkID != null) { MessageBox.Show("User ID is not available! Please use another User ID", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var newUser = new User() { userId = txtUserID.Text, countryName = cbCountries.SelectedItem.ToString(), passwd = txtRePassword.Text, userTypeIdFK = 2 }; context.Users.Add(newUser); context.SaveChanges(); MessageBox.Show("Account created successfully!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new Login()).ShowDialog(); Close(); } } } }
private void btnBook_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var getHotelID = (from x in context.Hotels where x.hotelName == _hotel select x.hotelId).FirstOrDefault(); var newBooking = new Hotel_Booking() { userIdFK = _user.userId, hotelIdFK = getHotelID, numDoubleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value), numSingleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value) }; context.Hotel_Booking.Add(newBooking); context.SaveChanges(); MessageBox.Show("Booking successful!"); Close(); } }
private void btnConfirm_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { if (rbtn22July.Checked) { if (dataGridView1.CurrentCell.Style.BackColor == Color.Black) { MessageBox.Show("Timing is not available for selected date!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var getTiming = dataGridView1.CurrentCell.Value.ToString(); var getArrivalDetails = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); if (getArrivalDetails == null) { var newArrival = new Arrival() { arrivalDate = DateTime.Parse("22/07/2020"), arrivalTime = getTiming, number19seat = Int32.Parse(lbl19Seater.Text), number42seat = Int32.Parse(lbl42Seater.Text), numberCars = Int32.Parse(lblCar.Text), userIdFK = _user.userId, numberHead = Convert.ToInt32(nudHead.Value), numberDelegate = Convert.ToInt32(nudDelegates.Value), numberCompetitors = Convert.ToInt32(nudCompetitors.Value) }; context.Arrivals.Add(newArrival); context.SaveChanges(); MessageBox.Show("Arrival confirmed!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new CountryMain(_user)).ShowDialog(); Close(); } else { getArrivalDetails.arrivalDate = DateTime.Parse("22/07/2020"); getArrivalDetails.arrivalTime = getTiming; getArrivalDetails.number19seat = Int32.Parse(lbl19Seater.Text); getArrivalDetails.number42seat = Int32.Parse(lbl42Seater.Text); getArrivalDetails.numberCars = Int32.Parse(lblCar.Text); getArrivalDetails.numberHead = Convert.ToInt32(nudHead.Value); getArrivalDetails.numberDelegate = Convert.ToInt32(nudDelegates.Value); getArrivalDetails.numberCompetitors = Convert.ToInt32(nudCompetitors.Value); context.SaveChanges(); MessageBox.Show("Arrival updated!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new CountryMain(_user)).ShowDialog(); Close(); } } } else if (rbtn23July.Checked) { if (dataGridView1.CurrentCell.Style.BackColor == Color.Black) { MessageBox.Show("Timing is not available for selected date!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var getTiming = dataGridView1.CurrentCell.Value.ToString(); var getArrivalDetails = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); if (getArrivalDetails == null) { var newArrival = new Arrival() { arrivalDate = DateTime.Parse("23/07/2020"), arrivalTime = getTiming, number19seat = Int32.Parse(lbl19Seater.Text), number42seat = Int32.Parse(lbl42Seater.Text), numberCars = Int32.Parse(lblCar.Text), userIdFK = _user.userId, numberHead = Convert.ToInt32(nudHead.Value), numberDelegate = Convert.ToInt32(nudDelegates.Value), numberCompetitors = Convert.ToInt32(nudCompetitors.Value) }; context.Arrivals.Add(newArrival); context.SaveChanges(); MessageBox.Show("Arrival confirmed!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new CountryMain(_user)).ShowDialog(); Close(); } else { getArrivalDetails.arrivalDate = DateTime.Parse("23/07/2020"); getArrivalDetails.arrivalTime = getTiming; getArrivalDetails.number19seat = Int32.Parse(lbl19Seater.Text); getArrivalDetails.number42seat = Int32.Parse(lbl42Seater.Text); getArrivalDetails.numberCars = Int32.Parse(lblCar.Text); getArrivalDetails.numberHead = Convert.ToInt32(nudHead.Value); getArrivalDetails.numberDelegate = Convert.ToInt32(nudDelegates.Value); getArrivalDetails.numberCompetitors = Convert.ToInt32(nudCompetitors.Value); context.SaveChanges(); MessageBox.Show("Arrival updated!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new CountryMain(_user)).ShowDialog(); Close(); } } } } }