using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.SelectCourse;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using EMIS.ViewModel.SelectCourse;
using EMIS.Utility;
namespace EMIS.Web.Controllers.SelectCourseManage
{
[Authorization]
public class SelectCourseOpenControlSettingController : Controller
{
public IOpenControlSettingServices OpenControlSettingServices { get; set; }
///
/// 限选控制页面
///
///
public ActionResult List()
{
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 yearID = pararms.getExtraInt("SchoolyearDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SchoolyearDictionaryDropDown");
var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
if (yearID == DropdownList.SELECT_ALL) yearID = null;
if (standardID == DropdownList.SELECT_ALL) standardID = null;
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(OpenControlSettingServices.GetOpenControlSettingViewList(configuretView, schoolYearID,
campusID, collegeID, yearID, standardID, (int)pararms.page, (int)pararms.rows));
}
[HttpPost]
public ActionResult Excel(QueryParamsModel pararms)
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
//避开全选值
var schoolYearID = Request.Form["SchoolyearDropdown"].ParseStrTo();
var campusID = Request.Form["CampusDropdown"].ParseStrTo();
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
var yearID = Request.Form["SchoolyearDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["Year"].ParseStrTo();
var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["Standard"].ParseStrTo();
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
var dt = OpenControlSettingServices.GetOpenControlSettingViewList(configuretView, schoolYearID,
campusID, collegeID, yearID, standardID)
.Select(x => new
{
x.SchoolyearCode,
x.YearName,
x.StandardDesc,
x.CollegeName,
StartTime = x.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"),
EndTime = x.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss"),
x.MaxSelectCount,
x.MinSelectCount,
x.MaxCredit,
x.MinCredit
}).ToTable();
string[] liststring = { "学年学期", "年级", "专业名称", RSL.Get("College"), "开始时间", "结束时间", "门数上限", "门数下限", "学分上限", "学分下限" };
neh.Export(dt, liststring, "网上选课类型设定");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/SelectCourseOpenControlSetting/List").AddMenuParameter()
});
}
public ActionResult Edit(Guid? selectCourseOpenControlSettingID)
{
SelectCourseOpenControlSettingView openControlSettingView = new SelectCourseOpenControlSettingView();
if (selectCourseOpenControlSettingID != null && selectCourseOpenControlSettingID != Guid.Empty)
{
openControlSettingView = OpenControlSettingServices.GetOpenControlSettingViewInfo(selectCourseOpenControlSettingID);
}
else
{
openControlSettingView.MaxSelectCount = 0;
openControlSettingView.MinSelectCount = 0;
openControlSettingView.MaxCredit = 0;
openControlSettingView.MinCredit = 0;
}
return View(openControlSettingView);
}
///
/// 新增
///
///
[HttpPost]
public ActionResult Edit(SelectCourseOpenControlSettingView openControlSettingView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
OpenControlSettingServices.Save(openControlSettingView);
return Json(new ReturnMessage
{
IsSuccess = true,
Message = "保存成功"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string openControlSettingIDs)
{
try
{
var openControlSettingIDList = openControlSettingIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
OpenControlSettingServices.Delete(openControlSettingIDList);
return base.Json("删除成功!");
}
catch (Exception ex)
{
return base.Json("删除失败,原因:" + ex.Message + "。");
}
}
}
}