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.Entities;
using EMIS.ViewModel.ScoreManage;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.JSON;
using Bowin.Common.Exceptions;
namespace EMIS.Web.Controllers.ScoreManage
{
[Authorization]
public class CreditFormulaController : Controller
{
public ICreditFormulaServices creditFormulaServices { get; set; }
//
// GET: /CreditFormula/
public ActionResult List()
{
return View();
}
///
/// 查询列表
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
string name = pararms.getExtraString("textName");
return Json(creditFormulaServices.GetCreditFormulaGrid(name, (int)pararms.page, (int)pararms.rows));
}
///
/// 编辑
///
///
///
public ActionResult Edit(Guid? creditFormulaID)
{
CreditFormulaView creditFormulaView = new CreditFormulaView();
if (creditFormulaID != null && creditFormulaID.Value != Guid.Empty)
{
ER_CreditFormula creditFormula = creditFormulaServices.GetCreditFormula(creditFormulaID);
creditFormulaView.CreditFormulaID = creditFormula.CreditFormulaID;
creditFormulaView.Name = creditFormula.Name;
creditFormulaView.Scores = creditFormula.Scores;
}
return View(creditFormulaView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(CreditFormulaView creditFormulaView)
{
try
{
creditFormulaServices.CreditFormulaAdd(creditFormulaView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string creditFormulaIDs)
{
try
{
List list = new List();
for (int i = 0; i < creditFormulaIDs.Split(',').Length; i++)
{
string id = creditFormulaIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid creditFormulaID = new Guid(id);
list.Add(creditFormulaID);
}
}
creditFormulaServices.CreditFormulaDelete(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 CreditFormulaDataBind(DropdownListBindType? bindType)
{
List list = creditFormulaServices.GetCreditFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = x.CreditFormulaID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
///
/// 绑定学分下拉列表
///
///
///
[HttpPost]
public ActionResult CreditFormulaDataJsonBind(DropdownListBindType? bindType)
{
List list = creditFormulaServices.GetCreditFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = new ER_CreditFormula { CreditFormulaID = x.CreditFormulaID, Name = x.Name, Scores = x.Scores }.ToJson() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
}
}