using System; using System.Collections.Generic; using System.Linq; using System.Text; using AutoMapper; using AngleSharp.Html.Parser; using DTO; using IServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System.Net.Http; using System.Threading.Tasks; using zhengcaioa.Models; using zhengcaioa.IService; using CommonToolsCore; using Services; using System.Transactions; namespace zhengcaioa.Controllers.admin { [CheckLogin] public class AdmGoodsManageController : Controller { private readonly ILogger _logger; private readonly ILiaotianService _liaotianService; private readonly IAdmGoodsManageService _admGoodsManageService; private readonly IAdmGoodsClassifyService _admGoodsClassifyService; private readonly IPltPageService _pltPageService; public AdmGoodsManageController(ILogger logger, ILiaotianService liaotianService, IAdmGoodsManageService admGoodsManageService, IAdmGoodsClassifyService admGoodsClassifyService, IPltPageService pltPageService) { _logger = logger; _liaotianService = liaotianService; _admGoodsManageService = admGoodsManageService; _admGoodsClassifyService = admGoodsClassifyService; _pltPageService = pltPageService; } public IActionResult Index() { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List actionlist = new List(); ActionEntity actionEntity = new ActionEntity(); actionEntity.OpenType = 0; actionEntity.ActionUrl = ""; actionEntity.ActionFun = "Search"; actionEntity.PageIco = "fa fa-search"; actionEntity.ActionName = "查询"; actionlist.Add(actionEntity); List pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/AdmGoodsManage/Index/"); foreach (var pageEntity in pageEntities ) { ActionEntity actionEntity1 = new ActionEntity(); actionEntity1.OpenType = pageEntity.OpenType; actionEntity1.ActionUrl = ""; actionEntity1.ActionFun = pageEntity.PageShortcut; actionEntity1.PageIco = pageEntity.PageIco; actionEntity1.ActionName = pageEntity.PageName; actionlist.Add(actionEntity1); } //ActionEntity actionEntity1 = new ActionEntity(); //actionEntity1.OpenType = 0; //actionEntity1.ActionUrl = ""; //actionEntity1.ActionFun = "Add"; //actionEntity1.PageIco = "fa fa-plus"; //actionEntity1.ActionName = "新增"; //actionlist.Add(actionEntity1); //ActionEntity actionEntity2 = new ActionEntity(); //actionEntity2.OpenType = 0; //actionEntity2.ActionUrl = ""; //actionEntity2.ActionFun = "Ruku"; //actionEntity2.PageIco = "fa fa-plus-square"; //actionEntity2.ActionName = "入库"; //actionlist.Add(actionEntity2); //ActionEntity actionEntity3 = new ActionEntity(); //actionEntity3.OpenType = 0; //actionEntity3.ActionUrl = ""; //actionEntity3.ActionFun = "Chuku"; //actionEntity3.PageIco = "fa fa-minus-square"; //actionEntity3.ActionName = "出库"; //actionlist.Add(actionEntity3); ViewData["ActionInfo"] = actionlist; ViewBag.GoodsStatus = _liaotianService.GetSYScode("adm_goods_manage", "goods_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.Goods = _admGoodsManageService.GetList().Select(x => new { code = x.Id, label = (x.GoodsName.Length>15? x.GoodsName.Substring(0, 15) : x.GoodsName) }).ToList(); ViewBag.ClassifyId = _admGoodsClassifyService.GetList().Select(x => new { code = x.Id, label = x.ClassifyName }).ToList(); return View(); } /// /// 获取物品 /// /// 省id /// /// [CheckLogin] public string getGoods(string ClassifyId = "") { var shi = _admGoodsManageService.GetList(ClassifyId); return JsonConvert.SerializeObject(shi); } /// /// 获取物品 /// /// 省id /// /// [CheckLogin] public string getGoodsLeft(string GoodsName = "") { var shi = _admGoodsManageService.Get(GoodsName); return JsonConvert.SerializeObject(shi); } public IActionResult GetList(AdmGoodsManageDTOSearch search) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); return new JsonResult(_admGoodsManageService.SearchByPaging(search)); } public IActionResult Edit(string id = null,string ClassifyIds = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; AdmGoodsManageDTO dto = new AdmGoodsManageDTO(); if (!String.IsNullOrEmpty(id)) { dto = _admGoodsManageService.Get(id); } ViewBag.ClassifyIds = ClassifyIds; ViewBag.ClassifyId = _admGoodsClassifyService.GetList(); ViewBag.GoodsStatus = _liaotianService.GetSYScode("adm_goods_manage", "goods_status"); ViewBag.shifou = _liaotianService.GetSYScode("system", "shifou"); ViewData.Model = dto; return View(); } /// /// 保存 /// /// 岗位实体类对象 /// /// [HttpPost] public IActionResult Save(AdmGoodsManageDTO data) { // data.DocContent = data.DocContent.Replace(";", ";"); ResultEntity resultEntity = new ResultEntity(); using (TransactionScope scope = new TransactionScope()) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; data.RecStatus = "A"; if (String.IsNullOrEmpty(data.Id)) { data.Creater = curentuser.Id; data.Createtime = DateTime.Now; } data.Modifier = curentuser.Id; data.Modifytime = DateTime.Now; resultEntity = _admGoodsManageService.save(data); scope.Complete(); } return new JsonResult(resultEntity); } public IActionResult Chuku(string id = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; AdmGoodsManageDTO dto = new AdmGoodsManageDTO(); if (!String.IsNullOrEmpty(id)) { dto = _admGoodsManageService.Get(id); } ViewBag.ClassifyId = _admGoodsClassifyService.GetList(); ViewBag.Goods = _admGoodsManageService.GetList().Where(x => x.GoodsStatus == "A").ToList(); ViewBag.GoodsStatus = _liaotianService.GetSYScode("adm_goods_manage", "goods_status"); ViewData.Model = dto; return View(); } /// /// 保存 /// /// 岗位实体类对象 /// /// [HttpPost] public IActionResult ChukuSave(AdmGoodsManageDTO data) { // data.DocContent = data.DocContent.Replace(";", ";"); ResultEntity resultEntity = new ResultEntity(); using (TransactionScope scope = new TransactionScope()) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; AdmGoodsManageDTO savedata = _admGoodsManageService.Get(data.GoodsName); if (savedata.GoodsLeft.HasValue) { savedata.GoodsLeft = savedata.GoodsLeft - data.GoodsCaozuo; } else { savedata.GoodsLeft = 0; } data.Modifier = curentuser.Id; data.Modifytime = DateTime.Now; resultEntity = _admGoodsManageService.save(savedata); scope.Complete(); } return new JsonResult(resultEntity); } public IActionResult Ruku(string id=null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; AdmGoodsManageDTO dto = new AdmGoodsManageDTO(); if (!String.IsNullOrEmpty(id)) { dto = _admGoodsManageService.Get(id); } ViewBag.ClassifyId = _admGoodsClassifyService.GetList(); ViewBag.Goods = _admGoodsManageService.GetList().Where(x => x.GoodsStatus == "A").ToList(); ViewBag.GoodsStatus = _liaotianService.GetSYScode("adm_goods_manage", "goods_status"); ViewData.Model = dto; return View(); } /// /// 保存 /// /// 岗位实体类对象 /// /// [HttpPost] public IActionResult RukuSave(AdmGoodsManageDTO data) { // data.DocContent = data.DocContent.Replace(";", ";"); ResultEntity resultEntity = new ResultEntity(); using (TransactionScope scope = new TransactionScope()) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; AdmGoodsManageDTO savedata = _admGoodsManageService.Get(data.GoodsName); if (savedata.GoodsNum.HasValue) { savedata.GoodsNum = savedata.GoodsNum + data.GoodsCaozuo; } else { savedata.GoodsNum = data.GoodsCaozuo; } if (savedata.GoodsLeft.HasValue) { savedata.GoodsLeft = savedata.GoodsLeft + data.GoodsCaozuo; } else { savedata.GoodsLeft = data.GoodsCaozuo; } data.Modifier = curentuser.Id; data.Modifytime = DateTime.Now; resultEntity = _admGoodsManageService.save(savedata); scope.Complete(); } return new JsonResult(resultEntity); } /// /// 删除主信息 /// /// 实体 /// /// public IActionResult Nullify(string Id = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; return new JsonResult(_admGoodsManageService.ModifyStatus(Id, curentuser.Id)); } } }