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/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj b/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj index 4b0949c..24fc67c 100644 --- a/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj +++ b/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -17,4 +17,8 @@ + + + + diff --git a/ConfectionaryBusinessLogic/ImplementationBusinessLogicExtension.cs b/ConfectionaryBusinessLogic/ImplementationBusinessLogicExtension.cs new file mode 100644 index 0000000..cf5a010 --- /dev/null +++ b/ConfectionaryBusinessLogic/ImplementationBusinessLogicExtension.cs @@ -0,0 +1,39 @@ +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryBusinessLogic.MailWorker; +using ConfectioneryBusinessLogic.OfficePackage.Implements; +using ConfectioneryBusinessLogic.OfficePackage; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic +{ + public class ImplementationBusinessLogicExtension : IImplementationBusinessLogicExtension + { + 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/ConfectionaryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/ConfectionaryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 5e1ca7d..1009191 100644 --- a/ConfectionaryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/ConfectionaryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -1,9 +1,4 @@ using ConfectioneryContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels { 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..e5a38fc --- /dev/null +++ b/ConfectionaryFileImplement/FileImplementationExtension.cs @@ -0,0 +1,24 @@ +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(); + 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 ba0dc59..237966f 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,20 +12,29 @@ 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; + [DataMember] public bool HasRead { get; private set; } + [DataMember] public string? Reply { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel model) @@ -97,6 +107,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/ConfectionaryFileImplement/Shop.cs b/ConfectionaryFileImplement/Shop.cs index 928faf6..949be69 100644 --- a/ConfectionaryFileImplement/Shop.cs +++ b/ConfectionaryFileImplement/Shop.cs @@ -2,23 +2,30 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels; using ConfectioneryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ConfectioneryFileImplement { + [DataContract] public class Shop : IShopModel { + [DataMember] public string Name { get; private set; } = string.Empty; + [DataMember] public string Address { get; private set; } = string.Empty; + [DataMember] public int MaxCountPastries { get; private set; } + [DataMember] public DateTime DateOpening { get; private set; } public Dictionary CountPastries { get; private set; } = new(); private Dictionary? _cachedPastries = null; + [DataMember] public Dictionary Pastries { get @@ -34,6 +41,7 @@ namespace ConfectioneryFileImplement } } + [DataMember] public int Id { get; private set; } public static Shop? Create(ShopBindingModel? model) 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..c29e394 --- /dev/null +++ b/ConfectionaryListImplement/ListImplementationExtension.cs @@ -0,0 +1,29 @@ +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(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/ConfectionaryListImplement/MessageInfo.cs b/ConfectionaryListImplement/MessageInfo.cs index 588b890..9c96932 100644 --- a/ConfectionaryListImplement/MessageInfo.cs +++ b/ConfectionaryListImplement/MessageInfo.cs @@ -67,6 +67,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..f958470 --- /dev/null +++ b/Confectionery/DataGridViewExtension.cs @@ -0,0 +1,47 @@ +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; + column.DefaultCellStyle.Format = columnAttr.Format; + 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 d3b98cb..052ab2c 100644 --- a/Confectionery/FormMain.Designer.cs +++ b/Confectionery/FormMain.Designer.cs @@ -38,25 +38,26 @@ reportsToolStripMenuItem = new ToolStripMenuItem(); reportShopsToolStripMenuItem = new ToolStripMenuItem(); ShopPastriesToolStripMenuItem = new ToolStripMenuItem(); - groupOrdersToolStripMenuItem = new ToolStripMenuItem(); - pastriesToolStripMenuItem = new ToolStripMenuItem(); - pastryComponentsToolStripMenuItem = new ToolStripMenuItem(); - ordersToolStripMenuItem = new ToolStripMenuItem(); - mailToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); + groupOrdersToolStripMenuItem = new ToolStripMenuItem(); + pastriesToolStripMenuItem = new ToolStripMenuItem(); + pastryComponentsToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + DoWorkToolStripMenuItem = new ToolStripMenuItem(); + mailToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); buttonCreateOrder = new Button(); button3 = new Button(); button4 = new Button(); buttonAddPastryInShop = new Button(); - DoWorkToolStripMenuItem = new ToolStripMenuItem(); buttonSellPastry = new Button(); + createBackupToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, reportsToolStripMenuItem, DoWorkToolStripMenuItem, mailToolStripMenuItem }); + 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); @@ -161,6 +162,13 @@ 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; @@ -182,13 +190,6 @@ buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += ButtonCreateOrder_Click; // - // mailToolStripMenuItem - // - mailToolStripMenuItem.Name = "mailToolStripMenuItem"; - mailToolStripMenuItem.Size = new Size(62, 20); - mailToolStripMenuItem.Text = "Письма"; - mailToolStripMenuItem.Click += MailToolStripMenuItem_Click; - // // button3 // button3.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -233,6 +234,13 @@ buttonSellPastry.UseVisualStyleBackColor = true; buttonSellPastry.Click += ButtonSellPastry_Click; // + // createBackupToolStripMenuItem + // + createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem"; + createBackupToolStripMenuItem.Size = new Size(97, 20); + createBackupToolStripMenuItem.Text = "Создать бекап"; + createBackupToolStripMenuItem.Click += CreateBackupToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -277,8 +285,9 @@ private ToolStripMenuItem clientsToolStripMenuItem; private Button buttonAddPastryInShop; private Button buttonSellPastry; - private ToolStripMenuItem ImplementersToolStripMenuItem; - private ToolStripMenuItem DoWorkToolStripMenuItem; - private ToolStripMenuItem mailToolStripMenuItem; - } + private ToolStripMenuItem ImplementersToolStripMenuItem; + private ToolStripMenuItem DoWorkToolStripMenuItem; + private ToolStripMenuItem mailToolStripMenuItem; + private ToolStripMenuItem createBackupToolStripMenuItem; + } } \ No newline at end of file diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index ff448d9..294cfd4 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -1,6 +1,8 @@ +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; @@ -13,14 +15,16 @@ namespace ConfectioneryView 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) + 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) { @@ -30,18 +34,7 @@ namespace ConfectioneryView { 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; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation(" "); } catch (Exception ex) @@ -54,29 +47,21 @@ namespace ConfectioneryView private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void PastryToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormViewPastry)); - if (service is FormViewPastry form) - { - form.ShowDialog(); - } + 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(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } private void ButtonIssuedOrder_Click(object sender, EventArgs e) @@ -133,101 +118,98 @@ namespace ConfectioneryView private void ShopPastriesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportShopPastries)); - if (service is FormReportShopPastries form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void PastryComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents)); - if (service is FormReportPastryComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupOrders)); - if (service is FormReportGroupOrders form) - { - form.ShowDialog(); - } + 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(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormViewShops)); - if (service is FormViewShops form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ButtonAddPastryInShop_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormAddPastryInShop)); - if (service is FormAddPastryInShop form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ButtonSellPastry_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSellPastry)); - if (service is FormSellPastry form) - { - form.ShowDialog(); - } + 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(); - } + 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(); - } + 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 9c7655c..e91f5d5 100644 --- a/Confectionery/FormViewMail.cs +++ b/Confectionery/FormViewMail.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.DI; namespace ConfectioneryView { @@ -29,27 +30,20 @@ namespace ConfectioneryView buttonPrevPage.Enabled = false; } - private void FormViewMail_Load(object sender, EventArgs e) - { - MailLoad(); - } + private void FormViewMail_Load(object sender, EventArgs e) + { + MailLoad(); + } private bool MailLoad() { try { - var list = _logic.ReadList(new() + dataGridView.FillAndConfigGrid(_logic.ReadList(new() { Page = currentPage, PageSize = pageSize, - }); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + })); _logger.LogInformation("Загрузка списка писем"); labelInfoPages.Text = $"{currentPage} страница"; return true; @@ -99,13 +93,10 @@ namespace ConfectioneryView private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReplyMail)); - if (service is FormReplyMail form) - { - form.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value; - form.ShowDialog(); - MailLoad(); - } + var form = DependencyManager.Instance.Resolve(); + form.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value; + form.ShowDialog(); + MailLoad(); } } } 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/FormViewShops.cs b/Confectionery/FormViewShops.cs index 419130c..0e7d571 100644 --- a/Confectionery/FormViewShops.cs +++ b/Confectionery/FormViewShops.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; namespace ConfectioneryView @@ -22,16 +23,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["Pastries"].Visible = false; - dataGridView.Columns["Name"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) @@ -43,20 +35,17 @@ namespace ConfectioneryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop 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(FormShop)); + var service = DependencyManager.Instance.Resolve(); if (service is FormShop form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/Confectionery/Program.cs b/Confectionery/Program.cs index 5406826..08d9a81 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,65 +44,45 @@ 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(); - 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(); - services.AddSingleton(); - - 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(); - 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(); } - 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..3700e4a --- /dev/null +++ b/ConfectioneryContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,34 @@ +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 string Format { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, string format = "") + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + Format = format; + } + } +} 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 47b1fce..9fc38f3 100644 --- a/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs +++ b/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs @@ -23,5 +23,6 @@ namespace ConfectioneryContracts.BindingModels public bool HasRead { get; set; } public string? Reply { 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..2ccddfa 100644 --- a/ConfectioneryContracts/ConfectioneryContracts.csproj +++ b/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -6,6 +6,14 @@ enable + + + + + + + + diff --git a/ConfectioneryContracts/DI/DependencyManager.cs b/ConfectioneryContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..a35a967 --- /dev/null +++ b/ConfectioneryContracts/DI/DependencyManager.cs @@ -0,0 +1,69 @@ +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 extList = ServiceProviderLoader.GetImplementationExtensions(); + foreach(var ext in extList) + { + 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/IImplementationBusinessLogicExtension.cs b/ConfectioneryContracts/DI/IImplementationBusinessLogicExtension.cs new file mode 100644 index 0000000..b963103 --- /dev/null +++ b/ConfectioneryContracts/DI/IImplementationBusinessLogicExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + /// + /// Интерфейс для индентификации и отделения загрузки бизнес-логики от загрузки хранилищ + /// + /// + public interface IImplementationBusinessLogicExtension : IImplementationExtension { } +} 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..dca5bf3 --- /dev/null +++ b/ConfectioneryContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,65 @@ +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 List GetImplementationExtensions() + { + // Список типов, по каждому из которых, должна быть выбрана наиболее приоритетная реализация + // IImplementationExtension должен быть последним, поскольку все классы реализации, наследуются от него и являются им в частности + Type[] handledTypes = + { + typeof(IImplementationBusinessLogicExtension), + typeof(IImplementationExtension) + }; + var result = handledTypes.Select(x => (IImplementationExtension?)null).ToList(); + 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()) + { + for (var i = 0; i < handledTypes.Length; i++) + { + if (t.IsClass && handledTypes[i].IsAssignableFrom(t)) + { + if (result[i] == null) + { + result[i] = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > result[i].Priority) + { + result[i] = newSource; + } + } + } + } + } + } + return result; + } + + 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/DI/UnityDependencyContainer.cs b/ConfectioneryContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..da703da --- /dev/null +++ b/ConfectioneryContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using System.ComponentModel; +using Unity; +using Unity.Lifetime; +using Unity.Microsoft.Logging; + +namespace ConfectioneryContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + 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); + } + } +} 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..030efdc 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, format: "0.00")] 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 2955d75..57a4045 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,26 +11,32 @@ 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, format: "D")] 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; - [DisplayName("Прочитано")] + [Column(visible: false)] + + public int Id => throw new NotImplementedException(); + + [Column("Прочитано", gridViewAutoSize: GridViewAutoSize.AllCellsExceptHeader, isUseAutoSize: true)] public bool HasRead { get; set; } - [DisplayName("Ответ")] + [Column("Ответ", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string? Reply { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 49e9198..f37f316 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, format: "0.00")] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100, format: "D")] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100, format: "D")] public DateTime? DateImplement { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/ConfectioneryContracts/ViewModels/PastryViewModel.cs index 32831ba..6754b6a 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,14 @@ 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, format: "0.00")] public double Price { get; set; } + [Column(visible: false)] public Dictionary PastryComponents { get; diff --git a/ConfectioneryContracts/ViewModels/ShopViewModel.cs b/ConfectioneryContracts/ViewModels/ShopViewModel.cs index f7fce9b..8862f57 100644 --- a/ConfectioneryContracts/ViewModels/ShopViewModel.cs +++ b/ConfectioneryContracts/ViewModels/ShopViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels; using ConfectioneryDataModels.Models; using System.ComponentModel; @@ -6,24 +7,26 @@ namespace ConfectioneryContracts.ViewModels { public class ShopViewModel : IShopModel { - [DisplayName("Название магазина")] + [Column("Название магазина", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string Name { get; set; } = string.Empty; - [DisplayName("Адрес магазина")] + [Column("Адрес магазина", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Address { get; set; } = string.Empty; - [DisplayName("Максимальное количество изделий в магазине")] + [Column("Максимальное количество изделий в магазине", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public int MaxCountPastries { get; set; } - [DisplayName("Время открытия")] + [Column("Время открытия", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true, format: "f")] public DateTime DateOpening { get; set; } = DateTime.Now; + [Column(visible: false)] public Dictionary Pastries { get; set; } = new(); + [Column(visible: false)] public int Id { get; set; } } diff --git a/ConfectioneryDataModels/IMessageInfoModel.cs b/ConfectioneryDataModels/IMessageInfoModel.cs index 8db6579..63263d5 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..6492523 --- /dev/null +++ b/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,24 @@ +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(); + 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 4225660..0e3511c 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; } @@ -67,6 +70,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 85a0129..4ea5602 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 diff --git a/ConfectioneryDatabaseImplement/Shop.cs b/ConfectioneryDatabaseImplement/Shop.cs index 190e58d..cc4e49c 100644 --- a/ConfectioneryDatabaseImplement/Shop.cs +++ b/ConfectioneryDatabaseImplement/Shop.cs @@ -7,25 +7,32 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging.Abstractions; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Shop : IShopModel { [Required] + [DataMember] public string Name { get; private set; } = string.Empty; [Required] + [DataMember] public string Address { get; private set; } = string.Empty; [Required] + [DataMember] public int MaxCountPastries { get; private set; } + [DataMember] public DateTime DateOpening { get; private set; } private Dictionary? _cachedPastries = null; [NotMapped] + [DataMember] public Dictionary Pastries { get @@ -41,6 +48,7 @@ namespace ConfectioneryDatabaseImplement.Models } } + [DataMember] public int Id { get; private set; } [ForeignKey("ShopId")]