Beispiel #1
0
        private Cats OurSearch()
        {
            string[] info = new string[6];
            if (checkBoxname.Checked)
            {
                info[0] = Convert.ToString(namebox.Text);
            }
            if (checkBoxsex.Checked)
            {
                info[1] = Convert.ToString(sexbox.Text);
            }
            if (checkBoxbreed.Checked)
            {
                info[2] = Convert.ToString(breedbox.Text);
            }
            if (checkBoxage.Checked)
            {
                info[3] = Convert.ToString(agebox.Text);
            }
            if (checkBoxvac.Checked)
            {
                info[4] = Convert.ToString(vacbox.Text);
            }
            Cats idealSearch = new Cats(info);

            return(idealSearch);
        }
Beispiel #2
0
        public List <Cats> AnalyzeFile(Cats mySearch, string path)
        {
            doc.Load(path);
            List <List <Cats> > info = new List <List <Cats> >();

            if (mySearch.name == null && mySearch.breed == null && mySearch.sex == null && mySearch.age == null && mySearch.vac == null)
            {
                return(ErrorCatch(doc));
            }

            if (mySearch.name != null)
            {
                info.Add(SearchByAttribute("cat", "NAME", mySearch.name, doc));
            }
            if (mySearch.sex != null)
            {
                info.Add(SearchByAttribute("cat", "SEX", mySearch.sex, doc));
            }
            if (mySearch.breed != null)
            {
                info.Add(SearchByAttribute("cat", "BREED", mySearch.breed, doc));
            }
            if (mySearch.age != null)
            {
                info.Add(SearchByAttribute("cat", "AGE", mySearch.age, doc));
            }
            if (mySearch.vac != null)
            {
                info.Add(SearchByAttribute("cat", "VACCINATIONS", mySearch.vac, doc));
            }

            return(Cross(info, mySearch));
        }
Beispiel #3
0
        public Cats Info(XmlNode node)
        {
            Cats search = new Cats();

            search.name  = node.Attributes.GetNamedItem("NAME").Value;
            search.sex   = node.Attributes.GetNamedItem("SEX").Value;
            search.breed = node.Attributes.GetNamedItem("BREED").Value;
            search.age   = node.Attributes.GetNamedItem("AGE").Value;
            search.vac   = node.Attributes.GetNamedItem("VACCINATIONS").Value;

            return(search);
        }
Beispiel #4
0
 public bool Compare(Cats obj)
 {
     if ((this.name == obj.name) &&
         (this.sex == obj.sex) &&
         (this.breed == obj.breed) &&
         (this.age == obj.age) &&
         (this.vac == obj.vac))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #5
0
        public List <Cats> AnalyzeFile(Cats mySearch, string path)
        {
            XmlReader   reader = XmlReader.Create(path);
            List <Cats> res    = new List <Cats>();

            Cats find = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.Name == "cat")
                    {
                        find = new Cats();
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name == "NAME")
                            {
                                find.name = reader.Value;
                            }
                            if (reader.Name == "SEX")
                            {
                                find.sex = reader.Value;
                            }
                            if (reader.Name == "BREED")
                            {
                                find.breed = reader.Value;
                            }
                            if (reader.Name == "AGE")
                            {
                                find.age = reader.Value;
                            }
                            if (reader.Name == "VACCINATIONS")
                            {
                                find.vac = reader.Value;
                            }
                        }
                        res.Add(find);
                    }
                    break;
                }
            }
            Lres = Filter(res, mySearch);
            return(Lres);
        }
Beispiel #6
0
        private List <Cats> Filter(List <Cats> allres, Cats Temp)
        {
            List <Cats> newres = new List <Cats>();

            if (allres != null)
            {
                foreach (Cats s in allres)
                {
                    if ((Temp.name == s.name || Temp.name == null) &&
                        (Temp.sex == s.sex || Temp.sex == null) &&
                        (Temp.age == s.age || Temp.age == null) &&
                        (Temp.breed == s.breed || Temp.breed == null) &&
                        (Temp.vac == s.name || Temp.vac == null))
                    {
                        newres.Add(s);
                    }
                }
            }
            return(newres);
        }
Beispiel #7
0
        public List <Cats> CheckNodes(List <List <Cats> > cat, Cats Temp)
        {
            List <Cats> res = new List <Cats>();

            foreach (List <Cats> x in cat)
            {
                foreach (Cats s in x)
                {
                    if ((Temp.name == s.name || Temp.name == null) &&
                        (Temp.sex == s.sex || Temp.sex == null) &&
                        (Temp.age == s.age || Temp.age == null) &&
                        (Temp.breed == s.breed || Temp.breed == null) &&
                        (Temp.vac == s.name || Temp.vac == null))
                    {
                        res.Add(s);
                    }
                }
            }
            return(res);
        }
Beispiel #8
0
        public List <Cats> Cross(List <List <Cats> > cats, Cats Temp)
        {
            List <Cats> res   = new List <Cats>();
            List <Cats> clear = CheckNodes(cats, Temp);

            foreach (Cats x in clear)
            {
                bool isIn = false;
                foreach (Cats s in res)
                {
                    if (s.Compare(x))
                    {
                        isIn = true;
                    }
                }
                if (isIn)
                {
                    res.Add(x);
                }
            }
            return(res);
        }
Beispiel #9
0
        private void Parsing4XML()
        {
            Cats        myTemp = OurSearch();
            List <Cats> res;

            if (radioSAX.Checked)
            {
                IStrategy parser = new SAX();
                res = parser.AnalyzeFile(myTemp, path);
                Output(res);
            }
            else if (radioDOM.Checked)
            {
                IStrategy parser = new DOM();
                res = parser.AnalyzeFile(myTemp, path);
                Output(res);
            }
            else if (radioLINQ.Checked)
            {
                IStrategy parser = new LinqToXML();
                res = parser.AnalyzeFile(myTemp, path);
                Output(res);
            }
        }
Beispiel #10
0
        public List <Cats> AnalyzeFile(Cats mySearch, string path)
        {
            doc  = XDocument.Load(@path);
            find = new List <Cats>();
            List <XElement> matches = (from val in doc.Descendants("cat")
                                       where ((mySearch.name == null || mySearch.name == val.Attribute("NAME").Value) &&
                                              (mySearch.sex == null || mySearch.sex == val.Attribute("SEX").Value) &&
                                              (mySearch.breed == null || mySearch.breed == val.Attribute("BREED").Value) &&
                                              (mySearch.age == null || mySearch.age == val.Attribute("AGE").Value) &&
                                              (mySearch.vac == null || mySearch.vac == val.Attribute("VACCINATIONS").Value))
                                       select val).ToList();

            foreach (XElement match in matches)
            {
                Cats res = new Cats();
                res.name  = match.Attribute("NAME").Value;
                res.sex   = match.Attribute("SEX").Value;
                res.breed = match.Attribute("BREED").Value;
                res.age   = match.Attribute("AGE").Value;
                res.vac   = match.Attribute("VACCINATIONS").Value;
                find.Add(res);
            }
            return(find);
        }