using Dapper;
using Learun.Application.Organization;
using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace Learun.Application.TwoDevelopment.EducationalAdministration
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2019-01-29 11:08
/// 描 述:班级信息管理
///
public class TeachClassService : RepositoryFactory
{
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
public IEnumerable GetPageList(Pagination pagination, string queryJson)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(@" * ");
strSql.Append(" FROM TeachClass t ");
strSql.Append(" WHERE 1=1 ");
var queryParam = queryJson.ToJObject();
// 虚拟参数
var dp = new DynamicParameters(new { });
if (!queryParam["F_SchoolId"].IsEmpty())
{
dp.Add("F_SchoolId", queryParam["F_SchoolId"].ToString(), DbType.String);
strSql.Append(" AND t.F_SchoolId = @F_SchoolId ");
}
if (!queryParam["AcademicYearNo"].IsEmpty())
{
dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
}
if (!queryParam["Semester"].IsEmpty())
{
dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
strSql.Append(" AND t.Semester = @Semester ");
}
if (!queryParam["DeptNo"].IsEmpty())
{
dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
strSql.Append(" AND t.DeptNo = @DeptNo ");
}
if (!queryParam["MajorNo"].IsEmpty())
{
dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
strSql.Append(" AND t.MajorNo = @MajorNo ");
}
if (!queryParam["Grade"].IsEmpty())
{
dp.Add("Grade", "%" + queryParam["Grade"].ToString() + "%", DbType.String);
strSql.Append(" AND t.Grade Like @Grade ");
}
if (!queryParam["LessonNo"].IsEmpty())
{
dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
strSql.Append(" AND t.LessonNo = @LessonNo ");
}
if (!queryParam["ClassNo"].IsEmpty())
{
dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
strSql.Append(" AND t.ClassNo = @ClassNo ");
}
if (!queryParam["EmpNo"].IsEmpty())
{
dp.Add("EmpNo", queryParam["EmpNo"].ToString(), DbType.String);
strSql.Append(" AND t.EmpNo = @EmpNo ");
}
return this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), dp, pagination);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
internal bool GetAny()
{
try
{
return this.BaseRepository("CollegeMIS").FindList().ToList().Count > 0 ? true : false;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取ClassInfo表实体数据
/// 主键
///
///
public TeachClassEntity GetTeachClassEntity(string keyValue)
{
try
{
int ID = Convert.ToInt32(keyValue);
return this.BaseRepository("CollegeMIS").FindEntity(ID);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
public void DeleteEntity(string keyValue)
{
var db = this.BaseRepository("CollegeMIS").BeginTrans();
try
{
//修改
var keyValueArr = keyValue.Split(',');
foreach (var item in keyValueArr)
{
var entity = this.BaseRepository("CollegeMIS").FindEntity(x => x.ID == Convert.ToInt32(item));
if (entity != null)
{
entity.EmpNo = "";
db.Update(entity);
}
}
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
public void SaveEntity(string keyValue, TeachClassEntity entity)
{
try
{
var keyvalue = Convert.ToInt32(keyValue);
if (!string.IsNullOrEmpty(keyValue))
{
entity.Modify(keyvalue);
this.BaseRepository("CollegeMIS").Update(entity);
}
else
{
entity.Create();
this.BaseRepository("CollegeMIS").Insert(entity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 扩展数据
public IEnumerable GetAllClass()
{
try
{
return this.BaseRepository("CollegeMIS").FindList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取ClassInfo表实体数据
/// 主键
///
///
public List GetTeachListById(string keyValue)
{
try
{
var id = keyValue.Split(',');
return this.BaseRepository("CollegeMIS")
.FindList(x => id.Contains(x.ID.ToString())).ToList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存数据
///
/// 主键
///
public void SaveEntityList(List List)
{
var db = this.BaseRepository("CollegeMIS").BeginTrans();
try
{
foreach (var item in List)
{
TeachClassEntity Teach = new TeachClassEntity
{
TeachClassNo = item.TeachClassNo,
AcademicYearNo = item.AcademicYearNo,
DeptNo = item.DeptNo,
MajorNo = item.MajorNo,
Grade = item.Grade,
EmpNo = item.EmpNo,
Semester = item.Semester,
LessonNo = item.LessonNo,
StuNum = item.StuNum,
LessonSortNo = item.LessonSortNo,
F_SchoolId = item.F_SchoolId
};
if (db.FindEntity(
x => x.F_SchoolId == Teach.F_SchoolId && x.AcademicYearNo == Teach.AcademicYearNo
&& x.Semester == Teach.Semester && x.DeptNo == Teach.DeptNo
&& x.MajorNo == Teach.MajorNo && x.TeachClassNo == Teach.TeachClassNo
&& x.Grade == Teach.Grade && x.LessonNo == Teach.LessonNo) == null)
{
db.Insert(Teach);
}
}
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存或修改教师
///
///
///
public void UpEmpNo(string keyValue, string EmpNo)
{
var db = this.BaseRepository("CollegeMIS").BeginTrans();
try
{
var keyarray = keyValue.Split(',');
foreach (var item in keyarray)
{
var entityList = this.GetTeachClassEntity(item);
entityList.EmpNo = EmpNo;
db.Update(entityList);
}
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 修改教师和成绩
///
///
///
public string UpSetTeach(string keyValue, string EmpNo)
{
string Result = "";
var db = BaseRepository("CollegeMIS").BeginTrans();
try
{
#region 获取班级开课计划的数据
var IdList = keyValue.Split(',');
var TeachClassList = BaseRepository("CollegeMIS").FindList(x => IdList.Contains(x.ID.ToString())).ToList();
foreach (var item in IdList)//修改TeachClass表
{
var entityList = GetTeachClassEntity(item);
entityList.EmpNo = EmpNo;
db.Update(entityList);
}
#endregion
List stuLessonList = new List();
for (int i = 0; i < TeachClassList.Count; i++)
{
var LessonData = db.FindList().Where(x => x.LessonNo == TeachClassList[i].LessonNo).FirstOrDefault();
var stuDataList = db.FindList().Where(s =>
s.DeptNo == TeachClassList[i].DeptNo && s.MajorNo == TeachClassList[i].MajorNo &&
s.F_SchoolId == TeachClassList[i].F_SchoolId &&
s.ClassNo == TeachClassList[i].TeachClassNo && s.CheckMark == "1");
var DeleteStuSelectLesson = db.FindList().Where(
x => x.AcademicYearNo == TeachClassList[i].AcademicYearNo &&
x.LessonNo == TeachClassList[i].LessonNo &&
x.Semester == TeachClassList[i].Semester &&
x.F_SchoolId == TeachClassList[i].F_SchoolId &&
x.DeptNo == TeachClassList[i].DeptNo &&
x.MajorNo == TeachClassList[i].MajorNo &&
x.ClassNo == TeachClassList[i].TeachClassNo &&
x.Grade == TeachClassList[i].Grade &&
x.OpenLessonDeptNo == TeachClassList[i].DeptNo &&
x.OpenLessonMajorNo == TeachClassList[i].MajorNo &&
x.LessonSortNo == "1").ToList();
if (DeleteStuSelectLesson.Count > 0)
{
db.Delete(DeleteStuSelectLesson);
}
if (stuDataList != null)
{
#region 修改StuSelectLessonList表
foreach (var item in stuDataList)
{
var StuSelectLessonEntity = new StuSelectLessonListEntity
{
StuNo = item.StuNo,
DeptNo = TeachClassList[i].DeptNo,
MajorNo = TeachClassList[i].MajorNo,
ClassNo = item.ClassNo,
GenderNo = item.GenderNo == true ? "0" : "1",
MajorDetailNo = TeachClassList[i].MajorDetailNo,
MajorDetailName = TeachClassList[i].MajorDetailName,
StuName = item.StuName,
AcademicYearNo = TeachClassList[i].AcademicYearNo,
Semester = TeachClassList[i].Semester,
OpenLessonDeptNo = TeachClassList[i].DeptNo,
OpenLessonMajorNo = TeachClassList[i].MajorNo,
LessonNo = TeachClassList[i].LessonNo,
LessonName = LessonData.LessonName,
PartCode = TeachClassList[i].PartCode,
OrdinaryScoreScale = 0,
TermInScoreScale = 0,
TermEndScoreScale = 0,
OtherScoreScale = 0,
TeachClassNo = TeachClassList[i].TeachClassNo,
LessonSortNo = TeachClassList[i].LessonSortNo,
StuSortNo = TeachClassList[i].LessonSortNo,
Grade = item.Grade,
StudyScore = 2,
TotalStudyHour = 2,
IsInEffect = "1",
IsPitchOn = "1",
F_SchoolId = TeachClassList[i].F_SchoolId,
CheckMark = "1",
InsertTime = DateTime.Now
};
stuLessonList.Add(StuSelectLessonEntity);
db.Insert(StuSelectLessonEntity);
}
#endregion
var ScoreList = db.FindList().Where(x => x.AcademicYearNo == TeachClassList[i].AcademicYearNo && x.Semester == TeachClassList[i].Semester && x.DeptNo == TeachClassList[i].DeptNo && x.MajorNo == TeachClassList[i].MajorNo && x.ClassNo == TeachClassList[i].TeachClassNo && x.LessonSortNo == TeachClassList[i].LessonSortNo && x.LessonNo == TeachClassList[i].LessonNo);
var DeleteStuScore = db.FindList().Where(
x => x.AcademicYearNo == TeachClassList[i].AcademicYearNo &&
x.LessonNo == TeachClassList[i].LessonNo &&
x.Semester == TeachClassList[i].Semester &&
x.F_SchoolId == TeachClassList[i].F_SchoolId &&
x.DeptNo == TeachClassList[i].DeptNo &&
x.MajorNo == TeachClassList[i].MajorNo &&
x.ClassNo == TeachClassList[i].TeachClassNo &&
x.Grade == TeachClassList[i].Grade &&
x.OpenLessonDeptNo == TeachClassList[i].DeptNo &&
x.OpenLessonMajorNo == TeachClassList[i].MajorNo &&
x.LessonSortNo == "1" && x.CheckMark == "1").ToList();
if (DeleteStuScore.Count > 0)
{
return Result = "成绩已审核不可设置教师";
}
db.Delete(DeleteStuScore);
if (ScoreList != null)
{
#region 添加StuScore表
foreach (var item in stuDataList)
{
var stuScoreEntity = new StuScoreEntity
{
StuNo = item.StuNo,
DeptNo = item.DeptNo,
MajorNo = item.MajorNo,
ClassNo = item.ClassNo,
StuName = item.StuName,
EmpNo = EmpNo,
GenderNo = item.GenderNo == true ? "0" : "1",
AcademicYearNo = TeachClassList[i].AcademicYearNo,
Semester = TeachClassList[i].Semester,
OpenLessonDeptNo = TeachClassList[i].DeptNo,
OpenLessonMajorNo = TeachClassList[i].MajorNo,
LessonNo = TeachClassList[i].LessonNo,
LessonName = LessonData.LessonName,
PartCode = TeachClassList[i].PartCode,
StuSortNo = item.TestStuSortNo,
TeachClassNo = TeachClassList[i].TeachClassNo,
LessonSortNo = TeachClassList[i].LessonSortNo,
Grade = TeachClassList[i].Grade,
StudyScore = 2,
TotalStudyHour = 2,
IsInEffect = "1",
IsPitchOn = "1",
F_SchoolId = TeachClassList[i].F_SchoolId,
CheckMark = "0",
TestKindNo = "1",
IsEditable = "1",
OrdinaryScore = 0,
TermInScore = 0,
TermEndScore = 0,
OtherScore = 0
};
db.Insert(stuScoreEntity);
}
#endregion
}
}
}
db.Commit();
return Result = "设置教师成功";
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 强制修改教师
///
///
///
public string UpQzSetTeach(string keyValue, string EmpNo)
{
string Result = "";
var db = BaseRepository("CollegeMIS").BeginTrans();
try
{
#region 获取班级开课计划的数据
var IdList = keyValue.Split(',');
var TeachClassList = BaseRepository("CollegeMIS").FindList(x => IdList.Contains(x.ID.ToString())).ToList();
foreach (var item in IdList)//修改TeachClass表
{
var entityList = GetTeachClassEntity(item);
entityList.EmpNo = EmpNo;
db.Update(entityList);
}
#endregion
List stuLessonList = new List();
for (int i = 0; i < TeachClassList.Count; i++)
{
var LessonData = db.FindList().Where(x => x.LessonNo == TeachClassList[i].LessonNo).FirstOrDefault();
var stuDataList = db.FindList().Where(s =>
s.DeptNo == TeachClassList[i].DeptNo && s.MajorNo == TeachClassList[i].MajorNo &&
s.F_SchoolId == TeachClassList[i].F_SchoolId &&
s.ClassNo == TeachClassList[i].TeachClassNo && s.CheckMark == "1");
var DeleteStuSelectLesson = db.FindList().Where(
x => x.AcademicYearNo == TeachClassList[i].AcademicYearNo &&
x.LessonNo == TeachClassList[i].LessonNo &&
x.Semester == TeachClassList[i].Semester &&
x.F_SchoolId == TeachClassList[i].F_SchoolId &&
x.DeptNo == TeachClassList[i].DeptNo &&
x.MajorNo == TeachClassList[i].MajorNo &&
x.ClassNo == TeachClassList[i].TeachClassNo &&
x.Grade == TeachClassList[i].Grade &&
x.OpenLessonDeptNo == TeachClassList[i].DeptNo &&
x.OpenLessonMajorNo == TeachClassList[i].MajorNo &&
x.LessonSortNo == "1").ToList();
if (DeleteStuSelectLesson.Count > 0)
{
db.Delete(DeleteStuSelectLesson);
}
if (stuDataList != null)
{
#region 修改StuSelectLessonList表
foreach (var item in stuDataList)
{
var StuSelectLessonEntity = new StuSelectLessonListEntity
{
StuNo = item.StuNo,
DeptNo = TeachClassList[i].DeptNo,
MajorNo = TeachClassList[i].MajorNo,
ClassNo = item.ClassNo,
GenderNo = item.GenderNo == true ? "0" : "1",
MajorDetailNo = TeachClassList[i].MajorDetailNo,
MajorDetailName = TeachClassList[i].MajorDetailName,
StuName = item.StuName,
AcademicYearNo = TeachClassList[i].AcademicYearNo,
Semester = TeachClassList[i].Semester,
OpenLessonDeptNo = TeachClassList[i].DeptNo,
OpenLessonMajorNo = TeachClassList[i].MajorNo,
LessonNo = TeachClassList[i].LessonNo,
LessonName = LessonData.LessonName,
PartCode = TeachClassList[i].PartCode,
OrdinaryScoreScale = 0,
TermInScoreScale = 0,
TermEndScoreScale = 0,
OtherScoreScale = 0,
TeachClassNo = TeachClassList[i].TeachClassNo,
LessonSortNo = TeachClassList[i].LessonSortNo,
StuSortNo = TeachClassList[i].LessonSortNo,
Grade = item.Grade,
StudyScore = 2,
TotalStudyHour = 2,
IsInEffect = "1",
IsPitchOn = "1",
F_SchoolId = TeachClassList[i].F_SchoolId,
CheckMark = "1",
InsertTime = DateTime.Now
};
stuLessonList.Add(StuSelectLessonEntity);
db.Insert(StuSelectLessonEntity);
}
#endregion
var ScoreList = db.FindList().Where(x => x.AcademicYearNo == TeachClassList[i].AcademicYearNo && x.Semester == TeachClassList[i].Semester && x.DeptNo == TeachClassList[i].DeptNo && x.MajorNo == TeachClassList[i].MajorNo && x.ClassNo == TeachClassList[i].TeachClassNo && x.LessonSortNo == TeachClassList[i].LessonSortNo && x.LessonNo == TeachClassList[i].LessonNo);
var DeleteStuScore = db.FindList().Where(
x => x.AcademicYearNo == TeachClassList[i].AcademicYearNo &&
x.LessonNo == TeachClassList[i].LessonNo &&
x.Semester == TeachClassList[i].Semester &&
x.F_SchoolId == TeachClassList[i].F_SchoolId &&
x.DeptNo == TeachClassList[i].DeptNo &&
x.MajorNo == TeachClassList[i].MajorNo &&
x.ClassNo == TeachClassList[i].TeachClassNo &&
x.Grade == TeachClassList[i].Grade &&
x.OpenLessonDeptNo == TeachClassList[i].DeptNo &&
x.OpenLessonMajorNo == TeachClassList[i].MajorNo &&
x.LessonSortNo == "1" && x.CheckMark == "0").ToList();
if (DeleteStuScore.Count > 0)
{
db.Delete(DeleteStuScore);
}
if (ScoreList != null)
{
#region 添加StuScore表
foreach (var item in stuDataList)
{
var stuScoreEntity = new StuScoreEntity
{
StuNo = item.StuNo,
DeptNo = item.DeptNo,
MajorNo = item.MajorNo,
ClassNo = item.ClassNo,
StuName = item.StuName,
EmpNo = EmpNo,
GenderNo = item.GenderNo == true ? "0" : "1",
AcademicYearNo = TeachClassList[i].AcademicYearNo,
Semester = TeachClassList[i].Semester,
OpenLessonDeptNo = TeachClassList[i].DeptNo,
OpenLessonMajorNo = TeachClassList[i].MajorNo,
LessonNo = TeachClassList[i].LessonNo,
LessonName = LessonData.LessonName,
PartCode = TeachClassList[i].PartCode,
StuSortNo = item.TestStuSortNo,
TeachClassNo = TeachClassList[i].TeachClassNo,
LessonSortNo = TeachClassList[i].LessonSortNo,
Grade = TeachClassList[i].Grade,
StudyScore = 2,
TotalStudyHour = 2,
IsInEffect = "1",
IsPitchOn = "1",
F_SchoolId = TeachClassList[i].F_SchoolId,
CheckMark = "0",
TestKindNo = "1",
IsEditable = "1",
OrdinaryScore = 0,
TermInScore = 0,
TermEndScore = 0,
OtherScore = 0
};
db.Insert(stuScoreEntity);
}
#endregion
}
}
}
db.Commit();
return Result = "设置教师成功";
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
public void UpEmpNos(string xn, string xq, string classNo, string LessonNo, string EmpNo, string hisempno, string Grade)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append(" update StuSelectLessonList set EmpNo ='" + EmpNo + "' where classno = '" + classNo + "' and Semester ='" + xq + "' and AcademicYearNo ='" + xn + "' and LessonNo ='" + LessonNo + "' and empno = '" + hisempno + "' and Grade = '" + Grade + "'");
this.BaseRepository("CollegeMIS").ExecuteBySql(sb.ToString());
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}