Начал кал делать

This commit is contained in:
maxnes3 2023-06-17 01:18:13 +04:00
parent 0e35a55b94
commit 0e5c0f7f5b
10 changed files with 268 additions and 9 deletions

View File

@ -18,11 +18,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics
private readonly IComponentStorage _componentStorage;
private readonly IComputerStorage _ComputerStorage;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IComputerStorage ComputerStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
public ReportLogic(IComputerStorage ComputerStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf, IShopStorage shopStorage)
{
_ComputerStorage = ComputerStorage;
_componentStorage = componentStorage;
@ -30,6 +31,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_shopStorage = shopStorage;
}
public List<ReportComputerComponentViewModel> GetComputerComponents()
@ -107,5 +109,73 @@ namespace ComputersShopBusinessLogic.BusinessLogics
Orders = GetOrders(model)
});
}
public List<ReportShopComputerViewModel> GetShopComputers()
{
var shops = _shopStorage.GetFullList();
var list = new List<ReportShopComputerViewModel>();
foreach (var shop in shops)
{
var record = new ReportShopComputerViewModel
{
ShopName = shop.ShopName,
Computers = new List<(string, int)>(),
TotalCount = 0
};
foreach (var comp in shop.Computers)
{
record.Computers.Add(new(comp.Value.Item1.ComputerName, shop.Computers[comp.Value.Item1.Id].Item2));
record.TotalCount += shop.Computers[comp.Value.Item1.Id].Item2;
}
list.Add(record);
}
return list;
}
public void SaveShopDocumentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateShopReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Заполненность магазинов",
ShopComputers = GetShopComputers()
});
}
public List<ReportOrdersGroupedByDateViewModel> GetGroupedByDateOrders()
{
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date)
.Select(x => new ReportOrdersGroupedByDateViewModel
{
Date = x.Key,
Count = x.Count(),
Sum = x.Sum(y => y.Sum)
})
.ToList();
}
public void SaveGroupedByDateOrders(ReportBindingModel model)
{
_saveToPdf.CreateDocWithGroupedOrders(new PdfInfo
{
FileName = model.FileName,
Title = "Заказы по дате",
GroupedOrders = GetGroupedByDateOrders(),
});
}
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateShopsTable(new WordInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
}
}
}

View File

@ -84,6 +84,77 @@ namespace ComputersShopBusinessLogic.OfficePackage
SaveExcel(info);
}
public void CreateShopReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var ss in info.ShopComputers)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = ss.ShopName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var (Computer, Count) in ss.Computers)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = Computer,
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 = ss.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfo info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);

View File

@ -57,6 +57,44 @@ namespace ComputersShopBusinessLogic.OfficePackage
SavePdf(info);
}
public void CreateDocWithGroupedOrders(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "3cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата", "Количество", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.GroupedOrders)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { order.Date.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.GroupedOrders.Sum(x => x.Sum)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph);

View File

@ -42,8 +42,47 @@ namespace ComputersShopBusinessLogic.OfficePackage
SaveWord(info);
}
public void CreateShopsTable(WordInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
List<(string, WordTextProperties)> shopsInfo = new()
{
{ ("Название", new WordTextProperties { Bold = true, Size = "24" }) },
{ ("Адрес", new WordTextProperties { Bold = true, Size = "24" }) },
{ ("Дата открытия", new WordTextProperties { Bold = true, Size = "24" }) }
};
foreach (var shop in info.Shops)
{
shopsInfo.Add((shop.ShopName, new WordTextProperties { Size = "20" }));
shopsInfo.Add((shop.ShopAddress, new WordTextProperties { Size = "20" }));
shopsInfo.Add((shop.DateOpening.ToString(), new WordTextProperties { Size = "20" }));
}
CreateTable(new WordParagraph
{
Texts = shopsInfo,
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
}, 3);
SaveWord(info);
}
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateTable(WordParagraph paragraph, int columnCount);
protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfo info);

View File

@ -12,5 +12,6 @@ namespace ComputersShopBusinessLogic.OfficePackage.HelperModels
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportComputerComponentViewModel> ComputerComponents { get; set; } = new();
public List<ReportShopComputerViewModel> ShopComputers { get; set; } = new();
}
}

View File

@ -14,5 +14,6 @@ namespace ComputersShopBusinessLogic.OfficePackage.HelperModels
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportOrdersViewModel> Orders { get; set; } = new();
public List<ReportOrdersGroupedByDateViewModel> GroupedOrders { get; set; } = new();
}
}

View File

@ -12,5 +12,6 @@ namespace ComputersShopBusinessLogic.OfficePackage.HelperModels
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ComputerViewModel> Computers { get; set; } = new();
public List<ShopViewModel> Shops { get; set; } = new();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.ViewModels
{
public class ReportOrdersGroupedByDateViewModel
{
public DateTime Date { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.ViewModels
{
public class ReportShopComputerViewModel
{
public string ShopName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<(string Computer, int Count)> Computers { get; set; } = new();
}
}

View File

@ -28,4 +28,10 @@
<ProjectReference Include="..\ComputersShopFileImplement\ComputersShopFileImplement.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="ReportOrders.rdlc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>