using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using EMIS.CommonLogic.ExamManage;
using EMIS.Entities;
using EMIS.CommonLogic.SystemSetting;
using Bowin.Common.Utility;
using Bowin.Common.Exceptions;
using Bowin.Common.Data;
using Bowin.Web.Controls.Mvc;
using EMIS.ViewModel.ExamManage;
namespace EMIS.Web.Controllers.ExamManage
{
[Authorization]
public class ChargeProjectController : Controller
{
public IProjectFeeServices IProjectFeeService { get; set; }
public IDictionaryServices DictionaryService { get; set; }
///
/// 收费项目页面
///
///
public ActionResult List()
{
return View();
}
///
///项目设置列表页面
///
///
public ActionResult ProjectList()
{
return View();
}
///
/// 收费项目列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var ExaminationProjectFeeID = Request["ExaminationProjectFeeID"].ParseStrTo();
configuretView.Attribute = "ExaminationProjectFeeID";
configuretView.Condition = "=";
configuretView.ConditionValue = ExaminationProjectFeeID.ToString();
return base.Json(IProjectFeeService.GetProjectFeeTypeGrid(configuretView, (int)pararms.page, (int)pararms.rows));
}
///
/// 项目类型列表查询
///
///
///
[HttpPost]
public ActionResult GetExaminationTypeList(QueryParamsModel pararms)
{
List configuretViews = new List();
configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
configuretViews.AddRange(pararms.getConditions());
return base.Json(IProjectFeeService.GetExaminationTypeList((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
}
[HttpPost]
public ActionResult ExaminationTypeDropdownList(DropdownListBindType? bindType)
{
var typeList = IProjectFeeService.GetExaminationTypeList()
.Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationTypeID }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, typeList);
return base.Json(typeList);
}
///
/// 考试科目列表查询
///
///
///
[HttpPost]
public ActionResult GetProjectSubjectListViewGrid(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var ExaminationProjectID = pararms.getExtraString("ExaminationProjectID");
if (!string.IsNullOrEmpty(ExaminationProjectID))
{
configuretView.Attribute = "ExaminationProjectID";
configuretView.Condition = "=";
configuretView.ConditionValue = ExaminationProjectID;
}
return base.Json(IProjectFeeService.GetProjectSubjectListViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
}
///
/// 收费项目编辑页
///
///
///
///
[HttpGet]
public ActionResult Edit(Guid? ProjectFeeTypeID, Guid? ExaminationProjectFeeID)
{
ProjectFeeTypeView projectFeeTypeView = new ProjectFeeTypeView() { ExaminationProjectFeeID = ExaminationProjectFeeID };
if (ProjectFeeTypeID.HasValue && ProjectFeeTypeID != Guid.Empty)
{
projectFeeTypeView = IProjectFeeService.GetProjectFeeType(ProjectFeeTypeID);
}
return View(projectFeeTypeView);
}
///
/// 收费项目编辑页提交
///
///
///
[HttpPost]
public ActionResult Edit(ProjectFeeTypeView view)
{
try
{
var feetype = IProjectFeeService.GetProjectFeeTypeList(x => (x.FeeTypeID == view.FeeTypeID && x.ExaminationProjectFeeID == view.ExaminationProjectFeeID) && x.ExaminationProjectFeeTypeID != view.ExaminationProjectFeeTypeID).FirstOrDefault();
if (feetype != null)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "收费项已经存在,不允许重复。"
});
}
IProjectFeeService.ProjectFeeTypeEdit(view);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// 删除项目设置
///
///
///
[HttpPost]
public JsonResult DeleteProjectFee(string ExaminationProjectFeeIDs)
{
try
{
List list = ExaminationProjectFeeIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
.Select(x => (Guid?)new Guid(x)).ToList();
IProjectFeeService.ProjectFeeDelete(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 JsonResult DeleteProjectFeeType(string ExaminationProjectFeeTypeIDs)
{
try
{
List list = ExaminationProjectFeeTypeIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
.Select(x => (Guid?)new Guid(x)).ToList();
IProjectFeeService.ProjectFeeTypeDelete(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 GetProjectListViewGrid(QueryParamsModel pararms)
{
List configuretViews = new List();
configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
configuretViews.AddRange(pararms.getConditions());
var Name = configuretViews.Where(x => x.Attribute == "Name").SingleOrDefault();
if (Name != null) Name.Condition = "中";
return base.Json(IProjectFeeService.GetProjectListViewGrid((int)pararms.page, (int)pararms.rows,
configuretViews.ToArray()));
}
///
/// 项目列表查询
///
///
///
[HttpPost]
public ActionResult ProjectDropdownList(DropdownListBindType? bindType, Guid? examinationTypeID)
{
var condition = new ConfiguretView { Attribute = "ExaminationTypeID", Condition = "=", ConditionValue = (examinationTypeID == null ? null : examinationTypeID.Value.ToString()) };
var projectList = IProjectFeeService.GetProjectList(condition).ToList()
.Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationProjectID }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, projectList);
return base.Json(projectList);
}
[HttpPost]
public ActionResult ExaminationSubjectDropdownList(DropdownListBindType? bindType, Guid? examinationProjectID)
{
var examinationSubjectList = IProjectFeeService.GetProjectSubjectListViewList(examinationProjectID)
.Select(x => new DropdownListItem { Text = x.ExaminationSubject, Value = x.ExaminationSubjectID }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, examinationSubjectList);
return base.Json(examinationSubjectList);
}
[HttpPost]
public ActionResult ProjectExcel(QueryParamsModel pararms)
{
List configuretViews = new List();
configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
configuretViews.AddRange(pararms.getConditions());
var query = IProjectFeeService.GetProjectList(configuretViews.ToArray());
var SelectedID = Request.Form["SelectedID"];
List selectIDlist = new List();
if (SelectedID != "" && SelectedID != null)
{
selectIDlist = SelectedID.SplitIDString();
query = query.Where(x => selectIDlist.Contains(x.ExaminationProjectID));
}
var dt = query.ToList().Select(q =>
new
{
q.Name,
q.ExaminationLevelText,
q.ExaminationType,
q.IssuedByIDText
}).ToTable();
NpoiExcelHelper neh = new NpoiExcelHelper();
string[] liststring = {
"项目名称","级别","考试类型","发证机关"};
neh.Export(dt, liststring, "考试项目信息列表" + DateTime.Now.ToString("yyyyMMddhhmmss"));
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/ChargeProject/ProjectList").AddMenuParameter()
});
}
[HttpPost]
public ActionResult FeeExcel(QueryParamsModel pararms)
{
List configuretViews = new List();
configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
configuretViews.AddRange(pararms.getConditions());
var query = IProjectFeeService.GetProjectFeeList(configuretViews.ToArray());
var SelectedID = Request.Form["SelectedID"];
List selectIDlist = new List();
if (SelectedID != "" && SelectedID != null)
{
selectIDlist = SelectedID.SplitIDString();
query = query.Where(x => selectIDlist.Contains(x.ExaminationProjectFeeID));
}
var dt = query.ToList().Select(q =>
new
{
q.ExaminationType,
q.ProjectName,
q.Name,
}).ToTable();
NpoiExcelHelper neh = new NpoiExcelHelper();
string[] liststring = {
"考试类型","项目名称","收费标准名称"};
neh.Export(dt, liststring, "收费项目信息列表" + DateTime.Now.ToString("yyyyMMddhhmmss"));
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/ChargeProject/ProjectList").AddMenuParameter()
});
}
///
/// 项目设置列表查询
///
///
///
[HttpPost]
public ActionResult GetProjectFeeListViewGrid(QueryParamsModel pararms)
{
List configuretViews = new List();
configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
configuretViews.AddRange(pararms.getConditions());
return base.Json(IProjectFeeService.GetProjectFeeGrid((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
}
///
/// 项目费用编辑页
///
///
///
[HttpGet]
public ActionResult FeeEdit(Guid? ExaminationProjectFeeID, bool? isCopy)
{
ExaminationProjectFeeView projectFeeView = new ExaminationProjectFeeView() { ExaminationProjectFeeID = Guid.NewGuid() };
if (ExaminationProjectFeeID.HasValue && ExaminationProjectFeeID != Guid.Empty)
{
projectFeeView = IProjectFeeService.GetProjectFee(ExaminationProjectFeeID);
//如果是复制新增
if (isCopy == true)
{
projectFeeView.ExaminationProjectFeeID = Guid.NewGuid();
projectFeeView.RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE;
IProjectFeeService.ProjectFeeEdit(projectFeeView);
var FeeTypeList = IProjectFeeService.GetProjectFeeTypeList(s => s.ExaminationProjectFeeID == ExaminationProjectFeeID).ToList();
FeeTypeList.ForEach(s =>
{
s.ExaminationProjectFeeID = projectFeeView.ExaminationProjectFeeID;
s.ExaminationProjectFeeTypeID = Guid.NewGuid();
IProjectFeeService.ProjectFeeTypeEdit(s);
});
}
}
else
{
projectFeeView.RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE;
IProjectFeeService.ProjectFeeEdit(projectFeeView);
}
return View(projectFeeView);
}
///
/// 项目费用编辑提交
///
///
///
[HttpPost]
public ActionResult FeeEdit(ExaminationProjectFeeView view)
{
try
{
var model = IProjectFeeService.GetProjectFeeView(x => (x.ExaminationProjectID == view.ExaminationProjectID && x.Name == view.Name) && x.ExaminationProjectFeeID != view.ExaminationProjectFeeID && x.RecordStatus != 0);
if (model != null)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "同一项目名称,收费标准名称不能重复!"
});
}
view.RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.USABLE;
IProjectFeeService.ProjectFeeEdit(view);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// 项目设置编辑页
///
///
///
[HttpGet]
public ActionResult ProjectEdit(Guid? ExaminationProjectID)
{
ExaminationProjectView projectFeeView = new ExaminationProjectView() { ExaminationProjectID = Guid.NewGuid() };
if (ExaminationProjectID.HasValue && ExaminationProjectID != Guid.Empty)
{
projectFeeView = IProjectFeeService.GetProject(ExaminationProjectID);
}
return View(projectFeeView);
}
///
/// 项目设置页面提交
///
///
///
[HttpPost]
public ActionResult ProjectEdit(ExaminationProjectView view)
{
try
{
//同一类型需作唯一性判断
var model = IProjectFeeService.GetProjectView(x => x.Name == view.Name && x.ExaminationProjectID != view.ExaminationProjectID);
if (model != null)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "项目名称不允许重复!"
});
}
var subjectList = DataGrid.GetTableData("dgSubjectList");
IProjectFeeService.ProjectEdit(view, subjectList);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
[HttpGet]
public ActionResult SelectSubject(Guid? examinationProjectID)
{
ViewBag.ExaminationProjectID = examinationProjectID;
return View();
}
[HttpPost]
public ActionResult SubjectListByProjectID(QueryParamsModel pararms, Guid? projectID)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//examinationPlanID = Request.Form["examinationPlanID"].ParseStrTo();
return base.Json(IProjectFeeService.GetSubjectByProjectIDGrid(configuretView, projectID));
}
[HttpPost]
public ActionResult SubjectList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//examinationPlanID = Request.Form["examinationPlanID"].ParseStrTo();
return base.Json(IProjectFeeService.GetSubjectListGrid(configuretView, (int)pararms.page, (int)pararms.rows));
}
///
/// 删除项目
///
///
///
[HttpPost]
public JsonResult DeleteProject(string ExaminationProjectIDs)
{
try
{
List list = ExaminationProjectIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
.Select(x => (Guid?)new Guid(x)).ToList();
IProjectFeeService.ProjectDelete(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);
}
}
}
}