-
abp(net core)+easyui+efcore实现仓储管理系统——出库管理之四(五十三)
八 创建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);
}
}
}
出处:https://www.cnblogs.com/chillsrc/p/13900971.html
栏目列表
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比