using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.EvaluationManage; using EMIS.ViewModel; using EMIS.ViewModel.EvaluationManage; using EMIS.Web.Controls; using Bowin.Common.Data; using EMIS.CommonLogic.CalendarManage; using EMIS.CommonLogic.EducationManagement; using EMIS.ViewModel.EvaluationManage.EvaluationEnter; using System.Text; using System.Collections; using EMIS.Utility; using Bowin.Common.JSON; using EMIS.Entities; using System.Text.RegularExpressions; using EMIS.Utility.FormValidate; namespace EMIS.Web.Controllers.EvaluationManage.EvaluationEnter { [Authorization] public class EvaluationEnterController : Controller { public IEvaluationEnterServices EvaluationEnterServices { get; set; } public IEvaluationTargetServices EvaluationTargetServices { get; set; } public IEvaluationProjectServices EvaluationProjectServices { get; set; } public IEvaluationTableServices EvaluationTableServices { get; set; } public IEvaluationNormServices EvaluationNormServices { get; set; } //public IEvaluationNeedServices EvaluationNeedServices { get; set; } public IEvaluationTypeServices EvaluationTypeServices { get; set; } public IEvaluationSettingServices EvaluationSettingServices { get; set; } Guid? educationMissionID = Guid.Empty; /// /// 进入评价页面 /// /// [HttpGet] public ActionResult List() { return View(); } [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var curUser = CustomPrincipal.Current; var schoolyearID = pararms.getExtraGuid("SchoolyearDropdown"); var result = EvaluationEnterServices.GetEvaluationEnterViewGrid(configuretView, schoolyearID, curUser.UserID, curUser.RoleID, curUser.IsStudent, (int)pararms.page, (int)pararms.rows); return Json(result); } /// /// 学生平台进入评价 /// /// [HttpGet] public ActionResult StudentList() { return View(); } /// /// 查询列表 /// /// /// [HttpPost] public ActionResult StudentList(QueryParamsModel pararms) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); return base.Json(EvaluationEnterServices.GetEvaluationEnterViewGrid(configuretView, null, curUser.UserID, curUser.RoleID, curUser.IsStudent, (int)pararms.page, (int)pararms.rows)); } /// /// /// /// /// /// /// /// public ActionResult Edit(Guid? evaluationSettingID, Guid? evaluationTableID, Guid? evaluationEnterID, bool IsEvaluation/*是否在可评时间内*/) { var vm = new EvaluationEnterView(); try { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; bool isStudent = curUser.IsStudent;//获取当前用户是否是学生 // Guid? typeID = isStudent == true ? Guid.Parse("AAF0A913-3A57-431A-8D4B-CAF11B130759")/*学生评*/ : Guid.Parse("B6D2461D-6F6E-4F6A-AF4F-2A9F34830F56")/*同行评*/; EM_EvaluationTable EvaluationTable = null; EvaluationEnterView evaluationEnterEntity = EvaluationEnterServices.GetEvaluationSettingOrEnterView(evaluationSettingID, curUser.UserID, curUser.RoleID, isStudent);//加载进入评价的被评教师、课程名称、教研室、相关信息 Guid? educationMissionClassID = evaluationEnterEntity.EducationMissionClassID; if (evaluationEnterEntity != null) { educationMissionClassID = evaluationEnterEntity.EducationMissionClassID; evaluationTableID = evaluationEnterEntity.EvaluationTableID; } if (evaluationTableID == null || evaluationTableID == Guid.Empty) { throw new Exception("评价类型与评价表不匹配,请检查。"); } ViewBag.EducationMissionClassID = educationMissionClassID; educationMissionID = educationMissionClassID; ViewBag.EvaluationTableID = evaluationTableID; EvaluationTable = EvaluationTableServices.GetEvaluationTable(evaluationTableID); ViewBag.TableWeight = EvaluationTable.Weight;//评价表权重; ViewBag.TableName = EvaluationTable.Name; //var evaluationTableLsit = EvaluationEnterServices.GetCreateEvaluationEnterTable(evaluationTableID, configuretView);//评价表ID、获取对应评价表 //ViewData["evaluationTableLsit"] = evaluationTableLsit; //根据教学任务班ID、获取相关课程、教师、教研室内容 ViewBag.UserNames = evaluationEnterEntity.UserNames;//教师名称 ViewBag.CourseName = evaluationEnterEntity.CourseName;//课程名称 ViewBag.Remark = evaluationEnterEntity.DepartmentName;//教研室 ViewBag.LimitMore = evaluationEnterEntity.LimitMore;//限制评价次数 int modifyTimeCount = 0;//已评次数 if (evaluationEnterID != Guid.Empty) { ViewBag.evaluationEnterID = evaluationEnterID; EM_EvaluationEnter evaluationEnterOrProjectEntity = EvaluationEnterServices.GetEvaluationEnterView(evaluationEnterID); if (evaluationEnterOrProjectEntity != null) { vm.EvaluationTableID = evaluationEnterOrProjectEntity.EvaluationTableID; vm.EducationMissionClassID = evaluationEnterOrProjectEntity.EducationMissionClassID; vm.EvaluationEnterID = evaluationEnterOrProjectEntity.EvaluationEnterID; vm.Remark = evaluationEnterOrProjectEntity.Remark; ViewBag.evaluationEnterID = evaluationEnterOrProjectEntity.EvaluationEnterID; modifyTimeCount = EvaluationEnterServices.GetEvaluationEnter_EM_EvaluationProjectList(evaluationEnterOrProjectEntity.EvaluationEnterID).GroupBy(x => x.ModifyTime).Select(x => x).Count(); } // EvaluationTypeView evaluationTypeEntity = EvaluationTypeServices.GetEvaluationTypeView(EvaluationTable.TypeID); } //判断是否是管理员 如果是管理员、那么禁用保存按钮 if (!curUser.IsStudent) { IsEvaluation = EvaluationEnterServices.GteDataRange(curUser.RoleID); } if (modifyTimeCount >= evaluationEnterEntity.LimitMore) { IsEvaluation = false;//如果已评次数大于 限评次数、那么隐藏保存按钮 } vm.PhotoUrl = evaluationEnterEntity.PhotoUrl;//教师照片 EM_EvaluationNeed evaluationNeedEntity = null; ViewBag.ContentStr = "评价需知内容";//教师评价需知内容 //EM_EvaluationNeed evaluationNeedEntity = EvaluationNeedServices.GetEvaluationNeedByRole(isStudent == true ? (int)SYS_RoleType.Student : (int)SYS_RoleType.Teacher); //if (evaluationNeedEntity != null) //{ // ViewBag.ContentStr = evaluationNeedEntity.Content;//教师评价需知内容 //} //else //{ // throw new Exception("对应的评价需知信息不能为空。"); //} // ViewBag.RoleType = isStudent == true ? "学生用" : "教师用"; ViewBag.YP = modifyTimeCount; ViewBag.IsEvaluation = IsEvaluation; } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { WindowID = Request["WindowID"], msg = "请求失败:" + ex.Message, url = Url.Action("List").AddMenuParameter() }); } return View(vm); } /// /// 新增或更新 /// /// /// [HttpPost] public ActionResult Edit(EvaluationEnterView vm) { try { vm.UserID = CustomPrincipal.Current.UserID; EvaluationEnterServices.Save(vm, CustomPrincipal.Current.IsStudent);//保存或更新进入评价数据 return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// /// /// public JsonResult GetTitle() { ArrayList arUpList = new ArrayList(); arUpList.Add(new { field = "OrderID", title = "次序", align = "center", width = "150" }); arUpList.Add(new { field = "ProjectName", title = "评价项目", align = "center", width = "300" }); arUpList.Add(new { field = "NormNameProjectID", title = "评价项目ID", align = "center", width = "50" }); arUpList.Add(new { field = "TargetID", title = "评价指标ID", align = "center", width = "50" }); arUpList.Add(new { field = "TargetWeight", title = "评价指标分数", align = "center", width = "50" }); arUpList.Add(new { field = "Weight", title = "权重", align = "center", width = "150" }); arUpList.Add(new { field = "NormNames", title = "评分标准", align = "center", width = "250" }); return Json(new { UpTitle = JsonHelper.ToJSON(arUpList) }, JsonRequestBehavior.AllowGet); } /// /// 根据对应的评价表创建表格 /// /// /// public JsonResult GetList(string tableID, string evaluationEnterID) { StringBuilder strRows = new StringBuilder(); Guid TableID = Guid.Parse(tableID); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var dataTargetList = EvaluationTargetServices.GetEvaluationTargetViewList(configuretView, TableID, null).Select(x => new { x.TargetID, x.NormID, x.Name, x.Weight }).ToList(); int i = 1; foreach (var dataTarget in dataTargetList) { var NormNames = string.Join(" ", EvaluationNormServices.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select(s => s.Name + s.Weight)); var NormNamesWeight = string.Join(",", EvaluationNormServices.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select(s => s.Weight)); StringBuilder strRow = new StringBuilder(); strRow.Append("{"); strRow.Append("\"OrderID\":\"" + dataTarget.Name + "\""); strRow.Append(",\"ProjectName\":\"\""); strRow.Append(",\"NormNameProjectID\":\"\""); strRow.Append(",\"TargetID\":\"" + dataTarget.TargetID + "\""); strRow.Append(",\"TargetWeight\":\"\""); strRow.Append(",\"Weight\":\"" + dataTarget.Weight + "\""); strRow.Append(",\"NormNames\":\"" + NormNames + "\""); strRow.Append("}"); if (string.IsNullOrEmpty(strRows.ToString())) { strRows.Append(strRow); } else { strRows.Append("," + strRow); } var dataProjectList = EvaluationProjectServices.GetEvaluationProjectViewList(configuretView, dataTarget.TargetID, TableID, null).Select(x => new { x.ProjectID, x.OrderID, x.Name, x.Weight, x.Code, x.TargetID, x.TargetWeight }).ToList(); int j = 1; foreach (var dataProject in dataProjectList) { string[] NormNamesArry = NormNamesWeight.Split(',').ToArray(); string strSplit1 = "", strSplit2 = ""; //foreach (var NormName in NormNamesArry) //{ // strSplit2 = Regex.Replace(NormName, "[0-9]", "", RegexOptions.IgnoreCase);//级别 // strSplit1 = Regex.Replace(NormName, "[\u4e00-\u9fa5]", "", RegexOptions.IgnoreCase); //力度 //} //保存以后加载、默认选中 var NormNames1 = ""; if (evaluationEnterID != "") { Guid evaluationEnterIDs = Guid.Parse(evaluationEnterID); IList tieleList = EvaluationEnterServices.GetEvaluationEnterByNormDetail(evaluationEnterIDs, TableID, dataTarget.NormID.Value).Where(x => x.ProjectID == dataProject.ProjectID).ToList(); string htmlStr = ""; string str = ""; if (tieleList.Count > 0) { // var evaluationNormList = EvaluationNormServices.GetEvaluationNormDetailViewList(dataTarget.NormID.Value); //兼容默认还原之前选中值 IList evaluationNormList = EvaluationNormServices.GetEvaluationNormOrProjectDetailViewList(dataTarget.NormID.Value); evaluationNormList = evaluationNormList.Where(x => x.ProjectID == dataProject.ProjectID).ToList(); foreach (var evaluationNorm in evaluationNormList) { foreach (var tiele in tieleList) { if (evaluationNorm.Weight == tiele.EvaluationScore && evaluationNorm.ProjectID == tiele.ProjectID) { str = evaluationNorm.Name + ""; } else { str = evaluationNorm.Name + ""; } } htmlStr += " " + str; } NormNames1 = htmlStr; } else { NormNames1 = string.Join(" ", EvaluationNormServices.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select((s, index) => s.Name + "")); } } else { NormNames1 = string.Join(" ", EvaluationNormServices.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select((s, index) => s.Name + "")); } // string.Join(" ", EvaluationNormServices.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select((s, index) => s.Name + "")); j++; StringBuilder strRow1 = new StringBuilder(); strRow1.Append("{"); strRow1.Append("\"OrderID\":\"" + dataProject.OrderID + "\""); strRow1.Append(",\"ProjectName\":\"" + dataProject.Name + "\""); strRow1.Append(",\"NormNameProjectID\":\"" + dataProject.ProjectID + "\""); strRow1.Append(",\"TargetID\":\"" + dataTarget.TargetID + "\""); strRow1.Append(",\"TargetWeight\":\"" + dataTarget.Weight + "\""); strRow1.Append(",\"Weight\":\"" + dataProject.Weight + "\""); strRow1.Append(",\"NormNames\":\"" + NormNames1 + "\""); strRow1.Append("}"); if (string.IsNullOrEmpty(strRows.ToString())) { strRows.Append(strRow1); } else { strRows.Append("," + strRow1); } } i++; } return Json(new { rows = strRows.ToString(), total = 0 }, JsonRequestBehavior.AllowGet); //var tableStrList = strRows.ToString().JsonToObject>();//将json转实体集合 //return tableStrList; } /// /// /// /// /// [HttpPost] public ActionResult GetWeightSum(string targetIDs) { List list = new List(); for (int i = 0; i < targetIDs.Split(',').Length; i++) { string id = targetIDs.Split(',')[i]; if (!string.IsNullOrEmpty(id)) { Guid targetID = new Guid(id); list.Add(targetID); } } decimal? WeightSum = EvaluationTargetServices.GetEvaluationTargetList(list).Select(x => x.Weight).Sum(); return base.Json(WeightSum.ToString()); } [HttpPost] public ActionResult GetProjectWeightSum(string targetID) { Guid TargetID = Guid.Parse(targetID); List list = new List(); list.Add(TargetID); decimal? WeightSum = EvaluationTargetServices.GetEvaluationProjectList(TargetID).Select(x => x.Weight).Sum(); return base.Json(WeightSum.ToString()); } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { try { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var schoolyearID = Request.Form["SchoolyearDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["SchoolyearDropdown"].ParseStrTo(); var dt = EvaluationEnterServices.GetEvaluationEnterViewList(configuretView, schoolyearID, CustomPrincipal.Current.UserID, CustomPrincipal.Current.RoleID, CustomPrincipal.Current.IsStudent).Select(x => new { x.EvaluationSettingCode, x.CourseName, x.EvaluationTableTypeName, x.UserCodes, x.UserNames, x.EvaluationTypeName, x.EvaluationCount }).ToTable(); string[] liststring = { "评价编号", "课程名称", "评价类型 ", "被评教师号", "被评教师", "参评类型 ", "已评次数" }; neh.Export(dt, liststring, "进入评价信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/EvaluationEnter/List").AddMenuParameter() }); } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { msg = "导出失败,原因:" + ex.Message + "!", url = Url.Content("~/EvaluationEnter/List").AddMenuParameter() }); } } } }