|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
|
using NPOI.SS.Util; |
|
|
|
|
using static Tiobon.Core.DataAccess.ReportHelper; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
@ -398,6 +400,51 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr |
|
|
|
|
|
|
|
|
|
var newFileName = Guid.NewGuid() + ".xlsx"; |
|
|
|
|
int listColIndex = 0; |
|
|
|
|
var items = await GetParaList("TrainingCategory"); |
|
|
|
|
var depts = await Db.Queryable<Ghro_Dept>().Select(x => new |
|
|
|
|
{ |
|
|
|
|
x.DeptID, |
|
|
|
|
x.DeptName |
|
|
|
|
}).ToListAsync(); |
|
|
|
|
|
|
|
|
|
//var courses = await Db.Queryable<Ghre_Course>().Select(x => new |
|
|
|
|
//{ |
|
|
|
|
// x.Id, |
|
|
|
|
// x.CourseName |
|
|
|
|
//}).ToListAsync(); |
|
|
|
|
|
|
|
|
|
var schools = await Db.Queryable<Ghre_School>().Select(x => new |
|
|
|
|
{ |
|
|
|
|
x.Id, |
|
|
|
|
x.SchoolName |
|
|
|
|
}).ToListAsync(); |
|
|
|
|
|
|
|
|
|
int sheetIndex = hssfworkbook.GetSheetIndex("培训计划"); |
|
|
|
|
if (sheetIndex >= 0) |
|
|
|
|
{ |
|
|
|
|
sheet = hssfworkbook.GetSheetAt(sheetIndex); |
|
|
|
|
|
|
|
|
|
//设置数据源的值 |
|
|
|
|
IDataValidationConstraint dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(items.Select(x => x.ParaDetailName).ToArray()); |
|
|
|
|
//设置编辑的区域 |
|
|
|
|
IDataValidation dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 2, 2)); |
|
|
|
|
sheet.AddValidationData(dataValidation1); |
|
|
|
|
|
|
|
|
|
dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(depts.Select(x => x.DeptName).ToArray()); |
|
|
|
|
//设置编辑的区域 |
|
|
|
|
dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 1, 1)); |
|
|
|
|
sheet.AddValidationData(dataValidation1); |
|
|
|
|
|
|
|
|
|
//dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(courses.Select(x => x.CourseName).ToArray()); |
|
|
|
|
////设置编辑的区域 |
|
|
|
|
//dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 3, 3)); |
|
|
|
|
//sheet.AddValidationData(dataValidation1); |
|
|
|
|
|
|
|
|
|
dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(schools.Select(x => x.SchoolName).ToArray()); |
|
|
|
|
//设置编辑的区域 |
|
|
|
|
dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 5, 5)); |
|
|
|
|
sheet.AddValidationData(dataValidation1); |
|
|
|
|
} |
|
|
|
|
//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()) |
|
|
|
@ -418,25 +465,23 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// }); |
|
|
|
|
// 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(); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
//} |
|
|
|
|
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; |
|
|
|
|
var physicsPath1 = physicsPath + path + newFileName; |
|
|
|
|
if (menuName == "F_TrainPlan_Temporary") |
|
|
|
|
return ServiceResult<string>.OprateSuccess("计划暂存_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); |
|
|
|
|
else |
|
|
|
|