public void sum_test() { LProduct test = new LProduct(); //Arrange int one = 5; int two = 6; int Expect = 11; //Act int actual = test.Sum(one, two); //Assert Assert.Equal(Expect, actual); }
private static void wp() { string[] urla = XmlTools.GetUrls.Where(x => x.Contains("/products/") && x.Contains("/pumps/") && x.Length > x.IndexOf("/pumps/") + 7).Select(x => x).Skip(14).Take(3).ToArray(); foreach (string url in urla) { LProduct product = new LProduct(); using (LeyboldHelper leybold = new LeyboldHelper()) { product = leybold.GetProduct(url); } using (WooCommerce woo = new WooCommerce()) { woo.createPost(product); } } }
private void btnSave_Click(object sender, EventArgs e) { Product product = new Product(); product.ProductName = txtProductName.Text.Trim(); product.Price = nudPrice.Value; product.Stock = nudStock.Value; product.CategoryId = Convert.ToInt32(cboCategory.SelectedValue.ToString()); //validacion if (product.ProductName.Length < 5) { txtProductName.Focus(); MessageBox.Show("Nombre del Producto Obligatorio", "Mensaje"); return; } LProduct lProduct = new LProduct(); bool answer = false; if (Operation == "UPDATE_PRODUCT") { //se va a actualizar el registro product.ProductId = Convert.ToInt32(txtId.Text.Trim()); answer = lProduct.Update(product); } else { //un registro nuevo answer = lProduct.Register(product); } if (!answer) { MessageBox.Show("Ocurrio un Error", "Mensaje"); return; } MessageBox.Show("La Operacion se Realizo con exito.", "Mensaje"); this.DialogResult = DialogResult.OK; }
private void ProductList_Load(object sender, EventArgs e) { lProduct = new LProduct(); ShowProducts(lProduct.GetAll()); }
public LProduct GetProduct(string url) { LProduct product = new LProduct(); HtmlDocument doc = new HtmlDocument(); using (HtmlHelper html = new HtmlHelper()) { doc = html.GetDocument(url); } var pagewrap = doc.DocumentNode.SelectSingleNode("//body//div[@class='page-wrap']"); //var pro = pagewrap.SelectSingleNode("//section[@class='content-main']"); var content = pagewrap.ChildNodes["section"].SelectSingleNode("//div[@class='content-main--inner']//div[@class='content--wrapper']//div[@class='content product--details']"); var divDetails = content.SelectSingleNode("//div[@class='product--detail-upper block-group']"); #region images var divImages = divDetails.SelectSingleNode("//div[@class='product--image-container image-slider product--image-zoom']"); var imageMain = divImages.SelectNodes("//div[@class='image-slider--container']//div[@class='image-slider--slide']//div[@class='image--box image-slider--item']//span[@class='image--element']"); List <LeyboldImage> productImages = new List <LeyboldImage>(); foreach (var item in imageMain.Where(x => x.HasAttributes)) { LeyboldImage image = new LeyboldImage(); image.Large = item.Attributes["data-img-large"].Value; image.Small = item.Attributes["data-img-small"].Value; image.Orginal = item.Attributes["data-img-original"].Value; image.Title = item.Attributes["data-alt"].Value; productImages.Add(image); } //var imageThumbnails = divImages.SelectNodes("//div[@class='image-slider--thumbnails-slide']//img"); //List<string> imgs = new List<string>(); //foreach (var item in imageThumbnails) //{ // imgs.Add(item.Attributes["srcset"].Value.Replace(",", "")); //} #endregion #region Title Buyer product.TitleEn = divDetails.SelectSingleNode("//div[@class='product--buybox block']//header[@class='product--header']//div[@class='product--info']//h1") .InnerText.Replace("\n", " ").Replace(" ", " ").Trim(); product.Title = "پمپ وکیوم " + product.TitleEn; product.Property = divDetails.SelectSingleNode("//div[@class='product--buybox block']//header[@class='product--header']//div[@class='product--info']//div[@class='product--properties']").InnerHtml.Replace("\n", "").Trim(); #endregion #region Tabs var divTabs = content.SelectSingleNode("//div[@class='em-tabs']"); //foreach (HtmlTextNode node in textNodes) // node.Text = node.Text.Replace(node.Text, translate.Translate(node.Text).Result); var tabs = divTabs.SelectNodes("div"); foreach (var item in tabs) { if (!string.IsNullOrWhiteSpace(item.InnerHtml.Trim())) { using (HtmlHelper html = new HtmlHelper()) { string tabName = item.Attributes["id"].Value.Replace("\n", "").Trim(); if (tabName.ToLower() == "description") { string text = html.StripHTML(item.InnerText.Trim()).Replace(" ", " "); string[] paraphs = text.Split('\n'); product.Html = "<p>" + translate.Translate(new InputTranslate { Input = text }).Result + "</p>"; product.HtmlEn = "<p>" + string.Join("<p> </p>", paraphs) + "</p>"; } } } } var sssss = divTabs.SelectNodes("//div[@id='downloads']//ul//li//a"); List <ProductCatalog> catalogs = new List <ProductCatalog>(); foreach (var item in sssss) { ProductCatalog catalog = new ProductCatalog(); catalog.File = item.Attributes["href"].Value; catalog.TitleEn = item.InnerText.Replace("\n", " ").Trim(); catalog.Title = translate.Translate(new InputTranslate { Input = catalog.TitleEn }).Result; catalogs.Add(catalog); } #endregion product.URL = url; product.Catalog = catalogs; //List<string> imgss = new List<string>(); //int i = 0; //foreach (var img in imgs) //{ // var _temp = img.Split(' ').Where(x => x.Contains("http")).Distinct(); // imgss.AddRange(_temp); //} product.Images = productImages; product.Keywords = url.Replace("https://www.leyboldproducts.com/products/", "").Replace("/pumps/", "/").Split('/'); product.Category = url.Replace("https://www.leyboldproducts.com/products/", "").Replace("/pumps/", "/").Split('/').FirstOrDefault(); return(product); }
public async void createPost(LProduct lProduct) { //Get all products //var products = await wc.Product.GetAll(); List <ProductImage> productImages = new List <ProductImage>(); int i = 0; foreach (var image in lProduct.Images) { ProductImage pi = new ProductImage(); pi.date_created = DateTime.Now; pi.src = image.Large; pi.alt = lProduct.Title; pi.date_created = DateTime.Now.AddMinutes(-10); pi.name = lProduct.TitleEn + "_" + lProduct.Title + "_" + i++; productImages.Add(pi); } List <ProductTagLine> productTags = new List <ProductTagLine>(); foreach (var tag in lProduct.Keywords) { var tagResult = wc.Tag.Get(tag); var t = new ProductTagLine(); if (tagResult != null) { t.id = tagResult.Id; } else { ProductTag newTag = new ProductTag(); newTag.name = tag; t.id = (wc.Tag.Add(newTag)).Id; } productTags.Add(t); } var vacCatId = wc.Category.Get("vacuumpump").Id; ProductCategory pc = new ProductCategory() { name = lProduct.Category, parent = vacCatId }; var getddd = wc.Category.Add(pc); //Add new product var p = new WooCommerceNET.WooCommerce.v3.Product() { name = lProduct.Title, images = productImages, description = string.IsNullOrWhiteSpace(lProduct.Html) ? string.Empty : $"<div>{lProduct.Html}</div><br /><div style='direction:ltr !important;text-align: left;'><h2>Description</h2>{lProduct.HtmlEn}</div>", price = 0, tags = productTags, date_created = DateTime.Now.AddHours(-5), date_on_sale_from = DateTime.Now.AddHours(-3), categories = new List <ProductCategoryLine>() { new ProductCategoryLine { name = lProduct.Category } } }; await wc.Product.Add(p); }