コード例 #1
0
        public ActionResult TestPageInfoData(int startRow, int rows, string orderby, string order, string filters)
        {
            PagingRecord retValue = new PagingRecord();
            retValue.PageInfo.Rows = 20;
            retValue.PageInfo.TotalRows = 15;
            retValue.FilterInfo.Order = "asc";
            retValue.FilterInfo.Orderby = "test";

            return Json(retValue);
        }
コード例 #2
0
        public ActionResult All(int startRow, int rows, string orderby, string order, string filters)
        {
            using (var db = new DBSession("default"))
            {
                List<QueryFilter> qFilters = null == filters ? new List<QueryFilter>() : DecodeUrlJson<List<QueryFilter>>(filters);

                ISession session = db.Session;
                try
                {
                    PagingRecord retRecord = new PagingRecord();
                    retRecord.FilterInfo.Order = order;
                    retRecord.FilterInfo.Orderby = orderby;
                    retRecord.PageInfo.Rows = rows;

                    //DetachedCriteria c = DetachedCriteria.For<Customer_reltab>()
                    //    .SetProjection(Projections.Property("custNo"));

                    ICriteria cmain = session.CreateCriteria<Customer_reltab>();

                    IClassMetadata metadata = db.Session.SessionFactory.GetClassMetadata(typeof(Customer_reltab));
                    //    .Add(Subqueries.PropertyNotIn("Vie_ieid", c));

                    BuildCriterionFromJsonQuery(cmain, qFilters,
                        metadata, (f) => { return f.Substring(0, 1).ToUpper() + f.Substring(1, f.Length - 1); });

                    switch (order.ToUpper())
                    {
                        case "ASC":
                            cmain.AddOrder(Order.Asc(orderby.ToFirstUpper()));
                            break;
                        case "DESC":
                            cmain.AddOrder(Order.Desc(orderby.ToFirstUpper()));
                            break;
                        default:
                            cmain.AddOrder(Order.Asc(orderby.ToFirstUpper()));
                            break;
                    }

                    ICriteria countc = cmain.Clone() as ICriteria;

                    countc.SetProjection(Projections.CountDistinct("CustNo"));

                    retRecord.PageInfo.TotalRows = countc.UniqueResult<int>();

                    if (0 != rows)
                    {
                        cmain.SetFirstResult(startRow - 1).SetMaxResults(rows);
                    }

                    IList<Customer_reltab> retValues = cmain.List<Customer_reltab>();

                    retRecord.Records = retValues;

                    return DefaultJson(retRecord);
                }
                catch (Exception eX)
                {
                    return ErrorContent(eX.Message);
                }
            }
        }