コード例 #1
0
 private bool IfEqual(Car c1, CarSearch c2)
 {
     if (c1.brand != c2.brand && c2.brand != "")
     {
         return(false);
     }
     if (c1.model != c2.model && c2.model != "")
     {
         return(false);
     }
     if (c1.color != c2.color && c2.color != "")
     {
         return(false);
     }
     if (Convert.ToDouble(c1.volume) < c2.lowVolume || Convert.ToDouble(c1.volume) > c2.highVolume)
     {
         return(false);
     }
     if (Convert.ToInt32(c1.year) < c2.lowYear || Convert.ToInt32(c1.year) > c2.highYear)
     {
         return(false);
     }
     if (Convert.ToInt32(c1.price) < c2.lowPrice || Convert.ToInt32(c1.price) > c2.highPrice)
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
ファイル: SAX.cs プロジェクト: andrey-khristofor/oop
        public List <Car> Search(CarSearch c)
        {
            List <Car> result = new List <Car>();

            var reader = new XmlTextReader(path);

            string currBrand = "";

            while (reader.Read())
            {
                if (reader.Name == "brand")
                {
                    if (reader.HasAttributes)
                    {
                        reader.MoveToNextAttribute();
                        if (reader.Name.Equals("Brand"))
                        {
                            currBrand = reader.Value;
                        }
                    }
                }
                if (reader.Name == "car")
                {
                    if (reader.HasAttributes)
                    {
                        Car current = new Car();
                        current.brand = currBrand;
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name == "model")
                            {
                                current.model = reader.Value;
                            }
                            if (reader.Name == "year")
                            {
                                current.year = reader.Value;
                            }
                            if (reader.Name == "volume")
                            {
                                current.volume = reader.Value;
                            }
                            if (reader.Name == "price")
                            {
                                current.price = reader.Value;
                            }
                            if (reader.Name == "color")
                            {
                                current.color = reader.Value;
                            }
                        }
                        if (IfEqual(current, c))
                        {
                            result.Add(current);
                        }
                    }
                }
            }
            reader.Close();
            return(result);
        }
コード例 #3
0
ファイル: LINQtoXLM.cs プロジェクト: andrey-khristofor/oop
        public List <Car> Search(CarSearch c)
        {
            List <Car> result = new List <Car>();

            XDocument doc  = XDocument.Load(path);
            var       cars = from obj in doc.Descendants("car")
                             select new
            {
                brand  = (string)obj.Parent.Attribute("Brand"),
                model  = (string)obj.Attribute("model"),
                year   = (string)obj.Attribute("year"),
                volume = (string)obj.Attribute("volume"),
                price  = (string)obj.Attribute("price"),
                color  = (string)obj.Attribute("color")
            };

            foreach (var current in cars)
            {
                Car car = new Car();
                car.brand  = current.brand;
                car.model  = current.model;
                car.year   = current.year;
                car.volume = current.volume;
                car.price  = current.price;
                car.color  = current.color;
                if (IfEqual(car, c))
                {
                    result.Add(car);
                }
            }
            return(result);
        }
コード例 #4
0
        public List <Car> Search(CarSearch c)
        {
            string     currentBrand;
            List <Car> result = new List <Car>();

            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            XmlElement root = doc.DocumentElement;


            foreach (XmlNode n in root.ChildNodes)
            {
                foreach (XmlNode a in n.ChildNodes)
                {
                    Car current = new Car();
                    currentBrand = n.Attributes[0].Value;
                    if (currentBrand != c.brand && c.brand != "")
                    {
                        break;
                    }
                    else
                    {
                        current.brand = currentBrand;
                        foreach (XmlAttribute attribu in a.Attributes)
                        {
                            if (attribu.Name == "model")
                            {
                                current.model = attribu.InnerText;
                            }
                            if (attribu.Name == "year")
                            {
                                current.year = attribu.InnerText;
                            }
                            if (attribu.Name == "volume")
                            {
                                current.volume = attribu.InnerText;
                            }
                            if (attribu.Name == "price")
                            {
                                current.price = attribu.InnerText;
                            }
                            if (attribu.Name == "color")
                            {
                                current.color = attribu.InnerText;
                            }
                        }
                        if (IfEqual(current, c))
                        {
                            result.Add(current);
                        }
                    }
                }
            }
            return(result);
        }
コード例 #5
0
        private CarSearch FindParams()
        {
            CarSearch car = new CarSearch();

            if (BrandCheck.Checked)
            {
                car.brand = Brand.Text;
            }
            if (ModelCheck.Checked)
            {
                car.model = Model.Text;
            }
            if (ColorCheck.Checked)
            {
                car.color = Color.Text;
            }
            if (PriceCheck.Checked)
            {
                if (LowerPrice.Text != "")
                {
                    car.lowPrice = Convert.ToInt32(LowerPrice.Text);
                }
                if (HigherPrice.Text != "")
                {
                    car.highPrice = Convert.ToInt32(HigherPrice.Text);
                }
            }
            if (VolumeCheck.Checked)
            {
                if (LowerVolume.Text != "")
                {
                    car.lowVolume = Convert.ToDouble(LowerVolume.Text);
                }
                if (HigherVolume.Text != "")
                {
                    car.highVolume = Convert.ToDouble(HigherVolume.Text);
                }
            }
            if (YearCheck.Checked)
            {
                if (LowerYear.Text != "")
                {
                    car.lowYear = Convert.ToInt32(LowerYear.Text);
                }
                if (HigherYear.Text != "")
                {
                    car.highYear = Convert.ToInt32(HigherYear.Text);
                }
            }

            return(car);
        }
コード例 #6
0
        private void Find_Click(object sender, EventArgs e)
        {
            IStrategy strategy = new DOM(path);
            CarSearch c        = FindParams();

            if (Dom.Checked == true)
            {
                strategy = new DOM(path);
            }
            if (Sax.Checked == true)
            {
                strategy = new SAX(path);
            }
            if (Linq.Checked == true)
            {
                strategy = new LINQtoXML(path);
            }

            list = strategy.Search(c);
            PrintInfo(list);
            CreateXML();
        }