示例#1
0
        private void btn_Down_Click(object sender, EventArgs e)
        {
            if (lstVew_Steps.SelectedIndices.Count > 0)
            {
                int selected = lstVew_Steps.SelectedIndices[0];
                if (selected < lstVew_Steps.Items.Count - 1)
                {
                    //Save the lower step to move up later.
                    ListViewItem item = (ListViewItem)lstVew_Steps.Items[selected + 1].Clone();

                    //Keep the order of Ids the same.
                    item.Text = lstVew_Steps.Items[selected].Text;
                    lstVew_Steps.Items[selected].Text = lstVew_Steps.Items[selected + 1].Text;

                    //Remove the item we saved
                    lstVew_Steps.Items.RemoveAt(selected + 1);

                    //Move the step down.
                    lstVew_Steps.Items.Insert(selected, item);


                    //Save the lower step to move down later.
                    //Make a copy of the upper element.
                    Etape etp = new Etape();
                    etp.setId(this.procedure.steps[selected + 1].getId());
                    etp.setName(this.procedure.steps[selected + 1].getName());
                    etp.setDescription(this.procedure.steps[selected + 1].getDescription());
                    etp.setprocedure(this.procedure.steps[selected + 1].getprocedure());
                    foreach (Object3d obj in this.procedure.steps[selected + 1].getObjectList())
                    {
                        etp.addObject3d(obj);
                    }

                    //Keep the order of Ids the same.
                    etp.setId(this.procedure.steps[selected].getId());
                    this.procedure.steps[selected].setId(this.procedure.steps[selected + 1].getId());

                    //Remove the item we saved
                    this.procedure.steps.RemoveAt(selected + 1);

                    //Move the step up.
                    this.procedure.steps.Insert(selected, etp);

                    //Use this variable so that the app delete the old steps and reinsert them in the specified order.
                    StepsRemoved = true;
                    //MessageBox.Show("selected-1: " + this.procedure.steps[selected - 1].getId() + "  selected: " + this.procedure.steps[selected].getId());
                }
            }
            else
            {
                MessageBox.Show(this, "Sélectionner une étape SVP.", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        /// <summary>
        /// Get the list of steps for a specified procedure.
        /// </summary>
        /// <param name="Id">The id of the procedure</param>
        /// <returns></returns>
        public static List <Etape> GetByProcedure(int Id)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            List <Etape> steps = new List <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 crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();
                /* On crée ici l'expression XPath de recherche d'expert à  partir de l'id */

                //To eleminate the case sensetive in XPath we use the methode translate().
                string ExpXPath = "//etape[procedure='" + Id + "']";

                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                /* On vérifie si la recherche a été fructueuse */
                if (Nodes.Count != 0)
                {
                    while (Nodes.MoveNext()) // NOTE: Necéssaire pour se placer sur le noeud recherché
                    {
                        Etape step = new Etape();
                        /* Encodage des données dans la classe Expert */
                        step.setId(Convert.ToInt32(Nodes.Current.GetAttribute("id", ""))); /* Pas besoin de chercher cette donnée vu que c'est notre
                                                                                            * critère de recherche, on peut donc directement
                                                                                            * l'encoder. */
                        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();                                        // On se déplace sur le noeud suivant "Objets"
                        //
                        //Get all the objects of the current step.
                        //
                        foreach (Object3d obj in XML3dObject.GetStepObjects(step.getId()))
                        {
                            step.addObject3d(obj);
                            //System.Windows.Forms.MessageBox.Show("obj.Id: " + obj.getId() + "\nPosX: " + obj.getPosition().X
                            //    + "\nPosY: " + obj.getPosition().Y + "\nPosZ: " + obj.getPosition().Z, "XMLStep.GetByProcedure");
                        }
                        Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Procedure"
                        //step.setprocedure(Convert.ToInt32(Nodes.Current.Value));
                        steps.Add(step);
                    }
                }
            }
            catch (System.IO.FileNotFoundException x) { }
            catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.ToString());
                return(null);
            }
            /* Renvoi de toutes les données dans une instance de la classe "Client" */
            return(steps);
        }