abp(net core)+easyui+efcore實現倉儲管理系統——EasyUI之貨物管理一 (十九)

abp(net core)+easyui+efcore實現倉儲管理系統目錄

abp(net core)+easyui+efcore實現倉儲管理系統——ABP整體介紹(一)html

abp(net core)+easyui+efcore實現倉儲管理系統——解決方案介紹(二)前端

abp(net core)+easyui+efcore實現倉儲管理系統——領域層建立實體(三)數據庫

 abp(net core)+easyui+efcore實現倉儲管理系統——定義倉儲並實現 (四)app

abp(net core)+easyui+efcore實現倉儲管理系統——建立應用服務(五)框架

abp(net core)+easyui+efcore實現倉儲管理系統——展示層實現增刪改查之控制器(六)工具

abp(net core)+easyui+efcore實現倉儲管理系統——展示層實現增刪改查之列表視圖(七)post

abp(net core)+easyui+efcore實現倉儲管理系統——展示層實現增刪改查之增刪改視圖(八)測試

abp(net core)+easyui+efcore實現倉儲管理系統——展示層實現增刪改查之菜單與測試(九)ui

abp(net core)+easyui+efcore實現倉儲管理系統——多語言(十)this

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控件來展示一個貨物信息管理的前端功能,並使用建立相應的實體類,服務類等來實現後臺功能。

4、建立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表建立成功。

 

 

5、定義應用服務接口須要用到的分頁類

      爲了在進行查詢時使用, 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; }
    }
}
相關文章
相關標籤/搜索