SGGL_JT/SUBQHSE/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx.cs

631 lines
24 KiB
C#
Raw Normal View History

2025-04-07 17:43:30 +08:00
using Aspose.Words;
using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace FineUIPro.Web.HSSE.EduTrain
{
public partial class TestRecord : PageBase
{
#region
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region
public string UnitId
{
get
{
return (string)ViewState["UnitId"];
}
set
{
ViewState["UnitId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
2025-04-08 18:30:09 +08:00
this.InitDropDownList();
2025-04-07 17:43:30 +08:00
this.ucTree.UnitId = this.CurrUser.UnitId;
this.ucTree.ProjectId = this.ProjectId;
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
this.panelLeftRegion.Hidden = true;
// this.Grid1.Columns[0].Hidden = true;
}
Funs.DropDownPageSize(this.ddlPageSize);
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
GetButtonPower();
///更新没有结束时间且超时的考试记录
GetDataService.UpdateTestPlanStates();
// 绑定表格
BindGrid();
}
else
{
if (GetRequestEventArgument() == "reloadGrid")
{
BindGrid();
}
}
}
#endregion
2025-04-08 18:30:09 +08:00
private void InitDropDownList()
{
//单位
BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true);
}
2025-04-07 17:43:30 +08:00
protected void changeTree(object sender, EventArgs e)
{
this.ProjectId = this.ucTree.ProjectId;
2025-04-08 18:30:09 +08:00
this.InitDropDownList();
2025-04-07 17:43:30 +08:00
//新增UnitId
this.UnitId = this.ucTree.UnitId;
//判断 当有projectId的时候单位id为空
if (!string.IsNullOrEmpty(this.ProjectId))
{
this.UnitId = "";
}
this.BindGrid();
}
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
if (!string.IsNullOrEmpty(this.ProjectId) || !string.IsNullOrEmpty(this.UnitId))
{
string strSql = @"SELECT TestRecord.TestRecordId,TestRecord.TestPlanId, TestRecord.TestManId,TestRecord.TestStartTime,TestRecord.TestEndTime, TestRecord.TestScores,
(CASE WHEN TestPlan.PlanName IS NULL THEN testTrain.TrainingName ELSE TestPlan.PlanName END) AS PlanName,
ISNULL(TestPlan.Duration,90) AS Duration,ISNULL(TestPlan.TotalScore,100) AS TotalScore,TestPlan.TestPalce,ISNULL(TestPlan.QuestionCount,95) AS QuestionCount,TestRecord.TemporaryUser,Person.PersonName AS TestManName
,Unit.UnitName,testTrain.TrainingName as TrainingName1"
+ @" FROM dbo.Training_TestRecord AS TestRecord"
+ @" LEFT JOIN dbo.Training_TestPlan AS TestPlan ON TestPlan.TestPlanId=TestRecord.TestPlanId"
+ @" LEFT JOIN dbo.Training_TestTraining AS Training ON Training.TrainingId = TestRecord.TestType"
+ @" LEFT JOIN dbo.SitePerson_Person AS Person ON Person.PersonId = TestRecord.TestManId "
+ @" LEFT JOIN dbo.Base_Unit AS Unit ON Person.UnitId=Unit.UnitId"
+ @" LEFT JOIN Training_TestTraining testTrain on TestRecord.TestPlanId = testTrain.TrainingId"
+ @" WHERE (isFiled IS NULL OR isFiled = 0) ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(ProjectId))
{
strSql += " AND TestRecord.ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", ProjectId));
}
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
strSql += " AND Unit.UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue.Trim() ));
}
if (!string.IsNullOrEmpty(UnitId))
{
strSql += " AND TestRecord.UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", UnitId));
}
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
strSql += " AND (Person.PersonName LIKE @name OR TestPlan.PlanName LIKE @name OR Training.TrainingName LIKE @name)";
listStr.Add(new SqlParameter("@name", "%" + this.txtName.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtMinScores.Text.Trim()))
{
strSql += " AND TestRecord.TestScores >= @MinScores";
listStr.Add(new SqlParameter("@MinScores", Funs.GetNewDecimalOrZero(this.txtMinScores.Text.Trim())));
}
if (!string.IsNullOrEmpty(this.txtMaxScores.Text.Trim()))
{
strSql += " AND TestRecord.TestScores <= @MaxScores";
listStr.Add(new SqlParameter("@MaxScores", Funs.GetNewDecimalOrZero(this.txtMaxScores.Text.Trim())));
}
//if (this.IsTemp.Checked)
//{
// strSql += " AND Users.IsTemp = 1 ";
//}
//else
//{
// strSql += " AND (Users.IsTemp = 0 OR Users.IsTemp IS NULL)";
//}
if (this.ckIsNULL.Checked)
{
strSql += " AND (TestRecord.TestStartTime IS NULL OR TestRecord.TestEndTime IS NULL) ";
}
if (!string.IsNullOrEmpty(this.txtStartDate.Text))
{
strSql += " AND TestRecord.TestStartTime >= @StartDate";
listStr.Add(new SqlParameter("@StartDate", Funs.GetNewDateTime(this.txtStartDate.Text)));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text))
{
strSql += " AND TestRecord.TestEndTime <= @EndDate ";
listStr.Add(new SqlParameter("@EndDate", Funs.GetNewDateTime(this.txtEndDate.Text)));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string testRecordId = Grid1.Rows[i].DataKeys[0].ToString();
var testRecord = BLL.TestRecordService.GetTestRecordById(testRecordId);
if (testRecord != null)
{
//if (testRecord.TestScores < SysConstSetService.getPassScore())
//{
// Grid1.Rows[i].RowCssClass = "Red";
//}
if (testRecord.TestScores < SysConstSetService.getPassScore(testRecord.TestPlanId))
{
Grid1.Rows[i].RowCssClass = "Red";
}
}
}
}
}
#endregion
#region
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuView_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TestRecordItem.aspx?TestRecordId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
#endregion
#region
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnMenuFile_Click(object sender, EventArgs e)
//{
// if (Grid1.SelectedRowIndexArray.Length > 0)
// {
// string values = string.Empty;
// foreach (int rowIndex in Grid1.SelectedRowIndexArray)
// {
// string rowID = Grid1.DataKeys[rowIndex][0].ToString();
// values += rowID + "|";
// }
// if (!string.IsNullOrEmpty(values) && values.Length <= 1850)
// {
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/InformationProject/FileCabinetAChange.aspx?values={0}&menuId={1}", values, BLL.Const.ProjectTestRecordMenuId, "查看 - "), "归档", 600, 540));
// }
// else
// {
// Alert.ShowInTop("请一次至少一条最多50条记录归档", MessageBoxIcon.Warning);
// }
// BindGrid();
// }
//}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
protected void IsTemp_CheckedChanged(object sender, CheckedEventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var getV = BLL.TestRecordService.GetTestRecordById(rowID);
if (getV != null)
{
BLL.LogService.AddSys_Log(this.CurrUser, "考试记录", rowID, BLL.Const.ProjectTestRecordMenuId, BLL.Const.BtnDelete);
BLL.TestRecordService.DeleteTestRecordByTestRecordId(rowID);
}
}
BindGrid();
ShowNotify("删除数据成功!");
}
}
#endregion
#region
/// <summary>
/// 导出事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("考试记录" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = Grid1.RecordCount;
BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#endregion
//protected void btnPrint_Click(object sender, EventArgs e)
//{
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
// return;
// }
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TestRecordPrint.aspx?TestRecordId={0}", Grid1.SelectedRowID, "编辑 - "), "考试试卷", 900, 650));
//}
protected void btnPrint_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
PrinterDocService.PrinterDocMethod(Const.ProjectTestRecordMenuId, Grid1.SelectedRowID, "试卷");
}
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.HSSETestRecordMenuId);
if (buttonList.Count > 0)
{
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
}
if (this.CurrUser.UserId == BLL.Const.sysglyId || this.CurrUser.UserId == BLL.Const.hfnbdId)
{
this.btnRefresh.Hidden = false;
}
}
#endregion
#region
/// <summary>
/// 校正
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnRefresh_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.ProjectId))
{
ThreadWithCallback(()=>RepairTest(), () => CallBack());
}
}
private void ThreadWithCallback(Action act, Action callback)
{
Thread thread = new Thread(() =>
{
act.Invoke();
callback.Invoke();
});
thread.Start();
}
private void CallBack()
{
PageContext.RegisterStartupScript(Alert.GetShowReference("操作完成,共处理", MessageBoxIcon.Success));
// ShowNotify("操作完成,共处理", MessageBoxIcon.Success);
// Alert.ShowInTop("操作完成,共处理", MessageBoxIcon.Success);
}
private void RepairTest()
{
int countRecod = 0;
var getDataALL = from x in Funs.DB.Training_TestRecordItem
join y in Funs.DB.Training_TestRecord on x.TestRecordId equals y.TestRecordId
where y.ProjectId == ProjectId
orderby y.TestStartTime descending
group x by new { x.TestRecordId, x.TrainingItemCode }
into g
where g.Count() > 1
select new { g.FirstOrDefault().TestRecordId, g.FirstOrDefault().TrainingItemCode, gCount = g.Count() };
if (getDataALL.Count() > 0)
{
var getData = getDataALL.Take(1000);
List<string> TestRecordIdList = getData.Select(x => x.TestRecordId).Distinct().ToList();
foreach (var item in getData)
{
var getTestRecordItem = Funs.DB.Training_TestRecordItem.FirstOrDefault(x =>
x.TestRecordId == item.TestRecordId
&& x.TrainingItemCode == item.TrainingItemCode &&
(!x.SubjectScore.HasValue || x.SubjectScore < x.Score));
if (getTestRecordItem == null)
{
getTestRecordItem = Funs.DB.Training_TestRecordItem.FirstOrDefault(x =>
x.TestRecordId == item.TestRecordId
&& x.TrainingItemCode == item.TrainingItemCode);
}
if (getTestRecordItem != null)
{
Funs.DB.Training_TestRecordItem.DeleteOnSubmit(getTestRecordItem);
Funs.DB.SubmitChanges();
}
}
foreach (var item in TestRecordIdList)
{
var getTestRecord = Funs.DB.Training_TestRecord.FirstOrDefault(x => x.TestRecordId == item);
if (getTestRecord != null)
{
getTestRecord.TestScores = Funs.DB.Training_TestRecordItem.Where(x => x.TestRecordId == item)
.Sum(x => x.SubjectScore ?? 0);
Funs.DB.SubmitChanges();
countRecod++;
}
}
}
if (countRecod == 0)
{
countRecod = CorrectingScore();
}
// Alert.ShowInTop("操作完成,共处理" + countRecod.ToString() + "条考试记录", MessageBoxIcon.Success);
}
private int CorrectingScore()
{
int countRecod = 0;
var getTestRecords = from x in Funs.DB.Training_TestRecord
join y in Funs.DB.Training_TestPlan on x.TestPlanId equals y.TestPlanId
where x.TestScores > y.TotalScore
select x;
if (getTestRecords.Count() > 0)
{
foreach (var item in getTestRecords)
{
var getT = (from x in Funs.DB.Training_TestPlanTraining
where x.TestPlanId == item.TestPlanId
select new { x.TestType1Count, x.TestType2Count, x.TestType3Count }).Distinct();
if (getT.Count() > 0)
{
int s = getT.Sum(x => x.TestType1Count) ?? 0;
int m = getT.Sum(x => x.TestType2Count) ?? 0;
int j = getT.Sum(x => x.TestType3Count) ?? 0;
var getTestRecordItems = from x in Funs.DB.Training_TestRecordItem where x.TestRecordId == item.TestRecordId select x;
if (getTestRecordItems.Count() > 0)
{
List<Model.Training_TestRecordItem> delList = new List<Model.Training_TestRecordItem>();
var getSItem = getTestRecordItems.Where(x => x.TestType == "1");
int sCount = getSItem.Count() - s;
if (sCount > 0)
{
delList.AddRange(getSItem.Take(sCount).ToList());
}
var getMItem = getTestRecordItems.Where(x => x.TestType == "2");
int mCount = getMItem.Count() - m;
if (mCount > 0)
{
delList.AddRange(getMItem.Take(mCount).ToList());
}
var getJItem = getTestRecordItems.Where(x => x.TestType == "3");
int jCount = getJItem.Count() - j;
if (jCount > 0)
{
delList.AddRange(getJItem.Take(jCount).ToList());
}
if (delList.Count() > 0)
{
Funs.DB.Training_TestRecordItem.DeleteAllOnSubmit(delList);
Funs.DB.SubmitChanges();
}
item.TestScores = Funs.DB.Training_TestRecordItem.Where(x => x.TestRecordId == item.TestRecordId).Sum(x => x.SubjectScore ?? 0);
Funs.DB.SubmitChanges();
countRecod++;
}
}
}
}
return countRecod;
}
#endregion
#region
protected void btnMenuReset_Click(object sender, EventArgs e) {
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
if (Grid1.SelectedRowIndexArray.Length>1)
{
Alert.ShowInTop("重考不能多选人员!", MessageBoxIcon.Warning);
return;
}
//修改该人员的TestEndTime为NULL
var TestRecordModel = Funs.DB.Training_TestRecord.FirstOrDefault(x => x.TestRecordId == Grid1.SelectedRowID);
if (TestRecordModel != null)
{
//状态修改为考试中
var getTestPlan = Funs.DB.Training_TestPlan.FirstOrDefault(x => x.TestPlanId == TestRecordModel.TestPlanId);
if (getTestPlan!=null)
{
if (getTestPlan.States!="2")
{
getTestPlan.States = "2";
Funs.DB.SubmitChanges();
}
}
TestRecordModel.TestStartTime = null;
TestRecordModel.TestEndTime = null;
TestRecordModel.TestScores = null;
Funs.DB.SubmitChanges();
var TestRecordItemModelList = Funs.DB.Training_TestRecordItem.Where(x => x.TestRecordId == TestRecordModel.TestRecordId).ToList();
Funs.DB.Training_TestRecordItem.DeleteAllOnSubmit(TestRecordItemModelList);
Funs.DB.SubmitChanges();
BindGrid();
Alert.ShowInTop("设置成功,请通知人员重考!", MessageBoxIcon.Success);
return;
}
else {
Alert.ShowInTop("数据有误,请刷新页面。", MessageBoxIcon.Warning);
}
}
#endregion
}
}