Excel done, lab done

This commit is contained in:
the 2023-04-04 14:30:46 +04:00
parent 2b5739b429
commit d89c3851ac
4 changed files with 16 additions and 18 deletions

View File

@ -40,24 +40,22 @@ namespace ComputerShopBusinessLogic.BusinessLogics
public List<ReportComputerComponentViewModel> GetComputerComponent()
{
var components = _componentStorage.GetFullList();
var products = _productStorage.GetFullList();
var computers = _productStorage.GetFullList();
var list = new List<ReportComputerComponentViewModel>();
foreach (var component in components)
foreach (var computer in computers)
{
var record = new ReportComputerComponentViewModel
{
ComponentName = component.ComponentName,
Computers = new List<Tuple<string, int>>(),
ComputerName = computer.ComputerName,
Components = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var product in products)
foreach (var component in components)
{
if (product.ComputerComponents.ContainsKey(component.Id))
if (computer.ComputerComponents.ContainsKey(component.Id))
{
record.Computers.Add(new Tuple<string,
int>(product.ComputerName, product.ComputerComponents[component.Id].Item2));
record.TotalCount +=
product.ComputerComponents[component.Id].Item2;
record.Components.Add(new Tuple<string, int>(component.ComponentName, computer.ComputerComponents[component.Id].Item2));
record.TotalCount += computer.ComputerComponents[component.Id].Item2;
}
}
list.Add(record);

View File

@ -36,11 +36,11 @@ namespace ComputerShopBusinessLogic.OfficePackage
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.ComponentName,
Text = pc.ComputerName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var product in pc.Computers)
foreach (var product in pc.Components)
{
InsertCellInWorksheet(new ExcelCellParameters
{

View File

@ -8,8 +8,8 @@ namespace ComputerShopContracts.ViewModels
{
public class ReportComputerComponentViewModel
{
public string ComponentName { get; set; } = string.Empty;
public string ComputerName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<Tuple<string, int>> Computers { get; set; } = new();
public List<Tuple<string, int>> Components { get; set; } = new();
}
}

View File

@ -34,8 +34,8 @@ namespace ComputersShop
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.ComponentName, "", "" });
foreach (var listElem in elem.Computers)
dataGridView.Rows.Add(new object[] { elem.ComputerName, "", "" });
foreach (var listElem in elem.Components)
{
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}
@ -43,11 +43,11 @@ namespace ComputersShop
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Загрузка списка изделий по компонентам");
_logger.LogInformation("Загрузка списка компонентов по изделиям");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам");
_logger.LogError(ex, "Ошибка загрузки списка компонентов по изделиям");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}