题库导入模板下载 课程列新增动态绑定数据库课程数据

master
xiaochanghai 12 months ago
parent ca38c76d1b
commit 933f864860
  1. 26
      Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs
  2. 103
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -236,17 +236,17 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
AND B.RoleNo LIKE 'TrainingExam%'";
var toolbarRoles = DbAccess.QueryList<ToolbarRole>(sql);
if (toolbars.Any(x => x.fnKey == "NewYN"))
Toolbar.Add(new Toolbar()
{
fnKey = "NewYN",
fnKeyValue = null,
fnTitle = "新增",
fnType = "table",
position = "left",
icon = "ghr-icon-add",
display = true
});
//if (toolbars.Any(x => x.fnKey == "NewYN"))
// Toolbar.Add(new Toolbar()
// {
// fnKey = "NewYN",
// fnKeyValue = null,
// fnTitle = "新增",
// fnType = "table",
// position = "left",
// icon = "ghr-icon-add",
// display = true
// });
if (param.menuName == "F_ExamManageDraft")
Toolbar.Add(new Toolbar()
{
@ -270,8 +270,8 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
icon = "ghr-publish",
display = true
});
if (toolbars.Any(x => x.fnKey == "ToExcelYN"))
Toolbar.Add(toolbars.First(x => x.fnKey == "ToExcelYN"));
//if (toolbars.Any(x => x.fnKey == "ToExcelYN"))
// Toolbar.Add(toolbars.First(x => x.fnKey == "ToExcelYN"));
#endregion

@ -1,9 +1,17 @@
using System.Data;
using System.Net;
using AgileObjects.AgileMapper;
using AgileObjects.AgileMapper.Extensions;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.HSSF.UserModel;
using NPOI.OpenXmlFormats.Spreadsheet;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using SharpCompress.Common;
using SqlSugar;
using Tiobon.Core.Common;
using Tiobon.Core.Common.Caches;
@ -15,6 +23,7 @@ using Tiobon.Core.IServices;
using Tiobon.Core.Model;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Services.BASE;
using static Tiobon.Core.DataAccess.ReportHelper;
namespace Tiobon.Core.Services;
@ -1052,9 +1061,103 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
Type entityType = typeof(Ghre_Question);
var fileName = entityType.GetEntityTableName() + ".xlsx";
//physicsPath = physicsPath + path + fileName;
IWorkbook hssfworkbook;
ISheet sheet;
using (FileStream file = new FileStream(physicsPath + path + fileName, FileMode.Open, FileAccess.Read))
{
//hssfworkbook = new HSSFWorkbook(file);
//hssfworkbook = new XSSFWorkbook(file);
hssfworkbook = WorkbookFactory.Create(file);
}
ISheet sheet2 = hssfworkbook.CreateSheet("下拉数据");
var newFileName = Guid.NewGuid() + ".xlsx";
int listColIndex = 0;
string sql = @"select 'Course' field, Id id, CourseNo no, CourseName name from Ghre_Course where IsEnable=1 and Status='Released'";
var dataSourceLists = await Db.Ado.SqlQueryAsync<DataSourceList>(sql);
if (dataSourceLists.Any())
{
var types = new List<string>
{
"单选题",
"多选题",
"判断题",
"填空题",
"简答题",
};
types.ForEach(sheetName =>
{
int sheetIndex = hssfworkbook.GetSheetIndex(sheetName);
if (sheetIndex >= 0)
{
sheet = hssfworkbook.GetSheetAt(sheetIndex);
SetCellDropdownList(sheet, 0, 0, dataSourceLists.Select(x => x.name).ToArray());
}
});
MemoryStream ms;
using (ms = new MemoryStream())
{
hssfworkbook.Write(ms);
ms.Flush();
hssfworkbook.Dispose();
//ms.Position = 0;
//return ms;
}
using (FileStream fs = new FileStream(physicsPath + path + newFileName, FileMode.Create, FileAccess.Write))
{
byte[] data = ms.ToArray();
fs.Write(data, 0, data.Length);
fs.Flush();
}
}
var physicsPath1 = physicsPath + path + fileName;
if (dataSourceLists.Any())
physicsPath1 = physicsPath + path + newFileName;
var result = ServiceResult<string>.OprateSuccess(fileName, physicsPath + path + fileName);
return result;
}
public static void SetCellDropdownList(ISheet sheet, int firstcol, int lastcol, string[] vals)
{
//設置生成下拉框的行和列
var cellRegions = new CellRangeAddressList(1, 65535, firstcol, lastcol);
IDataValidation validation = null;
if (sheet.GetType().Name.Contains("XSSF")) // .xlsx
{
XSSFDataValidationHelper helper = new XSSFDataValidationHelper((XSSFSheet)sheet);//获得一个数据验证Helper
//IDataValidation
validation = helper.CreateValidation(
helper.CreateExplicitListConstraint(vals), cellRegions);//创建约束
}
else // HSSF .xls
{
//設置 下拉框內容
DVConstraint constraint = DVConstraint.CreateExplicitListConstraint(vals);
validation = new HSSFDataValidation(cellRegions, constraint);
/*
HSSFDataValidation dataValidate = new HSSFDataValidation(cellRegions, constraint);
dataValidate.CreateErrorBox("輸入不合法", "請輸入或選擇下拉列表中的值。");
dataValidate.ShowPromptBox = true;
*/
}
validation.CreateErrorBox("输入不合法", "请输入或选择下拉列表中的值。");
validation.ShowPromptBox = true;
sheet.AddValidationData(validation);
}
#endregion
/// <summary>

Loading…
Cancel
Save