diff --git a/.gitignore b/.gitignore index d28d3b2..b9d330b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ #mac file .DS_Store - +ImplementationExtensions/ +/ImplementationExtensions/ # User-specific files *.rsuser *.suo diff --git a/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs b/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs new file mode 100644 index 0000000..ab884c3 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using FurnitureAssemblyContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyView +{ + public 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/FurnitureAssembly/FurnitureAssembly/FormClients.cs b/FurnitureAssembly/FurnitureAssembly/FormClients.cs index cfa5daa..4500f31 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormClients.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormClients.cs @@ -32,17 +32,7 @@ namespace FurnitureAssemblyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Email"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].Visible = false; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs b/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs index 57b7d19..0b8b320 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs @@ -1,6 +1,7 @@ using FurnitureAssembly; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.DI; using FurnitureAssemblyContracts.SearchModels; using FurnitureAssemblyDataModels.Models; using Microsoft.Extensions.Logging; @@ -25,10 +26,10 @@ namespace FurnitureAssemblyView public int Id { set { _id = value; } } public FormFurniture(ILogger logger, IFurnitureLogic logic) { - InitializeComponent(); - _logger = logger; - _logic = logic; - _productWorkpieces = new Dictionary(); + InitializeComponent(); + _logger = logger; + _logic = logic; + _productWorkpieces = new Dictionary(); } private void FormFurniture_Load(object sender, EventArgs e) { @@ -37,14 +38,8 @@ namespace FurnitureAssemblyView _logger.LogInformation("Загрузка заготовки"); try { - var view = _logic.ReadElement(new FurnitureSearchModel { Id =_id.Value }); - if (view != null) - { - textBoxName.Text = view.FurnitureName; - textBoxPrice.Text = view.Price.ToString(); - _productWorkpieces = view.FurnitureWorkpieces ?? new Dictionary(); - LoadData(); - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + } catch (Exception ex) { @@ -78,10 +73,7 @@ namespace FurnitureAssemblyView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormFurnitureWorkpiece)); - if (service is FormFurnitureWorkpiece form) - { + var form = DependencyManager.Instance.Resolve (); if (form.ShowDialog() == DialogResult.OK) { if (form.WorkpieceModel == null) @@ -98,16 +90,13 @@ namespace FurnitureAssemblyView _productWorkpieces.Add(form.Id, (form.WorkpieceModel,form.Count)); } LoadData(); - } } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormFurnitureWorkpiece)); - if (service is FormFurnitureWorkpiece form) - { + var form = DependencyManager.Instance.Resolve (); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; form.Count = _productWorkpieces[id].Item2; @@ -121,7 +110,6 @@ namespace FurnitureAssemblyView _productWorkpieces[form.Id] = (form.WorkpieceModel,form.Count); LoadData(); } - } } } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs b/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs index db7ea95..b58c7e8 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs @@ -1,6 +1,7 @@ using FurnitureAssembly; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -38,16 +39,7 @@ namespace FurnitureAssemblyView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["FurnitureWorkPieces"].Visible = false; - dataGridView.Columns["FurnitureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) @@ -59,31 +51,24 @@ namespace FurnitureAssemblyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormFurniture)); - - if (service is FormFurniture form) - { + var form = DependencyManager.Instance.Resolve < FormFurniture>(); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } - } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormFurniture)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormFurniture form) - { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs index f7d5f89..00475b2 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs @@ -1,6 +1,7 @@ using FurnitureAssembly; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,14 +34,7 @@ namespace FurnitureAssemblyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -53,31 +47,25 @@ namespace FurnitureAssemblyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateImplementer)); - if (service is FormCreateImplementer form) - { + var form = DependencyManager.Instance.Resolve(); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } - } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateImplementer)); - if (service is FormCreateImplementer form) - { + var form = DependencyManager.Instance.Resolve (); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } - } + } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMails.cs b/FurnitureAssembly/FurnitureAssembly/FormMails.cs index ec66672..3ac1084 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMails.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMails.cs @@ -37,16 +37,7 @@ namespace FurnitureAssemblyView try { - var list = _messageLogic.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(_messageLogic.ReadList(null)); _logger.LogInformation("Успешная загрузка писем"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 3944542..94175b1 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -40,6 +40,7 @@ компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem(); + создатьБэкапToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); ButtonCreateOrder = new Button(); ButtonIssuedOrder = new Button(); @@ -51,7 +52,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(32, 32); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, создатьБэкапToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1631, 42); @@ -68,35 +69,35 @@ // заготовкиToolStripMenuItem // заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem"; - заготовкиToolStripMenuItem.Size = new Size(359, 44); + заготовкиToolStripMenuItem.Size = new Size(295, 44); заготовкиToolStripMenuItem.Text = "Заготовки"; заготовкиToolStripMenuItem.Click += заготовкиToolStripMenuItem_Click; // // мебельToolStripMenuItem // мебельToolStripMenuItem.Name = "мебельToolStripMenuItem"; - мебельToolStripMenuItem.Size = new Size(359, 44); + мебельToolStripMenuItem.Size = new Size(295, 44); мебельToolStripMenuItem.Text = "Мебель"; мебельToolStripMenuItem.Click += мебельToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(359, 44); + клиентыToolStripMenuItem.Size = new Size(295, 44); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(359, 44); + исполнителиToolStripMenuItem.Size = new Size(295, 44); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; // // письмаToolStripMenuItem // письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - письмаToolStripMenuItem.Size = new Size(359, 44); + письмаToolStripMenuItem.Size = new Size(295, 44); письмаToolStripMenuItem.Text = "Письма"; письмаToolStripMenuItem.Click += MailsToolStripMenuItem_Click; // @@ -135,6 +136,13 @@ запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Click += doWorkToolStripMenuItem_Click; // + // создатьБэкапToolStripMenuItem + // + создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem"; + создатьБэкапToolStripMenuItem.Size = new Size(191, 38); + создатьБэкапToolStripMenuItem.Text = "Создать бэкап"; + создатьБэкапToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // // dataGridView // dataGridView.AllowUserToAddRows = false; @@ -228,5 +236,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБэкапToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 0387773..049c0ef 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -3,6 +3,7 @@ using FurnitureAssembly; using FurnitureAssemblyBusinessLogic.BusinessLogic; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.DI; using FurnitureAssemblyDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -23,7 +24,8 @@ namespace FurnitureAssemblyView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workModeling; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; @@ -31,6 +33,7 @@ namespace FurnitureAssemblyView _reportLogic = reportLogic; _workModeling = workModeling; _workModeling = workModeling; + _backUpLogic = backUpLogic; } private void MainForm_Load(object sender, EventArgs e) @@ -42,16 +45,7 @@ namespace FurnitureAssemblyView _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["FurnitureId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } - + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -63,31 +57,21 @@ namespace FurnitureAssemblyView private void заготовкиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkpieces)); - if (service is FormWorkpieces form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); - } } private void мебельToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormFurnitures)); - - if (service is FormFurnitures form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); - } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); LoadData(); - } } @@ -218,52 +202,59 @@ namespace FurnitureAssemblyView private void FurnituresComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportFurnitureWorkpieces)); - if (service is FormReportFurnitureWorkpieces form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); - } } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); - } } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); - } } private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); - } } private void doWorkToolStripMenuItem_Click(object sender, EventArgs e) { _workModeling.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + DependencyManager.Instance.Resolve() as IImplementerLogic)!, _orderLogic); } private void MailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - - if (service is FormMails form) - { + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); + } + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бэкап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormReportFurnitureWorkpieces.cs b/FurnitureAssembly/FurnitureAssembly/FormReportFurnitureWorkpieces.cs index c73cd24..11a007c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormReportFurnitureWorkpieces.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormReportFurnitureWorkpieces.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyBusinessLogic.BusinessLogic; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using System; @@ -48,10 +49,10 @@ namespace FurnitureAssemblyView dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); dataGridView.Rows.Add(Array.Empty()); - } + } } - _logger.LogInformation("Загрузка списка изделий по заготовкам"); + _logger.LogInformation("Загрузка списка изделий по заготовкам"); } catch (Exception ex) { diff --git a/FurnitureAssembly/FurnitureAssembly/FormWorkpieces.cs b/FurnitureAssembly/FurnitureAssembly/FormWorkpieces.cs index fe8d9d5..16b1229 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormWorkpieces.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormWorkpieces.cs @@ -1,6 +1,7 @@ using FurnitureAssembly; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -16,7 +17,7 @@ namespace FurnitureAssemblyView { public partial class FormWorkpieces : Form { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IWorkpieceLogic _logic; public FormWorkpieces(ILogger logger, IWorkpieceLogic logic) { @@ -32,13 +33,7 @@ namespace FurnitureAssemblyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["WorkpieceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -50,30 +45,24 @@ namespace FurnitureAssemblyView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkpiece)); - if (service is FormWorkpiece form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkpiece)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormWorkpiece form) - { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } - } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj b/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj index c426ea7..88457fa 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj @@ -26,14 +26,20 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 905c774..8fd5d73 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -11,13 +11,12 @@ using NLog.Extensions.Logging; using System; using FurnitureAssemblyBusinessLogic.MailWorker; using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.DI; namespace FurnitureAssembly { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -27,12 +26,10 @@ namespace FurnitureAssembly // 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, @@ -48,56 +45,60 @@ namespace FurnitureAssembly } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "<22><> <20><> <20> <20><>"); } - 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); + 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(); + 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/BackUpLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..8101bd1 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,102 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyDataModels; +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 FurnitureAssemblyBusinessLogic.BusinessLogic +{ + 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/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..01dd433 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + 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; + } + 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; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..294d289 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..f356174 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs index 850b145..b7f0d62 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace FurnitureAssemblyContracts.BindingModels public DateTime DateDelivery { get; set; } = DateTime.Now; public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IBackUpLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..ef6674c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using FurnitureAssemblyContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..a9f17b4 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs @@ -0,0 +1,68 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + private static DependencyManager? _manager; + private static readonly object _locjObject = new(); + private DependencyManager() + { + _dependencyManager = new UnityDependencyContainer(); + } + 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/FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..da93a03 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.DI +{ + public interface IDependencyContainer + { + /// + /// Регистрация логгера + /// + /// + void AddLogging(Action configure); + /// + /// Добавление зависимости + /// + /// + /// + /// + void RegisterType(bool isSingle) where U : class, T where T : + class; + /// + /// Добавление зависимости + /// + /// + /// + void RegisterType(bool isSingle) where T : class; + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + T Resolve(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..1b722b8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceDependencyContainer.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..c313e51 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/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 FurnitureAssemblyContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..f6ca78e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.DI +{ + public static partial 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/FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..32fcdc6 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Logging; +using Unity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity.Microsoft.Logging; + + +namespace FurnitureAssemblyContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer container; + + public UnityDependencyContainer() + { + container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + // регистрируем логгер в контейнере + var factory = LoggerFactory.Create(configure); + container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + container.RegisterSingleton(); + } + else + { + container.RegisterType(); + } + } + + public T Resolve() + { + return container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + if (isSingle) + { + container.RegisterSingleton(); + } + else + { + container.RegisterType(); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj b/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj index 71e2e97..d197c46 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj +++ b/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..85f4910 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs index 22784d6..d4dec8a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace FurnitureAssemblyContracts.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: 150)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs index 82ae56c..3d36130 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,13 @@ namespace FurnitureAssemblyContracts.ViewModels { public class FurnitureViewModel : IFurnitureModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название мебели")] + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string FurnitureName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Price { get; set; } + [Column(visible: false)] public Dictionary FurnitureWorkpieces { get; set;} = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs index e1033fc..1ec5b16 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,15 @@ namespace FurnitureAssemblyContracts.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: "Опыт работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index db50a55..87b876a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,19 +11,19 @@ namespace FurnitureAssemblyContracts.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: "Отправитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - - [DisplayName("Дата отправки")] - public DateTime DateDelivery { get; set; } = DateTime.Now; - - [DisplayName("Заголовок")] + [Column(title: "Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } + [Column(title: "Заголовок", width: 170)] public string Subject { get; set; } = string.Empty; - - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs index 3e1fbea..eede18d 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs @@ -6,31 +6,35 @@ using System.Linq; using System.ComponentModel; using System.Text; using System.Threading.Tasks; +using FurnitureAssemblyContracts.Attributes; namespace FurnitureAssemblyContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 50)] public int Id { get; set; } - public int FurnitureId { get; set; } - [DisplayName("Изделие")] - public string FurnitureName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now.ToUniversalTime(); - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { 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 int FurnitureId { get; set; } + [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string FurnitureName { get; set; } = string.Empty; + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public int Count { get; set; } + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public double Sum { get; set; } + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + [Column(title: "Исполнитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string? ImplementerFIO { get; set; } = string.Empty; } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/WorkpieceViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/WorkpieceViewModel.cs index d4563e3..ddbdf4a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/WorkpieceViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/WorkpieceViewModel.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace FurnitureAssemblyContracts.ViewModels { public class WorkpieceViewModel : IWorkpieceModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название заготовки")] + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string WorkpieceName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Cost { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs index 3dcb9d2..6ca701e 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..cad2ae9 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using FurnitureAssemblyContracts.DI; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj index 0437415..05a7055 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj @@ -25,4 +25,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..65fd1f1 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,31 @@ +using FurnitureAssemblyContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new FurnitureAssemblyDatabase(); + 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/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs index 0de7a1f..4c9666b 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs @@ -29,29 +29,25 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password)) + { + return null; + } using var context = new FurnitureAssemblyDatabase(); - if (model.Id.HasValue) { - return context.Clients - .Include(x => x.Orders) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } - - if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + if (model.Email != null && model.Password != null) { return context.Clients - .Include(x => x.Orders) - .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password)) + .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) ?.GetViewModel; } - - if (!string.IsNullOrEmpty(model.Email)) - return context.Clients - .FirstOrDefault(x => x.Email == model.Email) - ?.GetViewModel; - + if (model.Email != null) + { + return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel; + } return null; } public List GetFilteredList(ClientSearchModel model) diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs index 2f8a9ec..2aefe2e 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs @@ -6,23 +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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] - public virtual List Orders { get; set; } = new(); - [ForeignKey("ClientId")] public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index fa02fb9..ba9f2bc 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -7,24 +7,30 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Furniture : IFurnitureModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string FurnitureName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } public Dictionary? _furnitureWorkpieces = null; [NotMapped] + [DataMember] public Dictionary FurnitureWorkpieces { get diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs index cc28bed..65481d7 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs @@ -8,19 +8,26 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using FurnitureAssemblyContracts.ViewModels; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; private set; } [Required] + [DataMember] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] public virtual List Orders { get; private set; } = new(); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs index 7060ef3..9b0d3d0 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs @@ -5,29 +5,37 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; set; } = string.Empty; - + [DataMember] public int? ClientId { get; set; } [Required] + [DataMember] public string SenderName { get; set; } = string.Empty; [Required] + [DataMember] public DateTime DateDelivery { get; set; } = DateTime.Now; [Required] + [DataMember] public string Subject { get; set; } = string.Empty; [Required] + [DataMember] public string Body { get; set; } = string.Empty; + public int Id => throw new NotImplementedException(); public virtual Client? Client { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs index 8f84dcf..4c99d79 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -7,30 +7,39 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { [ForeignKey("ProductId")] + [DataMember] public int FurnitureId { get; set; } [Required] + [DataMember] public int Count { get; set; } [Required] + [DataMember] public double Sum { get; set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now.ToUniversalTime(); - + [DataMember] public DateTime? DateImplement { get; set; } - + [DataMember] public int Id { get; set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } public virtual Client Client { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Workpiece.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Workpiece.cs index 171c0b3..492e783 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Workpiece.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Workpiece.cs @@ -6,19 +6,24 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Workpiece : IWorkpieceModel { + [DataMember] public int Id { get; private set; } - + [Required] + [DataMember] public string WorkpieceName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } // для реализации связи многие ко многим с изделиями diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/FileImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..f2c4aef --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using FurnitureAssemblyContracts.DI; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyFileImplement +{ + 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/FurnitureAssembly/FurnitureAssemblyFileImplement/FurnitureAssemblyFileImplement.csproj b/FurnitureAssembly/FurnitureAssemblyFileImplement/FurnitureAssemblyFileImplement.csproj index 1080ca1..bfd0423 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/FurnitureAssemblyFileImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/FurnitureAssemblyFileImplement.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..60ad750 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,34 @@ +using FurnitureAssemblyContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + DataFileSingleton dataFileSingleton = DataFileSingleton.GetInstance(); + return (List?)dataFileSingleton.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))? + .GetValue(dataFileSingleton); + } + + 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/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Client.cs index 4f2cbf3..505f2fd 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Client.cs @@ -4,20 +4,23 @@ using FurnitureAssemblyDataModels.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 FurnitureAssemblyFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ClientFIO { get; private set; } = string.Empty; - + [DataMember] public string Email { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Furniture.cs index 20a14ad..2665902 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Furniture.cs @@ -4,23 +4,27 @@ using FurnitureAssemblyDataModels.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 FurnitureAssemblyFileImplement.Models { + [DataContract] public class Furniture { + [DataMember] public int Id { get; private set; } - + [DataMember] public string FurnitureName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Workpieces { get; private set; } = new(); private Dictionary? _furnitureWorkpieces = null; - + [DataMember] public Dictionary FurnitureWorkpieces { get diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs index 2b0d7a7..e439db7 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs @@ -4,21 +4,25 @@ using FurnitureAssemblyDataModels.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 FurnitureAssemblyFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/MessageInfo.cs index 17e2675..bfbcbc0 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/MessageInfo.cs @@ -4,20 +4,29 @@ using FurnitureAssemblyDataModels.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 FurnitureAssemblyFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now.ToUniversalTime(); + [DataMember] public string Subject { get; private set; } = string.Empty; + [DataMember] public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs index 80c1fea..80ad776 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs @@ -6,20 +6,23 @@ 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 FurnitureAssemblyFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public int FurnitureId { get; private set; } - + [DataMember] public int Count { get; private set; } - + [DataMember] public double Sum { get; private set; } public int ClientId { get; private set; } diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Workpiece.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Workpiece.cs index 7cff060..9134523 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Workpiece.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Workpiece.cs @@ -5,18 +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 FurnitureAssemblyFileImplement.Models { + [DataContract] public class Workpiece : IWorkpieceModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string WorkpieceName { get; private set; } = string.Empty; - + [DataMember] public double Cost { get; set; } public static Workpiece? Create(WorkpieceBindingModel model) diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj index 1b8ba63..864199b 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj @@ -8,8 +8,11 @@ - + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..17649c2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using FurnitureAssemblyContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.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/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..54bfa0d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using FurnitureAssemblyContracts.DI; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs index a39317f..88a986b 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs @@ -14,9 +14,10 @@ namespace FurnitureAssemblyListImplement.Models public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + public DateTime DateDelivery { get; private set; } = DateTime.Now.ToUniversalTime(); public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); public static MessageInfo? Create(MessageInfoBindingModel? model) { if (model == null) diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs index 7c692cd..d5740f2 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs @@ -1,6 +1,5 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; -using FurnitureAssemblyDatabaseImplement.Models; using FurnitureAssemblyDataModels.Enums; using FurnitureAssemblyDataModels.Models; using System;