|
@@ -267,13 +267,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
// 检查 Excel 中是否存在重复项
|
|
|
StringBuilder checkExcelMsg = new StringBuilder();
|
|
|
- var importRepeatGuid = dtImport.AsEnumerable().GroupBy(x => x["内码"]).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
|
|
|
var importRepeatNames = dtImport.AsEnumerable().GroupBy(x => x["材料名称*"]).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
|
|
|
- if (importRepeatGuid.Any())
|
|
|
- {
|
|
|
- string guids = string.Join("、", importRepeatGuid);
|
|
|
- checkExcelMsg.AppendLine($"内码:[{guids}]");
|
|
|
- }
|
|
|
if (importRepeatNames.Any())
|
|
|
{
|
|
|
string names = string.Join("、", importRepeatNames);
|
|
@@ -293,9 +287,6 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
int importCount = 0;
|
|
|
foreach (DataRow dr in dtImport.Rows)
|
|
|
{
|
|
|
- // 跳过系统中已存在的行:直接跳过,不提示
|
|
|
- if (mateGuids.Contains(dr["内码"].ToString())) { continue; }
|
|
|
-
|
|
|
// 跳过系统中已经存在的材料名称:提示用户 Excel 中哪几行的材料名称已存在,不导入
|
|
|
if (mateNames.Contains(dr["材料名称*"].ToString()))
|
|
|
{
|
|
@@ -305,7 +296,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
|
|
|
// 跳过必录项为空的行:提示用户 Excel 中哪几行的必录项为空,检查数据后重新导入
|
|
|
- if (string.IsNullOrWhiteSpace(dr["内码"].ToString()) || string.IsNullOrWhiteSpace(dr["材料名称*"].ToString()) || string.IsNullOrWhiteSpace(dr["品种代码*"].ToString()) || string.IsNullOrWhiteSpace(dr["材料类型代码*"].ToString()) || string.IsNullOrWhiteSpace(dr["材料规格*"].ToString()) || string.IsNullOrWhiteSpace(dr["计量单位*"].ToString()))
|
|
|
+ if (string.IsNullOrWhiteSpace(dr["材料名称*"].ToString()) || string.IsNullOrWhiteSpace(dr["品种代码*"].ToString()) || string.IsNullOrWhiteSpace(dr["材料类型代码*"].ToString()) || string.IsNullOrWhiteSpace(dr["材料规格*"].ToString()) || string.IsNullOrWhiteSpace(dr["计量单位*"].ToString()))
|
|
|
{
|
|
|
// 拼接行号
|
|
|
importNullMsg.Append($"第 [{dtImport.Rows.IndexOf(dr) + 1}] 行、");
|
|
@@ -482,7 +473,6 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
{
|
|
|
// 创建 DataTable
|
|
|
DataTable dtMate = new DataTable();
|
|
|
- dtMate.Columns.Add("内码", typeof(string));
|
|
|
dtMate.Columns.Add("材料名称*", typeof(string));
|
|
|
dtMate.Columns.Add("品种代码*", typeof(string));
|
|
|
dtMate.Columns.Add("材料类型代码*", typeof(string));
|
|
@@ -496,7 +486,6 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
foreach (var mate in Materials)
|
|
|
{
|
|
|
DataRow dr = dtMate.NewRow();
|
|
|
- dr["内码"] = mate.Guid;
|
|
|
dr["材料名称*"] = mate.Name;
|
|
|
dr["品种代码*"] = mate.VarietyCode;
|
|
|
dr["材料类型代码*"] = mate.CategoryCode;
|
|
@@ -511,7 +500,9 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
return dtMate;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 导入的行转换为数据库实体类型
|
|
|
+ /// </summary>
|
|
|
private Material ConvertToEntity(DataRow dr)
|
|
|
{
|
|
|
Material material = new Material();
|