ImportMethod_Equipment.cs
3.26 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
using Hh.Mes.POJO.Response;
using System;
using System.Collections.Generic;
using System.Data;
using static Hh.Mes.Common.Exel.NpoiExcelImportHelper;
namespace Hh.Mes.Service.WebService.Planned
{
/// <summary>
/// 定义导入方法加上特性
/// dicDtSource 添加需要保存到数据源的数据源
/// 注意:只改对应业务的dt 数据【公共方法里面的读取的数据源不要修改、其他地方可能需要用到】
/// </summary>
public partial class ImportMethod
{
#region 设备管理 【Action里面的 equipment 】 是数据库表名 ,方法名没有特殊要求 ,注意不要删除sysDicDtSource里面的key
[Action("equipment")]
public Response EquipmentMethod(Dictionary<string, SysDtAllCls> sysDicDtSource, dynamic user, DateTime nowTime)
{
#region init
var response = new Response();
//【修改项1】
var excelFileNameKeys = ExcelName.equipment.ToString();
response = ImportOhter.ImportMethodBefore(sysDicDtSource, response, excelFileNameKeys);
if (response.Code != 200)
{
response.Message = $"【{TableName.excelFileNameEquipment}】" + response.Message;
return response;
}
//公共方法数据源,需要判断的数据源单独建一个
DataTable excelDtSourceDt = response.Result.data;
DataTable titleVerifySourceDt = response.Result.title;
#endregion
#region 创建dt、添加保存到数据库的dicDtSource 【修改项2】
var tableName = TableName.tableNameEquipment;
var eqSaveDt = GetTableStructure(tableName);
var temp = new SysDtAllCls()
{
dtData = eqSaveDt
};
var dtSourceNameKey = tableName + TableName.tableSuffix;
sysDicDtSource.Add(dtSourceNameKey, temp);
#endregion
#region 去重 【修改项3 根据实际业务】
var tempExcelDtSourceDt = excelDtSourceDt.Distinct("Code");
#endregion
#region 赋值 理论上是通用的,修改excel文件名 【修改项4】
var columns = tempExcelDtSourceDt.Columns;
for (int i = 0; i < tempExcelDtSourceDt.Rows.Count; i++)
{
var dr = eqSaveDt.NewRow();
for (int c = 0; c < columns.Count; c++)
{
var colName = columns[c].ColumnName;
dynamic colNameVal = tempExcelDtSourceDt.Rows[i][colName].ToString();
response = ImportOhter.SetDataTableDataBefore(response, i, colName, colNameVal, titleVerifySourceDt, TableName.excelFileNameEquipment);
if (response.Code != 200) return response;
colNameVal = ImportOhter.SetDataTableData(colNameVal, eqSaveDt.Columns[colName].DataType.Name);
dr[colName] = colNameVal;
}
dr["CreatedBy"] = user.Account;
dr["Created"] = nowTime;
eqSaveDt.Rows.Add(dr);
}
#endregion
#region 逻辑判断
#endregion
return response;
}
#endregion
}
}