//Save Reservation
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CurrentReservation.LastName) || string.IsNullOrWhiteSpace(CurrentReservation.Street) || string.IsNullOrWhiteSpace(CurrentReservation.Village) || string.IsNullOrWhiteSpace(CurrentReservation.FirstName) || cbRoom.SelectedItem == null)
            {
                MessageBox.Show("Bitte fülle alle Felder korrket aus!");
                return;
            }



            CurrentReservation.RoomFK = (cbRoom.SelectedItem as TblRoom).RoomId;

            var entities = new entitiesDataContext();
            var changed  = entities.Reservation.Where(r => r.ReservationId == CurrentReservation.ReservationId).FirstOrDefault();

            if (changed != null)
            {
                changed.EndDate   = CurrentReservation.EndDate;
                changed.FirstName = CurrentReservation.FirstName;
                changed.LastName  = CurrentReservation.LastName;
                changed.RoomFK    = CurrentReservation.RoomFK;
                changed.StartDate = CurrentReservation.StartDate;
                changed.Street    = CurrentReservation.Street;
                changed.Village   = CurrentReservation.Village;
                entities.SubmitChanges();
            }
            else
            {
                entities.Reservation.InsertOnSubmit(CurrentReservation);
                entities.SubmitChanges();
            }
            entities.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
            WF.dgReservations.ItemsSource = new ObservableCollection <Reservation>(entities.Reservation);
            this.Close();
        }
Beispiel #2
0
        //ResetFilter
        private void btnFilter_Click(object sender, RoutedEventArgs e)
        {
            var entities = new entitiesDataContext();

            var rooms    = entities.TblRoom.ToList();
            var newRooms = new List <TblRoom>();

            foreach (var r in rooms)
            {
                var isBooked = false;

                if (entities.Reservation.Where(res => res.RoomFK == r.RoomId && res.StartDate < StartDate.SelectedDate && res.EndDate > EndDate.SelectedDate).Count() != 0)
                {
                    MessageBox.Show("" + entities.Reservation.Where(res => res.RoomFK == r.RoomId && res.StartDate <StartDate.SelectedDate && res.EndDate> EndDate.SelectedDate).Count());
                    isBooked = true;
                }
                else if (entities.Reservation.Where(res => res.RoomFK == r.RoomId && (res.StartDate > StartDate.SelectedDate && res.StartDate < EndDate.SelectedDate)).Count() != 0)
                {
                    isBooked = true;
                }
                else if (entities.Reservation.Where(res => res.RoomFK == r.RoomId && (res.EndDate > StartDate.SelectedDate && res.EndDate < EndDate.SelectedDate)).Count() != 0)
                {
                    isBooked = true;
                }

                if (!isBooked)
                {
                    newRooms.Add(r);
                }
            }
            dgRooms.ItemsSource = newRooms;

            //dgRooms.ItemsSource = entities.TblRoom.Where(room => entities.Reservation.Where(res => res.RoomFK == room.RoomId && (res.EndDate >= StartDate.SelectedDate && res.EndDate <= EndDate.SelectedDate) || (res.StartDate >= StartDate.SelectedDate && res.StartDate <= EndDate.SelectedDate) || (res.StartDate <= StartDate.SelectedDate && res.EndDate <= EndDate.SelectedDate)).Count() == 0);
        }
Beispiel #3
0
        //Konstruktor
        public WindowMieter()
        {
            InitializeComponent();

            var entities = new entitiesDataContext();

            dgRooms.ItemsSource    = entities.TblRoom;
            StartDate.SelectedDate = DateTime.Today;
            EndDate.SelectedDate   = DateTime.Today;
        }
        //Konstruktor for Edit
        public WindowReservation(WindowVerwaltung wf, Reservation res)
        {
            this.DataContext = this;
            InitializeComponent();
            Title.Content      = "Edit Reservation";
            CurrentReservation = res;
            var ro = new entitiesDataContext().TblRoom.ToList();

            cbRoom.ItemsSource  = new ObservableCollection <TblRoom>(ro);
            cbRoom.SelectedItem = ro.Where <TblRoom>(r => r.RoomId == res.RoomFK).FirstOrDefault();
            WF = wf;
        }
        //DELETE RESERVATION
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (dgReservations.SelectedItem != null)
            {
                var entities = new entitiesDataContext();
                var selected = dgReservations.SelectedItem as Reservation;

                entities.Reservation.DeleteOnSubmit(entities.Reservation.Where(r => r.ReservationId == selected.ReservationId).FirstOrDefault());
                entities.SubmitChanges();
                entities.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
                dgReservations.ItemsSource = entities.Reservation;
            }
        }