From 796505fe3b5cc62c8e1425223d6df0b14c4c7e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 20:16:32 +0400 Subject: [PATCH 1/3] =?UTF-8?q?8=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20Unity-=D0=BA=D0=BE=D0=BD=D1=82?= =?UTF-8?q?=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + ConfectionaryBusinessLogic/BackUpLogic.cs | 103 +++++ ConfectionaryFileImplement/BackUpInfo.cs | 34 ++ ConfectionaryFileImplement/Client.cs | 9 +- ConfectionaryFileImplement/Component.cs | 15 +- .../ConfectioneryFileImplement.csproj | 4 + .../FileImplementationExtension.cs | 23 + ConfectionaryFileImplement/Implementer.cs | 19 +- ConfectionaryFileImplement/MessageInfo.cs | 28 +- ConfectionaryFileImplement/Order.cs | 11 + ConfectionaryFileImplement/Pastry.cs | 7 + ConfectionaryListImplement/BackUpInfo.cs | 22 + .../ConfectioneryListImplement.csproj | 4 + .../ListImplementationExtension.cs | 28 ++ ConfectionaryListImplement/MessageInfo.cs | 3 +- Confectionery/DataGridViewExtension.cs | 46 ++ Confectionery/FormComponents.cs | 31 +- Confectionery/FormMain.Designer.cs | 433 +++++++++--------- Confectionery/FormMain.cs | 413 +++++++++-------- Confectionery/FormPastry.cs | 64 ++- Confectionery/FormViewClients.cs | 8 +- Confectionery/FormViewImplementers.cs | 31 +- Confectionery/FormViewMail.cs | 11 +- Confectionery/FormViewPastry.cs | 32 +- Confectionery/Program.cs | 82 ++-- .../Attributes/ColumnAttribute.cs | 31 ++ .../Attributes/GridViewAutoSize.cs | 27 ++ .../BindingModels/BackUpSaveBinidngModel.cs | 13 + .../BindingModels/MessageInfoBindingModel.cs | 4 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 14 + .../ConfectioneryContracts.csproj | 5 + .../DI/DependencyManager.cs | 66 +++ .../DI/IDependencyContainer.cs | 35 ++ .../DI/IImplementationExtension.cs | 17 + .../DI/ServiceDependencyContainer.cs | 57 +++ .../DI/ServiceProviderLoader.cs | 55 +++ .../StoragesContract/IBackUpInfo.cs | 14 + .../ViewModels/ClientViewModel.cs | 10 +- .../ViewModels/ComponentViewModel.cs | 8 +- .../ViewModels/ImplementerViewModel.cs | 14 +- .../ViewModels/MessageInfoViewModel.cs | 21 +- .../ViewModels/OrderViewModel.cs | 27 +- .../ViewModels/PastryViewModel.cs | 9 +- ConfectioneryDataModels/IMessageInfoModel.cs | 3 +- ConfectioneryDatabaseImplement/BackUpInfo.cs | 31 ++ ConfectioneryDatabaseImplement/Client.cs | 6 + ConfectioneryDatabaseImplement/Component.cs | 5 + .../ConfectioneryDatabaseImplement.csproj | 4 + .../DatabaseImplementationExtension.cs | 23 + ConfectioneryDatabaseImplement/Implementer.cs | 7 + ConfectioneryDatabaseImplement/MessageInfo.cs | 6 +- ConfectioneryDatabaseImplement/Order.cs | 10 + ConfectioneryDatabaseImplement/Pastry.cs | 6 + 53 files changed, 1349 insertions(+), 643 deletions(-) create mode 100644 ConfectionaryBusinessLogic/BackUpLogic.cs create mode 100644 ConfectionaryFileImplement/BackUpInfo.cs create mode 100644 ConfectionaryFileImplement/FileImplementationExtension.cs create mode 100644 ConfectionaryListImplement/BackUpInfo.cs create mode 100644 ConfectionaryListImplement/ListImplementationExtension.cs create mode 100644 Confectionery/DataGridViewExtension.cs create mode 100644 ConfectioneryContracts/Attributes/ColumnAttribute.cs create mode 100644 ConfectioneryContracts/Attributes/GridViewAutoSize.cs create mode 100644 ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 ConfectioneryContracts/DI/DependencyManager.cs create mode 100644 ConfectioneryContracts/DI/IDependencyContainer.cs create mode 100644 ConfectioneryContracts/DI/IImplementationExtension.cs create mode 100644 ConfectioneryContracts/DI/ServiceDependencyContainer.cs create mode 100644 ConfectioneryContracts/DI/ServiceProviderLoader.cs create mode 100644 ConfectioneryContracts/StoragesContract/IBackUpInfo.cs create mode 100644 ConfectioneryDatabaseImplement/BackUpInfo.cs create mode 100644 ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..52737dc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# dll файлы +*.dll + # Mono auto generated files mono_crash.* diff --git a/ConfectionaryBusinessLogic/BackUpLogic.cs b/ConfectionaryBusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..0a86ea5 --- /dev/null +++ b/ConfectionaryBusinessLogic/BackUpLogic.cs @@ -0,0 +1,103 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/ConfectionaryFileImplement/BackUpInfo.cs b/ConfectionaryFileImplement/BackUpInfo.cs new file mode 100644 index 0000000..3fc86fa --- /dev/null +++ b/ConfectionaryFileImplement/BackUpInfo.cs @@ -0,0 +1,34 @@ +using ConfectioneryContracts.StoragesContract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryFileImplement +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + // Получаем значения из singleton-объекта универсального свойства содержащее тип T + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/ConfectionaryFileImplement/Client.cs b/ConfectionaryFileImplement/Client.cs index 4796c2d..bd49fab 100644 --- a/ConfectionaryFileImplement/Client.cs +++ b/ConfectionaryFileImplement/Client.cs @@ -4,20 +4,23 @@ using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ConfectioneryFileImplement { + [DataContract] public class Client : IClientModel { + [DataMember] public string ClientFIO { get; private set; } = string.Empty; - + [DataMember] public string Email { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int Id { get; private set; } public static Client? Create(ClientBindingModel model) diff --git a/ConfectionaryFileImplement/Component.cs b/ConfectionaryFileImplement/Component.cs index e6f43e5..a11af5f 100644 --- a/ConfectionaryFileImplement/Component.cs +++ b/ConfectionaryFileImplement/Component.cs @@ -1,17 +1,22 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { + [DataContract] public class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } - public static Component? Create(ComponentBindingModel model) + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) { if (model == null) { diff --git a/ConfectionaryFileImplement/ConfectioneryFileImplement.csproj b/ConfectionaryFileImplement/ConfectioneryFileImplement.csproj index 41b6c3e..70542e0 100644 --- a/ConfectionaryFileImplement/ConfectioneryFileImplement.csproj +++ b/ConfectionaryFileImplement/ConfectioneryFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/ConfectionaryFileImplement/FileImplementationExtension.cs b/ConfectionaryFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..c643c48 --- /dev/null +++ b/ConfectionaryFileImplement/FileImplementationExtension.cs @@ -0,0 +1,23 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryFileImplement.Implements; + +namespace ConfectioneryFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/ConfectionaryFileImplement/Implementer.cs b/ConfectionaryFileImplement/Implementer.cs index 156c3ad..0d647f3 100644 --- a/ConfectionaryFileImplement/Implementer.cs +++ b/ConfectionaryFileImplement/Implementer.cs @@ -5,23 +5,30 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ConfectioneryFileImplement { + [DataContract] public class Implementer : IImplementerModel - { - public int Id { get; private set; } + { + [DataMember] + public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } - public int Qualification { get; private set; } + [DataMember] + public int Qualification { get; private set; } public static Implementer? Create(XElement element) { diff --git a/ConfectionaryFileImplement/MessageInfo.cs b/ConfectionaryFileImplement/MessageInfo.cs index 65396ae..63491ed 100644 --- a/ConfectionaryFileImplement/MessageInfo.cs +++ b/ConfectionaryFileImplement/MessageInfo.cs @@ -4,6 +4,7 @@ using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -11,21 +12,28 @@ using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { // Update в этой сущности не нужен, поскольку в логике мы не изменяем никакие поля после создания письма + [DataContract] public class MessageInfo : IMessageInfoModel - { - public string MessageId { get; private set; } = string.Empty; + { + [DataMember] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; - public static MessageInfo? Create(MessageInfoBindingModel model) + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) { @@ -77,6 +85,8 @@ namespace ConfectioneryFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/ConfectionaryFileImplement/Order.cs b/ConfectionaryFileImplement/Order.cs index 2953eac..78c060e 100644 --- a/ConfectionaryFileImplement/Order.cs +++ b/ConfectionaryFileImplement/Order.cs @@ -2,28 +2,39 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Enums; using ConfectioneryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int PastryId { get; private set; } + [DataMember] public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; set; } + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } + [DataMember] public OrderStatus Status { get; private set; } + [DataMember] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) diff --git a/ConfectionaryFileImplement/Pastry.cs b/ConfectionaryFileImplement/Pastry.cs index 6138c0c..701d2ff 100644 --- a/ConfectionaryFileImplement/Pastry.cs +++ b/ConfectionaryFileImplement/Pastry.cs @@ -1,17 +1,24 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { + [DataContract] public class Pastry : IPastryModel { + + [DataMember] public int Id { get; private set; } + [DataMember] public string PastryName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _PastryComponents = null; + [DataMember] public Dictionary PastryComponents { get diff --git a/ConfectionaryListImplement/BackUpInfo.cs b/ConfectionaryListImplement/BackUpInfo.cs new file mode 100644 index 0000000..69296f5 --- /dev/null +++ b/ConfectionaryListImplement/BackUpInfo.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.StoragesContract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/ConfectionaryListImplement/ConfectioneryListImplement.csproj b/ConfectionaryListImplement/ConfectioneryListImplement.csproj index 41b6c3e..70542e0 100644 --- a/ConfectionaryListImplement/ConfectioneryListImplement.csproj +++ b/ConfectionaryListImplement/ConfectioneryListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/ConfectionaryListImplement/ListImplementationExtension.cs b/ConfectionaryListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..5aa4fd4 --- /dev/null +++ b/ConfectionaryListImplement/ListImplementationExtension.cs @@ -0,0 +1,28 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/ConfectionaryListImplement/MessageInfo.cs b/ConfectionaryListImplement/MessageInfo.cs index 73645a4..881281a 100644 --- a/ConfectionaryListImplement/MessageInfo.cs +++ b/ConfectionaryListImplement/MessageInfo.cs @@ -51,6 +51,7 @@ namespace ConfectioneryListImplement.Models DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } diff --git a/Confectionery/DataGridViewExtension.cs b/Confectionery/DataGridViewExtension.cs new file mode 100644 index 0000000..d06ccc8 --- /dev/null +++ b/Confectionery/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using ConfectioneryContracts.Attributes; + +namespace ConfectioneryView +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + // ищем нужный нам атрибут + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} diff --git a/Confectionery/FormComponents.cs b/Confectionery/FormComponents.cs index 160d4d2..e7575bd 100644 --- a/Confectionery/FormComponents.cs +++ b/Confectionery/FormComponents.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; namespace ConfectioneryView @@ -22,14 +23,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -41,28 +35,21 @@ namespace ConfectioneryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Confectionery/FormMain.Designer.cs b/Confectionery/FormMain.Designer.cs index e72176d..039da09 100644 --- a/Confectionery/FormMain.Designer.cs +++ b/Confectionery/FormMain.Designer.cs @@ -1,220 +1,229 @@ namespace ConfectioneryView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #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() - { - menuStrip1 = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - pastryToolStripMenuItem = new ToolStripMenuItem(); - componentToolStripMenuItem = new ToolStripMenuItem(); - clientsToolStripMenuItem = new ToolStripMenuItem(); - ImplementersToolStripMenuItem = new ToolStripMenuItem(); - reportsToolStripMenuItem = new ToolStripMenuItem(); - pastriesToolStripMenuItem = new ToolStripMenuItem(); - pastryComponentsToolStripMenuItem = new ToolStripMenuItem(); - ordersToolStripMenuItem = new ToolStripMenuItem(); - DoWorkToolStripMenuItem = new ToolStripMenuItem(); - mailToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - button4 = new Button(); - button3 = new Button(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, reportsToolStripMenuItem, DoWorkToolStripMenuItem, mailToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(783, 24); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastryToolStripMenuItem, componentToolStripMenuItem, clientsToolStripMenuItem, ImplementersToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(94, 20); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // pastryToolStripMenuItem - // - pastryToolStripMenuItem.Name = "pastryToolStripMenuItem"; - pastryToolStripMenuItem.Size = new Size(149, 22); - pastryToolStripMenuItem.Text = "Изделия"; - pastryToolStripMenuItem.Click += PastryToolStripMenuItem_Click; - // - // componentToolStripMenuItem - // - componentToolStripMenuItem.Name = "componentToolStripMenuItem"; - componentToolStripMenuItem.Size = new Size(149, 22); - componentToolStripMenuItem.Text = "Компоненты"; - componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; - // - // clientsToolStripMenuItem - // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(149, 22); - clientsToolStripMenuItem.Text = "Клиенты"; - clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // - // ImplementersToolStripMenuItem - // - ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; - ImplementersToolStripMenuItem.Size = new Size(149, 22); - ImplementersToolStripMenuItem.Text = "Исполнители"; - ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; - // - // reportsToolStripMenuItem - // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastriesToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem }); - reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; - reportsToolStripMenuItem.Size = new Size(60, 20); - reportsToolStripMenuItem.Text = "Отчеты"; - // - // pastriesToolStripMenuItem - // - pastriesToolStripMenuItem.Name = "pastriesToolStripMenuItem"; - pastriesToolStripMenuItem.Size = new Size(215, 22); - pastriesToolStripMenuItem.Text = "Список изделий"; - pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click_1; - // - // pastryComponentsToolStripMenuItem - // - pastryComponentsToolStripMenuItem.Name = "pastryComponentsToolStripMenuItem"; - pastryComponentsToolStripMenuItem.Size = new Size(215, 22); - pastryComponentsToolStripMenuItem.Text = "Изделия с компонентами"; - pastryComponentsToolStripMenuItem.Click += PastryComponentsToolStripMenuItem_Click; - // - // ordersToolStripMenuItem - // - ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - ordersToolStripMenuItem.Size = new Size(215, 22); - ordersToolStripMenuItem.Text = "Список заказов"; - ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; - // - // DoWorkToolStripMenuItem - // - DoWorkToolStripMenuItem.Name = "DoWorkToolStripMenuItem"; - DoWorkToolStripMenuItem.Size = new Size(92, 20); - DoWorkToolStripMenuItem.Text = "Запуск работ"; - DoWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; - // - // mailToolStripMenuItem - // - mailToolStripMenuItem.Name = "mailToolStripMenuItem"; - mailToolStripMenuItem.Size = new Size(62, 20); - mailToolStripMenuItem.Text = "Письма"; - mailToolStripMenuItem.Click += MailToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 27); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(606, 341); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.Location = new Point(624, 39); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(147, 32); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // button4 - // - button4.Anchor = AnchorStyles.Top | AnchorStyles.Right; - button4.Location = new Point(624, 157); - button4.Name = "button4"; - button4.Size = new Size(147, 32); - button4.TabIndex = 6; - button4.Text = "Обновить список"; - button4.UseVisualStyleBackColor = true; - button4.Click += ButtonRef_Click; - // - // button3 - // - button3.Anchor = AnchorStyles.Top | AnchorStyles.Right; - button3.Location = new Point(624, 98); - button3.Name = "button3"; - button3.Size = new Size(147, 32); - button3.TabIndex = 5; - button3.Text = "Заказ выдан"; - button3.UseVisualStyleBackColor = true; - button3.Click += ButtonIssuedOrder_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(783, 380); - Controls.Add(button4); - Controls.Add(button3); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Name = "FormMain"; - Text = "Кондитерская"; - Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + pastryToolStripMenuItem = new ToolStripMenuItem(); + componentToolStripMenuItem = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + reportsToolStripMenuItem = new ToolStripMenuItem(); + pastriesToolStripMenuItem = new ToolStripMenuItem(); + pastryComponentsToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + DoWorkToolStripMenuItem = new ToolStripMenuItem(); + mailToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + button4 = new Button(); + button3 = new Button(); + createBackupToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, reportsToolStripMenuItem, DoWorkToolStripMenuItem, mailToolStripMenuItem, createBackupToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(783, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastryToolStripMenuItem, componentToolStripMenuItem, clientsToolStripMenuItem, ImplementersToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // pastryToolStripMenuItem + // + pastryToolStripMenuItem.Name = "pastryToolStripMenuItem"; + pastryToolStripMenuItem.Size = new Size(149, 22); + pastryToolStripMenuItem.Text = "Изделия"; + pastryToolStripMenuItem.Click += PastryToolStripMenuItem_Click; + // + // componentToolStripMenuItem + // + componentToolStripMenuItem.Name = "componentToolStripMenuItem"; + componentToolStripMenuItem.Size = new Size(149, 22); + componentToolStripMenuItem.Text = "Компоненты"; + componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(149, 22); + clientsToolStripMenuItem.Text = "Клиенты"; + clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(149, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // + // reportsToolStripMenuItem + // + reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastriesToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem }); + reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; + reportsToolStripMenuItem.Size = new Size(60, 20); + reportsToolStripMenuItem.Text = "Отчеты"; + // + // pastriesToolStripMenuItem + // + pastriesToolStripMenuItem.Name = "pastriesToolStripMenuItem"; + pastriesToolStripMenuItem.Size = new Size(215, 22); + pastriesToolStripMenuItem.Text = "Список изделий"; + pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click_1; + // + // pastryComponentsToolStripMenuItem + // + pastryComponentsToolStripMenuItem.Name = "pastryComponentsToolStripMenuItem"; + pastryComponentsToolStripMenuItem.Size = new Size(215, 22); + pastryComponentsToolStripMenuItem.Text = "Изделия с компонентами"; + pastryComponentsToolStripMenuItem.Click += PastryComponentsToolStripMenuItem_Click; + // + // ordersToolStripMenuItem + // + ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + ordersToolStripMenuItem.Size = new Size(215, 22); + ordersToolStripMenuItem.Text = "Список заказов"; + ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // DoWorkToolStripMenuItem + // + DoWorkToolStripMenuItem.Name = "DoWorkToolStripMenuItem"; + DoWorkToolStripMenuItem.Size = new Size(92, 20); + DoWorkToolStripMenuItem.Text = "Запуск работ"; + DoWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; + // + // mailToolStripMenuItem + // + mailToolStripMenuItem.Name = "mailToolStripMenuItem"; + mailToolStripMenuItem.Size = new Size(62, 20); + mailToolStripMenuItem.Text = "Письма"; + mailToolStripMenuItem.Click += MailToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(606, 341); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(624, 39); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(147, 32); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // button4 + // + button4.Anchor = AnchorStyles.Top | AnchorStyles.Right; + button4.Location = new Point(624, 157); + button4.Name = "button4"; + button4.Size = new Size(147, 32); + button4.TabIndex = 6; + button4.Text = "Обновить список"; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonRef_Click; + // + // button3 + // + button3.Anchor = AnchorStyles.Top | AnchorStyles.Right; + button3.Location = new Point(624, 98); + button3.Name = "button3"; + button3.Size = new Size(147, 32); + button3.TabIndex = 5; + button3.Text = "Заказ выдан"; + button3.UseVisualStyleBackColor = true; + button3.Click += ButtonIssuedOrder_Click; + // + // createBackupToolStripMenuItem + // + createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem"; + createBackupToolStripMenuItem.Size = new Size(97, 20); + createBackupToolStripMenuItem.Text = "Создать бекап"; + createBackupToolStripMenuItem.Click += CreateBackupToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(783, 380); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Кондитерская"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникиToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button button4; - private ToolStripMenuItem pastryToolStripMenuItem; - private ToolStripMenuItem componentToolStripMenuItem; - private ToolStripMenuItem reportsToolStripMenuItem; - private ToolStripMenuItem pastriesToolStripMenuItem; - private ToolStripMenuItem pastryComponentsToolStripMenuItem; - private ToolStripMenuItem ordersToolStripMenuItem; - private ToolStripMenuItem clientsToolStripMenuItem; - private ToolStripMenuItem ImplementersToolStripMenuItem; - private ToolStripMenuItem DoWorkToolStripMenuItem; - private Button button3; - private ToolStripMenuItem mailToolStripMenuItem; - } + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button button4; + private ToolStripMenuItem pastryToolStripMenuItem; + private ToolStripMenuItem componentToolStripMenuItem; + private ToolStripMenuItem reportsToolStripMenuItem; + private ToolStripMenuItem pastriesToolStripMenuItem; + private ToolStripMenuItem pastryComponentsToolStripMenuItem; + private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem ImplementersToolStripMenuItem; + private ToolStripMenuItem DoWorkToolStripMenuItem; + private Button button3; + private ToolStripMenuItem mailToolStripMenuItem; + private ToolStripMenuItem createBackupToolStripMenuItem; + } } \ No newline at end of file diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index 870ee07..6689d07 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -1,229 +1,224 @@ +using ConfectioneryBusinessLogic; using ConfectioneryBusinessLogic.BusinessLogics; using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using ConfectioneryDataModels.Enums; using Microsoft.Extensions.Logging; using System.Windows.Forms; namespace ConfectioneryView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].HeaderText = " "; - dataGridView.Columns["PastryId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation(" "); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs - e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void PastryToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormViewPastry)); - if (service is FormViewPastry form) - { - form.ShowDialog(); - } - } + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + _workProcess = workProcess; + _backUpLogic = backUpLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation(" "); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs + e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void PastryToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + + } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" No{id}. ' '", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception(" . ."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - OrderStatus orderStatus = (OrderStatus)dataGridView.SelectedRows[0].Cells["Status"].Value; - _logger.LogInformation(" No{id}. ''", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id, - Status = orderStatus - }); - if (!operationResult) - { - throw new Exception(" . ."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" No{id}. ''", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new - OrderBindingModel - { Id = id }); - if (!operationResult) - { - throw new Exception(" . ."); - } - _logger.LogInformation(" No{id} ", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation(" No{id}. ' '", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception(" . ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + OrderStatus orderStatus = (OrderStatus)dataGridView.SelectedRows[0].Cells["Status"].Value; + _logger.LogInformation(" No{id}. ''", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + Status = orderStatus + }); + if (!operationResult) + { + throw new Exception(" . ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation(" No{id}. ''", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception(" . ."); + } + _logger.LogInformation(" No{id} ", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } - private void PastriesToolStripMenuItem_Click_1(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SavePastriesToWordFile(new ReportBindingModel { FileName = dialog.FileName }); - MessageBox.Show("", "", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } + private void PastriesToolStripMenuItem_Click_1(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SavePastriesToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } - private void PastryComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents)); - if (service is FormReportPastryComponents form) - { - form.ShowDialog(); - } - } + private void PastryComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + + } - private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormViewClients)); - if (service is FormViewClients form) - { - form.ShowDialog(); - } - } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers)); - if (service is FormViewImplementers form) - { - form.ShowDialog(); - } - } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, - _orderLogic); - MessageBox.Show(" ", "", - MessageBoxButtons.OK, MessageBoxIcon.Information); - } + private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork( + DependencyManager.Instance.Resolve(), + _orderLogic); + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } - private void MailToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormViewMail)); - if (service is FormViewMail form) - { - form.ShowDialog(); - } - } - } + private void MailToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void CreateBackupToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } } \ No newline at end of file diff --git a/Confectionery/FormPastry.cs b/Confectionery/FormPastry.cs index 3b7bd3f..867c8bd 100644 --- a/Confectionery/FormPastry.cs +++ b/Confectionery/FormPastry.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using ConfectioneryContracts.SearchModels; using ConfectioneryDataModels.Models; using Microsoft.Extensions.Logging; @@ -72,53 +73,46 @@ namespace ConfectioneryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); - if (service is FormPastryComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", - form.ComponentModel.ComponentName, form.Count); - if (_pastryComponents.ContainsKey(form.Id)) - { - _pastryComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _pastryComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", + form.ComponentModel.ComponentName, form.Count); + if (_pastryComponents.ContainsKey(form.Id)) + { + _pastryComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _pastryComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); - if (service is FormPastryComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pastryComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _pastryComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", - form.ComponentModel.ComponentName, form.Count); - _pastryComponents[id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", + form.ComponentModel.ComponentName, form.Count); + _pastryComponents[id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/Confectionery/FormViewClients.cs b/Confectionery/FormViewClients.cs index 0e522a5..60dc8ec 100644 --- a/Confectionery/FormViewClients.cs +++ b/Confectionery/FormViewClients.cs @@ -31,13 +31,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/Confectionery/FormViewImplementers.cs b/Confectionery/FormViewImplementers.cs index b6f4906..7ce34e2 100644 --- a/Confectionery/FormViewImplementers.cs +++ b/Confectionery/FormViewImplementers.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -31,14 +32,8 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка исполнителей"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) { @@ -49,27 +44,21 @@ namespace ConfectioneryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Confectionery/FormViewMail.cs b/Confectionery/FormViewMail.cs index 619bac5..0438c47 100644 --- a/Confectionery/FormViewMail.cs +++ b/Confectionery/FormViewMail.cs @@ -29,15 +29,8 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка списка писем"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) { diff --git a/Confectionery/FormViewPastry.cs b/Confectionery/FormViewPastry.cs index cdcbec6..5a47377 100644 --- a/Confectionery/FormViewPastry.cs +++ b/Confectionery/FormViewPastry.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -31,15 +32,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PastryComponents"].Visible = false; - dataGridView.Columns["PastryName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) @@ -51,28 +44,23 @@ namespace ConfectioneryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); - if (service is FormPastry form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); - if (service is FormPastry form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/Confectionery/Program.cs b/Confectionery/Program.cs index 3596c05..3ca4057 100644 --- a/Confectionery/Program.cs +++ b/Confectionery/Program.cs @@ -2,22 +2,19 @@ using ConfectioneryDatabaseImplement.Implements; using ConfectioneryDatabaseImplement; using ConfectioneryBusinessLogic.BusinessLogics; using ConfectioneryContracts.BusinessLogicsContracts; -using ConfectioneryContracts.StoragesContract; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; +using ConfectioneryContracts.DI; using NLog.Extensions.Logging; using ConfectioneryBusinessLogic; using ConfectioneryBusinessLogic.OfficePackage.Implements; using ConfectioneryBusinessLogic.OfficePackage; using ConfectioneryBusinessLogic.MailWorker; using ConfectioneryContracts.BindingModels; +using Microsoft.Extensions.Logging; namespace ConfectioneryView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -27,13 +24,11 @@ namespace ConfectioneryView // To customize application configuration such as set high DPIsettings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -49,56 +44,53 @@ namespace ConfectioneryView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.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(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/ConfectioneryContracts/Attributes/ColumnAttribute.cs b/ConfectioneryContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..1b6bbc9 --- /dev/null +++ b/ConfectioneryContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + + public bool Visible { get; private set; } + + public int Width { get; private set; } + + public GridViewAutoSize GridViewAutoSize { get; private set; } + + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/ConfectioneryContracts/Attributes/GridViewAutoSize.cs b/ConfectioneryContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..a7d7365 --- /dev/null +++ b/ConfectioneryContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs b/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..5360e67 --- /dev/null +++ b/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs b/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs index 984939b..349102b 100644 --- a/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs +++ b/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace ConfectioneryContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs b/ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..c55c494 --- /dev/null +++ b/ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using ConfectioneryContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/ConfectioneryContracts/ConfectioneryContracts.csproj b/ConfectioneryContracts/ConfectioneryContracts.csproj index b0b970c..09a95fc 100644 --- a/ConfectioneryContracts/ConfectioneryContracts.csproj +++ b/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/ConfectioneryContracts/DI/DependencyManager.cs b/ConfectioneryContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..f524768 --- /dev/null +++ b/ConfectioneryContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/ConfectioneryContracts/DI/IDependencyContainer.cs b/ConfectioneryContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..74040c4 --- /dev/null +++ b/ConfectioneryContracts/DI/IDependencyContainer.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +namespace ConfectioneryContracts.DI +{ + public interface IDependencyContainer + { + /// + /// Регистрация логгера + /// + /// + void AddLogging(Action configure); + + /// + /// Добавление зависимости + /// + /// + /// + /// + void RegisterType(bool isSingle) where U : class, T where T : class; + + /// + /// Добавление зависимости + /// + /// + /// + void RegisterType(bool isSingle) where T : class; + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + T Resolve(); + } +} diff --git a/ConfectioneryContracts/DI/IImplementationExtension.cs b/ConfectioneryContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..c434658 --- /dev/null +++ b/ConfectioneryContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/ConfectioneryContracts/DI/ServiceDependencyContainer.cs b/ConfectioneryContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..5799ada --- /dev/null +++ b/ConfectioneryContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/ConfectioneryContracts/DI/ServiceProviderLoader.cs b/ConfectioneryContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..017dd9c --- /dev/null +++ b/ConfectioneryContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/ConfectioneryContracts/StoragesContract/IBackUpInfo.cs b/ConfectioneryContracts/StoragesContract/IBackUpInfo.cs new file mode 100644 index 0000000..01bbe3f --- /dev/null +++ b/ConfectioneryContracts/StoragesContract/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContract +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/ConfectioneryContracts/ViewModels/ClientViewModel.cs b/ConfectioneryContracts/ViewModels/ClientViewModel.cs index fc3d9e8..cf54477 100644 --- a/ConfectioneryContracts/ViewModels/ClientViewModel.cs +++ b/ConfectioneryContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace ConfectioneryContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column("Логин (эл. почта)", width: 150)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/ConfectioneryContracts/ViewModels/ComponentViewModel.cs b/ConfectioneryContracts/ViewModels/ComponentViewModel.cs index 8706c51..bca002d 100644 --- a/ConfectioneryContracts/ViewModels/ComponentViewModel.cs +++ b/ConfectioneryContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace ConfectioneryContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 80)] public double Cost { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs b/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs index d712215..515b5cb 100644 --- a/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs +++ b/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -13,18 +14,19 @@ namespace ConfectioneryContracts.ViewModels /// public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs b/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs index 5e38e72..1130890 100644 --- a/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs +++ b/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,26 @@ namespace ConfectioneryContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column("Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column("Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; - } + + [Column(visible: false)] + + public int Id => throw new NotImplementedException(); + } } diff --git a/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 49e9198..8975924 100644 --- a/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Enums; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Enums; using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; @@ -11,36 +12,40 @@ namespace ConfectioneryContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } + + [Column(visible: false)] public int PastryId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } - public int? ImplementerId { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } - [DisplayName("Фамилия клиента")] + [Column("Фамилия клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Фамилия исполнителя")] + [Column("Фамилия исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] + [Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string PastryName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/ConfectioneryContracts/ViewModels/PastryViewModel.cs index 32831ba..9454a7e 100644 --- a/ConfectioneryContracts/ViewModels/PastryViewModel.cs +++ b/ConfectioneryContracts/ViewModels/PastryViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,13 @@ namespace ConfectioneryContracts.ViewModels { public class PastryViewModel : IPastryModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PastryName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } + [Column(visible: false)] public Dictionary PastryComponents { get; diff --git a/ConfectioneryDataModels/IMessageInfoModel.cs b/ConfectioneryDataModels/IMessageInfoModel.cs index 38e68a1..29d11bc 100644 --- a/ConfectioneryDataModels/IMessageInfoModel.cs +++ b/ConfectioneryDataModels/IMessageInfoModel.cs @@ -6,8 +6,9 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { + string MessageId { get; } int? ClientId { get; } diff --git a/ConfectioneryDatabaseImplement/BackUpInfo.cs b/ConfectioneryDatabaseImplement/BackUpInfo.cs new file mode 100644 index 0000000..dacf384 --- /dev/null +++ b/ConfectioneryDatabaseImplement/BackUpInfo.cs @@ -0,0 +1,31 @@ +using ConfectioneryContracts.StoragesContract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDatabaseImplement +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new ConfectioneryDatabase(); + return context.Set().ToList(); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/ConfectioneryDatabaseImplement/Client.cs b/ConfectioneryDatabaseImplement/Client.cs index ce4bdfe..49c7bc2 100644 --- a/ConfectioneryDatabaseImplement/Client.cs +++ b/ConfectioneryDatabaseImplement/Client.cs @@ -6,22 +6,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; + [DataMember] public int Id { get; private set; } [ForeignKey("ClientId")] diff --git a/ConfectioneryDatabaseImplement/Component.cs b/ConfectioneryDatabaseImplement/Component.cs index e12c8f9..e17b7b6 100644 --- a/ConfectioneryDatabaseImplement/Component.cs +++ b/ConfectioneryDatabaseImplement/Component.cs @@ -3,15 +3,20 @@ using ConfectioneryDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using ConfectioneryContracts.ViewModels; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] diff --git a/ConfectioneryDatabaseImplement/ConfectioneryDatabaseImplement.csproj b/ConfectioneryDatabaseImplement/ConfectioneryDatabaseImplement.csproj index 6c6f63a..4183f7c 100644 --- a/ConfectioneryDatabaseImplement/ConfectioneryDatabaseImplement.csproj +++ b/ConfectioneryDatabaseImplement/ConfectioneryDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs b/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..f9d3c85 --- /dev/null +++ b/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,23 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryDatabaseImplement.Implements; + +namespace ConfectioneryDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/ConfectioneryDatabaseImplement/Implementer.cs b/ConfectioneryDatabaseImplement/Implementer.cs index 649bca3..a92a019 100644 --- a/ConfectioneryDatabaseImplement/Implementer.cs +++ b/ConfectioneryDatabaseImplement/Implementer.cs @@ -2,19 +2,26 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] public string Password { get; private set; } = string.Empty; + [DataMember] public int WorkExperience { get; private set; } + [DataMember] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] diff --git a/ConfectioneryDatabaseImplement/MessageInfo.cs b/ConfectioneryDatabaseImplement/MessageInfo.cs index 988e037..65716ef 100644 --- a/ConfectioneryDatabaseImplement/MessageInfo.cs +++ b/ConfectioneryDatabaseImplement/MessageInfo.cs @@ -2,13 +2,16 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { // Update в этой сущности не нужен, поскольку в логике мы не изменяем никакие поля после создания письма + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -50,6 +53,7 @@ namespace ConfectioneryDatabaseImplement.Models DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } diff --git a/ConfectioneryDatabaseImplement/Order.cs b/ConfectioneryDatabaseImplement/Order.cs index f50af00..6b35cd6 100644 --- a/ConfectioneryDatabaseImplement/Order.cs +++ b/ConfectioneryDatabaseImplement/Order.cs @@ -8,36 +8,46 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { public int Id { get; private set; } [Required] + [DataMember] public int PastryId { get; private set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } [Required] + [DataMember] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } public Pastry Pastry { get; private set; } diff --git a/ConfectioneryDatabaseImplement/Pastry.cs b/ConfectioneryDatabaseImplement/Pastry.cs index 6653728..f231a11 100644 --- a/ConfectioneryDatabaseImplement/Pastry.cs +++ b/ConfectioneryDatabaseImplement/Pastry.cs @@ -3,19 +3,25 @@ using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Pastry : IPastryModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string PastryName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _pastryComponents = null; [NotMapped] + [DataMember] public Dictionary PastryComponents { get From a392caad33e6a0207af05a11d3c02d8209a37e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 22:21:03 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=BC=D0=B4=D0=B0=D0=B0=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryContracts.csproj | 3 ++ .../DI/UnityDependencyContainer.cs | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ConfectioneryContracts/DI/UnityDependencyContainer.cs diff --git a/ConfectioneryContracts/ConfectioneryContracts.csproj b/ConfectioneryContracts/ConfectioneryContracts.csproj index 09a95fc..2ccddfa 100644 --- a/ConfectioneryContracts/ConfectioneryContracts.csproj +++ b/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -9,6 +9,9 @@ + + + diff --git a/ConfectioneryContracts/DI/UnityDependencyContainer.cs b/ConfectioneryContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..dd5e085 --- /dev/null +++ b/ConfectioneryContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,39 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace ConfectioneryContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + _container.AddExtension(new LoggingExtension()); + } + + public void AddLogging(Action configure) + { + var factory = _container.Configure().LoggerFactory; + _container.Configure(); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} From a79e59759a2bbb55fc5d97fecd8c157fae67f9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 22:21:32 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=D1=87=D1=88=D0=B5=20=D1=81=D1=82=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectioneryContracts/DI/UnityDependencyContainer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ConfectioneryContracts/DI/UnityDependencyContainer.cs b/ConfectioneryContracts/DI/UnityDependencyContainer.cs index dd5e085..da703da 100644 --- a/ConfectioneryContracts/DI/UnityDependencyContainer.cs +++ b/ConfectioneryContracts/DI/UnityDependencyContainer.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.Logging; +using System.ComponentModel; using Unity; +using Unity.Lifetime; using Unity.Microsoft.Logging; namespace ConfectioneryContracts.DI @@ -11,13 +13,12 @@ namespace ConfectioneryContracts.DI public UnityDependencyContainer() { _container = new UnityContainer(); - _container.AddExtension(new LoggingExtension()); } public void AddLogging(Action configure) { - var factory = _container.Configure().LoggerFactory; - _container.Configure(); + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); } public void RegisterType(bool isSingle) where T : class