Beispiel #1
0
        private Guitar OurGuitar()
        {
            string[] info = new string[6];
            if (Type.Checked)
            {
                info[0] = Convert.ToString(TypeBox.Text);
            }
            if (Brand.Checked)
            {
                info[1] = Convert.ToString(BrandBox.Text);
            }
            if (Body.Checked)
            {
                info[2] = Convert.ToString(BodyBox.Text);
            }
            if (Material.Checked)
            {
                info[3] = Convert.ToString(MaterialBox.Text);
            }
            if (Country.Checked)
            {
                info[4] = Convert.ToString(CountryBox.Text);
            }
            Guitar IdealGuitar = new Guitar(info);

            return(IdealGuitar);
        }
Beispiel #2
0
        public List <Guitar> Algorithm(Guitar guitar, string path)
        {
            List <XElement> match = (from val in doc.Descendants("Guitar")
                                     where
                                     ((guitar.Type == null || guitar.Type == val.Attribute("TYPE").Value) &&
                                      (guitar.Brand == null || guitar.Brand == val.Attribute("BRAND").Value) &&
                                      (guitar.Body == null || guitar.Body == val.Attribute("BODY").Value) &&
                                      (guitar.Material == null || guitar.Material == val.Attribute("MATERIAL").Value) &&
                                      (guitar.Country == null || guitar.Country == val.Attribute("COUNTRY").Value) &&
                                      (guitar.Name == null || guitar.Name == val.Attribute("NAME").Value))
                                     select val).ToList();

            foreach (XElement obj in match)
            {
                Guitar guitar1 = new Guitar();
                guitar1.Type     = obj.Attribute("TYPE").Value;
                guitar1.Brand    = obj.Attribute("BRAND").Value;
                guitar1.Body     = obj.Attribute("BODY").Value;
                guitar1.Material = obj.Attribute("MATERIAL").Value;
                guitar1.Country  = obj.Attribute("COUNTRY").Value;
                guitar1.Name     = obj.Attribute("NAME").Value;
                info.Add(guitar1);
            }
            return(info);
        }
Beispiel #3
0
        private List <Guitar> Filtr(List <Guitar> all, Guitar param)
        {
            List <Guitar> result = new List <Guitar>();

            foreach (Guitar g in all)
            {
                try
                {
                    if (
                        (g.Type == param.Type || param.Type == null) &&
                        (g.Brand == param.Brand || param.Brand == null) &&
                        (g.Body == param.Body || param.Body == null) &&
                        (g.Material == param.Material || param.Material == null) &&
                        (g.Country == param.Country || param.Country == null)
                        )
                    {
                        result.Add(g);
                    }
                }
                catch
                {
                }
            }
            return(result);
        }
Beispiel #4
0
        private Guitar Info(XmlNode node)
        {
            Guitar guitar = new Guitar();

            guitar.Type     = node.Attributes.GetNamedItem("TYPE").Value;
            guitar.Brand    = node.Attributes.GetNamedItem("BRAND").Value;
            guitar.Body     = node.Attributes.GetNamedItem("BODY").Value;
            guitar.Material = node.Attributes.GetNamedItem("MATERIAL").Value;
            guitar.Country  = node.Attributes.GetNamedItem("COUNTRY").Value;
            guitar.Name     = node.Attributes.GetNamedItem("NAME").Value;
            return(guitar);
        }
Beispiel #5
0
 public bool Comparing(Guitar guitar)
 {
     if ((this.Type == guitar.Type) &&
         (this.Brand == guitar.Brand) &&
         (this.Body == guitar.Body) &&
         (this.Material == guitar.Material) &&
         (this.Country == guitar.Country))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #6
0
        public List <Guitar> Algorithm(Guitar guitar, string path)
        {
            info.Clear();
            XmlReader     reader = XmlReader.Create(path);
            List <Guitar> result = new List <Guitar>();
            Guitar        gt     = null;

            while (reader.Read())
            {
                if (reader.Name == "Guitar")
                {
                    gt = new Guitar();
                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name == "TYPE")
                            {
                                gt.Type = reader.Value;
                            }
                            if (reader.Name == "BRAND")
                            {
                                gt.Brand = reader.Value;
                            }
                            if (reader.Name == "BODY")
                            {
                                gt.Body = reader.Value;
                            }
                            if (reader.Name == "MATERIAL")
                            {
                                gt.Material = reader.Value;
                            }
                            if (reader.Name == "COUNTRY")
                            {
                                gt.Country = reader.Value;
                            }
                            if (reader.Name == "NAME")
                            {
                                gt.Name = reader.Value;
                            }
                        }
                        result.Add(gt);
                    }
                }
            }
            info = Filtr(result, guitar);
            return(info);
        }
Beispiel #7
0
        public List <Guitar> Algorithm(Guitar guitar, string path)
        {
            List <List <Guitar> > info = new List <List <Guitar> >();

            try
            {
                if (guitar.Type != null)
                {
                    info.Add(SearchByParam("TYPE", guitar.Type, doc));
                }
                if (guitar.Brand != null)
                {
                    info.Add(SearchByParam("BRAND", guitar.Brand, doc));
                }
                if (guitar.Body != null)
                {
                    info.Add(SearchByParam("BODY", guitar.Body, doc));
                }
                if (guitar.Material != null)
                {
                    info.Add(SearchByParam("MATERIAL", guitar.Material, doc));
                }
                if (guitar.Country != null)
                {
                    info.Add(SearchByParam("COUNTRY", guitar.Country, doc));
                }
            }
            catch
            {
            }
            if (guitar.Type == null && guitar.Brand == null && guitar.Body == null && guitar.Material == null && guitar.Country == null)
            {
                return(AllGuitars(doc));
            }
            return(Cross(info));
        }
Beispiel #8
0
        private void Search_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            Guitar guitar = OurGuitar();

            if (Linq.Checked)
            {
                IStrategy CurrentStrategy = new Linq(path);
                final = CurrentStrategy.Algorithm(guitar, path);
                Output(final);
            }
            if (Dom.Checked)
            {
                IStrategy CurrentStrategy = new Dom(path);
                final = CurrentStrategy.Algorithm(guitar, path);
                Output(final);
            }
            if (Sax.Checked)
            {
                IStrategy CurrentStrategy = new Sax(path);
                final = CurrentStrategy.Algorithm(guitar, path);
                Output(final);
            }
        }
Beispiel #9
0
 public List <Guitar> Algorithm(Guitar guitar, string path)
 {
     return(Algo.Algorithm(guitar, path));
 }