博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OEA体验:查询面板
阅读量:7095 次
发布时间:2019-06-28

本文共 5815 字,大约阅读时间需要 19 分钟。

一、摘要

       在这里主要是写OEA设计方面的知识了。OEA 源码:

可以到的博客和中可以下到。虽然现在应经知道使用了,但是还是 需要了解框架相关知识运行机制,让我们更好的使用OEA进行开发

        OEA提供了自定义模板机制。我们这里主要是 实现简单的 查询面板

二、本文大纲

       a、摘要 。

       b、远景 。

       c、项目结构 。

       d、OEA实现方法  。

三、远景

     圈圈里的就是我们要实现查询条件,这个条件也是比较通用的,我们只要做一次就可以在多个页面上使用这个功能了,爽吧,减少的重复劳动了。

这个我们这里只用到了一个表的数据。

四、项目结构

      

用到的主要的类 如下:

1:Charging.cs
2:ChargingDateCriteria.cs
3:TimeSpanCriteria.cs
五、OEA实现方法

       我们现在来看看他是如何实现的

     1:第一步查询条件基础TimeSpanCriteria.cs

1:  [Serializable]
2:  public abstract class TimeSpanCriteria : Criteria
3:  {
4:      public TimeSpanCriteria()
5:      {
6:          this.TimeSpanType = TimeSpanType.LastMonth;
7:      }
8:   
9:      public static readonly Property
TimeSpanTypeProperty = P
.Register(e => e.TimeSpanType, new PropertyMetadata
10:      {
11:          PropertyChangedCallBack = (o, e) => (o as TimeSpanCriteria).OnTimeSpanTypeChanged(e)
12:      });
13:      public TimeSpanType TimeSpanType
14:      {
15:          get { return this.GetProperty(TimeSpanTypeProperty); }
16:          set { this.SetProperty(TimeSpanTypeProperty, value); }
17:      }
18:      protected virtual void OnTimeSpanTypeChanged(ManagedPropertyChangedEventArgs
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-6
30:
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
FromProperty = P
.Register(e => e.From);
61:      public DateTime From
62:      {
63:          get { return this.GetProperty(FromProperty); }
64:          set { this.SetProperty(FromProperty, value); }
65:      }
66:   
67:      public static readonly Property
ToProperty = P
.Register(e => e.To);
68:      public DateTime To
69:      {
70:          get { return this.GetProperty(ToProperty); }
71:          set { this.SetProperty(ToProperty, value); }
72:      }
73:  }
74:  internal class TimeSpanCriteriaConfig : EntityConfig
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 TimeSpanType
95:  {
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 : TimeSpanCriteria
3:  {
4:      public static readonly RefProperty
ChargingRefProperty =
5:          P
.RegisterRef(e => e.Charging, ReferenceType.Normal);
6:      public int ChargingId
7:      {
8:          get { return this.GetRefId(ChargingRefProperty); }
9:          set { this.SetRefId(ChargingRefProperty, value); }
10:      }
11:      public Charging Charging
12:      {
13:          get { return this.GetRefEntity(ChargingRefProperty); }
14:          set { this.SetRefEntity(ChargingRefProperty, value); }
15:      }
16:  }
17:  internal class ChargingDateCriteriaConfig : EntityConfig
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

  菜单界面,点击计费查询就可以看到上面的效果图了是不是很简单。

那我们现在想把这个条件附件到其他的模型上这么处理呢,如计费设定也想要这样的功能。

只需要从第二步改起就可以了。

转载地址:http://muaql.baihongyu.com/

你可能感兴趣的文章