Beispiel #1
0
        public override List <Teacher> Search(Teacher teacher)
        {
            List <Teacher> result   = new List <Teacher>();
            var            document = XDocument.Load(@"C:\Users\Егор\Desktop\C#\Lab3\XMLFile1.xml");
            var            result2  = from obj in document.Descendants("Teacher")
                                      where (
                ((obj.Attribute("Name").Value == teacher.Name) || (teacher.Name == null)) &&
                ((obj.Attribute("Faculty").Value == teacher.Faculty) || (teacher.Faculty == null)) &&
                ((obj.Attribute("Department").Value == teacher.Department) || (teacher.Department == null)) &&
                ((obj.Attribute("Position").Value == teacher.Position) || (teacher.Position == null)) &&
                ((WagesConv.WageToStr(obj.Attribute("Pension").Value) == WagesConv.WageToStr(teacher.Pension)) || (teacher.Pension == null)) &&
                ((ExperienseConv.ExperienseToStr(obj.Attribute("Experiense").Value) == ExperienseConv.ExperienseToStr(teacher.Experiense)) || (teacher.Experiense == null)))
                                      select new
            {
                Name       = obj.Attribute("Name").Value,
                Faculty    = obj.Attribute("Faculty").Value,
                Department = obj.Attribute("Department").Value,
                Position   = obj.Attribute("Position").Value,
                Pension    = obj.Attribute("Pension").Value,
                Experiense = obj.Attribute("Experiense").Value
            };

            foreach (var n in result2)
            {
                Teacher temp = new Teacher();
                temp.Name       = n.Name;
                temp.Faculty    = n.Faculty;
                temp.Department = n.Department;
                temp.Position   = n.Position;
                temp.Pension    = n.Pension;
                temp.Experiense = n.Experiense;
                result.Add(temp);
            }
            return(result);
        }
Beispiel #2
0
        public override List <Teacher> Search(Teacher teacher)
        {
            List <Teacher> result = new List <Teacher>();
            //string path = "";
            XmlDocument document = new XmlDocument();

            document.Load(@"C:\Users\Егор\Desktop\C#\Lab3\XMLFile1.xml");
            XmlNode base_el = document.DocumentElement;
            string  s       = "//Teacher[";
            int     count   = 0;

            if (teacher.Name != null)
            {
                s += "@Name=\"" + teacher.Name + "\"";
                count++;
            }

            if (teacher.Faculty != null)
            {
                if (count == 0)
                {
                    s += "@Faculty=\"" + teacher.Faculty + "\"";
                    count++;
                }
                else
                {
                    s += " and @Faculty=\"" + teacher.Faculty + "\"";
                    count++;
                }
            }

            if (teacher.Department != null)
            {
                if (count == 0)
                {
                    s += "@Department=\"" + teacher.Department + "\"";
                    count++;
                }
                else
                {
                    s += " and @Department=\"" + teacher.Department + "\"";
                }
            }

            if (teacher.Position != null)
            {
                if (count == 0)
                {
                    s += "@Position=\"" + teacher.Position + "\"";
                    count++;
                }
                else
                {
                    s += " and @Position=\"" + teacher.Position + "\"";
                }
            }

            s += "]";

            XmlNodeList result2 = document.SelectNodes(s);

            if (result2.Count != 0)
            {
                foreach (XmlNode node in result2)
                {
                    bool flag = false;
                    for (int i = 0; i < node.Attributes.Count; i++)
                    {
                        if (node.Attributes[i].Name.Equals("Pension") && (teacher.Pension != null))
                        {
                            if (WagesConv.WageToStr(node.Attributes[i].Value) != WagesConv.WageToStr(teacher.Pension))
                            {
                                flag = true; break;
                            }
                        }
                        if (node.Attributes[i].Name.Equals("Experiense") && (teacher.Experiense != null))
                        {
                            if (ExperienseConv.ExperienseToStr(node.Attributes[i].Value) != ExperienseConv.ExperienseToStr(teacher.Experiense))
                            {
                                flag = true; break;
                            }
                        }
                    }


                    if (!flag)
                    {
                        Teacher temp = new Teacher();
                        for (int i = 0; i < node.Attributes.Count; i++)
                        {
                            if (node.Attributes[i].Name.Equals("Name"))
                            {
                                temp.Name = node.Attributes[i].Value;
                            }
                            if (node.Attributes[i].Name.Equals("Faculty"))
                            {
                                temp.Faculty = node.Attributes[i].Value;
                            }
                            if (node.Attributes[i].Name.Equals("Department"))
                            {
                                temp.Department = node.Attributes[i].Value;
                            }
                            if (node.Attributes[i].Name.Equals("Position"))
                            {
                                temp.Position = node.Attributes[i].Value;
                            }
                            if (node.Attributes[i].Name.Equals("Pension"))
                            {
                                temp.Pension = node.Attributes[i].Value;
                            }
                            if (node.Attributes[i].Name.Equals("Experiense"))
                            {
                                temp.Experiense = node.Attributes[i].Value;
                            }
                        }
                        result.Add(temp);
                    }
                }
            }

            return(result);


            /*   foreach (XmlNode node in base_el.ChildNodes)
             * {
             *
             *
             *
             *     bool flag = false;
             *     for (int i = 0; i < node.Attributes.Count; i++)
             *     {
             *         if (node.Attributes[i].Name.Equals("Name") && (teacher.Name != null)) { if (node.Attributes[i].Value != teacher.Name) { flag = true; break; } }
             *         if (node.Attributes[i].Name.Equals("Faculty") && (teacher.Faculty != null)) { if (node.Attributes[i].Value != teacher.Faculty) { flag = true; break; } }
             *         if (node.Attributes[i].Name.Equals("Department") && (teacher.Department != null)) { if (node.Attributes[i].Value != teacher.Department) { flag = true; break; } }
             *         if (node.Attributes[i].Name.Equals("Position") && (teacher.Position != null)) { if (node.Attributes[i].Value != teacher.Position) { flag = true; break; } }
             *         if (node.Attributes[i].Name.Equals("Pension") && (teacher.Pension != null)) { if (WagesConv.WageToStr(node.Attributes[i].Value) != WagesConv.WageToStr(teacher.Pension)) { flag = true; break; } }
             *         if (node.Attributes[i].Name.Equals("Experiense") && (teacher.Experiense != null)) { if (ExperienseConv.ExperienseToStr(node.Attributes[i].Value) != ExperienseConv.ExperienseToStr(teacher.Experiense)) { flag = true; break; } }
             *     }
             *
             *     if (!flag)
             *     {
             *         Teacher temp = new Teacher();
             *         for (int i = 0; i < node.Attributes.Count; i++)
             *         {
             *             if (node.Attributes[i].Name.Equals("Name")) { temp.Name = node.Attributes[i].Value; }
             *             if (node.Attributes[i].Name.Equals("Faculty")) { temp.Faculty = node.Attributes[i].Value; }
             *             if (node.Attributes[i].Name.Equals("Department")) { temp.Department = node.Attributes[i].Value; }
             *             if (node.Attributes[i].Name.Equals("Position")) { temp.Position = node.Attributes[i].Value; }
             *             if (node.Attributes[i].Name.Equals("Pension")) { temp.Pension = node.Attributes[i].Value; }
             *             if (node.Attributes[i].Name.Equals("Experiense")) { temp.Experiense = node.Attributes[i].Value; }
             *         }
             *         result.Add(temp);
             *     }
             * }
             * return result;*/
        }
Beispiel #3
0
        public override List <Teacher> Search(Teacher teacher)
        {
            List <Teacher> result    = new List <Teacher>();
            var            xmlReader = new XmlTextReader(@"C:\Users\Егор\Desktop\C#\Lab3\XMLFile1.xml");

            while (xmlReader.Read())
            {
                if (xmlReader.HasAttributes)
                {
                    string Name       = null;
                    string Faculty    = null;
                    string Department = null;
                    string Position   = null;
                    string Pension    = null;
                    string Experiense = null;

                    bool flag = false;

                    if (xmlReader.AttributeCount != 6)
                    {
                        continue;
                    }
                    Console.WriteLine(xmlReader.AttributeCount);
                    for (int i = 0; i < xmlReader.AttributeCount; i++)
                    {
                        if (i == 0)
                        {
                            xmlReader.MoveToFirstAttribute();
                        }
                        if (i != 0)
                        {
                            xmlReader.MoveToNextAttribute();
                        }
                        string temp = xmlReader.Value;
                        if (xmlReader.Name.Equals("Name") && (teacher.Name != null))
                        {
                            if (temp != teacher.Name)
                            {
                                flag = true; break;
                            }
                        }
                        if (xmlReader.Name.Equals("Faculty") && (teacher.Faculty != null))
                        {
                            if (temp != teacher.Faculty)
                            {
                                flag = true; break;
                            }
                        }
                        if (xmlReader.Name.Equals("Department") && (teacher.Department != null))
                        {
                            if (temp != teacher.Department)
                            {
                                flag = true; break;
                            }
                        }
                        if (xmlReader.Name.Equals("Position") && (teacher.Position != null))
                        {
                            if (temp != teacher.Position)
                            {
                                flag = true; break;
                            }
                        }
                        if (xmlReader.Name.Equals("Pension") && (teacher.Pension != null))
                        {
                            if (WagesConv.WageToStr(temp) != WagesConv.WageToStr(teacher.Pension))
                            {
                                flag = true; break;
                            }
                        }
                        if (xmlReader.Name.Equals("Experiense") && (teacher.Experiense != null))
                        {
                            if (ExperienseConv.ExperienseToStr(temp) != ExperienseConv.ExperienseToStr(teacher.Experiense))
                            {
                                flag = true; break;
                            }
                        }

                        if (xmlReader.Name.Equals("Name"))
                        {
                            Name = temp;
                        }
                        if (xmlReader.Name.Equals("Faculty"))
                        {
                            Faculty = temp;
                        }
                        if (xmlReader.Name.Equals("Department"))
                        {
                            Department = temp;
                        }
                        if (xmlReader.Name.Equals("Position"))
                        {
                            Position = temp;
                        }
                        if (xmlReader.Name.Equals("Pension"))
                        {
                            Pension = temp;
                        }
                        if (xmlReader.Name.Equals("Experiense"))
                        {
                            Experiense = temp;
                        }
                    }

                    if (!flag)
                    {
                        Teacher temp = new Teacher();
                        temp.Name       = Name;
                        temp.Faculty    = Faculty;
                        temp.Department = Department;
                        temp.Position   = Position;
                        temp.Pension    = Pension;
                        temp.Experiense = Experiense;
                        result.Add(temp);
                    }
                }
            }
            xmlReader.Close();
            return(result);
        }
Beispiel #4
0
        public override List <Teacher> Search(Teacher teacher)
        {
            List <Teacher> result = new List <Teacher>();
            //string path = "";
            XmlDocument document = new XmlDocument();

            document.Load(@"C:\Users\Егор\Desktop\C#\Lab3\XMLFile1.xml");
            XmlNode base_el = document.DocumentElement;

            foreach (XmlNode node in base_el.ChildNodes)
            {
                bool flag = false;
                for (int i = 0; i < node.Attributes.Count; i++)
                {
                    if (node.Attributes[i].Name.Equals("Name") && (teacher.Name != null))
                    {
                        if (node.Attributes[i].Value != teacher.Name)
                        {
                            flag = true; break;
                        }
                    }
                    if (node.Attributes[i].Name.Equals("Faculty") && (teacher.Faculty != null))
                    {
                        if (node.Attributes[i].Value != teacher.Faculty)
                        {
                            flag = true; break;
                        }
                    }
                    if (node.Attributes[i].Name.Equals("Department") && (teacher.Department != null))
                    {
                        if (node.Attributes[i].Value != teacher.Department)
                        {
                            flag = true; break;
                        }
                    }
                    if (node.Attributes[i].Name.Equals("Position") && (teacher.Position != null))
                    {
                        if (node.Attributes[i].Value != teacher.Position)
                        {
                            flag = true; break;
                        }
                    }
                    if (node.Attributes[i].Name.Equals("Pension") && (teacher.Pension != null))
                    {
                        if (WagesConv.WageToStr(node.Attributes[i].Value) != WagesConv.WageToStr(teacher.Pension))
                        {
                            flag = true; break;
                        }
                    }
                    if (node.Attributes[i].Name.Equals("Experiense") && (teacher.Experiense != null))
                    {
                        if (ExperienseConv.ExperienseToStr(node.Attributes[i].Value) != ExperienseConv.ExperienseToStr(teacher.Experiense))
                        {
                            flag = true; break;
                        }
                    }
                }

                if (!flag)
                {
                    Teacher temp = new Teacher();
                    for (int i = 0; i < node.Attributes.Count; i++)
                    {
                        if (node.Attributes[i].Name.Equals("Name"))
                        {
                            temp.Name = node.Attributes[i].Value;
                        }
                        if (node.Attributes[i].Name.Equals("Faculty"))
                        {
                            temp.Faculty = node.Attributes[i].Value;
                        }
                        if (node.Attributes[i].Name.Equals("Department"))
                        {
                            temp.Department = node.Attributes[i].Value;
                        }
                        if (node.Attributes[i].Name.Equals("Position"))
                        {
                            temp.Position = node.Attributes[i].Value;
                        }
                        if (node.Attributes[i].Name.Equals("Pension"))
                        {
                            temp.Pension = node.Attributes[i].Value;
                        }
                        if (node.Attributes[i].Name.Equals("Experiense"))
                        {
                            temp.Experiense = node.Attributes[i].Value;
                        }
                    }
                    result.Add(temp);
                }
            }
            return(result);
        }