600 lines
28 KiB
C#
600 lines
28 KiB
C#
using Abp.Application.Services;
|
||
using Abp.Application.Services.Dto;
|
||
using Abp.Collections.Extensions;
|
||
using Abp.Domain.Repositories;
|
||
using Microsoft.AspNetCore.Http;
|
||
using MineTec.ProManager.Commd;
|
||
using MineTec.ProManager.FileStore.Dto;
|
||
using MineTec.ProManager.GalleryFiles.Dto;
|
||
using OfficeOpenXml;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using System.Web;
|
||
|
||
namespace MineTec.ProManager.GalleryFiles
|
||
{
|
||
public class GalleryFilesAppService : AsyncCrudAppService<Entitys.Graphic.GalleryFiles.GalleryFiles, GalleryFilesDto, Guid, PagedResultRequestDto,
|
||
CreateUpdateGalleryFilesDto, CreateUpdateGalleryFilesDto>, IGalleryFilesAppService
|
||
|
||
{
|
||
private readonly IRepository<Entitys.Graphic.GalleryFiles.GalleryFiles, Guid> _GalleryFilesRepository;
|
||
private readonly IRepository<Entitys.Public.FileStore.FileStore, Guid> _FileStore;
|
||
private readonly IRepository<Entitys.Project.Project, Guid> _ProjectRepository;
|
||
private readonly IRepository<Entitys.Graphic.MaterialNumber.MaterialNumber, Guid> _MaterialNumberRepository;
|
||
private readonly IRepository<Entitys.Graphic.MarketableNumber.MarketableNumber, Guid> _MarketableNumberRepository;
|
||
private readonly IRepository<Entitys.Graphic.PartNumber.PartNumber, Guid> _PartNumberRepository;
|
||
|
||
|
||
public GalleryFilesAppService(IRepository<Entitys.Graphic.GalleryFiles.GalleryFiles, Guid> repository, IRepository<Entitys.Graphic.GalleryFiles.GalleryFiles, Guid> GalleryFilesRepository, IRepository<Entitys.Public.FileStore.FileStore, Guid> FileStore, IRepository<Entitys.Project.Project, Guid> ProjectRepository, IRepository<Entitys.Graphic.MaterialNumber.MaterialNumber, Guid> MaterialNumberRepository, IRepository<Entitys.Graphic.MarketableNumber.MarketableNumber, Guid> MarketableNumberRepository, IRepository<Entitys.Graphic.PartNumber.PartNumber, Guid> PartNumberRepository)
|
||
: base(repository)
|
||
{
|
||
_GalleryFilesRepository = GalleryFilesRepository;
|
||
_FileStore = FileStore;
|
||
_ProjectRepository = ProjectRepository;
|
||
_MaterialNumberRepository = MaterialNumberRepository;
|
||
_MarketableNumberRepository = MarketableNumberRepository;
|
||
_PartNumberRepository = PartNumberRepository;
|
||
}
|
||
|
||
public OutputBase CreateGalleryFiles(CreateUpdateGalleryFilesDto input)
|
||
{
|
||
var result = new OutputBase();
|
||
try
|
||
{
|
||
var entity = _GalleryFilesRepository.GetAll().Where(a => a.FileNum == input.FileNum && a.IsDelete == 0)
|
||
.WhereIf(!string.IsNullOrEmpty(input.ProjectID), t => t.ProjectID == input.ProjectID).FirstOrDefault();
|
||
if (entity == null)
|
||
{
|
||
_GalleryFilesRepository.InsertAndGetId(ObjectMapper.Map<Entitys.Graphic.GalleryFiles.GalleryFiles>(input));
|
||
//base.CreateAsync(input);
|
||
result.code = 1;//成功
|
||
result.msg = "保存成功!";
|
||
}
|
||
else
|
||
{
|
||
result.code = 2;//重复
|
||
result.msg = "已经存在相同的图纸编号,请修改!";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result.code = 0;//失败
|
||
result.msg = e.Message;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public GalleryFilesOutPut GetAllGalleryFiles(GetAllGalleryFiles input)
|
||
{
|
||
var result = new GalleryFilesOutPut();
|
||
try
|
||
{
|
||
var query = base.CreateFilteredQuery(input).Where(t => t.IsDelete != 1 && t.PatternType != "0" && t.PatternType != "2")
|
||
.WhereIf(!string.IsNullOrEmpty(input.ProjectID), t => t.ProjectID == input.ProjectID)
|
||
.WhereIf(!string.IsNullOrEmpty(input.FileNum), t => t.FileNum.Contains(input.FileNum))
|
||
.WhereIf(!string.IsNullOrEmpty(input.FileName), t => t.FileName.Contains(input.FileName));
|
||
|
||
if (input.DocumentType == "pattern_0" || input.DocumentType == "pattern_2")
|
||
{
|
||
var Type = input.DocumentType.Split('_')[1];
|
||
query = base.CreateFilteredQuery(input).Where(t => t.IsDelete != 1 && t.PatternType == Type)
|
||
.WhereIf(!string.IsNullOrEmpty(input.ProjectID), t => t.ProjectID == input.ProjectID)
|
||
.WhereIf(!string.IsNullOrEmpty(input.FileNum), t => t.FileNum.Contains(input.FileNum))
|
||
.WhereIf(!string.IsNullOrEmpty(input.FileName), t => t.FileName.Contains(input.FileName));
|
||
}
|
||
|
||
var filescount = query.Count();
|
||
var fileslist = query.ToList();
|
||
|
||
foreach (var item in fileslist)
|
||
{
|
||
var annexid = item.annex_id;
|
||
if (annexid != "" && annexid != null)
|
||
{
|
||
Guid annex_id = new Guid(annexid);
|
||
var annexquery = _FileStore.GetAll().FirstOrDefault(a => a.Id == annex_id);
|
||
item.annex_url = "/" + annexquery.absolutepath.Replace('\\', '/') + "/" + annexquery.filename;
|
||
}
|
||
|
||
var cardid = item.card_id;
|
||
if (cardid != "" && cardid != null)
|
||
{
|
||
Guid card_id = new Guid(cardid);
|
||
var cardquery = _FileStore.GetAll().FirstOrDefault(a => a.Id == card_id);
|
||
item.card_url = "/" + cardquery.absolutepath.Replace('\\', '/') + "/" + cardquery.filename;
|
||
}
|
||
|
||
var picid = item.pic_id;
|
||
if (picid != "" && picid != null)
|
||
{
|
||
Guid pic_id = new Guid(picid);
|
||
var picquery = _FileStore.GetAll().FirstOrDefault(a => a.Id == pic_id);
|
||
item.pic_url = "/" + picquery.absolutepath.Replace('\\', '/') + "/" + picquery.filename;
|
||
}
|
||
}
|
||
|
||
var list = ObjectMapper.Map<List<GalleryFilesDto>>(fileslist);
|
||
result.code = 0;
|
||
result.count = filescount;
|
||
result.data = list;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.msg = ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
public OutputBase UpdateGalleryFiles(UpdateGalleryFiles input)
|
||
{
|
||
var result = new OutputBase();
|
||
try
|
||
{
|
||
var query = _GalleryFilesRepository.GetAll().FirstOrDefault(a => a.Id == input.id);
|
||
|
||
query.IsAnnex = input.IsAnnex;
|
||
query.annex_id = input.annex_id;
|
||
|
||
query.IsCard = input.IsCard;
|
||
query.card_id = input.card_id;
|
||
|
||
query.IsPic = input.IsPic;
|
||
query.pic_id = input.pic_id;
|
||
|
||
query.annex_name = input.annex_name;
|
||
query.card_name = input.card_name;
|
||
query.pic_name = input.pic_name;
|
||
|
||
query.UpdateTime = DateTime.Now;
|
||
query.UpdateUserID = input.UpdateUserID;
|
||
query.UpdateUserName = input.UpdateUserName;
|
||
|
||
query.FileName = input.FileName;
|
||
query.SubCode = input.SubCode;
|
||
query.FileNum = input.FileNum;
|
||
query.PictureFrame = input.PictureFrame;
|
||
query.Remark = input.Remark;
|
||
result.code = 1;//1成功0失败
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.code = 0;
|
||
result.msg = ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
public OutputBase UpdateDelStateGalleryFiles(UpdateGalleryFiles input)
|
||
{
|
||
var result = new OutputBase();
|
||
try
|
||
{
|
||
var query = _GalleryFilesRepository.GetAll().FirstOrDefault(a => a.Id == input.id);
|
||
if (input.IsDelete == 1)
|
||
{
|
||
query.IsDelete = 1;
|
||
}
|
||
result.code = 1;//1成功0失败
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.code = 0;
|
||
result.msg = ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
public OutputBase GetGalleryFilesTypeCount(GetAllGalleryFiles input)
|
||
{
|
||
var result = new OutputBase();
|
||
try
|
||
{
|
||
var entity = _GalleryFilesRepository.GetAll().Where(a => a.FileNum.StartsWith(input.FileNum) && a.IsDelete == 0);
|
||
result.count = entity.Count();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result.code = 0;//失败
|
||
result.msg = e.Message;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//单个文件上传
|
||
public async Task<OutputBase> UploadFile(IFormFile file)
|
||
{
|
||
var result = new OutputBase();
|
||
|
||
if (file == null)
|
||
{
|
||
result.code = 0;//获取不到文件
|
||
result.msg = "请先选择文件";
|
||
return result;
|
||
}
|
||
string rootdir = AppContext.BaseDirectory;
|
||
DirectoryInfo Dir = Directory.GetParent(rootdir);
|
||
string root = Dir.Parent.Parent.FullName;//获取当前站点路径
|
||
|
||
|
||
//string webRootPath = @"E:\FileStore\"; //保存文件路径--本地测试
|
||
string webRootPath = @"D:\ProMananger\WebApi\wwwroot"; //保存文件路径--服务器
|
||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));//增加日期文件夹
|
||
string dirPath = Path.Combine(webRootPath, uploadPath);
|
||
//创建路径
|
||
if (!Directory.Exists(dirPath))
|
||
{
|
||
Directory.CreateDirectory(dirPath);
|
||
}
|
||
string fileExt = Path.GetExtension(file.FileName).Trim('.'); //文件扩展名,不含“.”
|
||
string FileName = Path.GetFileName(file.FileName);
|
||
string newFileName = FileName.Split(".")[0] + "_" + DateTime.Now.ToString("yyMMddhhmmss") + "." + fileExt; //生成新的文件名,防止重复
|
||
var filePath = Path.Combine(dirPath, newFileName);
|
||
|
||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||
{
|
||
await file.CopyToAsync(stream);
|
||
}
|
||
//上传完成之后,写入数据库
|
||
var filestorn = new CreateUpdateFileStoreDto();
|
||
filestorn.createtime = DateTime.Now;
|
||
filestorn.ext = fileExt;//文件扩展名,不含“.”
|
||
filestorn.filename = newFileName;
|
||
filestorn.initialpath = webRootPath;
|
||
filestorn.absolutepath = uploadPath;
|
||
filestorn.fullpath = filePath;
|
||
filestorn.isdelete = 0;
|
||
|
||
Guid FileKey = _FileStore.InsertAndGetId(ObjectMapper.Map<Entitys.Public.FileStore.FileStore>(filestorn));
|
||
|
||
result.code = 1;//上传成功
|
||
result.msg = "上传成功";
|
||
result.ReturnID = FileKey;//FileStore主键
|
||
result.Other = newFileName;
|
||
|
||
return result;
|
||
}
|
||
|
||
//多个文件上传
|
||
public async Task<string> UploadFiles(IFormFileCollection files)
|
||
{
|
||
if (files.Count() == 0)
|
||
{
|
||
return "请先选择文件";
|
||
}
|
||
string webRootPath = @"D:\UploadingFiles\"; //保存文件路径
|
||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));//增加日期文件夹
|
||
string dirPath = Path.Combine(webRootPath, uploadPath);
|
||
//创建路径
|
||
if (!Directory.Exists(dirPath))
|
||
{
|
||
Directory.CreateDirectory(dirPath);
|
||
}
|
||
foreach (var file in files)
|
||
{
|
||
|
||
|
||
string fileExt = Path.GetExtension(file.FileName).Trim('.'); //文件扩展名,不含“.”
|
||
string newFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + fileExt; //随机生成新的文件名
|
||
var filePath = Path.Combine(dirPath, newFileName);
|
||
|
||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||
{
|
||
await file.CopyToAsync(stream);
|
||
}
|
||
}
|
||
var url = $@"\{uploadPath}\{dirPath}";
|
||
return url;
|
||
}
|
||
|
||
//导入
|
||
public async Task<OutputBase> Excel(IFormFile file)
|
||
{
|
||
var result = new OutputBase();
|
||
|
||
#region 上传excel文件
|
||
if (file == null)
|
||
{
|
||
result.code = 0;//获取不到文件
|
||
result.msg = "请先选择文件";
|
||
return result;
|
||
}
|
||
string rootdir = AppContext.BaseDirectory;
|
||
DirectoryInfo Dir = Directory.GetParent(rootdir);
|
||
string root = Dir.Parent.Parent.FullName;//获取当前站点路径
|
||
|
||
|
||
//string webRootPath = @"E:\FileStore\"; //保存文件路径--本地测试
|
||
string webRootPath = @"D:\ProMananger\WebApi\wwwroot"; //保存文件路径--服务器
|
||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));//增加日期文件夹
|
||
string dirPath = Path.Combine(webRootPath, uploadPath);
|
||
//创建路径
|
||
if (!Directory.Exists(dirPath))
|
||
{
|
||
Directory.CreateDirectory(dirPath);
|
||
}
|
||
string fileExt = Path.GetExtension(file.FileName).Trim('.'); //文件扩展名,不含“.”
|
||
string FileName = Path.GetFileName(file.FileName);
|
||
string newFileName = FileName.Split(".")[0] + "_" + DateTime.Now.ToString("yyMMddhhmmss") + "." + fileExt; //生成新的文件名,防止重复
|
||
var filePath = Path.Combine(dirPath, newFileName);
|
||
|
||
using (var stream_up = new FileStream(filePath, FileMode.Create))
|
||
{
|
||
await file.CopyToAsync(stream_up);
|
||
}
|
||
//上传完成之后,写入数据库
|
||
var filestorn = new CreateUpdateFileStoreDto();
|
||
filestorn.createtime = DateTime.Now;
|
||
filestorn.ext = fileExt;//文件扩展名,不含“.”
|
||
filestorn.filename = newFileName;
|
||
filestorn.initialpath = webRootPath;
|
||
filestorn.absolutepath = uploadPath;
|
||
filestorn.fullpath = filePath;
|
||
filestorn.isdelete = 0;
|
||
|
||
Guid FileKey = _FileStore.InsertAndGetId(ObjectMapper.Map<Entitys.Public.FileStore.FileStore>(filestorn));
|
||
|
||
#endregion
|
||
|
||
Stream stream = file.OpenReadStream();
|
||
//获取项目信息
|
||
var ProjectQuery = _ProjectRepository.GetAll().Where(t => t.isdelete != 1).OrderByDescending(t => t.createtime);
|
||
var projectlist = ProjectQuery.ToList();
|
||
//特征码5
|
||
var Query_5 = _MaterialNumberRepository.GetAll().Where(t => t.IsDelete != 1).OrderByDescending(t => t.CreateTime);
|
||
var query_5_list = Query_5.ToList();
|
||
//特征码6
|
||
var Query_6 = _MarketableNumberRepository.GetAll().Where(t => t.IsDelete != 1).OrderByDescending(t => t.CreateTime);
|
||
var query_6_list = Query_6.ToList();
|
||
//特征码8
|
||
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 GalleryFilesInfo = _GalleryFilesRepository.GetAll().Where(a => a.IsDelete == 0);
|
||
var GalleryFiles_list = GalleryFilesInfo.ToList();
|
||
|
||
using (var package = new ExcelPackage(stream))
|
||
{
|
||
//许可证,必须添加许可证,否则会报错
|
||
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
|
||
// 获取Exel指定工作簿,"Sheet1"也可以用索引代替
|
||
ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"];
|
||
// 获取数据行数
|
||
int RowNum = worksheet.Dimension.Rows;
|
||
// 待处理数据存储列表
|
||
List<PatternExcelImportDto> ExcelData = new List<PatternExcelImportDto>();
|
||
// 获取每行数据
|
||
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();//填写说明的内容
|
||
//从第2行开始,把每列标题也给赋值进去,方便导出生成数据,后续在校验和导入时,跳过第二行
|
||
int isFalse = 0;
|
||
for (int row = 2; row <= RowNum; row++)
|
||
{
|
||
//类型必须为string类型,防止为null时转换出错,在具体校验时,再进行验证
|
||
string msg = worksheet.Cells[row, 1].Value == null ? "" : worksheet.Cells[row, 1].Value.ToString();//提示信息
|
||
string result_excel = worksheet.Cells[row, 2].Value == null ? "" : worksheet.Cells[row, 2].Value.ToString();//导入结果
|
||
string index = worksheet.Cells[row, 3].Value == null ? "" : worksheet.Cells[row, 3].Value.ToString();//序号
|
||
string importmode = worksheet.Cells[row, 4].Value == null ? "" : worksheet.Cells[row, 4].Value.ToString();//导入模式
|
||
string filenum = worksheet.Cells[row, 5].Value == null ? "" : worksheet.Cells[row, 5].Value.ToString();//图纸编号
|
||
string productmodel = worksheet.Cells[row, 6].Value == null ? "" : worksheet.Cells[row, 6].Value.ToString();//产品型号/系列号
|
||
string patterninfo = worksheet.Cells[row, 7].Value == null ? "" : worksheet.Cells[row, 7].Value.ToString();//图样信息
|
||
string subcode = worksheet.Cells[row, 8].Value == null ? "" : worksheet.Cells[row, 8].Value.ToString();//附加尾号
|
||
string pictureframe = worksheet.Cells[row, 9].Value == null ? "" : worksheet.Cells[row, 9].Value.ToString();//图幅
|
||
string remark = worksheet.Cells[row, 10].Value == null ? "" : worksheet.Cells[row, 10].Value.ToString();//备注
|
||
|
||
|
||
string signaturecode = "";//特征码
|
||
string filename = "";//图样名称
|
||
string projectnum = "";//项目编号
|
||
string patterntype = "";//图样类型
|
||
|
||
|
||
if (row > 2)
|
||
{
|
||
if (importmode == "申请")
|
||
{
|
||
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 (filenum.Split('-')[0].Substring(0, 1) == "5" || filenum.Split('-')[0].Substring(0, 1) == "6" || filenum.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).ToList();
|
||
var ismodel = false;
|
||
for (int i = 0; i < model.Count(); i++)
|
||
{
|
||
if (model[i])
|
||
{
|
||
ismodel = true;
|
||
}
|
||
}
|
||
if (!ismodel)
|
||
{
|
||
msg += "产品型号/系列号不存在,";
|
||
isFalse = 1;
|
||
}
|
||
//项目编号
|
||
var pcode = projectlist.Select(t => t.projectcode == projectnum).ToList();
|
||
var ispcode = false;
|
||
for (int i = 0; i < pcode.Count(); i++)
|
||
{
|
||
if (pcode[i])
|
||
{
|
||
ispcode = true;
|
||
}
|
||
}
|
||
if (!ispcode)
|
||
{
|
||
msg += "项目编号不存在,";
|
||
isFalse = 1;
|
||
}
|
||
//特征码
|
||
if (patterntype == "5")
|
||
{
|
||
var patterntype_5 = query_5_list.Select(t => t.MaterialNum == signaturecode).ToList();
|
||
var ispatterntype_5 = false;
|
||
for (int i = 0; i < patterntype_5.Count(); i++)
|
||
{
|
||
if (patterntype_5[i])
|
||
{
|
||
ispatterntype_5 = true;
|
||
}
|
||
}
|
||
if (!ispatterntype_5)
|
||
{
|
||
msg += "特征码不存在,";
|
||
isFalse = 1;
|
||
}
|
||
}
|
||
else if (patterntype == "6")
|
||
{
|
||
var patterntype_6 = query_6_list.Select(t => t.MarketableNum == signaturecode).ToList();
|
||
var ispatterntype_6 = false;
|
||
for (int i = 0; i < patterntype_6.Count(); i++)
|
||
{
|
||
if (patterntype_6[i])
|
||
{
|
||
ispatterntype_6 = true;
|
||
}
|
||
}
|
||
if (!ispatterntype_6)
|
||
{
|
||
msg += "特征码不存在,";
|
||
isFalse = 1;
|
||
}
|
||
}
|
||
else if (patterntype == "8")
|
||
{
|
||
var patterntype_8 = query_8_list.Select(t => t.PartNum == signaturecode).ToList();
|
||
var ispatterntype_8 = false;
|
||
for (int i = 0; i < patterntype_8.Count(); i++)
|
||
{
|
||
if (patterntype_8[i])
|
||
{
|
||
ispatterntype_8 = true;
|
||
}
|
||
}
|
||
if (!ispatterntype_8)
|
||
{
|
||
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).ToList();
|
||
var isGalleryFiles_check = false;
|
||
for (int i = 0; i < GalleryFiles_check.Count(); i++)
|
||
{
|
||
if (GalleryFiles_check[i])
|
||
{
|
||
isGalleryFiles_check = true;
|
||
}
|
||
}
|
||
if (!isGalleryFiles_check)
|
||
{
|
||
msg += "图纸编号重复,";
|
||
isFalse = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
//校验数据填入对象
|
||
ExcelData.Add(new PatternExcelImportDto
|
||
{
|
||
// 获取每列数据
|
||
msg = msg,//提示信息
|
||
result = result_excel,//导入结果
|
||
index = index,//序号
|
||
importmode = importmode,//导入模式
|
||
filenum = filenum,//图纸编号
|
||
productmodel = productmodel,//产品型号/系列号
|
||
patterninfo = patterninfo,//图样信息
|
||
subcode = subcode,//附加尾号
|
||
pictureframe = pictureframe,//图幅
|
||
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 = createpackage.Workbook.Worksheets.Add("Sheet1");
|
||
createworksheet.Cells.LoadFromCollection(ExcelData, true);
|
||
createpackage.Save(); //Save the workbook.
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
}
|
||
} |