using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel; using EMIS.Web.Controls; using Bowin.Web.Controls.Mvc; using EMIS.ViewModel.SystemView; using Bowin.Common.Exceptions; namespace EMIS.Web.Controllers { [Authorization] public class AnnouncementController : Controller { public IAnnouncementServices AnnouncementServices { get; set; } /// /// 公告类型页面 /// /// public ActionResult TypeList() { return View(); } [HttpPost] public ActionResult TypeList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); //避开全选值 if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; return base.Json(AnnouncementServices.GetAnnouncementTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows)); } [HttpPost] public ActionResult TypeDropdownList(DropdownListBindType? bindType) { List list = AnnouncementServices.GetUsableAnnouncementTypeViewList() .Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 公告发布页面 /// /// 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(AnnouncementServices.GetAnnouncementViewList(configuretView, (int)pararms.page, (int)pararms.rows)); } [HttpGet] public ActionResult TypeEdit(Guid? announcementTypeID) { AnnouncementTypeView announcementTypeView = new AnnouncementTypeView(); if (announcementTypeID != null && announcementTypeID != Guid.Empty) { announcementTypeView = AnnouncementServices.GetAnnouncementTypeViewInfo(announcementTypeID); } return View(announcementTypeView); } [HttpGet] public ActionResult Edit(Guid? announcementID) { AnnouncementView announcementView = new AnnouncementView(); if (announcementID != null && announcementID != Guid.Empty) { announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID); } return View(announcementView); } /// /// 保存公告类型 /// /// [HttpPost] public ActionResult TypeEdit(AnnouncementTypeView announcementTypeView) { try { var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal; AnnouncementServices.SaveType(announcementTypeView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 保存 /// /// [HttpPost] public ActionResult Edit(AnnouncementView announcementView) { try { var roleList = DataGrid.GetTableData("dgRoleList"); AnnouncementServices.Save(announcementView, roleList.Select(x => (Guid?)x.RoleID).ToList()); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 删除公告类型 /// /// /// [HttpPost] public ActionResult DeleteType(string typeIDs) { try { var announcementTypeIDList = typeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList(); AnnouncementServices.DeleteType(announcementTypeIDList); 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 Delete(string announcementIDs) { try { var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList(); AnnouncementServices.Delete(announcementIDList); return base.Json("删除成功!"); } catch (Exception ex) { return base.Json("删除失败,原因:" + ex.Message + "。"); } } [HttpPost] public ActionResult GetRoleViewList(Guid? announcementID) { if (announcementID.HasValue) { var resultList = AnnouncementServices.GetAnnouncementRoleViewList(announcementID.Value); return Json(new JsonDataGridResult { rows = resultList, total = resultList.Count }); } else { return Json(new JsonDataGridResult()); } } /// /// 页面查询列获取公告名称 /// /// /// [HttpPost] public ActionResult AnnouncementTypeDropdownList(DropdownListBindType? bindType) { List list = AnnouncementServices.GetUsableAnnouncementTypeViewList().Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } [HttpPost] public ActionResult GetUserAnnouncementViewList(QueryParamsModel pararms) { var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal; return Json(AnnouncementServices.GetUserAnnouncementView(user.UserID, pararms.page.Value, pararms.rows.Value)); } public ActionResult AnnouncementView(Guid announcementID) { AnnouncementView announcementView = new AnnouncementView(); announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID); return View(announcementView); } } }