abp(net core)+easyui+efcore实现仓储管理系统——组织管理升级之上(六十一)
  MYrYhn3ObP4r 2023年11月02日 110 0

 Abp(net core)+easyui+efcore实现仓储管理系统目录

 

      有了前一篇文章(abp(net core)+easyui+efcore实现仓储管理系统——模块管理升级(六十) ),对于模块管理的升级过程中解决升级中出现的问题的一些经验。我们对组织管理这个模块进行升级。

一、添加Profile定义文件

   1. 在Visual Studio 2022的“解决方案资源管理器”中,右键单击“ABP.TPLMS.Application”项目,使用鼠标左键展开“Orgs” > “Dto”文件夹

  2. 使用鼠标右键单击“Dto”文件夹,然后选择“添加” > “类”。 将类命名为 OrgMapProfile,然后选择“添加”。代码如下。

using ABP.TPLMS.Authorization.Users; using ABP.TPLMS.Entitys; using ABP.TPLMS.Users.Dto; using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABP.TPLMS.Orgs.Dto { public class OrgMapProfile:Profile { public OrgMapProfile() { CreateMap<OrgDto, Org>(); CreateMap<OrgDto, CreateUpdateOrgDto>(); CreateMap<CreateUpdateOrgDto, Org>(); } } }
 

二、修改OrgAppService类

   3.在Visual Studio 2022的“解决方案资源管理器”中,在“Orgs”文件夹中找到OrgAppService.cs文件,双击在文本编辑器中打开,修改代码如下。

using Abp.Application.Services; using Abp.Application.Services.Dto; using Abp.Domain.Repositories; using Abp.Web.Models; using ABP.TPLMS.Entitys; using ABP.TPLMS.Modules.Dto; using ABP.TPLMS.Orgs.Dto; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABP.TPLMS.Orgs { public class OrgAppService : AsyncCrudAppService<Org, OrgDto, int, PagedOrgResultRequestDto, CreateUpdateOrgDto, CreateUpdateOrgDto>, IOrgAppService { public OrgAppService(IRepository<Org, int> repository) : base(repository) { } [DontWrapResult] public  PagedOrgResultDto<OrgDto> GetAllOrgs(PagedOrgResultRequestDto input) { PagedOrgResultDto<OrgDto> orgs = new PagedOrgResultDto<OrgDto>(); input.SkipCount = 0;//这里需要进行参数传递
            input.MaxResultCount= 1000; var allOrgs=GetAllAsync(input); IReadOnlyList<OrgDto> result = AddParentOrgs(input, allOrgs.Result.Items).AsReadOnly(); orgs.Rows = result; orgs.Total = result.Count; return orgs; } private List<OrgDto> AddParentOrgs(PagedOrgResultRequestDto input,IReadOnlyList<OrgDto> list) { List<OrgDto> result = new List<OrgDto>(); if (list == null) return result; var qry1 = base.CreateFilteredQuery(input); List<Org> listParent = new List<Org>(); GetParentOrgs(listParent, list[0].ParentId, qry1); foreach (var item in listParent) { result.Add(ObjectMapper.Map<OrgDto>(item)); } result.AddRange(list.ToArray()); return result; } protected override IQueryable<Org> CreateFilteredQuery(PagedOrgResultRequestDto input) { var qry = base.CreateFilteredQuery(input) .Where(t => t.Name.Contains(input.OrgName == null ? string.Empty : input.OrgName)) .Where(t => t.BizCode.Contains(input.OrgCode == null ? string.Empty : input.OrgCode)) .Where(t => t.CustomCode.Contains(input.CustomCode == null ? string.Empty : input.CustomCode)); return qry; } private void GetParentOrgs(List<Org> orgs, int ParentId, IQueryable<Org> listOrgs) { List<Org> drs = listOrgs.Where(x => x.Id == ParentId).ToList(); if (drs == null || drs.Count <= 0) { return; } else { for (int i = 0; i < drs.Count; i++) { var dr = drs[i]; if (!orgs.Contains(dr)) { orgs.Add(dr); } GetParentOrgs(orgs, dr.ParentId, listOrgs); } } } } }

4. 上面代码中需要特别注意的一点,是GetAllOrgs方法中的input.SkipCount=0这一行代码,如果将这一行代码注释掉,在进行条件查询时,会报错。在组织管理页面的海关代码中输入“2011”,然后点击“查询”按钮。如下图。

5.Visual Studio 2022会弹出一个用记未处理的异常,错误信息,如下图。

 

    6.在Visual Studio 2022的解决方案资源管理器中,将刚才注释掉的那一条代码“input.SkipCount=0”,还原。按F5运行应用程序。

   7.在浏览器中的登录页面中输入管理员用户名和密码进行登录。

   8.在主界面的菜单中,选择“Business->组织管理”菜单项,浏览器中呈现一个组织信息列表与四个按钮。组织信息能正常显示。如下图。

  9. 在“组织管理”列表页面的海关代码输入框中输入“2011”,然后点击“查询”按钮。如下图。

 

10.这一次程序运行正常,查询出了结果,结果如下图。

11.在“组织管理”列表页面中使用鼠标点击“添加”按钮,弹出“添加组织信息”界面。如下图。

 

12.在“添加组织信息”中填写完信息,然后点击“保存”按钮,将新添加的组织信息保存到数据库。如下图。

 

 

 

 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  ONUxOTrWxq0S   2天前   5   0   0 .NET
  N0voYI1hUq93   2天前   5   0   0 .NET
MYrYhn3ObP4r