devexpress Scheduler control 的自定义filter

最近几天,正在学习devexpress scheduler control

的确是比较复杂。

我们先列一下,可以从哪里得到学习的资源:

https://documentation.devexpress.com/#WindowsForms/CustomDocument2278

Lesson 5 - Bind a Scheduler to MS SQL Database at Design Time

这一段是比较重要的资源。

从文档中,我们看到,可以自定义有

Lesson 7 - Create a Custom Appointment Edit Form

Lesson 8 - Implement a Custom Inplace Editor

可是,这两项,老实说,并不是真正问题的关键。

整个Scheduler体系的核心是Appointment.

因为,作为一个管理者,需要面对所有的员工的任务安排,那么这种情况下,Filter就是关键,

上图就是Devexpress 自带示例中的两个与filter相关的示例。

第一个示例,是关于电视台的,界面中,有两个维度:channels 和 sports.

虽然,只有两个维度,已经初步展示了真实世界的复杂:电视频道,和体育运动之间,有着复杂的时空关系。

但是,如果我们面对更加复杂的需求。

比如说,我们需要再加一维过滤。

比如说,我就喜欢看NBA,或者,我就只喜欢一个运动员,比如最近世锦赛里比较出名的考森斯,那么如何来加一维呢?

再比如,电视频道,是独占性资源,然而,现实世界,很多资源并不是独立性的,比如8车道高速公路,比如一个工作岗位,可能为有限数目的对象服务。

这种情况,又当如何?

所以,只有两个维度,显然是不够的。

我们先来分析一下,Appointment Filtering的示例,它的过虑代码如下:

        private void schedulerStorage_FilterAppointment(object sender, PersistentObjectCancelEventArgs e) {
            int sportId = Convert.ToInt32(this.imcbSports.EditValue);
            if (sportId < 0)
                return;

            Appointment apt = (Appointment)e.Object;
            e.Cancel = apt.LabelId != sportId;
        }

看这句:

e.Cancel = apt.LabelId != sportId;

这里有一个问题,apt对象是Appointment类的一个实例。

而Appointment类,是DevExpress.XtraScheduler库的一个类。

也就是说,这个类在类库中,除非我们去重新编译devexpress的原代码,否则,我们无法改变它。

初步看了源代码,我们也无法继承这个类。因为,devexpress似乎没有提供一个注册工厂类的地方。

老实说,面对这种情况,真应当,真接把类库代码改了省事。但现在,我们还是再看看别的例子。

想到,下面还有一个例子

这个例子中,加入了新的维度。

下断了以后,我们分析一下:

也就是说,覆写了AppointmentForm类的

protected override AppointmentFormController CreateController(SchedulerControl control, Appointment apt) {

return new UserDefinedFilterAppointmentFormController(control, apt);

}

例子在填加自定义Appointment的对话框中,填加了一个自定义控制器。UserDefinedFilterAppointmentFormController的实例。

控制器的目的,就是为了扩展Appointment类,使这个类中,自定义的字段,也能够被使用。

	public class UserDefinedFilterAppointmentFormController : AppointmentFormController {
		public UserDefinedFilterAppointmentFormController(SchedulerControl control, Appointment apt)
			: base(control, apt) {
		}

		public Decimal Price {
			get {
				object value = EditedAppointmentCopy.CustomFields["CustomFieldPrice"];
				try {
					return Convert.ToDecimal(value);
				}
				catch {
					return 0;
				}
			}
			set { EditedAppointmentCopy.CustomFields["CustomFieldPrice"] = value; }
		}

		protected override void ApplyCustomFieldsValues() {
			base.ApplyCustomFieldsValues();
			SourceAppointment.CustomFields["CustomFieldPrice"] = Price;
		}
	}

上图是调用栈。

下面,我们分析一下UserDefinedFilterModule中,过滤的实现:

关键就一句话:

		private void OnBtnApplyClick(object sender, EventArgs e) {
			schedulerControl.Storage.Appointments.Filter = filterControlForAppointments.FilterString;
		}

到这就分析得差不多了。

另外,例子中,自定义字段的映射,

		private void AddCustomFieldsMapping() {
			AppointmentCustomFieldMapping customPriceMapping = new AppointmentCustomFieldMapping("CustomFieldPrice", "Price", FieldValueType.Decimal);
			schedulerStorage1.Appointments.CustomFieldMappings.Add(customPriceMapping);
		}

其实,对我来说,更加习惯用可视化的编辑器来定义自定义映射。

时间: 2024-08-29 12:23:49

devexpress Scheduler control 的自定义filter的相关文章

Devexpress GridView.CustomSummaryCalculate 实现自定义Group Summary

--首发于博客园, 转载请保留此链接  博客原文 DevExpress Documentation官方地址:GridView.CustomSummaryCalculate Event 1. 概要 界面上 GridView 显示的数据里某些字段在读出来的时候已经 SUM By FieldA ,在界面上统计时就不能简单累计总和,条件是 FieldA 相同不能重复相加. 2. 问题 view SalesOrderLineList 中,RealTimeStockTotalQuantity 与 RealT

Atitit.struts排除url&#160;的设计and&#160;原理&#160;自定义filter&#160;排除特定url

Atitit.struts排除url 的设计and 原理 自定义filter 排除特定url 1.1. 原理流程1 2. Invoke1 3. StrutsX2 1.1. 原理流程 读取struts配置xml文件内容 得到多个regexpress规则,匹配规则与uri <constant name="struts.action.excludePattern" value="/com.attilax/core/approot_js.jsp,.*\.jsp,/api.jsp

angular自定义filter

angular自定义filter angular除了几个自带的常用的filter,还可以自定义filter,以满足不同的需求,简单研究了一下自定义filter,记录一下. 有如下场景,后台返回的数据中,status可能是英文字符串,如果在html中使用if进行挨个判断,则显得有些啰嗦,这样我们就可以使用自定义的filter实现 javasc代码: var myapp = angular.module('demoApp', []); myapp.controller('filterControll

Asp.net mvc自定义Filter简单使用

自定义Filter的基本思路是继承基类ActionFilterAttribute,并根据实际需要重写OnActionExecuting,OnActionExecuted,OnResultExecuting,OnResultExecuted这四个中的一个或多个方法. 注意类名一定要以Attribute结尾. 故名思义,Action执行前,执行后,结果返回前,结果返回后.所以它们的执行先后顺序就是OnActionExecuting,OnActionExecuted,Action,OnResultEx

DirectX:在graph自动连线中加入自定义filter

为客户提供的视频播放的filter的测试程序中,采用正向手动连接的方式(http://blog.csdn.net/mao0514/article/details/40535791),由于不同的视频压缩格式,导致这种方式的缺点是不能及时的播放任意的视频文件.现在,采用在自动连线的graph中添加自己的filter: 过程如下: 1. 构建自动连线graph: 2. 在graph中查找render filter: 3.在renderf ilter上查找输入m_r_in_pin的上位连接m_n_out

Spring-Security 自定义Filter完成验证码校验

Spring-Security的功能主要是由一堆Filter构成过滤器链来实现,每个Filter都会完成自己的一部分工作.我今天要做的是对UsernamePasswordAuthenticationFilter进行扩展,新增一个Filter,完成对登录页面的校验码的验证.下面先给一张过滤器的说明,接下来讲自定义的登录验证Filter.  https://docs.spring.io/spring-security/site/docs/3.2.8.RELEASE/reference/htmlsin

Python学习(三十七)—— 模板语言之自定义filter和中间件

一.模板语言之自定义filter 自定义filter文件存放位置 模板中自定义函数 - 在已注册的app中创建一个名字叫 templatetags 文件夹 - 任意创建一个py文件 - 创建名字交 register 的Library类的对象 - 定义函数 from django.template import Library register = Library() # 调用示例:{{ "a1"|meikai:"n1,n2"}} # 参数最多2 # 可以做if的条件

SpringBoot自定义Filter

SpringBoot自定义Filter SpringBoot自动添加了OrderedCharacterEncodingFilter和HiddenHttpMethodFilter,当然我们可以自定 义Filter. 自定义Filter需要两个步骤: 实现Filter[javax.servlet.Filter]接口,实现Filter方法 添加 @Configuration 注解,将自定义Filter加入过滤链 [过滤打印请求URL]实例代码如下: package xatu.zsl.Filter; i

springboot(八)自定义Filter

自定义Filter 我们常常在项目中会使用filters用于录调用日志.排除有XSS威胁的字符.执行权限验证等等. Spring Boot自动添加了OrderedCharacterEncodingFilter和HiddenHttpMethodFilter,并且我们可以自定义Filter. 两个步骤: 实现Filter接口,实现Filter方法 添加@Configurationz 注解,将自定义Filter加入过滤链 package cn.cnki.ref.filter; import org.a