コード例 #1
0
        public DataTable GetProductList(int CategoryID, int PageIndex, int BrandID, decimal[] PriceRange, int OrderType, Hashtable Parameters, out int RecordCount, out int PageCount)
        {
            string where = String.Empty;

            int i = 0;

            if (Parameters != null)
            {
                foreach (string key in Parameters.Keys)
                {
                    CategoryParaModel para = new CategoryParaModelBll().GetModel(Convert.ToInt32(key), CategoryID);
                    if (i == Parameters.Count - 1)
                    {
                        where += String.Format(" and (pdproductpara.paraid = {0} and pdproductpara.paravalue like '%{1}%') ", key, para.ParaValues.Split(',')[Convert.ToInt32(Parameters[key])]);
                    }
                    else
                    {
                        where += String.Format(" and (pdproductpara.paraid = {0} and pdproductpara.paravalue like '%{1}%') ", key, para.ParaValues.Split(',')[Convert.ToInt32(Parameters[key])]);
                    }
                    i++;
                }
            }
            if (BrandID != 0)
            {
                where += " and pdproduct.brandid=" + BrandID;
            }
            if (PriceRange != null && PriceRange.Length == 2)
            {
                where += String.Format(" and pdproduct.merchantprice >= {0} and pdproduct.merchantprice <= {1}", PriceRange[0], PriceRange[1] + 0.99M);
            }

            string CategoryPath = Convert.ToString(GetCategoryInfo(CategoryID)["catepath"]);

            where += String.Format(" and pdproduct.catepath like '{0}%'", CategoryPath);
            where += " and pdproduct.status = 1";

            SearchPageInfo pageInfo = new SearchPageInfo();

            pageInfo.TableName     = "pdproductpara";
            pageInfo.PriKeyName    = "productid";
            pageInfo.FieldNames    = "pdproduct.productid,paraid,paravalue,productname,pdcategory.cateid,pdcategory.catepath,tradeprice,merchantprice,reduceprice,stock,smallimage,mediumimage,largeimage,keywords,brief,pageview,inserttime,changetime,pdproduct.status,score";
            pageInfo.TotalFieldStr = "";
            pageInfo.PageSize      = Config.ListPageSize;
            pageInfo.PageIndex     = PageIndex;
            pageInfo.OrderType     = GetOrderString(OrderType);
            pageInfo.StrWhere      = "1=1 " + where;
            pageInfo.StrJoin       = " inner join pdproduct on pdproduct.productid=pdproductpara.productid inner join pdcategory on pdproduct.cateid=pdcategory.cateid ";

            DataTable dt = CommDataHelper.GetDataFromMultiTablesByPage(pageInfo).Tables[0];

            RecordCount = pageInfo.TotalItem;
            PageCount   = pageInfo.TotalPage;

            return(dt);
        }