123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- 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; }
- /// <summary>
- /// 学年学期页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [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));
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- public ActionResult Edit(Guid? schoolyearID)
- {
- SchoolYearView schoolyearView = new SchoolYearView();
- if (schoolyearID != null && schoolyearID != Guid.Empty)
- schoolyearView = SchoolYearServices.GetSchoolYearView(schoolyearID);
- return View(schoolyearView);
- }
- /// <summary>
- /// 新增或更新
- /// </summary>
- /// <param name="schoolyearView"></param>
- /// <returns></returns>
- [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
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="activitiesIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string schoolyearIDs)
- {
- try
- {
- List<Guid> list = new List<Guid>();
- 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 + "!");
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [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));
- }
- /// <summary>
- /// 学年学期下拉菜单(全部学年学期,以降序排列)
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult DropDown(DropdownListBindType? bindType)
- {
- var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
- List<DropdownListItem> 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);
- }
- /// <summary>
- /// 学年学期(全部学年学期,以降序排列-启用学年学期首位)
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult YearsDropdownListBanid(DropdownListBindType? bindType)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- List<DropdownListItem> 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);
- }
- /// <summary>
- /// 学年学期下拉菜单(当前校历之后的学年学期,以降序排列)
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult DropDownAfterCurrent(DropdownListBindType? bindType)
- {
- //var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
- List<DropdownListItem> 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);
- }
- /// <summary>
- /// 学年学期下拉菜单(当前校历之前的学年学期,以降序排列)
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult DropDownBeforeCurrent(DropdownListBindType? bindType)
- {
- //var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
- List<DropdownListItem> 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);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult CurrentWeekListDropdown(DropdownListBindType? bindType)
- {
- List<DropdownListItem> 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);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bindType"></param>
- /// <param name="schoolyearID"></param>
- /// <returns></returns>
- [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);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bindType"></param>
- /// <param name="weekNum"></param>
- /// <returns></returns>
- [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);
- }
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- try
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
- 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()
- });
- }
- }
- }
- }
|