Example #1
0
        public Product_KeyComparisonEntyties SelectByProductID(long IDProduct)
        {
            Product_KeyComparisonEntyties obj = new Product_KeyComparisonEntyties();

            DB.Product_KeyComparisonDataTable dt = new DB.Product_KeyComparisonDataTable();
            DBTableAdapters.Product_KeyComparisonTableAdapter adt = new DBTableAdapters.Product_KeyComparisonTableAdapter();
            adt.Connection.ConnectionString = Server.ConnectionString;
            adt.FillBy_IDProduct(dt, IDProduct);
            if (dt.Rows.Count > 0)
            {
                obj = obj.MapObject((DataRow)dt.Rows[0]);
            }
            adt.Dispose();
            dt.Dispose();
            return(obj);
        }
Example #2
0
        public Product_KeyComparisonEntyties UpdatePriceAndTongSP_ProductAndKeyComparision(long IDProduct)
        {
            Product_KeyComparisonEntyties obj = new Product_KeyComparisonEntyties();

            obj = this.SelectByProductID(IDProduct);
            if (obj.Code != null)
            {
                if (obj.Code.Trim().Length <= 0)
                {
                    return(obj);
                }
                obj.InitKeyword();
                DBTableAdapters.ProductTableAdapter adt = new DBTableAdapters.ProductTableAdapter();
                adt.Connection.ConnectionString = Server.ConnectionString;
                DB.ProductAnalyticDataTable dtAN = new DB.ProductAnalyticDataTable();
                DBTableAdapters.ProductAnalyticTableAdapter adtAN = new DBTableAdapters.ProductAnalyticTableAdapter();
                adtAN.Connection.ConnectionString = Server.ConnectionString;
                DBTableAdapters.Price_LogsTableAdapter adtPriceLog = new DBTableAdapters.Price_LogsTableAdapter();
                adtPriceLog.Connection.ConnectionString = Server.ConnectionString;
                int priceMin = 0, priceMax = 0, tong = 0;
                try
                {
                    adtAN.CMS_Product_SearchAnaytic_v2(dtAN,
                                                       obj.PriceMin,
                                                       obj.PriceMax,
                                                       obj.codeContains,
                                                       obj.codeLike,
                                                       obj.codeLike1,
                                                       obj.codeLike2,
                                                       obj.codeLike3,
                                                       obj.notCode,
                                                       obj.notCodeLike,
                                                       obj.notCodeLike1,
                                                       obj.notCodeLike2,
                                                       obj.notCodeLike3,
                                                       0);
                    /// hiện thời đang không dùng đên idproduct sản phẩm gốc để check
                    ///
                    if (dtAN.Rows.Count > 0)
                    {
                        tong     = dtAN.Rows.Count;
                        priceMin = Common.Obj2Int(dtAN.Rows[0]["Price"].ToString());
                        priceMax = Common.Obj2Int(dtAN.Rows[tong - 1]["Price"].ToString());
                        if (dtAN.Rows.Count > 1)
                        {
                            obj.GiaChenh = Common.Obj2Int(dtAN.Rows[1]["Price"].ToString()) - priceMin;
                        }
                        else
                        {
                            obj.GiaChenh = 0;
                        }
                        /// Map lại toàn bộ product ID
                        ///
                        int proid = Common.Obj2Int(IDProduct);
                        foreach (DB.ProductAnalyticRow dr in dtAN)
                        {
                            adt.UpdateQuery_ProductID(proid, dr.ID);
                        }
                    }
                    // return xem log
                    obj.TongSanPham = tong;
                    obj.PriceMin    = priceMin;
                    obj.PriceMax    = priceMax;
                }
                catch (Exception)
                {
                }
                try
                {
                    adt.UpdateQuery_GiaSPGoc(priceMin, DateTime.Now, String.Format("Tìm thấy {0} sản phẩm", tong), IDProduct);
                    if (priceMin > 0)
                    {
                        adtPriceLog.Insert(IDProduct, DateTime.Now, priceMin, 0);
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    DBTableAdapters.Product_KeyComparisonTableAdapter adtKey = new DBTableAdapters.Product_KeyComparisonTableAdapter();
                    adtKey.Connection.ConnectionString = Server.ConnectionString;
                    adtKey.UpdateQuery_GiaSauPhanTich(tong, priceMin, priceMax, DateTime.Now, obj.GiaChenh, IDProduct);
                }
                catch (Exception)
                {
                }
                dtAN.Dispose();
                adt.Dispose();
                adtAN.Dispose();
                adtPriceLog.Dispose();
            }

            return(obj);
        }