Example #1
0
        public FrmEditCompanyRegion()
        {
            InitializeComponent();
            connectionStringCompanyAddress = Entities.Server.ConnectionString;
            if (string.IsNullOrEmpty(connectionStringCompanyAddress))
            {
                connectionStringCompanyAddress =
                    ConfigurationManager.ConnectionStrings["UpdateSolrTools.Properties.Settings.QTConnectionString"].ToString();
            }
            companyAddressTableAdapter.Connection = new SqlConnection(connectionStringCompanyAddress);
            companyAddressTableAdapter.Connection.Open();
            regionTree = RegionBAL.GetRegionTree(connectionStringCompanyAddress);
            var provinNodes = regionTree.GetAllNodeInLevel(1);

            foreach (var provinNode in provinNodes)
            {
                comboBoxProvin.Items.Add(new ComboboxItem()
                {
                    ID    = provinNode.ID,
                    Value = provinNode.Value.Name
                });
            }

            RefreshData();
        }
Example #2
0
 private void UpdateData()
 {
     while (_isRunning)
     {
         if ((DateTime.Now - LastUpdateDataTime) > TimeSpan.FromMinutes(600))
         {
             try
             {
                 var regionTree         = RegionBAL.GetRegionTree(_productConnectionString);
                 var categoryTree       = ProductCategoryBAL.GetProductCategoryTree(_productConnectionString);
                 var categoryTags       = IndexProductTools.GetAllCategoryTags(_productConnectionString);
                 var listPrefixCategory = IndexProductTools.GetAllPrefixCategory(_productConnectionString);
                 solrIndexer.RegionTree         = regionTree;
                 solrIndexer.CategoryTree       = categoryTree;
                 solrIndexer.CategoryTags       = categoryTags;
                 solrIndexer.ListPrefixCategory = listPrefixCategory;
                 LastUpdateDataTime             = DateTime.Now;
                 Logger.Info("Update Data Success!");
             }
             catch (Exception exception)
             {
                 Logger.Error("Update Data Error.", exception);
                 Thread.Sleep(30000);
             }
         }
         else
         {
             Thread.Sleep(10000);
         }
     }
 }
Example #3
0
        private void InitData()
        {
            this.Invoke((MethodInvoker) delegate
            {
                panelMainControl.Enabled = false;
            });
            var listMerchantUseDatafeedID = IndexProductTools.GetListMerchantUseDatafeedID(_productConnectionString);;
            var listSpecialMerchantID     = IndexProductTools.GetListSpecialMerchantID(_productConnectionString);
            var listPriorMerchants        = IndexProductTools.GetAllPriorMerchants(_productConnectionString);
            var listBadMerchant           = IndexProductTools.GetAllBadMerchantId(_productConnectionString, 35);

            solrIndexer.ListMerchantUseDatafeedID = listMerchantUseDatafeedID;
            solrIndexer.ListSpecialMerchantID     = listSpecialMerchantID;
            solrIndexer.ListPriorMerchants        = listPriorMerchants;
            solrIndexer.ListBadMerchantID         = listBadMerchant;
            var regionTree         = RegionBAL.GetRegionTree(_productConnectionString);
            var categoryTree       = ProductCategoryBAL.GetProductCategoryTree(_productConnectionString);
            var categoryTags       = IndexProductTools.GetAllCategoryTags(_productConnectionString);
            var listPrefixCategory = IndexProductTools.GetAllPrefixCategory(_productConnectionString);

            solrIndexer.RegionTree         = regionTree;
            solrIndexer.CategoryTree       = categoryTree;
            solrIndexer.CategoryTags       = categoryTags;
            solrIndexer.ListPrefixCategory = listPrefixCategory;
            var propertyValueDictionary = WebProductPropertyBAL.GetAllPropertyValues(_productConnectionString);
            var propertyUnitDictionary  = WebProductPropertyBAL.GetPropertyUnitDictionary(_productConnectionString);

            solrIndexer.PropertyUnitDictionary  = propertyUnitDictionary;
            solrIndexer.PropertyValueDictionary = propertyValueDictionary;
            this.Invoke((MethodInvoker) delegate
            {
                panelMainControl.Enabled = true;
            });
        }
Example #4
0
        private void frmChonRegion_Load(object sender, EventArgs e)
        {
            connectionStringCompanyAddress = Entities.Server.ConnectionString;
            //if (string.IsNullOrEmpty(connectionStringCompanyAddress))
            //    connectionStringCompanyAddress =
            //        ConfigurationManager.ConnectionStrings["UpdateSolrTools.Properties.Settings.QTConnectionString"].ToString();
            companyAddressTableAdapter.Connection.ConnectionString = QT.Entities.Server.ConnectionString;// = new SqlConnection(connectionStringCompanyAddress);
            //companyAddressTableAdapter.Connection.Open();
            regionTree = RegionBAL.GetRegionTree(connectionStringCompanyAddress);
            var provinNodes = regionTree.GetAllNodeInLevel(1);

            foreach (var provinNode in provinNodes)
            {
                comboBoxProvin.Items.Add(new ComboboxItem()
                {
                    ID    = provinNode.ID,
                    Value = provinNode.Value.Name
                });
            }
        }
Example #5
0
        public int UpdateProductOfCompany(long companyId, string companyName, Tree <int, Region> regionTree = null)
        {
            if (regionTree == null)
            {
                regionTree = RegionBAL.GetRegionTree(ConnectionStringProducts);
            }

            // Get Company Address
            var companyAddressTableAdapter = new Company_AddressTableAdapter
            {
                Connection = { ConnectionString = ConnectionStringProducts }
            };

            var companyAddressDataTable = companyAddressTableAdapter.GetData(companyId);
            //var companyRegions = new List<int>();
            var companyProvins   = new List <int>();
            var companyDistricts = new List <int>();

            for (var rowIndex = 0; rowIndex < companyAddressDataTable.Rows.Count; rowIndex++)
            {
                var branchDistrict = companyAddressDataTable.Rows[rowIndex]["RegionID"] == DBNull.Value ? -1 : (int)companyAddressDataTable.Rows[rowIndex]["RegionID"];
                if (branchDistrict == -1 || companyDistricts.Contains(branchDistrict))
                {
                    continue;
                }
                companyDistricts.Add(branchDistrict);
                var branchProvinNode = regionTree.GetParentNode(branchDistrict);
                if (branchProvinNode != null && !companyProvins.Contains(branchProvinNode.ID))
                {
                    companyProvins.Add(branchProvinNode.ID);
                }
            }
            //var dtCompanyRegion =
            var dtProduct  = new DBTool2.Product_SolrDataTable();
            var adtProduct = new DBTool2TableAdapters.Product_SolrTableAdapter
            {
                Connection = { ConnectionString = ConnectionStringProducts }
            };

            //this.Invoke((MethodInvoker)(() =>
            //    WriteLog(String.Format("Start download list products of company {0}", companyName))));
            try
            {
                adtProduct.FillBy_Company(dtProduct, companyId);
                SolrDriver.DeleteByCompanyId(companyId);
            }
            catch (Exception ex)
            {
                return(-1);
                //this.Invoke((MethodInvoker)(() =>
                //WriteLog(string.Format("Update Products Of Company {0}", companyId), ex)));
            }
            var solrProductItems = new List <SolrProductItem>();
            var numProduct       = dtProduct.Rows.Count;

            for (var index = 0; index < numProduct; index++)
            {
                var productRow = dtProduct.Rows[index];
                try
                {
                    var item = new SolrProductItem
                    {
                        Id               = QT.Entities.Common.Obj2Int64(productRow["ID"]),
                        Price            = QT.Entities.Common.Obj2Int(productRow["Price"]),
                        Warranty         = QT.Entities.Common.Obj2Int(productRow["Warranty"]),
                        Status           = QT.Entities.Common.Obj2Int(productRow["Status"]),
                        Company          = QT.Entities.Common.Obj2Int64(productRow["Company"]),
                        CompanyProvins   = companyProvins,
                        CompanyDistricts = companyDistricts,
                        LastUpdate       = QT.Entities.Common.ObjectToDataTime(productRow["LastUpdate"]),
                        Summary          = productRow["Summary"].ToString(),
                        Description      = "",
                        ProductId        = QT.Entities.Common.Obj2Int(productRow["ProductID"]),
                        ProductType      = 2,
                        Name             = productRow["Name"].ToString(),
                        NameFT           = productRow["NameFT"].ToString(),
                        DetailUrl        = productRow["DetailUrl"].ToString(),
                        ImagePath        = productRow["ImagePath"].ToString(),
                        CategoryId       = QT.Entities.Common.Obj2Int(productRow["CategoryID"]),
                        ContentFT        =
                            productRow["ContentFT"] != DBNull.Value ? productRow["ContentFT"].ToString() : "c000",
                        ViewCount            = QT.Entities.Common.Obj2Int(productRow["ViewCount"]),
                        AddPosition          = QT.Entities.Common.Obj2Int(productRow["AddPosition"]),
                        StringFilterFields   = new Dictionary <string, object>(),
                        DoubleFilterFields   = new Dictionary <string, object>(),
                        DateTimeFilterFields = new Dictionary <string, object>(),
                        IntFilterFields      = new Dictionary <string, object>()
                    };
                    for (int exIndex = 1; exIndex <= 10; exIndex++)
                    {
                        string filterPropertyId    = QT.Entities.Common.Obj2String(productRow["EX" + exIndex]);
                        string filterPropertyValue = QT.Entities.Common.Obj2String(productRow["EXVALUE" + exIndex]);
                        if (string.IsNullOrEmpty(filterPropertyId) || filterPropertyId.Equals("0") ||
                            string.IsNullOrEmpty(filterPropertyValue))
                        {
                            continue;
                        }
                        try
                        {
                            if (filterPropertyValue.StartsWith("number:"))
                            {
                                if (filterPropertyValue.Equals("number:"))
                                {
                                    continue;
                                }
                                double filterDoubleValue;
                                string filterIDAndValue = filterPropertyValue.Substring(7);
                                string filterValueID    = filterIDAndValue.Substring(0,
                                                                                     filterIDAndValue.IndexOf(":"));
                                string filterValue = filterIDAndValue.Length > filterValueID.Length + 1
                                    ? filterIDAndValue.Substring(filterValueID.Length + 1)
                                    : "";
                                var filterPropertyIdKey =
                                    SolrProductUtils.GetFilterIdKey(Int32.Parse(filterPropertyId));
                                if (item.IntFilterFields.ContainsKey(filterPropertyIdKey))
                                {
                                    continue;
                                }
                                int filterValueInt;
                                if (!int.TryParse(filterValueID, out filterValueInt))
                                {
                                    continue;
                                }
                                item.IntFilterFields.Add(filterPropertyIdKey, filterValueID);
                                if (Double.TryParse(filterValue, out filterDoubleValue))
                                {
                                    item.DoubleFilterFields.Add(filterPropertyId, filterDoubleValue);
                                }
                            }
                            else
                            {
                                string filterValueID = filterPropertyValue.Substring(0,
                                                                                     filterPropertyValue.IndexOf(":"));
                                string filterValue = filterPropertyValue.Length > filterValueID.Length + 1
                                    ? filterPropertyValue.Substring(filterValueID.Length + 1)
                                    : "";
                                var filterPropertyIdKey =
                                    SolrProductUtils.GetFilterIdKey(Int32.Parse(filterPropertyId));
                                if (item.IntFilterFields.ContainsKey(filterPropertyIdKey))
                                {
                                    continue;
                                }
                                int filterValueInt;
                                if (!int.TryParse(filterValueID, out filterValueInt))
                                {
                                    continue;
                                }
                                item.IntFilterFields.Add(filterPropertyIdKey, filterValueID);
                                item.StringFilterFields.Add(filterPropertyId, filterValue);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                    solrProductItems.Add(item);
                }
                catch (Exception oex)
                {
                    return(-2);
                    //Invoke((MethodInvoker)(() => WriteLog(string.Format("Update Products Of Company {0}", companyId), oex)));
                }
                if (index % 1000 == 0 || index == numProduct - 1)
                {
                    try
                    {
                        SolrDriver.IndexItems(solrProductItems);
                        solrProductItems.Clear();
                        var numUpdatedProducts = index;
                        //Invoke((MethodInvoker)(() => WriteLog(String.Format("Updated solr {0}/{1} products", numUpdatedProducts, numProduct))));
                    }
                    catch (Exception solrEx)
                    {
                        return(-3);
                        //Invoke((MethodInvoker)(() => WriteLog(string.Format("Update Products Of Company {0}", companyId), solrEx)));
                    }
                }
            }
            try
            {
                SolrDriver.IndexItems(solrProductItems);
                var adtCom = new DBToolTableAdapters.CompanyTableAdapter
                {
                    Connection = { ConnectionString = ConnectionStringProducts }
                };
                adtCom.UpdateQuery_LastUpdateSolr(DateTime.Now, companyId);
                adtCom.Dispose();
                //this.Invoke((MethodInvoker)(() =>
                //    this.richTextBoxInfo.AppendText(String.Format("Update Finish Company {0} - {1} products",
                //        companyName, numProduct))));
            }
            catch (Exception ex)
            {
                return(-4);
            }
            dtProduct.Dispose();
            adtProduct.Dispose();
            return(dtProduct.Rows.Count);
        }