Ejemplo n.º 1
0
        /// <summary>
        /// 订单后台-添加订单-查询商品
        /// </summary>
        /// <param name="request">
        /// 请求对象
        /// </param>
        /// <param name="searchModel">
        /// 查询对象
        /// </param>
        /// <returns>
        /// 查询结果
        /// </returns>
        public ActionResult OrderEditQueryOrderProduct(
            [DataSourceRequest] DataSourceRequest request,
            OrderProductSearchModel searchModel)
        {
            int rowCount = 0;
            int pageCount;
            var productService = new ProductService();
            var condition = productService.BuildProductQueryCondition(
                searchModel.ProductCategoryID < 1 ? string.Empty : searchModel.ProductCategoryID.ToString(),
                searchModel.SubProductCategoryID < 1 ? string.Empty : searchModel.SubProductCategoryID.ToString(),
                searchModel.ProductBrandID < 1 ? string.Empty : searchModel.ProductBrandID.ToString(),
                searchModel.SubProductBrandID < 1 ? string.Empty : searchModel.SubProductBrandID.ToString(),
                searchModel.ProductName,
                searchModel.Barcode,
                string.Empty,
                string.Empty);
            var paging = new Paging("view_Product_Paging", null, "ID", condition, request.Page, request.PageSize);
            var list = productService.Query(paging, out pageCount, out rowCount);
            if (list == null)
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }

            var modelList = new List<OrderProductModel>();

            foreach (var item in list)
            {
                var model = DataTransfer.Transfer<OrderProductModel>(item, typeof(ProductSearchResult));
                model.ProductID = item.ID;
                model.ProductName = item.Name;
                model.Path = item.ThumbnailPath;
                model.TransactPrice = item.GoujiuPrice;
                model.ID = 0;
                modelList.Add(model);
            }

            var result = new DataSourceResult { Data = modelList, Total = rowCount };

            return Json(result, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建订单商品搜索条件
        /// </summary>
        /// <param name="searchModel">
        /// 搜索对象
        /// </param>
        /// <returns>
        /// 搜索条件
        /// </returns>
        private string BuildOrderProductQueryCondition(OrderProductSearchModel searchModel)
        {
            /* **
             * select * from view_Product_SelectAllInfo where ProductBrandID in (
             *           select ID from Product_Brand where ParentID = 1
             *      ) and ProductCategoryID in (select ID from Product_Category where ParentID=1)
             *       And Name like '%电%' And Barcode like '%电%'
             * **/

            if (searchModel == null)
            {
                return null;
            }

            var sb = new StringBuilder();

            #region 类型级别转换

            if (searchModel.SubProductBrandID > 0)
            {
                if (sb.Length > 0)
                {
                    sb.Append(" And ProductBrandID =").Append(searchModel.SubProductBrandID);
                }
                else
                {
                    sb.Append(" ProductBrandID =").Append(searchModel.SubProductBrandID);
                }
            }
            else if (searchModel.ProductBrandID > 0)
            {
                // 若只选了一级品牌,需要获得二级品牌
                if (sb.Length > 0)
                {
                    sb.Append(" And ProductCategoryID in (select ID from Product_Category where ParentID=")
                        .Append(searchModel.ProductBrandID)
                        .Append(")");
                }
                else
                {
                    sb.Append(" ProductCategoryID in (select ID from Product_Category where ParentID=")
                        .Append(searchModel.ProductBrandID)
                        .Append(")");
                }
            }
            else if (searchModel.SubProductCategoryID > 0)
            {
                // 选了二级分类,则直接使用二级分类进行查询
                if (sb.Length > 0)
                {
                    sb.Append(" And ProductBrandID = ").Append(searchModel.SubProductCategoryID);
                }
                else
                {
                    sb.Append(" ProductBrandID = ").Append(searchModel.SubProductCategoryID);
                }
            }
            else if (searchModel.ProductCategoryID > 0)
            {
                // 若只选了一级分类,则转换为二级分类进行查询
                if (sb.Length > 0)
                {
                    sb.Append(
                        " And ProductCategoryID in (select ID from Product_Category where ParentID="
                        + searchModel.ProductCategoryID + ")");
                }
                else
                {
                    sb.Append(
                        " ProductCategoryID in (select ID from Product_Category where ParentID="
                        + searchModel.ProductCategoryID + ")");
                }
            }

            #endregion

            if (!string.IsNullOrWhiteSpace(searchModel.ProductName))
            {
                if (sb.Length > 0)
                {
                    sb.Append(" And Name like '%" + searchModel.ProductName + "%'");
                }
                else
                {
                    sb.Append(" Name like '%" + searchModel.ProductName + "%'");
                }
            }

            if (!string.IsNullOrWhiteSpace(searchModel.Barcode))
            {
                if (sb.Length > 0)
                {
                    sb.Append(" And Barcode like '%" + searchModel.Barcode + "%'");
                }
                else
                {
                    sb.Append(" Name Barcode '%" + searchModel.Barcode + "%'");
                }
            }

            return sb.ToString();
        }