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/DataGridViewExtension.cs b/JewelryStore/DataGridViewExtension.cs new file mode 100644 index 0000000..0d51ce8 --- /dev/null +++ b/JewelryStore/DataGridViewExtension.cs @@ -0,0 +1,58 @@ +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.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 833f03d..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 { @@ -30,36 +32,28 @@ 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) { - 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 76cf58a..b78684d 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; @@ -32,37 +33,27 @@ 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; - } + try + { + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _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 buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } private void buttonUpdate_Click(object sender, EventArgs e) { @@ -71,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 { @@ -103,19 +94,14 @@ namespace JewelryStore private void buttonChange_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (DataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } + var form = 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 22fa746..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 = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var form = 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 = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } + if (DataGridView.SelectedRows.Count == 1) + { + var form = 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) { @@ -96,25 +93,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/FormJewel.cs b/JewelryStore/FormJewel.cs index 584076e..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 = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); - if (service is FormJewelComponent form) - { + var form = 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 = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); - if (service is FormJewelComponent form) + var form = 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 5f5f06f..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 @@ -27,58 +29,44 @@ 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) { - var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + var form = 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 = Program.ServiceProvider?.GetService(typeof(FormJewel)); + var form = 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 5e37d56..c4e3000 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.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..15cfd03 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -1,6 +1,7 @@ using JewelryStoreBusinessLogic.BusinessLogics; using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.DI; using JewelryStoreDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -21,17 +22,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) { @@ -39,55 +43,37 @@ 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; - } - + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormJewels)); - - if (service is FormJewels form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void buttonCreate_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } private void buttonToWork_Click(object sender, EventArgs e) @@ -101,14 +87,6 @@ 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()), }); if (!operationResult) { @@ -137,14 +115,6 @@ 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()), }); if (!operationResult) { @@ -173,14 +143,6 @@ namespace JewelryStore 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()), }); if (!operationResult) { @@ -219,57 +181,62 @@ namespace JewelryStore private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportJewelComponents)); - if (service is FormReportJewelComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void списокЗаказзовToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _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 service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - if (service is FormImplementers form) + private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { { - form.ShowDialog(); + 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); + } } } - private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } - } + } } diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 9d4c511..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; @@ -11,93 +10,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(); + 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } - 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(); + 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/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/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/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/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/ServiceProviderLoader.cs b/JewelryStoreContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..c692882 --- /dev/null +++ b/JewelryStoreContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,64 @@ +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/DI/UnityDependencyContainer.cs b/JewelryStoreContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..9217e41 --- /dev/null +++ b/JewelryStoreContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,39 @@ +using Microsoft.Extensions.Logging; +using System.ComponentModel; +using Unity; +using Unity.Lifetime; +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 b4c900b..156d360 100644 --- a/JewelryStoreContracts/JewelryStoreContracts.csproj +++ b/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -7,7 +7,10 @@ + + + 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..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,12 +11,13 @@ 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; + [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..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,12 +11,14 @@ 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 + [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/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs b/JewelryStoreContracts/ViewModels/MessageInfoViewModel.cs index caadf29..16277df 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,19 @@ 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; + + public int Id => throw new NotImplementedException(); } } 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/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/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/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; + } + } +} diff --git a/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj b/JewelryStoreDatabaseImplement/JewelryStoreDatabaseImplement.csproj index f41d15e..bfc8881 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/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..45af43e 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] @@ -52,5 +56,7 @@ namespace JewelryStoreDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } 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/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/JewelryStoreFileImplement.csproj b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj index e899402..13cd42d 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/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..2d9efb4 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) @@ -76,5 +78,7 @@ namespace JewelryStoreFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + + public int Id => throw new NotImplementedException(); } } 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) { 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/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj index e899402..00057bd 100644 --- a/JewelryStoreListImplement/JewelryStoreListImplement.csproj +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -15,4 +15,8 @@ + + + + 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(); + } + } +} 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(); } } 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