@@ -2172,11 +2172,35 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad
}
/// <summary>
/// 导入学生成绩
/// 成绩导入--必修课 选修课
/// </summary>
/// <param name="type">1:必修,2:选修</param>
/// <param name="dt"></param>
/// <param name="fileGuid"></param>
/// <param name="queryJson"></param>
/// <returns></returns>
public (DataTable failDt, int snum, int fnum) ExecuteImportExcel(int type, DataTable dt, string fileGuid,
string queryJson)
{
if (type == 1)
{
//必修
return ExecuteImportExcelForRequired(dt, fileGuid, queryJson);
}
else
{
//选修
return ExecuteImportExcelForElective(dt, fileGuid, queryJson);
}
}
/// <summary>
/// 导入学生成绩--必修课
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public (DataTable failDt, int snum, int fnum) ExecuteImportExcel(DataTable dt, string fileGuid, string queryJson)
private (DataTable failDt, int snum, int fnum) ExecuteImportExcelForRequired (DataTable dt, string fileGuid, string queryJson)
{
int snum = 0;
int fnum = 0;
@@ -2185,6 +2209,9 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad
try
{
db.BeginTrans();
// 创建一个datatable容器用于保存导入失败的数据
DataTable failDt = new DataTable();
var queryParam = queryJson.ToJObject();
var F_SchoolId = queryParam["F_SchoolId"].ToString();
var AcademicYearNo = queryParam["AcademicYearNo"].ToString();
@@ -2193,70 +2220,181 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad
var ClassNo = queryParam["ClassNo"].ToString();
var classInfoEntity = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == ClassNo);
//获取成绩比例数据
var stuSelectLessonListEntity = db.FindEntity<StuSelectLessonListEntity>(x => x.F_SchoolId == F_SchoolId && x.AcademicYearNo == AcademicYearNo && x.Semester == Semester && x.OpenLessonDeptNo == classInfoEntity.DeptNo && x.OpenLessonMajorNo == classInfoEntity.MajorNo && x.LessonNo == LessonNo && x.LessonSortNo == "1" && x.ClassNo == ClassNo);
//当前班级学生成绩
var list = GetList(queryJson).ToList();
// 创建一个datatable容器用于保存导入失败的数据
DataTable failDt = new DataTable();
foreach (DataColumn dc in dt.Columns)
{
failDt.Columns.Add(dc.ColumnName, dc.DataType);
}
failDt.Columns.Add("导入错误", typeof(string));
dt.Columns.Add("导入错误", typeof(string));
foreach (DataRow dr in dt.Rows)
if (classInfoEntity != null)
{
try
//获取成绩比例数据
var stuSelectLessonListEntity = db.FindEntity<StuSelectLessonListEntity>(x => x.F_SchoolId == F_SchoolId && x.AcademicYearNo == AcademicYearNo && x.Semester == Semester && x.OpenLessonDeptNo == classInfoEntity.DeptNo && x.OpenLessonMajorNo == classInfoEntity.MajorNo && x.LessonNo == LessonNo && x.LessonSortNo == "1" && x.ClassNo == ClassNo);
if (stuSelectLessonListEntity != null)
{
var stuno = dr["学号"].ToString().Trim();
if (!string.IsNullOrEmpty(stuno))
//当前班级学生成绩
var list = GetList(queryJson).ToList();
foreach (DataColumn dc in dt.Columns)
{
failDt.Columns.Add(dc.ColumnName, dc.DataType);
}
failDt.Columns.Add("导入错误", typeof(string));
dt.Columns.Add("导入错误", typeof(string));
foreach (DataRow dr in dt.Rows)
{
var item = list.Find(x => x.StuNo == stuno);
if (item == null)
try
{
fnum++;
dr["导入错误"] = classInfoEntity.ClassName + "找不到学号为" + stuno + "的学生";
var stuno = dr["学号"].ToString().Trim();
if (!string.IsNullOrEmpty(stuno))
{
var item = list.Find(x => x.StuNo == stuno);
if (item == null)
{
fnum++;
dr["导入错误"] = classInfoEntity.ClassName + "找不到学号为" + stuno + "的学生";
failDt.Rows.Add(dr.ItemArray);
continue;
}
var OrdinaryScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["平时成绩"].ToString().Trim()) ? "0" : dr["平时成绩"].ToString().Trim());
var TermInScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期中成绩"].ToString().Trim()) ? "0" : dr["期中成绩"].ToString().Trim());
var TermEndScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期末成绩"].ToString().Trim()) ? "0" : dr["期末成绩"].ToString().Trim());
var OtherScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["其他成绩"].ToString().Trim()) ? "0" : dr["其他成绩"].ToString().Trim());
var Score = Math.Round(Convert.ToDouble(OrdinaryScore * (stuSelectLessonListEntity.OrdinaryScoreScale / 100) +
TermInScore * (stuSelectLessonListEntity.TermInScoreScale / 100) +
TermEndScore * (stuSelectLessonListEntity.TermEndScoreScale / 100) +
OtherScore * (stuSelectLessonListEntity.OtherScoreScale / 100)), MidpointRounding.AwayFromZero);
var remark = dr["备注"].ToString().Trim();
db.ExecuteBySql($"update StuScore set OrdinaryScore={OrdinaryScore},TermInScore={TermInScore},TermEndScore={TermEndScore},OtherScore={OtherScore},Score={Score},Remark='{remark}' where ScoreId='{item.ScoreId}' ");
}
else
{
break;
}
}
catch (Exception e)
{
dr["导入错误"] = "出现异常:" + e.Message;
failDt.Rows.Add(dr.ItemArray);
continue;
}
var OrdinaryScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["平时成绩"].ToString().Trim()) ? "0" : dr["平时成绩"].ToString().Trim());
var TermInScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期中成绩"].ToString().Trim()) ? "0" : dr["期中成绩"].ToString().Trim());
var TermEndScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期末成绩"].ToString().Trim()) ? "0" : dr["期末成绩"].ToString().Trim());
var OtherScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["其他成绩"].ToString().Trim()) ? "0" : dr["其他成绩"].ToString().Trim());
var Score = Math.Round(Convert.ToDouble(OrdinaryScore * (stuSelectLessonListEntity.OrdinaryScoreScale / 100) +
TermInScore * (stuSelectLessonListEntity.TermInScoreScale / 100) +
TermEndScore * (stuSelectLessonListEntity.TermEndScoreScale / 100) +
OtherScore * (stuSelectLessonListEntity.OtherScoreScale / 100)), MidpointRounding.AwayFromZero);
var remark = dr["备注"].ToString().Trim();
db.ExecuteBySql($"update StuScore set OrdinaryScore={OrdinaryScore},TermInScore={TermInScore},TermEndScore={TermEndScore},OtherScore={OtherScore},Score={Score},Remark='{remark}' where ScoreId='{item.ScoreId}' ");
}
else
db.Commit();
// 写入缓存如果有未导入的数据
if (failDt.Rows.Count > 0)
{
break;
string errordt = failDt.ToJson();
cache.Write<string>(cacheKey + fileGuid, errordt, CacheId.excel);
}
}
catch (Exception e)
{
dr["导入错误"] = "出现异常:" + e.Message;
failDt.Rows.Add(dr.ItemArray);
continue;
snum = list.Count - failDt.Rows.Count;
}
}
db.Commit();
// 写入缓存如果有未导入的数据
if (failDt.Rows.Count > 0)
return (failDt, snum, failDt.Rows.Count);
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
string errordt = failDt.ToJson();
cache.Write<string>(cacheKey + fileGuid, errordt, CacheId.excel);
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 导入学生成绩--选修课
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
private (DataTable failDt, int snum, int fnum) ExecuteImportExcelForElective(DataTable dt, string fileGuid, string queryJson)
{
int snum = 0;
int fnum = 0;
var db = this.BaseRepository("CollegeMIS");
var msg = "";
try
{
db.BeginTrans();
//创建一个datatable容器用于保存导入失败的数据
DataTable failDt = new DataTable();
var queryParam = queryJson.ToJObject();
var F_SchoolId = queryParam["F_SchoolId"].ToString();
var AcademicYearNo = queryParam["AcademicYearNo"].ToString();
var Semester = queryParam["Semester"].ToString();
var LessonNo = queryParam["LessonNo"].ToString();
var LessonSection = queryParam["LessonSection"].ToString();
var ClassRoomNo = queryParam["ClassRoomNo"].ToString();
snum = list.Count - failDt.Rows.Count;
//成绩比例数据
var stuSelectLessonListOfElectiveEntity = this.BaseRepository("CollegeMIS").FindEntity<StuSelectLessonListOfElectiveEntity>(x => x.F_SchoolId == F_SchoolId && x.AcademicYearNo == AcademicYearNo && x.Semester == Semester && x.LessonNo == LessonNo && x.LessonSortNo == "2" && x.ClassRoomNo == ClassRoomNo && x.LessonSection == LessonSection);
if (stuSelectLessonListOfElectiveEntity != null)
{
//查询学生成绩数据
var list = GetList(queryJson).ToList();
foreach (DataColumn dc in dt.Columns)
{
failDt.Columns.Add(dc.ColumnName, dc.DataType);
}
failDt.Columns.Add("导入错误", typeof(string));
dt.Columns.Add("导入错误", typeof(string));
foreach (DataRow dr in dt.Rows)
{
try
{
var stuno = dr["学号"].ToString().Trim();
if (!string.IsNullOrEmpty(stuno))
{
var item = list.Find(x => x.StuNo == stuno);
if (item == null)
{
fnum++;
dr["导入错误"] = "当前课程在" + LessonSection + "节次找不到学号为" + stuno + "的学生";
failDt.Rows.Add(dr.ItemArray);
continue;
}
var OrdinaryScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["平时成绩"].ToString().Trim()) ? "0" : dr["平时成绩"].ToString().Trim());
var TermInScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期中成绩"].ToString().Trim()) ? "0" : dr["期中成绩"].ToString().Trim());
var TermEndScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期末成绩"].ToString().Trim()) ? "0" : dr["期末成绩"].ToString().Trim());
var OtherScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["其他成绩"].ToString().Trim()) ? "0" : dr["其他成绩"].ToString().Trim());
var Score = Math.Round(Convert.ToDouble(OrdinaryScore * (stuSelectLessonListOfElectiveEntity.OrdinaryScoreScale / 100) +
TermInScore * (stuSelectLessonListOfElectiveEntity.TermInScoreScale / 100) +
TermEndScore * (stuSelectLessonListOfElectiveEntity.TermEndScoreScale / 100) +
OtherScore * (stuSelectLessonListOfElectiveEntity.OtherScoreScale / 100)), MidpointRounding.AwayFromZero);
var remark = dr["备注"].ToString().Trim();
db.ExecuteBySql($"update StuScore set OrdinaryScore={OrdinaryScore},TermInScore={TermInScore},TermEndScore={TermEndScore},OtherScore={OtherScore},Score={Score},Remark='{remark}' where ScoreId='{item.ScoreId}' ");
}
else
{
break;
}
}
catch (Exception e)
{
dr["导入错误"] = "出现异常:" + e.Message;
failDt.Rows.Add(dr.ItemArray);
continue;
}
}
db.Commit();
// 写入缓存如果有未导入的数据
if (failDt.Rows.Count > 0)
{
string errordt = failDt.ToJson();
cache.Write<string>(cacheKey + fileGuid, errordt, CacheId.excel);
}
snum = list.Count - failDt.Rows.Count;
}
return (failDt, snum, failDt.Rows.Count);
}
catch (Exception ex)
@@ -2273,6 +2411,5 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad
}
}
}
}