private void btnHotelBooking_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var getHotel = (from x in context.Hotel_Booking where x.userIdFK == _user.userId select x).FirstOrDefault(); var getArrival = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); if (getHotel != null) { MessageBox.Show("Hotel Booking has already been confirmed!", "Hotel Booking", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (getArrival == null) { MessageBox.Show("Please confirm your arrival details first!", "Hotel Booking", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Hide(); (new HotelMap(_user)).ShowDialog(); Close(); } } }
private void LoadComboBox() { cbCountry.Items.Clear(); var countryList = new List <string>() { "Brunei", "Cambodia", "Indonesia", "Laos", "Malaysia", "Myanmar", "Philippines", "Singapore", "Thailand", "Vietnam" }; using (var context = new Session3Entities()) { var getRegisteredCountries = (from x in context.Users where x.userTypeIdFK == 2 select x.countryName).Distinct().ToList(); foreach (var item in getRegisteredCountries) { if (countryList.Contains(item)) { countryList.Remove(item); } } cbCountry.Items.AddRange(countryList.ToArray()); } }
private void btnCreate_Click(object sender, EventArgs e) { Regex regex = new Regex("^[a-zA-Z0-9]*$"); if (cbCountry.SelectedItem == null || string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtRePassword.Text)) { MessageBox.Show("Please check your fields and try again!", "Empty Field(s)", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtPassword.Text != txtRePassword.Text) { MessageBox.Show("Passwords do not match!", "Password Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtUserID.TextLength < 8) { MessageBox.Show("User ID needs to be at least 8 characters long!", "User ID too short", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!regex.IsMatch(txtUserID.Text)) { MessageBox.Show("User ID cannot have special characters!", "User ID Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (var context = new Session3Entities()) { var getUser = (from x in context.Users where x.userId == txtUserID.Text select x).FirstOrDefault(); if (getUser != null) { MessageBox.Show("User ID used!", "Existing User ID", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var newUser = new User() { countryName = cbCountry.SelectedItem.ToString(), userId = txtUserID.Text, passwd = txtRePassword.Text, userTypeIdFK = 2 }; context.Users.Add(newUser); context.SaveChanges(); MessageBox.Show("Account created successfully!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new LoginForm()).ShowDialog(); Close(); } } } }
private void LoadData() { using (var context = new Session3Entities()) { var getArrivalDetails = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); lblDelegates.Text = getArrivalDetails.numberDelegate.ToString(); lblCompetitors.Text = getArrivalDetails.numberCompetitors.ToString(); arrival = getArrivalDetails.arrivalDate; lengthOfStay = (endDate - arrival).Days; } }
private void LoadGraph(int mode) { chart1.Series[0].Points.Clear(); chart1.Series[1].Points.Clear(); using (var context = new Session3Entities()) { var getDetails = (from x in context.Arrivals select x.User.countryName).Distinct(); if (mode == 0) { chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; chart1.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; foreach (var item in getDetails) { var getArrivalNumbers = (from x in context.Arrivals where x.User.countryName == item select x).FirstOrDefault(); var idx = chart1.Series[0].Points.AddXY(item, getArrivalNumbers.numberDelegate + getArrivalNumbers.numberHead); var idx1 = chart1.Series[1].Points.AddXY(item, getArrivalNumbers.numberCompetitors); chart1.Series[0].LegendText = "Delegates"; chart1.Series[1].LegendText = "Competitors"; chart1.Series[0].Points[idx].IsValueShownAsLabel = true; chart1.Series[1].Points[idx1].IsValueShownAsLabel = true; } } else if (mode == 1) { foreach (var item in getDetails) { var getArrivalNumbers = (from x in context.Arrivals where x.User.countryName == item select x).FirstOrDefault(); var idx = chart1.Series[0].Points.AddXY(item, getArrivalNumbers.numberDelegate + getArrivalNumbers.numberHead); chart1.Series[0].LegendText = "Delegates"; chart1.Series[0].Points[idx].IsValueShownAsLabel = true; } } else { foreach (var item in getDetails) { var getArrivalNumbers = (from x in context.Arrivals where x.User.countryName == item select x).FirstOrDefault(); var idx1 = chart1.Series[1].Points.AddXY(item, getArrivalNumbers.numberCompetitors); chart1.Series[1].LegendText = "Competitors"; chart1.Series[1].Points[idx1].IsValueShownAsLabel = true; } } } }
private void GetData() { using (var context = new Session3Entities()) { var getArrivalDetails = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); arrivalDate = getArrivalDetails.arrivalDate; lengthOfStay = (endDate - arrivalDate).Days; nudHead.Value = getArrivalDetails.numberHead; nudDelegates.Value = getArrivalDetails.numberDelegate; nudCompetitors.Value = getArrivalDetails.numberCompetitors; } }
private void LoadRooms() { dataGridView1.Rows.Clear(); var numberOfDelegates = Int32.Parse(lblDelegates.Text); var numberOfCompetitors = Int32.Parse(lblCompetitors.Text); using (var context = new Session3Entities()) { var getHotelDetails = (from x in context.Hotels where x.hotelName == HotelName select x).FirstOrDefault(); if (numberOfCompetitors % 2 == 0) { var singleRow = new List <string>() { "Single", getHotelDetails.singleRate.ToString(), (getHotelDetails.numSingleRoomsTotal - getHotelDetails.numSingleRoomsBooked).ToString(), numberOfDelegates.ToString(), (lengthOfStay * numberOfDelegates * getHotelDetails.singleRate).ToString() }; var doubleRow = new List <string>() { "Double", getHotelDetails.doubleRate.ToString(), (getHotelDetails.numDoubleRoomsTotal - getHotelDetails.numDoubleRoomsBooked).ToString(), (numberOfCompetitors / 2).ToString(), (lengthOfStay * (numberOfCompetitors / 2) * getHotelDetails.doubleRate).ToString() }; dataGridView1.Rows.Add(singleRow.ToArray()); dataGridView1.Rows.Add(doubleRow.ToArray()); } else { var singleRow = new List <string>() { "Single", getHotelDetails.singleRate.ToString(), (getHotelDetails.numSingleRoomsTotal - getHotelDetails.numSingleRoomsBooked).ToString(), (numberOfDelegates + 1).ToString(), (lengthOfStay * (numberOfDelegates + 1) * getHotelDetails.singleRate).ToString() }; var doubleRow = new List <string>() { "Double", getHotelDetails.doubleRate.ToString(), (getHotelDetails.numDoubleRoomsTotal - getHotelDetails.numDoubleRoomsBooked).ToString(), (numberOfCompetitors / 2).ToString(), (lengthOfStay * (numberOfCompetitors / 2) * getHotelDetails.doubleRate).ToString() }; dataGridView1.Rows.Add(singleRow.ToArray()); dataGridView1.Rows.Add(doubleRow.ToArray()); } CalculateTotal(); } }
private void btnLogin_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Please check your fields and try again!", "Empty Field(s)", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (var context = new Session3Entities()) { var findUser = (from x in context.Users where x.userId == txtUserID.Text select x).FirstOrDefault(); if (findUser == null) { MessageBox.Show("User does not exist!", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtPassword.Text != findUser.passwd) { MessageBox.Show("User ID or Password does not match our database!", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show($"Welcome {findUser.countryName}!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information); if (findUser.userTypeIdFK == 1) { Hide(); (new AdminMain()).ShowDialog(); Close(); } else if (findUser.userTypeIdFK == 2) { Hide(); (new CountryMain(findUser)).ShowDialog(); Close(); } } } } }
private void btnConfirm_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var getArrival = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); if (getArrival != null) { MessageBox.Show("Arrival details have been confirmed!", "Confirm Arrival Details", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Hide(); (new ConfirmArrival(_user)).ShowDialog(); Close(); } } }
private void LoadData() { using (var context = new Session3Entities()) { var date22 = DateTime.Parse("22 July"); var date23 = DateTime.Parse("23 July"); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { var timing = dataGridView1.Rows[row.Index].Cells[cell.Index].Value.ToString(); var getArrivalDetails = (from x in context.Arrivals where x.arrivalDate == date22 && x.arrivalTime == timing select x); var sb = new StringBuilder($"{dataGridView1.Rows[row.Index].Cells[cell.Index].Value}"); foreach (var item in getArrivalDetails) { sb.Append($"\n\n{item.User.countryName}\n({item.numberCars + item.number19seat + item.number42seat}Veh)"); } dataGridView1.Rows[row.Index].Cells[cell.Index].Value = sb.ToString(); } } foreach (DataGridViewRow row in dataGridView2.Rows) { foreach (DataGridViewColumn cell in dataGridView2.Columns) { var timing = dataGridView2.Rows[row.Index].Cells[cell.Index].Value.ToString(); var getArrivalDetails = (from x in context.Arrivals where x.arrivalDate == date23 && x.arrivalTime == timing select x); var sb = new StringBuilder($"{dataGridView2.Rows[row.Index].Cells[cell.Index].Value}"); foreach (var item in getArrivalDetails) { sb.Append($"\n\n{item.User.countryName}\n({item.numberCars + item.number19seat + item.number42seat}Veh)"); } dataGridView2.Rows[row.Index].Cells[cell.Index].Value = sb.ToString(); } } } }
private void LoadData(string HotelName) { lblHotelName.Text = HotelName; dataGridView1.Rows.Clear(); using (var context = new Session3Entities()) { var getHotelID = (from x in context.Hotels where x.hotelName == HotelName select x.hotelId).FirstOrDefault(); var getAllBookings = (from x in context.Hotel_Booking where x.hotelIdFK == getHotelID select x); foreach (var item in getAllBookings) { var newRow = new List <string>() { item.User.countryName, item.numSingleRoomsRequired.ToString(), item.numDoubleRoomsRequired.ToString() }; dataGridView1.Rows.Add(newRow.ToArray()); } } }
private void btnConfirm_Click(object sender, EventArgs e) { if (dataGridView1.CurrentCell.Style.BackColor == Color.Black) { MessageBox.Show("Unable to confirm blacked-out timings!", "Invalid Timing", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (rb22July.Checked == false && rb23July.Checked == false) { MessageBox.Show("Please select a date!", "Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var newArrival = new Arrival() { arrivalDate = DateTime.Parse(rb22July.Text), arrivalTime = dataGridView1.CurrentCell.Value.ToString(), numberHead = Convert.ToInt32(nudHead.Value), numberDelegate = Convert.ToInt32(nudDelegates.Value), numberCompetitors = Convert.ToInt32(nudCompetitors.Value), userIdFK = _user.userId, numberCars = Int32.Parse(lblCar.Text), number19seat = Int32.Parse(lbl19Bus.Text), number42seat = Int32.Parse(lbl42Bus.Text) }; using (var context = new Session3Entities()) { context.Arrivals.Add(newArrival); context.SaveChanges(); } MessageBox.Show("Arrival confirmed!", "Confirm Arrival Details", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new CountryMain(_user)).ShowDialog(); Close(); } }
private void btnUpdate_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var getHotel = (from x in context.Hotel_Booking where x.userIdFK == _user.userId select x).FirstOrDefault(); var getArrival = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); if (getArrival == null || getHotel == null) { MessageBox.Show("Please confirm your arrival details or complete your hotel booking first!", "Update Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Hide(); (new UpdateInfo(_user)).ShowDialog(); Close(); } } }
private void LoadTable() { dataGridView1.Rows.Clear(); using (var context = new Session3Entities()) { var getBookings = (from x in context.Hotel_Booking where x.userIdFK == _user.userId select x).FirstOrDefault(); var singleRow = new List <string>() { "Single", getBookings.Hotel.singleRate.ToString(), (getBookings.Hotel.numSingleRoomsTotal - getBookings.Hotel.numSingleRoomsBooked).ToString(), getBookings.numSingleRoomsRequired.ToString(), "", "" }; var doubleRow = new List <string>() { "Double", getBookings.Hotel.doubleRate.ToString(), (getBookings.Hotel.numDoubleRoomsTotal - getBookings.Hotel.numDoubleRoomsBooked).ToString(), getBookings.numDoubleRoomsRequired.ToString(), "", "" }; dataGridView1.Rows.Add(singleRow.ToArray()); dataGridView1.Rows.Add(doubleRow.ToArray()); } }
private void btnBook_Click(object sender, EventArgs e) { var totalParticipants = Int32.Parse(lblDelegates.Text) + Int32.Parse(lblCompetitors.Text); var getTotalCapOfRooms = 0; var boolCheck = true; for (int i = 0; i <= dataGridView1.RowCount - 1; i++) { if (i == 0) { getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value); } else if (i == 1) { getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value) * 2; } } foreach (DataGridViewRow item in dataGridView1.Rows) { if (Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[2].Value) - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) < 0) { boolCheck = false; } } if (getTotalCapOfRooms < totalParticipants) { MessageBox.Show("There are not enough rooms booked to accomedate all participants!", "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (boolCheck == false) { MessageBox.Show("There are not enough rooms for the hotel to accomedate all participants!", "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var numberOfSingleBooked = Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value); var numberOfDoubleBooked = Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value); using (var context = new Session3Entities()) { var getHotel = (from x in context.Hotels where x.hotelName == HotelName select x).FirstOrDefault(); var newBooking = new Hotel_Booking() { hotelIdFK = getHotel.hotelId, userIdFK = _user.userId, numSingleRoomsRequired = numberOfSingleBooked, numDoubleRoomsRequired = numberOfDoubleBooked }; context.Hotel_Booking.Add(newBooking); context.SaveChanges(); getHotel.numSingleRoomsBooked += numberOfSingleBooked; getHotel.numDoubleRoomsBooked += numberOfDoubleBooked; context.SaveChanges(); MessageBox.Show("Hotel booked successfully!", "Hotel Booking", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } } }
private void btnUpdate_Click(object sender, EventArgs e) { var totalParticipants = Convert.ToInt32(nudCompetitors.Value) + Convert.ToInt32(nudDelegates.Value); var getTotalCapOfRooms = 0; var boolCheck = true; for (int i = 0; i <= dataGridView1.RowCount - 1; i++) { if (i == 0) { if (dataGridView1.Rows[i].Cells[4].Value.ToString() == "") { getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value); } else { getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value); } } else if (i == 1) { if (dataGridView1.Rows[i].Cells[4].Value.ToString() == "") { getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value) * 2; } else { getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value) * 2; } } } foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1.Rows[item.Index].Cells[4].Value.ToString() != "") { if (Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[2].Value) - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value) < 0) { boolCheck = false; } } else { if (Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[2].Value) - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) < 0) { boolCheck = false; } } } if (getTotalCapOfRooms < totalParticipants) { MessageBox.Show("There are not enough rooms booked to accomedate all participants!", "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (boolCheck == false) { MessageBox.Show("There are not enough rooms for the hotel to accomedate all participants!", "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (var context = new Session3Entities()) { var getArrivalDetails = (from x in context.Arrivals where x.userIdFK == _user.userId select x).FirstOrDefault(); var getBookings = (from x in context.Hotel_Booking where x.userIdFK == _user.userId select x).FirstOrDefault(); var hotelDetails = (from x in context.Hotels where x.hotelId == getBookings.hotelIdFK select x).FirstOrDefault(); getArrivalDetails.numberHead = Convert.ToInt32(nudHead.Value); getArrivalDetails.numberDelegate = Convert.ToInt32(nudDelegates.Value); getArrivalDetails.numberCompetitors = Convert.ToInt32(nudCompetitors.Value); context.SaveChanges(); foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1.Rows[item.Index].Cells[4].Value.ToString() == "") { continue; } else { if (dataGridView1.Rows[item.Index].Cells[0].Value.ToString() == "Single") { getBookings.numSingleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value); if (hotelDetails.numSingleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) == 0) { hotelDetails.numSingleRoomsBooked = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value); } else { hotelDetails.numSingleRoomsBooked = hotelDetails.numSingleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) + Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value); } } else { getBookings.numDoubleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value); if (hotelDetails.numDoubleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) == 0) { hotelDetails.numDoubleRoomsBooked = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value); } else { hotelDetails.numDoubleRoomsBooked = hotelDetails.numDoubleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) + Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value); } } } } context.SaveChanges(); MessageBox.Show("Updated info and booking successful!", "Update Info / Booking", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new CountryMain(_user)).ShowDialog(); Close(); } } }