Пример #1
0
        public static double Blydo_Price(blydo blyd)
        {
            Baza   bd    = new Baza();
            double Summa = 0;

            System.Data.Entity.DbSet <Ingridients> ingridients = bd.Ingridients;
            List <string> List_Ing = blyd.GetIng();
            List <string> in_Price = new List <string>();

            int Pos = 0;


            foreach (var ing in ingridients)
            {
                Pos = 0;
                foreach (var k in in_Price)
                {
                    if (k.Substring(0, 5) == ing.Ing_Name.Substring(0, 5))
                    {
                        Pos++; break;
                    }
                }



                if (Pos == 0)
                {
                    for (int i = 0; i < blyd.GetIng().Count; i++)
                    {
                        if (List_Ing[i].Substring(0, 5) == ing.Ing_Name.Substring(0, 5))
                        {
                            Summa += ing.ING_Price;

                            Pos = i;
                            in_Price.Add(List_Ing[i].Substring(0, 5));
                            break;
                        }
                    }
                }
            }

            return(Summa);
        }
Пример #2
0
        static public async void Start_Parse(ToolStripStatusLabel tl)
        {
            Baza      db     = new Baza();
            Recipe    recipe = new Recipe();
            WebClient wc     = new WebClient();
            Regex     reg    = new Regex(@"\....$");

            tl.Text = "Удаление старых данных";
            List <Recipe> list_Rec = new List <Recipe>();

            foreach (var item in db.Cooking_Method)
            {
                db.Cooking_Method.Attach(item);
                db.Cooking_Method.Remove(item);
            }
            foreach (var item in db.Recipe)
            {
                db.Recipe.Attach(item);
                db.Recipe.Remove(item);
            }

            for (int i = blydo_BD.start_parse; i < blydo_BD.end_parse; i++)
            {
                tl.Text = $"Обновлене: {i} из {blydo_BD.end_parse}";

                await Task.Run(() => PageParsing(i));

                int Counter = 0;

                list_Rec.Add(new Recipe());


                foreach (var k in blydo.GetIng())
                {
                    list_Rec[Counter].Ing_List += k;
                }
                try
                {
                    wc.DownloadFile(blydo.BlydoPicture, blydo.BlydoName + "0" + ".png");
                }
                catch { continue; }
                list_Rec[Counter].Rec_Pic = blydo.BlydoName + "0" + ".png" + " * ";
                int number = 1;
                foreach (var item in blydo.BlydoSP_Picture)
                {
                    wc.DownloadFile("https://e-dostavka.by" + item.GetAttribute("href"), blydo.BlydoName + Convert.ToString(number) + ".png");
                    list_Rec[Counter].Rec_Pic += blydo.BlydoName + Convert.ToString(number) + ".png" + " * ";
                    number++;
                }
                list_Rec[Counter].Ingr_Count = blydo.GetIng().Count.ToString();

                list_Rec[Counter].Rec_Name = blydo.BlydoName;


                list_Rec[Counter].Cooking_Method = new Cooking_Method();



                foreach (var k in blydo.BlydoSposobPrigotovleniya)
                {
                    list_Rec[Counter].Cooking_Method.Cooking_Order += k.GetAttribute("data-body").Replace("&nbsp;", "") + " * ";
                }

                db.Cooking_Method.Add(list_Rec[Counter].Cooking_Method);

                list_Rec[Counter].Rec_Price = blydo_BD.Blydo_Price(blydo);

                foreach (var item in list_Rec)
                {
                    if (item.Ing_List != null)
                    {
                        db.Recipe.Add(item);
                    }
                }
                db.SaveChanges();
            }
            tl.Text = "Готово!";
        }