public static ProductCategory FromBegemotProduct(BegemotProduct bproduct) { var rootCats = Context.Inst.ProductCategorySet.Where(c => c.Parent == null).ToList(); ProductCategory cat = GetOrAdd(rootCats, bproduct.Group, null); cat = GetOrAdd(cat.Childs.ToList(), bproduct.Group1, cat); cat = GetOrAdd(cat.Childs.ToList(), bproduct.Group2, cat); return cat; }
public void Apply(Product product, BegemotProduct bproduct) { var needAdd = !product.SpecialStyle.Any(s => s.Id == Id); if (needAdd) { product.SpecialStyle.Add(this); } product.ReApplyStyle(); }
private void InitImage(BegemotProduct product) { if (product.HasImage()) { pictureEdit1.Image = new Bitmap(product.ImagePath); } else { pictureEdit1.Image = null; } }
public static decimal CalcOldPrice(Product product, BegemotProduct begemotProduct, BegemotSalePrice sale) { decimal oldPrice; if (sale == null) { oldPrice = begemotProduct.RetailPrice * Context.OldPriceCoefficient; } else { oldPrice = sale.RetailPriceOld * Context.OldPriceCoefficient; } return oldPrice; }
public void Apply(Product product, BegemotProduct bproduct, BegemotSalePrice bsale) { var needAdd = !product.Sales.Any(s => s.Id == Id); if (needAdd) { product.Sales.Add(this); } product.RecalcPrice(bproduct, bsale); if (Style != null) { product.ReApplyStyle(); } }
public static decimal CalcSelfPrice(BegemotProduct begemotProduct, BegemotSalePrice sale) { decimal price; if (sale != null) { price = sale.WholeSalePrice; } else { price = Context.WithBegemotDescount(begemotProduct.WholeSalePrice); } return price; }
public static decimal CalcPrice(Product product, BegemotProduct begemotProduct, BegemotSalePrice bsale, Sale sale) { decimal retPrice = CalcRetailPrice(begemotProduct, bsale); product.Price = retPrice; product.PriceOld = retPrice; if (sale != null) { decimal selfPrice = CalcSelfPrice(begemotProduct, bsale); retPrice = sale.CalcSalePrice(retPrice, selfPrice); product.Price = retPrice; } return retPrice; }
private void InitDescription(BegemotProduct product) { var description = product.GetDescription(); txtDescription.Text = description; }
//public static string Convert(this Encoding sourceEncoding, Encoding targetEncoding, string value) //{ // string reEncodedString = null; // byte[] sourceBytes = sourceEncoding.GetBytes(value); // byte[] targetBytes = Encoding.Convert(sourceEncoding, targetEncoding, sourceBytes); // reEncodedString = sourceEncoding.GetString(targetBytes); // return reEncodedString; //} public void DownloadImage(BegemotProduct bproduct, Uri imageUri = null) { PageLoader pageLoader = new PageLoader(); string uri = null; if (imageUri == null) { uri = string.Format(ImageUrlFormat, bproduct.Article); } else { uri = imageUri.ToString(); } string savePath = bproduct.GenerateImagePath(); try { pageLoader.RequestImage(uri, savePath); bproduct.ImagePath = savePath; } catch (WebException we) { bproduct.SetNoImage(); } }
private void AddToDict(Product product, BegemotProduct bproduct, Style specialStyle, Sale activeSale) { valueDict.Add(StyleTag.Title, bproduct.GetClearTitle()); valueDict.Add(StyleTag.TitleShort, bproduct.GetTitleShort()); valueDict.Add(StyleTag.TitleClear, bproduct.GetClearTitle()); valueDict.Add(StyleTag.TitleClearShort, bproduct.GetClearShortTitle()); valueDict.Add(StyleTag.Description, bproduct.GetClearDescrption()); valueDict.Add(StyleTag.Price, product.Price.ToString("f2")); valueDict.Add(StyleTag.PriceOld, product.PriceOld.ToString("f2")); var codeProduct = product.GetCode(); valueDict.Add(StyleTag.CodeProduct, codeProduct); if (specialStyle != null) { var codeStyle = specialStyle.GetCode(true); //codeStyle = HttpUtility.UrlEncode(codeStyle); valueDict.Add(StyleTag.CodeStyle, codeStyle); } if (activeSale != null) { var codeSale = activeSale.GetCode(true); // codeSale = HttpUtility.UrlEncode(codeSale); valueDict.Add(StyleTag.CodeSale, codeSale); } var salesLinks = SalesLinks(); valueDict.Add(StyleTag.Sales, salesLinks); var menuLinks = MenuLinks(); valueDict.Add(StyleTag.Menu, menuLinks); }
public void ApplyStyles(Product product, BegemotProduct bproduct, Style specialStyle, Style saleStyle, Style marketStyle, Marketplace market, Adv24au adv) { //bool isNoStyles = specialStyle == null && saleStyle == null && marketStyle == null; var activeSale = product.GetActiveSale(); Style defultStyle = Style.GetDefault(); valueDict = new Dictionary<string, string>(); AddToDict(product, bproduct, specialStyle, activeSale); AppleResult ar = null; ar = Apply(defultStyle, StyleType.SpecialDescrition); ar = Apply(specialStyle, StyleType.SpecialDescrition); ar = Apply(saleStyle, StyleType.Sale); ar = Apply(marketStyle, StyleType.MarketPlace); ar.ClearTags(); //ar.ClearPolicyWords(market); var title = ar.GetResultTitle(); var description = ar.GetResultDescription(); if (adv == null) { product.Title = title; product.Description = description; } else { title = market.PrepareTitle(title); description = market.PrepareDescription(description); adv.Title = title; adv.Description = description; } }
public void ApplyStyles(Product product, BegemotProduct bproduct, Adv24au adv = null) { Marketplace market = adv.Marketplace; var specialStyle = product.GetSpecialStyle(); var saleStyle = product.GetSaleStyle(); var marketStyle = market == null ? null : market.GetActiveStyle(); ApplyStyles(product, bproduct, specialStyle, saleStyle, marketStyle, market, adv); }
private static decimal CalcBegemotRetailPrice(BegemotProduct begemotProduct, BegemotSalePrice sale) { decimal price; if (sale != null) { price = sale.RetailPriceOld; } else { price = begemotProduct.RetailPrice; } return price; }
public void DownloadDescription(BegemotProduct product) { PageLoader pageLoader = new PageLoader(); string uri = string.Format(DescriptionUrlFormat, product.Code); try { // uri = "http://krsk.24au.ru/2365348/"; var response = pageLoader.RequestsHtml(uri, decompress: true); var doc = new HtmlDocument(); doc.LoadHtml(response.Html); var titleHeader = doc.DocumentNode.NodeByXpath("/html/body/table/tr/td/table[1]/tr/td/table/tr/td[4]/div[2]/h1"); product.Title = titleHeader.InnerText.Trim(); bool contains = doc.DocumentNode.InnerHtml.Contains("<b>ќписание:</b>"); if (contains) { var descHeader = doc.DocumentNode.NodeByXpath( "/html/body/table/tr/td/table[1]/tr/td/table/tr/td[4]/div[2]/div[2]/b"); var nodes = descHeader.ParentNode.ChildNodes; var indexHeader = nodes.IndexOf(descHeader); var descNode = nodes[indexHeader + 1]; var innerText = descNode.InnerText.Trim(); product.Descrption = innerText; } else { product.SetNoDescrption(); } } catch (WebException we) { product.SetNoDescrption(); } }
public void RecalcPrice(BegemotProduct bproduct, BegemotSalePrice bsale) { var sale = GetActiveSale(); PriceCalculator.CalcPrice(this, bproduct, bsale, sale); }
public Bitmap GetImage(BegemotProduct bproduct) { if (_bitmap == null) { var path = GetImagePath(); if (!File.Exists(path)) { path = bproduct.GetImagePath(); } bool hasImage = path == BegemotProduct.NoImagePath; _bitmap = hasImage ? null : new Bitmap(path); } return _bitmap; }
public decimal CalcMargin(BegemotProduct begemotProduct, BegemotSalePrice sale) { var selfPrice = PriceCalculator.CalcSelfPrice(begemotProduct, sale); var margin = Price - selfPrice; return margin; }
public static Product FromBegemotProduct(BegemotProduct begemotProduct) { var product = new Product(); product.Article = begemotProduct.Article; product.Title = begemotProduct.GetClearTitle(); product.Description = begemotProduct.GetDescription(); product.Price = begemotProduct.RetailPrice; begemotProduct.GetImagePath(); product.Category = ProductCategory.FromBegemotProduct(begemotProduct); product.Active = true; return product; }
private static decimal CalcRetailPrice(BegemotProduct begemotProduct, BegemotSalePrice bsale) { // розничная цена decimal bRetPrice = CalcBegemotRetailPrice(begemotProduct, bsale); var price = bRetPrice * Context.OldPriceCoefficient; return price; }