private void Save_Click(object sender, RoutedEventArgs e) { if (myPersonalMapData.Save()) { MessageBox.Show("Erreur: myPersonalMapData.Save()"); this.Close(); } }
private void Connexion_Click(object sender, RoutedEventArgs e) { MyPersonalMapData utilisateur = new MyPersonalMapData(NomTB.Text, PrenomTB.Text, emailTB.Text); WindowPrincipal w = new WindowPrincipal(utilisateur); Coordonnees A = new Coordonnees(40.25, 48.25); MyCartographyObjects.Polyline Poly1 = new MyCartographyObjects.Polyline(new List <Coordonnees>() { A }, 10, Color.FromArgb(255, 201, 200, 152), 1); ObservableCollection <ICartoObj> ListeTest = new ObservableCollection <ICartoObj>(); ListeTest.Add(Poly1); utilisateur.ObservableCollection = ListeTest; Coordonnees B = new Coordonnees(40.25, 48.25); Coordonnees D = new Coordonnees(3.25, 10.45); Coordonnees E = new Coordonnees(4.254, 5.2545); Polygone Polygone = new Polygone(new List <Coordonnees>() { B, D, E }, Color.FromArgb(165, 187, 195, 0), Color.FromArgb(165, 200, 140, 165), 1, 1); ListeTest.Add(Polygone); utilisateur.ObservableCollection = ListeTest; string filename = utilisateur.Nom + utilisateur.Prenom + ".dat"; if (NomTB.Text.Length < 1 || PrenomTB.Text.Length < 1 || emailTB.Text.Length < 1) { ApresConnexion.Text = "Erreur : Veuillez remplir tous les champs"; MessageBox.Show("Erreur : Veuillez remplir tous les champs"); } else { // ApresConnexion.Text = filename; if (!(File.Exists(@"C:\Users\gaetan\source\repos\CartoProject\Test\bin\Debug\" + filename))) { ApresConnexion.Text = "Utilisateur n'existe pas"; MessageBox.Show("Utilisateur n'existe pas"); utilisateur.Save(); w.Show(); this.Close(); } else { ApresConnexion.Text = "Utilisateur existe deja"; MessageBox.Show("Utilisateur existe deja"); // utilisateur.Load(); w.Show(); this.Close(); } } }
private void sauvegarde_Click(object sender, RoutedEventArgs e) { if (_user.ObservableCollection == null || _user.ObservableCollection.Count < 1) { MessageBox.Show("la liste est vide"); } else { MessageBox.Show("Vos données ont été souvegardé avec succès"); _user.Save(); } }
static void Main(string[] args) { #region DECLARATION Coordonnees c = new Coordonnees(150, 120); Coordonnees cDef = new Coordonnees(); POI poi = new POI(125, 38, "Test"); POI poiDef = new POI(); List <Coordonnees> maliste = new List <Coordonnees>(); { maliste.Add(c); maliste.Add(cDef); } Polyline pl = new Polyline(maliste, Color.FromRgb(255, 0, 0), 17); Polyline plDef = new Polyline(); Polygon pg = new Polygon("", Colors.Red, Colors.Blue, 0, maliste); Polygon pgDef = new Polygon(); List <CartoObj> listeCO = new List <CartoObj>() { c, cDef, poi, poiDef, pl, plDef, pg, pgDef }; // Polyline List <Coordonnees> listCD2 = new List <Coordonnees>(); { listCD2.Add(new Coordonnees(6, 9)); listCD2.Add(new Coordonnees(7, 2)); } List <Coordonnees> listCD4 = new List <Coordonnees>(); { listCD4.Add(new Coordonnees(8, 4)); listCD4.Add(new Coordonnees(3, 0)); listCD4.Add(new Coordonnees(2, 9)); } List <Coordonnees> listCD5 = new List <Coordonnees>(); { listCD5.Add(new Coordonnees(8, 3)); listCD5.Add(new Coordonnees(3, 3)); listCD5.Add(new Coordonnees(5, 7)); } Polyline pl1 = new Polyline(); Polyline pl2 = new Polyline(listCD2, Colors.Aqua, 5); Polyline pl3 = new Polyline(); Polyline pl4 = new Polyline(listCD4, Colors.Red, 7); Polyline pl5 = new Polyline(listCD5, Colors.Green, 9); List <Polyline> listePL = new List <Polyline>() { pl1, pl2, pl3, pl4, pl5 }; MyPersonalMapData mdataDef = new MyPersonalMapData(); mdataDef.OcICartoObj.Add(poiDef); // plante mdataDef.OcICartoObj.Add(pgDef); mdataDef.OcICartoObj.Add(plDef); Polygon prout = new Polygon("", Colors.RosyBrown, Colors.Teal, 15, listCD4); ObservableCollection <ICartoObj> OCtest = new ObservableCollection <ICartoObj>(); { OCtest.Add(prout); OCtest.Add(pl2); OCtest.Add(poiDef); } MyPersonalMapData mdata = new MyPersonalMapData("Jooris", "Yannick", "*****@*****.**", OCtest); // test depuis le 15/04 Polyline pl10 = new Polyline(Colors.White, 10); Polyline pl11 = new Polyline(Colors.Blue, 11); #endregion #region TESTS bool exit = false; ConsoleKeyInfo choix; while (!exit) { PrintMenu(); choix = Console.ReadKey(); Console.Clear(); switch (choix.Key) { case ConsoleKey.D1: #region TEST 01 Console.WriteLine("Test Coordonnées: "); Console.WriteLine(c.ToString()); Console.WriteLine(cDef.ToString()); Console.ReadKey(); Console.Clear(); Console.WriteLine("Test POI: "); Console.WriteLine(poi.ToString()); Console.WriteLine(poiDef.ToString()); Console.ReadKey(); Console.Clear(); Console.WriteLine("Test Polyline: "); pl.Draw(); plDef.Draw(); Console.ReadKey(); Console.Clear(); Console.WriteLine("Test Polygon: "); pg.Draw(); pgDef.Draw(); Console.ReadKey(); Console.Clear(); #endregion break; case ConsoleKey.D2: #region TEST 02 Console.WriteLine("Liste générique d'objets CartoObjs: "); foreach (CartoObj co in listeCO) { co.Draw(); } Console.ReadKey(); Console.Clear(); Console.WriteLine("Objets implémentant IPointy: "); foreach (CartoObj co in listeCO) { if (co is IPointy) { Console.WriteLine(co.ToString() + "\n"); } } Console.ReadKey(); Console.Clear(); Console.WriteLine("Objets n'implémentant pas IPointy: "); foreach (CartoObj co in listeCO) { if (!(co is IPointy)) { Console.WriteLine(co.ToString() + "\n"); } } Console.ReadKey(); Console.Clear(); #endregion break; case ConsoleKey.D3: #region TEST 03 Console.WriteLine("Liste générique de 5 objets Polyline: "); foreach (Polyline polyline in listePL) { polyline.Draw(); } Console.ReadKey(); Console.Clear(); Console.WriteLine("Tri par ordre croissant de longueur:"); listePL.Sort(); foreach (Polyline polyline in listePL) { polyline.Draw(); } Console.ReadKey(); Console.Clear(); Console.WriteLine("Tri par ordre croissant de surface:"); MyPolylineBoundingBoxComparer polylineCmp = new MyPolylineBoundingBoxComparer(); listePL.Sort(polylineCmp); foreach (Polyline polyline in listePL) { polyline.Draw(); } Console.ReadKey(); Console.Clear(); #endregion break; case ConsoleKey.D4: #region TEST 04 Console.WriteLine("Comparaison à un Polyline de référence:"); listePL.Add(pl2); foreach (Polyline polyline in listePL.FindAll(cmp => cmp.Equals(pl1))) { Console.WriteLine(polyline.ToString()); } listePL.Remove(pl2); Console.ReadKey(); Console.Clear(); Console.WriteLine("Polylines proches d'un point passé en paramètre:"); foreach (Polyline polyline in listePL) { if (polyline.IsPointClose(5, 5, 2)) { Console.WriteLine(polyline.ToString()); } } Console.ReadKey(); Console.Clear(); #endregion break; case ConsoleKey.D5: #region TEST 05 Console.WriteLine("Mécanisme qui trie une liste de CartoObjs selon le nombre de coordonnées:"); foreach (CartoObj co in listeCO) { Console.WriteLine(co.ToString() + "\n"); } Console.ReadKey(); Console.Clear(); MyNombreCoordonneesComparer ncComparer = new MyNombreCoordonneesComparer(); listeCO.Sort(ncComparer); foreach (CartoObj co in listeCO) { Console.WriteLine(co.ToString() + "\n"); } #endregion break; case ConsoleKey.D6: #region TEST 06 Console.WriteLine("Test d'objets MyPersonalMapData et de leurs méthodes"); Console.WriteLine(mdataDef.ToString() + "\n"); Console.WriteLine(mdata.ToString()); Console.ReadKey(); //Console.Clear(); Console.WriteLine("Test BinaryFormatter (save)"); Console.WriteLine("Saving..."); mdata.Save(@"C:\Users\Yannick\OneDrive\Prog\mapdata.dat"); Console.WriteLine("Done!"); Console.ReadKey(); //Console.Clear(); Console.WriteLine("Test BinaryFormatter (load)"); MyPersonalMapData fromfile = new MyPersonalMapData("Jooris", "Yannick", "3"); Console.WriteLine("Loading..."); fromfile.Load(@"C:\Users\Yannick\OneDrive\Prog\mapdata.dat"); Console.WriteLine("Done!"); Console.WriteLine(fromfile.ToString()); Console.ReadKey(); #endregion break; case ConsoleKey.D7: #region TEST 07 Console.WriteLine("Resultat CompareTo: " + pl10.CompareTo(pl11)); Console.ReadKey(); #endregion break; case ConsoleKey.D8: #region TEST 08 Console.ReadKey(); #endregion break; case ConsoleKey.Escape: exit = true; break; } } #endregion }
private void FileSave_Click(object sender, RoutedEventArgs e) { // we're saving the collection of a PersonalMapData object by using the Save() method, // here we're just letting the user select the file to save to string path = ""; try { SaveFileDialog saveDlg = new SaveFileDialog { DefaultExt = ".dat", InitialDirectory = CurrentDir }; saveDlg.ShowDialog(); path = saveDlg.FileName; // get filepath if (path != "") { currentUser.Save(path); /* Alright, now listen here buddy cause I got a story for you, * a story about the many ways this f*****g method drilled me another asshole. * You see, to serialize an object, you need to mark the class as [Serializable], easy enough, right ? * Well the teachers wanted us to use the Windows.Something.Media.Color class which is not serializable, * "but, don't you have to just write [NonSerialized] in front of it and it will ignore it ?" I hear you say ? * Well yes but also f**k no it's not that easy. See, I used autoimplemented properties because I'm a lazy f**k * (that is: public Color clr { get; set; } and then you don't have to add the properties, they're right there). * This means that putting [NonSerialized] in front of the now Properties and not field resulted in the compiler * telling me to F**K RIGHT OFF. * To the internet we go but I didn't really find any conclusive answers. * I ended up finding about that if I set the propertes apart from the variable declaration, * I could put [NonSerialized] without getting an error, yay ! * But now I'm not saving the Color properties from my objects... This fortunately had an easy solution as I simply * had to add a string to save the Color as that (a string) and I could serialize the string. * BUT WAIT, THERE'S MOOOOOOOOOOORE ! * Since this is a WPF app (that means it has a GUI), there are events going left and right and events in my classes, * events are not serializab... F**K! * Well of to the interwebz we go once again then, and I find that I simply have to put [field: NonSerialized] * to remove the compiler error, so I do that. * *gets a different compiler error* "ARE YOU JDKLFJDSFKLFJSDKLFJKLDJFLKRJFLKRJFLKSJFLKSDFJKLSDJF" * Turns out you apparently need a more recent version of the .NET framework than the one I'm working with, * since this is a school project, I wasn't sure about updating my solution to a more recent version of .NET framework. * So I used the same trick as for the Colors and implemented INotifyPropertyChanged explicitely and I wouldn't even have * to write [NonSerialized] anymore, great ! * ... * Except that broke the PropetyChanged thingelything f**k, basically, my databinded controls were not updating anymore * when a change was happening because I didn't learn to implement interfaces that way and I don't have time to learn. * So either my Serialization doesn't work or my UI is broken. * AND THEN AFTER ALL THAT * After days and hours, after choosing a non working Serialization rather than a broken UI, * I once again type [field: NonSerialized] in front of my event. * ... * It. * F*****g. * Works. * Not compiler error, no nothing, it just works. * Did I ever tell you what the definition of insanity is? * * It's 5:51am, f**k me */ } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public static void Main(string[] args) { Console.WriteLine("************COORDONNEES************\n"); Coordonnees A = new Coordonnees(40.25, 48.25); Coordonnees B = new Coordonnees(2.25, 12.25); Coordonnees C = new Coordonnees(3.45, 50.45); Coordonnees D = new Coordonnees(3.25, 10.45); Coordonnees Z = new Coordonnees(5.2, 11); A.latitude = 41.2; Console.WriteLine(A.ToString()); Console.WriteLine(C.ToString()); Console.WriteLine("\n**************POI**************\n"); POI E = new POI(); POI F = new POI("ici", 25.2, 1.25); POI Y = new POI("ok", 14, 2); Console.WriteLine(E.ToString()); Console.WriteLine(F.ToString()); Console.WriteLine("\n**************** Polyline******************\n"); Polyline Poly1 = new Polyline(new List <Coordonnees>() { A, D, Y }, 10, Color.FromArgb(255, 255, 255, 255), 1); Polyline Poly2 = new Polyline(new List <Coordonnees>() { E, F }, 15, Color.FromArgb(0, 0, 0, 0), 1); Polyline Poly3 = new Polyline(new List <Coordonnees>() { Z, A }, 11, Color.FromArgb(254, 0, 211, 0), 0); Polyline Poly4 = new Polyline(new List <Coordonnees>() { Z, B }, 11, Color.FromArgb(254, 158, 251, 0), 0); Console.WriteLine(Poly1.ToString()); Console.WriteLine(Poly2.ToString()); Console.WriteLine("\n**************Polygone**********************\n"); Polygone Polygone = new Polygone(new List <Coordonnees>() { A, D, E }, Color.FromArgb(165, 187, 195, 0), Color.FromArgb(165, 200, 140, 165), 1, 1); Polygone P5 = new Polygone(); Console.WriteLine(Polygone.ToString()); Console.WriteLine(P5.ToString()); Console.WriteLine("\n******************Liste CartObj********************\n"); List <CartoObj> ListeCart = new List <CartoObj>(); ListeCart.Add(A); ListeCart.Add(E); ListeCart.Add(F); ListeCart.Add(Poly1); ListeCart.Add(Poly2); //Afficher la liste ListeCart.ForEach(item => Console.WriteLine(item)); //Afficher ceux qui utilise ipointy Console.Write("\n****************On affiche ceux qui utilise IPOINTY*************\n"); foreach (CartoObj item in ListeCart) { if (!(item is IPointy)) { item.Draw(); } } Console.Write("\n****************On affiche ceux qui n'utilise pas IPOINTY*************\n"); foreach (CartoObj item in ListeCart) { if (item is IPointy) { item.Draw(); } } Console.WriteLine("\n****************Cree une liste de 5 polyline***********************\n"); List <Polyline> Polyliste = new List <Polyline>(); Polyliste.Add(Poly1); Polyliste.Add(Poly2); Polyliste.Add(Poly3); Polyliste.Add(Poly4); foreach (Polyline item in Polyliste) { Console.WriteLine(item.ToString()); } Polyliste.Sort(); Console.WriteLine("\n*************************** On Affiche la liste polyline triee -> longueur********************"); foreach (Polyline item in Polyliste) { Console.WriteLine(item.ToString()); } Console.WriteLine("\n*************************** On Affiche la liste polyline triee -> AIR Box********************"); MyPolylineBoundingBoxComparer Compare = new MyPolylineBoundingBoxComparer(); Polyliste.Sort(Compare); foreach (Polyline item in Polyliste) { Console.WriteLine(item.ToString()); } Console.WriteLine("\n******************Nombre de point Different Dans poly 1 : **************************"); int point = Poly1.NbPoints; Console.WriteLine("il y a : " + point + "point(s) différent"); Console.WriteLine("\n**************** Utilisation de IPointCLose*************"); Polyline P = Polyliste.Find(i => i.IsPointClose(25.2, 71, 1) == 1); //recherche dans la liste un element qui correspont if (P == null) // il ne sera pas proche { Console.WriteLine("Le point n'est pas proche."); } else { Console.WriteLine("Le point est proche ===>"); P.Draw(); } Polyline P2 = Polyliste.Find(i => i.IsPointClose(41.2, 48, 1) == 1); //recherche dans la liste un element qui correspont if (P2 == null) // il sera proche de la coordonnee A { Console.WriteLine("Le point n'est pas proche."); } else { Console.WriteLine("Le point est proche ===>"); P2.Draw(); } Console.WriteLine("\n*********************Test Longueur*******************\n"); double longueur = Poly1.LongueurPoly(); Console.WriteLine("Voici la longueur: " + longueur); Polyline PP = Polyliste.Find(i => i.LongueurPoly() == longueur); if (PP == null) { Console.WriteLine("Aucun point ne correspond a cette longueur"); } else { PP.Draw(); } Console.WriteLine("TestLoad et Save"); ObservableCollection <ICartoObj> ListeTest = new ObservableCollection <ICartoObj>(); ListeTest.Add(Poly1); MyPersonalMapData user = new MyPersonalMapData("Dresse", "Amarige", "email1"); user.ObservableCollection = ListeTest; user.Save(); Console.ReadKey(); }