чек на отдельный товар
This commit is contained in:
parent
472b98ba57
commit
5678ff27d5
@ -17,12 +17,16 @@ namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly IProductStorage _productStorage;
|
||||
private readonly ISupplyStorage _supplyStorage;
|
||||
private readonly IMediaFileStorage _mediaFileStorage;
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf)
|
||||
private readonly AbstractSaveToPdfCheque _saveToCheque;
|
||||
public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf, AbstractSaveToPdfCheque saveToPdfCheque, IMediaFileStorage mediaFileStorage)
|
||||
{
|
||||
_productStorage = productStorage;
|
||||
_supplyStorage = supplyStorage;
|
||||
_saveToPdf = saveToPdf;
|
||||
_saveToCheque = saveToPdfCheque;
|
||||
_mediaFileStorage = mediaFileStorage;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||||
@ -70,5 +74,19 @@ namespace BusinessLogic.BusinessLogic
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveProductToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToCheque.CreateDoc(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Чек на товар",
|
||||
Product = _productStorage.GetElement(new ProductSearchModel()
|
||||
{
|
||||
Id = model.ProductId
|
||||
}),
|
||||
//MediaFiles = _mediaFileStorage.GetFilteredList(new MediaFileSearchModel() { ProductId = model.ProductId })
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
57
BusinessLogic/OfficePackage/AbstractSaveToPdfCheque.cs
Normal file
57
BusinessLogic/OfficePackage/AbstractSaveToPdfCheque.cs
Normal file
@ -0,0 +1,57 @@
|
||||
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 AbstractSaveToPdfCheque
|
||||
{
|
||||
public void CreateDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"{info.Title}\nНа товар {info.Product.Name}",
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"Id: {info.Product.Id}",
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Right
|
||||
});
|
||||
//CreateParagraph(new PdfParagraph
|
||||
//{
|
||||
// Text = "Список прилагаемых файлов",
|
||||
// Style = "NormalTitle",
|
||||
// ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
//});
|
||||
//CreateTable(new List<string> { "10cm", "5cm" });
|
||||
//CreateRow(new PdfRowParameters
|
||||
//{
|
||||
// Texts = new List<string> { "Название", "расширение" },
|
||||
// Style = "NormalTitle",
|
||||
// ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
//});
|
||||
CreateImage($"product{info.Product.Id}.png");
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"Цена: {info.Product.Price}",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Right
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
@ -11,7 +11,9 @@ namespace BusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime Date { get; set; }
|
||||
public SupplyViewModel Supply { get; set; } = new();
|
||||
public DateTime? Date { get; set; }
|
||||
public SupplyViewModel? Supply { get; set; } = new();
|
||||
public ProductViewModel? Product { get; set; } = new();
|
||||
public List<MediaFileViewModel>? MediaFiles { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
119
BusinessLogic/OfficePackage/Implements/SaveToPdfCheque.cs
Normal file
119
BusinessLogic/OfficePackage/Implements/SaveToPdfCheque.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using BusinessLogic.OfficePackage.HelperEnums;
|
||||
using BusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using PdfSharp.Drawing;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToPdfCheque : AbstractSaveToPdfCheque
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private PdfPage? _page;
|
||||
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;
|
||||
}
|
||||
XImage image = XImage.FromFile(path);
|
||||
_document.LastSection.AddImage(path);
|
||||
}
|
||||
protected override void SavePdf(PdfInfo info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ namespace Contracts.BindingModels
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? Date { get; set; }
|
||||
public Guid SupplyId { get; set; }
|
||||
public Guid? SupplyId { get; set; }
|
||||
public Guid? ProductId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,6 @@ namespace Contracts.BusinessLogicContracts
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveSuppliesToPdfFile(ReportBindingModel model);
|
||||
void SaveProductToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
19
WinFormsApp/FormProducts.Designer.cs
generated
19
WinFormsApp/FormProducts.Designer.cs
generated
@ -45,6 +45,7 @@
|
||||
textBoxName = new TextBox();
|
||||
menuStrip1 = new MenuStrip();
|
||||
медиаФайлыToolStripMenuItem = new ToolStripMenuItem();
|
||||
buttonPrintCheque = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
groupBoxControls.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
@ -79,6 +80,7 @@
|
||||
// groupBoxControls
|
||||
//
|
||||
groupBoxControls.BackColor = Color.Transparent;
|
||||
groupBoxControls.Controls.Add(buttonPrintCheque);
|
||||
groupBoxControls.Controls.Add(buttonReadBarCode);
|
||||
groupBoxControls.Controls.Add(pictureBox1);
|
||||
groupBoxControls.Controls.Add(buttonGenerateBarCode);
|
||||
@ -95,7 +97,7 @@
|
||||
//
|
||||
// buttonReadBarCode
|
||||
//
|
||||
buttonReadBarCode.Location = new Point(69, 379);
|
||||
buttonReadBarCode.Location = new Point(69, 335);
|
||||
buttonReadBarCode.Name = "buttonReadBarCode";
|
||||
buttonReadBarCode.Size = new Size(139, 52);
|
||||
buttonReadBarCode.TabIndex = 6;
|
||||
@ -105,9 +107,9 @@
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
pictureBox1.Location = new Point(69, 235);
|
||||
pictureBox1.Location = new Point(69, 210);
|
||||
pictureBox1.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(139, 112);
|
||||
pictureBox1.Size = new Size(139, 119);
|
||||
pictureBox1.TabIndex = 5;
|
||||
pictureBox1.TabStop = false;
|
||||
//
|
||||
@ -228,6 +230,16 @@
|
||||
медиаФайлыToolStripMenuItem.Text = "Медиа файлы";
|
||||
медиаФайлыToolStripMenuItem.Click += медиаФайлыToolStripMenuItem_Click;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// FormProducts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -273,5 +285,6 @@
|
||||
private Button buttonReadBarCode;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem медиаФайлыToolStripMenuItem;
|
||||
private Button buttonPrintCheque;
|
||||
}
|
||||
}
|
@ -22,10 +22,11 @@ namespace WinFormsApp
|
||||
private Guid? _id;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductLogic _productLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
private readonly BarcodeLogic _barcodeLogic;
|
||||
private BarcodeResults? _barcode;
|
||||
List<string> _mediaFiles;
|
||||
public FormProducts(ILogger<FormMain> logger, IProductLogic productLogic)
|
||||
public FormProducts(ILogger<FormMain> logger, IProductLogic productLogic, IReportLogic reportLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_productLogic = productLogic;
|
||||
@ -33,6 +34,7 @@ namespace WinFormsApp
|
||||
_barcodeLogic = new BarcodeLogic();
|
||||
_barcode = null;
|
||||
_mediaFiles = new List<string>();
|
||||
_reportLogic = reportLogic;
|
||||
}
|
||||
|
||||
private void FormProducts_Load(object sender, EventArgs e)
|
||||
@ -271,5 +273,35 @@ namespace WinFormsApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonPrintCheque_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPreviewPDF));
|
||||
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);
|
||||
}
|
||||
form.src = System.IO.Path.GetFullPath(src);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
IronPrint.Printer.PrintAsync(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,11 +42,12 @@ namespace WinFormsApp
|
||||
{
|
||||
var date = dateTimePickerTo.Value;
|
||||
chart.Series.Add("Pending");
|
||||
for (int i = 0; i < diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
||||
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
||||
{
|
||||
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Pending).ToList().Count;
|
||||
DataPoint dataPoint = new DataPoint();
|
||||
dataPoint.XValue = i;
|
||||
dataPoint.IsVisibleInLegend = false;
|
||||
dataPoint.Label = $"{date.Year}.{date.Month}";
|
||||
dataPoint.SetValueY(count);
|
||||
chart.Series["Pending"].Points.Add(dataPoint);
|
||||
@ -57,11 +58,12 @@ namespace WinFormsApp
|
||||
{
|
||||
var date = dateTimePickerTo.Value;
|
||||
chart.Series.Add("Arriving");
|
||||
for (int i = 0; i < diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
||||
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
||||
{
|
||||
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Arriving).ToList().Count;
|
||||
DataPoint dataPoint = new DataPoint();
|
||||
dataPoint.XValue = i;
|
||||
dataPoint.IsVisibleInLegend = false;
|
||||
dataPoint.Label = $"{date.Year}.{date.Month}";
|
||||
dataPoint.SetValueY(count);
|
||||
chart.Series["Arriving"].Points.Add(dataPoint);
|
||||
@ -72,11 +74,12 @@ namespace WinFormsApp
|
||||
{
|
||||
var date = dateTimePickerTo.Value;
|
||||
chart.Series.Add("Completed");
|
||||
for (int i = 0; i < diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
||||
for (int i = 0; i <= diff_month(dateTimePickerFrom.Value, dateTimePickerTo.Value); i++)
|
||||
{
|
||||
var count = list.Where(x => x.Date.Month == date.Month && x.Status == SupplyStatus.Completed).ToList().Count;
|
||||
DataPoint dataPoint = new DataPoint();
|
||||
dataPoint.XValue = i;
|
||||
dataPoint.IsVisibleInLegend = false;
|
||||
dataPoint.Label = $"{date.Year}.{date.Month}";
|
||||
dataPoint.SetValueY(count);
|
||||
chart.Series["Completed"].Points.Add(dataPoint);
|
||||
|
@ -52,6 +52,7 @@ namespace WinFormsApp
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddTransient<AbstractSaveToPdfCheque, SaveToPdfCheque>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProducts>();
|
||||
|
Loading…
Reference in New Issue
Block a user