去除warn

This commit is contained in:
2023-06-19 16:27:13 +08:00
parent 0b492898af
commit aea9e3a9d5
69 changed files with 512 additions and 483 deletions

View File

@@ -72,7 +72,7 @@ namespace Tnb.PerMgr
sheet.SetColumnWidth(i,15 * 256);
}
int rowIndex = 1;
// int rowIndex = 1;
// var column = sheet.GetColumn(0);
// 设置下拉项
@@ -109,7 +109,7 @@ namespace Tnb.PerMgr
{
int rowIndex = 1;
bool flag = false;
IWorkbook workbook = null;
IWorkbook? workbook = null;
try
{
using (Stream stream = input.file.OpenReadStream())
@@ -121,9 +121,12 @@ namespace Tnb.PerMgr
else if (input.fileName.IndexOf(".xls") > 0)
workbook = new HSSFWorkbook(stream);
ISheet sheet = workbook.GetSheetAt(0);
ISheet? sheet = workbook?.GetSheetAt(0);
if(workbook==null || sheet==null)
throw Oops.Bah("无导入数据");
if (sheet.LastRowNum <= 1)
if (sheet?.LastRowNum <= 1)
throw Oops.Bah("无导入数据");
var db = _repository.AsSugarClient();
@@ -132,12 +135,12 @@ namespace Tnb.PerMgr
int errorColumnIndex = 5;
ICellStyle style = workbook.CreateCellStyle();
IFont font = workbook.CreateFont();
IFont font = workbook.CreateFont();
font.Color = IndexedColors.Red.Index; // 将字体颜色设置为红色
style.SetFont(font);
List<PerProcessStandardsD> list = new List<PerProcessStandardsD>() { };
for (rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++)
for (rowIndex = 1; rowIndex <= sheet?.LastRowNum; rowIndex++)
{
IRow row = sheet.GetRow(rowIndex);
ICell cell0 = row.GetCell(0);
@@ -146,7 +149,7 @@ namespace Tnb.PerMgr
PerProcessStandardsD item = new PerProcessStandardsD();
item.process_standards_id = id;
PerProcessParamType perProcessParamType = perProcessParamTypes.FirstOrDefault(x => x.name == cell0.StringCellValue);
PerProcessParamType? perProcessParamType = perProcessParamTypes.FirstOrDefault(x => x.name == cell0.StringCellValue);
if (perProcessParamType != null)
{
item.process_param_type_id = perProcessParamType.id;
@@ -159,7 +162,7 @@ namespace Tnb.PerMgr
flag = true;
}
PerProcessParam perProcessParam = perProcessParams.FirstOrDefault(x => x.name == cell1.StringCellValue);
PerProcessParam? perProcessParam = perProcessParams.FirstOrDefault(x => x.name == cell1.StringCellValue);
if (perProcessParam != null)
{
item.process_param_id = perProcessParam.id;
@@ -232,7 +235,7 @@ namespace Tnb.PerMgr
{
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
workbook?.Write(ms);
string fileName = $"工艺标准导入报错{DateTime.Now.Ticks}.xlsx";
using (MemoryStream ms2 = new MemoryStream(ms.ToArray()))
{
@@ -278,6 +281,7 @@ namespace Tnb.PerMgr
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}
}