diff --git a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx index f74a815..ddfcee1 100644 --- a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx +++ b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx @@ -5,105 +5,78 @@ 导入考试试题 - +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.cs b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.cs index 2bfd483..3031803 100644 --- a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.cs +++ b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.cs @@ -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 /// /// 错误集合 /// - public static string errorInfos = string.Empty; + public static List errorInfos = new List(); + #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 保存 + /// + /// 保存 + /// + /// + /// + 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 关闭弹出窗口 /// @@ -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(); } } diff --git a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.designer.cs b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.designer.cs index 144c941..b979098 100644 --- a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.designer.cs +++ b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestTrainingItemIn.aspx.designer.cs @@ -7,11 +7,13 @@ // //------------------------------------------------------------------------------ -namespace FineUIPro.Web.HSSE.EduTrain { - - - public partial class TestTrainingItemIn { - +namespace FineUIPro.Web.HSSE.EduTrain +{ + + + public partial class TestTrainingItemIn + { + /// /// form1 控件。 /// @@ -20,7 +22,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::System.Web.UI.HtmlControls.HtmlForm form1; - + /// /// PageManager1 控件。 /// @@ -29,7 +31,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.PageManager PageManager1; - + /// /// SimpleForm1 控件。 /// @@ -38,7 +40,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Form SimpleForm1; - + /// /// Toolbar2 控件。 /// @@ -47,16 +49,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Toolbar Toolbar2; - - /// - /// ToolbarFill1 控件。 - /// - /// - /// 自动生成的字段。 - /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 - /// - protected global::FineUIPro.ToolbarFill ToolbarFill1; - + /// /// btnAudit 控件。 /// @@ -65,7 +58,16 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Button btnAudit; - + + /// + /// btnSave 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::FineUIPro.Button btnSave; + /// /// btnDownLoad 控件。 /// @@ -74,7 +76,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Button btnDownLoad; - + /// /// fuAttachUrl 控件。 /// @@ -83,25 +85,25 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.FileUpload fuAttachUrl; - + /// - /// Grid1 控件。 + /// gvErrorInfo 控件。 /// /// /// 自动生成的字段。 /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// - protected global::FineUIPro.Grid Grid1; - + protected global::FineUIPro.Grid gvErrorInfo; + /// - /// Label2 控件。 + /// lblPageIndex 控件。 /// /// /// 自动生成的字段。 /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// - protected global::System.Web.UI.WebControls.Label Label2; - + protected global::System.Web.UI.WebControls.Label lblPageIndex; + /// /// hdFileName 控件。 /// @@ -110,7 +112,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.HiddenField hdFileName; - + /// /// hdCheckResult 控件。 /// @@ -119,7 +121,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.HiddenField hdCheckResult; - + /// /// lblBottom 控件。 /// @@ -128,7 +130,7 @@ namespace FineUIPro.Web.HSSE.EduTrain { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Label lblBottom; - + /// /// Window1 控件。 ///