public Etape(int id, String name, String description, Procedure procedure) { this.id = id; this.name = name; this.description = description; this.procedure = procedure; objects3d = new List<Object3d>(); }
public frm_AddStep(Etape prevStep, Etape step,Procedure procedure,Operation operation) { InitializeComponent(); this.Step = step; this.Procedure = procedure; this._Operation = operation; this.prevStep = prevStep; }
public usrStep(RenderForm parent,usrProcedure brother,Etape prevStep, Etape step,Procedure procedure,Operation operation) { InitializeComponent(); pParent = parent; Brother = brother; this.Step = step; this.Procedure = procedure; this._Operation = operation; this.prevStep = prevStep; }
public static bool Add(Procedure procedure) { //If the file exists we insert a new element. if (Helper.service.FileExists("procedure.xml")) { //System.Windows.Forms.MessageBox.Show("Insert","XMLProcedure.Add"); return insert(procedure); } else //Otherwise we create the file and insert the first elemet. { //System.Windows.Forms.MessageBox.Show("FirstAdd", "XMLProcedure.Add"); return firstAdd(procedure); } }
public void addProcedure(Procedure procedure) { procedure.setPanne(this); procedures.Add(procedure); }
public void removeProcedure(Procedure procedure) { procedure.setPanne(null); procedures.Remove(procedure); }
public usrProcedure(RenderForm parent, TypePanne type, Panne failure, Procedure procedure, Operation operation) { InitializeComponent(); this.pParent = parent; //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 }
private void btn_SendProcedure_Click(object sender, EventArgs e) { //frm_ListOf frm = new frm_ListOf(Subject.ProcedureSbjct); //frm.ShowDialog(); //if (frm.Tag != null) { //Procedure proc = (Procedure)frm.Tag; //Helper.service.SendProcedure(login, proc.getId()); if (this.CreatedProcedure != null) { Helper.service.SendProcedure(login, this.CreatedProcedure.getId()); MessageBox.Show(this, "Procedure envoyée avec succès.", "Message d'information", MessageBoxButtons.OK, MessageBoxIcon.Information); this.CreatedProcedure = null; } else { DialogResult dr = MessageBox.Show(this, "Vous n'avez pas créé des procedures, voullez vous choisir une?.", "Message d'erreur", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dr == DialogResult.Yes) { frm_ListOf frm = new frm_ListOf(Subject.ProcedureSbjct); frm.ShowDialog(); if (frm.Tag != null) { Procedure proc = (Procedure)frm.Tag; Helper.service.SendProcedure(login, proc.getId()); MessageBox.Show(this, "Procedure envoyée avec succès.", "Message d'information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }
/// <summary> /// Returns the list of the procedures. /// </summary> /// <returns></returns> public static List<Procedure> GetAllProcedures() { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ List<Procedure> procedures = new List<Procedure>(); Procedure procedure = new Procedure(); try { string rslt = Helper.service.LoadFile("procedure.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 = "//procedure"; /* 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,"XMLProcedure.GetAllProcedures"); 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(); procedure = new Procedure(); procedure.setId(Convert.ToInt32(Nodes.Current.GetAttribute("id", ""))); //System.Windows.Forms.MessageBox.Show("Attrib. " + Nodes.Current.GetAttribute("id", ""), "XMLProcedure.GetAllProcedures"); 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, "XMLProcedure.GetAllProcedures"); procedure.setName(Nodes.Current.Value); //System.Windows.Forms.MessageBox.Show("libelle. " + Nodes.Current.Value, "XMLProcedure.GetAllProcedures"); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Description" //System.Windows.Forms.MessageBox.Show("Description. " + Nodes.Current.Value, "XMLProcedure.GetAllProcedures"); procedure.setDescription(Nodes.Current.Value); //System.Windows.Forms.MessageBox.Show("Type.Description. " +type.getDescription() , "XMLProcedure.GetAllProcedures"); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Failure" procedure.setPanne(Panne.GetByID(Convert.ToInt32(Nodes.Current.Value))); procedures.Add(procedure); tillCount++; Nodes.Current.MoveToParent(); } } /* Si aucun expert n'a été trouvé */ else { procedure = 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 procedures; }
/// <summary> /// inserts a procedure to "procedure.xml". /// </summary> /// <param name="expert">The object holding the data</param> /// <returns></returns> private static bool insert(Procedure procedure) { 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("procedure.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 = "//procedure[@id='" + ID.ToString() + "']"; //Nodes = Navigator.Select(Navigator.Compile(ExpXPath)); if (Nodes.Count != 0) { //Nodes.MoveNext(); Nodes.Current.MoveToPrevious(); /* On crée le noeud principal (procedure). */ Nodes.Current.InsertElementAfter("", "procedure", "", ""); /* 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", "", procedure.getName()); Nodes.Current.AppendChildElement("", "description", "", procedure.getDescription()); Nodes.Current.AppendChildElement("", "panne", "", procedure.getPanne().getId().ToString()); //XmlDoc.Save((Stream)Helper.service.LoadFile("procedure.xml"); Helper.service.SaveXmlFile("procedure.xml", XmlDoc); } else { return false; } } catch (System.IO.FileNotFoundException x) { } catch (Exception x) { //System.Windows.Forms.MessageBox.Show(x.ToString()); } return true; }
/// <summary> /// Creates the file "procedure.xml" and inserts the first procedure to it. /// </summary> /// <param name="expert">The object holding the data.</param> /// <returns></returns> private static bool firstAdd(Procedure procedure) { 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("Procedures"); // Write the expert and the expert elements xw.WriteStartElement("procedure"); xw.WriteStartAttribute("id"); xw.WriteString("0"); xw.WriteEndAttribute(); //---------------- xw.WriteStartElement("libelle"); xw.WriteString(procedure.getName()); xw.WriteEndElement(); //----------------- xw.WriteStartElement("description"); xw.WriteString(procedure.getDescription()); xw.WriteEndElement(); //----------------- xw.WriteStartElement("panne"); xw.WriteString(procedure.getPanne().getId().ToString()); xw.WriteEndElement(); //----------------- xw.WriteEndElement(); xw.WriteStartElement("MaxID"); xw.WriteString("0"); xw.WriteEndElement(); // Close the document xw.WriteEndDocument(); // 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("procedure.xml", xmlOutput); Helper.service.CreateXmlFile("procedure.xml", xmlOutput); } catch (System.IO.FileNotFoundException x) { } catch (Exception x) { //System.Windows.Forms.MessageBox.Show(x.ToString()); } return true; }
/// <summary> /// Modifies the Procedure Data. /// </summary> /// <param name="login">The id of the target Procedure object.</param> /// <param name="admin">The object that holds the new data.</param> /// <returns></returns> public static bool Update(int id, Procedure procedure) { //System.Windows.Forms.MessageBox.Show("Proc.Id: "+procedure.getId()+" Proc.Name: "+procedure.getName(),"XMLProcedure.Modify"); 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("procedure.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 = "//procedure[@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(procedure.getId().ToString()); Nodes.Current.MoveToParent(); Nodes.Current.MoveToFirstChild(); //System.Windows.Forms.MessageBox.Show(Nodes.Current.Name.ToString() + " | " + Nodes.Current.Value.ToString()); Nodes.Current.SetValue(procedure.getName()); Nodes.Current.MoveToNext(XPathNodeType.Element); Nodes.Current.SetValue(procedure.getDescription()); Nodes.Current.MoveToNext(XPathNodeType.Element); Nodes.Current.SetValue(procedure.getPanne().getId().ToString()); //System.Windows.Forms.MessageBox.Show(Nodes.Current.Name + " | " + Nodes.Current.Value); Nodes.Current.MoveToNext(XPathNodeType.Element); //XmlDoc.Save((Stream)Helper.service.LoadFile("procedure.xml"); Helper.service.SaveXmlFile("procedure.xml", XmlDoc); } else { return false; } } catch (System.IO.FileNotFoundException x) { } catch (Exception x) { //System.Windows.Forms.MessageBox.Show(x.ToString()); } return true; }
public static Procedure GetById(int id) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ Procedure procedure = new Procedure(); try { string rslt = Helper.service.LoadFile("procedure.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 = "//procedure[@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 */ procedure.setId(id); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Libelle" */ procedure.setName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Description" procedure.setDescription(Nodes.Current.Value); Nodes.Current.MoveToNext();// On se déplace sur le noeud suivant "type_panne" procedure.setPanne(XMLFailure.GetById(Convert.ToInt32(Nodes.Current.Value))); } /* Si aucun expert n'a été trouvé */ else { procedure = 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 procedure; }
public void setprocedure(Procedure procedure) { this.procedure = procedure; }