123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Dynamic;
- using EMIS.ViewModel;
- using EMIS.Utility;
- using EMIS.CommonLogic.ScoreManage;
- using EMIS.Entities;
- using Bowin.Common.Mvc;
- using Bowin.Common.Linq.Entity;
- using Bowin.Web.Controls.Mvc;
- using EMIS.ViewModel.ScoreManage;
- using Bowin.Common.Exceptions;
- using EMIS.ViewModel.CacheManage;
- using Bowin.Common.JSON;
- namespace EMIS.Web.Controllers.ScoreManage
- {
- [Authorization]
- public class ScoreFormulaController : JsonNetController
- {
- public IScoreFormulaServices scoreFormulaServices { get; set; }
-
- /// <summary>
- /// 总分公式页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- ViewBag.ScoreDynamicTypes = scoreDynamicTypes;
- return View();
- }
- /// <summary>
- /// 总分公式列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- var name = pararms.getExtraString("textName");
- var query = scoreFormulaServices.GetScoreFormulaGrid(name, (int)pararms.page, (int)pararms.rows);
- var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- var list = WrapResult(query.rows, differentDynamicTypes);
- return Json(new { total = list.Count, rows = list });
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="scoreFormulaID"></param>
- /// <returns></returns>
- public ActionResult Edit(Guid? scoreFormulaID)
- {
- ScoreFormulaView scoreFormulaView = new ScoreFormulaView();
- if (scoreFormulaID != null && scoreFormulaID != Guid.Empty)
- {
- ER_ScoreFormula scoreFormula = scoreFormulaServices.GetScoreFormula(scoreFormulaID);
- scoreFormulaView.ScoreFormulaID = scoreFormula.ScoreFormulaID;
- scoreFormulaView.Name = scoreFormula.Name;
- }
- return View(scoreFormulaView);
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="scoreFormula"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(ScoreFormulaView scoreFormulaView)
- {
- try
- {
- var scoreFormulaDetailList = DataGrid.GetTableData<ScoreFormulaDropdownDetailView>("dgScoreFormulaDetailList");
- scoreFormulaServices.ScoreFormulaAdd(scoreFormulaView, scoreFormulaDetailList);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败,原因:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="scoreFormulaIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string scoreFormulaIDs)
- {
- try
- {
- List<Guid> list = new List<Guid>();
- for (int i = 0; i < scoreFormulaIDs.Split(',').Length; i++)
- {
- string id = scoreFormulaIDs.Split(',')[i];
- if (!string.IsNullOrEmpty(id))
- {
- Guid scoreFormulaID = new Guid(id);
- list.Add(scoreFormulaID);
- }
- }
- scoreFormulaServices.ScoreFormulaDelete(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 base.Json("删除失败,原因:" + mge);
- }
- }
- /// <summary>
- /// 总分公式明细页面
- /// </summary>
- /// <param name="scoreFormulaID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ScoreFormulaDetailList(Guid? scoreFormulaID)
- {
- var listScoreFormulaDetail = scoreFormulaServices.GetScoreFormulaDetailListByScoreFormulaID(scoreFormulaID);
- return Json(new GridResultSet<ScoreFormulaDropdownDetailView>() { rows = listScoreFormulaDetail, total = listScoreFormulaDetail.Count });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="result"></param>
- /// <param name="differentDynamicTypes"></param>
- /// <returns></returns>
- private List<ExpandoObject> WrapResult(List<ER_ScoreFormula> result, IEnumerable<Sys_DictionaryItem> differentDynamicTypes)
- {
- var list = new List<ExpandoObject>();
- if (result == null || result.Count == 0)
- {
- return list;
- }
- var scoreFormulas = result.Select(s => new { s.ScoreFormulaID, s.Name }).Distinct();
- foreach (var scoreFormula in scoreFormulas)
- {
- dynamic item = new ExpandoObject();
- item.ScoreFormulaID = scoreFormula.ScoreFormulaID;
- item.Name = scoreFormula.Name;
- ER_ScoreFormulaDetail scoreFormulaDetail = null;
- foreach (var differentDynamicType in differentDynamicTypes)
- {
- scoreFormulaDetail = scoreFormulaServices.GetScoreFormulaDetailList(scoreFormula.ScoreFormulaID).Where(x => x.ScoreType == differentDynamicType.Value).FirstOrDefault();
- var percentage = scoreFormulaDetail == null ? 0 : scoreFormulaDetail.Percentage;
- ((IDictionary<string, object>)item).Add("ScoreType" + differentDynamicType.Value.ToString(), percentage.ToString());
- }
- list.Add(item);
- }
- return list;
- }
- /// <summary>
- /// 绑定下拉列表
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ScoreFormulaDataBind(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = scoreFormulaServices.GetScoreFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = x.ScoreFormulaID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- /// 绑定下拉列表
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ScoreFormulaDataJosnBind(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = new List<DropdownListItem>();
- var scoreType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ScoreType.ToString());
- List<ER_ScoreFormula> listScoreFormula = scoreFormulaServices.GetScoreFormulaList("");
- foreach (var scoreFormula in listScoreFormula)
- {
- string reulst = "{\"ScoreFormulaID\":\"" + scoreFormula.ScoreFormulaID + "\",";
- foreach (var st in scoreType)
- {
- ER_ScoreFormulaDetail scoreFormulaDetail = scoreFormula.ER_ScoreFormulaDetail.ToList().Where(x => x.ScoreType == st.Value).FirstOrDefault();
- if (scoreFormulaDetail != null)
- reulst += "\"Formula_" + st.Value + "\":\"" + scoreFormulaDetail.Percentage + "\",";
- else
- reulst += "\"Formula_" + st.Value + "\":\"0\",";
- }
- reulst = reulst.Substring(0, reulst.Length - 1) + "}";
- DropdownListItem dlt = new DropdownListItem { Text = scoreFormula.Name, Value = reulst };
- list.Add(dlt);
- }
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- }
- }
|