From 8028c36b1a31bbc1a0cd1b1571ae470e17fa5747 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 29 Apr 2023 12:30:45 +0400 Subject: [PATCH 1/8] =?UTF-8?q?LabWork08=20=D0=BF=D0=BE=20=D0=A2=D0=97.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataGridViewExtension.cs | 61 +++ .../BlacksmithWorkshop/FormClients.cs | 21 +- .../BlacksmithWorkshop/FormMain.Designer.cs | 425 +++++++++--------- .../BlacksmithWorkshop/FormMain.cs | 59 ++- .../BlacksmithWorkshop/Program.cs | 90 ++-- .../BusinessLogic/BackUpLogic.cs | 125 ++++++ .../Attributes/ColumnAttribute.cs | 32 ++ .../Attributes/GridViewAutoSize.cs | 27 ++ .../BindingModels/BackUpSaveBinidngModel.cs | 14 + .../BlacksmithWorkshopContracts.csproj | 4 + .../BusinessLogicsContracts/IBackUpLogic.cs | 17 + .../DI/DependencyManager.cs | 63 +++ .../DI/IDependencyContainer.cs | 26 ++ .../DI/IImplementationExtension.cs | 19 + .../DI/ServiceProviderLoader.cs | 61 +++ .../StoragesContracts/IBackUpInfo.cs | 18 + .../ViewModels/ClientViewModel.cs | 3 - .../Implements/BackUpInfo.cs | 36 ++ .../ListImplementationExtension.cs | 34 ++ 19 files changed, 845 insertions(+), 290 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs new file mode 100644 index 0000000..5f555c7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs @@ -0,0 +1,61 @@ +using BlacksmithWorkshopContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshop +{ + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs index 0ed15ea..c271656 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs @@ -36,21 +36,12 @@ namespace BlacksmithWorkshop private void LoadData() { - _logger.LogInformation("Загрузка клиентов"); - - try - { - var list = _clientLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Успешная загрузка клиентов"); - } - catch (Exception ex) + try + { + dataGridView.FillandConfigGrid(_clientLogic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки клиентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 8899630..0e0f3a9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -22,215 +22,224 @@ #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - menuStrip = new MenuStrip(); - toolStripMenuItem = new ToolStripMenuItem(); - workPieceToolStripMenuItem = new ToolStripMenuItem(); - manufactureToolStripMenuItem = new ToolStripMenuItem(); - reportsToolStripMenuItem = new ToolStripMenuItem(); - workPiecesToolStripMenuItem = new ToolStripMenuItem(); - workPieceManufacturesToolStripMenuItem = new ToolStripMenuItem(); - ordersToolStripMenuItem = new ToolStripMenuItem(); - workWithClientsToolStripMenuItem = new ToolStripMenuItem(); - clientsToolStripMenuItem = new ToolStripMenuItem(); - работаСИсполнителямиToolStripMenuItem = new ToolStripMenuItem(); - implementerToolStripMenuItem = new ToolStripMenuItem(); - startingWorkToolStripMenuItem = new ToolStripMenuItem(); - mailsToolStripMenuItem = new ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - menuStrip.SuspendLayout(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 36); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(1209, 402); - dataGridView.TabIndex = 0; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(1247, 70); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(235, 29); - buttonCreateOrder.TabIndex = 1; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(1247, 144); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(235, 29); - buttonIssuedOrder.TabIndex = 4; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Location = new Point(1247, 221); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(235, 29); - buttonRef.TabIndex = 5; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // menuStrip - // - menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, reportsToolStripMenuItem, workWithClientsToolStripMenuItem, работаСИсполнителямиToolStripMenuItem, startingWorkToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1506, 28); - menuStrip.TabIndex = 6; - menuStrip.Text = "menuStrip1"; - // - // toolStripMenuItem - // - toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPieceToolStripMenuItem, manufactureToolStripMenuItem, mailsToolStripMenuItem }); - toolStripMenuItem.Name = "toolStripMenuItem"; - toolStripMenuItem.Size = new Size(117, 24); - toolStripMenuItem.Text = "Справочники"; - // - // workPieceToolStripMenuItem - // - workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; - workPieceToolStripMenuItem.Size = new Size(224, 26); - workPieceToolStripMenuItem.Text = "Заготовки"; - workPieceToolStripMenuItem.Click += WorkPieceToolStripMenuItem_Click; - // - // manufactureToolStripMenuItem - // - manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem"; - manufactureToolStripMenuItem.Size = new Size(224, 26); - manufactureToolStripMenuItem.Text = "Изделия"; - manufactureToolStripMenuItem.Click += ManufactureToolStripMenuItem_Click; - // - // reportsToolStripMenuItem - // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPiecesToolStripMenuItem, workPieceManufacturesToolStripMenuItem, ordersToolStripMenuItem }); - reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; - reportsToolStripMenuItem.Size = new Size(73, 24); - reportsToolStripMenuItem.Text = "Отчёты"; - // - // workPiecesToolStripMenuItem - // - workPiecesToolStripMenuItem.Name = "workPiecesToolStripMenuItem"; - workPiecesToolStripMenuItem.Size = new Size(256, 26); - workPiecesToolStripMenuItem.Text = "Список заготовок"; - workPiecesToolStripMenuItem.Click += WorkPiecesToolStripMenuItem_Click; - // - // workPieceManufacturesToolStripMenuItem - // - workPieceManufacturesToolStripMenuItem.Name = "workPieceManufacturesToolStripMenuItem"; - workPieceManufacturesToolStripMenuItem.Size = new Size(256, 26); - workPieceManufacturesToolStripMenuItem.Text = "Заготовки по изделиям"; - workPieceManufacturesToolStripMenuItem.Click += WorkPieceManufacturesToolStripMenuItem_Click; - // - // ordersToolStripMenuItem - // - ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - ordersToolStripMenuItem.Size = new Size(256, 26); - ordersToolStripMenuItem.Text = "Список заказов"; - ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; - // - // workWithClientsToolStripMenuItem - // - workWithClientsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { clientsToolStripMenuItem }); - workWithClientsToolStripMenuItem.Name = "workWithClientsToolStripMenuItem"; - workWithClientsToolStripMenuItem.Size = new Size(161, 24); - workWithClientsToolStripMenuItem.Text = "Работа с клиентами"; - // - // clientsToolStripMenuItem - // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(152, 26); - clientsToolStripMenuItem.Text = "Клиенты"; - clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // - // работаСИсполнителямиToolStripMenuItem - // - работаСИсполнителямиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { implementerToolStripMenuItem }); - работаСИсполнителямиToolStripMenuItem.Name = "работаСИсполнителямиToolStripMenuItem"; - работаСИсполнителямиToolStripMenuItem.Size = new Size(196, 24); - работаСИсполнителямиToolStripMenuItem.Text = "Работа с исполнителями"; - // - // implementerToolStripMenuItem - // - implementerToolStripMenuItem.Name = "implementerToolStripMenuItem"; - implementerToolStripMenuItem.Size = new Size(185, 26); - implementerToolStripMenuItem.Text = "Исполнители"; - implementerToolStripMenuItem.Click += ImplementerToolStripMenuItem_Click; - // - // startingWorkToolStripMenuItem - // - startingWorkToolStripMenuItem.Name = "startingWorkToolStripMenuItem"; - startingWorkToolStripMenuItem.Size = new Size(114, 24); - startingWorkToolStripMenuItem.Text = "Запуск работ"; - startingWorkToolStripMenuItem.Click += StartingWorkToolStripMenuItem_Click; - // - // mailsToolStripMenuItem - // - mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; - mailsToolStripMenuItem.Size = new Size(224, 26); - mailsToolStripMenuItem.Text = "Письма"; - mailsToolStripMenuItem.Click += MailsToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1506, 450); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Name = "FormMain"; - Text = "Кузнечная мастерская"; - Load += FormMain_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip = new MenuStrip(); + toolStripMenuItem = new ToolStripMenuItem(); + workPieceToolStripMenuItem = new ToolStripMenuItem(); + manufactureToolStripMenuItem = new ToolStripMenuItem(); + mailsToolStripMenuItem = new ToolStripMenuItem(); + reportsToolStripMenuItem = new ToolStripMenuItem(); + workPiecesToolStripMenuItem = new ToolStripMenuItem(); + workPieceManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + workWithClientsToolStripMenuItem = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + работаСИсполнителямиToolStripMenuItem = new ToolStripMenuItem(); + implementerToolStripMenuItem = new ToolStripMenuItem(); + startingWorkToolStripMenuItem = new ToolStripMenuItem(); + createBackUpToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 36); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(1209, 402); + dataGridView.TabIndex = 0; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1247, 70); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(235, 29); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1247, 144); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(235, 29); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(1247, 221); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(235, 29); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, reportsToolStripMenuItem, workWithClientsToolStripMenuItem, работаСИсполнителямиToolStripMenuItem, startingWorkToolStripMenuItem, createBackUpToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1506, 28); + menuStrip.TabIndex = 6; + menuStrip.Text = "menuStrip1"; + // + // toolStripMenuItem + // + toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPieceToolStripMenuItem, manufactureToolStripMenuItem, mailsToolStripMenuItem }); + toolStripMenuItem.Name = "toolStripMenuItem"; + toolStripMenuItem.Size = new Size(117, 24); + toolStripMenuItem.Text = "Справочники"; + // + // workPieceToolStripMenuItem + // + workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; + workPieceToolStripMenuItem.Size = new Size(162, 26); + workPieceToolStripMenuItem.Text = "Заготовки"; + workPieceToolStripMenuItem.Click += WorkPieceToolStripMenuItem_Click; + // + // manufactureToolStripMenuItem + // + manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem"; + manufactureToolStripMenuItem.Size = new Size(162, 26); + manufactureToolStripMenuItem.Text = "Изделия"; + manufactureToolStripMenuItem.Click += ManufactureToolStripMenuItem_Click; + // + // mailsToolStripMenuItem + // + mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; + mailsToolStripMenuItem.Size = new Size(162, 26); + mailsToolStripMenuItem.Text = "Письма"; + mailsToolStripMenuItem.Click += MailsToolStripMenuItem_Click; + // + // reportsToolStripMenuItem + // + reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPiecesToolStripMenuItem, workPieceManufacturesToolStripMenuItem, ordersToolStripMenuItem }); + reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; + reportsToolStripMenuItem.Size = new Size(73, 24); + reportsToolStripMenuItem.Text = "Отчёты"; + // + // workPiecesToolStripMenuItem + // + workPiecesToolStripMenuItem.Name = "workPiecesToolStripMenuItem"; + workPiecesToolStripMenuItem.Size = new Size(256, 26); + workPiecesToolStripMenuItem.Text = "Список заготовок"; + workPiecesToolStripMenuItem.Click += WorkPiecesToolStripMenuItem_Click; + // + // workPieceManufacturesToolStripMenuItem + // + workPieceManufacturesToolStripMenuItem.Name = "workPieceManufacturesToolStripMenuItem"; + workPieceManufacturesToolStripMenuItem.Size = new Size(256, 26); + workPieceManufacturesToolStripMenuItem.Text = "Заготовки по изделиям"; + workPieceManufacturesToolStripMenuItem.Click += WorkPieceManufacturesToolStripMenuItem_Click; + // + // ordersToolStripMenuItem + // + ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + ordersToolStripMenuItem.Size = new Size(256, 26); + ordersToolStripMenuItem.Text = "Список заказов"; + ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // workWithClientsToolStripMenuItem + // + workWithClientsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { clientsToolStripMenuItem }); + workWithClientsToolStripMenuItem.Name = "workWithClientsToolStripMenuItem"; + workWithClientsToolStripMenuItem.Size = new Size(161, 24); + workWithClientsToolStripMenuItem.Text = "Работа с клиентами"; + // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(152, 26); + clientsToolStripMenuItem.Text = "Клиенты"; + clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // работаСИсполнителямиToolStripMenuItem + // + работаСИсполнителямиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { implementerToolStripMenuItem }); + работаСИсполнителямиToolStripMenuItem.Name = "работаСИсполнителямиToolStripMenuItem"; + работаСИсполнителямиToolStripMenuItem.Size = new Size(196, 24); + работаСИсполнителямиToolStripMenuItem.Text = "Работа с исполнителями"; + // + // implementerToolStripMenuItem + // + implementerToolStripMenuItem.Name = "implementerToolStripMenuItem"; + implementerToolStripMenuItem.Size = new Size(185, 26); + implementerToolStripMenuItem.Text = "Исполнители"; + implementerToolStripMenuItem.Click += ImplementerToolStripMenuItem_Click; + // + // startingWorkToolStripMenuItem + // + startingWorkToolStripMenuItem.Name = "startingWorkToolStripMenuItem"; + startingWorkToolStripMenuItem.Size = new Size(114, 24); + startingWorkToolStripMenuItem.Text = "Запуск работ"; + startingWorkToolStripMenuItem.Click += StartingWorkToolStripMenuItem_Click; + // + // createBackUpToolStripMenuItem + // + createBackUpToolStripMenuItem.Name = "createBackUpToolStripMenuItem"; + createBackUpToolStripMenuItem.Size = new Size(123, 24); + createBackUpToolStripMenuItem.Text = "Создать бекап"; + createBackUpToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1506, 450); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Кузнечная мастерская"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } #endregion - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonIssuedOrder; - private Button buttonRef; - private MenuStrip menuStrip; - private ToolStripMenuItem toolStripMenuItem; - private ToolStripMenuItem workPieceToolStripMenuItem; - private ToolStripMenuItem manufactureToolStripMenuItem; - private ToolStripMenuItem reportsToolStripMenuItem; - private ToolStripMenuItem workPiecesToolStripMenuItem; - private ToolStripMenuItem workPieceManufacturesToolStripMenuItem; - private ToolStripMenuItem ordersToolStripMenuItem; - private ToolStripMenuItem workWithClientsToolStripMenuItem; - private ToolStripMenuItem clientsToolStripMenuItem; - private ToolStripMenuItem startingWorkToolStripMenuItem; - private ToolStripMenuItem работаСИсполнителямиToolStripMenuItem; - private ToolStripMenuItem implementerToolStripMenuItem; - private ToolStripMenuItem mailsToolStripMenuItem; - } + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonIssuedOrder; + private Button buttonRef; + private MenuStrip menuStrip; + private ToolStripMenuItem toolStripMenuItem; + private ToolStripMenuItem workPieceToolStripMenuItem; + private ToolStripMenuItem manufactureToolStripMenuItem; + private ToolStripMenuItem reportsToolStripMenuItem; + private ToolStripMenuItem workPiecesToolStripMenuItem; + private ToolStripMenuItem workPieceManufacturesToolStripMenuItem; + private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem workWithClientsToolStripMenuItem; + private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem startingWorkToolStripMenuItem; + private ToolStripMenuItem работаСИсполнителямиToolStripMenuItem; + private ToolStripMenuItem implementerToolStripMenuItem; + private ToolStripMenuItem mailsToolStripMenuItem; + private ToolStripMenuItem createBackUpToolStripMenuItem; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index ef89681..7e5af01 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -25,7 +25,9 @@ namespace BlacksmithWorkshop private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); @@ -33,6 +35,7 @@ namespace BlacksmithWorkshop _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -192,20 +195,46 @@ namespace BlacksmithWorkshop { var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } - private void MailsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + private void MailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } - } + if (service is FormMails form) + { + form.ShowDialog(); + } + } + + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + + MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index e73215b..484375e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -4,6 +4,7 @@ using BlacksmithWorkshopBusinessLogic.OfficePackage; using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements; using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; @@ -14,10 +15,6 @@ namespace BlacksmithWorkshop { internal static class Program { - private static ServiceProvider? _serviceProvider; - - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// /// The main entry point for the application. /// @@ -28,13 +25,12 @@ namespace BlacksmithWorkshop // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); - try + try { - var mailSender = _serviceProvider.GetService(); - mailSender?.MailConfig(new MailConfigBindingModel + var mailSender = DependencyManager.Instance.Resolve(); + mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, @@ -49,60 +45,56 @@ namespace BlacksmithWorkshop } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); - logger?.LogError(ex, " "); + 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(); + 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.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..c59648b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,125 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDataModels; +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 BlacksmithWorkshopBusinessLogic.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..c34a5fe --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..9743ae1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..df0ac4c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj index f685e06..9e282a5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..7c3cb90 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,17 @@ +using BlacksmithWorkshopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + //интерфейс создания бекапа + public interface IBackUpLogic + { + //путь и имя файла для архивации + void CreateBackUp(BackUpSaveBinidngModel model); + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..2335d5e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs @@ -0,0 +1,63 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + /// + /// Менеджер для работы с зависимостями + /// + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance + { + get + { + if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } + + return _manager; + } + } + + //Иницализация библиотек, в которых идут установки зависомстей + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + + // регистрируем зависимости + ext.RegisterServices(); + } + + //Регистрация логгера + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + //Добавление зависимости + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + //Добавление зависимости + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + //Получение класса со всеми зависмостями + public T Resolve() => _dependencyManager.Resolve(); + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..d4b1f9d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..7a7c24e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + + //Интерфейс для регистрации зависимостей в модулях + public interface IImplementationExtension + { + public int Priority { get; } + + //Регистрация сервисов + public void RegisterServices(); + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..12929f0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..30efc7d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + //интерфейс получения данных по всем сущностям + public interface IBackUpInfo + { + //метод получения данных по всем сущностям + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs index 1f817c6..ca7e87a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs @@ -12,13 +12,10 @@ namespace BlacksmithWorkshopContracts.ViewModels { public int Id { get; set; } - [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/BackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..aefe94f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,36 @@ +using BlacksmithWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new BlacksmithWorkshopDatabase(); + + 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/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..2f024fd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs @@ -0,0 +1,34 @@ +using BlacksmithWorkshopContracts.DI; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement +{ + 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 7097dab6007b104378faad8ecde3bead977ca8f9 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 29 Apr 2023 13:35:30 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8F=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormImplementers.cs | 23 +++---- .../BlacksmithWorkshop/FormMain.cs | 63 ++++++----------- .../BlacksmithWorkshop/FormManufacture.cs | 69 +++++++++---------- .../BlacksmithWorkshop/FormManufactures.cs | 23 +++---- .../BlacksmithWorkshop/FormWorkPieces.cs | 23 +++---- .../DI/ServiceDependencyContainer.cs | 62 +++++++++++++++++ .../Implements/BackUpInfo.cs | 22 ++++++ 7 files changed, 163 insertions(+), 122 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackUpInfo.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs index 9cc564e..6bf2565 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -58,14 +59,11 @@ namespace BlacksmithWorkshop private void ButtonCreate_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormImplementer form) + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -73,16 +71,13 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormImplementer form) + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 7e5af01..0f833ad 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -1,6 +1,7 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogic; using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using BlacksmithWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -73,34 +74,24 @@ namespace BlacksmithWorkshop private void WorkPieceToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkPieces)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormWorkPieces form) - { - form.ShowDialog(); - } + form.ShowDialog(); } private void ManufactureToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormManufactures form) - { - form.ShowDialog(); - } + form.ShowDialog(); } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } private void ButtonIssuedOrder_Click(object sender, EventArgs e) @@ -156,59 +147,45 @@ namespace BlacksmithWorkshop private void WorkPieceManufacturesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportManufactureWorkPieces)); + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); - if (service is FormReportManufactureWorkPieces form) - { - form.ShowDialog(); - } } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + form.ShowDialog(); } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormClients form) - { - form.ShowDialog(); - } + form.ShowDialog(); } private void StartingWorkToolStripMenuItem_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 ImplementerToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormImplementers form) - { - form.ShowDialog(); - } + form.ShowDialog(); } private void MailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormMails form) - { - form.ShowDialog(); - } + form.ShowDialog(); } private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs index 1aed36c..055a2a9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopDataModels.Models; using Microsoft.Extensions.Logging; @@ -89,30 +90,27 @@ namespace BlacksmithWorkshop private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece)); - - if (service is FormManufactureWorkPiece form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.WorkPieceModel == null) { - if (form.WorkPieceModel == null) - { - return; - } - - _logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); - - if (_manufactureWorkPieces.ContainsKey(form.Id)) - { - _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count); - } - else - { - _manufactureWorkPieces.Add(form.Id, (form.WorkPieceModel, form.Count)); - } - - LoadData(); + return; } + + _logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); + + if (_manufactureWorkPieces.ContainsKey(form.Id)) + { + _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count); + } + else + { + _manufactureWorkPieces.Add(form.Id, (form.WorkPieceModel, form.Count)); + } + + LoadData(); } } @@ -120,26 +118,23 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormManufactureWorkPiece form) + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _manufactureWorkPieces[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _manufactureWorkPieces[id].Item2; - - if (form.ShowDialog() == DialogResult.OK) + if (form.WorkPieceModel == null) { - if (form.WorkPieceModel == null) - { - return; - } - - _logger.LogInformation("Изменение компонента:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); - _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count); - - LoadData(); + return; } + + _logger.LogInformation("Изменение компонента:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); + _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count); + + LoadData(); } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index 00d71a4..a06e1ec 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -58,14 +59,11 @@ namespace BlacksmithWorkshop private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormManufacture form) + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -73,16 +71,13 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormManufacture form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs index 0007c92..0abe750 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -57,14 +58,11 @@ namespace BlacksmithWorkshop private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormWorkPiece form) + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -73,15 +71,12 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece)); - - if (service is FormWorkPiece form) + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..bdc7f22 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/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 BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..9e150a8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} -- 2.25.1 From ebed3c5c1df40ea4b310b83f41ec6e7dc0a3f45b Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 30 Apr 2023 01:01:54 +0400 Subject: [PATCH 3/8] =?UTF-8?q?LabWork08=20=D0=BF=D0=BE=20=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D0=B5=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ BlacksmithWorkshop/BlacksmithWorkshop.sln | 4 ++-- .../BlacksmithWorkshop/DataGridViewExtension.cs | 2 ++ .../BusinessLogic/BackUpLogic.cs | 4 ++++ .../Attributes/ColumnAttribute.cs | 1 + .../BindingModels/MessageInfoBindingModel.cs | 6 ++++-- .../DI/IImplementationExtension.cs | 1 + .../ViewModels/ClientViewModel.cs | 7 ++++++- .../ViewModels/MessageInfoViewModel.cs | 4 +++- .../Models/IMessageInfoModel.cs | 2 +- .../BlacksmithWorkshopDatabaseImplement.csproj | 4 ++++ .../Models/MessageInfo.cs | 4 +++- .../BlacksmithWorkshopFileImplement.csproj | 4 ++++ .../BlacksmithWorkshopFileImplement/Models/MessageInfo.cs | 6 ++++-- .../BlacksmithWorkshopListImplement.csproj | 4 ++++ .../BlacksmithWorkshopListImplement/Models/MessageInfo.cs | 6 ++++-- 16 files changed, 49 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index ca1c7a3..a743e0a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +ImplementationExtensions + # Mono auto generated files mono_crash.* diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index d66652b..96a37bb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{EE03BAE3-52EE-4E3B-8992-382D89E61E1A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopRestApi", "BlackmithWorkshopRestApi\BlacksmithWorkshopRestApi.csproj", "{23DBD9A3-2107-44AB-8B87-6982BFD2E69A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopRestApi", "BlackmithWorkshopRestApi\BlacksmithWorkshopRestApi.csproj", "{23DBD9A3-2107-44AB-8B87-6982BFD2E69A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopClientApp", "BlacksmithWorkshopClientApp\BlacksmithWorkshopClientApp.csproj", "{FCA95914-11AF-494A-8116-BB7B3253D925}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopClientApp", "BlacksmithWorkshopClientApp\BlacksmithWorkshopClientApp.csproj", "{FCA95914-11AF-494A-8116-BB7B3253D925}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs index 5f555c7..fd6b156 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs @@ -18,8 +18,10 @@ namespace BlacksmithWorkshop grid.DataSource = data; + //получаем тип var type = typeof(T); + //получаем свойства var properties = type.GetProperties(); foreach (DataGridViewColumn column in grid.Columns) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs index c59648b..6169c15 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -19,6 +19,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic private readonly ILogger _logger; private readonly IBackUpInfo _backUpInfo; + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) { _logger = logger; @@ -40,6 +41,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if (dirInfo.Exists) { + //НЕ ВЫБИРАЕМ РАБОЧИЙ СТОЛ, ИНАЧЕ ВСЁ С НЕГО УДАЛИТСЯ foreach (var file in dirInfo.GetFiles()) { file.Delete(); @@ -73,6 +75,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic foreach (var type in types) { + //проверка на то, является ли тип интерфейсом и унаследован ли он от IId if (type.IsInterface && type.GetInterface(typeIId.Name) != null) { var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); @@ -114,6 +117,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return; } + //три строчки ниже - сериализация файлов в json var jsonFormatter = new DataContractJsonSerializer(typeof(List)); using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs index c34a5fe..aec5b3a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.Attributes { + //указываем, что данный атрибут можно прописать только в Property [AttributeUsage(AttributeTargets.Property)] public class ColumnAttribute : Attribute { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs index 7d7d454..23b9a70 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs @@ -9,7 +9,9 @@ namespace BlacksmithWorkshopContracts.BindingModels { public class MessageInfoBindingModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + public int Id { get; set; } + + public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } @@ -20,5 +22,5 @@ namespace BlacksmithWorkshopContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; - } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs index 7a7c24e..12b6fd0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs @@ -10,6 +10,7 @@ namespace BlacksmithWorkshopContracts.DI //Интерфейс для регистрации зависимостей в модулях public interface IImplementationExtension { + //для установления приоритета public int Priority { get; } //Регистрация сервисов diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs index ca7e87a..f222404 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,16 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } + [Column(title: "ФИО клиента", width: 150)] public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Логие (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs index 5933def..8a9a2a1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -10,7 +10,9 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + public int Id { get; set; } + + public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs index a7ac56e..b91d51d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj index bdecbbd..15df830 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs index a42d009..d0f0af4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -12,7 +12,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { - [Key] + public int Id { get; set; } + + [Key] public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj index b65badc..d1597ab 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs index 4884680..5d36e6a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs @@ -14,7 +14,9 @@ namespace BlacksmithWorkshopFileImplement.Models { public class MessageInfo : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; + public int Id { get; private set; } + + public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -94,5 +96,5 @@ namespace BlacksmithWorkshopFileImplement.Models new XElement("Body", Body), new XElement("Subject", Subject), new XElement("DateDelivery", DateDelivery.ToString())); - } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj index b65badc..d1597ab 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs index cfcc629..e116e76 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs @@ -12,7 +12,9 @@ namespace BlacksmithWorkshopListImplement.Models { public class MessageInfo : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; + public int Id { get; private set; } + + public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -69,5 +71,5 @@ namespace BlacksmithWorkshopListImplement.Models Subject = Subject, Body = Body }; - } + } } -- 2.25.1 From 5fd72c9524080c21a34bfbf62506e4c6bb87f129 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 30 Apr 2023 11:44:13 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B8=20dataGridView.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormImplementers.cs | 19 ++++++------------- .../BlacksmithWorkshop/FormMails.cs | 12 ++---------- .../BlacksmithWorkshop/FormMain.cs | 13 +------------ .../BlacksmithWorkshop/FormManufactures.cs | 13 +++---------- .../BlacksmithWorkshop/FormWorkPieces.cs | 13 +++---------- 5 files changed, 15 insertions(+), 55 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs index 6bf2565..f2f7036 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; @@ -35,19 +36,11 @@ namespace BlacksmithWorkshop private void LoadData() { - try - { - var list = _logic.ReadList(null); + try + { + dataGridView.FillandConfigGrid(_logic.ReadList(null)); - //растягиваем колонку Название на всю ширину, колонку Id скрываем - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка исполнителей"); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs index 56ae275..ab2f6fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs @@ -38,17 +38,9 @@ namespace BlacksmithWorkshop try { - var list = _messageLogic.ReadList(null); + dataGridView.FillandConfigGrid(_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; - } - - _logger.LogInformation("Успешная загрузка писем"); + _logger.LogInformation("Успешная загрузка писем"); } catch (Exception ex) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 0f833ad..7f3c5c6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -50,18 +50,7 @@ namespace BlacksmithWorkshop try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ManufactureId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index a06e1ec..b2625c4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; @@ -38,15 +39,7 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ManufactureWorkPieces"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs index 0abe750..b1ebe5e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; @@ -36,15 +37,7 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - - //растягиваем колонку Название на всю ширину, колонку Id скрываем - if(list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["WorkPieceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка заготовок"); } -- 2.25.1 From c984bc9462c7e5fe8984ea6d7a9c91d2c4312b33 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 30 Apr 2023 12:07:12 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=93=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBaseImplementationExtension.cs | 33 +++++++++++++++++ .../Models/Client.cs | 20 ++++++---- .../Models/Implementer.cs | 19 +++++++--- .../Models/Manufacture.cs | 6 +++ .../Models/ManufactureWorkPiece.cs | 6 +++ .../Models/MessageInfo.cs | 17 ++++++--- .../Models/Order.cs | 15 +++++++- .../Models/WorkPiece.cs | 5 +++ .../FileImplementationExtension.cs | 34 +++++++++++++++++ .../Implements/BackUpInfo.cs | 37 +++++++++++++++++++ .../Models/Client.cs | 12 ++++-- .../Models/Implementer.cs | 17 ++++++--- .../Models/Manufacture.cs | 7 +++- .../Models/MessageInfo.cs | 18 ++++++--- .../Models/Order.cs | 17 +++++++-- .../Models/WorkPiece.cs | 5 +++ 16 files changed, 231 insertions(+), 37 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DataBaseImplementationExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackUpInfo.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DataBaseImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DataBaseImplementationExtension.cs new file mode 100644 index 0000000..8967c2f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DataBaseImplementationExtension.cs @@ -0,0 +1,33 @@ +using BlacksmithWorkshopContracts.DI; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement +{ + 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/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs index a2120cb..ad8b63d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs @@ -6,23 +6,29 @@ 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 BlacksmithWorkshopDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } + + [Required] + [DataMember] + public string ClientFIO { get; set; } = string.Empty; [Required] - public string ClientFIO { get; set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; [Required] - public string Email { get; set; } = string.Empty; - - [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; //для реализации связи многие ко многим с заказами (так как клиенты могу сделать одинаковый заказ) [ForeignKey("ClientId")] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs index 972afd3..a45f54e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs @@ -6,26 +6,33 @@ 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 BlacksmithWorkshopDatabaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; set; } = string.Empty; [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; [Required] - public int WorkExperience { get; set; } + [DataMember] + public int WorkExperience { get; set; } [Required] - public int Qualification { get; set; } + [DataMember] + public int Qualification { get; set; } //для реализации связи один ко многим с заказами [ForeignKey("ImplementerId")] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs index 742aa11..08543ad 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs @@ -7,25 +7,31 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Models { + [DataContract] public class Manufacture : IManufactureModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ManufactureName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } public Dictionary? _manufactureWorkPieces = null; //это поле не будет "мапиться" в бд [NotMapped] + [DataMember] public Dictionary ManufactureWorkPieces { get diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs index dbe90f6..8bfea2a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs @@ -2,22 +2,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Models { + [DataContract] public class ManufactureWorkPiece { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public int ManufactureId { get; set; } [Required] + [DataMember] public int WorkPieceId { get; set; } [Required] + [DataMember] public int Count { get; set; } public virtual WorkPiece WorkPiece { get; set; } = new(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs index d0f0af4..9f67f02 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -5,31 +5,38 @@ 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 BlacksmithWorkshopDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { public int Id { get; set; } [Key] - public string MessageId { get; set; } = string.Empty; + [DataMember] + public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } [Required] - public string SenderName { get; set; } = string.Empty; + [DataMember] + public string SenderName { get; set; } = string.Empty; [Required] - public DateTime DateDelivery { get; set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; set; } = DateTime.Now; [Required] - public string Subject { get; set; } = string.Empty; + [DataMember] + public string Subject { get; set; } = string.Empty; [Required] - public string Body { get; set; } = string.Empty; + [DataMember] + public string Body { get; set; } = string.Empty; public virtual Client? Client { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 8ca4b34..0ddcf3d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -6,36 +6,47 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public int ManufactureId { get; private set; } [Required] - public int ClientId { get; private set; } + [DataMember] + public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set; } //для передачи названия изделия diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs index 8ef7ca3..e6c01b7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs @@ -7,19 +7,24 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.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/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..28d2b45 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs @@ -0,0 +1,34 @@ +using BlacksmithWorkshopContracts.DI; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement +{ + //для реализации нужных нам зависимостей в данном варианте хранения информации + 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/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ae8ab4c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,37 @@ +using BlacksmithWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + var source = DataFileSingleton.GetInstance(); + + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs index 85bff7a..2d16557 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs @@ -7,21 +7,27 @@ using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; + [DataMember] + public string Email { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs index 21a0148..cb58634 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs @@ -5,23 +5,30 @@ 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 BlacksmithWorkshopFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } - public int Qualification { get; private set; } + [DataMember] + public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs index fb73403..40d0062 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs @@ -4,6 +4,7 @@ using BlacksmithWorkshopDataModels.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; @@ -11,19 +12,23 @@ using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { //класс реализующий интерфейс модели изделия + [DataContract] public class Manufacture : IManufactureModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ManufactureName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary WorkPieces { get; private set; } = new(); - private Dictionary? _manufactureWorkPieces = null; + [DataMember] public Dictionary ManufactureWorkPieces { get diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs index 5d36e6a..84bdd55 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs @@ -6,27 +6,35 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { public int Id { get; private set; } + [DataMember] public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index 7635cd2..2f55887 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -6,6 +6,7 @@ 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; @@ -13,24 +14,34 @@ using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { //класс, реализующий интерфейс модели заказа + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } - public int ClientId { get; private set; } + [DataMember] + public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } - public int ManufactureId { get; private set; } + [DataMember] + public int ManufactureId { get; private set; } + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel model) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs index b4f6a61..895100e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs @@ -5,6 +5,7 @@ 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; @@ -12,12 +13,16 @@ using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.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) -- 2.25.1 From ea70ee1e69ac73c8efdeb8ffe84f205fbee41513 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 30 Apr 2023 12:39:36 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/BackUpSaveBinidngModel.cs | 1 - .../BlacksmithWorkshopContracts.csproj | 2 + .../BusinessLogicsContracts/IBackUpLogic.cs | 1 - .../DI/DependencyManager.cs | 2 +- .../DI/UnityDependencyContainer.cs | 43 +++++++++++++++++++ .../ViewModels/ImplementerViewModel.cs | 20 +++++---- .../ViewModels/ManufactureViewModel.cs | 9 ++-- .../ViewModels/MessageInfoViewModel.cs | 16 ++++--- .../ViewModels/OrderViewModel.cs | 30 +++++++------ .../ViewModels/WorkPieceViewModel.cs | 6 ++- 10 files changed, 94 insertions(+), 36 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs index df0ac4c..01c9bd9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -10,5 +10,4 @@ namespace BlacksmithWorkshopContracts.BindingModels { public string FolderName { get; set; } = string.Empty; } - } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj index 9e282a5..2216d57 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -8,6 +8,8 @@ + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs index 7c3cb90..0b66910 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -13,5 +13,4 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts //путь и имя файла для архивации void CreateBackUp(BackUpSaveBinidngModel model); } - } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs index 2335d5e..a8837bb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs @@ -20,7 +20,7 @@ namespace BlacksmithWorkshopContracts.DI private DependencyManager() { - _dependencyManager = new ServiceDependencyContainer(); + _dependencyManager = new UnityDependencyContainer(); } public static DependencyManager Instance diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..2ba045b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Logging; +using Unity.Microsoft.Logging; +using Unity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs index 2554098..73c74b8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", width: 150)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; - [DisplayName("Стаж")] - public int WorkExperience { get; set; } + [Column(title: "Стаж", width: 150)] + public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(title: "Квалификация", width: 150)] + public int Qualification { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs index 6dca595..c8ccd7f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -11,14 +12,16 @@ namespace BlacksmithWorkshopContracts.ViewModels //класс для отображения пользователю информаци о продуктах (изделиях) public class ManufactureViewModel : IManufactureModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Навание изделия")] + [Column(title: "Навание изделия", width: 150)] public string ManufactureName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Price { get; set; } + [Column(visible: false)] public Dictionary ManufactureWorkPieces { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs index 8a9a2a1..e487f07 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,22 +11,25 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public int Id { get; set; } + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата отправки")] + [Column(title: "Дата отправки", width: 150)] public DateTime DateDelivery { get; set; } = DateTime.Now; - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; + [Column(title: "Текст", width: 150)] + public string Body { get; set; } = string.Empty; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index b550429..094f1f0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Enums; using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; @@ -12,37 +13,40 @@ namespace BlacksmithWorkshopContracts.ViewModels //класс для отображения пользователю информации о заказах public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(visible: false)] public int Id { get; set; } - public int ClientId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } - public int? ImplementerId { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } - public int ManufactureId { get; set; } + [Column(visible: false)] + public int ManufactureId { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", width: 150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] + [Column(title: "Изделие", width: 150)] public string ManufactureName { get; set; } = string.Empty; - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", width: 150)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 150)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 150)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 150)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 150)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 150)] public DateTime? DateImplement { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs index c04bcdc..690f8ea 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs @@ -5,18 +5,20 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BlacksmithWorkshopContracts.Attributes; namespace BlacksmithWorkshopContracts.ViewModels { //класс для отображения пользователю данных о заготовких (заготовках) public class WorkPieceViewModel : IWorkPieceModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название заготовки")] + [Column(title: "Название заготовки", width: 150)] public string WorkPieceName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } } -- 2.25.1 From 840586d4221a69a201f8f0c33af0ec31a53ebaca Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 30 Apr 2023 12:56:03 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=9A=D0=B0=D0=B6=D0=B8=D1=81=D1=8C=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB,=20=D1=85=D0=BE=D0=BF=20?= =?UTF-8?q?=D1=85=D0=B5=D0=B9=20=D0=BB=D0=B0=D0=BB=D0=B0=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs | 1 - .../ViewModels/ManufactureViewModel.cs | 2 +- .../Models/ManufactureWorkPiece.cs | 4 ---- .../Models/MessageInfo.cs | 10 +--------- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 7f3c5c6..07305cd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -200,7 +200,6 @@ namespace BlacksmithWorkshop { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs index c8ccd7f..d027131 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs @@ -15,7 +15,7 @@ namespace BlacksmithWorkshopContracts.ViewModels [Column(visible: false)] public int Id { get; set; } - [Column(title: "Навание изделия", width: 150)] + [Column(title: "Навание изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ManufactureName { get; set; } = string.Empty; [Column(title: "Цена", width: 150)] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs index 8bfea2a..09640c9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs @@ -11,19 +11,15 @@ namespace BlacksmithWorkshopDatabaseImplement.Models [DataContract] public class ManufactureWorkPiece { - [DataMember] public int Id { get; set; } [Required] - [DataMember] public int ManufactureId { get; set; } [Required] - [DataMember] public int WorkPieceId { get; set; } [Required] - [DataMember] public int Count { get; set; } public virtual WorkPiece WorkPiece { get; set; } = new(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs index 9f67f02..c4c08a5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -14,7 +14,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models [DataContract] public class MessageInfo : IMessageInfoModel { - public int Id { get; set; } + public int Id => throw new NotImplementedException(); [Key] [DataMember] @@ -22,20 +22,12 @@ namespace BlacksmithWorkshopDatabaseImplement.Models 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 virtual Client? Client { get; set; } -- 2.25.1 From 2ea914d9ec1c59824fbd28b39755e920324f3b38 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 3 May 2023 09:45:20 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BB=D0=B0=D0=B1=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopContracts.csproj | 6 +++--- BlacksmithWorkshop/Для бэкапа.zip | Bin 0 -> 1726 bytes 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 BlacksmithWorkshop/Для бэкапа.zip diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj index 2216d57..92640ef 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -8,8 +8,8 @@ - - + + diff --git a/BlacksmithWorkshop/Для бэкапа.zip b/BlacksmithWorkshop/Для бэкапа.zip new file mode 100644 index 0000000000000000000000000000000000000000..092d7bcdd87766c03f984a1f29c57d5b57ff66d2 GIT binary patch literal 1726 zcmWIWW@Zs#U|`^2c;d4-?2h@1wh|z(9*DVt*f}RNHLpZ3t2jTedtF%3xsyI;wF^Ig z3Evd7%i!ywcih%`W^p&TT4swh+&L@$EjEY2(2Q|rwEmmDH<%|euF4F*6j*fD_ski_ zEN|cQ`j@=Vp49R4)xB)IWs5;EgXas;sZ3WZmT5%Je5JvvA|^ilxj3VxSDPE#F*i20 zV_sV~G6bMFu1W8XOB>Kpoj@!A#GbhYIjOlo_oWuWT=>Z+aFfxcz)xp%Pk5g7J*(}h zTLf|Kh7X7Kb@Kw9c%wA&c*=nkuyMx@oBbRaOC~LxxN_!3&H$YaCWh+9y2h3pRgCTZPo4^J*ROK zruvqlCr>Rg6GL-zio4t2^+31gF+$wzo0wOcmY7^pT9k_7<|~1pe9vh6di&^U>Uw?k zKI0n-3}T?8uXX#1m&M*#P_Xggp*C)5{Wm*qlqEI`b=~^#XVII6GgqEmNm5 z?p%0f+Y6xQc$uM|OD!%=Oi%U9OUnm)u6NRIFBeAvm;Xrty=)8&T)@!rFG_(X(4|*)`yDnAVS7;ikwq!!{N1wa zn@SR1c}Oa82n9t4c&c3~Kb{#Ha?(O2wNvQ1#lMn2*8TB$8!NNR-hMiIc56}h_q^-7 zEJNSz%bR_4pJ%vv`RmC470qHE7gnb)D`00T*gbD&@Y|x_8#A}P^p4y)v0p&{)bFhv zm$K}OXZ`exAX3QQI6Od8omAQ^N&wg-Cm}6G)KF7KWgq;XQPaE4sy zg=3cmITRK@E>*wM(iHWx;}ApaO_7Y8E5ViW`sXF*E@NG`|LsdD#ivUpBo>84Y~$Wg zBys!O7U!g6)Aui)Z2Ps)E9u-f6T_q>hcBC>hW*KU-o8*!b^~HQAP&zj$_~g(O@?Q- zqI3Fsz#_uP;6fm{thf@$bzc7z-w7XIKUl6ac$jp!)mGdrCTG_To|N2xRaYA`jZIs# zj1Mi!ec1X}ybM%wOg^-DTIMoH8O6vX!hpL71-b$WAQh+q-l!VUi#LR>xj-g*VTZ08 zy`Vwp4g{t}^kN5HH+oJ+=+PE}g=(^EUJVLh%uw+1_e{_B5v4zlgfCWA70=!v) R`H6vn4G7bLK5}FQ@c=Yqo<;xw literal 0 HcmV?d00001 -- 2.25.1