Ejemplo n.º 1
0
        internal void ParseFileUpdateDB()
        {
            form.buttonDownload.Enabled = false;
            form.button1.Enabled = false;
            OpenFile of = new OpenFile("vo.xml");
            List<OkPneuTire> lt = of.OpenXml();

            Dictionary<string, OkPneuTire> DictData = new Dictionary<string, OkPneuTire>();
            OkPneuTire MatchTire = new OkPneuTire();
            foreach (var i in lt)
            {

                if (i.EAN.Length > 14) i.EAN = i.EAN.Substring(0, 13);
                if (i.Manufacturer.Length > 10) i.Manufacturer = i.Manufacturer.Substring(0, 9);
                if (i.code.Length > 15) i.code = i.code.Substring(0, 14);
                if (i.Name.Length > 50) i.Name = i.Name.Substring(0, 49);
                if (i.Description.Length > 2000) i.Description = i.Description.Substring(0, 1999);
                i.ImageURL = i.ImageURL.Trim();
                if (i.ImageURL.Length > 200) i.ImageURL = i.ImageURL.Substring(0, 199);
                if (i.EAN == "" || i.EAN == null) continue;

                if (DictData.TryGetValue(i.EAN, out MatchTire))
                {
                    DictData.Remove(i.EAN);
                    MatchTire = ChoseRightTire(i, MatchTire);
                    DictData.Add(MatchTire.EAN, MatchTire);
                }
                else
                {
                    DictData.Add(i.EAN, i);
                }
            }
            UpdateDB(DictData.Values.ToList());
            form.buttonDownload.Enabled = true;
            form.button1.Enabled = true;
        }