abp(net core)+easyui+efcore实现仓储管理系统——abp总体介绍(一)
abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二)
abp(net core)+easyui+efcore实现仓储管理系统——领域层创建实体(三)
abp(net core)+easyui+efcore实现仓储管理系统——定义仓储并实现 (四)
abp(net core)+easyui+efcore实现仓储管理系统——创建应用服务(五)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之控制器(六)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之列表视图(七)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之增删改视图(八)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之菜单与测试(九)
abp(net core)+easyui+efcore实现仓储管理系统——多语言(十)
abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十一)
abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十二)
abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十三)
abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十四)
abp(net core)+easyui+efcore实现仓储管理系统——使用 webapi实现curd (十五)
abp(net core)+easyui+efcore实现仓储管理系统——菜单-上 (十六)
abp(net core)+easyui+efcore实现仓储管理系统——菜单-下(十七)
通过上一篇(abp(net core)+easyui+efcore实现仓储管理系统——easyui前端页面框架 (十八) )文章,我们已经将easyui添加到我们的项目中了。下面我们通过easyui做为前端页面的ui控件来展现一个货物信息管理的前端功能,并使用创建相应的实体类,服务类等来实现后台功能。
四、创建cargo实体
1. 在visual studio 2017的“解决方案资源管理器”中,右键单击“abp.tplms.core”项目的“entitys”文件夹,在弹出菜单中选择“添加” >
> “类”。 将类命名为 cargo,然后选择“添加”。
2.创建cargo类继承自entity<int>,通过实现审计模块中的ihascreationtime来实现保存创建时间。代码如下:
using abp.domain.entities; using abp.domain.entities.auditing; using system; using system.collections.generic; using system.componentmodel.dataannotations; using system.componentmodel.dataannotations.schema; using system.text; namespace abp.tplms.entitys { public class cargo : entity<int>, ihascreationtime { public cargo() { this.id = 0; this.supplierid = 0; this.cargocode = string.empty; this.cargoname = string.empty; this.brand = string.empty; this.country = string.empty; this.creationtime = datetime.now; this.curr = string.empty; this.grosswt = 0; this.height = 0; this.hscode = string.empty; this.length = 0; this.maxnum = 100; this.minnum = 0; this.netwt = 0; this.package = string.empty; this.price = 0; this.remark = string.empty; this.spcf = string.empty; this.unit = string.empty; this.updatetime = datetime.now; this.updoper = string.empty; this.vol = 0; this.width = 0; } public int supplierid { get; set; } [stringlength(50)] public string cargocode { get; set; } [stringlength(10)] public string hscode { get; set; } [stringlength(250)] public string cargoname { get; set; } [stringlength(512)] public string spcf { get; set; } public string unit { get; set; } public string country { get; set; } public string brand { get; set; } public string curr { get; set; } public string package { get; set; } public decimal length { get; set; } public decimal width { get; set; } public decimal height { get; set; } public decimal vol { get; set; } public decimal minnum { get; set; } public decimal maxnum { get; set; } public decimal price { get; set; } public decimal grosswt { get; set; } public decimal netwt { get; set; } public string remark { get; set; } public datetime creationtime { get; set; } public datetime updatetime { get; set; } public string updoper { get; set; } } }
3.定义好实体之后,我们去“abp.tplms.entityframeworkcore”项目中的“tplmsdbcontext”类中定义实体对应的dbset,以应用code first 数据迁移。添加以下代码
using microsoft.entityframeworkcore; using abp.zero.entityframeworkcore; using abp.tplms.authorization.roles; using abp.tplms.authorization.users; using abp.tplms.multitenancy; using abp.tplms.entitys; namespace abp.tplms.entityframeworkcore { public class tplmsdbcontext : abpzerodbcontext<tenant, role, user, tplmsdbcontext> { /* define a dbset for each entity of the application */ public tplmsdbcontext(dbcontextoptions<tplmsdbcontext> options) : base(options) { } public dbset<module> modules { get; set; } public dbset<supplier> suppliers { get; set; } public dbset<cargo> cargos { get; set; } } }
4.从菜单中选择“工具->nuget包管理器器—>程序包管理器控制台”菜单。
5. 在pmc中,默认项目选择entityframeworkcore对应的项目后。输入以下命令:add-migration addentitycargo,创建迁移。
6. 在上面的命令执行完毕之后,创建成功后,会在migrations文件夹下创建时间_addentitycargo格式的类文件,这些代码是基于dbcontext指定的模型。如下图。
7.在程序包管理器控制台,输入update-database,回车执行迁移。执行成功后,如下图。
8. 在sql server management studio中查看数据库,cargos表创建成功。
五、定义应用服务接口需要用到的分页类
为了在进行查询时使用, pagedcargoresultrequestdto被用来将货物查询条件的数据传递到给应用层.
1. 在visual studio 2017的“解决方案资源管理器”中,右键单击“abp.tplms.application”项目,在弹出菜单中选择“添加” > “新建文件夹”,并重命名为“cargos”
2. 使用鼠标右键单击我们刚才创建的“cargos”文件夹,在弹出菜单中选择“添加” > “新建文件夹”,并重命名为“dto”。
3.右键单击“dto”文件夹,然后选择“添加” > “类”。 将类命名为 paged cargoresultrequestdto,然后选择“添加”。代码如下。
using abp.application.services.dto; using system; using system.collections.generic; using system.text; namespace abp.tplms.cargos.dto { public class pagedcargoresultrequestdto : pagedresultrequestdto { public string keyword { get; set; } } }
4.右键单击“dto”文件夹,然后选择“添加” > “类”。 将类命名为 cargodto,然后选择“添加”。代码如下。
using abp.application.services.dto; using abp.automapper; using abp.tplms.entitys; using system; using system.collections.generic; using system.text; namespace abp.tplms.cargos.dto { [automapfrom(typeof(cargo))] public class cargodto:entitydto<int> { public int supplierid { get; set; } public string cargocode { get; set; } public string hscode { get; set; } public string cargoname { get; set; } public string spcf { get; set; } public string unit { get; set; } public string country { get; set; } public string brand { get; set; } public string curr { get; set; } public string package { get; set; } public decimal length { get; set; } public decimal width { get; set; } public decimal height { get; set; } public decimal vol { get; set; } public decimal minnum { get; set; } public decimal maxnum { get; set; } public decimal price { get; set; } public decimal grosswt { get; set; } public decimal netwt { get; set; } public string remark { get; set; } public datetime creationtime { get; set; } public datetime updatetime { get; set; } public string updoper { get; set; } } }
5.右键单击“dto”文件夹,然后选择“添加” > “类”。 将类命名为 createupdatecargodto,然后选择“添加”。代码如下。
using abp.application.services.dto; using abp.automapper; using abp.tplms.entitys; using system; using system.collections.generic; using system.componentmodel.dataannotations; using system.text; namespace abp.tplms.cargos.dto { [automapto(typeof(cargo))] public class createupdatecargodto : entitydto<int> { public int supplierid { get; set; } [stringlength(50)] public string cargocode { get; set; } [stringlength(10)] public string hscode { get; set; } [stringlength(250)] public string cargoname { get; set; } [stringlength(512)] public string spcf { get; set; } [stringlength(20)] public string unit { get; set; } [stringlength(20)] public string country { get; set; } [stringlength(50)] public string brand { get; set; } [stringlength(20)] public string curr { get; set; } [stringlength(50)] public string package { get; set; } public decimal length { get; set; } public decimal width { get; set; } public decimal height { get; set; } public decimal vol { get; set; } public decimal minnum { get; set; } public decimal maxnum { get; set; } public decimal price { get; set; } public decimal grosswt { get; set; } public decimal netwt { get; set; } [stringlength(2048)] public string remark { get; set; } public datetime creationtime { get; set; } public datetime updatetime { get; set; } [stringlength(50)] public string updoper { get; set; } } }