From 725da7701e18f530244caea45c53666771573fb4 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Sun, 14 May 2023 00:56:36 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=92=D0=BE=D1=81=D1=8C=D0=BC=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../Confectionery/DataGridViewExtension.cs | 51 +++++++++ .../Confectionery/FormClients.Designer.cs | 6 +- Confectionery/Confectionery/FormClients.cs | 8 +- .../FormImplementers.Designer.cs | 12 +- .../Confectionery/FormImplementers.cs | 15 +-- .../Confectionery/FormIngredients.cs | 13 +-- Confectionery/Confectionery/FormMails.cs | 9 +- .../Confectionery/FormMain.Designer.cs | 24 ++-- Confectionery/Confectionery/FormMain.cs | 56 ++++++---- Confectionery/Confectionery/FormPastries.cs | 14 +-- Confectionery/Confectionery/FormPastry.cs | 5 +- Confectionery/Confectionery/Program.cs | 84 +++++++------- .../BusinessLogics/BackUpLogic.cs | 103 ++++++++++++++++++ .../Attributes/ColumnAttribute.cs | 31 ++++++ .../Attributes/GridViewAutoSize.cs | 20 ++++ .../BindingModels/BackUpSaveBinidngModel.cs | 13 +++ .../BusinessLogicsContracts/IBackUpLogic.cs | 14 +++ .../ConfectioneryContracts.csproj | 6 + .../DI/DependencyManager.cs | 66 +++++++++++ .../DI/IDependancyContainer.cs | 37 +++++++ .../DI/IImplementationExtension.cs | 17 +++ .../DI/ServiceDependencyContainer.cs | 62 +++++++++++ .../DI/ServiceProviderLoader.cs | 55 ++++++++++ .../DI/UnityDependancyContainer.cs | 42 +++++++ .../StoragesContracts/IBackUpInfo.cs | 15 +++ .../ViewModels/ClientViewModel.cs | 10 +- .../ViewModels/ImplementerViewModel.cs | 12 +- .../ViewModels/IngredientViewModel.cs | 8 +- .../ViewModels/MessageInfoViewModel.cs | 13 ++- .../ViewModels/OrderViewModel.cs | 25 +++-- .../ViewModels/PastryViewModel.cs | 9 +- .../ConfectioneryDataBaseImplement.csproj | 4 + .../DataBaseImplementationExtension.cs | 26 +++++ .../Implements/BackUpInfo.cs | 33 ++++++ .../Models/Client.cs | 6 + .../Models/Implementer.cs | 7 ++ .../Models/Ingredient.cs | 5 + .../Models/MessageInfo.cs | 8 ++ .../Models/Order.cs | 11 ++ .../Models/Pastry.cs | 6 + .../ConfectioneryFileImplement.csproj | 4 + .../FileImplementationExtension.cs | 26 +++++ .../Implements/BackUpInfo.cs | 42 +++++++ .../Models/Client.cs | 6 + .../Models/Implementer.cs | 10 +- .../Models/Ingredient.cs | 5 + .../Models/MessageInfo.cs | 8 ++ .../Models/Order.cs | 14 ++- .../Models/Pastry.cs | 6 + .../ConfectioneryListImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 22 ++++ .../ListImplementationExtension.cs | 27 +++++ 53 files changed, 971 insertions(+), 165 deletions(-) create mode 100644 Confectionery/Confectionery/DataGridViewExtension.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs create mode 100644 Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs create mode 100644 Confectionery/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/DI/DependencyManager.cs create mode 100644 Confectionery/ConfectioneryContracts/DI/IDependancyContainer.cs create mode 100644 Confectionery/ConfectioneryContracts/DI/IImplementationExtension.cs create mode 100644 Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs create mode 100644 Confectionery/ConfectioneryContracts/DI/ServiceProviderLoader.cs create mode 100644 Confectionery/ConfectioneryContracts/DI/UnityDependancyContainer.cs create mode 100644 Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/DataBaseImplementationExtension.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Implements/BackUpInfo.cs create mode 100644 Confectionery/ConfectioneryFileImplements/FileImplementationExtension.cs create mode 100644 Confectionery/ConfectioneryFileImplements/Implements/BackUpInfo.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs create mode 100644 Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..ecb2ca5 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/Confectionery/ImplementationExtensions \ No newline at end of file diff --git a/Confectionery/Confectionery/DataGridViewExtension.cs b/Confectionery/Confectionery/DataGridViewExtension.cs new file mode 100644 index 0000000..0ca546c --- /dev/null +++ b/Confectionery/Confectionery/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using ConfectioneryContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Confectionery +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + // ищем нужный нам атрибут + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} diff --git a/Confectionery/Confectionery/FormClients.Designer.cs b/Confectionery/Confectionery/FormClients.Designer.cs index 30db287..c2cc0a4 100644 --- a/Confectionery/Confectionery/FormClients.Designer.cs +++ b/Confectionery/Confectionery/FormClients.Designer.cs @@ -44,12 +44,12 @@ this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.Size = new System.Drawing.Size(605, 449); this.dataGridView.TabIndex = 1; // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(529, 12); + this.buttonRefresh.Location = new System.Drawing.Point(613, 12); this.buttonRefresh.Name = "buttonRefresh"; this.buttonRefresh.Size = new System.Drawing.Size(94, 29); this.buttonRefresh.TabIndex = 2; @@ -61,7 +61,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(660, 450); + this.ClientSize = new System.Drawing.Size(719, 450); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.dataGridView); this.Name = "FormClients"; diff --git a/Confectionery/Confectionery/FormClients.cs b/Confectionery/Confectionery/FormClients.cs index fc7176d..3ee152f 100644 --- a/Confectionery/Confectionery/FormClients.cs +++ b/Confectionery/Confectionery/FormClients.cs @@ -37,13 +37,7 @@ namespace Confectionery { 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/Confectionery/FormImplementers.Designer.cs b/Confectionery/Confectionery/FormImplementers.Designer.cs index e9ce8c9..52d2fd9 100644 --- a/Confectionery/Confectionery/FormImplementers.Designer.cs +++ b/Confectionery/Confectionery/FormImplementers.Designer.cs @@ -38,7 +38,7 @@ // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(523, 185); + this.buttonRef.Location = new System.Drawing.Point(625, 184); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(94, 29); this.buttonRef.TabIndex = 9; @@ -48,7 +48,7 @@ // // buttonDel // - this.buttonDel.Location = new System.Drawing.Point(523, 127); + this.buttonDel.Location = new System.Drawing.Point(625, 126); this.buttonDel.Name = "buttonDel"; this.buttonDel.Size = new System.Drawing.Size(94, 29); this.buttonDel.TabIndex = 8; @@ -58,7 +58,7 @@ // // buttonUpd // - this.buttonUpd.Location = new System.Drawing.Point(523, 70); + this.buttonUpd.Location = new System.Drawing.Point(625, 69); this.buttonUpd.Name = "buttonUpd"; this.buttonUpd.Size = new System.Drawing.Size(94, 29); this.buttonUpd.TabIndex = 7; @@ -68,7 +68,7 @@ // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(523, 13); + this.buttonAdd.Location = new System.Drawing.Point(625, 12); this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Size = new System.Drawing.Size(94, 29); this.buttonAdd.TabIndex = 6; @@ -87,14 +87,14 @@ this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.Size = new System.Drawing.Size(618, 449); this.dataGridView.TabIndex = 5; // // FormImplementers // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(628, 450); + this.ClientSize = new System.Drawing.Size(727, 450); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonDel); this.Controls.Add(this.buttonUpd); diff --git a/Confectionery/Confectionery/FormImplementers.cs b/Confectionery/Confectionery/FormImplementers.cs index 883f787..7d2f577 100644 --- a/Confectionery/Confectionery/FormImplementers.cs +++ b/Confectionery/Confectionery/FormImplementers.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,14 +34,8 @@ namespace Confectionery { 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) { @@ -51,7 +46,7 @@ namespace Confectionery private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -65,7 +60,7 @@ namespace Confectionery { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/Confectionery/Confectionery/FormIngredients.cs b/Confectionery/Confectionery/FormIngredients.cs index 42d7e50..ce842a5 100644 --- a/Confectionery/Confectionery/FormIngredients.cs +++ b/Confectionery/Confectionery/FormIngredients.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,13 +35,7 @@ namespace Confectionery { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -52,7 +47,7 @@ namespace Confectionery private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredient form) { if (form.ShowDialog() == DialogResult.OK) @@ -66,7 +61,7 @@ namespace Confectionery { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredient form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/Confectionery/Confectionery/FormMails.cs b/Confectionery/Confectionery/FormMails.cs index 3b06e0c..c365eec 100644 --- a/Confectionery/Confectionery/FormMails.cs +++ b/Confectionery/Confectionery/FormMails.cs @@ -27,14 +27,7 @@ namespace Confectionery { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/Confectionery/Confectionery/FormMain.Designer.cs b/Confectionery/Confectionery/FormMain.Designer.cs index 43fef5e..daa23c2 100644 --- a/Confectionery/Confectionery/FormMain.Designer.cs +++ b/Confectionery/Confectionery/FormMain.Designer.cs @@ -39,11 +39,12 @@ this.IngredientPastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -55,7 +56,8 @@ this.справочникиToolStripMenuItem, this.отчётыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.создатьБекапToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1703, 28); @@ -139,6 +141,13 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.Color.White; @@ -182,12 +191,12 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); // - // письмаToolStripMenuItem + // создатьБекапToolStripMenuItem // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); - this.письмаToolStripMenuItem.Text = "Письма"; - this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(123, 24); + this.создатьБекапToolStripMenuItem.Text = "Создать бекап"; + this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.создатьБекапToolStripMenuItem_Click); // // FormMain // @@ -229,5 +238,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs index 5b8cc52..65bb78d 100644 --- a/Confectionery/Confectionery/FormMain.cs +++ b/Confectionery/Confectionery/FormMain.cs @@ -1,6 +1,7 @@ using ConfectioneryBusinessLogic.BusinessLogics; using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -20,14 +21,16 @@ namespace Confectionery 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) @@ -40,18 +43,7 @@ namespace Confectionery _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["PastryId"].Visible = false; - dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ClientEmail"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); } catch (Exception ex) { @@ -62,7 +54,7 @@ namespace Confectionery private void ингредиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredients form) { form.ShowDialog(); @@ -71,7 +63,7 @@ namespace Confectionery private void изделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastries)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPastries form) { form.ShowDialog(); @@ -80,7 +72,7 @@ namespace Confectionery private void buttonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -175,7 +167,7 @@ namespace Confectionery private void IngredientPastriesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportPastryIngredients form) { form.ShowDialog(); @@ -184,7 +176,7 @@ namespace Confectionery private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -193,7 +185,7 @@ namespace Confectionery private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -202,7 +194,7 @@ namespace Confectionery private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -211,17 +203,37 @@ namespace Confectionery private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMails form) { form.ShowDialog(); } } + + private void создатьБекапToolStripMenuItem_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); + } + } } } diff --git a/Confectionery/Confectionery/FormPastries.cs b/Confectionery/Confectionery/FormPastries.cs index 46471e4..70280eb 100644 --- a/Confectionery/Confectionery/FormPastries.cs +++ b/Confectionery/Confectionery/FormPastries.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,14 +35,7 @@ namespace Confectionery { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PastryIngredients"].Visible = false; - dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) @@ -53,7 +47,7 @@ namespace Confectionery private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPastry form) { if (form.ShowDialog() == DialogResult.OK) @@ -67,7 +61,7 @@ namespace Confectionery { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPastry form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/Confectionery/Confectionery/FormPastry.cs b/Confectionery/Confectionery/FormPastry.cs index 3006995..c02718a 100644 --- a/Confectionery/Confectionery/FormPastry.cs +++ b/Confectionery/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; @@ -79,7 +80,7 @@ namespace Confectionery private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastryIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPastryIngredient form) { if (form.ShowDialog() == DialogResult.OK) @@ -106,7 +107,7 @@ namespace Confectionery { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastryIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPastryIngredient form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/Confectionery/Confectionery/Program.cs b/Confectionery/Confectionery/Program.cs index 47ca145..a86596e 100644 --- a/Confectionery/Confectionery/Program.cs +++ b/Confectionery/Confectionery/Program.cs @@ -9,13 +9,12 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using ConfectioneryBusinessLogic.MailWorker; using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.DI; namespace Confectionery { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. @@ -26,12 +25,10 @@ namespace Confectionery // To customize application configuration such as set high DPI settings 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, @@ -47,54 +44,51 @@ namespace Confectionery } 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(); - services.AddTransient(); - 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(); - } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/BackUpLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..cdb4576 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,103 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +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.BusinessLogics +{ + 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/Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs b/Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..1b6bbc9 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + + public bool Visible { get; private set; } + + public int Width { get; private set; } + + public GridViewAutoSize GridViewAutoSize { get; private set; } + + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs b/Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..aff1480 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +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/Confectionery/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..5360e67 --- /dev/null +++ b/Confectionery/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/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..c55c494 --- /dev/null +++ b/Confectionery/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/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj index b0b970c..c96077c 100644 --- a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj +++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/Confectionery/ConfectioneryContracts/DI/DependencyManager.cs b/Confectionery/ConfectioneryContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..880aad6 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public class DependencyManager + { + private readonly IDependancyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new UnityDependancyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/Confectionery/ConfectioneryContracts/DI/IDependancyContainer.cs b/Confectionery/ConfectioneryContracts/DI/IDependancyContainer.cs new file mode 100644 index 0000000..6a5f151 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/IDependancyContainer.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryContracts.DI +{ + public interface IDependancyContainer + { + /// + /// Регистрация логгера + /// + /// + 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/Confectionery/ConfectioneryContracts/DI/IImplementationExtension.cs b/Confectionery/ConfectioneryContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..c434658 --- /dev/null +++ b/Confectionery/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/Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs b/Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..b790780 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +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 ServiceDependencyContainer : IDependancyContainer + { + 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/Confectionery/ConfectioneryContracts/DI/ServiceProviderLoader.cs b/Confectionery/ConfectioneryContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..017dd9c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/Confectionery/ConfectioneryContracts/DI/UnityDependancyContainer.cs b/Confectionery/ConfectioneryContracts/DI/UnityDependancyContainer.cs new file mode 100644 index 0000000..a2370ad --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/UnityDependancyContainer.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using Unity.Microsoft.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; + +namespace ConfectioneryContracts.DI +{ + public class UnityDependancyContainer : IDependancyContainer + { + private readonly UnityContainer _unityContainer; + + public UnityDependancyContainer() + { + _unityContainer = new UnityContainer(); + } + public void AddLogging(Action configure) + { + _unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + void IDependancyContainer.RegisterType(bool isSingle) + { + if (isSingle) _unityContainer.RegisterSingleton(); + else _unityContainer.RegisterType(); + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) _unityContainer.RegisterSingleton(); + else _unityContainer.RegisterType(); + } + + public T Resolve() + { + return _unityContainer.Resolve(); + } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..d596fd6 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs index 84d002e..63ed7df 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.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 ClientViewModel : IClientModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title:"ФИО клиента", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title:"Логин (эл. почта)", width:200)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title:"Пароль", width:150)] public string Password { get; set; } = string.Empty; } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs index 4c4d896..0b895e4 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,15 @@ namespace ConfectioneryContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("ФИО")] + [Column(title:"ФИО", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string ImplementerFIO { get; set; } = String.Empty; - [DisplayName("Пароль")] + [Column(title:"Пароль", width:150)] public string Password { get; set; } = String.Empty; - [DisplayName("Опыт работы")] + [Column(title:"Опыт работы", width:120)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title:"Квалификация", width:120)] public int Qualification { get; set; } } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs index 81a9302..727f6f2 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace ConfectioneryContracts.ViewModels { public class IngredientViewModel : IIngredientModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("Название ингредиента")] + [Column(title:"Название ингредиента", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string IngredientName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title:"Цена", width:50)] public double Cost { get; set; } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs index 0b10bf7..0972e21 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,17 @@ namespace ConfectioneryContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible:false)] public string MessageId { get; set; } = string.Empty; + [Column(visible:false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column(title:"Отправитель", width:75)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Доставлено")] + [Column(title:"Доставлено")] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title:"Заголовок", width:75)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title:"Текст", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string Body { get; set; } = string.Empty; } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 2603110..b585c45 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/Confectionery/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,27 +12,31 @@ namespace ConfectioneryContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title:"Номер")] public int Id { get; set; } + [Column(visible:false)] public int PastryId { get; set; } - [DisplayName("Кондитерское изделие")] + [Column(title:"Кондитерское изделие", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string PastryName { get; set; } = string.Empty; + [Column(visible:false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + [Column(title:"Исполнитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string? ImplementerFIO { get; set; } + [Column(visible:false)] public int ClientId { get; set; } - [DisplayName("ФИО клиента")] + [Column(title:"ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; + [Column(visible:false)] public string ClientEmail { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title:"Количество", width:100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title:"Сумма", width:100)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title:"Статус", width:125)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title:"Дата создания", width: 120)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title:"Дата выполнения", width: 120)] public DateTime? DateImplement { get; set; } } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs index b96bfb9..8f70740 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,13 @@ namespace ConfectioneryContracts.ViewModels { public class PastryViewModel : IPastryModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("Название кондитерского изделия")] + [Column(title:"Название кондитерского изделия", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string PastryName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title:"Цена", width:75)] public double Price { get; set; } + [Column(visible:false)] public Dictionary PastryIngredients { get; diff --git a/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDataBaseImplement.csproj b/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDataBaseImplement.csproj index 6c6f63a..e289585 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDataBaseImplement.csproj +++ b/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDataBaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/Confectionery/ConfectioneryDataBaseImplement/DataBaseImplementationExtension.cs b/Confectionery/ConfectioneryDataBaseImplement/DataBaseImplementationExtension.cs new file mode 100644 index 0000000..0bd4493 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/DataBaseImplementationExtension.cs @@ -0,0 +1,26 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryDataBaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataBaseImplement +{ + public class DataBaseImplementationExtension : IImplementationExtension + { + public int Priority => 3; + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Implements/BackUpInfo.cs b/Confectionery/ConfectioneryDataBaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..2962b30 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,33 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataBaseImplement.Implements +{ + 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/Confectionery/ConfectioneryDataBaseImplement/Models/Client.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Client.cs index 2bed1fd..47147d7 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Client.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Client.cs @@ -6,18 +6,24 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ConfectioneryDataBaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ClientFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; + [DataMember] [Required] public string Email { get; private set; } = string.Empty; diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs index f23f6b3..3f0d245 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs @@ -6,20 +6,27 @@ 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 Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; + [DataMember] [Required] public int WorkExperience { get; set; } + [DataMember] [Required] public int Qualification { get; set; } [ForeignKey("ImplementerId")] diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Ingredient.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Ingredient.cs index 2f1d6a8..baaeb77 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Ingredient.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Ingredient.cs @@ -6,16 +6,21 @@ 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 Ingredient : IIngredientModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string IngredientName { get; private set; } = string.Empty; + [DataMember] [Required] public double Cost { get; set; } [ForeignKey("IngredientId")] diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs index 40aa044..0d2eaf3 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs @@ -6,23 +6,31 @@ 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 MessageInfo : IMessageInfoModel { + [DataMember] [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public string MessageId { get; set; } = string.Empty; + [DataMember] public int? ClientId { get; set; } + [DataMember] [Required] public string SenderName { get; set; } = string.Empty; + [DataMember] [Required] public DateTime DateDelivery { get; set; } + [DataMember] [Required] public string Subject { get; set; } = string.Empty; + [DataMember] [Required] public string Body { get; set; } = string.Empty; diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs index 1dfa5ec..2ef1fb9 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs @@ -6,29 +6,40 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ConfectioneryDataBaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public int PastryId { get; private set; } + [DataMember] [Required] public int ClientId { get; set; } public virtual Client Client { get; set; } = new(); + [DataMember] public int? ImplementerId { get; set; } public virtual Implementer? Implementer { get; set; } = new(); + [DataMember] [Required] public int Count { get; private set; } + [DataMember] [Required] public double Sum { get; private set; } + [DataMember] [Required] public OrderStatus Status { get; private set; } + [DataMember] [Required] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(ConfectioneryDatabase context, OrderBindingModel? model) { diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Pastry.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Pastry.cs index c7a3c44..37883ff 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Pastry.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Pastry.cs @@ -6,19 +6,25 @@ 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 Pastry : IPastryModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] public string PastryName { get; set; } = string.Empty; + [DataMember] [Required] public double Price { get; set; } private Dictionary? _pastryIngredients = null; + [DataMember] [NotMapped] public Dictionary PastryIngredients { diff --git a/Confectionery/ConfectioneryFileImplements/ConfectioneryFileImplement.csproj b/Confectionery/ConfectioneryFileImplements/ConfectioneryFileImplement.csproj index 68fca7e..919712e 100644 --- a/Confectionery/ConfectioneryFileImplements/ConfectioneryFileImplement.csproj +++ b/Confectionery/ConfectioneryFileImplements/ConfectioneryFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/Confectionery/ConfectioneryFileImplements/FileImplementationExtension.cs b/Confectionery/ConfectioneryFileImplements/FileImplementationExtension.cs new file mode 100644 index 0000000..68e2f1a --- /dev/null +++ b/Confectionery/ConfectioneryFileImplements/FileImplementationExtension.cs @@ -0,0 +1,26 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Confectionery/ConfectioneryFileImplements/Implements/BackUpInfo.cs b/Confectionery/ConfectioneryFileImplements/Implements/BackUpInfo.cs new file mode 100644 index 0000000..3cfb23a --- /dev/null +++ b/Confectionery/ConfectioneryFileImplements/Implements/BackUpInfo.cs @@ -0,0 +1,42 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public readonly DataFileSingleton _source; + + public BackUpInfo() + { + _source = DataFileSingleton.GetInstance(); + } + + public List? GetList() where T : class, new() + { + Type type = typeof(T); + var list = _source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments().First() == type)?.GetValue(_source); + return (List?)list; + } + + 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/Confectionery/ConfectioneryFileImplements/Models/Client.cs b/Confectionery/ConfectioneryFileImplements/Models/Client.cs index 9833239..9977654 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/Client.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/Client.cs @@ -4,17 +4,23 @@ using ConfectioneryDataModels.Models; 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.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; set; } + [DataMember] public string ClientFIO { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; public static Client? Create(ClientBindingModel? model) { diff --git a/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs b/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs index 95bed1b..0f7f720 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs @@ -5,21 +5,25 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ImplementerFIO { get; set; } = string.Empty; - + [DataMember] public string Password { get; set; } = string.Empty; - + [DataMember] public int WorkExperience { get; set; } - + [DataMember] public int Qualification { get; set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/Confectionery/ConfectioneryFileImplements/Models/Ingredient.cs b/Confectionery/ConfectioneryFileImplements/Models/Ingredient.cs index ed8c0bd..bee7479 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/Ingredient.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/Ingredient.cs @@ -5,16 +5,21 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { + [DataContract] public class Ingredient : IIngredientModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string IngredientName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Ingredient? Create(IngredientBindingModel model) { diff --git a/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs b/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs index 723d7fd..5afc9cc 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs @@ -4,19 +4,27 @@ using ConfectioneryDataModels.Models; 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.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; set; } = string.Empty; + [DataMember] public int? ClientId { get; set; } + [DataMember] public string SenderName { get; set; } = string.Empty; + [DataMember] public DateTime DateDelivery { get; set; } + [DataMember] public string Subject { get; set; } = string.Empty; + [DataMember] public string Body { get; set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) diff --git a/Confectionery/ConfectioneryFileImplements/Models/Order.cs b/Confectionery/ConfectioneryFileImplements/Models/Order.cs index 2db58fa..9ca1ab8 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/Order.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/Order.cs @@ -5,25 +5,33 @@ using ConfectioneryDataModels.Models; 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.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; private set; } + [DataMember] public int? ImplementerId { get; private 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/Confectionery/ConfectioneryFileImplements/Models/Pastry.cs b/Confectionery/ConfectioneryFileImplements/Models/Pastry.cs index 2bb7093..5f8bff9 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/Pastry.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/Pastry.cs @@ -4,17 +4,23 @@ using ConfectioneryDataModels.Models; 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.Models { + [DataContract] public class Pastry { + [DataMember] public int Id { get; private set; } + [DataMember] public string PastryName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } + [DataMember] public Dictionary Ingredients { get; private set; } = new(); private Dictionary? _pastryIngredients = null; public Dictionary PastryIngredients diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj index 41b6c3e..69d8853 100644 --- a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs b/Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..458b705 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + 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/Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs b/Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..b6e3c6f --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryListImplement.Implements; +using ConfectioneryListImplement.Models; +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(); + } + } +} -- 2.25.1 From 94cefbfbe1586be081f24aecf4ad82f451b63f04 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Mon, 15 May 2023 10:09:47 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=92=D0=BE=D1=81=D1=8C=D0=BC=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=A4?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=20id=20=D1=83=20messageinfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/MessageInfoBindingModel.cs | 2 + .../ViewModels/MessageInfoViewModel.cs | 2 + ...0230515055212_IdForMessageInfo.Designer.cs | 281 ++++++++++++++++++ .../20230515055212_IdForMessageInfo.cs | 29 ++ .../ConfectioneryDatabaseModelSnapshot.cs | 3 + .../Models/MessageInfo.cs | 1 + .../Models/IMessageInfoModel.cs | 2 +- .../Models/MessageInfo.cs | 2 + .../Models/MessageInfo.cs | 2 + 9 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.Designer.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.cs diff --git a/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs index 85b4c39..a84be8c 100644 --- a/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace ConfectioneryContracts.BindingModels public DateTime DateDelivery { get; set; } public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + + public int Id { get; set; } } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs index 0972e21..863604f 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs @@ -23,5 +23,7 @@ namespace ConfectioneryContracts.ViewModels public string Subject { get; set; } = string.Empty; [Column(title:"Текст", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string Body { get; set; } = string.Empty; + + public int Id { get; set; } } } diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.Designer.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.Designer.cs new file mode 100644 index 0000000..7e6e3b4 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.Designer.cs @@ -0,0 +1,281 @@ +// +using System; +using ConfectioneryDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ConfectioneryDataBaseImplement.Migrations +{ + [DbContext(typeof(ConfectioneryDatabase))] + [Migration("20230515055212_IdForMessageInfo")] + partial class IdForMessageInfo + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("IngredientName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ingredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("Id") + .HasColumnType("int"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.ToTable("MessageInfos"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PastryId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PastryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pastrys"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IngredientId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IngredientId"); + + b.HasIndex("PastryId"); + + b.ToTable("PastryIngredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b => + { + b.HasOne("ConfectioneryDataBaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null) + .WithMany("Orders") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => + { + b.HasOne("ConfectioneryDataBaseImplement.Models.Ingredient", "Ingredient") + .WithMany("PastryIgredients") + .HasForeignKey("IngredientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry") + .WithMany("Ingredients") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ingredient"); + + b.Navigation("Pastry"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => + { + b.Navigation("PastryIgredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b => + { + b.Navigation("Ingredients"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.cs new file mode 100644 index 0000000..e67fb33 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515055212_IdForMessageInfo.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ConfectioneryDataBaseImplement.Migrations +{ + /// + public partial class IdForMessageInfo : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Id", + table: "MessageInfos", + type: "int", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Id", + table: "MessageInfos"); + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs index ce1089f..342cf99 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs @@ -109,6 +109,9 @@ namespace ConfectioneryDataBaseImplement.Migrations b.Property("DateDelivery") .HasColumnType("datetime2"); + b.Property("Id") + .HasColumnType("int"); + b.Property("SenderName") .IsRequired() .HasColumnType("nvarchar(max)"); diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs index 0d2eaf3..1e1a106 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/MessageInfo.cs @@ -60,5 +60,6 @@ namespace ConfectioneryDataBaseImplement.Models Subject = Subject, DateDelivery = DateDelivery }; + public int Id { get; set; } } } diff --git a/Confectionery/ConfectioneryDataModels/Models/IMessageInfoModel.cs b/Confectionery/ConfectioneryDataModels/Models/IMessageInfoModel.cs index b9ef9d2..e005065 100644 --- a/Confectionery/ConfectioneryDataModels/Models/IMessageInfoModel.cs +++ b/Confectionery/ConfectioneryDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs b/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs index 5afc9cc..68c45a9 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/MessageInfo.cs @@ -78,5 +78,7 @@ namespace ConfectioneryFileImplement.Models new XElement("Subject", Subject), new XElement("Body", Body), new XElement("DateDelivery", DateDelivery.ToString())); + + public int Id { get; set; } } } diff --git a/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs b/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs index 18b93e9..42c29a8 100644 --- a/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs @@ -44,5 +44,7 @@ namespace ConfectioneryListImplement.Models Subject = Subject, DateDelivery = DateDelivery }; + + public int Id { get; set; } } } -- 2.25.1