1试题导入优化
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user