public ActionResult Index(ListItem_model Model, int?page)
        {
            var pageNumber = page ?? 1;
            int total      = new int();
            List <DisplayItem_model> lstModel    = new List <DisplayItem_model>();
            List <GetCatetory_model> lstcombobox = new List <GetCatetory_model>();

            if (!string.IsNullOrEmpty(Session["code"] as string))
            {
                Model.code = Session["code"].ToString();
            }
            if (!string.IsNullOrEmpty(Session["name"] as string))
            {
                Model.name = Session["name"].ToString();
            }
            if (Session["category_id"] as int? != null)
            {
                Model.category_id = (int)Session["category_id"];
            }
            _itemBLL.Search(Model, out lstModel, out total, pageNumber);
            var list = new StaticPagedList <DisplayItem_model>(lstModel, pageNumber, 15, total);

            ViewBag.ListSearch = lstModel.OrderByDescending(x => x.id);
            _itemBLL.GetCategory(true, out lstcombobox);
            ViewBag.lstcombobox = lstcombobox;
            ViewBag.page        = 0;
            if (page != null)
            {
                ViewBag.page = pageNumber - 1;
            }
            return(View(new Tuple <ListItem_model, IPagedList <DisplayItem_model> >(Model, list)));
        }
Пример #2
0
        public int Search(ListItem_model searchCondition, out List <DisplayItem_model> lstModel, out int total, int _page)
        {
            _page = _page * 15 - 15;
            int returnCode = (int)Common.ReturnCode.Succeed;

            lstModel = new List <DisplayItem_model>();
            total    = new int();
            try
            {
                string sql = "SELECT item.`id`, item.`code`, item.`name`, cate.`name` AS category_name, item.`specification`, item.`description` ";
                sql += "FROM `product_item` AS item ";
                sql += "JOIN (SELECT c.`id`, cpp.`name` AS category_parent_name, c.`name` ";
                sql += "FROM `product_category` AS c ";
                sql += "LEFT JOIN (SELECT cp.`name`, cp.`id` FROM `product_category` cp) cpp on cpp.`id` = c.`parent_id` ";
                sql += ") cate ON item.`category_id` = cate.`id` WHERE TRUE ";

                string _sql = "SELECT count(item.`id`) ";
                _sql += "FROM `product_item` AS item ";
                _sql += "JOIN (SELECT c.`id`, cpp.`name` AS category_parent_name, c.`name` ";
                _sql += "FROM `product_category` AS c ";
                _sql += "LEFT JOIN (SELECT cp.`name`, cp.`id` FROM `product_category` cp) cpp on cpp.`id` = c.`parent_id` ";
                _sql += ") cate ON item.`category_id` = cate.`id` WHERE TRUE ";

                if (!string.IsNullOrEmpty(searchCondition.category_id.ToString()))
                {
                    sql  += "AND (item.`category_id` = @category_id OR item.`category_id` IN (SELECT cate.`id` FROM `product_category` cate WHERE cate.`parent_id` = @category_id)) ";
                    _sql += "AND (item.`category_id` = @category_id OR item.`category_id` IN (SELECT cate.`id` FROM `product_category` cate WHERE cate.`parent_id` = @category_id)) ";
                }
                if (!string.IsNullOrEmpty(searchCondition.code))
                {
                    sql  += "AND item.`code` LIKE @code ";
                    _sql += "AND item.`code` LIKE @code ";
                }
                if (!string.IsNullOrEmpty(searchCondition.name))
                {
                    sql  += "AND item.`name` LIKE @name ";
                    _sql += "AND item.`name` LIKE @name ";
                }
                sql     += " LIMIT @page,15";
                lstModel = db.Query <DisplayItem_model>(sql, new { category_id = searchCondition.category_id, code = '%' + searchCondition.code + '%', name = '%' + searchCondition.name + '%', page = _page }).ToList();
                total    = db.ExecuteScalar <int>(_sql, new { category_id = searchCondition.category_id, code = '%' + searchCondition.code + '%', name = '%' + searchCondition.name + '%', page = _page });
            }
            catch (Exception ex)
            {
                return(returnCode = (int)Common.ReturnCode.UnSuccess);
            }
            return(returnCode);
        }
        public ActionResult IndexPost(ListItem_model Model, int?page)
        {
            var pageNumber = page ?? 1;
            List <DisplayItem_model> lstModel    = new List <DisplayItem_model>();
            List <GetCatetory_model> lstcombobox = new List <GetCatetory_model>();
            int total = new int();

            _itemBLL.Search(Model, out lstModel, out total, pageNumber);
            var list = new StaticPagedList <DisplayItem_model>(lstModel, pageNumber, 15, total);

            ViewBag.ListSearch      = lstModel.OrderByDescending(x => x.id);
            Session["code"]         = Model.code;
            Session["name"]         = Model.name;
            Session["category_id"]  = Model.category_id;
            TempData["CountResult"] = total.ToString() + " row(s) found!";
            _itemBLL.GetCategory(true, out lstcombobox);
            ViewBag.lstcombobox = lstcombobox;
            return(View(new Tuple <ListItem_model, IPagedList <DisplayItem_model> >(Model, list)));
        }
Пример #4
0
 public int Search(ListItem_model model, out List <DisplayItem_model> lstmodel, out int total, int _page)
 {
     return(item_bll.Search(model, out lstmodel, out total, _page));
 }