Ejemplo n.º 1
0
 public void InsertRelevanceWords(Product updated)
 {
     CanonDataContext db = Cdb.Instance;
     foreach (ProductsRelevance pr in this.ProductsRelevances)
     {
         ProductsRelevance newPr = new ProductsRelevance();
         newPr.ProductId = updated.ProductId;
         newPr.Points = pr.Points;
         newPr.Word = pr.Word;
         newPr.Max = pr.Max;
         db.ProductsRelevances.InsertOnSubmit(newPr);
     }
     db.SubmitChanges();
 }
Ejemplo n.º 2
0
        public void InsertRelevanceWords(Product updated)
        {
            CanonDataContext db = Cdb.Instance;

            foreach (ProductsRelevance pr in this.ProductsRelevances)
            {
                ProductsRelevance newPr = new ProductsRelevance();
                newPr.ProductId = updated.ProductId;
                newPr.Points    = pr.Points;
                newPr.Word      = pr.Word;
                newPr.Max       = pr.Max;
                db.ProductsRelevances.InsertOnSubmit(newPr);
            }
            db.SubmitChanges();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses a row
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public T ParseRow(Object row)
        {
            if (!(row is DataRow))
            {
                throw new ArgumentException("Only DataRow object can be passed.");
            }

            DataRow dr = row as DataRow;

            //get, validate EAN code
            if (dr[0] == null)
            {
                return(null);
            }
            string ean = dr[0].ToString();

            if ((string.IsNullOrEmpty(ean)) || (ean.Length < 10) || (ean.Length > 13))
            {
                return(null);
            }
            //get, validate product name
            if (dr[1] == null)
            {
                return(null);
            }
            string name = dr[1].ToString();

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            //get, validate recommended price
            if (dr[5] == null)
            {
                return(null);
            }
            string price = dr[5].ToString();
            //synonims, stopwords
            string synonims  = string.Empty;
            string stopwords = string.Empty;

            if (dr[13] != null)
            {
                synonims = dr[13].ToString();
            }
            if (dr[14] != null)
            {
                stopwords = dr[14].ToString();
            }
            //category
            string category = string.Empty;

            if (dr[12] != null)
            {
                category = dr[12].ToString();
            }
            double dPrice = 0;

            if (!string.IsNullOrEmpty(price))
            {
                try
                {
                    dPrice = double.Parse(price, culture.NumberFormat);
                }
                catch (Exception ex)
                {
                    ErrorMessages.Add(new ImportErrorMessage("CantParseNumber", new string[] { price.ToString() }));
                    WebVariables.Logger.Error(string.Format("File {0}, error number parse {1}", _filename, price), ex);
                    return(null);
                }
            }
            //create new product
            CanonDataContext db = Cdb.Instance;
            T a = Activator.CreateInstance <T>();

            a.ProductCode  = ean;
            a.ProductName  = name;
            a.IsActive     = true;
            a.CurrentPrice = (decimal)dPrice;

            if (dPrice > 0)
            {
                RecommendedPrice newPrice = new RecommendedPrice();
                newPrice.ChangeDate = DateTime.Now;
                newPrice.UserId     = WebVariables.LoggedUserId;
                newPrice.Price      = (decimal)dPrice;
                newPrice.Product    = a;
                a.RecommendedPrices.Add(newPrice);
            }
            if (!string.IsNullOrEmpty(category))
            {
                Category newCat = new Category();
                newCat.CategoryName = category;
                newCat.InternalId   = category;
                a.Category          = newCat;
            }

            //update product relevance words
            string filteredName = name.Replace(",", "").Replace(";", "");

            string[]          nameTokens = filteredName.Split(' ');
            string[]          synTokens  = synonims.Split(' ');
            int               maxValue   = this.CountMaxRelevance(2, nameTokens, synTokens);
            ProductsRelevance fromCode   = new ProductsRelevance();

            fromCode.Word   = ean;
            fromCode.Points = 2;
            fromCode.Max    = maxValue;
            a.ProductsRelevances.Add(fromCode);

            //update relevance from name
            foreach (string nameToken in nameTokens)
            {
                if (nameToken.Trim().Length < 2)
                {
                    continue;
                }
                ProductsRelevance fromName = new ProductsRelevance();
                fromName.Word   = nameToken;
                fromName.Points = 2;
                fromName.Max    = maxValue;
                a.ProductsRelevances.Add(fromName);
            }

            //update relevance from synonims
            foreach (string synToken in synTokens)
            {
                if (synToken.Trim().Length < 2)
                {
                    continue;
                }
                ProductsRelevance fromSyn = new ProductsRelevance();
                fromSyn.Word   = synToken;
                fromSyn.Points = 1;
                fromSyn.Max    = maxValue;
                a.ProductsRelevances.Add(fromSyn);
            }

            //update relevance from stopwords
            string[] stopTokens = stopwords.Split(' ');
            foreach (string stopToken in stopTokens)
            {
                if (stopToken.Trim().Length < 2)
                {
                    continue;
                }
                ProductsRelevance fromStop = new ProductsRelevance();
                fromStop.Word   = stopToken;
                fromStop.Points = -1;
                fromStop.Max    = maxValue;
                a.ProductsRelevances.Add(fromStop);
            }

            return(a);
        }