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 ActivitieController : Controller
{
public IActivitieServices ActivitieServices { get; set; }
///
/// 固定假日页面
///
///
public ActionResult List()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var activitiesType = pararms.getExtraInt("ActivitiesTypeDropdown");
var timesSegment = pararms.getExtraInt("TimesSegmentDropdown");
return base.Json(ActivitieServices.GetActivitieViewGrid(configuretView, activitiesType, timesSegment, (int)pararms.page, (int)pararms.rows));
}
///
/// 编辑页面
///
///
[HttpGet]
public ActionResult Edit(Guid? activitiesID)
{
ActivitieView activitieView = new ActivitieView();
if (activitiesID != null && activitiesID != Guid.Empty)
activitieView = ActivitieServices.GetActivitieView(activitiesID);
return View(activitieView);
}
///
/// 新增或更新
///
///
///
[HttpPost]
public ActionResult Edit(ActivitieView activitieView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
if (!activitieView.ActivitiesID.HasValue || activitieView.ActivitiesID == Guid.Empty)
{
ActivitieServices.ActivitiesAdd(activitieView);
}
else
{
ActivitieServices.ActivitiesUpdate(activitieView);
}
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string activitiesIDs)
{
try
{
List list = new List();
for (int i = 0; i < activitiesIDs.Split(',').Length; i++)
{
string id = activitiesIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid activitiesID = new Guid(id);
list.Add(activitiesID);
}
}
ActivitieServices.ActivitiesDelete(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 + "!");
}
}
///
/// 导出Excel
///
///
///
[HttpPost]
public ActionResult Excel()
{
try
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var activitiesType = Request.Form["ActivitiesTypeDropdown"].ParseStrTo();
var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo();
var dt = ActivitieServices.GetActivitieViewList(configuretView, activitiesType, timesSegment).Select(x => new
{
x.Name,
x.ActivitiesTime,
x.TimesSegmentName,
x.ActivitiesTypeName,
x.ActivitiesContent
}).ToTable();
string[] liststring = { "活动名称", "月日", "时间段", "活动类型", "活动内容" };
neh.Export(dt, liststring, "固定活动信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/Activitie/List").AddMenuParameter()
});
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出失败,原因:" + ex.Message + "!",
url = Url.Content("~/Activitie/List").AddMenuParameter()
});
}
}
///
/// 活动类型下拉绑定数据
///
///
///
[HttpPost]
public ActionResult ActivitiesTypeDropdownListBanid(DropdownListBindType? bindType)
{
List list = DictionaryHelper.GetDictionaryValue("CF_ActivitiesType").Select(x => new DropdownListItem { Text = x.Name, Value = x.Value }).ToList();
DropdownList.FormatDropdownItemList(bindType.Value, list);
return base.Json(list);
}
///
///时间段下拉绑定数据
///
///
///
[HttpPost]
public ActionResult TimesSegmentDropdownListBanid(DropdownListBindType? bindType)
{
List list = DictionaryHelper.GetDictionaryValue("CF_TimesSegment").Select(x => new DropdownListItem { Text = x.Name, Value = x.Value }).ToList();
DropdownList.FormatDropdownItemList(bindType.Value, list);
return base.Json(list);
}
}
}