Пример #1
0
        public Dictionary<string, object> GetAll(int pageNum, int pageSize)
        {
            ISession s = NHibernateUtils.CurrentSession;
            int total = GetTotalCars(s);
            Pager pager = new Pager(total, pageNum, pageSize);

            string item_msg = pager.GetItemMessage();

            int lowerbound = pager.LowerBound;
            int hasnext = pager.HasNext ? 1 : 0;
            int hasprev = pager.HasPrev ? 1 : 0;

            Dictionary<string, object> dic = new Dictionary<string, object>()
            {
                { "item_msg", item_msg },
                { "hasnext", hasnext },
                { "hasprev", hasprev },
                { "nextpage", pageNum + 1 },
                { "prevpage", pageNum - 1 }
            };

            IList<Car> cars = s.QueryOver<Car>()
                .Skip(lowerbound)
                .Take(pager.PageSize)
                .List();

            dic.Add("list", cars);

            return dic;
        }
Пример #2
0
        public Dictionary<string, object> GetFilterBy(int find, string keyword, int pageNum, int pageSize)
        {
            ISession s = NHibernateUtils.CurrentSession;
            ICriteria c = s.CreateCriteria<Car>();
            GetFilterCriteria(c, find, keyword);

            int total = c.List().Count;
            Pager pager = new Pager(total, pageNum, pageSize);

            string item_msg = pager.GetItemMessage();

            int lowerbound = pager.LowerBound;
            int hasnext = pager.HasNext ? 1 : 0;
            int hasprev = pager.HasPrev ? 1 : 0;

            Dictionary<string, object> dic = new Dictionary<string, object>()
            {
                { "item_msg", item_msg },
                { "hasnext", hasnext },
                { "hasprev", hasprev },
                { "nextpage", pageNum + 1 },
                { "prevpage", pageNum - 1 }
            };

            c.SetFirstResult(lowerbound);
            c.SetMaxResults(pager.PageSize);

            IList<Car> cars = c.List<Car>();

            dic.Add("list", cars);

            return dic;
        }
Пример #3
0
        public string GetItemMessage(int find, string keyword, int pageNum, int pageSize)
        {
            ISession s = NHibernateUtils.CurrentSession;
            int total = 0;
            string item_msg = "";

            if (find == 0 && string.IsNullOrEmpty(keyword))
            {
                total = GetTotalCars(s);
                Pager pager = new Pager(total, pageNum, pageSize);
                item_msg = pager.GetItemMessage();
                return item_msg;
            }

            else
            {
                ICriteria c = s.CreateCriteria<Car>();
                GetFilterCriteria(c, find, keyword);
                total = c.List().Count;
                Pager pager = new Pager(total, pageNum, pageSize);
                item_msg = pager.GetItemMessage();
                return item_msg;
            }
        }