Ejemplo n.º 1
0
        List <Wardrobe> iStrategy.Algorithm(Wardrobe wardrobe, string path)
        {
            List <Wardrobe> MyWardobe = new List <Wardrobe>();
            XmlDocument     document  = new XmlDocument();

            try
            {
                document.Load(path);
                string filter = GetFilterString(wardrobe);

                XmlNodeList nodes = document.SelectNodes(filter);

                foreach (XmlNode n in nodes)
                {
                    Wardrobe wr = new Wardrobe();

                    wr.Brand  = n.Attributes.GetNamedItem("Brand").InnerText;
                    wr.Type   = n.Attributes.GetNamedItem("Type").InnerText;
                    wr.Fabric = n.Attributes.GetNamedItem("Fabric").InnerText;
                    wr.Color  = n.Attributes.GetNamedItem("Color").InnerText;
                    wr.Season = n.Attributes.GetNamedItem("Season").InnerText;

                    MyWardobe.Add(wr);
                }
            }

            catch (SystemException)
            {
                string message = "File error!";
                MessageBox.Show(message);
            }

            return(MyWardobe);
        }
Ejemplo n.º 2
0
        private void SearchWardrobe()
        {
            iStrategy       clothing;
            Wardrobe        war = new Wardrobe();
            List <Wardrobe> wr  = new List <Wardrobe>();

            if (checkBoxBrand.Checked)
            {
                war.Brand = cBoxBrand.Text;
            }

            if (checkBoxType.Checked)
            {
                war.Type = cBoxType.Text;
            }

            if (checkBoxFabric.Checked)
            {
                war.Fabric = cBoxFabric.Text;
            }

            if (checkBoxColor.Checked)
            {
                war.Color = cBoxColor.Text;
            }

            if (checkBoxSeason.Checked)
            {
                war.Season = cBoxSeason.Text;
            }

            if (radioButtonDom.Checked)
            {
                clothing = new Dom();
                wr       = clothing.Algorithm(war, path);
            }

            else
            {
                if (radioButtonSax.Checked)
                {
                    clothing = new Sax();
                    wr       = clothing.Algorithm(war, path);
                }
                else if (radioButtonLinq.Checked)
                {
                    clothing = new Linq();
                    wr       = clothing.Algorithm(war, path);
                }
            }

            PrintWardrobeList(wr);
        }
Ejemplo n.º 3
0
        List <Wardrobe> iStrategy.Algorithm(Wardrobe wardrobe, string path)
        {
            List <Wardrobe> MyWardobe = new List <Wardrobe>();
            var             document  = XDocument.Load(path);

            try
            {
                var result = from obj in document.Descendants("Wardrobe")
                             where
                             (
                    (obj.Attribute("Brand").Value.Equals(wardrobe.Brand) || wardrobe.Brand.Equals(String.Empty)) &&
                    (obj.Attribute("Type").Value.Equals(wardrobe.Type) || wardrobe.Type.Equals(String.Empty)) &&
                    (obj.Attribute("Fabric").Value.Equals(wardrobe.Fabric) || wardrobe.Fabric.Equals(String.Empty)) &&
                    (obj.Attribute("Color").Value.Equals(wardrobe.Color) || wardrobe.Color.Equals(String.Empty)) &&
                    (obj.Attribute("Season").Value.Equals(wardrobe.Season) || wardrobe.Season.Equals(String.Empty))
                             )
                             select new
                {
                    Brand  = (string)obj.Attribute("Brand").Value,
                    Type   = (string)obj.Attribute("Type").Value,
                    Fabric = (string)obj.Attribute("Fabric").Value,
                    Color  = (string)obj.Attribute("Color").Value,
                    Season = (string)obj.Attribute("Season").Value,
                };
                foreach (var i in result)
                {
                    Wardrobe NewWardrobe = new Wardrobe();
                    NewWardrobe.Brand  = i.Brand;
                    NewWardrobe.Type   = i.Type;
                    NewWardrobe.Fabric = i.Fabric;
                    NewWardrobe.Color  = i.Color;
                    NewWardrobe.Season = i.Season;

                    MyWardobe.Add(NewWardrobe);
                }
            }

            catch (SystemException ex)
            {
                string message = "File error!";
                MessageBox.Show(message);
            }

            return(MyWardobe);
        }
Ejemplo n.º 4
0
        List <Wardrobe> iStrategy.Algorithm(Wardrobe wardrobe, string path)
        {
            List <Wardrobe> MyWardobe = new List <Wardrobe>();
            var             xmlReader = new XmlTextReader(path);

            try
            {
                while (xmlReader.Read())
                {
                    if (xmlReader.HasAttributes)
                    {
                        while (xmlReader.MoveToNextAttribute())
                        {
                            string Brand  = "";
                            string Type   = "";
                            string Fabric = "";
                            string Color  = "";
                            string Season = "";

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

                                xmlReader.MoveToNextAttribute();

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

                                    xmlReader.MoveToNextAttribute();

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

                                        xmlReader.MoveToNextAttribute();

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

                                            xmlReader.MoveToNextAttribute();

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

                                                xmlReader.MoveToNextAttribute();
                                            }
                                        }
                                    }
                                }
                            }

                            if (Brand != "" && Type != "" && Fabric != "" && Color != "" && Season != "")
                            {
                                Wardrobe myWardrobe = new Wardrobe();
                                myWardrobe.Brand  = Brand;
                                myWardrobe.Type   = Type;
                                myWardrobe.Fabric = Fabric;
                                myWardrobe.Color  = Color;
                                myWardrobe.Season = Season;

                                MyWardobe.Add(myWardrobe);
                            }
                        }
                    }
                }
            }

            catch (SystemException ex)
            {
                string message = "File error!";
                MessageBox.Show(message);
            }

            xmlReader.Close();
            return(MyWardobe);
        }
Ejemplo n.º 5
0
        private string GetFilterString(Wardrobe wardrobe)
        {
            string filter = "//Wardrobe";
            bool   f1     = false;

            if (wardrobe.Brand != "" || wardrobe.Type != "" || wardrobe.Fabric != "" || wardrobe.Color != "" || wardrobe.Season != "")
            {
                filter += "[";



                if (wardrobe.Brand != "")
                {
                    filter += @"@Brand=""" + wardrobe.Brand + @"""";
                    f1      = true;
                }
                if ((f1) && (wardrobe.Type != "" || wardrobe.Fabric != "" || wardrobe.Color != "" || wardrobe.Season != ""))
                {
                    filter += " and ";
                    f1      = false;
                }
                if (wardrobe.Fabric != "")
                {
                    filter += @"@Fabric=""" + wardrobe.Fabric + @"""";
                    f1      = true;
                }

                if ((f1) && (wardrobe.Type != "" || wardrobe.Color != "" || wardrobe.Season != ""))
                {
                    filter += " and ";
                    f1      = false;
                }
                if (wardrobe.Type != "")
                {
                    filter += @"@Type=""" + wardrobe.Type + @"""";
                    f1      = true;
                }

                if ((f1) && (wardrobe.Color != "" || wardrobe.Season != ""))
                {
                    filter += " and ";
                    f1      = false;
                }
                if (wardrobe.Color != "")
                {
                    filter += @"@Color=""" + wardrobe.Color + @"""";
                    f1      = true;
                }

                if ((f1) && wardrobe.Season != "")
                {
                    filter += " and ";
                    f1      = false;
                }
                if (wardrobe.Season != "")
                {
                    filter += @"@Season=""" + wardrobe.Season + @"""";
                }
                filter += "]";
            }

            return(filter);
        }