Merge branch 'master' of http://student.git.athene.tech/the/CourseWork_CompShop
This commit is contained in:
@@ -3,6 +3,7 @@ using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,11 +17,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IAssemblyStorage _assemblyStorage;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
|
||||
public AssemblyLogic(ILogger<AssemblyLogic> logger, IAssemblyStorage assemblyStorage)
|
||||
public AssemblyLogic(ILogger<AssemblyLogic> logger, IAssemblyStorage assemblyStorage, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_assemblyStorage = assemblyStorage;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
|
||||
public bool Create(AssemblyBindingModel model)
|
||||
@@ -87,6 +90,38 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddComponentToAssembly(AssemblySearchModel model, ComponentSearchModel componentmodel, int amount)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddComponentToAssembly. AssemblyName:{AssemblyName}.Id:{ Id}", model.AssemblyName, model.Id);
|
||||
var element = _assemblyStorage.GetElement(model);
|
||||
var component = _componentStorage.GetElement(componentmodel);
|
||||
|
||||
if (element == null || component == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddComponentToAssembly find. Id:{Id}", element.Id);
|
||||
|
||||
element.AssemblyComponents[component.Id] = (component, amount);
|
||||
|
||||
_assemblyStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
AssemblyName = element.AssemblyName,
|
||||
Price = element.Price + component.Cost * amount,
|
||||
ClientId = element.ClientId,
|
||||
AssemblyComponents = element.AssemblyComponents,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(AssemblyBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
||||
@@ -24,8 +24,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() :
|
||||
_componentStorage.GetFilteredList(model);
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
|
||||
@@ -7,78 +7,77 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.OfficePackage
|
||||
{
|
||||
public class AbstractSaveToExcel
|
||||
public abstract class AbstractSaveToExcel
|
||||
{
|
||||
public void CreateReport(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 pc in info.DocumentBlanks)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.DocumentName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
foreach (var (Blank, Count) in pc.Blanks)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Blank,
|
||||
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 = pc.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
SaveExcel(info);
|
||||
}
|
||||
/// Создание excel-файла
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
/// Добавляем новую ячейку в лист
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
/// Объединение ячеек
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
/// Сохранение файла
|
||||
protected abstract void SaveExcel(ExcelInfo info);
|
||||
//public void CreateReport(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 pc in info.DocumentBlanks)
|
||||
// {
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "A",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = pc.DocumentName,
|
||||
// StyleInfo = ExcelStyleInfoType.Text
|
||||
// });
|
||||
// rowIndex++;
|
||||
// foreach (var (Blank, Count) in pc.Blanks)
|
||||
// {
|
||||
// InsertCellInWorksheet(new ExcelCellParameters
|
||||
// {
|
||||
// ColumnName = "B",
|
||||
// RowIndex = rowIndex,
|
||||
// Text = Blank,
|
||||
// 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 = pc.TotalCount.ToString(),
|
||||
// StyleInfo = ExcelStyleInfoType.Text
|
||||
// });
|
||||
// rowIndex++;
|
||||
// }
|
||||
// SaveExcel(info);
|
||||
//}
|
||||
///// Создание excel-файла
|
||||
//protected abstract void CreateExcel(ExcelInfo info);
|
||||
///// Добавляем новую ячейку в лист
|
||||
//protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
///// Объединение ячеек
|
||||
//protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
///// Сохранение файла
|
||||
//protected abstract void SaveExcel(ExcelInfo info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user