abp(net core)+easyui+efcore實現倉儲管理系統——出庫管理之四(五十三)

DotNet菜園發表於2020-10-30

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); } } }

 

相關文章