/// <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 générer les fichiers XML /// </summary> private void genererDocXML() { int nbElements = this.astronautes.Count; foreach (Astronaute a in this.astronautes) a.nbJournees(ref nbElements); nbElements += CalendrierMission.domaines.Count; foreach (Domaine d in CalendrierMission.domaines) d.nbTypeActivite(ref nbElements); Progression progression = new Progression(nbElements); progression.Show(); XmlDocument xmlDoc = new XmlDocument(); XmlDocument xmlDocActs = new XmlDocument(); XmlNode donnees = xmlDoc.CreateElement("Donnees"); xmlDoc.AppendChild(donnees); XmlNode acts = xmlDocActs.CreateElement("Activites"); xmlDocActs.AppendChild(acts); XmlNode debutMission = xmlDoc.CreateElement("DebutMission"); donnees.AppendChild(debutMission); XmlNode jour = xmlDoc.CreateElement("Jour"); XmlNode mois = xmlDoc.CreateElement("Mois"); XmlNode annee = xmlDoc.CreateElement("Annee"); XmlNode heures = xmlDoc.CreateElement("Heures"); XmlNode minutes = xmlDoc.CreateElement("Minutes"); XmlNode secondes = xmlDoc.CreateElement("Secondes"); debutMission.AppendChild(jour); debutMission.AppendChild(mois); debutMission.AppendChild(annee); debutMission.AppendChild(heures); debutMission.AppendChild(minutes); debutMission.AppendChild(secondes); jour.InnerText = this.debutMission.Day.ToString(); mois.InnerText = this.debutMission.Month.ToString(); annee.InnerText = this.debutMission.Year.ToString(); heures.InnerText = this.debutMission.Hour.ToString(); minutes.InnerText = this.debutMission.Minute.ToString(); secondes.InnerText = this.debutMission.Second.ToString(); XmlNode nbE = xmlDoc.CreateElement("NbElements"); donnees.AppendChild(nbE); nbE.InnerText = nbElements.ToString(); XmlNode astronautes = xmlDoc.CreateElement("Astronautes"); donnees.AppendChild(astronautes); foreach (Astronaute a in this.astronautes) { XmlNode astronaute = xmlDoc.CreateElement("Astronaute"); astronautes.AppendChild(astronaute); a.genererXML(xmlDoc, xmlDocActs, astronaute, acts, progression); progression.incrementer(); } if (!System.IO.Directory.Exists("Donnees")) System.IO.Directory.CreateDirectory("Donnees"); XmlDocument xmlDocDom = new XmlDocument(); XmlNode domaines = xmlDocDom.CreateElement("Domaines"); xmlDocDom.AppendChild(domaines); foreach (Domaine d in CalendrierMission.domaines) { XmlNode domaine = xmlDocDom.CreateElement("Domaine"); domaines.AppendChild(domaine); XmlNode nomD = xmlDocDom.CreateElement("NomDom"); domaine.AppendChild(nomD); nomD.InnerText = d.getNom(); XmlNode couleur = xmlDocDom.CreateElement("Couleur"); domaine.AppendChild(couleur); XmlNode r = xmlDocDom.CreateElement("R"); couleur.AppendChild(r); r.InnerText = d.getCouleur()[0].ToString(); XmlNode g = xmlDocDom.CreateElement("G"); couleur.AppendChild(g); g.InnerText = d.getCouleur()[1].ToString(); XmlNode b = xmlDocDom.CreateElement("B"); couleur.AppendChild(b); b.InnerText = d.getCouleur()[2].ToString(); XmlNode typeActivite = xmlDocDom.CreateElement("TypeActivite"); domaine.AppendChild(typeActivite); foreach (TypeActivite ta in d.getActivites()) { XmlNode nomType = xmlDocDom.CreateElement("NomTA"); typeActivite.AppendChild(nomType); nomType.InnerText = ta.getNom(); progression.incrementer(); } progression.incrementer(); } xmlDocDom.Save("Donnees/Domaines.xml"); xmlDoc.Save("Donnees/Mars-o-Matic_" + this.debutMission.Day + "_" + this.debutMission.Month + "_" + this.debutMission.Year + ".xml"); xmlDocActs.Save("Donnees/ActivitesRefs_" + this.debutMission.Day + "_" + this.debutMission.Month + "_" + this.debutMission.Year + ".xml"); progression.fermerFenetre(); }
/// <summary> /// Permet de générer les fichiers XML /// </summary> private void genererDocXML() { int nbElements = this.astronautes.Count; foreach (Astronaute a in this.astronautes) { a.nbJournees(ref nbElements); } nbElements += CalendrierMission.domaines.Count; foreach (Domaine d in CalendrierMission.domaines) { d.nbTypeActivite(ref nbElements); } Progression progression = new Progression(nbElements); progression.Show(); XmlDocument xmlDoc = new XmlDocument(); XmlDocument xmlDocActs = new XmlDocument(); XmlNode donnees = xmlDoc.CreateElement("Donnees"); xmlDoc.AppendChild(donnees); XmlNode acts = xmlDocActs.CreateElement("Activites"); xmlDocActs.AppendChild(acts); XmlNode debutMission = xmlDoc.CreateElement("DebutMission"); donnees.AppendChild(debutMission); XmlNode jour = xmlDoc.CreateElement("Jour"); XmlNode mois = xmlDoc.CreateElement("Mois"); XmlNode annee = xmlDoc.CreateElement("Annee"); XmlNode heures = xmlDoc.CreateElement("Heures"); XmlNode minutes = xmlDoc.CreateElement("Minutes"); XmlNode secondes = xmlDoc.CreateElement("Secondes"); debutMission.AppendChild(jour); debutMission.AppendChild(mois); debutMission.AppendChild(annee); debutMission.AppendChild(heures); debutMission.AppendChild(minutes); debutMission.AppendChild(secondes); jour.InnerText = this.debutMission.Day.ToString(); mois.InnerText = this.debutMission.Month.ToString(); annee.InnerText = this.debutMission.Year.ToString(); heures.InnerText = this.debutMission.Hour.ToString(); minutes.InnerText = this.debutMission.Minute.ToString(); secondes.InnerText = this.debutMission.Second.ToString(); XmlNode nbE = xmlDoc.CreateElement("NbElements"); donnees.AppendChild(nbE); nbE.InnerText = nbElements.ToString(); XmlNode astronautes = xmlDoc.CreateElement("Astronautes"); donnees.AppendChild(astronautes); foreach (Astronaute a in this.astronautes) { XmlNode astronaute = xmlDoc.CreateElement("Astronaute"); astronautes.AppendChild(astronaute); a.genererXML(xmlDoc, xmlDocActs, astronaute, acts, progression); progression.incrementer(); } if (!System.IO.Directory.Exists("Donnees")) { System.IO.Directory.CreateDirectory("Donnees"); } XmlDocument xmlDocDom = new XmlDocument(); XmlNode domaines = xmlDocDom.CreateElement("Domaines"); xmlDocDom.AppendChild(domaines); foreach (Domaine d in CalendrierMission.domaines) { XmlNode domaine = xmlDocDom.CreateElement("Domaine"); domaines.AppendChild(domaine); XmlNode nomD = xmlDocDom.CreateElement("NomDom"); domaine.AppendChild(nomD); nomD.InnerText = d.getNom(); XmlNode couleur = xmlDocDom.CreateElement("Couleur"); domaine.AppendChild(couleur); XmlNode r = xmlDocDom.CreateElement("R"); couleur.AppendChild(r); r.InnerText = d.getCouleur()[0].ToString(); XmlNode g = xmlDocDom.CreateElement("G"); couleur.AppendChild(g); g.InnerText = d.getCouleur()[1].ToString(); XmlNode b = xmlDocDom.CreateElement("B"); couleur.AppendChild(b); b.InnerText = d.getCouleur()[2].ToString(); XmlNode typeActivite = xmlDocDom.CreateElement("TypeActivite"); domaine.AppendChild(typeActivite); foreach (TypeActivite ta in d.getActivites()) { XmlNode nomType = xmlDocDom.CreateElement("NomTA"); typeActivite.AppendChild(nomType); nomType.InnerText = ta.getNom(); progression.incrementer(); } progression.incrementer(); } xmlDocDom.Save("Donnees/Domaines.xml"); xmlDoc.Save("Donnees/Mars-o-Matic_" + this.debutMission.Day + "_" + this.debutMission.Month + "_" + this.debutMission.Year + ".xml"); xmlDocActs.Save("Donnees/ActivitesRefs_" + this.debutMission.Day + "_" + this.debutMission.Month + "_" + this.debutMission.Year + ".xml"); progression.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(); }