abp(net core)+easyui+efcore實現倉儲管理系統目錄
abp(net core)+easyui+efcore實現倉儲管理系統——EasyUI前端頁面框架 (十八)
我們已經在ABP中實現瞭如何呼叫儲存過程的方法 ,接下來我們要來實現應用層的具體程式碼。
六、定義應用層介面
1. 在Visual Studio 2017的“解決方案資源管理器”中,滑鼠右鍵單擊“OutStocks”資料夾,然後選擇“新增” > “新建項”,在彈出對話方塊中選擇“介面”。為應用服務定義一個名為 IOutStockOrderAppService 的介面。程式碼如下。
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Application.Services;
using ABP.TPLMS.OutStocks.Dto;
namespace ABP.TPLMS.OutStocks
{
public interface IOutStockOrderAppService : IAsyncCrudAppService<//定義了CRUD方法
OutStockOrderDto, //用來展示出庫單資訊
int, //出庫單實體的主鍵
PagedOutStockResultRequestDto, //獲取出庫單資訊的時候用於分頁
CreateUpdateOutStockOrderDto, //用於建立出庫單資訊
CreateUpdateOutStockOrderDto> //用於更新出庫單資訊
{
/// <summary>
/// 建立單號
/// </summary>
/// <returns></returns>
string GetNo();
/// <summary>
/// 儲存出庫單資料
/// </summary>
/// <param name="iso"></param>
/// <returns></returns>
string Save(OutStockOrderDto iso);
/// <summary>
/// 匯入貨物資訊
/// </summary>
/// <param name="ids">匯出庫貨物資訊的ID</param>
/// <param name="No">出庫單單號</param>
/// <returns></returns>
string ImportInStockDetail(string ids,string No);
/// <summary>
/// 批量刪除
/// </summary>
/// <param name="ids">出庫單ID集合</param>
/// <returns></returns>
bool DeleteById(string ids);
}
}
2. 在Visual Studio 2017的“解決方案資源管理器”中,滑鼠右鍵單擊“OutStocks”資料夾,然後選擇“新增” > “新建項”,在彈出對話方塊中選擇“介面”。為應用服務定義一個名為 IOutStockOrderDetailAppService 的介面。程式碼如下。
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Application.Services;
using ABP.TPLMS.OutStocks.Dto;
namespace ABP.TPLMS.OutStocks
{
public interface IOutStockOrderDetailAppService : IAsyncCrudAppService<//定義了CRUD方法
OutStockOrderDetailDto, //用來展示出庫單明細資訊
int, //出庫單實體的主鍵
PagedOutStockDetailResultRequestDto, //獲取出庫單資訊的時候用於分頁
CreateUpdateOutStockOrderDetailDto, //用於建立出庫單明細資訊
CreateUpdateOutStockOrderDetailDto > //用於更新出庫單明細資訊
{
}
}
七、實現OutStockOrderAppService
3.在Visual Studio 2017的“解決方案資源管理器”中,右鍵單擊“OutStocks”資料夾,然後選擇“新增” > “新建項”,在彈出對話方塊中選擇“類”。為應用服務定義一個名為 OutStockOrderAppService 的服務類,實現IOutStockOrderAppService介面中的方法。特別注意在建構函式中定義IOutStockOrderRepository 介面,方便注入。程式碼如下。
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Web.Models;
using ABP.TPLMS.Entitys;
using ABP.TPLMS.OutStocks.Dto;
using ABP.TPLMS.IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABP.TPLMS.OutStocks
{
public class OutStockOrderAppService : AsyncCrudAppService<OutStockOrder, OutStockOrderDto,
int, PagedOutStockResultRequestDto,
CreateUpdateOutStockOrderDto, CreateUpdateOutStockOrderDto>,
IOutStockOrderAppService
{
IOutStockOrderRepository rep = null;
IOutStockOrderDetailAppService outDetApp=null;
public OutStockOrderAppService(IRepository<OutStockOrder, int> repository,
IOutStockOrderRepository isdRepository,IOutStockOrderDetailAppService outodAppser)
: base(repository)
{
rep = isdRepository;
outDetApp = outodAppser;
}
public override Task<PagedResultDto<OutStockOrderDto>> GetAll
(PagedOutStockResultRequestDto input)
{
return base.GetAll(input);
}
[DontWrapResult]
public PagedOutStockOrderResultDto<OutStockOrderDto> GetAllOutStockOrders
(PagedOutStockResultRequestDto input)
{
PagedOutStockOrderResultDto<OutStockOrderDto> outODs =
new PagedOutStockOrderResultDto<OutStockOrderDto>();
var allOrgs=GetAll(input);
outODs.Rows = allOrgs.Result.Items;
outODs.Total = allOrgs.Result.TotalCount;
return outODs;
}
protected override IQueryable<OutStockOrder> CreateFilteredQuery
(PagedOutStockResultRequestDto input)
{
var qry= base.CreateFilteredQuery(input)
.Where(t=>t.OwnerName.Contains(input.OwnerName==null?string.Empty:input.OwnerName))
.Where(t => t.No.Contains(input.No == null ? string.Empty : input.No))
.Where(t => t.CreationTime>input.BeginTime)
.Where(t => t.CreationTime<input.EndTime);
return qry;
}
[DontWrapResult]
public string GetNo()
{
string no = rep.GetNo("ODO");
return no;
}
[DontWrapResult]
public string ImportInStockDetail(string ids,string No)
{
try
{
//匯入貨物資訊
rep.ImportInStockOrder(ids, No);
}
catch (Exception ex)
{
throw ex;
}
return "OK";
}
public string Save(OutStockOrderDto iso)
{
try
{
CreateUpdateOutStockOrderDto order =
ObjectMapper.Map<CreateUpdateOutStockOrderDto>(iso);
foreach (var item in order.OutStockOrderDetail)
{
CreateUpdateOutStockOrderDetailDto outODet =
ObjectMapper.Map<CreateUpdateOutStockOrderDetailDto>(item);
if (outODet.Id > 0)
{
outDetApp.Update(outODet);
}
else
outDetApp.Create(outODet);
}
order.OutStockOrderDetail = null;
order.Status = 1 ;
Update(order);
}
catch (Exception ex)
{
throw ex;
}
return "OK";
}
public bool DeleteById(string Ids)
{
var idList = Ids.Split(',');
bool result = true;
try
{
foreach (var id in idList)
{
int.TryParse(id, out int intId);
var odo = GetEntityByIdAsync(intId).GetAwaiter().GetResult();
PagedOutStockDetailResultRequestDto PagedDetail =
new PagedOutStockDetailResultRequestDto
{
InStockNo = odo.No
};
var isods = outDetApp.GetAll(PagedDetail).GetAwaiter().GetResult();
OutStockOrderDto order = ObjectMapper.Map<OutStockOrderDto>(odo);
Delete(order);
}
}
catch (Exception ex)
{
result = false;
throw ex;
}
return result;
}
}
}
4.在Visual Studio 2017的“解決方案資源管理器”中,右鍵單擊“OutStocks”資料夾,然後選擇“新增” > “新建項”,在彈出對話方塊中選擇“類”。為應用服務定義一個名為 OutStockOrderDetailAppService 的服務類,實現IOutStockOrderDetailAppService介面。程式碼如下。
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Web.Models;
using ABP.TPLMS.Entitys;
using ABP.TPLMS.OutStocks.Dto;
using ABP.TPLMS.IRepositories;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABP.TPLMS.OutStocks
{
public class OutStockOrderDetailAppService : AsyncCrudAppService<OutStockOrderDetail
, OutStockOrderDetailDto, int
, PagedOutStockDetailResultRequestDto,
CreateUpdateOutStockOrderDetailDto, CreateUpdateOutStockOrderDetailDto>
, IOutStockOrderDetailAppService
{
public OutStockOrderDetailAppService( IRepository<OutStockOrderDetail, int> repository)
: base(repository)
{
}
protected override IQueryable<OutStockOrderDetail>
CreateFilteredQuery(PagedOutStockDetailResultRequestDto input)
{
var qry = base.CreateFilteredQuery(input)
.Where(t => t.OutStockNo == input.OutStockNo);
return qry;
}
}
}