示例#1
0
        private CarSale OurCarSale()
        {
            CarSale cs = new CarSale();

            if (checkBoxBody.Checked)
            {
                cs.Body = comboBoxBody.SelectedItem.ToString();
            }
            if (checkBoxBrand.Checked)
            {
                cs.Brand = comboBoxBrand.SelectedItem.ToString();
            }
            if (checkBoxModel.Checked)
            {
                cs.Model = comboBoxModel.SelectedItem.ToString();
            }
            if (checkBoxRegion.Checked)
            {
                cs.Region = comboBoxRegion.SelectedItem.ToString();
            }
            if (checkBoxYear.Checked)
            {
                cs.Year = comboBoxYear.SelectedItem.ToString();
            }
            if (checkBoxPrice.Checked)
            {
                cs.Price = comboBoxPrice.SelectedItem.ToString();
            }
            return(cs);
        }
示例#2
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            rtb.Clear();
            CarSale   carSale = OurCarSale();
            IStrategy CurrentStrategy;

            if (LINQradioButton.Checked)
            {
                CurrentStrategy = new Linq(path);
                final           = CurrentStrategy.Algorithm(carSale, path);
                Output(final);
            }
            else if (DOMradioButton.Checked)
            {
                CurrentStrategy = new Dom(path);
                final           = CurrentStrategy.Algorithm(carSale, path);
                Output(final);
            }
            else if (SAXradioButton.Checked)
            {
                CurrentStrategy = new Sax();
                final           = CurrentStrategy.Algorithm(carSale, path);
                Output(final);
            }
        }
示例#3
0
文件: Linq.cs 项目: GlebiyP/Laba2
        public List <CarSale> Algorithm(CarSale carSale, string path)
        {
            List <XElement> result = (from val in doc.Descendants("Car")
                                      where
                                      ((carSale.Body == null || carSale.Body == val.Attribute("Body").Value) &&
                                       (carSale.Brand == null || carSale.Brand == val.Attribute("Brand").Value) &&
                                       (carSale.Model == null || carSale.Model == val.Attribute("Model").Value) &&
                                       (carSale.Region == null || carSale.Region == val.Attribute("Region").Value) &&
                                       (carSale.Year == null || isYearRange(val.Attribute("Year").Value, carSale.Year)) &&
                                       (carSale.Price == null || isPriceRange(val.Attribute("Price").Value, carSale.Price)))
                                      select val).ToList();

            foreach (XElement obj in result)
            {
                CarSale carSale1 = new CarSale();
                carSale1.Body   = obj.Attribute("Body").Value;
                carSale1.Brand  = obj.Attribute("Brand").Value;
                carSale1.Model  = obj.Attribute("Model").Value;
                carSale1.Region = obj.Attribute("Region").Value;
                carSale1.Year   = obj.Attribute("Year").Value;
                carSale1.Price  = obj.Attribute("Price").Value;
                info.Add(carSale1);
            }
            return(info);
        }
示例#4
0
文件: CarSale.cs 项目: GlebiyP/Laba2
 public bool Comparing(CarSale carSale)
 {
     if ((this.Body == carSale.Body) &&
         (this.Brand == carSale.Brand) &&
         (this.Model == carSale.Model) &&
         (this.Region == carSale.Region) &&
         (this.Year == carSale.Year) &&
         (this.Price == carSale.Price))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#5
0
文件: Sax.cs 项目: GlebiyP/Laba2
        public List <CarSale> Algorithm(CarSale carSale, string path)
        {
            List <CarSale> AllResults = new List <CarSale>();
            var            xmlReader  = new XmlTextReader(path);

            while (xmlReader.Read())
            {
                if (xmlReader.HasAttributes)
                {
                    while (xmlReader.MoveToNextAttribute())
                    {
                        string Body   = "";
                        string Brand  = "";
                        string Model  = "";
                        string Region = "";
                        string Year   = "";
                        string Price  = "";

                        if (xmlReader.Name.Equals("Body") && (xmlReader.Value.Equals(carSale.Body) || carSale.Body == null))
                        {
                            Body = xmlReader.Value;
                            xmlReader.MoveToNextAttribute();

                            if (xmlReader.Name.Equals("Brand") && (xmlReader.Value.Equals(carSale.Brand) || carSale.Brand == null))
                            {
                                Brand = xmlReader.Value;
                                xmlReader.MoveToNextAttribute();

                                if (xmlReader.Name.Equals("Model") && (xmlReader.Value.Equals(carSale.Model) || carSale.Model == null))
                                {
                                    Model = xmlReader.Value;
                                    xmlReader.MoveToNextAttribute();

                                    if (xmlReader.Name.Equals("Region") && (xmlReader.Value.Equals(carSale.Region) || carSale.Region == null))
                                    {
                                        Region = xmlReader.Value;
                                        xmlReader.MoveToNextAttribute();

                                        if (xmlReader.Name.Equals("Year") && (isYearRange(xmlReader.Value, carSale.Year) || carSale.Year == null))
                                        {
                                            Year = xmlReader.Value;
                                            xmlReader.MoveToNextAttribute();

                                            if (xmlReader.Name.Equals("Price") && (isPriceRange(xmlReader.Value, carSale.Price) || carSale.Price == null))
                                            {
                                                Price = xmlReader.Value;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (Body != "" && Brand != "" && Model != "" && Region != "" && Year != "" && Price != "")
                        {
                            CarSale carSale1 = new CarSale();
                            carSale1.Body   = Body;
                            carSale1.Brand  = Brand;
                            carSale1.Model  = Model;
                            carSale1.Region = Region;
                            carSale1.Year   = Year;
                            carSale1.Price  = Price;

                            AllResults.Add(carSale1);
                        }
                    }
                }
            }
            xmlReader.Close();
            return(AllResults);
        }
示例#6
0
文件: CarSale.cs 项目: GlebiyP/Laba2
 public List <CarSale> Algorithm(CarSale parametrs, string path)
 {
     return(Alg.Algorithm(parametrs, path));
 }
示例#7
0
文件: Dom.cs 项目: GlebiyP/Laba2
        public List <CarSale> Algorithm(CarSale carSale, string path)
        {
            List <CarSale> res  = new List <CarSale>();
            XmlNode        node = doc.DocumentElement;

            foreach (XmlNode nod in node.ChildNodes)
            {
                string Body   = "";
                string Brand  = "";
                string Model  = "";
                string Region = "";
                string Year   = "";
                string Price  = "";

                foreach (XmlAttribute attribute in nod.Attributes)
                {
                    if (attribute.Name.Equals("Body") && (attribute.Value.Equals(carSale.Body) || carSale.Body == null))
                    {
                        Body = attribute.Value;
                    }

                    if (attribute.Name.Equals("Brand") && (attribute.Value.Equals(carSale.Brand) || carSale.Brand == null))
                    {
                        Brand = attribute.Value;
                    }

                    if (attribute.Name.Equals("Model") && (attribute.Value.Equals(carSale.Model) || carSale.Model == null))
                    {
                        Model = attribute.Value;
                    }

                    if (attribute.Name.Equals("Region") && (attribute.Value.Equals(carSale.Region) || carSale.Region == null))
                    {
                        Region = attribute.Value;
                    }

                    if (attribute.Name.Equals("Year") && (isYearRange(attribute.Value, carSale.Year) || carSale.Year == null))
                    {
                        Year = attribute.Value;
                    }

                    if (attribute.Name.Equals("Price") && (isPriceRange(attribute.Value, carSale.Price) || carSale.Price == null))
                    {
                        Price = attribute.Value;
                    }
                }

                if (Body != "" && Brand != "" && Model != "" && Region != "" && Year != "" && Price != "")
                {
                    CarSale carSale1 = new CarSale();
                    carSale1.Body   = Body;
                    carSale1.Brand  = Brand;
                    carSale1.Model  = Model;
                    carSale1.Region = Region;
                    carSale1.Year   = Year;
                    carSale1.Price  = Price;
                    res.Add(carSale1);
                }
            }
            return(res);
        }