[原] XAF 如何启用ListView Top N records 提升用户使用体验
為了提升用戶使用體驗,特擴展此功能(來源與Xafari Framework)。
1.可在模型編輯器中設置是否啓用,默認啓用。
2.DataAccessMode為Client模式才啓用。其它模式自動關閉。
3.詳見代碼。
4.當有篩選條件時有Bug,還有待解決,才能上綫使用!

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text; namespace CommonModule.ListViewControl.PartialLoadListView
{
[DefaultValue()]
public enum PartSize
{
//[Description("100")]
//Rec100,
//[Description("250")]
//Rec250,
//[Description("500")]
//Rec500,
[Description("")]
Rec1000,
//[Description("2500")]
//Rec2500,
[Description("")]
Rec5000,
[Description("All")]
RecAll
} public enum LoadingBehavior
{
Refresh,
LoadPart,
LoadAll
} public enum ItemsStringId
{
StringTop,
StringAll,
StringAllShown,
StringTopShown,
StringRecords
} public interface IModelListViewXafari : IModelNode,IModelExtender
{
[Category("Data"), DefaultValue(true), Description("If set to true, partial loading will be used.")]
bool TopReturnedObjectsChangingEnabled
{
get;
set;
}
} [DomainLogic(typeof(IModelListViewXafari))]
public static class IModelListViewXafariLogic
{
public static bool TopReturnedObjectsChangingEnabled(this IModelListView modelListView)
{
return ((IModelListViewXafari)modelListView).TopReturnedObjectsChangingEnabled;
}
}
}
using CommonModule.ListViewControl.PartialLoadListView;
using DevExpress.Data;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Templates;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.ExpressApp.Xpo;
using DevExpress.Utils;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows.Forms; namespace CommonModule.ListViewControl.PartialLoadListView
{
public class PartialLoadListViewController : ViewController<DevExpress.ExpressApp.ListView>, IModelExtender
{
private const string limitImage = null;
private const string allImage = null;
private int _partSize;
private ChoiceActionItem _setPartSizeItem;
private XPCollection _collection;
private CollectionSourceBase _collectionSource;
private bool _allShown;
private int _records;
private int _partCountCore = ;
private IContainer components;
private SingleChoiceAction partLoadAction;
public int PartCount
{
get
{
return this._partCountCore;
}
}
public PartialLoadListViewController()
{
this.InitializeComponent();
base.RegisterActions(this.components);
base.TargetViewType = DevExpress.ExpressApp.ViewType.ListView;
this.SetupItems();
}
protected override void OnActivated()
{
this.partLoadAction.Active.SetItemValue("Active", false);
if (base.View != null && base.View.Model.DataAccessMode != CollectionSourceDataAccessMode.Client)
{
return;
}
if (this.GetModelListView() == null)
{
return;
}
base.OnActivated(); this.SetupAppearance();
}
private void ViewOnControlsCreated(object sender, EventArgs eventArgs)
{
GridView gridView = this.GetGridView();
this.InitCollection();
this._collection.LoadingEnabled = false;
this._collectionSource.TopReturnedObjects = ;
this._collectionSource.Sorting.Clear();
gridView.BeginSort();
foreach (GridColumn gridColumn in gridView.Columns)
{
if (gridColumn.SortOrder != ColumnSortOrder.None)
{
if (gridColumn.SortOrder == ColumnSortOrder.Ascending)
{
this._collectionSource.Sorting.Add(new SortProperty(PartialLoadListViewController.PropertyName(gridColumn), SortingDirection.Ascending));
}
else
{
this._collectionSource.Sorting.Add(new SortProperty(PartialLoadListViewController.PropertyName(gridColumn), SortingDirection.Descending));
}
}
}
gridView.EndSort();
this._collectionSource.TopReturnedObjects = this._records;
this._collection.LoadingEnabled = true;
} private IModelListViewXafari GetModelListView()
{
IModelListViewXafari modelListViewXafari = base.View.Model as IModelListViewXafari;
if (modelListViewXafari == null || !modelListViewXafari.TopReturnedObjectsChangingEnabled)
{
return null;
}
this._records = base.View.Model.TopReturnedObjects;
return modelListViewXafari;
}
private void SetupAppearance()
{
this.partLoadAction.PaintStyle = ActionItemPaintStyle.CaptionAndImage;
if (base.View.Model.TopReturnedObjects != )
{
this.SetImageAndCaptionToLimitShow();
}
else
{
this.SetImageAndCaptionToShowAllRecords();
}
this.partLoadAction.Active.SetItemValue("Active", true);
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
base.View.CurrentObjectChanged += new EventHandler(this.ViewOnCurrentObjectChanged);
this.InitCollection();
GridView gridView = this.GetGridView();
if (gridView != null)
{
gridView.Click += new EventHandler(this.GridViewOnClick);
}
}
private static string PropertyName(GridColumn column)
{
IGridColumnModelSynchronizer gridColumnInfo = PartialLoadListViewController.GetGridColumnInfo(column);
if (gridColumnInfo == null)
{
return column.FieldName;
}
return gridColumnInfo.PropertyName;
} private static IGridColumnModelSynchronizer GetGridColumnInfo(GridColumn column)
{
if (column != null && column.View is IModelSynchronizersHolder)
{
return ((IModelSynchronizersHolder)column.View).GetSynchronizer(column) as IGridColumnModelSynchronizer;
}
return null;
}
private void GridViewOnClick(object sender, EventArgs eventArgs)
{
if (this._allShown || this._collectionSource.Sorting == null)
{
return;
}
MouseEventArgs mouseEventArgs = eventArgs as MouseEventArgs;
if (mouseEventArgs == null || mouseEventArgs.Button != MouseButtons.Left)
{
return;
}
GridView gridView = sender as GridView;
if (gridView.IsSizingState)
{
return;
}
GridHitInfo gridHitInfo = gridView.CalcHitInfo(mouseEventArgs.Location);
if (gridHitInfo.HitTest == GridHitTest.ColumnFilterButton)
{
return;
}
if (gridHitInfo.InColumn)
{
this._collection.LoadingEnabled = false;
this._collectionSource.TopReturnedObjects = ;
if (this._collectionSource.Sorting != null)
{
this._collectionSource.Sorting.Clear();
}
else
{
this._collectionSource.Sorting = new List<SortProperty>();
}
gridView.BeginSort();
foreach (GridColumn gridColumn in gridView.Columns)
{
gridColumn.SortOrder = ColumnSortOrder.None;
}
if (gridHitInfo.Column.SortOrder == ColumnSortOrder.None || gridHitInfo.Column.SortOrder == ColumnSortOrder.Descending)
{
this._collectionSource.Sorting.Add(new SortProperty(PartialLoadListViewController.PropertyName(gridHitInfo.Column), SortingDirection.Ascending));
gridHitInfo.Column.SortOrder = ColumnSortOrder.Ascending;
}
else
{
this._collectionSource.Sorting.Add(new SortProperty(PartialLoadListViewController.PropertyName(gridHitInfo.Column), SortingDirection.Descending));
gridHitInfo.Column.SortOrder = ColumnSortOrder.Descending;
}
gridView.EndSort();
this._collectionSource.TopReturnedObjects = this._records;
this._collection.LoadingEnabled = true;
base.ObjectSpace.Refresh();
DXMouseEventArgs.GetMouseArgs(mouseEventArgs).Handled = true;
}
} private GridView GetGridView()
{
GridListEditor gridListEditor = base.View.Editor as GridListEditor;
if (gridListEditor == null || gridListEditor.GridView == null)
{
return null;
}
return gridListEditor.GridView;
}
private void ViewOnCurrentObjectChanged(object sender, EventArgs eventArgs)
{
base.View.CurrentObjectChanged -= new EventHandler(this.ViewOnCurrentObjectChanged);
int topReturnedObjects = base.View.Model.TopReturnedObjects;
if (topReturnedObjects == )
{
this.SetImageAndCaptionToShowAllRecords();
this._allShown = true;
return;
}
this._partSize = topReturnedObjects;
this.SetImageAndCaptionToLimitShow();
this.SetPartSize();
this.ResetPartCount();
this.UpdateCollection(LoadingBehavior.LoadPart);
}
private void SetPartSize()
{
if (!(base.View.Model is IModelListViewXafari))
{
return;
}
this._partSize = base.View.Model.TopReturnedObjects;
}
private void InitCollection()
{
this._collectionSource = base.View.CollectionSource;
ProxyCollection proxyCollection = this._collectionSource.Collection as ProxyCollection;
if (proxyCollection == null)
{
return;
}
this._collection = (XPCollection)proxyCollection.OriginalCollection;
}
private void ResetPartCount()
{
this._partCountCore = ;
}
private void UpdatePartCount()
{
this._partCountCore++;
}
private void UpdateCollection(LoadingBehavior behavior)
{
if (this._collection == null)
{
this.InitCollection();
}
try
{
this._collection.LoadingEnabled = false;
Type type = base.View.ObjectTypeInfo.Type;
decimal value = Convert.ToDecimal(((XPObjectSpace)base.ObjectSpace).Session.Evaluate(type, CriteriaOperator.Parse("Count()", new object[]), XPObjectSpace.CombineCriteria(this._collectionSource.Criteria.GetValues().ToArray())));
int num;
if (behavior != LoadingBehavior.LoadAll && (this._partCountCore == || behavior == LoadingBehavior.Refresh))
{
num = this._records;
}
else if (behavior == LoadingBehavior.LoadAll)
{
num = (int)value;
this._records = num;
}
else
{
if (this._partSize == )
{
this._partSize = this._records;
}
this._records += this._partSize;
num = this._records;
}
this._collectionSource.TopReturnedObjects = num;
if (behavior != LoadingBehavior.Refresh)
{
base.View.ObjectSpace.Refresh();
}
this._collection.LoadingEnabled = true;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
private void SetupItems()
{
this.partLoadAction.Items.Clear();
this.FillItemWithEnumValues(typeof(PartSize));
}
private void FillItemWithEnumValues(Type enumType)
{
IEnumerator enumerator = Enum.GetValues(enumType).GetEnumerator();
try
{
while (enumerator.MoveNext())
{
object current = enumerator.Current;
PartSize enumValue = (PartSize)current;
ChoiceActionItem choiceActionItem = new ChoiceActionItem(Guid.NewGuid().ToString(), current);
choiceActionItem.ImageName = ImageLoader.Instance.GetEnumValueImageName(current);
choiceActionItem.Caption = ((DescriptionAttribute)Attribute.GetCustomAttribute(typeof(PartSize).GetFields(BindingFlags.Static | BindingFlags.Public).Single((FieldInfo x) => (PartSize)x.GetValue(null) == enumValue), typeof(DescriptionAttribute))).Description;
this.partLoadAction.Items.Add(choiceActionItem);
if (current.ToString() == "RecAll")
{
choiceActionItem.BeginGroup = true;
}
}
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
}
private void partLoadAction_Execute(object sender, SingleChoiceActionExecuteEventArgs e)
{
if (e.SelectedChoiceActionItem.ParentItem != this._setPartSizeItem)
{
if (e.SelectedChoiceActionItem.Caption == "顯示更多")
{
this.UpdatePartCount();
this.UpdateCollection(LoadingBehavior.LoadPart);
this.SetImageAndCaptionToLimitShow();
}
return;
}
ChoiceActionItem choiceActionItem = this.partLoadAction.Items.FirstOrDefault((ChoiceActionItem a) => a.Id == "顯示更多");
if (e.SelectedChoiceActionItem.Caption == "All")
{
if (DialogResult.OK != MessageBox.Show("這個操作比較耗時,建議你請先設置查詢條件再執行次操作,確定執行?", "警告!",
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
return; this.SetImageAndCaptionToShowAllRecords();
this.UpdateCollection(LoadingBehavior.LoadAll);
this.partLoadAction.ToolTip = "顯示所有記錄";//XafariWinLocalizer.Active.GetLocalizedString(ItemsStringId.StringAllShown);
this._allShown = true;
if (choiceActionItem != null)
{
choiceActionItem.Enabled.SetItemValue("Enabled", false);
}
return;
}
int num = Convert.ToInt32(e.SelectedChoiceActionItem.Caption);
base.View.Model.TopReturnedObjects = num;
this._partSize = num;
this.ResetPartCount();
this._records = this._partSize;
this.UpdateCollection(LoadingBehavior.LoadPart);
if (choiceActionItem != null)
{
choiceActionItem.Enabled.SetItemValue("Enabled", true);
}
this.SetImageAndCaptionToLimitShow();
this._allShown = false;
}
protected override void OnDeactivated()
{
GridView gridView = this.GetGridView();
if (gridView != null)
{
gridView.Click -= new EventHandler(this.GridViewOnClick);
}
base.OnDeactivated();
}
private void SetImageAndCaptionToShowAllRecords()
{
this.partLoadAction.ImageName = null;
this.partLoadAction.Caption = "All";// XafariWinLocalizer.Active.GetLocalizedString(ItemsStringId.StringAll);
this.partLoadAction.ToolTip = "顯示所有記錄";//XafariWinLocalizer.Active.GetLocalizedString(ItemsStringId.StringAllShown);
}
private void SetImageAndCaptionToLimitShow()
{
this.partLoadAction.ImageName = null;
this.partLoadAction.Caption = string.Format("{0} {1} ", "僅顯示前", this._records);
this.partLoadAction.ToolTip = string.Format("{0} {1} {2}.", "僅顯示前", this._records, "條記錄");
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new Container();
this.partLoadAction = new SingleChoiceAction(this.components);
this.partLoadAction.ItemType = SingleChoiceActionItemType.ItemIsOperation;
this.partLoadAction.Caption = "部分顯示";
this.partLoadAction.ConfirmationMessage = null;
this.partLoadAction.EmptyItemsBehavior = EmptyItemsBehavior.None;
this.partLoadAction.Id = "partLoadAction";
this.partLoadAction.PaintStyle = ActionItemPaintStyle.CaptionAndImage;
this.partLoadAction.ShowItemsOnClick = true;
this.partLoadAction.ToolTip = string.Empty;
this.partLoadAction.Execute += new SingleChoiceActionExecuteEventHandler(this.partLoadAction_Execute);
}
public void ExtendModelInterfaces(DevExpress.ExpressApp.Model.ModelInterfaceExtenders extenders)
{
extenders.Add<IModelViews, IModelListViewXafari>();
extenders.Add<IModelListView, IModelListViewXafari>();
}
} }
[原] XAF 如何启用ListView Top N records 提升用户使用体验的更多相关文章
- [原] XAF ListView 凍結列
using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostic ...
- [原] XAF 如何啟用ListView橫向滾動條
using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Win.Editors; using DevExpress ...
- [原] XAF How to bind a stored procedure to a ListView in XAF
First, I suggest that you review the following topic to learn how to show a custom set of objects in ...
- [原] XAF ListView显示隐藏Footer菜单
using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Win.Editors; using DevExpress ...
- [原] XAF How to Edit multiple objects in a ListViewAndDetailView
2014年好久没有更新Blog了,工作调换了,很少用XAF,但还是很关注XAF的发展和学习,对中国的中小企业数据管理软件开发真的太实用了!! 功能比较简单,但很实用,直接上图和代码! ListView ...
- [原] XAF 添加日期筛选下拉选择
1.ListView 添加日期筛选下拉选择,选择指定,可指定日期范围 2.Code using DevExpress.Data.Filtering; using DevExpress.ExpressA ...
- [原] XAF 如何将数据库中Byte array图片显示出来
问题比较简单,直接上代码. private Image _Cover; [Size(SizeAttribute.Unlimited), ValueConverter(typeof(ImageValue ...
- [原] XAF 如何基于业务规则禁用属性
How to: Disable Property Editors Based on a Business Rule // Developer Express Code Central Example: ...
- 安卓程序代写 网上程序代写[原]Android开发技巧--ListView
1. ListView中元素的排序 ListView中的元素排序, 即将数据源排序即可; 给集合排序的方法 : 调用Collections的sort(list, Comparator)方法, 该方法需 ...
随机推荐
- ios UILabel在storyBoard或xib中如何在每行文字不显示完就换行
大家知道怎么用代码让label中的文字换行,只需要 label.numberOfLines = 0; label.text = @"这是第一行啦啦啦啦,\n这是第二行啦啦,\n这是第三行&q ...
- HTML实体符号代码速查表
1.特色的 © © © 版权标志 | | 竖线,常用作菜单或导航中的分隔符 · · · 圆点,有时被用来作为菜单分隔符 ↑ ↑ ↑ 上箭头,常用作网页“返回页面顶部”标识 € € € 欧元标识 ² ...
- Volley简单封装
public interface IRequest { /** * 获取头部信息 * * @return */ public Map<String, String> getHeaderMa ...
- CentOS下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
一.源码包准备 服务器端主要是安装memcache服务器端下载:http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz另外,Memca ...
- SpringMVC+Freemarker+JSTL支持
前提: 网页编程中,我的思路是,通用的模块不仅仅只有后台代码,前端页面也可以独立为模块. 这个和asp.net中的UserController很像 比如有个人员基本信息的展示界面,需要在多个界面中嵌入 ...
- [修改后]html+css 做成一个可浏览的表格
现在表格内容需要显示的要求如下: 1, 表格很大,界面放不小,需要放到div中. 2, 在div中可以用scroll滑动查看. 3, td中的内容保持在一行中. 4, 可以点击tr,然后可以选中并了解 ...
- AdminLTE-2.2.0 学习
这货基于Bootstrap 3(提供了统一的样式,覆盖了默认的),所以官方建议先搞懂Bootstrap 3再说. # 布局 Layout 布局由四个主要部分组成: Wrapper (.wrapper) ...
- caffe net 可视化工具
http://ethereon.github.io/netscope/#/editor 将对应的网络输入到里面,然后按shift+enter即可查看对应的网络结构
- 总结最近移动端遇到的坑(auto-size + zepto)
问题一:移动端页面双击会放大,图片时大时正常,布局偶尔很丑..刷新多遍又乜有问题 解决:所有图片设置宽高100%,最外面的html,给个 <meta name="viewport&qu ...
- Nginx禁止ip访问或IP网段访问方法
Nginx禁止ip访问可以防止指定IP访问我们的网站,本例子可以实现是防止单IP访问或IP网段访问了,非常的有用我们一起来看看吧. 常用的linux做法 iptables参考规则 代码如下 复制代码 ...