using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using EMIS.CommonLogic.SelectCourse;
using Bowin.Common.Data;
using Bowin.Common.Utility;
using EMIS.ViewModel.SelectCourse;
namespace EMIS.Web.Controllers.SelectCourseManage
{
[Authorization]
public class SelectCourseTypeSettingController : Controller
{
public ITypeSettingServices TypeSettingServices { get; set; }
///
/// 类型设定页面
///
///
public ActionResult List()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//避开全选值
var schoolYearID = pararms.getExtraGuid("SchoolYear");
var selectCourseTypeID = pararms.getExtraInt("SelectCourseType");
if (selectCourseTypeID == DropdownList.SELECT_ALL) selectCourseTypeID = null;
var recordStatus = pararms.getExtraInt("RecordStatus");
if (recordStatus == DropdownList.SELECT_ALL) recordStatus = null;
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(TypeSettingServices.GetTypeSettingViewList(configuretView, schoolYearID, selectCourseTypeID, recordStatus,
(int)pararms.page, (int)pararms.rows));
}
public ActionResult Edit(Guid? typeSettingID)
{
SelectCourseTypeSettingView typeSettingView = new SelectCourseTypeSettingView();
if (typeSettingID != null && typeSettingID != Guid.Empty)
{
typeSettingView = TypeSettingServices.GetTypeSettingViewInfo(typeSettingID);
}
else
{
typeSettingView.MaxSelectCount = 2;
typeSettingView.MinSelectCount = 0;
typeSettingView.MaxCredit = 0;
typeSettingView.MinCredit = 0;
}
return View(typeSettingView);
}
///
/// 新增
///
///
[HttpPost]
public ActionResult Edit(SelectCourseTypeSettingView typeSettingView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
TypeSettingServices.Save(typeSettingView);
return Json(new ReturnMessage
{
IsSuccess = true,
Message = "保存成功"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string typeSettingIDs)
{
try
{
var typeSettingIDList = typeSettingIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
TypeSettingServices.Delete(typeSettingIDList);
return base.Json("删除成功!");
}
catch (Exception ex)
{
return base.Json("删除失败,原因:" + ex.Message + "。");
}
}
[HttpPost]
public ActionResult Excel(QueryParamsModel pararms)
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
//避开全选值
var schoolYearID = Request.Form["SchoolYear"].ParseStrTo();
var selectCourseTypeID = Request.Form["SelectCourseType"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["SelectCourseType"].ParseStrTo();
var recordStatus = Request.Form["RecordStatus"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["RecordStatus"].ParseStrTo();
var dt = TypeSettingServices.GetTypeSettingViewList(configuretView, schoolYearID, selectCourseTypeID, recordStatus)
.Select(x => new
{
x.SchoolyearCode,
x.SelectCourseTypeDesc,
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,
x.RecordStatusDesc,
x.Remark
}).ToTable();
string[] liststring = { "学年学期", "选修类型", "开始时间", "结束时间",
"门数上限", "门数下限", "学分上限", "学分下限", "是否启用", "备注" };
neh.Export(dt, liststring, "网上选课类型设定");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/SelectCourseTypeSetting/List").AddMenuParameter()
});
}
}
}