ToB企服应用市场:ToB评测及商务社交产业平台

标题: abp(net core)+easyui+efcore实现仓储管理系统——供应商管理升级之上(六十 [打印本页]

作者: 干翻全岛蛙蛙    时间: 2023-5-4 23:48
标题: abp(net core)+easyui+efcore实现仓储管理系统——供应商管理升级之上(六十
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实现仓储管理系统——使用 WEBAPI实现CURD (十一)abp(net core)+easyui+efcore实现仓储管理系统——EasyUI之货物管理一 (十九)abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与EasyUI结合增删改查之一(二十七)abp(net core)+easyui+efcore实现仓储管理系统——入库管理之一(三十七)abp(net core)+easyui+efcore实现仓储管理系统——出库管理之一(四十九)abp(net core)+easyui+efcore实现仓储管理系统——ABP升级7.3上(五十八)      有了前面两篇关于升级的文章,组织管理和模块管理,并在升级过程中解决了一些升级中出现的问题。我们对供应商管理这个模块进行升级,这次的升级涉及到前端页面的一些问题。 
1.在Visual Studio 2022的解决方案资源管理器中,选中“ABP.TPLMS.Web.Mvc”项目,然后单击鼠标右键,在弹出菜单中选中“设为启动项目”。按F5运行应用程序。

2.在浏览器将呈现登录页面,然后输入管理员用户名进行登录。浏览器跳转到首页面。如下图。

 

 
3.在主界面的菜单中,选择“Business->供应商管理”菜单项,浏览器立即报了一个错误。如下图。

 
4.这是AutoMapper.Mapper方法造成的。这是由于在升级的时候,AutoMapper也升级了。由于NET模型映射器AutoMapper 9.0之后,官方宣称不再支持静态方法调用,之前直接升级编译报错无法使用。我简单的在代码的构造函数中使用注入方式,注入Mapper。现在实际运行时,发现这种方式,如果没有在startup.cs代码中预先注册,是无法使用的。原先的代码如下:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Abp.Application.Services.Dto;
  6. using Abp.AspNetCore.Mvc.Authorization;
  7. using Abp.Auditing;
  8. using Abp.Runtime.Validation;
  9. using ABP.TPLMS.Controllers;
  10. using ABP.TPLMS.Suppliers;
  11. using ABP.TPLMS.Suppliers.Dto;
  12. using ABP.TPLMS.Web.Models.Supplier;
  13. using Microsoft.AspNetCore.Mvc;
  14. using Microsoft.EntityFrameworkCore;
  15. // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  16. namespace ABP.TPLMS.Web.Controllers
  17. {
  18.     [AbpMvcAuthorize]
  19.     [Audited]
  20.     public class SupplierController : TPLMSControllerBase
  21.     {
  22.         const int MaxNum= 10;
  23.         // GET: /<controller>/
  24.         [DisableAuditing]
  25.         public async Task<IActionResult> Index()
  26.         {
  27.             SupplierDto cuModule=null;
  28.             var module = (await _supplierAppService.GetAllAsync(new PagedSupplierResultRequestDto { MaxResultCount = MaxNum })).Items; // Paging not implemented yet
  29.             if (module.Count>0)
  30.             {
  31.                 cuModule = module.First();
  32.             }
  33.            
  34.             var model = new SupplierListViewModel
  35.             {
  36.                 Supplier = cuModule,
  37.                 Suppliers=module
  38.             };
  39.          
  40.             return View(model);
  41.         }
  42.         private readonly ISupplierAppService _supplierAppService;
  43.         AutoMapper.Mapper m_map;
  44.         public SupplierController(ISupplierAppService supplierAppService,AutoMapper.Mapper map)
  45.         {
  46.             _supplierAppService = supplierAppService;
  47.             m_map = map;
  48.         }
  49.         public async Task<ActionResult> EditSupplierModal(int supplierId)
  50.         {
  51.            
  52.             var module = await _supplierAppService.GetAsync(new EntityDto<int>(supplierId));
  53.             CreateUpdateSupplierDto cuSupplier = m_map.Map<CreateUpdateSupplierDto>(module);
  54.             var model = new EditSupplierModalViewModel
  55.             {
  56.                 Supplier = cuSupplier
  57.             };
  58.             return View("_EditSupplierModal", model);
  59.         }
  60.     }
  61. }
复制代码
 
 5.幸好发现有一个ABP.ObjectMapper.Map方法可以使用,我们将代码修改为:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Abp.Application.Services.Dto;
  6. using Abp.AspNetCore.Mvc.Authorization;
  7. using Abp.Auditing;
  8. using Abp.Runtime.Validation;
  9. using ABP.TPLMS.Controllers;
  10. using ABP.TPLMS.Suppliers;
  11. using ABP.TPLMS.Suppliers.Dto;
  12. using ABP.TPLMS.Web.Models.Supplier;
  13. using Microsoft.AspNetCore.Mvc;
  14. using Microsoft.EntityFrameworkCore;
  15. // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  16. namespace ABP.TPLMS.Web.Controllers
  17. {
  18.     [AbpMvcAuthorize]
  19.     [Audited]
  20.     public class SupplierController : TPLMSControllerBase
  21.     {
  22.         const int MaxNum= 10;
  23.         // GET: /<controller>/
  24.         [DisableAuditing]
  25.         public async Task<IActionResult> Index()
  26.         {
  27.             SupplierDto cuModule=null;
  28.             var module = (await _supplierAppService.GetAllAsync(new PagedSupplierResultRequestDto { MaxResultCount = MaxNum })).Items; // Paging not implemented yet
  29.             if (module.Count>0)
  30.             {
  31.                 cuModule = module.First();
  32.             }
  33.            
  34.             var model = new SupplierListViewModel
  35.             {
  36.                 Supplier = cuModule,
  37.                 Suppliers=module
  38.             };
  39.          
  40.             return View(model);
  41.         }
  42.         private readonly ISupplierAppService _supplierAppService;
  43.         public SupplierController(ISupplierAppService supplierAppService)
  44.         {
  45.             _supplierAppService = supplierAppService;
  46.            
  47.         }
  48.         public async Task<ActionResult> EditSupplierModal(int supplierId)
  49.         {
  50.             
  51.             var module = await _supplierAppService.GetAsync(new EntityDto<int>(supplierId));
  52.             CreateUpdateSupplierDto cuSupplier = ObjectMapper.Map<CreateUpdateSupplierDto>(module);
  53.             var model = new EditSupplierModalViewModel
  54.             {
  55.                 Supplier = cuSupplier
  56.             };
  57.            return View("_EditSupplierModal", model);
  58.         }
  59. }
  60. }
复制代码
 
6.在Visual Studio 2022的解决方案资源管理器,按F5运行应用程序。

7.在浏览器将呈现登录页面,然后输入管理员用户名进行登录。浏览器跳转到首页面,在主界面的菜单中,选择“Business->供应商管理”菜单项,浏览器中呈现一个供应商信息列表页面,我们发现此页面的顶部与右边的菜单部分缺失css,样式不好看。如下图。


8. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击在领域层“ABP.TPLMS.Web.Mvc”项目中的Views\Supplier目录。 找到Index.cshmtl文件,修改顶部的代码与按钮的代码。具体代码如下:

 
  1. @using ABP.TPLMS.Web.Startup
  2. @model ABP.TPLMS.Web.Models.Supplier.SupplierListViewModel
  3. @{
  4.     ViewData["Title"] = PageNames.Supplier;
  5. }
  6. @section scripts
  7.     {
  8.    
  9. }
  10. <section class="content-header">
  11.    
  12.         
  13.             
  14.                 <h1>@L("Supplier")</h1>
  15.             
  16.             
  17.                 <a id="RefreshButton" target="_blank" href="https://www.cnblogs.com/javascript:void(0);"><i class="fas fa-redo-alt"></i></a>
  18.             
  19.             
  20.                 <button type="button" class="btn btn-primary btn-circle waves-effect waves-circle waves-float pull-right"<br> data-toggle="modal" data-target="#SupplierCreateModal">
  21.                     <i class="fa fa-plus-square">Add</i>
  22.                 </button>
  23.             
  24.         
  25.    
  26. </section>
  27.    
  28.                   
  29.             
  30.                 <table class="table">
  31.                     <thead>
  32.                         <tr>
  33.                             <th>
  34.                                 @Html.DisplayNameFor(model => model.Supplier.Code)
  35.                             </th>
  36.                             <th>
  37.                                 @Html.DisplayNameFor(model => model.Supplier.Name)
  38.                             </th>
  39.                             <th>
  40.                                 @Html.DisplayNameFor(model => model.Supplier.LinkName)
  41.                             </th>
  42.                             <th>
  43.                                 @Html.DisplayNameFor(model => model.Supplier.Mobile)
  44.                             </th>
  45.                             <th>
  46.                                 @Html.DisplayNameFor(model => model.Supplier.Address)
  47.                             </th>
  48.                             <th>
  49.                                 @Html.DisplayNameFor(model => model.Supplier.Tel)
  50.                             </th>
  51.                             <th>
  52.                                 @Html.DisplayNameFor(model => model.Supplier.Status)
  53.                             </th>
  54.                             <th></th>
  55.                         </tr>
  56.                     </thead>
  57.                     <tbody>
  58.                         @foreach (var item in Model.Suppliers)
  59.                         {
  60.                             <tr>
  61.                                 <td>
  62.                                     @Html.DisplayFor(modelItem => item.Code)
  63.                                 </td>
  64.                                 <td>
  65.                                     @Html.DisplayFor(modelItem => item.Name)
  66.                                 </td>
  67.                                 <td>
  68.                                     @Html.DisplayFor(modelItem => item.LinkName)
  69.                                 </td>
  70.                                 <td>
  71.                                     @Html.DisplayFor(modelItem => item.Mobile)
  72.                                 </td>
  73.                                 <td>
  74.                                     @Html.DisplayFor(modelItem => item.Address)
  75.                                 </td>
  76.                                 <td>
  77.                                     @Html.DisplayFor(modelItem => item.Tel)
  78.                                 </td>
  79.                                 <td>
  80.                                     @Html.DisplayFor(modelItem => item.Status)
  81.                                 </td>
  82.                                 <td >
  83.                                     <a target="_blank" href="https://www.cnblogs.com/#" class="btn btn-sm bg-secondary edit-supplier" data-supplier-id="@item.Id" <br>data-toggle="modal" data-target="#SupplierEditModal"><i class="fas fa-pencil-alt"></i>@L("Edit")</a>
  84.                                     <a target="_blank" href="https://www.cnblogs.com/#" class="btn btn-sm bg-danger delete-supplier" data-supplier-id="@item.Id" <br>data-supplier-name="@item.Name"><i class="fas fa-trash"></i>@L("Delete")</a>
  85.                                 </td>
  86.                             </tr>
  87.                         }
  88.                     </tbody>
  89.                 </table>
  90.             
  91.         
  92.    
  93. data-backdrop="static">
  94.    
  95.         
  96.             
  97.                 <h4 class="modal-title">
  98.                     <span>@L("CreateNewSupplier")</span>
  99.                 </h4>
  100.             
  101.             
  102.                 <form name="SupplierCreateForm" role="form" class="form-validation">
  103.                     
  104.                         
  105.                            
  106.                                 
  107.                                     
  108.                                        <label asp-for="@Model.Supplier.Code" class="form-label"></label>
  109.                                         <input type="text" name="Code" class="form-control" required maxlength="50" />
  110.                                     
  111.                                 
  112.                            
  113.                            
  114.                                 
  115.                                     
  116.                                         <label asp-for="@Model.Supplier.Name" class="form-label"></label>
  117.                                         <input type="text" name="Name" class="form-control" required maxlength="50" />
  118.                                     
  119.                                 
  120.                            
  121.                         
  122.                         
  123.                            
  124.                                 
  125.                                     
  126.                                         <label asp-for="@Model.Supplier.Address" class="form-label"></label>
  127.                                         <input type="text" name="Address" class="form-control" required maxlength="255" />
  128.                                     
  129.                                 
  130.                            
  131.                         
  132.                         
  133.                            
  134.                                 
  135.                                     
  136.                                         <label asp-for="@Model.Supplier.LinkName" class="form-label"></label>
  137.                                         <input type="text" name="LinkName" class="form-control" />
  138.                                     
  139.                                 
  140.                            
  141.                            
  142.                                 
  143.                                     
  144.                                         <label asp-for="@Model.Supplier.Mobile" class="form-label"></label>
  145.                                         <input type="text" name="Mobile" class="form-control" />
  146.                                     
  147.                                 
  148.                            
  149.                         
  150.                         
  151.                            
  152.                                 
  153.                                     
  154.                                         <label asp-for="@Model.Supplier.Tel" class="form-label"></label>
  155.                                         <input type="text" name="Tel" class="form-control" required maxlength="255" />
  156.                                     
  157.                                 
  158.                            
  159.                            
  160.                                 
  161.                                     
  162.                                         <label asp-for="@Model.Supplier.Status" class="form-label"></label>
  163.                                         <input type="text" name="Status" class="form-control" />
  164.                                     
  165.                                 
  166.                            
  167.                         
  168.                         
  169.                            
  170.                                 
  171.                                     <label asp-for="@Model.Supplier.Sex"></label>
  172.                                     <input name="Sex" type="text" class="form-control" />
  173.                                 
  174.                            
  175.                            
  176.                                 
  177.                                     <label asp-for="@Model.Supplier.Email"></label>
  178.                                     <input name="Email" type="text" class="form-control" />
  179.                                 
  180.                            
  181.                         
  182.                     
  183.                     
  184.                         <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
  185.                         <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
  186.                     
  187.                 </form>
  188.             
  189.         
  190.    
  191. data-backdrop="static">
  192.    
  193.         
  194.         
  195.    
复制代码
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4