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); }
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(" ", "") + " * "; } 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 = "Готово!"; }
public static void DynamicRecepy(Point startpos, Form form, Recipe recipe) { Baza baza = new Baza(); System.Data.Entity.DbSet <Recipe> recepts = baza.Recipe; List <string> vs = recipe.Cooking_Method.Cooking_Order.Split('*').ToList(); int count = vs.Count - 1; form.Controls.RemoveByKey("Dynamic"); Panel MainPanel = new Panel(); MainPanel.Name = "Dynamic"; MainPanel.Location = startpos; MainPanel.Height = form.Height - 410; MainPanel.Width = form.Width - startpos.X - 20; MainPanel.SendToBack(); MainPanel.AutoScroll = true; form.Controls.Add(MainPanel); var label = new TextBox[count]; var pictures = new PictureBox[count]; for (int i = 0; i < count; i++) { if (i == 0) { pictures[i] = new PictureBox(); pictures[i].Name = "Dynamic"; pictures[i].Location = new Point(1, 1); pictures[i].Height = 150; pictures[i].Width = 200; pictures[i].SizeMode = PictureBoxSizeMode.StretchImage; pictures[i].Image = Image.FromFile(recipe.Rec_Name + (i + 1) + ".png"); label[i] = new TextBox(); label[i].Name = "Dynamic"; label[i].Multiline = true; label[i].ReadOnly = true; label[i].Location = new Point(pictures[i].Location.X + pictures[i].Width + 10, pictures[i].Location.Y); label[i].Text = vs[i]; label[i].Font = new Font("SECRET FONT", 18, FontStyle.Bold); label[i].Height = pictures[i].Height; label[i].ScrollBars = ScrollBars.None; label[i].Width = MainPanel.Width - pictures[i].Width - 10 - 10 - 40; MainPanel.Controls.Add(pictures[i]); MainPanel.Controls.Add(label[i]); continue; } pictures[i] = new PictureBox(); pictures[i].Name = "Dynamic"; pictures[i].Location = new Point(pictures[i - 1].Location.X, pictures[i - 1].Location.Y + pictures[i - 1].Height + 20); pictures[i].Height = 150; pictures[i].Width = 200; pictures[i].SizeMode = PictureBoxSizeMode.StretchImage; pictures[i].Image = Image.FromFile(recipe.Rec_Name + (i + 1) + ".png"); label[i] = new TextBox(); label[i].Name = "Dynamic"; label[i].Multiline = true; label[i].ReadOnly = true; label[i].Location = new Point(pictures[i].Location.X + pictures[i].Width + 10, pictures[i].Location.Y); label[i].Text = vs[i]; label[i].Font = new Font("SECRET FONT", 18, FontStyle.Bold); label[i].Height = pictures[i].Height; label[i].ScrollBars = ScrollBars.None; label[i].Width = MainPanel.Width - pictures[i].Width - 10 - 10 - 40; MainPanel.Controls.Add(pictures[i]); MainPanel.Controls.Add(label[i]); } }