/// <summary> /// Permet de charger les données depuis un fichier XML /// </summary> /// <param name="marsOMatic">Le fichier XML Mars-o-Matic</param> /// <param name="activitesRefs">Le fichier XML ActivitesRefs associé au fichier précédent</param> private void chargerXml(String marsOMatic, String activitesRefs) { XmlDocument mars = new XmlDocument(); mars.Load(marsOMatic); XmlDocument acts = new XmlDocument(); acts.Load(activitesRefs); Dictionary <int, Activite> activitesBase = new Dictionary <int, Activite>(); int nbElements = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("NbElements").InnerText); Progression p = new Progression(nbElements); p.Show(); /* Chargement données des activités de base */ XmlNodeList activites = acts.GetElementsByTagName("Activite"); foreach (XmlNode n in activites) { Activite a; int num = int.Parse(n.SelectSingleNode("Numero").InnerText); bool exterieure = bool.Parse(n.SelectSingleNode("Exterieure").InnerText); bool exploration = bool.Parse(n.SelectSingleNode("Exploration").InnerText); TypeActivite ta = new TypeActivite(n.SelectSingleNode("TypeActivite").SelectSingleNode("Nom").InnerText); if (exterieure) { if (exploration) { a = new ExplorationExterieure(ta, "", null, null, null, null); } else { a = new ExperienceExterieure(ta, "", null, null, null, null); } } else { a = new Activite(ta); } activitesBase.Add(num, a); p.incrementer(); } /* Chargement données */ int jour = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Jour").InnerText); int mois = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Mois").InnerText); int annee = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Annee").InnerText); int heures = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Heures").InnerText); int minutes = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Minutes").InnerText); int secondes = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Secondes").InnerText); this.debutMission = new DateTime(annee, mois, jour, heures, minutes, secondes); TimeMartien nb = TimeMartien.calculerJours(debutMission); int numJour = nb.getJours() + 1; if (numJour > 500) { numJour = 500; } XmlNodeList astronautesNodes = mars.GetElementsByTagName("Astronaute"); foreach (XmlNode n in astronautesNodes) { String nom = n.SelectSingleNode("Nom").InnerText; String prenom = n.SelectSingleNode("Prenom").InnerText; int age = int.Parse(n.SelectSingleNode("Age").InnerText); Astronaute a = new Astronaute(nom, prenom, age); Dictionary <int, Journee> joursMission = new Dictionary <int, Journee>(); a.setJourneesMission(joursMission); astronautes.Add(a); a.getJourneesMission().Clear(); astroList.Items.Add(a); // Ajout dans la liste => interface XmlNodeList missionNode = n.SelectSingleNode("JourneesMission").SelectNodes("Journee"); foreach (XmlNode nn in missionNode) { int num = int.Parse(nn.SelectSingleNode("Numero").InnerText); String etat = nn.SelectSingleNode("Etat").InnerText; IEtat etatJournee = new Passe(); if (etat.Equals("EnCours")) { etatJournee = new EnCours(); } else if (etat.Equals("Futur")) { etatJournee = new Futur(); } String rapport = nn.SelectSingleNode("Rapport").InnerText; Journee j = new Journee(num, rapport, etatJournee, false); j.getActivites().Clear(); joursMission.Add(num, j); XmlNodeList activitesNode = nn.SelectSingleNode("Activites").SelectNodes("Activite"); foreach (XmlNode nnn in activitesNode) { int numA = int.Parse(nnn.SelectSingleNode("Numero").InnerText); String transport = nnn.SelectSingleNode("Transport").InnerText; ITransport transportAct = null; if (transport.Equals("Scaphandre")) { transportAct = new Scaphandre(); } else if (transport.Equals("Vehicule")) { transportAct = new Vehicule(); } String description = nnn.SelectSingleNode("Description").InnerText; etat = nnn.SelectSingleNode("Etat").InnerText; IEtat etatAct = new Passe(); if (etat.Equals("EnCours")) { etatAct = new EnCours(); } else if (etat.Equals("Futur")) { etatAct = new Futur(); } int mD = int.Parse(nnn.SelectSingleNode("HeureDebut").InnerText); int mF = int.Parse(nnn.SelectSingleNode("HeureFin").InnerText); String xy = nnn.SelectSingleNode("XY").InnerText; int x = int.Parse(xy.Split(',')[0]); int y = int.Parse(xy.Split(',')[1]); Lieu l = new Lieu(x, y); Activite aBase = activitesBase[numA]; Activite act; if (aBase.isActiviteExterieure()) { if (aBase.isExperience()) { act = new ExperienceExterieure(aBase.getTypeActivite(), description, new TimeMartien(0, 0, mD, 0), new TimeMartien(0, 0, mF, 0), l, transportAct); } else { act = new ExplorationExterieure(aBase.getTypeActivite(), description, new TimeMartien(0, 0, mD, 0), new TimeMartien(0, 0, mF, 0), l, transportAct); } } else { act = new Activite(aBase.getTypeActivite(), description, new TimeMartien(0, 0, mD, 0), new TimeMartien(0, 0, mF, 0), l); } act.setDescription(description); act.setEtat(etatAct); j.ajouterActivite(act); p.incrementer(); } p.incrementer(); } p.incrementer(); } initialisationInterface(); astronauteSelectionne = astronautes[0]; journeesMission = astronauteSelectionne.getJourneesMission(); journeeActuelle = journeesMission[numJour]; modificationJourneeActuelle(numJour); changerPeriode(periode); verificationChangementPeriode(); mettreAJourHeures(); miseAJourEdt(journeesMission[journeeSelectionnee]); descriptionTexte.Text = journeesMission[journeeSelectionnee].getDescription(); astroList.SelectedItem = astronauteSelectionne; p.fermerFenetre(); }
/// <summary> /// Permet de charger les données depuis un fichier XML /// </summary> /// <param name="marsOMatic">Le fichier XML Mars-o-Matic</param> /// <param name="activitesRefs">Le fichier XML ActivitesRefs associé au fichier précédent</param> private void chargerXml(String marsOMatic, String activitesRefs) { XmlDocument mars = new XmlDocument(); mars.Load(marsOMatic); XmlDocument acts = new XmlDocument(); acts.Load(activitesRefs); Dictionary<int, Activite> activitesBase = new Dictionary<int, Activite>(); int nbElements = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("NbElements").InnerText); Progression p = new Progression(nbElements); p.Show(); /* Chargement données des activités de base */ XmlNodeList activites = acts.GetElementsByTagName("Activite"); foreach (XmlNode n in activites) { Activite a; int num = int.Parse(n.SelectSingleNode("Numero").InnerText); bool exterieure = bool.Parse(n.SelectSingleNode("Exterieure").InnerText); bool exploration = bool.Parse(n.SelectSingleNode("Exploration").InnerText); TypeActivite ta = new TypeActivite(n.SelectSingleNode("TypeActivite").SelectSingleNode("Nom").InnerText); if (exterieure) if (exploration) a = new ExplorationExterieure(ta, "", null, null, null, null); else a = new ExperienceExterieure(ta, "", null, null, null, null); else a = new Activite(ta); activitesBase.Add(num, a); p.incrementer(); } /* Chargement données */ int jour = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Jour").InnerText); int mois = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Mois").InnerText); int annee = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Annee").InnerText); int heures = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Heures").InnerText); int minutes = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Minutes").InnerText); int secondes = int.Parse(mars.SelectSingleNode("Donnees").SelectSingleNode("DebutMission").SelectSingleNode("Secondes").InnerText); this.debutMission = new DateTime(annee, mois, jour, heures, minutes, secondes); TimeMartien nb = TimeMartien.calculerJours(debutMission); int numJour = nb.getJours() + 1; if (numJour > 500) numJour = 500; XmlNodeList astronautesNodes = mars.GetElementsByTagName("Astronaute"); foreach (XmlNode n in astronautesNodes) { String nom = n.SelectSingleNode("Nom").InnerText; String prenom = n.SelectSingleNode("Prenom").InnerText; int age = int.Parse(n.SelectSingleNode("Age").InnerText); Astronaute a = new Astronaute(nom, prenom, age); Dictionary<int, Journee> joursMission = new Dictionary<int, Journee>(); a.setJourneesMission(joursMission); astronautes.Add(a); a.getJourneesMission().Clear(); astroList.Items.Add(a); // Ajout dans la liste => interface XmlNodeList missionNode = n.SelectSingleNode("JourneesMission").SelectNodes("Journee"); foreach (XmlNode nn in missionNode) { int num = int.Parse(nn.SelectSingleNode("Numero").InnerText); String etat = nn.SelectSingleNode("Etat").InnerText; IEtat etatJournee = new Passe(); if (etat.Equals("EnCours")) etatJournee = new EnCours(); else if (etat.Equals("Futur")) etatJournee = new Futur(); String rapport = nn.SelectSingleNode("Rapport").InnerText; Journee j = new Journee(num, rapport, etatJournee, false); j.getActivites().Clear(); joursMission.Add(num, j); XmlNodeList activitesNode = nn.SelectSingleNode("Activites").SelectNodes("Activite"); foreach (XmlNode nnn in activitesNode) { int numA = int.Parse(nnn.SelectSingleNode("Numero").InnerText); String transport = nnn.SelectSingleNode("Transport").InnerText; ITransport transportAct = null; if (transport.Equals("Scaphandre")) transportAct = new Scaphandre(); else if (transport.Equals("Vehicule")) transportAct = new Vehicule(); String description = nnn.SelectSingleNode("Description").InnerText; etat = nnn.SelectSingleNode("Etat").InnerText; IEtat etatAct = new Passe(); if (etat.Equals("EnCours")) etatAct = new EnCours(); else if (etat.Equals("Futur")) etatAct = new Futur(); int mD = int.Parse(nnn.SelectSingleNode("HeureDebut").InnerText); int mF = int.Parse(nnn.SelectSingleNode("HeureFin").InnerText); String xy = nnn.SelectSingleNode("XY").InnerText; int x = int.Parse(xy.Split(',')[0]); int y = int.Parse(xy.Split(',')[1]); Lieu l = new Lieu(x, y); Activite aBase = activitesBase[numA]; Activite act; if (aBase.isActiviteExterieure()) if (aBase.isExperience()) act = new ExperienceExterieure(aBase.getTypeActivite(), description, new TimeMartien(0, 0, mD, 0), new TimeMartien(0, 0, mF, 0), l, transportAct); else act = new ExplorationExterieure(aBase.getTypeActivite(), description, new TimeMartien(0, 0, mD, 0), new TimeMartien(0, 0, mF, 0), l, transportAct); else act = new Activite(aBase.getTypeActivite(), description, new TimeMartien(0, 0, mD, 0), new TimeMartien(0, 0, mF, 0), l); act.setDescription(description); act.setEtat(etatAct); j.ajouterActivite(act); p.incrementer(); } p.incrementer(); } p.incrementer(); } initialisationInterface(); astronauteSelectionne = astronautes[0]; journeesMission = astronauteSelectionne.getJourneesMission(); journeeActuelle = journeesMission[numJour]; modificationJourneeActuelle(numJour); changerPeriode(periode); verificationChangementPeriode(); mettreAJourHeures(); miseAJourEdt(journeesMission[journeeSelectionnee]); descriptionTexte.Text = journeesMission[journeeSelectionnee].getDescription(); astroList.SelectedItem = astronauteSelectionne; p.fermerFenetre(); }