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 Bowin.Common.Utility; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.ScoreManage; using EMIS.Utility; namespace EMIS.Web.Controllers.ScoreManage { [Authorization] public class ScoreParameterSettingController : Controller { public IParameterServices ParameterServices { get; set; } public IScoreParameterSettingServices ScoreParameterSettingServices { get; set; } public IExamsCategorySettingServices ExamsCategorySettingServices { get; set; } // // GET: /ScoreParameterSetting/ public ActionResult List() { var scoreParameterSettingList = ScoreParameterSettingServices.GetScoreParameterSettingViewGrid(); ViewData["scoreParameterSettingList"] = scoreParameterSettingList; return View(); } [HttpPost] public ActionResult ExamsCategorySettingCheckList() { var examsCategorySettingViewList = ExamsCategorySettingServices.GetExamsCategorySettingViewList(); var listControlItemList = examsCategorySettingViewList.Select(x => new ListControlItem { Text = x.ExamsCategoryDesc, Value = x.ExamsCategoryID, IsSelected = x.IsReadHistory }).ToList(); return Json(listControlItemList); } [HttpPost] public ActionResult List(Guid? ScoreParameterSettingID, FormCollection collection) { try { //var isMisconductCanGraduateExam = collection.GetValue("IsMisconductCanGraduateExam").ConvertTo(typeof(bool?)); //var isLoadScoreForResit = collection.GetValue("IsLoadScoreForResit").ConvertTo(typeof(bool?)); var isScoreEditControlForCharge = collection.GetValue("IsScoreEditControlForCharge").ConvertTo(typeof(bool?)); var examsCategorySettingList = new List(); if(collection.GetValues("chkIsReadScoreHistory") != null) { examsCategorySettingList = collection.GetValues("chkIsReadScoreHistory").Select(x => int.Parse(x)).ToList(); } List scoreParameterSettingList = 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); scoreParameterSettingList.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?)); scoreParameterSettingList.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?)); scoreParameterSettingList.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?)); scoreParameterSettingList.Add(new ScoreParameterSettingView { ExamsTypeID = null, CourseTypeID = courseType.Value, ScoreFormulaID = courseTypeScoreFormula, IsTotalFormula = courseTypeIsScoreFormula ?? false, CreditFormulaID = courseTypeCreditFormula, IsCreditFormula = courseTypeIsCreditFormula ?? false, GradePointFormulaID = courseTypeGradePointFormula, IsGradePointFormula = courseTypeIsGradePointFormula ?? false }); } #endregion //ParameterServices.SaveTo(CF_ParameterType.IsMisconductCanGraduateExam, isMisconductCanGraduateExam); //ParameterServices.SaveTo(CF_ParameterType.LoadScoreForResit, isLoadScoreForResit); ExamsCategorySettingServices.SaveExamsCategorySetting(examsCategorySettingList); ParameterServices.SaveTo(CF_ParameterType.IsScoreEditControlForCharge, isScoreEditControlForCharge); ScoreParameterSettingServices.ScoreParameterSettingServicesAdd(scoreParameterSettingList); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = true, Message = "保存失败,原因:" + ex.Message + "!" }); } } } }