示例#1
0
        void doUpdateTongView()
        {
            QT.Entities.Product_KeyComparison obj = new Product_KeyComparison();
            DBPMan.ProductDataTable           dt  = new DBPMan.ProductDataTable();
            if (chkAll.Checked == true)
            {
                this.productTableAdapter.FillBy_AllSPGocValid_orderByLastUpdate(dt, Common.GetIDCompany("quangtrung.vn"), DateTime.Now);
            }
            else
            {
                this.productTableAdapter.FillBy_CompanyID_Valid_Category(dt, Common.GetIDCompany("quangtrung.vn"), true, Common.Obj2Int(this.iDListClassificationTextBox.Text));
            }
            DBPManTableAdapters.Product_LogsTableAdapter adtLog = new DBPManTableAdapters.Product_LogsTableAdapter();
            adtLog.Connection.ConnectionString = QT.Entities.Server.ConnectionString;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                try
                {
                    int productid = 0;

                    productid = Common.Obj2Int(dt.Rows[i]["ID"].ToString());
                    int viewCount = 0;
                    try
                    {
                        viewCount = Common.Obj2Int(adtLog.ScalarQuery_SumCountByProductID_FromDate(productid, DateTime.Now.AddDays(-30)));
                    }
                    catch (Exception)
                    {
                    }
                    int delay = 1000;
                    this.Invoke(
                        (MethodInvoker) delegate
                    {
                        this.laMess1.Text = String.Format("Update thông tin view {0}/{1} sản phẩm: {2}\n Tổng: {3}\n ", i, dt.Rows.Count, dt.Rows[i]["Name"].ToString(),
                                                          viewCount);
                        delay = Common.Obj2Int(txtDelay.Text.Trim());
                    });
                    this.productTableAdapter.UpdateQuery_ViewCount(viewCount, productid);
                    Thread.Sleep(delay);
                }
                catch (Exception)
                {
                }
            }
            adtLog.Dispose();
            if (updateFulltextThread != null)
            {
                if (updateFulltextThread.IsAlive)
                {
                    updateFulltextThread.Abort();
                    updateFulltextThread.Join();
                    updateFulltextThread = null;
                }
            }
        }
示例#2
0
        void doUpdateGiaSPGoc()
        {
            QT.Entities.Product_KeyComparison obj = new Product_KeyComparison();
            DBPMan.ProductDataTable           dt  = new DBPMan.ProductDataTable();
            while (true)
            {
                if (chkAll.Checked == true)
                {
                    this.productTableAdapter.FillBy_AllSPGocValid_orderByLastUpdate(dt, Common.GetIDCompany("quangtrung.vn"), DateTime.Now.AddDays(-1));
                }
                else
                {
                    this.productTableAdapter.FillBy_CompanyID_Valid_Category(dt, Common.GetIDCompany("quangtrung.vn"), true, Common.Obj2Int(this.iDListClassificationTextBox.Text));
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    try
                    {
                        int productid = 0;

                        productid = Common.Obj2Int(dt.Rows[i]["ID"].ToString());
                        long idSPChuyenSPGoc = Common.Obj2Int64(dt.Rows[i]["ClassificationID"].ToString());
                        /// Update ProductID của những sản phẩm được chuyển sang làm sản phẩm gốc, ProductID=ClassificationID
                        this.productTableAdapter.UpdateQuery_ProductID(productid, idSPChuyenSPGoc);
                        Product_KeyComparisonEntyties oe = obj.UpdatePriceAndTongSP_ProductAndKeyComparision(productid);
                        int delay = 1000;
                        this.Invoke(
                            (MethodInvoker) delegate
                        {
                            this.laMess1.Text = String.Format("Update thông tin so sánh giá {0}/{1} sản phẩm: {2}\n Tổng: {3}\n PriceMin: {4}\n PriceMax: {5}", i, dt.Rows.Count, dt.Rows[i]["Name"].ToString(),
                                                              oe.TongSanPham, oe.PriceMin, oe.PriceMax);
                            delay = Common.Obj2Int(txtDelay.Text.Trim());
                        });
                        Thread.Sleep(delay);
                    }
                    catch (Exception)
                    {
                    }
                }
                if (updateFulltextThread != null)
                {
                    if (updateFulltextThread.IsAlive)
                    {
                        updateFulltextThread.Abort();
                        updateFulltextThread.Join();
                        updateFulltextThread = null;
                    }
                }
            }
        }
示例#3
0
        private void btUpdateTopGiamGiaTuan_Click(object sender, EventArgs e)
        {
            QT.Entities.Product_KeyComparison obj = new Product_KeyComparison();
            DBPMan.ProductDataTable           dt  = new DBPMan.ProductDataTable();
            if (chkAll.Checked == true)
            {
                this.productTableAdapter.FillBy_AllSPGocValid_orderByLastUpdate(dt, Common.GetIDCompany("quangtrung.vn"), DateTime.Now);
            }
            else
            {
                this.productTableAdapter.FillBy_CompanyID_Valid_Category(dt, Common.GetIDCompany("quangtrung.vn"), true, Common.Obj2Int(this.iDListClassificationTextBox.Text));
            }
            DBPManTableAdapters.Price_LogsTableAdapter adtLog = new DBPManTableAdapters.Price_LogsTableAdapter();
            DBPMan.Price_LogsDataTable dtLog = new DBPMan.Price_LogsDataTable();
            adtLog.Connection.ConnectionString = QT.Entities.Server.ConnectionString;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int productid = 0;

                productid = Common.Obj2Int(dt.Rows[i]["ID"].ToString());
                int PriceChange = 0;
                try
                {
                    adtLog.FillBy_ProductIDFromDate(dtLog, productid, DateTime.Now.AddDays(-7));
                    if (dtLog.Rows.Count > 0)
                    {
                        DateTime dateUpdate = Common.ObjectToDataTime(dtLog.Rows[0]["DateUpdate"]);
                        if (dateUpdate < DateTime.Now.AddDays(-6))
                        {
                            int price0 = Common.Obj2Int(dtLog.Rows[0]["NewPrice"].ToString());
                            int pricen = Common.Obj2Int(dtLog.Rows[dtLog.Rows.Count - 1]["NewPrice"].ToString());
                            PriceChange = pricen - price0;
                        }
                    }
                }
                catch (Exception)
                {
                }

                this.productTableAdapter.UpdateQuery_PriceChangeWeek(PriceChange, productid);
                this.laMess1.Text = String.Format("Update giá giảm trong tuần {0}/{1} sản phẩm: {2}\n Tổng: {3}\n ", i, dt.Rows.Count, dt.Rows[i]["Name"].ToString(),
                                                  PriceChange);
                Application.DoEvents();
            }
            adtLog.Dispose();
        }
示例#4
0
 private void btUpdateTinLienQuan_Click(object sender, EventArgs e)
 {
     #region update lại giá, tổng số sản phẩm tìm thấy trong dữ liệu
     QT.Entities.Product_KeyComparison obj = new Product_KeyComparison();
     DBPMan.ProductDataTable           dt  = new DBPMan.ProductDataTable();
     if (chkAll.Checked == true)
     {
         this.productTableAdapter.FillBy_AllSPGocValid_orderByLastUpdate(dt, Common.GetIDCompany("quangtrung.vn"), DateTime.Now);
     }
     else
     {
         this.productTableAdapter.FillBy_CompanyID_Valid_Category(dt, Common.GetIDCompany("quangtrung.vn"), true, Common.Obj2Int(this.iDListClassificationTextBox.Text));
     }
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         int productid = 0;
         productid = Common.Obj2Int(dt.Rows[i]["ID"].ToString());
         int tong = obj.UpdateProductIDTinLienQuan(productid);
         this.laMess1.Text = String.Format("Update tin liên quan {0}/{1} sản phẩm: {2}\n Tổng: {3}\n ", i, dt.Rows.Count, dt.Rows[i]["Name"].ToString(),
                                           tong);
         Application.DoEvents();
     }
     #endregion
 }
示例#5
0
        void DoUpdateSolrRootProduct()
        {
            var startTime = DateTime.Now;
            //Invoke((MethodInvoker)(() =>
            //    WriteLog(String.Format("Start download List Product ID"))));
            var dtProduct  = new DBTool2.Product_SolrDataTable();
            var adtProduct = new DBTool2TableAdapters.Product_SolrTableAdapter();

            adtProduct.Connection.ConnectionString = Server.ConnectionString;

            var dataTableVotes   = new DB.UserCommentDataTable();
            var tableAdapterVote = new DBTableAdapters.UserCommentTableAdapter();

            tableAdapterVote.Connection.ConnectionString = Server.UserConnectionString;
            //Invoke((MethodInvoker)(() =>
            //        WriteLog(string.Format("User Conection String: {0}", Server.UserConnectionString))));
            var startGetDb = DateTime.Now;

            try
            {
                tableAdapterVote.FillAllVote(dataTableVotes);
                adtProduct.FillBy_ProductSanPhamGoc(dtProduct, DateTime.Now.AddDays(-100));
            }
            catch (Exception ex)
            {
                //Invoke((MethodInvoker)(() =>
                //    WriteLog("Get ProductSanPhamGoc Error", ex)));
            }
            var getDbTime = (DateTime.Now - startGetDb).TotalSeconds;

            //calculate avgVote
            //Invoke((MethodInvoker)(() =>
            //        WriteLog(string.Format("Num Votes: {0}", dataTableVotes.Rows.Count))));
            Dictionary <long, double> avgVoteDict;
            Dictionary <long, int>    numVoteDict;

            IndexProductTools.CalculateAvgVotes(
                dataTableVotes.AsEnumerable().Select(x => new KeyValuePair <long, int>(x.IDObject, x.Vote)).ToList(), out avgVoteDict, out numVoteDict);
            double getObjectTime = 0;
            double indexSolrTime = 0;

            var listProducts = new List <SolrProductItem>();

            try
            {
                SolrDriver.DeleteByCompanyId(IDWebsosanh);
            }
            catch (Exception ex)
            {
                //Invoke((MethodInvoker)(() =>
                //    WriteLog("Delete root Product Error", ex)));
            }
            var numProduct = dtProduct.Rows.Count;

            for (var rowIndex = 0; rowIndex < numProduct; rowIndex++)
            {
                var startGetObjectTime = DateTime.Now;
                var productRow         = dtProduct.Rows[rowIndex];
                try
                {
                    var item = new SolrProductItem
                    {
                        Id                = Common.Obj2Int64(productRow["ID"]),
                        Price             = Common.Obj2Int(productRow["GiaNhoNhat"]),
                        Warranty          = Common.Obj2Int(productRow["Warranty"]),
                        Status            = Common.Obj2Int(productRow["Status"]),
                        Company           = Common.Obj2Int64(productRow["Company"]),
                        LastUpdate        = Common.ObjectToDataTime(productRow["LastUpdate"]),
                        Summary           = productRow["Summary"].ToString(),
                        Description       = "",
                        ProductId         = Common.Obj2Int(productRow["ProductID"]),
                        ProductType       = 1,
                        Name              = productRow["Name"].ToString(),
                        NameFT            = productRow["NameFT"].ToString(),
                        DetailUrl         = productRow["DetailUrl"].ToString(),
                        ImagePath         = productRow["ImagePath"].ToString(),
                        CategoryId        = Common.Obj2Int(productRow["CategoryID"]),
                        ContentFT         = productRow["ContentFT"] != DBNull.Value ? productRow["ContentFT"].ToString() : "c000",
                        ViewCount         = Common.Obj2Int(productRow["ViewCount"]),
                        ViewCountLastWeek = Common.Obj2Int(productRow["PriceChangeWeek"]),
                        AvgRate           = 0,

                        AddPosition          = Common.Obj2Int(productRow["AddPosition"]),
                        StringFilterFields   = new Dictionary <string, object>(),
                        DoubleFilterFields   = new Dictionary <string, object>(),
                        DateTimeFilterFields = new Dictionary <string, object>(),
                        IntFilterFields      = new Dictionary <string, object>()
                    };
                    //Thuoc tinh san pham
                    for (var exIndex = 1; exIndex <= 10; exIndex++)
                    {
                        string filterPropertyId    = Common.Obj2String(productRow["EX" + exIndex]);
                        string filterPropertyValue = Common.Obj2String(productRow["EXVALUE" + exIndex]);
                        if (string.IsNullOrEmpty(filterPropertyId) || filterPropertyId.Equals("0") || string.IsNullOrEmpty(filterPropertyValue))
                        {
                            continue;
                        }
                        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);
                        }
                    }
                    //Get NumProduct And Price Min
                    Product_KeyComparison         productKeyComparison = new Product_KeyComparison();
                    Product_KeyComparisonEntyties objKey = new Product_KeyComparisonEntyties();
                    objKey = productKeyComparison.SelectByProductID(item.Id);

                    item.NumProducts = objKey.TongSanPham;
                    item.PriceMin    = objKey.GiaNhoNhat;

                    if (avgVoteDict.ContainsKey(item.Id))
                    {
                        item.AvgRate = avgVoteDict[item.Id];
                        item.NumVote = numVoteDict[item.Id];
                    }
                    //productKeyComparison.GetRootProductMinPriceAndNumProducts(item.Id, out minPrice, out numProducts);
                    //if (numProducts > 0)
                    //{
                    //    item.NumProducts = numProducts;
                    //    item.PriceMin = minPrice;
                    //}
                    listProducts.Add(item);
                    getObjectTime += (DateTime.Now - startGetObjectTime).TotalSeconds;
                }
                catch (Exception ex)
                {
                    //Invoke((MethodInvoker)(() =>
                    //    WriteLog("Update Root Products", ex)));
                }

                if (rowIndex % 1000 == 0 || rowIndex == numProduct - 1)
                {
                    var startIndexSolr = DateTime.Now;
                    try
                    {
                        SolrDriver.IndexItems(listProducts);
                        listProducts.Clear();
                        var index = rowIndex;
                        //Invoke((MethodInvoker)(() =>
                        //    WriteLog(String.Format("Update solr {0}/{1} San Pham goc", index,
                        //        numProduct))));
                    }
                    catch (Exception ex)
                    {
                        //Invoke((MethodInvoker)(() =>
                        //   WriteLog("Update Solr Error", ex)));
                    }
                    indexSolrTime += (DateTime.Now - startIndexSolr).TotalSeconds;
                }
            }
            var startIndexRemainSolr = DateTime.Now;

            try
            {
                if (listProducts.Count > 0)
                {
                    SolrDriver.IndexItems(listProducts);
                }
                SolrDriver.Commit();
                //Invoke((MethodInvoker)(() =>
                //    WriteLog(String.Format("Update Finish Company san pham goc"))));
            }
            catch (Exception ex)
            {
                //Invoke((MethodInvoker)(() =>
                //    WriteLog("Update Solr Error", ex)));
            }
            indexSolrTime += (DateTime.Now - startIndexRemainSolr).TotalSeconds;
            var totalTime = (DateTime.Now - startTime).TotalSeconds;

            //Invoke((MethodInvoker)(() =>
            //    WriteLog(
            //        String.Format(
            //            "Update Complete!\nTotalTime: {0}\nGetDbTime: {1}\nGetObjectTime:{2}\nIndexSolrTime:{3}",
            //            totalTime, getDbTime, getObjectTime, indexSolrTime))));
            dtProduct.Dispose();
            adtProduct.Dispose();
        }