zoukankan      html  css  js  c++  java
  • OEA体验:查询面板

    一、摘要

           在这里主要是写OEA设计方面的知识了。OEA 源码:OEA框架 2.9 Pre-Alpha 源码公布

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

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

    二、本文大纲

           a、摘要 。

           b、远景 。

           c、项目结构 。

           d、OEA实现方法  。

    三、远景

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

    image

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

    四、项目结构

           image

    用到的主要的类 如下:

    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<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 TimeSpanType
     14:      {
     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-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<DateTime> FromProperty = P<TimeSpanCriteria>.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<DateTime> ToProperty = P<TimeSpanCriteria>.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<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 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<Charging> ChargingRefProperty =
     5:          P<ChargingDateCriteria>.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<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:   

    第三步查询面板关联那个模型

    image 

    第四步显示在菜单上MyLibrary.CS

    image

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

    image

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

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

  • 相关阅读:
    树链剖分总结
    主席树总结
    BZOJ1053:反素数(数学)
    CH3101 阶乘分解
    2018-2019 ACM-ICPC ECfinal I. Misunderstood … Missing
    洛谷P3201 [HNOI2009]梦幻布丁(链表 + 启发式合并)
    Codeforces Round #552 (Div. 3) 题解
    线段树合并 总结
    生成器
    Python中input()和raw_input()的区别
  • 原文地址:https://www.cnblogs.com/luomingui/p/2471740.html
Copyright © 2011-2022 走看看