using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.ViewModel;
using EMIS.ViewModel.ChargeManage.ChargeSituation;
using EMIS.CommonLogic.ChargeManage.ChargeSituation;
using EMIS.Web.Controls;
using Bowin.Common.Exceptions;
using Bowin.Common.Utility;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Data;
using EMIS.Utility;
namespace EMIS.Web.Controllers.ChargeManage.ChargeSituation
{
[Authorization]
public class ChargeProjectController : Controller
{
public IChargeProjectServices ChargeProjectService { get; set; }
///
///收费项目页面
///
///
public ActionResult List()
{
return View();
}
///
/// 收费项目列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
return base.Json(ChargeProjectService.GetChargeProjectViewGrid(configuretView,(int)pararms.page, (int)pararms.rows));
}
///
/// 编辑
///
///
///
[HttpGet]
public ActionResult Edit(Guid? chargeProjectID)
{
ChargeProjectView chargeProjectView = new ChargeProjectView();
if (chargeProjectID.HasValue && chargeProjectID != Guid.Empty)
{
chargeProjectView = ChargeProjectService.GetChargeProjectView(chargeProjectID);
}
return View(chargeProjectView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(ChargeProjectView chargeProjectView)
{
try
{
ChargeProjectService.ChargeProjectAdd(chargeProjectView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message + "。"
});
}
}
///
/// 详情页面
///
///
///
[HttpGet]
public ActionResult Details(Guid? chargeProjectID)
{
ChargeProjectView chargeProjectView = new ChargeProjectView();
if (chargeProjectID.HasValue && chargeProjectID != Guid.Empty)
{
chargeProjectView = ChargeProjectService.GetChargeProjectDetailsView(chargeProjectID);
}
return View(chargeProjectView);
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string ChargeProjectIDs)
{
try
{
List list = new List();
for (int i = 0; i < ChargeProjectIDs.Split(',').Length; i++)
{
string id = ChargeProjectIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid chargeProjectID = new Guid(id);
list.Add(chargeProjectID);
}
}
ChargeProjectService.ChargeProjectDelete(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 + "。");
}
}
///
/// 验证
///
///
///
///
[HttpPost]
public ActionResult Verification(Guid? chargeProjectID, string chrageProjectName)
{
return Json(ChargeProjectService.GetVerification(chargeProjectID, chrageProjectName));
}
///
/// Excel导出
///
///
///
[HttpPost]
public ActionResult Excel(ChargeProjectView pararms)
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var dt = ChargeProjectService.GetChargeProjectViewList(configuretView).Select(x => new
{
x.ChrageProjectName,
x.Remark
}).ToTable();
string[] liststring = { "收费项目", "备注" };
neh.Export(dt, liststring, "收费项目信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
}
}