excel导入校验
This commit is contained in:
parent
4646f273b4
commit
bbf23b8be8
@ -28,10 +28,9 @@ namespace MineTec.ProManager.GalleryFiles.Dto
|
|||||||
|
|
||||||
public string pictureframe { get; set; } //图幅
|
public string pictureframe { get; set; } //图幅
|
||||||
|
|
||||||
/// <summary>
|
public string productmodel { get; set; }//产品型号/系列
|
||||||
/// 产品型号/系列
|
|
||||||
/// </summary>
|
public string patterninfo { get; set; }//图样信息
|
||||||
public string productmodel { get; set; }
|
|
||||||
|
|
||||||
public string remark { get; set; } //备注
|
public string remark { get; set; } //备注
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
@ -354,6 +355,9 @@ namespace MineTec.ProManager.GalleryFiles
|
|||||||
//特征码8
|
//特征码8
|
||||||
var Query_8 = _PartNumberRepository.GetAll().Where(t => t.IsDelete != 1 && t.PartMark == 8).OrderByDescending(t => t.CreateTime);
|
var Query_8 = _PartNumberRepository.GetAll().Where(t => t.IsDelete != 1 && t.PartMark == 8).OrderByDescending(t => t.CreateTime);
|
||||||
var query_8_list = Query_8.ToList();
|
var query_8_list = Query_8.ToList();
|
||||||
|
//图号信息
|
||||||
|
var GalleryFilesInfo = _GalleryFilesRepository.GetAll().Where(a => a.IsDelete == 0);
|
||||||
|
var GalleryFiles_list = GalleryFilesInfo.ToList();
|
||||||
|
|
||||||
using (var package = new ExcelPackage(stream))
|
using (var package = new ExcelPackage(stream))
|
||||||
{
|
{
|
||||||
@ -369,6 +373,7 @@ namespace MineTec.ProManager.GalleryFiles
|
|||||||
string explainTitle = worksheet.Cells[1, 1].Value == null ? "" : worksheet.Cells[1, 1].Value.ToString();//第一行第一列,填写说明的标题
|
string explainTitle = worksheet.Cells[1, 1].Value == null ? "" : worksheet.Cells[1, 1].Value.ToString();//第一行第一列,填写说明的标题
|
||||||
string explainText = worksheet.Cells[1, 2].Value == null ? "" : worksheet.Cells[1, 2].Value.ToString();//填写说明的内容
|
string explainText = worksheet.Cells[1, 2].Value == null ? "" : worksheet.Cells[1, 2].Value.ToString();//填写说明的内容
|
||||||
//从第2行开始,把每列标题也给赋值进去,方便导出生成数据,后续在校验和导入时,跳过第二行
|
//从第2行开始,把每列标题也给赋值进去,方便导出生成数据,后续在校验和导入时,跳过第二行
|
||||||
|
int isFalse = 0;
|
||||||
for (int row = 2; row <= RowNum; row++)
|
for (int row = 2; row <= RowNum; row++)
|
||||||
{
|
{
|
||||||
//类型必须为string类型,防止为null时转换出错,在具体校验时,再进行验证
|
//类型必须为string类型,防止为null时转换出错,在具体校验时,再进行验证
|
||||||
@ -383,64 +388,132 @@ namespace MineTec.ProManager.GalleryFiles
|
|||||||
string pictureframe = worksheet.Cells[row, 9].Value == null ? "" : worksheet.Cells[row, 11].Value.ToString();//图幅
|
string pictureframe = worksheet.Cells[row, 9].Value == null ? "" : worksheet.Cells[row, 11].Value.ToString();//图幅
|
||||||
string remark = worksheet.Cells[row, 10].Value == null ? "" : worksheet.Cells[row, 12].Value.ToString();//备注
|
string remark = worksheet.Cells[row, 10].Value == null ? "" : worksheet.Cells[row, 12].Value.ToString();//备注
|
||||||
|
|
||||||
|
|
||||||
string signaturecode = "";//特征码
|
string signaturecode = "";//特征码
|
||||||
string filename = "";//图样名称
|
string filename = "";//图样名称
|
||||||
string projectnum = patterninfo.Split('_')[0].Remove(0, 1);//项目编号
|
string projectnum = "";//项目编号
|
||||||
string patterntype = patterninfo.Split('_')[0].Substring(0, 1);//图样类型
|
string patterntype = "";//图样类型
|
||||||
if (patterninfo.Split('_')[0].Substring(0, 1) == "5" || patterninfo.Split('_')[0].Substring(0, 1) == "6" || patterninfo.Split('_')[0].Substring(0, 1) == "8")
|
|
||||||
{
|
|
||||||
signaturecode = patterninfo.Split('_')[1];
|
|
||||||
filename = patterninfo.Split('_')[2];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
filename = patterninfo.Split('_')[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
//校验
|
|
||||||
//类型是否为02568
|
if (row > 2)
|
||||||
if (patterntype != "0" && patterntype != "2" && patterntype != "5" && patterntype != "6" && patterntype != "8")
|
|
||||||
{
|
{
|
||||||
msg += "图样类型有误,";
|
if (importmode == "申请")
|
||||||
}
|
|
||||||
//项目编号
|
|
||||||
var pcode = projectlist.Select(t => t.projectcode == projectnum);
|
|
||||||
if (pcode == null)
|
|
||||||
{
|
|
||||||
msg += "项目编号不存在,";
|
|
||||||
}
|
|
||||||
//特征码
|
|
||||||
if (patterntype == "5")
|
|
||||||
{
|
|
||||||
var patterntype_5 = query_5_list.Select(t => t.MaterialNum == signaturecode);
|
|
||||||
if (patterntype_5 == null)
|
|
||||||
{
|
{
|
||||||
msg += "特征码不存在,";
|
projectnum = patterninfo.Split('_')[0].Remove(0, 1);
|
||||||
|
patterntype = patterninfo.Split('_')[0].Substring(0, 1);
|
||||||
|
|
||||||
|
if (patterninfo.Split('_')[0].Substring(0, 1) == "5" || patterninfo.Split('_')[0].Substring(0, 1) == "6" || patterninfo.Split('_')[0].Substring(0, 1) == "8")
|
||||||
|
{
|
||||||
|
signaturecode = patterninfo.Split('_')[1];
|
||||||
|
filename = patterninfo.Split('_')[2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filename = patterninfo.Split('_')[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (importmode == "录入")
|
||||||
|
{
|
||||||
|
projectnum = filenum.Split('_')[0].Remove(0, 1);
|
||||||
|
patterntype = filenum.Split('_')[0].Substring(0, 1);
|
||||||
|
|
||||||
|
if (patterninfo.Split('_')[0].Substring(0, 1) == "5" || patterninfo.Split('_')[0].Substring(0, 1) == "6" || patterninfo.Split('_')[0].Substring(0, 1) == "8")
|
||||||
|
{
|
||||||
|
signaturecode = filenum.Split('_')[1];
|
||||||
|
}
|
||||||
|
if (filenum.Contains("~"))
|
||||||
|
{
|
||||||
|
subcode = filenum.Split('~')[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//校验
|
||||||
|
//类型是否为02568
|
||||||
|
if (patterntype != "0" && patterntype != "2" && patterntype != "5" && patterntype != "6" && patterntype != "8")
|
||||||
|
{
|
||||||
|
msg += "图样类型有误,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
//产品型号
|
||||||
|
var model = projectlist.Select(t => t.productmodel == productmodel);
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
msg += "产品型号/系列号不存在,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
//项目编号
|
||||||
|
var pcode = projectlist.Select(t => t.projectcode == projectnum);
|
||||||
|
if (pcode == null)
|
||||||
|
{
|
||||||
|
msg += "项目编号不存在,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
//特征码
|
||||||
|
if (patterntype == "5")
|
||||||
|
{
|
||||||
|
var patterntype_5 = query_5_list.Select(t => t.MaterialNum == signaturecode);
|
||||||
|
if (patterntype_5 == null)
|
||||||
|
{
|
||||||
|
msg += "特征码不存在,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (patterntype == "6")
|
||||||
|
{
|
||||||
|
var patterntype_6 = query_6_list.Select(t => t.MarketableNum == signaturecode);
|
||||||
|
if (patterntype_6 == null)
|
||||||
|
{
|
||||||
|
msg += "特征码不存在,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (patterntype == "8")
|
||||||
|
{
|
||||||
|
var patterntype_8 = query_8_list.Select(t => t.PartNum == signaturecode);
|
||||||
|
if (patterntype_8 == null)
|
||||||
|
{
|
||||||
|
msg += "特征码不存在,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//附加尾号
|
||||||
|
if (subcode != "" && subcode != null)
|
||||||
|
{
|
||||||
|
string pattern = @"^[1-9]\d*$";
|
||||||
|
if (!Regex.IsMatch(subcode, pattern))
|
||||||
|
{
|
||||||
|
msg += "附加尾号有误,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
else if (Convert.ToInt32(subcode) < 1 || Convert.ToInt32(subcode) > 999)
|
||||||
|
{
|
||||||
|
msg += "附加尾号的值超出1-999之间的范围,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//图幅
|
||||||
|
if (pictureframe != "" && pictureframe != null)
|
||||||
|
{
|
||||||
|
if (pictureframe != "A1" && pictureframe != "A2" && pictureframe != "A3" && pictureframe != "A4")
|
||||||
|
{
|
||||||
|
msg += "图幅输入错误,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (importmode == "录入")
|
||||||
|
{
|
||||||
|
|
||||||
|
var GalleryFiles_check = GalleryFiles_list.Select(t => t.FileNum == filenum);
|
||||||
|
if (GalleryFiles_check != null)
|
||||||
|
{
|
||||||
|
msg += "图纸编号重复,";
|
||||||
|
isFalse = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (patterntype == "6")
|
|
||||||
{
|
|
||||||
var patterntype_6 = query_6_list.Select(t => t.MarketableNum == signaturecode);
|
|
||||||
if (patterntype_6 == null)
|
|
||||||
{
|
|
||||||
msg += "特征码不存在,";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (patterntype == "8")
|
|
||||||
{
|
|
||||||
var patterntype_8 = query_8_list.Select(t => t.PartNum == signaturecode);
|
|
||||||
if (patterntype_8 == null)
|
|
||||||
{
|
|
||||||
msg += "特征码不存在,";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//生成序列号
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//校验数据填入对象
|
||||||
ExcelData.Add(new PatternExcelImportDto
|
ExcelData.Add(new PatternExcelImportDto
|
||||||
{
|
{
|
||||||
// 获取每列数据
|
// 获取每列数据
|
||||||
@ -450,19 +523,26 @@ namespace MineTec.ProManager.GalleryFiles
|
|||||||
importmode = importmode,//导入模式
|
importmode = importmode,//导入模式
|
||||||
filenum = filenum,//图纸编号
|
filenum = filenum,//图纸编号
|
||||||
productmodel = productmodel,//产品型号/系列号
|
productmodel = productmodel,//产品型号/系列号
|
||||||
projectnum = patterninfo.Split('_')[0].Remove(0, 1),//项目编号
|
patterninfo = patterninfo,//图样信息
|
||||||
patterntype = patterninfo.Split('_')[0].Substring(0, 1),//图样类型
|
|
||||||
signaturecode = signaturecode,//特征码
|
|
||||||
subcode = subcode,//附加尾号
|
subcode = subcode,//附加尾号
|
||||||
filename = filename,//图样名称
|
|
||||||
pictureframe = pictureframe,//图幅
|
pictureframe = pictureframe,//图幅
|
||||||
remark = remark,//备注
|
remark = remark,//备注
|
||||||
|
|
||||||
|
projectnum = projectnum,//项目编号
|
||||||
|
patterntype = patterntype,//图样类型
|
||||||
|
signaturecode = signaturecode,//特征码
|
||||||
|
filename = filename,//图样名称
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//数据获取完毕,开始校验
|
string sFileName = "校验结果_" + DateTime.Now.ToString("yyMMddhhmmss") + ".xlsx";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var path = Path.Combine(dirPath, sFileName);
|
||||||
|
FileInfo createfile = new FileInfo(path);
|
||||||
|
using ExcelPackage createpackage = new ExcelPackage(createfile);
|
||||||
|
//创建sheet
|
||||||
|
ExcelWorksheet createworksheet = package.Workbook.Worksheets.Add("Sheet1");
|
||||||
|
createworksheet.Cells.LoadFromCollection(ExcelData, true);
|
||||||
|
createpackage.Save(); //Save the workbook.
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
BIN
待处理问题/待处理问题.docx
BIN
待处理问题/待处理问题.docx
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user