示例#1
0
        public string GetProductList(int pageIndex, int pageSize, out int totalRecords)
        {
            totalRecords = 0;
            try
            {
                ProductItem bll  = new ProductItem();
                var         list = bll.GetListByJoin(pageIndex, pageSize, out totalRecords, string.Empty, null);
                if (list == null || list.Count() == 0)
                {
                    return("");
                }

                StringBuilder sb = new StringBuilder(3000);
                sb.Append("<Rsp>");
                foreach (var model in list)
                {
                    //sb.Append("<N>");
                    //sb.AppendFormat("<Id>{0}</Id><Name>{1}</Name><SubTitle>{2}</SubTitle><OriginalPrice>{3}</OriginalPrice><ProductPrice>{4}</ProductPrice><Discount>{5}</Discount><DiscountDescri>{6}</DiscountDescri><StockNum>{7}</StockNum><OtherPicture>{8}</OtherPicture>",
                    //   model.ProductId, model.ProductName, model.SubTitle, model.OriginalPrice, model.ProductPrice, model.Discount, model.DiscountDescri, model.StockNum, model.OtherPicture
                    //);
                    //sb.AppendFormat("<OriginalPicture>{0}</OriginalPicture><BPicture>{1}</BPicture><MPicture>{2}</MPicture><SPicture>{3}</SPicture>", WebSiteHost + model.OriginalPicture, WebSiteHost + model.BPicture, WebSiteHost + model.MPicture, WebSiteHost + model.SPicture);
                    //sb.Append("</N>");
                }
                sb.Append("</Rsp>");

                return(sb.ToString());
            }
            catch
            {
                return("");
            }
        }
示例#2
0
        private void Bind()
        {
            GetSearchItem();

            List <ProductItemInfo> list = null;
            int totalRecords            = 0;

            ProductItem bll = new ProductItem();

            list = bll.GetListByJoin(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());

            rpData.DataSource = list;
            rpData.DataBind();

            myDataAppend += "<div id=\"myDataForPage\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>";
        }
示例#3
0
        private void GetJsonForDatagrid(HttpContext context)
        {
            int totalRecords = 0;
            int pageIndex    = 1;
            int pageSize     = 10;

            if (!string.IsNullOrWhiteSpace(context.Request.Form["page"]))
            {
                int.TryParse(context.Request.Form["page"], out pageIndex);
            }
            if (!string.IsNullOrWhiteSpace(context.Request.Form["rows"]))
            {
                int.TryParse(context.Request.Form["rows"], out pageSize);
            }
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (pageSize < 10)
            {
                pageSize = 10;
            }

            string keyword     = context.Request.Form["keyword"];
            string sCategoryId = context.Request.Form["categoryId"];
            string sBrandId    = context.Request.Form["brandId"];

            string       sqlWhere = "";
            ParamsHelper parms    = null;

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                keyword   = keyword.Trim();
                sqlWhere += "and (p.ProductName like @ProductName or c.CategoryName like @CategoryName or b.BrandName like @BrandName) ";
                if (parms == null)
                {
                    parms = new ParamsHelper();
                }
                SqlParameter parm = new SqlParameter("@ProductName", SqlDbType.NVarChar, 50);
                parm.Value = keyword;
                parms.Add(parm);
                parm       = new SqlParameter("@CategoryName", SqlDbType.NVarChar, 50);
                parm.Value = keyword;
                parms.Add(parm);
                parm       = new SqlParameter("@BrandName", SqlDbType.NVarChar, 50);
                parm.Value = keyword;
                parms.Add(parm);
            }
            if (!string.IsNullOrWhiteSpace(sCategoryId))
            {
                Guid categoryId = Guid.Empty;
                Guid.TryParse(sCategoryId, out categoryId);
                if (!categoryId.Equals(Guid.Empty))
                {
                    sqlWhere += "and c.Id = @CategoryId ";
                    if (parms == null)
                    {
                        parms = new ParamsHelper();
                    }
                    SqlParameter parm = new SqlParameter("@CategoryId", SqlDbType.UniqueIdentifier);
                    parm.Value = categoryId;
                    parms.Add(parm);
                }
            }
            if (!string.IsNullOrWhiteSpace(sBrandId))
            {
                Guid brandId = Guid.Empty;
                Guid.TryParse(sBrandId, out brandId);
                if (!brandId.Equals(Guid.Empty))
                {
                    sqlWhere += "and b.Id = @BrandId ";
                    if (parms == null)
                    {
                        parms = new ParamsHelper();
                    }
                    SqlParameter parm = new SqlParameter("@BrandId", SqlDbType.UniqueIdentifier);
                    parm.Value = brandId;
                    parms.Add(parm);
                }
            }

            ProductItem bll  = new ProductItem();
            var         list = bll.GetListByJoin(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());

            if (list == null || list.Count == 0)
            {
                context.Response.Write("{\"total\":0,\"rows\":[]}");
                return;
            }

            context.Response.Write("{\"total\":" + totalRecords + ",\"rows\":" + JsonConvert.SerializeObject(list) + "}");
        }