diff --git a/AutomobilePlant.sln b/AutomobilePlant.sln
new file mode 100644
index 0000000..7e4bb3f
--- /dev/null
+++ b/AutomobilePlant.sln
@@ -0,0 +1,49 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.4.33213.308
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{970E66D6-3147-419D-98DC-9E05B10232B5}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantDataModels", "AutomobilePlantDataModels\AutomobilePlantDataModels.csproj", "{27B6E4A1-BB53-4AF6-AACA-099A40B64D60}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantContracts", "AutomobilePlantContracts\AutomobilePlantContracts.csproj", "{2F1D0A55-2722-48B4-87D1-0440E74D6E0A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AutomobilePlantBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{CC4E3C20-ABA4-4A54-B992-B68D39A1236E}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplements", "AutomobilePlantListImplements\AutomobilePlantListImplements.csproj", "{B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {970E66D6-3147-419D-98DC-9E05B10232B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {970E66D6-3147-419D-98DC-9E05B10232B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {970E66D6-3147-419D-98DC-9E05B10232B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {970E66D6-3147-419D-98DC-9E05B10232B5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {27B6E4A1-BB53-4AF6-AACA-099A40B64D60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {27B6E4A1-BB53-4AF6-AACA-099A40B64D60}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {27B6E4A1-BB53-4AF6-AACA-099A40B64D60}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {27B6E4A1-BB53-4AF6-AACA-099A40B64D60}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2F1D0A55-2722-48B4-87D1-0440E74D6E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2F1D0A55-2722-48B4-87D1-0440E74D6E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2F1D0A55-2722-48B4-87D1-0440E74D6E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2F1D0A55-2722-48B4-87D1-0440E74D6E0A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CC4E3C20-ABA4-4A54-B992-B68D39A1236E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CC4E3C20-ABA4-4A54-B992-B68D39A1236E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CC4E3C20-ABA4-4A54-B992-B68D39A1236E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CC4E3C20-ABA4-4A54-B992-B68D39A1236E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {41F89D22-CD9D-4FAB-A7AA-A3DF6DA7078A}
+ EndGlobalSection
+EndGlobal
diff --git a/AutomobilePlant/AutomobilePlant.csproj b/AutomobilePlant/AutomobilePlant.csproj
new file mode 100644
index 0000000..a64875e
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant.csproj
@@ -0,0 +1,23 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormCar.Designer.cs b/AutomobilePlant/FormCar.Designer.cs
new file mode 100644
index 0000000..07d275a
--- /dev/null
+++ b/AutomobilePlant/FormCar.Designer.cs
@@ -0,0 +1,232 @@
+namespace AutomobilePlant
+{
+ partial class FormCar
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxPrice = new System.Windows.Forms.TextBox();
+ this.groupBoxComponents = new System.Windows.Forms.GroupBox();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.groupBoxComponents.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 9);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(80, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(12, 45);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(86, 20);
+ this.labelPrice.TabIndex = 1;
+ this.labelPrice.Text = "Стоимость:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(98, 6);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(315, 27);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxPrice
+ //
+ this.textBoxPrice.Location = new System.Drawing.Point(98, 39);
+ this.textBoxPrice.Name = "textBoxPrice";
+ this.textBoxPrice.Size = new System.Drawing.Size(157, 27);
+ this.textBoxPrice.TabIndex = 3;
+ //
+ // groupBoxComponents
+ //
+ this.groupBoxComponents.Controls.Add(this.buttonUpdate);
+ this.groupBoxComponents.Controls.Add(this.buttonDelete);
+ this.groupBoxComponents.Controls.Add(this.buttonEdit);
+ this.groupBoxComponents.Controls.Add(this.buttonAdd);
+ this.groupBoxComponents.Controls.Add(this.dataGridView);
+ this.groupBoxComponents.Location = new System.Drawing.Point(15, 83);
+ this.groupBoxComponents.Name = "groupBoxComponents";
+ this.groupBoxComponents.Size = new System.Drawing.Size(699, 275);
+ this.groupBoxComponents.TabIndex = 4;
+ this.groupBoxComponents.TabStop = false;
+ this.groupBoxComponents.Text = "Компоненты";
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(521, 240);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(155, 29);
+ this.buttonUpdate.TabIndex = 4;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(521, 96);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(155, 29);
+ this.buttonDelete.TabIndex = 3;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(521, 61);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(155, 29);
+ this.buttonEdit.TabIndex = 2;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(521, 26);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(155, 29);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ID,
+ this.ColumnComponentName,
+ this.ColumnCount});
+ this.dataGridView.Location = new System.Drawing.Point(6, 26);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(490, 243);
+ this.dataGridView.TabIndex = 0;
+ //
+ // ID
+ //
+ this.ID.HeaderText = "ID";
+ this.ID.MinimumWidth = 6;
+ this.ID.Name = "ID";
+ this.ID.Visible = false;
+ this.ID.Width = 125;
+ //
+ // ColumnComponentName
+ //
+ this.ColumnComponentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ColumnComponentName.HeaderText = "Компонент";
+ this.ColumnComponentName.MinimumWidth = 6;
+ this.ColumnComponentName.Name = "ColumnComponentName";
+ this.ColumnComponentName.Resizable = System.Windows.Forms.DataGridViewTriState.True;
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.MinimumWidth = 6;
+ this.ColumnCount.Name = "ColumnCount";
+ this.ColumnCount.Width = 125;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(356, 379);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(155, 29);
+ this.buttonSave.TabIndex = 5;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(536, 379);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(155, 29);
+ this.buttonCancel.TabIndex = 6;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormCar
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(726, 427);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.groupBoxComponents);
+ this.Controls.Add(this.textBoxPrice);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormCar";
+ this.Text = "Автомобиль";
+ this.groupBoxComponents.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxPrice;
+ private GroupBox groupBoxComponents;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ID;
+ private DataGridViewTextBoxColumn ColumnComponentName;
+ private DataGridViewTextBoxColumn ColumnCount;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonEdit;
+ private Button buttonAdd;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormCar.cs b/AutomobilePlant/FormCar.cs
new file mode 100644
index 0000000..315f1d3
--- /dev/null
+++ b/AutomobilePlant/FormCar.cs
@@ -0,0 +1,218 @@
+using AutomobilePlantDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.BindingModels;
+
+namespace AutomobilePlant
+{
+ public partial class FormCar : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ICarLogic _logic;
+ private int? _id;
+ private Dictionary _carComponents;
+ public int Id { set { _id = value; } }
+
+ public FormCar(ILogger logger, ICarLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _carComponents = new Dictionary();
+ }
+
+ private void FormCar_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка автомобиля");
+ try
+ {
+ var view = _logic.ReadElement(new CarSearchModel { Id = _id.Value });
+ if (view != null)
+ {
+ textBoxName.Text = view.CarName;
+ textBoxPrice.Text = view.Price.ToString();
+ _carComponents = view.CarComponents ?? new
+ Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки автомобиля");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонентов автомобиля");
+ try
+ {
+ if (_carComponents != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var cc in _carComponents)
+ {
+ dataGridView.Rows.Add(new object[] {
+ cc.Key,
+ cc.Value.Item1.ComponentName,
+ cc.Value.Item2
+ });
+ }
+ textBoxPrice.Text = CalcPrice().ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонентов автомобиля");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private double CalcPrice()
+ {
+ double price = 0;
+ foreach (var elem in _carComponents)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCarComponent));
+ if (service is FormCarComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_carComponents.ContainsKey(form.Id))
+ {
+ _carComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _carComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCarComponent));
+ if (service is FormCarComponent form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _carComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ _carComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ try
+ {
+ _logger.LogInformation("Удаление компонента:{ ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
+ _carComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxPrice.Text))
+ {
+ MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (_carComponents == null || _carComponents.Count == 0)
+ {
+ MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение изделия");
+ try
+ {
+ var model = new CarBindingModel
+ {
+ Id = _id ?? 0,
+ CarName = textBoxName.Text,
+ Price = Convert.ToDouble(textBoxPrice.Text),
+ CarComponents = _carComponents
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormCar.resx b/AutomobilePlant/FormCar.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AutomobilePlant/FormCar.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormCarComponent.Designer.cs b/AutomobilePlant/FormCarComponent.Designer.cs
new file mode 100644
index 0000000..70c7b2f
--- /dev/null
+++ b/AutomobilePlant/FormCarComponent.Designer.cs
@@ -0,0 +1,119 @@
+namespace AutomobilePlant
+{
+ partial class FormCarComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.labelComponent = new System.Windows.Forms.Label();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.comboBoxComponent = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelComponent
+ //
+ this.labelComponent.AutoSize = true;
+ this.labelComponent.Location = new System.Drawing.Point(25, 26);
+ this.labelComponent.Name = "labelComponent";
+ this.labelComponent.Size = new System.Drawing.Size(91, 20);
+ this.labelComponent.TabIndex = 0;
+ this.labelComponent.Text = "Компонент:";
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(25, 74);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(93, 20);
+ this.labelCount.TabIndex = 1;
+ this.labelCount.Text = "Количество:";
+ //
+ // comboBoxComponent
+ //
+ this.comboBoxComponent.FormattingEnabled = true;
+ this.comboBoxComponent.Location = new System.Drawing.Point(146, 26);
+ this.comboBoxComponent.Name = "comboBoxComponent";
+ this.comboBoxComponent.Size = new System.Drawing.Size(322, 28);
+ this.comboBoxComponent.TabIndex = 2;
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(146, 71);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(322, 27);
+ this.textBoxCount.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(146, 115);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(143, 29);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(325, 115);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(143, 29);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormCarComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(491, 165);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxComponent);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelComponent);
+ this.Name = "FormCarComponent";
+ this.Text = "Компонент автомобиля";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelComponent;
+ private Label labelCount;
+ private ComboBox comboBoxComponent;
+ private TextBox textBoxCount;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormCarComponent.cs b/AutomobilePlant/FormCarComponent.cs
new file mode 100644
index 0000000..49f3bd9
--- /dev/null
+++ b/AutomobilePlant/FormCarComponent.cs
@@ -0,0 +1,90 @@
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormCarComponent : Form
+ {
+ private readonly List? _list;
+
+ public int Id
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxComponent.SelectedValue);
+ }
+ set
+ {
+ comboBoxComponent.SelectedValue = value;
+ }
+ }
+
+ public IComponentModel? ComponentModel
+ {
+ get
+ {
+ if (_list == null)
+ {
+ return null;
+ }
+ foreach (var elem in _list)
+ {
+ if (elem.Id == Id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+ }
+
+ public int Count
+ {
+ get { return Convert.ToInt32(textBoxCount.Text); }
+ set { textBoxCount.Text = value.ToString(); }
+ }
+
+ public FormCarComponent(IComponentLogic logic)
+ {
+ InitializeComponent();
+ _list = logic.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxComponent.DisplayMember = "ComponentName";
+ comboBoxComponent.ValueMember = "Id";
+ comboBoxComponent.DataSource = _list;
+ comboBoxComponent.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxComponent.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormCarComponent.resx b/AutomobilePlant/FormCarComponent.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AutomobilePlant/FormCarComponent.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormCars.Designer.cs b/AutomobilePlant/FormCars.Designer.cs
new file mode 100644
index 0000000..4b02b75
--- /dev/null
+++ b/AutomobilePlant/FormCars.Designer.cs
@@ -0,0 +1,115 @@
+namespace AutomobilePlant
+{
+ partial class FormCars
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(507, 426);
+ this.dataGridView.TabIndex = 1;
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(533, 12);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(152, 29);
+ this.buttonAdd.TabIndex = 2;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(533, 47);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(152, 29);
+ this.buttonEdit.TabIndex = 3;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(533, 82);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(152, 29);
+ this.buttonDelete.TabIndex = 4;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(533, 409);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(152, 29);
+ this.buttonUpdate.TabIndex = 5;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
+ //
+ // FormCars
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(697, 450);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonEdit);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormCars";
+ this.Text = "Автомобили";
+ this.Load += new System.EventHandler(this.FormCars_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonEdit;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormCars.cs b/AutomobilePlant/FormCars.cs
new file mode 100644
index 0000000..c68e240
--- /dev/null
+++ b/AutomobilePlant/FormCars.cs
@@ -0,0 +1,115 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.BindingModels;
+
+namespace AutomobilePlant
+{
+ public partial class FormCars : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ICarLogic _logic;
+ public FormCars(ILogger logger, ICarLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormCars_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["CarComponents"].Visible = false;
+ }
+ _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(FormCar));
+ if (service is FormCar form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCar));
+ if (service is FormCar form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление автомобиля");
+ try
+ {
+ if (!_logic.Delete(new CarBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления автомобиля");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormCars.resx b/AutomobilePlant/FormCars.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AutomobilePlant/FormCars.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormComponent.Designer.cs b/AutomobilePlant/FormComponent.Designer.cs
new file mode 100644
index 0000000..a3d9be6
--- /dev/null
+++ b/AutomobilePlant/FormComponent.Designer.cs
@@ -0,0 +1,118 @@
+namespace AutomobilePlant
+{
+ partial class FormComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxCost = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(27, 19);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(80, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(27, 70);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(48, 20);
+ this.labelPrice.TabIndex = 1;
+ this.labelPrice.Text = "Цена:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(113, 16);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(257, 27);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ this.textBoxCost.Location = new System.Drawing.Point(113, 67);
+ this.textBoxCost.Name = "textBoxCost";
+ this.textBoxCost.Size = new System.Drawing.Size(257, 27);
+ this.textBoxCost.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(176, 108);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(276, 108);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(400, 149);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCost);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormComponent";
+ this.Text = "Компонент";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormComponent.cs b/AutomobilePlant/FormComponent.cs
new file mode 100644
index 0000000..a0f321e
--- /dev/null
+++ b/AutomobilePlant/FormComponent.cs
@@ -0,0 +1,93 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+
+namespace AutomobilePlant
+{
+ public partial class FormComponent : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+
+ public FormComponent(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormComponent_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение компонента");
+ var view = _logic.ReadElement(new ComponentSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ComponentName;
+ textBoxCost.Text = view.Cost.ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение компонента");
+ try
+ {
+ var model = new ComponentBindingModel
+ {
+ Id = _id ?? 0,
+ ComponentName = textBoxName.Text,
+ Cost = Convert.ToDouble(textBoxCost.Text)
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormComponent.resx b/AutomobilePlant/FormComponent.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AutomobilePlant/FormComponent.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormComponents.Designer.cs b/AutomobilePlant/FormComponents.Designer.cs
new file mode 100644
index 0000000..42b9913
--- /dev/null
+++ b/AutomobilePlant/FormComponents.Designer.cs
@@ -0,0 +1,115 @@
+namespace AutomobilePlant
+{
+ partial class FormComponents
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(599, 540);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(661, 12);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(145, 55);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(661, 100);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(145, 52);
+ this.buttonEdit.TabIndex = 2;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(661, 186);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(145, 52);
+ this.buttonDelete.TabIndex = 3;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(661, 273);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(145, 55);
+ this.buttonUpdate.TabIndex = 4;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
+ //
+ // FormComponents
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(843, 564);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonEdit);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormComponents";
+ this.Text = "Компоненты";
+ this.Load += new System.EventHandler(this.FormComponents_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonEdit;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormComponents.cs b/AutomobilePlant/FormComponents.cs
new file mode 100644
index 0000000..f9a7d77
--- /dev/null
+++ b/AutomobilePlant/FormComponents.cs
@@ -0,0 +1,114 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormComponents : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+
+ public FormComponents(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormComponents_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ 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);
+ }
+ }
+
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
+ if (service is FormComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
+ if (service is FormComponent form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление компонента");
+ try
+ {
+ if (!_logic.Delete(new ComponentBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormComponents.resx b/AutomobilePlant/FormComponents.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AutomobilePlant/FormComponents.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormCreateOrder.Designer.cs b/AutomobilePlant/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..04f26c8
--- /dev/null
+++ b/AutomobilePlant/FormCreateOrder.Designer.cs
@@ -0,0 +1,143 @@
+namespace AutomobilePlant
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.labelSum = new System.Windows.Forms.Label();
+ this.comboBoxCar = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(30, 20);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(79, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Автомобиль:";
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(30, 70);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(93, 20);
+ this.labelCount.TabIndex = 1;
+ this.labelCount.Text = "Количество:";
+ //
+ // labelSum
+ //
+ this.labelSum.AutoSize = true;
+ this.labelSum.Location = new System.Drawing.Point(30, 119);
+ this.labelSum.Name = "labelSum";
+ this.labelSum.Size = new System.Drawing.Size(58, 20);
+ this.labelSum.TabIndex = 2;
+ this.labelSum.Text = "Сумма:";
+ //
+ // comboBoxCar
+ //
+ this.comboBoxCar.FormattingEnabled = true;
+ this.comboBoxCar.Location = new System.Drawing.Point(171, 20);
+ this.comboBoxCar.Name = "comboBoxCar";
+ this.comboBoxCar.Size = new System.Drawing.Size(262, 28);
+ this.comboBoxCar.TabIndex = 3;
+ this.comboBoxCar.SelectedIndexChanged += new System.EventHandler(this.ComboBoxCar_SelectedIndexChanged);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(171, 67);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(262, 27);
+ this.textBoxCount.TabIndex = 4;
+ this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(171, 112);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.Size = new System.Drawing.Size(262, 27);
+ this.textBoxSum.TabIndex = 5;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(239, 164);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 6;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(339, 164);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 7;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormCreateOrder
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(450, 212);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxCar);
+ this.Controls.Add(this.labelSum);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormCreateOrder";
+ this.Text = "Создание заказа";
+ this.Load += new System.EventHandler(this.FormCreateOrder_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelCount;
+ private Label labelSum;
+ private ComboBox comboBoxCar;
+ private TextBox textBoxCount;
+ private TextBox textBoxSum;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormCreateOrder.cs b/AutomobilePlant/FormCreateOrder.cs
new file mode 100644
index 0000000..4114dd4
--- /dev/null
+++ b/AutomobilePlant/FormCreateOrder.cs
@@ -0,0 +1,129 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ICarLogic _logicС;
+ private readonly IOrderLogic _logicO;
+
+ public FormCreateOrder(ILogger logger, ICarLogic logicС, IOrderLogic logicO)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicС = logicС;
+ _logicO = logicO;
+ }
+
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка автомобилей для заказа");
+ try
+ {
+ var list = _logicС.ReadList(null);
+ if (list != null)
+ {
+ comboBoxCar.DisplayMember = "CarName";
+ comboBoxCar.ValueMember = "Id";
+ comboBoxCar.DataSource = list;
+ comboBoxCar.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка автомобилей");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void CalcSum()
+ {
+ if (comboBoxCar.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxCar.SelectedValue);
+ var product = _logicС.ReadElement(new CarSearchModel
+ {
+ Id = id
+ });
+ int count = Convert.ToInt32(textBoxCount.Text);
+ textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
+ _logger.LogInformation("Расчет суммы заказа");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка расчета суммы заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void TextBoxCount_TextChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+
+ private void ComboBoxCar_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxCar.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите автомобиль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Создание заказа");
+ try
+ {
+ var operationResult = _logicO.CreateOrder(new OrderBindingModel
+ {
+ CarId = Convert.ToInt32(comboBoxCar.SelectedValue),
+ Count = Convert.ToInt32(textBoxCount.Text),
+ Sum = Convert.ToDouble(textBoxSum.Text)
+ });
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка создания заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormCreateOrder.resx b/AutomobilePlant/FormCreateOrder.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/AutomobilePlant/FormCreateOrder.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/FormMain.Designer.cs
new file mode 100644
index 0000000..8ad81b0
--- /dev/null
+++ b/AutomobilePlant/FormMain.Designer.cs
@@ -0,0 +1,176 @@
+namespace AutomobilePlant
+{
+ partial class FormMain
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #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()
+ {
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonCreateOrder = new System.Windows.Forms.Button();
+ this.buttonSetToWork = new System.Windows.Forms.Button();
+ this.buttonSetToDone = new System.Windows.Forms.Button();
+ this.buttonSetToFinish = new System.Windows.Forms.Button();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ this.menuStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // menuStrip
+ //
+ this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.справочникиToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(1176, 28);
+ this.menuStrip.TabIndex = 0;
+ this.menuStrip.Text = "Справочники";
+ //
+ // справочникиToolStripMenuItem
+ //
+ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.компонентыToolStripMenuItem,
+ this.автомобилиToolStripMenuItem});
+ this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
+ this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
+ this.справочникиToolStripMenuItem.Text = "Справочники";
+ //
+ // компонентыToolStripMenuItem
+ //
+ this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
+ this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
+ this.компонентыToolStripMenuItem.Text = "Компоненты";
+ this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click);
+ //
+ // автомобилиToolStripMenuItem
+ //
+ this.автомобилиToolStripMenuItem.Name = "автомобилиToolStripMenuItem";
+ this.автомобилиToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
+ this.автомобилиToolStripMenuItem.Text = "Автомобили";
+ this.автомобилиToolStripMenuItem.Click += new System.EventHandler(this.автомобилиToolStripMenuItem_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 31);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(942, 407);
+ this.dataGridView.TabIndex = 1;
+ //
+ // buttonCreateOrder
+ //
+ this.buttonCreateOrder.Location = new System.Drawing.Point(969, 42);
+ this.buttonCreateOrder.Name = "buttonCreateOrder";
+ this.buttonCreateOrder.Size = new System.Drawing.Size(194, 29);
+ this.buttonCreateOrder.TabIndex = 2;
+ this.buttonCreateOrder.Text = "Создать заказ";
+ this.buttonCreateOrder.UseVisualStyleBackColor = true;
+ this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
+ //
+ // buttonSetToWork
+ //
+ this.buttonSetToWork.Location = new System.Drawing.Point(969, 77);
+ this.buttonSetToWork.Name = "buttonSetToWork";
+ this.buttonSetToWork.Size = new System.Drawing.Size(194, 29);
+ this.buttonSetToWork.TabIndex = 3;
+ this.buttonSetToWork.Text = "Отдать на выполнение";
+ this.buttonSetToWork.UseVisualStyleBackColor = true;
+ this.buttonSetToWork.Click += new System.EventHandler(this.ButtonSetToWork_Click);
+ //
+ // buttonSetToDone
+ //
+ this.buttonSetToDone.Location = new System.Drawing.Point(969, 112);
+ this.buttonSetToDone.Name = "buttonSetToDone";
+ this.buttonSetToDone.Size = new System.Drawing.Size(194, 29);
+ this.buttonSetToDone.TabIndex = 4;
+ this.buttonSetToDone.Text = "Заказ готов";
+ this.buttonSetToDone.UseVisualStyleBackColor = true;
+ this.buttonSetToDone.Click += new System.EventHandler(this.ButtonSetToDone_Click);
+ //
+ // buttonSetToFinish
+ //
+ this.buttonSetToFinish.Location = new System.Drawing.Point(969, 147);
+ this.buttonSetToFinish.Name = "buttonSetToFinish";
+ this.buttonSetToFinish.Size = new System.Drawing.Size(194, 29);
+ this.buttonSetToFinish.TabIndex = 5;
+ this.buttonSetToFinish.Text = "Заказ выдан";
+ this.buttonSetToFinish.UseVisualStyleBackColor = true;
+ this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonSetToFinish_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(969, 407);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(194, 29);
+ this.buttonUpdate.TabIndex = 6;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1176, 450);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonSetToFinish);
+ this.Controls.Add(this.buttonSetToDone);
+ this.Controls.Add(this.buttonSetToWork);
+ this.Controls.Add(this.buttonCreateOrder);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
+ this.Name = "FormMain";
+ this.Text = "Автомобильный завод";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem справочникиToolStripMenuItem;
+ private ToolStripMenuItem компонентыToolStripMenuItem;
+ private ToolStripMenuItem автомобилиToolStripMenuItem;
+ private DataGridView dataGridView;
+ private Button buttonCreateOrder;
+ private Button buttonSetToWork;
+ private Button buttonSetToDone;
+ private Button buttonSetToFinish;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/FormMain.cs b/AutomobilePlant/FormMain.cs
new file mode 100644
index 0000000..02cfdf1
--- /dev/null
+++ b/AutomobilePlant/FormMain.cs
@@ -0,0 +1,167 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantDataModels.Enums;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormMain : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _orderLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ }
+
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка заказов");
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["CarId"].Visible = false;
+
+ }
+ _logger.LogInformation("Загрузка заказов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки заказов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void автомобилиToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCars));
+ if (service is FormCars 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 ButtonSetToWork_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 ButtonSetToDone_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("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ButtonSetToFinish_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("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ _logger.LogInformation("Заказ №{id} выдан", id);
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/AutomobilePlant/FormMain.resx b/AutomobilePlant/FormMain.resx
new file mode 100644
index 0000000..81a9e3d
--- /dev/null
+++ b/AutomobilePlant/FormMain.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/Program.cs b/AutomobilePlant/Program.cs
new file mode 100644
index 0000000..263d671
--- /dev/null
+++ b/AutomobilePlant/Program.cs
@@ -0,0 +1,48 @@
+using AutomobilePlantBusinessLogic.BusinessLogics;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantListImplements.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
+namespace AutomobilePlant
+{
+ internal static class Program
+ {
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
+
+ [STAThread]
+ static void Main()
+ {
+ ApplicationConfiguration.Initialize();
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+ _serviceProvider = services.BuildServiceProvider();
+
+ 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();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ }
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj b/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj
new file mode 100644
index 0000000..9a26466
--- /dev/null
+++ b/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs b/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs
new file mode 100644
index 0000000..3442776
--- /dev/null
+++ b/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs
@@ -0,0 +1,119 @@
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantBusinessLogic.BusinessLogics
+{
+ public class CarLogic : ICarLogic
+ {
+ private readonly ILogger _logger;
+ private readonly ICarStorage _carStorage;
+
+ public CarLogic(ILogger logger, ICarStorage carStorage)
+ {
+ _logger = logger;
+ _carStorage = carStorage;
+ }
+
+ public bool Create(CarBindingModel model)
+ {
+ CheckModel(model);
+ if (_carStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(CarBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_carStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(CarBindingModel model)
+ {
+ CheckModel(model);
+ if (_carStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public CarViewModel? ReadElement(CarSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. CarName:{CarName}.Id:{ Id}", model.CarName, model.Id);
+ var element = _carStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(CarSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. CarName:{CarName}.Id:{ Id}", model?.CarName, model?.Id);
+ var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ private void CheckModel(CarBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.CarName))
+ {
+ throw new ArgumentNullException("Нет названия авто", nameof(model.CarName));
+ }
+ if (model.Price <= 0)
+ {
+ throw new ArgumentNullException("Стоимость авто должна быть больше 0", nameof(model.Price));
+ }
+ _logger.LogInformation("Car. CarName:{CarName}.Price:{ Price}. Id: { Id}", model.CarName, model.Price, model.Id);
+ var element = _carStorage.GetElement(new CarSearchModel
+ {
+ CarName = model.CarName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Авто с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs b/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs
new file mode 100644
index 0000000..8f3fe23
--- /dev/null
+++ b/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs
@@ -0,0 +1,119 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantBusinessLogic.BusinessLogics
+{
+ public class ComponentLogic : IComponentLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentStorage _componentStorage;
+
+ public ComponentLogic(ILogger logger, IComponentStorage componentStorage)
+ {
+ _logger = logger;
+ _componentStorage = componentStorage;
+ }
+
+ public bool Create(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Update(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(ComponentBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_componentStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public List? ReadList(ComponentSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id);
+ var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public ComponentViewModel? ReadElement(ComponentSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id);
+ var element = _componentStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ private void CheckModel(ComponentBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
+ }
+ if (model.Cost <= 0)
+ {
+ throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
+ }
+ _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
+ var element = _componentStorage.GetElement(new ComponentSearchModel
+ {
+ ComponentName = model.ComponentName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs
new file mode 100644
index 0000000..f351853
--- /dev/null
+++ b/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -0,0 +1,139 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Enums;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantBusinessLogic.BusinessLogics
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderStorage _orderStorage;
+
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+
+ public bool CreateOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (model.Status != OrderStatus.Неизвестен)
+ {
+ _logger.LogWarning("Insert operation failed. Order status incorrect.");
+ return false;
+ }
+ model.Status = OrderStatus.Принят;
+ if (_orderStorage.Insert(model) == null)
+ {
+ model.Status = OrderStatus.Неизвестен;
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool StatusUpdate(OrderBindingModel rawModel, OrderStatus newStatus)
+ {
+ var viewModel = _orderStorage.GetElement(new OrderSearchModel
+ {
+ Id = rawModel.Id
+ });
+
+ if (viewModel == null)
+ {
+ _logger.LogWarning("Order model not found");
+ return false;
+ }
+
+ OrderBindingModel model = new OrderBindingModel
+ {
+ Id = viewModel.Id,
+ CarId = viewModel.CarId,
+ Status = viewModel.Status,
+ DateCreate = viewModel.DateCreate,
+ DateImplement = viewModel.DateImplement,
+ Count = viewModel.Count,
+ Sum = viewModel.Sum
+ };
+
+ CheckModel(model, false);
+ if (model.Status + 1 != newStatus)
+ {
+ _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
+ return false;
+ }
+ model.Status = newStatus;
+ if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
+ if (_orderStorage.Update(model) == null)
+ {
+ model.Status--;
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выполняется);
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Готов);
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выдан);
+ }
+
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _logger.LogInformation("Order. OrderID:{Id}", model?.Id);
+ var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.CarId < 0)
+ {
+ throw new ArgumentNullException("Некорректный идентификатор авто", nameof(model.CarId));
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException("Количество авто в заказе должно быть больше 0", nameof(model.Count));
+ }
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
+ }
+ _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. CarId: { CarId}", model.Id, model.Sum, model.CarId);
+ }
+ }
+}
diff --git a/AutomobilePlantContracts/AutomobilePlantContracts.csproj b/AutomobilePlantContracts/AutomobilePlantContracts.csproj
new file mode 100644
index 0000000..743e9bf
--- /dev/null
+++ b/AutomobilePlantContracts/AutomobilePlantContracts.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/AutomobilePlantContracts/BindingModels/CarBindingModel.cs b/AutomobilePlantContracts/BindingModels/CarBindingModel.cs
new file mode 100644
index 0000000..b8170a5
--- /dev/null
+++ b/AutomobilePlantContracts/BindingModels/CarBindingModel.cs
@@ -0,0 +1,17 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BindingModels
+{
+ public class CarBindingModel : ICarModel
+ {
+ public int Id { get; set; }
+ public string CarName { get; set; } = string.Empty;
+ public double Price { get; set; }
+ public Dictionary CarComponents { get; set; } = new();
+ }
+}
diff --git a/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs b/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs
new file mode 100644
index 0000000..1ebc60b
--- /dev/null
+++ b/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs
@@ -0,0 +1,17 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BindingModels
+{
+ public class ComponentBindingModel : IComponentModel
+ {
+ public int Id { get; set; }
+ public string ComponentName { get; set; } = string.Empty;
+ public double Cost { get; set; }
+
+ }
+}
diff --git a/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..a0e90ae
--- /dev/null
+++ b/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,21 @@
+using AutomobilePlantDataModels.Enums;
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BindingModels
+{
+ public class OrderBindingModel : IOrderModel
+ {
+ public int Id { get; set; }
+ public int CarId { get; set; }
+ public int Count { get; set; }
+ public double Sum { get; set; }
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/AutomobilePlantContracts/BusinessLogicContracts/ICarLogic.cs b/AutomobilePlantContracts/BusinessLogicContracts/ICarLogic.cs
new file mode 100644
index 0000000..af898de
--- /dev/null
+++ b/AutomobilePlantContracts/BusinessLogicContracts/ICarLogic.cs
@@ -0,0 +1,20 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BusinessLogicContracts
+{
+ public interface ICarLogic
+ {
+ List? ReadList(CarSearchModel? model);
+ CarViewModel? ReadElement(CarSearchModel model);
+ bool Create(CarBindingModel model);
+ bool Update(CarBindingModel model);
+ bool Delete(CarBindingModel model);
+ }
+}
diff --git a/AutomobilePlantContracts/BusinessLogicContracts/IComponentLogic.cs b/AutomobilePlantContracts/BusinessLogicContracts/IComponentLogic.cs
new file mode 100644
index 0000000..8b1ccff
--- /dev/null
+++ b/AutomobilePlantContracts/BusinessLogicContracts/IComponentLogic.cs
@@ -0,0 +1,20 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BusinessLogicContracts
+{
+ public interface IComponentLogic
+ {
+ List? ReadList(ComponentSearchModel? model);
+ ComponentViewModel? ReadElement(ComponentSearchModel model);
+ bool Create(ComponentBindingModel model);
+ bool Update(ComponentBindingModel model);
+ bool Delete(ComponentBindingModel model);
+ }
+}
diff --git a/AutomobilePlantContracts/BusinessLogicContracts/IOrderLogic.cs b/AutomobilePlantContracts/BusinessLogicContracts/IOrderLogic.cs
new file mode 100644
index 0000000..c5bc886
--- /dev/null
+++ b/AutomobilePlantContracts/BusinessLogicContracts/IOrderLogic.cs
@@ -0,0 +1,20 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BusinessLogicContracts
+{
+ public interface IOrderLogic
+ {
+ List? ReadList(OrderSearchModel? model);
+ bool CreateOrder(OrderBindingModel model);
+ bool TakeOrderInWork(OrderBindingModel model);
+ bool FinishOrder(OrderBindingModel model);
+ bool DeliveryOrder(OrderBindingModel model);
+ }
+}
diff --git a/AutomobilePlantContracts/SearchModels/CarSearchModel.cs b/AutomobilePlantContracts/SearchModels/CarSearchModel.cs
new file mode 100644
index 0000000..8994576
--- /dev/null
+++ b/AutomobilePlantContracts/SearchModels/CarSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.SearchModels
+{
+ public class CarSearchModel
+ {
+ public int? Id { get; set; }
+ public string? CarName { get; set; }
+ }
+}
diff --git a/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs b/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs
new file mode 100644
index 0000000..f158a80
--- /dev/null
+++ b/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.SearchModels
+{
+ public class ComponentSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ComponentName { get; set; }
+ }
+}
diff --git a/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs b/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..afbc5f1
--- /dev/null
+++ b/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.SearchModels
+{
+ public class OrderSearchModel
+ {
+ public int? Id { get; set; }
+ }
+}
diff --git a/AutomobilePlantContracts/StorageContracts/ICarStorage.cs b/AutomobilePlantContracts/StorageContracts/ICarStorage.cs
new file mode 100644
index 0000000..0e64ae4
--- /dev/null
+++ b/AutomobilePlantContracts/StorageContracts/ICarStorage.cs
@@ -0,0 +1,21 @@
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.BindingModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.StorageContracts
+{
+ public interface ICarStorage
+ {
+ List GetFullList();
+ List GetFilteredList(CarSearchModel model);
+ CarViewModel? GetElement(CarSearchModel model);
+ CarViewModel? Insert(CarBindingModel model);
+ CarViewModel? Update(CarBindingModel model);
+ CarViewModel? Delete(CarBindingModel model);
+ }
+}
diff --git a/AutomobilePlantContracts/StorageContracts/IComponentStorage.cs b/AutomobilePlantContracts/StorageContracts/IComponentStorage.cs
new file mode 100644
index 0000000..d024fbd
--- /dev/null
+++ b/AutomobilePlantContracts/StorageContracts/IComponentStorage.cs
@@ -0,0 +1,21 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.StorageContracts
+{
+ public interface IComponentStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ComponentSearchModel model);
+ ComponentViewModel? GetElement(ComponentSearchModel model);
+ ComponentViewModel? Insert(ComponentBindingModel model);
+ ComponentViewModel? Update(ComponentBindingModel model);
+ ComponentViewModel? Delete(ComponentBindingModel model);
+ }
+}
diff --git a/AutomobilePlantContracts/StorageContracts/IOrderStorage.cs b/AutomobilePlantContracts/StorageContracts/IOrderStorage.cs
new file mode 100644
index 0000000..321979f
--- /dev/null
+++ b/AutomobilePlantContracts/StorageContracts/IOrderStorage.cs
@@ -0,0 +1,21 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.StorageContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/AutomobilePlantContracts/ViewModels/CarViewModel.cs b/AutomobilePlantContracts/ViewModels/CarViewModel.cs
new file mode 100644
index 0000000..c095358
--- /dev/null
+++ b/AutomobilePlantContracts/ViewModels/CarViewModel.cs
@@ -0,0 +1,20 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.ViewModels
+{
+ public class CarViewModel : ICarModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название машины")]
+ public string CarName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Price { get; set; }
+ public Dictionary CarComponents { get; set; } = new();
+ }
+}
diff --git a/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs b/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs
new file mode 100644
index 0000000..92d581d
--- /dev/null
+++ b/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs
@@ -0,0 +1,19 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.ViewModels
+{
+ public class ComponentViewModel : IComponentModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название компонента")]
+ public string ComponentName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Cost { get; set; }
+ }
+}
diff --git a/AutomobilePlantContracts/ViewModels/OrderViewModel.cs b/AutomobilePlantContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..adcff73
--- /dev/null
+++ b/AutomobilePlantContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,30 @@
+using AutomobilePlantDataModels.Enums;
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.ViewModels
+{
+ public class OrderViewModel : IOrderModel
+ {
+ public int CarId { get; set; }
+ [DisplayName("Номер")]
+ public int Id { get; set; }
+ [DisplayName("Машина")]
+ public string CarName { 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; }
+ }
+}
diff --git a/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj b/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj
new file mode 100644
index 0000000..132c02c
--- /dev/null
+++ b/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/AutomobilePlantDataModels/Enums/OrderStatus.cs b/AutomobilePlantDataModels/Enums/OrderStatus.cs
new file mode 100644
index 0000000..9f6907e
--- /dev/null
+++ b/AutomobilePlantDataModels/Enums/OrderStatus.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantDataModels.Enums
+{
+ public enum OrderStatus
+ {
+ Неизвестен = -1,
+ Принят = 0,
+ Выполняется = 1,
+ Готов = 2,
+ Выдан = 3,
+ }
+}
diff --git a/AutomobilePlantDataModels/IID.cs b/AutomobilePlantDataModels/IID.cs
new file mode 100644
index 0000000..e2268d5
--- /dev/null
+++ b/AutomobilePlantDataModels/IID.cs
@@ -0,0 +1,7 @@
+namespace AutomobilePlantDataModels
+{
+ public interface IId
+ {
+ int Id { get; }
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlantDataModels/Models/ICarModel.cs b/AutomobilePlantDataModels/Models/ICarModel.cs
new file mode 100644
index 0000000..53e8864
--- /dev/null
+++ b/AutomobilePlantDataModels/Models/ICarModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantDataModels.Models
+{
+ public interface ICarModel : IId
+ {
+ string CarName { get; }
+ double Price { get; }
+ Dictionary CarComponents { get; }
+ }
+}
diff --git a/AutomobilePlantDataModels/Models/IComponentModel.cs b/AutomobilePlantDataModels/Models/IComponentModel.cs
new file mode 100644
index 0000000..65039ce
--- /dev/null
+++ b/AutomobilePlantDataModels/Models/IComponentModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantDataModels.Models
+{
+ public interface IComponentModel : IId
+ {
+ string ComponentName { get; }
+ double Cost { get; }
+ }
+}
diff --git a/AutomobilePlantDataModels/Models/IOrderModel.cs b/AutomobilePlantDataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..3eec2ef
--- /dev/null
+++ b/AutomobilePlantDataModels/Models/IOrderModel.cs
@@ -0,0 +1,20 @@
+using AutomobilePlantDataModels.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantDataModels.Models
+{
+ public interface IOrderModel : IId
+ {
+ int CarId { get; }
+ int Count { get; }
+ double Sum { get; }
+ OrderStatus Status { get; }
+ DateTime DateCreate { get; }
+ DateTime? DateImplement { get; }
+ }
+}
diff --git a/AutomobilePlantListImplements/AutomobilePlantListImplements.csproj b/AutomobilePlantListImplements/AutomobilePlantListImplements.csproj
new file mode 100644
index 0000000..a6820c2
--- /dev/null
+++ b/AutomobilePlantListImplements/AutomobilePlantListImplements.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/AutomobilePlantListImplements/DataListSingleton.cs b/AutomobilePlantListImplements/DataListSingleton.cs
new file mode 100644
index 0000000..d18f01f
--- /dev/null
+++ b/AutomobilePlantListImplements/DataListSingleton.cs
@@ -0,0 +1,26 @@
+using AutomobilePlantListImplements.Models;
+
+namespace AutomobilePlantListImplements
+{
+ public class DataListSingleton
+ {
+ private static DataListSingleton? _instance;
+ public List Components { get; set; }
+ public List Orders { get; set; }
+ public List Cars { get; set; }
+ private DataListSingleton()
+ {
+ Components = new List();
+ Orders = new List();
+ Cars = new List();
+ }
+ public static DataListSingleton GetInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new DataListSingleton();
+ }
+ return _instance;
+ }
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlantListImplements/Implements/CarStorage.cs b/AutomobilePlantListImplements/Implements/CarStorage.cs
new file mode 100644
index 0000000..ade393d
--- /dev/null
+++ b/AutomobilePlantListImplements/Implements/CarStorage.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection.Metadata;
+using System.Text;
+using System.Threading.Tasks;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantListImplements.Models;
+
+namespace AutomobilePlantListImplements.Implements
+{
+ public class CarStorage : ICarStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public CarStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public CarViewModel? GetElement(CarSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var car in _source.Cars)
+ {
+ if ((!string.IsNullOrEmpty(model.CarName) && car.CarName == model.CarName) || (model.Id.HasValue && car.Id == model.Id))
+ {
+ return car.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public List GetFilteredList(CarSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.CarName))
+ {
+ return result;
+ }
+ foreach (var car in _source.Cars)
+ {
+ if (car.CarName.Contains(model.CarName))
+ {
+ result.Add(car.GetViewModel);
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var car in _source.Cars)
+ {
+ result.Add(car.GetViewModel);
+ }
+ return result;
+ }
+
+ public CarViewModel? Insert(CarBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var car in _source.Cars)
+ {
+ if (model.Id <= car.Id)
+ {
+ model.Id = car.Id + 1;
+ }
+ }
+ var newCar = Car.Create(model);
+ if (newCar == null)
+ {
+ return null;
+ }
+ _source.Cars.Add(newCar);
+ return newCar.GetViewModel;
+ }
+
+ public CarViewModel? Update(CarBindingModel model)
+ {
+ foreach (var car in _source.Cars)
+ {
+ if (car.Id == model.Id)
+ {
+ car.Update(model);
+ return car.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public CarViewModel? Delete(CarBindingModel model)
+ {
+ for (int i = 0; i < _source.Cars.Count; ++i)
+ {
+ if (_source.Cars[i].Id == model.Id)
+ {
+ var element = _source.Cars[i];
+ _source.Cars.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/AutomobilePlantListImplements/Implements/ComponentStorage.cs b/AutomobilePlantListImplements/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..f458863
--- /dev/null
+++ b/AutomobilePlantListImplements/Implements/ComponentStorage.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantListImplements.Models;
+
+
+namespace AutomobilePlantListImplements.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public ComponentStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var component in _source.Components)
+ {
+ result.Add(component.GetViewModel);
+ }
+ return result;
+ }
+
+ public List GetFilteredList(ComponentSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return result;
+ }
+ foreach (var component in _source.Components)
+ {
+ if (component.ComponentName.Contains(model.ComponentName))
+ {
+ result.Add(component.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var component in _source.Components)
+ {
+ if ((!string.IsNullOrEmpty(model.ComponentName) &&
+ component.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && component.Id == model.Id))
+ {
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var component in _source.Components)
+ {
+ if (model.Id <= component.Id)
+ {
+ model.Id = component.Id + 1;
+ }
+ }
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ _source.Components.Add(newComponent);
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ foreach (var component in _source.Components)
+ {
+ if (component.Id == model.Id)
+ {
+ component.Update(model);
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ for (int i = 0; i < _source.Components.Count; ++i)
+ {
+ if (_source.Components[i].Id == model.Id)
+ {
+ var element = _source.Components[i];
+ _source.Components.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/AutomobilePlantListImplements/Implements/OrderStorage.cs b/AutomobilePlantListImplements/Implements/OrderStorage.cs
new file mode 100644
index 0000000..a999087
--- /dev/null
+++ b/AutomobilePlantListImplements/Implements/OrderStorage.cs
@@ -0,0 +1,126 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantListImplements.Models;
+
+namespace AutomobilePlantListImplements.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public OrderStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id.HasValue && order.Id == model.Id)
+ {
+ return GetViewModel(order);
+ }
+ }
+ return null;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+ if (!model.Id.HasValue)
+ {
+ return result;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ result.Add(GetViewModel(order));
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var order in _source.Orders)
+ {
+ result.Add(GetViewModel(order));
+ }
+ return result;
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id <= order.Id)
+ {
+ model.Id = order.Id + 1;
+ }
+ }
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ _source.Orders.Add(newOrder);
+ return GetViewModel(newOrder);
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ return GetViewModel(order);
+ }
+ }
+ return null;
+ }
+
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ for (int i = 0; i < _source.Orders.Count; ++i)
+ {
+ if (_source.Orders[i].Id == model.Id)
+ {
+ var element = _source.Orders[i];
+ _source.Orders.RemoveAt(i);
+ return GetViewModel(element);
+ }
+ }
+ return null;
+ }
+
+ private OrderViewModel GetViewModel(Order order)
+ {
+ var viewModel = order.GetViewModel;
+ foreach (var car in _source.Cars)
+ {
+ if (car.Id == order.CarId)
+ {
+ viewModel.CarName = car.CarName;
+ break;
+ }
+ }
+ return viewModel;
+ }
+ }
+}
diff --git a/AutomobilePlantListImplements/Models/Car.cs b/AutomobilePlantListImplements/Models/Car.cs
new file mode 100644
index 0000000..6b8e677
--- /dev/null
+++ b/AutomobilePlantListImplements/Models/Car.cs
@@ -0,0 +1,57 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection.Metadata;
+using System.Text;
+using System.Threading.Tasks;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.ViewModels;
+
+namespace AutomobilePlantListImplements.Models
+{
+ public class Car : ICarModel
+ {
+ public string CarName { get; private set; } = string.Empty;
+
+ public double Price { get; private set; }
+
+ public Dictionary CarComponents { get; private set; } = new Dictionary();
+
+ public int Id { get; private set; }
+
+ public static Car? Create(CarBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Car()
+ {
+ Id = model.Id,
+ CarName = model.CarName,
+ Price = model.Price,
+ CarComponents = model.CarComponents
+ };
+ }
+
+ public void Update(CarBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ CarName = model.CarName;
+ Price = model.Price;
+ CarComponents = model.CarComponents;
+ }
+
+ public CarViewModel GetViewModel => new()
+ {
+ Id = Id,
+ CarName = CarName,
+ Price = Price,
+ CarComponents = CarComponents
+ };
+ }
+}
diff --git a/AutomobilePlantListImplements/Models/Component.cs b/AutomobilePlantListImplements/Models/Component.cs
new file mode 100644
index 0000000..84f1876
--- /dev/null
+++ b/AutomobilePlantListImplements/Models/Component.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Models;
+
+namespace AutomobilePlantListImplements.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+ public static Component? Create(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public void Update(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ }
+}
diff --git a/AutomobilePlantListImplements/Models/Order.cs b/AutomobilePlantListImplements/Models/Order.cs
new file mode 100644
index 0000000..c39798a
--- /dev/null
+++ b/AutomobilePlantListImplements/Models/Order.cs
@@ -0,0 +1,68 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Enums;
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantListImplements.Models
+{
+ public class Order : IOrderModel
+ {
+ public int CarId { get; private set; }
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order
+ {
+ CarId = model.CarId,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement,
+ Id = model.Id,
+ };
+ }
+
+ public void Update(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Status = model.Status;
+ DateImplement = model.DateImplement;
+ }
+
+ public OrderViewModel GetViewModel => new()
+ {
+ CarId = CarId,
+ Count = Count,
+ Sum = Sum,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement,
+ Id = Id,
+ Status = Status,
+ };
+ }
+}