3.1EM实体模型参数
private string _EMNameSpace = "EM";
[Category("2EM实体模型"), DisplayName("2.1EM命名空间"), DefaultValue("EM"),
Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string EMNameSpace { get { return _EMNameSpace; } set { _EMNameSpace = value; } }
private string _EMClass = "EM";
[Category("2EM实体模型"), DisplayName("2.2EM类名后缀"), DefaultValue("EM")]
public string EMClass { get { return _EMClass; } set { _EMClass = value; } }
private string _EMFolder = "EM";
[Category("2EM实体模型"), DisplayName("2.3EM文件夹名"), Description("EM代码保存到磁盘上的文件名")]
[DefaultValue("EM")]
public string EMFolder { get { return _EMFolder; } set { _EMFolder = value; } }
private bool _EMGenerator = true;
[Category("2EM实体模型"), DisplayName("2.4生成EM代码"), DefaultValue(true)]
public bool EMGenerator { get { return _EMGenerator; } set { _EMGenerator = value; } }
3.1.1EM命名空间
设置生成EM实体的命名空间。
3.1.2EM类后缀名
设置EM实体模型类名后缀,EM实体模型的默认类名为表名+后缀名,其中表名首字母大写,没有下画线,比如表名为:SYS_USER;类名为SysUserEM。
3.1.3EM文件夹名
设置生成的EM代码保存的子文件夹名。
3.1.4生成EM代码
设置是否生成EM代码
3.2BLL业务逻辑层参数
private string _BLLNameSpace = "BLL";
[Category("3BLL业务逻辑层"), DisplayName("3.1BLL命名空间"),DefaultValue("BLL"),
Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string BLLNameSpace { get { return _BLLNameSpace; } set { _BLLNameSpace = value; } }
private string _BLLClass = "BLL";
[Category("3BLL业务逻辑层"), DisplayName("3.2BLL类名后缀"), DefaultValue("BLL")]
public string BLLClass { get { return _BLLClass; } set { _BLLClass = value; } }
private string _BLLFolder = "BLL";
[Category("3BLL业务逻辑层"), DisplayName("3.3BLL文件夹名"), Description("BLL代码保存到磁盘上的文件名")]
[DefaultValue("BLL")]
public string BLLFolder { get { return _BLLFolder; } set { _BLLFolder = value; } }
private bool _BLLGenerator = false;
[Category("3BLL业务逻辑层"), DisplayName("3.4生成BLL代码"), DefaultValue(false)]
public bool BLLGenerator { get { return _BLLGenerator; } set { _BLLGenerator = value; } }
相关描述类似EM实体类。
3.3DAL数据访问层
private string _DALNameSpace = "DAL";
[Category("4DAL数据访问层"), DisplayName("4.1DAL命名空间"), DefaultValue("DAL"),
Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string DALNameSpace { get { return _DALNameSpace; } set { _DALNameSpace = value; } }
private string _DALClass = "DAL";
[Category("4DAL数据访问层"), DisplayName("4.2DAL类名后缀"), DefaultValue("DAL"),]
public string DALClass { get { return _DALClass; } set { _DALClass = value; } }
private string _DALFolder = "DAL";
[Category("4DAL数据访问层"), DisplayName("4.3DAL文件夹名"), Description("DAL代码保存到磁盘上的文件名")]
[DefaultValue("DAL"),]
public string DALFolder { get { return _DALFolder; } set { _DALFolder = value; } }
private bool _DALGenerator = false;
[Category("4DAL数据访问层"), DisplayName("4.4生成DAL代码"), DefaultValue(false),]
public bool DALGenerator { get { return _DALGenerator; } set { _DALGenerator = value; } }
相关描述类似EM实体类。
3.4其他参数
[Category("5其他设置"), DisplayName("5.1代码只读"), DefaultValue(false)]
public bool ReadOnly { get; set; }
设置为True则右边显示的代码为只读。设置为False则右边的代码可以修改。
3.5 代码生成器完整参数类
using System.ComponentModel;
using System.Drawing.Design;
using System;
using System.Windows.Forms.Design;
using System.Data;
using System.Windows.Forms;
namespace BLMaCodeGenerator
{
///
/// 代码生成器参数实体类
///
//[DefaultProperty("TableName")] //默认属性,不写就是第一个
[Serializable] //可序列化
public class CodeParam
{
/*特性说明
* Category() 分组
* DisplayName() 显示名
* Description() 说明
* DefaultValue() 不加粗显示的值
* Editor() 自定义编辑器
* Browsable() 是否显示
* ReadOnly() 只读
*/
private string _ConnStr = "Data Source=CQYH; User ID=nmis; password=nmis";
[Category("1数据库设置"), DisplayName("1.1连接Oracle字符串")]
[Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string ConnStr { get { return _ConnStr; } set { _ConnStr = value;}}
[Category("1数据库设置"), DisplayName("1.2表名集合"), Description("多个表名用逗号,分隔")]
[Editor(typeof(TextTableEditor), typeof(UITypeEditor))]
public TextDataTable textDataTable { get; set; }
private bool _ExistsTable = true;
[Category("1数据库设置"), DisplayName("1.3检测表是否存在"),DefaultValue(true)]
public bool ExistsTable { get { return _ExistsTable; } set { _ExistsTable = value; } }
private string _OracleDML = "OracleDML";
[Category("1数据库设置"), DisplayName("1.4OracleHelper类"), Description("Oracle数据操作封装类")]
[DefaultValue("OracleDML")]
public string OracleDML { get { return _OracleDML; } set { _OracleDML = value; } }
private string _EMNameSpace = "EM";
[Category("2EM实体模型"), DisplayName("2.1EM命名空间"), DefaultValue("EM"),
Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string EMNameSpace { get { return _EMNameSpace; } set { _EMNameSpace = value; } }
private string _EMClass = "EM";
[Category("2EM实体模型"), DisplayName("2.2EM类名后缀"), DefaultValue("EM")]
public string EMClass { get { return _EMClass; } set { _EMClass = value; } }
private string _EMFolder = "EM";
[Category("2EM实体模型"), DisplayName("2.3EM文件夹名"), Description("EM代码保存到磁盘上的文件名")]
[DefaultValue("EM")]
public string EMFolder { get { return _EMFolder; } set { _EMFolder = value; } }
private bool _EMGenerator = true;
[Category("2EM实体模型"), DisplayName("2.4生成EM代码"), DefaultValue(true)]
public bool EMGenerator { get { return _EMGenerator; } set { _EMGenerator = value; } }
private string _BLLNameSpace = "BLL";
[Category("3BLL业务逻辑层"), DisplayName("3.1BLL命名空间"),DefaultValue("BLL"),
Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string BLLNameSpace { get { return _BLLNameSpace; } set { _BLLNameSpace = value; } }
private string _BLLClass = "BLL";
[Category("3BLL业务逻辑层"), DisplayName("3.2BLL类名后缀"), DefaultValue("BLL")]
public string BLLClass { get { return _BLLClass; } set { _BLLClass = value; } }
private string _BLLFolder = "BLL";
[Category("3BLL业务逻辑层"), DisplayName("3.3BLL文件夹名"), Description("BLL代码保存到磁盘上的文件名")]
[DefaultValue("BLL")]
public string BLLFolder { get { return _BLLFolder; } set { _BLLFolder = value; } }
private bool _BLLGenerator = false;
[Category("3BLL业务逻辑层"), DisplayName("3.4生成BLL代码"), DefaultValue(false)]
public bool BLLGenerator { get { return _BLLGenerator; } set { _BLLGenerator = value; } }
private string _DALNameSpace = "DAL";
[Category("4DAL数据访问层"), DisplayName("4.1DAL命名空间"), DefaultValue("DAL"),
Editor(typeof(RichTextBoxEditor), typeof(UITypeEditor))]
public string DALNameSpace { get { return _DALNameSpace; } set { _DALNameSpace = value; } }
private string _DALClass = "DAL";
[Category("4DAL数据访问层"), DisplayName("4.2DAL类名后缀"), DefaultValue("DAL"),]
public string DALClass { get { return _DALClass; } set { _DALClass = value; } }
private string _DALFolder = "DAL";
[Category("4DAL数据访问层"), DisplayName("4.3DAL文件夹名"), Description("DAL代码保存到磁盘上的文件名")]
[DefaultValue("DAL"),]
public string DALFolder { get { return _DALFolder; } set { _DALFolder = value; } }
private bool _DALGenerator = false;
[Category("4DAL数据访问层"), DisplayName("4.4生成DAL代码"), DefaultValue(false),]
public bool DALGenerator { get { return _DALGenerator; } set { _DALGenerator = value; } }
[Category("5其他设置"), DisplayName("5.1代码只读"), DefaultValue(false)]
public bool ReadOnly { get; set; }
}
///
/// 自定义表名编辑类
///
public class TextDataTable
{
DataTable _dTable = null;
public DataTable dataTable { get { return _dTable; } set { _dTable = value; } }
string _tableName = "Dual";
public string tableName { get { return _tableName; } set { _tableName = value;} }
public override string ToString()
{
return tableName;
}
}
}
其中TextDataTable为表名选择用到的类
DialogFormEditor为PropertyGrid自定义弹窗编辑器。
RichTextBoxEditor为PropertyGrid自定义RichTextBox编辑器。
TextTableEditor为PropertyGrid自定义的表名选择编辑器
4-BLMa白龙马C#代码生成器-核心要点
5-BLMa白龙马C#代码生成器-代码示例