コード例 #1
0
        //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();
        }
コード例 #2
0
        //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;
            }
        }