ImportMethod_ProcessRoute.cs
6.98 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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里面的 base_process_route_head 】 是数据库表名 ,方法名没有特殊要求 ,注意不要删除sysDicDtSource里面的key
[Action("base_process_route_head")]
public Response BaseProcessRouteHeadMethod(Dictionary<string, SysDtAllCls> sysDicDtSource, dynamic user, DateTime nowTime)
{
#region init
var response = new Response();
//【修改项1】
var excelFileNameKeys = ExcelName.base_process_route_head.ToString();
response = ImportOhter.ImportMethodBefore(sysDicDtSource, response, excelFileNameKeys);
if (response.Code != 200)
{
response.Message = $"【{TableName.excelFileNameBaseProcessRouteHead}】" + response.Message;
return response;
}
//公共方法数据源,需要判断的数据源单独建一个
DataTable excelDtSourceDt = response.Result.data;
DataTable titleVerifySourceDt = response.Result.title;
#endregion
#region 创建dt、添加保存到数据库的dicDtSource 【修改项2】
var tableName = TableName.tableNameBaseProcessRouteHead;
var eqSaveDt = GetTableStructure(tableName);
if (eqSaveDt.Columns.Contains("Id")) eqSaveDt.Columns.Remove("Id");
var temp = new SysDtAllCls()
{
dtData = eqSaveDt
};
var dtSourceNameKey = tableName + TableName.tableSuffix;
sysDicDtSource.Add(dtSourceNameKey, temp);
#endregion
#region 去重 【修改项3 根据实际业务】
var tempExcelDtSourceDt = excelDtSourceDt.Distinct("processCode");
#endregion
///////////////////////////////////////////////////////////////////
#region 工艺路线明细
#region init
var response2 = new Response();
//【修改项1】
var excelFileNameKeys2 = ExcelName.base_process_route_detail.ToString();
response2 = ImportOhter.ImportMethodBefore(sysDicDtSource, response2, excelFileNameKeys2);
if (response2.Code != 200)
{
response2.Message = $"【{TableName.excelFileNameBaseProcessRouteDetail}】" + response2.Message;
return response2;
}
//公共方法数据源,需要判断的数据源单独建一个
DataTable excelDtSourceDt2 = response2.Result.data;
DataTable titleVerifySourceDt2 = response2.Result.title;
#endregion
#region 创建dt、添加保存到数据库的dicDtSource 【修改项2】
var tableName2 = TableName.tableNameBaseProcessRouteDetail;
var eqSaveDt2 = GetTableStructure(tableName2);
if (eqSaveDt2.Columns.Contains("Id")) eqSaveDt2.Columns.Remove("Id");
var temp2 = new SysDtAllCls()
{
dtData = eqSaveDt2
};
var dtSourceNameKey2 = tableName2 + TableName.tableSuffix;
sysDicDtSource.Add(dtSourceNameKey2, temp2);
#endregion
#region 去重 【修改项3 根据实际业务】
var tempExcelDtSourceDt_detail = excelDtSourceDt2.Distinct("oprSequenceCode");
#endregion
#endregion
#region 赋值 理论上是通用的,修改excel文件名 【修改项4】
var columns = tempExcelDtSourceDt.Columns;
var detail_columns = tempExcelDtSourceDt_detail.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.excelFileNameBaseProcessRouteHead);
if (response.Code != 200) return response;
colNameVal = ImportOhter.SetDataTableData(colNameVal, eqSaveDt.Columns[colName].DataType.Name);
dr[colName] = colNameVal;
if (colName == "productCode") productCodes = colNameVal;
}
dr["keys"] = Guid.NewGuid().ToString();
dr["createBy"] = user.Account;
dr["createTime"] = nowTime;
dr["productCode"] = "";
dr["productHeaderCode"] = "";
eqSaveDt.Rows.Add(dr);
//明细表赋值
for (int j = 0; j < tempExcelDtSourceDt_detail.Rows.Count; j++)
{
var dr2 = eqSaveDt2.NewRow();
for (int c = 0; c < detail_columns.Count; c++)
{
var colName = detail_columns[c].ColumnName;
dynamic colNameVal = tempExcelDtSourceDt_detail.Rows[j][colName].ToString();
response2 = ImportOhter.SetDataTableDataBefore(response2, j, colName, colNameVal, titleVerifySourceDt2, TableName.excelFileNameBaseProcessRouteDetail);
if (response2.Code != 200) return response2;
colNameVal = ImportOhter.SetDataTableData(colNameVal, eqSaveDt2.Columns[colName].DataType.Name);
dr2[colName] = colNameVal;
}
dr2["headkeys"] = dr["keys"];
dr2["bodyKeys"] = Guid.NewGuid().ToString();
dr2["createBy"] = user.Account;
dr2["createTime"] = nowTime;
eqSaveDt2.Rows.Add(dr2);
}
}
#endregion
#region 逻辑判断
#endregion
response = SaveBaseProcessRouteAfter(sysDicDtSource, user);//有关联的一系列表赋值
return response;
}
#endregion
#region Save BaseProcessRoute Success After
/// <summary>
/// 工艺路线表保存之后
/// </summary>
/// <param name="baseProcessRoute"></param>
public Response SaveBaseProcessRouteAfter(Dictionary<string, SysDtAllCls> sysDicDtSource, dynamic sysWebUser)
{
Response response = new Response();
return response;
}
#endregion
}
}