Browse Source

导入功能 下载模板 添加sheet(数据字典、数据源数据)

金隅分支
zhangli 3 years ago
parent
commit
884211058b
4 changed files with 83 additions and 11 deletions
  1. +43
    -10
      Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LR_SystemModule/Controllers/ExcelImportController.cs
  2. +3
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Excel/ExcelConfig.cs
  3. +28
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Excel/ExcelHelper.cs
  4. +9
    -1
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Excel/Model/ColumnModel.cs

+ 43
- 10
Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LR_SystemModule/Controllers/ExcelImportController.cs View File

@@ -6,6 +6,7 @@ using System.Data;
using Learun.Application.Base.SystemModule;
using System;
using System.Drawing;
using System.Linq;

namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
{
@@ -20,6 +21,8 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
{
private ExcelImportIBLL excelImportIBLL = new ExcelImportBLL();
private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
private DataItemIBLL dataItemIBLL = new DataItemBLL();
private DataSourceIBLL dataSourceIBLL = new DataSourceBLL();
#region 视图功能
/// <summary>
/// 导入模板管理页面
@@ -177,8 +180,12 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
excelconfig.FileName = Server.UrlDecode(templateInfo.F_Name) + ".xls";
excelconfig.IsAllSizeColumn = true;
excelconfig.ColumnEntity = new List<ColumnModel>();
excelconfig.SpecialColumnEntity = new List<SpecialColumnModel>();
//表头
DataTable dt = new DataTable();

//数据字典
var dataItemList = dataItemIBLL.GetAllDetailList();
foreach (var col in fileds)
{
if (col.F_RelationType != 1 && col.F_RelationType != 4 && col.F_RelationType != 5 && col.F_RelationType != 6 && col.F_RelationType != 7)
@@ -191,9 +198,35 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
Background = col.F_IsMandatory == true ? Color.Red : new Color()
});
dt.Columns.Add(col.F_Name, typeof(string));

//数据字典
if (col.F_RelationType == 2)
{
excelconfig.SpecialColumnEntity.Add(new SpecialColumnModel()
{
Name = col.F_ColName,
ValueList = dataItemList.Where(x => x.F_ItemCode == col.F_DataItemCode).Select(x => x.F_ItemName).ToList()
});
}
else if (col.F_RelationType == 3)
{
//数据源
var colDatasourceAry = col.F_DataSourceId.Split(',');
var datasourceDt = dataSourceIBLL.GetDataTable($"{colDatasourceAry[0]}", "");
List<string> list = (from d in datasourceDt.AsEnumerable() select d.Field<string>($"{colDatasourceAry[1]}")).ToList();
excelconfig.SpecialColumnEntity.Add(new SpecialColumnModel()
{
Name = col.F_ColName,
ValueList = list
});

}
}
}

ExcelHelper.ExcelDownload(dt, excelconfig);
dataItemList = null;
}

/// <summary>
@@ -206,10 +239,10 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
/// <returns></returns>
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ExecuteImportExcel(string templateId, string fileId, int chunks,string ext)
public ActionResult ExecuteImportExcel(string templateId, string fileId, int chunks, string ext)
{
UserInfo userInfo = LoginUserInfo.Get();
string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "."+ ext, chunks, userInfo);
string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
if (!string.IsNullOrEmpty(path))
{
DataTable dt = ExcelHelper.ExcelImport(path);
@@ -236,14 +269,14 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
/// <returns></returns>
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ExecuteImportSaralExcel(string fileId, int chunks,string ext)
public ActionResult ExecuteImportSaralExcel(string fileId, int chunks, string ext)
{
UserInfo userInfo = LoginUserInfo.Get();
string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "."+ ext, chunks, userInfo);
string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
if (!string.IsNullOrEmpty(path))
{
DataTable dt = ExcelHelper.ExcelImport(path);
string res = excelImportIBLL.ImportSalaryInfo(dt,fileId);
string res = excelImportIBLL.ImportSalaryInfo(dt, fileId);
var data = new
{
Success = res.Split('|')[0],
@@ -266,14 +299,14 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
/// <returns></returns>
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EmpInfoImport(string fileId, int chunks,string ext)
public ActionResult EmpInfoImport(string fileId, int chunks, string ext)
{
UserInfo userInfo = LoginUserInfo.Get();
string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "."+ ext, chunks, userInfo);
string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
if (!string.IsNullOrEmpty(path))
{
DataTable dt = ExcelHelper.ExcelImport(path);
string res = excelImportIBLL.EmpInfoImport(dt,fileId);
string res = excelImportIBLL.EmpInfoImport(dt, fileId);
var data = new
{
Success = res.Split('|')[0],
@@ -294,7 +327,7 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
/// <returns></returns>
[HttpPost]
[ValidateAntiForgeryToken]
public void DownImportErrorFile(string fileId,string fileName)
public void DownImportErrorFile(string fileId, string fileName)
{
//设置导出格式
ExcelConfig excelconfig = new ExcelConfig();
@@ -325,7 +358,7 @@ namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
});
}

}
ExcelHelper.ExcelDownload(dt, excelconfig);
}


+ 3
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Excel/ExcelConfig.cs View File

@@ -121,5 +121,8 @@ namespace Learun.Util
/// </summary>
public List<ColumnModel> ColumnEntity { get; set; }

//特殊列处理(数据字典、数据源)
public List<SpecialColumnModel> SpecialColumnEntity { get; set; }

}
}

+ 28
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Excel/ExcelHelper.cs View File

@@ -404,6 +404,34 @@ namespace Learun.Util
#endregion
rowIndex++;
}

foreach (var entity in excelConfig.SpecialColumnEntity)
{
sheet = workbook.CreateSheet(entity.Name);
rowIndex = 0;
#region 列头及样式
{
IRow headerRow = sheet.CreateRow(rowIndex);
headerRow.CreateCell(0).SetCellValue("");
headerRow.GetCell(0).CellStyle = cHeadStyle;
//设置列宽
sheet.SetColumnWidth(0, (arrColWidth[0] + 1) * 256);
}
#endregion

#region 填充内容
foreach (var value in entity.ValueList)
{
rowIndex++;
IRow dataRow = sheet.CreateRow(rowIndex);
ICell newCell = dataRow.CreateCell(0);
newCell.CellStyle = arryColumStyle[0];
string drValue = value;
SetCell(newCell, dateStyle, typeof(string), drValue);
}
#endregion
}
using (MemoryStream ms = new MemoryStream())
{
workbook.Write(ms);


+ 9
- 1
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Excel/Model/ColumnModel.cs View File

@@ -1,4 +1,5 @@
using System.Drawing;
using System.Collections.Generic;
using System.Drawing;

namespace Learun.Util
{
@@ -51,4 +52,11 @@ namespace Learun.Util
/// </summary>
public string Alignment { get; set; }
}


public class SpecialColumnModel
{
public string Name { get; set; }
public List<string> ValueList { get; set; }
}
}

Loading…
Cancel
Save