using DevExpress.Spreadsheet;
using DeviceRepair.Models;
using DeviceRepair.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DeviceRepairAndOptimization.Biz.PreserveTemplate
{
public class TemplateIndexV2 : TemplateIndexV1
{
private Worksheet worksheet;
///
/// 最大行下标
///
private int LastUsedRowIndex
{
get
{
return worksheet.Rows.LastUsedIndex;
}
}
///
/// 最大列下标
///
private int LastUsedColumnIndex
{
get
{
return worksheet.GetUsedRange().ColumnCount - 1;
}
}
public TemplateIndexV2()
{
DeviceSpecification = new List();
EquipmentID = new List();
Year = new List();
Content = new List();
ExceptionDescription = new List();
Operation = new List();
OperationDate = new List();
}
public TemplateIndexV2(Worksheet ws)
{
DeviceSpecification = new List();
EquipmentID = new List();
Year = new List();
Content = new List();
ExceptionDescription = new List();
Operation = new List();
OperationDate = new List();
worksheet = ws;
try
{
SheetDataItem FrequencyItem = new SheetDataItem();
DeviceSpecification.Add(new SheetDataItem { ColumnIndex = 3, RowIndex = 0 });
EquipmentID.Add(new SheetDataItem { ColumnIndex = 3, RowIndex = 2 });
Cell cell = worksheet.Cells[4, 2];
if (cell.Value.TextValue?.ToString() == "频次")
{
FrequencyItem.RowIndex = 4;
FrequencyItem.ColumnIndex = 2;
}
for (int rowIndex = 5; rowIndex < LastUsedRowIndex; rowIndex++)
{
cell = worksheet.Cells[rowIndex, 2];
if (cell.Value.IsEmpty)
{
if (cell.IsMerged)
{
//获取主单元格位置
int top = (worksheet.Cells[rowIndex, 2].GetMergedRanges()[0]).TopRowIndex;
int left = (worksheet.Cells[rowIndex, 2].GetMergedRanges()[0]).LeftColumnIndex;
if(worksheet.Cells[top, left].Value.TextValue?.Replace("\n", "")?.Trim() == "异常处理备注")
{
ExceptionDescription.Add(new SheetDataItem { ColumnIndex = 3, RowIndex = rowIndex, MaintenanceType = EnumMaintenanceType.None });
continue;
}
}
else
{
continue;
}
}
//string CellValue = cell.Value.TextValue?.Replace("\n", "")?.Trim();
//if (CellValue == "异常处理备注")
//{
// ExceptionDescription.Add(new SheetDataItem { ColumnIndex = 3, RowIndex = rowIndex, MaintenanceType = EnumMaintenanceType.None });
// continue;
//}
string FrequencyType = worksheet.Cells[rowIndex, FrequencyItem.ColumnIndex].Value.TextValue;
EnumMaintenanceType type = EnumMaintenanceTypeHelper.MatchToEnum(FrequencyType);
string FrequencyValue = worksheet.Cells[rowIndex, 2].Value.IsText
? worksheet.Cells[rowIndex, 2].Value.TextValue
: worksheet.Cells[rowIndex, 2].Value.NumericValue + "";
for (int colIndex = 6; colIndex < LastUsedColumnIndex; colIndex++)
{
Content.Add(new SheetDataItem { ColumnIndex = colIndex, RowIndex = rowIndex, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
if (!Operation.Any(x=>x.ColumnIndex == colIndex))
{
Operation.Add(new SheetDataItem { RowIndex = 3, ColumnIndex = colIndex, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
OperationDate.Add(new SheetDataItem { RowIndex = 2, ColumnIndex = colIndex, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
}
}
}
}
catch (Exception ex)
{
throw;
}
}
}
}