diff --git a/.gitignore b/.gitignore index e8d9387..e72f343 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ *.dll /Pizzeria/ImplementationExtensions +/Pizzeria/BusinessLogicExtensions # Mono auto generated files mono_crash.* diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BusinessLogicExtension.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BusinessLogicExtension.cs new file mode 100644 index 0000000..f4e1780 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BusinessLogicExtension.cs @@ -0,0 +1,34 @@ +using PizzeriaBusinessLogic.MailWorker; +using PizzeriaBusinessLogic.OfficePackage.Implements; +using PizzeriaBusinessLogic.OfficePackage; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class BusinessLogicExtension : IBusinessLogicExtension + { + 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj index bb052a8..15c3591 100644 --- a/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj +++ b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs b/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs index 3e1ba95..4b05d67 100644 --- a/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs +++ b/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs @@ -13,13 +13,18 @@ public bool IsUseAutoSize { get; private set; } - public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + 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/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs b/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs index 46f8bb8..412c23d 100644 --- a/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs +++ b/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs @@ -23,12 +23,14 @@ namespace PizzeriaContracts.DI public static void InitDependency() { var ext = ServiceProviderLoader.GetImplementationExtensions(); - if (ext == null) + var extLogic = ServiceProviderLoader.GetBusinessLogicExtensions(); + if (ext == null || extLogic == null) { throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); } // регистрируем зависимости ext.RegisterServices(); + extLogic.RegisterServices(); } /// diff --git a/Pizzeria/PizzeriaContracts/DI/IBusinessLogicExtension.cs b/Pizzeria/PizzeriaContracts/DI/IBusinessLogicExtension.cs new file mode 100644 index 0000000..b0b6837 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/IBusinessLogicExtension.cs @@ -0,0 +1,9 @@ +namespace PizzeriaContracts.DI +{ + public interface IBusinessLogicExtension + { + public int Priority { get; } + + public void RegisterServices(); + } +} diff --git a/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs b/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs index 80b8801..8720a0f 100644 --- a/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs +++ b/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs @@ -42,6 +42,35 @@ namespace PizzeriaContracts.DI return source; } + public static IBusinessLogicExtension? GetBusinessLogicExtensions() + { + IBusinessLogicExtension? source = null; + var files = Directory.GetFiles(TryGetBusinessLogicExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IBusinessLogicExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IBusinessLogicExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IBusinessLogicExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + private static string TryGetImplementationExtensionsFolder() { var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); @@ -51,5 +80,15 @@ namespace PizzeriaContracts.DI } return $"{directory?.FullName}\\ImplementationExtensions"; } + + private static string TryGetBusinessLogicExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("BusinessLogicExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\BusinessLogicExtensions"; + } } } diff --git a/Pizzeria/PizzeriaContracts/DI/UnityDependencyContainer.cs b/Pizzeria/PizzeriaContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..e3158a7 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace PizzeriaContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly UnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + _container.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj index cf9fe6a..5c0772e 100644 --- a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj +++ b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj @@ -8,6 +8,7 @@ + diff --git a/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs index d0b833d..610abc7 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs @@ -26,7 +26,7 @@ namespace PizzeriaContracts.ViewModels [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; - [DisplayName("Прочитанно")] + [Column("Прочитанно", width: 120)] public bool IsReaded { get; set; } public string? ReplyMessageId { get; set; } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs index 7ae212a..18f67d7 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs @@ -1,4 +1,5 @@ -using PizzeriaDataModels.Models; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -8,17 +9,25 @@ using System.Threading.Tasks; namespace PizzeriaContracts.ViewModels { + public class ShopViewModel : IShopModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название")] + + [Column(title: "Магазин", width: 200)] public string ShopName { get; set; } = string.Empty; - [DisplayName("Адрес")] + + [Column(title: "Адрес", width: 100)] public string Adress { get; set; } = string.Empty; - [DisplayName("Дата открытия")] + + [Column(title: "Дата открытия", width: 100, format: "d")] public DateTime OpeningDate { get; set; } + + [Column(visible: false)] public Dictionary ShopPizzas { get; set; } = new(); - [DisplayName("Вместимость")] + + [Column(title: "Вместимость", width: 100)] public int PizzaMaxCount { get; set; } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs b/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs index f44bee3..5458d21 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs @@ -14,6 +14,8 @@ namespace PizzeriaDatabaseImplement DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs index 0b3f928..897fdec 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs @@ -1,19 +1,32 @@ using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PizzeriaDatabaseImplement.Models { + [DataContract] public class Shop : IShopModel { + [DataMember] public int Id { get; set; } + + [DataMember] + [Required] public string ShopName { get; set; } = string.Empty; + [DataMember] + [Required] public string Adress { get; set; } = string.Empty; + [DataMember] + [Required] public DateTime OpeningDate { get; set; } + [DataMember] + [Required] public int PizzaMaxCount { get; set; } private Dictionary? _shopPizzas = null; diff --git a/Pizzeria/PizzeriaFileImplement/Models/Shop.cs b/Pizzeria/PizzeriaFileImplement/Models/Shop.cs index ccf98b0..4b091f1 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Shop.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Shop.cs @@ -7,18 +7,28 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace PizzeriaFileImplement.Models { + [DataContract] public class Shop : IShopModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string ShopName { get; private set; } = string.Empty; + + [DataMember] public string Adress { get; private set; } = string.Empty; + + [DataMember] public DateTime OpeningDate { get; private set; } public Dictionary Pizzas { get; private set; } = new(); private Dictionary? _shopPizzas = null; + [DataMember] public Dictionary ShopPizzas { get @@ -32,6 +42,7 @@ namespace PizzeriaFileImplement.Models } } + [DataMember] public int PizzaMaxCount { get; private set; } public static Shop? Create(ShopBindingModel? model) diff --git a/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs b/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs index 8b4f391..822e96b 100644 --- a/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs +++ b/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs @@ -28,22 +28,6 @@ namespace PizzeriaListImplement.Models public int Id => throw new NotImplementedException(); - public static MessageInfo? Create(MessageInfoBindingModel model) - { - if (model == null) - { - return null; - } - return new() - { - Body = model.Body, - Subject = model.Subject, - ClientId = model.ClientId, - MessageId = model.MessageId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - }; - } public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/Pizzeria/PizzeriaView/DataGridViewExtension.cs b/Pizzeria/PizzeriaView/DataGridViewExtension.cs index c82fdab..7bdd623 100644 --- a/Pizzeria/PizzeriaView/DataGridViewExtension.cs +++ b/Pizzeria/PizzeriaView/DataGridViewExtension.cs @@ -39,6 +39,7 @@ namespace PizzeriaView { column.Width = columnAttr.Width; } + column.DefaultCellStyle.Format = columnAttr.Format; } } } diff --git a/Pizzeria/PizzeriaView/FormComponents.Designer.cs b/Pizzeria/PizzeriaView/FormComponents.Designer.cs index 878ed95..c103da7 100644 --- a/Pizzeria/PizzeriaView/FormComponents.Designer.cs +++ b/Pizzeria/PizzeriaView/FormComponents.Designer.cs @@ -43,13 +43,12 @@ this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(10, 9); - this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Location = new System.Drawing.Point(11, 12); this.dataGridView.Name = "dataGridView"; this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.Size = new System.Drawing.Size(590, 427); this.dataGridView.TabIndex = 0; // // ToolsPanel @@ -58,18 +57,16 @@ this.ToolsPanel.Controls.Add(this.buttonDelete); this.ToolsPanel.Controls.Add(this.buttonEdit); this.ToolsPanel.Controls.Add(this.buttonAdd); - this.ToolsPanel.Location = new System.Drawing.Point(532, 9); - this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); this.ToolsPanel.Name = "ToolsPanel"; - this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.Size = new System.Drawing.Size(181, 427); this.ToolsPanel.TabIndex = 1; // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(27, 154); - this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Location = new System.Drawing.Point(31, 205); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(110, 27); + this.buttonUpdate.Size = new System.Drawing.Size(126, 36); this.buttonUpdate.TabIndex = 3; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -77,10 +74,9 @@ // // buttonDelete // - this.buttonDelete.Location = new System.Drawing.Point(27, 106); - this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Location = new System.Drawing.Point(31, 141); this.buttonDelete.Name = "buttonDelete"; - this.buttonDelete.Size = new System.Drawing.Size(110, 27); + this.buttonDelete.Size = new System.Drawing.Size(126, 36); this.buttonDelete.TabIndex = 2; this.buttonDelete.Text = "Удалить"; this.buttonDelete.UseVisualStyleBackColor = true; @@ -88,10 +84,9 @@ // // buttonEdit // - this.buttonEdit.Location = new System.Drawing.Point(27, 57); - this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Location = new System.Drawing.Point(31, 76); this.buttonEdit.Name = "buttonEdit"; - this.buttonEdit.Size = new System.Drawing.Size(110, 27); + this.buttonEdit.Size = new System.Drawing.Size(126, 36); this.buttonEdit.TabIndex = 1; this.buttonEdit.Text = "Изменить"; this.buttonEdit.UseVisualStyleBackColor = true; @@ -99,10 +94,9 @@ // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(27, 12); - this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Location = new System.Drawing.Point(31, 16); this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.Size = new System.Drawing.Size(126, 36); this.buttonAdd.TabIndex = 0; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; @@ -110,12 +104,11 @@ // // FormComponents // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(700, 338); + this.ClientSize = new System.Drawing.Size(800, 451); this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.dataGridView); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormComponents"; this.Text = "Ингредиенты"; this.Load += new System.EventHandler(this.FormComponents_Load); diff --git a/Pizzeria/PizzeriaView/FormComponents.cs b/Pizzeria/PizzeriaView/FormComponents.cs index 7c7e014..cca61f9 100644 --- a/Pizzeria/PizzeriaView/FormComponents.cs +++ b/Pizzeria/PizzeriaView/FormComponents.cs @@ -27,21 +27,13 @@ namespace PizzeriaView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка ингридиентов"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки ингридиентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Pizzeria/PizzeriaView/FormImplementers.Designer.cs b/Pizzeria/PizzeriaView/FormImplementers.Designer.cs index 2641948..3648c24 100644 --- a/Pizzeria/PizzeriaView/FormImplementers.Designer.cs +++ b/Pizzeria/PizzeriaView/FormImplementers.Designer.cs @@ -44,7 +44,7 @@ this.ToolsPanel.Controls.Add(this.buttonDel); this.ToolsPanel.Controls.Add(this.buttonUpd); this.ToolsPanel.Controls.Add(this.buttonAdd); - this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Location = new System.Drawing.Point(992, 12); this.ToolsPanel.Name = "ToolsPanel"; this.ToolsPanel.Size = new System.Drawing.Size(180, 426); this.ToolsPanel.TabIndex = 3; @@ -99,14 +99,14 @@ this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.Size = new System.Drawing.Size(957, 426); this.dataGridView.TabIndex = 2; // // FormImplementers // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(1206, 450); this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.dataGridView); this.Name = "FormImplementers"; diff --git a/Pizzeria/PizzeriaView/FormImplementers.cs b/Pizzeria/PizzeriaView/FormImplementers.cs index 339d97d..3d19faf 100644 --- a/Pizzeria/PizzeriaView/FormImplementers.cs +++ b/Pizzeria/PizzeriaView/FormImplementers.cs @@ -2,6 +2,7 @@ using Pizzeria; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -48,13 +49,10 @@ namespace PizzeriaView 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(); } } @@ -62,14 +60,11 @@ namespace PizzeriaView { 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/Pizzeria/PizzeriaView/FormLetter.cs b/Pizzeria/PizzeriaView/FormLetter.cs index 1d4534f..dedfbeb 100644 --- a/Pizzeria/PizzeriaView/FormLetter.cs +++ b/Pizzeria/PizzeriaView/FormLetter.cs @@ -3,6 +3,7 @@ using Pizzeria; using PizzeriaBusinessLogic.MailWorker; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; using PizzeriaContracts.SearchModels; using PizzeriaContracts.ViewModels; using System; @@ -110,7 +111,7 @@ namespace PizzeriaView private void buttonReply_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormLetter)); + var service = DependencyManager.Instance.Resolve(); if (service is FormLetter form) { if (!string.IsNullOrEmpty(model.ReplyMessageId)) diff --git a/Pizzeria/PizzeriaView/FormMail.cs b/Pizzeria/PizzeriaView/FormMail.cs index f69bead..12166f1 100644 --- a/Pizzeria/PizzeriaView/FormMail.cs +++ b/Pizzeria/PizzeriaView/FormMail.cs @@ -4,6 +4,7 @@ using Pizzeria; using PizzeriaBusinessLogic.BusinessLogics; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; using PizzeriaContracts.SearchModels; using System; using System.Collections.Generic; @@ -55,7 +56,7 @@ namespace PizzeriaView if (dataGridView.SelectedRows.Count <= 0) return; - var service = Program.ServiceProvider?.GetService(typeof(FormLetter)); + var service = DependencyManager.Instance.Resolve(); if (service is FormLetter form) { string? messageId = dataGridView.SelectedRows[0].Cells["MessageId"].Value.ToString(); diff --git a/Pizzeria/PizzeriaView/FormMain.Designer.cs b/Pizzeria/PizzeriaView/FormMain.Designer.cs index ad75f0f..9e7ae62 100644 --- a/Pizzeria/PizzeriaView/FormMain.Designer.cs +++ b/Pizzeria/PizzeriaView/FormMain.Designer.cs @@ -69,10 +69,11 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.bookToolStripMenuItem, - this.отчётыToolStripMenuItem, this.запускРаботToolStripMenuItem, + this.создатьБекапToolStripMenuItem, this.почтаToolStripMenuItem, - this.создатьБекапToolStripMenuItem}); + this.operationToolStripMenuItem, + this.отчётыToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index 85fa572..3c9fb07 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -150,29 +150,20 @@ namespace PizzeriaView private void shopsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void transactionToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); - if (service is FormCreateSupply form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void SellToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza)); - if (service is FormSellPizza form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) @@ -244,8 +235,7 @@ namespace PizzeriaView MessageBox.Show(ex.Message, "Ошибка создания бэкапа", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } - } + var service = Program.ServiceProvider?.GetService(typeof(FormMail)); if (service is FormMail form) { @@ -265,20 +255,14 @@ namespace PizzeriaView private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportShop)); - if (service is FormReportShop form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); - if (service is FormReportGroupedOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } } } diff --git a/Pizzeria/PizzeriaView/FormShops.Designer.cs b/Pizzeria/PizzeriaView/FormShops.Designer.cs index 3af7c45..05cb888 100644 --- a/Pizzeria/PizzeriaView/FormShops.Designer.cs +++ b/Pizzeria/PizzeriaView/FormShops.Designer.cs @@ -44,16 +44,16 @@ this.ToolsPanel.Controls.Add(this.buttonDel); this.ToolsPanel.Controls.Add(this.buttonUpd); this.ToolsPanel.Controls.Add(this.buttonAdd); - this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Location = new System.Drawing.Point(676, 12); this.ToolsPanel.Name = "ToolsPanel"; - this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.Size = new System.Drawing.Size(180, 406); this.ToolsPanel.TabIndex = 3; // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Location = new System.Drawing.Point(31, 196); this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.Size = new System.Drawing.Size(126, 34); this.buttonRef.TabIndex = 3; this.buttonRef.Text = "Обновить"; this.buttonRef.UseVisualStyleBackColor = true; @@ -61,9 +61,9 @@ // // buttonDel // - this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Location = new System.Drawing.Point(31, 135); this.buttonDel.Name = "buttonDel"; - this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.Size = new System.Drawing.Size(126, 34); this.buttonDel.TabIndex = 2; this.buttonDel.Text = "Удалить"; this.buttonDel.UseVisualStyleBackColor = true; @@ -71,9 +71,9 @@ // // buttonUpd // - this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Location = new System.Drawing.Point(31, 72); this.buttonUpd.Name = "buttonUpd"; - this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.Size = new System.Drawing.Size(126, 34); this.buttonUpd.TabIndex = 1; this.buttonUpd.Text = "Изменить"; this.buttonUpd.UseVisualStyleBackColor = true; @@ -81,9 +81,9 @@ // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Location = new System.Drawing.Point(31, 15); this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.Size = new System.Drawing.Size(126, 34); this.buttonAdd.TabIndex = 0; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; @@ -94,19 +94,19 @@ this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Location = new System.Drawing.Point(12, 11); this.dataGridView.Name = "dataGridView"; this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.Size = new System.Drawing.Size(649, 415); this.dataGridView.TabIndex = 2; // // FormShops // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(868, 429); this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.dataGridView); this.Name = "FormShops"; diff --git a/Pizzeria/PizzeriaView/FormShops.cs b/Pizzeria/PizzeriaView/FormShops.cs index b1f946e..404e629 100644 --- a/Pizzeria/PizzeriaView/FormShops.cs +++ b/Pizzeria/PizzeriaView/FormShops.cs @@ -2,6 +2,7 @@ using Pizzeria; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -35,15 +36,7 @@ namespace PizzeriaView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShopPizzas"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) @@ -55,7 +48,7 @@ namespace PizzeriaView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + var service = DependencyManager.Instance.Resolve(); if (service is FormShop form) { if (form.ShowDialog() == DialogResult.OK) @@ -69,7 +62,7 @@ namespace PizzeriaView { 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/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index e2e34c5..d1e6960 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -11,7 +11,6 @@ using PizzeriaView; using PizzeriaBusinessLogic.OfficePackage; using Microsoft.EntityFrameworkCore.Design; using PizzeriaContracts.DI; -using PizzeriaBusinessLogic.OfficePackage.Implements; namespace Pizzeria { @@ -62,34 +61,6 @@ namespace Pizzeria option.AddNLog("nlog.config"); }); - 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(true); - 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(); @@ -103,27 +74,14 @@ namespace Pizzeria 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(); - 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) => DependencyManager.Instance.Resolve()?.MailCheck();