From 59ddefed7fcd22d22834c59d17ca864415c8d085 Mon Sep 17 00:00:00 2001 From: "yuliya.mavrina@internet.ru" Date: Tue, 5 Mar 2024 18:28:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=5F1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RenovationWork/RenovationWork.sln | 49 ++++++ .../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 | 163 ++++++++++++++++++ RenovationWork/RenovationWork/FormMain.cs | 20 +++ RenovationWork/RenovationWork/FormMain.resx | 123 +++++++++++++ RenovationWork/RenovationWork/Program.cs | 48 ++++++ .../Properties/Resources.Designer.cs | 63 +++++++ .../RenovationWork/Properties/Resources.resx | 120 +++++++++++++ .../RenovationWork/RenovationWorkView.csproj | 40 +++++ 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 | 110 ++++++++++++ .../Implements/OrderStorage.cs | 112 ++++++++++++ .../Implements/RepairStorage.cs | 106 ++++++++++++ .../Models/Component.cs | 47 +++++ .../Models/Order.cs | 70 ++++++++ .../Models/Repair.cs | 54 ++++++ .../RenovationWorkListImplement.csproj | 14 ++ 52 files changed, 2987 insertions(+) create mode 100644 RenovationWork/RenovationWork.sln 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/Program.cs create mode 100644 RenovationWork/RenovationWork/Properties/Resources.Designer.cs create mode 100644 RenovationWork/RenovationWork/Properties/Resources.resx 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 new file mode 100644 index 0000000..5b85026 --- /dev/null +++ b/RenovationWork/RenovationWork.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkView", "RenovationWork\RenovationWorkView.csproj", "{F7DA64D8-ACE1-4703-906A-A25CBD36F7BE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkDataModels", "RenovationWorkDataModels\RenovationWorkDataModels.csproj", "{7B3260AB-0375-4F6A-A1E1-E74228E20DAA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkContracts", "RenovationWorkContracts\RenovationWorkContracts.csproj", "{933A8F36-3513-48F4-848A-635597FDFE1C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkBusinessLogic", "RenovationWorkBusinessLogic\RenovationWorkBusinessLogic.csproj", "{F7FB3E21-1E5E-4271-A22B-53B0E40E1F95}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkListImplement", "RenovationWorkListImplement\RenovationWorkListImplement.csproj", "{5F454425-8555-4E69-A0EC-0EEC94309A06}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F7DA64D8-ACE1-4703-906A-A25CBD36F7BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7DA64D8-ACE1-4703-906A-A25CBD36F7BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7DA64D8-ACE1-4703-906A-A25CBD36F7BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7DA64D8-ACE1-4703-906A-A25CBD36F7BE}.Release|Any CPU.Build.0 = Release|Any CPU + {7B3260AB-0375-4F6A-A1E1-E74228E20DAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B3260AB-0375-4F6A-A1E1-E74228E20DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B3260AB-0375-4F6A-A1E1-E74228E20DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B3260AB-0375-4F6A-A1E1-E74228E20DAA}.Release|Any CPU.Build.0 = Release|Any CPU + {933A8F36-3513-48F4-848A-635597FDFE1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {933A8F36-3513-48F4-848A-635597FDFE1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {933A8F36-3513-48F4-848A-635597FDFE1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {933A8F36-3513-48F4-848A-635597FDFE1C}.Release|Any CPU.Build.0 = Release|Any CPU + {F7FB3E21-1E5E-4271-A22B-53B0E40E1F95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7FB3E21-1E5E-4271-A22B-53B0E40E1F95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7FB3E21-1E5E-4271-A22B-53B0E40E1F95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7FB3E21-1E5E-4271-A22B-53B0E40E1F95}.Release|Any CPU.Build.0 = Release|Any CPU + {5F454425-8555-4E69-A0EC-0EEC94309A06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F454425-8555-4E69-A0EC-0EEC94309A06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F454425-8555-4E69-A0EC-0EEC94309A06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F454425-8555-4E69-A0EC-0EEC94309A06}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {91A58B52-1154-47F4-BD3F-13132A90EEB2} + EndGlobalSection +EndGlobal 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..39b0859 --- /dev/null +++ b/RenovationWork/RenovationWork/FormMain.Designer.cs @@ -0,0 +1,163 @@ +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(); + dataGridView1 = new DataGridView(); + button1 = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + button5 = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { refbooksToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(809, 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(180, 22); + componentsToolStripMenuItem.Text = "Компоненты"; + // + // JobTypeToolStripMenuItem + // + JobTypeToolStripMenuItem.Name = "JobTypeToolStripMenuItem"; + JobTypeToolStripMenuItem.Size = new Size(180, 22); + JobTypeToolStripMenuItem.Text = "Вид работы"; + // + // dataGridView1 + // + dataGridView1.BackgroundColor = SystemColors.ControlLightLight; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 27); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowTemplate.Height = 25; + dataGridView1.Size = new Size(654, 331); + dataGridView1.TabIndex = 1; + // + // button1 + // + button1.Location = new Point(672, 42); + button1.Name = "button1"; + button1.Size = new Size(128, 23); + button1.TabIndex = 2; + button1.Text = "button1"; + button1.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(672, 81); + button2.Name = "button2"; + button2.Size = new Size(128, 23); + button2.TabIndex = 3; + button2.Text = "button2"; + button2.UseVisualStyleBackColor = true; + // + // button3 + // + button3.Location = new Point(672, 120); + button3.Name = "button3"; + button3.Size = new Size(128, 23); + button3.TabIndex = 4; + button3.Text = "button3"; + button3.UseVisualStyleBackColor = true; + // + // button4 + // + button4.Location = new Point(672, 159); + button4.Name = "button4"; + button4.Size = new Size(128, 23); + button4.TabIndex = 5; + button4.Text = "button4"; + button4.UseVisualStyleBackColor = true; + // + // button5 + // + button5.Location = new Point(672, 197); + button5.Name = "button5"; + button5.Size = new Size(128, 23); + button5.TabIndex = 6; + button5.Text = "button5"; + button5.UseVisualStyleBackColor = true; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(809, 370); + Controls.Add(button5); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(dataGridView1); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Ремонтные работы"; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem refbooksToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem JobTypeToolStripMenuItem; + private DataGridView dataGridView1; + private Button button1; + private Button button2; + private Button button3; + private Button button4; + private Button button5; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormMain.cs b/RenovationWork/RenovationWork/FormMain.cs new file mode 100644 index 0000000..08c569c --- /dev/null +++ b/RenovationWork/RenovationWork/FormMain.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RenovationWorkView +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + } + } +} 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/Program.cs b/RenovationWork/RenovationWork/Program.cs new file mode 100644 index 0000000..419c2af --- /dev/null +++ b/RenovationWork/RenovationWork/Program.cs @@ -0,0 +1,48 @@ +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 + { + 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(); + 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/Properties/Resources.resx b/RenovationWork/RenovationWork/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWork/Properties/Resources.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/RenovationWorkView.csproj b/RenovationWork/RenovationWork/RenovationWorkView.csproj new file mode 100644 index 0000000..f6aa5a9 --- /dev/null +++ b/RenovationWork/RenovationWork/RenovationWorkView.csproj @@ -0,0 +1,40 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ 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..10fb863 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +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 ComponentStorage : IComponentStorage + { + private readonly Models.Component _source; + public ComponentStorage() + { + _source = Models.Component.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 = System.ComponentModel.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..82029ae --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs @@ -0,0 +1,112 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; + +namespace RenovationWorkListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly Component _source; + public OrderStorage() + { + _source = Component.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(); + if (model.Id.HasValue) + { + return result; + } + 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; + result.Add(thisorder); + } + } + 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; + } + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs new file mode 100644 index 0000000..f5db68c --- /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 Component _source; + public RepairStorage() + { + _source = Component.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 + + + + + + + +