Фиксация

This commit is contained in:
devil_1nc 2024-06-23 16:11:47 +04:00
commit 545ab2321e
11 changed files with 786 additions and 110 deletions

View File

@ -18,11 +18,11 @@ namespace DatabaseImplement.Implements
{
using var context = new Database();
var element = context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
@ -41,11 +41,11 @@ namespace DatabaseImplement.Implements
}
using var context = new Database();
return context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
@ -59,11 +59,11 @@ namespace DatabaseImplement.Implements
if (model.Price.HasValue)
{
return context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.Where(x => x.Price <= model.Price)
.ToList()
.Select(x => x.GetViewModel)
@ -72,11 +72,11 @@ namespace DatabaseImplement.Implements
if (model.Rate.HasValue)
{
return context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.Where(x => x.Rate <= model.Rate)
.ToList()
.Select(x => x.GetViewModel)
@ -85,22 +85,22 @@ namespace DatabaseImplement.Implements
if (model.Amount.HasValue && model.IsBeingSold.HasValue)
{
return context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.Where(x => x.IsBeingSold == model.IsBeingSold && x.Amount >= model.Amount)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.Where(x => x.Name == model.Name)
.ToList()
.Select(x => x.GetViewModel)
@ -111,11 +111,11 @@ namespace DatabaseImplement.Implements
{
using var context = new Database();
return context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
//.Include(x => x.Name)
//.Include(x => x.Price)
//.Include(x => x.IsBeingSold)
//.Include(x => x.Rate)
//.Include(x => x.Amount)
.ToList()
.Select(x => x.GetViewModel)
.ToList();

View File

@ -1,39 +0,0 @@
namespace WinFormsApp
{
partial class Form1
{
/// <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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace WinFormsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

98
WinFormsApp/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,98 @@
namespace WinFormsApp
{
partial class FormMain
{
/// <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()
{
dataGridView = new DataGridView();
buttonCreateSupply = new Button();
menuStrip1 = new MenuStrip();
товарыToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 28);
dataGridView.Name = "dataGridView";
dataGridView.Size = new Size(614, 321);
dataGridView.TabIndex = 0;
//
// buttonCreateSupply
//
buttonCreateSupply.Location = new Point(632, 28);
buttonCreateSupply.Name = "buttonCreateSupply";
buttonCreateSupply.Size = new Size(154, 23);
buttonCreateSupply.TabIndex = 1;
buttonCreateSupply.Text = "Оформить поставку";
buttonCreateSupply.UseVisualStyleBackColor = true;
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(798, 24);
menuStrip1.TabIndex = 2;
menuStrip1.Text = "menuStrip1";
//
// товарыToolStripMenuItem
//
товарыToolStripMenuItem.Name = оварыToolStripMenuItem";
товарыToolStripMenuItem.Size = new Size(60, 20);
товарыToolStripMenuItem.Text = "Товары";
товарыToolStripMenuItem.Click += товарыToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(798, 361);
Controls.Add(buttonCreateSupply);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormMain";
Text = "FormMain";
Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private DataGridView dataGridView;
private Button buttonCreateSupply;
private MenuStrip menuStrip1;
private ToolStripMenuItem товарыToolStripMenuItem;
}
}

64
WinFormsApp/FormMain.cs Normal file
View File

@ -0,0 +1,64 @@
using Contracts.BusinessLogicContracts;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsApp
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly ISupplyLogic _supplyLogic;
private readonly IProductLogic _productLogic;
private readonly ISupplierLogic _supplierLogic;
public FormMain(ILogger<FormMain> logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic)
{
InitializeComponent();
_supplierLogic = supplierLogic;
_supplyLogic = supplyLogic;
_productLogic = productLogic;
_logger = logger;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
_logger.LogInformation("Загрузка поставок");
try
{
var list = _supplyLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
}
_logger.LogInformation("Загрузка поставок");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки поставок");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void товарыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProducts));
if (service is FormProducts form)
{
form.ShowDialog();
}
}
}
}

123
WinFormsApp/FormMain.resx Normal file
View File

@ -0,0 +1,123 @@
<?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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

206
WinFormsApp/FormProducts.Designer.cs generated Normal file
View File

@ -0,0 +1,206 @@
namespace WinFormsApp
{
partial class FormProducts
{
/// <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()
{
dataGridView = new DataGridView();
buttonCreateProduct = new Button();
groupBoxControls = new GroupBox();
buttonUpdateProduct = new Button();
groupBoxCreateProduct = new GroupBox();
numericUpDownAmount = new NumericUpDown();
numericUpDownPrice = new NumericUpDown();
buttonCancel = new Button();
buttonSaveProduct = new Button();
checkBoxIsSold = new CheckBox();
textBoxName = new TextBox();
buttonDeleteProduct = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
groupBoxControls.SuspendLayout();
groupBoxCreateProduct.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 12);
dataGridView.Name = "dataGridView";
dataGridView.Size = new Size(631, 304);
dataGridView.TabIndex = 0;
//
// buttonCreateProduct
//
buttonCreateProduct.Location = new Point(69, 22);
buttonCreateProduct.Name = "buttonCreateProduct";
buttonCreateProduct.Size = new Size(139, 23);
buttonCreateProduct.TabIndex = 1;
buttonCreateProduct.Text = "Добавить товар";
buttonCreateProduct.UseVisualStyleBackColor = true;
buttonCreateProduct.Click += buttonCreateProduct_Click;
//
// groupBoxControls
//
groupBoxControls.BackColor = Color.Transparent;
groupBoxControls.Controls.Add(buttonDeleteProduct);
groupBoxControls.Controls.Add(buttonUpdateProduct);
groupBoxControls.Controls.Add(buttonCreateProduct);
groupBoxControls.Location = new Point(649, 12);
groupBoxControls.Name = "groupBoxControls";
groupBoxControls.Size = new Size(264, 304);
groupBoxControls.TabIndex = 2;
groupBoxControls.TabStop = false;
groupBoxControls.Text = "Действия";
//
// buttonUpdateProduct
//
buttonUpdateProduct.Location = new Point(69, 62);
buttonUpdateProduct.Name = "buttonUpdateProduct";
buttonUpdateProduct.Size = new Size(139, 23);
buttonUpdateProduct.TabIndex = 2;
buttonUpdateProduct.Text = "Изменить товар";
buttonUpdateProduct.UseVisualStyleBackColor = true;
buttonUpdateProduct.Click += buttonUpdateProduct_Click;
//
// groupBoxCreateProduct
//
groupBoxCreateProduct.BackColor = Color.Transparent;
groupBoxCreateProduct.Controls.Add(numericUpDownAmount);
groupBoxCreateProduct.Controls.Add(numericUpDownPrice);
groupBoxCreateProduct.Controls.Add(buttonCancel);
groupBoxCreateProduct.Controls.Add(buttonSaveProduct);
groupBoxCreateProduct.Controls.Add(checkBoxIsSold);
groupBoxCreateProduct.Controls.Add(textBoxName);
groupBoxCreateProduct.Location = new Point(649, 330);
groupBoxCreateProduct.Name = "groupBoxCreateProduct";
groupBoxCreateProduct.Size = new Size(257, 304);
groupBoxCreateProduct.TabIndex = 3;
groupBoxCreateProduct.TabStop = false;
groupBoxCreateProduct.Text = "Создание/изменение продукта";
//
// numericUpDownAmount
//
numericUpDownAmount.Location = new Point(17, 153);
numericUpDownAmount.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
numericUpDownAmount.Name = "numericUpDownAmount";
numericUpDownAmount.Size = new Size(120, 23);
numericUpDownAmount.TabIndex = 7;
//
// numericUpDownPrice
//
numericUpDownPrice.DecimalPlaces = 2;
numericUpDownPrice.Location = new Point(17, 94);
numericUpDownPrice.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(120, 23);
numericUpDownPrice.TabIndex = 6;
//
// buttonCancel
//
buttonCancel.Location = new Point(111, 235);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSaveProduct
//
buttonSaveProduct.Location = new Point(17, 235);
buttonSaveProduct.Name = "buttonSaveProduct";
buttonSaveProduct.Size = new Size(75, 23);
buttonSaveProduct.TabIndex = 4;
buttonSaveProduct.Text = "Сохранить";
buttonSaveProduct.UseVisualStyleBackColor = true;
buttonSaveProduct.Click += buttonSaveProduct_Click;
//
// checkBoxIsSold
//
checkBoxIsSold.AutoSize = true;
checkBoxIsSold.Location = new Point(17, 210);
checkBoxIsSold.Name = "checkBoxIsSold";
checkBoxIsSold.Size = new Size(148, 19);
checkBoxIsSold.TabIndex = 3;
checkBoxIsSold.Text = "Поместить в магазин?";
checkBoxIsSold.UseVisualStyleBackColor = true;
//
// textBoxName
//
textBoxName.Location = new Point(17, 40);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(100, 23);
textBoxName.TabIndex = 0;
//
// buttonDeleteProduct
//
buttonDeleteProduct.Location = new Point(69, 102);
buttonDeleteProduct.Name = "buttonDeleteProduct";
buttonDeleteProduct.Size = new Size(139, 23);
buttonDeleteProduct.TabIndex = 3;
buttonDeleteProduct.Text = "Удалить товар";
buttonDeleteProduct.UseVisualStyleBackColor = true;
buttonDeleteProduct.Click += buttonDeleteProduct_Click;
//
// FormProducts
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(925, 646);
Controls.Add(groupBoxCreateProduct);
Controls.Add(groupBoxControls);
Controls.Add(dataGridView);
Name = "FormProducts";
Text = "FormProducts";
Load += FormProducts_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
groupBoxControls.ResumeLayout(false);
groupBoxCreateProduct.ResumeLayout(false);
groupBoxCreateProduct.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonCreateProduct;
private GroupBox groupBoxControls;
private GroupBox groupBoxCreateProduct;
private TextBox textBoxName;
private Button buttonSaveProduct;
private CheckBox checkBoxIsSold;
private NumericUpDown numericUpDownAmount;
private NumericUpDown numericUpDownPrice;
private Button buttonCancel;
private Button buttonUpdateProduct;
private Button buttonDeleteProduct;
}
}

185
WinFormsApp/FormProducts.cs Normal file
View File

@ -0,0 +1,185 @@
using BusinessLogic.BusinessLogic;
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Microsoft.Extensions.Logging;
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;
namespace WinFormsApp
{
public partial class FormProducts : Form
{
private Guid? _id;
private readonly ILogger _logger;
private readonly IProductLogic _productLogic;
public FormProducts(ILogger<FormMain> logger, IProductLogic productLogic)
{
InitializeComponent();
_productLogic = productLogic;
_logger = logger;
}
private void FormProducts_Load(object sender, EventArgs e)
{
LoadData();
groupBoxCreateProduct.Hide();
//groupBoxCreateProduct.Enabled = false;
}
private void LoadData()
{
_logger.LogInformation("Загрузка товаров");
try
{
var list = _productLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
}
_logger.LogInformation("Загрузка товаров");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки товаров");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreateProduct_Click(object sender, EventArgs e)
{
//надо сделать че нибудь с фронтом а то всё грустно
groupBoxControls.Hide();
//groupBoxControls.Enabled = false;
groupBoxCreateProduct.Show();
//groupBoxCreateProduct.Enabled = true;
}
private void buttonSaveProduct_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(numericUpDownPrice.Value.ToString()))
{
MessageBox.Show("Укажите цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(numericUpDownAmount.Value.ToString()))
{
MessageBox.Show("Укажите кол-во", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение товара");
try
{
var model = new ProductBindingModel
{
Id = _id ?? Guid.Empty,
Name = textBoxName.Text,
Price = Convert.ToDouble(numericUpDownPrice.Value),
Amount = Convert.ToInt16(numericUpDownAmount.Value),
Rate = 0.0,
IsBeingSold = checkBoxIsSold.Checked,
};
var operationResult = _id.HasValue ? _productLogic.Update(model) : _productLogic.Create(model);
_id = null;
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения товара");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
LoadData();
groupBoxControls.Enabled = true;
groupBoxControls.Show();
groupBoxCreateProduct.Enabled = false;
groupBoxCreateProduct.Hide();
textBoxName.Text = string.Empty;
numericUpDownAmount.Value = 0;
numericUpDownPrice.Value = 0;
checkBoxIsSold.Checked = false;
}
}
private void buttonUpdateProduct_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count <= 0) return;
_id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
groupBoxControls.Hide();
groupBoxCreateProduct.Show();
_logger.LogInformation("Получение товара");
var view = _productLogic.ReadElement(new ProductSearchModel
{
Id = _id.Value
});
textBoxName.Text = view.Name;
numericUpDownPrice.Value = Convert.ToDecimal(view.Price);
numericUpDownAmount.Value = view.Amount;
checkBoxIsSold.Checked = view.IsBeingSold;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
_id = null;
groupBoxControls.Show();
//groupBoxControls.Enabled = false;
groupBoxCreateProduct.Hide();
//groupBoxCreateProduct.Enabled = true;
textBoxName.Text = string.Empty;
numericUpDownAmount.Value = 0;
numericUpDownPrice.Value = 0;
checkBoxIsSold.Checked = false;
}
private void buttonDeleteProduct_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Guid id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
_logger.LogInformation("Удаление товара");
try
{
if (!_productLogic.Delete(new ProductBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления товара");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -1,7 +1,18 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using NLog.Extensions.Logging;
using Microsoft.Extensions.Logging;
using Contracts.StorageContracts;
using DatabaseImplement.Implements;
using Contracts.BusinessLogicContracts;
using BusinessLogic.BusinessLogic;
namespace WinFormsApp
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -11,7 +22,30 @@ namespace WinFormsApp
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<ISupplyStorage, SupplyStorage>();
//services.AddTransient<ISupplyDocStorage, SupplyDocStorage>();
services.AddTransient<IProductStorage, ProductStorage>();
services.AddTransient<ISupplierStorage, SupplierStorage>();
//services.AddTransient<, ImplementerStorage>();
services.AddTransient<ISupplyLogic, SupplyLogic>();
services.AddTransient<ISupplierLogic, SupplierLogic>();
services.AddTransient<IProductLogic, ProductLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormProducts>();
}
}
}

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
</ItemGroup>
</Project>