using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.CalendarManage;
using EMIS.CommonLogic.EducationSchedule;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Utility;
using System.Text;
using EMIS.Utility;
using Bowin.Common.Data;
using EMIS.ViewModel.EducationManagement;
using EMIS.ViewModel.EducationManage;
using Bowin.Common.Exceptions;
namespace EMIS.Web.Controllers.EducationSchedule
{
[Authorization]
public class EducationMissionClassScheduleAdultController : Controller
{
//
// GET: /EducationMissionClassScheduleAdult/
public ISchoolYearServices SchoolYearServices { get; set; }
public IEducationMissionClassScheduleAdultServices IEducationMissionClassScheduleAdultServices { get; set; }
public ActionResult List()
{
var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
return View();
}
#region 查询任务班排课列表
///
/// 查询任务班排课列表
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var schoolyearID = pararms.getExtraGuid("SchoolyearDropdownList");
var coursematerialID = pararms.getExtraGuid("CoursematerialComboGrid");
var campusID = pararms.getExtraGuid("ComboGridCampus");
var collegeID = pararms.getExtraGuid("ComboGridCollege");
var StandardID = pararms.getExtraInt("DictionaryStandard");
var departmentID = pararms.getExtraGuid("DepartmentDropdown");
var grademajorID = pararms.getExtraGuid("GrademajorComboGrid");
var gradeYearID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
var approvalStatus = pararms.getExtraInt("ApprovalStatusDropdownList") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ApprovalStatusDropdownList");
var teachingMode = pararms.getExtraInt("DictionaryTeachingMode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTeachingMode");
var CoursesTimeID = pararms.getExtraGuid("TimeComboGrid");
var learningformID = pararms.getExtraInt("LearningformDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("LearningformDictionaryDropDown");
var education = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
var LearnSystem = pararms.getExtraString("DictionaryLearnSystem");
var result = IEducationMissionClassScheduleAdultServices.GetEducationMissionClassScheduleViewGrid(configuretView, campusID, collegeID, schoolyearID, departmentID, coursematerialID, approvalStatus, teachingMode, grademajorID, gradeYearID, StandardID, CoursesTimeID,learningformID,education,LearnSystem, (int)pararms.page, (int)pararms.rows);
return Json(result);
}
#endregion
[HttpPost]
public ActionResult Delete(string educationMissionClassIDs)
{
try
{
List list = new List();
var educationMissionClassArray = educationMissionClassIDs.Split(',');
for (int i = 0; i < educationMissionClassArray.Length; i++)
{
if (!string.IsNullOrEmpty(educationMissionClassArray[i]))
{
Guid? educationMissionClassID = new Guid(educationMissionClassArray[i]);
list.Add(educationMissionClassID);
}
}
IEducationMissionClassScheduleAdultServices.EducationMissionClassScheduleDelete(list);
return Json(new ReturnMessage { IsSuccess = true });
}
catch (Exception ex)
{
string mge = ex.Message;
System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
if (num != null)
{
if (num.Number == 547)
mge = "请先删除所有关联的数据,排课课表,学生成绩,教学评价等";
}
return Json(new ReturnMessage { IsSuccess = false, Message = "删除失败:" + mge });
}
}
[HttpGet]
public ActionResult Import(string errorFile, string operationTips)
{
ViewBag.ErrorFile = errorFile;
var schoolYearView = SchoolYearServices.GetSchoolYearIsCurrent(true);
var schoolyear = SchoolYearServices.GetSchoolYearViewListAfterCurrent().OrderBy(x => x.Code).Where(x => x.Value > schoolYearView.Value).FirstOrDefault();
EducationMissionImportClassView classView = new EducationMissionImportClassView();
if (schoolyear != null)
{
classView.SchoolyearID = schoolyear.SchoolYearID;
}
else
{
classView.SchoolyearID = schoolYearView.SchoolyearID;
}
if (string.IsNullOrEmpty(operationTips))
{
operationTips = "错误数据下载";
}
ViewBag.operationTips = operationTips;
return View(classView);
}
#region 导入
[HttpPost]
public ActionResult Import(HttpPostedFileBase file,EducationMissionClassView classView)
{
try
{
Guid schoolyearID = (Guid)classView.SchoolyearID;
//1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
//2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
{
throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
}
StringBuilder errorMsg = new StringBuilder(); // 错误信息
string sourceWebPath = FileUploadHelper.UploadFile(file);
var sourcePhysicalPath = Server.MapPath(sourceWebPath);
List errList = new List();
int errCount = 0;//失败条数
int OkCount = 0;//成功条数
string errorWebPath = "";
string Errinfo = "";
IEducationMissionClassScheduleAdultServices.EducationMissionClassImport(out errCount, out errList, out OkCount, sourcePhysicalPath, sourceWebPath, out errorWebPath, out Errinfo,schoolyearID);
System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
if (errCount > 0)
{
ViewBag.ErrorFile = errorWebPath;
ViewBag.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
#region 2.0 Excel导出
///
/// 导出Excel
///
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var EducationMissionClassID = Request.Form["EducationMissionClassID"];
var campusID = Request.Form["ComboGridCampus"].ParseStrTo();
var collegeID = Request.Form["ComboGridCollege"].ParseStrTo();
var coursematerialID = Request.Form["CoursematerialComboGrid"].ParseStrTo();
var grademajorID = Request.Form["GrademajorComboGrid"].ParseStrTo();
var gradeYearID = Request.Form["DictionaryGrade"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo();
var schoolyearID = Request.Form["SchoolyearDropdownList"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["SchoolyearDropdownList"].ParseStrTo();
var approvalStatus = Request.Form["ApprovalStatusDropdownList"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["ApprovalStatusDropdownList"].ParseStrTo();
var teachingModeID = Request.Form["DictionaryTeachingMode"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryTeachingMode"].ParseStrTo();
var StandardID = Request.Form["DictionaryStandard"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo();
var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo();
List EducationMissionClassList =new List();
var CoursesTimeID = Request.Form["TimeComboGrid"].ParseStrTo();
var learningformID = Request.Form["LearningformDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["LearningformDictionaryDropDown"].ParseStrTo();
var education = Request.Form["DictionaryEducation"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo();
var LearnSystem = Request.Form["DictionaryLearnSystem"].ToString();
if (EducationMissionClassID != "")
{
EducationMissionClassList = EducationMissionClassID.SplitIDString();
}
else
{
EducationMissionClassList = null;
}
var dt = IEducationMissionClassScheduleAdultServices.GetEducationMissionClassScheduleViewGridExcel(configuretView, campusID, collegeID, schoolyearID, departmentID, coursematerialID, approvalStatus, teachingModeID, grademajorID, gradeYearID, StandardID, EducationMissionClassList, CoursesTimeID, learningformID, education, LearnSystem).Select(x => new
{
x.CollegeName,
x.EducationName,
x.LearningformName,
x.ClassNum,
x.Name,
x.CourseName,
x.Totalhours,
x.ExamDay,
x.date,
x.showClassRoom,
x.TeacherNames,
x.ExaminationModeName,
x.ExamWeekShow,
x.Examedate_time,
x.Assistant,
x.StandardName,
x.CourseCode,
courseTimeShow = x.CourseTimeShow,
x.TheoryCourse,
x.Practicehours,
teachingDay = x.TeachingDay,
teachingHours = x.TeachingHours
}).ToTable();
string[] liststring = { RSL.Get("College"), RSL.Get("CultureModel"),"学习形式","班级人数", "任务班名称",
"课程名称", "总学时","参考天数","上课时间","课室",
"授课教师", "考试方式","考试周次","考试时间",
"班主任","年级专业","课程代码","课时类别", "理论学时" ,
"实践学时", "执行天数","执行学时"};
neh.Export(dt, liststring, "教学任务班基础信息");
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功!"
});
}
#endregion
}
}