private void AddButton_Click(object sender, EventArgs e) { if (TypeNametextBox.Text != "" && GuestnumericUpDown.Value != 0) { RoomType type = new RoomType() { TypeName = TypeNametextBox.Text, MaxGuestNo = Convert.ToInt32(GuestnumericUpDown.Value) }; db.RoomTypes.Add(type); db.SaveChanges(); MessageBox.Show("Room Type Added Successfully", "Add New Room Type", MessageBoxButtons.OK, MessageBoxIcon.Information); Utilities.ClearControls(this); GetTypes(); } else { MessageBox.Show("Cannot Add Empty Values", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ReservationsGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 5) { int bookId = Convert.ToInt32(ReservationsGridView.Rows[e.RowIndex].Cells[0].Value.ToString()); var cancelBooking = db.Bookings.Find(bookId); db.Bookings.Remove(cancelBooking); db.SaveChanges(); MessageBox.Show("Reservation Cancelled Successfully!", "Cancel Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information); GetBookingData(); } }
private void AddButton_Click(object sender, EventArgs e) { //Check if all values entered then add it in database if (RoomNumbertextBox.Text != "" && RoomNametextBox.Text != "" && RoomFloortextBox.Text != "" && RoomDescriptiontextBox.Text != "" && RoomPricetextBox.Text != "" && RoomViewcomboBox.SelectedIndex != -1) { Room newRoom = new Room() { RoomId = Convert.ToInt32(RoomNumbertextBox.Text), RoomName = RoomNametextBox.Text, FloorNo = Convert.ToInt32(RoomFloortextBox.Text), Description = RoomDescriptiontextBox.Text, Price = Convert.ToDecimal(RoomPricetextBox.Text), TypeId = Convert.ToInt32(RoomTypecomboBox.SelectedValue), View = RoomViewcomboBox.SelectedItem.ToString() }; if (db.Rooms.Find(newRoom.RoomId) == null) { db.Rooms.Add(newRoom); db.SaveChanges(); MessageBox.Show("Room Added Successfully", "Add New Room", MessageBoxButtons.OK, MessageBoxIcon.Information); Utilities.ClearControls(this); GetRooms(); } else { MessageBox.Show("Room Number Exists before", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Cannot Add Empty Values", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ReservationButton_Click(object sender, EventArgs e) { if (FirstNametextBox.Text != "" && LastNametextBox.Text != "" && PhonetextBox.Text != "" && EmailtextBox.Text != "") { int GuestNationalId = Convert.ToInt32(SearchtextBox.Text); Guest guest = db.Guests.Find(GuestNationalId); if (guest == null) { Guest newGuest = new Guest() { GuestId = GuestNationalId, FirstName = FirstNametextBox.Text, LastName = LastNametextBox.Text, Phone = PhonetextBox.Text, Email = EmailtextBox.Text }; db.Guests.Add(newGuest); } Booking newBooking = new Booking() { CheckIn = ChecKInTimePicker.Value, CheckOut = CheckOutTimePicker.Value, GuestId = GuestNationalId, RoomId = Convert.ToInt32(RoomNumbercomboBox.SelectedValue) }; db.Bookings.Add(newBooking); db.SaveChanges(); MessageBox.Show("Booking Done Successfully", "New Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information); Utilities.ClearControls(this); } else { MessageBox.Show("Cannot Add Empty Values", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }