using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.ViewModel;
using EMIS.CommonLogic.ScoreManage;
using EMIS.ViewModel.ScoreManage;
using EMIS.Entities;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.JSON;
using Bowin.Common.Exceptions;
namespace EMIS.Web.Controllers.ScoreManage
{
[Authorization]
public class GradePointFormulaController : Controller
{
public IGradePointFormulaServices gradePointFormulaServices { get; set; }
//
// GET: /GradePointFormula/
public ActionResult List()
{
return View();
}
///
/// 绩点公式设置列表
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
string name = pararms.getExtraString("textName");
return Json(gradePointFormulaServices.GetGradePointFormulaGrid(name, (int)pararms.page, (int)pararms.rows));
}
///
/// 编辑
///
///
///
public ActionResult Edit(Guid? gradePointFormulaID)
{
GradePointFormulaView gradePointFormulaView = new GradePointFormulaView();
if (gradePointFormulaID != null && gradePointFormulaID.Value != Guid.Empty)
{
ER_GradePointFormula gradePointFormula = gradePointFormulaServices.GetGradePointFormula(gradePointFormulaID);
if (gradePointFormula != null)
{
gradePointFormulaView.Name = gradePointFormula.Name;
gradePointFormulaView.GradePointlimit = gradePointFormula.GradePointlimit;
gradePointFormulaView.GradePointFloor = gradePointFormula.GradePointFloor;
}
}
return View(gradePointFormulaView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(GradePointFormulaView gradePointFormulaView)
{
try
{
gradePointFormulaServices.GradePointFormulaAdd(gradePointFormulaView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string gradePointFormulaIDs)
{
try
{
List list = new List();
for (int i = 0; i < gradePointFormulaIDs.Split(',').Length; i++)
{
string id = gradePointFormulaIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid gradePointFormulaID = new Guid(id);
list.Add(gradePointFormulaID);
}
}
gradePointFormulaServices.GradePointFormulaDelete(list);
return 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 this.Json("删除失败,原因:" + mge);
}
}
///
/// 绑定下拉
///
///
///
[HttpPost]
public ActionResult GradePointFormulaDataBind(DropdownListBindType? bindType)
{
List list = gradePointFormulaServices.GetGradePointFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = x.GradePointFormulaID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 绑定下拉
///
///
///
[HttpPost]
public ActionResult GradePointFormulaDataJsonBind(DropdownListBindType? bindType)
{
List list = gradePointFormulaServices.GetGradePointFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = new GradePointView { GradePointFormulaID = x.GradePointFormulaID, Name = x.Name, GradePointlimit = x.GradePointlimit, GradePointFloor = x.GradePointFloor }.ToJson() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
}
}