195 lines
6.8 KiB
C#
195 lines
6.8 KiB
C#
using ComputerShopBusinessLogic.OfficePackage.HelperEnums;
|
|
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ComputerShopBusinessLogic.OfficePackage
|
|
{
|
|
public abstract class AbstractSaveToExcelImplementer
|
|
{
|
|
public void CreateReport(ExcelInfoImplementer info)
|
|
{
|
|
CreateExcel(info);
|
|
|
|
//!!!2 абзаца ниже - настройка заголовков, исправить скорее всего
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "A",
|
|
RowIndex = 1,
|
|
Text = info.Title1,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
//MergeCells(new ExcelMergeParameters
|
|
//{
|
|
// CellFromName = "A1",
|
|
// CellToName = "C1"
|
|
//});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "B",
|
|
RowIndex = 1,
|
|
Text = info.Title2,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "C",
|
|
RowIndex = 1,
|
|
Text = info.Title3,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "D",
|
|
RowIndex = 1,
|
|
Text = info.Title4,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "E",
|
|
RowIndex = 1,
|
|
Text = info.Title5,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "F",
|
|
RowIndex = 1,
|
|
Text = info.Title6,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "G",
|
|
RowIndex = 1,
|
|
Text = info.Title7,
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
});
|
|
|
|
uint rowIndex = 2;
|
|
foreach (var orderAs in info.OrderAssemblies)
|
|
{
|
|
int cnt_of_assemblies = orderAs.Assemblies.Count;
|
|
int assemblyIndex = 0;
|
|
foreach (var assembly in orderAs.Assemblies)
|
|
{
|
|
if (!string.IsNullOrEmpty(assembly.AssemblyName) && !string.IsNullOrEmpty(assembly.AssemblyCategory) && assembly.AssemblyPrice != 0)
|
|
{
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "A",
|
|
RowIndex = rowIndex,
|
|
Text = orderAs.OrderId.ToString(),
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "B",
|
|
RowIndex = rowIndex,
|
|
Text = orderAs.DateCreateOrder.ToShortDateString(),
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "C",
|
|
RowIndex = rowIndex,
|
|
Text = orderAs.OrderSum.ToString(),
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "D",
|
|
RowIndex = rowIndex,
|
|
Text = orderAs.OrderStatus.ToString(),
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "E",
|
|
RowIndex = rowIndex,
|
|
Text = assembly.AssemblyName,
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "F",
|
|
RowIndex = rowIndex,
|
|
Text = assembly.AssemblyCategory,
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "G",
|
|
RowIndex = rowIndex,
|
|
Text = assembly.AssemblyPrice.ToString(),
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
}
|
|
assemblyIndex++;
|
|
if (assemblyIndex < cnt_of_assemblies && !string.IsNullOrEmpty(assembly.AssemblyName) && !string.IsNullOrEmpty(assembly.AssemblyCategory) && assembly.AssemblyPrice != 0)
|
|
{
|
|
rowIndex++;
|
|
}
|
|
}
|
|
|
|
//rowIndex++;
|
|
|
|
// foreach (var (Component, Count) in tc.Components)
|
|
// {
|
|
// InsertCellInWorksheet(new ExcelCellParameters
|
|
// {
|
|
// ColumnName = "B",
|
|
// RowIndex = rowIndex,
|
|
// Text = Component,
|
|
// StyleInfo = ExcelStyleInfoType.TextWithBorder
|
|
// });
|
|
|
|
// InsertCellInWorksheet(new ExcelCellParameters
|
|
// {
|
|
// ColumnName = "C",
|
|
// RowIndex = rowIndex,
|
|
// Text = Count.ToString(),
|
|
// StyleInfo = ExcelStyleInfoType.TextWithBorder
|
|
// });
|
|
|
|
// rowIndex++;
|
|
// }
|
|
|
|
// InsertCellInWorksheet(new ExcelCellParameters
|
|
// {
|
|
// ColumnName = "A",
|
|
// RowIndex = rowIndex,
|
|
// Text = "Итого",
|
|
// StyleInfo = ExcelStyleInfoType.Text
|
|
// });
|
|
// InsertCellInWorksheet(new ExcelCellParameters
|
|
// {
|
|
// ColumnName = "C",
|
|
// RowIndex = rowIndex,
|
|
// Text = tc.TotalCount.ToString(),
|
|
// StyleInfo = ExcelStyleInfoType.Text
|
|
// });
|
|
// rowIndex++;
|
|
|
|
}
|
|
|
|
SaveExcel(info);
|
|
}
|
|
protected abstract void CreateExcel(ExcelInfoImplementer info);
|
|
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
|
protected abstract void SaveExcel(ExcelInfoImplementer info);
|
|
}
|
|
}
|