using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using Bowin.Common.JSON;
using EMIS.Utility;
using EMIS.Web.Controls;
using EMIS.ViewModel;
using EMIS.ViewModel.SchedulingManage;
using EMIS.CommonLogic.SchedulingManage.SchedulingSettings;
namespace EMIS.Web.Controllers.SchedulingManage.SchedulingSettings
{
[Authorization]
public class CollegePriorityController : Controller
{
public ICollegePriorityServices CollegePriorityServices { get; set; }
///
/// 院系控制页面
///
///
public ActionResult List()
{
return View();
}
///
/// 院系控制列表查询
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown");
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var dateRange = pararms.getExtraDateTime("txtDateRange");
return Json(CollegePriorityServices.GetCollegePriorityViewGrid(configuretView, campusID, collegeID,
dateRange, (int)pararms.page, (int)pararms.rows));
}
///
/// 复制新增
///
///
///
public ActionResult CopyAdd(Guid collegePriorityID)
{
CollegePriorityView collegePriorityView = new CollegePriorityView();
collegePriorityView = CollegePriorityServices.GetCollegePriorityView(collegePriorityID);
return View("Edit", collegePriorityView);
}
///
/// 复制新增
///
///
///
[HttpPost]
public ActionResult CopyAdd(CollegePriorityView collegePriorityView)
{
collegePriorityView.CollegePriorityID = Guid.Empty;
return this.Edit(collegePriorityView);
}
///
/// 编辑(新增、修改)
///
///
///
public ActionResult Edit(Guid? collegePriorityID)
{
CollegePriorityView collegePriorityView = new CollegePriorityView();
if (collegePriorityID.HasValue && collegePriorityID != Guid.Empty)
{
collegePriorityView = CollegePriorityServices.GetCollegePriorityView(collegePriorityID);
}
else
{
collegePriorityView.Priority = 1;
collegePriorityView.StartDate = DateTime.Now;
collegePriorityView.EndDate = DateTime.Now.AddMonths(1);
}
return View(collegePriorityView);
}
///
/// 编辑(新增、修改)
///
///
///
[HttpPost]
public ActionResult Edit(CollegePriorityView collegePriorityView)
{
try
{
CollegePriorityServices.CollegePriorityEdit(collegePriorityView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// 院系控制信息批量新增
///
///
[HttpGet]
public ActionResult CollegePriorityBatchAdd()
{
CollegePriorityView collegePriorityView = new CollegePriorityView();
collegePriorityView.Priority = 1;
collegePriorityView.StartDate = DateTime.Now;
collegePriorityView.EndDate = DateTime.Now.AddMonths(1);
return View(collegePriorityView);
}
///
/// 院系控制信息批量新增
///
///
///
public ActionResult CollegePriorityBatchAdd(CollegePriorityView collegePriorityView)
{
try
{
var collegeIDList = Request["collegeIDList"].JsonToObject>();
string result = CollegePriorityServices.CollegePriorityBatchAdd(collegeIDList, collegePriorityView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "新增成功" + result + "。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "新增失败,原因:" + ex.Message
});
}
}
///
/// 查询对应的未新增院系所信息CollegeView
///
///
///
[HttpPost]
public ActionResult CollegeNoAddList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown");
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory");
return base.Json(CollegePriorityServices.GetCollegeViewNoAddGrid(configuretView, campusID, collegeID,
unitCategoryID, (int)pararms.page, (int)pararms.rows));
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string collegePriorityIDs)
{
try
{
List list = collegePriorityIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
.Select(x => (Guid?)new Guid(x)).ToList();
CollegePriorityServices.CollegePriorityDelete(list);
return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
}
catch (Exception ex)
{
return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + ex.Message });
}
}
///
/// Excel导出
///
///
[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 dateRange = Request.Form["txtDateRange"].ParseStrTo();
var dt = CollegePriorityServices.GetCollegePriorityViewList(configuretView, campusID, collegeID, dateRange)
.Select(x => new
{
x.CollegeNo,
x.CollegeName,
x.UnitCategoryName,
x.Priority,
x.CampusNo,
x.CampusName,
StartDate = x.StartDate == null ? null : x.StartDate.Value.ToString("yyyy-MM-dd"),
EndDate = x.EndDate == null ? null : x.EndDate.Value.ToString("yyyy-MM-dd"),
x.OpenDays,
x.CreateUserName
}).ToTable();
string[] liststring = {
RSL.Get("CollegeCode"), RSL.Get("CollegeName"), "单位类别", "优先级",
RSL.Get("CampusCode"), RSL.Get("CampusName"), "开始日期", "结束日期",
"开放天数", "创建人"
};
neh.Export(dt, liststring, "院系控制信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
}
}