From cedda578eab3dc227583301b39b1ffcf8cf0ab09 Mon Sep 17 00:00:00 2001 From: Arklightning Date: Wed, 8 Feb 2023 02:53:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=9B=D0=A01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarRepairShop/CarRepairShop.sln | 29 ++- .../CarRepairShop/CarRepairShop.csproj | 11 + .../CarRepairShop/FormCar.Designer.cs | 200 ++++++++++++++++ CarRepairShop/CarRepairShop/FormCar.cs | 215 ++++++++++++++++++ CarRepairShop/CarRepairShop/FormCar.resx | 78 +++++++ .../CarRepairShop/FormCarDetail.Designer.cs | 117 ++++++++++ CarRepairShop/CarRepairShop/FormCarDetail.cs | 89 ++++++++ .../CarRepairShop/FormCarDetail.resx | 60 +++++ .../CarRepairShop/FormCars.Designer.cs | 109 +++++++++ CarRepairShop/CarRepairShop/FormCars.cs | 114 ++++++++++ CarRepairShop/CarRepairShop/FormCars.resx | 60 +++++ .../CarRepairShop/FormCreateOrder.Designer.cs | 139 +++++++++++ .../CarRepairShop/FormCreateOrder.cs | 127 +++++++++++ .../CarRepairShop/FormCreateOrder.resx | 60 +++++ .../CarRepairShop/FormMain.Designer.cs | 28 +-- CarRepairShop/CarRepairShop/FormMain.cs | 12 +- CarRepairShop/CarRepairShop/Program.cs | 43 +++- .../BusinessLogic/CarLogic.cs | 113 +++++++++ .../BusinessLogic/DetailLogic.cs | 113 +++++++++ .../BusinessLogic/OrderLogic.cs | 111 +++++++++ .../CarRepairShopBisinessLogic.csproj | 19 ++ .../BindingModels/CarBindingModel.cs | 18 ++ .../BindingModels/DetailBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../BusinessLogicsContracts/ICarLogic.cs | 20 ++ .../BusinessLogicsContracts/IDetailLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../CarRepairShopContracts.csproj | 13 ++ .../SearchModels/CarSearchModel.cs | 14 ++ .../SearchModels/DetailSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 ++ .../StoragesContracts/ICarStorages.cs | 21 ++ .../StoragesContracts/IDetailStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../ViewModels/CarViewModel.cs | 20 ++ .../ViewModels/DetailViewModel.cs | 19 ++ .../ViewModels/OrderViewModel.cs | 30 +++ .../CarRepairShopDataModels.csproj | 9 + .../Enums/OrderStatus.cs | 17 ++ CarRepairShop/CarRepairShopDataModels/IId.cs | 13 ++ .../Models/ICarModel.cs | 15 ++ .../Models/IDetailModel.cs | 14 ++ .../Models/IOrderModel.cs | 19 ++ .../CarRepairShopListImplement.csproj | 14 ++ .../DataListSingleton.cs | 26 +++ .../Implements/CarStorage.cs | 107 +++++++++ .../Implements/DetailStorage.cs | 110 +++++++++ .../Implements/OrderStorage.cs | 106 +++++++++ .../CarRepairShopListImplement/Models/Car.cs | 52 +++++ .../Models/Detail.cs | 48 ++++ .../Models/Order.cs | 73 ++++++ 51 files changed, 2750 insertions(+), 22 deletions(-) create mode 100644 CarRepairShop/CarRepairShop/FormCar.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormCar.cs create mode 100644 CarRepairShop/CarRepairShop/FormCar.resx create mode 100644 CarRepairShop/CarRepairShop/FormCarDetail.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormCarDetail.cs create mode 100644 CarRepairShop/CarRepairShop/FormCarDetail.resx create mode 100644 CarRepairShop/CarRepairShop/FormCars.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormCars.cs create mode 100644 CarRepairShop/CarRepairShop/FormCars.resx create mode 100644 CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormCreateOrder.cs create mode 100644 CarRepairShop/CarRepairShop/FormCreateOrder.resx create mode 100644 CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/CarLogic.cs create mode 100644 CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/DetailLogic.cs create mode 100644 CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 CarRepairShop/CarRepairShopBisinessLogic/CarRepairShopBisinessLogic.csproj create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/CarBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/DetailBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/ICarLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IDetailLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/CarSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/DetailSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/ICarStorages.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IDetailStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/CarViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/DetailViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj create mode 100644 CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/IId.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/ICarModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/IDetailModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj create mode 100644 CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/CarStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/DetailStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Car.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Detail.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Order.cs diff --git a/CarRepairShop/CarRepairShop.sln b/CarRepairShop/CarRepairShop.sln index 61a05eb..b548a85 100644 --- a/CarRepairShop/CarRepairShop.sln +++ b/CarRepairShop/CarRepairShop.sln @@ -3,7 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShop", "CarRepairShop\CarRepairShop.csproj", "{59651A2B-2304-453C-B67E-91EF8353B196}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShop", "CarRepairShop\CarRepairShop.csproj", "{59651A2B-2304-453C-B67E-91EF8353B196}" + ProjectSection(ProjectDependencies) = postProject + {853143CB-5B00-49BC-ADF2-557269EB2235} = {853143CB-5B00-49BC-ADF2-557269EB2235} + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopDataModels", "CarRepairShopDataModels\CarRepairShopDataModels.csproj", "{85B7EA38-8F19-4199-B83A-B3128A145E3F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopBisinessLogic", "CarRepairShopBisinessLogic\CarRepairShopBisinessLogic.csproj", "{853143CB-5B00-49BC-ADF2-557269EB2235}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopContracts", "CarRepairShopContracts\CarRepairShopContracts.csproj", "{CE6A6A6F-A0D3-428F-B70F-E73695DD2C91}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopListImplement", "CarRepairShopListImplement\CarRepairShopListImplement.csproj", "{7A19A758-A68B-4B08-8F70-62D42A777926}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +26,22 @@ Global {59651A2B-2304-453C-B67E-91EF8353B196}.Debug|Any CPU.Build.0 = Debug|Any CPU {59651A2B-2304-453C-B67E-91EF8353B196}.Release|Any CPU.ActiveCfg = Release|Any CPU {59651A2B-2304-453C-B67E-91EF8353B196}.Release|Any CPU.Build.0 = Release|Any CPU + {85B7EA38-8F19-4199-B83A-B3128A145E3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85B7EA38-8F19-4199-B83A-B3128A145E3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85B7EA38-8F19-4199-B83A-B3128A145E3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85B7EA38-8F19-4199-B83A-B3128A145E3F}.Release|Any CPU.Build.0 = Release|Any CPU + {853143CB-5B00-49BC-ADF2-557269EB2235}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {853143CB-5B00-49BC-ADF2-557269EB2235}.Debug|Any CPU.Build.0 = Debug|Any CPU + {853143CB-5B00-49BC-ADF2-557269EB2235}.Release|Any CPU.ActiveCfg = Release|Any CPU + {853143CB-5B00-49BC-ADF2-557269EB2235}.Release|Any CPU.Build.0 = Release|Any CPU + {CE6A6A6F-A0D3-428F-B70F-E73695DD2C91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE6A6A6F-A0D3-428F-B70F-E73695DD2C91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE6A6A6F-A0D3-428F-B70F-E73695DD2C91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE6A6A6F-A0D3-428F-B70F-E73695DD2C91}.Release|Any CPU.Build.0 = Release|Any CPU + {7A19A758-A68B-4B08-8F70-62D42A777926}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A19A758-A68B-4B08-8F70-62D42A777926}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A19A758-A68B-4B08-8F70-62D42A777926}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A19A758-A68B-4B08-8F70-62D42A777926}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarRepairShop/CarRepairShop/CarRepairShop.csproj b/CarRepairShop/CarRepairShop/CarRepairShop.csproj index b57c89e..464829f 100644 --- a/CarRepairShop/CarRepairShop/CarRepairShop.csproj +++ b/CarRepairShop/CarRepairShop/CarRepairShop.csproj @@ -8,4 +8,15 @@ enable + + + + + + + + + + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormCar.Designer.cs b/CarRepairShop/CarRepairShop/FormCar.Designer.cs new file mode 100644 index 0000000..35ec40b --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCar.Designer.cs @@ -0,0 +1,200 @@ +namespace CarRepairShop +{ + 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Деталь = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Количество = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(10, 7); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(38, 15); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(10, 33); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(38, 15); + this.label2.TabIndex = 1; + this.label2.Text = "label2"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(90, 4); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(235, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(90, 29); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(139, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.ButtonRef); + this.groupBox1.Controls.Add(this.ButtonDel); + this.groupBox1.Controls.Add(this.ButtonUpd); + this.groupBox1.Controls.Add(this.ButtonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(10, 54); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(679, 232); + this.groupBox1.TabIndex = 4; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Детали"; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.Деталь, + this.Количество}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(475, 208); + 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; + // + // Деталь + // + this.Деталь.HeaderText = "Деталь"; + this.Деталь.MinimumWidth = 6; + this.Деталь.Name = "Деталь"; + this.Деталь.Width = 306; + // + // Количество + // + this.Количество.HeaderText = "Количество"; + this.Количество.MinimumWidth = 6; + this.Количество.Name = "Количество"; + this.Количество.Width = 125; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(538, 20); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(106, 38); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(538, 69); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(106, 38); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(538, 121); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(106, 38); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(538, 175); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(106, 38); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + // + // FormCar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormCar"; + this.Text = "FormCar"; + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn Деталь; + private DataGridViewTextBoxColumn Количество; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormCar.cs b/CarRepairShop/CarRepairShop/FormCar.cs new file mode 100644 index 0000000..e9bcf03 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCar.cs @@ -0,0 +1,215 @@ +using Microsoft.Extensions.Logging; +using CarRepairShop; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopDataModels.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 CarRepairShop +{ + public partial class FormCar : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + private int? _id; + private Dictionary _carDetails; + public int Id { set { _id = value; } } + public FormCar(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _carDetails = 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(); + _carDetails = view.CarDetails ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка деталей изделия"); + try + { + if (_carDetails != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _carDetails) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.DetailName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + 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(FormCarDetail)); + if (service is FormCarDetail form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.DetailModel == null) + { + return; + } + _logger.LogInformation("Добавление нового детали:{ DetailName} - { Count}", form.DetailModel.DetailName, form.Count); + if (_carDetails.ContainsKey(form.Id)) + { + _carDetails[form.Id] = (form.DetailModel, form.Count); + } + else + { + _carDetails.Add(form.Id, (form.DetailModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCarDetail)); + if (service is FormCarDetail form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _carDetails[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.DetailModel == null) + { + return; + } + _logger.LogInformation("Изменение детали: { DetailName} - { Count}", form.DetailModel.DetailName, form.Count); + _carDetails[form.Id] = (form.DetailModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление детали:{ DetailName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _carDetails?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_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 (_carDetails == null || _carDetails.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), + CarDetails = _carDetails + }; + 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(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _carDetails) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormCar.resx b/CarRepairShop/CarRepairShop/FormCar.resx new file mode 100644 index 0000000..9405c8d --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCar.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormCarDetail.Designer.cs b/CarRepairShop/CarRepairShop/FormCarDetail.Designer.cs new file mode 100644 index 0000000..091d553 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCarDetail.Designer.cs @@ -0,0 +1,117 @@ +namespace CarRepairShop +{ + partial class FormCarDetail + { + /// + /// 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.labelDetail = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxDetail = 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(); + // + // labelDetail + // + this.labelDetail.AutoSize = true; + this.labelDetail.Location = new System.Drawing.Point(10, 14); + this.labelDetail.Name = "labelDetail"; + this.labelDetail.Size = new System.Drawing.Size(45, 15); + this.labelDetail.TabIndex = 0; + this.labelDetail.Text = "Деталь"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 42); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество"; + // + // comboBoxDetail + // + this.comboBoxDetail.FormattingEnabled = true; + this.comboBoxDetail.Location = new System.Drawing.Point(98, 12); + this.comboBoxDetail.Name = "comboBoxDetail"; + this.comboBoxDetail.Size = new System.Drawing.Size(221, 23); + this.comboBoxDetail.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(98, 40); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(221, 23); + this.textBoxCount.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(141, 87); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(82, 22); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(236, 87); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(82, 22); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // FormCarDetail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(329, 118); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDetail); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelDetail); + this.Name = "FormCarDetail"; + this.Text = "Деталь машины"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelDetail; + private Label labelCount; + private ComboBox comboBoxDetail; + private TextBox textBoxCount; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormCarDetail.cs b/CarRepairShop/CarRepairShop/FormCarDetail.cs new file mode 100644 index 0000000..f7e00fa --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCarDetail.cs @@ -0,0 +1,89 @@ +using Microsoft.VisualBasic.Logging; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.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 CarRepairShop +{ + public partial class FormCarDetail : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxDetail.SelectedValue); + } + set + { + comboBoxDetail.SelectedValue = value; + } + } + public IDetailModel? DetailModel + { + 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 FormCarDetail(IDetailLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxDetail.DisplayMember = "DetailName"; + comboBoxDetail.ValueMember = "Id"; + comboBoxDetail.DataSource = _list; + comboBoxDetail.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDetail.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/CarRepairShop/CarRepairShop/FormCarDetail.resx b/CarRepairShop/CarRepairShop/FormCarDetail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCarDetail.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/CarRepairShop/CarRepairShop/FormCars.Designer.cs b/CarRepairShop/CarRepairShop/FormCars.Designer.cs new file mode 100644 index 0000000..888ba58 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCars.Designer.cs @@ -0,0 +1,109 @@ +namespace CarRepairShop +{ + 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.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = 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(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(549, 338); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(566, 34); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(123, 32); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(566, 92); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(123, 32); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(566, 146); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(123, 32); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(566, 202); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(123, 32); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormCars"; + this.Text = "Машины"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormCars.cs b/CarRepairShop/CarRepairShop/FormCars.cs new file mode 100644 index 0000000..5e032a4 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCars.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using CarRepairShop; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +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 CarRepairShop +{ + 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["CarDetails"].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 ButtonUpd_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 ButtonDel_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 ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormCars.resx b/CarRepairShop/CarRepairShop/FormCars.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarRepairShop/CarRepairShop/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/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs b/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..50b2bf0 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs @@ -0,0 +1,139 @@ +namespace CarRepairShop +{ + 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.ComboBoxCars = new System.Windows.Forms.ComboBox(); + this.labelCar = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + 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(); + // + // ComboBoxCars + // + this.ComboBoxCars.FormattingEnabled = true; + this.ComboBoxCars.Location = new System.Drawing.Point(120, 14); + this.ComboBoxCars.Name = "ComboBoxCars"; + this.ComboBoxCars.Size = new System.Drawing.Size(258, 23); + this.ComboBoxCars.TabIndex = 0; + // + // labelCar + // + this.labelCar.AutoSize = true; + this.labelCar.Location = new System.Drawing.Point(29, 20); + this.labelCar.Name = "labelCar"; + this.labelCar.Size = new System.Drawing.Size(53, 15); + this.labelCar.TabIndex = 1; + this.labelCar.Text = "Изделие"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(29, 52); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(29, 86); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(45, 15); + this.labelPrice.TabIndex = 3; + this.labelPrice.Text = "Сумма"; + // + // TextBoxCount + // + this.TextBoxCount.Location = new System.Drawing.Point(120, 46); + this.TextBoxCount.Name = "TextBoxCount"; + this.TextBoxCount.Size = new System.Drawing.Size(258, 23); + this.TextBoxCount.TabIndex = 4; + // + // TextBoxSum + // + this.TextBoxSum.Location = new System.Drawing.Point(120, 81); + this.TextBoxSum.Name = "TextBoxSum"; + this.TextBoxSum.Size = new System.Drawing.Size(258, 23); + this.TextBoxSum.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(218, 116); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(82, 22); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(318, 116); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(82, 22); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(410, 145); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.TextBoxSum); + this.Controls.Add(this.TextBoxCount); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelCar); + this.Controls.Add(this.ComboBoxCars); + this.Name = "FormCreateOrder"; + this.Text = "Создание заказа"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox ComboBoxCars; + private Label labelCar; + private Label labelCount; + private Label labelPrice; + private TextBox TextBoxCount; + private TextBox TextBoxSum; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormCreateOrder.cs b/CarRepairShop/CarRepairShop/FormCreateOrder.cs new file mode 100644 index 0000000..c70bd37 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.cs @@ -0,0 +1,127 @@ +using Microsoft.Extensions.Logging; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +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 CarRepairShop +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logicS; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ICarLogic logicS, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicS = logicS; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + ComboBoxCars.DisplayMember = "CarName"; + ComboBoxCars.ValueMember = "Id"; + ComboBoxCars.DataSource = list; + ComboBoxCars.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка кораблей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (ComboBoxCars.SelectedValue != null && + !string.IsNullOrEmpty(TextBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(ComboBoxCars.SelectedValue); + var product = _logicS.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 ComboBoxCars_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 (ComboBoxCars.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + CarId = Convert.ToInt32(ComboBoxCars.SelectedValue), + CarName = ComboBoxCars.Text, + 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/CarRepairShop/CarRepairShop/FormCreateOrder.resx b/CarRepairShop/CarRepairShop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.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/CarRepairShop/CarRepairShop/FormMain.Designer.cs b/CarRepairShop/CarRepairShop/FormMain.Designer.cs index 80b38e8..91c34eb 100644 --- a/CarRepairShop/CarRepairShop/FormMain.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormMain.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.dataGridView = new System.Windows.Forms.DataGridView(); this.ButtonCreateOrder = new System.Windows.Forms.Button(); this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); this.ButtonOrderReady = new System.Windows.Forms.Button(); @@ -38,18 +38,18 @@ this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ДеталиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.МашиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // - // dataGridView1 + // dataGridView // - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Location = new System.Drawing.Point(0, 24); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowTemplate.Height = 25; - this.dataGridView1.Size = new System.Drawing.Size(816, 332); - this.dataGridView1.TabIndex = 0; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 24); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(816, 332); + this.dataGridView.TabIndex = 0; // // ButtonCreateOrder // @@ -118,13 +118,13 @@ // ДеталиToolStripMenuItem // this.ДеталиToolStripMenuItem.Name = "ДеталиToolStripMenuItem"; - this.ДеталиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ДеталиToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.ДеталиToolStripMenuItem.Text = "Детали"; // // МашиныToolStripMenuItem // this.МашиныToolStripMenuItem.Name = "МашиныToolStripMenuItem"; - this.МашиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.МашиныToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.МашиныToolStripMenuItem.Text = "Машины"; // // FormMain @@ -137,12 +137,12 @@ this.Controls.Add(this.ButtonOrderReady); this.Controls.Add(this.ButtonTakeOrderInWork); this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "FormMain"; this.Text = "Автомастерская"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); @@ -152,7 +152,7 @@ #endregion - private DataGridView dataGridView1; + private DataGridView dataGridView; private Button ButtonCreateOrder; private Button ButtonTakeOrderInWork; private Button ButtonOrderReady; diff --git a/CarRepairShop/CarRepairShop/FormMain.cs b/CarRepairShop/CarRepairShop/FormMain.cs index c8d8a60..52c2f17 100644 --- a/CarRepairShop/CarRepairShop/FormMain.cs +++ b/CarRepairShop/CarRepairShop/FormMain.cs @@ -40,7 +40,7 @@ namespace CarRepairShop if (list != null) { dataGridView.DataSource = list; - dataGridView.Columns["ShipId"].Visible = false; + dataGridView.Columns["CarId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -62,8 +62,8 @@ namespace CarRepairShop private void КораблиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShips)); - if (service is FormShips form) + var service = Program.ServiceProvider?.GetService(typeof(FormCars)); + if (service is FormCars form) { form.ShowDialog(); } @@ -87,7 +87,7 @@ namespace CarRepairShop _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].Value), CarName = dataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -111,7 +111,7 @@ namespace CarRepairShop _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].Value), CarName = dataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); @@ -134,7 +134,7 @@ namespace CarRepairShop _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].Value), CarName = dataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/CarRepairShop/CarRepairShop/Program.cs b/CarRepairShop/CarRepairShop/Program.cs index 957c7ea..3ff9771 100644 --- a/CarRepairShop/CarRepairShop/Program.cs +++ b/CarRepairShop/CarRepairShop/Program.cs @@ -1,7 +1,20 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using CarRepairShopBusinessLogic.BusinessLogics; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopListImplement.Implements; +using CarRepairShop; +using System.Drawing; +using CarRepairShopBisinessLogic.BusinessLogic; + namespace CarRepairShop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +24,35 @@ namespace CarRepairShop // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + 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/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/CarLogic.cs b/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/CarLogic.cs new file mode 100644 index 0000000..efd01f1 --- /dev/null +++ b/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/CarLogic.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class CarLogic : ICarLogic + { + private readonly ILogger _logger; + private readonly ICarStorage _carStorage; + public CarLogic(ILogger logger, ICarStorage carStorage) + { + _logger = logger; + _carStorage = carStorage; + } + 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; + } + 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 bool Create(CarBindingModel model) + { + CheckModel(model); + if (_carStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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 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; + } + 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/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/DetailLogic.cs b/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/DetailLogic.cs new file mode 100644 index 0000000..843a145 --- /dev/null +++ b/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/DetailLogic.cs @@ -0,0 +1,113 @@ +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBisinessLogic.BusinessLogic +{ + public class DetailLogic : IDetailLogic + { + private readonly ILogger _logger; + private readonly IDetailStorage _detailStorage; + public DetailLogic(ILogger logger, IDetailStorage detailStorage) + { + _logger = logger; + _detailStorage = detailStorage; + } + public List? ReadList(DetailSearchModel? model) + { + _logger.LogInformation("ReadList. DetailName:{DetailName}. Id:{Id}", model?.DetailName, model?.Id); + var list = model == null ? _detailStorage.GetFullList() : _detailStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DetailViewModel? ReadElement(DetailSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DetailName:{DetailName}. Id:{ Id}", model.DetailName, model.Id); + var element = _detailStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(DetailBindingModel model) + { + CheckModel(model); + if (_detailStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DetailBindingModel model) + { + CheckModel(model); + if (_detailStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DetailBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_detailStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DetailBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.DetailName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.DetailName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Detail. DetailName:{DetailName}. Cost:{ Cost}. Id: { Id}", model.DetailName, model.Cost, model.Id); + var element = _detailStorage.GetElement(new DetailSearchModel + { + DetailName = model.DetailName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/OrderLogic.cs b/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..6f807e2 --- /dev/null +++ b/CarRepairShop/CarRepairShopBisinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{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; + } + 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) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + 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); + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + 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.Готов); + } + } +} diff --git a/CarRepairShop/CarRepairShopBisinessLogic/CarRepairShopBisinessLogic.csproj b/CarRepairShop/CarRepairShopBisinessLogic/CarRepairShopBisinessLogic.csproj new file mode 100644 index 0000000..37f7015 --- /dev/null +++ b/CarRepairShop/CarRepairShopBisinessLogic/CarRepairShopBisinessLogic.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/CarBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/CarBindingModel.cs new file mode 100644 index 0000000..85a3c35 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/CarBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CarRepairShopDataModels.Models; + +namespace CarRepairShopContracts.BindingModels +{ + public class CarBindingModel : ICarModel + { + public int Id { get; set; } + public string CarName { get; set; } = String.Empty; + public double Price { get; set; } + public Dictionary CarDetails { get; set; } = new(); + + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/DetailBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/DetailBindingModel.cs new file mode 100644 index 0000000..af2ec10 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/DetailBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CarRepairShopDataModels.Models; + +namespace CarRepairShopContracts.BindingModels +{ + public class DetailBindingModel : IDetailModel + { + public int Id { get; set; } + public string DetailName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..a442aed --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CarRepairShopDataModels.Models; +using CarRepairShopDataModels.Enums; + +namespace CarRepairShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int CarId { get; set; } + public string CarName { 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/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/ICarLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/ICarLogic.cs new file mode 100644 index 0000000..08ab4b6 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/ICarLogic.cs @@ -0,0 +1,20 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + 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/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IDetailLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IDetailLogic.cs new file mode 100644 index 0000000..b8331d6 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IDetailLogic.cs @@ -0,0 +1,20 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IDetailLogic + { + List? ReadList(DetailSearchModel? model); + DetailViewModel? ReadElement(DetailSearchModel model); + bool Create(DetailBindingModel model); + bool Update(DetailBindingModel model); + bool Delete(DetailBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..01d0b4b --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + 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/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj b/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj new file mode 100644 index 0000000..215400f --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/CarSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/CarSearchModel.cs new file mode 100644 index 0000000..c008169 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/CarSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class CarSearchModel + { + public int? Id { get; set; } + public string? CarName { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/DetailSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/DetailSearchModel.cs new file mode 100644 index 0000000..c363a50 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/DetailSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class DetailSearchModel + { + public int? Id { get; set; } + public string? DetailName { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..1344f19 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/ICarStorages.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/ICarStorages.cs new file mode 100644 index 0000000..dfc1b39 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/ICarStorages.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + 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/CarRepairShop/CarRepairShopContracts/StoragesContracts/IDetailStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IDetailStorage.cs new file mode 100644 index 0000000..753819e --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IDetailStorage.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IDetailStorage + { + List GetFullList(); + List GetFilteredList(DetailSearchModel model); + DetailViewModel? GetElement(DetailSearchModel model); + DetailViewModel? Insert(DetailBindingModel model); + DetailViewModel? Update(DetailBindingModel model); + DetailViewModel? Delete(DetailBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..8fe2230 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + 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/CarRepairShop/CarRepairShopContracts/ViewModels/CarViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/CarViewModel.cs new file mode 100644 index 0000000..2e9c4f7 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/CarViewModel.cs @@ -0,0 +1,20 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.ViewModels +{ + public class CarViewModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string CarName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary CarDetails { get; set; } = new(); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/DetailViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/DetailViewModel.cs new file mode 100644 index 0000000..2da5260 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/DetailViewModel.cs @@ -0,0 +1,19 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.ViewModels +{ + public class DetailViewModel : IDetailModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string DetailName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..8b65d69 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.ViewModels +{ + public class OrderViewModel:IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int CarId { 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/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj b/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs b/CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..fce8e78 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/IId.cs b/CarRepairShop/CarRepairShopDataModels/IId.cs new file mode 100644 index 0000000..0276204 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/ICarModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/ICarModel.cs new file mode 100644 index 0000000..ecbaeb2 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/ICarModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Models +{ + public interface ICarModel : IId + { + string CarName { get; } + double Price { get; } + Dictionary CarDetails { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IDetailModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IDetailModel.cs new file mode 100644 index 0000000..a32bc8f --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IDetailModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Models +{ + public interface IDetailModel : IId + { + string DetailName { get; } + double Cost { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..1eec31a --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using CarRepairShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.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/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj b/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj new file mode 100644 index 0000000..e49be3f --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..6f9135e --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using CarRepairShopListImplement.Models; + +namespace CarRepairShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Details { get; set; } + public List Orders { get; set; } + public List Cars { get; set; } + private DataListSingleton() + { + Details = 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/CarRepairShop/CarRepairShopListImplement/Implements/CarStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/CarStorage.cs new file mode 100644 index 0000000..daf52c9 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/CarStorage.cs @@ -0,0 +1,107 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + public class CarStorage : ICarStorage + { + private readonly DataListSingleton _source; + public CarStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var car in _source.Cars) + { + result.Add(car.GetViewModel); + } + return result; + } + 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 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 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/CarRepairShop/CarRepairShopListImplement/Implements/DetailStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/DetailStorage.cs new file mode 100644 index 0000000..d8ca01e --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/DetailStorage.cs @@ -0,0 +1,110 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; +using CarRepairShopListImplement; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + public class DetailStorage : IDetailStorage + { + private readonly DataListSingleton _source; + public DetailStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var detail in _source.Details) + { + result.Add(detail.GetViewModel); + } + return result; + } + public List GetFilteredList(DetailSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.DetailName)) + { + return result; + } + foreach (var detail in _source.Details) + { + if (detail.DetailName.Contains(model.DetailName)) + { + result.Add(detail.GetViewModel); + } + } + return result; + } + public DetailViewModel? GetElement(DetailSearchModel model) + { + if (string.IsNullOrEmpty(model.DetailName) && !model.Id.HasValue) + { + return null; + } + foreach (var detail in _source.Details) + { + if ((!string.IsNullOrEmpty(model.DetailName) && + detail.DetailName == model.DetailName) || + (model.Id.HasValue && detail.Id == model.Id)) + { + return detail.GetViewModel; + } + } + return null; + } + public DetailViewModel? Insert(DetailBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Details) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newDetail = Detail.Create(model); + if (newDetail == null) + { + return null; + } + _source.Details.Add(newDetail); + return newDetail.GetViewModel; + } + public DetailViewModel? Update(DetailBindingModel model) + { + foreach (var detail in _source.Details) + { + if (detail.Id == model.Id) + { + detail.Update(model); + return detail.GetViewModel; + } + } + return null; + } + public DetailViewModel? Delete(DetailBindingModel model) + { + for (int i = 0; i < _source.Details.Count; ++i) + { + if (_source.Details[i].Id == model.Id) + { + var element = _source.Details[i]; + _source.Details.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..9c153c3 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,106 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; +using CarRepairShopListImplement; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + 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(order.GetViewModel); + } + } + return result; + } + 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 order.GetViewModel; + } + } + return null; + } + 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 newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + 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 element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Car.cs b/CarRepairShop/CarRepairShopListImplement/Models/Car.cs new file mode 100644 index 0000000..54c1839 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Car.cs @@ -0,0 +1,52 @@ +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using CarRepairShopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.ConstrainedExecution; + +namespace CarRepairShopListImplement.Models +{ + public class Car : ICarModel + { + public int Id { get; private set; } + public string CarName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary CarDetails { get; private set; } = new Dictionary(); + public static Car? Create(CarBindingModel? model) + { + if (model == null) + { + return null; + } + return new Car() + { + Id = model.Id, + CarName = model.CarName, + Price = model.Price, + CarDetails = model.CarDetails + }; + } + public void Update(CarBindingModel? model) + { + if (model == null) + { + return; + } + CarName = model.CarName; + Price = model.Price; + CarDetails = model.CarDetails; + } + public CarViewModel GetViewModel => new() + { + Id = Id, + CarName = CarName, + Price = Price, + CarDetails = CarDetails + }; + + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Detail.cs b/CarRepairShop/CarRepairShopListImplement/Models/Detail.cs new file mode 100644 index 0000000..8fd099d --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Detail.cs @@ -0,0 +1,48 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Models +{ + public class Detail : IDetailModel + { + public int Id { get; private set; } + public string DetailName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Detail? Create(DetailBindingModel? model) + { + if (model == null) + { + return null; + } + return new Detail() + { + Id = model.Id, + DetailName = model.DetailName, + Cost = model.Cost + }; + } + public void Update(DetailBindingModel? model) + { + if (model == null) + { + return; + } + DetailName = model.DetailName; + Cost = model.Cost; + } + public DetailViewModel GetViewModel => new() + { + Id = Id, + DetailName = DetailName, + Cost = Cost + }; + + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Order.cs b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs new file mode 100644 index 0000000..ce7b133 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs @@ -0,0 +1,73 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels.Models; + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int CarId { get; private set; } + public string CarName { 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 static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + CarId = model.CarId, + CarName = model.CarName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + CarId = model.CarId; + CarName = model.CarName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + CarId = CarId, + CarName = CarName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + } +} \ No newline at end of file