其他分享
首页 > 其他分享> > XPO笔记6:数据排序

XPO笔记6:数据排序

作者:互联网

XPO数据排序支持服务端排序和客户端排序,它们都依赖于以下数据集组件中的Sorting属性

  1. XPCollection服务端
  2. XPCollection客户端
  3. XPView服务端
  4. XPView客户端
  5. XPCursor
  6. XPDataView

它们不同区别和使用如下:

/// <summary>
        /// XPCollection服务端
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCollectionServer_Click(object sender, EventArgs e)
        {
            XPCollection xpc = new XPCollection(session1, typeof(Customer));
            xpCustomer.Sorting.Add(new SortProperty("Name", DevExpress.Xpo.DB.SortingDirection.Ascending));
            xpCustomer.TopReturnedObjects = 500;//XPCollection服务端设置,设置一次读取或写入的最大数据集数量
            gridControl3.DataSource = xpc;
        }
        /// <summary>
        /// XPCollection客户端
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCollectionClient_Click(object sender, EventArgs e)
        {
            XPCollection xpc = new XPCollection(session1, typeof(Customer));
            xpCustomer.Sorting.Add(new SortProperty("Name", DevExpress.Xpo.DB.SortingDirection.Descending));
            xpCustomer.TopReturnedObjects = 0;//XPCollection客户端设置0或者不设。
            gridControl3.DataSource = xpc;
        }
        /// <summary>
        /// XPView服务端
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnXPViewServer_Click(object sender, EventArgs e)
        {
            XPView xpv = new XPView(session1, typeof(Customer));
            xpv.Properties.AddRange(new ViewProperty[]
            {
                new ViewProperty("Oid", SortDirection.None, new OperandProperty("Oid"), false, true),
                new ViewProperty("Name", SortDirection.Ascending, new OperandProperty("Name"), false, true),
                new ViewProperty("Age", SortDirection.Descending, new OperandProperty("Age"), false, true)
            });
            gridControl3.DataSource = xpv;
        }
        /// <summary>
        /// XPView客户端
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnXPViewClient_Click(object sender, EventArgs e)
        {
            XPView xpv = new XPView(session1, typeof(Customer));
            SortingCollection sc1 = new SortingCollection();
            sc1.Add(new SortProperty("Name", DevExpress.Xpo.DB.SortingDirection.Descending));
            xpv.Sorting = sc1;
            gridControl3.DataSource = xpv;
        }
        /// <summary>
        /// XPCursor排序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnXPCursor_Click(object sender, EventArgs e)
        {
            XPCursor xps = new XPCursor(session1, typeof(Customer));
            xps.PageSize = 50;
            xps.Sorting.Add(new SortProperty("Name", DevExpress.Xpo.DB.SortingDirection.Ascending));
            gridControl3.DataSource = xps;
        }
        /// <summary>
        /// XPDataView排序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnXPDtataView_Click(object sender, EventArgs e)
        {
            //只支持客户端排序
            XPDataView xpdv = new XPDataView(session1.Dictionary, session1.GetClassInfo<Customer>());
            xpdv.LoadData(session1.ExecuteQuery("select * from Customer"));//如果需要在服务商排序,可以SQL语句里填写select * from Customerorder by Name asc
            xpdv.Sorting.Add(new SortProperty("Name", DevExpress.Xpo.DB.SortingDirection.Descending));
            gridControl3.DataSource = xpdv;
        }

 

标签:XPO,XPView,笔记,XPCollection,客户端,new,Name,排序,session1
来源: https://www.cnblogs.com/east115/p/16683936.html