abp(net core)+easyui+efcore实现仓储管理系统——出库管理之四(五十三)
abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统——EasyUI前端页面框架 (十八)
今天我们来创建出库单的控制器代码。
八 创建OutStockController继承自TPLMSControllerBase
1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击在领域层“ABP.TPLMS.Web.Mvc”项目中的Controller目录。 选择“添加” > “新建项…”。如下图。
2. 在弹出对话框“添加新项-ABP.TPLMS.Web.Mvc”中选择“控制器类”,然后在名称输入框中输入“OutStockController”,然后点击“添加”按钮。
3.在OutStockController.cs文件中输入如下代码,通过构造函数注入对应用服务的依赖。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Runtime.Validation;
using Abp.Web.Models;
using ABP.TPLMS.Controllers;
using ABP.TPLMS.Helpers;
using ABP.TPLMS.Models.InStock;
using ABP.TPLMS.OutStocks;
using ABP.TPLMS.OutStocks.Dto;
using Microsoft.AspNetCore.Mvc;
namespace ABP.TPLMS.Web.Controllers
{
public class OutStockController : TPLMSControllerBase
{
private readonly IOutStockOrderAppService _outOODAppService;
private readonly IOutStockOrderDetailAppService _outOODAppDetService;
private const int MAX_COUNT = 1000;
public OutStockController(IOutStockOrderAppService InSOAppService
, IOutStockOrderDetailAppService InSODAppService)
{
_outOODAppService = InSOAppService;
_outOODAppDetService = InSODAppService;
}
public IActionResult Index()
{
return View();
}
[DontWrapResult]
[HttpPost]
public string List()
{
var page = Request.Form["page"].ToString();
var size = Request.Form["rows"].ToString();
int pageIndex = page == null ? 1 : int.Parse(page);
int pageSize = size == null ? 20 : int.Parse(size);
PagedOutStockResultRequestDto paged = new PagedOutStockResultRequestDto();
paged.MaxResultCount = MAX_COUNT;
paged.SkipCount = ((pageIndex - 1) < 0 ? 0 : pageIndex - 1) * pageSize;
paged.BeginTime = DateTime.Now.AddMonths(-1);
paged.EndTime = DateTime.Now.AddDays(1);
var query = _outOODAppService.GetAll(paged).GetAwaiter().GetResult();
var isoList = query.Items;
int total = query.TotalCount;
var json = JsonEasyUI(isoList, total);
return json;
}
[DontWrapResult]
public string GetDetail(string no)
{
PagedOutStockDetailResultRequestDto paged = new PagedOutStockDetailResultRequestDto();
paged.MaxResultCount = MAX_COUNT;
paged.OutStockNo = no;
var outDetailList = _outOODAppDetService.GetAll(paged).GetAwaiter().GetResult().Items;
for (int i = 0; i < outDetailList.Count; i++)
{
outDetailList[i].SeqNo = i + 1;
}
var json = JsonEasyUI(outDetailList);
return json;
}
[HttpPost]
[DisableValidation]
public ActionResult Add(OutStockOrderDto iso)
{
string result = "NO";
try
{
PagedOutStockResultRequestDto condition = new PagedOutStockResultRequestDto();
condition.No = iso.No;
var outExists = _outOODAppService.GetAll(condition).GetAwaiter().GetResult();
if (outExists.TotalCount > 0)
{
return Content(result);
}
CreateUpdateOutStockOrderDto cuIso = ObjectMapper
.Map<CreateUpdateOutStockOrderDto>(iso);
// TODO: Add logic here
var obj = _outOODAppService.Create(cuIso);
result = "OK";
}
catch (Exception ex)
{
result = "NO";
}
return Content(result);
}
//[DontWrapResult]
[HttpPost]
[DisableValidation]
public string Update(OutStockOrderDto iso)
{
string result = "NO";
List<OutStockOrderDetailDto> list = new List<OutStockOrderDetailDto>();
try
{
string head = Request.Form["postdata"];
if (!string.IsNullOrEmpty(head))
{
//把json字符串转换成对象
iso = JsonHelper.Instance.Deserialize<OutStockOrderDto>(head);
}
list = GetDetailDtos();
if (iso == null)
{
return "没有表头!";
}
iso.OutStockOrderDetail = list;
result = _outOODAppService.Save(iso);
}
catch
{
}
if (result == "OK")
{
return "更新成功!";
}
else
return "更新失败!";
}
private List<OutStockOrderDetailDto> GetDetailDtos()
{
List<OutStockOrderDetailDto> list = new List<OutStockOrderDetailDto>();
string deleted = Request.Form["deleted"];
string inserted = Request.Form["inserted"];
string updated = Request.Form["updated"];
// TODO: Add update logic here
if (!string.IsNullOrEmpty(deleted))
{
//把json字符串转换成对象
List<OutStockOrderDetailDto> listDeleted = JsonHelper.Instance
.Deserialize<List<OutStockOrderDetailDto>>(deleted);
//TODO 下面就可以根据转换后的对象进行相应的操作了
if (listDeleted != null && listDeleted.Count > 0)
{
list.AddRange(listDeleted.ToArray());
}
}
if (!string.IsNullOrEmpty(inserted))
{
//把json字符串转换成对象
List<OutStockOrderDetailDto> listInserted = JsonHelper.Instance
.Deserialize<List<OutStockOrderDetailDto>>(inserted);
if (listInserted != null && listInserted.Count > 0)
{
list.AddRange(listInserted.ToArray());
}
}
if (!string.IsNullOrEmpty(updated))
{
//把json字符串转换成对象
List<OutStockOrderDetailDto> listUpdated = JsonHelper.Instance
.Deserialize<List<OutStockOrderDetailDto>>(updated);
if (listUpdated != null && listUpdated.Count > 0)
{
list.AddRange(listUpdated.ToArray());
}
}
return list;
}
[HttpPost]
[DisableValidation]
public ActionResult ImportInStockOrder(CargoModel isoder)
{
string result = "NO";
try
{
// TODO: 导入货物信息
result = _outOODAppService.ImportInStockDetail(isoder.Ids, isoder.No);
}
catch
{
}
return Content(result);
}
[HttpPost]
[DontWrapResult]
public ActionResult Delete(string ids)
{
string result = "NO";
try
{
// TODO: Add Delete logic here
bool flag = _outOODAppService.DeleteById(ids);
if (flag)
{
result = "OK";
}
}
catch
{
}
return Content(result);
}
}
}