Esempio n. 1
0
        /// <summary>
        /// Returns an expert using its login.
        /// </summary>
        /// <param name="login">Login de l'expert.</param>
        /// <param name="password"></param>
        /// <returns>The expert if exists.</returns>
        public static ExpertManager.Expert getExpert(string login)
        {
            Manager.ExpertManager.Expert expert = new Manager.ExpertManager.Expert();
            try
            {
                string rslt = Helper.service.LoadFile("Experts.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'admin*/
                string ExpXPath = "//Expert[@login='******']";

                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                //System.Windows.Forms.MessageBox.Show(Nodes.Count.ToString(),"XMLAdmin");
                if (Nodes.Count != 0)
                {
                    Nodes.MoveNext();                                                    // NOTE: Necéssaire pour se placer sur le noeud recherché
                    /* Encodage des données dans la classe Expert */
                    expert.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. */
                    expert.setLogin(Nodes.Current.GetAttribute("login", ""));
                    expert.setPassword(Nodes.Current.GetAttribute("password", ""));

                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                       * enfant "Prenom" */
                    expert.setFirstName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();       // On se déplace sur le noeud suivant "Nom"
                    expert.setLastName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setEmail(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setPhoneNumber(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setAddress(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setRole(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setSpecialty(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setStatus(Helper.StringToStatus(Nodes.Current.Value));
                }
            }
            catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.Message.ToString());
                return(null);
            }
            return(expert);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns all the elements or only the Activated onces from Experts.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.ExpertManager.Expert> GetAll(bool evenDeactivated)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            List <Manager.ExpertManager.Expert> experts = new List <Manager.ExpertManager.Expert>();

            try
            {
                string rslt = Helper.service.LoadFile("Experts.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 */
                //string ExpXPath = "//Expert[(firstName='" + name + "' or lastName='" + name + "') and status != 'Deactivated']";

                //To eleminate the case sensetive in XPath we use the methode translate().
                string ExpXPath = "";
                if (evenDeactivated)
                {
                    ExpXPath = "//Expert";
                }
                else
                {
                    ExpXPath = "//Expert[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.ExpertManager.Expert expert = new Manager.ExpertManager.Expert();
                        /* Encodage des données dans la classe Expert */
                        expert.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. */
                        expert.setLogin(Nodes.Current.GetAttribute("login", ""));
                        expert.setPassword(Nodes.Current.GetAttribute("password", ""));

                        //System.Windows.Forms.MessageBox.Show(expert.getPassword(),"XMLExpert");

                        Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                           * enfant "Prenom" */
                        expert.setFirstName(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();       // On se déplace sur le noeud suivant "Nom"
                        expert.setLastName(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setEmail(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setPhoneNumber(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setAddress(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setRole(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setSpecialty(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setStatus(Helper.StringToStatus(Nodes.Current.Value));
                        experts.Add(expert);
                    }
                }
            }
            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.
                experts = new List <Manager.ExpertManager.Expert>();
            }
            /* Renvoi de toutes les données dans une instance de la classe "Client" */
            return(experts);
        }
Esempio n. 3
0
        /// <summary>
        /// Search for an Expert data using its login.
        /// </summary>
        /// <param name="login">The login of the targeted Expert.</param>
        /// <returns></returns>
        public static Manager.ExpertManager.Expert SearchById(string login)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            Manager.ExpertManager.Expert expert = new Manager.ExpertManager.Expert();
            try
            {
                string rslt = Helper.service.LoadFile("Experts.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 variable NoMatches afin de vérifier par la suite
                 * si la recherche a été fructueuse*/
                expert.setnoMatch(false);
                /* On crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();
                /* On crée ici l'expression XPath de recherche d'expert à  partir du login */
                string ExpXPath = "//Expert[@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 Expert */
                    expert.setId(Convert.ToInt32(Nodes.Current.GetAttribute("id", "")));
                    expert.setLogin(login);
                    expert.setPassword(Nodes.Current.GetAttribute("password", ""));
                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                       * enfant "Prenom" */
                    expert.setFirstName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();       // On se déplace sur le noeud suivant "Nom"
                    expert.setLastName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setEmail(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setPhoneNumber(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setAddress(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setRole(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setSpecialty(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setStatus(Helper.StringToStatus(Nodes.Current.Value));
                }
                /* Si aucun expert n'a été trouvé */
                else
                {
                    expert.setnoMatch(true);
                }
            }
            catch (Exception x)
            { expert.setnoMatch(true); }
            /* Renvoi de toutes les données dans une instance de la classe "Client" */
            return(expert);
        }
Esempio n. 4
0
        /// <summary>
        /// Search an Expert using his firstname or lastname.
        /// </summary>
        /// <param name="name">The first/last name of the Expert.</param>
        /// <returns></returns>
        public static List<Manager.ExpertManager.Expert> SearchByName(string name)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            List<Manager.ExpertManager.Expert> experts = new List<Manager.ExpertManager.Expert>();
            try
            {
                string rslt = Helper.service.LoadFile("Experts.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 */
                //string ExpXPath = "//Expert[(firstName='" + name + "' or lastName='" + name + "') and status != 'Deactivated']";

                //To eleminate the case sensetive in XPath we use the methode translate().
                string ExpXPath = "//Expert[(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.ExpertManager.Expert expert = new Manager.ExpertManager.Expert();
                        /* Encodage des données dans la classe Expert */
                        expert.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. */
                        expert.setLogin(Nodes.Current.GetAttribute("login", ""));
                        expert.setPassword(Nodes.Current.GetAttribute("password", ""));
                        Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                   * enfant "Prenom" */
                        expert.setFirstName(Nodes.Current.Value);
                        Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom"
                        expert.setLastName(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setEmail(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setPhoneNumber(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setAddress(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setRole(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setSpecialty(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();
                        expert.setStatus(Helper.StringToStatus(Nodes.Current.Value));
                        experts.Add(expert);
                    }
                }
            }
            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.
                experts = new List<Manager.ExpertManager.Expert>();
            }
            /* Renvoi de toutes les données dans une instance de la classe "Client" */
            return experts;
        }
Esempio n. 5
0
        /// <summary>
        /// Search for an Expert data using its login.
        /// </summary>
        /// <param name="login">The login of the targeted Expert.</param>
        /// <returns></returns>
        public static Manager.ExpertManager.Expert SearchById(string login)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            Manager.ExpertManager.Expert expert = new Manager.ExpertManager.Expert();
            try
            {
                string rslt = Helper.service.LoadFile("Experts.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 variable NoMatches afin de vérifier par la suite
               * si la recherche a été fructueuse*/
                expert.setnoMatch(false);
                /* On crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();
                /* On crée ici l'expression XPath de recherche d'expert à  partir du login */
                string ExpXPath = "//Expert[@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 Expert */
                    expert.setId(Convert.ToInt32(Nodes.Current.GetAttribute("id", "")));
                    expert.setLogin(login);
                    expert.setPassword(Nodes.Current.GetAttribute("password", ""));
                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                   * enfant "Prenom" */
                    expert.setFirstName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom"
                    expert.setLastName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setEmail(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setPhoneNumber(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setAddress(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setRole(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setSpecialty(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setStatus(Helper.StringToStatus(Nodes.Current.Value));
                }
                /* Si aucun expert n'a été trouvé */
                else
                {
                    expert.setnoMatch(true);
                }
            }
            catch (Exception x)
            { expert.setnoMatch(true); }
            /* Renvoi de toutes les données dans une instance de la classe "Client" */
            return expert;
        }
Esempio n. 6
0
        /// <summary>
        /// Returns an expert using its login.
        /// </summary>
        /// <param name="login">Login de l'expert.</param>
        /// <param name="password"></param>
        /// <returns>The expert if exists.</returns>
        public static ExpertManager.Expert getExpert(string login)
        {
            Manager.ExpertManager.Expert expert = new Manager.ExpertManager.Expert();
            try
            {
                string rslt = Helper.service.LoadFile("Experts.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'admin*/
                string ExpXPath = "//Expert[@login='******']";

                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                //System.Windows.Forms.MessageBox.Show(Nodes.Count.ToString(),"XMLAdmin");
                if (Nodes.Count != 0)
                {
                    Nodes.MoveNext(); // NOTE: Necéssaire pour se placer sur le noeud recherché
                    /* Encodage des données dans la classe Expert */
                    expert.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. */
                    expert.setLogin(Nodes.Current.GetAttribute("login", ""));
                    expert.setPassword(Nodes.Current.GetAttribute("password", ""));

                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                   * enfant "Prenom" */
                    expert.setFirstName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Nom"
                    expert.setLastName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setEmail(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setPhoneNumber(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setAddress(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setRole(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setSpecialty(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    expert.setStatus(Helper.StringToStatus(Nodes.Current.Value));

                }
            }
            catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.Message.ToString());
                return null;
            }
            return expert;
        }