using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.Students;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using EMIS.Utility;
using System.Dynamic;
using EMIS.ViewModel.DifferentDynamic;
using Bowin.Common.Mvc;
using Bowin.Common.Utility;
using Bowin.Common.Linq;
using EMIS.Entities;
namespace EMIS.Web.Controllers.DifferentDynamic
{
///
/// 异动统计
///
[Authorization]
public class DifferentDynamicStatisticsController : JsonNetController
{
public IDifferentDynamicServices DifferentDynamicServices { get; set; }
///
///
///
///
public ActionResult List()
{
var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType);
ViewBag.DifferentDynamicTypes = differentDynamicTypes;
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
var configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown"); //校区
var collegeID = pararms.getExtraGuid("CollegeDropdown"); //院系所
var schoolYearID = pararms.getExtraGuid("SchoolYearDropdown"); //异动学期
var result = DifferentDynamicServices.GetDifferentDynamicStatistics(configuretView, campusID, collegeID, schoolYearID);
var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType);
var list = WrapResult(result, differentDynamicTypes);
return Json(new { total = list.Count, rows = list });
}
///
///
///
///
///
///
private List WrapResult(ICollection result, IEnumerable differentDynamicTypes)
{
var list = new List();
if (result == null || result.Count == 0)
{
return list;
}
var colleges = result.Select(s => new { s.CollegeID, s.CollegeName }).OrderBy(o => o.CollegeName).Distinct().ToList();
foreach (var college in colleges)
{
dynamic item = new ExpandoObject();
item.CollegeName = college.CollegeName;
DifferentDynamicStatisticsView covarianceItem = null;
foreach (var differentDynamicType in differentDynamicTypes)
{
covarianceItem = result.FirstOrDefault(w => w.CollegeID == college.CollegeID && w.DifferentDynamicType == differentDynamicType.Value);
var quantity = covarianceItem == null ? 0 : covarianceItem.Quantity;
((IDictionary)item).Add("Item" + differentDynamicType.Value, quantity.ToString());
}
list.Add(item);
}
return list;
}
///
///
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var campusID = Request.Form["CampusDropdown"].ParseStrTo(); //校区
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); //院系所
var schoolYearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); //异动学期
var result = DifferentDynamicServices.GetDifferentDynamicStatistics(configuretView, campusID, collegeID, schoolYearID);
var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType);
var dt = WrapResult(result, differentDynamicTypes).ToTable();
var columns = new List { RSL.Get("College") };
foreach (var item in differentDynamicTypes)
{
columns.Add(item.Name);
}
neh.Export(dt, columns.ToArray(), "异动统计");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Action("List").AddMenuParameter()
});
}
}
}