diff --git a/SushiBar/ImplementationExtensions/SushiBarContracts.dll b/SushiBar/ImplementationExtensions/SushiBarContracts.dll new file mode 100644 index 0000000..194d57b Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarContracts.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarDataModels.dll b/SushiBar/ImplementationExtensions/SushiBarDataModels.dll new file mode 100644 index 0000000..502b2a1 Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarDataModels.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarDatabaseImplement.dll b/SushiBar/ImplementationExtensions/SushiBarDatabaseImplement.dll new file mode 100644 index 0000000..cd45e62 Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarDatabaseImplement.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarFileImplement.dll b/SushiBar/ImplementationExtensions/SushiBarFileImplement.dll new file mode 100644 index 0000000..350a03c Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarFileImplement.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarListImplement.dll b/SushiBar/ImplementationExtensions/SushiBarListImplement.dll new file mode 100644 index 0000000..d85b83f Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarListImplement.dll differ diff --git a/SushiBar/SushiBar/Extensions/DataGridViewExtension.cs b/SushiBar/SushiBar/Extensions/DataGridViewExtension.cs new file mode 100644 index 0000000..8cfc6b0 --- /dev/null +++ b/SushiBar/SushiBar/Extensions/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using SushiBarContracts.Attributes; + +namespace SushiBar.Extensions +{ + 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/SushiBar/SushiBar/Forms/FormClients.Designer.cs b/SushiBar/SushiBar/Forms/FormClients.Designer.cs index 2cd8cae..1fadac7 100644 --- a/SushiBar/SushiBar/Forms/FormClients.Designer.cs +++ b/SushiBar/SushiBar/Forms/FormClients.Designer.cs @@ -28,19 +28,19 @@ /// private void InitializeComponent() { - DataGridView = new DataGridView(); + dataGridView = new DataGridView(); DeleteButton = new Button(); - ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // DataGridView + // dataGridView // - DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - DataGridView.Location = new Point(12, 34); - DataGridView.Name = "DataGridView"; - DataGridView.RowTemplate.Height = 25; - DataGridView.Size = new Size(776, 404); - DataGridView.TabIndex = 0; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 34); + dataGridView.Name = "DataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(776, 404); + dataGridView.TabIndex = 0; // // DeleteButton // @@ -58,17 +58,17 @@ AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); Controls.Add(DeleteButton); - Controls.Add(DataGridView); + Controls.Add(dataGridView); Name = "ClientsForm"; Text = "Клиенты"; Load += ClientsForm_Load; - ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } #endregion - private DataGridView DataGridView; + private DataGridView dataGridView; private Button DeleteButton; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/Forms/FormClients.cs b/SushiBar/SushiBar/Forms/FormClients.cs index dc6d81a..51fc24d 100644 --- a/SushiBar/SushiBar/Forms/FormClients.cs +++ b/SushiBar/SushiBar/Forms/FormClients.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SushiBar.Extensions; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; @@ -17,28 +18,22 @@ namespace SushiBar.Forms 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"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка клиентов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки клиентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.FillandConfigGrid(list); + _logger.LogInformation("Загрузка клиентов"); + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void ClientsForm_Load(object sender, EventArgs e) { @@ -47,12 +42,12 @@ namespace SushiBar.Forms private void DeleteButton_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); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Удаление клиента"); try { diff --git a/SushiBar/SushiBar/Forms/FormComponents.cs b/SushiBar/SushiBar/Forms/FormComponents.cs index 7943174..7d78183 100644 --- a/SushiBar/SushiBar/Forms/FormComponents.cs +++ b/SushiBar/SushiBar/Forms/FormComponents.cs @@ -1,6 +1,8 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using SushiBar.Extensions; +using SushiBarContracts.DI; namespace SushiBar.Forms { @@ -20,26 +22,20 @@ namespace SushiBar.Forms } private void LoadData() { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + try + { + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -52,7 +48,7 @@ namespace SushiBar.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/Forms/FormCreateOrder.cs b/SushiBar/SushiBar/Forms/FormCreateOrder.cs index b447051..8624895 100644 --- a/SushiBar/SushiBar/Forms/FormCreateOrder.cs +++ b/SushiBar/SushiBar/Forms/FormCreateOrder.cs @@ -20,24 +20,25 @@ namespace SushiBar.Forms } private void FormCreateOrder_Load(object sender, EventArgs e) { - try - { - _logger.LogInformation("Загрузка суши для заказа"); - List? _list = _logicS.ReadList(null); - if (_list != null) - { - ComboBoxSushi.DisplayMember = "SushiName"; - ComboBoxSushi.ValueMember = "Id"; - ComboBoxSushi.DataSource = _list; - ComboBoxSushi.SelectedItem = null; - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки суши"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + _logger.LogInformation("Загрузка суши для заказа"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + ComboBoxSushi.DisplayMember = "SushiCreamName"; + ComboBoxSushi.ValueMember = "Id"; + ComboBoxSushi.DataSource = list; + ComboBoxSushi.SelectedItem = null; + } + _logger.LogInformation("Суши загружено"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void CalcSum() { if (ComboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(TextBoxCount.Text)) diff --git a/SushiBar/SushiBar/Forms/FormImplementer.cs b/SushiBar/SushiBar/Forms/FormImplementer.cs index f359f4a..959744a 100644 --- a/SushiBar/SushiBar/Forms/FormImplementer.cs +++ b/SushiBar/SushiBar/Forms/FormImplementer.cs @@ -40,8 +40,7 @@ namespace SushiBar.Forms catch (Exception ex) { _logger.LogError(ex, "Ошибка получения исполнителя"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/SushiBar/SushiBar/Forms/FormImplementers.cs b/SushiBar/SushiBar/Forms/FormImplementers.cs index db4c42e..204b804 100644 --- a/SushiBar/SushiBar/Forms/FormImplementers.cs +++ b/SushiBar/SushiBar/Forms/FormImplementers.cs @@ -1,6 +1,9 @@ using Microsoft.Extensions.Logging; +using SushiBar.Extensions; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; +using System.Windows.Forms; namespace SushiBar.Forms { @@ -24,28 +27,18 @@ namespace SushiBar.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView.FillandConfigGrid(_logic.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 CreateButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -59,7 +52,7 @@ namespace SushiBar.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/Forms/FormMailView.cs b/SushiBar/SushiBar/Forms/FormMailView.cs index 112d5b6..d2f27d1 100644 --- a/SushiBar/SushiBar/Forms/FormMailView.cs +++ b/SushiBar/SushiBar/Forms/FormMailView.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SushiBar.Extensions; using SushiBarContracts.BusinessLogicsContracts; namespace SushiBar.Forms @@ -16,24 +17,16 @@ namespace SushiBar.Forms private void FormMailView_Load(object sender, EventArgs e) { - 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("Загрузка списка писем"); - } - 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/SushiBar/SushiBar/Forms/FormMain.Designer.cs b/SushiBar/SushiBar/Forms/FormMain.Designer.cs index 83a9518..b5574a5 100644 --- a/SushiBar/SushiBar/Forms/FormMain.Designer.cs +++ b/SushiBar/SushiBar/Forms/FormMain.Designer.cs @@ -20,242 +20,250 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - menuStrip1 = new MenuStrip(); - toolStripMenuItem = new ToolStripMenuItem(); - sushiToolStripMenuItem = new ToolStripMenuItem(); - componentsToolStripMenuItem = new ToolStripMenuItem(); - clientsToolStripMenuItem = new ToolStripMenuItem(); - implementersToolStripMenuItem = new ToolStripMenuItem(); - отчётыToolStripMenuItem1 = new ToolStripMenuItem(); - sushisReportToolStripMenuItem = new ToolStripMenuItem(); - componentsReportПоСушиToolStripMenuItem = new ToolStripMenuItem(); - orderReportToolStripMenuItem = new ToolStripMenuItem(); - startWorksToolStripMenuItem = new ToolStripMenuItem(); - отчётыToolStripMenuItem = new ToolStripMenuItem(); - sushisToolStripMenuItem = new ToolStripMenuItem(); - componentSushisToolStripMenuItem = new ToolStripMenuItem(); - ordersToolStripMenuItem = new ToolStripMenuItem(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - MailToolStripMenuItem = new ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - menuStrip1.SuspendLayout(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 28); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(986, 514); - dataGridView.TabIndex = 0; - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчётыToolStripMenuItem1, startWorksToolStripMenuItem, MailToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1184, 28); - menuStrip1.TabIndex = 1; - menuStrip1.Text = "menuStrip1"; - // - // toolStripMenuItem - // - toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushiToolStripMenuItem, componentsToolStripMenuItem, clientsToolStripMenuItem, implementersToolStripMenuItem }); - toolStripMenuItem.Name = "toolStripMenuItem"; - toolStripMenuItem.Size = new Size(117, 24); - toolStripMenuItem.Text = "Справочники"; - // - // sushiToolStripMenuItem - // - sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; - sushiToolStripMenuItem.Size = new Size(185, 26); - sushiToolStripMenuItem.Text = "Суши"; - sushiToolStripMenuItem.Click += SushiToolStripMenuItem_Click; - // - // componentsToolStripMenuItem - // - componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(185, 26); - componentsToolStripMenuItem.Text = "Компоненты"; - componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; - // - // clientsToolStripMenuItem - // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(185, 26); - clientsToolStripMenuItem.Text = "Клиенты"; - clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; - // - // implementersToolStripMenuItem - // - implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; - implementersToolStripMenuItem.Size = new Size(185, 26); - implementersToolStripMenuItem.Text = "Исполнители"; - implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; - // - // отчётыToolStripMenuItem1 - // - отчётыToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { sushisReportToolStripMenuItem, componentsReportПоСушиToolStripMenuItem, orderReportToolStripMenuItem }); - отчётыToolStripMenuItem1.Name = "отчётыToolStripMenuItem1"; - отчётыToolStripMenuItem1.Size = new Size(73, 24); - отчётыToolStripMenuItem1.Text = "Отчёты"; - // - // sushisReportToolStripMenuItem - // - sushisReportToolStripMenuItem.Name = "sushisReportToolStripMenuItem"; - sushisReportToolStripMenuItem.Size = new Size(243, 26); - sushisReportToolStripMenuItem.Text = "Список суши"; - sushisReportToolStripMenuItem.Click += sushisReportToolStripMenuItem_Click; - // - // componentsReportПоСушиToolStripMenuItem - // - componentsReportПоСушиToolStripMenuItem.Name = "componentsReportПоСушиToolStripMenuItem"; - componentsReportПоСушиToolStripMenuItem.Size = new Size(243, 26); - componentsReportПоСушиToolStripMenuItem.Text = "Компоненты по суши"; - componentsReportПоСушиToolStripMenuItem.Click += componentsReportПоСушиToolStripMenuItem_Click; - // - // orderReportToolStripMenuItem - // - orderReportToolStripMenuItem.Name = "orderReportToolStripMenuItem"; - orderReportToolStripMenuItem.Size = new Size(243, 26); - orderReportToolStripMenuItem.Text = "Список заказов"; - orderReportToolStripMenuItem.Click += orderReportToolStripMenuItem_Click; - // - // startWorksToolStripMenuItem - // - startWorksToolStripMenuItem.Name = "startWorksToolStripMenuItem"; - startWorksToolStripMenuItem.Size = new Size(114, 24); - startWorksToolStripMenuItem.Text = "Запуск работ"; - startWorksToolStripMenuItem.Click += startWorksToolStripMenuItem_Click; - // - // отчётыToolStripMenuItem - // - отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - отчётыToolStripMenuItem.Size = new Size(32, 19); - // - // sushisToolStripMenuItem - // - sushisToolStripMenuItem.Name = "sushisToolStripMenuItem"; - sushisToolStripMenuItem.Size = new Size(32, 19); - // - // componentSushisToolStripMenuItem - // - componentSushisToolStripMenuItem.Name = "componentSushisToolStripMenuItem"; - componentSushisToolStripMenuItem.Size = new Size(32, 19); - // - // ordersToolStripMenuItem - // - ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - ordersToolStripMenuItem.Size = new Size(32, 19); - // - // buttonCreateOrder - // - buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.Location = new Point(992, 28); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(180, 30); - buttonCreateOrder.TabIndex = 8; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonTakeOrderInWork.Location = new Point(992, 64); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(180, 30); - buttonTakeOrderInWork.TabIndex = 9; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonOrderReady.Location = new Point(992, 100); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(180, 30); - buttonOrderReady.TabIndex = 10; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.Location = new Point(992, 136); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(180, 30); - buttonIssuedOrder.TabIndex = 11; - buttonIssuedOrder.Text = "Заказ Выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRef.Location = new Point(992, 172); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(180, 30); - buttonRef.TabIndex = 12; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // MailToolStripMenuItem - // - MailToolStripMenuItem.Name = "MailToolStripMenuItem"; - MailToolStripMenuItem.Size = new Size(65, 24); - MailToolStripMenuItem.Text = "Почта"; - MailToolStripMenuItem.Click += MailToolStripMenuItem_Click; - // - // FormMain - // - AllowDrop = true; - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1184, 554); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Name = "FormMain"; - Text = "Сушибар"; - WindowState = FormWindowState.Maximized; - Load += FormMain_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + menuStrip1 = new MenuStrip(); + toolStripMenuItem = new ToolStripMenuItem(); + sushiToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + implementersToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem1 = new ToolStripMenuItem(); + sushisReportToolStripMenuItem = new ToolStripMenuItem(); + componentsReportПоСушиToolStripMenuItem = new ToolStripMenuItem(); + orderReportToolStripMenuItem = new ToolStripMenuItem(); + startWorksToolStripMenuItem = new ToolStripMenuItem(); + MailToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + sushisToolStripMenuItem = new ToolStripMenuItem(); + componentSushisToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + backupToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 28); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(986, 514); + dataGridView.TabIndex = 0; + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчётыToolStripMenuItem1, startWorksToolStripMenuItem, MailToolStripMenuItem, backupToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1184, 28); + menuStrip1.TabIndex = 1; + menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItem + // + toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushiToolStripMenuItem, componentsToolStripMenuItem, clientsToolStripMenuItem, implementersToolStripMenuItem }); + toolStripMenuItem.Name = "toolStripMenuItem"; + toolStripMenuItem.Size = new Size(117, 24); + toolStripMenuItem.Text = "Справочники"; + // + // sushiToolStripMenuItem + // + sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; + sushiToolStripMenuItem.Size = new Size(185, 26); + sushiToolStripMenuItem.Text = "Суши"; + sushiToolStripMenuItem.Click += SushiToolStripMenuItem_Click; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(185, 26); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(185, 26); + clientsToolStripMenuItem.Text = "Клиенты"; + clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; + // + // implementersToolStripMenuItem + // + implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + implementersToolStripMenuItem.Size = new Size(185, 26); + implementersToolStripMenuItem.Text = "Исполнители"; + implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; + // + // отчётыToolStripMenuItem1 + // + отчётыToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { sushisReportToolStripMenuItem, componentsReportПоСушиToolStripMenuItem, orderReportToolStripMenuItem }); + отчётыToolStripMenuItem1.Name = "отчётыToolStripMenuItem1"; + отчётыToolStripMenuItem1.Size = new Size(73, 24); + отчётыToolStripMenuItem1.Text = "Отчёты"; + // + // sushisReportToolStripMenuItem + // + sushisReportToolStripMenuItem.Name = "sushisReportToolStripMenuItem"; + sushisReportToolStripMenuItem.Size = new Size(243, 26); + sushisReportToolStripMenuItem.Text = "Список суши"; + sushisReportToolStripMenuItem.Click += sushisReportToolStripMenuItem_Click; + // + // componentsReportПоСушиToolStripMenuItem + // + componentsReportПоСушиToolStripMenuItem.Name = "componentsReportПоСушиToolStripMenuItem"; + componentsReportПоСушиToolStripMenuItem.Size = new Size(243, 26); + componentsReportПоСушиToolStripMenuItem.Text = "Компоненты по суши"; + componentsReportПоСушиToolStripMenuItem.Click += componentsReportПоСушиToolStripMenuItem_Click; + // + // orderReportToolStripMenuItem + // + orderReportToolStripMenuItem.Name = "orderReportToolStripMenuItem"; + orderReportToolStripMenuItem.Size = new Size(243, 26); + orderReportToolStripMenuItem.Text = "Список заказов"; + orderReportToolStripMenuItem.Click += orderReportToolStripMenuItem_Click; + // + // startWorksToolStripMenuItem + // + startWorksToolStripMenuItem.Name = "startWorksToolStripMenuItem"; + startWorksToolStripMenuItem.Size = new Size(114, 24); + startWorksToolStripMenuItem.Text = "Запуск работ"; + startWorksToolStripMenuItem.Click += startWorksToolStripMenuItem_Click; + // + // MailToolStripMenuItem + // + MailToolStripMenuItem.Name = "MailToolStripMenuItem"; + MailToolStripMenuItem.Size = new Size(65, 24); + MailToolStripMenuItem.Text = "Почта"; + MailToolStripMenuItem.Click += MailToolStripMenuItem_Click; + // + // отчётыToolStripMenuItem + // + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(32, 19); + // + // sushisToolStripMenuItem + // + sushisToolStripMenuItem.Name = "sushisToolStripMenuItem"; + sushisToolStripMenuItem.Size = new Size(32, 19); + // + // componentSushisToolStripMenuItem + // + componentSushisToolStripMenuItem.Name = "componentSushisToolStripMenuItem"; + componentSushisToolStripMenuItem.Size = new Size(32, 19); + // + // ordersToolStripMenuItem + // + ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + ordersToolStripMenuItem.Size = new Size(32, 19); + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(992, 28); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(180, 30); + buttonCreateOrder.TabIndex = 8; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(992, 64); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(180, 30); + buttonTakeOrderInWork.TabIndex = 9; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(992, 100); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(180, 30); + buttonOrderReady.TabIndex = 10; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.Location = new Point(992, 136); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(180, 30); + buttonIssuedOrder.TabIndex = 11; + buttonIssuedOrder.Text = "Заказ Выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(992, 172); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(180, 30); + buttonRef.TabIndex = 12; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // backupToolStripMenuItem + // + backupToolStripMenuItem.Name = "backupToolStripMenuItem"; + backupToolStripMenuItem.Size = new Size(123, 24); + backupToolStripMenuItem.Text = "Создать бекап"; + backupToolStripMenuItem.Click += backupToolStripMenuItem_Click; + // + // FormMain + // + AllowDrop = true; + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1184, 554); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Сушибар"; + WindowState = FormWindowState.Maximized; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private DataGridView dataGridView; + private DataGridView dataGridView; private MenuStrip menuStrip1; private Button buttonCreateOrder; private Button buttonTakeOrderInWork; @@ -277,5 +285,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem startWorksToolStripMenuItem; private ToolStripMenuItem MailToolStripMenuItem; - } + private ToolStripMenuItem backupToolStripMenuItem; + } } \ No newline at end of file diff --git a/SushiBar/SushiBar/Forms/FormMain.cs b/SushiBar/SushiBar/Forms/FormMain.cs index 5b1b4e7..3988bab 100644 --- a/SushiBar/SushiBar/Forms/FormMain.cs +++ b/SushiBar/SushiBar/Forms/FormMain.cs @@ -1,208 +1,236 @@ using Microsoft.Extensions.Logging; +using SushiBar.Extensions; +using SushiBarBusinessLogic.BusinessLogic; using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBar.Forms { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["SushiId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки суши"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void SushiToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSushis)); - if (service is FormSushis form) - { - form.ShowDialog(); - } - } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - private void sushisReportToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveSushisToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - private void componentsReportПоСушиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiComponents)); - if (service is FormReportSushiComponents form) - { - form.ShowDialog(); - } - } + public FormMain(ILogger logger, + IOrderLogic orderLogic, + IReportLogic reportLogic, + IWorkProcess workProcess, + IBackUpLogic backUpLogic + ) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + _workProcess = workProcess; + _backUpLogic = backUpLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void SushiToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormSushis form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } - private void orderReportToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + private void sushisReportToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveSushisToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } - private void clientsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } + private void componentsReportПоСушиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormReportSushiComponents form) + { + form.ShowDialog(); + } + } - private void implementersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } + private void orderReportToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } - private void startWorksToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + private void clientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormClients form) + { + form.ShowDialog(); + } + } - private void MailToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMailView)); - if (service is FormMailView form) - { - form.ShowDialog(); - } - } - } + private void implementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void startWorksToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((DependencyManager.Instance.Resolve() as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void MailToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormMailView form) + { + form.ShowDialog(); + } + } + + private void backupToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } diff --git a/SushiBar/SushiBar/Forms/FormSushi.cs b/SushiBar/SushiBar/Forms/FormSushi.cs index 9df5936..2c33ae7 100644 --- a/SushiBar/SushiBar/Forms/FormSushi.cs +++ b/SushiBar/SushiBar/Forms/FormSushi.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; using SushiBarContracts.SearchModels; using SushiBarDataModels.Models; @@ -69,7 +70,7 @@ namespace SushiBar.Forms } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushiComponent form) { @@ -96,7 +97,7 @@ namespace SushiBar.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushiComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/SushiBar/SushiBar/Forms/FormSushis.cs b/SushiBar/SushiBar/Forms/FormSushis.cs index caefccd..b821910 100644 --- a/SushiBar/SushiBar/Forms/FormSushis.cs +++ b/SushiBar/SushiBar/Forms/FormSushis.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Logging; +using SushiBar.Extensions; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBar.Forms { @@ -20,27 +22,20 @@ namespace SushiBar.Forms } private void LoadData() { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["SushiComponents"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка суши"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки суши"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + try + { + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка суши"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushi form) { if (form.ShowDialog() == DialogResult.OK) @@ -53,7 +48,7 @@ namespace SushiBar.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushi form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index eab4db8..2374f76 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -1,20 +1,19 @@ -using IceCreamShopContracts.StoragesContracts; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using SushiBar.Forms; +using SushiBarBusinessLogic.BusinessLogic; using SushiBarBusinessLogic.BusinessLogics; using SushiBarBusinessLogic.MailWorker; using SushiBarBusinessLogic.OfficePackage; using SushiBarBusinessLogic.OfficePackage.Implements; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.StoragesContracts; -using SushiBarDatabaseImplement.Implements; +using SushiBarContracts.DI; namespace SushiBar { - internal static class Program + internal static class Program { private static ServiceProvider? _serviceProvider; public static ServiceProvider? ServiceProvider => _serviceProvider; @@ -28,12 +27,11 @@ namespace SushiBar // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); - try + try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -48,54 +46,53 @@ namespace SushiBar } catch (Exception ex) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); + var logger = DependencyManager.Instance.Resolve(); + 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(); + Application.Run(DependencyManager.Instance.Resolve()); + } - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - services.AddTransient(); + private static void InitDependency() + { + DependencyManager.InitDependency(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - } + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } diff --git a/SushiBar/SushiBar/SushiBar.csproj b/SushiBar/SushiBar/SushiBar.csproj index dfe9d68..62b806d 100644 --- a/SushiBar/SushiBar/SushiBar.csproj +++ b/SushiBar/SushiBar/SushiBar.csproj @@ -24,11 +24,12 @@ - - + + Always + PreserveNewest diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..3dd51bc --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.StoragesContracts; +using SushiBarDataModels; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace SushiBarBusinessLogic.BusinessLogic +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + private readonly IBackUpInfo _backUpInfo; + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс - модель для { type.Name }"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + ZipFile.CreateFromDirectory(model.FolderName, fileName); + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs index 0fae2b2..3d09b6a 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -1,8 +1,8 @@ -using IceCreamShopContracts.StoragesContracts; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; namespace SushiBarBusinessLogic.BusinessLogics diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index c724cbd..48c34eb 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -115,7 +115,7 @@ namespace SushiBarBusinessLogic.BusinessLogics } model.Status = orderStatus; - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; } diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj index 5639c84..7017c98 100644 --- a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj +++ b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -16,6 +16,7 @@ + diff --git a/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..d6a1576 --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,22 @@ +namespace SushiBarContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public ColumnAttribute(string title = "", bool visible = true, int width = 0, + GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + public string Title { get; private set; } + public bool Visible { get; private set; } + public int Width { get; private set; } + public GridViewAutoSize GridViewAutoSize { get; private set; } + public bool IsUseAutoSize { get; private set; } + + } +} diff --git a/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..9fa1721 --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace SushiBarContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..f0ca175 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } + +} diff --git a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs index 6db61aa..b1ed58f 100644 --- a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace SushiBarContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..bd17b76 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using SushiBarContracts.BindingModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/SushiBar/SushiBarContracts/DI/DependencyManager.cs b/SushiBar/SushiBarContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..e15165a --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/DependencyManager.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..f00efbe --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..4f2d798 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs @@ -0,0 +1,9 @@ +namespace SushiBarContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + + } +} diff --git a/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..f2af4f7 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.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 T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where U : class, T 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/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..a4e2763 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,53 @@ +using System.Reflection; + +namespace SushiBarContracts.DI +{ + public static partial class ServiceProviderLoader + { + 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/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..7cbedd5 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs index 3b112b3..fb23fc6 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IImplementerStorage.cs @@ -2,7 +2,7 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; -namespace IceCreamShopContracts.StoragesContracts +namespace SushiBarContracts.StoragesContracts { public interface IImplementerStorage { diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj index ef52534..fba228a 100644 --- a/SushiBar/SushiBarContracts/SushiBarContracts.csproj +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -4,8 +4,13 @@ net6.0 enable enable + \bin + + + + diff --git a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs index d4ab405..95d5a2b 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,18 @@ -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { - public class ClientViewModel + 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(visible: false)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Email клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } } diff --git a/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs index f879afc..69fb28a 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs @@ -1,14 +1,15 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.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(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column(title: "Цена", width: 80)] + public double Cost { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs index 8dc68c4..b1c6c13 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs @@ -1,18 +1,19 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs index d1cb3cb..7c2b854 100644 --- a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,27 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { - public class MessageInfoViewModel : IMessageInfoModel + public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } - public int? ClientId { get; set; } + [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; + [Column(title: "Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } + [Column(title: "Заголовок", width: 150)] + public string Subject { get; set; } = string.Empty; - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; - } + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 6c3fc54..f6bafa4 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -1,31 +1,34 @@ -using SushiBarDataModels.Enums; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Enums; using SushiBarDataModels.Models; -using System.ComponentModel; namespace SushiBarContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int SushiId { get; set; } - public int ClientId { get; set; } - public int? ImplementerId { get; set; } - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Суши")] - public string SushiName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] - public string ImplementerName { 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; } + [Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } + [Column(visible: false)] + public int SushiId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Суши", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string SushiName { get; set; } = string.Empty; + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerName { get; set;} = string.Empty; + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/ReportOrdersViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ReportOrdersViewModel.cs index dfb4ded..3d43be1 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ReportOrdersViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ReportOrdersViewModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.ViewModels +namespace SushiBarContracts.ViewModels { public class ReportOrdersViewModel { diff --git a/SushiBar/SushiBarContracts/ViewModels/ReportProductComponentViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ReportProductComponentViewModel.cs index 63ce68a..730ee42 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ReportProductComponentViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ReportProductComponentViewModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.ViewModels +namespace SushiBarContracts.ViewModels { public class ReportSushiComponentViewModel { diff --git a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs index 73b3ae8..037996b 100644 --- a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -1,16 +1,18 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class SushiViewModel : ISushiModel { - public int Id { get; set; } - [DisplayName("Название суши")] - public string SushiName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary SushiComponents + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название Суши", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string SushiName { get; set; } = string.Empty; + [Column(title: "Цена", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary SushiComponents { get; set; diff --git a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs index 626ae17..8468874 100644 --- a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs @@ -1,6 +1,6 @@ namespace SushiBarDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } @@ -8,6 +8,5 @@ DateTime DateDelivery { get; } string Subject { get; } string Body { get; } - } } diff --git a/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs b/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..b3a9a1f --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarDatabaseImplement.Implements; + +namespace SushiBarDatabaseImplement +{ + 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/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..712ae1e --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new SushiBarDatabase(); + 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/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs index 4918d1a..aca63f2 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ImplementerStorage.cs @@ -1,6 +1,6 @@ -using IceCreamShopContracts.StoragesContracts; -using SushiBarContracts.BindingModels; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDatabaseImplement.Models; diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 4cf9ba3..28999ab 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -4,7 +4,6 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDatabaseImplement.Models; -using System.Collections.Generic; namespace SushiBarDatabaseImplement.Implements { diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs index 936bd1a..5b3a0c9 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs @@ -3,18 +3,24 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } - [Required] - public string ClientFIO { get; private set; } = string.Empty; - [Required] - public string Email { get; private set; } = string.Empty; - [Required] - public string Password { get; private set; } = string.Empty; + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Email { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] public List Messages = new(); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Component.cs b/SushiBar/SushiBarDatabaseImplement/Models/Component.cs index df26753..085903e 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Component.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Component.cs @@ -3,16 +3,21 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - [Required] - public string ComponentName { get; private set; } = string.Empty; - [Required] - public double Cost { get; set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + [Required] + public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List SushiComponents { get; set; } = new(); public static Component? Create(ComponentBindingModel model) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs index 950256f..6d634a4 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs @@ -3,18 +3,25 @@ using System.ComponentModel.DataAnnotations; using SushiBarDataModels.Models; using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; + [DataMember] [Required] public int Qualification { get; set; } = 0; + [DataMember] [Required] public int WorkExperience { get; set; } = 0; [ForeignKey("ImplementerId")] diff --git a/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs b/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs index 5109a4a..bce621d 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs @@ -2,23 +2,26 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { - [Key] + [DataMember] + [Key] public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { 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 Client? Client; public static MessageInfo? Create(SushiBarDatabase context, MessageInfoBindingModel model) { @@ -46,5 +49,7 @@ namespace SushiBarDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 3000751..5240952 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -3,29 +3,38 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public int Count { get; set; } - [Required] + [DataMember] + [Required] public double Sum { get; set; } - [Required] + [DataMember] + [Required] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Required] + [DataMember] + [Required] public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } - [Required] + [DataMember] + public DateTime? DateImplement { get; set; } + [DataMember] + [Required] public int SushiId { get; private set; } public virtual Sushi Sushi { get; set; } - - public int ClientId { get; private set; } + [DataMember] + public int ClientId { get; private set; } public virtual Client Client { get; private set; } - - public int? ImplementerId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } public virtual Implementer? Implementer { get; set; } public static Order Create(SushiBarDatabase context, OrderBindingModel model) @@ -46,6 +55,7 @@ namespace SushiBarDatabaseImplement.Models Sushi = context.Sushis.First(x => x.Id == model.SushiId), ClientId = model.ClientId, Client = context.Clients.First(x => x.Id == model.ClientId), + ImplementerId = model.ImplementerId, Implementer = model.ImplementerId == null ? null : context.Implementers.First(i => i.Id == model.ImplementerId) }; } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs index ea0c130..1429073 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs @@ -3,18 +3,24 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class Sushi : ISushiModel + [DataContract] + public class Sushi : ISushiModel { - public int Id { get; set; } - [Required] + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public string SushiName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Price { get; set; } - private Dictionary? _sushiComponents = null; - [NotMapped] + + private Dictionary? _sushiComponents = null; + [NotMapped] public Dictionary SushiComponents { get diff --git a/SushiBar/SushiBarDatabaseImplement/Models/SushiComponent.cs b/SushiBar/SushiBarDatabaseImplement/Models/SushiComponent.cs index e47fdfb..55f06d3 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/SushiComponent.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/SushiComponent.cs @@ -1,18 +1,23 @@ using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class SushiComponent + [DataContract] + public class SushiComponent { - public int Id { get; set; } - [Required] + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public int SushiId { get; set; } - [Required] + [DataMember] + [Required] public int ComponentId { get; set; } - [Required] + [DataMember] + [Required] public int Count { get; set; } - public virtual Component Component { get; set; } = new(); + public virtual Component Component { get; set; } = new(); public virtual Sushi Sushi { get; set; } = new(); - } } diff --git a/SushiBar/SushiBarDatabaseImplement/Properties/Resources.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Properties/Resources.Designer.cs new file mode 100644 index 0000000..daab7e1 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace SushiBarDatabaseImplement.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SushiBarDatabaseImplement.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Properties/Resources.resx b/SushiBar/SushiBarDatabaseImplement/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj index 2af36de..85958cc 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj @@ -26,4 +26,23 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + diff --git a/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..2c4f761 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarFileImplement.Implements; + +namespace SushiBarFileImplement +{ + public class FileImplementationExtension : 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/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..708688f --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,38 @@ +using SushiBarContracts.StoragesContracts; +using System.Reflection; + +namespace SushiBarFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + 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; + } + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.GetValue(source); + } + + } +} diff --git a/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs index 9950acb..ad0690f 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs @@ -1,11 +1,12 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarFileImplement.Models; namespace SushiBarFileImplement.Implements { - public class ClientStorage + public class ClientStorage : IClientStorage { private readonly DataFileSingleton source; public ClientStorage() diff --git a/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs index 6369c82..ebab256 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ImplementerStorage.cs @@ -1,6 +1,6 @@ -using IceCreamShopContracts.StoragesContracts; -using SushiBarContracts.BindingModels; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarFileImplement.Models; diff --git a/SushiBar/SushiBarFileImplement/Models/Client.cs b/SushiBar/SushiBarFileImplement/Models/Client.cs index 26bd8e5..87e0228 100644 --- a/SushiBar/SushiBarFileImplement/Models/Client.cs +++ b/SushiBar/SushiBarFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { - public class Client + [DataContract] + public class Client { - 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/SushiBar/SushiBarFileImplement/Models/Component.cs b/SushiBar/SushiBarFileImplement/Models/Component.cs index 8c4ce84..d4d0b76 100644 --- a/SushiBar/SushiBarFileImplement/Models/Component.cs +++ b/SushiBar/SushiBarFileImplement/Models/Component.cs @@ -1,15 +1,20 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { - public class Component : IComponentModel + [DataContract] + 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) { if (model == null) diff --git a/SushiBar/SushiBarFileImplement/Models/Implementer.cs b/SushiBar/SushiBarFileImplement/Models/Implementer.cs index 7585909..9e05cd0 100644 --- a/SushiBar/SushiBarFileImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarFileImplement/Models/Implementer.cs @@ -1,17 +1,24 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { - internal class Implementer : IImplementerModel + [DataContract] + internal class Implementer : IImplementerModel { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public int Qualification { get; set; } = 0; - public int WorkExperience { get; set; } = 0; + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; + [DataMember] + public int Qualification { get; set; } = 0; + [DataMember] + public int WorkExperience { get; set; } = 0; public static Implementer? Create(ImplementerBindingModel model) { if (model == null) diff --git a/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs b/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs index 0d6e81a..dd164a6 100644 --- a/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs +++ b/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs @@ -1,23 +1,31 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; + [DataMember] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; + + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -71,5 +79,7 @@ namespace SushiBarFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 31df23d..3c996be 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -2,21 +2,32 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - public int SushiId { get; private set; } - public int ClientId { get; private set; } - 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; } - public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public int SushiId { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } + [DataMember] + public int Count { get; private set; } + [DataMember] + public double Sum { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public DateTime DateCreate { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel model) { if (model == null) diff --git a/SushiBar/SushiBarFileImplement/Models/Sushi.cs b/SushiBar/SushiBarFileImplement/Models/Sushi.cs index 5e98c30..db0f606 100644 --- a/SushiBar/SushiBarFileImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarFileImplement/Models/Sushi.cs @@ -1,15 +1,20 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { - public class Sushi : ISushiModel + [DataContract] + public class Sushi : ISushiModel { - public int Id { get; private set; } - public string SushiName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string SushiName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _sushiComponents = null; public Dictionary SushiComponents diff --git a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj index 00e2c96..9f96834 100644 --- a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj +++ b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj @@ -11,4 +11,7 @@ + + + diff --git a/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f6f3014 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarListImplement.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/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs b/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs index 8836a46..35fa59e 100644 --- a/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ImplementerStorage.cs @@ -1,6 +1,6 @@ -using IceCreamShopContracts.StoragesContracts; -using SushiBarContracts.BindingModels; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarListImplement.Models; diff --git a/SushiBar/SushiBarListImplement/ListImplementationExtension.cs b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..aaebeb8 --- /dev/null +++ b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarListImplement.Implements; + +namespace SushiBarListImplement +{ + 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/SushiBar/SushiBarListImplement/Models/MessageInfo.cs b/SushiBar/SushiBarListImplement/Models/MessageInfo.cs index 8a99091..7cba57c 100644 --- a/SushiBar/SushiBarListImplement/Models/MessageInfo.cs +++ b/SushiBar/SushiBarListImplement/Models/MessageInfo.cs @@ -45,5 +45,6 @@ namespace SushiBarListImplement.Models DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj index 00e2c96..9f96834 100644 --- a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -11,4 +11,7 @@ + + +