using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Dynamic; using System.Data; using Bowin.Common.Mvc; using Bowin.Common.Utility; using Bowin.Common.Data; using Bowin.Web.Controls.Mvc; using EMIS.Utility; using EMIS.Web.Controls; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.StudentChange; using EMIS.CommonLogic.StudentManage.StudentChange; namespace EMIS.Web.Controllers.StudentManage.StudentChange { [Authorization] public class ChangeTotalController : JsonNetController { public Lazy ChangeTotalServices { get; set; } /// /// 异动统计页面 /// /// public ActionResult List() { var changeTypeDisPlayList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType).Where(x => x.RecordStatus >= 1).ToList(); ViewBag.ChangeTypeList = changeTypeDisPlayList; return View(); } /// /// 异动统计列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var schoolyearID = pararms.getExtraGuid("SchoolyearDropdown"); var campusID = pararms.getExtraGuid("CampusDropdown"); var collegeID = pararms.getExtraGuid("CollegeDropdown"); var changeTotalViewList = ChangeTotalServices.Value.GetChangeTotalViewList(configuretView, schoolyearID, campusID, collegeID); var camColList = changeTotalViewList.Select(x => new { x.CampusID, x.CampusCode, x.CampusName, x.CollegeID, x.CollegeNo, x.CollegeName }).OrderBy(x => x.CollegeNo).Distinct().ToList(); var changeTypeDisPlayList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType).Where(x => x.RecordStatus >= 1).ToList(); var dblist = new List(); foreach (var camCol in camColList) { dynamic item = new ExpandoObject(); ((IDictionary)item).Add("CampusID", camCol.CampusID); ((IDictionary)item).Add("CampusCode", camCol.CampusCode); ((IDictionary)item).Add("CampusName", camCol.CampusName); ((IDictionary)item).Add("CollegeID", camCol.CollegeID); ((IDictionary)item).Add("CollegeNo", camCol.CollegeNo); ((IDictionary)item).Add("CollegeName", camCol.CollegeName); var changeTypeTotal = 0; foreach (var changeTypeDisPlay in changeTypeDisPlayList) { var changeTotalView = changeTotalViewList.Where(x => x.CollegeID == camCol.CollegeID && x.ChangeTypeID == changeTypeDisPlay.Value).SingleOrDefault(); changeTypeTotal += (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount.Value); ((IDictionary)item).Add("ChangeType_" + changeTypeDisPlay.Value, (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount).ToString()); } ((IDictionary)item).Add("ChangeTypeTotal", changeTypeTotal.ToString()); dblist.Add(item); } return Json(new { total = dblist.Count, rows = dblist }); } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var schoolyearID = Request.Form["SchoolyearDropdown"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["SchoolyearDropdown"].ParseStrTo(); var campusID = Request.Form["CampusDropdown"].ParseStrTo(); var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); var changeTotalViewList = ChangeTotalServices.Value.GetChangeTotalViewList(configuretView, schoolyearID, campusID, collegeID); var camColList = changeTotalViewList.Select(x => new { x.CampusID, x.CampusCode, x.CampusName, x.CollegeID, x.CollegeNo, x.CollegeName }).OrderBy(x => x.CollegeNo).Distinct().ToList(); var changeTypeDisPlayList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType).Where(x => x.RecordStatus >= 1).ToList(); var dt = new DataTable(); dt.Columns.Add("CampusCode", typeof(string)); dt.Columns.Add("CampusName", typeof(string)); dt.Columns.Add("CollegeNo", typeof(string)); dt.Columns.Add("CollegeName", typeof(string)); foreach (var changeTypeDisPlay in changeTypeDisPlayList) { dt.Columns.Add("Change_" + changeTypeDisPlay.Value, typeof(string)); } dt.Columns.Add("ChangeTypeTotal", typeof(string)); foreach (var camCol in camColList) { DataRow dr = dt.NewRow(); dr["CampusCode"] = camCol.CampusCode; dr["CampusName"] = camCol.CampusName; dr["CollegeNo"] = camCol.CollegeNo; dr["CollegeName"] = camCol.CollegeName; var changeTypeTotal = 0; foreach (var changeTypeDisPlay in changeTypeDisPlayList) { var changeTotalView = changeTotalViewList.Where(x => x.CollegeID == camCol.CollegeID && x.ChangeTypeID == changeTypeDisPlay.Value).SingleOrDefault(); changeTypeTotal += (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount.Value); dr["Change_" + changeTypeDisPlay.Value] = (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount).ToString(); } dr["ChangeTypeTotal"] = changeTypeTotal.ToString(); dt.Rows.Add(dr); } var liststring = new List { RSL.Get("CampusCode"), RSL.Get("Campus"), RSL.Get("CollegeCode"), RSL.Get("College") }; foreach (var changeTypeDisPlay in changeTypeDisPlayList) { liststring.Add(changeTypeDisPlay.Name); } liststring.Add("总数"); neh.Export(dt, liststring.ToArray(), "异动统计信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }