2024-10-24 18:01:26 +08:00
|
|
|
|
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>
|
2024-10-26 14:00:04 +08:00
|
|
|
|
public static IEnumerable<ExcelModel> GetWireTerminalMappingTable(string wireModel, string prefix = "")
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
|
|
|
|
CheckAndGetCache();
|
2024-11-08 08:34:20 +08:00
|
|
|
|
return _terminalMappingCache.Where(item => item.WireModelSpecification == wireModel && (item.Prefix == prefix || prefix == ""));
|
2024-11-07 12:14:44 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取线材信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IEnumerable<ExcelModel> GetWireInfo(string wireModel, string prefix = "")
|
|
|
|
|
{
|
|
|
|
|
CheckAndGetCache();
|
|
|
|
|
return _terminalMappingCache.Where(item => item.WireModelSpecification == wireModel && (item.Prefix == prefix || item.Prefix == null));
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
//}
|
|
|
|
|
|
2024-11-02 11:56:50 +08:00
|
|
|
|
public static dynamic GetNumberTube(string tubeModel)
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
|
|
|
|
CheckAndGetCache();
|
2024-11-02 11:56:50 +08:00
|
|
|
|
return _terminalMappingCache.Where(item => item.TubeModel == tubeModel)
|
2024-10-26 10:27:03 +08:00
|
|
|
|
.Select(item => new
|
|
|
|
|
{
|
|
|
|
|
item.TubeModel,
|
|
|
|
|
item.TubeMaterialCode,
|
|
|
|
|
})
|
2024-10-24 18:01:26 +08:00
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|