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实现仓储管理系统——菜单-上 (十六)

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

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

abp(net core)+easyui+efcore实现仓储管理系统——easyui之货物管理六(二十四)
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表创建成功。