From 38441ab9126339975af6d01a41e16e775ca0feec Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 2 May 2023 11:38:30 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/DataGridViewExtension.cs | 51 +++ JewelryStore/FormClients.cs | 30 +- JewelryStore/FormMain.Designer.cs | 368 +++++++++--------- JewelryStore/FormMain.cs | 49 ++- JewelryStore/Program.cs | 4 +- .../BusinessLogics/BackUpLogic.cs | 99 +++++ .../Attributes/ColumnAttribute.cs | 32 ++ .../Attributes/GridViewAutoSize.cs | 20 + .../BindingModels/BackUpSaveBinidngModel.cs | 13 + .../BusinessLogicsContracts/IBackUpLogic.cs | 14 + JewelryStoreContracts/DI/DependencyManager.cs | 60 +++ .../DI/IDependencyContainer.cs | 40 ++ .../DI/IImplementationExtension.cs | 20 + .../DI/ServiceProviderLoader.cs | 57 +++ .../JewelryStoreContracts.csproj | 1 + .../StoragesContracts/IBackUpInfo.cs | 14 + .../ViewModels/ClientViewModel.cs | 3 - .../Implements/BackUpInfo.cs | 31 ++ 18 files changed, 692 insertions(+), 214 deletions(-) create mode 100644 JewelryStore/DataGridViewExtension.cs create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 JewelryStoreContracts/Attributes/ColumnAttribute.cs create mode 100644 JewelryStoreContracts/Attributes/GridViewAutoSize.cs create mode 100644 JewelryStoreContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 JewelryStoreContracts/DI/DependencyManager.cs create mode 100644 JewelryStoreContracts/DI/IDependencyContainer.cs create mode 100644 JewelryStoreContracts/DI/IImplementationExtension.cs create mode 100644 JewelryStoreContracts/DI/ServiceProviderLoader.cs create mode 100644 JewelryStoreContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 JewelryStoreDatabaseImplement/Implements/BackUpInfo.cs diff --git a/JewelryStore/DataGridViewExtension.cs b/JewelryStore/DataGridViewExtension.cs new file mode 100644 index 0000000..e55c84e --- /dev/null +++ b/JewelryStore/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using JewelryStoreContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStore +{ + 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/JewelryStore/FormClients.cs b/JewelryStore/FormClients.cs index 833f03d..ddb75cb 100644 --- a/JewelryStore/FormClients.cs +++ b/JewelryStore/FormClients.cs @@ -30,25 +30,17 @@ namespace JewelryStore private void LoadData() { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Email"].AutoSizeMode =DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].Visible = false; - } - _logger.LogInformation("Загрузка клиентов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки клиентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } + try + { + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs index 5c00a81..d89e3c1 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -28,207 +28,216 @@ /// private void InitializeComponent() { - this.buttonReady = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonToWork = new System.Windows.Forms.Button(); - this.buttonPut = new System.Windows.Forms.Button(); - this.buttonRefresh = new System.Windows.Forms.Button(); - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокЗаказзовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonReady = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonToWork = new System.Windows.Forms.Button(); + this.buttonPut = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказзовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.элПисьмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.menuStrip.SuspendLayout(); - this.SuspendLayout(); - // - // buttonReady - // - this.buttonReady.Location = new System.Drawing.Point(1273, 298); - this.buttonReady.Name = "buttonReady"; - this.buttonReady.Size = new System.Drawing.Size(215, 34); - this.buttonReady.TabIndex = 3; - this.buttonReady.Text = "Заказ выдан"; - this.buttonReady.UseVisualStyleBackColor = true; - this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); - // - // dataGridView - // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(9, 52); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 62; - this.dataGridView.RowTemplate.Height = 33; - this.dataGridView.Size = new System.Drawing.Size(1227, 386); - this.dataGridView.TabIndex = 0; - // - // buttonCreate - // - this.buttonCreate.Location = new System.Drawing.Point(1273, 52); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(215, 34); - this.buttonCreate.TabIndex = 1; - this.buttonCreate.Text = "Создать заказ"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); - // - // buttonToWork - // - this.buttonToWork.Location = new System.Drawing.Point(1273, 137); - this.buttonToWork.Name = "buttonToWork"; - this.buttonToWork.Size = new System.Drawing.Size(215, 34); - this.buttonToWork.TabIndex = 2; - this.buttonToWork.Text = "Отдать на выполнение"; - this.buttonToWork.UseVisualStyleBackColor = true; - this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); - // - // buttonPut - // - this.buttonPut.Location = new System.Drawing.Point(1273, 218); - this.buttonPut.Name = "buttonPut"; - this.buttonPut.Size = new System.Drawing.Size(215, 34); - this.buttonPut.TabIndex = 4; - this.buttonPut.Text = "Заказ готов"; - this.buttonPut.UseVisualStyleBackColor = true; - this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); - // - // buttonRefresh - // - this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); - this.buttonRefresh.Name = "buttonRefresh"; - this.buttonRefresh.Size = new System.Drawing.Size(215, 34); - this.buttonRefresh.TabIndex = 5; - this.buttonRefresh.Text = "Обновить список"; - this.buttonRefresh.UseVisualStyleBackColor = true; - this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); - // - // menuStrip - // - this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonReady + // + this.buttonReady.Location = new System.Drawing.Point(1273, 298); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(215, 34); + this.buttonReady.TabIndex = 3; + this.buttonReady.Text = "Заказ выдан"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(9, 52); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(1227, 386); + this.dataGridView.TabIndex = 0; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(1273, 52); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(215, 34); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Создать заказ"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonToWork + // + this.buttonToWork.Location = new System.Drawing.Point(1273, 137); + this.buttonToWork.Name = "buttonToWork"; + this.buttonToWork.Size = new System.Drawing.Size(215, 34); + this.buttonToWork.TabIndex = 2; + this.buttonToWork.Text = "Отдать на выполнение"; + this.buttonToWork.UseVisualStyleBackColor = true; + this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); + // + // buttonPut + // + this.buttonPut.Location = new System.Drawing.Point(1273, 218); + this.buttonPut.Name = "buttonPut"; + this.buttonPut.Size = new System.Drawing.Size(215, 34); + this.buttonPut.TabIndex = 4; + this.buttonPut.Text = "Заказ готов"; + this.buttonPut.UseVisualStyleBackColor = true; + this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(215, 34); + this.buttonRefresh.TabIndex = 5; + this.buttonRefresh.Text = "Обновить список"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.элПисьмаToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(1530, 33); - this.menuStrip.TabIndex = 6; - this.menuStrip.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.элПисьмаToolStripMenuItem, + this.создатьБекапToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1530, 33); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, this.клиентыToolStripMenuItem, this.исполнителиToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); - // - // изделияToolStripMenuItem - // - this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34); - this.изделияToolStripMenuItem.Text = "Драгоценности"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); - // - // клиентыToolStripMenuItem - // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); - // - // исполнителиToolStripMenuItem - // - this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(240, 34); - this.исполнителиToolStripMenuItem.Text = "Исполнители"; - this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); - // - // отчетыToolStripMenuItem - // - this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.изделияToolStripMenuItem.Text = "Драгоценности"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); + // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокКомпонентовToolStripMenuItem, this.компонентыПоИзделиямToolStripMenuItem, this.списокЗаказзовToolStripMenuItem}); - this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); - this.отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокКомпонентовToolStripMenuItem - // - this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); - this.списокКомпонентовToolStripMenuItem.Text = "Список изделий"; - this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click); - // - // компонентыПоИзделиямToolStripMenuItem - // - this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(325, 34); - this.компонентыПоИзделиямToolStripMenuItem.Text = "Изделия по компонентам"; - this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click); - // - // списокЗаказзовToolStripMenuItem - // - this.списокЗаказзовToolStripMenuItem.Name = "списокЗаказзовToolStripMenuItem"; - this.списокЗаказзовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); - this.списокЗаказзовToolStripMenuItem.Text = "Список заказов"; - this.списокЗаказзовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказзовToolStripMenuItem_Click); - // - // запускРаботToolStripMenuItem - // - this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(136, 29); - this.запускРаботToolStripMenuItem.Text = "Запуск работ"; - this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокКомпонентовToolStripMenuItem + // + this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; + this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); + this.списокКомпонентовToolStripMenuItem.Text = "Список изделий"; + this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click); + // + // компонентыПоИзделиямToolStripMenuItem + // + this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; + this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(325, 34); + this.компонентыПоИзделиямToolStripMenuItem.Text = "Изделия по компонентам"; + this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click); + // + // списокЗаказзовToolStripMenuItem + // + this.списокЗаказзовToolStripMenuItem.Name = "списокЗаказзовToolStripMenuItem"; + this.списокЗаказзовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); + this.списокЗаказзовToolStripMenuItem.Text = "Список заказов"; + this.списокЗаказзовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказзовToolStripMenuItem_Click); + // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(136, 29); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); // // элПисьмаToolStripMenuItem // this.элПисьмаToolStripMenuItem.Name = "элПисьмаToolStripMenuItem"; - this.элПисьмаToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.элПисьмаToolStripMenuItem.Size = new System.Drawing.Size(119, 29); this.элПисьмаToolStripMenuItem.Text = "Эл. Письма"; this.элПисьмаToolStripMenuItem.Click += new System.EventHandler(this.элПисьмаToolStripMenuItem_Click); // + // создатьБекапToolStripMenuItem + // + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(140, 29); + this.создатьБекапToolStripMenuItem.Text = "СоздатьБекап"; + this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.создатьБекапToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1530, 450); - this.Controls.Add(this.buttonRefresh); - this.Controls.Add(this.buttonPut); - this.Controls.Add(this.buttonReady); - this.Controls.Add(this.buttonToWork); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Name = "FormMain"; - this.Text = "Изготовление Драгоценностей"; - this.Load += new System.EventHandler(this.FormMain_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.menuStrip.ResumeLayout(false); - this.menuStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1530, 450); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonPut); + this.Controls.Add(this.buttonReady); + this.Controls.Add(this.buttonToWork); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Изготовление Драгоценностей"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -252,5 +261,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem элПисьмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index 91ac56c..702f776 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -21,17 +21,20 @@ namespace JewelryStore private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; - LoadData(); - } + _backUpLogic = backUpLogic; + LoadData(); + } private void FormMain_Load(object sender, EventArgs e) { @@ -263,13 +266,35 @@ namespace JewelryStore form.ShowDialog(); } } - private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } - } + private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if (service is FormMails form) + { + form.ShowDialog(); + } + } + + private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel { FolderName = fbd.SelectedPath }); + MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } } diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 9d4c511..81d36ba 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -79,8 +79,10 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/JewelryStoreBusinessLogic/BusinessLogics/BackUpLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..a590b00 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,99 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreDataModels; +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 JewelryStoreBusinessLogic.BusinessLogics +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + private readonly IBackUpInfo _backUpInfo; + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/JewelryStoreContracts/Attributes/ColumnAttribute.cs b/JewelryStoreContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..99cff93 --- /dev/null +++ b/JewelryStoreContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + + public bool Visible { get; private set; } + + public int Width { get; private set; } + + public GridViewAutoSize GridViewAutoSize { get; private set; } + + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/JewelryStoreContracts/Attributes/GridViewAutoSize.cs b/JewelryStoreContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..ddb8d60 --- /dev/null +++ b/JewelryStoreContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/JewelryStoreContracts/BindingModels/BackUpSaveBinidngModel.cs b/JewelryStoreContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..a1c744c --- /dev/null +++ b/JewelryStoreContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IBackUpLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..bdfba62 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using JewelryStoreContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/JewelryStoreContracts/DI/DependencyManager.cs b/JewelryStoreContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..2991a82 --- /dev/null +++ b/JewelryStoreContracts/DI/DependencyManager.cs @@ -0,0 +1,60 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/DI/IDependencyContainer.cs b/JewelryStoreContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..200e70e --- /dev/null +++ b/JewelryStoreContracts/DI/IDependencyContainer.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/DI/IImplementationExtension.cs b/JewelryStoreContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..33b8de3 --- /dev/null +++ b/JewelryStoreContracts/DI/IImplementationExtension.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.DI +{ + /// + /// Интерфейс для регистрации зависимостей в модулях + /// + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/JewelryStoreContracts/DI/ServiceProviderLoader.cs b/JewelryStoreContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..8acd2d3 --- /dev/null +++ b/JewelryStoreContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/JewelryStoreContracts.csproj b/JewelryStoreContracts/JewelryStoreContracts.csproj index b4c900b..a196f49 100644 --- a/JewelryStoreContracts/JewelryStoreContracts.csproj +++ b/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -7,6 +7,7 @@ + diff --git a/JewelryStoreContracts/StoragesContracts/IBackUpInfo.cs b/JewelryStoreContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..9008686 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/JewelryStoreContracts/ViewModels/ClientViewModel.cs b/JewelryStoreContracts/ViewModels/ClientViewModel.cs index fb12e3f..504ee45 100644 --- a/JewelryStoreContracts/ViewModels/ClientViewModel.cs +++ b/JewelryStoreContracts/ViewModels/ClientViewModel.cs @@ -11,11 +11,8 @@ namespace JewelryStoreContracts.ViewModels public class ClientViewModel : IClientModel { 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/JewelryStoreDatabaseImplement/Implements/BackUpInfo.cs b/JewelryStoreDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..40ea98b --- /dev/null +++ b/JewelryStoreDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,31 @@ +using JewelryStoreContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new JewelryStoreDataBase(); + 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; + } + } +} -- 2.25.1 From 50ce8a61b1e69a28e41e26d880f81ee789158eb5 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 2 May 2023 13:59:21 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=84=D0=B8=D0=BA=D1=88=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=BC=20=D0=BF=D1=83=D0=BB=D1=8B=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D1=8F=D1=82=D1=8C=20:=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStoreRestApi/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JewelryStoreRestApi/Program.cs b/JewelryStoreRestApi/Program.cs index db22cef..bda72b2 100644 --- a/JewelryStoreRestApi/Program.cs +++ b/JewelryStoreRestApi/Program.cs @@ -20,7 +20,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -- 2.25.1 From 7a1e2a6849ccb7ddc8edac2c2389c73ebc4a716d Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 2 May 2023 14:50:43 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=B2=D1=81=D0=B5=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormComponents.cs | 31 ++-- JewelryStore/FormImplementers.cs | 32 ++--- JewelryStore/FormJewels.cs | 32 ++--- JewelryStore/FormMails.cs | 11 +- JewelryStore/FormMain.cs | 33 ++--- JewelryStore/Program.cs | 134 ++++++++---------- .../DI/ServiceDependencyContainer.cs | 62 ++++++++ .../DI/UnityDependencyContainer.cs | 42 ++++++ .../JewelryStoreContracts.csproj | 1 + .../ViewModels/ClientViewModel.cs | 15 +- .../ViewModels/ComponentViewModel.cs | 14 +- .../ViewModels/ImplementerViewModel.cs | 25 ++-- .../ViewModels/JewelViewModel.cs | 2 - .../ViewModels/MessageInfoViewModel.cs | 18 ++- .../ViewModels/OrderViewModel.cs | 51 +++---- .../DatabaseImplementationExtension.cs | 28 ++++ .../Models/Client.cs | 17 ++- .../Models/Component.cs | 14 +- .../Models/Implementer.cs | 20 ++- JewelryStoreDatabaseImplement/Models/Jewel.cs | 17 ++- .../Models/JewelComponent.cs | 17 ++- .../Models/Message.cs | 4 + JewelryStoreDatabaseImplement/Models/Order.cs | 29 ++-- .../Implements/BackUpInfo.cs | 22 +++ .../Implements/ImplementerStorage.cs | 3 +- .../ListImplementationExtension.cs | 26 ++++ 26 files changed, 439 insertions(+), 261 deletions(-) create mode 100644 JewelryStoreContracts/DI/ServiceDependencyContainer.cs create mode 100644 JewelryStoreContracts/DI/UnityDependencyContainer.cs create mode 100644 JewelryStoreDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 JewelryStoreListImplement/Implements/BackUpInfo.cs create mode 100644 JewelryStoreListImplement/ListImplementationExtension.cs diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs index 76cf58a..6071dc4 100644 --- a/JewelryStore/FormComponents.cs +++ b/JewelryStore/FormComponents.cs @@ -32,25 +32,18 @@ namespace JewelryStore } private void LoadData() { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } + try + { + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void buttonAdd_Click(object sender, EventArgs e) { diff --git a/JewelryStore/FormImplementers.cs b/JewelryStore/FormImplementers.cs index 22fa746..5970a0c 100644 --- a/JewelryStore/FormImplementers.cs +++ b/JewelryStore/FormImplementers.cs @@ -96,25 +96,17 @@ namespace JewelryStore private void LoadData() { - try - { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка исполнителей"); - } - - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки исполнителей"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + try + { + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index 5f5f06f..fd2ffe0 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -27,28 +27,18 @@ namespace JewelryStore private void LoadData() { - try - { - var list = _logic.ReadList(null); + try + { + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка изделий"); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["JewelComponents"].Visible = false; - - } - - _logger.LogInformation("Загрузка компонентов"); - - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void AddButton_Click(object sender, EventArgs e) { diff --git a/JewelryStore/FormMails.cs b/JewelryStore/FormMails.cs index 5e37d56..6e44a70 100644 --- a/JewelryStore/FormMails.cs +++ b/JewelryStore/FormMails.cs @@ -29,15 +29,8 @@ namespace JewelryStore { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["MessageId"].Visible = false; - DataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка писем"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) { diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index 702f776..a7a23e1 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -42,27 +42,18 @@ namespace JewelryStore } private void LoadData() { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["JewelId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } - - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + try + { + DataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 81d36ba..1856df7 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -11,95 +11,83 @@ using JewelryStoreBusinessLogic.OfficePackage; using JewelryStoreBusinessLogic.OfficePackage.Implements; using JewelryStoreBusinessLogic.MailWorker; using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.DI; namespace JewelryStore { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI - //settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - try - { - var mailSender = _serviceProvider.GetService(); - mailSender?.MailConfig(new MailConfigBindingModel - { - MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, - MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, - SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, - SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), - PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, - PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) - }); + ApplicationConfiguration.Initialize(); + InitDependency(); + try + { + 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, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); - // - var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); - } - catch (Exception ex) - { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, " "); - } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, "<22><> <20><> <20> <20><>"); + } + Application.Run(DependencyManager.Instance.Resolve()); + } - services.AddTransient(); - services.AddSingleton(); + private static void InitDependency() + { + DependencyManager.InitDependency(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - } + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + } } \ No newline at end of file diff --git a/JewelryStoreContracts/DI/ServiceDependencyContainer.cs b/JewelryStoreContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..6723d24 --- /dev/null +++ b/JewelryStoreContracts/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 JewelryStoreContracts.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/JewelryStoreContracts/DI/UnityDependencyContainer.cs b/JewelryStoreContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..e83532e --- /dev/null +++ b/JewelryStoreContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Microsoft.Logging; +namespace JewelryStoreContracts.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/JewelryStoreContracts/JewelryStoreContracts.csproj b/JewelryStoreContracts/JewelryStoreContracts.csproj index a196f49..0d7edcf 100644 --- a/JewelryStoreContracts/JewelryStoreContracts.csproj +++ b/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -9,6 +9,7 @@ + diff --git a/JewelryStoreContracts/ViewModels/ClientViewModel.cs b/JewelryStoreContracts/ViewModels/ClientViewModel.cs index 504ee45..9ea58da 100644 --- a/JewelryStoreContracts/ViewModels/ClientViewModel.cs +++ b/JewelryStoreContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using JewelryStoreDataModels.Models; +using JewelryStoreContracts.Attributes; +using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,9 +11,13 @@ namespace JewelryStoreContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - public string ClientFIO { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column("Логин (эл. почта)", width: 150)] + public string Email { get; set; } = string.Empty; + [Column("Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } } diff --git a/JewelryStoreContracts/ViewModels/ComponentViewModel.cs b/JewelryStoreContracts/ViewModels/ComponentViewModel.cs index dcd3252..dd85e89 100644 --- a/JewelryStoreContracts/ViewModels/ComponentViewModel.cs +++ b/JewelryStoreContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using JewelryStoreDataModels.Models; +using JewelryStoreContracts.Attributes; +using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace JewelryStoreContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } + [Column(visible: false)] + public int Id { get; set; } + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column("Цена", width: 80)] + public double Cost { get; set; } } } diff --git a/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs b/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs index f84e6f7..b14ca61 100644 --- a/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs +++ b/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using JewelryStoreDataModels.Models; +using JewelryStoreContracts.Attributes; +using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,16 @@ namespace JewelryStoreContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column("Пароль", width: 150)] - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } - - [DisplayName("Квалификация")] - public int Qualification { get; set; } + public string Password { get; set; } = string.Empty; + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int WorkExperience { get; set; } + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Qualification { get; set; } } } diff --git a/JewelryStoreContracts/ViewModels/JewelViewModel.cs b/JewelryStoreContracts/ViewModels/JewelViewModel.cs index f09420f..bae786d 100644 --- a/JewelryStoreContracts/ViewModels/JewelViewModel.cs +++ b/JewelryStoreContracts/ViewModels/JewelViewModel.cs @@ -11,9 +11,7 @@ namespace JewelryStoreContracts.ViewModels public class JewelViewModel : IJewelModel { public int Id { get; set; } - [DisplayName("Название драгоценности")] public string JewelName { get; set; } = string.Empty; - [DisplayName("Цена")] public double Price { get; set; } public Dictionary JewelComponents { diff --git a/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs b/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs index caadf29..766c416 100644 --- a/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs +++ b/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using JewelryStoreDataModels.Models; +using JewelryStoreContracts.Attributes; +using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,17 @@ namespace JewelryStoreContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + [Column(visible: false)] public int? ClientId { get; set; } - - [DisplayName("Имя отправителя")] + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - - [DisplayName("Дата отправления")] + [Column("Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - - [DisplayName("Тема")] + [Column("Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - - [DisplayName("Содержание")] + [Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; } } diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs index fcb9cce..1eb4cc7 100644 --- a/JewelryStoreContracts/ViewModels/OrderViewModel.cs +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using JewelryStoreDataModels.Enums; +using JewelryStoreContracts.Attributes; +using JewelryStoreDataModels.Enums; using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; @@ -11,32 +12,32 @@ namespace JewelryStoreContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int JewelId { get; set; } - public int ClientId { get; set; } - [DisplayName("Драгоценность")] - public string JewelName { get; set; } = string.Empty; + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; - - [DisplayName("Количество")] - public int Count { get; set; } - - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } - public int? ImplementerId { get; set; } + [Column(visible: false)] + public int JewelId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } + [Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string JewelName { get; set; } = string.Empty; + [Column("Фамилия исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column("Фамилия клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column("Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column("Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } } diff --git a/JewelryStoreDatabaseImplement/DatabaseImplementationExtension.cs b/JewelryStoreDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..fe52687 --- /dev/null +++ b/JewelryStoreDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,28 @@ +using JewelryStoreContracts.DI; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement +{ + 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/JewelryStoreDatabaseImplement/Models/Client.cs b/JewelryStoreDatabaseImplement/Models/Client.cs index b3248da..f405e0c 100644 --- a/JewelryStoreDatabaseImplement/Models/Client.cs +++ b/JewelryStoreDatabaseImplement/Models/Client.cs @@ -8,18 +8,25 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace JewelryStoreDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + + public class Client : IClientModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ClientFIO { get; set; } = string.Empty; + [DataMember] + public string ClientFIO { get; set; } = string.Empty; [Required] - public string Email { get; set; } = string.Empty; + [DataMember] + 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")] public virtual List Orders { get; set; } = new(); diff --git a/JewelryStoreDatabaseImplement/Models/Component.cs b/JewelryStoreDatabaseImplement/Models/Component.cs index 3e9d653..5be17c4 100644 --- a/JewelryStoreDatabaseImplement/Models/Component.cs +++ b/JewelryStoreDatabaseImplement/Models/Component.cs @@ -4,18 +4,24 @@ using JewelryStoreDatabaseImplement.Models; using JewelryStoreDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace JewelryStoreDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + + public class Component : IComponentModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public string ComponentName { get; private set; } = string.Empty; [Required] - public double Cost { get; set; } + [DataMember] + public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List JewelComponents { get; set; } = new(); diff --git a/JewelryStoreDatabaseImplement/Models/Implementer.cs b/JewelryStoreDatabaseImplement/Models/Implementer.cs index 71b05b5..8301312 100644 --- a/JewelryStoreDatabaseImplement/Models/Implementer.cs +++ b/JewelryStoreDatabaseImplement/Models/Implementer.cs @@ -8,24 +8,32 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace JewelryStoreDatabaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + + public class Implementer : IImplementerModel { [Required] - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; [Required] - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; [Required] - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } [Required] - public int Qualification { get; private set; } + [DataMember] + public int Qualification { get; private set; } - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [ForeignKey("ImplementerId")] public virtual List Orders { get; private set; } = new(); diff --git a/JewelryStoreDatabaseImplement/Models/Jewel.cs b/JewelryStoreDatabaseImplement/Models/Jewel.cs index 0d01025..a2d6055 100644 --- a/JewelryStoreDatabaseImplement/Models/Jewel.cs +++ b/JewelryStoreDatabaseImplement/Models/Jewel.cs @@ -8,23 +8,30 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace JewelryStoreDatabaseImplement.Models { - public class Jewel : IJewelModel + [DataContract] + + public class Jewel : IJewelModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public string JewelName { get; set; } = string.Empty; + [DataMember] + public string JewelName { get; set; } = string.Empty; [Required] - public double Price { get; set; } + [DataMember] + public double Price { get; set; } private Dictionary? _jewelComponents = null; [NotMapped] - public Dictionary JewelComponents + [DataMember] + public Dictionary JewelComponents { get { diff --git a/JewelryStoreDatabaseImplement/Models/JewelComponent.cs b/JewelryStoreDatabaseImplement/Models/JewelComponent.cs index 79fa697..79b887c 100644 --- a/JewelryStoreDatabaseImplement/Models/JewelComponent.cs +++ b/JewelryStoreDatabaseImplement/Models/JewelComponent.cs @@ -2,23 +2,30 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace JewelryStoreDatabaseImplement.Models { - public class JewelComponent + [DataContract] + + public class JewelComponent { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public int JewelId { get; set; } + [DataMember] + public int JewelId { get; set; } [Required] - public int ComponentId { get; set; } + [DataMember] + public int ComponentId { get; set; } [Required] - public int Count { get; set; } + [DataMember] + public int Count { get; set; } public virtual Component Component { get; set; } = new(); public virtual Jewel Jewel { get; set; } = new(); diff --git a/JewelryStoreDatabaseImplement/Models/Message.cs b/JewelryStoreDatabaseImplement/Models/Message.cs index 6e9aaf3..e3ba8d4 100644 --- a/JewelryStoreDatabaseImplement/Models/Message.cs +++ b/JewelryStoreDatabaseImplement/Models/Message.cs @@ -5,14 +5,18 @@ 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 JewelryStoreDatabaseImplement.Models { + [DataContract] + public class Message: IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } [Required] diff --git a/JewelryStoreDatabaseImplement/Models/Order.cs b/JewelryStoreDatabaseImplement/Models/Order.cs index 97d4cfe..f5174e8 100644 --- a/JewelryStoreDatabaseImplement/Models/Order.cs +++ b/JewelryStoreDatabaseImplement/Models/Order.cs @@ -8,30 +8,37 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreDataModels.Models; using JewelryStoreDataModels.Enums; using System.ComponentModel.DataAnnotations; - +using System.Runtime.Serialization; namespace JewelryStoreDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + + public class Order : IOrderModel { public int Id { get; private set; } - - public int JewelId { get; private set; } + [DataMember] + public int JewelId { get; private set; } [Required] - public int ClientId { get; set; } - public int? ImplementerId { get; private set; } - - public string JewelName { get; private set; } = string.Empty; + [DataMember] + public int ClientId { get; set; } + [DataMember] + public int? ImplementerId { get; private set; } + [DataMember] + public string JewelName { get; private set; } = string.Empty; [Required] - public int Count { get; private set; } + [DataMember] + public int Count { get; private set; } [Required] - public double Sum { get; private set; } + [DataMember] + public double Sum { get; private set; } [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; diff --git a/JewelryStoreListImplement/Implements/BackUpInfo.cs b/JewelryStoreListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..a1f8e0f --- /dev/null +++ b/JewelryStoreListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/JewelryStoreListImplement/Implements/ImplementerStorage.cs index 42077eb..d8f37c0 100644 --- a/JewelryStoreListImplement/Implements/ImplementerStorage.cs +++ b/JewelryStoreListImplement/Implements/ImplementerStorage.cs @@ -1,5 +1,6 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; using JewelryStoreListImplement.Models; using System; @@ -10,7 +11,7 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - public class ImplementerStorage + public class ImplementerStorage : IImplementerStorage { private readonly DataListSingleton _source; public ImplementerStorage() diff --git a/JewelryStoreListImplement/ListImplementationExtension.cs b/JewelryStoreListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..f91a70e --- /dev/null +++ b/JewelryStoreListImplement/ListImplementationExtension.cs @@ -0,0 +1,26 @@ +using JewelryStoreContracts.DI; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement +{ + 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 ee7089972d75be313f74718b593464a4d9f07af2 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 2 May 2023 14:58:27 +0400 Subject: [PATCH 4/8] =?UTF-8?q?83=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8,?= =?UTF-8?q?=20=D1=81=20=D0=BA=D0=B0=D0=B9=D1=84=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormComponents.cs | 4 ++-- JewelryStore/FormImplementers.cs | 4 ++-- JewelryStore/FormJewel.cs | 4 ++-- JewelryStore/FormJewels.cs | 4 ++-- JewelryStore/FormMain.cs | 27 +++++++++++++-------------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs index 6071dc4..7f7ae33 100644 --- a/JewelryStore/FormComponents.cs +++ b/JewelryStore/FormComponents.cs @@ -47,7 +47,7 @@ namespace JewelryStore private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve; + form.ShowDialog(); + } private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormJewels)); + var service = DependencyManager.Instance.Resolve Date: Tue, 9 May 2023 22:09:41 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/DataGridViewExtension.cs | 9 +- JewelryStore/FormClients.cs | 2 +- JewelryStore/FormComponents.cs | 37 +++--- JewelryStore/FormImplementers.cs | 43 ++++--- JewelryStore/FormJewel.cs | 11 +- JewelryStore/FormJewels.cs | 30 +++-- JewelryStore/FormMails.cs | 2 +- JewelryStore/FormMain.cs | 109 +++++------------- .../DI/UnityDependencyContainer.cs | 7 +- .../JewelryStoreContracts.csproj | 1 + .../ViewModels/JewelViewModel.cs | 15 ++- .../FileImplementationExtension.cs | 27 +++++ .../Implements/BackUpInfo.cs | 37 ++++++ JewelryStoreFileImplement/Models/Client.cs | 13 ++- JewelryStoreFileImplement/Models/Component.cs | 10 +- .../Models/Implementer.cs | 20 ++-- JewelryStoreFileImplement/Models/Jewel.cs | 14 ++- JewelryStoreFileImplement/Models/Message.cs | 12 +- JewelryStoreFileImplement/Models/Order.cs | 38 +++--- 19 files changed, 234 insertions(+), 203 deletions(-) create mode 100644 JewelryStoreFileImplement/FileImplementationExtension.cs create mode 100644 JewelryStoreFileImplement/Implements/BackUpInfo.cs diff --git a/JewelryStore/DataGridViewExtension.cs b/JewelryStore/DataGridViewExtension.cs index e55c84e..0d51ce8 100644 --- a/JewelryStore/DataGridViewExtension.cs +++ b/JewelryStore/DataGridViewExtension.cs @@ -9,33 +9,40 @@ namespace JewelryStore { public static class DataGridViewExtension { - public static void FillAndConfigGrid(this DataGridView grid, List? data) + 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()); diff --git a/JewelryStore/FormClients.cs b/JewelryStore/FormClients.cs index ddb75cb..a034728 100644 --- a/JewelryStore/FormClients.cs +++ b/JewelryStore/FormClients.cs @@ -32,7 +32,7 @@ namespace JewelryStore { try { - dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs index 7f7ae33..c7b9479 100644 --- a/JewelryStore/FormComponents.cs +++ b/JewelryStore/FormComponents.cs @@ -3,6 +3,7 @@ using JewelryStore; using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using JewelryStoreContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -34,8 +35,8 @@ namespace JewelryStore { try { - DataGridView.FillAndConfigGrid(_logic.ReadList(null)); - _logger.LogInformation("Загрузка компонентов"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -47,15 +48,12 @@ namespace JewelryStore private void buttonAdd_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } private void buttonUpdate_Click(object sender, EventArgs e) { @@ -98,17 +96,12 @@ namespace JewelryStore { if (dataGridView.SelectedRows.Count == 1) { - var service = - DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } } } } \ No newline at end of file diff --git a/JewelryStore/FormImplementers.cs b/JewelryStore/FormImplementers.cs index a0b3664..7df4587 100644 --- a/JewelryStore/FormImplementers.cs +++ b/JewelryStore/FormImplementers.cs @@ -1,5 +1,6 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -26,32 +27,28 @@ namespace JewelryStore private void AddButton_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); - if (service is FormImplementer form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } private void ChangeButton_Click(object sender, EventArgs e) { - if (DataGridView.SelectedRows.Count == 1) - { - var service = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } private void DeleteButton_Click(object sender, EventArgs e) { @@ -98,7 +95,7 @@ namespace JewelryStore { try { - dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) diff --git a/JewelryStore/FormJewel.cs b/JewelryStore/FormJewel.cs index 875549c..cbe4856 100644 --- a/JewelryStore/FormJewel.cs +++ b/JewelryStore/FormJewel.cs @@ -1,5 +1,6 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.DI; using JewelryStoreContracts.SearchModels; using JewelryStoreDataModels.Models; using Microsoft.Extensions.Logging; @@ -84,9 +85,8 @@ namespace JewelryStore private void buttonAdd_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) @@ -104,16 +104,13 @@ namespace JewelryStore } LoadData(); } - } - } private void buttonChange_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = DependencyManager.Instance.Resolve(); { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index 325b7d7..67bcdb0 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -11,6 +11,8 @@ using System.Windows.Forms; using JewelryStore; using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.DI; + namespace JewelryStore { public partial class FormJewels : Form //TODO @@ -29,7 +31,7 @@ namespace JewelryStore { try { - DataGridView.FillAndConfigGrid(_logic.ReadList(null)); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } @@ -42,33 +44,29 @@ namespace JewelryStore private void AddButton_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); - if (service is FormJewel form) - { + if (form.ShowDialog() == DialogResult.OK) { LoadData(); } - } + } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = DependencyManager.Instance.Resolve(); - if (service is FormJewel form) - { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + + } + } private void DeleteButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) diff --git a/JewelryStore/FormMails.cs b/JewelryStore/FormMails.cs index 6e44a70..c4e3000 100644 --- a/JewelryStore/FormMails.cs +++ b/JewelryStore/FormMails.cs @@ -29,7 +29,7 @@ namespace JewelryStore { try { - dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index 0069f7b..d3b04c2 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -45,7 +45,7 @@ namespace JewelryStore { try { - dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -58,30 +58,23 @@ namespace JewelryStore private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve; + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); } private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void buttonCreate_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } private void buttonToWork_Click(object sender, EventArgs e) { @@ -93,15 +86,7 @@ namespace JewelryStore { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) { @@ -129,15 +114,7 @@ namespace JewelryStore { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) { @@ -165,15 +142,7 @@ namespace JewelryStore var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) { @@ -212,58 +181,40 @@ namespace JewelryStore private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void списокЗаказзовToolStripMenuItem_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { { - _workProcess.DoWork(( DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) { diff --git a/JewelryStoreContracts/DI/UnityDependencyContainer.cs b/JewelryStoreContracts/DI/UnityDependencyContainer.cs index e83532e..9217e41 100644 --- a/JewelryStoreContracts/DI/UnityDependencyContainer.cs +++ b/JewelryStoreContracts/DI/UnityDependencyContainer.cs @@ -1,10 +1,7 @@ using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; using Unity; +using Unity.Lifetime; using Unity.Microsoft.Logging; namespace JewelryStoreContracts.DI { diff --git a/JewelryStoreContracts/JewelryStoreContracts.csproj b/JewelryStoreContracts/JewelryStoreContracts.csproj index 0d7edcf..156d360 100644 --- a/JewelryStoreContracts/JewelryStoreContracts.csproj +++ b/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -10,6 +10,7 @@ + diff --git a/JewelryStoreContracts/ViewModels/JewelViewModel.cs b/JewelryStoreContracts/ViewModels/JewelViewModel.cs index bae786d..e68f13f 100644 --- a/JewelryStoreContracts/ViewModels/JewelViewModel.cs +++ b/JewelryStoreContracts/ViewModels/JewelViewModel.cs @@ -1,4 +1,5 @@ -using JewelryStoreDataModels.Models; +using JewelryStoreContracts.Attributes; +using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,14 @@ namespace JewelryStoreContracts.ViewModels { public class JewelViewModel : IJewelModel { - public int Id { get; set; } - public string JewelName { get; set; } = string.Empty; - public double Price { get; set; } - public Dictionary JewelComponents + [Column(visible: false)] + public int Id { get; set; } + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string JewelName { get; set; } = string.Empty; + [Column("Цена", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary JewelComponents { get; set; diff --git a/JewelryStoreFileImplement/FileImplementationExtension.cs b/JewelryStoreFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..6840af2 --- /dev/null +++ b/JewelryStoreFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using JewelryStoreContracts.DI; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement +{ + 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/JewelryStoreFileImplement/Implements/BackUpInfo.cs b/JewelryStoreFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..abd6713 --- /dev/null +++ b/JewelryStoreFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,37 @@ +using JewelryStoreContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.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/JewelryStoreFileImplement/Models/Client.cs b/JewelryStoreFileImplement/Models/Client.cs index 3ee800a..9fb90b5 100644 --- a/JewelryStoreFileImplement/Models/Client.cs +++ b/JewelryStoreFileImplement/Models/Client.cs @@ -4,6 +4,7 @@ using JewelryStoreDataModels.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; @@ -12,10 +13,14 @@ namespace JewelryStoreFileImplement.Models { public class Client : IClientModel { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { if (model == null) diff --git a/JewelryStoreFileImplement/Models/Component.cs b/JewelryStoreFileImplement/Models/Component.cs index 634fb12..4591750 100644 --- a/JewelryStoreFileImplement/Models/Component.cs +++ b/JewelryStoreFileImplement/Models/Component.cs @@ -4,6 +4,7 @@ using JewelryStoreDataModels.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; @@ -12,9 +13,12 @@ namespace JewelryStoreFileImplement.Models { public class Component : IComponentModel { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public double Cost { get; set; } public static Component? Create(ComponentBindingModel? model) { diff --git a/JewelryStoreFileImplement/Models/Implementer.cs b/JewelryStoreFileImplement/Models/Implementer.cs index e6b305f..11e1720 100644 --- a/JewelryStoreFileImplement/Models/Implementer.cs +++ b/JewelryStoreFileImplement/Models/Implementer.cs @@ -4,6 +4,7 @@ using JewelryStoreDataModels.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; @@ -12,15 +13,16 @@ namespace JewelryStoreFileImplement.Models { public class Implementer : IImplementerModel { - public string ImplementerFIO { get; private set; } = string.Empty; - - public string Password { get; private set; } = string.Empty; - - public int WorkExperience { get; private set; } - - public int Qualification { get; private set; } - - public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; + [DataMember] + public int WorkExperience { get; private set; } + [DataMember] + public int Qualification { get; private set; } + [DataMember] + public int Id { get; private set; } public static Implementer? Create(XElement element) { diff --git a/JewelryStoreFileImplement/Models/Jewel.cs b/JewelryStoreFileImplement/Models/Jewel.cs index 0f171bd..d2b8844 100644 --- a/JewelryStoreFileImplement/Models/Jewel.cs +++ b/JewelryStoreFileImplement/Models/Jewel.cs @@ -7,18 +7,22 @@ using System.Text; using System.Threading.Tasks; using JewelryStoreContracts.BindingModels; using System.Xml.Linq; +using System.Runtime.Serialization; namespace JewelryStoreFileImplement.Models { public class Jewel: IJewelModel { - public int Id { get; private set; } - public string JewelName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string JewelName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _productComponents = null; - - public Dictionary JewelComponents + [DataMember] + public Dictionary JewelComponents { get { diff --git a/JewelryStoreFileImplement/Models/Message.cs b/JewelryStoreFileImplement/Models/Message.cs index 03ba95d..f9d46e7 100644 --- a/JewelryStoreFileImplement/Models/Message.cs +++ b/JewelryStoreFileImplement/Models/Message.cs @@ -4,6 +4,7 @@ using JewelryStoreDataModels.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; @@ -12,16 +13,17 @@ namespace JewelryStoreFileImplement.Models { public class Message : IMessageInfoModel { + [DataMember] public string MessageId { get; private set; } = string.Empty; - + [DataMember] public int? ClientId { get; private set; } - + [DataMember] public string SenderName { get; private set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; private set; } = DateTime.Now; - + [DataMember] public string Subject { get; private set; } = string.Empty; - + [DataMember] public string Body { get; private set; } = string.Empty; public static Message? Create(MessageInfoBindingModel model) diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs index 23bcf7c..f106c17 100644 --- a/JewelryStoreFileImplement/Models/Order.cs +++ b/JewelryStoreFileImplement/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; @@ -14,23 +15,26 @@ namespace JewelryStoreFileImplement.Models { public class Order : IOrderModel { - public int JewelId { get; private set; } - public int ClientId { get; private set; } - - public string JewelName { get; private set; } = string.Empty; - public int? ImplementerId { get; private set; } - - public int Count { get; private set; } - - public double Sum { get; private set; } - - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - - public int Id { get; private set; } + [DataMember] + public int JewelId { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public string JewelName { get; private set; } = string.Empty; + [DataMember] + public int? ImplementerId { get; private set; } + [DataMember] + public int Count { get; private set; } + [DataMember] + public double Sum { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] + public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } public static Order? Create(OrderBindingModel model) { -- 2.25.1 From deddf34e8819e8735eac1125facab6d7773e314e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 15 May 2023 16:42:48 +0400 Subject: [PATCH 6/8] full 8 --- .gitignore | 5 ++++ JewelryStore/FormClients.Designer.cs | 22 ++++++++-------- JewelryStore/FormClients.cs | 12 +++++---- JewelryStore/FormComponents.Designer.cs | 26 +++++++++---------- JewelryStore/FormComponents.cs | 8 +++--- JewelryStore/Program.cs | 1 - .../BindingModels/MessageInfoBindingModel.cs | 2 ++ .../DI/ServiceProviderLoader.cs | 7 +++++ .../ViewModels/MessageInfoViewModel.cs | 2 ++ .../Models/IMessageInfoModel.cs | 2 +- .../JewelryStoreDatabaseImplement.csproj | 5 ++++ .../Models/Message.cs | 2 ++ .../JewelryStoreFileImplement.csproj | 7 ++++- JewelryStoreFileImplement/Models/Message.cs | 2 ++ .../JewelryStoreListImplement.csproj | 6 ++++- JewelryStoreListImplement/Models/Message.cs | 2 ++ 16 files changed, 74 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index ca1c7a3..0fe264c 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,8 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml + + +# dll файлы +*.dll + diff --git a/JewelryStore/FormClients.Designer.cs b/JewelryStore/FormClients.Designer.cs index c3bb02d..0238873 100644 --- a/JewelryStore/FormClients.Designer.cs +++ b/JewelryStore/FormClients.Designer.cs @@ -28,19 +28,19 @@ /// private void InitializeComponent() { - this.dataGridView = new System.Windows.Forms.DataGridView(); + this.DataGridView = new System.Windows.Forms.DataGridView(); this.ButtonDel = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); // // dataGridView // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 85); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(559, 453); - this.dataGridView.TabIndex = 6; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(12, 85); + this.DataGridView.Name = "dataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(559, 453); + this.DataGridView.TabIndex = 6; // // ButtonDel // @@ -58,18 +58,18 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(588, 549); this.Controls.Add(this.ButtonDel); - this.Controls.Add(this.dataGridView); + this.Controls.Add(this.DataGridView); this.Name = "FormClients"; this.Text = "Клиенты"; this.Load += new System.EventHandler(this.FormClients_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); this.ResumeLayout(false); } #endregion - private DataGridView dataGridView; + private DataGridView DataGridView; private Button ButtonDel; } } \ No newline at end of file diff --git a/JewelryStore/FormClients.cs b/JewelryStore/FormClients.cs index a034728..963d960 100644 --- a/JewelryStore/FormClients.cs +++ b/JewelryStore/FormClients.cs @@ -1,6 +1,4 @@ -using JewelryStoreContracts.BindingModels; -using JewelryStoreContracts.BusinessLogicsContracts; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,6 +8,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using JewelryStore; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.DI; namespace JewelryStore { @@ -45,13 +47,13 @@ namespace JewelryStore private void ButtonDel_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (DataGridView.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Удаление клиента"); try { diff --git a/JewelryStore/FormComponents.Designer.cs b/JewelryStore/FormComponents.Designer.cs index 7156e1f..4999362 100644 --- a/JewelryStore/FormComponents.Designer.cs +++ b/JewelryStore/FormComponents.Designer.cs @@ -28,24 +28,24 @@ /// private void InitializeComponent() { - this.dataGridView = new System.Windows.Forms.DataGridView(); + this.DataGridView = new System.Windows.Forms.DataGridView(); this.buttonAdd = new System.Windows.Forms.Button(); this.buttonChange = new System.Windows.Forms.Button(); this.buttonDelete = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); // // dataGridView // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; - this.dataGridView.Location = new System.Drawing.Point(0, 0); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 62; - this.dataGridView.RowTemplate.Height = 33; - this.dataGridView.Size = new System.Drawing.Size(459, 488); - this.dataGridView.TabIndex = 0; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.DataGridView.Location = new System.Drawing.Point(0, 0); + this.DataGridView.Name = "dataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 33; + this.DataGridView.Size = new System.Drawing.Size(459, 488); + this.DataGridView.TabIndex = 0; // // buttonAdd // @@ -96,18 +96,18 @@ this.Controls.Add(this.buttonDelete); this.Controls.Add(this.buttonChange); this.Controls.Add(this.buttonAdd); - this.Controls.Add(this.dataGridView); + this.Controls.Add(this.DataGridView); this.Name = "FormComponents"; this.Text = "Компоненты"; this.Load += new System.EventHandler(this.FormComponents_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); this.ResumeLayout(false); } #endregion - private DataGridView dataGridView; + private DataGridView DataGridView; private Button buttonAdd; private Button buttonChange; private Button buttonDelete; diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs index c7b9479..b78684d 100644 --- a/JewelryStore/FormComponents.cs +++ b/JewelryStore/FormComponents.cs @@ -35,7 +35,7 @@ namespace JewelryStore { try { - DataGridView.FillandConfigGrid(_logic.ReadList(null)); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } @@ -62,13 +62,13 @@ namespace JewelryStore private void buttonDelete_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (DataGridView.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Удаление компонента"); try { @@ -94,7 +94,7 @@ namespace JewelryStore private void buttonChange_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (DataGridView.SelectedRows.Count == 1) { var form = DependencyManager.Instance.Resolve(); if (form.ShowDialog() == DialogResult.OK) diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 1856df7..ab30205 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -1,7 +1,6 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.StoragesContracts; using JewelryStoreBusinessLogic.BusinessLogics; -using JewelryStoreDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using System.Drawing; diff --git a/JewelryStoreContracts/BindingModels/MessageInfoBindingModel.cs b/JewelryStoreContracts/BindingModels/MessageInfoBindingModel.cs index defcf64..494198a 100644 --- a/JewelryStoreContracts/BindingModels/MessageInfoBindingModel.cs +++ b/JewelryStoreContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace JewelryStoreContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + + public int Id => throw new NotImplementedException(); } } diff --git a/JewelryStoreContracts/DI/ServiceProviderLoader.cs b/JewelryStoreContracts/DI/ServiceProviderLoader.cs index 8acd2d3..c692882 100644 --- a/JewelryStoreContracts/DI/ServiceProviderLoader.cs +++ b/JewelryStoreContracts/DI/ServiceProviderLoader.cs @@ -20,9 +20,11 @@ namespace JewelryStoreContracts.DI { 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)) @@ -34,6 +36,7 @@ namespace JewelryStoreContracts.DI else { var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) { source = newSource; @@ -42,15 +45,19 @@ namespace JewelryStoreContracts.DI } } } + 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/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs b/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs index 766c416..16277df 100644 --- a/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs +++ b/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs @@ -23,5 +23,7 @@ namespace JewelryStoreContracts.ViewModels public string Subject { get; set; } = string.Empty; [Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/JewelryStoreDataModels/Models/IMessageInfoModel.cs b/JewelryStoreDataModels/Models/IMessageInfoModel.cs index 120de88..738ae14 100644 --- a/JewelryStoreDataModels/Models/IMessageInfoModel.cs +++ b/JewelryStoreDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace JewelryStoreDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj b/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj index f41d15e..a60091c 100644 --- a/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj +++ b/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + OnBuildSuccess @@ -21,4 +22,8 @@ + + diff --git a/JewelryStoreDatabaseImplement/Models/Message.cs b/JewelryStoreDatabaseImplement/Models/Message.cs index e3ba8d4..45af43e 100644 --- a/JewelryStoreDatabaseImplement/Models/Message.cs +++ b/JewelryStoreDatabaseImplement/Models/Message.cs @@ -56,5 +56,7 @@ namespace JewelryStoreDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } diff --git a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj index e899402..c6146ac 100644 --- a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj +++ b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj @@ -1,9 +1,10 @@ - + net6.0 enable enable + OnBuildSuccess @@ -15,4 +16,8 @@ + + diff --git a/JewelryStoreFileImplement/Models/Message.cs b/JewelryStoreFileImplement/Models/Message.cs index f9d46e7..2d9efb4 100644 --- a/JewelryStoreFileImplement/Models/Message.cs +++ b/JewelryStoreFileImplement/Models/Message.cs @@ -78,5 +78,7 @@ namespace JewelryStoreFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + + public int Id => throw new NotImplementedException(); } } diff --git a/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj index e899402..2818ea3 100644 --- a/JewelryStoreListImplement/JewelryStoreListImplement.csproj +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -15,4 +15,8 @@ + + diff --git a/JewelryStoreListImplement/Models/Message.cs b/JewelryStoreListImplement/Models/Message.cs index 48376a6..7ae55ac 100644 --- a/JewelryStoreListImplement/Models/Message.cs +++ b/JewelryStoreListImplement/Models/Message.cs @@ -49,5 +49,7 @@ namespace JewelryStoreListImplement.Models ClientId = ClientId, MessageId = MessageId }; + + public int Id => throw new NotImplementedException(); } } -- 2.25.1 From cd4d024d4f0a58a258b5f9b38c88189c5553ad9b Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 16 May 2023 13:24:39 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D1=83=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JewelryStoreDatabaseImplement.csproj | 4 ++-- JewelryStoreFileImplement/JewelryStoreFileImplement.csproj | 4 ++-- JewelryStoreListImplement/JewelryStoreListImplement.csproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj b/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj index a60091c..bfc8881 100644 --- a/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj +++ b/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj @@ -22,8 +22,8 @@ - + diff --git a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj index c6146ac..13cd42d 100644 --- a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj +++ b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj @@ -16,8 +16,8 @@ - + diff --git a/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj index 2818ea3..00057bd 100644 --- a/JewelryStoreListImplement/JewelryStoreListImplement.csproj +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -15,8 +15,8 @@ - + -- 2.25.1 From 59ad8879f3f17985fe7c4837f9920af6dbf522f8 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 22 May 2023 00:38:19 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D1=83=D1=80=D0=B0=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=84=D0=BB=D0=B8=D0=BA=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormMain.cs | 85 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index d3b04c2..15cfd03 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -43,38 +43,38 @@ namespace JewelryStore } private void LoadData() { - try - { - dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } + try + { + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); - + } private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void buttonCreate_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } private void buttonToWork_Click(object sender, EventArgs e) { @@ -86,7 +86,7 @@ namespace JewelryStore { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id + Id = id, }); if (!operationResult) { @@ -114,7 +114,7 @@ namespace JewelryStore { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id + Id = id, }); if (!operationResult) { @@ -142,7 +142,7 @@ namespace JewelryStore var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id + Id = id, }); if (!operationResult) { @@ -181,40 +181,41 @@ namespace JewelryStore private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void списокЗаказзовToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { { - _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) { -- 2.25.1