Делаю сохранение в pdf
This commit is contained in:
parent
6e1690d28c
commit
a445a2307d
@ -3,6 +3,8 @@ using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,36 +19,77 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public ReportImplementerLogic(IAssemblyStorage assemblyStorage, IRequestStorage requestStorage, IOrderStorage orderStorage)
|
||||
private readonly AbstractSaveToExcelImplementer _saveToExcel;
|
||||
private readonly AbstractSaveToWordImplementer _saveToWord;
|
||||
private readonly AbstractSaveToPdfImplementer _saveToPdf;
|
||||
|
||||
public ReportImplementerLogic(IAssemblyStorage assemblyStorage, IRequestStorage requestStorage, IOrderStorage orderStorage,
|
||||
AbstractSaveToExcelImplementer saveToExcel, AbstractSaveToWordImplementer saveToWord, AbstractSaveToPdfImplementer saveToPdf)
|
||||
{
|
||||
_assemblyStorage = assemblyStorage;
|
||||
_requestStorage = requestStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
/// <summary>
|
||||
/// Отчёт для doc/xls
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<ReportOrderAssemblyViewModel> GetReportOrdersAssemblies(List<OrderSearchModel> selectedOrders)
|
||||
public List<ReportOrderAssemblyViewModel> GetReportOrdersAssemblies(/*List<OrderSearchModel>*/List<int> selectedOrders)
|
||||
{
|
||||
return _orderStorage.GetOrdersAssemblies(selectedOrders);
|
||||
}
|
||||
/// <summary>
|
||||
/// Отчёт для почты/страницы
|
||||
/// Отчёт для почты/страницы в формате PDF
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<ReportOrdersViewModel> GetReportOrdersByDates(UserSearchModel currentUser, ReportBindingModel report)
|
||||
public List<ReportOrdersViewModel> GetReportOrdersByDates(ReportBindingModel report)
|
||||
{
|
||||
return _orderStorage.GetOrdersInfoByDates(currentUser, report);
|
||||
return _orderStorage.GetOrdersInfoByDates(report);
|
||||
}
|
||||
|
||||
public void SaveReportOrderAssembliesToWordFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_saveToWord.CreateDoc(new WordInfoImplementer
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список сборок по выбранным заявкам",
|
||||
OrderAssemblies = GetReportOrdersAssemblies(model.Ids)
|
||||
});;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
public void SaveReportOrderAssembliesToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_saveToExcel.CreateReport(new ExcelInfoImplementer
|
||||
{
|
||||
FileName = model.FileName,
|
||||
OrderAssemblies = GetReportOrdersAssemblies(model.Ids)
|
||||
});
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//!!!ИСПРАВИТЬ
|
||||
public void SaveReportOrdersByDatesToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
if (model.DateFrom == null)
|
||||
{
|
||||
throw new ArgumentException("Дата начала не задана");
|
||||
}
|
||||
|
||||
if (model.DateTo == null)
|
||||
{
|
||||
throw new ArgumentException("Дата окончания не задана");
|
||||
}
|
||||
_saveToPdf.CreateDoc(new PdfInfoImplementer
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список участников",
|
||||
DateFrom = model.DateFrom!.Value,
|
||||
DateTo = model.DateTo!.Value,
|
||||
Orders = GetReportOrdersByDates(model)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -0,0 +1,194 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.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);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdfImplementer
|
||||
{
|
||||
public void CreateDoc(PdfInfoImplementer 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 });
|
||||
|
||||
//CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
|
||||
|
||||
//CreateRow(new PdfRowParameters
|
||||
//{
|
||||
// Texts = new List<string> { "Номер", "Дата заказа", "Текстиль", "Статус", "Сумма" },
|
||||
// Style = "NormalTitle",
|
||||
// ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
//});
|
||||
|
||||
//foreach (var order in info.Orders)
|
||||
//{
|
||||
// CreateRow(new PdfRowParameters
|
||||
// {
|
||||
// Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.TextileName, order.Status.ToString(), order.Sum.ToString() },
|
||||
// Style = "Normal",
|
||||
// ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
// });
|
||||
//}
|
||||
//CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
|
||||
|
||||
//SavePdf(info);
|
||||
}
|
||||
protected abstract void CreatePdf(PdfInfoImplementer info);
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
protected abstract void SavePdf(PdfInfoImplementer info);
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToWordImplementer
|
||||
{
|
||||
public void CreateDoc(WordInfoImplementer 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 orderAs in info.OrderAssemblies)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)>
|
||||
{
|
||||
("Заказ №" + orderAs.OrderId.ToString() + " - " + orderAs.DateCreateOrder.ToShortDateString() + " - " + orderAs.OrderStatus + " - " + orderAs.OrderSum, new WordTextProperties {Size = "24", Bold=true})
|
||||
},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
foreach (var assembly in orderAs.Assemblies)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(assembly.AssemblyName) && !string.IsNullOrEmpty(assembly.AssemblyCategory) && assembly.AssemblyPrice != 0)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> {
|
||||
//(orderAs.OrderId.ToString() + "\n", new WordTextProperties {Size = "24", Bold=true}),
|
||||
//(orderAs.DateCreateOrder.ToShortDateString() + " - ", new WordTextProperties { Size = "24" }),
|
||||
//(orderAs.OrderSum.ToString() + " - ", new WordTextProperties { Size = "24" }),
|
||||
//(orderAs.OrderStatus.ToString() + " - ", new WordTextProperties { Size = "24" }),
|
||||
(assembly.AssemblyName + " - ", new WordTextProperties { Size = "24" }),
|
||||
(assembly.AssemblyCategory + " - ", new WordTextProperties { Size = "24" }),
|
||||
(assembly.AssemblyPrice.ToString(), new WordTextProperties { Size = "24" })
|
||||
}, TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreateWord(WordInfoImplementer 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(WordInfoImplementer info);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum ExcelStyleInfoType
|
||||
{
|
||||
Title,
|
||||
Text,
|
||||
TextWithBorder
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum PdfParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Rigth
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum WordJustificationType
|
||||
{
|
||||
Center,
|
||||
Both
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelCellParameters
|
||||
{
|
||||
public string ColumnName { get; set; } = string.Empty;
|
||||
public uint RowIndex { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string CellReference => $"{ColumnName}{RowIndex}";
|
||||
public ExcelStyleInfoType StyleInfo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelInfoImplementer
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
//public string Title { get; set; } = string.Empty;
|
||||
//!!!Мб поставить string.Empty, названия задать в ReportImplementerLogic
|
||||
public string Title1 { get; set; } = "ID заказа";
|
||||
public string Title2 { get; set; } = "Дата заказа";
|
||||
public string Title3 { get; set; } = "Стоимость заказа";
|
||||
public string Title4 { get; set; } = "Статус заказа";
|
||||
public string Title5 { get; set; } = "Название сборки";
|
||||
public string Title6 { get; set; } = "Категория сборки";
|
||||
public string Title7 { get; set; } = "Цена сборки";
|
||||
public List<ReportOrderAssemblyViewModel> OrderAssemblies { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelMergeParameters
|
||||
{
|
||||
public string CellFromName { get; set; } = string.Empty;
|
||||
public string CellToName { get; set; } = string.Empty;
|
||||
public string Merge => $"{CellFromName}:{CellToName}";
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfoImplementer
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportOrdersViewModel> Orders { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordInfoImplementer
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportOrderAssemblyViewModel> OrderAssemblies { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordParagraph
|
||||
{
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordTextProperties
|
||||
{
|
||||
public string Size { get; set; } = string.Empty;
|
||||
public bool Bold { get; set; }
|
||||
public WordJustificationType JustificationType { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,324 @@
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToExcelImplementer : AbstractSaveToExcelImplementer
|
||||
{
|
||||
private SpreadsheetDocument? _spreadsheetDocument;
|
||||
private SharedStringTablePart? _shareStringPart;
|
||||
private Worksheet? _worksheet;
|
||||
|
||||
/// <summary>
|
||||
/// Настройка стилей для файла
|
||||
/// </summary>
|
||||
/// <param name="workbookpart"></param>
|
||||
// WorkbookPart содержит информацию о стилях для ячеек в рабочей книге, добавление стилей в неё
|
||||
private static void CreateStyles(WorkbookPart workbookpart)
|
||||
{
|
||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||
sp.Stylesheet = new Stylesheet();
|
||||
|
||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||
|
||||
//Создание шрифтов для основного текста и заголовка (в ячейке A1)
|
||||
var fontUsual = new Font();
|
||||
fontUsual.Append(new FontSize() { Val = 12D });
|
||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
var fontTitle = new Font();
|
||||
fontTitle.Append(new Bold());
|
||||
fontTitle.Append(new FontSize() { Val = 14D });
|
||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
fonts.Append(fontUsual);
|
||||
fonts.Append(fontTitle);
|
||||
|
||||
|
||||
//Создание заливок ячеек
|
||||
var fills = new Fills() { Count = 2U };
|
||||
|
||||
var fill1 = new Fill();
|
||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||
|
||||
var fill2 = new Fill();
|
||||
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
||||
|
||||
fills.Append(fill1);
|
||||
fills.Append(fill2);
|
||||
|
||||
//Создание границ (без границ и с тонкими границами (исп., где название и кол-во компонента))
|
||||
var borders = new Borders() { Count = 2U };
|
||||
|
||||
var borderNoBorder = new Border();
|
||||
borderNoBorder.Append(new LeftBorder());
|
||||
borderNoBorder.Append(new RightBorder());
|
||||
borderNoBorder.Append(new TopBorder());
|
||||
borderNoBorder.Append(new BottomBorder());
|
||||
borderNoBorder.Append(new DiagonalBorder());
|
||||
|
||||
var borderThin = new Border();
|
||||
|
||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
||||
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
||||
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
borderThin.Append(leftBorder);
|
||||
borderThin.Append(rightBorder);
|
||||
borderThin.Append(topBorder);
|
||||
borderThin.Append(bottomBorder);
|
||||
borderThin.Append(new DiagonalBorder());
|
||||
|
||||
borders.Append(borderNoBorder);
|
||||
borders.Append(borderThin);
|
||||
|
||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
|
||||
|
||||
cellStyleFormats.Append(cellFormatStyle);
|
||||
|
||||
//Создание 3 стилей ячеек
|
||||
var cellFormats = new CellFormats() { Count = 3U };
|
||||
var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true };
|
||||
var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true };
|
||||
var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true };
|
||||
|
||||
cellFormats.Append(cellFormatFont);
|
||||
cellFormats.Append(cellFormatFontAndBorder);
|
||||
cellFormats.Append(cellFormatTitle);
|
||||
|
||||
var cellStyles = new CellStyles() { Count = 1U };
|
||||
|
||||
cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U });
|
||||
|
||||
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U };
|
||||
|
||||
var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };
|
||||
|
||||
var stylesheetExtensionList = new StylesheetExtensionList();
|
||||
|
||||
var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
|
||||
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||
stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" });
|
||||
|
||||
var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" };
|
||||
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||
stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" });
|
||||
|
||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||
|
||||
sp.Stylesheet.Append(fonts);
|
||||
sp.Stylesheet.Append(fills);
|
||||
sp.Stylesheet.Append(borders);
|
||||
sp.Stylesheet.Append(cellStyleFormats);
|
||||
sp.Stylesheet.Append(cellFormats);
|
||||
sp.Stylesheet.Append(cellStyles);
|
||||
sp.Stylesheet.Append(differentialFormats);
|
||||
sp.Stylesheet.Append(tableStyles);
|
||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение номера стиля из типа
|
||||
/// </summary>
|
||||
/// <param name="styleInfo"></param>
|
||||
/// <returns></returns>
|
||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||
{
|
||||
return styleInfo switch
|
||||
{
|
||||
ExcelStyleInfoType.Title => 2U,
|
||||
ExcelStyleInfoType.TextWithBorder => 1U,
|
||||
ExcelStyleInfoType.Text => 0U,
|
||||
_ => 0U,
|
||||
};
|
||||
}
|
||||
|
||||
protected override void CreateExcel(ExcelInfoImplementer info)
|
||||
{
|
||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
|
||||
// Создание книги (в ней хранятся листы)
|
||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||
workbookpart.Workbook = new Workbook();
|
||||
|
||||
CreateStyles(workbookpart);
|
||||
|
||||
// Получение/создание хранилища текстов для книги
|
||||
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
||||
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||
|
||||
// Создание SharedStringTable, если его нет
|
||||
if (_shareStringPart.SharedStringTable == null)
|
||||
{
|
||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||
}
|
||||
|
||||
// Создание листа в книге
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||
|
||||
// Добавление столбцов с заданной шириной
|
||||
// Save the stylesheet formats
|
||||
//stylesPart.Stylesheet.Save();
|
||||
|
||||
// Create custom widths for columns
|
||||
Columns lstColumns = worksheetPart.Worksheet.GetFirstChild<Columns>();
|
||||
if (lstColumns == null)
|
||||
{
|
||||
lstColumns = new Columns();
|
||||
}
|
||||
// Min = 1, Max = 1 ==> Apply this to column 1 (A)
|
||||
// Min = 2, Max = 2 ==> Apply this to column 2 (B)
|
||||
// Width = 25 ==> Set the width to 25
|
||||
// CustomWidth = true ==> Tell Excel to use the custom width
|
||||
lstColumns.Append(new Column() { Min = 1, Max = 1, Width = 10, CustomWidth = true });
|
||||
lstColumns.Append(new Column() { Min = 2, Max = 2, Width = 10, CustomWidth = true });
|
||||
lstColumns.Append(new Column() { Min = 3, Max = 3, Width = 20, CustomWidth = true });
|
||||
lstColumns.Append(new Column() { Min = 4, Max = 4, Width = 10, CustomWidth = true });
|
||||
lstColumns.Append(new Column() { Min = 5, Max = 5, Width = 20, CustomWidth = true });
|
||||
lstColumns.Append(new Column() { Min = 6, Max = 6, Width = 20, CustomWidth = true });
|
||||
lstColumns.Append(new Column() { Min = 7, Max = 7, Width = 20, CustomWidth = true });
|
||||
worksheetPart.Worksheet.InsertAt(lstColumns, 0);
|
||||
|
||||
// Добавление листа в книгу
|
||||
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||
var sheet = new Sheet()
|
||||
{
|
||||
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||
SheetId = 1,
|
||||
Name = "Лист"
|
||||
};
|
||||
sheets.Append(sheet);
|
||||
|
||||
_worksheet = worksheetPart.Worksheet;
|
||||
}
|
||||
|
||||
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null || _shareStringPart == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
||||
if (sheetData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ищем строку, либо добавляем ее
|
||||
Row row;
|
||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||
{
|
||||
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||
sheetData.Append(row);
|
||||
}
|
||||
|
||||
// Ищем нужную ячейку
|
||||
Cell cell;
|
||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
||||
{
|
||||
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Все ячейки должны быть последовательно друг за другом расположены
|
||||
// нужно определить, после какой вставлять
|
||||
Cell? refCell = null;
|
||||
foreach (Cell rowCell in row.Elements<Cell>())
|
||||
{
|
||||
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
|
||||
{
|
||||
refCell = rowCell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var newCell = new Cell() { CellReference = excelParams.CellReference };
|
||||
row.InsertBefore(newCell, refCell);
|
||||
|
||||
cell = newCell;
|
||||
}
|
||||
|
||||
// вставляем новый текст
|
||||
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
||||
_shareStringPart.SharedStringTable.Save();
|
||||
|
||||
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||
}
|
||||
|
||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MergeCells mergeCells;
|
||||
|
||||
if (_worksheet.Elements<MergeCells>().Any())
|
||||
{
|
||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||
}
|
||||
else
|
||||
{
|
||||
mergeCells = new MergeCells();
|
||||
|
||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
|
||||
}
|
||||
else
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
|
||||
}
|
||||
}
|
||||
|
||||
var mergeCell = new MergeCell()
|
||||
{
|
||||
Reference = new StringValue(excelParams.Merge)
|
||||
};
|
||||
mergeCells.Append(mergeCell);
|
||||
}
|
||||
|
||||
protected override void SaveExcel(ExcelInfoImplementer info)
|
||||
{
|
||||
if (_spreadsheetDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||
_spreadsheetDocument.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToPdfImplementer : AbstractSaveToPdfImplementer
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
|
||||
protected override void CreatePdf(PdfInfoImplementer info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateRow(PdfRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SavePdf(PdfInfoImplementer info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToWordImplementer : AbstractSaveToWordImplementer
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
|
||||
/// <summary>
|
||||
/// Получение типа выравнивания
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Настройки страницы
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
|
||||
properties.AppendChild(pageSize);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Задание форматирования для абзаца
|
||||
/// </summary>
|
||||
/// <param name="paragraphProperties"></param>
|
||||
/// <returns></returns>
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var properties = new ParagraphProperties();
|
||||
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
|
||||
properties.AppendChild(new Indentation());
|
||||
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected override void CreateWord(WordInfoImplementer info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
|
||||
protected override void SaveWord(WordInfoImplementer info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
|
||||
_wordDocument.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,5 +11,10 @@ namespace ComputerShopContracts.BindingModels
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
//Id выбранных записей
|
||||
public List<int>? Ids { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace ComputerShopContracts.BusinessLogicContracts
|
||||
/// Получение отчёта для word/excel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<ReportOrderAssemblyViewModel> GetReportOrdersAssemblies(List<OrderSearchModel> selectedOrders);
|
||||
List<ReportOrderAssemblyViewModel> GetReportOrdersAssemblies(List</*OrderSearchModel*/int> selectedOrders);
|
||||
|
||||
/// <summary>
|
||||
/// Получение отчёта для почты
|
||||
|
@ -18,7 +18,7 @@ namespace ComputerShopContracts.StorageContracts
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
//получение данных о заказах для отчётов
|
||||
List<ReportOrderAssemblyViewModel> GetOrdersAssemblies(List<OrderSearchModel> model);
|
||||
List<ReportOrdersViewModel> GetOrdersInfoByDates(UserSearchModel currentUser, ReportBindingModel report);
|
||||
List<ReportOrderAssemblyViewModel> GetOrdersAssemblies(List<int/*OrderSearchModel*/> model);
|
||||
List<ReportOrdersViewModel> GetOrdersInfoByDates(ReportBindingModel report);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -18,5 +19,7 @@ namespace ComputerShopContracts.ViewModels
|
||||
|
||||
//данные о сборках
|
||||
public List<(string AssemblyName, string AssemblyCategory, double AssemblyPrice)> Assemblies { get; set; }
|
||||
|
||||
//public Dictionary<int, IAssemblyModel> Assemblies { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,14 @@ namespace ComputerShopContracts.ViewModels
|
||||
public RequestViewModel() { }
|
||||
|
||||
[JsonConstructor]
|
||||
public RequestViewModel(Dictionary<int, OrderViewModel> requestOrders)
|
||||
public RequestViewModel(Dictionary<int, OrderViewModel> requestOrders, AssemblyViewModel assembly)
|
||||
{
|
||||
this.RequestOrders = requestOrders.ToDictionary(x => x.Key, x => x.Value as IOrderModel);
|
||||
this.Assembly = assembly as IAssemblyModel;
|
||||
}
|
||||
//public RequestViewModel(Dictionary<int, OrderViewModel> requestOrders)
|
||||
//{
|
||||
// this.RequestOrders = requestOrders.ToDictionary(x => x.Key, x => x.Value as IOrderModel);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -55,17 +55,18 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
}
|
||||
|
||||
//получение данных сборок по выбранным заказам для отчёта (doc/xls)
|
||||
public List<ReportOrderAssemblyViewModel> GetOrdersAssemblies(List<OrderSearchModel> selectedModels)
|
||||
public List<ReportOrderAssemblyViewModel> GetOrdersAssemblies(List<int>/*<OrderSearchModel>*/ selectedModels)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
//id заказов, которые выбрал пользователь
|
||||
List<int?> id_of_selected_models = selectedModels.Select(x => x.Id).ToList();
|
||||
//List<int?> id_of_selected_models = selectedModels.Select(x => x.Id).ToList();
|
||||
|
||||
//те заказы из бд, которые выбрал пользователь и имеют сборку
|
||||
//МБ ИЗМЕНИТЬ, И СДЕЛАТЬ ВЫВОД ВСЕХ ЗАЯВОК (В ТОМ ЧИСЛЕ БЕЗ СБОРОК)
|
||||
return context.Orders.Include(x => x.Requests)
|
||||
.ThenInclude(x => x.Request)
|
||||
.ThenInclude(x => x.Assembly)
|
||||
.Where(x => id_of_selected_models.Contains(x.Id) && x.Requests.Any(r => r.Request.Assembly != null))
|
||||
.Where(x => selectedModels.Contains(x.Id) && x.Requests.Any(r => r.Request.Assembly != null))
|
||||
.ToList()
|
||||
.Select(x => new ReportOrderAssemblyViewModel
|
||||
{
|
||||
@ -79,13 +80,13 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
}
|
||||
|
||||
//получение заказов (все, что создал сам пользователь) за период с расшифровкой по заявкам и сборкам для отчёта (почта/страница)
|
||||
public List<ReportOrdersViewModel> GetOrdersInfoByDates(UserSearchModel currentUser, ReportBindingModel report)
|
||||
public List<ReportOrdersViewModel> GetOrdersInfoByDates(ReportBindingModel report)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
return context.Orders.Include(x => x.Requests)
|
||||
.ThenInclude(x => x.Request)
|
||||
.ThenInclude(x => x.Assembly)
|
||||
.Where(x => x.UserId == currentUser.Id && x.DateCreate >= report.DateFrom && x.DateCreate <= report.DateTo)
|
||||
.Where(x => x.UserId == report.UserId && x.DateCreate >= report.DateFrom && x.DateCreate <= report.DateTo)
|
||||
.ToList()
|
||||
.Select(x => new ReportOrdersViewModel
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var request = context.Requests.FirstOrDefault(x => x.Id == model.Id);
|
||||
var request = context.Requests.Include(x => x.Orders).ThenInclude(x => x.Order).Include(x => x.Assembly).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (request == null)
|
||||
{
|
||||
return null;
|
||||
@ -141,9 +141,28 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
using var context = new ComputerShopDatabase();
|
||||
var request = context.Requests
|
||||
.Include(x => x.Orders)
|
||||
.ThenInclude(x => x.Order)
|
||||
.Include(x => x.Assembly)
|
||||
.FirstOrDefault(y => y.Id == model.Id);
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
double assemblyPrice;
|
||||
if (request.Assembly == null)
|
||||
{
|
||||
assemblyPrice = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
assemblyPrice = request.Assembly.Price;
|
||||
}
|
||||
//var ordersOfRequest = context.RequestOrders.Where(x => x.RequestId == model.Id).ToList();
|
||||
foreach (Order order_request in request.RequestOrders.Values)
|
||||
{
|
||||
//Если была связанная сборка, то вычитание стоимости сборки, иначе -0
|
||||
//order_request.ChangeSum(-(request.Assembly?.Price ?? 0));
|
||||
order_request.ChangeSum(-assemblyPrice);
|
||||
}
|
||||
context.Requests.Remove(request);
|
||||
context.SaveChanges();
|
||||
return request.GetViewModel;
|
||||
@ -154,15 +173,40 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
public bool ConnectRequestAssembly(RequestBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var request = context.Requests.FirstOrDefault(x => x.Id == model.Id);
|
||||
var assembly = context.Assemblies.FirstOrDefault(x => x.Id == model.AssemblyId);
|
||||
if (request == null || assembly == null)
|
||||
var request = context.Requests.Include(x => x.Orders).ThenInclude(x => x.Order).Include(x => x.Assembly).FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
// Если у заявки до этого уже была другая связанная сборка
|
||||
// вычитание стоимости сборки из всех связанных чеков
|
||||
if (request.Assembly != null)
|
||||
{
|
||||
foreach (Order order_of_request in request.RequestOrders.Values)
|
||||
{
|
||||
order_of_request.ChangeSum(-request.Assembly.Price);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
//Поиск заявки, с которой надо связать
|
||||
var newAssembly = context.Assemblies.FirstOrDefault(x => x.Id == model.AssemblyId);
|
||||
|
||||
if (newAssembly == null) {
|
||||
return false;
|
||||
}
|
||||
request.ConnectAssembly(context, model);
|
||||
|
||||
// Прибавление к стоимости всех связанных заказов стоимость новой сборки
|
||||
foreach (Order order_of_request in request.RequestOrders.Values)
|
||||
{
|
||||
order_of_request.ChangeSum(newAssembly.Price);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
// Запоминание новой сборки в заявке
|
||||
request.ConnectAssembly(context, model);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,16 +96,16 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
var currentRequest = context.Requests.First(x => x.Id == Id);
|
||||
//стоимость сборки, связанной с заявкой (или 0, если заявка не связана со сборкой)
|
||||
double price_of_assembly = (currentRequest.Assembly.Price != null) ? currentRequest.Assembly.Price : 0;
|
||||
double price_of_assembly = (currentRequest.AssemblyId != null) ? context.Assemblies.First(x => x.Id == currentRequest.AssemblyId).Price : 0;
|
||||
|
||||
var requestOrders = context.RequestOrders.Where(x => x.RequestId == model.Id).ToList();
|
||||
var oldRequestOrders = context.RequestOrders.Where(x => x.RequestId == model.Id).ToList();
|
||||
|
||||
//удаление тех заказов, которых нет в модели (+ изменение суммы у удаляемых заказов)
|
||||
//ИЗМЕНЕНО: удаление всех заказов
|
||||
if (requestOrders != null && requestOrders.Count > 0)
|
||||
if (oldRequestOrders != null && oldRequestOrders.Count > 0)
|
||||
{
|
||||
//var delOrders = requestOrders.Where(x => !model.RequestOrders.ContainsKey(x.OrderId));
|
||||
var delOrders = requestOrders;
|
||||
var delOrders = oldRequestOrders;
|
||||
foreach (var delOrder in delOrders)
|
||||
{
|
||||
context.RequestOrders.Remove(delOrder);
|
||||
@ -136,21 +136,9 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
//Связывание заявки со сборкой (+ изменение суммы у соответствующих заказов)
|
||||
public void ConnectAssembly(ComputerShopDatabase context, RequestBindingModel model)
|
||||
{
|
||||
//стоимость старой сборки (или 0, если её не было)
|
||||
double price_of_old_assembly = (Assembly.Price != null) ? Assembly.Price : 0;
|
||||
|
||||
AssemblyId = model.AssemblyId;
|
||||
Assembly = context.Assemblies.First(x => x.Id == model.AssemblyId);
|
||||
//изменение стоимости всех связанных заказов
|
||||
foreach (var request_order in model.RequestOrders)
|
||||
{
|
||||
var connectedOrder = context.Orders.First(x => x.Id == request_order.Key);
|
||||
//вычитание из стоимости заказа старой сборки
|
||||
connectedOrder.ChangeSum(-price_of_old_assembly);
|
||||
//прибавление стоимости новой сборки
|
||||
connectedOrder.ChangeSum(Assembly.Price);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -447,11 +447,25 @@ namespace ComputerShopImplementerApp.Controllers
|
||||
}
|
||||
ViewBag.Requests = await APIUser.GetRequestRequestAsync<List<RequestViewModel>>($"api/request/getrequests?userId={APIUser.User.Id}");
|
||||
//ViewBag.Orders = APIUser.GetRequest<List<OrderViewModel>>($"api/order/getorders?userId={APIUser.User.Id}");
|
||||
ViewBag.Assemblies = APIUser.GetRequest<List<AssemblyViewModel>>($"api/")
|
||||
ViewBag.Assemblies = APIUser.GetRequest<List<AssemblyViewModel>>($"api/assembly/getassemblies");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ConnectRequestAssembly(int request, int assembly)
|
||||
{
|
||||
if (APIUser.User == null)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}
|
||||
|
||||
APIUser.PostRequest("api/request/connectRequestAssembly", new RequestBindingModel
|
||||
{
|
||||
Id = request,
|
||||
AssemblyId = assembly
|
||||
});
|
||||
Response.Redirect("Requests");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -482,6 +496,68 @@ namespace ComputerShopImplementerApp.Controllers
|
||||
}
|
||||
|
||||
|
||||
//ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ ОТЧЁТЫ
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ReportOrdersAssembliesToFile()
|
||||
{
|
||||
if (APIUser.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Orders = APIUser.GetRequest<List<OrderViewModel>>($"api/order/getorders?userId={APIUser.User.Id}");
|
||||
//ViewBag.Statuses =
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ReportOrdersAssembliesToFile(int[] orders, string type)
|
||||
{
|
||||
if (APIUser.User == null)
|
||||
{
|
||||
Redirect("Index");
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}
|
||||
if (orders.Length <= 0)
|
||||
{
|
||||
throw new Exception("Выберите хотя бы 1 заказ");
|
||||
}
|
||||
if (string.IsNullOrEmpty(type))
|
||||
{
|
||||
throw new Exception("Неверный тип отчета");
|
||||
}
|
||||
|
||||
//Преобразование массива в список
|
||||
List<int> ids = new List<int>();
|
||||
foreach (var item in orders)
|
||||
{
|
||||
ids.Add(item);
|
||||
}
|
||||
|
||||
if (type == "docx")
|
||||
{
|
||||
APIUser.PostRequest("api/order/createreporttowordfile", new ReportBindingModel
|
||||
{
|
||||
Ids = ids,
|
||||
//FileName = "C:\\ReportsCourseWork\\wordfile.docx"
|
||||
FileName = "C:\\!КУРСОВАЯ\\Сборки по выбранным заказам.docx"
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
if (type == "xlsx")
|
||||
{
|
||||
APIUser.PostRequest("api/order/createreporttoexcelfile", new ReportBindingModel
|
||||
{
|
||||
Ids = ids,
|
||||
//FileName = "C:\\ReportsCourseWork\\wordfile.docx"
|
||||
FileName = "C:\\!КУРСОВАЯ\\Сборки по выбранным заказам.xlsx"
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ
|
||||
|
||||
[HttpGet]
|
||||
|
@ -24,6 +24,9 @@ builder.Services.AddTransient<IShipmentLogic, ShipmentLogic>();
|
||||
builder.Services.AddTransient<IRequestLogic, RequestLogic>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
|
||||
|
||||
//builder.Services.AddTransient<IReportImplementerLogic, ReportImplementerLogic>();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Изменить" class="btn btn-primary" /></div>
|
||||
<div class="col-4"><input type="submit" value="Связать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -17,11 +17,11 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="mb-3">Дата оформления:</label>
|
||||
<input type="datetime-local" id="date" name="date" class="mb-3 form-control" step="1">
|
||||
<input disabled type="datetime-local" id="date" name="date" class="mb-3 form-control" step="1">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="mb-3">ФИО клиента-заявителя:</label>
|
||||
<input type="text" id="clientFIO" name="clientFIO" class="mb-3 form-control" />
|
||||
<input disabled type="text" id="clientFIO" name="clientFIO" class="mb-3 form-control" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
|
@ -0,0 +1,66 @@
|
||||
@using ComputerShopContracts.ViewModels
|
||||
@{
|
||||
ViewData["Title"] = "Create report with assemblies by orders";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Получение списка сборок по заказам</h2>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="mb-3">Выберите заказы для отчёта:</label>
|
||||
<select multiple id="orders" name="orders" class="form-control">
|
||||
@* !!!ЕСЛИ НЕ БУДЕТ РАБОТАТЬ, УБРАТЬ ОТСЮДА @order.Sum *@
|
||||
@foreach (var order in ViewBag.Orders)
|
||||
{
|
||||
<option value="@order.Id">@order.DateCreate; @order.Sum</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">
|
||||
Выберите формат файла:
|
||||
</label>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="type" value="docx" id="docx" checked>
|
||||
<label class="u-label u-text-custom-color-1 u-label-1" for="docx">
|
||||
Word-файл
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1" for="xlsx">
|
||||
Excel-файл
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Получить отчёт" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@* <script>
|
||||
$('#orders').on('change', function () {
|
||||
check();
|
||||
});
|
||||
function check() {
|
||||
var order = $('#order').val();
|
||||
if (order) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetOrder",
|
||||
data: { orderId: order },
|
||||
success: function (result) {
|
||||
console.log(result);
|
||||
var localDate = result.dateCreate.toLocaleString();
|
||||
$("#date").val(localDate);
|
||||
//!!!ТУТ КАК-ТО ВЫВЕСТИ СТАТУС
|
||||
var orderStatusName = orderStatusNames[result.status + 1];
|
||||
$("#currentStatus").text(orderStatusName);
|
||||
$("#sum").val(result.sum);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
</script> *@
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - GarmentFactoryClientApp</title>
|
||||
<title>@ViewData["Title"] - ComputerShopImplementerApp</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
@ -32,6 +32,16 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Requests">Заявки</a>
|
||||
</li>
|
||||
|
||||
|
||||
@* !!!СЮДА ВСТАВИТЬ 2 ССЫЛКИ НА СТРАНИЦЫ С ПОЛУЧЕНИЕМ ОТЧЁТОВ *@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportOrdersAssembliesToFile">Отчёт по заказам в файле</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||
</li>
|
||||
|
@ -16,10 +16,13 @@ namespace ComputerShopRestApi.Controllers
|
||||
|
||||
private readonly IOrderLogic _logic;
|
||||
|
||||
public OrderController(IOrderLogic logic, ILogger<OrderController> logger)
|
||||
private readonly IReportImplementerLogic _reportLogic;
|
||||
|
||||
public OrderController(IOrderLogic logic, ILogger<OrderController> logger, IReportImplementerLogic reportLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_reportLogic = reportLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -58,6 +61,34 @@ namespace ComputerShopRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportToWordFile(ReportBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportLogic.SaveReportOrderAssembliesToWordFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportLogic.SaveReportOrderAssembliesToExcelFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
//МБ ИЗМЕНИТЬ IEnumerable на List
|
||||
//!!!ПОТОМ УДАЛИТЬ
|
||||
//[HttpGet]
|
||||
|
@ -74,11 +74,11 @@ namespace ComputerShopRestApi.Controllers
|
||||
|
||||
//параметры для удобного использования в swagger, потом скорее всего будет передаваться RequestBindingModel model
|
||||
[HttpPost]
|
||||
public void ConnectRequestAssembly(int requestId, int assemblyId)
|
||||
public void ConnectRequestAssembly(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.ConnectRequestAssembly(new RequestBindingModel { Id = requestId, AssemblyId = assemblyId });
|
||||
_logic.ConnectRequestAssembly(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -4,6 +4,8 @@ using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopDatabaseImplement.Implements;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using ComputerShopDataModels.Models;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.Implements;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
var Builder = WebApplication.CreateBuilder(args);
|
||||
@ -31,8 +33,12 @@ Builder.Services.AddTransient<IAssemblyLogic, AssemblyLogic>();
|
||||
Builder.Services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
Builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||
|
||||
Builder.Services.AddTransient<IReportImplementerLogic, ReportImplementerLogic>();
|
||||
Builder.Services.AddTransient<IReportGuarantorLogic, ReportGuarantorLogic>();
|
||||
|
||||
Builder.Services.AddTransient<AbstractSaveToExcelImplementer, SaveToExcelImplementer>();
|
||||
Builder.Services.AddTransient<AbstractSaveToWordImplementer, SaveToWordImplementer>();
|
||||
Builder.Services.AddTransient<AbstractSaveToPdfImplementer, SaveToPdfImplementer>();
|
||||
|
||||
Builder.Services.AddControllers();
|
||||
Builder.Services.AddEndpointsApiExplorer();
|
||||
|
Loading…
Reference in New Issue
Block a user