Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW
This commit is contained in:
commit
1dd2a00964
@ -13,7 +13,8 @@ namespace BusinessLogic.BusinessLogic
|
||||
public GeneratedBarcode CreateBarcode(ProductBindingModel model, bool save)
|
||||
{
|
||||
var barCode = IronBarCode.BarcodeWriter.CreateBarcode(model.Id.ToString(), BarcodeEncoding.Code128);
|
||||
if (save) return barCode.SaveAsPng($"product{model.Id}.png");
|
||||
var path = $"product{model.Id}.png";
|
||||
if (save) return barCode.SaveAsPng(path);
|
||||
return barCode;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ namespace DatabaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Server=192.168.191.42:32768;Database=gun_market;Username=postgres;Password=7355608;");
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
|
||||
optionsBuilder.UseNpgsql("Server=192.168.191.42:32768;Database=gun_market;Username=postgres;Password=7355608;");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ namespace DatabaseImplement.Implements
|
||||
product.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return product.GetViewModel;
|
||||
return new();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
11
WinFormsApp/FormMain.Designer.cs
generated
11
WinFormsApp/FormMain.Designer.cs
generated
@ -41,6 +41,7 @@
|
||||
printPreviewDialog = new PrintPreviewDialog();
|
||||
printDialog = new PrintDialog();
|
||||
buttonRefresh = new Button();
|
||||
статистикаToolStripMenuItem = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
@ -66,7 +67,7 @@
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, поставщикиToolStripMenuItem });
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, поставщикиToolStripMenuItem, статистикаToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(901, 24);
|
||||
@ -151,6 +152,13 @@
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// статистикаToolStripMenuItem
|
||||
//
|
||||
статистикаToolStripMenuItem.Name = "статистикаToolStripMenuItem";
|
||||
статистикаToolStripMenuItem.Size = new Size(80, 20);
|
||||
статистикаToolStripMenuItem.Text = "Статистика";
|
||||
статистикаToolStripMenuItem.Click += статистикаToolStripMenuItem_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -189,5 +197,6 @@
|
||||
private PrintPreviewDialog printPreviewDialog;
|
||||
private PrintDialog printDialog;
|
||||
private Button buttonRefresh;
|
||||
private ToolStripMenuItem статистикаToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -153,22 +153,22 @@ namespace WinFormsApp
|
||||
MessageBox.Show("Выберите одну поставку для формирования отчета", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
try
|
||||
{
|
||||
_reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel
|
||||
{
|
||||
_reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
|
||||
Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value,
|
||||
SupplyId = (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);
|
||||
}
|
||||
FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
|
||||
Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value,
|
||||
SupplyId = (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);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonPrintReport_Click(object sender, EventArgs e)
|
||||
@ -214,5 +214,14 @@ namespace WinFormsApp
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void статистикаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStatistics));
|
||||
if (service is FormStatistics form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
WinFormsApp/FormProducts.Designer.cs
generated
22
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();
|
||||
@ -60,8 +61,11 @@
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(0, 24);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(602, 622);
|
||||
dataGridView.TabIndex = 0;
|
||||
dataGridView.SelectionChanged += dataGridView_SelectionChanged;
|
||||
//
|
||||
// buttonCreateProduct
|
||||
//
|
||||
@ -76,6 +80,7 @@
|
||||
// groupBoxControls
|
||||
//
|
||||
groupBoxControls.BackColor = Color.Transparent;
|
||||
groupBoxControls.Controls.Add(buttonPrintCheque);
|
||||
groupBoxControls.Controls.Add(buttonReadBarCode);
|
||||
groupBoxControls.Controls.Add(pictureBox1);
|
||||
groupBoxControls.Controls.Add(buttonGenerateBarCode);
|
||||
@ -92,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;
|
||||
@ -102,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;
|
||||
//
|
||||
@ -225,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);
|
||||
@ -270,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)
|
||||
@ -100,12 +102,16 @@ namespace WinFormsApp
|
||||
IsBeingSold = checkBoxIsSold.Checked,
|
||||
};
|
||||
var operationResult = _id.HasValue ? _productLogic.Update(model) : _productLogic.Create(model);
|
||||
var lastProductCreated = _productLogic.ReadList(null).Last();
|
||||
_barcodeLogic.CreateBarcode(new ProductBindingModel()
|
||||
if (!_id.HasValue)
|
||||
{
|
||||
Id = lastProductCreated.Id,
|
||||
Name = lastProductCreated.Name,
|
||||
}, true);
|
||||
var lastProductCreated = _productLogic.ReadList(null).Last();
|
||||
_barcodeLogic.CreateBarcode(new ProductBindingModel()
|
||||
{
|
||||
Id = lastProductCreated.Id,
|
||||
Name = lastProductCreated.Name,
|
||||
}, true);
|
||||
|
||||
}
|
||||
_id = null;
|
||||
if (!operationResult)
|
||||
{
|
||||
@ -123,9 +129,9 @@ namespace WinFormsApp
|
||||
finally
|
||||
{
|
||||
LoadData();
|
||||
groupBoxControls.Enabled = true;
|
||||
//groupBoxControls.Enabled = true;
|
||||
groupBoxControls.Show();
|
||||
groupBoxCreateProduct.Enabled = false;
|
||||
//groupBoxCreateProduct.Enabled = false;
|
||||
groupBoxCreateProduct.Hide();
|
||||
textBoxName.Text = string.Empty;
|
||||
numericUpDownAmount.Value = 0;
|
||||
@ -230,6 +236,7 @@ namespace WinFormsApp
|
||||
numericUpDownPrice.Value = Convert.ToDecimal(product.Price);
|
||||
numericUpDownAmount.Value = product.Amount;
|
||||
checkBoxIsSold.Checked = product.IsBeingSold;
|
||||
_id = product.Id;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -246,5 +253,55 @@ namespace WinFormsApp
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (!File.Exists($"product{dataGridView.SelectedRows[0].Cells["Id"].Value}.png"))
|
||||
{
|
||||
var barcode = _barcodeLogic.CreateBarcode(new ProductBindingModel()
|
||||
{
|
||||
Id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value,
|
||||
Name = Convert.ToString(dataGridView.SelectedRows[0].Cells["Name"].Value),
|
||||
}, true);
|
||||
pictureBox1.Image = barcode.Image;
|
||||
}
|
||||
else
|
||||
{
|
||||
pictureBox1.Image = new Bitmap($"product{dataGridView.SelectedRows[0].Cells["Id"].Value}.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
171
WinFormsApp/FormStatistics.Designer.cs
generated
Normal file
171
WinFormsApp/FormStatistics.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
namespace WinFormsApp
|
||||
{
|
||||
partial class FormStatistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
|
||||
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
|
||||
chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
|
||||
dateTimePickerTo = new DateTimePicker();
|
||||
dateTimePickerFrom = new DateTimePicker();
|
||||
panel1 = new Panel();
|
||||
checkBoxPending = new CheckBox();
|
||||
checkBoxArriving = new CheckBox();
|
||||
checkBoxCompleted = new CheckBox();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)chart).BeginInit();
|
||||
panel1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// chart
|
||||
//
|
||||
chartArea1.Name = "ChartArea1";
|
||||
chart.ChartAreas.Add(chartArea1);
|
||||
chart.Dock = DockStyle.Bottom;
|
||||
legend1.Name = "Legend1";
|
||||
chart.Legends.Add(legend1);
|
||||
chart.Location = new Point(0, 30);
|
||||
chart.Name = "chart";
|
||||
chart.Size = new Size(800, 420);
|
||||
chart.TabIndex = 0;
|
||||
chart.Text = "chart1";
|
||||
chart.Click += chart_Click;
|
||||
//
|
||||
// dateTimePickerTo
|
||||
//
|
||||
dateTimePickerTo.Location = new Point(24, -1);
|
||||
dateTimePickerTo.Name = "dateTimePickerTo";
|
||||
dateTimePickerTo.Size = new Size(200, 23);
|
||||
dateTimePickerTo.TabIndex = 1;
|
||||
dateTimePickerTo.ValueChanged += dateTimePickerFrom_ValueChanged;
|
||||
//
|
||||
// dateTimePickerFrom
|
||||
//
|
||||
dateTimePickerFrom.Location = new Point(262, -1);
|
||||
dateTimePickerFrom.Name = "dateTimePickerFrom";
|
||||
dateTimePickerFrom.Size = new Size(200, 23);
|
||||
dateTimePickerFrom.TabIndex = 2;
|
||||
dateTimePickerFrom.ValueChanged += dateTimePickerTo_ValueChanged;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.BorderStyle = BorderStyle.FixedSingle;
|
||||
panel1.Controls.Add(checkBoxPending);
|
||||
panel1.Controls.Add(checkBoxArriving);
|
||||
panel1.Controls.Add(checkBoxCompleted);
|
||||
panel1.Controls.Add(label2);
|
||||
panel1.Controls.Add(label1);
|
||||
panel1.Controls.Add(dateTimePickerFrom);
|
||||
panel1.Controls.Add(dateTimePickerTo);
|
||||
panel1.Dock = DockStyle.Top;
|
||||
panel1.Location = new Point(0, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(800, 24);
|
||||
panel1.TabIndex = 3;
|
||||
//
|
||||
// checkBoxPending
|
||||
//
|
||||
checkBoxPending.AutoSize = true;
|
||||
checkBoxPending.Location = new Point(481, 3);
|
||||
checkBoxPending.Name = "checkBoxPending";
|
||||
checkBoxPending.Size = new Size(92, 19);
|
||||
checkBoxPending.TabIndex = 7;
|
||||
checkBoxPending.Text = "В ожидании";
|
||||
checkBoxPending.UseVisualStyleBackColor = true;
|
||||
checkBoxPending.CheckedChanged += checkBoxPending_CheckedChanged;
|
||||
//
|
||||
// checkBoxArriving
|
||||
//
|
||||
checkBoxArriving.AutoSize = true;
|
||||
checkBoxArriving.Location = new Point(590, 3);
|
||||
checkBoxArriving.Name = "checkBoxArriving";
|
||||
checkBoxArriving.Size = new Size(61, 19);
|
||||
checkBoxArriving.TabIndex = 6;
|
||||
checkBoxArriving.Text = "В пути";
|
||||
checkBoxArriving.UseVisualStyleBackColor = true;
|
||||
checkBoxArriving.CheckedChanged += checkBoxArriving_CheckedChanged;
|
||||
//
|
||||
// checkBoxCompleted
|
||||
//
|
||||
checkBoxCompleted.AutoSize = true;
|
||||
checkBoxCompleted.Location = new Point(668, 4);
|
||||
checkBoxCompleted.Name = "checkBoxCompleted";
|
||||
checkBoxCompleted.Size = new Size(104, 19);
|
||||
checkBoxCompleted.TabIndex = 5;
|
||||
checkBoxCompleted.Text = "Завершенные";
|
||||
checkBoxCompleted.UseVisualStyleBackColor = true;
|
||||
checkBoxCompleted.CheckedChanged += checkBoxCompleted_CheckedChanged;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(230, 5);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(26, 15);
|
||||
label2.TabIndex = 4;
|
||||
label2.Text = "По:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(3, 5);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(18, 15);
|
||||
label1.TabIndex = 3;
|
||||
label1.Text = "С:";
|
||||
//
|
||||
// FormStatistics
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(panel1);
|
||||
Controls.Add(chart);
|
||||
Name = "FormStatistics";
|
||||
Text = "FormStatistics";
|
||||
Load += FormStatistics_Load;
|
||||
((System.ComponentModel.ISupportInitialize)chart).EndInit();
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataVisualization.Charting.Chart chart;
|
||||
private DateTimePicker dateTimePickerTo;
|
||||
private DateTimePicker dateTimePickerFrom;
|
||||
private Panel panel1;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private CheckBox checkBoxPending;
|
||||
private CheckBox checkBoxArriving;
|
||||
private CheckBox checkBoxCompleted;
|
||||
}
|
||||
}
|
126
WinFormsApp/FormStatistics.cs
Normal file
126
WinFormsApp/FormStatistics.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.SearchModels;
|
||||
using DataModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.DataVisualization.Charting;
|
||||
|
||||
namespace WinFormsApp
|
||||
{
|
||||
public partial class FormStatistics : Form
|
||||
{
|
||||
ISupplyLogic _supplyLogic;
|
||||
public FormStatistics(ISupplyLogic supplyLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_supplyLogic = supplyLogic;
|
||||
}
|
||||
|
||||
private void FormStatistics_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
chart.Series.Clear();
|
||||
var list = _supplyLogic.ReadList(new SupplySearchModel()
|
||||
{
|
||||
DateStart = dateTimePickerTo.Value,
|
||||
DateEnd = dateTimePickerFrom.Value,
|
||||
});
|
||||
if (checkBoxPending.Checked)
|
||||
{
|
||||
var date = dateTimePickerTo.Value;
|
||||
chart.Series.Add("Pending");
|
||||
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);
|
||||
date = date.AddMonths(1);
|
||||
}
|
||||
}
|
||||
if (checkBoxArriving.Checked)
|
||||
{
|
||||
var date = dateTimePickerTo.Value;
|
||||
chart.Series.Add("Arriving");
|
||||
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);
|
||||
date = date.AddMonths(1);
|
||||
}
|
||||
}
|
||||
if (checkBoxCompleted.Checked)
|
||||
{
|
||||
var date = dateTimePickerTo.Value;
|
||||
chart.Series.Add("Completed");
|
||||
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);
|
||||
date = date.AddMonths(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chart_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void dateTimePickerFrom_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void dateTimePickerTo_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private int diff_month(DateTime d1, DateTime d2)
|
||||
{
|
||||
return (d1.Year - d2.Year) * 12 + d1.Month - d2.Month;
|
||||
}
|
||||
|
||||
private void checkBoxPending_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void checkBoxArriving_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void checkBoxCompleted_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsApp/FormStatistics.resx
Normal file
120
WinFormsApp/FormStatistics.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -52,6 +52,7 @@ namespace WinFormsApp
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddTransient<AbstractSaveToPdfCheque, SaveToPdfCheque>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProducts>();
|
||||
@ -62,7 +63,7 @@ namespace WinFormsApp
|
||||
services.AddTransient<FormSupplierProduct>();
|
||||
services.AddTransient<FormMediaFiles>();
|
||||
services.AddTransient<FormPreviewPDF>();
|
||||
|
||||
services.AddTransient<FormStatistics>();
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
|
||||
<PackageReference Include="Spire.PDF" Version="10.6.7" />
|
||||
<PackageReference Include="WinForms.DataVisualization" Version="1.9.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user