/// <summary> /// Search for a technician data using its id. /// </summary> /// <param name="id">The id of the targeted technician.</param> /// <returns></returns> public static Manager.Technician SearchById(int id) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ Manager.Technician technician = new Manager.Technician(); try { XPathDocument XPathDocu = new XPathDocument(path + "Technicians.xml"); XPathNavigator Navigator; XPathNodeIterator Nodes; /* On affecte false à la variable NoMatches afin de vérifier par la suite * si la recherche a été fructueuse*/ technician.setnoMatch(false); /* On crée un navigateur */ Navigator = XPathDocu.CreateNavigator(); /* On crée ici l'expression XPath de recherche d'technician à partir de l'id */ string ExpXPath = "//Technician[@id='" + id + "' and status != 'Deactivated']"; /* 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 technician */ technician.setId(id); /* Pas besoin de chercher cette donnée vu que c'est notre * critère de recherche, on peut donc directement * l'encoder. */ technician.setLogin(Nodes.Current.GetAttribute("login", "")); technician.setPassword(Nodes.Current.GetAttribute("password", "")); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Prenom" */ technician.setFirstName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom" technician.setLastName(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setEmail(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setPhoneNumber(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setAddress(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setRole(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setSpecialty(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setStatus(Helper.StringToStatus(Nodes.Current.Value)); } /* Si aucun technician n'a été trouvé */ else { technician.setnoMatch(true); } } catch (Exception x) { technician.setnoMatch(true); } /* Renvoi de toutes les données dans une instance de la classe "Client" */ return(technician); }
/// <summary> /// Returns all the elements or only the Activated onces from Technicians.xml depending on the value of the boolean argument. /// </summary> /// <param name="evenDeactivated">When true get all elments, otherwise get only the activated onces.</param> /// <returns></returns> public static List <Manager.Technician> GetAll(bool evenDeactivated) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ List <Manager.Technician> technicians = new List <Manager.Technician>(); try { XPathDocument XPathDocu = new XPathDocument(path + "Technicians.xml"); XPathNavigator Navigator; XPathNodeIterator Nodes; /* On crée un navigateur */ Navigator = XPathDocu.CreateNavigator(); //To eleminate the case sensetive in XPath we use the methode translate(). string ExpXPath = ""; if (evenDeactivated) { ExpXPath = "//Technician"; } else { ExpXPath = "//Technician[status != 'Deactivated']"; } /* On lance la recherche */ Nodes = Navigator.Select(Navigator.Compile(ExpXPath)); /* On vérifie si la recherche a été fructueuse */ //System.Windows.Forms.MessageBox.Show("XMLTechnician: "+Nodes.Count.ToString()); if (Nodes.Count != 0) { while (Nodes.MoveNext()) // NOTE: Necéssaire pour se placer sur le noeud recherché { Manager.Technician technician = new Manager.Technician(); /* Encodage des données dans la classe Technician */ technician.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. */ technician.setLogin(Nodes.Current.GetAttribute("login", "")); technician.setPassword(Nodes.Current.GetAttribute("password", "")); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Prenom" */ technician.setFirstName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom" technician.setLastName(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setEmail(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setPhoneNumber(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setAddress(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setRole(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setSpecialty(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setStatus(Helper.StringToStatus(Nodes.Current.Value)); technicians.Add(technician); } } } catch (Exception x) { //If there was a problem we re-instanciate the list so no element is sent. //It returns an empty list instead of null, then we make our test on list.count. technicians = new List <Manager.Technician>(); } /* Renvoi de toutes les données dans une instance de la classe "Client" */ return(technicians); }
/// <summary> /// Search a technician using his firstname or lastname. /// </summary> /// <param name="name">The first/last name of the technician.</param> /// <returns></returns> public static List <Manager.Technician> SearchByName(string name) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ List <Manager.Technician> technicians = new List <Manager.Technician>(); try { XPathDocument XPathDocu = new XPathDocument(path + "Technicians.xml"); XPathNavigator Navigator; XPathNodeIterator Nodes; /* On crée un navigateur */ Navigator = XPathDocu.CreateNavigator(); /* On crée ici l'expression XPath de recherche d'technician à partir de l'id */ //string ExpXPath = "//Technician[(firstName='" + name + "' or lastName='" + name + "') and status != 'Deactivated']"; //To eleminate the case sensetive in XPath we use the methode translate(). string ExpXPath = "//Technician[(translate(firstName,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + name.ToUpper() + "' or translate(lastName,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + name.ToUpper() + "') and status != 'Deactivated']"; /* 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é { Manager.Technician technician = new Manager.Technician(); /* Encodage des données dans la classe technician */ technician.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. */ technician.setLogin(Nodes.Current.GetAttribute("login", "")); technician.setPassword(Nodes.Current.GetAttribute("password", "")); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Prenom" */ technician.setFirstName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom" technician.setLastName(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setEmail(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setPhoneNumber(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setAddress(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setRole(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setSpecialty(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setStatus(Helper.StringToStatus(Nodes.Current.Value)); technicians.Add(technician); } } } catch (Exception x) { //If there was a problem we re-instanciate the list so no element is sent. //It returns an empty list instead of null, then we make our test on list.count. technicians = new List <Manager.Technician>(); } /* Renvoi de toutes les données dans une instance de la classe "Client" */ return(technicians); }
/// <summary> /// Search a technician using his firstname or lastname. /// </summary> /// <param name="name">The first/last name of the technician.</param> /// <returns></returns> public static List<Manager.Technician> SearchByName(string name) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ List<Manager.Technician> technicians = new List<Manager.Technician>(); try { XPathDocument XPathDocu = new XPathDocument(path + "Technicians.xml"); XPathNavigator Navigator; XPathNodeIterator Nodes; /* On crée un navigateur */ Navigator = XPathDocu.CreateNavigator(); /* On crée ici l'expression XPath de recherche d'technician à partir de l'id */ //string ExpXPath = "//Technician[(firstName='" + name + "' or lastName='" + name + "') and status != 'Deactivated']"; //To eleminate the case sensetive in XPath we use the methode translate(). string ExpXPath = "//Technician[(translate(firstName,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + name.ToUpper() + "' or translate(lastName,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + name.ToUpper() + "') and status != 'Deactivated']"; /* 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é { Manager.Technician technician = new Manager.Technician(); /* Encodage des données dans la classe technician */ technician.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. */ technician.setLogin(Nodes.Current.GetAttribute("login", "")); technician.setPassword(Nodes.Current.GetAttribute("password", "")); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Prenom" */ technician.setFirstName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom" technician.setLastName(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setEmail(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setPhoneNumber(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setAddress(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setRole(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setSpecialty(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setStatus(Helper.StringToStatus(Nodes.Current.Value)); technicians.Add(technician); } } } catch (Exception x) { //If there was a problem we re-instanciate the list so no element is sent. //It returns an empty list instead of null, then we make our test on list.count. technicians = new List<Manager.Technician>(); } /* Renvoi de toutes les données dans une instance de la classe "Client" */ return technicians; }
/// <summary> /// Search for a technician data using its login. /// </summary> /// <param name="login">The login of the targeted technician.</param> /// <returns></returns> public static Manager.Technician SearchById(string login) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ Manager.Technician technician = new Manager.Technician(); try { XPathDocument XPathDocu = new XPathDocument(path + "Technicians.xml"); XPathNavigator Navigator; XPathNodeIterator Nodes; /* On affecte false à la variable NoMatches afin de vérifier par la suite * si la recherche a été fructueuse*/ technician.setnoMatch(false); /* On crée un navigateur */ Navigator = XPathDocu.CreateNavigator(); /* On crée ici l'expression XPath de recherche d'technician à partir de l'id */ string ExpXPath = "//Technician[@login='******' and status != 'Deactivated']"; /* 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 technician */ technician.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. */ technician.setLogin(login); technician.setPassword(Nodes.Current.GetAttribute("password", "")); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Prenom" */ technician.setFirstName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom" technician.setLastName(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setEmail(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setPhoneNumber(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setAddress(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setRole(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setSpecialty(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setStatus(Helper.StringToStatus(Nodes.Current.Value)); } /* Si aucun technician n'a été trouvé */ else { technician.setnoMatch(true); } } catch (Exception x) { technician.setnoMatch(true); } /* Renvoi de toutes les données dans une instance de la classe "Client" */ return technician; }
/// <summary> /// Returns all the elements or only the Activated onces from Technicians.xml depending on the value of the boolean argument. /// </summary> /// <param name="evenDeactivated">When true get all elments, otherwise get only the activated onces.</param> /// <returns></returns> public static List<Manager.Technician> GetAll(bool evenDeactivated) { /* On déclare et on crée une instance des variables nécéssaires pour la recherche */ List<Manager.Technician> technicians = new List<Manager.Technician>(); try { XPathDocument XPathDocu = new XPathDocument(path + "Technicians.xml"); XPathNavigator Navigator; XPathNodeIterator Nodes; /* On crée un navigateur */ Navigator = XPathDocu.CreateNavigator(); //To eleminate the case sensetive in XPath we use the methode translate(). string ExpXPath = ""; if (evenDeactivated) ExpXPath = "//Technician"; else ExpXPath = "//Technician[status != 'Deactivated']"; /* On lance la recherche */ Nodes = Navigator.Select(Navigator.Compile(ExpXPath)); /* On vérifie si la recherche a été fructueuse */ //System.Windows.Forms.MessageBox.Show("XMLTechnician: "+Nodes.Count.ToString()); if (Nodes.Count != 0) { while (Nodes.MoveNext()) // NOTE: Necéssaire pour se placer sur le noeud recherché { Manager.Technician technician = new Manager.Technician(); /* Encodage des données dans la classe Technician */ technician.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. */ technician.setLogin(Nodes.Current.GetAttribute("login", "")); technician.setPassword(Nodes.Current.GetAttribute("password", "")); Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud * enfant "Prenom" */ technician.setFirstName(Nodes.Current.Value); Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom" technician.setLastName(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setEmail(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setPhoneNumber(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setAddress(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setRole(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setSpecialty(Nodes.Current.Value); Nodes.Current.MoveToNext(); technician.setStatus(Helper.StringToStatus(Nodes.Current.Value)); technicians.Add(technician); } } } catch (Exception x) { //If there was a problem we re-instanciate the list so no element is sent. //It returns an empty list instead of null, then we make our test on list.count. technicians = new List<Manager.Technician>(); } /* Renvoi de toutes les données dans une instance de la classe "Client" */ return technicians; }