94 lines
3.3 KiB
C#
94 lines
3.3 KiB
C#
using MiniExcelLibs;
|
|
using MiniExcelLibs.OpenXml;
|
|
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
|
|
{
|
|
public class ExcelHelper
|
|
{
|
|
private static IEnumerable<ExcelModel> _terminalMappingCache = [];
|
|
/// <summary>
|
|
/// 线材端子对照表
|
|
/// </summary>
|
|
public static IEnumerable<ExcelModel> GetWireTerminalMappingTable(string wireModel)
|
|
{
|
|
CheckAndGetCache();
|
|
return _terminalMappingCache.Where(item => item.WireModelSpecification == wireModel);
|
|
}
|
|
|
|
private static void CheckAndGetCache()
|
|
{
|
|
lock (_terminalMappingCache)
|
|
{
|
|
if (_terminalMappingCache == null || !_terminalMappingCache.Any())
|
|
{
|
|
GetAllWireTerminalMappingTable();
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void GetAllWireTerminalMappingTable()
|
|
{
|
|
var config = new OpenXmlConfiguration()
|
|
{
|
|
FillMergedCells = true
|
|
};
|
|
var path = Path.Combine(Consts.DATA_FILE_PATH, Consts.DATA_FILE_PATH_WIRE_TERMINAL);
|
|
var result = MiniExcel.Query<ExcelModel>(path, configuration: config)
|
|
//.Where(item => item.WireModelSpecification == wireModel)
|
|
.ToList();
|
|
_terminalMappingCache = result;
|
|
}
|
|
/// <summary>
|
|
/// 绝缘软套
|
|
/// </summary>
|
|
public static IEnumerable<InsulationModel> GetInsulationSoftSleeveTable(string wireModel)
|
|
{
|
|
var path = Path.Combine(Consts.DATA_FILE_PATH, Consts.DATA_FILE_PATH_INSULATION);
|
|
var results = MiniExcel.Query<InsulationModel>(path);
|
|
//.Where(item => item.Specification == wireModel)
|
|
//.ToList();
|
|
return results.Where(item => item.Specification == wireModel);
|
|
}
|
|
|
|
//public static List<IDictionary<string, object>> GetWireTerminalMappingTable()
|
|
//{
|
|
// var config = new OpenXmlConfiguration()
|
|
// {
|
|
// FillMergedCells = true
|
|
// };
|
|
// return MiniExcel.Query("D:\\Desktop\\123\\线材端子号码管配对表(配CE端子)2024-10-18.xlsm", useHeaderRow: true, configuration: config)
|
|
// //.Where(item => item.WireModelSpecification == wireModel)
|
|
// .Cast<IDictionary<string, object>>()
|
|
// .ToList();
|
|
//}
|
|
|
|
public static dynamic GetNumberTube(string wireModel)
|
|
{
|
|
CheckAndGetCache();
|
|
return _terminalMappingCache.Where(item => item.WireModelSpecification == wireModel)
|
|
.Select(item => new
|
|
{
|
|
item.TubeModel,
|
|
item.TubeMaterialCode,
|
|
})
|
|
.FirstOrDefault();
|
|
}
|
|
public static void SaveByTemplate(object data, string newFilePath)
|
|
{
|
|
var config = new OpenXmlConfiguration()
|
|
{
|
|
IgnoreTemplateParameterMissing = true,
|
|
};
|
|
var path = Path.Combine(Consts.DATA_FILE_PATH, Consts.TEMPLATE_FILE_NAME);
|
|
MiniExcel.SaveAsByTemplate(newFilePath, path, new
|
|
{
|
|
items = data
|
|
}, configuration: config);
|
|
}
|
|
}
|
|
}
|