using Learun.Util;
using System.Data;
using Learun.Application.TwoDevelopment.EducationalAdministration;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2019-08-26 16:58
/// 描 述:选修合班设置
///
public class ElectiveMergeController : MvcControllerBase
{
private ElectiveMergeIBLL electiveMergeIBLL = new ElectiveMergeBLL();
private LessonInfoIBLL lessonInfoIbll = new LessonInfoBLL();
private OpenLessonPlanOfElectiveIBLL openLessonPlanOfElectiveIbll = new OpenLessonPlanOfElectiveBLL();
#region 视图功能
///
/// 主页面
///
///
[HttpGet]
public ActionResult Index()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public ActionResult Form()
{
return View();
}
#endregion
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
[HttpGet]
[AjaxOnly]
public ActionResult GetPageList(string pagination, string queryJson)
{
Pagination paginationobj = pagination.ToObject();
var data = electiveMergeIBLL.GetPageList(paginationobj, queryJson);
var jsonData = new
{
rows = data,
total = paginationobj.total,
page = paginationobj.page,
records = paginationobj.records
};
return Success(jsonData);
}
///
/// 获取表单数据
///
///
[HttpGet]
[AjaxOnly]
public ActionResult GetFormData(string keyValue)
{
var ElectiveMergeData = electiveMergeIBLL.GetElectiveMergeEntity(keyValue);
var jsonData = new
{
ElectiveMerge = ElectiveMergeData,
};
return Success(jsonData);
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult DeleteForm(string keyValue)
{
electiveMergeIBLL.DeleteEntity(keyValue);
return Success("取消成功!");
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult SaveForm(string keyValue, string strEntity)
{
ElectiveMergeEntity entity = strEntity.ToObject();
electiveMergeIBLL.SetStuNumMax(keyValue, entity.StuNumMax.Value);
return Success("设置成功!");
}
[HttpPost]
[AjaxOnly]
public ActionResult Merge(string AcademicYearNo, string Semester, string LessonNo, string EmpNo, string keyValue, string F_SchoolId)
{
var keyValueArr = keyValue.Split(',');
if (AcademicYearNo.Split(',').Distinct().Count() == 1 &&
Semester.Split(',').Distinct().Count() == 1 &&
LessonNo.Split(',').Distinct().Count() == 1 && EmpNo.Split(',').Distinct().Count() == 1)
{
var lesson = lessonInfoIbll.GetLessonInfoEntityByLessonNo(LessonNo.Split(',')[0]);
if (lesson == null)
{
return Fail("合班失败!课程库和排课数据不匹配,请检查。");
}
ElectiveMergeEntity emMergeEntity = new ElectiveMergeEntity();
emMergeEntity.Create();
emMergeEntity.AcademicYearNo = AcademicYearNo.Split(',')[0];
emMergeEntity.Semester = Semester.Split(',')[0];
emMergeEntity.F_SchoolId = F_SchoolId.Split(',')[0];
emMergeEntity.LessonId = lesson.LessonId;
emMergeEntity.LessonNo = lesson.LessonNo;
emMergeEntity.LessonName = lesson.LessonName;
List listElectiveMergeItemEntity = new List();
foreach (var item in keyValueArr)
{
ElectiveMergeItemEntity emItemEntity = new ElectiveMergeItemEntity();
emItemEntity.Create();
emItemEntity.EmId = emMergeEntity.EMId;
emItemEntity.OLPOEId = item;
var olpoe = openLessonPlanOfElectiveIbll.GetOpenLessonPlanOfElectiveEntity(item);
emItemEntity.LessonSection = olpoe.LessonSection;
emItemEntity.LessonTime = olpoe.LessonTime;
emItemEntity.EmpNo = olpoe.EmpNo;
emItemEntity.EmpName = olpoe.EmpName;
emItemEntity.ClassRoomNo = olpoe.ClassRoomNo;
emItemEntity.ClassRoomName = olpoe.ClassRoomName;
listElectiveMergeItemEntity.Add(emItemEntity);
}
if (listElectiveMergeItemEntity.Select(m=>m.LessonSection.Substring(0,1)).Distinct().Count()>1)
{
return Fail("合班失败!请确认所选课程是否为同一天课程。");
}
electiveMergeIBLL.SaveEntity(null, emMergeEntity, listElectiveMergeItemEntity);
return Success("合班成功!");
}
else
return Fail("合班失败!请确认所选课程是否为可合并课程。");
}
#endregion
}
}