using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Web.Controls.Mvc;
using EMIS.Utility;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using EMIS.CommonLogic.CalendarManage;
using EMIS.ViewModel.CalendarManage;
using EMIS.Entities;
using Bowin.Common.Exceptions;
using Bowin.Common.Utility;
using Bowin.Common.Data;
namespace EMIS.Web.Controllers.CalendarManage
{
[Authorization]
public class SchoolYearController : Controller
{
public ISchoolYearServices SchoolYearServices { get; set; }
public DictionaryHelper DictionaryHelper { get; set; }
///
/// 学年学期页面
///
///
public ActionResult List()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var isCurrent = pararms.getExtraInt("IsCurrentDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsCurrentDropDown");
return base.Json(SchoolYearServices.GetSchoolYearViewGrid(configuretView, isCurrent, (int)pararms.page, (int)pararms.rows));
}
///
/// 编辑页面
///
///
public ActionResult Edit(Guid? schoolyearID)
{
SchoolYearView schoolyearView = new SchoolYearView();
if (schoolyearID != null && schoolyearID != Guid.Empty)
schoolyearView = SchoolYearServices.GetSchoolYearView(schoolyearID);
return View(schoolyearView);
}
///
/// 新增或更新
///
///
///
[HttpPost]
public ActionResult Edit(SchoolYearView schoolyearView)
{
try
{
if (!schoolyearView.SchoolYearID.HasValue || schoolyearView.SchoolYearID == Guid.Empty)
{
SchoolYearServices.SchoolYearAdd(schoolyearView);
}
else
{
SchoolYearServices.SchoolYearUpdate(schoolyearView);
}
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string schoolyearIDs)
{
try
{
List list = new List();
for (int i = 0; i < schoolyearIDs.Split(',').Length; i++)
{
string id = schoolyearIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid schoolyearID = new Guid(id);
list.Add(schoolyearID);
}
}
SchoolYearServices.SchoolYearDelete(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 + "!");
}
}
///
///
///
///
///
[HttpPost]
public ActionResult GetYearsList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var isCurrent = pararms.getExtraInt("IsCurrentDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsCurrentDropDown");
return base.Json(SchoolYearServices.GetYearsViewGrid(configuretView, isCurrent, (int)pararms.page, (int)pararms.rows));
}
///
/// 学年学期下拉菜单(全部学年学期,以降序排列)
///
///
///
[HttpPost]
public ActionResult DropDown(DropdownListBindType? bindType)
{
var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo();
List list = SchoolYearServices.GetSchoolYearViewList(new ConfiguretView(), isCurrent)
.Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 学年学期(全部学年学期,以降序排列-启用学年学期首位)
///
///
///
[HttpPost]
public ActionResult YearsDropdownListBanid(DropdownListBindType? bindType)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
List list = SchoolYearServices.GetSchoolYearViewList(configuretView, null).ToList()
.OrderByDescending(x => x.IsCurrent).Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 学年学期下拉菜单(当前校历之后的学年学期,以降序排列)
///
///
///
[HttpPost]
public ActionResult DropDownAfterCurrent(DropdownListBindType? bindType)
{
//var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo();
List list = SchoolYearServices.GetSchoolYearViewListAfterCurrent()
.Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 学年学期下拉菜单(当前校历之前的学年学期,以降序排列)
///
///
///
[HttpPost]
public ActionResult DropDownBeforeCurrent(DropdownListBindType? bindType)
{
//var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo();
List list = SchoolYearServices.GetSchoolYearViewListBeforeCurrent()
.Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
///
///
///
///
[HttpPost]
public ActionResult CurrentWeekListDropdown(DropdownListBindType? bindType)
{
List list = SchoolYearServices.GetCurrentSchoolyearWeekNumList().OrderByDescending(x => x).Select(x => new DropdownListItem { Text = x.ToString(), Value = x.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
///
///
///
///
///
[HttpPost]
public ActionResult GetWeekListDropdown(DropdownListBindType? bindType, Guid? schoolyearID)
{
var list = SchoolYearServices.GetSchoolyearWeekNumList(schoolyearID).OrderByDescending(x => x).Select(x => new DropdownListItem { Text = x.ToString(), Value = x.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
///
///
///
///
///
[HttpPost]
public ActionResult GetFutureWeekListDropdown(DropdownListBindType? bindType, int weekNum)
{
var list = SchoolYearServices.GetFutureWeekdayList(weekNum)
.OrderBy(x => (x.WeekDay == 0 ? 7 : x.WeekDay)).Select(x => new DropdownListItem { Value = x.WeekDay.ToString(), Text = x.ChineseName.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 导出Excel
///
///
///
[HttpPost]
public ActionResult Excel()
{
try
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo();
var dt = SchoolYearServices.GetSchoolYearViewList(configuretView, isCurrent).Select(x => new
{
x.Code,
x.Years,
x.SchoolcodeName,
x.WeeksNum,
FirstWeek = x.FirstWeek.Value.ToString("yyyy-MM-dd"),
x.Current,
x.WeekDays
}).ToTable();
string[] liststring = { "学年学期", "学年", "学期名称", "周数", "首周周一日期", "是否当前学期", "每周工作天数" };
neh.Export(dt, liststring, "学年学期信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/SchoolYear/List").AddMenuParameter()
});
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出失败,原因:" + ex.Message + "!",
url = Url.Content("~/SchoolYear/List").AddMenuParameter()
});
}
}
}
}