add material for orders

This commit is contained in:
DozorovaA.A 2023-05-19 23:07:37 +04:00
parent 543946a9fe
commit 454b2524f5
11 changed files with 497 additions and 0 deletions

View File

@ -0,0 +1,70 @@
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.StorageContracts;
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
{
public class ReportStorekeeperLogic : IReportStorekeeperLogic
{
private readonly IFurnitureStorage _furnitureStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IFurnitureStorage furnitureStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_furnitureStorage = furnitureStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportFurnitureMaterialViewModel> GetFurnitureComponent()
{
var furnitures = _furnitureStorage.GetFullList();
var list = new List<ReportFurnitureMaterialViewModel>();
foreach (var furniture in furnitures)
{
var record = new ReportFurnitureComponentViewModel
{
FurnitureName = furniture.FurnitureName,
Components = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var componentCount in furniture.FurnitureComponents.Values)
{
record.Components.Add(new Tuple<string, int>(componentCount.Item1.ComponentName, componentCount.Item2));
record.TotalCount += componentCount.Item2;
}
list.Add(record);
}
return list;
}
public List<ReportMaterialsViewModel> GetOrders(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveFurnituresToExelFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveFurnituresToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveMaterialsToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,20 @@
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels
{
public class ExcelStoreKeeperInfo
{
public string FileName { get; set; } = "C:\\temp\\excel_storekeeper.xlsx";
public string Title { get; set; } = string.Empty;
public List<ReportFurnitureMaterialViewModel> FurnitureMaterials
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,18 @@
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels
{
public class PdfStoreKeeperInfo
{
public string FileName { get; set; } = "C:\\temp\\pdf_storekeeper.pdf";
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportMaterialsViewModel> Materials { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels
{
public class WordStoreKeeperInfo
{
public string FileName { get; set; } = "C:\\temp\\word_storekeeper.docx";
public string Title { get; set; } = string.Empty;
public List<ReportFurnitureMaterialViewModel> FurnitureMaterialsList { get; set; } = new();
}
}

View File

@ -0,0 +1,106 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.StorekeeperSaveToFile
{
public abstract class AbstractSaveToExcel
{
/// <summary>
/// Создание отчета
/// </summary>
/// <param name="info"></param>
public void CreateReport(ExcelStoreKeeperInfo 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 furniture in info.FurnitureMaterials)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = furniture.FurnitureName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var materials in furniture.Materials)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = materials.Item1,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = materials.Item2.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = furniture.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelStoreKeeperInfo info);
/// <summary>
/// Добавляем новую ячейку в лист
/// </summary>
/// <param name="cellParameters"></param>
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
/// <summary>
/// Объединение ячеек
/// </summary>
/// <param name="mergeParameters"></param>
protected abstract void MergeCells(ExcelMergeParameters excelParams);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveExcel(ExcelStoreKeeperInfo info);
}
}

View File

@ -0,0 +1,91 @@
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.StorekeeperSaveToFile
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfStoreKeeperInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Материал", "Стоимость" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
double sum = 0;
foreach (var material in info.Materials)
{
//CreateParagraph(new PdfParagraph
//{
// Text = material.MaterialName,
// Style = "Normal",
// ParagraphAlignment = PdfParagraphAlignmentType.Left
//});
//CreateTable(new List<string> { "6cm", "3cm" });
sum += material.Sum;
CreateRow(new PdfRowParameters
{
Texts = new List<string> { material.MaterialName, material.Sum.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {sum}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
SavePdf(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreatePdf(PdfStoreKeeperInfo info);
/// <summary>
/// Создание параграфа с текстом
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateParagraph(PdfParagraph paragraph);
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateTable(List<string> columns);
/// <summary>
/// Создание и заполнение строки
/// </summary>
/// <param name="rowParameters"></param>
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SavePdf(PdfStoreKeeperInfo PdfStoreKeeperInfo);
}
}

View File

@ -0,0 +1,87 @@
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels;
using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.StorekeeperSaveToFile
{
public abstract class AbstractSaveToWord
{
public void CreateDoc(WordStoreKeeperInfo 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
}
});
foreach (var furniture in info.FurnitureMaterialsList)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(furniture.FurnitureName, new WordTextProperties { Bold = true, Size = "24", })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var materials in furniture.Materials)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(materials.Item1 + " " + materials.Item2.ToString(), new WordTextProperties { Bold = false, Size = "20", })
},
TextProperties = new WordTextProperties
{
Size = "20",
JustificationType = WordJustificationType.Both
}
});
}
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Итого " + furniture.TotalCount.ToString(), new WordTextProperties { Bold = false, Size = "24", })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordStoreKeeperInfo info);
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
/// <returns></returns>
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordStoreKeeperInfo info);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyContracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,43 @@
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
{
public interface IReportStorekeeperLogic
{
/// <summary>
/// Получение списка мебели с разбиением по материалам
/// </summary>
/// <returns></returns>
List<ReportFurnitureMaterialViewModel> GetFurnitureComponent();
/// <summary>
/// Получение отчета по движению материалов за период времени
/// </summary>
/// <returns></returns>
List<ReportMaterialsViewModel> GetOrders(ReportBindingModel model);
/// <summary>
/// Сохранение отчета по гарнитурам в файл-Word
/// </summary>
/// <param name="model"></param>
void SaveFurnituresToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение отчета по гарнитурам в файл-Excel
/// </summary>
/// <param name="model"></param>
void SaveFurnituresToExelFile(ReportBindingModel model);
/// <summary>
/// Сохранение отчета о материалах в файл-Pdf
/// </summary>
/// <param name="model"></param>
void SaveMaterialsToPdfFile(ReportBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyContracts.ViewModels
{
public class ReportFurnitureMaterialViewModel
{
public string FurnitureName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<Tuple<string, int>> Materials { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyContracts.ViewModels
{
public class ReportMaterialsViewModel
{
public int Id { get; set; }
public DateTime DateCreate { get; set; }
public string MaterialName { get; set; } = string.Empty;
public double Sum { get; set; }
}
}