250 lines
9.9 KiB
C#
250 lines
9.9 KiB
C#
using FineUIPro;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
|
|
namespace BLL
|
|
{
|
|
/// <summary>
|
|
/// 考试记录
|
|
/// </summary>
|
|
public static class TestRecordService
|
|
{
|
|
public static Model.SUBQHSEDB db = Funs.DB;
|
|
|
|
/// <summary>
|
|
/// 记录数
|
|
/// </summary>
|
|
public static int count
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 定义变量
|
|
/// </summary>
|
|
private static IQueryable<Model.Training_TestRecord> getDatas = from x in db.Training_TestRecord select x;
|
|
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="PageIndex">页码</param>
|
|
/// <param name="PageSize">每页数量</param>
|
|
/// <returns></returns>
|
|
public static IEnumerable getListData(string projectId, string unitId, string departId, string name, decimal? minScores, decimal? maxScores, DateTime? startDate, DateTime? endDate, Grid Grid1)
|
|
{
|
|
var getDataLists = from x in getDatas
|
|
join y in db.Training_TestPlan on x.TestPlanId equals y.TestPlanId
|
|
join z in db.SitePerson_Person on x.TestManId equals z.PersonId
|
|
select new
|
|
{
|
|
x.ProjectId,
|
|
x.TestRecordId,
|
|
x.TestPlanId,
|
|
y.PlanName,
|
|
x.UnitId,
|
|
db.Base_Unit.First(u => u.UnitId == z.UnitId).UnitName,
|
|
z.DepartId,
|
|
db.Base_Depart.First(u => u.DepartId == z.DepartId).DepartName,
|
|
x.TestManId,
|
|
TestManName = z.PersonName,
|
|
x.TestStartTime,
|
|
x.TestEndTime,
|
|
x.TestScores,
|
|
y.TotalScore,
|
|
y.Duration,
|
|
y.TestPalce,
|
|
y.QuestionCount
|
|
};
|
|
if (!string.IsNullOrEmpty(projectId))
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.ProjectId == projectId);
|
|
}
|
|
else
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.ProjectId == null || e.ProjectId == "");
|
|
}
|
|
if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null)
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.UnitId == unitId);
|
|
}
|
|
if (!string.IsNullOrEmpty(departId) && departId != Const._Null)
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.DepartId == departId);
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.PlanName.Contains(name) || e.TestManName.Contains(name));
|
|
}
|
|
if (minScores.HasValue)
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.TestScores >= minScores);
|
|
}
|
|
if (maxScores.HasValue)
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.TestScores <= maxScores);
|
|
}
|
|
if (startDate.HasValue)
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.TestStartTime >= startDate);
|
|
}
|
|
if (endDate.HasValue)
|
|
{
|
|
getDataLists = getDataLists.Where(e => e.TestEndTime <= endDate);
|
|
}
|
|
|
|
count = getDataLists.Count();
|
|
if (count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
getDataLists = SortConditionHelper.SortingAndPaging(getDataLists, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|
return getDataLists;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据主键获取考试记录
|
|
/// </summary>
|
|
/// <param name="testRecordId"></param>
|
|
/// <returns></returns>
|
|
public static Model.Training_TestRecord GetTestRecordById(string testRecordId)
|
|
{
|
|
return Funs.DB.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增考生记录信息
|
|
/// </summary>
|
|
/// <param name="Training"></param>
|
|
public static void AddTestRecord(Model.Training_TestRecord testRecord)
|
|
{
|
|
Model.SUBQHSEDB db = Funs.DB;
|
|
Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
|
|
{
|
|
TestRecordId = testRecord.TestRecordId,
|
|
ProjectId = testRecord.ProjectId,
|
|
TestPlanId = testRecord.TestPlanId,
|
|
TestManId = testRecord.TestManId,
|
|
TestType=testRecord.TestType,
|
|
};
|
|
|
|
if (string.IsNullOrEmpty(newTestRecord.TestType))
|
|
{
|
|
var getTrainTypeName = (from x in db.Training_TestPlan
|
|
join y in db.Training_Plan on x.PlanId equals y.PlanId
|
|
join z in db.Base_TrainType on y.TrainTypeId equals z.TrainTypeId
|
|
where x.TestPlanId == testRecord.TestPlanId
|
|
select z).FirstOrDefault();
|
|
|
|
if (getTrainTypeName != null)
|
|
{
|
|
testRecord.TestType = getTrainTypeName.TrainTypeName;
|
|
}
|
|
}
|
|
|
|
db.Training_TestRecord.InsertOnSubmit(newTestRecord);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改考试记录信息
|
|
/// </summary>
|
|
/// <param name="Training"></param>
|
|
public static void UpdateTestRecord(Model.Training_TestRecord testRecord)
|
|
{
|
|
Model.SUBQHSEDB db = Funs.DB;
|
|
Model.Training_TestRecord newTestRecord = db.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecord.TestRecordId);
|
|
if (newTestRecord != null)
|
|
{
|
|
newTestRecord.TestScores = testRecord.TestScores;
|
|
newTestRecord.TestEndTime = testRecord.TestEndTime;
|
|
newTestRecord.IsFiled = testRecord.IsFiled;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据计划主键删除考试人员信息
|
|
/// </summary>
|
|
/// <param name="planId"></param>
|
|
public static void DeleteTestRecordByTestPlanId(string testPlanId)
|
|
{
|
|
var deleteRecords = from x in Funs.DB.Training_TestRecord where x.TestPlanId == testPlanId select x;
|
|
if (deleteRecords.Count() > 0)
|
|
{
|
|
foreach (var item in deleteRecords)
|
|
{
|
|
DeleteTestRecordByTestRecordId(item.TestRecordId);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据考生主键删除考生信息
|
|
/// </summary>
|
|
/// <param name="planId"></param>
|
|
public static void DeleteTestRecordByTestRecordId(string testRecordId)
|
|
{
|
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
|
{
|
|
var testRecord = db.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
|
|
if (testRecord != null)
|
|
{
|
|
var testRecordItem = from x in db.Training_TestRecordItem where x.TestRecordId == testRecordId select x;
|
|
if (testRecordItem.Count() > 0)
|
|
{
|
|
db.Training_TestRecordItem.DeleteAllOnSubmit(testRecordItem);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.Training_TestRecord.DeleteOnSubmit(testRecord);
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新没有结束时间且超时的考试记录
|
|
/// </summary>
|
|
public static int UpdateTestEndTimeNull(string testRecordId)
|
|
{
|
|
int icount = 0;
|
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
|
{
|
|
var q = from x in db.Training_TestRecord
|
|
where x.TestRecordId == testRecordId
|
|
select x;
|
|
var testRecord = q.FirstOrDefault();
|
|
if (!testRecord.TestEndTime.HasValue && testRecord.TestStartTime.HasValue
|
|
&& testRecord.TestStartTime.Value.AddMinutes(testRecord.Duration) < DateTime.Now)
|
|
{
|
|
testRecord.TestEndTime = testRecord.TestStartTime.Value.AddMinutes(testRecord.Duration);
|
|
testRecord.TestScores = db.Training_TestRecordItem.Where(x => x.TestRecordId == testRecord.TestRecordId).Sum(x => x.SubjectScore) ?? 0;
|
|
db.SubmitChanges();
|
|
icount++;
|
|
}
|
|
|
|
//var testRecord = from x in db.Training_TestRecord
|
|
// where !x.TestEndTime.HasValue && x.TestStartTime.HasValue
|
|
// && x.TestStartTime.Value.AddMinutes(x.Duration) < DateTime.Now
|
|
// && x.TestRecordId == testRecordId
|
|
// select x;
|
|
//if (testRecord.Count() > 0)
|
|
//{
|
|
// foreach (var item in testRecord)
|
|
// {
|
|
// item.TestEndTime = item.TestStartTime.Value.AddMinutes(item.Duration);
|
|
// item.TestScores = db.Training_TestRecordItem.Where(x => x.TestRecordId == item.TestRecordId).Sum(x => x.SubjectScore) ?? 0;
|
|
// db.SubmitChanges();
|
|
// icount++;
|
|
// }
|
|
//}
|
|
|
|
|
|
}
|
|
return icount;
|
|
}
|
|
}
|
|
}
|