Ejemplo n.º 1
0
        //model category
        //Jewellery
        public ActionResult Jewellery(int index = 1)
        {
            //judge if user is logined
            if (Session["UserID"] != null)
            {
                ViewBag.UserId = Session["UserID"];
                int userId = Convert.ToInt32(Session["UserID"].ToString());
                var user   = db.Users.Find(userId);
                ViewBag.UserName = user.UserName;
            }
            var filterTime = Request.QueryString["filterTime"];
            var minPrice   = Request.QueryString["minPrice"];
            var maxPrice   = Request.QueryString["maxPrice"];
            var orderBy    = Request.QueryString["orderBy"];

            if (minPrice == "")
            {
                minPrice = null;
            }
            if (maxPrice == "")
            {
                maxPrice = null;
            }
            PagingForFilter <ModelLibrary> modelPaging = FilterCategory("珠宝类", filterTime, minPrice, maxPrice, orderBy, index);

            SetFilterFormParameter(filterTime, orderBy, minPrice, maxPrice);
            return(View(modelPaging));
        }
Ejemplo n.º 2
0
        //set modelpaging parameter(index and source) and calculate counts
        private PagingForFilter <ModelLibrary> SetModelPagingParam(int index, IQueryable <ModelLibrary> models)
        {
            PagingForFilter <ModelLibrary> model = new PagingForFilter <ModelLibrary>(8);

            model.PageData  = models;
            model.PageIndex = index;
            model.CalCount();
            return(model);
        }
Ejemplo n.º 3
0
        //filter category by parameter
        private PagingForFilter <ModelLibrary> FilterCategory(string modelClass, string filterTime, string minPrice, string maxPrice, string orderBy, int index)
        {
            if (modelClass == null)
            {
                return(null);
            }

            if (filterTime == null && minPrice == null && maxPrice == null && orderBy == null)
            {
                SQLQuery = QueryString.queryNull;
            }
            else if (filterTime != null && minPrice == null && maxPrice == null && orderBy == null)
            {
                SQLQuery = QueryString.queryTime;
            }
            else if (filterTime == null && minPrice != null && maxPrice == null && orderBy == null)
            {
                SQLQuery = QueryString.queryMinprice;
            }
            else if (filterTime == null && minPrice == null && maxPrice != null && orderBy == null)
            {
                SQLQuery = QueryString.queryMaxprice;
            }
            else if (filterTime == null && minPrice == null && maxPrice == null && orderBy != null)
            {
                SQLQuery = QueryString.queryOrder;
            }
            else if (filterTime != null && minPrice != null && maxPrice == null && orderBy == null)
            {
                SQLQuery = QueryString.queryTimeMinprice;
            }
            else if (filterTime != null && minPrice == null && maxPrice != null && orderBy == null)
            {
                SQLQuery = QueryString.queryTimeMaxprice;
            }
            else if (filterTime != null && minPrice == null && maxPrice == null && orderBy != null)
            {
                SQLQuery = QueryString.queryTimeOrder;
            }
            else if (filterTime == null && minPrice != null && maxPrice == null && orderBy != null)
            {
                SQLQuery = QueryString.queryOrderMinprice;
            }
            else if (filterTime == null && minPrice == null && maxPrice != null && orderBy != null)
            {
                SQLQuery = QueryString.queryOrderMaxprice;
            }
            else if (filterTime == null && minPrice != null && maxPrice != null && orderBy == null)
            {
                SQLQuery = QueryString.queryMinpriceMaxprice;
            }
            else if (filterTime != null && minPrice != null && maxPrice != null && orderBy == null)
            {
                SQLQuery = QueryString.queryTimeMinpriceMaxprice;
            }
            else if (filterTime != null && minPrice != null && maxPrice == null && orderBy != null)
            {
                SQLQuery = QueryString.queryTimeOrderMinprice;
            }
            else if (filterTime != null && minPrice == null && maxPrice != null && orderBy != null)
            {
                SQLQuery = QueryString.queryTimeOrderMaxprice;
            }
            else if (filterTime == null && minPrice != null && maxPrice != null && orderBy != null)
            {
                SQLQuery = QueryString.queryOrderMinpriceMaxprice;
            }
            else if (filterTime != null && minPrice != null && maxPrice != null && orderBy != null)
            {
                SQLQuery = QueryString.queryTimeMinpriceMaxpriceOrder;
            }

            //exce linq to read data from sqlserver
            //var db = new OnlinePrintDbContext();
            PagingForFilter <ModelLibrary> modelPaging = new PagingForFilter <ModelLibrary>(8);
            IQueryable <ModelLibrary>      models      = null;

            if (modelClass == "all")
            {
                models = db.ModelLibrary.Where(n => n.ModelState);
            }
            else
            {
                models = db.ModelLibrary.Where(n => n.ModelState).Where(n => n.ModelClass == modelClass);
            }
            decimal min = 0;
            decimal max = 100000;

            switch (SQLQuery)
            {
            case QueryString.queryNull:
                //modelPaging.PageData = models;
                //modelPaging.PageIndex = index;
                //modelPaging.CalCount();
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTime:
                //modelPaging.PageData = FilterTime(filterTime, DateTime.Now, models);
                //modelPaging.PageIndex = index;
                //modelPaging.CalCount();
                models      = FilterTime(filterTime, DateTime.Now, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryMinprice:
                min         = Convert.ToDecimal(minPrice);
                models      = models.Where(n => (min <= n.ModelPrintPrice));
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryMaxprice:
                max         = Convert.ToDecimal(maxPrice);
                models      = models.Where(n => (n.ModelPrintPrice <= max));
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryOrder:
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeMinprice:
                min         = Convert.ToDecimal(minPrice);
                models      = models.Where(n => (min <= n.ModelPrintPrice));
                models      = FilterTime(filterTime, DateTime.Now, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeMaxprice:
                max         = Convert.ToDecimal(maxPrice);
                models      = models.Where(n => (n.ModelPrintPrice <= max));
                models      = FilterTime(filterTime, DateTime.Now, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeOrder:
                models      = FilterTime(filterTime, DateTime.Now, models);
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryOrderMinprice:
                min         = Convert.ToDecimal(minPrice);
                models      = models.Where(n => (min <= n.ModelPrintPrice));
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryOrderMaxprice:
                max         = Convert.ToDecimal(maxPrice);
                models      = models.Where(n => (n.ModelPrintPrice <= max));
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryMinpriceMaxprice:
                min         = Convert.ToDecimal(minPrice);
                max         = Convert.ToDecimal(maxPrice);
                models      = models.Where(n => (min <= n.ModelPrintPrice) && (n.ModelPrintPrice <= max));
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeMinpriceMaxprice:
                min         = Convert.ToDecimal(minPrice);
                max         = Convert.ToDecimal(maxPrice);
                models      = FilterTime(filterTime, DateTime.Now, models);
                models      = models.Where(n => (min <= n.ModelPrintPrice) && (n.ModelPrintPrice <= max));
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeOrderMinprice:
                min         = Convert.ToDecimal(minPrice);
                models      = models.Where(n => (min <= n.ModelPrintPrice));
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeOrderMaxprice:
                max         = Convert.ToDecimal(maxPrice);
                models      = models.Where(n => (n.ModelPrintPrice <= max));
                models      = FilterTime(filterTime, DateTime.Now, models);
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryOrderMinpriceMaxprice:
                min         = Convert.ToDecimal(minPrice);
                max         = Convert.ToDecimal(maxPrice);
                models      = models.Where(n => (min <= n.ModelPrintPrice) && (n.ModelPrintPrice <= max));
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            case QueryString.queryTimeMinpriceMaxpriceOrder:
                min         = Convert.ToDecimal(minPrice);
                max         = Convert.ToDecimal(maxPrice);
                models      = FilterTime(filterTime, DateTime.Now, models);
                models      = models.Where(n => (min <= n.ModelPrintPrice) && (n.ModelPrintPrice <= max));
                models      = FilterOrderBy(orderBy, models);
                modelPaging = SetModelPagingParam(index, models);
                break;

            default:
                break;
            }
            return(modelPaging);
        }