Ejemplo n.º 1
0
        public List <Tournaments> Search(Tournaments tournament)
        {
            List <Tournaments> allResult = new List <Tournaments>();
            var doc    = XDocument.Load(@"C:\Users\qwert\Desktop\LAB2\LAB2\Tournaments.xml");
            var result = from obj in doc.Descendants("Tournament")
                         where
                         (
                (obj.Attribute("Title").Value.Equals(tournament.Title) || tournament.Title.Equals(string.Empty)) &&
                (obj.Attribute("Date").Value.Equals(tournament.Date) || tournament.Date.Equals(string.Empty)) &&
                (tournament.PriceRange.Equals(string.Empty) || isPriceRange(obj.Attribute("PriceRange").Value, tournament.PriceRange)) &&
                (obj.Attribute("Location").Value.Contains(tournament.Location) || tournament.Location.Equals(string.Empty)) &&
                (obj.Attribute("Commentators").Value.Contains(tournament.Commentators) || tournament.Commentators.Equals(string.Empty)) &&
                (obj.Attribute("Participants").Value.Contains(tournament.Participants) || tournament.Participants.Equals(string.Empty)) &&
                (obj.Attribute("Type").Value.Equals(tournament.Type) || tournament.Type.Equals(string.Empty))
                         )
                         select new
            {
                title        = (string)obj.Attribute("Title"),
                date         = (string)obj.Attribute("Date"),
                priceRange   = (string)obj.Attribute("PriceRange"),
                location     = (string)obj.Attribute("Location"),
                commentators = (string)obj.Attribute("Commentators"),
                participants = (string)obj.Attribute("Participants"),
                type         = (string)obj.Attribute("Type"),
            };

            foreach (var n in result)
            {
                Tournaments myConcert = new Tournaments();
                myConcert.Title        = n.title;
                myConcert.Date         = n.date;
                myConcert.PriceRange   = n.priceRange;
                myConcert.Location     = n.location;
                myConcert.Commentators = n.commentators;
                myConcert.Participants = n.participants;
                myConcert.Type         = n.type;

                allResult.Add(myConcert);
            }
            return(allResult);
        }
Ejemplo n.º 2
0
        public List <Tournaments> Search(Tournaments tournament)
        {
            List <Tournaments> result = new List <Tournaments>();
            XmlDocument        doc    = new XmlDocument();

            doc.Load(@"C:\Users\qwert\Desktop\LAB2\LAB2\Tournaments.xml");

            XmlNode node = doc.DocumentElement;

            string xpath = "/Tournaments/Tournament[";
            int    count = 0;

            if (tournament.Title != "")
            {
                xpath += "@Title=\"" + tournament.Title + "\"";
                count++;
            }

            if (tournament.Date != "")
            {
                if (count == 0)
                {
                    xpath += "@Date=\"" + tournament.Date + "\"";
                    count++;
                }
                else
                {
                    xpath += " and @Date=\"" + tournament.Date + "\"";
                }
            }


            if (tournament.PriceRange != "")
            {
                if (count == 0)
                {
                    xpath += "@PriceRange=\"" + tournament.PriceRange + "\"";
                    count++;
                }
                else
                {
                    xpath += " and @PriceRange=\"" + tournament.PriceRange + "\"";
                }
            }

            if (tournament.Location != "")
            {
                if (count == 0)
                {
                    xpath += "contains(@Location, \"" + tournament.Location + "\")";
                    count++;
                }
                else
                {
                    xpath += " and contains(@Location, \"" + tournament.Location + "\")";
                }
            }

            if (tournament.Commentators != "")
            {
                if (count == 0)
                {
                    xpath += "contains(@Commentators, \"" + tournament.Commentators + "\")";
                    count++;
                }
                else
                {
                    xpath += " and contains(@Commentators, \"" + tournament.Commentators + "\")";
                }
            }

            if (tournament.Participants != "")
            {
                if (count == 0)
                {
                    xpath += "contains(@Participants, \"" + tournament.Participants + "\")";
                    count++;
                }
                else
                {
                    xpath += " and contains(@Participants, \"" + tournament.Participants + "\")";
                }
            }

            if (tournament.Type != "")
            {
                if (count == 0)
                {
                    xpath += "@Type=\"" + tournament.Type + "\"";
                    count++;
                }
                else
                {
                    xpath += " and @Type=\"" + tournament.Type + "\"";
                }
            }

            xpath += "]";

            XmlNodeList res = doc.SelectNodes(xpath);

            if (res.Count != 0)
            {
                foreach (XmlNode nod in res)
                {
                    Tournaments temp = new Tournaments();

                    for (int i = 0; i < nod.Attributes.Count; i++)
                    {
                        if (nod.Attributes[i].Name.Equals("Title"))
                        {
                            temp.Title = nod.Attributes[i].Value;
                        }
                        if (nod.Attributes[i].Name.Equals("Date"))
                        {
                            temp.Date = nod.Attributes[i].Value;
                        }
                        if (nod.Attributes[i].Name.Equals("PriceRange"))
                        {
                            temp.PriceRange = nod.Attributes[i].Value;
                        }
                        if (nod.Attributes[i].Name.Equals("Location"))
                        {
                            temp.Location = nod.Attributes[i].Value;
                        }
                        if (nod.Attributes[i].Name.Equals("Commentators"))
                        {
                            temp.Commentators = nod.Attributes[i].Value;
                        }
                        if (nod.Attributes[i].Name.Equals("Participants"))
                        {
                            temp.Participants = nod.Attributes[i].Value;
                        }
                        if (nod.Attributes[i].Name.Equals("Type"))
                        {
                            temp.Type = nod.Attributes[i].Value;
                        }
                    }
                    result.Add(temp);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public List <Tournaments> Search(Tournaments tournament)
        {
            List <Tournaments> AllResult = new List <Tournaments>();
            var xmlReader = new XmlTextReader(@"C:\Users\qwert\Desktop\LAB2\LAB2\Tournaments.xml");

            while (xmlReader.Read())
            {
                if (xmlReader.HasAttributes)
                {
                    while (xmlReader.MoveToNextAttribute())
                    {
                        string Title        = "";
                        string Date         = "";
                        string PriceRange   = "";
                        string Location     = "";
                        string Commentators = "";
                        string Participants = "";
                        string Type         = "";

                        if (xmlReader.Name.Equals("Title") && (xmlReader.Value.Equals(tournament.Title) || tournament.Title.Equals(String.Empty)))
                        {
                            Title = xmlReader.Value;

                            xmlReader.MoveToNextAttribute();

                            if (xmlReader.Name.Equals("Date") && (xmlReader.Value.Equals(tournament.Date) || tournament.Date.Equals(String.Empty)))
                            {
                                Date = xmlReader.Value;

                                xmlReader.MoveToNextAttribute();

                                if (xmlReader.Name.Equals("PriceRange") && (tournament.PriceRange.Equals(String.Empty) || isPriceRange(xmlReader.Value, tournament.PriceRange)))
                                {
                                    PriceRange = xmlReader.Value;

                                    xmlReader.MoveToNextAttribute();

                                    if (xmlReader.Name.Equals("Location") && (xmlReader.Value.Contains(tournament.Location)) || tournament.Location.Equals(String.Empty))
                                    {
                                        Location = xmlReader.Value;

                                        xmlReader.MoveToNextAttribute();

                                        if (xmlReader.Name.Equals("Commentators") && (xmlReader.Value.Contains(tournament.Commentators) || tournament.Commentators.Equals(String.Empty)))
                                        {
                                            Commentators = xmlReader.Value;

                                            xmlReader.MoveToNextAttribute();

                                            if (xmlReader.Name.Equals("Participants") && (xmlReader.Value.Contains(tournament.Participants) || tournament.Participants.Equals(String.Empty)))
                                            {
                                                Participants = xmlReader.Value;

                                                xmlReader.MoveToNextAttribute();

                                                if (xmlReader.Name.Equals("Type") && (xmlReader.Value.Equals(tournament.Type) || tournament.Type.Equals(String.Empty)))
                                                {
                                                    Type = xmlReader.Value;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (Title != "" && Date != "" && PriceRange != "" && Location != "" && Commentators != "" && Participants != "" && Type != "")
                        {
                            Tournaments myConcert = new Tournaments();
                            myConcert.Title        = Title;
                            myConcert.Date         = Date;
                            myConcert.PriceRange   = PriceRange;
                            myConcert.Location     = Location;
                            myConcert.Commentators = Commentators;
                            myConcert.Participants = Participants;
                            myConcert.Type         = Type;

                            AllResult.Add(myConcert);
                        }
                    }
                }
            }

            xmlReader.Close();
            return(AllResult);
        }
Ejemplo n.º 4
0
        private void search()
        {
            richTextBox1.Text = "";
            Tournaments tournament = new Tournaments();

            tournament.Title        = "";
            tournament.Date         = "";
            tournament.PriceRange   = "";
            tournament.Location     = "";
            tournament.Commentators = "";
            tournament.Participants = "";
            tournament.Type         = "";
            bool ex = false;

            if (checkBox1.Checked && comboBox1.SelectedItem != null)
            {
                tournament.Title = comboBox1.SelectedItem.ToString();
                ex = true;
            }

            if (checkBox2.Checked && comboBox2.SelectedItem != null)
            {
                tournament.Date = comboBox2.SelectedItem.ToString();
                ex = true;
            }

            if (Price.Checked && PriceL.SelectedItem != null)
            {
                tournament.PriceRange = PriceL.SelectedItem.ToString();
                ex = true;
            }
            if (checkBox4.Checked && comboBox4.SelectedItem != null)
            {
                tournament.Location = comboBox4.SelectedItem.ToString();
                ex = true;
            }
            if (checkBox5.Checked && comboBox5.SelectedItem != null)
            {
                tournament.Commentators = comboBox5.SelectedItem.ToString();
                ex = true;
            }
            if (checkBox6.Checked && comboBox6.SelectedItem != null)
            {
                tournament.Participants = comboBox6.SelectedItem.ToString();
                ex = true;
            }
            if (checkBox7.Checked && comboBox7.SelectedItem != null)
            {
                tournament.Type = comboBox7.SelectedItem.ToString();
                ex = true;
            }
            IStrategy analizator = new DOMStrategy();

            if (DOM.Checked)
            {
                analizator = new DOMStrategy();
            }

            if (radioButton2.Checked)
            {
                analizator = new SAXStrategy();
            }

            if (radioButton3.Checked)
            {
                analizator = new LINQToXMLStrategy();
            }
            if (ex)
            {
                List <Tournaments> result = analizator.Search(tournament);

                foreach (Tournaments conc in result)
                {
                    richTextBox1.Text += "Назва: " + conc.Title + "\n";
                    richTextBox1.Text += "Дата: " + conc.Date + "\n";
                    richTextBox1.Text += "Цінова категорія: " + conc.PriceRange + "\n";
                    richTextBox1.Text += "Місце проведення: " + conc.Location + "\n";
                    richTextBox1.Text += "Коментатори: " + conc.Commentators + "\n";
                    richTextBox1.Text += "Учасники: " + conc.Participants + "\n";
                    richTextBox1.Text += "Тип: " + conc.Type + "\n";

                    richTextBox1.Text += "\n\n\n";
                }
            }
            else
            {
                MessageBox.Show("Заповніть хоча б одне поле");
            }
        }