vs.c#.asp.net.mvc自动代码生成器1.0发布--即将改变人类编程方式

本文介绍了vs.c#.asp.net.mvc自动代码生成器1.0,该工具能够自动生成C# MVC代码,提高程序员的效率。通过设计数据库并自动生成SQL,它能创建后端代码,但目前仅限于单个表的界面,需手工调整以满足复杂需求。未来计划升级为2.0版,支持更多语言和数据库,以进一步提升编程效率。
摘要由CSDN通过智能技术生成

自动代码生成早期收获,vs.c#.asp.net.mvc自动代码生成器1.0发布!

研究自动编程已经一段时间了,但是要把自动编程变成现实并非易事。

编程就是编写代码,写程序,最初为了加快程序编写,很多程序员学会了盲打,不看键盘输入,速度很快。不过我没有学会盲打。后来写程序不再单个字符输入,出现了智能感知,自动提示输入单词。再后来是复制粘贴,复制一段代码粘贴后再修改。复制粘贴应该是编程的最高速度了。可是复制粘贴往往忘记修改一些代码,所以有不少错误,要调试测试才能发现错误。

我在编写mvc程序的时候,很多程序员喜欢编写动作action然后让前端用ajax调用并填充表单。后来我发现,其实可以用代码输出一段javascript程序然后输送到前端页面执行。这就是自动编程的雏形吧。既然编程能输出js代码,也可以输出html,输出c#代码本身。代码能写出编译器,编译器也能编译代码,先有鸡还是先有蛋?其实先有鸡,只是这个鸡从别的方式产生,最初的编译器其实是使用别的语言造出来的,比如c语言最初编译器是从汇编产生。自动编程工具能生产出程序代码,这些程序代码也能编译成自动编程工具。

有想法就赶快行动,打造世界上第一个自动编程工具,我把它叫自动代码生成器。理论上自动生成器可以生成任何语言的代码,任意功能的程序。但是有市场需求才是开发生成器的原因,而且开发生成器需要经验,就是把你的经验和技术转化成代码生成。

自动代码生成器开发出来后我发现,对于mvc来说,后端似乎是差不多的,千变万化的是前端界面,要满足这个要求,前段界面可以定义的,比如显示标题,是否必填,是否查询,是否验证,以及显示形式,比如对于布尔值可以显示单个复选框,两个单选按钮,下拉列表选择真假。这样代码生成器必须从设计数据库开始,把设计的数据库自动生成sql然后传入数据库自动生成库表。

自动化生成器出来后代码迅速膨胀,程序员要面对的不再是写程序,而是阅读程序,调整程序。所以下一阶段开发的自动代码生成器叫2.0.输出平台是汉澳sinox

对象关系映射架构(DBFramework)及代码生成器源码 一、使用对象关系映射组件Kenly.DBFramework.dll不用编写任何SQL或者存储过程即可实现下列功能: 1、数据表、视图和存储过程与对象之间的转换。 2、数据表、视图的自定义条件查询。 3、数据表、视图的分页查询。 4、根据ID、主键或自定义条件对数据表进行增、删、改操作。 5、实现一对一、一对多、多对一和多对多的关系映射。 6、支持单个对象和多个对象之间的事务控制。 7、支持查询结果排序。 8、支持查询表达式生成。 9、支持延迟加载。 二、代码生成器 1、根据指定的数据库连接,自动生成数据表、视图和存储过程对应的对象代码(C#代码)。 2、自动生成相关的工程文件,生成完整的业务层项目文件。 3、可以帮助生成自定义查询方法。 4、支持SQLServer2000、SQLServer2005和Oracle代码生成插件,支持插件扩展。 提供 1、对象关系映射组件: Kenly.DBFramework.dll 2、代码生成器源码:CodeHelper。 3、代码生成器插件源码(支持SQLServer2000、SQLServer2005和Oracle):Plugin。 4、使用手册:DBFramework.Manual V4.5.3.pdf。 主要API: public abstract class ViewGateway where T: new() { // Methods static ViewGateway(); protected ViewGateway(); protected static int Count(); protected static int Count(string condition); protected static List CountGroup(string groupBy); protected static List CountGroup(string condition, string groupBy); public static List CreateInstances(int count); protected static List Distinct(string columnName); protected static List Distinct(string columnName, string condition); protected static List Distinct(string columnName, string condition, bool ignoreNull); protected static bool Exists(string condition); public bool ExistsById(); public bool ExistsByPK(); protected static List Find(PagingArg pagingArg, params string[] propertyNames); protected static List Find(string condition, params string[] propertyNames); protected static List Find(PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames); protected static List Find(string condition, PagingArg pagingArg, params string[] propertyNames); protected static List Find(string condition, PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames); protected static List FindAll(params string[] propertyNames); protected static void FindTop(T firstOne); protected static List FindTop(int topCount, params string[] propertyNames); protected static void FindTop(string condition, T firstOne); protected static List FindTop(string condition, int topCount, params string[] propertyNames); protected static void InitializeGateway(GatewayConfig config); protected static void InitializeGateway(DatabaseType dbType, string connectionString); protected void InitializeInstance(T entity); protected static object Max(string columnName); protected static object Max(string columnName, string condition); protected static List MaxGroup(string columnName, string groupBy); protected static List MaxGroup(string columnName, string condition, string groupBy); protected static object Min(string columnName); protected static object Min(string columnName, string condition); protected static List MinGroup(string columnName, string groupBy); protected static List MinGroup(string columnName, string condition, string groupBy); protected static DataTable Query(PagingArg pagingArg, params string[] propertyNames); protected static DataTable Query(string condition, params string[] propertyNames); protected static DataTable Query(PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames); protected static DataTable Query(string condition, PagingArg pagingArg, params string[] propertyNames); protected static DataTable Query(string condition, PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames); protected static DataTable QueryAll(params string[] propertyNames); protected static DataTable QueryTop(int topCount, params string[] propertyNames); protected static DataTable QueryTop(string condition, int topCount, params string[] propertyNames); public ArrayList RetrieveAssociations(); public ArrayList RetrieveAssociations(Type elementType); public ArrayList RetrieveAssociations(params Type[] elementTypes); public void RetrieveById(); public void RetrieveByPK(); protected internal virtual void RetrieveBySql(string sql); public void ShadowCopyTo(object targetEntity); public void ShadowCopyTo(T targetEntity); protected static double Sum(string columnName); protected static double Sum(string columnName, string condition); protected static List SumGroup(string columnName, string groupBy); protected static List SumGroup(string columnName, string condition, string groupBy); public static string ToColumnName(string propertyName); public static T ToObject(DataRow adaptedRow); public static List ToObjects(DataTable adaptedTable); public static List ToObjects(DataRow[] adaptedRows); public static string ToPropertyName(string columnName); public static DataTable ToTable(IList entities); public static DataTable ToTable(params T[] entities); public static DataTable ToTable(bool isAdapted, params T[] entities); public static DataTable ToTable(bool isAdapted, IList entities); // Properties protected internal static string CommandText { get; } protected internal static GatewayConfig Config { get; } internal T Entity { get; set; } public object EntityId { get; } public object PrimaryKey { get; } protected static Order SortedOrder { get; set; } } public abstract class TableGateway : ViewGateway where T: TableGateway, new() { // Methods static TableGateway(); protected TableGateway(); public int AddNew(); public static int AddNew(IList entities); public static int AddNew(T entity); public int AddNew(bool returnIdentity); public static int AddNew(T entity, bool returnIdentity); public static int AddNew(IList entities, out Transaction transaction); public static int AddNew(IList entities, bool returnIdentity); public static int AddNew(T entity, out Transaction transaction); public static int AddNew(IList entities, bool returnIdentity, out Transaction transaction); public static int AddNew(T entity, bool returnIdentity, out Transaction transaction); public IDbTransaction BeginTransaction(); public IDbTransaction BeginTransaction(IsolationLevel isolationLevel); public IDbTransaction BeginTransaction(double activeTime); public IDbTransaction BeginTransaction(IsolationLevel isolationLevel, double activeTime); public bool Commit(); protected static int Delete(string condition); protected static int Delete(string condition, out Transaction transaction); public int DeleteById(); public static int DeleteById(T entity); public static int DeleteById(IList entities); public static int DeleteById(IList entities, out Transaction transaction); public static int DeleteById(T entity, out Transaction transaction); public int DeleteByPK(); public static int DeleteByPK(T entity); public static int DeleteByPK(IList entities); public static int DeleteByPK(IList entities, out Transaction transaction); public static int DeleteByPK(T entity, out Transaction transaction); protected void OnPropertyChanged(MethodBase propertyMethod); protected void OnPropertyChanged(string propertyName); protected internal override void RetrieveBySql(string sql); public bool Rollback(); protected static int Update(T entity, string condition); protected static int Update(T entity, string condition, out Transaction transaction); public int UpdateById(); public static int UpdateById(IList entities); public static int UpdateById(T entity); public static int UpdateById(T entity, out Transaction transaction); public static int UpdateById(IList entities, out Transaction transaction); public int UpdateByPK(); public static int UpdateByPK(IList entities); public static int UpdateByPK(T entity); public static int UpdateByPK(IList entities, out Transaction transaction); public static int UpdateByPK(T entity, out Transaction transaction); // Properties public bool Changed { get; } public List ChangedPropertyNames { get; } } public class StoredProcedure : IStoredProcedure { public bool BeginTransaction(); public void CloseReader(IDataReader reader); public bool Commit(); public DataSet ExecuteDataSet(); public DataTable ExecuteDataTable(); public DataTable ExecuteDataTable(); public List ExecuteEntity(); public int ExecuteNonQuery(); public IDataReader ExecuteReader(); public object ExecuteScalar(); protected static void InitializeGateway(GatewayConfig config); protected static void InitializeGateway(DatabaseType dbType, string connectionString); protected void InitializeInstance(T entity); public bool Rollback(); } public class AggregateEntity where T: AggregateEntity, new() { public static List Execute(); protected static List Execute(string condition); public static DataTable ExecuteDataTable(); protected static DataTable ExecuteDataTable(string condition); protected static void InitializeGateway(GatewayConfig config); protected static void InitializeGateway(DatabaseType dbType, string connectionString); // Properties protected static Order SortedOrder { get; set; } } public static class EntityMapper { // Methods public static void AdaptToDatabase(DataTable adaptedTable); public static void AdaptToEntity(DataTable rawTable); public static void CopyToEntities(IList entities, IList adaptedRows); public static void CopyToEntities(IList entities, DataTable adaptedTable); public static void CopyToEntity(T entity, DataRow row); public static List CreateEntities(int count); public static DataTable CreateTable(); public static DataTable CreateTable(bool isAdapted); public static string ToColumnName(string propertyName); public static List ToEntities(IList adaptedRows); public static List ToEntities(DataTable table); public static T ToEntity(DataRow adaptedRow); public static string ToPropertyName(string columnName); public static DataTable ToTable(IList entities); public static DataTable ToTable(params T[] entities); public static DataTable ToTable(bool isAdapted, params T[] entities); public static DataTable ToTable(bool isAdapted, IList entities); } public static class EntityUtility { // Methods public static List Inherit(IList entities); public static T Inherit(object entity); public static T Inherit(Tbase baseEntity, TransformAction method); public static List Inherit(IList baseEntities, TransformAction method); public static void ShadowCopy(IList targetEntities, IList sourceEntities); public static void ShadowCopy(object targetEntity, object sourceEntity); }
【基本说明】 1、能够生成三层工厂模式操作的所有基本代码,简单的数据库操作。 2、生成的代码包括了 MODEL、BLL、Factory、IDAL、DAL、DBHelper、Config 生成的代码内有详细注释可提供参考。 3、提供数据库增、删、改、查、分页及其事务,并提供多种重载方式。 4、所有数据表必须有主键且主键是第一列,这个主要是为了保证获取记录和分页获取的统一性,其实可以取消这个规则。 6、建议新建App_Code文件夹将生成的C#代码放里面。见此文件夹直接拷贝到项目下既可以使用。 7、不保证所提供软件或程序的完整性和安全性。 8、请在使用前查毒 (这也是您使用其它网络资源所必须注意的) 。 9、《Coder(ASP.NET代码生成器)》需要.Net FrameWork2.0运行环境,基于SQL Server 2005使用。 10、如无法运行本软件,请下载并安装由微软公司提供的.Net FrameWork2.0系统. 11、如果您在使用过程中遇到程序问题或建议请于我联系我的Email是 mailto:liliang119007@163.com。 【生成单层代码】 输入数据库名(Server)登录名(Name)密码(Pwd),连接后选择库名(Database)表名(Tables) 之后单击'生成单层代码'新建App_Code文件夹将生成的C#代码(ASP.NET后台代码)放里面, 【生成三层工厂模式项目】 (1)B/S架构: 输入数据库名(Server)登录名(Name)密码(Pwd)连接数据库成功后直接点生成整个项目选择路径确定就好了。 (2)C/S架构: 输入数据库名(Server)登录名(Name)密码(Pwd)连接数据库成功后直接点生成整个项目选择路径确定, 生成项目后打开该项目解决方案将表示层删掉, 再单击vs的(文件→添加→新建项目→选择Windows应用程序),这样就生成C/S架构的程序了!
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值