From fa55038a86ea0779a977c5e6a989b6a9e1a17443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=94?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=BE=D0=B2?= Date: Thu, 21 Mar 2024 20:10:13 +0400 Subject: [PATCH] Lab1 --- RenovationWork/RenovationWork.sln | 26 +- .../RenovationWork/Form1.Designer.cs | 39 --- RenovationWork/RenovationWork/Form1.cs | 10 - .../RenovationWork/FormComponent.Designer.cs | 118 +++++++++ .../RenovationWork/FormComponent.cs | 99 ++++++++ .../RenovationWork/FormComponent.resx | 120 ++++++++++ .../RenovationWork/FormComponents.Designer.cs | 115 +++++++++ .../RenovationWork/FormComponents.cs | 113 +++++++++ .../RenovationWork/FormComponents.resx | 120 ++++++++++ .../FormCreateOrder.Designer.cs | 143 +++++++++++ .../RenovationWork/FormCreateOrder.cs | 115 +++++++++ .../RenovationWork/FormCreateOrder.resx | 120 ++++++++++ .../RenovationWork/FormMain.Designer.cs | 171 +++++++++++++ RenovationWork/RenovationWork/FormMain.cs | 159 +++++++++++++ RenovationWork/RenovationWork/FormMain.resx | 123 ++++++++++ .../RenovationWork/FormRepair.Designer.cs | 224 ++++++++++++++++++ RenovationWork/RenovationWork/FormRepair.cs | 213 +++++++++++++++++ RenovationWork/RenovationWork/FormRepair.resx | 129 ++++++++++ .../FormRepairComponent.Designer.cs | 119 ++++++++++ .../RenovationWork/FormRepairComponent.cs | 94 ++++++++ .../RenovationWork/FormRepairComponent.resx | 120 ++++++++++ .../RenovationWork/FormRepairs.Designer.cs | 114 +++++++++ RenovationWork/RenovationWork/FormRepairs.cs | 110 +++++++++ .../RenovationWork/FormRepairs.resx | 120 ++++++++++ RenovationWork/RenovationWork/Program.cs | 41 +++- .../Properties/Resources.Designer.cs | 63 +++++ .../{Form1.resx => Properties/Resources.resx} | 0 .../RenovationWork/RenovationWork.csproj | 11 - .../RenovationWork/RenovationWorkView.csproj | 22 ++ RenovationWork/RenovationWork/nlog.config | 14 ++ .../BusinessLogics/ComponentLogic.cs | 108 +++++++++ .../BusinessLogics/OrderLogic.cs | 119 ++++++++++ .../BusinessLogics/RepairLogic.cs | 112 +++++++++ .../RenovationWorkBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 12 + .../BindingModels/OrderBindingModel.cs | 22 ++ .../BindingModels/RepairBindingModel.cs | 17 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 21 ++ .../BusinessLogicsContracts/IRepairLogic.cs | 20 ++ .../RenovationWorkContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 14 ++ .../SearchModels/RepairSearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IRepairStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 31 +++ .../ViewModels/RepairViewModel.cs | 20 ++ .../Enums/OrderStatus.cs | 17 ++ .../RenovationWorkDataModels/IId.cs | 8 + .../Models/IComponentModel.cs | 14 ++ .../Models/IOrderModel.cs | 19 ++ .../Models/IRepairModel.cs | 15 ++ .../RenovationWorkDataModels.csproj | 9 + .../DataListSingleton.cs | 31 +++ .../Implements/ComponentStorage.cs | 105 ++++++++ .../Implements/OrderStorage.cs | 118 +++++++++ .../Implements/RepairStorage.cs | 106 +++++++++ .../Models/Component.cs | 47 ++++ .../Models/Order.cs | 70 ++++++ .../Models/Repair.cs | 54 +++++ .../RenovationWorkListImplement.csproj | 14 ++ 64 files changed, 4204 insertions(+), 66 deletions(-) delete mode 100644 RenovationWork/RenovationWork/Form1.Designer.cs delete mode 100644 RenovationWork/RenovationWork/Form1.cs create mode 100644 RenovationWork/RenovationWork/FormComponent.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormComponent.cs create mode 100644 RenovationWork/RenovationWork/FormComponent.resx create mode 100644 RenovationWork/RenovationWork/FormComponents.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormComponents.cs create mode 100644 RenovationWork/RenovationWork/FormComponents.resx create mode 100644 RenovationWork/RenovationWork/FormCreateOrder.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormCreateOrder.cs create mode 100644 RenovationWork/RenovationWork/FormCreateOrder.resx create mode 100644 RenovationWork/RenovationWork/FormMain.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormMain.cs create mode 100644 RenovationWork/RenovationWork/FormMain.resx create mode 100644 RenovationWork/RenovationWork/FormRepair.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormRepair.cs create mode 100644 RenovationWork/RenovationWork/FormRepair.resx create mode 100644 RenovationWork/RenovationWork/FormRepairComponent.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormRepairComponent.cs create mode 100644 RenovationWork/RenovationWork/FormRepairComponent.resx create mode 100644 RenovationWork/RenovationWork/FormRepairs.Designer.cs create mode 100644 RenovationWork/RenovationWork/FormRepairs.cs create mode 100644 RenovationWork/RenovationWork/FormRepairs.resx create mode 100644 RenovationWork/RenovationWork/Properties/Resources.Designer.cs rename RenovationWork/RenovationWork/{Form1.resx => Properties/Resources.resx} (100%) delete mode 100644 RenovationWork/RenovationWork/RenovationWork.csproj create mode 100644 RenovationWork/RenovationWork/RenovationWorkView.csproj create mode 100644 RenovationWork/RenovationWork/nlog.config create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs create mode 100644 RenovationWork/RenovationWorkDataModels/IId.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj create mode 100644 RenovationWork/RenovationWorkListImplement/DataListSingleton.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Component.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Order.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Repair.cs create mode 100644 RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj diff --git a/RenovationWork/RenovationWork.sln b/RenovationWork/RenovationWork.sln index 58b8f70..62abf84 100644 --- a/RenovationWork/RenovationWork.sln +++ b/RenovationWork/RenovationWork.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWork", "RenovationWork\RenovationWork.csproj", "{0CB24AB4-7DB9-4B3B-B178-A5866CAB684D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkView", "RenovationWork\RenovationWorkView.csproj", "{0CB24AB4-7DB9-4B3B-B178-A5866CAB684D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkDataModels", "RenovationWorkDataModels\RenovationWorkDataModels.csproj", "{82B84205-6A94-434F-8A60-DD5EE186CF18}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkContracts", "RenovationWorkContracts\RenovationWorkContracts.csproj", "{14E076E8-311A-47CE-96C6-BF5CD477D7D4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkBusinessLogic", "RenovationWorkBusinessLogic\RenovationWorkBusinessLogic.csproj", "{3D6114C0-46B0-4140-9B38-68DCC260A334}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkListImplement", "RenovationWorkListImplement\RenovationWorkListImplement.csproj", "{CBEF7964-AEB9-4FE9-B85F-9FBDEE198EED}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {0CB24AB4-7DB9-4B3B-B178-A5866CAB684D}.Debug|Any CPU.Build.0 = Debug|Any CPU {0CB24AB4-7DB9-4B3B-B178-A5866CAB684D}.Release|Any CPU.ActiveCfg = Release|Any CPU {0CB24AB4-7DB9-4B3B-B178-A5866CAB684D}.Release|Any CPU.Build.0 = Release|Any CPU + {82B84205-6A94-434F-8A60-DD5EE186CF18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82B84205-6A94-434F-8A60-DD5EE186CF18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82B84205-6A94-434F-8A60-DD5EE186CF18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82B84205-6A94-434F-8A60-DD5EE186CF18}.Release|Any CPU.Build.0 = Release|Any CPU + {14E076E8-311A-47CE-96C6-BF5CD477D7D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14E076E8-311A-47CE-96C6-BF5CD477D7D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14E076E8-311A-47CE-96C6-BF5CD477D7D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14E076E8-311A-47CE-96C6-BF5CD477D7D4}.Release|Any CPU.Build.0 = Release|Any CPU + {3D6114C0-46B0-4140-9B38-68DCC260A334}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D6114C0-46B0-4140-9B38-68DCC260A334}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D6114C0-46B0-4140-9B38-68DCC260A334}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D6114C0-46B0-4140-9B38-68DCC260A334}.Release|Any CPU.Build.0 = Release|Any CPU + {CBEF7964-AEB9-4FE9-B85F-9FBDEE198EED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CBEF7964-AEB9-4FE9-B85F-9FBDEE198EED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CBEF7964-AEB9-4FE9-B85F-9FBDEE198EED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CBEF7964-AEB9-4FE9-B85F-9FBDEE198EED}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RenovationWork/RenovationWork/Form1.Designer.cs b/RenovationWork/RenovationWork/Form1.Designer.cs deleted file mode 100644 index 273f6ae..0000000 --- a/RenovationWork/RenovationWork/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace RenovationWork -{ - 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 - } -} diff --git a/RenovationWork/RenovationWork/Form1.cs b/RenovationWork/RenovationWork/Form1.cs deleted file mode 100644 index 8d3567c..0000000 --- a/RenovationWork/RenovationWork/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace RenovationWork -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/RenovationWork/RenovationWork/FormComponent.Designer.cs b/RenovationWork/RenovationWork/FormComponent.Designer.cs new file mode 100644 index 0000000..411540f --- /dev/null +++ b/RenovationWork/RenovationWork/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace RenovationWorkView +{ + 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + labelName = new Label(); + labelCost = new Label(); + textBoxCost = new TextBox(); + textBoxComponentName = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(223, 82); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(314, 83); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(11, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 2; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(11, 45); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(38, 15); + labelCost.TabIndex = 3; + labelCost.Text = "Цена:"; + // + // textBoxCost + // + textBoxCost.Location = new Point(79, 45); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(170, 23); + textBoxCost.TabIndex = 4; + // + // textBoxComponentName + // + textBoxComponentName.Location = new Point(79, 9); + textBoxComponentName.Name = "textBoxComponentName"; + textBoxComponentName.Size = new Size(310, 23); + textBoxComponentName.TabIndex = 5; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(401, 117); + Controls.Add(textBoxComponentName); + Controls.Add(textBoxCost); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxCost; + private TextBox textBoxComponentName; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormComponent.cs b/RenovationWork/RenovationWork/FormComponent.cs new file mode 100644 index 0000000..e867ea7 --- /dev/null +++ b/RenovationWork/RenovationWork/FormComponent.cs @@ -0,0 +1,99 @@ +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 RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + 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) + { + textBoxComponentName.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(textBoxComponentName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxComponentName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RenovationWork/RenovationWork/FormComponent.resx b/RenovationWork/RenovationWork/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/FormComponent.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/RenovationWork/RenovationWork/FormComponents.Designer.cs b/RenovationWork/RenovationWork/FormComponents.Designer.cs new file mode 100644 index 0000000..bcb8ac7 --- /dev/null +++ b/RenovationWork/RenovationWork/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace RenovationWorkView +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.GridColor = SystemColors.ButtonHighlight; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(641, 277); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(659, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(126, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(659, 50); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(126, 23); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(659, 88); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(126, 23); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(659, 126); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(126, 23); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(797, 301); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormComponents.cs b/RenovationWork/RenovationWork/FormComponents.cs new file mode 100644 index 0000000..3d741cf --- /dev/null +++ b/RenovationWork/RenovationWork/FormComponents.cs @@ -0,0 +1,113 @@ +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 RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + 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/RenovationWork/RenovationWork/FormComponents.resx b/RenovationWork/RenovationWork/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/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/RenovationWork/RenovationWork/FormCreateOrder.Designer.cs b/RenovationWork/RenovationWork/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..5588e28 --- /dev/null +++ b/RenovationWork/RenovationWork/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace RenovationWorkView +{ + 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() + { + labelComponent = new Label(); + labelCount = new Label(); + labelSum = new Label(); + textBoxSum = new TextBox(); + textBoxCount = new TextBox(); + comboBoxRepair = new ComboBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 6); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(56, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 37); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(12, 67); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(48, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // textBoxSum + // + textBoxSum.Location = new Point(95, 67); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(298, 23); + textBoxSum.TabIndex = 3; + // + // textBoxCount + // + textBoxCount.Location = new Point(95, 37); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(298, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // comboBoxRepair + // + comboBoxRepair.FormattingEnabled = true; + comboBoxRepair.Location = new Point(95, 6); + comboBoxRepair.Name = "comboBoxRepair"; + comboBoxRepair.Size = new Size(298, 23); + comboBoxRepair.TabIndex = 5; + comboBoxRepair.SelectedIndexChanged += comboBoxRepair_SelectedIndexChanged; + // + // buttonSave + // + buttonSave.Location = new Point(220, 96); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(311, 96); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(398, 124); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxRepair); + Controls.Add(textBoxCount); + Controls.Add(textBoxSum); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private Label labelSum; + private TextBox textBoxSum; + private TextBox textBoxCount; + private ComboBox comboBoxRepair; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormCreateOrder.cs b/RenovationWork/RenovationWork/FormCreateOrder.cs new file mode 100644 index 0000000..1db4606 --- /dev/null +++ b/RenovationWork/RenovationWork/FormCreateOrder.cs @@ -0,0 +1,115 @@ +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using Microsoft.Extensions.Logging; +using RenovationWorkListImplement.Models; + +namespace RenovationWorkView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logicC; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IRepairLogic logicC, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicC = logicC; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxRepair.DisplayMember = "RepairName"; + comboBoxRepair.ValueMember = "Id"; + comboBoxRepair.DataSource = list; + comboBoxRepair.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxRepair.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxRepair.SelectedValue); + var repair = _logicC.ReadElement(new RepairSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void comboBoxRepair_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void textBoxCount_TextChanged(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 + { + int id = Convert.ToInt32(comboBoxRepair.SelectedValue); + int counr = Convert.ToInt32(textBoxCount.Text); + double sum = Convert.ToDouble(textBoxSum.Text); + 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/RenovationWork/RenovationWork/FormCreateOrder.resx b/RenovationWork/RenovationWork/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/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/RenovationWork/RenovationWork/FormMain.Designer.cs b/RenovationWork/RenovationWork/FormMain.Designer.cs new file mode 100644 index 0000000..4449b0f --- /dev/null +++ b/RenovationWork/RenovationWork/FormMain.Designer.cs @@ -0,0 +1,171 @@ +namespace RenovationWorkView +{ + 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(); + refbooksToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + JobTypeToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { refbooksToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(984, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // refbooksToolStripMenuItem + // + refbooksToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, JobTypeToolStripMenuItem }); + refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem"; + refbooksToolStripMenuItem.Size = new Size(94, 20); + refbooksToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(145, 22); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; + // + // JobTypeToolStripMenuItem + // + JobTypeToolStripMenuItem.Name = "JobTypeToolStripMenuItem"; + JobTypeToolStripMenuItem.Size = new Size(145, 22); + JobTypeToolStripMenuItem.Text = "Вид работы"; + JobTypeToolStripMenuItem.Click += JobTypeToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(797, 341); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(815, 42); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(157, 23); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(815, 71); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(157, 45); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отправить на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(815, 122); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(157, 23); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(815, 151); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(157, 23); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(815, 180); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(157, 23); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(984, 370); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Ремонтные работы"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem refbooksToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem JobTypeToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormMain.cs b/RenovationWork/RenovationWork/FormMain.cs new file mode 100644 index 0000000..d143cbe --- /dev/null +++ b/RenovationWork/RenovationWork/FormMain.cs @@ -0,0 +1,159 @@ +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 RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + 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; + } + } + 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 JobTypeToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepairs)); + if (service is FormRepairs 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/RenovationWork/RenovationWork/FormMain.resx b/RenovationWork/RenovationWork/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/RenovationWork/RenovationWork/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/RenovationWork/RenovationWork/FormRepair.Designer.cs b/RenovationWork/RenovationWork/FormRepair.Designer.cs new file mode 100644 index 0000000..ec5f53a --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepair.Designer.cs @@ -0,0 +1,224 @@ +namespace RenovationWorkView +{ + 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ComponentT = new DataGridViewTextBoxColumn(); + CountT = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(4, 12); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(4, 43); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(70, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(88, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(334, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(88, 43); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(334, 23); + textBoxPrice.TabIndex = 3; + // + // groupBox + // + groupBox.Controls.Add(buttonRef); + groupBox.Controls.Add(buttonDel); + groupBox.Controls.Add(buttonUpd); + groupBox.Controls.Add(buttonAdd); + groupBox.Controls.Add(dataGridView); + groupBox.Location = new Point(12, 87); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(763, 351); + groupBox.TabIndex = 5; + groupBox.TabStop = false; + groupBox.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(656, 121); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(99, 23); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(656, 92); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(99, 23); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(656, 63); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(99, 23); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(656, 34); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(99, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentT, CountT }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(644, 323); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "id"; + ID.Name = "ID"; + ID.Visible = false; + // + // ComponentT + // + ComponentT.HeaderText = "Компонент"; + ComponentT.Name = "ComponentT"; + ComponentT.Width = 300; + // + // CountT + // + CountT.HeaderText = "Количество"; + CountT.Name = "CountT"; + CountT.Width = 300; + // + // buttonSave + // + buttonSave.Location = new Point(599, 451); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(692, 451); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormRepair + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(783, 486); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(groupBox); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormRepair"; + Text = "Работа"; + Load += FormRepair_Load; + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox; + private DataGridView dataGridView; + private Button buttonAdd; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ComponentT; + private DataGridViewTextBoxColumn CountT; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepair.cs b/RenovationWork/RenovationWork/FormRepair.cs new file mode 100644 index 0000000..777b6cf --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepair.cs @@ -0,0 +1,213 @@ +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 RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + public partial class FormRepair : Form + { + 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; + textBoxPrice.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) + { + dataGridView.Rows.Clear(); + foreach (var pc in _repairComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(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 (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + if (service is FormRepairComponent form) + { + int id = Convert.ToInt32(dataGridView.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 (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value); + _repairComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_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(textBoxPrice.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/RenovationWork/RenovationWork/FormRepair.resx b/RenovationWork/RenovationWork/FormRepair.resx new file mode 100644 index 0000000..a7f951f --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepair.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepairComponent.Designer.cs b/RenovationWork/RenovationWork/FormRepairComponent.Designer.cs new file mode 100644 index 0000000..7d74a43 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace RenovationWorkView +{ + 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(9, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(9, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 9); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(354, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 38); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(354, 23); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(288, 76); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(369, 76); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormRepairComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(456, 107); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormRepairComponent"; + Text = "Компонент работы"; + Load += FormRepairComponent_Load; + 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/RenovationWork/RenovationWork/FormRepairComponent.cs b/RenovationWork/RenovationWork/FormRepairComponent.cs new file mode 100644 index 0000000..78aa07b --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairComponent.cs @@ -0,0 +1,94 @@ +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 RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; + +namespace RenovationWorkView +{ + 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(); + } + + private void FormRepairComponent_Load(object sender, EventArgs e) + { + + } + } +} diff --git a/RenovationWork/RenovationWork/FormRepairComponent.resx b/RenovationWork/RenovationWork/FormRepairComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/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/RenovationWork/RenovationWork/FormRepairs.Designer.cs b/RenovationWork/RenovationWork/FormRepairs.Designer.cs new file mode 100644 index 0000000..638fec6 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairs.Designer.cs @@ -0,0 +1,114 @@ +namespace RenovationWorkView +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(2, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(553, 444); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(561, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(98, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(561, 41); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(98, 23); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(561, 70); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(98, 23); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(561, 99); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(98, 23); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormRepairs + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(671, 448); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormRepairs"; + Text = "Список работ"; + Load += FormRepairs_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepairs.cs b/RenovationWork/RenovationWork/FormRepairs.cs new file mode 100644 index 0000000..dc8d7f4 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairs.cs @@ -0,0 +1,110 @@ +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 RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + 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) + { + 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/RenovationWork/RenovationWork/FormRepairs.resx b/RenovationWork/RenovationWork/FormRepairs.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/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/RenovationWork/RenovationWork/Program.cs b/RenovationWork/RenovationWork/Program.cs index b2aaac6..419c2af 100644 --- a/RenovationWork/RenovationWork/Program.cs +++ b/RenovationWork/RenovationWork/Program.cs @@ -1,17 +1,48 @@ -namespace RenovationWork +using RenovationWorkBusinessLogic.BusinessLogics; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace RenovationWorkView { internal static class Program { - /// - /// The main entry point for the application. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; [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()); + 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/RenovationWork/RenovationWork/Properties/Resources.Designer.cs b/RenovationWork/RenovationWork/Properties/Resources.Designer.cs new file mode 100644 index 0000000..5e21999 --- /dev/null +++ b/RenovationWork/RenovationWork/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace RenovationWorkView.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RenovationWorkView.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/RenovationWork/RenovationWork/Form1.resx b/RenovationWork/RenovationWork/Properties/Resources.resx similarity index 100% rename from RenovationWork/RenovationWork/Form1.resx rename to RenovationWork/RenovationWork/Properties/Resources.resx diff --git a/RenovationWork/RenovationWork/RenovationWork.csproj b/RenovationWork/RenovationWork/RenovationWork.csproj deleted file mode 100644 index b57c89e..0000000 --- a/RenovationWork/RenovationWork/RenovationWork.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/RenovationWork/RenovationWork/RenovationWorkView.csproj b/RenovationWork/RenovationWork/RenovationWorkView.csproj new file mode 100644 index 0000000..9a90fc6 --- /dev/null +++ b/RenovationWork/RenovationWork/RenovationWorkView.csproj @@ -0,0 +1,22 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenovationWork/RenovationWork/nlog.config b/RenovationWork/RenovationWork/nlog.config new file mode 100644 index 0000000..77b13bf --- /dev/null +++ b/RenovationWork/RenovationWork/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..6799037 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,108 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkBusinessLogic.BusinessLogics +{ + 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/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..b34651d --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Update operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.RepairId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.RepairId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество работ в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); + } + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs new file mode 100644 index 0000000..3301975 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkBusinessLogic.BusinessLogics +{ + 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. RepairName:{RepairName}.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/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj b/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj new file mode 100644 index 0000000..62a4b97 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..350a457 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,12 @@ +using RenovationWorkDataModels.Models; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..483a273 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkDataModels.Enums; +using RenovationWorkDataModels.Models; + + +namespace RenovationWorkContracts.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; } + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs new file mode 100644 index 0000000..4491dd7 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkDataModels.Models; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..a4726c5 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..ce60d67 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs new file mode 100644 index 0000000..46433e9 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj b/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj new file mode 100644 index 0000000..96ab30f --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..b2f3639 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..1d07126 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} + diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs new file mode 100644 index 0000000..15d1906 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class RepairSearchModel + { + public int? Id { get; set; } + public string? RepairName { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..f10b3e4 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..d7e583d --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs new file mode 100644 index 0000000..b360537 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..2ff68d6 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkDataModels.Models; +using System.ComponentModel; + + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..102e7e9 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkDataModels.Enums; +using RenovationWorkDataModels.Models; +using System.ComponentModel; + + +namespace RenovationWorkContracts.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; } + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs new file mode 100644 index 0000000..9ba0548 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkDataModels.Models; +using System.ComponentModel; + +namespace RenovationWorkContracts.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(); + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs b/RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..a401b60 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/RenovationWork/RenovationWorkDataModels/IId.cs b/RenovationWork/RenovationWorkDataModels/IId.cs new file mode 100644 index 0000000..4718473 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/IId.cs @@ -0,0 +1,8 @@ +namespace RenovationWorkDataModels +{ + public interface IId + { + int Id { get; } + + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..852d354 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..7a2279d --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using RenovationWorkDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IOrderModel : IId + { + int RepairId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs new file mode 100644 index 0000000..19080ab --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IRepairModel : IId + { + string RepairName { get; } + double Price { get; } + Dictionary RepairComponents { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj b/RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/RenovationWork/RenovationWorkListImplement/DataListSingleton.cs b/RenovationWork/RenovationWorkListImplement/DataListSingleton.cs new file mode 100644 index 0000000..c1e46cf --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkListImplement.Models; + +namespace RenovationWorkListImplement +{ + 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/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..0f8848b --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,105 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; + +namespace RenovationWorkListImplement.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/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..004e189 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs @@ -0,0 +1,118 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; +using System.Reflection; + +namespace RenovationWorkListImplement.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) + { + OrderViewModel thisorder = order.GetViewModel; + Repair? repair = _source.Repairs.Find(x => x.Id == order.RepairId); + string repairName = repair?.RepairName ?? string.Empty; + thisorder.RepairName = repairName; + result.Add(thisorder); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(GetViewModel(order)); + } + 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)) + { + OrderViewModel thisorder = order.GetViewModel; + Repair? repair = _source.Repairs.Find(x => x.Id == order.RepairId); + string repairName = repair?.RepairName ?? string.Empty; + thisorder.RepairName = repairName; + return thisorder; + } + } + 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.Repairs.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var prod in _source.Repairs) + { + if (prod.Id == order.RepairId) + { + viewModel.RepairName = prod.RepairName; + break; + } + } + return viewModel; + } + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs new file mode 100644 index 0000000..2c34924 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; + +namespace RenovationWorkListImplement.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/RenovationWork/RenovationWorkListImplement/Models/Component.cs b/RenovationWork/RenovationWorkListImplement/Models/Component.cs new file mode 100644 index 0000000..e0f4f71 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; + +namespace RenovationWorkListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Models/Order.cs b/RenovationWork/RenovationWorkListImplement/Models/Order.cs new file mode 100644 index 0000000..b3d1069 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Order.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Enums; +using RenovationWorkDataModels.Models; + +namespace RenovationWorkListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int RepairId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + RepairId = model.RepairId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.DateImplement != null) + { + DateImplement = model.DateImplement; + } + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + RepairId = RepairId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} + diff --git a/RenovationWork/RenovationWorkListImplement/Models/Repair.cs b/RenovationWork/RenovationWorkListImplement/Models/Repair.cs new file mode 100644 index 0000000..e7c8739 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Repair.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; + +namespace RenovationWorkListImplement.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 + }; + } +} diff --git a/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj b/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj new file mode 100644 index 0000000..2d896a8 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + -- 2.25.1