diff --git a/FlowerShopBusinessLogic/ComponentLogic.cs b/FlowerShopBusinessLogic/ComponentLogic.cs index ed0ddc3..ed18633 100644 --- a/FlowerShopBusinessLogic/ComponentLogic.cs +++ b/FlowerShopBusinessLogic/ComponentLogic.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace FlowerShopBusinessLogic.BusinessLogic { - public class ComponentLogic : IFlowerLogic + public class ComponentLogic : IComponentLogic { private readonly ILogger _logger; private readonly IComponentStorage _componentStorage; diff --git a/FlowerShopListImplement/FlowerStorage.cs b/FlowerShopListImplement/FlowerStorage.cs index eb8aef6..00274ec 100644 --- a/FlowerShopListImplement/FlowerStorage.cs +++ b/FlowerShopListImplement/FlowerStorage.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace FlowerShopListImplement +namespace FlowerShopListImplement.Implements { public class FlowerStorage : IFlowerStorage { diff --git a/ProjectFlowerShop/FormFlowers.Designer.cs b/ProjectFlowerShop/FormFlowers.Designer.cs new file mode 100644 index 0000000..6d482c9 --- /dev/null +++ b/ProjectFlowerShop/FormFlowers.Designer.cs @@ -0,0 +1,113 @@ +namespace IceCreamShop +{ + partial class FormFlowers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormFlowers.cs b/ProjectFlowerShop/FormFlowers.cs new file mode 100644 index 0000000..9fdcfd2 --- /dev/null +++ b/ProjectFlowerShop/FormFlowers.cs @@ -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 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(); + + } + } +} diff --git a/ProjectFlowerShop/FormFlowers.resx b/ProjectFlowerShop/FormFlowers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/FormFlowers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs index 2b62d4f..d5dc8d4 100644 --- a/ProjectFlowerShop/MainForm.Designer.cs +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -31,7 +31,7 @@ menuStrip1 = new MenuStrip(); ToolStripMenu = new ToolStripMenuItem(); КомпонентыStripMenuItem = new ToolStripMenuItem(); - МороженноеStripMenuItem = new ToolStripMenuItem(); + ЦветыStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -54,7 +54,7 @@ // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, МороженноеStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(117, 24); ToolStripMenu.Text = "Справочники"; @@ -62,16 +62,16 @@ // КомпонентыStripMenuItem // КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; - КомпонентыStripMenuItem.Size = new Size(186, 26); + КомпонентыStripMenuItem.Size = new Size(224, 26); КомпонентыStripMenuItem.Text = "Компоненты"; КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; // - // МороженноеStripMenuItem + // ЦветыStripMenuItem // - МороженноеStripMenuItem.Name = "МороженноеStripMenuItem"; - МороженноеStripMenuItem.Size = new Size(186, 26); - МороженноеStripMenuItem.Text = "Мороженное"; - МороженноеStripMenuItem.Click += МороженноеStripMenuItem_Click; + ЦветыStripMenuItem.Name = "ЦветыStripMenuItem"; + ЦветыStripMenuItem.Size = new Size(224, 26); + ЦветыStripMenuItem.Text = "Цветы"; + ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click; // // DataGridView // @@ -160,7 +160,7 @@ private MenuStrip menuStrip1; private ToolStripMenuItem ToolStripMenu; private ToolStripMenuItem КомпонентыStripMenuItem; - private ToolStripMenuItem МороженноеStripMenuItem; + private ToolStripMenuItem ЦветыStripMenuItem; private DataGridView DataGridView; private Button CreateOrderButton; private Button TakeInWorkButton; diff --git a/ProjectFlowerShop/MainForm.cs b/ProjectFlowerShop/MainForm.cs index 613d82d..41f131a 100644 --- a/ProjectFlowerShop/MainForm.cs +++ b/ProjectFlowerShop/MainForm.cs @@ -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)); - if (service is IceCreamsForm form) + var service = Program.ServiceProvider?.GetService(typeof(FormFlowers)); + if (service is FormFlowers form) { form.ShowDialog(); } diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index b26be2c..0ba0c05 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -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 { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new ComponentForm()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } -} \ No newline at end of file +} diff --git a/ProjectFlowerShop/ProjectFlowerShop.csproj b/ProjectFlowerShop/ProjectFlowerShop.csproj index cb55f75..337ad0f 100644 --- a/ProjectFlowerShop/ProjectFlowerShop.csproj +++ b/ProjectFlowerShop/ProjectFlowerShop.csproj @@ -10,6 +10,7 @@ +