1试题导入优化

This commit is contained in:
夏菊 2025-10-23 17:04:29 +08:00
parent 53230dc06f
commit f9d9e124b6
3 changed files with 184 additions and 164 deletions

View File

@ -5,105 +5,78 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>导入考试试题</title>
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" AutoSizePanelID="SimpleForm1" runat="server" OnCustomEvent="PageManager1_CustomEvent" />
<f:Form ID="SimpleForm1" ShowBorder="false" ShowHeader="false" AutoScroll="true"
BodyPadding="10px" runat="server" RedStarPosition="BeforeText" LabelAlign="Right">
<Toolbars>
<f:Toolbar ID="Toolbar2" Position="Top" ToolbarAlign="Right" runat="server">
<Items>
<f:ToolbarFill ID="ToolbarFill1" runat="server"></f:ToolbarFill>
<f:Button ID="btnAudit" Icon="ApplicationEdit" runat="server" ToolTip="数据导入" ValidateForms="SimpleForm1"
OnClick="btnAudit_Click">
</f:Button>
<f:Button ID="btnDownLoad" runat="server" Icon="ApplicationGo" ToolTip="下载模板" OnClick="btnDownLoad_Click">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Rows>
<f:FormRow>
<Items>
<f:FileUpload runat="server" ID="fuAttachUrl" EmptyText="选择要导入的文件" Label="选择要导入的文件"
LabelWidth="150px">
</f:FileUpload>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" EnableCollapse="true" runat="server"
EnableColumnLines="true" BoxFlex="1" DataKeyNames="TrainingItemId" ForceFit="true"
DataIDField="TrainingItemId" AllowSorting="true" SortField="TrainingCode,TrainingItemCode"
PageSize="50" Height="360px">
<Columns>
<f:TemplateField Width="55px" HeaderText="序号">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</f:TemplateField>
<f:RenderField Width="90px" ColumnID="TrainingCode" DataField="TrainingCode" FieldType="String"
HeaderText="类型编号" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="110px" ColumnID="TrainingName" DataField="TrainingName" FieldType="String"
HeaderText="试题类型" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="80px" ColumnID="TrainingItemCode" DataField="TrainingItemCode" FieldType="String"
HeaderText="编号" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="90px" ColumnID="TestTypeName" DataField="TestTypeName" FieldType="String"
HeaderText="题型" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="140px" ColumnID="WorkPostNames" DataField="WorkPostNames" FieldType="String"
HeaderText="适合岗位" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="200px" ColumnID="Abstracts" DataField="Abstracts" FieldType="String"
HeaderText="试题内容" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="80px" ColumnID="AItem" DataField="AItem" FieldType="String"
HeaderText="答案项A" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="80px" ColumnID="BItem" DataField="BItem" FieldType="String"
HeaderText="答案项B" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="80px" ColumnID="CItem" DataField="CItem" FieldType="String"
HeaderText="答案项C" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="80px" ColumnID="DItem" DataField="DItem" FieldType="String"
HeaderText="答案项D" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="80px" ColumnID="EItem" DataField="EItem" FieldType="String"
HeaderText="答案项E" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="90px" ColumnID="AnswerItems" DataField="AnswerItems" FieldType="String"
HeaderText="正确答案项" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
</Columns>
</f:Grid>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:HiddenField ID="hdFileName" runat="server">
</f:HiddenField>
<f:HiddenField ID="hdCheckResult" runat="server">
</f:HiddenField>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:Label ID="lblBottom" runat="server" Text="说明1 导入模板为.xls后缀的EXCEL文件黑体字为必填项。2 对于导入信息中重复记录自动过滤插入一条记录。3 题型为单选题、多选题、判断题,多岗位时用,隔开。4 适合岗位空时为通用试题。 5 数据导入完成,成功后自动返回,如果有不成功数据页面弹出提示框,列表显示导入成功数据。">
</f:Label>
</Items>
</f:FormRow>
</Rows>
</f:Form>
<f:Window ID="Window1" Title="导入信息" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window1_Close" IsModal="false"
CloseAction="HidePostBack" Width="900px" Height="600px">
</f:Window>
<f:PageManager ID="PageManager1" AutoSizePanelID="SimpleForm1" runat="server" OnCustomEvent="PageManager1_CustomEvent" />
<f:Form ID="SimpleForm1" ShowBorder="false" ShowHeader="false" AutoScroll="true"
BodyPadding="10px" runat="server" RedStarPosition="BeforeText" LabelAlign="Right">
<Toolbars>
<f:Toolbar ID="Toolbar2" Position="Top" ToolbarAlign="Right" runat="server">
<Items>
<f:Button ID="btnAudit" Icon="ApplicationEdit" runat="server" ToolTip="审核" ValidateForms="SimpleForm1"
OnClick="btnAudit_Click">
</f:Button>
<f:Button ID="btnSave" Icon="SystemSave" runat="server" ToolTip="保存" ValidateForms="SimpleForm1"
OnClick="btnSave_Click">
</f:Button>
<f:Button ID="btnDownLoad" runat="server" Icon="ApplicationGo" ToolTip="下载模板" OnClick="btnDownLoad_Click">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Rows>
<f:FormRow>
<Items>
<f:FileUpload runat="server" ID="fuAttachUrl" EmptyText="选择要导入的文件" Label="选择要导入的文件"
LabelWidth="150px">
</f:FileUpload>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:Grid ID="gvErrorInfo" ShowBorder="true" EnableAjax="false" ShowHeader="false" Title="导入试题信息" EnableCollapse="true"
runat="server" BoxFlex="1" AllowCellEditing="true" ClicksToEdit="2" AllowSorting="true"
SortDirection="DESC" EnableColumnLines="true" ForceFit="true" AllowPaging="false" IsDatabasePaging="false" PageSize="10"
EnableRowDoubleClickEvent="true" AllowFilters="true" EnableTextSelection="True" Height="400">
<Columns>
<f:TemplateField ColumnID="tfPageIndex" Width="40px" HeaderText="序号" HeaderTextAlign="Center" TextAlign="Center"
EnableLock="true" Locked="False">
<ItemTemplate>
<asp:Label ID="lblPageIndex" runat="server" Text='<%# gvErrorInfo.PageIndex * gvErrorInfo.PageSize + Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</f:TemplateField>
<f:BoundField DataField="Row" HeaderText="错误行号" Width="50px">
</f:BoundField>
<f:BoundField DataField="Column" HeaderText="错误列" Width="100px">
</f:BoundField>
<f:BoundField DataField="Reason" HeaderText="错误类型" MinWidth="220px">
</f:BoundField>
</Columns>
</f:Grid>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:HiddenField ID="hdFileName" runat="server">
</f:HiddenField>
<f:HiddenField ID="hdCheckResult" runat="server">
</f:HiddenField>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:Label ID="lblBottom" runat="server" Text="说明1 导入模板为.xls后缀的EXCEL文件黑体字为必填项。2 对于导入信息中重复记录自动过滤插入一条记录。3 题型为单选题、多选题、判断题,多岗位时用,隔开。4 适合岗位空时为通用试题。 5 数据导入完成,成功后自动返回,如果有不成功数据页面弹出提示框,列表显示导入成功数据。">
</f:Label>
</Items>
</f:FormRow>
</Rows>
</f:Form>
<f:Window ID="Window1" Title="导入信息" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window1_Close" IsModal="false"
CloseAction="HidePostBack" Width="900px" Height="600px">
</f:Window>
</form>
</body>
</html>

View File

@ -1,4 +1,5 @@
using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
@ -24,7 +25,8 @@ namespace FineUIPro.Web.HSSE.EduTrain
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
public static List<Model.ErrorInfo> errorInfos = new List<Model.ErrorInfo>();
#endregion
#region
@ -43,7 +45,10 @@ namespace FineUIPro.Web.HSSE.EduTrain
{
viewTrainingItems.Clear();
}
errorInfos = string.Empty;
if (errorInfos != null)
{
errorInfos.Clear();
}
}
}
#endregion
@ -73,9 +78,9 @@ namespace FineUIPro.Web.HSSE.EduTrain
{
viewTrainingItems.Clear();
}
if (!string.IsNullOrEmpty(errorInfos))
if (errorInfos != null)
{
errorInfos = string.Empty;
errorInfos.Clear();
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
@ -176,7 +181,7 @@ namespace FineUIPro.Web.HSSE.EduTrain
string col1 = pds.Rows[i][1].ToString().Trim();
if (string.IsNullOrEmpty(col1))
{
result += "第" + (i + 2).ToString() + "行," + "导入试题类型" + "," + "此项为必填项!" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "试题类型", Reason = "此项为必填项!" });
}
else
{
@ -200,11 +205,10 @@ namespace FineUIPro.Web.HSSE.EduTrain
string col3 = pds.Rows[i][3].ToString().Trim();
if (string.IsNullOrEmpty(col3))
{
result += "第" + (i + 2).ToString() + "行," + "导入试题题型" + "," + "此项为必填项!" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "试题题型", Reason = "此项为必填项!" });
}
else
{
if (col3 == "单选题")
{
newViewTrainingItem.TestType = "1";
@ -250,14 +254,15 @@ namespace FineUIPro.Web.HSSE.EduTrain
string ids = string.Empty;
foreach (var item in WorkPostSels)
{
var wp = workPosts.FirstOrDefault(x => x.WorkPostName == item);
string workItem = item.Trim();
var wp = workPosts.FirstOrDefault(x => x.WorkPostName == workItem);
if (wp != null)
{
ids += wp.WorkPostId + ",";
}
else
{
result += "第" + (i + 2).ToString() + "行," + "导入适合岗位" + item + "," + "此项基础表不存在!" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "适合岗位", Reason = $"[{workItem}]不在岗位表中!" });
}
}
if (!string.IsNullOrEmpty(ids))
@ -272,7 +277,7 @@ namespace FineUIPro.Web.HSSE.EduTrain
string col11 = pds.Rows[i][11].ToString().Trim();
if (string.IsNullOrEmpty(col11))
{
result += "第" + (i + 2).ToString() + "行," + "导入正确答案项" + "," + "为必填项!" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "正确答案项", Reason = "此项为必填项!" });
}
else
{
@ -291,14 +296,14 @@ namespace FineUIPro.Web.HSSE.EduTrain
}
else
{
result += "第" + (i + 2).ToString() + "行," + "正确答案项只能输入ABCDE且用','隔开!" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "正确答案项", Reason = "只能输入ABCDE且用','隔开!" });
}
}
////试题内容
if (string.IsNullOrEmpty(newViewTrainingItem.Abstracts))
{
result += "第" + (i + 2).ToString() + "行," + "导入试题内容" + "," + "为必填项!" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "试题内容", Reason = "此项为必填项!" });
}
else
{
@ -308,7 +313,7 @@ namespace FineUIPro.Web.HSSE.EduTrain
{
Model.Training_TestTrainingItem newTrainingItem = new Model.Training_TestTrainingItem
{
TrainingItemId = newViewTrainingItem.TrainingItemId = SQLHelper.GetNewID(typeof(Model.Training_TestTraining)),
TrainingItemId = newViewTrainingItem.TrainingItemId = SQLHelper.GetNewID(typeof(Model.Training_TestTrainingItem)),
TrainingId = newViewTrainingItem.TrainingId,
TrainingItemCode = newViewTrainingItem.TrainingItemCode,
TrainingItemName = newViewTrainingItem.TrainingItemName,
@ -336,41 +341,32 @@ namespace FineUIPro.Web.HSSE.EduTrain
newTrainingItem.Abstracts = newViewTrainingItem.Abstracts + "( )";
}
BLL.TestTrainingItemService.AddTestTrainingItem(newTrainingItem);
///加入培训试题库
viewTrainingItems.Add(newViewTrainingItem);
}
else
{
result += "第" + (i + 2).ToString() + "行," + "导入试题重复" + "|";
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "试题内容", Reason = "试题重复!" });
}
}
}
if (viewTrainingItems.Count > 0)
{
viewTrainingItems = viewTrainingItems.Distinct().ToList();
this.Grid1.Hidden = false;
this.Grid1.DataSource = viewTrainingItems;
this.Grid1.DataBind();
}
if (!string.IsNullOrEmpty(result))
if (errorInfos.Any())
{
viewTrainingItems.Clear();
result = "数据导入完成,未成功数据:" + result.Substring(0, result.LastIndexOf("|"));
errorInfos = result;
Alert alert = new Alert
{
Message = result,
Target = Target.Self
};
alert.Show();
this.gvErrorInfo.DataSource = errorInfos;
this.gvErrorInfo.DataBind();
}
else
{
errorInfos = string.Empty;
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
errorInfos.Clear();
if (!viewTrainingItems.Any())
{
Alert.ShowInTop("导入数据为空!", MessageBoxIcon.Warning);
}
else
{
ShowNotify("审核完成,请点击导入!", MessageBoxIcon.Success);
}
}
}
else
@ -381,6 +377,55 @@ namespace FineUIPro.Web.HSSE.EduTrain
}
#endregion
#endregion
#region
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (!errorInfos.Any())
{
int a = viewTrainingItems.Count();
int insertCount = 0;
int updateCount = 0;
for (int i = 0; i < a; i++)
{
Model.Training_TestTrainingItem newModel = new Model.Training_TestTrainingItem
{
TrainingItemId = viewTrainingItems[i].TrainingItemId,
TrainingId = viewTrainingItems[i].TrainingId,
TrainingItemCode = viewTrainingItems[i].TrainingItemCode,
TestType = viewTrainingItems[i].TestType,
Abstracts = viewTrainingItems[i].Abstracts,
WorkPostIds = viewTrainingItems[i].WorkPostIds,
WorkPostNames = viewTrainingItems[i].WorkPostNames,
AItem = viewTrainingItems[i].AItem,
BItem = viewTrainingItems[i].BItem,
CItem = viewTrainingItems[i].CItem,
DItem = viewTrainingItems[i].DItem,
EItem = viewTrainingItems[i].EItem,
AnswerItems = viewTrainingItems[i].AnswerItems
};
BLL.TestTrainingItemService.AddTestTrainingItem(newModel);
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
string filePath = initFullPath + this.hdFileName.Text;
if (filePath != string.Empty && File.Exists(filePath))
{
File.Delete(filePath);//删除上传的XLS文件
}
ShowNotify("导入完成!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop("请先将错误数据修正,再重新导入保存!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
@ -396,9 +441,9 @@ namespace FineUIPro.Web.HSSE.EduTrain
}
if (viewTrainingItems.Count > 0)
{
this.Grid1.Hidden = false;
this.Grid1.DataSource = viewTrainingItems;
this.Grid1.DataBind();
this.gvErrorInfo.Hidden = false;
this.gvErrorInfo.DataSource = viewTrainingItems;
this.gvErrorInfo.DataBind();
}
}

View File

@ -7,11 +7,13 @@
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.HSSE.EduTrain {
public partial class TestTrainingItemIn {
namespace FineUIPro.Web.HSSE.EduTrain
{
public partial class TestTrainingItemIn
{
/// <summary>
/// form1 控件。
/// </summary>
@ -20,7 +22,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
@ -29,7 +31,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// SimpleForm1 控件。
/// </summary>
@ -38,7 +40,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Form SimpleForm1;
/// <summary>
/// Toolbar2 控件。
/// </summary>
@ -47,16 +49,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar Toolbar2;
/// <summary>
/// ToolbarFill1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarFill ToolbarFill1;
/// <summary>
/// btnAudit 控件。
/// </summary>
@ -65,7 +58,16 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnAudit;
/// <summary>
/// btnSave 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSave;
/// <summary>
/// btnDownLoad 控件。
/// </summary>
@ -74,7 +76,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDownLoad;
/// <summary>
/// fuAttachUrl 控件。
/// </summary>
@ -83,25 +85,25 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.FileUpload fuAttachUrl;
/// <summary>
/// Grid1 控件。
/// gvErrorInfo 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
protected global::FineUIPro.Grid gvErrorInfo;
/// <summary>
/// Label2 控件。
/// lblPageIndex 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label2;
protected global::System.Web.UI.WebControls.Label lblPageIndex;
/// <summary>
/// hdFileName 控件。
/// </summary>
@ -110,7 +112,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.HiddenField hdFileName;
/// <summary>
/// hdCheckResult 控件。
/// </summary>
@ -119,7 +121,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.HiddenField hdCheckResult;
/// <summary>
/// lblBottom 控件。
/// </summary>
@ -128,7 +130,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Label lblBottom;
/// <summary>
/// Window1 控件。
/// </summary>