This commit is contained in:
2021-04-30 10:28:37 +08:00
commit f901e87a6e
9029 changed files with 1810915 additions and 0 deletions
@@ -0,0 +1,186 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace BLL
{
/// <summary>
/// 知识竞赛计划
/// </summary>
public static class ServerTestPlanService
{
public static Model.SGGLDB db = Funs.DB;
/// <summary>
/// 根据主键获取知识竞赛计划
/// </summary>
/// <param name="TestPlanId"></param>
/// <returns></returns>
public static Model.Test_TestPlan GetTestPlanById(string TestPlanId)
{
return Funs.DB.Test_TestPlan.FirstOrDefault(e => e.TestPlanId == TestPlanId);
}
/// <summary>
/// 添加知识竞赛计划
/// </summary>
/// <param name="TestPlan"></param>
public static void AddTestPlan(Model.Test_TestPlan TestPlan)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestPlan newTestPlan = new Model.Test_TestPlan
{
TestPlanId = TestPlan.TestPlanId,
PlanCode = TestPlan.PlanCode,
PlanName = TestPlan.PlanName,
PlanManId = TestPlan.PlanManId,
PlanDate = TestPlan.PlanDate,
TestStartTime = TestPlan.TestStartTime,
TestEndTime = TestPlan.TestEndTime,
Duration = TestPlan.Duration,
TotalScore = TestPlan.TotalScore,
QuestionCount = TestPlan.QuestionCount,
TestPalce = TestPlan.TestPalce,
QRCodeUrl = TestPlan.QRCodeUrl,
SValue = TestPlan.SValue,
MValue = TestPlan.MValue,
JValue = TestPlan.JValue,
States = TestPlan.States,
};
db.Test_TestPlan.InsertOnSubmit(newTestPlan);
db.SubmitChanges();
}
/// <summary>
/// 修改知识竞赛计划
/// </summary>
/// <param name="TestPlan"></param>
public static void UpdateTestPlan(Model.Test_TestPlan TestPlan)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestPlan newTestPlan = db.Test_TestPlan.FirstOrDefault(e => e.TestPlanId == TestPlan.TestPlanId);
if (newTestPlan != null)
{
newTestPlan.PlanCode = TestPlan.PlanCode;
newTestPlan.PlanName = TestPlan.PlanName;
newTestPlan.PlanManId = TestPlan.PlanManId;
newTestPlan.PlanDate = TestPlan.PlanDate;
newTestPlan.TestStartTime = TestPlan.TestStartTime;
newTestPlan.TestEndTime = TestPlan.TestEndTime;
newTestPlan.Duration = TestPlan.Duration;
newTestPlan.TotalScore = TestPlan.TotalScore;
newTestPlan.QuestionCount = TestPlan.QuestionCount;
newTestPlan.TestPalce = TestPlan.TestPalce;
newTestPlan.QRCodeUrl = TestPlan.QRCodeUrl;
newTestPlan.SValue = TestPlan.SValue;
newTestPlan.MValue = TestPlan.MValue;
newTestPlan.JValue = TestPlan.JValue;
newTestPlan.States = TestPlan.States;
db.SubmitChanges();
}
}
/// <summary>
/// 根据主键删除知识竞赛计划
/// </summary>
/// <param name="TestPlanId"></param>
public static void DeleteTestPlanById(string TestPlanId)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestPlan TestPlan = db.Test_TestPlan.FirstOrDefault(e => e.TestPlanId == TestPlanId);
if (TestPlan != null)
{
///删除编码表记录
CodeRecordsService.DeleteCodeRecordsByDataId(TestPlan.TestPlanId);
////删除附件表
CommonService.DeleteAttachFileById(TestPlan.TestPlanId);
///删除题目类型
ServerTestPlanTrainingService.DeleteTestPlanTrainingByTestPlanId(TestPlan.TestPlanId);
db.Test_TestPlan.DeleteOnSubmit(TestPlan);
db.SubmitChanges();
}
}
/// <summary>
/// 结束考试
/// </summary>
/// <returns></returns>
public static string EndTestPlan(string testPlanId)
{
Model.SGGLDB db = Funs.DB;
string info = string.Empty;
var getTestPlans = from x in db.Test_TestPlan
where x.States == Const.State_2 && x.TestEndTime.Value.AddMinutes(x.Duration.Value) < DateTime.Now
&& (testPlanId == null || x.TestPlanId == testPlanId)
select x;
foreach (var getTestPlan in getTestPlans)
{
string itemInfo = string.Empty;
var getTestRecords = from x in db.Test_TestRecord
where x.TestPlanId == testPlanId && (!x.TotalScore.HasValue || !x.TestEndTime.HasValue)
select x;
//// 考试下所有考试都交卷
if (getTestRecords.Count() > 0)
{
//// 扫码结束时间 + 考试时长 小于当前时间 考试结束 所有人自动交卷
if (getTestPlan.TestStartTime.Value.AddMinutes(getTestPlan.Duration.Value) < DateTime.Now)
{
foreach (var itemRecord in getTestRecords)
{
DateTime rdateTime = itemRecord.TestStartTime.HasValue ? itemRecord.TestStartTime.Value : getTestPlan.TestStartTime.Value;
itemRecord.TestEndTime = rdateTime.AddMinutes(itemRecord.Duration.Value);
itemRecord.TestScores = db.Test_TestRecordItem.Where(x => x.TestRecordId == itemRecord.TestRecordId).Sum(x => x.SubjectScore) ?? 0;
db.SubmitChanges();
}
}
else
{
itemInfo = getTestPlan.PlanCode + "竞赛中还有未交卷人员,且未达到考试结束时间!";
info += itemInfo;
}
}
if (string.IsNullOrEmpty(itemInfo))
{
getTestPlan.States = Const.State_3;
getTestPlan.ActualTime = DateTime.Now;
db.SubmitChanges();
}
}
if (getTestPlans.Count() == 0 && !string.IsNullOrEmpty(testPlanId))
{
info = "当前竞赛还不到结束时间!";
}
return info;
}
/// <summary>
/// 获取类别下拉项
/// </summary>
/// <returns></returns>
public static List<Model.Test_TestPlan> GetTestPlanList()
{
var list = (from x in Funs.DB.Test_TestPlan orderby x.PlanCode descending select x).ToList();
return list;
}
#region 表下拉框
/// <summary>
/// 表下拉框
/// </summary>
/// <param name="dropName">下拉框名字</param>
/// <param name="isShowPlease">是否显示请选择</param>
public static void InitTestPlanDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
{
dropName.DataValueField = "TestPlanId";
dropName.DataTextField = "PlanName";
dropName.DataSource = GetTestPlanList();
dropName.DataBind();
if (isShowPlease)
{
Funs.FineUIPleaseSelect(dropName);
}
}
#endregion
}
}
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
/// <summary>
/// 知识竞赛计划题目类型
/// </summary>
public static class ServerTestPlanTrainingService
{
public static Model.SGGLDB db = Funs.DB;
/// <summary>
/// 根据主键获取知识竞赛计划
/// </summary>
/// <param name="TestPlanTrainingId"></param>
/// <returns></returns>
public static Model.Test_TestPlanTraining GetTestPlanTrainingById(string TestPlanTrainingId)
{
return Funs.DB.Test_TestPlanTraining.FirstOrDefault(e => e.TestPlanTrainingId == TestPlanTrainingId);
}
/// <summary>
/// 添加知识竞赛计划
/// </summary>
/// <param name="TestPlanTraining"></param>
public static void AddTestPlanTraining(Model.Test_TestPlanTraining TestPlanTraining)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestPlanTraining newTestPlanTraining = new Model.Test_TestPlanTraining
{
TestPlanTrainingId = TestPlanTraining.TestPlanTrainingId,
TestPlanId = TestPlanTraining.TestPlanId,
TrainingId = TestPlanTraining.TrainingId,
TestType1Count = TestPlanTraining.TestType1Count,
TestType2Count = TestPlanTraining.TestType2Count,
TestType3Count = TestPlanTraining.TestType3Count,
UserType = TestPlanTraining.UserType,
};
db.Test_TestPlanTraining.InsertOnSubmit(newTestPlanTraining);
db.SubmitChanges();
}
/// <summary>
/// 修改知识竞赛计划
/// </summary>
/// <param name="TestPlanTraining"></param>
public static void UpdateTestPlanTraining(Model.Test_TestPlanTraining TestPlanTraining)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestPlanTraining newTestPlanTraining = db.Test_TestPlanTraining.FirstOrDefault(e => e.TestPlanTrainingId == TestPlanTraining.TestPlanTrainingId);
if (newTestPlanTraining != null)
{
newTestPlanTraining.TrainingId = TestPlanTraining.TrainingId;
newTestPlanTraining.TestType1Count = TestPlanTraining.TestType1Count;
newTestPlanTraining.TestType2Count = TestPlanTraining.TestType2Count;
newTestPlanTraining.TestType3Count = TestPlanTraining.TestType3Count;
newTestPlanTraining.UserType = TestPlanTraining.UserType;
db.SubmitChanges();
}
}
/// <summary>
/// 根据主键删除知识竞赛计划
/// </summary>
/// <param name="TestPlanTrainingId"></param>
public static void DeleteTestPlanTrainingById(string TestPlanTrainingId)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestPlanTraining TestPlanTraining = db.Test_TestPlanTraining.FirstOrDefault(e => e.TestPlanTrainingId == TestPlanTrainingId);
if (TestPlanTraining != null)
{
db.Test_TestPlanTraining.DeleteOnSubmit(TestPlanTraining);
db.SubmitChanges();
}
}
/// <summary>
/// 根据主键删除知识竞赛计划
/// </summary>
/// <param name="TestPlanTrainingId"></param>
public static void DeleteTestPlanTrainingByTestPlanId(string TestPlanId)
{
Model.SGGLDB db = Funs.DB;
var TestPlanTraining = from x in db.Test_TestPlanTraining where x.TestPlanId == TestPlanId select x;
if (TestPlanTraining.Count() > 0)
{
db.Test_TestPlanTraining.DeleteAllOnSubmit(TestPlanTraining);
db.SubmitChanges();
}
}
}
}
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
/// <summary>
/// 考试记录
/// </summary>
public static class ServerTestRecordService
{
public static Model.SGGLDB db = Funs.DB;
/// <summary>
/// 根据主键获取考试记录
/// </summary>
/// <param name="testRecordId"></param>
/// <returns></returns>
public static Model.Test_TestRecord GetTestRecordById(string testRecordId)
{
return Funs.DB.Test_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
}
/// <summary>
/// 新增考生记录信息
/// </summary>
/// <param name="Training"></param>
public static void AddTestRecord(Model.Test_TestRecord testRecord)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestRecord newTestRecord = new Model.Test_TestRecord
{
TestRecordId = testRecord.TestRecordId,
ProjectId = testRecord.ProjectId,
TestPlanId = testRecord.TestPlanId,
TestManId = testRecord.TestManId,
};
db.Test_TestRecord.InsertOnSubmit(newTestRecord);
db.SubmitChanges();
}
/// <summary>
/// 修改考试记录信息
/// </summary>
/// <param name="Training"></param>
public static void UpdateTestRecord(Model.Test_TestRecord testRecord)
{
Model.SGGLDB db = Funs.DB;
Model.Test_TestRecord newTestRecord = db.Test_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecord.TestRecordId);
if (newTestRecord != null)
{
newTestRecord.TestScores = testRecord.TestScores;
newTestRecord.TestEndTime = testRecord.TestEndTime;
db.SubmitChanges();
}
}
/// <summary>
/// 根据计划主键删除考试人员信息
/// </summary>
/// <param name="planId"></param>
public static void DeleteTestRecordByTestPlanId(string testPlanId)
{
var deleteRecords = from x in Funs.DB.Test_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.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var testRecord = db.Test_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
if (testRecord != null)
{
var testRecordItem = from x in db.Test_TestRecordItem where x.TestRecordId == testRecordId select x;
if (testRecordItem.Count() > 0)
{
db.Test_TestRecordItem.DeleteAllOnSubmit(testRecordItem);
db.SubmitChanges();
}
db.Test_TestRecord.DeleteOnSubmit(testRecord);
db.SubmitChanges();
}
}
}
/// <summary>
/// 更新没有结束时间且超时的考试记录
/// </summary>
public static int UpdateTestEndTimeNull(string testRecordId)
{
int icount = 0;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var testRecord = from x in db.Test_TestRecord
where !x.TestEndTime.HasValue && x.TestStartTime.HasValue
&& x.TestStartTime.Value.AddMinutes(x.Duration.Value) < DateTime.Now
&& x.TestRecordId == testRecordId
select x;
if (testRecord.Count() > 0)
{
foreach (var item in testRecord)
{
item.TestEndTime = item.TestStartTime.Value.AddMinutes(item.Duration.Value);
item.TestScores = db.Test_TestRecordItem.Where(x => x.TestRecordId == item.TestRecordId).Sum(x => x.SubjectScore) ?? 0;
db.SubmitChanges();
icount++;
}
}
}
return icount;
}
}
}