ColumnMapping.cs
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using NPOI.HPSF;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HH.Data.Excel.ColumnMapConfig
{
/// <summary>
/// 字段映射定义
/// </summary>
public class ColumnMapping
{
/// <summary>
/// IP地址表 excel 文件配置 对应的实体类名称
/// </summary>
public static readonly Dictionary<string, string> ColumnMapIpExcel = new()
{
["类型"] = "equipmentTypeId",
["IP地址"] = "iP",
["区域"] = "destinationArea",
["设备名称"] = "name",
["文件名称"] = "fileName",
};
// 2. 转换规则注册表
public static readonly Dictionary<string, Func<object, object>> ValueConverters = new()
{
["equipmentTypeId"] = v => GenderConverter(v.ToString()),
};
// 3. 具体转换方法实现
private static object GenderConverter(string value)
{
value = value.Trim();
if (Program._mainWindow == null) throw new ArgumentException("_mainWindow未初始化!");
if (Program._mainWindow.EqTypeDataSource == null) throw new ArgumentException("设备类型的数据源值[EqTypeDataSource]为空!");
//输送线类型返回 Program._mainWindow._eventHandlers.ccTypeId
if (value == Program._mainWindow._eventHandlers.ccTypeCode)
{
return Program._mainWindow._eventHandlers.ccTypeId;
}
//只会有一个
var currentKeyList = Program._mainWindow.EqTypeDataSource.Where(x => x.Value == value).ToList();
if (currentKeyList.Count == 0)
{
throw new ArgumentException($"IP地址表.xlsx文件,列【类型】的值【{value}】设备类型解析转换失败,不存在于设备类型所选的复选框值!");
}
return currentKeyList[0].Key;
}
/// <summary>
/// 输送线 excel文件配置 对应的实体类名称
/// </summary>
public static readonly Dictionary<string, string> ColumnMapCC = new()
{
["变量名称"] = "Code",
["Name"] = "Name",
["PropType"] = "PropType",
["MonitorCompareValue"] = "MonitorCompareValue",
["数据类型"] = "DataType",
["DB块编号"] = "Address",
["注释"] = "MonitorFailure",
["Created"] = "Created",
["CreatedBy"] = "CreatedBy",
};
/// <summary>
/// Display和输送线状态地址 excel文件配置 对应的实体类名称
/// </summary>
public static readonly Dictionary<string, string> ColumnMapDisplayAndLineCC = new()
{
["Code"] = "Code",
["Name"] = "Name",
["DataType"] = "DataType",
["Address"] = "Address",
["PropType"] = "PropType",
["Created"] = "Created",
["CreatedBy"] = "CreatedBy",
};
}
}