using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.TeachingMaterial;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Utility;
using EMIS.ViewModel.TeachingMaterial;
using EMIS.CommonLogic.Cultureplan;
using Bowin.Common.Data;
using Bowin.Common.Exceptions;
using System.IO;
using EMIS.Utility;
using System.Text;
using EMIS.Entities;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.Cultureplan;
namespace EMIS.Web.Controllers.TeachingMaterial
{
[Authorization]
public class TeachingMaterialPoolController : Controller
{
public ITeachingMaterialPoolServices TeachingMaterialPoolServices { get; set; }
public ICoursematerialServices CoursematerialServices { get; set; }
public ICoursematerialServices coursematerialServices { get; set; }
///
/// 教材信息页面
///
///
[HttpGet]
public ActionResult List()
{
return View();
}
public ActionResult StudentList()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
bool? isLate = null;
publishID = pararms.getExtraGuid("PublishDropdown");
coursematerialID = pararms.getExtraGuid("CourseDropdown");
if (pararms.getExtraInt("LateDropdown") != null && pararms.getExtraInt("LateDropdown") != DropdownList.SELECT_ALL)
{
isLate = pararms.getExtraInt("LateDropdown") == 1 ? true : false; ;
}
int? teachingMaterialType = pararms.getExtraInt("TeachingMaterialTypeDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("TeachingMaterialTypeDropdown");
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(TeachingMaterialPoolServices.GetTeachingMaterialPoolViewGrid(configuretView, publishID, coursematerialID, isLate, teachingMaterialType, (int)pararms.page, (int)pararms.rows));
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult StudentList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
return base.Json(TeachingMaterialPoolServices.GetStudentTeachingMaterialViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
}
[HttpPost]
public ActionResult Excel(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
bool? isLate = null;
publishID = Request.Form["PublishDropdown"].ParseStrTo();
coursematerialID = Request.Form["CourseDropdown"].ParseStrTo();
if (Request.Form["LateDropdown"].ParseStrTo() != null && Request.Form["LateDropdown"].ParseStrTo() != DropdownList.SELECT_ALL)
{
isLate = Request.Form["LateDropdown"].ParseStrTo() == 1 ? true : false; ;
}
int? teachingMaterialType = Request.Form["TeachingMaterialTypeDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["TeachingMaterialTypeDropdown"].ParseStrTo();
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
NpoiExcelHelper neh = new NpoiExcelHelper();
var dt = TeachingMaterialPoolServices.GetTeachingMaterialPoolViewExcel(configuretView, publishID, coursematerialID, isLate, teachingMaterialType).Select(x => new
{
x.TeachingMaterialCode,
x.CoursematerialCode,
x.CoursematerialName,
x.TeachingMaterialName,
x.ISBN,
x.TeachingMaterialTypeName,
x.PublishTime,
x.PublishName,
x.Author,
x.Price,
x.IsLateName,
x.Desc
}).ToTable();
string[] liststring = { "教材编号", "课程代码", "课程名称", "教材名称", "ISBN", "教材类型", "版本时间",
"出版单位","作者","单价","是否过期","备注"};
neh.Export(dt, liststring, "教材总库信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/TeachingMaterialPool/List").AddMenuParameter()
});
}
[HttpPost]
public ActionResult StudentExcel(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
NpoiExcelHelper neh = new NpoiExcelHelper();
var dt = TeachingMaterialPoolServices.GetStudentTeachingMaterialViewList(configuretView).Select(x => new
{
x.SchoolYearCode,
x.CourseName,
x.TeachingMaterialName,
x.PublishTime,
x.ISBN,
x.PublishName,
x.Price
}).ToTable();
string[] liststring = { "学年学期", "课程名称", "教材名称", "版本", "ISBN", "出版单位", "价格" };
neh.Export(dt, liststring, "课程教材信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/ TeachingMaterialPool/StudentList").AddMenuParameter()
});
}
///
/// 编辑页面
///
///
[HttpGet]
public ActionResult Edit(Guid? teachingMaterialPoolID)
{
TeachingMaterialPoolView TeachingMaterialPoolView;
if (teachingMaterialPoolID != null && teachingMaterialPoolID != Guid.Empty)
{
TeachingMaterialPoolView = TeachingMaterialPoolServices.GetSingleTeachingMaterialPool(teachingMaterialPoolID.Value);
}
else
{
string code = TeachingMaterialPoolServices.GetLastTeachingMaterialCode();
TeachingMaterialPoolView = new TeachingMaterialPoolView()
{
TeachingMaterialPoolID = Guid.Empty,
TeachingMaterialCode = code,
IsLate = false
};
}
return View(TeachingMaterialPoolView);
}
///
/// 新增
///
///
[HttpPost]
public ActionResult Edit(TeachingMaterialPoolView TeachingMaterialPoolView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
var coursematerialList = DataGrid.GetTableData("dgCoursematerialList");
if (coursematerialList.Count == 0)
{
throw new Exception("没有选择课程");
}
TeachingMaterialPoolServices.EditTeachingMaterialPool(TeachingMaterialPoolView, user.UserID, coursematerialList);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string teachingMaterialPoolIDs)
{
try
{
var TeachingMaterialPoolIDList = teachingMaterialPoolIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
TeachingMaterialPoolServices.DeleteTeachingMaterialPool(TeachingMaterialPoolIDList);
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 + "!");
}
}
///
/// 查询教材对应的课程信息
///
///
///
[HttpPost]
public ActionResult GetTeachingMaterialPoolCoursematerialList(Guid? teachingMaterialPoolID)
{
var coursematerialViewList = TeachingMaterialPoolServices.GetTeachingMaterialCoursematerialList(teachingMaterialPoolID);
return base.Json(new GridResultSet { rows = coursematerialViewList, total = coursematerialViewList.Count });
}
///
/// 查询没有过期的教材信息(下拉框条件为出版单位和课程)
///
///
///
[HttpPost]
public ActionResult GetTeachingMaterialPoolIsEffectiveList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
string ISBN = null;
string teachingMaterialName = null;
publishID = pararms.getExtraGuid("PublishDropdown");
coursematerialID = pararms.getExtraGuid("hidCoursematerialID");
ISBN = pararms.getExtraString("txtISBN");
teachingMaterialName = pararms.getExtraString("TeachingMaterialName");
var isCheck = pararms.getExtraString("isCheck") == null ? "true" : pararms.getExtraString("isCheck");
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(TeachingMaterialPoolServices.GetTeachingMaterialPoolForOrder(configuretView, publishID, ISBN, coursematerialID, teachingMaterialName, isCheck, (int)pararms.page, (int)pararms.rows));
}
///
/// 查询启用的课程资料信息
///
///
///
[HttpPost]
public ActionResult CoursematerialList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var courseScienceID = pararms.getExtraInt("DictionaryCourseScience") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseScience");
var courseLevelID = pararms.getExtraInt("DictionaryCourseLevel") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseLevel");
var isEnable = 1;
return base.Json(coursematerialServices.GetCoursematerialViewGrid(configuretView, courseLevelID, courseScienceID, null, isEnable, (int)pararms.page, (int)pararms.rows));
}
#region 13.0 教材信息导入
[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
{
if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
{
throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
}
var excel = new NpoiExcelHelper();
#region 表单头
Dictionary cellheader = new Dictionary
{
{ "TeachingMaterialCode", "教材编号" },
{ "CoursematerialName", "课程名称" },
{ "TeachingMaterialName", "教材名称" },
{ "PublishTime", "版本时间" },
{ "PublishName", "出版单位" }, { "Author", "作者" },
{ "ISBN", "ISBN" },
{ "Price", "单价" }, { "TeachingMaterialTypeName", "教材类型" },
{ "WnningLevelName", "获奖级别" }, { "Desc", "备注" }, { "ErrorMessage", "错误信息" }
};
#endregion
StringBuilder errorMsg = new StringBuilder(); // 错误信息
string sourceWebPath = FileUploadHelper.UploadFile(file);
var sourcePhysicalPath = Server.MapPath(sourceWebPath);
List errList = new List();
List dataList = new List();
int errCount = 0;
int OkCount = 0;
TeachingMaterialPoolServices.TeachingMaterialPoolImport(cellheader, out errCount, out errList, out OkCount, sourcePhysicalPath);
System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
if (errCount > 0)
{
var errorPhysicalPath = sourcePhysicalPath;
var errorWebPaths = sourceWebPath;
string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教材操作失败文件", errorWebPaths));
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
}
}
}