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.Common.Data;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Mapping;
using EMIS.ViewModel.SelectCourse;
using EMIS.Utility.FormValidate;
using Bowin.Common.Exceptions;
using Bowin.Common.Utility;
using Bowin.Common.Linq.Entity;
using Bowin.Common.JSON;
using EMIS.Utility;
using EMIS.ViewModel.EnrollManage.SpecialtyManage;
namespace EMIS.Web.Controllers.SelectCourseManage
{
[Authorization]
public class FreeSelectionCourseApplyController : Controller
{
public IFreeSelectionCourseServices FreeSelectionCourseServices { get; set; }
public IFreeSelectionCourseApplyServices FreeSelectionCourseApplyServices { get; set; }
public IExecutableFreeSelectionCouseServices ExecutableFreeSelectionCouseServices { get; set; }
///
/// 开课申请页面
///
///
public ActionResult List()
{
return View();
}
///
/// 查询列表
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown");
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var departmentID = pararms.getExtraGuid("DepartmentDropdown");
var schoolyear = pararms.getExtraGuid("SchoolYearDropdown").ToString() == DropdownList.SELECT_ALL.ToString() ? null : pararms.getExtraGuid("SchoolYearDropdown");
var schoolyearNum = pararms.getExtraInt("DictionarySchoolyearNum").ToString() == DropdownList.SELECT_ALL.ToString() ? null : pararms.getExtraInt("DictionarySchoolyearNum");
var schoolcode = pararms.getExtraInt("DictionarySchoolcode").ToString() == DropdownList.SELECT_ALL.ToString() ? null : pararms.getExtraInt("DictionarySchoolcode");
var approvalStatus = pararms.getExtraInt("DictionaryApprovalStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryApprovalStatus");
return this.Json(FreeSelectionCourseApplyServices.GetFreeSelectionCoursePlanViewGrid(configuretView,
schoolyear, campusID, collegeID, departmentID, approvalStatus, (int)pararms.page, (int)pararms.rows));
}
[HttpPost]
public ActionResult Save()
{
try
{
var freeSelectionCourseApplyList = DataGrid.GetTableData("dgFreeSelectionCourseApplyList");
this.FreeSelectionCourseApplyServices.FreeSelectionCourseApplyUpdate(freeSelectionCourseApplyList);
return RedirectToAction("MsgShow", "Common", new
{
msg = "保存成功!",
url = Url.Content("~/FreeSelectionCourseApply/List").AddMenuParameter()
});
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
msg = "保存失败!" + ex.Message,
url = Url.Content("~/FreeSelectionCourseApply/List").AddMenuParameter()
});
}
}
public ActionResult Edit(Guid? freeSelectionCourseApplyID)
{
FreeSelectionCourseApplyView freeSelectCourseApplyView = new FreeSelectionCourseApplyView();
freeSelectCourseApplyView.HandleModeID = (int)EMIS.ViewModel.CF_HandleMode.SelectionCourse;
freeSelectCourseApplyView.DepartmentID = CustomPrincipal.Current.DepartmentID;
ViewBag.LoginID = CustomPrincipal.Current.LoginID;
ViewBag.Name = CustomPrincipal.Current.Name;
ViewBag.UserID = CustomPrincipal.Current.UserID;
ViewBag.StaffCode = "";
if (freeSelectionCourseApplyID.HasValue)
freeSelectCourseApplyView = FreeSelectionCourseApplyServices.GetFreeSelectionCourseApplyView(freeSelectionCourseApplyID);
else
{
var staff = FreeSelectionCourseApplyServices.GetStaff(CustomPrincipal.Current.UserID);
if (staff != null)
{
freeSelectCourseApplyView.DepartmentID = staff.DepartmentID;
ViewBag.DepartmentID = staff.DepartmentID;
ViewBag.StaffCode = staff.StaffCode;
}
freeSelectCourseApplyView.ResultTypeID = (int)CF_ResultType.Percentage;
}
return View(freeSelectCourseApplyView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(FreeSelectionCourseApplyView freeSelectionCourseApply)
{
int? type = 0;
try
{
var teacherList = DataGrid.GetTableData("dgTeacherList");
var specialtyList = DataGrid.GetTableData("dgSpecialtyList");
var schedulingList = DataGrid.GetTableData("dgSchedulingList");
if (freeSelectionCourseApply.FreeSelectionCouseApplyID == null || freeSelectionCourseApply.FreeSelectionCouseApplyID == Guid.Empty)
{
FreeSelectionCourseApplyServices.FreeSelectionCourseApplyAdd(freeSelectionCourseApply, teacherList, specialtyList, schedulingList, out type);
}
else
{
FreeSelectionCourseApplyServices.FreeSelectionCourseApplyUpdate(freeSelectionCourseApply, teacherList, specialtyList, schedulingList, out type);
}
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{ //如果验证到排课冲突type返回1,页面js根据type弹出选择框,用户可选择继续保存或不保存,如果不返回1,弹出一般的错误提示框
if (type == 1)
{
return Json(new ReturnMessage()
{
Type = 1,
IsSuccess = false,
Message = "保存失败:" + ex.Message,
});
}
else
return Json(new ReturnMessage()
{
IsSuccess = false,
Type = 2,
Message = "保存失败:" + ex.Message,
});
}
}
///
/// 明细
///
///
///
public ActionResult Details(Guid? freeSelectionCourseApplyID)
{
FreeSelectionCourseApplyView freeSelectCourseApplyView = new FreeSelectionCourseApplyView();
if (freeSelectionCourseApplyID.HasValue)
freeSelectCourseApplyView = FreeSelectionCourseApplyServices.GetFreeSelectionCourseApplyView(freeSelectionCourseApplyID);
return View(freeSelectCourseApplyView);
}
public ActionResult TeacherEdit(Guid freeSelectionCourseApplyID)
{
return View();
}
///
/// 提交
///
///
///
[HttpPost]
public ActionResult SubmitFreeSelectionCourseApply(string freeSelectionCourseApplyIDs)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
//for (int i = 0; i < freeSelectionCourseApplyIDs.Split(',').Length; i++)
//{
// if (!string.IsNullOrEmpty(freeSelectionCourseApplyIDs.Split(',')[i]))
// {
// Guid freeSelectionCourseApplyID = new Guid(freeSelectionCourseApplyIDs.Split(',')[i]);
// FreeSelectionCourseApplyServices.StartUp(freeSelectionCourseApplyID, user.UserID);
// }
//}
List list = new List();
for (int i = 0; i < freeSelectionCourseApplyIDs.Split(',').Length; i++)
{
if (!string.IsNullOrEmpty(freeSelectionCourseApplyIDs.Split(',')[i]))
{
Guid planApplicationID = new Guid(freeSelectionCourseApplyIDs.Split(',')[i]);
list.Add(planApplicationID);
}
}
FreeSelectionCourseApplyServices.Submit(list, user.UserID, "");
return this.Json("提交成功!");
}
catch (Exception ex)
{
return this.Json("提交失败,原因:" + ex.Message);
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string freeSelectionCourseApplyIDs)
{
try
{
List list = new List();
for (int i = 0; i < freeSelectionCourseApplyIDs.Split(',').Length; i++)
{
string id = freeSelectionCourseApplyIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid freeSelectionCourseApplyID = new Guid(id);
list.Add(freeSelectionCourseApplyID);
}
}
FreeSelectionCourseApplyServices.FreeSelectionCourseApplyDelete(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 campusID = Request.Form["CampusDropdown"].ParseStrTo();
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo();
var schoolyear = Request.Form["SchoolyearDropdown"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["SchoolyearDropdown"].ParseStrTo();
//var schoolyearNum = Request.Form["DictionarySchoolyearNum"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["DictionarySchoolyearNum"];
//var schoolcode = Request.Form["DictionarySchoolcode"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["DictionarySchoolcode"];
var approvalStatus = Request.Form["DictionaryApprovalStatus"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryApprovalStatus"].ParseStrTo();
var dt = FreeSelectionCourseApplyServices.GetFreeSelectionCoursePlanViewList(configuretView, schoolyear, campusID, collegeID, departmentID, approvalStatus).Select(x => new
{
//x.FreeSelectionCouseNo,
x.SchoolyearCode,
x.DepartmentName,
//x.CollegeName,
x.DefaultClassName,
//x.CourseCode,
//x.CourseName,
//x.CourseCategoryName,
//x.CourseTypeName,
//x.CourseQualityName,
//x.Credit,
//x.Totalhours,
//x.SchoolweeksNum,
//x.SchoolyearNumName,
//x.SchoolcodeName,
//x.StarttermName,
x.TeacherNames,
x.PeopleNumlower,
x.PeopleNumlimit,
x.CourseTypeName,
x.IsNeedMaterialName,
x.ApprovalStatusName
}).ToTable();
string[] liststring = { //"选课编号",
"学年学期", "教研室", //RSL.Get("College"),
"选修任务班名称",
//"课程代码",
//"课程名称", "课程属性", "课程类型", "课程性质", "学分","总学时",
//"上课周数", "学年数", "学期", "开课学期"
"授课教师","人数下限","人数上限","选修类型","是否需要教材","审批状态"};
neh.Export(dt, liststring, "计划申请信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/FreeSelectionCourseApply/List").AddMenuParameter()
});
}
public ActionResult GetFreeSelectionCourseView(Guid? freeSelectionCourseID)
{
FreeSelectionCourseView freeSelectionCourseView = new FreeSelectionCourseView();
if (freeSelectionCourseID.HasValue)
freeSelectionCourseView = FreeSelectionCourseServices.GetFreeSelectionCourseView(freeSelectionCourseID);
return base.Json(freeSelectionCourseView);
}
///
/// 获取任选课程已经存在在授课方式
///
///
///
[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()));
}
///
/// 获取任选课程申请已经存在在授课方式
///
///
///
[HttpPost]
public ActionResult CourseApplyTeachingModeType(Guid? freeSelectionCourseID)
{
List list = new List();
if (freeSelectionCourseID.HasValue && freeSelectionCourseID != Guid.Empty)
list = FreeSelectionCourseApplyServices.GetCourseApplyTeachingModeType(freeSelectionCourseID);
else
list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory));
return base.Json(list.ConvertAll(x => x.ToString()));
}
[HttpPost]
public ActionResult GradeYear(Guid? freeSelectionCourseApplyID)
{
List list = new List();
if (freeSelectionCourseApplyID.HasValue && freeSelectionCourseApplyID != Guid.Empty)
list = FreeSelectionCourseApplyServices.GetCourseApplyGradeYear(freeSelectionCourseApplyID);
return base.Json(list.ConvertAll(x => x.ToString()));
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult SpecialtyList(Guid freeSelectionCourseApplyID)
{
var specialtyList = this.FreeSelectionCourseApplyServices.GetFreeSelectionCourseApplySpecialtyListView(freeSelectionCourseApplyID);
return base.Json(new GridResultSet() { rows = specialtyList, total = specialtyList.Count });
}
///
/// 列表查询
///
///
///
public ActionResult TeacherList(Guid freeSelectionCourseApplyID)
{
var teacherList = this.FreeSelectionCourseApplyServices.GetFreeSelectionCourseApplyTeacherListView(freeSelectionCourseApplyID);
return base.Json(new GridResultSet() { rows = teacherList, total = teacherList.Count });
}
[HttpPost]
public ActionResult TeacherEdit(Guid freeSelectionCourseApplyID, string addTeacherListJson)
{
try
{
var addTeacherList = addTeacherListJson.JsonToObject>();
FreeSelectionCourseServices.SaveFreeSelectionCourseTeachers(freeSelectionCourseApplyID, addTeacherList);
return Json(new ReturnMessage { IsSuccess = true });
}
catch (Exception ex)
{
return Json(new ReturnMessage { IsSuccess = false, Message = ex.Message });
}
}
[HttpPost]
public ActionResult DefaultClassNo(Guid SchoolyearID, Guid freeSelectionCourseID, string StartWeeklyNum, string EndWeeklyNum)
{
try
{
var result = FreeSelectionCourseApplyServices.DefaultClassNo(SchoolyearID, freeSelectionCourseID, StartWeeklyNum, EndWeeklyNum);
return base.Json(result);
}
catch (Exception ex)
{
return Json("");
}
}
public ActionResult GetSchedulingViewList(Guid FreeSelectionCouseApplyID)
{
var courseProcessList = FreeSelectionCourseApplyServices.GetSchedulingView(FreeSelectionCouseApplyID);
return Json(new GridResultSet { rows = courseProcessList, total = courseProcessList.Count });
}
public ActionResult CourseProcessClassroomList()
{
return View();
}
public ActionResult CoursesTimeList()
{
return View();
}
///
/// 列出课程进度中的可选教室
///
///
///
[HttpPost]
public ActionResult GetCourseProcessClassroomList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
int? classroomType = pararms.getExtraString("ClassroomType").ParseStrTo() == DropdownList.SELECT_ALL ? null : pararms.getExtraString("ClassroomType").ParseStrTo();
string schedulingWeek = pararms.getExtraString("schedulingWeek");
int? weekday = pararms.getExtraString("weekDay").ParseStrTo() == DropdownList.SELECT_ALL ? null : pararms.getExtraString("weekDay").ParseStrTo();
var coursesTimeID = pararms.getExtraGuid("coursesTimeID") ?? Guid.Empty;
//int? minSeatCount = pararms.getExtraString("MinSeatCount").ParseStrTo() == DropdownList.SELECT_ALL ? null : pararms.getExtraString("MinSeatCount").ParseStrTo();
//var collegeID = pararms.getExtraGuid("CollegeDropdown") ?? Guid.Empty;
var buildingsID = pararms.getExtraInt("BuildingsDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraGuid("BuildingsDropdown");
return base.Json(ExecutableFreeSelectionCouseServices.GetAvailableClassroom(configuretView, buildingsID, schedulingWeek, weekday, coursesTimeID, classroomType, (int)pararms.page, (int)pararms.rows));
}
}
}