private void tbDetails_Click(object sender, RoutedEventArgs e) { ICartoObj o = (ICartoObj)ListBox.SelectedItem; string titreFenetre = "", messageFenetre = ""; if (o == null) { MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (o is POI) { POI p = o as POI; titreFenetre = "Caractéristiques détaillées du POI sélectionné"; messageFenetre = p.Draw(); } if (o is Polyline) { Polyline p = o as Polyline; titreFenetre = "Caractéristiques détaillées du trajet (Polyline) sélectionné"; messageFenetre = p.Draw(); } if (o is Polygon) { Polygon p = o as Polygon; titreFenetre = "Caractéristiques détaillées de la surface (Polygon) sélectionné"; messageFenetre = p.Draw(); } MessageBox.Show(messageFenetre, titreFenetre, MessageBoxButton.OK, MessageBoxImage.Information); } }
private void tbModifier_Click(object sender, RoutedEventArgs e) { bool modificationOK = false; ICartoObj o = (ICartoObj)ListBox.SelectedItem; if (o == null) { modificationOK = true; MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { Carte.Children.Clear(); if (o is POI) { POI p = o as POI; fenetrePOI fenetrePOI = new fenetrePOI(p); fenetrePOI.Owner = this; fenetrePOI.ShowDialog(); if (fenetrePOI.NewPOI != null) { foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is POI) { POI poiInCollection = oInCollection as POI; if (poiInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(poiInCollection)) { POI newPOI = new POI(); newPOI.Id = p.Id; newPOI.Latitude = fenetrePOI.NewPOI.Latitude; newPOI.Longitude = fenetrePOI.NewPOI.Longitude; newPOI.Description = fenetrePOI.NewPOI.Description; Console.WriteLine("DEBUG newPoi to string : " + newPOI.Draw()); PersonneConnectee.ObservableCollection.Add(newPOI); modificationOK = true; } break; } } } } else { modificationOK = true; } } if (o is Polyline) { Polyline p = o as Polyline; Console.WriteLine("DEBUG polyline dans modifier fenetre principale:\n" + p.Draw()); FenetrePolyline fenetrePolyline = new FenetrePolyline(p); fenetrePolyline.Owner = this; fenetrePolyline.ShowDialog(); if (fenetrePolyline.NewPolyline != null) { foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is Polyline) { Polyline polylineInCollection = oInCollection as Polyline; if (polylineInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(polylineInCollection)) { Polyline newPolyline = new Polyline(); newPolyline.Id = p.Id; newPolyline.Epaisseur = fenetrePolyline.NewPolyline.Epaisseur; newPolyline.Couleur = fenetrePolyline.NewPolyline.Couleur; newPolyline.NomTrajet = fenetrePolyline.NewPolyline.NomTrajet; newPolyline.CollectionDeCoordonnes = new List <Coordonnees>(fenetrePolyline.NewPolyline.CollectionDeCoordonnes); PersonneConnectee.ObservableCollection.Add(newPolyline); modificationOK = true; } break; } } } } else { modificationOK = true; } } //} //if (o is Polygon) //{ // Polygon p = o as Polygon; // foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) // { // if (oInCollection is Polygon) // { // Polygon polygonInCollection = oInCollection as Polygon; // if (polygonInCollection.Id == p.Id) // { // if (PersonneConnectee.ObservableCollection.Remove(polygonInCollection)) // { // MessageBox.Show("Suppression du polyline OK", "", MessageBoxButton.OK, MessageBoxImage.Information); // suppressionOK = true; // } // break; // } // } // } //} UpdateListBox(); } if (!modificationOK) { MessageBox.Show("La modification à échouée", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } }