@@ -201,30 +201,49 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration
/// 删除课程
/// </summary>
/// <param name="keyValue"></param>
public void DeleteLessonTerm(string keyValue)
public void DeleteLessonTerm(string keyValue, string WeekTime )
{
var db = this.BaseRepository("CollegeMIS");
try
{
db.BeginTrans();
var entity = db.FindEntity<ArrangeLessonTermEntity>(keyValue);
//更改课程表标记
entity.CheckMark = "0";
entity.Modify(keyValue);
db.Update(entity);
//新增修改记录表
ArgLessonTermUpdRecordEntity record = new ArgLessonTermUpdRecordEntity();
record.Create();
record.ALTId = entity.ALTId;
record.LessonNoOld = entity.LessonNo;
record.LessonNoNew = "";
record.EmpNoOld = entity.EmpNo;
record.EmpNoNew = "";
record.ClassroomNoOld = entity.ClassroomNo;
record.ClassroomNoNew = "";
record.Remark = "删除";
db.Insert(record);
//周次
var weekTimeAry = WeekTime.Split(',');
foreach (var weekTime in weekTimeAry)
{
var weektime = Convert.ToInt32(weekTime);
var lessonDate = GetLessonDate(weektime, Convert.ToInt32(entity.LessonTime.Split('-')[0]));
var model =
db.FindEntity<ArrangeLessonTermEntity>(x =>
x.LessonDate == lessonDate && x.LessonTime == entity.LessonTime);
if (model != null)
{
//更改课程表标记
model.CheckMark = "0";
model.Modify(keyValue);
db.Update(model);
//新增修改记录表
ArgLessonTermUpdRecordEntity record = new ArgLessonTermUpdRecordEntity();
record.Create();
record.ALTId = model.ALTId;
record.LessonNoOld = model.LessonNo;
record.LessonNoNew = "";
record.EmpNoOld = model.EmpNo;
record.EmpNoNew = "";
record.ClassroomNoOld = model.ClassroomNo;
record.ClassroomNoNew = "";
record.Remark = "删除";
db.Insert(record);
}
}
db.Commit();
}
catch (Exception ex)
@@ -245,51 +264,115 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration
/// 修改课程
/// </summary>
/// <param name="keyValue"></param>
public void UpdateLessonTerm(string keyValue, UpdateLessonTermEntity model)
public string UpdateLessonTerm(string keyValue, UpdateLessonTermEntity model)
{
var db = this.BaseRepository("CollegeMIS");
try
{
db.BeginTrans();
//开始时间
var startdate = DateTime.Today;
var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
var semesterAndYear = Common.GetSemesterAndYear(startDate);
//学校日历
var schoolCalendar = this.BaseRepository().FindEntity<SchoolCalendarEntity>(x =>
x.AcademicYearNo == semesterAndYear.AcademicYearShort && x.Semester == semesterAndYear.Semester);
//当前修改的课程数据
var ArrangeLessonTerm = db.FindEntity<ArrangeLessonTermEntity>(keyValue);
var LessonTimeOld = ArrangeLessonTerm?.LessonTime;
//周次
var weekTimeAry = model.WeekTimeSelect.Split(',');
foreach (var weekTime in weekTimeAry)
{
var weektime = Convert.ToInt32(weekTime);
//开课时间
DateTime lessonDate = DateTime.Now;
if (weektime == 1)
{
//第一周
lessonDate = Common.CalculateFirstDateOfWeek(schoolCalendar.StartTime.Value)
.AddDays(model.WeekSelect - 1);
}
else
{
var start= Common.CalculateFirstDateOfWeek(schoolCalendar.StartTime.Value).AddDays((Convert.ToInt32(weekTime) - 1) * 14);
lessonDate = start.AddDays(model.WeekSelect - 1);
}
var lessiontime = model.WeekSelect + "-" + model.NodeSelect;
//需要修改周次的开课时间
var lessonDate = GetLessonDate(weektime, Convert.ToInt32(LessonTimeOld?.Split('-')[0]));
//最后调整到
var lessonDateNew = GetLessonDate(weektime, model.WeekSelect);
#region old
//var lessonDate = GetLessonDate(weektime, model.WeekSelect);
//var lessiontime = model.WeekSelect + "-" + model.NodeSelect;
//var entity =
// db.FindEntity<ArrangeLessonTermEntity>(x =>
// x.LessonDate == lessonDate && x.LessonTime == lessiontime);
//if (entity == null)
//{
// //不存在 新增
// var classInfo = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == model.TeachClassNo);
// entity = new ArrangeLessonTermEntity();
// entity.Create();
// entity.LessonDate = lessonDate;
// entity.AcademicYearNo = semesterAndYear.AcademicYearShort;
// entity.Semester = semesterAndYear.Semester;
// entity.LessonDate = lessonDate;
// entity.DeptNo = classInfo?.DeptNo;
// entity.MajorNo = classInfo?.MajorNo;
// entity.LessonNo = model.LessonNo;
// entity.LessonName = model.LessonName;
// entity.EmpNo = model.EmpNo;
// entity.EmpName = model.EmpName;
// entity.TeachClassNo = model.TeachClassNo;
// entity.ClassroomNo = model.ClassroomNo;
// entity.LessonTime = lessiontime;
// entity.CheckMark = "1";
// entity.F_SchoolId = LoginUserInfo.Get().companyId;
// db.Insert(entity);
// //新增修改记录表
// ArgLessonTermUpdRecordEntity record = new ArgLessonTermUpdRecordEntity();
// record.Create();
// record.ALTId = entity.ALTId;
// record.LessonNoOld = "";
// record.LessonNoNew = model.LessonNo;
// record.EmpNoOld = "";
// record.EmpNoNew = model.EmpNo;
// record.ClassroomNoOld = "";
// record.ClassroomNoNew = model.ClassroomNo;
// record.Remark = "新增";
// db.Insert(record);
//}
//else
//{
// //新增修改记录表
// ArgLessonTermUpdRecordEntity record = new ArgLessonTermUpdRecordEntity();
// record.Create();
// record.ALTId = entity.ALTId;
// record.LessonNoOld = entity.LessonNo;
// record.LessonNoNew = model.LessonNo;
// record.EmpNoOld = entity.EmpNo;
// record.EmpNoNew = model.EmpNo;
// record.ClassroomNoOld = entity.ClassroomNo;
// record.ClassroomNoNew = model.ClassroomNo;
// record.Remark = "修改";
// db.Insert(record);
// //存在 修改
// entity.TeachClassNo = model.TeachClassNo;
// entity.LessonNo = model.LessonNo;
// entity.LessonName = model.LessonName;
// entity.EmpNo = model.EmpNo;
// entity.EmpName = model.EmpName;
// entity.ClassroomNo = model.ClassroomNo;
// db.Update(entity);
//}
#endregion
var entity =
db.FindEntity<ArrangeLessonTermEntity>(x =>
x.LessonDate == lessonDate && x.LessonTime == lessiontime);
x.LessonDate == lessonDate && x.LessonTime == LessonTimeOld);
//当前星期-节次
var lessiontimeNow = model.WeekSelect + "-" + model.NodeSelect;
if (entity == null)
{
//不存在 新增
var startdate = DateTime.Today;
var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
var semesterAndYear = Common.GetSemesterAndYear(startDate);
var classInfo = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == model.TeachClassNo);
entity = new ArrangeLessonTermEntity();
entity.Create();
entity.LessonDate = lessonDate;
entity.LessonDate = lessonDateNew ;
entity.AcademicYearNo = semesterAndYear.AcademicYearShort;
entity.Semester = semesterAndYear.Semester;
entity.LessonDate = lessonDate;
@@ -303,7 +386,7 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration
entity.EmpName = model.EmpName;
entity.TeachClassNo = model.TeachClassNo;
entity.ClassroomNo = model.ClassroomNo;
entity.LessonTime = lessiontime;
entity.LessonTime = lessiontimeNow ;
entity.CheckMark = "1";
entity.F_SchoolId = LoginUserInfo.Get().companyId;
db.Insert(entity);
@@ -312,42 +395,59 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration
ArgLessonTermUpdRecordEntity record = new ArgLessonTermUpdRecordEntity();
record.Create();
record.ALTId = entity.ALTId;
record.LessonDateNew = lessonDateNew;
record.LessonNoOld = "";
record.LessonNoNew = model.LessonNo;
record.EmpNoOld = "";
record.EmpNoNew = model.EmpNo;
record.ClassroomNoOld = "";
record.ClassroomNoNew = model.ClassroomNo;
record.LessonTimeNew = lessiontimeNow;
record.Remark = "新增";
db.Insert(record);
}
else
{
//直接修改
//判断是否冲突(新时间是否存在课程)
if (db.FindList<ArrangeLessonTermEntity>(x =>
x.LessonDate == lessonDateNew && x.LessonTime == lessiontimeNow&&x.CheckMark=="1" && x.ALTId != keyValue).Count() > 0)
{
return "第" + weektime + "周当前课程冲突!";
}
//新增修改记录表
ArgLessonTermUpdRecordEntity record = new ArgLessonTermUpdRecordEntity();
record.Create();
record.ALTId = entity.ALTId;
record.LessonDateOld = entity.LessonDate;
record.LessonDateNew = lessonDateNew;
record.LessonNoOld = entity.LessonNo;
record.LessonNoNew = model.LessonNo;
record.EmpNoOld = entity.EmpNo;
record.EmpNoNew = model.EmpNo;
record.ClassroomNoOld = entity.ClassroomNo;
record.ClassroomNoNew = model.ClassroomNo;
record.LessonTimeOld = entity.LessonTime;
record.LessonTimeNew = lessiontimeNow;
record.Remark = "修改";
db.Insert(record);
//存在 修改
entity.LessonDate = lessonDateNew;
entity.TeachClassNo = model.TeachClassNo;
entity.LessonNo = model.LessonNo;
entity.LessonName = model.LessonName;
entity.EmpNo = model.EmpNo;
entity.EmpName = model.EmpName;
entity.ClassroomNo = model.ClassroomNo;
entity.LessonTime = lessiontimeNow;
db.Update(entity);
}
}
db.Commit();
return "";
}
catch (Exception ex)
{
@@ -362,6 +462,38 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration
}
}
}
/// <summary>
/// 获取开课时间
/// </summary>
/// <param name="weektime"></param>
/// <param name="WeekSelect"></param>
/// <returns></returns>
private DateTime GetLessonDate(int weektime, int WeekSelect)
{
//开课时间
DateTime lessonDate = DateTime.Now;
//开始时间
var startdate = DateTime.Today;
var startDate = Common.CalculateFirstDateOfWeek(startdate).ToString("yyyy-MM-dd");
var semesterAndYear = Common.GetSemesterAndYear(startDate);
//学校日历
var schoolCalendar = this.BaseRepository().FindEntity<SchoolCalendarEntity>(x =>
x.AcademicYearNo == semesterAndYear.AcademicYearShort && x.Semester == semesterAndYear.Semester);
if (weektime == 1)
{
//第一周
lessonDate = Common.CalculateFirstDateOfWeek(schoolCalendar.StartTime.Value)
.AddDays(WeekSelect - 1);
}
else
{
var start = Common.CalculateFirstDateOfWeek(schoolCalendar.StartTime.Value).AddDays((weektime - 1) * 14);
lessonDate = start.AddDays(WeekSelect - 1);
}
return lessonDate;
}
/// <summary>
/// 保存实体数据(新增、修改)