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 EMIS.ViewModel.SelectCourse;
using EMIS.Entities;
using Bowin.Common.Exceptions;
using Bowin.Common.Data;
using Bowin.Common.Utility;
using EMIS.Utility;
using EMIS.Utility.FormValidate;
namespace EMIS.Web.Controllers.SelectCourseManage
{
[Authorization]
public class FreeSelectionCourseController : Controller
{
public IFreeSelectionCourseServices FreeSelectionCourseServices { get; set; }
public IFreeSelectionCourseApplyServices FreeSelectionCourseApplyServices { get; set; }
///
/// 任选课程页面
///
///
public ActionResult List()
{
return View();
}
///
/// 查询列表
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var coursematerialID = pararms.getExtraGuid("CoursematerialIDDropdownGridBo");
var departmentID = pararms.getExtraGuid("DepartmentComboGrid");
var schoolcodeID = pararms.getExtraInt("DictionarySchoolcode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolcode");
var starttermID = pararms.getExtraInt("DictionaryStartterm") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStartterm");
var isEnable = pararms.getExtraInt("DictionaryIsEnable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEnable");
return base.Json(FreeSelectionCourseServices.GetFreeSelectionCourseViewGrid(configuretView, coursematerialID, departmentID,schoolcodeID, starttermID, isEnable, (int)pararms.page, (int)pararms.rows));
}
public ActionResult Edit(Guid? freeSelectionCourseIDs,string type)
{
FreeSelectionCourseView freeSelectionCourseView = new FreeSelectionCourseView();
if (freeSelectionCourseIDs.HasValue)
freeSelectionCourseView = FreeSelectionCourseServices.GetFreeSelectionCourseView(freeSelectionCourseIDs);
else
{
var staff = FreeSelectionCourseApplyServices.GetStaff(CustomPrincipal.Current.UserID);
if (staff != null)
{
freeSelectionCourseView.DepartmentID = staff.DepartmentID;
ViewBag.DepartmentID = staff.DepartmentID;
}
freeSelectionCourseView.ResultTypeID = (int)CF_ResultType.Percentage;
}
//默认启用
freeSelectionCourseView.IsEnable = true;
if (freeSelectionCourseIDs.HasValue && type == "copyAdd")
{
freeSelectionCourseView.FreeSelectionCouseID = Guid.Empty;
}
return View(freeSelectionCourseView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(FreeSelectionCourseView freeSelectionCourseView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
if (freeSelectionCourseView.FreeSelectionCouseID == null || freeSelectionCourseView.FreeSelectionCouseID == Guid.Empty)
{
FreeSelectionCourseServices.FreeSelectionCourseAdd(freeSelectionCourseView);
}
else
{
FreeSelectionCourseServices.FreeSelectionCourseUpdate(freeSelectionCourseView);
}
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string freeSelectionCourseIDs)
{
try
{
List list = new List();
for (int i = 0; i < freeSelectionCourseIDs.Split(',').Length; i++)
{
string id = freeSelectionCourseIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid specialtyCourseID = new Guid(id);
list.Add(specialtyCourseID);
}
}
FreeSelectionCourseServices.FreeSelectionCourseDelete(list);
return base.Json("删除成功!");
}
catch (Exception ex)
{
string mge = ex.Message;
System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
if (num != null)
{
if (num.Number == 547)
mge = "请先删除所有关联的数据,如:开课申请、任选设定、选课结果等!";
}
return base.Json("删除失败,原因:" + mge);
}
}
///
/// 导出Excel
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var coursematerialID = Request.Form["CoursematerialIDDropdownGridBo"].ParseStrTo();
var departmentID = Request.Form["DepartmentComboGrid"].ParseStrTo();
var schoolcodeID = Request.Form["DictionarySchoolcode"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolcode"].ParseStrTo();
var starttermID = Request.Form["DictionaryStartterm"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStartterm"].ParseStrTo();
var isEnable = Request.Form["DictionaryIsEnable"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEnable"].ParseStrTo();
var dt = FreeSelectionCourseServices.GetFreeSelectionCourseViewList(configuretView, coursematerialID,departmentID, schoolcodeID, starttermID, isEnable).Select(x => new
{
//x.No,
x.CourseCode,
x.CourseName,
//x.CourseCategoryName,
x.CourseTypeName,
x.CourseQualityName,
x.Credit,
x.Totalhours,
//x.SchoolweeksNum,
//x.SchoolyearNumName,
//x.SchoolcodeName,
//x.StarttermName,
x.TeachingModeName,
x.DepartmentName,
x.IsEnableDesc
}).ToTable();
string[] liststring = { //"选课编号",
"课程代码", "课程名称", //"课程属性",
"课程类型",
"课程性质","学分","总学时",//"上课周数","学年数","学期","开课学期",
"授课方式","教研室","是否启用"};
neh.Export(dt, liststring, "任选课程信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/FreeSelectionCourse/List").AddMenuParameter()
});
}
///
/// 获取已经存在在授课方式
///
///
///
[HttpPost]
public ActionResult TeachingModeType(Guid? freeSelectionCourseID)
{
List list = new List();
if (freeSelectionCourseID.HasValue && freeSelectionCourseID != Guid.Empty)
list = FreeSelectionCourseServices.GetTeachingModeType(freeSelectionCourseID);
else
list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory));
return base.Json(list.ConvertAll(x=>x.ToString()));
}
}
}