/* * 仓库库存变动信息 */ using System; using System.Web; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Data; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MySystem.Models; using Library; using LitJson; using MySystemLib; namespace MySystem.Areas.Admin.Controllers { [Area("Admin")] [Route("Admin/[controller]/[action]")] public class StoreBalanceController : BaseController { public StoreBalanceController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 仓库库存变动信息列表 /// /// 根据条件查询仓库库存变动信息列表 /// /// public IActionResult Index(StoreBalance data, string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } #endregion #region 根据条件查询仓库库存变动信息列表 /// /// 仓库库存变动信息列表 /// /// public JsonResult IndexData(StoreBalance data, string StoreIdStoreNo, string StoreIdStoreName, string TransTypeSelect, string CreateDateData, string BrandIdSelect, int page = 1, int limit = 30) { Dictionary Fields = new Dictionary(); Fields.Add("TransRecordNo", "1"); //交易流水编号 string condition = " and Status>-1"; //仓库仓库编号 if (!string.IsNullOrEmpty(StoreIdStoreNo)) { condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')"; } //仓库仓库名称 if (!string.IsNullOrEmpty(StoreIdStoreName)) { condition += " and StoreId in (select StoreId from StoreForStoreName where Name='" + StoreIdStoreName + "')"; } //操作时间 if(!string.IsNullOrEmpty(CreateDateData)) { string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None); string start = datelist[0]; string end = datelist[1]; condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'"; } //交易类型 if (!string.IsNullOrEmpty(TransTypeSelect)) { condition += " and TransType=" + TransTypeSelect; } //产品类型 if (!string.IsNullOrEmpty(BrandIdSelect)) { condition += " and BrandId=" + BrandIdSelect; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreBalance", Fields, "Id desc", "0", page, limit, condition); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //仓库 int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString())); StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse(); dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo; dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName; dic.Remove("StoreId"); //交易类型 int TransType = int.Parse(dic["TransType"].ToString()); if (TransType == 0) dic["TransType"] = "入库"; if (TransType == 1) dic["TransType"] = "调拨"; if (TransType == 2) dic["TransType"] = "出货"; //产品类型 dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString())); //操作符 string OpSymbol = dic["OpSymbol"].ToString(); if (OpSymbol == "1") dic["OpSymbol"] = "增加"; if (OpSymbol == "2") dic["OpSymbol"] = "减少"; if (OpSymbol == "") dic["OpSymbol"] = ""; } Dictionary other = new Dictionary(); int InCount = 0;//入库 int MoveInCount = 0;//调拨入库 int MoveOutCount = 0;//调拨出库 int OutCount = 0;//出库 DataTable dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=0" + condition); if (dt.Rows.Count > 0) { InCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString())); } dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=1 and OpSymbol='+'" + condition); if (dt.Rows.Count > 0) { MoveInCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString())); } dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=1 and OpSymbol='-'" + condition); if (dt.Rows.Count > 0) { MoveOutCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString())); } dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=2" + condition); if (dt.Rows.Count > 0) { OutCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString())); } other.Add("InCount", InCount); other.Add("MoveInCount", MoveInCount); other.Add("MoveOutCount", MoveOutCount); other.Add("OutCount", OutCount); obj.Add("other", other); return Json(obj); } #endregion #region 增加仓库库存变动信息 /// /// 增加或修改仓库库存变动信息信息 /// /// public IActionResult Add(string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } #endregion #region 增加仓库库存变动信息 /// /// 增加或修改仓库库存变动信息信息 /// /// [HttpPost] public string Add(StoreBalance data) { Dictionary Fields = new Dictionary(); Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreBalance", Fields, 0); AddSysLog(data.Id.ToString(), "StoreBalance", "add"); db.SaveChanges(); return "success"; } #endregion #region 修改仓库库存变动信息 /// /// 增加或修改仓库库存变动信息信息 /// /// public IActionResult Edit(string right, int Id = 0) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; StoreBalance editData = db.StoreBalance.FirstOrDefault(m => m.Id == Id) ?? new StoreBalance(); ViewBag.data = editData; return View(); } #endregion #region 修改仓库库存变动信息 /// /// 增加或修改仓库库存变动信息信息 /// /// [HttpPost] public string Edit(StoreBalance data) { Dictionary Fields = new Dictionary(); Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, data.Id); AddSysLog(data.Id.ToString(), "StoreBalance", "update"); db.SaveChanges(); return "success"; } #endregion #region 删除仓库库存变动信息信息 /// /// 删除仓库库存变动信息信息 /// /// public string Delete(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "StoreBalance", "del"); foreach (string subid in idlist) { int id = int.Parse(subid); Dictionary Fields = new Dictionary(); Fields.Add("Status", -1); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 开启 /// /// 开启 /// /// public string Open(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "StoreBalance", "open"); foreach (string subid in idlist) { int id = int.Parse(subid); Dictionary Fields = new Dictionary(); Fields.Add("Status", 1); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 关闭 /// /// 关闭 /// /// public string Close(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "StoreBalance", "close"); foreach (string subid in idlist) { int id = int.Parse(subid); Dictionary Fields = new Dictionary(); Fields.Add("Status", 0); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 排序 /// /// 排序 /// /// public string Sort(int Id, int Sort) { new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreBalance", Sort, Id); AddSysLog(Id.ToString(), "StoreBalance", "sort"); return "success"; } #endregion #region 导入数据 /// /// 导入数据 /// /// public string Import(string ExcelData) { ExcelData = HttpUtility.UrlDecode(ExcelData); JsonData list = JsonMapper.ToObject(ExcelData); for (int i = 1; i < list.Count; i++) { JsonData dr = list[i]; db.StoreBalance.Add(new StoreBalance() { CreateDate = DateTime.Now, UpdateDate = DateTime.Now, }); db.SaveChanges(); } AddSysLog("0", "StoreBalance", "Import"); return "success"; } #endregion #region 导出Excel /// /// 导出Excel /// /// public JsonResult ExportExcel(StoreBalance data, string StoreIdStoreNo, string StoreIdStoreName, string TransTypeSelect, string BrandIdSelect) { Dictionary Fields = new Dictionary(); Fields.Add("CreateDate", "3"); //时间 Fields.Add("TransRecordNo", "1"); //交易流水编号 string condition = " and Status>-1"; //仓库仓库编号 if (!string.IsNullOrEmpty(StoreIdStoreNo)) { condition += " and StoreId in (select StoreId from StoreForStoreNo where StoreNo='" + StoreIdStoreNo + "')"; } //仓库仓库名称 if (!string.IsNullOrEmpty(StoreIdStoreName)) { condition += " and StoreId in (select StoreId from StoreForStoreName where StoreName='" + StoreIdStoreName + "')"; } //交易类型 if (!string.IsNullOrEmpty(TransTypeSelect)) { condition += " and TransType=" + TransTypeSelect; } //产品类型 if (!string.IsNullOrEmpty(BrandIdSelect)) { condition += " and BrandId=" + BrandIdSelect; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreBalance", Fields, "Id desc", "0", 1, 20000, condition, "StoreId,TransRecordNo,TransType,BrandId,OpStoreNum,OpSymbol,BeforeTotalNum,AfterTotalNum,BeforeLaveNum,AfterLaveNum,BeforeOutNum,AfterOutNum", false); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //仓库 int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString())); StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse(); dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo; dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName; dic.Remove("StoreId"); //交易类型 int TransType = int.Parse(dic["TransType"].ToString()); if (TransType == 0) dic["TransType"] = "入库"; if (TransType == 1) dic["TransType"] = "调拨"; if (TransType == 2) dic["TransType"] = "出货"; //产品类型 dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString())); //操作符 string OpSymbol = dic["OpSymbol"].ToString(); if (OpSymbol == "1") dic["OpSymbol"] = "增加"; if (OpSymbol == "2") dic["OpSymbol"] = "减少"; if (OpSymbol == "") dic["OpSymbol"] = ""; } Dictionary result = new Dictionary(); result.Add("Status", "1"); result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx"); result.Add("Obj", diclist); Dictionary ReturnFields = new Dictionary(); ReturnFields.Add("StoreIdStoreNo", "仓库仓库编号"); ReturnFields.Add("StoreIdStoreName", "仓库仓库名称"); ReturnFields.Add("TransRecordNo", "交易流水编号"); ReturnFields.Add("TransType", "交易类型"); ReturnFields.Add("BrandId", "产品类型"); ReturnFields.Add("OpStoreNum", "操作库存数"); ReturnFields.Add("OpSymbol", "操作符"); ReturnFields.Add("BeforeTotalNum", "操作前总库存数"); ReturnFields.Add("AfterTotalNum", "操作后总库存数"); ReturnFields.Add("BeforeLaveNum", "操作前剩余库存数"); ReturnFields.Add("AfterLaveNum", "操作后剩余库存数"); ReturnFields.Add("BeforeOutNum", "操作前出库数"); ReturnFields.Add("AfterOutNum", "操作后出库数"); result.Add("Fields", ReturnFields); AddSysLog("0", "StoreBalance", "ExportExcel"); return Json(result); } #endregion } }