abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与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实现仓储管理系统——使用 WEBAPI实现CURD (十一)

abp(net core)+easyui+efcore实现仓储管理系统——菜单-上 (十六)

abp(net core)+easyui+efcore实现仓储管理系统——EasyUI前端页面框架 (十八)

abp(net core)+easyui+efcore实现仓储管理系统——EasyUI之货物管理一 (十九)

 

一.前言

       通过前面的文章abp(net core)+easyui+efcore实现仓储管理系统——EasyUI之货物管理一 (十九) abp(net core)+easyui+efcore实现仓储管理系统——EasyUI之货物管理八(二十六) 的学习,我们已经有实现了传统的ASP.NET Core MVC+EasyUI的增删改查功能。本篇文章我们要实现了使用ABP提供的WebAPI方式+EasyUI来实现增删改查的功能。本文中我们将不在使用DataGrid表格控件,而是使用树形表格(TreeGrid)控件。

二、树形表格(TreeGrid)介绍

       我先上图,让我们来看一下功能完成之后的组织管理信息列表页面。如下图。

       这个组织管理列表页面使用TreeGrid来实现的。我们接下来介绍一下TreeGrid。

     首先、在定义TreeGrid时有两个属性必须要有一个是idField,这个要唯一;另一个是treeField的定义,这是树节点的值,必须要有。 

     其次、easyui加载treegrid的json数据格式有三种,我就介绍我常用的这种。其他两种方式,请查看easyui的相关文档。

  {"total":7,"rows":[

           {"id":1,"name":"All Tasks","begin":"3/4/2010","end":"3/20/2010","progress":60,"iconCls":"icon-ok"},      
{"id":2,"name":"Designing","begin":"3/4/2010","end":"3/10/2010","progress":100,"_parentId":1,"state":"closed"},
{"id":21,"name":"Database","persons":2,"begin":"3/4/2010","end":"3/6/2010","progress":100,"_parentId":2},
{"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2}, {"id":23,"name":"Export Document","persons":1,"begin":"3/9/2010","end":"3/10/2010","progress":100,"_parentId":2},
{"id":3,"name":"Coding","persons":2,"begin":"3/11/2010","end":"3/18/2010","progress":80},
{"id":4,"name":"Testing","persons":1,"begin":"3/19/2010","end":"3/20/2010","progress":20} ],"footer":[ {"name":"Total Persons:","persons":7,"iconCls":"icon-sum"} ]}

     下面介绍一下上面数据中的几个重要属性:

     1)  _parentId :字段_parentId必不可少,且名称唯一。记得前面有“_” ,他是用来记录父级节点,没有这个属性,是没法展示父级节点 其次就是这个父级节点必须存在,不然信息也是展示不出来,在后台遍历组合的时候,如果父级节点不存在或为0时,此时 _parentId 应该不赋值,或设为“”。如果赋值 “0” 则在表格中不显示数据。

    2) state:是否展开

     3) checked:是否选中(用于复选框)

    4) iconCls:选项前面的图标,如果自己不设定,父级节点默认为文件夹图标,子级节点为文件图标

 

    下面我们来开始实现组织管理页面的相关功能。首先我们要创建一个组织信息实体。

三、创建Org实体

       1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击“ABP.TPLMS.Core”项目的“Entitys”文件夹,在弹出菜单中选择“添加” >

 > “类”。 将类命名为 Org,然后选择“添加”。

      2.创建Org类继承自Entity<int>,通过实现审计模块中的IHasCreationTime来实现保存创建时间。根据TreeGrid所需要的数据格式的要求。代码如下:

using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
 

namespace ABP.TPLMS.Entitys
{

   public partial class Org : Entity<int>, IHasCreationTime
{
      int m_parentId = 0;
        public Org()
        {

            this.Id = 0;
            this.Name = string.Empty;
            this.HotKey = string.Empty;
            this.ParentId = 0;
            this.ParentName = string.Empty;

            this.IconName = string.Empty;

            this.Status = 0;

            this.Type = 0;

            this.BizCode = string.Empty;
            this.CustomCode = string.Empty;
            this.CreationTime = DateTime.Now;
            this.UpdateTime = DateTime.Now;
            this.CreateId = 0;

            this.SortNo = 0;

        }

        [Required]
        [StringLength(255)]
        public string Name { get; set; }

        [StringLength(255)]
        public string HotKey { get; set; }

        public int ParentId { get { return m_parentId; } set { m_parentId = value; } }

        [Required]
        [StringLength(255)]
        public string ParentName { get; set; }

        public bool IsLeaf { get; set; }

        public bool IsAutoExpand { get; set; }

        [StringLength(255)]
        public string IconName { get; set; } 

        public int Status { get; set; }

        public int Type { get; set; }

        [StringLength(255)]
        public string BizCode { get; set; }

        [StringLength(100)]
        public string CustomCode { get; set; }

        public DateTime CreationTime { get; set; }
        public DateTime UpdateTime { get; set; }
        public int CreateId { get; set; }

        public int SortNo { get; set; }
public int? _parentId {
            get {
                if (m_parentId == 0)                

                {
                    return null;
                }

                return m_parentId;
            }           

        }
    }
}
      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; }
          public DbSet<Org> Orgs { get; set; }

    }
}

 

 

 

      4.从菜单中选择“工具->NuGet包管理器器—>程序包管理器控制台”菜单。

     5. 在PMC中,默认项目选择EntityframeworkCore对应的项目后。输入以下命令:Add-Migration AddEntityOrg,创建迁移。如下图。

 

       6. 在上面的命令执行完毕之后,创建成功后,会在Migrations文件夹下创建时间_AddEntityOrg格式的类文件,这些代码是基于DbContext指定的模型。如下图。

 

     7.在程序包管理器控制台,输入Update-Database,回车执行迁移。执行成功后,如下图。

 

     8. 在SQL Server Management Studio中查看数据库,Orgs表创建成功。

 

 

 

 

posted @ 2019-11-20 17:47  DotNet菜园  阅读(2171)  评论(2编辑  收藏  举报