using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Bowin.Common.Data;
using Bowin.Common.Exceptions;
using Bowin.Common.Utility;
using Bowin.Web.Controls.Mvc;
using EMIS.Web.Controls;
using EMIS.Utility;
using EMIS.ViewModel;
using EMIS.ViewModel.UniversityManage.ClassroomManage;
using EMIS.CommonLogic.UniversityManage.ClassroomManage;
namespace EMIS.Web.Controllers.UniversityManage.ClassroomManage
{
[Authorization]
public class ClassroomController : Controller
{
public IClassroomServices ClassroomServices { get; set; }
///
/// 教室信息页面
///
///
public ActionResult List()
{
return View();
}
///
/// 教室信息页面列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown");
var buildingsID = pararms.getExtraGuid("BuildingsDropdown");
//教室名称
var classroomName = pararms.getExtraString("ClassroomNameDropdown");
//教室类型
var classroomTypeID = pararms.getExtraInt("ClassroomTypeDictionary") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ClassroomTypeDictionary");
//所属院系所
var collegeID = pararms.getExtraGuid("CollegeDropdown");
//可否多班教学
var isConcurrentUse = pararms.getExtraInt("IsConcurrentUseDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsConcurrentUseDropdown");
//是否预留
var isReserve = pararms.getExtraInt("IsReserveDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsReserveDropdown");
//是否可用
var isAvailable = pararms.getExtraInt("IsAvailableDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsAvailableDropdown");
return base.Json(ClassroomServices.GetClassroomViewGrid(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
}
///
/// 教室信息页面列表查询
///
///
///
[HttpPost]
public ActionResult ListIsEnable(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown");
var buildingsID = pararms.getExtraGuid("BuildingsDropdown");
//教室名称
var classroomName = pararms.getExtraString("ClassroomNameDropdown");
//教室类型
var classroomTypeID = pararms.getExtraInt("ClassroomTypeDictionary") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ClassroomTypeDictionary");
//所属院系所
var collegeID = pararms.getExtraGuid("CollegeDropdown");
//可否多班教学
var isConcurrentUse = pararms.getExtraInt("IsConcurrentUseDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsConcurrentUseDropdown");
//是否预留
var isReserve = pararms.getExtraInt("IsReserveDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsReserveDropdown");
//是否可用
var isAvailable = (int)SYS_STATUS.USABLE;
return base.Json(ClassroomServices.GetClassroomViewGrid(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
}
///
/// 查询对应的教室信息下拉(带数据范围)
///
///
///
[HttpPost]
public ActionResult DropDown(DropdownListBindType? bindType, int? classroomType)
{
var allClassroomList = ClassroomServices.GetClassroomViewList(new ConfiguretView(), null, null, null, classroomType, null, null, null, null);
List list = allClassroomList.Select(x => new DropdownListItem { Text = x.Name, Value = x.ClassroomID }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 复制新增
///
///
///
public ActionResult CopyAdd(Guid classroomID)
{
ClassroomView classroomView = new ClassroomView();
classroomView = ClassroomServices.GetClassroomView(classroomID);
return View("Edit", classroomView);
}
///
/// 复制新增
///
///
///
[HttpPost]
public ActionResult CopyAdd(ClassroomView classroomView)
{
classroomView.ClassroomID = Guid.Empty;
return this.Edit(classroomView);
}
///
/// 编辑(新增、修改,业务主键:教室编号唯一)
///
///
///
[HttpGet]
public ActionResult Edit(Guid? classroomID)
{
ClassroomView classroomView = new ClassroomView();
if (classroomID.HasValue && classroomID != Guid.Empty)
{
classroomView = ClassroomServices.GetClassroomView(classroomID);
}
else
{
classroomView.RoomUseID = (int)CF_RoomUse.Classroom;
classroomView.IsAvailable = true;
}
return View(classroomView);
}
///
/// 编辑(新增、修改,业务主键:教室编号唯一)
///
///
///
[HttpPost]
public ActionResult Edit(ClassroomView classroomView)
{
try
{
ClassroomServices.ClassroomEdit(classroomView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string classroomIDs)
{
try
{
List list = classroomIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
ClassroomServices.ClassroomDelete(list);
return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
}
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(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
}
}
///
/// 根据教室信息ID查询对应的教室类型List
///
///
///
[HttpPost]
public ActionResult GetClassroomModeType(Guid? classroomID)
{
List list = new List();
if (classroomID.HasValue && classroomID != Guid.Empty)
{
list = ClassroomServices.GetClassroomTypeList(classroomID).Select(x => x.ToString()).ToList();
}
else
{
list.Add(((int)EMIS.ViewModel.CF_ClassroomType.Classroom).ToString());
}
return base.Json(list);
}
///
/// Excel导入
///
///
///
///
[HttpGet]
public ActionResult Import(string errorFile, string operationTips)
{
ViewBag.ErrorFile = errorFile;
if (string.IsNullOrEmpty(operationTips))
{
operationTips = "点击查看失败原因...";
}
ViewBag.operationTips = operationTips;
return View();
}
///
/// Excel导入
///
///
///
[HttpPost]
public ActionResult Import(HttpPostedFileBase file)
{
try
{
if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
{
throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
}
Dictionary cellheader = new Dictionary
{
{ "Code", "教室编号" },
{ "Name", "教室名称" },
{ "BuildingsInfoCode", "建筑编号" },
{ "CollegeCode", RSL.Get("CollegeCode") },
{ "ClassroomTypeIDListStr", "教室类型" },
//{ "LayoutTypeStr", "布局类型" },
{ "RoomUseStr", "房间用途" },
{ "FloorLevelStr", "所在楼层" },
{ "AcreageStr", "面积" },
{ "RowCoutStr", "行数" },
{ "ColumnCountStr", "列数" },
{ "TotalseatingStr", "总座位数" },
{ "EffectiveseatingStr", "有效座位数" },
{ "ExaminationseatingStr", "考试座位数" },
{ "IsWrittenExamStr", "可否笔试" },
{ "IsMachinetestStr", "可否机试" },
{ "IsConcurrentUseStr", "可否多班教学" },
{ "IsAvailableStr", "是否可用" },
{ "Remark", "备注" },
{ "ErrorMessage", "未导入原因" }
};
StringBuilder errorMsg = new StringBuilder();
string sourceWebPath = FileUploadHelper.UploadFile(file);
var sourcePhysicalPath = Server.MapPath(sourceWebPath);
List errList = new List();
List dataList = new List();
int? inCount = 0; //导入个数
int? upCount = 0; //更新个数
int? errCount = 0; //失败个数
//导入
ClassroomServices.ClassroomImport(cellheader, out inCount, out upCount, 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}条教室信息更新成功,{2}条教室信息导入失败,点击查看。", inCount, upCount, errCount);
ViewBag.operationTips = Errinfo;
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = Errinfo,
url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
});
}
else
{
string successInfo = string.Format("提示:{0}条教室信息导入成功,{1}条教室信息更新成功。", inCount, upCount);
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = successInfo,
url = Url.Action("List").AddMenuParameter()
});
}
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = "导入失败,原因:" + ex.Message,
url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
});
}
}
///
/// 查询教室信息对应的排课分配院系所信息List(无数据范围)
///
///
public ActionResult ClassroomCollegeList()
{
return View();
}
///
/// 查询教室信息对应的排课分配院系所信息List(无数据范围)
///
///
///
[HttpPost]
public ActionResult ClassroomCollegeList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var classroomID = Request["classroomID"].ParseStrTo();
var campusID = pararms.getExtraGuid("CampusDropdown");
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory");
return base.Json(ClassroomServices.GetClassroomCollegeViewGrid(configuretView, classroomID, campusID, collegeID, unitCategoryID, (int)pararms.page, (int)pararms.rows));
}
///
/// 教室信息对应的排课分配院系所信息Excel导出
///
///
[HttpPost]
public ActionResult Excel_ClassroomCollege()
{
try
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var classroomID = Request["classroomID"].ParseStrTo();
var campusID = Request.Form["CampusDropdown"].ParseStrTo();
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
var unitCategoryID = Request.Form["DictionaryUnitCategory"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryUnitCategory"].ParseStrTo();
var dt = ClassroomServices.GetClassroomCollegeViewList(configuretView, classroomID, campusID, collegeID, unitCategoryID)
.Select(x => new
{
x.Code,
x.Name,
x.BuildingsInfoCode,
x.BuildingsInfoName,
x.CampusCode,
x.CampusName,
x.ClassroomTypeName,
x.RoomUseName,
x.FloorLevel,
x.Acreage,
x.RowCout,
x.ColumnCount,
x.Totalseating,
x.Effectiveseating,
x.Examinationseating,
x.CollegeCode,
x.CollegeName,
x.UnitCategoryName,
x.CollegeCampusCode,
x.CollegeCampusName,
x.IsWrittenExamName,
x.IsMachinetestName,
x.IsConcurrentUseName,
x.IsReserveName,
x.IsAvailableName,
x.Remark
}).ToTable();
string[] liststring = {
"教室编号", "教室名称", "建筑物编号", "建筑物名称", RSL.Get("CampusCode"),
RSL.Get("Campus"), "教室类型", "房间用途", "所在楼层","面积", "行数", "列数",
"总座位数", "有效座位数", "考试座位数", "分配" + RSL.Get("CollegeCode"),
"分配" + RSL.Get("College"), "单位类别", "分配" + RSL.Get("CampusCode"),
"分配" + RSL.Get("Campus"), "可否笔试", "可否机试", "可否多班教学", "是否预留",
"是否可用", "备注"
};
neh.Export(dt, liststring, "教室信息排课分配院系明细信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "导出失败,原因:" + ex.Message
});
}
}
///
/// Excel导出
///
///
///
[HttpPost]
public ActionResult Excel()
{
try
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var campusID = Request.Form["CampusDropdown"].ParseStrTo();
var buildingsID = Request.Form["BuildingsDropdown"].ParseStrTo();
//教室名称
var classroomName = Request.Form["ClassroomNameDropdown"].ToString();
//教室类型
var classroomTypeID = Request.Form["ClassroomTypeDictionary"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["ClassroomTypeDictionary"].ParseStrTo();
//所属院系所
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
//可否多班教学
var isConcurrentUse = Request.Form["IsConcurrentUseDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsConcurrentUseDropdown"].ParseStrTo();
//是否预留
var isReserve = Request.Form["IsReserveDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsReserveDropdown"].ParseStrTo();
//是否可用
var isAvailable = Request.Form["IsAvailableDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsAvailableDropdown"].ParseStrTo();
var dt = ClassroomServices.GetClassroomViewList(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable)
.Select(x => new
{
x.Code,
x.Name,
x.BuildingsInfoCode,
x.BuildingsInfoName,
x.CampusCode,
x.CampusName,
x.ClassroomTypeName,
x.RoomUseName,
x.FloorLevel,
x.Acreage,
x.RowCout,
x.ColumnCount,
x.Totalseating,
x.Effectiveseating,
x.Examinationseating,
x.CollegeCode,
x.CollegeName,
x.CollegeCampusCode,
x.CollegeCampusName,
x.IsWrittenExamName,
x.IsMachinetestName,
x.IsConcurrentUseName,
x.IsReserveName,
x.ScheduleCollegeCount,
x.IsAvailableName,
x.Remark
}).ToTable();
string[] liststring = {
"教室编号", "教室名称", "建筑物编号", "建筑物名称", RSL.Get("CampusCode"),
RSL.Get("Campus"), "教室类型", "房间用途", "所在楼层","面积", "行数", "列数",
"总座位数", "有效座位数", "考试座位数", "所属" + RSL.Get("CollegeCode"),
"所属" + RSL.Get("College"), "所属" + RSL.Get("CampusCode"), "所属" + RSL.Get("Campus"),
"可否笔试", "可否机试", "可否多班教学", "是否预留", "排课院系个数", "是否可用", "备注"
};
neh.Export(dt, liststring, "教室信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "导出失败,原因:" + ex.Message
});
}
}
}
}