This commit is contained in:
antoc0der 2024-02-12 16:52:44 +03:00
parent f930b4b56c
commit 6a305bb8df
9 changed files with 405 additions and 18 deletions

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace FlowerShopBusinessLogic.BusinessLogic namespace FlowerShopBusinessLogic.BusinessLogic
{ {
public class ComponentLogic : IFlowerLogic public class ComponentLogic : IComponentLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage; private readonly IComponentStorage _componentStorage;

View File

@ -9,7 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FlowerShopListImplement namespace FlowerShopListImplement.Implements
{ {
public class FlowerStorage : IFlowerStorage public class FlowerStorage : IFlowerStorage
{ {

113
ProjectFlowerShop/FormFlowers.Designer.cs generated Normal file
View File

@ -0,0 +1,113 @@
namespace IceCreamShop
{
partial class FormFlowers
{
/// <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();
AddButton = new Button();
UpdateButton = new Button();
DeleteButton = new Button();
RefreshButton = new Button();
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout();
//
// DataGridView
//
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
DataGridView.Location = new Point(12, 12);
DataGridView.Name = "DataGridView";
DataGridView.RowHeadersWidth = 51;
DataGridView.Size = new Size(379, 426);
DataGridView.TabIndex = 0;
//
// AddButton
//
AddButton.Location = new Point(397, 12);
AddButton.Name = "AddButton";
AddButton.Size = new Size(148, 29);
AddButton.TabIndex = 1;
AddButton.Text = "Добавить";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += AddButton_Click;
//
// UpdateButton
//
UpdateButton.Location = new Point(397, 47);
UpdateButton.Name = "UpdateButton";
UpdateButton.Size = new Size(148, 29);
UpdateButton.TabIndex = 2;
UpdateButton.Text = "Изменить";
UpdateButton.UseVisualStyleBackColor = true;
UpdateButton.Click += UpdateButton_Click;
//
// DeleteButton
//
DeleteButton.Location = new Point(397, 82);
DeleteButton.Name = "DeleteButton";
DeleteButton.Size = new Size(148, 29);
DeleteButton.TabIndex = 3;
DeleteButton.Text = "Удалить";
DeleteButton.UseVisualStyleBackColor = true;
DeleteButton.Click += DeleteButton_Click;
//
// RefreshButton
//
RefreshButton.Location = new Point(397, 117);
RefreshButton.Name = "RefreshButton";
RefreshButton.Size = new Size(148, 29);
RefreshButton.TabIndex = 4;
RefreshButton.Text = "Обновить";
RefreshButton.UseVisualStyleBackColor = true;
RefreshButton.Click += RefreshButton_Click;
//
// IceCreamsForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(557, 450);
Controls.Add(RefreshButton);
Controls.Add(DeleteButton);
Controls.Add(UpdateButton);
Controls.Add(AddButton);
Controls.Add(DataGridView);
Name = "IceCreamsForm";
Text = "IceCreamsForm";
Load += IceCreamsForm_Load;
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView DataGridView;
private Button AddButton;
private Button UpdateButton;
private Button DeleteButton;
private Button RefreshButton;
}
}

View File

@ -0,0 +1,117 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using ProjectFlowerShop;
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 IceCreamShop
{
public partial class FormFlowers : Form
{
private readonly ILogger _logger;
private readonly IFlowerLogic _logic;
public FormFlowers(ILogger<FormFlowers> logger, IFlowerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void IceCreamsForm_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["IceCreamName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["IceCreamComponents"].Visible = false;
}
_logger.LogInformation("Загрузка цветов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки цветов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AddButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProduct));
if (service is FormProduct form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProduct));
if (service is FormProduct form)
{
var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void DeleteButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление цветов");
try
{
if (!_logic.Delete(new FlowerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления цветов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void RefreshButton_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View 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>

View File

@ -31,7 +31,7 @@
menuStrip1 = new MenuStrip(); menuStrip1 = new MenuStrip();
ToolStripMenu = new ToolStripMenuItem(); ToolStripMenu = new ToolStripMenuItem();
КомпонентыStripMenuItem = new ToolStripMenuItem(); КомпонентыStripMenuItem = new ToolStripMenuItem();
МороженноеStripMenuItem = new ToolStripMenuItem(); ЦветыStripMenuItem = new ToolStripMenuItem();
DataGridView = new DataGridView(); DataGridView = new DataGridView();
CreateOrderButton = new Button(); CreateOrderButton = new Button();
TakeInWorkButton = new Button(); TakeInWorkButton = new Button();
@ -54,7 +54,7 @@
// //
// ToolStripMenu // ToolStripMenu
// //
ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, МороженноеStripMenuItem }); ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem });
ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Name = "ToolStripMenu";
ToolStripMenu.Size = new Size(117, 24); ToolStripMenu.Size = new Size(117, 24);
ToolStripMenu.Text = "Справочники"; ToolStripMenu.Text = "Справочники";
@ -62,16 +62,16 @@
// КомпонентыStripMenuItem // КомпонентыStripMenuItem
// //
КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem";
КомпонентыStripMenuItem.Size = new Size(186, 26); КомпонентыStripMenuItem.Size = new Size(224, 26);
КомпонентыStripMenuItem.Text = "Компоненты"; КомпонентыStripMenuItem.Text = "Компоненты";
КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click;
// //
// МороженноеStripMenuItem // ЦветыStripMenuItem
// //
МороженноеStripMenuItem.Name = "МороженноеStripMenuItem"; ЦветыStripMenuItem.Name = "ЦветыStripMenuItem";
МороженноеStripMenuItem.Size = new Size(186, 26); ЦветыStripMenuItem.Size = new Size(224, 26);
МороженноеStripMenuItem.Text = "Мороженное"; ЦветыStripMenuItem.Text = "Цветы";
МороженноеStripMenuItem.Click += МороженноеStripMenuItem_Click; ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click;
// //
// DataGridView // DataGridView
// //
@ -160,7 +160,7 @@
private MenuStrip menuStrip1; private MenuStrip menuStrip1;
private ToolStripMenuItem ToolStripMenu; private ToolStripMenuItem ToolStripMenu;
private ToolStripMenuItem КомпонентыStripMenuItem; private ToolStripMenuItem КомпонентыStripMenuItem;
private ToolStripMenuItem МороженноеStripMenuItem; private ToolStripMenuItem ЦветыStripMenuItem;
private DataGridView DataGridView; private DataGridView DataGridView;
private Button CreateOrderButton; private Button CreateOrderButton;
private Button TakeInWorkButton; private Button TakeInWorkButton;

View File

@ -63,10 +63,10 @@ namespace IceCreamShop
} }
} }
private void МороженноеStripMenuItem_Click(object sender, EventArgs e) private void ЦветыStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(IceCreamsForm)); var service = Program.ServiceProvider?.GetService(typeof(FormFlowers));
if (service is IceCreamsForm form) if (service is FormFlowers form)
{ {
form.ShowDialog(); form.ShowDialog();
} }

View File

@ -1,17 +1,53 @@
using FlowerShopBusinessLogic.BusinessLogic;
using FlowerShopContracts.BusinessLogicsContracts;
using FlowerShopContracts.StoragesContracts;
using FlowerShopListImplement.Implements;
using IceCreamShop;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
using System.Drawing;
namespace ProjectFlowerShop namespace ProjectFlowerShop
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new ComponentForm()); var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
} }
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IFlowerStorage, FlowerStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IFlowerLogic, FlowerLogic>();
services.AddTransient<MainForm>();
services.AddTransient<ComponentForm>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormProduct>();
services.AddTransient<FormProductComponent>();
services.AddTransient<FormFlowers>();
}
} }
} }

View File

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>