156 lines
8.9 KiB
C#
156 lines
8.9 KiB
C#
using DevExpress.Spreadsheet;
|
|
using DeviceRepair.Models;
|
|
using DeviceRepair.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace TsSFCDevice.Client.Launch.PreserveTemplate
|
|
{
|
|
public class TemplateIndexV1 : BaseTemplate
|
|
{
|
|
public TemplateIndexV1() : base()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化对象
|
|
/// </summary>
|
|
/// <param name="ws">Worksheet 控件对象</param>
|
|
/// <param name="CurrentType">当前计划类型</param>
|
|
/// <param name="EditColValue">当前编辑列</param>
|
|
public TemplateIndexV1(Worksheet ws) : base(ws)
|
|
{
|
|
try
|
|
{
|
|
SheetDataItem FrequencyItem = new SheetDataItem();
|
|
for (int rowIndex = 0; rowIndex < LastUsedRowIndex; rowIndex++)
|
|
{
|
|
for (int colIndex = 0; colIndex < LastUsedColumnIndex; colIndex++)
|
|
{
|
|
Cell cell = worksheet.Cells[rowIndex, colIndex];
|
|
|
|
string CellValue = cell.Value.TextValue?.Replace("\n", "")?.Trim();
|
|
if (cell.Value.IsText && CellValue == "设备型号:")
|
|
{
|
|
DeviceSpecification.Add(new SheetDataItem { ColumnIndex = colIndex + 1, RowIndex = rowIndex });
|
|
}
|
|
else if (cell.Value.IsText && CellValue == "设备编号:")
|
|
{
|
|
EquipmentID.Add(new SheetDataItem { ColumnIndex = colIndex + 1, RowIndex = rowIndex });
|
|
|
|
Year.Add(new SheetDataItem { ColumnIndex = colIndex + 2, RowIndex = rowIndex });
|
|
}
|
|
else if (cell.Value.IsText && CellValue == "频次")
|
|
{
|
|
FrequencyItem.RowIndex = cell.RowIndex;
|
|
FrequencyItem.ColumnIndex = cell.ColumnIndex;
|
|
}
|
|
else if (worksheet.Cells[rowIndex, 0].Value.IsText && Regex.IsMatch(worksheet.Cells[rowIndex, 0].Value.TextValue.Replace("\n", "").Trim(), @"^[a-zA-Z][1-9]\d*$") && FrequencyItem.ColumnIndex < colIndex)
|
|
{
|
|
string FrequencyType = worksheet.Cells[rowIndex, FrequencyItem.ColumnIndex].Value.TextValue;
|
|
EnumMaintenanceType type = EnumMaintenanceTypeHelper.MatchToEnum(FrequencyType);
|
|
|
|
string FrequencyValue = worksheet.Cells[FrequencyItem.RowIndex, colIndex].Value.IsText
|
|
? worksheet.Cells[FrequencyItem.RowIndex, colIndex].Value.TextValue
|
|
: worksheet.Cells[FrequencyItem.RowIndex, colIndex].Value.NumericValue + "";
|
|
|
|
//如果首列的内容为 单英文开头+ N*数字结束,则判断为需填写的列
|
|
if (cell.IsMerged)
|
|
{
|
|
//获取主单元格位置
|
|
int top = (worksheet.Cells[rowIndex, colIndex].GetMergedRanges()[0]).TopRowIndex;
|
|
int left = (worksheet.Cells[rowIndex, colIndex].GetMergedRanges()[0]).LeftColumnIndex;
|
|
if (!worksheet.Cells[top, left].Value.IsEmpty)
|
|
continue;
|
|
|
|
if (!Content.Any(f => f.RowIndex == top && f.ColumnIndex == left))
|
|
Content.Add(new SheetDataItem { ColumnIndex = colIndex, RowIndex = rowIndex, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
|
|
}
|
|
else
|
|
{
|
|
Content.Add(new SheetDataItem { ColumnIndex = colIndex, RowIndex = rowIndex, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
|
|
}
|
|
}
|
|
}
|
|
|
|
CellValue FirstColValue = worksheet.Cells[rowIndex, 0].Value;
|
|
if (FirstColValue.IsText && FirstColValue.TextValue.Replace("\n", "").Trim() == "其它异常处理")
|
|
{
|
|
//异常处理信息
|
|
List<CellRange> cells = worksheet.Cells[rowIndex, 1].GetMergedRanges().ToList();
|
|
if (cells != null && cells.Count == 1)
|
|
{
|
|
string FrequencyType = worksheet.Cells[rowIndex - 1, FrequencyItem.ColumnIndex].Value.TextValue;
|
|
EnumMaintenanceType type = EnumMaintenanceTypeHelper.MatchToEnum(FrequencyType);
|
|
|
|
ExceptionDescription.Add(new SheetDataItem { ColumnIndex = 1, RowIndex = rowIndex, MaintenanceType = type });
|
|
|
|
//保养签名
|
|
FirstColValue = worksheet.Cells[rowIndex, cells[0].RightColumnIndex + 1].Value;
|
|
if (FirstColValue.IsText && (FirstColValue.TextValue.Replace("\n", "").Trim() == "保养签名") || FirstColValue.TextValue.Replace("\n", "").Trim() == "保养签字")
|
|
{
|
|
for (int j = cells[0].RightColumnIndex + 1; j < LastUsedColumnIndex - 1; j++)
|
|
{
|
|
string FrequencyValue = worksheet.Cells[FrequencyItem.RowIndex, j + 1].Value.IsText
|
|
? worksheet.Cells[FrequencyItem.RowIndex, j + 1].Value.TextValue
|
|
: worksheet.Cells[FrequencyItem.RowIndex, j + 1].Value.NumericValue + "";
|
|
|
|
if (worksheet.Cells[rowIndex, j + 1].IsMerged)
|
|
{
|
|
//获取主单元格位置
|
|
int top = (worksheet.Cells[rowIndex, j + 1].GetMergedRanges()[0]).TopRowIndex;
|
|
int left = (worksheet.Cells[rowIndex, j + 1].GetMergedRanges()[0]).LeftColumnIndex;
|
|
if (!Operation.Any(x => x.RowIndex == top && x.ColumnIndex == left))
|
|
{
|
|
Operation.Add(new SheetDataItem { RowIndex = rowIndex, ColumnIndex = j + 1, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Operation.Add(new SheetDataItem { RowIndex = rowIndex, ColumnIndex = j + 1, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
|
|
}
|
|
}
|
|
}
|
|
|
|
//保养日期
|
|
FirstColValue = worksheet.Cells[rowIndex + 1, cells[0].RightColumnIndex + 1].Value;
|
|
if (FirstColValue.IsText && FirstColValue.TextValue.Replace("\n", "").Trim() == "保养日期")
|
|
{
|
|
for (int j = cells[0].RightColumnIndex + 1; j < LastUsedColumnIndex - 1; j++)
|
|
{
|
|
string FrequencyValue = worksheet.Cells[FrequencyItem.RowIndex, j + 1].Value.IsText
|
|
? worksheet.Cells[FrequencyItem.RowIndex, j + 1].Value.TextValue
|
|
: worksheet.Cells[FrequencyItem.RowIndex, j + 1].Value.NumericValue + "";
|
|
|
|
if (worksheet.Cells[rowIndex + 1, j + 1].IsMerged)
|
|
{
|
|
//获取主单元格位置
|
|
int top = (worksheet.Cells[rowIndex + 1, j + 1].GetMergedRanges()[0]).TopRowIndex;
|
|
int left = (worksheet.Cells[rowIndex + 1, j + 1].GetMergedRanges()[0]).LeftColumnIndex;
|
|
|
|
if (!OperationDate.Any(x => x.RowIndex == top && x.ColumnIndex == left))
|
|
{
|
|
OperationDate.Add(new SheetDataItem { RowIndex = rowIndex + 1, ColumnIndex = j + 1, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
OperationDate.Add(new SheetDataItem { RowIndex = rowIndex + 1, ColumnIndex = j + 1, MaintenanceType = type, MaintenanceTypeValue = FrequencyValue });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|