📄 examination.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace ExaminationSystem.BLL.Domain
{
public class Examination:DomainObject<long>
{
private string name;
public virtual string Name
{
get { return name; }
set { name = value; }
}
private DateTime startTime;
public virtual DateTime StartTime
{
get { return startTime; }
set { startTime = value; }
}
private DateTime endTime;
public virtual DateTime EndTime
{
get { return endTime; }
set { endTime = value; }
}
private IList<Class> attendClasses = new List<Class>();
public virtual IList<Class> AttendClasses
{
get { return attendClasses; }
set { attendClasses = value; }
}
private PaperStrategy paperStrategy;
public virtual PaperStrategy PaperStrategy
{
get { return paperStrategy; }
set { paperStrategy = value; }
}
private IList<Paper> papers = new List<Paper>();
public virtual IList<Paper> Papers
{
get { return papers; }
set { papers = value; }
}
public override int GetHashCode()
{
return (GetType().FullName + "|" +
Name + "|" +
StartTime.ToString()).GetHashCode();
}
public void AddClass(Class cls)
{
AttendClasses.Add(cls);
cls.Examinations.Add(this);
}
private int lateMinutes;
public virtual int LateMinutes
{
get { return lateMinutes; }
set { lateMinutes = value; }
}
private int permitSubmitMinutes;
public virtual int PermitSubmitMinutes
{
get { return permitSubmitMinutes; }
set { permitSubmitMinutes = value; }
}
private bool IsStudentLate()
{
TimeSpan timeSpan =DateTime.Now - StartTime;
if (timeSpan.Minutes > lateMinutes)
return true;
else
return false;
}
private bool IsStudentEarly()
{
TimeSpan span = StartTime - DateTime.Now;
if(span.TotalSeconds>0)
return true;
else
return false;
}
private bool IsPermitSubmit()
{
TimeSpan span = DateTime.Now - StartTime;
if (span.TotalMinutes > PermitSubmitMinutes)
return true;
else
return false;
}
public bool IsExaminationOver()
{
TimeSpan span = DateTime.Now - EndTime;
if (span.TotalMinutes > 0)
return true;
else
return false;
}
private bool IsReEnterExamination(Student student)
{
if (student.CurrentPaper == null)
{
foreach (Paper paper in student.Papers)
{
if (paper.Examination == this)
return true;
}
}
return false;
}
public void EnterExamination(Student student)
{
if (IsExaminationOver())
throw new Exception("考试已经结束!");
if (student.CurrentPaper != null&& student.CurrentPaper.Examination==this)
return;
if (!AttendClasses.Contains(student.Class))
throw new Exception("学生不在参加考试班级");
if (IsStudentLate())
throw new Exception("学生考试迟到不能参加考试");
if (IsStudentEarly())
throw new Exception("考试未开始");
if (student.CurrentPaper == null)
{
student.CurrentPaper = PaperStrategy.GetCurrentPaper();
student.CurrentPaper.Student = student;
student.CurrentPaper.Examination = this;
this.Papers.Add(student.CurrentPaper);
}
}
public void SubmitPaper(Student student)
{
if (student.CurrentPaper == null)
throw new Exception("考试没有在考试状态或已经交卷!");
if (!IsPermitSubmit())
throw new Exception("不到交卷时间");
student.CurrentPaper.IsSubmited = true;
}
public string AttendClassesToString
{
get
{
string csString="";
foreach (Class cs in AttendClasses)
{
csString += cs.Name+" ";
}
return csString;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -