abp(net core)+easyui+efcore實現倉儲管理系統——EasyUI之貨物管理一 (十九)
abp(net core)+easyui+efcore實現倉儲管理系統目錄
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前端頁面框架 (十八)
通過上一篇(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; } } }
&n