1试题导入优化
This commit is contained in:
parent
53230dc06f
commit
f9d9e124b6
|
|
@ -15,10 +15,12 @@
|
|||
<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"
|
||||
<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>
|
||||
|
|
@ -34,52 +36,23 @@
|
|||
</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">
|
||||
<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 Width="55px" HeaderText="序号">
|
||||
<f:TemplateField ColumnID="tfPageIndex" Width="40px" HeaderText="序号" HeaderTextAlign="Center" TextAlign="Center"
|
||||
EnableLock="true" Locked="False">
|
||||
<ItemTemplate>
|
||||
<asp:Label ID="Label2" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
|
||||
<asp:Label ID="lblPageIndex" runat="server" Text='<%# gvErrorInfo.PageIndex * gvErrorInfo.PageSize + 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>
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@
|
|||
// </自动生成>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FineUIPro.Web.HSSE.EduTrain {
|
||||
namespace FineUIPro.Web.HSSE.EduTrain
|
||||
{
|
||||
|
||||
|
||||
public partial class TestTrainingItemIn {
|
||||
public partial class TestTrainingItemIn
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// form1 控件。
|
||||
|
|
@ -48,15 +50,6 @@ namespace FineUIPro.Web.HSSE.EduTrain {
|
|||
/// </remarks>
|
||||
protected global::FineUIPro.Toolbar Toolbar2;
|
||||
|
||||
/// <summary>
|
||||
/// ToolbarFill1 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.ToolbarFill ToolbarFill1;
|
||||
|
||||
/// <summary>
|
||||
/// btnAudit 控件。
|
||||
/// </summary>
|
||||
|
|
@ -66,6 +59,15 @@ namespace FineUIPro.Web.HSSE.EduTrain {
|
|||
/// </remarks>
|
||||
protected global::FineUIPro.Button btnAudit;
|
||||
|
||||
/// <summary>
|
||||
/// btnSave 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.Button btnSave;
|
||||
|
||||
/// <summary>
|
||||
/// btnDownLoad 控件。
|
||||
/// </summary>
|
||||
|
|
@ -85,22 +87,22 @@ namespace FineUIPro.Web.HSSE.EduTrain {
|
|||
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 控件。
|
||||
|
|
|
|||
Loading…
Reference in New Issue