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.Web.Controls; using EMIS.ViewModel.ScoreManage; using Bowin.Common.Utility; using Bowin.Web.Controls.Mvc; using EMIS.Utility; namespace EMIS.Web.Controllers.ScoreManage { [Authorization] public class ScoreParameterCollegeSettingController : Controller { public IScoreParamterCollegeSettingServices ScoreParamterCollegeSettingServices { get; set; } public ActionResult List() { return View(); } public ActionResult Edit(string action, Guid? scoreParameterCollegeSettingID) { ScoreParameterCollegeSettingView entity; if (scoreParameterCollegeSettingID.HasValue) { entity = ScoreParamterCollegeSettingServices.GetScoreParameterCollegeSettingView(scoreParameterCollegeSettingID.Value); } else { entity = new ScoreParameterCollegeSettingView(); } var scoreParameterCollegeSettingDetailList = ScoreParamterCollegeSettingServices.GetScoreParameterSettingViewForDetail(scoreParameterCollegeSettingID); ViewData["scoreParameterCollegeSettingDetailList"] = scoreParameterCollegeSettingDetailList; return View(entity); } [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var collegeID = pararms.getExtraGuid("cbgCollege"); var years = pararms.getExtraInt("ddlGradeYear") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlGradeYear"); return Json(ScoreParamterCollegeSettingServices.GetScoreParameterCollegeSettingViewGrid(configuretView, collegeID, years, pararms.page, pararms.rows)); } [HttpPost] public ActionResult Delete(string scoreParameterCollegeSettingIDString) { var deleteIDList = scoreParameterCollegeSettingIDString.Split(',') .Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); try { this.ScoreParamterCollegeSettingServices.Delete(deleteIDList); return Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" }); } catch (Exception ex) { return Json(new ReturnMessage { IsSuccess = false, Message = "删除失败:" + ex.Message }); } } [HttpPost] public ActionResult Edit(ScoreParameterCollegeSettingView scoreParameterCollegeSettingView, FormCollection collection) { List detailViewList = new List(); #region 获取界面控件的值到detailViewList #region 通用设置 var commonName = DropdownList.PLEASE_SELECT.ToString() + "_" + DropdownList.PLEASE_SELECT.ToString(); var commonScoreFormula = collection.GetValue("ddlScoreFormula_" + commonName).AttemptedValue.ParseStrTo(); var commonIsScoreFormula = (bool?)collection.GetValue("chkScoreFormula_" + commonName).ConvertTo(typeof(bool?)); var commonCreditFormula = (Guid?)collection.GetValue("ddlCreditFormula_" + commonName).AttemptedValue.ParseStrTo(); var commonIsCreditFormula = (bool?)collection.GetValue("chkCreditFormula_" + commonName).ConvertTo(typeof(bool?)); var commonGradePointFormula = (Guid?)collection.GetValue("ddlGradePointFormula_" + commonName).AttemptedValue.ParseStrTo(); var commonIsGradePointFormula = (bool?)collection.GetValue("chkGradePointFormula_" + commonName).ConvertTo(typeof(bool?)); //if (commonScoreFormula == null || commonCreditFormula == null || commonGradePointFormula == null) //{ // return Json(new ReturnMessage // { // IsSuccess = false, // Message = "保存失败:必须填写通用设置的总分公式、学分公式、绩点公式。" // }); //} var examsCategoryList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExamsCategory); var courseTypeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_CourseType); detailViewList.Add(new ScoreParameterSettingView { ExamsTypeID = null, CourseTypeID = null, ScoreFormulaID = commonScoreFormula, IsTotalFormula = commonIsScoreFormula ?? false, CreditFormulaID = commonCreditFormula, IsCreditFormula = commonIsCreditFormula ?? false, GradePointFormulaID = commonGradePointFormula, IsGradePointFormula = commonIsGradePointFormula ?? false }); #endregion #region 为了减少循环次数,按考试性质和详细设置一起来 foreach (var examsCategory in examsCategoryList) { var examsCategoryName = (examsCategory.Value ?? DropdownList.PLEASE_SELECT).ToString() + "_" + DropdownList.PLEASE_SELECT.ToString(); var examsCategoryScoreFormula = (Guid?)collection.GetValue("ddlScoreFormula_" + examsCategoryName).AttemptedValue.ParseStrTo(); var examsCategoryIsScoreFormula = (bool?)collection.GetValue("chkScoreFormula_" + examsCategoryName).ConvertTo(typeof(bool?)); var examsCategoryCreditFormula = (Guid?)collection.GetValue("ddlCreditFormula_" + examsCategoryName).AttemptedValue.ParseStrTo(); var examsCategoryIsCreditFormula = (bool?)collection.GetValue("chkCreditFormula_" + examsCategoryName).ConvertTo(typeof(bool?)); var examsCategoryGradePointFormula = (Guid?)collection.GetValue("ddlGradePointFormula_" + examsCategoryName).AttemptedValue.ParseStrTo(); var examsCategoryIsGradePointFormula = (bool?)collection.GetValue("chkGradePointFormula_" + examsCategoryName).ConvertTo(typeof(bool?)); detailViewList.Add(new ScoreParameterSettingView { ExamsTypeID = examsCategory.Value, CourseTypeID = null, ScoreFormulaID = examsCategoryScoreFormula, IsTotalFormula = examsCategoryIsScoreFormula ?? false, CreditFormulaID = examsCategoryCreditFormula, IsCreditFormula = examsCategoryIsCreditFormula ?? false, GradePointFormulaID = examsCategoryGradePointFormula, IsGradePointFormula = examsCategoryIsGradePointFormula ?? false }); foreach (var courseType in courseTypeList) { var courseTypeName = (examsCategory.Value ?? DropdownList.PLEASE_SELECT).ToString() + "_" + (courseType.Value ?? DropdownList.PLEASE_SELECT).ToString(); var courseTypeScoreFormula = (Guid?)collection.GetValue("ddlScoreFormula_" + courseTypeName).AttemptedValue.ParseStrTo(); var courseTypeIsScoreFormula = (bool?)collection.GetValue("chkScoreFormula_" + courseTypeName).ConvertTo(typeof(bool?)); var courseTypeCreditFormula = (Guid?)collection.GetValue("ddlCreditFormula_" + courseTypeName).AttemptedValue.ParseStrTo(); var courseTypeIsCreditFormula = (bool?)collection.GetValue("chkCreditFormula_" + courseTypeName).ConvertTo(typeof(bool?)); var courseTypeGradePointFormula = (Guid?)collection.GetValue("ddlGradePointFormula_" + courseTypeName).AttemptedValue.ParseStrTo(); var courseTypeIsGradePointFormula = (bool?)collection.GetValue("chkGradePointFormula_" + courseTypeName).ConvertTo(typeof(bool?)); detailViewList.Add(new ScoreParameterSettingView { ExamsTypeID = examsCategory.Value, CourseTypeID = courseType.Value, ScoreFormulaID = courseTypeScoreFormula, IsTotalFormula = courseTypeIsScoreFormula ?? false, CreditFormulaID = courseTypeCreditFormula, IsCreditFormula = courseTypeIsCreditFormula ?? false, GradePointFormulaID = courseTypeGradePointFormula, IsGradePointFormula = courseTypeIsGradePointFormula ?? false }); } } #endregion foreach (var courseType in courseTypeList) { var courseTypeName = DropdownList.PLEASE_SELECT.ToString() + "_" + (courseType.Value ?? DropdownList.PLEASE_SELECT).ToString(); var courseTypeScoreFormula = (Guid?)collection.GetValue("ddlScoreFormula_" + courseTypeName).AttemptedValue.ParseStrTo(); var courseTypeIsScoreFormula = (bool?)collection.GetValue("chkScoreFormula_" + courseTypeName).ConvertTo(typeof(bool?)); var courseTypeCreditFormula = (Guid?)collection.GetValue("ddlCreditFormula_" + courseTypeName).AttemptedValue.ParseStrTo(); var courseTypeIsCreditFormula = (bool?)collection.GetValue("chkCreditFormula_" + courseTypeName).ConvertTo(typeof(bool?)); var courseTypeGradePointFormula = (Guid?)collection.GetValue("ddlGradePointFormula_" + courseTypeName).AttemptedValue.ParseStrTo(); var courseTypeIsGradePointFormula = (bool?)collection.GetValue("chkGradePointFormula_" + courseTypeName).ConvertTo(typeof(bool?)); detailViewList.Add(new ScoreParameterSettingView { ExamsTypeID = null, CourseTypeID = courseType.Value, ScoreFormulaID = courseTypeScoreFormula, IsTotalFormula = courseTypeIsScoreFormula ?? false, CreditFormulaID = courseTypeCreditFormula, IsCreditFormula = courseTypeIsCreditFormula ?? false, GradePointFormulaID = courseTypeGradePointFormula, IsGradePointFormula = courseTypeIsGradePointFormula ?? false }); } #endregion try { if (scoreParameterCollegeSettingView.Years == DropdownList.PLEASE_SELECT) { scoreParameterCollegeSettingView.Years = null; } if (scoreParameterCollegeSettingView.ScoreTypeID == DropdownList.PLEASE_SELECT) { scoreParameterCollegeSettingView.ScoreTypeID = null; } this.ScoreParamterCollegeSettingServices.Save(scoreParameterCollegeSettingView, detailViewList); return Json(new ReturnMessage { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } } }