using System; using System.Collections.Generic; using System.Linq; 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.EvaluationManage.EvaluationSetting; using EMIS.CommonLogic.EvaluationManage.EvaluationSetting; namespace EMIS.Web.Controllers.EvaluationManage.EvaluationSetting { [Authorization] public class EvaluationNeedController : Controller { public Lazy EvaluationNeedServices { get; set; } /// /// 评价需知页面 /// /// public ActionResult List() { return View(); } /// /// 评价需知列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var participateTypeID = pararms.getExtraInt("DictionaryParticipateType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryParticipateType"); var isEnabled = pararms.getExtraInt("IsEnabledDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsEnabledDropdown"); return base.Json(EvaluationNeedServices.Value.GetEvaluationNeedViewGrid(configuretView, participateTypeID, isEnabled, (int)pararms.page, (int)pararms.rows)); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid evaluationNeedID) { var evaluationNeedView = new EvaluationNeedView(); evaluationNeedView = EvaluationNeedServices.Value.GetEvaluationNeedView(evaluationNeedID); return View("Edit", evaluationNeedView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(EvaluationNeedView evaluationNeedView) { evaluationNeedView.EvaluationNeedID = Guid.Empty; return this.Edit(evaluationNeedView); } /// /// 编辑(新增、修改) /// /// /// [HttpGet] public ActionResult Edit(Guid? evaluationNeedID) { var evaluationNeedView = new EvaluationNeedView(); if (evaluationNeedID.HasValue && evaluationNeedID != Guid.Empty) { evaluationNeedView = EvaluationNeedServices.Value.GetEvaluationNeedView(evaluationNeedID); } else { evaluationNeedView.IsEnabled = true; } return View(evaluationNeedView); } /// /// 编辑(新增、修改) /// /// /// [HttpPost] public ActionResult Edit(EvaluationNeedView evaluationNeedView) { try { EvaluationNeedServices.Value.EvaluationNeedEdit(evaluationNeedView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string evaluationNeedIDs) { try { List list = evaluationNeedIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); EvaluationNeedServices.Value.EvaluationNeedDelete(list); return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" }); } catch (Exception ex) { return base.Json(new ReturnMessage() { IsSuccess = false, Message = "删除失败,原因:" + ex.Message }); } } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var participateTypeID = Request.Form["DictionaryParticipateType"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryParticipateType"].ParseStrTo(); var isEnabled = Request.Form["IsEnabledDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsEnabledDropdown"].ParseStrTo(); var dt = EvaluationNeedServices.Value.GetEvaluationNeedViewList(configuretView, participateTypeID, isEnabled) .Select(x => new { x.Code, x.Title, x.ParticipateTypeName, x.Content, x.IsEnabledName, x.Remark, x.CreateUserName, x.ModifyUserName, ModifyTime = x.ModifyTime == null ? null : x.ModifyTime.Value.ToString("yyyy-MM-dd HH:mm:ss") }).ToTable(); string[] liststring = { "编号", "标题", "参评类型", "内容", "是否启用", "备注", "创建人", "修改人", "修改时间" }; neh.Export(dt, liststring, "评价需知信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }