示例#1
0
        /// <summary>
        /// Gets the step by Id.
        /// </summary>
        /// <param name="id">The id of the targeted Step.</param>
        /// <returns></returns>
        public static Etape GetById(int id)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            Etape step = new Etape();
            try
            {
                string rslt = Helper.service.LoadFile("etape.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 = "//etape[@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 */
                    step.setId(id);
                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                   * enfant "Libelle" */
                    step.setName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Description"
                    step.setDescription(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    //
                    //Get all the objects
                    //
                    step.setObjectList(XML3dObject.GetStepObjects(id));
                    Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Procedure"
                    step.setprocedure(XMLProcedure.GetById(Convert.ToInt32(Nodes.Current.Value)));
                }
                /* Si aucun expert n'a été trouvé */
                else
                {
                    step = 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 step;
        }