using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Common.Utility;
using Bowin.Web.Controls.Mvc;
using EMIS.CommonLogic.TeachingMaterial;
using EMIS.ViewModel;
using EMIS.ViewModel.TeachingMaterial;
using EMIS.Web.Controls;
using Bowin.Common.Data;
using EMIS.CommonLogic.SystemServices;
using EMIS.CommonLogic.CalendarManage;
namespace EMIS.Web.Controllers.TeachingMaterial
{
[Authorization]
public class TeacherRetailController : Controller
{
public IStockOutServices StockOutServices { get; set; }
public ISerialNumberServices SerialNumberServices { get; set; }//编号生成
public IStockInDetailServices StockInDetailServices { get; set; }
public IStockInServices StockInServices { get; set; }
public ISchoolYearServices SchoolYearServices { get; set; }
///
/// 教材零售页面
///
///
[HttpGet]
public ActionResult List()
{
//默认当前学年
var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();
return View();
}
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//避开全选值
Guid? supplierID = null;
Guid? schoolyearID = null;
DateTime? startStockInTime = DateTime.Now;
DateTime? endStockInTime = DateTime.Now;
supplierID = pararms.getExtraGuid("LibraryDropdown");//书库ID
schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");//学年
endStockInTime = pararms.getExtraDateTime("EndStockInTime");
startStockInTime = pararms.getExtraDateTime("StartStockInTime");
return base.Json(StockOutServices.GetStockOutViewGrid(configuretView, schoolyearID, new List { (int)CF_StockOutType.TeachingMaterialRetail }, supplierID, startStockInTime, endStockInTime, (int)pararms.page, (int)pararms.rows));
}
///
///
///
///
///
[HttpGet]
public ActionResult Edit(Guid? stockOutID)
{
var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
StockOutView stockOutView = new StockOutView();
if (stockOutID != null && stockOutID != Guid.Empty)
{
stockOutView = StockOutServices.GetSingleStockOut(stockOutID.Value);
}
else
{
stockOutView = new StockOutView()
{
OutNumber = 1,
StockOutID = Guid.Empty,
StockOutNo = StockOutServices.GetStockOutNo(CF_StockOutType.TeachingMaterialRetail),
SchoolyearID = schoolYear.SchoolyearID,
StockOutTime = DateTime.Now
};
}
return View(stockOutView);
}
///
///
///
///
///
[HttpPost]
public ActionResult Edit(StockOutView stockOutView)
{
try
{
string type = Request.Params["hid_ActionsType"];//0 保存 1 提交
string time = DateTime.Now.ToString("yyyy-MM-dd");
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
var TMList = DataGrid.GetTableData("dgStockInTMSelectList");//获取底部列表项数据
//string keyValue = SerialNumberServices.SetSN(time);//格式: 2016-3-25-001
if (TMList.Count <= 0)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "操作失败,原因:教材信息不能为空。"
});
}
else
{
StockOutServices.Save(stockOutView, TMList, user.UserID, type);
}
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// Excel 导出
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
Guid? supplierID = null;
Guid? schoolyearID = null;
supplierID = Request.Form["SupplierDropdown"].ParseStrTo();
schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo();
DateTime? startStockInTime = DateTime.Now;
DateTime? endStockInTime = DateTime.Now;
endStockInTime = DateTime.Parse(Request.Form["EndStockInTime"]);
startStockInTime = DateTime.Parse(Request.Form["StartStockInTime"]);
var dt = StockOutServices.GetStockOutViewList(configuretView, schoolyearID, new List { (int)CF_StockOutType.TeachingMaterialRetail }, supplierID, startStockInTime, endStockInTime).Select(x => new
{
x.StockOutNo,
x.RecordStatusName,
x.SchoolyearName,
x.StockOutTypeName,
x.StockOutSumMoney,
x.RecipientUserName,
x.StockOutUserName,
x.StockOutTime,
x.Desc
}).ToTable();
string[] liststring = { "出库单据号", "是否出库", "学年学期", "出库类型", "单据总金额", "签收人", "经手人", "零售日期", "零售说明" };
neh.Export(dt, liststring, "教材零售信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/TeacherRetail/List").AddMenuParameter()
});
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string stockOutIDs)
{
try
{
var stockOutIDList = stockOutIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
StockOutServices.Delete(stockOutIDList);
return base.Json("删除成功。");
}
catch (Exception ex)
{
string mge = ex.Message;
return base.Json("删除失败,原因:" + mge);
}
}
///
/// 添加教材
///
///
public ActionResult TeachingMaterial()
{
return View();
}
///
///
///
///
[HttpGet]
public ActionResult GetStockOutByTMList()
{
return View();
}
///
///
///
///
///
[HttpPost]
public ActionResult GetStockOutByTMList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
bool? isLate = false;
var teachingMaterialPoolID = pararms.getExtraGuid("TeachingMaterialDropdown");
publishID = pararms.getExtraGuid("PublishDropdown");
coursematerialID = pararms.getExtraGuid("CourseDropdown");
var isSelectMax = pararms.getExtraInt("hidIsSelectMax") == 1;
return base.Json(StockOutServices.GetStockInByTeachingMaterialPoolViewGrid(configuretView, isLate, teachingMaterialPoolID, coursematerialID, isSelectMax, (int)pararms.page, (int)pararms.rows));
}
///
///
///
///
///
[HttpPost]
public ActionResult GetTMViewList(Guid? stockOutID)
{
if (stockOutID.HasValue)
{
var resultList = StockOutServices.GetStockOutByTMViewList(stockOutID.Value);
return Json(new JsonDataGridResult { rows = resultList, total = resultList.Count });
}
else
{
return Json(new JsonDataGridResult());
}
}
///
/// 提交
///
///
///
[HttpPost]
public ActionResult Submit(string stockOutIDs)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
var stockOutIDList = stockOutIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
StockOutServices.Submit(stockOutIDList, user.UserID);
return base.Json("提交出库成功。");
}
catch (Exception ex)
{
string mge = ex.Message;
return base.Json("提交出库失败,原因:" + mge);
}
}
}
}