Прайс-лист
This commit is contained in:
parent
6a6aabdf86
commit
146deadf89
@ -20,13 +20,15 @@ namespace BusinessLogic.BusinessLogic
|
||||
private readonly IMediaFileStorage _mediaFileStorage;
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
private readonly AbstractSaveToPdfCheque _saveToCheque;
|
||||
public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf, AbstractSaveToPdfCheque saveToPdfCheque, IMediaFileStorage mediaFileStorage)
|
||||
private readonly AbstractSaveToPdfPricelist _savePricelist;
|
||||
public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf, AbstractSaveToPdfCheque saveToPdfCheque, IMediaFileStorage mediaFileStorage, AbstractSaveToPdfPricelist savePricelist)
|
||||
{
|
||||
_productStorage = productStorage;
|
||||
_supplyStorage = supplyStorage;
|
||||
_saveToPdf = saveToPdf;
|
||||
_saveToCheque = saveToPdfCheque;
|
||||
_mediaFileStorage = mediaFileStorage;
|
||||
_savePricelist = savePricelist;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||||
@ -88,5 +90,15 @@ namespace BusinessLogic.BusinessLogic
|
||||
//MediaFiles = _mediaFileStorage.GetFilteredList(new MediaFileSearchModel() { ProductId = model.ProductId })
|
||||
});
|
||||
}
|
||||
public void SavePriceListToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_savePricelist.CreateDoc(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Прайс-лист",
|
||||
Date = model.Date,
|
||||
Products = _productStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
BusinessLogic/OfficePackage/AbstractSaveToPdfPricelist.cs
Normal file
51
BusinessLogic/OfficePackage/AbstractSaveToPdfPricelist.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using BusinessLogic.OfficePackage.HelperEnums;
|
||||
using BusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdfPricelist
|
||||
{
|
||||
public void CreateDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"{info.Title}\nОт {info.Date}",
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = "Товары",
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateTable(new List<string> { "5cm", "5cm", "3cm", "2cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Id", "Название", "Цена", "Кол-во на складе" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
foreach (var product in info.Products)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { product.Id.ToString(), product.Name, product.Price.ToString(), product.Amount.ToString() },
|
||||
});
|
||||
}
|
||||
SavePdf(info);
|
||||
}
|
||||
protected abstract void CreatePdf(PdfInfo info);
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
protected abstract void CreateImage(string path);
|
||||
protected abstract void SavePdf(PdfInfo info);
|
||||
}
|
||||
}
|
@ -15,5 +15,6 @@ namespace BusinessLogic.OfficePackage.HelperModels
|
||||
public SupplyViewModel? Supply { get; set; } = new();
|
||||
public ProductViewModel? Product { get; set; } = new();
|
||||
public List<MediaFileViewModel>? MediaFiles { get; set; } = new();
|
||||
public List<ProductViewModel>? Products { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
115
BusinessLogic/OfficePackage/Implements/SaveToPdfPricelist.cs
Normal file
115
BusinessLogic/OfficePackage/Implements/SaveToPdfPricelist.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using BusinessLogic.OfficePackage.HelperEnums;
|
||||
using BusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToPdfPricelist : AbstractSaveToPdfPricelist
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
private Image _image;
|
||||
private static ParagraphAlignment
|
||||
GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание стилей для документа
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
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(PdfInfo 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 CreateImage(string path)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_document.LastSection.AddImage(path);
|
||||
}
|
||||
protected override void SavePdf(PdfInfo info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,5 +21,6 @@ namespace Contracts.BusinessLogicContracts
|
||||
/// <param name="model"></param>
|
||||
void SaveSuppliesToPdfFile(ReportBindingModel model);
|
||||
void SaveProductToPdfFile(ReportBindingModel model);
|
||||
void SavePriceListToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
29
WinFormsApp/FormProducts.Designer.cs
generated
29
WinFormsApp/FormProducts.Designer.cs
generated
@ -31,6 +31,7 @@
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreateProduct = new Button();
|
||||
groupBoxControls = new GroupBox();
|
||||
buttonPrintCheque = new Button();
|
||||
buttonReadBarCode = new Button();
|
||||
pictureBox1 = new PictureBox();
|
||||
buttonGenerateBarCode = new Button();
|
||||
@ -45,7 +46,7 @@
|
||||
textBoxName = new TextBox();
|
||||
menuStrip1 = new MenuStrip();
|
||||
медиаФайлыToolStripMenuItem = new ToolStripMenuItem();
|
||||
buttonPrintCheque = new Button();
|
||||
прайслистToolStripMenuItem = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
groupBoxControls.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
@ -95,6 +96,16 @@
|
||||
groupBoxControls.TabStop = false;
|
||||
groupBoxControls.Text = "Действия";
|
||||
//
|
||||
// buttonPrintCheque
|
||||
//
|
||||
buttonPrintCheque.Location = new Point(80, 425);
|
||||
buttonPrintCheque.Name = "buttonPrintCheque";
|
||||
buttonPrintCheque.Size = new Size(108, 45);
|
||||
buttonPrintCheque.TabIndex = 7;
|
||||
buttonPrintCheque.Text = "Распечатать чек";
|
||||
buttonPrintCheque.UseVisualStyleBackColor = true;
|
||||
buttonPrintCheque.Click += buttonPrintCheque_Click;
|
||||
//
|
||||
// buttonReadBarCode
|
||||
//
|
||||
buttonReadBarCode.Location = new Point(69, 335);
|
||||
@ -216,7 +227,7 @@
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { медиаФайлыToolStripMenuItem });
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { медиаФайлыToolStripMenuItem, прайслистToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(925, 24);
|
||||
@ -230,15 +241,12 @@
|
||||
медиаФайлыToolStripMenuItem.Text = "Медиа файлы";
|
||||
медиаФайлыToolStripMenuItem.Click += медиаФайлыToolStripMenuItem_Click;
|
||||
//
|
||||
// buttonPrintCheque
|
||||
// прайслистToolStripMenuItem
|
||||
//
|
||||
buttonPrintCheque.Location = new Point(80, 425);
|
||||
buttonPrintCheque.Name = "buttonPrintCheque";
|
||||
buttonPrintCheque.Size = new Size(108, 45);
|
||||
buttonPrintCheque.TabIndex = 7;
|
||||
buttonPrintCheque.Text = "Распечатать чек";
|
||||
buttonPrintCheque.UseVisualStyleBackColor = true;
|
||||
buttonPrintCheque.Click += buttonPrintCheque_Click;
|
||||
прайслистToolStripMenuItem.Name = "прайслистToolStripMenuItem";
|
||||
прайслистToolStripMenuItem.Size = new Size(84, 20);
|
||||
прайслистToolStripMenuItem.Text = "Прайс-лист";
|
||||
прайслистToolStripMenuItem.Click += прайслистToolStripMenuItem_Click;
|
||||
//
|
||||
// FormProducts
|
||||
//
|
||||
@ -286,5 +294,6 @@
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem медиаФайлыToolStripMenuItem;
|
||||
private Button buttonPrintCheque;
|
||||
private ToolStripMenuItem прайслистToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -281,21 +281,52 @@ namespace WinFormsApp
|
||||
if (service is FormPreviewPDF form)
|
||||
{
|
||||
var src = $"productcheque{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf";
|
||||
try
|
||||
{
|
||||
_reportLogic.SaveProductToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = $"productcheque{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
|
||||
ProductId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value,
|
||||
});
|
||||
_logger.LogInformation("Сохранение чека о товаре");
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения чека");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
try
|
||||
{
|
||||
_reportLogic.SaveProductToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = $"productcheque{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
|
||||
ProductId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value,
|
||||
});
|
||||
_logger.LogInformation("Сохранение чека о товаре");
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения чека");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
form.src = System.IO.Path.GetFullPath(src);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
IronPrint.Printer.PrintAsync(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void прайслистToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPreviewPDF));
|
||||
if (service is FormPreviewPDF form)
|
||||
{
|
||||
var date = DateTime.Now;
|
||||
var src = $"pricelist{date.Year}{date.Month}{date.Day}.pdf";
|
||||
try
|
||||
{
|
||||
_reportLogic.SavePriceListToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = $"pricelist{date.Year}{date.Month}{date.Day}.pdf",
|
||||
Date = date,
|
||||
});
|
||||
_logger.LogInformation("Сохранение прайс-листа");
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения прайс-листа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
form.src = System.IO.Path.GetFullPath(src);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ namespace WinFormsApp
|
||||
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddTransient<AbstractSaveToPdfCheque, SaveToPdfCheque>();
|
||||
services.AddTransient<AbstractSaveToPdfPricelist, SaveToPdfPricelist>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProducts>();
|
||||
|
Loading…
Reference in New Issue
Block a user