using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using Bowin.Web.Controls.Mvc;
using EMIS.Web.Controls;
using EMIS.Utility;
using EMIS.ViewModel;
using EMIS.ViewModel.TeachingMaterial;
using EMIS.CommonLogic.TeachingMaterial;
using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan;
namespace EMIS.Web.Controllers.TeachingMaterial
{
[Authorization]
public class LibraryController : Controller
{
public ILibraryServices LibraryServices { get; set; }
public ICampusServices CampusServices { get; set; }
///
/// 书库信息页面
///
///
[HttpGet]
public ActionResult List()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(LibraryServices.GetLibraryViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
}
[HttpPost]
public ActionResult Excel(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
NpoiExcelHelper neh = new NpoiExcelHelper();
var dt = LibraryServices.GetLibraryViewExcel(configuretView).Select(x => new
{
x.LibraryCode,
x.LibraryName,
x.CampusName,
x.HeadPeople,
x.ContectTelNumber,
x.CreateTime,
x.CreateUserName
}).ToTable();
string[] liststring = { "书库编号", "书库名称", RSL.Get("CampusName"), "负责人", "联系电话", "创建时间", "创建人" };
neh.Export(dt, liststring, "书库信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/ Library/List").AddMenuParameter()
});
}
///
/// 编辑页面
///
///
[HttpGet]
public ActionResult Edit(Guid? libraryID)
{
LibraryView libraryView;
if (libraryID != null && libraryID != Guid.Empty)
{
libraryView = LibraryServices.GetSingleLibrary(libraryID.Value);
}
else
{
libraryView = new LibraryView()
{
LibraryID = Guid.Empty
};
}
return View(libraryView);
}
///
/// 新增
///
///
[HttpPost]
public ActionResult Edit(LibraryView libraryView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
LibraryServices.EditLibrary(libraryView, user.UserID);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string libraryIDs)
{
try
{
var libraryIDList = libraryIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
LibraryServices.DeleteLibrary(libraryIDList);
return base.Json("删除成功");
}
catch (Exception ex)
{
return base.Json("删除失败,原因:" + ex.Message + "。");
}
}
[HttpPost]
public ActionResult GetCampusCodeByCampusID(Guid campusID)
{
string campusCode = string.Empty;
var campus = CampusServices.GetCampusList()
.Where(x => x.CampusID == campusID).SingleOrDefault();
if (campus != null)
{
campusCode = campus.No;
}
return base.Json(campusCode);
}
}
}