tnblog
首页
视频
资源
登录

XAF生成MarkDown

6094人阅读 2020/11/27 15:57 总访问:436987 评论:6 收藏:0 手机
分类: ASP.NET
  1. using DevExpress.ExpressApp.DC;
  2. using DevExpress.ExpressApp.Model;
  3. using DevExpress.Persistent.Validation;
  4. using JGSoft.MES.Module.Extension.BaseBO;
  5. using JGSoft.MES.Module.Utils;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. namespace JGSoft.MES.Module.AttributeExtend
  12. {
  13.     public class ModelAttribute
  14.     {
  15.         public static void GetAttribute()
  16.         {
  17.             Dictionary<String, String> titlelist = new Dictionary<String, String>();
  18.             #region 获取bo实体属性
  19.             if (CommonTools.application != null)
  20.             {
  21.                 var list = CommonTools.application.Model.BOModel.ToList();
  22.                 //添加md数据正文
  23.                 StringBuilder content = new StringBuilder();
  24.                 //菜单
  25.                 StringBuilder Header = new StringBuilder();
  26.                 //bo实体属性信息
  27.                 StringBuilder textcontent = new StringBuilder();
  28.                 foreach (IModelClass modelclass in list)
  29.                 {
  30.                     var typeinfo = modelclass.TypeInfo;
  31.                     bool issubclasssingle = typeinfo.Type.IsSubclassOf(typeof(SingleObject));
  32.                     //跳过不继承的类
  33.                     if (!issubclasssingle)
  34.                     {
  35.                         continue;
  36.                     }
  37.                     int count = 1;
  38.                     foreach (IMemberInfo minfo in typeinfo.Members)
  39.                     {
  40.                         //自定义的公共属性 并有displayname的字段
  41.                         if (minfo.IsPublic && minfo.IsProperty && minfo.FindAttribute<XafDisplayNameAttribute>() != null)
  42.                         {
  43.                             XafDisplayNameAttribute displays = minfo.Owner.FindAttribute<XafDisplayNameAttribute>();
  44.                             if (!titlelist.ContainsKey(minfo.Owner.Name))
  45.                             {
  46.                                 if (!string.IsNullOrEmpty(displays?.DisplayName))
  47.                                 {
  48.                                     //标题
  49.                                     content.Append("##" + minfo.Owner.Name + "(" + displays?.DisplayName + ")");
  50.                                     //菜单
  51.                                     Header.Append("| 序号 <div style=\"width:25pt\"> | 字段 | 字段名称 <div style=\"width:75pt\"> | 主键 | 外键 | 数据类型 | 是否只读 <div style=\"width:50pt\"> | 长度 <div style=\"width:30pt\"> | 是否必填 <div style=\"width:50pt\"> |");
  52.                                     titlelist.Add(minfo.Owner.Name, displays?.DisplayName);
  53.                                 }
  54.                                 else
  55.                                 {
  56.                                     if (!string.IsNullOrEmpty(displays?.DisplayName))
  57.                                     {
  58.                                         //标题
  59.                                         content.Append("##" + minfo.Owner.Name + "");
  60.                                         //菜单
  61.                                         Header.Append("| 序号 <div style=\"width:25pt\"> | 字段 | 字段名称 <div style=\"width:75pt\"> | 主键 | 外键 | 数据类型 | 是否只读 <div style=\"width:50pt\"> | 长度 <div style=\"width:30pt\"> | 是否必填 <div style=\"width:50pt\"> |");
  62.                                         titlelist.Add(minfo.Owner.Name, displays?.DisplayName);
  63.                                     }
  64.                                 }
  65.                             }
  66.                             var display = minfo.FindAttribute<XafDisplayNameAttribute>();
  67.                             var require = minfo.FindAttribute<RuleRequiredFieldAttribute>();
  68.                             bool required = require != null;
  69.                             if (!string.IsNullOrEmpty(minfo.Owner.Name) && !string.IsNullOrEmpty(displays?.DisplayName))
  70.                             {
  71.                                 textcontent.Append("\n");
  72.                                 //序号
  73.                                 textcontent.Append("| " + count + " |");
  74.                                 //字段
  75.                                 textcontent.Append(" " + minfo.Name + " |");
  76.                                 //字段名称
  77.                                 textcontent.Append(" " + display?.DisplayName + " |");
  78.                                 //主键
  79.                                 textcontent.Append(" " + minfo.IsKey + " |");
  80.                                 //外键
  81.                                 if (minfo.MemberType.FullName.Contains("JGSoft.MES.Module"))
  82.                                 {
  83.                                     textcontent.Append(" True |");
  84.                                 }
  85.                                 else
  86.                                 {
  87.                                     textcontent.Append(" False |");
  88.                                 }
  89.                                 //数据类型
  90.                                 if (minfo.MemberType.FullName.Contains("System.DateTime"))
  91.                                 {
  92.                                     textcontent.Append(" System.DateTime |");
  93.                                 }
  94.                                 else
  95.                                 {
  96.                                     textcontent.Append(" " + minfo.MemberType.FullName + " |");
  97.                                 }
  98.                                 //是否只读
  99.                                 textcontent.Append(" " + minfo.IsReadOnly + " |");
  100.                                 //长度
  101.                                 textcontent.Append(" " + minfo.Size + " |");
  102.                                 //是否必填
  103.                                 textcontent.Append(" " + required + " |");
  104.                             }
  105.                             count++;
  106.                         }
  107.                     }
  108.                     if (!string.IsNullOrEmpty(Header.ToString()) && !string.IsNullOrEmpty(textcontent.ToString()))
  109.                     {
  110.                         content.Append("\n");
  111.                         content.Append(Header);
  112.                         content.Append("\n");
  113.                         content.Append("|--------|--------|--------|--------|--------|--------|--------|--------|--------|");
  114.                         content.Append(textcontent);
  115.                         content.Append("\n");
  116.                         Header.Length = 0;
  117.                         textcontent.Length = 0;
  118.                     }
  119.                 }
  120.                 string filepath = AppDomain.CurrentDomain.BaseDirectory + "ModelAttributeinfo";
  121.                 //如果不存在就创建file文件夹
  122.                 if (Directory.Exists(filepath) == false)
  123.                 {
  124.                     Directory.CreateDirectory(filepath);
  125.                 }
  126.                 string path = filepath + "\\bo实体属性信息.md";
  127.                 FileStream file = null;
  128.                 //创建写入流文件存在则清空文件
  129.                 if (File.Exists(path))
  130.                 {
  131.                     file = new FileStream(path, FileMode.Truncate, FileAccess.Write);
  132.                 }
  133.                 else
  134.                 {
  135.                     //不存在则创建
  136.                     file = new FileStream(path, FileMode.Create, FileAccess.Write);
  137.                 }
  138.                 //写入信息
  139.                 byte[] writeBytes = Encoding.UTF8.GetBytes(content.ToString());
  140.                 //写入文件流
  141.                 file.Write(writeBytes, 0, writeBytes.Length);
  142.                 //关闭
  143.                 file.Close();
  144.             }
  145.             #endregion
  146.         }
  147.     }
  148. }


评价

剑轩

2020/11/27 17:36:06

牛皮,给个示例用法就更牛皮了[威武][给力]

幽梦紫曦:@剑轩示例用法想要那种的

2020/11/30 9:16:47 回复

剑轩:@幽梦紫曦就是来一个具体的demo呢

2020/11/30 11:40:24 回复

幽梦紫曦:@剑轩哈哈哈哈,诶呀傲总你就直接说你想要那一模块的

2020/11/30 13:40:52 回复

剑轩:@幽梦紫曦我也母鸡哇

2020/11/30 19:59:52 回复

幽梦紫曦:@剑轩不不不不这个你可以知道

2020/12/1 9:12:29 回复

XAF创建实体属性快速开发

在BusinessObjects文件里面创建XAF类在bo里面写入自定义实体private string _name; public string name { get {...

XAF配置多文件上传

在bo文件创建两个类主要配置主从关系默认继承BaseObject将其修改为FileAttachmentBase[DefaultClassOptions] public class...

XAF登录权限配置

点击角色然后用张三进行登录没有密码可以看到刚刚设置的菜单可以通过该用户打开

XAF特性属性使用方法

1.[XafDisplayName(&quot;名称&quot;)] (1)在类上面表示修改左侧菜单的名称 (2)在字段属性上使用表示修改字段名称 2.[Im...

XAF配置主从关系

1.建立主表可读可写属性并使用Association特性进行关联 [Association(&quot;采购订单明细&quot;)] [XafDisplayName(&quot...

XAF加载Action按钮

1.VC的生命周期分别对应一个重写方法 (1)界面激活 protectedoverridevoidOnActivated() { base.OnActivated(); } (2)...

XAF下拉框获取点击项

找到属性双击Execute点击事件在Execute事件里面获取数据

XAF获取PopupWindowShowAction弹窗窗体的字段数据

在Execute点击事件里面获取数据获取窗体视图数据DetailView view= e.PopupWindowView as DetailView;将窗体视图数据转换为...

XAF弹窗按钮弹出自定义窗体

加载CustomizePopupWindowParams事件并创建窗体弹出private void popupWindowShowAction1_CustomizePopupWindowParams(obje...

XAF定义主键XPBaseObject和BaseObject

BaseObject默认主键为oidXPBaseObject可自定义主键

XAF语法使用

1.创建视图对象 IObjectSpaceresponseios=Application.CreateObjectSpace(); 2.查询(返回包含条件的所有数据) Userinfou...

XAF在VC使用释放资源机制

publicinterfaceIProgressControl:IDisposable { voidShowProgress(BackgroundWorkerworker); }

XAF在DashboardView右下方添加SimpleAction

首先在VC里面添加自定义的按钮加载点击事件在自定义的按钮属性里面设置TargetViewId继承DashboardView在设计器里面添加加载...

XAF条件查询

IObjectSpaceios=Application.CreateObjectSpace(); GroupOperatorgroup=newGroupOperator(); CriteriaOperatorcriteria=...

不重复订单号生成的方法

第一种 GUID 由算法自动生成下 理论上能产生全球唯一的值 不过对于用户记订单号不方便Console.WriteLine(System.Guid.Ne...
当你知道迷惑时,并不可怜,当你不知道迷惑时,才是最可怜的。
排名
11
文章
201
粉丝
10
评论
13
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
情到深处人孤独。