using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.MinorManage;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using EMIS.ViewModel.MinorManage.MinorCourseManage;
using Bowin.Common.Exceptions;
using Bowin.Common.Utility;
using EMIS.Utility;
using Bowin.Common.Data;
namespace EMIS.Web.Controllers.MinorManage
{
[Authorization]
public class MinorSpecialtyCourseController : Controller
{
public IMinorSpecialtyCourseServices minorSpecialtyCourseServices { get; set; }
//
// GET: /MinorCourse/
public ActionResult List()
{
return View();
}
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
var coursematerialID = pararms.getExtraGuid("CoursematerialIDDropdownGridBo");
var startYearID = pararms.getExtraInt("DictionarySchoolYearNum") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolYearNum");
var schoolcodeID = pararms.getExtraInt("DictionarySchoolcode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolcode");
var isEnable = pararms.getExtraInt("DictionaryIsEnable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEnable");
var departmentID = pararms.getExtraGuid("DepartmentDropdown");
return this.Json(minorSpecialtyCourseServices.GetMinorSpecialtyCourseViewGrid(configuretView, standardID, coursematerialID, startYearID, schoolcodeID, departmentID, isEnable, (int)pararms.page, (int)pararms.rows));
}
///
/// 复制新增
///
///
///
public ActionResult CopyAdd(Guid sourceMinorCourseID)
{
MinorSpecialtyCourseView minorSpecialtyCourseView = new MinorSpecialtyCourseView();
minorSpecialtyCourseView = minorSpecialtyCourseServices.GetMinorSpecialtyCourseView(sourceMinorCourseID);
minorSpecialtyCourseView.MinorCourseID = null;
return View("Edit", minorSpecialtyCourseView);
}
[HttpPost]
public ActionResult CopyAdd(MinorSpecialtyCourseView minorSpecialtyCourseView)
{
return this.Edit(minorSpecialtyCourseView);
}
///
/// 编辑
///
///
///
public ActionResult Edit(Guid? MinorCourseID)
{
MinorSpecialtyCourseView minorSpecialtyCourseView = new MinorSpecialtyCourseView();
if (MinorCourseID.HasValue)
{
minorSpecialtyCourseView = minorSpecialtyCourseServices.GetMinorSpecialtyCourseView(MinorCourseID);
}
else
{
minorSpecialtyCourseView.ResultTypeID = (int)CF_ResultType.Percentage;
minorSpecialtyCourseView.Credit = 0;
minorSpecialtyCourseView.TheoryCourse = 0;
minorSpecialtyCourseView.Practicehours = 0;
minorSpecialtyCourseView.Trialhours = 0;
minorSpecialtyCourseView.Totalhours = 0;
minorSpecialtyCourseView.TheoryWeeklyNum = 0;
minorSpecialtyCourseView.PracticeWeeklyNum = 0;
minorSpecialtyCourseView.TrialWeeklyNum = 0;
minorSpecialtyCourseView.SchoolweeksNum = 0;
minorSpecialtyCourseView.WeeklyHours = 0;
minorSpecialtyCourseView.WeeklyNum = 0;
minorSpecialtyCourseView.IsEnable = true;
}
return View(minorSpecialtyCourseView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(MinorSpecialtyCourseView minorSpecialtyCourseView)
{
try
{
minorSpecialtyCourseServices.MinorSpecialtyCourseAdd(minorSpecialtyCourseView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 获取已经存在在授课方式
///
///
///
[HttpPost]
public ActionResult TeachingModeType(Guid? MinorCourseID)
{
List list = new List();
if (MinorCourseID.HasValue && MinorCourseID != Guid.Empty)
list = minorSpecialtyCourseServices.GetTeachingModeType(MinorCourseID);
else
list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory).ToString());
return base.Json(list);
}
///
/// 获取已经存在在授课地点
///
///
///
[HttpPost]
public ActionResult TeachingPlace(Guid? MinorCourseID)
{
List list = new List();
if (MinorCourseID.HasValue && MinorCourseID != Guid.Empty)
list = minorSpecialtyCourseServices.GetTeachingPlace(MinorCourseID);
return base.Json(list);
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string MinorCourseIDs)
{
try
{
List list = new List();
for (int i = 0; i < MinorCourseIDs.Split(',').Length; i++)
{
string id = MinorCourseIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid MinorCourseID = new Guid(id);
list.Add(MinorCourseID);
}
}
minorSpecialtyCourseServices.MinorCourseDelete(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();
var MinorCourseID = Request.Form["MinorCourseID"];
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["StandardDictionaryDropDown"].ParseStrTo();
var coursematerialID = Request.Form["CoursematerialIDDropdownGridBo"].ParseStrTo();
var startYearID = Request.Form["DictionarySchoolYearNum"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolYearNum"].ParseStrTo();
var schoolcodeID = Request.Form["DictionarySchoolcode"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolcode"].ParseStrTo();
var isEnable = Request.Form["DictionaryIsEnable"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEnable"].ParseStrTo();
var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo();
List MinorCourseIDList = new List();
if (MinorCourseID != "")
{
MinorCourseIDList = MinorCourseID.SplitIDString();
}
else
{
MinorCourseIDList = null;
}
var dt = minorSpecialtyCourseServices.GetMinorCourseViewList(configuretView, standardID, coursematerialID, startYearID, schoolcodeID, departmentID, isEnable, MinorCourseIDList).Select(x => new
{
x.SpecialtyCode,
x.StandardName,
x.CourseCode,
x.CourseName,
x.CourseTypeName,
x.Credit,
x.TheoryCourse,
x.Practicehours,
x.Trialhours,
x.Totalhours,
x.SchoolyearNumName,
x.SchoolcodeName,
x.DepartmentName,
x.IsEnableName
}).ToTable();
string[] liststring = { "专业代码", "专业名称", "课程代码", "课程名称", "课程类型","学分",
"理论学时","实践学时","实验学时","总学时","开课学年","开课学期","开课教研室","是否启用"};
neh.Export(dt, liststring, "辅修课程信息");
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
#region 辅修课程信息导入
[HttpGet]
public ActionResult Import(string errorFile, string operationTips)
{
ViewBag.ErrorFile = errorFile;
if (string.IsNullOrEmpty(operationTips))
{
operationTips = "错误数据下载";
}
ViewBag.operationTips = operationTips;
return View();
}
[HttpPost]
public ActionResult Import(HttpPostedFileBase file)
{
try
{
//1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
//2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
{
throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
}
#region 构建单元头
Dictionary cellheader = new Dictionary
{
{ "SpecialtyCodeStr", "专业代码" },
{ "StandardNameStr", "专业名称" },
{"CourseCode","课程代码"}, { "CourseName", "课程名称" },
{ "DepartmentName", "教研室" }, { "SchoolyearNumNameStr", "授课年级" },
{ "SchoolcodeStr", "学期" }, { "CourseTypeStr", "课程类型" },
{ "CourseCategoryNameStr", "课程属性" }, { "CourseQualityNameStr", "课程性质" },
{ "CourseStructureNameStr", "课程结构" }, { "CreditStr", "学分" },
{ "TheoryCourseStr", "理论学时" }, { "PracticehoursStr", "实践学时" },
{ "TrialhoursStr", "实验学时" }, { "PracticeTypeNameStr", "实践方式" },
{ "ExaminationModeNameStr", "考试方式" },{ "ResultTypeNameStr", "成绩类型" },
{ "IsSpecialtycoreName", "是否专业核心" },{ "IsCooperationName", "是否校企开发" },
{ "IsRequiredName", "是否课证融通" },/*是否必修课*/{ "IsMainCourseName", "是否学位主干" },
{ "IsElectiveName", "是否选修" },{ "IsNetworkCourseName", "是否网络" },
{ "CourseFineNameStr", "精品课程" },{ "TeachinglanguageNameStr", "授课语言" },
{ "TeachingModeStr", "授课方式" },{ "TeachingPlaceStr", "授课地点" },
{ "Remarks", "备注" }, { "ErrorMessage", "错误信息" }
};
#endregion
string sourceWebPath = FileUploadHelper.UploadFile(file);
var sourcePhysicalPath = Server.MapPath(sourceWebPath);
List errList = new List();
int errCount = 0;
int OkCount = 0;
minorSpecialtyCourseServices.MinorSpecialtyCourseImport(cellheader, out OkCount, out errList, out errCount, sourcePhysicalPath);
System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
if (errList.Count() > 0)
{
//将异常文件路径显示
string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, " 专业课程导入失败文件", sourcePhysicalPath));
ViewBag.ErrorFile = errorWebPath;
string Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", OkCount < 1 ? 0 : OkCount, errCount < 1 ? 0 : errCount);
ViewBag.operationTips = Errinfo;
//return RedirectToAction("Import", new { errorFile = errorWebPath, operationTips = Errinfo });
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = "导入失败!",
url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
});
}
else
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = "导入成功!",
url = Url.Action("List").AddMenuParameter()
});
}
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = "导入失败,原因:" + ex.Message + "!",
url = Url.Action("List").AddMenuParameter()
});
}
}
#endregion
}
}