private void login_button_Click(object sender, EventArgs e) { if (!(string.IsNullOrWhiteSpace(user_box.Text) && string.IsNullOrWhiteSpace(password_box.Text))) { using (var db = new Session3Entities()) { try { var user = (from a in db.Users where a.passwd == password_box.Text where a.userId == user_box.Text select a).First(); this.Hide(); var form = new MainMenu(user); form.Closed += (s, args) => this.Close(); form.Show(); } catch { MessageBox.Show("Invalid Login"); } } } else { MessageBox.Show("One or more fields are empty!!"); } }
private void ArrivalSummary_Load(object sender, EventArgs e) { timer1.Start(); using (var db = new Session3Entities()) { var date = DateTime.Parse("22 July 2020"); var q = db.Arrivals.Where(x => x.arrivalDate == date).ToList(); dataGridView1.DataSource = cdt(q); dataGridView1.Columns["10AM"].DefaultCellStyle.BackColor = Color.Black; dataGridView1.Columns["1PM"].DefaultCellStyle.BackColor = Color.Black; dataGridView1.Columns["2PM"].DefaultCellStyle.BackColor = Color.Black; dataGridView1.Columns["10AM"].HeaderCell.Style.BackColor = Color.Black; dataGridView1.Columns["1PM"].HeaderCell.Style.BackColor = Color.Black; dataGridView1.Columns["2PM"].HeaderCell.Style.BackColor = Color.Black; var date2 = DateTime.Parse("23 July 2020"); var q2 = db.Arrivals.Where(x => x.arrivalDate == date2).ToList(); dataGridView2.DataSource = cdt(q2); dataGridView2.Columns["9AM"].DefaultCellStyle.BackColor = Color.Black; dataGridView2.Columns["12PM"].DefaultCellStyle.BackColor = Color.Black; dataGridView2.Columns["4PM"].DefaultCellStyle.BackColor = Color.Black; dataGridView1.Columns["9AM"].HeaderCell.Style.BackColor = Color.Black; dataGridView2.Columns["12PM"].HeaderCell.Style.BackColor = Color.Black; dataGridView2.Columns["4PM"].HeaderCell.Style.BackColor = Color.Black; } }
private void UpdateUI(int id) { var dgvlist = new List <SummaryHotel>(); using (var db = new Session3Entities()) { var hotel = (from h in db.Hotels where h.hotelId == id select h.hotelName).First(); var bookings = (from b in db.Hotel_Booking where b.hotelIdFK == id select b); foreach (var item in bookings) { var sh = new SummaryHotel() { Country = item.User.countryName, NoOfDoubleRoomsBooked = item.numDoubleRoomsRequired, NoOfSingleRoomsBooked = item.numSingleRoomsRequired }; dgvlist.Add(sh); } dataGridView1.DataSource = null; dataGridView1.DataSource = dgvlist; hotelname_label.Text = hotel; } }
private void Login_Click(object sender, EventArgs e) { using (var db = new Session3Entities()) { var ID = UID.Text; var pass = Pass.Text; var q = db.Users.Where(x => x.userId == ID && x.passwd == pass).FirstOrDefault(); if (q != null) { //Only administrators and country representatives //can successfully login via this screen. if (q.userTypeIdFK == 1) { //When a user successfully logs in, they will be //automatically re‐directed to the appropriate main menu for that type of user. AdminMainMenu adminMainMenu = new AdminMainMenu(q); this.Hide(); adminMainMenu.Show(); } else { //When a user successfully logs in, they will be //automatically re‐directed to the appropriate main menu for that type of user. CountryRepresentativeMainMenu countryRepresentativeMainMenu = new CountryRepresentativeMainMenu(q); this.Hide(); countryRepresentativeMainMenu.Show(); } } else { MessageBox.Show("Invalid User!"); } } }
private void NewCountryRepresentative_AccountCreation_Load(object sender, EventArgs e) { timer1.Start(); using (var db = new Session3Entities()) { List <String> Countrys = new List <string>(); Countrys.Add("Brunei"); Countrys.Add("Cambodia"); Countrys.Add("Indonesia"); Countrys.Add("Laos"); Countrys.Add("Malaysia"); Countrys.Add("Myanmar"); Countrys.Add("Philippines"); Countrys.Add("Singapore"); Countrys.Add("Thailand"); Countrys.Add("Vietnam"); foreach (var item in Countrys) { //So, the drop‐down list should only show //the countries with no country rep account. var q = db.Users.Where(x => x.countryName == item && x.userTypeIdFK == 2).FirstOrDefault(); if (q == null) { Country.Items.Add(item); } else { continue; } } Country.SelectedIndex = 0; } }
public async void Initialize() { InitializeComponent(); var combolist = new List <string>(); combolist.Add("Brunei"); combolist.Add("Cambodia"); combolist.Add("Indonesia"); combolist.Add("Laos"); combolist.Add("Malaysia"); combolist.Add("Myanmar"); combolist.Add("Phillipines"); combolist.Add("Singapore"); combolist.Add("Thailand"); combolist.Add("Vietnam"); using (var db = new Session3Entities()) { var existing = (from a in db.Users select a.countryName).ToList(); foreach (var item in existing) { if (combolist.Contains(item)) { combolist.Remove(item); } } } country_combo.DataSource = combolist; }
private void HotalBooking_Load(object sender, EventArgs e) { timer1.Start(); using (var db = new Session3Entities()) { var q2 = db.Hotel_Booking.Where(x => x.userIdFK == users.userId).FirstOrDefault(); if (q2 == null) { var q = db.Hotels.Where(x => x.hotelId == hotels).FirstOrDefault(); HotalName.Text = q.hotelName; var user = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); numberD.Text = user.numberDelegate.ToString(); NumberC.Text = user.numberCompetitors.ToString(); dataGridView1.DataSource = CDT(q); } else { var q = db.Hotels.Where(x => x.hotelId == hotels).FirstOrDefault(); HotalName.Text = q.hotelName; var user = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); numberD.Text = user.numberDelegate.ToString(); NumberC.Text = user.numberCompetitors.ToString(); dataGridView1.DataSource = CDTU(q2); } } }
private void loginBtn_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { //Checks if User ID or password field is empty if (userIDBox.Text.Trim() == "" || passwordBox.Text.Trim() == "") { MessageBox.Show("Please check your User ID or Password fields!", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { var getUser = (from x in context.Users where x.userId == userIDBox.Text select x).FirstOrDefault(); //Checks if User exist in DB if (getUser == null) { MessageBox.Show("User does not exist!", "Invalid Credentials", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } //Check if password enteredmatches DB password else if (passwordBox.Text != getUser.passwd) { MessageBox.Show("Password is incorrect!", "Invalid Credentials", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { var getUserType = (from x in context.User_Type where x.userTypeId == getUser.userTypeIdFK select x.userTypeName).FirstOrDefault(); //Gets the User type and redirects the user to Representative Main Menu if user is a Country Rep - 3.3 if (getUserType == "Country Rep") { MessageBox.Show($"Welcome {getUser.countryName}!", "Successful Login", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); (new RepresentativeMain(getUser.userId)).ShowDialog(); this.Close(); } //If not Country Rep, redirects to Admin Main Menu - 3.4 else { MessageBox.Show($"Welcome {getUser.countryName}!", "Successful Login", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); (new AdminMain()).ShowDialog(); this.Close(); } } } } }
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 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); } } } }
void retrieve(int id) { using (var db = new Session3Entities()) { var q = db.Hotel_Booking.Where(x => x.hotelIdFK == id).ToList(); var q2 = db.Hotels.Where(x => x.hotelId == id).FirstOrDefault(); hotelName.Text = q2.hotelName; dataGridView1.DataSource = CDT(q); } }
private async void done_button_Click(object sender, EventArgs e) { using (var db = new Session3Entities()) { if (!(dgvlist[0].RoomsRequired > dgvlist[0].AvailableNoOfRooms)) { if (!(dgvlist[1].RoomsRequired > dgvlist[1].AvailableNoOfRooms)) { if (((dgvlist[1].RoomsRequired * 2) + dgvlist[0].RoomsRequired) >= Totalpeople) { try { Hotel_Booking hb = new Hotel_Booking() { bookingId = (from a in db.Hotel_Booking orderby a.bookingId descending select a.bookingId).First() + 1, hotelIdFK = hotelID, userIdFK = LoggedIn.userId, numDoubleRoomsRequired = dgvlist[1].RoomsRequired, numSingleRoomsRequired = dgvlist[0].RoomsRequired }; db.Hotel_Booking.Add(hb); await db.SaveChangesAsync(); } catch { Hotel_Booking hb = new Hotel_Booking() { bookingId = 1, hotelIdFK = hotelID, userIdFK = LoggedIn.userId, numDoubleRoomsRequired = dgvlist[1].RoomsRequired, numSingleRoomsRequired = dgvlist[0].RoomsRequired }; db.Hotel_Booking.Add(hb); await db.SaveChangesAsync(); } } 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"); } } }
public List <UpdateTable> GetInfo(int comp, int delegates) { var returnlist = new List <UpdateTable>(); using (var db = new Session3Entities()) { int singlerooms = 0; int doublerooms = 0; int i = comp; while ((i - 2) >= 1) { i = i - 2; doublerooms++; } singlerooms = i; singlerooms += delegates; try { var booking = (from d in db.Hotel_Booking where d.userIdFK == LoggedIn.userId select d).First(); var hotelID = booking.hotelIdFK; var hotel = (from d in db.Hotels where d.hotelId == hotelID select d).First(); var singlebt = new UpdateTable() { RoomType = "Single", AvailableNoOfRooms = hotel.numSingleRoomsTotal - hotel.numSingleRoomsBooked, RoomRatePerNight = hotel.singleRate, RoomsBooked = booking.numSingleRoomsRequired, NewNoOfRoomsRequired = singlerooms, SubTotal = hotel.singleRate * singlerooms }; var doublebt = new UpdateTable() { RoomType = "Double", AvailableNoOfRooms = hotel.numDoubleRoomsTotal - hotel.numDoubleRoomsBooked, RoomsBooked = booking.numDoubleRoomsRequired, RoomRatePerNight = hotel.doubleRate, NewNoOfRoomsRequired = doublerooms, SubTotal = hotel.doubleRate * doublerooms }; returnlist.Add(singlebt); returnlist.Add(doublebt); } catch { MessageBox.Show("No Valid Booking Found"); } return(returnlist); } }
/// <summary> /// Triggered when value change is committed (Pressed enter) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { //Runs if only the change happens in the 5th Column of the DGV if (e.ColumnIndex == 4) { //Check if there are any overbooking of rooms based on available rooms of the room types of the hotel if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) > Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value)) { MessageBox.Show("Unable to reserve more rooms than current availble rooms!", "Insufficient Rooms", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; } else { var total = 0; lblTotal.Text = "Total($): "; using (var context = new Session3Entities()) { var getDate = (from x in context.Arrivals where x.userIdFK == _userID select x.arrivalDate).First(); //Calculation based on 22nd July arrival if (getDate == DateTime.Parse("22 July")) { dataGridView1.Rows[e.RowIndex].Cells[5].Value = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value) * Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) * 8; foreach (DataGridViewRow item in dataGridView1.Rows) { total += Convert.ToInt32(item.Cells[5].Value); } lblTotal.Text += total.ToString(); } //Calculation based on 23rd July arrival else { dataGridView1.Rows[e.RowIndex].Cells[5].Value = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value) * Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) * 7; foreach (DataGridViewRow item in dataGridView1.Rows) { total += Convert.ToInt32(item.Cells[5].Value); } lblTotal.Text += total.ToString(); } } } } }
private void button2_Click(object sender, EventArgs e) { using (var db = new Session3Entities()) { var q = db.Hotel_Booking.Where(x => x.userIdFK == users.userId).FirstOrDefault(); if (q != null) { MessageBox.Show("You have already made a hotel selection!"); return; } } this.Hide(); HotelSelection hotalBooking = new HotelSelection(users); hotalBooking.Show(); }
private void CountryRepresentativeMainMenu_Load(object sender, EventArgs e) { timer1.Start(); using (var db = new Session3Entities()) { //var q = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); //if(q != null) //{ // button1.Visible = false; //} //else //{ // button1.Visible = true; //} } }
private async void create_account_box_Click(object sender, EventArgs e) { var regexItem = new Regex("^[a-zA-Z0-9 ]*$"); if (user_box.Text.Length >= 8) { using (var db = new Session3Entities()) { if (regexItem.IsMatch(user_box.Text)) { if (!(from a in db.Users select a.userId).ToList().Contains(user_box.Text)) { if (password_box.Text == password_again_box.Text) { User user = new User() { userId = user_box.Text, countryName = country_combo.Text, passwd = password_box.Text, userTypeIdFK = 2 }; db.Users.Add(user); await db.SaveChangesAsync(); button2_Click(null, null); } else { MessageBox.Show("Passwords do not match!!"); } } else { MessageBox.Show("userid already exists!!!"); } } else { MessageBox.Show("User ID cannot contain special characters"); } } } else { MessageBox.Show("UserID must have 8 or more characters!!"); } }
private void Update_Load(object sender, EventArgs e) { using (var context = new Session3Entities()) { #region Populating fields of current booking var getBookings = (from x in context.Arrivals where x.userIdFK == _userID join y in context.Hotel_Booking on x.userIdFK equals y.userIdFK select new { x, y }).FirstOrDefault(); numHeadOfDelegation.Value = getBookings.x.numberHead; txtDelegates.Text = getBookings.x.numberDelegate.ToString(); txtCompetitors.Text = getBookings.x.numberCompetitors.ToString(); #endregion } //Loads the DGV GridRefresh(); }
private void AccountCreation_Load(object sender, EventArgs e) { #region Populating the Country Combo box, then delete the country if account of the country exist in DB HashSet <string> country = new HashSet <string>() { "Brunei", "Cambodia", "Indonesia", "Laos", "Malaysia", "Myanmar", "Philippines", "Singapore", "Thailand", "Vietnam" }; countryBox.Items.AddRange(country.ToArray()); using (var context = new Session3Entities()) { var getCountry = (from x in context.Users where x.userTypeIdFK == 2 select x.countryName); foreach (var item in getCountry) { countryBox.Items.Remove(item); } } #endregion }
//Redirects user to Hotel Selection page - 3.6 private void bookingBtn_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var checkBookings = (from x in context.Arrivals where x.userIdFK == _userID select x).FirstOrDefault(); if (checkBookings != null) { this.Hide(); (new HotelSelection(_userID)).ShowDialog(); this.Close(); } else { MessageBox.Show("Please confirm your arrival details first!", "No details for arrival confrimed!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//Redirects user to Update Info/Booking page - 3.8 private void updateBtn_Click(object sender, EventArgs e) { using (var context = new Session3Entities()) { var checkBookings = (from x in context.Hotel_Booking where x.userIdFK == _userID select x).FirstOrDefault(); if (checkBookings != null) { this.Hide(); (new Update(_userID)).ShowDialog(); this.Close(); } else { MessageBox.Show("You have not booked a hotel yet!", "No bookings detected", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task <List <BookingTable> > getInfo(int comp, int delegates) { var returnlist = new List <BookingTable>(); using (var db = new Session3Entities()) { int singlerooms = 0; int doublerooms = 0; int i = comp; while ((i - 2) >= 1) { i = i - 2; doublerooms++; } singlerooms = i; singlerooms += delegates; var hotel = (from d in db.Hotels where d.hotelId == hotelID select d).First(); var singlebt = new BookingTable() { RoomType = "Single", AvailableNoOfRooms = hotel.numSingleRoomsTotal - hotel.numSingleRoomsBooked, RoomRatePerNight = hotel.singleRate, RoomsRequired = singlerooms, SubTotal = hotel.singleRate * singlerooms }; var doublebt = new BookingTable() { RoomType = "Double", AvailableNoOfRooms = hotel.numDoubleRoomsTotal - hotel.numDoubleRoomsBooked, RoomRatePerNight = hotel.doubleRate, RoomsRequired = doublerooms, SubTotal = hotel.doubleRate * doublerooms }; returnlist.Add(singlebt); returnlist.Add(doublebt); } return(returnlist); }
private void ConfirmArrivalDetails_Load(object sender, EventArgs e) { timer1.Start(); dataGridView1.ColumnHeadersVisible = false; dataGridView1.DataSource = cdt(); dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect; using (var db = new Session3Entities()) { var q = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); if (q != null) { if (q.arrivalDate == DateTime.Parse("22 July 2020")) { jul22.Checked = true; } else if (q.arrivalDate == DateTime.Parse("23 July 2020")) { jul23.Checked = true; } time = q.arrivalTime; foreach (DataGridViewColumn column in dataGridView1.Columns) { if (column.HeaderCell.Value.ToString() == q.arrivalTime) { column.HeaderCell.Style.BackColor = Color.Yellow; } } numericUpDown1.Value = q.numberHead; Dels.Text = q.numberDelegate.ToString(); Comps.Text = q.numberCompetitors.ToString(); carHeadDel.Text = q.numberCars.ToString(); seat19.Text = q.number19seat.ToString(); seat42.Text = q.number42seat.ToString(); } } }
/// <summary> /// Gets the rooms booked for the Intercontinental Singapore /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnIntercontinentalSingapore_Click(object sender, EventArgs e) { lblHotelName.Text = "Hotal Name: "; dataGridView1.Rows.Clear(); GridRefresh(); using (var context = new Session3Entities()) { var getHotel = (from x in context.Hotels where x.hotelName == "Intercontinental Singapore" join y in context.Hotel_Booking on x.hotelId equals y.hotelIdFK select y); foreach (var item in getHotel) { var rows = new List <string>() { item.User.countryName, item.numSingleRoomsRequired.ToString(), item.numDoubleRoomsRequired.ToString() }; dataGridView1.Rows.Add(rows.ToArray()); } lblHotelName.Text += "Intercontinental Singapore"; } }
/// <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(); } } }
public async void Initialize() { InitializeComponent(); date_label.Text = DateTime.Now.ToString("dd'/'MM'/'yy"); using (var db = new Session3Entities()) { try { var h = (from a in db.Hotel_Booking where a.userIdFK == LoggedIn.userId select a).First(); MessageBox.Show("Error: Already booked"); this.Close(); } catch { //carry on. } try { var arrival = (from a in db.Arrivals where a.userIdFK == LoggedIn.userId select new { a.numberCompetitors, a.numberDelegate }).First(); hotel_label.Text = hotelname; people_number.Text = arrival.numberDelegate.ToString(); competitors_number.Text = arrival.numberCompetitors.ToString(); dgvlist = await getInfo(arrival.numberCompetitors, arrival.numberDelegate); Totalpeople = arrival.numberCompetitors + arrival.numberDelegate; dataGridView1.DataSource = dgvlist; updateValuelabel(); } catch { MessageBox.Show("Error, no arrival found"); } } }
/// <summary> /// This method is responsible for the loading of the DGV and the previously booked number of rooms of the hotels. /// New required rooms field and new sub-total will be 0 by default /// </summary> private void GridRefresh() { dataGridView1.ColumnCount = 6; dataGridView1.Columns[0].Name = "Room Type"; dataGridView1.Columns[1].Name = "Room Rate per Night ($)"; dataGridView1.Columns[2].Name = "Available Number of Rooms"; dataGridView1.Columns[3].Name = "Rooms Booked"; dataGridView1.Columns[4].Name = "New No. of Rooms Required"; dataGridView1.Columns[5].Name = "New Sub-Total"; using (var context = new Session3Entities()) { var getBooking = (from x in context.Hotel_Booking where x.userIdFK == _userID join y in context.Hotels on x.hotelIdFK equals y.hotelId select new { singleRoomRate = y.singleRate, doubleRoomRate = y.doubleRate, singleBooked = x.numSingleRoomsRequired, doubleBooked = x.numDoubleRoomsRequired, availSingle = y.numSingleRoomsTotal - y.numSingleRoomsBooked, availDouble = y.numDoubleRoomsTotal - y.numDoubleRoomsBooked }).First(); var row1 = new List <string>() { "Single", getBooking.singleRoomRate.ToString(), getBooking.availSingle.ToString(), getBooking.singleBooked.ToString(), "0", "0" }; var row2 = new List <string>() { "Double", getBooking.doubleRoomRate.ToString(), getBooking.availDouble.ToString(), getBooking.doubleBooked.ToString(), "0", "0" }; dataGridView1.Rows.Add(row1.ToArray()); dataGridView1.Rows.Add(row2.ToArray()); } }
public HotelUpdate(User user) { LoggedIn = user; InitializeComponent(); date_label.Text = DateTime.Now.ToString("dd'/'MM'/'yy"); using (var db = new Session3Entities()) { try { var h = (from a in db.Hotel_Booking where a.userIdFK == LoggedIn.userId select a).First(); } catch { MessageBox.Show("Error: No Booking Found"); this.Close(); } try { var arrival = (from a in db.Arrivals where a.userIdFK == LoggedIn.userId select a).First(); head_updown.Value = arrival.numberHead; delegates_updown.Value = arrival.numberDelegate; competitors_updown.Value = arrival.numberCompetitors; dgvlist = GetInfo(arrival.numberCompetitors, arrival.numberDelegate); dataGridView1.DataSource = dgvlist; updateValuelabel(); } catch { MessageBox.Show("Error, no arrival found"); } } }
private void UpdateInfoBooking_Load(object sender, EventArgs e) { timer1.Start(); using (var db = new Session3Entities()) { var q = db.Arrivals.Where(x => x.userIdFK == users.userId).FirstOrDefault(); if (q == null) { MessageBox.Show("Please Book Something First!"); this.Hide(); CountryRepresentativeMainMenu countryRepresentativeMainMenu = new CountryRepresentativeMainMenu(users); countryRepresentativeMainMenu.Show(); } else { var q2 = db.Hotel_Booking.Where(x => x.userIdFK == users.userId).FirstOrDefault(); dataGridView1.DataSource = CDTU(q2); HOD.Value = q.numberHead; Dels.Text = q.numberDelegate.ToString(); Comps.Text = q.numberCompetitors.ToString(); } } }
/// <summary> /// Upon change of value in cell, recalculate the sub-total by re-retrieving arrival date for calculation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { using (var context = new Session3Entities()) { var total = 0; var checkArrival = (from x in context.Arrivals where x.userIdFK == _userID select x.arrivalDate).FirstOrDefault(); if (checkArrival == DateTime.Parse("22 July")) { totalValue.Text = "Total ($): "; if (e.ColumnIndex == 3) { dataGridView1.Rows[e.RowIndex].Cells[4].Value = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value) * Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) * 8; foreach (DataGridViewRow item in dataGridView1.Rows) { total += Convert.ToInt32(item.Cells[4].Value); } totalValue.Text += total.ToString(); } } else { totalValue.Text = "Total ($): "; if (e.ColumnIndex == 3) { dataGridView1.Rows[e.RowIndex].Cells[4].Value = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value) * Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) * 7; foreach (DataGridViewRow item in dataGridView1.Rows) { total += Convert.ToInt32(item.Cells[4].Value); } totalValue.Text += total.ToString(); } } } }