• OEA体验 :常用功能1


    一、摘要

           我下面写的是我在使用OEA中用到的功能,当然还有好多现在还没有用到,希望高手们多多指点指点。

    OEA 源码:OEA框架 2.9 Pre-Alpha 源码公布可以到BloodyAngel 的博客中可以下到。

    二、本文大纲

           a、摘要。

           b、数据过滤。

           c、托管属性。

           d、支持树型实体 。

    二、数据过滤

    数据查询是一个在平常不过的事,我们来看看OEA是怎么帮我们实现的。下面用一个简单的例子来说明,如我们要实现根据客户名称来查询,效果图如下:

    image

    要达到上面效果实现代码如下:

    前台调用如下:

     1:  internal class ClientinfoConfig : EntityConfig<Clientinfo>
     2:  {
     3:      protected override void ConfigMeta()
     4:      {
     5:          base.ConfigMeta();
     6:      }
     7:      protected override void ConfigView()
     8:      {
     9:          base.ConfigView();
    10:          View.UseWPFCommands("CLCS.WPF.ClientinfoSearchCommand");
    11:      }
    12:  }
    13:   

    具体代码如下:

     1:  using OEA.WPF.Command;
     2:  using OEA.MetaModel.Attributes;
     3:  using OEA.Module.WPF;
     4:  using OEA.Module.WPF.CommandAutoUI;
     5:  using OEA.MetaModel.View;
     6:   
     7:  namespace CLCS.WPF
     8:  {
     9:      [Command(Label = "过滤客户名称", UIAlgorithm = typeof(GenericItemAlgorithm<TextBoxButtonItemGenerator>))]
    10:      public class ClientinfoSearchCommand : ListViewCommand
    11:  {
    12:          public override void Execute(ListObjectView view)
    13:          {
    14:              var txt = this.TryGetCustomParams<string>(CommandCustomParams.TextBox);
                     // 设置查询条件
    15:              view.Filter = e => (e as Clientinfo).CcName.Contains(txt);
    16:          }
    17:      }
    18:  }
    19:   
    20:   
    21:   
    二、托管属性(代码生成 OEAPropertyReference )

    数据关联也是一个很平常的了,向下面的以前要写好多代码现在还不到10行就可以了。

    image

    在这需要用 小区表,和客户表  两个表

    DemoEntity 类可以在OEA体验 :元数据编写中找到

    下面的代码可以使用OEAPropertyReference 来生成

     1:  ///<summary>
     2:  ///描è述? : 客í户§信?息¢.
     3:  ///<see>类à库a对?应|的?数y据Y库a表í NT_Clcs_ClientInfo </see>
     4:  ///</summary>
     5:  [Serializable]
     6:  [RootEntity]
     7:  public class Clientinfo : DemoEntity
     8:  {
     9:      protected Clientinfo() { }
    10:      public static readonly RefProperty<Village> VillageRefProperty =
    11:          P<Clientinfo>.RegisterRef(e => e.Village, ReferenceType.Normal);
    12:      public int VillageId
    13:      {
    14:          get { return this.GetRefId(VillageRefProperty); }
    15:          set { this.SetRefId(VillageRefProperty, value); }
    16:      }
    17:      public Village Village
    18:      {
    19:          get { return this.GetRefEntity(VillageRefProperty); }
    20:          set { this.SetRefEntity(VillageRefProperty, value); }
    21:      }
    22:      #endregion
    23:  }
    24:   

    下面的是小区表的配置类

     1:  internal class VillageConfig : EntityConfig<Village>
     2:     {
     3:         protected override void ConfigMeta()
     4:         {
     5:             base.ConfigMeta();
     6:   
     7:             Meta.MapTable().HasColumns(
     8:             Village.ParentidProperty,
     9:             Village.CvNameProperty,
    10:             Village.CvPinyiProperty,
    11:             Village.CvTypeProperty,
    12:             Village.CvHeatingplantProperty,
    13:             Village.CvHscuProperty,
    14:             Village.BustypeProperty,
    15:             Village.ClientcountProperty
    16:                 );
    17:   
    18:         }
    19:         protected override void ConfigView()
    20:         {
    21:             base.ConfigView();
    22:   
    23:             View.HasTitle(Village.CvNameProperty).HasLabel("小?区?名?称?");
    24:             View.Property(Village.CvNameProperty).HasLabel("小?区?名?称?").ShowIn(ShowInWhere.List | ShowInWhere.Lookup);
    25:    }

    自动生成数据库关联关系

    image

    三、支持树型实体(代码生成 OEATreeEntity )

           向小区下面还有楼栋和单元,我们看OEA如何实现

    image

    生成的代码如下:

     1:  #region 支§持?树÷型í实μ体?
     2:   
     3:          public static readonly Property<string> TreeCodeProperty = P<Village>.Register(e => e.TreeCode);
     4:          [Column]
     5:          public override string TreeCode
     6:          {
     7:              get { return GetProperty(TreeCodeProperty); }
     8:              set { SetProperty(TreeCodeProperty, value); }
     9:          }
    10:   
    11:          public static readonly Property<int?> TreePIdProperty = P<Village>.Register(e => e.TreePId);
    12:          [Column]
    13:          public override int? TreePId
    14:          {
    15:              get { return this.GetProperty(TreePIdProperty); }
    16:              set { this.SetProperty(TreePIdProperty, value); }
    17:          }
    18:   
    19:          public override bool SupportTree { get { return true; } }
    20:   
    21:          #endregion
    22:  

    自动生成数据库关联关系

    image

    是不是很简单

    作者:罗敏贵
    邮箱:minguiluo@gmail.com
    QQ群:34178394 建群 主要是寻找志同道合的人士一起学习和讨论自己的所学所思
    出处:http://luomingui.cnblogs.com/
    说明:专注于微软平台项目架构、熟悉设计模式、架构设计、敏捷个人和项目管理。现主要从事WinForm、ASP.NET、等方面的项目开发、架构、管理工作。文章为作者平时里的思考和练习,可能有不当之处,请博客园的园友们多提宝贵意见。
    知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

  • 相关阅读:
    sqlserver判断是否为数字的函数
    vs2013 旗舰版 密钥
    HttpWebRequest类与HttpRequest类的区别
    C#中HttpWebRequest的用法详解
    SQL Server查询优化方法(查询速度慢的原因很多,常见如下几种)
    随机数Random
    PadLeft 补零
    delphi Firemonkey ListBoxItem自绘
    windows自带杀毒防火墙
    IIS 更新EXE文件
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2438249.html
Copyright © 2020-2023  润新知