private void buttonAdd_Click(object sender, EventArgs e) { if (ValidationService.ValidateHotelName(textBoxHotelName.Text) && ValidationService.ValidateFoundationYear(dateTimePickerFYear.Value)) { var hotel = new Hotel() { HotelName = textBoxHotelName.Text, Adress = textBoxAdress.Text, FoundationYear = dateTimePickerFYear.Value, IsActive = Convert.ToBoolean(comboBoxIsActive.Text), Created = DateTime.Now }; using (var context = ContextResolver.GetContext(connectionString)) { var hotelService = new HotelService(context); hotelService.Add(hotel); } MessageBox.Show("New record has been added"); this.Close(); } else { labelValidationMessage.Visible = true; } }
private void buttonUpdate_Click(object sender, EventArgs e) { if (ValidationService.ValidateHotelName(textBoxHotelName.Text) && ValidationService.ValidateIsNumber(textBoxFyndById.Text) && ValidationService.ValidateFoundationYear(dateTimePickerFYear.Value)) { var hotel = new Hotel() { Id = Convert.ToInt32(textBoxFyndById.Text), HotelName = textBoxHotelName.Text, Adress = textBoxAdress.Text, FoundationYear = dateTimePickerFYear.Value, IsActive = Convert.ToBoolean(comboBoxIsActive.Text), Modified = DateTime.Now }; using (var context = ContextResolver.GetContext(connectionString)) { var hotelService = new HotelService(context); hotelService.Update(hotel); } MessageBox.Show("The record has been updated!"); this.Close(); } else { labelValidationMessage.Visible = true; } }
private void buttonFind_Click(object sender, EventArgs e) { textBoxHotelName.ReadOnly = false; textBoxAdress.ReadOnly = false; dateTimePickerFYear.Enabled = true; buttonUpdate.Enabled = true; comboBoxIsActive.Enabled = true; if (ValidationService.ValidateIsNumber(textBoxFyndById.Text)) { var hotel = new Hotel(); using (var context = ContextResolver.GetContext(connectionString)) { var hotelService = new HotelService(context); hotel = hotelService.Get(Convert.ToInt32(textBoxFyndById.Text)); } textBoxHotelName.Text = hotel.HotelName; textBoxAdress.Text = hotel.Adress; dateTimePickerFYear.Value = hotel.FoundationYear; comboBoxIsActive.Text = hotel.IsActive.ToString(); comboBoxIsActive.Text = hotel.IsActive.ToString(); } else { labelValidationMessage.Visible = true; } }
private void FormAddReservation_Shown(object sender, EventArgs e) { var bookings = new List <Booking>(); using (var context = ContextResolver.GetContext(connectionString)) { BookingService bookingService = new BookingService(context); bookings = bookingService.GetAllByRoomId(roomId); } monthCalendarBookedDays.BoldedDates = bookedDatesService.GetAllBookedDays(bookings).ToArray(); listViewUsers.Items.Clear(); var allUsers = new List <User>(); using (var context = ContextResolver.GetContext(connectionString)) { UserService userService = new UserService(context); allUsers = userService.GetAll(); } foreach (var user in allUsers) { ListViewItem listViewUserRecord = new ListViewItem(user.Id.ToString()); listViewUserRecord.SubItems.Add(user.UserName); listViewUsers.Items.Add(listViewUserRecord); } }
private void buttonUpdate_Click(object sender, EventArgs e) { if (ValidationService.ValidateIsNumber(textBoxNumber.Text) && ValidationService.ValidateIsNumber(textBoxCapability.Text) && ValidationService.ValidateIsPrice(textBoxPrice.Text)) { var room = new Room() { Id = Convert.ToInt32(textBoxId.Text), Number = Convert.ToInt32(textBoxNumber.Text), Price = Convert.ToDouble(textBoxPrice.Text), Capability = Convert.ToInt16(textBoxCapability.Text), ComfortLevel = Convert.ToInt16(comboBoxComfortLvl.Text), HotelId = hotelId, Modified = DateTime.Now }; using (var context = ContextResolver.GetContext(connectionString)) { var roomService = new RoomService(context); roomService.Update(room); } MessageBox.Show("The record has been updated!"); this.Close(); } else { labelValidationMessage.Visible = true; } }
private void buttonFind_Click(object sender, EventArgs e) { if (ValidationService.ValidateIsNumber(textBoxId.Text)) { textBoxPrice.ReadOnly = false; textBoxCapability.ReadOnly = false; comboBoxComfortLvl.Enabled = true; buttonUpdate.Enabled = true; textBoxNumber.Enabled = true; var room = new Room(); using (var context = ContextResolver.GetContext(connectionString)) { var roomService = new RoomService(context); room = roomService.GetById(Convert.ToInt32(textBoxId.Text)); } textBoxId.Text = room.Id.ToString(); textBoxPrice.Text = room.Price.ToString(); textBoxCapability.Text = room.Capability.ToString(); comboBoxComfortLvl.Text = room.ComfortLevel.ToString(); textBoxNumber.Text = room.Number.ToString(); } else { labelValidationMessage.Visible = true; } }
private void buttonDelete_Click(object sender, EventArgs e) { if (ValidationService.ValidateIsNumber(textBoxAdress.Text)) { using (var context = ContextResolver.GetContext(connectionString)) { var hotelService = new HotelService(context); hotelService.Delete(Convert.ToInt16(textBoxAdress.Text)); } MessageBox.Show("The record has been deleted!"); this.Close(); } else { labelValidationMessage.Visible = true; } }
private void buttonCancel_Click(object sender, EventArgs e) { if (listViewRoomReservation.SelectedItems.Count != 0) { ListViewItem item = listViewRoomReservation.SelectedItems[0]; using (var context = ContextResolver.GetContext(connectionString)) { BookingService bookingService = new BookingService(context); bookingService.Delete(Convert.ToInt32(item.Text)); } MessageBox.Show("The reservation has been canceled"); } else { MessageBox.Show("Select the reservation!"); } }
private void buttonAddReservation_Click(object sender, EventArgs e) { if (listViewUsers.SelectedItems.Count != 0) { if (ValidationService.ValidateBookingDates(dateTimePickerStart.Value, dateTimePickerEnd.Value)) { var bookedDates = new List <DateTime>(); using (var context = ContextResolver.GetContext(connectionString)) { BookingService bookingService = new BookingService(context); bookedDates = bookedDatesService.GetAllBookedDays(bookingService.GetAllByRoomId(roomId)); } if (bookedDatesService.CheckIsBookedDates(dateTimePickerStart.Value, dateTimePickerEnd.Value, bookedDates)) { ListViewItem item = listViewUsers.SelectedItems[0]; Booking booking = new Booking() { StartDate = dateTimePickerStart.Value, EndDate = dateTimePickerEnd.Value, UserId = Convert.ToInt32(item.Text), RoomId = roomId }; using (var context = ContextResolver.GetContext(connectionString)) { BookingService bookingService = new BookingService(context); bookingService.Add(booking); } MessageBox.Show("New record has added"); this.Close(); } else { labelErrorBookedRoom.Visible = true; } } else { labelDatesValidation.Visible = true; } } else { labelError.Visible = true; } }
private void GetAllRooms() { listViewHotelRooms.Items.Clear(); var hotelRooms = new List <Room>(); using (var context = ContextResolver.GetContext(connectionString)) { var roomService = new RoomService(context); hotelRooms = roomService.GetAllByHotelId(hotelId); } foreach (var room in hotelRooms) { ListViewItem listViewItem = new ListViewItem(room.Id.ToString()); listViewItem.SubItems.Add(room.Number.ToString()); listViewItem.SubItems.Add(room.Price.ToString()); listViewItem.SubItems.Add(room.Capability.ToString()); listViewItem.SubItems.Add(room.ComfortLevel.ToString()); listViewHotelRooms.Items.Add(listViewItem); } }
private void GetAllHotels() { listViewHotels.Items.Clear(); var hotels = new List <Hotel>(); using (var context = ContextResolver.GetContext(connectionString)) { HotelService hotelService = new HotelService(context); hotels = hotelService.GetAll(); } foreach (var hotel in hotels) { ListViewItem listViewItem = new ListViewItem(hotel.Id.ToString()); listViewItem.SubItems.Add(hotel.HotelName); listViewItem.SubItems.Add(hotel.FoundationYear.ToShortDateString()); listViewItem.SubItems.Add(hotel.Adress); listViewItem.SubItems.Add(hotel.IsActive.ToString()); listViewHotels.Items.Add(listViewItem); } }
private void buttonShowRating_Click(object sender, EventArgs e) { if (ValidationService.ValidateRatingBookingDates(dateTimePickerStartDate.Value, dateTimePickerEndDate.Value)) { var roomsBookings = new List <Booking>(); var roomsRating = new List <RoomBookings>(); using (var context = ContextResolver.GetContext(connectionString)) { BookingService bookingService = new BookingService(context); roomsBookings = bookingService.GetRoomReservationsByDatesRange(dateTimePickerStartDate.Value, dateTimePickerEndDate.Value); RoomsRatingService roomsRatingService = new RoomsRatingService(); roomsRating = roomsRatingService.GetRoomBookingsRating(roomsBookings); } foreach (var item in roomsRating) { ListViewItem viewItem = new ListViewItem(item.CountBookings.ToString()); viewItem.SubItems.Add(item.RoomNumber.ToString()); viewItem.SubItems.Add(item.HotelName); listViewHotelsRating.Items.Add(viewItem); } } }
private void GetBookings() { listViewRoomReservation.Items.Clear(); if (listViewHotelRooms.SelectedItems.Count != 0) { int roomId = Convert.ToInt32(item.Text); var roomBookings = new List <Booking>(); using (var context = ContextResolver.GetContext(connectionString)) { BookingService bookingService = new BookingService(context); roomBookings = bookingService.GetAllByRoomId(roomId); } foreach (var booking in roomBookings) { ListViewItem listViewItem = new ListViewItem(booking.Id.ToString()); listViewItem.SubItems.Add(booking.User.UserName); listViewItem.SubItems.Add(booking.Room.Price.ToString()); listViewItem.SubItems.Add(booking.StartDate.ToShortDateString()); listViewItem.SubItems.Add(booking.EndDate.ToShortDateString()); listViewItem.SubItems.Add(booking.User.Email); listViewRoomReservation.Items.Add(listViewItem); } } }