Пример #1
0
        public bool MapProperties(int RootId)
        {
            var isDone = false;

            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                var lstRootProperties = db.Query <RootProperty>(@"select a.ProductID,
                                                                    a.PropertiesID,
                                                                    a.PropertiesGroupID,
                                                                    a.PropertiesValueID,
                                                                    b.Name,
                                                                    c.Value,
                                                                    b.Unit
                                                                     from Product_Properties a
                                                                     inner join Properties b 
                                                                     on a.PropertiesID = b.ID
                                                                     inner join PropertiesValue c 
                                                                     on a.PropertiesValueID = c.ID where a.ProductID = @ProductID order by a.STT",
                                                                new { ProductID = RootId }).ToList();
                if (lstRootProperties != null && lstRootProperties.Count > 0)
                {
                    var lstProductByRoot = db.Query <Entity.Product>("select a.ID,a.Company,a.ProductID,b.Domain,a.DetailUrl,a.ImageUrls,a.ClassificationID,a.CategoryID from Product a inner join Company b on a.Company = b.ID where a.ProductID = @ProductID",
                                                                     new { ProductID = RootId }).ToList();
                    Dictionary <string, string> dicProperties = new Dictionary <string, string>();
                    foreach (var property in lstRootProperties)
                    {
                        if (!dicProperties.ContainsKey(property.Name))
                        {
                            if (!string.IsNullOrEmpty(property.Unit))
                            {
                                property.Value += " " + property.Unit;
                            }
                            dicProperties.Add(property.Name, property.Value);
                        }
                    }
                    foreach (var item in lstProductByRoot)
                    {
                        PropertyProduct productProperty = new PropertyProduct();
                        productProperty.ProductId = item.ID;
                        try
                        {
                            productProperty.Properties = dicProperties;
                            SaveProperiesProduct(productProperty);
                            //productProperty.Properties.Clear();
                            isDone = true;
                            log.InfoFormat("Product: {0} Map Success!", productProperty.ProductId);
                        }
                        catch (Exception ex01)
                        {
                            log.ErrorFormat("Product: {0} Map error {1}", productProperty.ProductId, ex01);
                            isDone = false;
                        }
                    }
                    dicProperties.Clear();
                }
            }
            log.InfoFormat("Product: {0} Map Success!", RootId);
            return(isDone);
        }
Пример #2
0
 public void FattanToSql(PropertyProduct propertyData)
 {
     foreach (var VARIABLE in propertyData.Properties)
     {
         string propertyName = propertyData.Category + ":" + VARIABLE.Key;
         long   propertyID   = CommonConvert.CrcProductID(propertyName);
         bool   bOk          = this.sqlDbProperties.RunQuery("sp_Property_Ins", CommandType.StoredProcedure, new[]
         {
             SqlDb.CreateParamteterSQL("CategoryID", propertyData.CategoryId, SqlDbType.BigInt),
             SqlDb.CreateParamteterSQL("CategoryName", propertyData.Category, SqlDbType.NVarChar),
             SqlDb.CreateParamteterSQL("ProperyID", propertyID, SqlDbType.BigInt),
             SqlDb.CreateParamteterSQL("ProperyValue", VARIABLE.Value, SqlDbType.NVarChar),
             SqlDb.CreateParamteterSQL("CompanyID", propertyData.CompanyID, SqlDbType.BigInt),
             SqlDb.CreateParamteterSQL("ProductID", propertyData.ProductId, SqlDbType.BigInt),
             SqlDb.CreateParamteterSQL("PropertyName", propertyName, SqlDbType.NVarChar),
         });
     }
 }
Пример #3
0
        public void SaveProperiesProduct(PropertyProduct propertyData)
        {
            //string queryDelete = "{product_id:NumberLong(" + propertyData.ProductId + ")}";
            //this._collection.DeleteMany(queryDelete);
            //try
            //{
            //    this._collection.InsertOne(propertyData);
            //}
            //catch (Exception ex)
            //{
            //    log.Info(ex);
            //}
            //SaveToRedis
            var properties = propertyData.Properties.Select(variable => new KeyValuePair <string, string>(variable.Key, variable.Value)).ToList();

            _cacheMan.Set("prs:" + propertyData.ProductId, properties, true, new TimeSpan(20000, 0, 0, 0));
            //database.SetAdd(propertyData.ProductId.ToString(), x);
        }
Пример #4
0
        public PropertyProduct ParseData(HtmlDocument document)
        {
            PropertyProduct propertyData = new PropertyProduct();

            propertyData.Category   = "";
            propertyData.Domain     = _configPropertyNomal.Domain;
            propertyData.CategoryId = CommonConvert.CrcProductID(propertyData.Category);
            var     nodeRows        = document.DocumentNode.SelectNodes(_configPropertyNomal.XPath);
            dynamic configOtherData = JObject.Parse(_configPropertyNomal.JSonOtherConfig);
            string  colH            = configOtherData.IndexColHeader.ToString();
            string  colB            = configOtherData.IndexColData.ToString();

            if (nodeRows != null)
            {
                foreach (var variable in nodeRows)
                {
                    var nodeCell = variable.SelectNodes("./td");
                    if (nodeCell != null)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(nodeCell[Convert.ToInt32(colH)].InnerText.Trim()) && !string.IsNullOrEmpty(nodeCell[Convert.ToInt32(colB)].InnerText.Trim()))
                            {
                                propertyData.Properties.Add(
                                    nodeCell[Convert.ToInt32(colH)].InnerText.Trim(),
                                    nodeCell[Convert.ToInt32(colB)].InnerText.Trim());
                            }
                        }
                        catch (Exception ex)
                        {
                            // ignored
                        }
                    }
                }
            }
            return(propertyData);
        }
Пример #5
0
        public void SaveProperties(PropertyProduct propertyData)
        {
            BsonDocument bSon = propertyData.ToBsonDocument();

            this._colPropertiesData.InsertOne(bSon);
        }