Создание и чтение (получение товара) штрих-кодов
This commit is contained in:
parent
da4de1eb95
commit
f8f28c3cfd
@ -11,6 +11,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="BarCode" Version="2024.6.1" />
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
|
||||||
|
19
BusinessLogic/BusinessLogic/BarcodeLogic.cs
Normal file
19
BusinessLogic/BusinessLogic/BarcodeLogic.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Contracts.BindingModels;
|
||||||
|
using IronBarCode;
|
||||||
|
|
||||||
|
namespace BusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class BarcodeLogic
|
||||||
|
{
|
||||||
|
public GeneratedBarcode CreateBarcode(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
var barCode = IronBarCode.BarcodeWriter.CreateBarcode(model.Id.ToString(), BarcodeEncoding.Code128);
|
||||||
|
return barCode.SaveAsPng($"product{model.Id}.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
WinFormsApp/FormProducts.Designer.cs
generated
39
WinFormsApp/FormProducts.Designer.cs
generated
@ -31,6 +31,9 @@
|
|||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
buttonCreateProduct = new Button();
|
buttonCreateProduct = new Button();
|
||||||
groupBoxControls = new GroupBox();
|
groupBoxControls = new GroupBox();
|
||||||
|
buttonReadBarCode = new Button();
|
||||||
|
pictureBox1 = new PictureBox();
|
||||||
|
buttonGenerateBarCode = new Button();
|
||||||
buttonDeleteProduct = new Button();
|
buttonDeleteProduct = new Button();
|
||||||
buttonUpdateProduct = new Button();
|
buttonUpdateProduct = new Button();
|
||||||
groupBoxCreateProduct = new GroupBox();
|
groupBoxCreateProduct = new GroupBox();
|
||||||
@ -42,6 +45,7 @@
|
|||||||
textBoxName = new TextBox();
|
textBoxName = new TextBox();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
groupBoxControls.SuspendLayout();
|
groupBoxControls.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||||
groupBoxCreateProduct.SuspendLayout();
|
groupBoxCreateProduct.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
||||||
@ -69,6 +73,9 @@
|
|||||||
// groupBoxControls
|
// groupBoxControls
|
||||||
//
|
//
|
||||||
groupBoxControls.BackColor = Color.Transparent;
|
groupBoxControls.BackColor = Color.Transparent;
|
||||||
|
groupBoxControls.Controls.Add(buttonReadBarCode);
|
||||||
|
groupBoxControls.Controls.Add(pictureBox1);
|
||||||
|
groupBoxControls.Controls.Add(buttonGenerateBarCode);
|
||||||
groupBoxControls.Controls.Add(buttonDeleteProduct);
|
groupBoxControls.Controls.Add(buttonDeleteProduct);
|
||||||
groupBoxControls.Controls.Add(buttonUpdateProduct);
|
groupBoxControls.Controls.Add(buttonUpdateProduct);
|
||||||
groupBoxControls.Controls.Add(buttonCreateProduct);
|
groupBoxControls.Controls.Add(buttonCreateProduct);
|
||||||
@ -80,6 +87,34 @@
|
|||||||
groupBoxControls.TabStop = false;
|
groupBoxControls.TabStop = false;
|
||||||
groupBoxControls.Text = "Действия";
|
groupBoxControls.Text = "Действия";
|
||||||
//
|
//
|
||||||
|
// buttonReadBarCode
|
||||||
|
//
|
||||||
|
buttonReadBarCode.Location = new Point(69, 379);
|
||||||
|
buttonReadBarCode.Name = "buttonReadBarCode";
|
||||||
|
buttonReadBarCode.Size = new Size(139, 52);
|
||||||
|
buttonReadBarCode.TabIndex = 6;
|
||||||
|
buttonReadBarCode.Text = "Получить товар по штрих-коду";
|
||||||
|
buttonReadBarCode.UseVisualStyleBackColor = true;
|
||||||
|
buttonReadBarCode.Click += buttonReadBarCode_Click;
|
||||||
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
pictureBox1.Location = new Point(69, 235);
|
||||||
|
pictureBox1.Name = "pictureBox1";
|
||||||
|
pictureBox1.Size = new Size(139, 112);
|
||||||
|
pictureBox1.TabIndex = 5;
|
||||||
|
pictureBox1.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonGenerateBarCode
|
||||||
|
//
|
||||||
|
buttonGenerateBarCode.Location = new Point(69, 153);
|
||||||
|
buttonGenerateBarCode.Name = "buttonGenerateBarCode";
|
||||||
|
buttonGenerateBarCode.Size = new Size(139, 52);
|
||||||
|
buttonGenerateBarCode.TabIndex = 4;
|
||||||
|
buttonGenerateBarCode.Text = "Сгенерировать штрих-код товара";
|
||||||
|
buttonGenerateBarCode.UseVisualStyleBackColor = true;
|
||||||
|
buttonGenerateBarCode.Click += buttonGenerateBarCode_Click;
|
||||||
|
//
|
||||||
// buttonDeleteProduct
|
// buttonDeleteProduct
|
||||||
//
|
//
|
||||||
buttonDeleteProduct.Location = new Point(69, 102);
|
buttonDeleteProduct.Location = new Point(69, 102);
|
||||||
@ -184,6 +219,7 @@
|
|||||||
Load += FormProducts_Load;
|
Load += FormProducts_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
groupBoxControls.ResumeLayout(false);
|
groupBoxControls.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||||
groupBoxCreateProduct.ResumeLayout(false);
|
groupBoxCreateProduct.ResumeLayout(false);
|
||||||
groupBoxCreateProduct.PerformLayout();
|
groupBoxCreateProduct.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
|
||||||
@ -205,5 +241,8 @@
|
|||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
private Button buttonUpdateProduct;
|
private Button buttonUpdateProduct;
|
||||||
private Button buttonDeleteProduct;
|
private Button buttonDeleteProduct;
|
||||||
|
private Button buttonGenerateBarCode;
|
||||||
|
private PictureBox pictureBox1;
|
||||||
|
private Button buttonReadBarCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using Contracts.BindingModels;
|
using Contracts.BindingModels;
|
||||||
using Contracts.BusinessLogicContracts;
|
using Contracts.BusinessLogicContracts;
|
||||||
using Contracts.SearchModels;
|
using Contracts.SearchModels;
|
||||||
|
using IronBarCode;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -21,11 +22,15 @@ namespace WinFormsApp
|
|||||||
private Guid? _id;
|
private Guid? _id;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IProductLogic _productLogic;
|
private readonly IProductLogic _productLogic;
|
||||||
|
private readonly BarcodeLogic _barcodeLogic;
|
||||||
|
private BarcodeResults? _barcode;
|
||||||
public FormProducts(ILogger<FormMain> logger, IProductLogic productLogic)
|
public FormProducts(ILogger<FormMain> logger, IProductLogic productLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_productLogic = productLogic;
|
_productLogic = productLogic;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_barcodeLogic = new BarcodeLogic();
|
||||||
|
_barcode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormProducts_Load(object sender, EventArgs e)
|
private void FormProducts_Load(object sender, EventArgs e)
|
||||||
@ -124,7 +129,7 @@ namespace WinFormsApp
|
|||||||
|
|
||||||
private void buttonUpdateProduct_Click(object sender, EventArgs e)
|
private void buttonUpdateProduct_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count <= 0) return;
|
if (dataGridView.SelectedRows.Count != 1) return;
|
||||||
_id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
_id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
||||||
groupBoxControls.Hide();
|
groupBoxControls.Hide();
|
||||||
groupBoxCreateProduct.Show();
|
groupBoxCreateProduct.Show();
|
||||||
@ -181,5 +186,49 @@ namespace WinFormsApp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonGenerateBarCode_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var barcode = _barcodeLogic.CreateBarcode(new ProductBindingModel()
|
||||||
|
{
|
||||||
|
Id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value,
|
||||||
|
Name = Convert.ToString(dataGridView.SelectedRows[0].Cells["Name"].Value),
|
||||||
|
});
|
||||||
|
pictureBox1.Image = barcode.Image;
|
||||||
|
_barcode = BarcodeReader.Read($"product{barcode.Value}.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonReadBarCode_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var dialog = new OpenFileDialog();
|
||||||
|
dialog.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp";
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
pictureBox1.Image = new Bitmap(dialog.FileName);
|
||||||
|
_barcode = BarcodeReader.Read(dialog.FileName);
|
||||||
|
Debug.WriteLine(_barcode.ToList()[0]);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var product = _productLogic.ReadElement(new ProductSearchModel()
|
||||||
|
{
|
||||||
|
Id = new Guid(_barcode.ToList()[0].Text),
|
||||||
|
});
|
||||||
|
groupBoxControls.Hide();
|
||||||
|
groupBoxCreateProduct.Show();
|
||||||
|
_logger.LogInformation("Получение товара");
|
||||||
|
textBoxName.Text = product.Name;
|
||||||
|
numericUpDownPrice.Value = Convert.ToDecimal(product.Price);
|
||||||
|
numericUpDownAmount.Value = product.Amount;
|
||||||
|
checkBoxIsSold.Checked = product.IsBeingSold;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Ошибка получения товара по штрихкоду");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user