abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与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实现仓储管理系统——定义仓储并实现 (四)json

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实现仓储管理系统——使用 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)控件。

2、树形表格(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:选项前面的图标,若是本身不设定,父级节点默认为文件夹图标,子级节点为文件图标

 

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

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

 

相关文章
相关标签/搜索