using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.Students;
using System.Dynamic;
using EMIS.ViewModel.ScoreManage;
using Bowin.Common.Utility;
using EMIS.ViewModel;
using EMIS.Utility;
using EMIS.Entities;
using EMIS.CommonLogic.ScoreManage;
using EMIS.Web.Controls;
using EMIS.ViewModel.CacheManage;
using EMIS.CommonLogic.CalendarManage;
using EMIS.CommonLogic.SystemServices;
namespace EMIS.Web.Controllers.ScoreManage
{
[Authorization]
public class PersonalScoreController : Controller
{
public IStudentScoreServices StudentScoreServices { get; set; }
public ICourseGradeServices CourseGradeServices { get; set; }
public IStudentsServices StudentfileServices { get; set; }
public ISchoolYearServices SchoolYearServices { get; set; }
public IParameterServices ParameterServices { get; set; }
///
/// 通用个人成绩页面
///
///
public ActionResult List()
{
List listPersonalCoursematerialScoreView = new List();
ViewBag.ListPersonalCoursematerialScoreView = listPersonalCoursematerialScoreView;
//默认加载学生成绩
//var student = StudentfileServices.Value.GetStudentView();
//ViewBag.StudentNo = student.UserID;
return View();
}
///
/// 广体个人成绩页面
///
///
public ActionResult NewList()
{
List listPersonalCoursematerialScoreView = new List();
ViewBag.ListPersonalCoursematerialScoreView = listPersonalCoursematerialScoreView;
var userID = Request.Params["UserID"];
if (userID != null)
{
ViewBag.StudentNo = userID;
}
//默认加载学生成绩
//var student = StudentfileServices.Value.GetStudentView();
//ViewBag.StudentNo = student.UserID;
return View();
}
//[HttpPost]
//public ActionResult List(Guid? Id)
//{
// var userID = Request.Form["StudentsComboGrid"].ParseStrTo();
// List listPersonalCoursematerialScoreView = new List();
// //课程成绩
// var listCoursematerialScore = courseGradeServices.Value.GetStudentCourseGrade((Guid)userID);
// if (listCoursematerialScore.Count > 0)
// {
// var Student = courseGradeServices.Value.GetStudentPersonalScore((Guid)userID);
// PersonalCoursematerialScoreView personalCoursematerialScoreView = new PersonalCoursematerialScoreView();
// if (Student != null)
// {
// personalCoursematerialScoreView.UserID = Student.UserID;
// personalCoursematerialScoreView.LoginID = Student.LoginID;
// personalCoursematerialScoreView.UserName = Student.UserName;
// personalCoursematerialScoreView.CollegeName = Student.FacultyName;
// personalCoursematerialScoreView.ClassName = Student.ClassName;
// personalCoursematerialScoreView.CoursematerialCount = Student.Menshu;
// personalCoursematerialScoreView.AVGScore = Student.AverageGrade;
// personalCoursematerialScoreView.TotalCredit = Student.TotalScore;
// personalCoursematerialScoreView.PlanningGraduateDate = Student.PlanningGraduateDate;
// }
// personalCoursematerialScoreView.ListStarttermID = listCoursematerialScore.Select(x => (int)x.StarttermID).Distinct().ToList();
// personalCoursematerialScoreView.ListCourseGradeView = listCoursematerialScore.ToList();
// listPersonalCoursematerialScoreView.Add(personalCoursematerialScoreView);
// }
// ViewBag.ListPersonalCoursematerialScoreView = listPersonalCoursematerialScoreView;
// return View();
//}
[HttpPost]
public ActionResult CoursematerialList(Guid? userID)
{
userID = userID ?? Guid.Empty;
List listPersonalCoursematerialScoreView = new List();
//课程成绩
var listCoursematerialScore = CourseGradeServices.GetStudentCourseGrade((Guid)userID);
if (listCoursematerialScore.Count > 0)
{
var Student = CourseGradeServices.GetStudentPersonalScore((Guid)userID);
PersonalCoursematerialScoreView personalCoursematerialScoreView = new PersonalCoursematerialScoreView();
if (Student != null)
{
personalCoursematerialScoreView.UserID = Student.UserID;
personalCoursematerialScoreView.LoginID = Student.LoginID;
personalCoursematerialScoreView.UserName = Student.UserName;
personalCoursematerialScoreView.CollegeName = Student.FacultyName;
personalCoursematerialScoreView.ClassName = Student.ClassName;
personalCoursematerialScoreView.CoursematerialCount = Student.Menshu;
personalCoursematerialScoreView.AVGScore = Student.AverageGrade ?? 0;
personalCoursematerialScoreView.TotalCredit = Student.TotalScore ?? 0;
personalCoursematerialScoreView.PlanningGraduateDate = Student.PlanningGraduateDate;
}
try
{
personalCoursematerialScoreView.ListStarttermID = listCoursematerialScore.Select(x => (int)x.StarttermID).Distinct().ToList();
}
catch (Exception ex)
{
throw ex;
}
personalCoursematerialScoreView.ListCourseGradeView = listCoursematerialScore.ToList();
listPersonalCoursematerialScoreView.Add(personalCoursematerialScoreView);
}
return Json(listPersonalCoursematerialScoreView);
}
///
/// 个人成绩(开课学期分组)
///
///
///
[HttpPost]
public ActionResult NewCoursematerialList(Guid? userID)
{
userID = userID ?? Guid.Empty;
List listPersonalCoursematerialScoreView = new List();
//课程成绩
var listCoursematerialScore = CourseGradeServices.GetStudentCourseGrade((Guid)userID);
if (listCoursematerialScore.Count > 0)
{
var Student = CourseGradeServices.GetStudentPersonalScoreGT((Guid)userID);
PersonalCoursematerialScoreView personalCoursematerialScoreView = new PersonalCoursematerialScoreView();
if (Student != null)
{
personalCoursematerialScoreView.UserID = Student.UserID;
personalCoursematerialScoreView.LoginID = Student.LoginID;
personalCoursematerialScoreView.UserName = Student.UserName;
personalCoursematerialScoreView.CollegeName = Student.FacultyName;
personalCoursematerialScoreView.ClassName = Student.ClassName;
personalCoursematerialScoreView.CoursematerialCount = Student.Menshu;
personalCoursematerialScoreView.AVGScore = Student.AverageGrade ?? 0;
//personalCoursematerialScoreView.TotalCredit = (Student.Required ?? 0) + (Student.CapLimit ?? 0) + (Student.Optional ?? 0) + (Student.Direction ?? 0) + (Student.Commonality ?? 0) + (Student.PractiseNotCredit ?? 0);//Student.TotalScore ?? 0;
personalCoursematerialScoreView.PlanningGraduateDate = Student.PlanningGraduateDate;
personalCoursematerialScoreView.RequiredCredit = ((Student.Required ?? 0) - (Student.PractiseCredit ?? 0));//必修 - 实践环节
personalCoursematerialScoreView.OptionalCourseCredit = ((Student.OptionalCourseCredit ?? 0) - (Student.SchoolbasedCredit ?? 0) - (Student.ElectiveCredit ?? 0));//限选 - 校本课程 - 方向性选修
personalCoursematerialScoreView.FreeSelectionCourseCredit = (Student.FreeSelectionCourseCredit ?? 0) - (Student.ElectivePublicCredit ?? 0);//任选 - 公共选修
personalCoursematerialScoreView.ElectiveCredit = Student.ElectiveCredit ?? 0;
personalCoursematerialScoreView.ElectivePublicCredit = Student.ElectivePublicCredit ?? 0;
personalCoursematerialScoreView.PractiseNotCredit = Student.PractiseNotCredit ?? 0;//实践环节不包含俱乐部
personalCoursematerialScoreView.ClubWithSchoolbasedCredit = ((Student.PractiseWithClub ?? 0) > 4 ? 4 : (Student.PractiseWithClub ?? 0)) + ((Student.SchoolbasedWithClub ?? 0) > 4 ? 4 : (Student.SchoolbasedWithClub ?? 0)) + (Student.SchoolbasedNotClub ?? 0);
personalCoursematerialScoreView.TotalCredit = (Student.Required ?? 0) + (Student.OptionalCourseCredit ?? 0) + (Student.FreeSelectionCourseCredit ?? 0) - (Student.PractiseCredit ?? 0) - (Student.SchoolbasedCredit ?? 0)
+ (Student.PractiseNotCredit ?? 0) + ((Student.PractiseWithClub ?? 0) > 4 ? 4 : (Student.PractiseWithClub ?? 0)) + (Student.SchoolbasedNotClub ?? 0) + ((Student.SchoolbasedWithClub ?? 0) > 4 ? 4 : (Student.SchoolbasedWithClub ?? 0));
}
try
{
personalCoursematerialScoreView.ListStarttermID = listCoursematerialScore.Select(x => (int)x.StarttermID).Distinct().ToList();
}
catch (Exception ex)
{
throw ex;
}
personalCoursematerialScoreView.ListCourseGradeView = listCoursematerialScore.ToList();
listPersonalCoursematerialScoreView.Add(personalCoursematerialScoreView);
}
return Json(listPersonalCoursematerialScoreView);
}
///
/// 学生个人成绩报表
///
///
public ActionResult StudentScoreReport()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult GetSubmitedScoreList(Guid? CoursematerialID, int? StartTermID, Guid? UserID)
{
return base.Json(CourseGradeServices.GetSubmitedScoreList(CoursematerialID.Value, StartTermID, UserID.Value));
}
public ActionResult Add(Guid? submitedScoreID)
{
var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; //获取当前登录用户
Guid curUserID = curUser.UserID;
ViewBag.curUserName = curUser.Name;
ViewBag.curLoginID = curUser.LoginID;
List> listDictionary = new List>();
var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
SubmitedScoreDetailView submitedScoreDetailView = new SubmitedScoreDetailView();
if (submitedScoreID.HasValue)
{
submitedScoreDetailView = CourseGradeServices.GetSubmitedScoreDetailView(submitedScoreID);
ER_SubmitedScore submitedScore = CourseGradeServices.GetSubmitedScore(submitedScoreID);
var listSubmitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.ToList();
foreach (var scoreDynamicType in scoreDynamicTypes)
{
ER_SubmitedScoreDetail submitedScoreDetail = listSubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault();
listDictionary.Add(new Dictionary { { "Formula_" + submitedScoreDetail.ScoreTypeID, submitedScoreDetail.Score.ToString() } });
}
listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
else
{
submitedScoreDetailView.StarttermID = Convert.ToInt32(Request["StarttermID"]);
submitedScoreDetailView.SchoolyearID = new Guid(Request["SchoolyearID"]);
submitedScoreDetailView.CoursematerialID = new Guid(Request["CoursematerialID"]);
submitedScoreDetailView.UserID = new Guid(Request["UserID"]);
foreach (var scoreDynamicType in scoreDynamicTypes)
{
listDictionary.Add(new Dictionary { { "Formula_" + scoreDynamicType.Value, "0" } });
}
listDictionary.Add(new Dictionary { { "TotalScore", "0" } });
}
submitedScoreDetailView.CreatorUserID = curUserID;
ViewBag.ListDictionary = listDictionary;
ViewBag.ScoreDynamicTypes = scoreDynamicTypes;
return View(submitedScoreDetailView);
}
///
/// 新增
///
///
///
[HttpPost]
public ActionResult Add(SubmitedScoreDetailView submitedScoreDetailView)
{
try
{
int atype = Convert.ToInt32(Request.Form["hid_atype"]);
List listExpandoObject = new List();
var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
foreach (var differentDynamicType in differentDynamicTypes)
{
dynamic dyic = new ExpandoObject();
dyic.ScoreTypeID = differentDynamicType.Value;
dyic.Score = Convert.ToDecimal(Request.Form["Formula_" + differentDynamicType.Value]);
listExpandoObject.Add(dyic);
}
submitedScoreDetailView.TotalScore = Convert.ToDecimal(Request.Form["TotalScore"]);
submitedScoreDetailView.ScoreCredit = Convert.ToDecimal(Request.Form["ScoreCredit"]);
submitedScoreDetailView.GradePoint = Convert.ToDecimal(Request.Form["GradePoint"]);
submitedScoreDetailView.Remarks = Request.Params["hid_SaveType"];//识别是否是复制性新增操作~~
submitedScoreDetailView.StudentScoreRemark = Request.Form["Remark"];
//Request.Params["changedUserID"] = submitedScoreDetailView.UserID.ToString();
StudentScoreServices.StudentScoreAdd(submitedScoreDetailView, listExpandoObject);
return Json(new ReturnMessage
{
IsSuccess = true,
Message = "保存成功!",
Data = submitedScoreDetailView.UserID
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
public ActionResult Edit(Guid? submitedScoreID)
{
var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; //获取当前登录用户
Guid curUserID = curUser.UserID;
var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);//获取当前学年学期
Guid schoolYearID = schoolYear.SchoolyearID;
Guid? departmentID = StudentScoreServices.GetDepartmentByUserID(curUserID);
List> listDictionary = new List>();
var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
int examsState = (int)CF_ExamsState.NormalExams;
List examsStateList = StudentScoreServices.GetNormalExamsState();
SubmitedScoreDetailView submitedScoreDetailView = new SubmitedScoreDetailView();
var scoreDigitCount = ParameterServices.GetParameterValue(CF_ParameterType.ScoreDigitCount) ?? 1;
if (submitedScoreID.HasValue)
{
submitedScoreDetailView = CourseGradeServices.GetSubmitedScoreDetailView(submitedScoreID);
ER_SubmitedScore submitedScore = CourseGradeServices.GetSubmitedScore(submitedScoreID);
var listSubmitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.ToList();
foreach (var scoreDynamicType in scoreDynamicTypes)
{
ER_SubmitedScoreDetail submitedScoreDetail = listSubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault();
listDictionary.Add(new Dictionary { { "Formula_" + submitedScoreDetail.ScoreTypeID, submitedScoreDetail.Score == null ? "" : submitedScoreDetail.Score.ToString() } });//平时、实验、考试成绩为空时显示为0
}
if (examsStateList.Any(x => x.Value == submitedScoreDetailView.ExamsStateID))
{
if (submitedScoreDetailView.ResultTypeID == (int)CF_ResultType.Percentage)
{
if (scoreDigitCount > 0)
{
if (scoreDigitCount > 1)
{
submitedScoreDetailView.TotalScore = Math.Round((decimal)submitedScoreDetailView.TotalScore, scoreDigitCount);
//listDictionary.RemoveAll(x => x.Keys.Contains("TotalScore"));
listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
else
{
submitedScoreDetailView.TotalScore = Math.Round((decimal)submitedScoreDetailView.TotalScore, scoreDigitCount);
//listDictionary.RemoveAll(x => x.Keys.Contains("TotalScore"));
listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
}
else
{
submitedScoreDetailView.TotalScore = Math.Round((decimal)submitedScoreDetailView.TotalScore, scoreDigitCount);
//listDictionary.RemoveAll(x => x.Keys.Contains("TotalScore"));
listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
//listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
else {
string totalStr = StudentScoreServices.GetResultTypeDetailByIDandScore((int)submitedScoreDetailView.ResultTypeID, (decimal)submitedScoreDetailView.TotalScore).Name;
submitedScoreDetailView.ResultTypeDetailID = StudentScoreServices.GetResultTypeDetailByIDandScore((int)submitedScoreDetailView.ResultTypeID, (decimal)submitedScoreDetailView.TotalScore).ResultTypeDetailID;
listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
}
else
{
string totalStr = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ExamsState.ToString()).Where(x => x.Value == submitedScoreDetailView.ExamsStateID).Select(x => x.Name).FirstOrDefault();
listDictionary.Add(new Dictionary { { "TotalScore", totalStr } });
}
}
else
{
if (Request["UserID"].ToString() != null && Request["UserID"].ToString() != "")
submitedScoreDetailView.UserID = new Guid(Request["UserID"]);
if (submitedScoreDetailView.UserID != null) {
submitedScoreDetailView.ClassName = StudentScoreServices.GetClassByUserID(submitedScoreDetailView.UserID.Value);
}
submitedScoreDetailView.ResultTypeID = (int)CF_ResultType.TwoGrade;
foreach (var scoreDynamicType in scoreDynamicTypes)
{
listDictionary.Add(new Dictionary { { "Formula_" + scoreDynamicType.Value, "" } });
}
listDictionary.Add(new Dictionary { { "TotalScore", "" } });
submitedScoreDetailView.SchoolyearID = schoolYearID;
submitedScoreDetailView.ExamsCategoryID = (int)CF_ExamsCategory.FinalExam;
submitedScoreDetailView.ExaminationModeID = (int)CF_ExaminationMode.WrittenExam;
submitedScoreDetailView.ExamsStateID = (int)CF_ExamsState.NormalExams;
submitedScoreDetailView.CreatorUserID = curUserID;
submitedScoreDetailView.DepartmentID = departmentID;
}
//var scoreDigitCount = ParameterServices.GetParameterValue(CF_ParameterType.ScoreDigitCount) ?? 1;
if (scoreDigitCount > 0)
{
if (scoreDigitCount > 1)
{
submitedScoreDetailView.TotalScorePattern = @"^\d+(\.\d{1," + scoreDigitCount.ToString() + "})?$";
submitedScoreDetailView.TotalScorePatternError = "请输入整数或1-" + scoreDigitCount.ToString() + "位小数。";
//submitedScoreDetailView.TotalScore = Math.Round((decimal)submitedScoreDetailView.TotalScore, scoreDigitCount);
//listDictionary.RemoveAll(x => x.Keys.Contains("TotalScore"));
//listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
else
{
submitedScoreDetailView.TotalScorePattern = @"^\d+(\.\d{1}(0{0,1}))?$";
submitedScoreDetailView.TotalScorePatternError = "请输入整数或1位小数。";
//submitedScoreDetailView.TotalScore = Math.Round((decimal)submitedScoreDetailView.TotalScore, scoreDigitCount);
//listDictionary.RemoveAll(x => x.Keys.Contains("TotalScore"));
//listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
}
else
{
submitedScoreDetailView.TotalScorePattern = @"^\d+(\.0{1,2})?$";
submitedScoreDetailView.TotalScorePatternError = "请输入整数。";
//submitedScoreDetailView.TotalScore = Math.Round((decimal)submitedScoreDetailView.TotalScore, scoreDigitCount);
//listDictionary.RemoveAll(x => x.Keys.Contains("TotalScore"));
//listDictionary.Add(new Dictionary { { "TotalScore", submitedScoreDetailView.TotalScore.ToString() } });
}
ViewBag.ListDictionary = listDictionary;
ViewBag.ScoreDynamicTypes = scoreDynamicTypes;
ViewBag.ResultTypeDetailID = submitedScoreDetailView.ResultTypeDetailID;
return View(submitedScoreDetailView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(SubmitedScoreDetailView submitedScoreDetailView)
{
try
{
int atype = Convert.ToInt32(Request.Form["hid_atype"]);
List listExpandoObject = new List();
var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
decimal? Score = 0;
foreach (var differentDynamicType in differentDynamicTypes)
{
dynamic dyic = new ExpandoObject();
dyic.ScoreTypeID = differentDynamicType.Value;
dyic.Score = Request.Form["Formula_" + differentDynamicType.Value];
listExpandoObject.Add(dyic);
}
string totalScore = Request.Form["TotalScore"];
if (submitedScoreDetailView.ResultTypeID == (int)CF_ResultType.Percentage || submitedScoreDetailView.ResultTypeID == -1)
{
submitedScoreDetailView.TotalScore = Convert.ToDecimal(Request.Form["TotalScore"]);
}
else if (submitedScoreDetailView.ResultTypeDetailID != null)
{
Score = StudentScoreServices.GetResultTypeDetailByDetaliID((Guid)submitedScoreDetailView.ResultTypeDetailID).Score;
submitedScoreDetailView.TotalScore = Score;
}
submitedScoreDetailView.ScoreCredit = Convert.ToDecimal(Request.Form["ScoreCredit"]);
submitedScoreDetailView.GradePoint = Convert.ToDecimal(Request.Form["GradePoint"]);
submitedScoreDetailView.Remarks = Request.Params["hid_SaveType"];//识别是否是复制性新增操作~~
submitedScoreDetailView.StudentScoreRemark = Request.Form["Remark"];
//Request.Params["changedUserID"] = submitedScoreDetailView.UserID.ToString();
StudentScoreServices.StudentScoreAdd(submitedScoreDetailView, listExpandoObject);
return Json(new ReturnMessage
{
IsSuccess = true,
Message = "保存成功!",
Data = submitedScoreDetailView.UserID
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string submitedScoreIDs, Guid? schoolyearID, Guid? coursematerialID, int? starttermID, Guid? userID)
{
try
{
List list = new List();
for (int i = 0; i < submitedScoreIDs.Split(',').Length; i++)
{
if (!string.IsNullOrEmpty(submitedScoreIDs.Split(',')[i]))
{
Guid submitedScoreID = new Guid(submitedScoreIDs.Split(',')[i]);
list.Add(submitedScoreID);
}
}
CourseGradeServices.SubmitedScoreDelete(list, schoolyearID, coursematerialID, starttermID, userID);
return Json("删除成功");
}
catch (Exception ex)
{
return Json("删除失败,原因:" + ex.Message);
}
}
[HttpPost]
public ActionResult GetClassNameByUserID(Guid userID)
{
string className = StudentScoreServices.GetClassByUserID(userID);
//return Json(StudentScoreServices.GetClassByUserID(userID));
return Json(new ReturnMessage { IsSuccess = true, Message = className });
}
[HttpPost]
public ActionResult GetTypeNameByID(int typeID)
{
//ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
return Json(StudentScoreServices.GetResultTypeDetail(typeID));
}
}
}