Ejemplo n.º 1
0
        /// <summary>
        /// Returns the list of the types of failure.
        /// </summary>
        /// <returns></returns>
        public static List<TypePanne> GetAllFailureTypes()
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            List<TypePanne> types = new List<TypePanne>();
            TypePanne type = new TypePanne();
            try
            {
                string rslt = Helper.service.LoadFile("typepanne.xml").ToString();

                StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                sw.Write(rslt);
                sw.Close();

                //XPathDocument XPathDocu = new XPathDocument((Stream)Helper.service.LoadFile("Experts.xml"));
                XPathDocument XPathDocu = new XPathDocument(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                XPathNavigator Navigator;
                XPathNodeIterator Nodes;
                /* On affecte false à  la
                /* On crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();

                string ExpXPath = "//type";
                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                /* On vérifie si la recherche a été fructueuse */
                //System.Windows.Forms.MessageBox.Show("Node.count. "+Nodes.Count,"XMLFailureType.GetAllFailureTypes");
                if (Nodes.Count != 0)
                {
                    // NOTE: Necéssaire pour se placer sur le noeud recherché
                    /* Encodage des données dans la classe Etape */

                    int tillCount = 0;
                    while (tillCount < Nodes.Count)
                    {
                        Nodes.MoveNext();
                        type = new TypePanne();
                        type.setId(Convert.ToInt32(Nodes.Current.GetAttribute("id", "")));
                        //System.Windows.Forms.MessageBox.Show("Attrib. " + Nodes.Current.GetAttribute("id", ""), "XMLFailureType.GetAllFailureTypes");
                        Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                   * enfant "Libelle" */
                        //System.Windows.Forms.MessageBox.Show("Current: " + Nodes.Current.Name + "    Current.Value " + Nodes.Current.Value, "XMLFailureType.GetAllFailureTypes");
                        type.setName(Nodes.Current.Value);
                        //System.Windows.Forms.MessageBox.Show("libelle. " + Nodes.Current.Value, "XMLFailureType.GetAllFailureTypes");
                        Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Description"
                        //System.Windows.Forms.MessageBox.Show("Description. " + Nodes.Current.Value, "XMLFailureType.GetAllFailureTypes");
                        type.setDescription(Nodes.Current.Value);
                        //System.Windows.Forms.MessageBox.Show("Type.Description. " +type.getDescription() , "XMLFailureType.GetAllFailureTypes");
                        types.Add(type);
                        tillCount++;
                        Nodes.Current.MoveToParent();
                    }
                }
                /* Si aucun expert n'a été trouvé */
                else
                {
                    type = null;
                }
            }
            catch (System.IO.FileNotFoundException x) { }
            catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.ToString());
            }
            /* Renvoi de toutes les données dans une instance de la classe "etape" */
            return types;
        }
Ejemplo n.º 2
0
        public static TypePanne GetById(int id)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            TypePanne type = new TypePanne();
            try
            {
                string rslt = Helper.service.LoadFile("typepanne.xml").ToString();

                StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                sw.Write(rslt);
                sw.Close();

                //XPathDocument XPathDocu = new XPathDocument((Stream)Helper.service.LoadFile("Experts.xml"));
                XPathDocument XPathDocu = new XPathDocument(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                XPathNavigator Navigator;
                XPathNodeIterator Nodes;
                /* On affecte false à  la
                /* On crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();

                string ExpXPath = "//type[@id='" + id + "']";
                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                /* On vérifie si la recherche a été fructueuse */
                if (Nodes.Count != 0)
                {
                    Nodes.MoveNext(); // NOTE: Necéssaire pour se placer sur le noeud recherché
                    /* Encodage des données dans la classe Etape */
                    type.setId(id);
                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                   * enfant "Libelle" */
                    type.setName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Description"
                    type.setDescription(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                }
                /* Si aucun expert n'a été trouvé */
                else
                {
                    type = null;
                }
            }
            catch (System.IO.FileNotFoundException x) { }catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.ToString());
            }
            /* Renvoi de toutes les données dans une instance de la classe "etape" */
            return type;
        }