一、摘要
在这里主要是写OEA设计方面的知识了。OEA 源码:OEA框架 2.9 Pre-Alpha 源码公布
可以到BloodyAngel的博客和中可以下到。虽然现在应经知道使用了,但是还是 需要了解框架相关知识运行机制,让我们更好的使用OEA进行开发
OEA提供了自定义模板机制。我们这里主要是 实现简单的 查询面板
二、本文大纲
a、摘要 。
b、远景 。
c、项目结构 。
d、OEA实现方法 。
三、远景
圈圈里的就是我们要实现查询条件,这个条件也是比较通用的,我们只要做一次就可以在多个页面上使用这个功能了,爽吧,减少的重复劳动了。
这个我们这里只用到了一个表的数据。
四、项目结构
用到的主要的类 如下:
1:Charging.cs2:ChargingDateCriteria.cs3:TimeSpanCriteria.cs
五、OEA实现方法
我们现在来看看他是如何实现的
1:第一步查询条件基础TimeSpanCriteria.cs
1: [Serializable]2: public abstract class TimeSpanCriteria : Criteria3: {
4: public TimeSpanCriteria()5: {
6: this.TimeSpanType = TimeSpanType.LastMonth;7: }
8:
9: public static readonly Property<TimeSpanType> TimeSpanTypeProperty = P<TimeSpanCriteria>.Register(e => e.TimeSpanType, new PropertyMetadata<TimeSpanType>10: {
11: PropertyChangedCallBack = (o, e) => (o as TimeSpanCriteria).OnTimeSpanTypeChanged(e)12: });
13: public TimeSpanType TimeSpanType14: {
15: get { return this.GetProperty(TimeSpanTypeProperty); }16: set { this.SetProperty(TimeSpanTypeProperty, value); }17: }
18: protected virtual void OnTimeSpanTypeChanged(ManagedPropertyChangedEventArgs<TimeSpanType> e)19: {
20: var today = DateTime.Today;21: switch (e.NewValue)22: {
23: case TimeSpanType.Today:24: this.From = this.To = today;25: break;26: case TimeSpanType.Week:27: var dayOfWeek = (int)today.DayOfWeek;28: if (dayOfWeek == 0) dayOfWeek = 7;29: dayOfWeek--;//0-630:
31: var monday = today.AddDays(-dayOfWeek);32: this.From = monday;33: this.To = monday.AddDays(6);34: break;35: case TimeSpanType.Month:36: this.From = new DateTime(today.Year, today.Month, 1);37: this.To = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));38: break;39: case TimeSpanType.LastMonth:40: this.From = today.AddDays(-30);41: this.To = today;42: break;43: case TimeSpanType.Year:44: this.From = new DateTime(today.Year, 1, 1);45: this.To = new DateTime(today.Year, 12, DateTime.DaysInMonth(today.Year, 12));46: break;47: case TimeSpanType.All:48: this.From = new DateTime(1800, 1, 1);49: this.To = new DateTime(9999, 12, 31);50: break;51: case TimeSpanType.Custom:52: break;53: default:54: break;55: }
56: var to = this.To;57: this.To = to.Add(new TimeSpan(23, 59, 59));58: }
59:
60: public static readonly Property<DateTime> FromProperty = P<TimeSpanCriteria>.Register(e => e.From);61: public DateTime From62: {
63: get { return this.GetProperty(FromProperty); }64: set { this.SetProperty(FromProperty, value); }65: }
66:
67: public static readonly Property<DateTime> ToProperty = P<TimeSpanCriteria>.Register(e => e.To);68: public DateTime To69: {
70: get { return this.GetProperty(ToProperty); }71: set { this.SetProperty(ToProperty, value); }72: }
73: }
74: internal class TimeSpanCriteriaConfig : EntityConfig<TimeSpanCriteria>75: {
76: protected override void ConfigView()77: {
78: View.DomainName("查é询ˉ条?件t");79:
80: //横á向ò显?示?查é询ˉ面?板?。£81: //View.DetailAsHorizontal = true;82:
83: using (View.OrderProperties())84: {
85: View.Property(TimeSpanCriteria.TimeSpanTypeProperty)86: .HasLabel("入?库a日?期ú").ShowIn(ShowInWhere.Detail);87: View.Property(TimeSpanCriteria.FromProperty)88: .HasLabel("从ó").ShowInDetail(labelWidth: 30);89: View.Property(TimeSpanCriteria.ToProperty)90: .HasLabel("至á").ShowInDetail(labelWidth: 30);91: }
92: }
93: }
94: public enum TimeSpanType95: {
96: [Label("自?定¨义?")]97: Custom,
98: [Label("当±天ì")]99: Today,
100: [Label("本?周ü")]101: Week,
102: [Label("本?月?")]103: Month,
104: [Label("最?近ü一?月?")]105: LastMonth,
106: [Label("本?年ê")]107: Year,
108: [Label("全?部?")]109: All
110: }
111:
2:第二步查询面板对应的模型ChargingDateCriteria.cs
1: [QueryEntity, Serializable]2: public class ChargingDateCriteria : TimeSpanCriteria3: {
4: public static readonly RefProperty<Charging> ChargingRefProperty =5: P<ChargingDateCriteria>.RegisterRef(e => e.Charging, ReferenceType.Normal);6: public int ChargingId7: {
8: get { return this.GetRefId(ChargingRefProperty); }9: set { this.SetRefId(ChargingRefProperty, value); }10: }
11: public Charging Charging12: {
13: get { return this.GetRefEntity(ChargingRefProperty); }14: set { this.SetRefEntity(ChargingRefProperty, value); }15: }
16: }
17: internal class ChargingDateCriteriaConfig : EntityConfig<ChargingDateCriteria>18: {
19: protected override void ConfigView()20: {
21: using (View.OrderProperties())22: {
23: View.Property(TimeSpanCriteria.TimeSpanTypeProperty);24: View.Property(TimeSpanCriteria.FromProperty);25: View.Property(TimeSpanCriteria.ToProperty);26: }
27: }
28: }
29:
30:
第三步查询面板关联那个模型
第四步显示在菜单上MyLibrary.CS
菜单界面,点击计费查询就可以看到上面的效果图了是不是很简单。
那我们现在想把这个条件附件到其他的模型上这么处理呢,如计费设定也想要这样的功能。
只需要从第二步改起就可以了。
作者:罗敏贵
邮箱:minguiluo@gmail.com
QQ群:34178394 建群 主要是寻找志同道合的人士一起学习和讨论自己的所学所思
出处:http://luomingui.cnblogs.com/
说明:专注于微软平台项目架构、熟悉设计模式、架构设计、敏捷个人和项目管理。现主要从事WinForm、ASP.NET、等方面的项目开发、架构、管理工作。文章为作者平时里的思考和练习,可能有不当之处,请博客园的园友们多提宝贵意见。
本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。