From 81f4829e145b5460b780b4f5da99b461830e9e11 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Fri, 9 Feb 2024 22:08:31 +0400 Subject: [PATCH 1/8] =?UTF-8?q?Lab1=20=D0=BD=D0=B5=20=D0=B4=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarRepairShop/CarRepairShop.sln | 26 +++- .../CarRepairShop/CarRepairShop.csproj | 9 ++ CarRepairShop/CarRepairShop/Form1.Designer.cs | 39 ------ CarRepairShop/CarRepairShop/Form1.cs | 10 -- .../CarRepairShop/FormComponent.Designer.cs | 118 ++++++++++++++++ CarRepairShop/CarRepairShop/FormComponent.cs | 90 +++++++++++++ .../{Form1.resx => FormComponent.resx} | 50 +++---- .../CarRepairShop/FormComponents.Designer.cs | 115 ++++++++++++++++ CarRepairShop/CarRepairShop/FormComponents.cs | 115 ++++++++++++++++ .../CarRepairShop/FormComponents.resx | 120 +++++++++++++++++ .../CarRepairShop/FormRepair.Designer.cs | 119 +++++++++++++++++ CarRepairShop/CarRepairShop/FormRepair.cs | 20 +++ CarRepairShop/CarRepairShop/FormRepair.resx | 126 ++++++++++++++++++ .../FormRepairComponent.Designer.cs | 116 ++++++++++++++++ .../CarRepairShop/FormRepairComponent.cs | 74 ++++++++++ .../CarRepairShop/FormRepairComponent.resx | 120 +++++++++++++++++ CarRepairShop/CarRepairShop/Program.cs | 39 +++++- .../CarRepairShopBusinessLogic.csproj | 17 +++ .../ComponentLogic.cs | 109 +++++++++++++++ .../CarRepairShopBusinessLogic/OrderLogic.cs | 105 +++++++++++++++ .../CarRepairShopBusinessLogic/RepairLogic.cs | 113 ++++++++++++++++ .../BindingModels/ComponentBindingModel.cs | 11 ++ .../BindingModels/OrderBindingModel.cs | 16 +++ .../BindingModels/RepairBindingModel.cs | 12 ++ .../IComponentLogic.cs | 15 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 16 +++ .../BusinessLogicsContracts/IRepairLogic.cs | 15 +++ .../CarRepairShopContracts.csproj | 13 ++ .../SearchModels/ComponentSearchModel.cs | 8 ++ .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/RepairSearchModel.cs | 8 ++ .../StoragesContracts/IComponentStorage.cs | 17 +++ .../StoragesContracts/IOrderStorage.cs | 17 +++ .../StoragesContracts/IRepairStorage.cs | 17 +++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/OrderViewModel.cs | 26 ++++ .../ViewModels/RepairViewModel.cs | 15 +++ .../CarRepairShopDataModels.csproj | 9 ++ .../IComponentModel.cs | 8 ++ CarRepairShop/CarRepairShopDataModels/IId.cs | 7 + .../CarRepairShopDataModels/IOrderModel.cs | 15 +++ .../CarRepairShopDataModels/IRepairModel.cs | 10 ++ .../CarRepairShopDataModels/OrderStatus.cs | 11 ++ .../CarRepairShopListImplement.csproj | 14 ++ .../DataListSingleton.cs | 26 ++++ .../Implements/ComponentStorage.cs | 102 ++++++++++++++ .../Implements/OrderStorage.cs | 113 ++++++++++++++++ .../Implements/RepairStorage.cs | 102 ++++++++++++++ .../Models/Component.cs | 41 ++++++ .../Models/Order.cs | 54 ++++++++ .../Models/Repair.cs | 49 +++++++ 51 files changed, 2360 insertions(+), 78 deletions(-) delete mode 100644 CarRepairShop/CarRepairShop/Form1.Designer.cs delete mode 100644 CarRepairShop/CarRepairShop/Form1.cs create mode 100644 CarRepairShop/CarRepairShop/FormComponent.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormComponent.cs rename CarRepairShop/CarRepairShop/{Form1.resx => FormComponent.resx} (93%) create mode 100644 CarRepairShop/CarRepairShop/FormComponents.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormComponents.cs create mode 100644 CarRepairShop/CarRepairShop/FormComponents.resx create mode 100644 CarRepairShop/CarRepairShop/FormRepair.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormRepair.cs create mode 100644 CarRepairShop/CarRepairShop/FormRepair.resx create mode 100644 CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormRepairComponent.cs create mode 100644 CarRepairShop/CarRepairShop/FormRepairComponent.resx create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj create mode 100644 CarRepairShop/CarRepairShopDataModels/IComponentModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/IId.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/IOrderModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/IRepairModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/OrderStatus.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj create mode 100644 CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Component.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Order.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Repair.cs diff --git a/CarRepairShop/CarRepairShop.sln b/CarRepairShop/CarRepairShop.sln index 3a9a4b7..a7c5942 100644 --- a/CarRepairShop/CarRepairShop.sln +++ b/CarRepairShop/CarRepairShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34221.43 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShop", "CarRepairShop\CarRepairShop.csproj", "{5FEF443C-F2C8-4CD9-843D-0DFD94B66CD2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShop", "CarRepairShop\CarRepairShop.csproj", "{5FEF443C-F2C8-4CD9-843D-0DFD94B66CD2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopDataModels", "CarRepairShopDataModels\CarRepairShopDataModels.csproj", "{A30B704D-BB52-4073-B3FB-A43B214FB730}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopContracts", "CarRepairShopContracts\CarRepairShopContracts.csproj", "{FA47DABA-C657-4049-B02A-6AB850A6D29E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopBusinessLogic", "CarRepairShopBusinessLogic\CarRepairShopBusinessLogic.csproj", "{550ABD23-557C-41F3-97DF-DCA974DC2C91}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopListImplement", "CarRepairShopListImplement\CarRepairShopListImplement.csproj", "{687C5C03-1B68-494D-8006-12862232D229}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {5FEF443C-F2C8-4CD9-843D-0DFD94B66CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {5FEF443C-F2C8-4CD9-843D-0DFD94B66CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU {5FEF443C-F2C8-4CD9-843D-0DFD94B66CD2}.Release|Any CPU.Build.0 = Release|Any CPU + {A30B704D-BB52-4073-B3FB-A43B214FB730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A30B704D-BB52-4073-B3FB-A43B214FB730}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A30B704D-BB52-4073-B3FB-A43B214FB730}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A30B704D-BB52-4073-B3FB-A43B214FB730}.Release|Any CPU.Build.0 = Release|Any CPU + {FA47DABA-C657-4049-B02A-6AB850A6D29E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA47DABA-C657-4049-B02A-6AB850A6D29E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA47DABA-C657-4049-B02A-6AB850A6D29E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA47DABA-C657-4049-B02A-6AB850A6D29E}.Release|Any CPU.Build.0 = Release|Any CPU + {550ABD23-557C-41F3-97DF-DCA974DC2C91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {550ABD23-557C-41F3-97DF-DCA974DC2C91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {550ABD23-557C-41F3-97DF-DCA974DC2C91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {550ABD23-557C-41F3-97DF-DCA974DC2C91}.Release|Any CPU.Build.0 = Release|Any CPU + {687C5C03-1B68-494D-8006-12862232D229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {687C5C03-1B68-494D-8006-12862232D229}.Debug|Any CPU.Build.0 = Debug|Any CPU + {687C5C03-1B68-494D-8006-12862232D229}.Release|Any CPU.ActiveCfg = Release|Any CPU + {687C5C03-1B68-494D-8006-12862232D229}.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..7aa279b 100644 --- a/CarRepairShop/CarRepairShop/CarRepairShop.csproj +++ b/CarRepairShop/CarRepairShop/CarRepairShop.csproj @@ -8,4 +8,13 @@ enable + + + + + + + + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Form1.Designer.cs b/CarRepairShop/CarRepairShop/Form1.Designer.cs deleted file mode 100644 index 9e59291..0000000 --- a/CarRepairShop/CarRepairShop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CarRepairShop -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Form1.cs b/CarRepairShop/CarRepairShop/Form1.cs deleted file mode 100644 index a8a4d35..0000000 --- a/CarRepairShop/CarRepairShop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CarRepairShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormComponent.Designer.cs b/CarRepairShop/CarRepairShop/FormComponent.Designer.cs new file mode 100644 index 0000000..8157a96 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace CarRepairShop +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(24, 19); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(24, 71); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(48, 20); + labelCost.TabIndex = 1; + labelCost.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(110, 19); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(366, 27); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(110, 71); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(257, 27); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(273, 119); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(382, 119); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(490, 165); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + Text = "Компонент"; + Click += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormComponent.cs b/CarRepairShop/CarRepairShop/FormComponent.cs new file mode 100644 index 0000000..25dd99c --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormComponent.cs @@ -0,0 +1,90 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace CarRepairShop +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Form1.resx b/CarRepairShop/CarRepairShop/FormComponent.resx similarity index 93% rename from CarRepairShop/CarRepairShop/Form1.resx rename to CarRepairShop/CarRepairShop/FormComponent.resx index 1af7de1..af32865 100644 --- a/CarRepairShop/CarRepairShop/Form1.resx +++ b/CarRepairShop/CarRepairShop/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/CarRepairShop/CarRepairShop/FormComponents.Designer.cs b/CarRepairShop/CarRepairShop/FormComponents.Designer.cs new file mode 100644 index 0000000..5c53dc6 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace CarRepairShop +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(593, 450); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(641, 27); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(120, 39); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(641, 87); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(120, 39); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(641, 150); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(120, 39); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(641, 210); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(120, 39); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Click += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormComponents.cs b/CarRepairShop/CarRepairShop/FormComponents.cs new file mode 100644 index 0000000..e50d691 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormComponents.cs @@ -0,0 +1,115 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShop +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void 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 ComponentBindingModel + { + 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/FormComponents.resx b/CarRepairShop/CarRepairShop/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs new file mode 100644 index 0000000..72fe267 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs @@ -0,0 +1,119 @@ +namespace CarRepairShop +{ + partial class FormRepair + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + groupBox1 = new GroupBox(); + dataGridView1 = new DataGridView(); + Component = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(25, 18); + label1.Name = "label1"; + label1.Size = new Size(50, 20); + label1.TabIndex = 0; + label1.Text = "label1"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(25, 58); + label2.Name = "label2"; + label2.Size = new Size(50, 20); + label2.TabIndex = 1; + label2.Text = "label2"; + // + // groupBox1 + // + groupBox1.Controls.Add(dataGridView1); + groupBox1.Location = new Point(12, 97); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(776, 303); + groupBox1.TabIndex = 2; + groupBox1.TabStop = false; + groupBox1.Text = "groupBox1"; + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Component, Count }); + dataGridView1.Location = new Point(13, 23); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.RowTemplate.Height = 29; + dataGridView1.Size = new Size(570, 274); + dataGridView1.TabIndex = 0; + // + // Component + // + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + Component.Width = 370; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.Width = 200; + // + // FormRepair + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(groupBox1); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormRepair"; + Text = "FormRepair"; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private GroupBox groupBox1; + private DataGridView dataGridView1; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepair.cs b/CarRepairShop/CarRepairShop/FormRepair.cs new file mode 100644 index 0000000..4e30c0a --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepair.cs @@ -0,0 +1,20 @@ +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 FormRepair : Form + { + public FormRepair() + { + InitializeComponent(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormRepair.resx b/CarRepairShop/CarRepairShop/FormRepair.resx new file mode 100644 index 0000000..1206194 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepair.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs new file mode 100644 index 0000000..4281b74 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs @@ -0,0 +1,116 @@ +namespace CarRepairShop +{ + partial class FormRepairComponent + { + /// + /// 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() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(20, 23); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(91, 20); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(20, 70); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(124, 23); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(301, 28); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(124, 70); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(301, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(231, 118); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + // + // buttonCancel + // + buttonCancel.Location = new Point(331, 118); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormRepairComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(439, 160); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormRepairComponent"; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.cs b/CarRepairShop/CarRepairShop/FormRepairComponent.cs new file mode 100644 index 0000000..89063b7 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.cs @@ -0,0 +1,74 @@ +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; + +namespace CarRepairShop +{ + public partial class FormRepairComponent : Form + { + private readonly List? _list; + public int Id + { + get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } + set { comboBoxComponent.SelectedValue = value; } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormRepairComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.resx b/CarRepairShop/CarRepairShop/FormRepairComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Program.cs b/CarRepairShop/CarRepairShop/Program.cs index 957c7ea..ab5a301 100644 --- a/CarRepairShop/CarRepairShop/Program.cs +++ b/CarRepairShop/CarRepairShop/Program.cs @@ -1,17 +1,50 @@ +using CarRepairShopBusinessLogic; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + namespace CarRepairShop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj b/CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj new file mode 100644 index 0000000..fc431b7 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..880be09 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs @@ -0,0 +1,109 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBusinessLogic +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..c00d197 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs @@ -0,0 +1,105 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBusinessLogic +{ + 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.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); + } + } +} diff --git a/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs new file mode 100644 index 0000000..96aace7 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs @@ -0,0 +1,113 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBusinessLogic +{ + public class RepairLogic : IRepairLogic + { + private readonly ILogger _logger; + private readonly IRepairStorage _repairStorage; + public RepairLogic(ILogger logger, IRepairStorage repairStorage) + { + _logger = logger; + _repairStorage = repairStorage; + } + + public List? ReadList(RepairSearchModel? model) + { + _logger.LogInformation("ReadList. RepairName:{RepairName}. Id:{ Id}", model?.RepairName, model?.Id); + var list = model == null ? _repairStorage.GetFullList() : + _repairStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public RepairViewModel? ReadElement(RepairSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. RepairName:{RepairName}.Id:{ Id}", model.RepairName, model.Id); + var element = _repairStorage.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(RepairBindingModel model) + { + CheckModel(model); + if (_repairStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(RepairBindingModel model) + { + CheckModel(model); + if (_repairStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(RepairBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_repairStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(RepairBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.RepairName)) + { + throw new ArgumentNullException("Нет названия мороженного", + nameof(model.RepairName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена мороженного должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Repair. Repair:{Repair}. Price:{ Price }. Id: { Id}", model.RepairName, model.Price, model.Id); + var element = _repairStorage.GetElement(new RepairSearchModel + { + RepairName = model.RepairName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..0cef747 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using CarRepairShopDataModels.Models; + +namespace CarRepairShopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..9f23e56 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels; + +namespace CarRepairShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int RepairId { 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/BindingModels/RepairBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs new file mode 100644 index 0000000..19d47a7 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs @@ -0,0 +1,12 @@ +using CarRepairShopDataModels.Models; + +namespace CarRepairShopContracts.BindingModels +{ + public class RepairBindingModel : IRepairModel + { + public int Id { get; set; } + public string RepairName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary RepairComponents { get; set; } = new(); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..f95958a --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..b0de48a --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,16 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +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/BusinessLogicsContracts/IRepairLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs new file mode 100644 index 0000000..20d2eec --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs @@ -0,0 +1,15 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IRepairLogic + { + List? ReadList(RepairSearchModel? model); + RepairViewModel? ReadElement(RepairSearchModel model); + bool Create(RepairBindingModel model); + bool Update(RepairBindingModel model); + bool Delete(RepairBindingModel 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/ComponentSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..bcd5cb6 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace CarRepairShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..a7ebe6a --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace CarRepairShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs new file mode 100644 index 0000000..7f3af09 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs @@ -0,0 +1,8 @@ +namespace CarRepairShopContracts.SearchModels +{ + public class RepairSearchModel + { + public int? Id { get; set; } + public string? RepairName { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..79ecace --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..cf129ee --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,17 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +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/StoragesContracts/IRepairStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs new file mode 100644 index 0000000..eafdef5 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs @@ -0,0 +1,17 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IRepairStorage + { + List GetFullList(); + List GetFilteredList(RepairSearchModel model); + RepairViewModel? GetElement(RepairSearchModel model); + RepairViewModel? Insert(RepairBindingModel model); + RepairViewModel? Update(RepairBindingModel model); + RepairViewModel? Delete(RepairBindingModel model); + + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..7958153 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using CarRepairShopDataModels.Models; +using System.ComponentModel; + +namespace CarRepairShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..9ea4e89 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,26 @@ +using CarRepairShopDataModels; +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels.Models; +using System.ComponentModel; + +namespace CarRepairShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int RepairId { get; set; } + [DisplayName("Изделие")] + public string RepairName { 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/CarRepairShopContracts/ViewModels/RepairViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs new file mode 100644 index 0000000..8a26f48 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs @@ -0,0 +1,15 @@ +using CarRepairShopDataModels.Models; +using System.ComponentModel; + +namespace CarRepairShopContracts.ViewModels +{ + public class RepairViewModel : IRepairModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string RepairName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary RepairComponents { get; set; } = new(); + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj b/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/CarRepairShop/CarRepairShopDataModels/IComponentModel.cs b/CarRepairShop/CarRepairShopDataModels/IComponentModel.cs new file mode 100644 index 0000000..05fc0fd --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace CarRepairShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/IId.cs b/CarRepairShop/CarRepairShopDataModels/IId.cs new file mode 100644 index 0000000..7798cff --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace CarRepairShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs b/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs new file mode 100644 index 0000000..484696d --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs @@ -0,0 +1,15 @@ +using CarRepairShopDataModels.Enums; + +namespace CarRepairShopDataModels +{ + public interface IOrderModel + { + int RepairId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/IRepairModel.cs b/CarRepairShop/CarRepairShopDataModels/IRepairModel.cs new file mode 100644 index 0000000..2a46953 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IRepairModel.cs @@ -0,0 +1,10 @@ +namespace CarRepairShopDataModels.Models +{ + public interface IRepairModel : IId + { + string RepairName { get; } + double Price { get; } + Dictionary RepairComponents { get; } + + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/OrderStatus.cs b/CarRepairShop/CarRepairShopDataModels/OrderStatus.cs new file mode 100644 index 0000000..76fcb27 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace CarRepairShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file 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..d2f576d --- /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 Components { get; set; } + public List Orders { get; set; } + public List Repairs { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Repairs = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..5d1be57 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopListImplement.Models; + +namespace CarRepairShopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..e666ec7 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,113 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; + +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(AccessIceCreamStorage(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(AccessIceCreamStorage(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; + } + + public OrderViewModel AccessIceCreamStorage(OrderViewModel model) + { + foreach (var repair in _source.Repairs) + { + if (repair.Id == model.RepairId) + { + model.RepairName = repair.RepairName; + break; + } + } + return model; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs new file mode 100644 index 0000000..9fce0dc --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs @@ -0,0 +1,102 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; + +namespace CarRepairShopListImplement.Implements +{ + public class RepairStorage : IRepairStorage + { + private readonly DataListSingleton _source; + public RepairStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var repair in _source.Repairs) + { + result.Add(repair.GetViewModel); + } + return result; + } + public List GetFilteredList(RepairSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.RepairName)) + { + return result; + } + foreach (var repair in _source.Repairs) + { + if (repair.RepairName.Contains(model.RepairName)) + { + result.Add(repair.GetViewModel); + } + } + return result; + } + public RepairViewModel? GetElement(RepairSearchModel model) + { + if (string.IsNullOrEmpty(model.RepairName) && !model.Id.HasValue) + { + return null; + } + foreach (var repair in _source.Repairs) + { + if ((!string.IsNullOrEmpty(model.RepairName) && + repair.RepairName == model.RepairName) || + (model.Id.HasValue && repair.Id == model.Id)) + { + return repair.GetViewModel; + } + } + return null; + } + public RepairViewModel? Insert(RepairBindingModel model) + { + model.Id = 1; + foreach (var repair in _source.Repairs) + { + if (model.Id <= repair.Id) + { + model.Id = repair.Id + 1; + } + } + var newRepair = Repair.Create(model); + if (newRepair == null) + { + return null; + } + _source.Repairs.Add(newRepair); + return newRepair.GetViewModel; + } + public RepairViewModel? Update(RepairBindingModel model) + { + foreach (var repair in _source.Repairs) + { + if (repair.Id == model.Id) + { + repair.Update(model); + return repair.GetViewModel; + } + } + return null; + } + public RepairViewModel? Delete(RepairBindingModel model) + { + for (int i = 0; i < _source.Repairs.Count; ++i) + { + if (_source.Repairs[i].Id == model.Id) + { + var element = _source.Repairs[i]; + _source.Repairs.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Component.cs b/CarRepairShop/CarRepairShopListImplement/Models/Component.cs new file mode 100644 index 0000000..36db3db --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; + +namespace CarRepairShopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Order.cs b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs new file mode 100644 index 0000000..74962bc --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs @@ -0,0 +1,54 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels; +using CarRepairShopDataModels.Enums; + +namespace CarRepairShopListImplement.Models +{ + public class Order : IOrderModel + { + public int RepairId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + RepairId = model.RepairId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + RepairId = RepairId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Repair.cs b/CarRepairShop/CarRepairShopListImplement/Models/Repair.cs new file mode 100644 index 0000000..666fd7a --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Repair.cs @@ -0,0 +1,49 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; + +namespace CarRepairShopListImplement.Models +{ + public class Repair : IRepairModel + { + public int Id { get; private set; } + public string RepairName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary RepairComponents + { + get; + private set; + } = new Dictionary(); + public static Repair? Create(RepairBindingModel? model) + { + if (model == null) + { + return null; + } + return new Repair() + { + Id = model.Id, + RepairName = model.RepairName, + Price = model.Price, + RepairComponents = model.RepairComponents + }; + } + public void Update(RepairBindingModel? model) + { + if (model == null) + { + return; + } + RepairName = model.RepairName; + Price = model.Price; + RepairComponents = model.RepairComponents; + } + public RepairViewModel GetViewModel => new() + { + Id = Id, + RepairName = RepairName, + Price = Price, + RepairComponents = RepairComponents + }; + } +} -- 2.25.1 From 9d47e1d3a0f29a39355a96934360a3e7206934e9 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sun, 11 Feb 2024 01:25:10 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BC=D0=B5=D0=BB=D0=BE=D1=87=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShop/CarRepairShop.csproj | 6 + .../CarRepairShop/FormComponent.Designer.cs | 3 +- .../CarRepairShop/FormComponents.Designer.cs | 3 +- .../CarRepairShop/FormCreateOrder.Designer.cs | 148 ++++++++++++ .../CarRepairShop/FormCreateOrder.cs | 121 ++++++++++ .../CarRepairShop/FormCreateOrder.resx | 120 ++++++++++ .../CarRepairShop/FormMain.Designer.cs | 175 ++++++++++++++ CarRepairShop/CarRepairShop/FormMain.cs | 153 ++++++++++++ CarRepairShop/CarRepairShop/FormMain.resx | 123 ++++++++++ .../CarRepairShop/FormRepair.Designer.cs | 223 +++++++++++++----- CarRepairShop/CarRepairShop/FormRepair.cs | 216 ++++++++++++++++- CarRepairShop/CarRepairShop/FormRepair.resx | 4 +- .../FormRepairComponent.Designer.cs | 3 + .../CarRepairShop/FormRepairComponent.cs | 4 +- .../CarRepairShop/FormRepairs.Designer.cs | 116 +++++++++ CarRepairShop/CarRepairShop/FormRepairs.cs | 106 +++++++++ CarRepairShop/CarRepairShop/FormRepairs.resx | 120 ++++++++++ CarRepairShop/CarRepairShop/Program.cs | 7 +- 18 files changed, 1571 insertions(+), 80 deletions(-) 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/CarRepairShop/FormMain.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormMain.cs create mode 100644 CarRepairShop/CarRepairShop/FormMain.resx create mode 100644 CarRepairShop/CarRepairShop/FormRepairs.Designer.cs create mode 100644 CarRepairShop/CarRepairShop/FormRepairs.cs create mode 100644 CarRepairShop/CarRepairShop/FormRepairs.resx diff --git a/CarRepairShop/CarRepairShop/CarRepairShop.csproj b/CarRepairShop/CarRepairShop/CarRepairShop.csproj index 7aa279b..7fff8d0 100644 --- a/CarRepairShop/CarRepairShop/CarRepairShop.csproj +++ b/CarRepairShop/CarRepairShop/CarRepairShop.csproj @@ -17,4 +17,10 @@ + + + + + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormComponent.Designer.cs b/CarRepairShop/CarRepairShop/FormComponent.Designer.cs index 8157a96..2ca1162 100644 --- a/CarRepairShop/CarRepairShop/FormComponent.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormComponent.Designer.cs @@ -100,8 +100,9 @@ Controls.Add(labelCost); Controls.Add(labelName); Name = "FormComponent"; + StartPosition = FormStartPosition.CenterScreen; Text = "Компонент"; - Click += FormComponent_Load; + Load += FormComponent_Load; ResumeLayout(false); PerformLayout(); } diff --git a/CarRepairShop/CarRepairShop/FormComponents.Designer.cs b/CarRepairShop/CarRepairShop/FormComponents.Designer.cs index 5c53dc6..9825bc9 100644 --- a/CarRepairShop/CarRepairShop/FormComponents.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormComponents.Designer.cs @@ -98,8 +98,9 @@ Controls.Add(buttonAdd); Controls.Add(dataGridView); Name = "FormComponents"; + StartPosition = FormStartPosition.CenterScreen; Text = "Компоненты"; - Click += FormComponents_Load; + Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs b/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..162be18 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs @@ -0,0 +1,148 @@ +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() + { + comboBoxRepair = new ComboBox(); + labelRepair = new Label(); + labelCount = new Label(); + labelSum = new Label(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxRepair + // + comboBoxRepair.FormattingEnabled = true; + comboBoxRepair.Location = new Point(131, 9); + comboBoxRepair.Name = "comboBoxRepair"; + comboBoxRepair.Size = new Size(260, 28); + comboBoxRepair.TabIndex = 0; + comboBoxRepair.SelectedIndexChanged += ComboBoxRepair_SelectedIndexChanged; + comboBoxRepair.Click += ComboBoxRepair_SelectedIndexChanged; + // + // labelRepair + // + labelRepair.AutoSize = true; + labelRepair.Location = new Point(22, 9); + labelRepair.Name = "labelRepair"; + labelRepair.Size = new Size(71, 20); + labelRepair.TabIndex = 1; + labelRepair.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(26, 47); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(26, 89); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(58, 20); + labelSum.TabIndex = 3; + labelSum.Text = "Сумма:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(131, 47); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(260, 27); + textBoxCount.TabIndex = 4; + textBoxCount.Click += TextBoxCount_TextChanged; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(131, 89); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(260, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(177, 134); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(277, 134); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(406, 175); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelRepair); + Controls.Add(comboBoxRepair); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateOrder_Load; + Click += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxRepair; + private Label labelRepair; + private Label labelCount; + private Label labelSum; + 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..8b054b9 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.cs @@ -0,0 +1,121 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace CarRepairShop +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logicR; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IRepairLogic logicR, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicR = logicR; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка ремонта для заказа"); + try + { + var list = _logicR.ReadList(null); + if (list != null) + { + comboBoxRepair.DisplayMember = "RepairName"; + comboBoxRepair.ValueMember = "Id"; + comboBoxRepair.DataSource = list; + comboBoxRepair.SelectedItem = null; + } + _logger.LogInformation("Ремонт загружено"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ремонта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxRepair.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxRepair.SelectedValue); + var product = _logicR.ReadElement(new RepairSearchModel + { + 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 ComboBoxRepair_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 (comboBoxRepair.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + RepairId = Convert.ToInt32(comboBoxRepair.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormCreateOrder.resx b/CarRepairShop/CarRepairShop/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormMain.Designer.cs b/CarRepairShop/CarRepairShop/FormMain.Designer.cs new file mode 100644 index 0000000..8bf3995 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormMain.Designer.cs @@ -0,0 +1,175 @@ +namespace CarRepairShop +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + ремонтToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1082, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, ремонтToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // ремонтToolStripMenuItem + // + ремонтToolStripMenuItem.Name = "ремонтToolStripMenuItem"; + ремонтToolStripMenuItem.Size = new Size(182, 26); + ремонтToolStripMenuItem.Text = "Ремонт"; + ремонтToolStripMenuItem.Click += RepairToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(839, 368); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(858, 63); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(212, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(858, 131); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(212, 29); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(858, 197); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(212, 29); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(858, 263); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(212, 29); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(858, 331); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(212, 29); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1082, 403); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Автомастерская"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem ремонтToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormMain.cs b/CarRepairShop/CarRepairShop/FormMain.cs new file mode 100644 index 0000000..cd10bbe --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormMain.cs @@ -0,0 +1,153 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarRepairShop +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["RepairId"].Visible = false; + dataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void RepairToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); + if (service is FormRepair form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormMain.resx b/CarRepairShop/CarRepairShop/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs index 72fe267..1ede5a0 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs @@ -28,92 +28,193 @@ /// private void InitializeComponent() { - label1 = new Label(); - label2 = new Label(); - groupBox1 = new GroupBox(); - dataGridView1 = new DataGridView(); - Component = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); - groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + labelName = new Label(); + labelCost = new Label(); + groupBoxComponents = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridViewComponents = new DataGridView(); + ComponentNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); SuspendLayout(); // - // label1 + // labelName // - label1.AutoSize = true; - label1.Location = new Point(25, 18); - label1.Name = "label1"; - label1.Size = new Size(50, 20); - label1.TabIndex = 0; - label1.Text = "label1"; + labelName.AutoSize = true; + labelName.Location = new Point(25, 18); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; // - // label2 + // labelCost // - label2.AutoSize = true; - label2.Location = new Point(25, 58); - label2.Name = "label2"; - label2.Size = new Size(50, 20); - label2.TabIndex = 1; - label2.Text = "label2"; + labelCost.AutoSize = true; + labelCost.Location = new Point(25, 58); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(86, 20); + labelCost.TabIndex = 1; + labelCost.Text = "Стоимость:"; // - // groupBox1 + // groupBoxComponents // - groupBox1.Controls.Add(dataGridView1); - groupBox1.Location = new Point(12, 97); - groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(776, 303); - groupBox1.TabIndex = 2; - groupBox1.TabStop = false; - groupBox1.Text = "groupBox1"; + groupBoxComponents.Controls.Add(buttonRefresh); + groupBoxComponents.Controls.Add(buttonDelete); + groupBoxComponents.Controls.Add(buttonUpdate); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridViewComponents); + groupBoxComponents.Location = new Point(12, 97); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(776, 303); + groupBoxComponents.TabIndex = 2; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; // - // dataGridView1 + // buttonRefresh // - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Component, Count }); - dataGridView1.Location = new Point(13, 23); - dataGridView1.Name = "dataGridView1"; - dataGridView1.RowHeadersWidth = 51; - dataGridView1.RowTemplate.Height = 29; - dataGridView1.Size = new Size(570, 274); - dataGridView1.TabIndex = 0; + buttonRefresh.Location = new Point(634, 191); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; // - // Component + // buttonDelete // - Component.HeaderText = "Компонент"; - Component.MinimumWidth = 6; - Component.Name = "Component"; - Component.Width = 370; + buttonDelete.Location = new Point(634, 142); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 6; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; // - // Count + // buttonUpdate // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - Count.Width = 200; + buttonUpdate.Location = new Point(634, 92); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(94, 29); + buttonUpdate.TabIndex = 5; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(634, 44); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewComponents + // + dataGridViewComponents.BackgroundColor = Color.White; + dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { ComponentNameColumn, CountColumn }); + dataGridViewComponents.Location = new Point(13, 23); + dataGridViewComponents.Name = "dataGridViewComponents"; + dataGridViewComponents.RowHeadersWidth = 51; + dataGridViewComponents.RowTemplate.Height = 29; + dataGridViewComponents.Size = new Size(573, 274); + dataGridViewComponents.TabIndex = 0; + // + // ComponentNameColumn + // + ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentNameColumn.HeaderText = "Компонент"; + ComponentNameColumn.MinimumWidth = 320; + ComponentNameColumn.Name = "ComponentNameColumn"; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 200; + // + // textBoxName + // + textBoxName.Location = new Point(117, 18); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(404, 27); + textBoxName.TabIndex = 1; + // + // textBoxCost + // + textBoxCost.Location = new Point(117, 58); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(229, 27); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(546, 406); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(646, 406); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormRepair // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(groupBox1); - Controls.Add(label2); - Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(groupBoxComponents); + Controls.Add(labelCost); + Controls.Add(labelName); Name = "FormRepair"; - Text = "FormRepair"; - groupBox1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + StartPosition = FormStartPosition.CenterScreen; + Text = "Изделие"; + Load += FormRepair_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).EndInit(); ResumeLayout(false); PerformLayout(); } #endregion - private Label label1; - private Label label2; - private GroupBox groupBox1; - private DataGridView dataGridView1; - private DataGridViewTextBoxColumn Component; - private DataGridViewTextBoxColumn Count; + private Label labelName; + private Label labelCost; + private GroupBox groupBoxComponents; + private DataGridView dataGridViewComponents; + private DataGridViewTextBoxColumn ComponentNameColumn; + private DataGridViewTextBoxColumn CountColumn; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepair.cs b/CarRepairShop/CarRepairShop/FormRepair.cs index 4e30c0a..deaec89 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.cs @@ -1,20 +1,216 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopDataModels.Models; +using Microsoft.Extensions.Logging; namespace CarRepairShop { public partial class FormRepair : Form { - public FormRepair() + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + private int? _id; + private Dictionary _repairComponents; + public int Id { set { _id = value; } } + public FormRepair(ILogger logger, IRepairLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + _repairComponents = new Dictionary(); + } + private void FormRepair_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new RepairSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.RepairName; + textBoxCost.Text = view.Price.ToString(); + _repairComponents = view.RepairComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_repairComponents != null) + { + dataGridViewComponents.Rows.Clear(); + foreach (var pc in _repairComponents) + { + dataGridViewComponents.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxCost.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(FormRepairComponent)); + if (service is FormRepairComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_repairComponents.ContainsKey(form.Id)) + { + _repairComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _repairComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + if (service is FormRepairComponent form) + { + int id = + Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _repairComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _repairComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridViewComponents.SelectedRows[0].Cells[1].Value); + + _repairComponents?.Remove(Convert.ToInt32(dataGridViewComponents.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(textBoxCost.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_repairComponents == null || _repairComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new RepairBindingModel + { + Id = _id ?? 0, + RepairName = textBoxName.Text, + Price = Convert.ToDouble(textBoxCost.Text), + RepairComponents = _repairComponents + }; + 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 _repairComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); } } } diff --git a/CarRepairShop/CarRepairShop/FormRepair.resx b/CarRepairShop/CarRepairShop/FormRepair.resx index 1206194..41edeb3 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.resx +++ b/CarRepairShop/CarRepairShop/FormRepair.resx @@ -117,10 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True - + True \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs index 4281b74..df2181b 100644 --- a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs @@ -77,6 +77,7 @@ buttonSave.TabIndex = 4; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // buttonCancel // @@ -86,6 +87,7 @@ buttonCancel.TabIndex = 5; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormRepairComponent // @@ -99,6 +101,7 @@ Controls.Add(labelCount); Controls.Add(labelComponent); Name = "FormRepairComponent"; + StartPosition = FormStartPosition.CenterScreen; Text = "Компонент изделия"; ResumeLayout(false); PerformLayout(); diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.cs b/CarRepairShop/CarRepairShop/FormRepairComponent.cs index 89063b7..917f7a9 100644 --- a/CarRepairShop/CarRepairShop/FormRepairComponent.cs +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.cs @@ -9,8 +9,8 @@ namespace CarRepairShop private readonly List? _list; public int Id { - get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } - set { comboBoxComponent.SelectedValue = value; } + get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } + set { comboBoxComponent.SelectedValue = value; } } public IComponentModel? ComponentModel { diff --git a/CarRepairShop/CarRepairShop/FormRepairs.Designer.cs b/CarRepairShop/CarRepairShop/FormRepairs.Designer.cs new file mode 100644 index 0000000..9b0343d --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepairs.Designer.cs @@ -0,0 +1,116 @@ +namespace CarRepairShop +{ + partial class FormRepairs + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(593, 450); + dataGridView.TabIndex = 1; + // + // buttonAdd + // + buttonAdd.Location = new Point(638, 38); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(120, 39); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(638, 94); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(120, 39); + buttonUpdate.TabIndex = 3; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(638, 151); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(120, 39); + buttonDelete.TabIndex = 4; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(638, 211); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(120, 39); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormRepairs + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormRepairs"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Ремонты"; + Load += FormRepairs_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepairs.cs b/CarRepairShop/CarRepairShop/FormRepairs.cs new file mode 100644 index 0000000..d67cbf3 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepairs.cs @@ -0,0 +1,106 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarRepairShop +{ + public partial class FormRepairs : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + public FormRepairs(ILogger logger, IRepairLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormRepairs_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["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["RepairComponents"].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(FormRepair)); + if (service is FormRepair 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(FormRepair)); + if (service is FormRepair form) + { + var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + 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 RepairBindingModel + { + 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/FormRepairs.resx b/CarRepairShop/CarRepairShop/FormRepairs.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormRepairs.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Program.cs b/CarRepairShop/CarRepairShop/Program.cs index ab5a301..28c4224 100644 --- a/CarRepairShop/CarRepairShop/Program.cs +++ b/CarRepairShop/CarRepairShop/Program.cs @@ -4,6 +4,7 @@ using CarRepairShopContracts.StoragesContracts; using CarRepairShopListImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace CarRepairShop { @@ -42,9 +43,9 @@ namespace CarRepairShop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 4b9b9046f07e079d5bc5658d2d3734f981f20b33 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sun, 11 Feb 2024 18:17:52 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShop/FormCreateOrder.Designer.cs | 2 + .../CarRepairShop/FormCreateOrder.cs | 4 ++ CarRepairShop/CarRepairShop/FormMain.cs | 25 ++++++---- .../CarRepairShop/FormRepair.Designer.cs | 49 ++++++++++++------- CarRepairShop/CarRepairShop/FormRepair.cs | 6 +-- CarRepairShop/CarRepairShop/FormRepair.resx | 3 ++ .../FormRepairComponent.Designer.cs | 1 + 7 files changed, 58 insertions(+), 32 deletions(-) diff --git a/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs b/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs index 162be18..ab51b66 100644 --- a/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.Designer.cs @@ -40,6 +40,7 @@ // // comboBoxRepair // + comboBoxRepair.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxRepair.FormattingEnabled = true; comboBoxRepair.Location = new Point(131, 9); comboBoxRepair.Name = "comboBoxRepair"; @@ -91,6 +92,7 @@ textBoxSum.ReadOnly = true; textBoxSum.Size = new Size(260, 27); textBoxSum.TabIndex = 5; + textBoxSum.TextChanged += TextBoxSum_TextChanged; // // buttonSave // diff --git a/CarRepairShop/CarRepairShop/FormCreateOrder.cs b/CarRepairShop/CarRepairShop/FormCreateOrder.cs index 8b054b9..e3f4ec6 100644 --- a/CarRepairShop/CarRepairShop/FormCreateOrder.cs +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.cs @@ -69,6 +69,10 @@ namespace CarRepairShop { CalcSum(); } + private void TextBoxSum_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } private void ComboBoxRepair_SelectedIndexChanged(object sender, EventArgs e) { CalcSum(); diff --git a/CarRepairShop/CarRepairShop/FormMain.cs b/CarRepairShop/CarRepairShop/FormMain.cs index cd10bbe..c14d176 100644 --- a/CarRepairShop/CarRepairShop/FormMain.cs +++ b/CarRepairShop/CarRepairShop/FormMain.cs @@ -1,5 +1,6 @@ using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopDataModels.Enums; using Microsoft.Extensions.Logging; namespace CarRepairShop @@ -65,6 +66,18 @@ namespace CarRepairShop LoadData(); } } + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + RepairId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["RepairId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -74,9 +87,7 @@ namespace CarRepairShop _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new - OrderBindingModel - { Id = id }); + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -101,9 +112,7 @@ namespace CarRepairShop id); try { - var operationResult = _orderLogic.FinishOrder(new - OrderBindingModel - { Id = id }); + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -127,9 +136,7 @@ namespace CarRepairShop id); try { - var operationResult = _orderLogic.DeliveryOrder(new - OrderBindingModel - { Id = id }); + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs index 1ede5a0..8c41e87 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs @@ -36,12 +36,13 @@ buttonUpdate = new Button(); buttonAdd = new Button(); dataGridViewComponents = new DataGridView(); - ComponentNameColumn = new DataGridViewTextBoxColumn(); - CountColumn = new DataGridViewTextBoxColumn(); textBoxName = new TextBox(); textBoxCost = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + id = new DataGridViewTextBoxColumn(); + ComponentNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); groupBoxComponents.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); SuspendLayout(); @@ -122,7 +123,7 @@ // dataGridViewComponents.BackgroundColor = Color.White; dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { ComponentNameColumn, CountColumn }); + dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { id, ComponentNameColumn, CountColumn }); dataGridViewComponents.Location = new Point(13, 23); dataGridViewComponents.Name = "dataGridViewComponents"; dataGridViewComponents.RowHeadersWidth = 51; @@ -130,20 +131,6 @@ dataGridViewComponents.Size = new Size(573, 274); dataGridViewComponents.TabIndex = 0; // - // ComponentNameColumn - // - ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ComponentNameColumn.HeaderText = "Компонент"; - ComponentNameColumn.MinimumWidth = 320; - ComponentNameColumn.Name = "ComponentNameColumn"; - // - // CountColumn - // - CountColumn.HeaderText = "Количество"; - CountColumn.MinimumWidth = 6; - CountColumn.Name = "CountColumn"; - CountColumn.Width = 200; - // // textBoxName // textBoxName.Location = new Point(117, 18); @@ -155,6 +142,7 @@ // textBoxCost.Location = new Point(117, 58); textBoxCost.Name = "textBoxCost"; + textBoxCost.ReadOnly = true; textBoxCost.Size = new Size(229, 27); textBoxCost.TabIndex = 3; // @@ -178,6 +166,28 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // id + // + id.HeaderText = ""; + id.MinimumWidth = 6; + id.Name = "id"; + id.Visible = false; + id.Width = 125; + // + // ComponentNameColumn + // + ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentNameColumn.HeaderText = "Компонент"; + ComponentNameColumn.MinimumWidth = 320; + ComponentNameColumn.Name = "ComponentNameColumn"; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 200; + // // FormRepair // AutoScaleDimensions = new SizeF(8F, 20F); @@ -206,8 +216,6 @@ private Label labelCost; private GroupBox groupBoxComponents; private DataGridView dataGridViewComponents; - private DataGridViewTextBoxColumn ComponentNameColumn; - private DataGridViewTextBoxColumn CountColumn; private Button buttonRefresh; private Button buttonDelete; private Button buttonUpdate; @@ -216,5 +224,8 @@ private TextBox textBoxCost; private Button buttonSave; private Button buttonCancel; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn ComponentNameColumn; + private DataGridViewTextBoxColumn CountColumn; } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormRepair.cs b/CarRepairShop/CarRepairShop/FormRepair.cs index deaec89..c3996c0 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.cs @@ -29,15 +29,13 @@ namespace CarRepairShop { var view = _logic.ReadElement(new RepairSearchModel { - Id = - _id.Value + Id = _id.Value }); if (view != null) { textBoxName.Text = view.RepairName; textBoxCost.Text = view.Price.ToString(); - _repairComponents = view.RepairComponents ?? new - Dictionary(); + _repairComponents = view.RepairComponents ?? new Dictionary(); LoadData(); } } diff --git a/CarRepairShop/CarRepairShop/FormRepair.resx b/CarRepairShop/CarRepairShop/FormRepair.resx index 41edeb3..23f2d4a 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.resx +++ b/CarRepairShop/CarRepairShop/FormRepair.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + True diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs index df2181b..a8a8877 100644 --- a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs @@ -56,6 +56,7 @@ // // comboBoxComponent // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxComponent.FormattingEnabled = true; comboBoxComponent.Location = new Point(124, 23); comboBoxComponent.Name = "comboBoxComponent"; -- 2.25.1 From adbc7928e6ff98fa6a3458fcfba10c225a5c7d28 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sun, 11 Feb 2024 18:33:58 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarRepairShop/CarRepairShop/FormCreateOrder.cs | 6 +++--- CarRepairShop/CarRepairShop/FormRepair.cs | 12 ++++++------ CarRepairShop/CarRepairShop/FormRepairs.cs | 2 +- .../CarRepairShopBusinessLogic/RepairLogic.cs | 4 ++-- .../Implements/OrderStorage.cs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CarRepairShop/CarRepairShop/FormCreateOrder.cs b/CarRepairShop/CarRepairShop/FormCreateOrder.cs index e3f4ec6..f3763da 100644 --- a/CarRepairShop/CarRepairShop/FormCreateOrder.cs +++ b/CarRepairShop/CarRepairShop/FormCreateOrder.cs @@ -47,13 +47,13 @@ namespace CarRepairShop try { int id = Convert.ToInt32(comboBoxRepair.SelectedValue); - var product = _logicR.ReadElement(new RepairSearchModel + var repair = _logicR.ReadElement(new RepairSearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), + textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } @@ -87,7 +87,7 @@ namespace CarRepairShop } if (comboBoxRepair.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", + MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } diff --git a/CarRepairShop/CarRepairShop/FormRepair.cs b/CarRepairShop/CarRepairShop/FormRepair.cs index c3996c0..7603346 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.cs @@ -24,7 +24,7 @@ namespace CarRepairShop { if (_id.HasValue) { - _logger.LogInformation("Загрузка изделия"); + _logger.LogInformation("Загрузка ремонта"); try { var view = _logic.ReadElement(new RepairSearchModel @@ -41,7 +41,7 @@ namespace CarRepairShop } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделия"); + _logger.LogError(ex, "Ошибка загрузки ремонта"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -49,7 +49,7 @@ namespace CarRepairShop } private void LoadData() { - _logger.LogInformation("Загрузка компонент изделия"); + _logger.LogInformation("Загрузка компонент ремонта"); try { if (_repairComponents != null) @@ -64,7 +64,7 @@ namespace CarRepairShop } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + _logger.LogError(ex, "Ошибка загрузки компонент ремонта"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -168,7 +168,7 @@ namespace CarRepairShop MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение изделия"); + _logger.LogInformation("Сохранение ремонта"); try { var model = new RepairBindingModel @@ -191,7 +191,7 @@ namespace CarRepairShop } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения ремонта"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/CarRepairShop/CarRepairShop/FormRepairs.cs b/CarRepairShop/CarRepairShop/FormRepairs.cs index d67cbf3..ab0c331 100644 --- a/CarRepairShop/CarRepairShop/FormRepairs.cs +++ b/CarRepairShop/CarRepairShop/FormRepairs.cs @@ -32,7 +32,7 @@ namespace CarRepairShop dataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["RepairComponents"].Visible = false; } - _logger.LogInformation("Загрузка компьютеров"); + _logger.LogInformation("Загрузка ремонтов"); } catch (Exception ex) { diff --git a/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs index 96aace7..1c80564 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs @@ -92,12 +92,12 @@ namespace CarRepairShopBusinessLogic } if (string.IsNullOrEmpty(model.RepairName)) { - throw new ArgumentNullException("Нет названия мороженного", + throw new ArgumentNullException("Нет названия ремонта", nameof(model.RepairName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена мороженного должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена ремонта должна быть больше 0", nameof(model.Price)); } _logger.LogInformation("Repair. Repair:{Repair}. Price:{ Price }. Id: { Id}", model.RepairName, model.Price, model.Id); var element = _repairStorage.GetElement(new RepairSearchModel diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs index e666ec7..000661d 100644 --- a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs @@ -18,7 +18,7 @@ namespace CarRepairShopListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(AccessIceCreamStorage(order.GetViewModel)); + result.Add(AccessRepairStorage(order.GetViewModel)); } return result; } @@ -33,7 +33,7 @@ namespace CarRepairShopListImplement.Implements { if (order.Id == model.Id) { - result.Add(AccessIceCreamStorage(order.GetViewModel)); + result.Add(AccessRepairStorage(order.GetViewModel)); } } return result; @@ -97,7 +97,7 @@ namespace CarRepairShopListImplement.Implements return null; } - public OrderViewModel AccessIceCreamStorage(OrderViewModel model) + public OrderViewModel AccessRepairStorage(OrderViewModel model) { foreach (var repair in _source.Repairs) { -- 2.25.1 From 354ace7ab08ca2d2f5c86ddccd70a94799305686 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sun, 11 Feb 2024 18:44:41 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShopContracts/ViewModels/OrderViewModel.cs | 2 +- .../CarRepairShopContracts/ViewModels/RepairViewModel.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs index 9ea4e89..d5ea81b 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -10,7 +10,7 @@ namespace CarRepairShopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int RepairId { get; set; } - [DisplayName("Изделие")] + [DisplayName("Ремонт")] public string RepairName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs index 8a26f48..e6776f7 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs @@ -6,7 +6,7 @@ namespace CarRepairShopContracts.ViewModels public class RepairViewModel : IRepairModel { public int Id { get; set; } - [DisplayName("Название изделия")] + [DisplayName("Название ремонта")] public string RepairName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } -- 2.25.1 From 64f741e671e1f03935d2e5389d7dbc1dd69f92ac Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Mon, 12 Feb 2024 23:51:06 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShop/FormRepair.Designer.cs | 52 +++++++++---------- .../FormRepairComponent.Designer.cs | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs index 8c41e87..2c252f7 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs @@ -36,13 +36,13 @@ buttonUpdate = new Button(); buttonAdd = new Button(); dataGridViewComponents = new DataGridView(); + id = new DataGridViewTextBoxColumn(); + ComponentNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); textBoxName = new TextBox(); textBoxCost = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); - id = new DataGridViewTextBoxColumn(); - ComponentNameColumn = new DataGridViewTextBoxColumn(); - CountColumn = new DataGridViewTextBoxColumn(); groupBoxComponents.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); SuspendLayout(); @@ -131,6 +131,28 @@ dataGridViewComponents.Size = new Size(573, 274); dataGridViewComponents.TabIndex = 0; // + // id + // + id.HeaderText = ""; + id.MinimumWidth = 6; + id.Name = "id"; + id.Visible = false; + id.Width = 125; + // + // ComponentNameColumn + // + ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentNameColumn.HeaderText = "Компонент"; + ComponentNameColumn.MinimumWidth = 320; + ComponentNameColumn.Name = "ComponentNameColumn"; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 200; + // // textBoxName // textBoxName.Location = new Point(117, 18); @@ -166,28 +188,6 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // - // id - // - id.HeaderText = ""; - id.MinimumWidth = 6; - id.Name = "id"; - id.Visible = false; - id.Width = 125; - // - // ComponentNameColumn - // - ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ComponentNameColumn.HeaderText = "Компонент"; - ComponentNameColumn.MinimumWidth = 320; - ComponentNameColumn.Name = "ComponentNameColumn"; - // - // CountColumn - // - CountColumn.HeaderText = "Количество"; - CountColumn.MinimumWidth = 6; - CountColumn.Name = "CountColumn"; - CountColumn.Width = 200; - // // FormRepair // AutoScaleDimensions = new SizeF(8F, 20F); @@ -202,7 +202,7 @@ Controls.Add(labelName); Name = "FormRepair"; StartPosition = FormStartPosition.CenterScreen; - Text = "Изделие"; + Text = "Ремонт"; Load += FormRepair_Load; groupBoxComponents.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).EndInit(); diff --git a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs index a8a8877..3fccce6 100644 --- a/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepairComponent.Designer.cs @@ -103,7 +103,7 @@ Controls.Add(labelComponent); Name = "FormRepairComponent"; StartPosition = FormStartPosition.CenterScreen; - Text = "Компонент изделия"; + Text = "Компонент ремонта"; ResumeLayout(false); PerformLayout(); } -- 2.25.1 From 813a5eb6a1e1d128ebd81e06f99c2bc747d4c106 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Mon, 19 Feb 2024 21:46:05 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=BF=D1=83=D0=BB=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShop/FormMain.Designer.cs | 2 +- .../CarRepairShop/FormRepair.Designer.cs | 54 +++++++++---------- CarRepairShop/CarRepairShop/FormRepair.resx | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CarRepairShop/CarRepairShop/FormMain.Designer.cs b/CarRepairShop/CarRepairShop/FormMain.Designer.cs index 8bf3995..eb2ee1b 100644 --- a/CarRepairShop/CarRepairShop/FormMain.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormMain.Designer.cs @@ -50,7 +50,7 @@ menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1082, 28); menuStrip.TabIndex = 0; - menuStrip.Text = "menuStrip1"; + menuStrip.Text = "Меню справочников"; // // справочникиToolStripMenuItem // diff --git a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs index 2c252f7..14b77fc 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.Designer.cs +++ b/CarRepairShop/CarRepairShop/FormRepair.Designer.cs @@ -36,13 +36,13 @@ buttonUpdate = new Button(); buttonAdd = new Button(); dataGridViewComponents = new DataGridView(); - id = new DataGridViewTextBoxColumn(); - ComponentNameColumn = new DataGridViewTextBoxColumn(); - CountColumn = new DataGridViewTextBoxColumn(); textBoxName = new TextBox(); textBoxCost = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + ColumnId = new DataGridViewTextBoxColumn(); + ComponentNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); groupBoxComponents.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); SuspendLayout(); @@ -123,7 +123,7 @@ // dataGridViewComponents.BackgroundColor = Color.White; dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { id, ComponentNameColumn, CountColumn }); + dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ComponentNameColumn, CountColumn }); dataGridViewComponents.Location = new Point(13, 23); dataGridViewComponents.Name = "dataGridViewComponents"; dataGridViewComponents.RowHeadersWidth = 51; @@ -131,28 +131,6 @@ dataGridViewComponents.Size = new Size(573, 274); dataGridViewComponents.TabIndex = 0; // - // id - // - id.HeaderText = ""; - id.MinimumWidth = 6; - id.Name = "id"; - id.Visible = false; - id.Width = 125; - // - // ComponentNameColumn - // - ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ComponentNameColumn.HeaderText = "Компонент"; - ComponentNameColumn.MinimumWidth = 320; - ComponentNameColumn.Name = "ComponentNameColumn"; - // - // CountColumn - // - CountColumn.HeaderText = "Количество"; - CountColumn.MinimumWidth = 6; - CountColumn.Name = "CountColumn"; - CountColumn.Width = 200; - // // textBoxName // textBoxName.Location = new Point(117, 18); @@ -188,6 +166,28 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // ColumnId + // + ColumnId.HeaderText = "Идентификатор"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ComponentNameColumn + // + ComponentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentNameColumn.HeaderText = "Компонент"; + ComponentNameColumn.MinimumWidth = 320; + ComponentNameColumn.Name = "ComponentNameColumn"; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 200; + // // FormRepair // AutoScaleDimensions = new SizeF(8F, 20F); @@ -224,7 +224,7 @@ private TextBox textBoxCost; private Button buttonSave; private Button buttonCancel; - private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn ColumnId; private DataGridViewTextBoxColumn ComponentNameColumn; private DataGridViewTextBoxColumn CountColumn; } diff --git a/CarRepairShop/CarRepairShop/FormRepair.resx b/CarRepairShop/CarRepairShop/FormRepair.resx index 23f2d4a..16aedde 100644 --- a/CarRepairShop/CarRepairShop/FormRepair.resx +++ b/CarRepairShop/CarRepairShop/FormRepair.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True -- 2.25.1 From eb5d53ec9d9ac431db0f170759a326ca196c7666 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sat, 2 Mar 2024 00:22:56 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D0=9F=D1=83=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarRepairShop/CarRepairShop/FormMain.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CarRepairShop/CarRepairShop/FormMain.cs b/CarRepairShop/CarRepairShop/FormMain.cs index c14d176..893ec0f 100644 --- a/CarRepairShop/CarRepairShop/FormMain.cs +++ b/CarRepairShop/CarRepairShop/FormMain.cs @@ -50,8 +50,8 @@ namespace CarRepairShop } private void RepairToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); - if (service is FormRepair form) + var service = Program.ServiceProvider?.GetService(typeof(FormRepairs)); + if (service is FormRepairs form) { form.ShowDialog(); } -- 2.25.1