コード例 #1
0
ファイル: XMLFailure.cs プロジェクト: AbdBelf/MARS_project
        /// <summary>
        /// inserts a panne to "panne.xml".
        /// </summary>
        /// <param name="expert">The object holding the data</param>
        /// <returns></returns>
        private static bool insert(Panne failure)
        {
            try
            {
                XmlDocument       XmlDoc = new XmlDocument();
                XPathNavigator    Navigator;
                XPathNodeIterator Nodes;
                Int32             ID; /* Variable utilisée pour savoir quel est l'ID qu'il faut affecter au nouveau
                                       * noeud créé */
                string rslt = Helper.service.LoadFile("panne.xml").ToString();

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


                XmlDoc.Load(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                Navigator = XmlDoc.CreateNavigator();

                /* Recherche du noeud MaxID pour déterminer quelle sera l'ID du nouveau
                 * procedure. */
                string ExpXPath = "//MaxID";
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                Nodes.MoveNext();
                /* On place l'ID le plus élevé du document dans la variable ID */
                ID = Nodes.Current.ValueAsInt;

                /* On incrémente la valeur du noeud MaxID car une fois notre nouveau noeud
                 * créé, l'ID le plus élevé du document sera aussi incrémenté */
                Nodes.Current.SetValue((ID + 1).ToString());
                /* On se place sur le noeud ayant l'ID le plus élevé */
                ExpXPath = "//panne[@id='" + ID.ToString() + "']";
                Nodes    = Navigator.Select(Navigator.Compile(ExpXPath));
                if (Nodes.Count != 0)
                {
                    Nodes.MoveNext();
                    /* On crée le noeud principal (panne). */
                    Nodes.Current.InsertElementAfter("", "panne", "", "");
                    /* On se place sur le noeud ainsi créé. */
                    Nodes.Current.MoveToNext(XPathNodeType.Element);
                    ID++; /* On incrémente ID pour que sa valeur soit identique à celle se
                           * trouvant dans le noeud MaxID. */
                    /* Encodage des données */
                    Nodes.Current.CreateAttribute("", "id", "", ID.ToString());
                    Nodes.Current.AppendChildElement("", "libelle", "", failure.getName());
                    Nodes.Current.AppendChildElement("", "description", "", failure.getDescription());
                    Nodes.Current.AppendChildElement("", "type_panne", "", failure.getTypePanne().getId().ToString());
                    //XmlDoc.Save((Stream)Helper.service.LoadFile("panne.xml");
                    Helper.service.SaveXmlFile("panne.xml", XmlDoc);
                }
                else
                {
                    return(false);
                }
            }
            catch (System.IO.FileNotFoundException x) { }catch (Exception x) {// System.Windows.Forms.MessageBox.Show(x.ToString());
            }
            return(true);
        }
コード例 #2
0
ファイル: XMLFailure.cs プロジェクト: AbdBelf/MARS_project
        /// <summary>
        /// Creates the file "panne.xml" and inserts the first panne to it.
        /// </summary>
        /// <param name="expert">The object holding the data.</param>
        /// <returns></returns>
        private static bool firstAdd(Panne failure)
        {
            try
            {
                XmlWriterSettings wSettings = new XmlWriterSettings();
                wSettings.Indent = true;
                MemoryStream ms = new MemoryStream();
                XmlWriter    xw = XmlWriter.Create(ms, wSettings);// Write Declaration
                xw.WriteStartDocument();

                // Write the root node
                xw.WriteStartElement("Pannes");//<Pannes>

                // Write the expert and the expert elements
                xw.WriteStartElement("panne");//<panne>
                xw.WriteStartAttribute("id");
                xw.WriteString("0");
                xw.WriteEndAttribute();
                //----------------
                xw.WriteStartElement("libelle");     //<libelle>
                xw.WriteString(failure.getName());
                xw.WriteEndElement();                //</libelle>
                //-----------------
                xw.WriteStartElement("description"); //<description>
                xw.WriteString(failure.getDescription());
                xw.WriteEndElement();                //</description>
                //-----------------
                xw.WriteStartElement("type_panne");  //<type_panne>
                xw.WriteString(failure.getTypePanne().getId().ToString());
                xw.WriteEndElement();                //</type_panne>
                //-----------------
                xw.WriteEndElement();                //</panne>

                xw.WriteStartElement("MaxID");       //<MaxID>
                xw.WriteString("0");
                xw.WriteEndElement();                //</MaxID>

                // Close the document
                xw.WriteEndDocument();//</Pannes>

                // Flush the write
                xw.Flush();

                Byte[] buffer = new Byte[ms.Length];
                buffer = ms.ToArray();
                string xmlOutput = System.Text.Encoding.UTF8.GetString(buffer);

                //File.WriteAllText((Stream)Helper.service.LoadFile("panne.xml", xmlOutput);
                Helper.service.CreateXmlFile("panne.xml", xmlOutput);
            }
            catch (System.IO.FileNotFoundException x) { }
            catch (Exception x) {// System.Windows.Forms.MessageBox.Show(x.ToString());
            }
            return(true);
        }
コード例 #3
0
ファイル: XMLFailure.cs プロジェクト: AbdBelf/MARS_project
        /// <summary>
        /// Modifies the Dailure Data.
        /// </summary>
        /// <param name="login">The id of the target Failure object.</param>
        /// <param name="admin">The object that holds the new data.</param>
        /// <returns></returns>
        public static bool Update(int id, Panne failure)
        {
            try
            {
                /* On utilise un XmlDocument et non un XPathDocument car ce dernier ne permet
                 * pas l'édition des données XML. */
                XmlDocument       XmlDoc = new XmlDocument();
                XPathNavigator    Navigator;
                XPathNodeIterator Nodes;
                string            rslt = Helper.service.LoadFile("panne.xml").ToString();

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


                XmlDoc.Load(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                Navigator = XmlDoc.CreateNavigator();
                string ExpXPath = "//panne[@id='" + id.ToString() + "']";
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                if (Nodes.Count != 0)
                {
                    /* Encodage des nouvelles données */
                    Nodes.MoveNext();
                    Nodes.Current.MoveToFirstAttribute();
                    Nodes.Current.SetValue(failure.getId().ToString());
                    Nodes.Current.MoveToParent();

                    Nodes.Current.MoveToFirstChild();
                    //System.Windows.Forms.MessageBox.Show(Nodes.Current.Name.ToString() + " | " + Nodes.Current.Value.ToString());
                    Nodes.Current.SetValue(failure.getName());
                    Nodes.Current.MoveToNext(XPathNodeType.Element);
                    Nodes.Current.SetValue(failure.getDescription());
                    Nodes.Current.MoveToNext(XPathNodeType.Element);
                    Nodes.Current.SetValue(failure.getTypePanne().getId().ToString());
                    //XmlDoc.Save((Stream)Helper.service.LoadFile("panne.xml");
                    Helper.service.SaveXmlFile("panne.xml", XmlDoc);
                }
                else
                {
                    return(false);
                }
            }
            catch (System.IO.FileNotFoundException x) { }catch (Exception x)
            { System.Windows.Forms.MessageBox.Show(x.ToString()); }
            return(true);
        }
コード例 #4
0
        public frm_AddProcedure(TypePanne type, Panne failure, Procedure procedure, Operation operation)
        {
            InitializeComponent();

            //Initialize the attributes.
            failureType       = type;
            Failure           = failure;
            this.procedure    = procedure;
            this.StepsRemoved = false;
            this._Operation   = operation;

            //Use the GUI to add a new procedure.
            if (this._Operation == Operation.AddNew)
            {
                if (this.procedure == null)
                {
                    this.procedure = new Procedure();
                    //Create the list of steps for the current procedure.
                    this.procedure.steps = new List <Etape>();
                }
            }
            //Use the GUI to update a procedure.
            else
            {
                if (type != null)
                {
                    //txtBx_FailureType.ReadOnly = true;
                    //txtBx_FailureType.Enabled = false;
                    txtBx_FailureType.Text = failureType.getName();
                    FailureTypeDesc        = type.getDescription();
                }
                else
                {
                    MessageBox.Show("Type est null", "frm_AddProcedure.Constructor");
                    throw new ArgumentNullException();
                }
                if (failure != null)
                {
                    //txtBx_Failure.ReadOnly = true;
                    //txtBx_Failure.Enabled = false;
                    txtBx_Failure.Text = failure.getName();
                    FailureDesc        = failure.getDescription();
                }
                else
                {
                    MessageBox.Show("Panne est null", "frm_AddProcedure.Constructor");
                    throw new ArgumentNullException();
                }

                if (this.procedure != null)
                {
                    txtBx_Title.Text       = this.procedure.getName();
                    txtBx_Description.Text = this.procedure.getDescription();


                    if (this.procedure.steps != null && this.procedure.steps.Count > 0)
                    {
                        foreach (Etape step in this.procedure.getEtapes())
                        {
                            //Fill the list view with the step's data.
                            ListViewItem item = new ListViewItem(new string[] { step.getId().ToString(), step.getName(), step.getDescription() });
                            lstVew_Steps.Items.Add(item);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Procedure est null", "frm_AddProcedure.Constructor");
                    throw new ArgumentNullException();
                }
            }
            //Set the value of the Id textBox.
            txtBx_Id.Text = this.procedure.getId().ToString();

            #region Load the form text fields to Fields list.
            Fields.Add(txtBx_Title);
            if (failureType == null)
            {
                Fields.Add(txtBx_FailureType);
            }
            if (Failure == null)
            {
                Fields.Add(txtBx_Failure);
            }
            #endregion

            #region Load the form labels to FieldLabels list.
            FieldLabels.Add(lbl_Title);
            if (failureType == null)
            {
                FieldLabels.Add(lbl_FailureType);
            }
            if (Failure == null)
            {
                FieldLabels.Add(lbl_Failure);
            }
            #endregion
        }