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 System.Data;
using EMIS.CommonLogic.CalendarManage;
namespace EMIS.Web.Controllers.TeachingMaterial
{
public class StockInStatisticsController : Controller
{
public IStockInDetailServices StockInDetailServices { 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;
Guid? teachingMaterialID = null;
supplierID = pararms.getExtraGuid("PublishDropdown");
schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
teachingMaterialID = pararms.getExtraGuid("TeachingMaterialDropdown");
return base.Json(StockInDetailServices.GetStockInStatisticsViewGrid(configuretView, schoolyearID, supplierID, teachingMaterialID, (int)pararms.page, (int)pararms.rows));
}
#region 2.0 页面数据Excel导出
///
/// Excel 导出
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
Guid? supplierID = null;
Guid? schoolyearID = null;
Guid? teachingMaterialID = null;
supplierID = Request.Form["PublishDropdown"].ParseStrTo();
schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo();
teachingMaterialID = Request.Form["TeachingMaterialDropdown"].ParseStrTo();
var dt = StockInDetailServices.GetStockInStatisticsVieList(configuretView, schoolyearID, supplierID, teachingMaterialID).Select(x => new
{
x.SchoolyearName,
//x.StockInDocumentNo,
//x.StockInType,
x.TeachingMaterialCode,
x.TeachingMaterialName,
x.SupplierName,
x.PublishName,
x.PublishTime,
x.Author,
x.Quantity,
x.Price,
x.DiscountStr,
x.DiscountPriceStr,
x.TotalPriceStr,
x.TotalDollarStr
//x.HandlerUserName,
//x.StockInUserName,
//x.StockInTime
}).ToTable();
int sumQuantity = 0;
decimal sumTotalPrice = 0;
decimal sumTotalDollar = 0;
foreach(DataRow dr in dt.Rows)
{
int quantity = (int)dr["Quantity"];
decimal totalPrice = (decimal)dr["TotalPriceStr"];
decimal totalDollar = (decimal)dr["TotalDollarStr"];
sumQuantity += quantity;
sumTotalPrice += totalPrice;
sumTotalDollar += totalDollar;
}
//新增合计数量、码洋、实洋的行
DataRow newrow = dt.NewRow();
newrow["SchoolyearName"] = "";
newrow["TeachingMaterialCode"] = "";
newrow["TeachingMaterialName"] = "";
newrow["SupplierName"] = "";
newrow["PublishName"] = "";
newrow["PublishTime"] = "";
newrow["Author"] = "";
newrow["Quantity"] = sumQuantity;
newrow["Price"] = DBNull.Value;
newrow["DiscountStr"] = DBNull.Value;
newrow["DiscountPriceStr"] = DBNull.Value;
newrow["TotalPriceStr"] = sumTotalPrice;
newrow["TotalDollarStr"] = sumTotalDollar;
dt.Rows.Add(newrow);
string[] liststring = { "学年学期", "教材编号", "教材名称", "供应商",
"出版单位", "版本时间", "作者", "数量", "单价", "折扣率", "折合价", "码洋", "实洋" };
neh.Export(dt, liststring, "入库明细信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/StockInDetail/List").AddMenuParameter()
});
}
#endregion
}
}