From 24d535afbf21b65fcb4abae72273bda020b44ff4 Mon Sep 17 00:00:00 2001 From: ker73rus Date: Thu, 9 Mar 2023 08:39:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Secure/BusinessLogic/Class1.cs | 7 - .../IceCreamShop/FormCreateOrder.Designer.cs | 152 +++++++++++ Secure/IceCreamShop/FormCreateOrder.cs | 118 +++++++++ Secure/IceCreamShop/FormCreateOrder.resx | 60 +++++ Secure/IceCreamShop/FormFacilitie.Designer.cs | 124 +++++++++ Secure/IceCreamShop/FormFacilitie.cs | 86 ++++++ Secure/IceCreamShop/FormFacilitie.resx | 60 +++++ .../IceCreamShop/FormFacilities.Designer.cs | 121 +++++++++ Secure/IceCreamShop/FormFacilities.cs | 105 ++++++++ Secure/IceCreamShop/FormFacilities.resx | 60 +++++ Secure/IceCreamShop/FormMain.Designer.cs | 184 +++++++++++++ Secure/IceCreamShop/FormMain.cs | 158 +++++++++++ Secure/IceCreamShop/FormMain.resx | 63 +++++ Secure/IceCreamShop/FormSecure.Designer.cs | 245 ++++++++++++++++++ Secure/IceCreamShop/FormSecure.cs | 213 +++++++++++++++ Secure/IceCreamShop/FormSecure.resx | 60 +++++ .../FormSecureFacilities.Designer.cs | 125 +++++++++ Secure/IceCreamShop/FormSecureFacilities.cs | 86 ++++++ Secure/IceCreamShop/FormSecureFacilities.resx | 60 +++++ Secure/IceCreamShop/FormSecures.Designer.cs | 121 +++++++++ Secure/IceCreamShop/FormSecures.cs | 106 ++++++++ Secure/IceCreamShop/FormSecures.resx | 60 +++++ Secure/IceCreamShop/Program.cs | 52 ++++ Secure/IceCreamShop/SecureShopView.csproj | 23 ++ .../BusinessLogics/FacilitiesLogic.cs | 114 ++++++++ .../BusinessLogics/OrderLogic.cs | 126 +++++++++ .../BusinessLogics/SecureLogic.cs | 114 ++++++++ .../SecureShopBusinessLogic.csproj | 2 +- .../BindingModels/FacilitiesBindingModel.cs} | 6 +- .../BindingModels/OrderBindingModel.cs | 10 +- .../BindingModels/SecureBindingModel.cs | 13 +- .../IFacilitiesLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 11 +- .../BusinessLogicsContracts/ISecureLogic.cs | 12 +- .../SearchModels/FacilitiesSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/SecureSearchModel.cs | 8 + .../SecureShopContracts.csproj | 4 +- .../StoragesContracts/IFacilitiesStorage.cs | 16 ++ .../StoragesContracts}/IOrderStorage.cs | 10 +- .../StoragesContracts}/ISecureStorage.cs | 9 +- .../ViewModels/FacilitiesViewModel.cs | 16 ++ .../ViewModels/OrderViewModel.cs | 19 +- .../ViewModels/SecureViewModel.cs | 19 +- .../Enums}/OrderStatus.cs | 11 +- Secure/IceCreamShopDataModels/IId.cs | 7 + .../Models/IFacilitiesModel.cs | 8 + .../Models/IOrderModel.cs | 11 +- .../Models/ISecureModel.cs | 9 + .../SecureShopDataModels.csproj} | 0 .../DataListSingleton.cs | 17 +- .../Implements/FacilitiesStorage.cs | 107 ++++++++ .../Implements/OrderStorage.cs | 121 +++++++++ .../Implements/SecureStorage.cs | 107 ++++++++ .../Models/Facilities.cs} | 22 +- .../IceCreamShopListImplement/Models/Order.cs | 61 +++++ .../Models/Secure.cs | 28 +- .../SecureShopListImplement.csproj | 4 +- Secure/Secure.sln | 49 ---- Secure/Secure/Form1.Designer.cs | 39 --- Secure/Secure/Form1.cs | 10 - Secure/Secure/Form1.resx | 120 --------- Secure/Secure/Program.cs | 17 -- Secure/Secure/Secure.csproj | 11 - Secure/SecureShop.sln | 49 ++++ .../BusinessLogic/ComponentLogic.cs | 111 -------- .../SecureShopContracts.sln | 25 -- .../IComponentLogic.cs | 21 -- .../SearchModels/ComponentSearchModel.cs | 14 - .../SearchModels/OrderSearchModel.cs | 13 - .../SearchModels/SecureSearchModel.cs | 14 - .../StorageContracts/IComponentStorage.cs | 22 -- .../ViewModels/ComponentViewModel.cs | 19 -- .../SecureShopDataModels.sln | 25 -- .../SecureShopDataModels/IId.cs | 7 - .../Models/IComponentModel.cs | 14 - .../Models/ISecureModel.cs | 16 -- .../SecureShopDataModels.csproj | 9 - .../SecureShopListImplement/Models/Order.cs | 12 - 79 files changed, 3408 insertions(+), 710 deletions(-) delete mode 100644 Secure/BusinessLogic/Class1.cs create mode 100644 Secure/IceCreamShop/FormCreateOrder.Designer.cs create mode 100644 Secure/IceCreamShop/FormCreateOrder.cs create mode 100644 Secure/IceCreamShop/FormCreateOrder.resx create mode 100644 Secure/IceCreamShop/FormFacilitie.Designer.cs create mode 100644 Secure/IceCreamShop/FormFacilitie.cs create mode 100644 Secure/IceCreamShop/FormFacilitie.resx create mode 100644 Secure/IceCreamShop/FormFacilities.Designer.cs create mode 100644 Secure/IceCreamShop/FormFacilities.cs create mode 100644 Secure/IceCreamShop/FormFacilities.resx create mode 100644 Secure/IceCreamShop/FormMain.Designer.cs create mode 100644 Secure/IceCreamShop/FormMain.cs create mode 100644 Secure/IceCreamShop/FormMain.resx create mode 100644 Secure/IceCreamShop/FormSecure.Designer.cs create mode 100644 Secure/IceCreamShop/FormSecure.cs create mode 100644 Secure/IceCreamShop/FormSecure.resx create mode 100644 Secure/IceCreamShop/FormSecureFacilities.Designer.cs create mode 100644 Secure/IceCreamShop/FormSecureFacilities.cs create mode 100644 Secure/IceCreamShop/FormSecureFacilities.resx create mode 100644 Secure/IceCreamShop/FormSecures.Designer.cs create mode 100644 Secure/IceCreamShop/FormSecures.cs create mode 100644 Secure/IceCreamShop/FormSecures.resx create mode 100644 Secure/IceCreamShop/Program.cs create mode 100644 Secure/IceCreamShop/SecureShopView.csproj create mode 100644 Secure/IceCreamShopBusinessLogic/BusinessLogics/FacilitiesLogic.cs create mode 100644 Secure/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 Secure/IceCreamShopBusinessLogic/BusinessLogics/SecureLogic.cs rename Secure/{SecureShopBusinessLogic => IceCreamShopBusinessLogic}/SecureShopBusinessLogic.csproj (77%) rename Secure/{SecureShopContracts/SecureShopContracts/BindingModels/ComponentBindingModel.cs => IceCreamShopContracts/BindingModels/FacilitiesBindingModel.cs} (57%) rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/BindingModels/OrderBindingModel.cs (76%) rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/BindingModels/SecureBindingModel.cs (53%) create mode 100644 Secure/IceCreamShopContracts/BusinessLogicsContracts/IFacilitiesLogic.cs rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/BusinessLogicsContracts/IOrderLogic.cs (64%) rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/BusinessLogicsContracts/ISecureLogic.cs (66%) create mode 100644 Secure/IceCreamShopContracts/SearchModels/FacilitiesSearchModel.cs create mode 100644 Secure/IceCreamShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 Secure/IceCreamShopContracts/SearchModels/SecureSearchModel.cs rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/SecureShopContracts.csproj (57%) create mode 100644 Secure/IceCreamShopContracts/StoragesContracts/IFacilitiesStorage.cs rename Secure/{SecureShopContracts/SecureShopContracts/StorageContracts => IceCreamShopContracts/StoragesContracts}/IOrderStorage.cs (75%) rename Secure/{SecureShopContracts/SecureShopContracts/StorageContracts => IceCreamShopContracts/StoragesContracts}/ISecureStorage.cs (76%) create mode 100644 Secure/IceCreamShopContracts/ViewModels/FacilitiesViewModel.cs rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/ViewModels/OrderViewModel.cs (81%) rename Secure/{SecureShopContracts/SecureShopContracts => IceCreamShopContracts}/ViewModels/SecureViewModel.cs (52%) rename Secure/{SecureShopDataModels/SecureShopDataModels/Enum => IceCreamShopDataModels/Enums}/OrderStatus.cs (53%) create mode 100644 Secure/IceCreamShopDataModels/IId.cs create mode 100644 Secure/IceCreamShopDataModels/Models/IFacilitiesModel.cs rename Secure/{SecureShopDataModels/SecureShopDataModels => IceCreamShopDataModels}/Models/IOrderModel.cs (56%) create mode 100644 Secure/IceCreamShopDataModels/Models/ISecureModel.cs rename Secure/{BusinessLogic/BusinessLogic.csproj => IceCreamShopDataModels/SecureShopDataModels.csproj} (100%) rename Secure/{SecureShopListImplement => IceCreamShopListImplement}/DataListSingleton.cs (63%) create mode 100644 Secure/IceCreamShopListImplement/Implements/FacilitiesStorage.cs create mode 100644 Secure/IceCreamShopListImplement/Implements/OrderStorage.cs create mode 100644 Secure/IceCreamShopListImplement/Implements/SecureStorage.cs rename Secure/{SecureShopListImplement/Models/Component.cs => IceCreamShopListImplement/Models/Facilities.cs} (56%) create mode 100644 Secure/IceCreamShopListImplement/Models/Order.cs rename Secure/{SecureShopListImplement => IceCreamShopListImplement}/Models/Secure.cs (64%) rename Secure/{SecureShopListImplement => IceCreamShopListImplement}/SecureShopListImplement.csproj (52%) delete mode 100644 Secure/Secure.sln delete mode 100644 Secure/Secure/Form1.Designer.cs delete mode 100644 Secure/Secure/Form1.cs delete mode 100644 Secure/Secure/Form1.resx delete mode 100644 Secure/Secure/Program.cs delete mode 100644 Secure/Secure/Secure.csproj create mode 100644 Secure/SecureShop.sln delete mode 100644 Secure/SecureShopBusinessLogic/BusinessLogic/ComponentLogic.cs delete mode 100644 Secure/SecureShopContracts/SecureShopContracts.sln delete mode 100644 Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IComponentLogic.cs delete mode 100644 Secure/SecureShopContracts/SecureShopContracts/SearchModels/ComponentSearchModel.cs delete mode 100644 Secure/SecureShopContracts/SecureShopContracts/SearchModels/OrderSearchModel.cs delete mode 100644 Secure/SecureShopContracts/SecureShopContracts/SearchModels/SecureSearchModel.cs delete mode 100644 Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IComponentStorage.cs delete mode 100644 Secure/SecureShopContracts/SecureShopContracts/ViewModels/ComponentViewModel.cs delete mode 100644 Secure/SecureShopDataModels/SecureShopDataModels.sln delete mode 100644 Secure/SecureShopDataModels/SecureShopDataModels/IId.cs delete mode 100644 Secure/SecureShopDataModels/SecureShopDataModels/Models/IComponentModel.cs delete mode 100644 Secure/SecureShopDataModels/SecureShopDataModels/Models/ISecureModel.cs delete mode 100644 Secure/SecureShopDataModels/SecureShopDataModels/SecureShopDataModels.csproj delete mode 100644 Secure/SecureShopListImplement/Models/Order.cs diff --git a/Secure/BusinessLogic/Class1.cs b/Secure/BusinessLogic/Class1.cs deleted file mode 100644 index 67ecd1e..0000000 --- a/Secure/BusinessLogic/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace BusinessLogic -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormCreateOrder.Designer.cs b/Secure/IceCreamShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..37d1545 --- /dev/null +++ b/Secure/IceCreamShop/FormCreateOrder.Designer.cs @@ -0,0 +1,152 @@ +namespace SecureShopView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxSecure = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 18); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(136, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Система безопасности:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 53); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 87); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxSecure + // + this.comboBoxSecure.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSecure.FormattingEnabled = true; + this.comboBoxSecure.Location = new System.Drawing.Point(150, 15); + this.comboBoxSecure.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxSecure.Name = "comboBoxSecure"; + this.comboBoxSecure.Size = new System.Drawing.Size(230, 23); + this.comboBoxSecure.TabIndex = 3; + this.comboBoxSecure.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSecure_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(150, 50); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Enabled = false; + this.textBoxSum.Location = new System.Drawing.Point(150, 84); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(230, 23); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(209, 123); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(297, 123); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 159); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxSecure); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxSecure; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormCreateOrder.cs b/Secure/IceCreamShop/FormCreateOrder.cs new file mode 100644 index 0000000..976a10f --- /dev/null +++ b/Secure/IceCreamShop/FormCreateOrder.cs @@ -0,0 +1,118 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SecureShopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logicI; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, ISecureLogic logicI, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка мороженого для заказа"); + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxSecure.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSecure.SelectedValue); + var Secure = _logicI.ReadElement(new SecureSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Secure?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxSecure_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + SecureId = Convert.ToInt32(comboBoxSecure.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(); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormCreateOrder.resx b/Secure/IceCreamShop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/IceCreamShop/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/FormFacilitie.Designer.cs b/Secure/IceCreamShop/FormFacilitie.Designer.cs new file mode 100644 index 0000000..bae7c9d --- /dev/null +++ b/Secure/IceCreamShop/FormFacilitie.Designer.cs @@ -0,0 +1,124 @@ +namespace SecureShopView +{ + partial class FormFacilitie + { + /// + /// 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.labelFacilitiesName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelFacilitiesName + // + this.labelFacilitiesName.AutoSize = true; + this.labelFacilitiesName.Location = new System.Drawing.Point(27, 14); + this.labelFacilitiesName.Name = "labelFacilitiesName"; + this.labelFacilitiesName.Size = new System.Drawing.Size(62, 15); + this.labelFacilitiesName.TabIndex = 0; + this.labelFacilitiesName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(27, 73); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(127, 12); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(263, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(127, 70); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(128, 23); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(127, 116); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(254, 116); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormFacilitie + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(454, 155); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelFacilitiesName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormFacilitie"; + this.Text = "Оборудование"; + this.Load += new System.EventHandler(this.FormFacilities_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFacilitiesName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormFacilitie.cs b/Secure/IceCreamShop/FormFacilitie.cs new file mode 100644 index 0000000..5ad3343 --- /dev/null +++ b/Secure/IceCreamShop/FormFacilitie.cs @@ -0,0 +1,86 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SecureShopView +{ + public partial class FormFacilitie : Form + { + private readonly ILogger _logger; + private readonly IFacilitiesLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormFacilitie(ILogger logger, IFacilitiesLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormFacilities_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение добавки"); + var view = _logic.ReadElement(new FacilitiesSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.FacilitiesName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения добавки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение добавки"); + try + { + var model = new FacilitiesBindingModel + { + Id = _id ?? 0, + FacilitiesName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения добавки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormFacilitie.resx b/Secure/IceCreamShop/FormFacilitie.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/IceCreamShop/FormFacilitie.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/FormFacilities.Designer.cs b/Secure/IceCreamShop/FormFacilities.Designer.cs new file mode 100644 index 0000000..a05e816 --- /dev/null +++ b/Secure/IceCreamShop/FormFacilities.Designer.cs @@ -0,0 +1,121 @@ +namespace SecureShopView +{ + partial class FormFacilitiess + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(444, 320); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(471, 9); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(133, 22); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(471, 35); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(133, 22); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(471, 62); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(133, 22); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(471, 88); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(133, 22); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormFacilitiess + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 338); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormFacilitiess"; + this.Text = "Оборудования"; + this.Load += new System.EventHandler(this.FormFacilitiess_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormFacilities.cs b/Secure/IceCreamShop/FormFacilities.cs new file mode 100644 index 0000000..3fc4b6a --- /dev/null +++ b/Secure/IceCreamShop/FormFacilities.cs @@ -0,0 +1,105 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SecureShopView +{ + public partial class FormFacilitiess : Form + { + private readonly ILogger _logger; + private readonly IFacilitiesLogic _logic; + + public FormFacilitiess(ILogger logger, IFacilitiesLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormFacilitiess_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["FacilitiesName"].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(FormFacilitie)); + if (service is FormFacilitie 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(FormFacilitie)); + if (service is FormFacilitie 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 FacilitiesBindingModel + { + 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(); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormFacilities.resx b/Secure/IceCreamShop/FormFacilities.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/IceCreamShop/FormFacilities.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/FormMain.Designer.cs b/Secure/IceCreamShop/FormMain.Designer.cs new file mode 100644 index 0000000..28f2dc4 --- /dev/null +++ b/Secure/IceCreamShop/FormMain.Designer.cs @@ -0,0 +1,184 @@ +namespace SecureShopView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.FacilitiessToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SecuresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip.Size = new System.Drawing.Size(997, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "Справочники"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.FacilitiessToolStripMenuItem, + this.SecuresToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // FacilitiessToolStripMenuItem + // + this.FacilitiessToolStripMenuItem.Name = "FacilitiessToolStripMenuItem"; + this.FacilitiessToolStripMenuItem.Size = new System.Drawing.Size(200, 22); + this.FacilitiessToolStripMenuItem.Text = "Оборудование"; + this.FacilitiessToolStripMenuItem.Click += new System.EventHandler(this.FacilitiessToolStripMenuItem_Click); + // + // SecuresToolStripMenuItem + // + this.SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem"; + this.SecuresToolStripMenuItem.Size = new System.Drawing.Size(200, 22); + this.SecuresToolStripMenuItem.Text = "Система Безопасности"; + this.SecuresToolStripMenuItem.Click += new System.EventHandler(this.SecuresToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 23); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(801, 305); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(816, 34); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 22); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(816, 60); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(170, 22); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(816, 86); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(170, 22); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(816, 112); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(170, 22); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(816, 138); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(170, 22); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(997, 338); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormMain"; + this.Text = "Магазин систем безопасности"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem FacilitiessToolStripMenuItem; + private ToolStripMenuItem SecuresToolStripMenuItem; + 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/Secure/IceCreamShop/FormMain.cs b/Secure/IceCreamShop/FormMain.cs new file mode 100644 index 0000000..c32a6f6 --- /dev/null +++ b/Secure/IceCreamShop/FormMain.cs @@ -0,0 +1,158 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace SecureShopView +{ + 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() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["SecureId"].Visible = false; + dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FacilitiessToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFacilitiess)); + if (service is FormFacilitiess form) + { + form.ShowDialog(); + } + } + + private void SecuresToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecures)); + if (service is FormSecures 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.OrderReady(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.IssuedOrder(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(); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormMain.resx b/Secure/IceCreamShop/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/Secure/IceCreamShop/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecure.Designer.cs b/Secure/IceCreamShop/FormSecure.Designer.cs new file mode 100644 index 0000000..45a7a5d --- /dev/null +++ b/Secure/IceCreamShop/FormSecure.Designer.cs @@ -0,0 +1,245 @@ +namespace SecureShopView +{ + partial class FormSecure + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxFacilitiess = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnFacilitiesName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxFacilitiess.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 7); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(10, 34); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(70, 15); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(86, 4); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(86, 29); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(138, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxFacilitiess + // + this.groupBoxFacilitiess.Controls.Add(this.buttonRef); + this.groupBoxFacilitiess.Controls.Add(this.buttonDel); + this.groupBoxFacilitiess.Controls.Add(this.buttonUpd); + this.groupBoxFacilitiess.Controls.Add(this.buttonAdd); + this.groupBoxFacilitiess.Controls.Add(this.dataGridView); + this.groupBoxFacilitiess.Location = new System.Drawing.Point(13, 62); + this.groupBoxFacilitiess.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxFacilitiess.Name = "groupBoxFacilitiess"; + this.groupBoxFacilitiess.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxFacilitiess.Size = new System.Drawing.Size(612, 206); + this.groupBoxFacilitiess.TabIndex = 4; + this.groupBoxFacilitiess.TabStop = false; + this.groupBoxFacilitiess.Text = "Оборудование"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(456, 98); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(136, 22); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(456, 72); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(136, 22); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(456, 46); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(136, 22); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(456, 20); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(136, 22); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnFacilitiesName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(429, 182); + this.dataGridView.TabIndex = 0; + this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(312, 284); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(136, 22); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(469, 284); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(136, 22); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // ColumnFacilitiesName + // + this.ColumnFacilitiesName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnFacilitiesName.HeaderText = "Оборудование"; + this.ColumnFacilitiesName.MinimumWidth = 6; + this.ColumnFacilitiesName.Name = "ColumnFacilitiesName"; + this.ColumnFacilitiesName.Resizable = System.Windows.Forms.DataGridViewTriState.True; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // FormSecure + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(635, 320); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxFacilitiess); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormSecure"; + this.Text = "Система безопасности"; + this.Load += new System.EventHandler(this.FormSecure_Load); + this.groupBoxFacilitiess.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxFacilitiess; + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnFacilitiesName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecure.cs b/Secure/IceCreamShop/FormSecure.cs new file mode 100644 index 0000000..c1fb1bb --- /dev/null +++ b/Secure/IceCreamShop/FormSecure.cs @@ -0,0 +1,213 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using SecureShopDataModels.Models; +using Microsoft.Extensions.Logging; + + +namespace SecureShopView +{ + public partial class FormSecure : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logic; + private int? _id; + private Dictionary _SecureFacilitiess; + public int Id { set { _id = value; } } + + public FormSecure(ILogger logger, ISecureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _SecureFacilitiess = new Dictionary(); + } + + private void FormSecure_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка мороженого"); + try + { + var view = _logic.ReadElement(new SecureSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.SecureName; + textBoxPrice.Text = view.Price.ToString(); + _SecureFacilitiess = view.SecureFacilitiess ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка добавок мороженого"); + try + { + if (_SecureFacilitiess != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _SecureFacilitiess) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.FacilitiesName, element.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(FormSecureFacilities)); + if (service is FormSecureFacilities form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.FacilitiesModel == null) + { + return; + } + _logger.LogInformation("Добавление новой добавки: {FacilitiesName} - {Count}", form.FacilitiesModel.FacilitiesName, form.Count); + if (_SecureFacilitiess.ContainsKey(form.Id)) + { + _SecureFacilitiess[form.Id] = (form.FacilitiesModel, form.Count); + } + else + { + _SecureFacilitiess.Add(form.Id, (form.FacilitiesModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecureFacilities)); + if (service is FormSecureFacilities form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _SecureFacilitiess[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.FacilitiesModel == null) + { + return; + } + _logger.LogInformation("Изменение добавки: {FacilitiesName} - {Count}", form.FacilitiesModel.FacilitiesName, form.Count); + _SecureFacilitiess[form.Id] = (form.FacilitiesModel, 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("Удаление добавки:{FacilitiesName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _SecureFacilitiess?.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 (_SecureFacilitiess == null || _SecureFacilitiess.Count == 0) + { + MessageBox.Show("Заполните добавки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение мороженого"); + try + { + var model = new SecureBindingModel + { + Id = _id ?? 0, + SecureName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SecureFacilitiess = _SecureFacilitiess + }; + 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 _SecureFacilitiess) + { + price += (elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2; + } + return Math.Round(price * 1.1, 2); + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecure.resx b/Secure/IceCreamShop/FormSecure.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/IceCreamShop/FormSecure.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecureFacilities.Designer.cs b/Secure/IceCreamShop/FormSecureFacilities.Designer.cs new file mode 100644 index 0000000..97e6637 --- /dev/null +++ b/Secure/IceCreamShop/FormSecureFacilities.Designer.cs @@ -0,0 +1,125 @@ +namespace SecureShopView +{ + partial class FormSecureFacilities + { + /// + /// 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.labelFacilities = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxFacilities = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelFacilities + // + this.labelFacilities.AutoSize = true; + this.labelFacilities.Location = new System.Drawing.Point(22, 20); + this.labelFacilities.Name = "labelFacilities"; + this.labelFacilities.Size = new System.Drawing.Size(92, 15); + this.labelFacilities.TabIndex = 0; + this.labelFacilities.Text = "Обородование:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(22, 70); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxFacilities + // + this.comboBoxFacilities.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxFacilities.FormattingEnabled = true; + this.comboBoxFacilities.Location = new System.Drawing.Point(128, 20); + this.comboBoxFacilities.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxFacilities.Name = "comboBoxFacilities"; + this.comboBoxFacilities.Size = new System.Drawing.Size(282, 23); + this.comboBoxFacilities.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(128, 68); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(282, 23); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(128, 111); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(125, 22); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(284, 111); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(125, 22); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSecureFacilities + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(447, 142); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxFacilities); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelFacilities); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormSecureFacilities"; + this.Text = "Оборудование Системы безопасности"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFacilities; + private Label labelCount; + private ComboBox comboBoxFacilities; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecureFacilities.cs b/Secure/IceCreamShop/FormSecureFacilities.cs new file mode 100644 index 0000000..7802f98 --- /dev/null +++ b/Secure/IceCreamShop/FormSecureFacilities.cs @@ -0,0 +1,86 @@ +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.ViewModels; +using SecureShopDataModels.Models; + +namespace SecureShopView +{ + public partial class FormSecureFacilities : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxFacilities.SelectedValue); + } + set + { + comboBoxFacilities.SelectedValue = value; + } + } + public IFacilitiesModel? FacilitiesModel + { + 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 FormSecureFacilities(IFacilitiesLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxFacilities.DisplayMember = "FacilitiesName"; + comboBoxFacilities.ValueMember = "Id"; + comboBoxFacilities.DataSource = _list; + comboBoxFacilities.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxFacilities.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(); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecureFacilities.resx b/Secure/IceCreamShop/FormSecureFacilities.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/IceCreamShop/FormSecureFacilities.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecures.Designer.cs b/Secure/IceCreamShop/FormSecures.Designer.cs new file mode 100644 index 0000000..1d772f7 --- /dev/null +++ b/Secure/IceCreamShop/FormSecures.Designer.cs @@ -0,0 +1,121 @@ +namespace SecureShopView +{ + partial class FormSecures + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(444, 320); + this.dataGridView.TabIndex = 1; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(466, 9); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(133, 22); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(466, 35); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(133, 22); + this.buttonUpd.TabIndex = 3; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(466, 62); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(133, 22); + this.buttonDel.TabIndex = 4; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(466, 88); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(133, 22); + this.buttonRef.TabIndex = 5; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormSecures + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(610, 338); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormSecures"; + this.Text = "Системы безопасности"; + this.Load += new System.EventHandler(this.FormSecures_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecures.cs b/Secure/IceCreamShop/FormSecures.cs new file mode 100644 index 0000000..a4be9b1 --- /dev/null +++ b/Secure/IceCreamShop/FormSecures.cs @@ -0,0 +1,106 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SecureShopView +{ + public partial class FormSecures : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logic; + + public FormSecures(ILogger logger, ISecureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormSecures_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["SecureFacilitiess"].Visible = false; + dataGridView.Columns["SecureName"].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(FormSecure)); + if (service is FormSecure 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(FormSecure)); + if (service is FormSecure 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 SecureBindingModel + { + 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(); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShop/FormSecures.resx b/Secure/IceCreamShop/FormSecures.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/IceCreamShop/FormSecures.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Secure/IceCreamShop/Program.cs b/Secure/IceCreamShop/Program.cs new file mode 100644 index 0000000..4b9efec --- /dev/null +++ b/Secure/IceCreamShop/Program.cs @@ -0,0 +1,52 @@ +using SecureShopBusinessLogic.BusinessLogics; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.StoragesContracts; +using SecureShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace SecureShopView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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/Secure/IceCreamShop/SecureShopView.csproj b/Secure/IceCreamShop/SecureShopView.csproj new file mode 100644 index 0000000..8ad1113 --- /dev/null +++ b/Secure/IceCreamShop/SecureShopView.csproj @@ -0,0 +1,23 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Secure/IceCreamShopBusinessLogic/BusinessLogics/FacilitiesLogic.cs b/Secure/IceCreamShopBusinessLogic/BusinessLogics/FacilitiesLogic.cs new file mode 100644 index 0000000..fb5f561 --- /dev/null +++ b/Secure/IceCreamShopBusinessLogic/BusinessLogics/FacilitiesLogic.cs @@ -0,0 +1,114 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SecureShopBusinessLogic.BusinessLogics +{ + public class FacilitiesLogic : IFacilitiesLogic + { + private readonly ILogger _logger; + private readonly IFacilitiesStorage _FacilitiesStorage; + + public FacilitiesLogic(ILogger logger, IFacilitiesStorage FacilitiesStorage) + { + _logger = logger; + _FacilitiesStorage = FacilitiesStorage; + } + + public List? ReadList(FacilitiesSearchModel? model) + { + _logger.LogInformation("ReadList. FacilitiesName:{FacilitiesName}. Id:{Id}", model?.FacilitiesName, model?.Id); + var list = model == null ? _FacilitiesStorage.GetFullList() : _FacilitiesStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public FacilitiesViewModel? ReadElement(FacilitiesSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FacilitiesName:{FacilitiesName}. Id:{Id}", model.FacilitiesName, model.Id); + var element = _FacilitiesStorage.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(FacilitiesBindingModel model) + { + CheckModel(model); + if (_FacilitiesStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(FacilitiesBindingModel model) + { + CheckModel(model); + if (_FacilitiesStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(FacilitiesBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_FacilitiesStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(FacilitiesBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FacilitiesName)) + { + throw new ArgumentNullException("Нет названия оборудования", nameof(model.FacilitiesName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена оборудования должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Facilities. FacilitiesName:{FacilitiesName}. Cost:{Cost}. Id: {Id}", model.FacilitiesName, model.Cost, model.Id); + var element = _FacilitiesStorage.GetElement(new FacilitiesSearchModel + { + FacilitiesName = model.FacilitiesName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Оборудование с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs b/Secure/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..bee862f --- /dev/null +++ b/Secure/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,126 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace SecureShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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.SecureId < 0) + { + throw new ArgumentNullException("Нет системы безопасности с таким ид", nameof(model.SecureId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество систем безопасности в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderId: {Id}. SecureId: {SecureId}. Count: {Count} Sum: {Sum}.", model.Id, model.SecureId, model.Count, model.Sum); + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus 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("Change status operation failed"); + return false; + } + model.Status = newStatus; + model.SecureId = viewModel.SecureId; + model.Count = viewModel.Count; + model.Sum = viewModel.Sum; + model.DateCreate = viewModel.DateCreate; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool IssuedOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + public bool OrderReady(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopBusinessLogic/BusinessLogics/SecureLogic.cs b/Secure/IceCreamShopBusinessLogic/BusinessLogics/SecureLogic.cs new file mode 100644 index 0000000..8407dee --- /dev/null +++ b/Secure/IceCreamShopBusinessLogic/BusinessLogics/SecureLogic.cs @@ -0,0 +1,114 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SecureShopBusinessLogic.BusinessLogics +{ + public class SecureLogic : ISecureLogic + { + private readonly ILogger _logger; + private readonly ISecureStorage _SecureStorage; + + public SecureLogic(ILogger logger, ISecureStorage SecureStorage) + { + _logger = logger; + _SecureStorage = SecureStorage; + } + + public List? ReadList(SecureSearchModel? model) + { + _logger.LogInformation("ReadList. SecureName:{SecureName}.Id:{Id}", model?.SecureName, model?.Id); + var list = model == null ? _SecureStorage.GetFullList() : _SecureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public SecureViewModel? ReadElement(SecureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. SecureName:{SecureName}. Id:{Id}", model.SecureName, model.Id); + var element = _SecureStorage.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(SecureBindingModel model) + { + CheckModel(model); + if (_SecureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(SecureBindingModel model) + { + CheckModel(model); + if (_SecureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(SecureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_SecureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(SecureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SecureName)) + { + throw new ArgumentNullException("Нет названия Сиситемы безопасности ", nameof(model.SecureName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена Сиситемы безопасности должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Secure. SecureName:{SecureName}. Cost:{Cost}. Id: {Id}", model.SecureName, model.Price, model.Id); + var element = _SecureStorage.GetElement(new SecureSearchModel + { + SecureName = model.SecureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Сиситема безопасности с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj b/Secure/IceCreamShopBusinessLogic/SecureShopBusinessLogic.csproj similarity index 77% rename from Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj rename to Secure/IceCreamShopBusinessLogic/SecureShopBusinessLogic.csproj index eba4ce4..900a1ba 100644 --- a/Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj +++ b/Secure/IceCreamShopBusinessLogic/SecureShopBusinessLogic.csproj @@ -11,7 +11,7 @@ - + diff --git a/Secure/SecureShopContracts/SecureShopContracts/BindingModels/ComponentBindingModel.cs b/Secure/IceCreamShopContracts/BindingModels/FacilitiesBindingModel.cs similarity index 57% rename from Secure/SecureShopContracts/SecureShopContracts/BindingModels/ComponentBindingModel.cs rename to Secure/IceCreamShopContracts/BindingModels/FacilitiesBindingModel.cs index fc54a4b..0ce1c64 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/BindingModels/ComponentBindingModel.cs +++ b/Secure/IceCreamShopContracts/BindingModels/FacilitiesBindingModel.cs @@ -1,11 +1,11 @@ using SecureShopDataModels.Models; + namespace SecureShopContracts.BindingModels { - public class ComponentBindingModel : IComponentModel + public class FacilitiesBindingModel : IFacilitiesModel { public int Id { get; set; } - public string ComponentName { get; set; } = string.Empty; + public string FacilitiesName { get; set; } = string.Empty; public double Cost { get; set; } } - } \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/BindingModels/OrderBindingModel.cs b/Secure/IceCreamShopContracts/BindingModels/OrderBindingModel.cs similarity index 76% rename from Secure/SecureShopContracts/SecureShopContracts/BindingModels/OrderBindingModel.cs rename to Secure/IceCreamShopContracts/BindingModels/OrderBindingModel.cs index 14ff0d9..3d41eac 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/BindingModels/OrderBindingModel.cs +++ b/Secure/IceCreamShopContracts/BindingModels/OrderBindingModel.cs @@ -1,10 +1,5 @@ -using SecureShopDataModels.Enum; +using SecureShopDataModels.Enums; using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopContracts.BindingModels { @@ -18,5 +13,4 @@ namespace SecureShopContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } } - -} +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/BindingModels/SecureBindingModel.cs b/Secure/IceCreamShopContracts/BindingModels/SecureBindingModel.cs similarity index 53% rename from Secure/SecureShopContracts/SecureShopContracts/BindingModels/SecureBindingModel.cs rename to Secure/IceCreamShopContracts/BindingModels/SecureBindingModel.cs index a554530..4943974 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/BindingModels/SecureBindingModel.cs +++ b/Secure/IceCreamShopContracts/BindingModels/SecureBindingModel.cs @@ -1,9 +1,4 @@ using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopContracts.BindingModels { @@ -12,10 +7,6 @@ namespace SecureShopContracts.BindingModels public int Id { get; set; } public string SecureName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary SecureComponents - { - get; - set; - } = new(); + public Dictionary SecureFacilitiess { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/Secure/IceCreamShopContracts/BusinessLogicsContracts/IFacilitiesLogic.cs b/Secure/IceCreamShopContracts/BusinessLogicsContracts/IFacilitiesLogic.cs new file mode 100644 index 0000000..247d141 --- /dev/null +++ b/Secure/IceCreamShopContracts/BusinessLogicsContracts/IFacilitiesLogic.cs @@ -0,0 +1,15 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.ViewModels; + +namespace SecureShopContracts.BusinessLogicsContracts +{ + public interface IFacilitiesLogic + { + List? ReadList(FacilitiesSearchModel? model); + FacilitiesViewModel? ReadElement(FacilitiesSearchModel model); + bool Create(FacilitiesBindingModel model); + bool Update(FacilitiesBindingModel model); + bool Delete(FacilitiesBindingModel model); + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/Secure/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs similarity index 64% rename from Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IOrderLogic.cs rename to Secure/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs index 0a12197..d94b990 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Secure/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,11 +1,6 @@ using SecureShopContracts.BindingModels; using SecureShopContracts.SearchModels; using SecureShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopContracts.BusinessLogicsContracts { @@ -14,7 +9,7 @@ namespace SecureShopContracts.BusinessLogicsContracts List? ReadList(OrderSearchModel? model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); - bool FinishOrder(OrderBindingModel model); - bool DeliveryOrder(OrderBindingModel model); + bool OrderReady(OrderBindingModel model); + bool IssuedOrder(OrderBindingModel model); } -} +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/ISecureLogic.cs b/Secure/IceCreamShopContracts/BusinessLogicsContracts/ISecureLogic.cs similarity index 66% rename from Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/ISecureLogic.cs rename to Secure/IceCreamShopContracts/BusinessLogicsContracts/ISecureLogic.cs index dfe728a..daf3e32 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/ISecureLogic.cs +++ b/Secure/IceCreamShopContracts/BusinessLogicsContracts/ISecureLogic.cs @@ -1,11 +1,6 @@ -using SecureShopContracts.SearchModels; -using SecureShopContracts.BindingModels; +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; using SecureShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopContracts.BusinessLogicsContracts { @@ -17,5 +12,4 @@ namespace SecureShopContracts.BusinessLogicsContracts bool Update(SecureBindingModel model); bool Delete(SecureBindingModel model); } - -} +} \ No newline at end of file diff --git a/Secure/IceCreamShopContracts/SearchModels/FacilitiesSearchModel.cs b/Secure/IceCreamShopContracts/SearchModels/FacilitiesSearchModel.cs new file mode 100644 index 0000000..67b00a0 --- /dev/null +++ b/Secure/IceCreamShopContracts/SearchModels/FacilitiesSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecureShopContracts.SearchModels +{ + public class FacilitiesSearchModel + { + public int? Id { get; set; } + public string? FacilitiesName { get; set; } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopContracts/SearchModels/OrderSearchModel.cs b/Secure/IceCreamShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..1b0edef --- /dev/null +++ b/Secure/IceCreamShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace SecureShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopContracts/SearchModels/SecureSearchModel.cs b/Secure/IceCreamShopContracts/SearchModels/SecureSearchModel.cs new file mode 100644 index 0000000..62cb02d --- /dev/null +++ b/Secure/IceCreamShopContracts/SearchModels/SecureSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecureShopContracts.SearchModels +{ + public class SecureSearchModel + { + public int? Id { get; set; } + public string? SecureName { get; set; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/SecureShopContracts.csproj b/Secure/IceCreamShopContracts/SecureShopContracts.csproj similarity index 57% rename from Secure/SecureShopContracts/SecureShopContracts/SecureShopContracts.csproj rename to Secure/IceCreamShopContracts/SecureShopContracts.csproj index ca641e5..035a757 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/SecureShopContracts.csproj +++ b/Secure/IceCreamShopContracts/SecureShopContracts.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/Secure/IceCreamShopContracts/StoragesContracts/IFacilitiesStorage.cs b/Secure/IceCreamShopContracts/StoragesContracts/IFacilitiesStorage.cs new file mode 100644 index 0000000..6f7c768 --- /dev/null +++ b/Secure/IceCreamShopContracts/StoragesContracts/IFacilitiesStorage.cs @@ -0,0 +1,16 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.ViewModels; + +namespace SecureShopContracts.StoragesContracts +{ + public interface IFacilitiesStorage + { + List GetFullList(); + List GetFilteredList(FacilitiesSearchModel model); + FacilitiesViewModel? GetElement(FacilitiesSearchModel model); + FacilitiesViewModel? Insert(FacilitiesBindingModel model); + FacilitiesViewModel? Update(FacilitiesBindingModel model); + FacilitiesViewModel? Delete(FacilitiesBindingModel model); + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IOrderStorage.cs b/Secure/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs similarity index 75% rename from Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IOrderStorage.cs rename to Secure/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs index 115d0cf..be918bf 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IOrderStorage.cs +++ b/Secure/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs @@ -1,13 +1,8 @@ using SecureShopContracts.BindingModels; using SecureShopContracts.SearchModels; using SecureShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace SecureShopContracts.StorageContracts +namespace SecureShopContracts.StoragesContracts { public interface IOrderStorage { @@ -18,5 +13,4 @@ namespace SecureShopContracts.StorageContracts OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); } - -} +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/ISecureStorage.cs b/Secure/IceCreamShopContracts/StoragesContracts/ISecureStorage.cs similarity index 76% rename from Secure/SecureShopContracts/SecureShopContracts/StorageContracts/ISecureStorage.cs rename to Secure/IceCreamShopContracts/StoragesContracts/ISecureStorage.cs index e5b1667..c32a91a 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/ISecureStorage.cs +++ b/Secure/IceCreamShopContracts/StoragesContracts/ISecureStorage.cs @@ -1,13 +1,8 @@ using SecureShopContracts.BindingModels; using SecureShopContracts.SearchModels; using SecureShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace SecureShopContracts.StorageContracts +namespace SecureShopContracts.StoragesContracts { public interface ISecureStorage { @@ -18,4 +13,4 @@ namespace SecureShopContracts.StorageContracts SecureViewModel? Update(SecureBindingModel model); SecureViewModel? Delete(SecureBindingModel model); } -} +} \ No newline at end of file diff --git a/Secure/IceCreamShopContracts/ViewModels/FacilitiesViewModel.cs b/Secure/IceCreamShopContracts/ViewModels/FacilitiesViewModel.cs new file mode 100644 index 0000000..515a48a --- /dev/null +++ b/Secure/IceCreamShopContracts/ViewModels/FacilitiesViewModel.cs @@ -0,0 +1,16 @@ +using SecureShopDataModels.Models; +using System.ComponentModel; + +namespace SecureShopContracts.ViewModels +{ + public class FacilitiesViewModel : IFacilitiesModel + { + public int Id { get; set; } + + [DisplayName("Название оборудования")] + public string FacilitiesName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts/ViewModels/OrderViewModel.cs b/Secure/IceCreamShopContracts/ViewModels/OrderViewModel.cs similarity index 81% rename from Secure/SecureShopContracts/SecureShopContracts/ViewModels/OrderViewModel.cs rename to Secure/IceCreamShopContracts/ViewModels/OrderViewModel.cs index 78debd1..cf26262 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/ViewModels/OrderViewModel.cs +++ b/Secure/IceCreamShopContracts/ViewModels/OrderViewModel.cs @@ -1,11 +1,6 @@ -using SecureShopDataModels.Enum; +using SecureShopDataModels.Enums; using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopContracts.ViewModels { @@ -13,19 +8,25 @@ namespace SecureShopContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int SecureId { get; set; } - [DisplayName("Изделие")] + + [DisplayName("Система безопасности")] public string SecureName { 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/Secure/SecureShopContracts/SecureShopContracts/ViewModels/SecureViewModel.cs b/Secure/IceCreamShopContracts/ViewModels/SecureViewModel.cs similarity index 52% rename from Secure/SecureShopContracts/SecureShopContracts/ViewModels/SecureViewModel.cs rename to Secure/IceCreamShopContracts/ViewModels/SecureViewModel.cs index 3bdd90f..efe5bee 100644 --- a/Secure/SecureShopContracts/SecureShopContracts/ViewModels/SecureViewModel.cs +++ b/Secure/IceCreamShopContracts/ViewModels/SecureViewModel.cs @@ -1,25 +1,18 @@ using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopContracts.ViewModels { public class SecureViewModel : ISecureModel { public int Id { get; set; } - [DisplayName("Название изделия")] + + [DisplayName("Название Сиситемы безопасности")] public string SecureName { get; set; } = string.Empty; + [DisplayName("Цена")] public double Price { get; set; } - public Dictionary SecureComponents - { - get; - set; - } = new(); - } -} + public Dictionary SecureFacilitiess { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Secure/SecureShopDataModels/SecureShopDataModels/Enum/OrderStatus.cs b/Secure/IceCreamShopDataModels/Enums/OrderStatus.cs similarity index 53% rename from Secure/SecureShopDataModels/SecureShopDataModels/Enum/OrderStatus.cs rename to Secure/IceCreamShopDataModels/Enums/OrderStatus.cs index a84c87d..f213a70 100644 --- a/Secure/SecureShopDataModels/SecureShopDataModels/Enum/OrderStatus.cs +++ b/Secure/IceCreamShopDataModels/Enums/OrderStatus.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopDataModels.Enum +namespace SecureShopDataModels.Enums { public enum OrderStatus { @@ -13,6 +7,5 @@ namespace SecureShopDataModels.Enum Выполняется = 1, Готов = 2, Выдан = 3 - } -} +} \ No newline at end of file diff --git a/Secure/IceCreamShopDataModels/IId.cs b/Secure/IceCreamShopDataModels/IId.cs new file mode 100644 index 0000000..37f7216 --- /dev/null +++ b/Secure/IceCreamShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace SecureShopDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopDataModels/Models/IFacilitiesModel.cs b/Secure/IceCreamShopDataModels/Models/IFacilitiesModel.cs new file mode 100644 index 0000000..0005f0d --- /dev/null +++ b/Secure/IceCreamShopDataModels/Models/IFacilitiesModel.cs @@ -0,0 +1,8 @@ +namespace SecureShopDataModels.Models +{ + public interface IFacilitiesModel : IId + { + string FacilitiesName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopDataModels/SecureShopDataModels/Models/IOrderModel.cs b/Secure/IceCreamShopDataModels/Models/IOrderModel.cs similarity index 56% rename from Secure/SecureShopDataModels/SecureShopDataModels/Models/IOrderModel.cs rename to Secure/IceCreamShopDataModels/Models/IOrderModel.cs index 16aa42c..4f81c80 100644 --- a/Secure/SecureShopDataModels/SecureShopDataModels/Models/IOrderModel.cs +++ b/Secure/IceCreamShopDataModels/Models/IOrderModel.cs @@ -1,13 +1,8 @@ -using SecureShopDataModels.Enum; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using SecureShopDataModels.Enums; namespace SecureShopDataModels.Models { - public interface IOrderModel:IId + public interface IOrderModel : IId { int SecureId { get; } int Count { get; } @@ -16,4 +11,4 @@ namespace SecureShopDataModels.Models DateTime DateCreate { get; } DateTime? DateImplement { get; } } -} +} \ No newline at end of file diff --git a/Secure/IceCreamShopDataModels/Models/ISecureModel.cs b/Secure/IceCreamShopDataModels/Models/ISecureModel.cs new file mode 100644 index 0000000..367dedc --- /dev/null +++ b/Secure/IceCreamShopDataModels/Models/ISecureModel.cs @@ -0,0 +1,9 @@ +namespace SecureShopDataModels.Models +{ + public interface ISecureModel : IId + { + string SecureName { get; } + double Price { get; } + Dictionary SecureFacilitiess { get; } + } +} \ No newline at end of file diff --git a/Secure/BusinessLogic/BusinessLogic.csproj b/Secure/IceCreamShopDataModels/SecureShopDataModels.csproj similarity index 100% rename from Secure/BusinessLogic/BusinessLogic.csproj rename to Secure/IceCreamShopDataModels/SecureShopDataModels.csproj diff --git a/Secure/SecureShopListImplement/DataListSingleton.cs b/Secure/IceCreamShopListImplement/DataListSingleton.cs similarity index 63% rename from Secure/SecureShopListImplement/DataListSingleton.cs rename to Secure/IceCreamShopListImplement/DataListSingleton.cs index 450208b..e51a494 100644 --- a/Secure/SecureShopListImplement/DataListSingleton.cs +++ b/Secure/IceCreamShopListImplement/DataListSingleton.cs @@ -1,24 +1,21 @@ using SecureShopListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopListImplement { public class DataListSingleton { private static DataListSingleton? _instance; - public List Components { get; set; } + public List Facilitiess { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Secures { get; set; } + private DataListSingleton() { - Components = new List(); + Facilitiess = new List(); Orders = new List(); - Products = new List(); + Secures = new List(); } + public static DataListSingleton GetInstance() { if (_instance == null) @@ -28,4 +25,4 @@ namespace SecureShopListImplement return _instance; } } -} +} \ No newline at end of file diff --git a/Secure/IceCreamShopListImplement/Implements/FacilitiesStorage.cs b/Secure/IceCreamShopListImplement/Implements/FacilitiesStorage.cs new file mode 100644 index 0000000..6c168e7 --- /dev/null +++ b/Secure/IceCreamShopListImplement/Implements/FacilitiesStorage.cs @@ -0,0 +1,107 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopListImplement.Models; + +namespace SecureShopListImplement.Implements +{ + public class FacilitiesStorage : IFacilitiesStorage + { + private readonly DataListSingleton _source; + + public FacilitiesStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var Facilities in _source.Facilitiess) + { + result.Add(Facilities.GetViewModel); + } + return result; + } + + public List GetFilteredList(FacilitiesSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.FacilitiesName)) + { + return result; + } + foreach (var Facilities in _source.Facilitiess) + { + if (Facilities.FacilitiesName.Contains(model.FacilitiesName)) + { + result.Add(Facilities.GetViewModel); + } + } + return result; + } + + public FacilitiesViewModel? GetElement(FacilitiesSearchModel model) + { + if (string.IsNullOrEmpty(model.FacilitiesName) && !model.Id.HasValue) + { + return null; + } + foreach (var Facilities in _source.Facilitiess) + { + if ((!string.IsNullOrEmpty(model.FacilitiesName) && Facilities.FacilitiesName == model.FacilitiesName) || (model.Id.HasValue && Facilities.Id == model.Id)) + { + return Facilities.GetViewModel; + } + } + return null; + } + + public FacilitiesViewModel? Insert(FacilitiesBindingModel model) + { + model.Id = 1; + foreach (var Facilities in _source.Facilitiess) + { + if (model.Id <= Facilities.Id) + { + model.Id = Facilities.Id + 1; + } + } + var newFacilities = Facilities.Create(model); + if (newFacilities == null) + { + return null; + } + _source.Facilitiess.Add(newFacilities); + return newFacilities.GetViewModel; + } + + public FacilitiesViewModel? Update(FacilitiesBindingModel model) + { + foreach (var Facilities in _source.Facilitiess) + { + if (Facilities.Id == model.Id) + { + Facilities.Update(model); + return Facilities.GetViewModel; + } + } + return null; + } + + public FacilitiesViewModel? Delete(FacilitiesBindingModel model) + { + for (int i = 0; i < _source.Facilitiess.Count; ++i) + { + if (_source.Facilitiess[i].Id == model.Id) + { + var element = _source.Facilitiess[i]; + _source.Facilitiess.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopListImplement/Implements/OrderStorage.cs b/Secure/IceCreamShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..5e8882f --- /dev/null +++ b/Secure/IceCreamShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,121 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopListImplement.Models; + +namespace SecureShopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(GetViewModel(order)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return GetViewModel(order); + } + } + return null; + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var Secure in _source.Secures) + { + if (Secure.Id == order.SecureId) + { + viewModel.SecureName = Secure.SecureName; + break; + } + } + return viewModel; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return GetViewModel(newOrder); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return GetViewModel(order); + } + } + return null; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return GetViewModel(element); + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Secure/IceCreamShopListImplement/Implements/SecureStorage.cs b/Secure/IceCreamShopListImplement/Implements/SecureStorage.cs new file mode 100644 index 0000000..dbf31f9 --- /dev/null +++ b/Secure/IceCreamShopListImplement/Implements/SecureStorage.cs @@ -0,0 +1,107 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopListImplement.Models; + +namespace SecureShopListImplement.Implements +{ + public class SecureStorage : ISecureStorage + { + private readonly DataListSingleton _source; + + public SecureStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var Secure in _source.Secures) + { + result.Add(Secure.GetViewModel); + } + return result; + } + + public List GetFilteredList(SecureSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SecureName)) + { + return result; + } + foreach (var Secure in _source.Secures) + { + if (Secure.SecureName.Contains(model.SecureName)) + { + result.Add(Secure.GetViewModel); + } + } + return result; + } + + public SecureViewModel? GetElement(SecureSearchModel model) + { + if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue) + { + return null; + } + foreach (var Secure in _source.Secures) + { + if ((!string.IsNullOrEmpty(model.SecureName) && Secure.SecureName == model.SecureName) || (model.Id.HasValue && Secure.Id == model.Id)) + { + return Secure.GetViewModel; + } + } + return null; + } + + public SecureViewModel? Insert(SecureBindingModel model) + { + model.Id = 1; + foreach (var Secure in _source.Secures) + { + if (model.Id <= Secure.Id) + { + model.Id = Secure.Id + 1; + } + } + var newSecure = Secure.Create(model); + if (newSecure == null) + { + return null; + } + _source.Secures.Add(newSecure); + return newSecure.GetViewModel; + } + + public SecureViewModel? Update(SecureBindingModel model) + { + foreach (var Secure in _source.Secures) + { + if (Secure.Id == model.Id) + { + Secure.Update(model); + return Secure.GetViewModel; + } + } + return null; + } + + public SecureViewModel? Delete(SecureBindingModel model) + { + for (int i = 0; i < _source.Secures.Count; ++i) + { + if (_source.Secures[i].Id == model.Id) + { + var element = _source.Secures[i]; + _source.Secures.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Secure/SecureShopListImplement/Models/Component.cs b/Secure/IceCreamShopListImplement/Models/Facilities.cs similarity index 56% rename from Secure/SecureShopListImplement/Models/Component.cs rename to Secure/IceCreamShopListImplement/Models/Facilities.cs index ababe0d..7cade8f 100644 --- a/Secure/SecureShopListImplement/Models/Component.cs +++ b/Secure/IceCreamShopListImplement/Models/Facilities.cs @@ -4,39 +4,41 @@ using SecureShopDataModels.Models; namespace SecureShopListImplement.Models { - public class Component : IComponentModel + public class Facilities : IFacilitiesModel { public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; + public string FacilitiesName { get; private set; } = string.Empty; public double Cost { get; set; } - public static Component? Create(ComponentBindingModel? model) + + public static Facilities? Create(FacilitiesBindingModel? model) { if (model == null) { return null; } - return new Component() + return new Facilities() { Id = model.Id, - ComponentName = model.ComponentName, + FacilitiesName = model.FacilitiesName, Cost = model.Cost }; } - public void Update(ComponentBindingModel? model) + + public void Update(FacilitiesBindingModel? model) { if (model == null) { return; } - ComponentName = model.ComponentName; + FacilitiesName = model.FacilitiesName; Cost = model.Cost; } - public ComponentViewModel GetViewModel => new() + + public FacilitiesViewModel GetViewModel => new() { Id = Id, - ComponentName = ComponentName, + FacilitiesName = FacilitiesName, Cost = Cost }; } - } \ No newline at end of file diff --git a/Secure/IceCreamShopListImplement/Models/Order.cs b/Secure/IceCreamShopListImplement/Models/Order.cs new file mode 100644 index 0000000..8e7f9aa --- /dev/null +++ b/Secure/IceCreamShopListImplement/Models/Order.cs @@ -0,0 +1,61 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.ViewModels; +using SecureShopDataModels.Enums; +using SecureShopDataModels.Models; + +namespace SecureShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int SecureId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + SecureId = model.SecureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + SecureId = model.SecureId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + SecureId = SecureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/Secure/SecureShopListImplement/Models/Secure.cs b/Secure/IceCreamShopListImplement/Models/Secure.cs similarity index 64% rename from Secure/SecureShopListImplement/Models/Secure.cs rename to Secure/IceCreamShopListImplement/Models/Secure.cs index cf605bb..91d190b 100644 --- a/Secure/SecureShopListImplement/Models/Secure.cs +++ b/Secure/IceCreamShopListImplement/Models/Secure.cs @@ -1,11 +1,6 @@ using SecureShopContracts.BindingModels; using SecureShopContracts.ViewModels; using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SecureShopListImplement.Models { @@ -14,11 +9,8 @@ namespace SecureShopListImplement.Models public int Id { get; private set; } public string SecureName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary SecureComponents - { - get; - private set; - } = new Dictionary(); + public Dictionary SecureFacilitiess{ get; private set; } = new Dictionary(); + public static Secure? Create(SecureBindingModel? model) { if (model == null) @@ -27,12 +19,13 @@ namespace SecureShopListImplement.Models } return new Secure() { - Id = model.Id, - SecureName = model.SecureName, - Price = model.Price, - SecureComponents = model.SecureComponents + Id = model.Id, + SecureName = model.SecureName, + Price = model.Price, + SecureFacilitiess = model.SecureFacilitiess }; } + public void Update(SecureBindingModel? model) { if (model == null) @@ -41,14 +34,15 @@ namespace SecureShopListImplement.Models } SecureName = model.SecureName; Price = model.Price; - SecureComponents = model.SecureComponents; + SecureFacilitiess = model.SecureFacilitiess; } + public SecureViewModel GetViewModel => new() { Id = Id, SecureName = SecureName, Price = Price, - SecureComponents = SecureComponents + SecureFacilitiess = SecureFacilitiess }; } -} +} \ No newline at end of file diff --git a/Secure/SecureShopListImplement/SecureShopListImplement.csproj b/Secure/IceCreamShopListImplement/SecureShopListImplement.csproj similarity index 52% rename from Secure/SecureShopListImplement/SecureShopListImplement.csproj rename to Secure/IceCreamShopListImplement/SecureShopListImplement.csproj index c2fb905..c3261d5 100644 --- a/Secure/SecureShopListImplement/SecureShopListImplement.csproj +++ b/Secure/IceCreamShopListImplement/SecureShopListImplement.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/Secure/Secure.sln b/Secure/Secure.sln deleted file mode 100644 index f7926bb..0000000 --- a/Secure/Secure.sln +++ /dev/null @@ -1,49 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32929.385 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Secure", "Secure\Secure.csproj", "{12E086AF-F155-48EC-B9B9-ABEF1B76B8DC}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopContracts", "SecureShopContracts\SecureShopContracts\SecureShopContracts.csproj", "{5F8E31D5-D9BD-4D40-BE28-12D12A91E4C7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopDataModels", "SecureShopDataModels\SecureShopDataModels\SecureShopDataModels.csproj", "{3278670B-B887-4C00-B8A4-BAEED8C4F020}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecureShopBusinessLogic", "SecureShopBusinessLogic\SecureShopBusinessLogic.csproj", "{BA3B23C1-47F8-4734-BFE2-3F5A35C3BF2A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecureShopListImplement", "SecureShopListImplement\SecureShopListImplement.csproj", "{52CEC57F-E90F-4406-BB70-2B43B97D2358}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {12E086AF-F155-48EC-B9B9-ABEF1B76B8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {12E086AF-F155-48EC-B9B9-ABEF1B76B8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {12E086AF-F155-48EC-B9B9-ABEF1B76B8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {12E086AF-F155-48EC-B9B9-ABEF1B76B8DC}.Release|Any CPU.Build.0 = Release|Any CPU - {5F8E31D5-D9BD-4D40-BE28-12D12A91E4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5F8E31D5-D9BD-4D40-BE28-12D12A91E4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5F8E31D5-D9BD-4D40-BE28-12D12A91E4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5F8E31D5-D9BD-4D40-BE28-12D12A91E4C7}.Release|Any CPU.Build.0 = Release|Any CPU - {3278670B-B887-4C00-B8A4-BAEED8C4F020}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3278670B-B887-4C00-B8A4-BAEED8C4F020}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3278670B-B887-4C00-B8A4-BAEED8C4F020}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3278670B-B887-4C00-B8A4-BAEED8C4F020}.Release|Any CPU.Build.0 = Release|Any CPU - {BA3B23C1-47F8-4734-BFE2-3F5A35C3BF2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BA3B23C1-47F8-4734-BFE2-3F5A35C3BF2A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BA3B23C1-47F8-4734-BFE2-3F5A35C3BF2A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BA3B23C1-47F8-4734-BFE2-3F5A35C3BF2A}.Release|Any CPU.Build.0 = Release|Any CPU - {52CEC57F-E90F-4406-BB70-2B43B97D2358}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {52CEC57F-E90F-4406-BB70-2B43B97D2358}.Debug|Any CPU.Build.0 = Debug|Any CPU - {52CEC57F-E90F-4406-BB70-2B43B97D2358}.Release|Any CPU.ActiveCfg = Release|Any CPU - {52CEC57F-E90F-4406-BB70-2B43B97D2358}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {91A88ACE-177C-4A5D-BA80-5580140BF7E9} - EndGlobalSection -EndGlobal diff --git a/Secure/Secure/Form1.Designer.cs b/Secure/Secure/Form1.Designer.cs deleted file mode 100644 index d6a6517..0000000 --- a/Secure/Secure/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Secure -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Secure/Secure/Form1.cs b/Secure/Secure/Form1.cs deleted file mode 100644 index 24aac69..0000000 --- a/Secure/Secure/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Secure -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Secure/Secure/Form1.resx b/Secure/Secure/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Secure/Secure/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/Secure/Secure/Program.cs b/Secure/Secure/Program.cs deleted file mode 100644 index e5c5365..0000000 --- a/Secure/Secure/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Secure -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/Secure/Secure/Secure.csproj b/Secure/Secure/Secure.csproj deleted file mode 100644 index b57c89e..0000000 --- a/Secure/Secure/Secure.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/Secure/SecureShop.sln b/Secure/SecureShop.sln new file mode 100644 index 0000000..8d8c479 --- /dev/null +++ b/Secure/SecureShop.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32421.90 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopView", "IceCreamShop\SecureShopView.csproj", "{5364D1DA-47C2-45E4-9022-DCDEFD5D3BE5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopDataModels", "IceCreamShopDataModels\SecureShopDataModels.csproj", "{565CCA80-81C4-4581-879F-05B870AA8AC9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopContracts", "IceCreamShopContracts\SecureShopContracts.csproj", "{5BED4A3C-2BA8-41AA-8EEA-23F08A77C9DB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopBusinessLogic", "IceCreamShopBusinessLogic\SecureShopBusinessLogic.csproj", "{8863CC31-0B08-4149-8DFF-6BBFC1F65814}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopListImplement", "IceCreamShopListImplement\SecureShopListImplement.csproj", "{91B8625D-ED80-4C09-966E-9C8F46B6477B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5364D1DA-47C2-45E4-9022-DCDEFD5D3BE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5364D1DA-47C2-45E4-9022-DCDEFD5D3BE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5364D1DA-47C2-45E4-9022-DCDEFD5D3BE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5364D1DA-47C2-45E4-9022-DCDEFD5D3BE5}.Release|Any CPU.Build.0 = Release|Any CPU + {565CCA80-81C4-4581-879F-05B870AA8AC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {565CCA80-81C4-4581-879F-05B870AA8AC9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {565CCA80-81C4-4581-879F-05B870AA8AC9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {565CCA80-81C4-4581-879F-05B870AA8AC9}.Release|Any CPU.Build.0 = Release|Any CPU + {5BED4A3C-2BA8-41AA-8EEA-23F08A77C9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5BED4A3C-2BA8-41AA-8EEA-23F08A77C9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5BED4A3C-2BA8-41AA-8EEA-23F08A77C9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5BED4A3C-2BA8-41AA-8EEA-23F08A77C9DB}.Release|Any CPU.Build.0 = Release|Any CPU + {8863CC31-0B08-4149-8DFF-6BBFC1F65814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8863CC31-0B08-4149-8DFF-6BBFC1F65814}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8863CC31-0B08-4149-8DFF-6BBFC1F65814}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8863CC31-0B08-4149-8DFF-6BBFC1F65814}.Release|Any CPU.Build.0 = Release|Any CPU + {91B8625D-ED80-4C09-966E-9C8F46B6477B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91B8625D-ED80-4C09-966E-9C8F46B6477B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91B8625D-ED80-4C09-966E-9C8F46B6477B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91B8625D-ED80-4C09-966E-9C8F46B6477B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {03723299-E9A9-4557-B252-F7DE584EED8F} + EndGlobalSection +EndGlobal diff --git a/Secure/SecureShopBusinessLogic/BusinessLogic/ComponentLogic.cs b/Secure/SecureShopBusinessLogic/BusinessLogic/ComponentLogic.cs deleted file mode 100644 index c9bcdd9..0000000 --- a/Secure/SecureShopBusinessLogic/BusinessLogic/ComponentLogic.cs +++ /dev/null @@ -1,111 +0,0 @@ -using Microsoft.Extensions.Logging; -using SecureShopContracts.BindingModels; -using SecureShopContracts.BusinessLogicsContracts; -using SecureShopContracts.SearchModels; -using SecureShopContracts.StorageContracts; -using SecureShopContracts.ViewModels; - -namespace SecureShopBusinessLogic.BusinessLogic -{ - 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/Secure/SecureShopContracts/SecureShopContracts.sln b/Secure/SecureShopContracts/SecureShopContracts.sln deleted file mode 100644 index ba2ec48..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32929.385 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecureShopContracts", "SecureShopContracts\SecureShopContracts.csproj", "{06AD38FD-7CA7-45BA-A1C7-D8531F794FF5}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {06AD38FD-7CA7-45BA-A1C7-D8531F794FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06AD38FD-7CA7-45BA-A1C7-D8531F794FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06AD38FD-7CA7-45BA-A1C7-D8531F794FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06AD38FD-7CA7-45BA-A1C7-D8531F794FF5}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E76FFD02-B2F5-428E-950B-132138F2E535} - EndGlobalSection -EndGlobal diff --git a/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IComponentLogic.cs deleted file mode 100644 index d515a48..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts/BusinessLogicsContracts/IComponentLogic.cs +++ /dev/null @@ -1,21 +0,0 @@ -using SecureShopContracts.BindingModels; -using SecureShopContracts.SearchModels; -using SecureShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopContracts.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/Secure/SecureShopContracts/SecureShopContracts/SearchModels/ComponentSearchModel.cs b/Secure/SecureShopContracts/SecureShopContracts/SearchModels/ComponentSearchModel.cs deleted file mode 100644 index ed86a99..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts/SearchModels/ComponentSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopContracts.SearchModels -{ - public class ComponentSearchModel - { - public int? Id { get; set; } - public string? ComponentName { get; set; } - } -} diff --git a/Secure/SecureShopContracts/SecureShopContracts/SearchModels/OrderSearchModel.cs b/Secure/SecureShopContracts/SecureShopContracts/SearchModels/OrderSearchModel.cs deleted file mode 100644 index 3d09960..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts/SearchModels/OrderSearchModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopContracts.SearchModels -{ - public class OrderSearchModel - { - public int? Id { get; set; } - } -} diff --git a/Secure/SecureShopContracts/SecureShopContracts/SearchModels/SecureSearchModel.cs b/Secure/SecureShopContracts/SecureShopContracts/SearchModels/SecureSearchModel.cs deleted file mode 100644 index ce5f397..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts/SearchModels/SecureSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopContracts.SearchModels -{ - public class SecureSearchModel - { - public int? Id { get; set; } - public string? SecureName { get; set; } - } -} diff --git a/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IComponentStorage.cs b/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IComponentStorage.cs deleted file mode 100644 index 7675e59..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts/StorageContracts/IComponentStorage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using SecureShopContracts.BindingModels; -using SecureShopContracts.SearchModels; -using SecureShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopContracts.StorageContracts -{ - public interface IComponentStorage - { - List GetFullList(); - List GetFilteredList(ComponentSearchModel model); - ComponentViewModel? GetElement(ComponentSearchModel model); - ComponentViewModel? Insert(ComponentBindingModel model); - ComponentViewModel? Update(ComponentBindingModel model); - ComponentViewModel? Delete(ComponentBindingModel model); - } - -} diff --git a/Secure/SecureShopContracts/SecureShopContracts/ViewModels/ComponentViewModel.cs b/Secure/SecureShopContracts/SecureShopContracts/ViewModels/ComponentViewModel.cs deleted file mode 100644 index 0c1ecc5..0000000 --- a/Secure/SecureShopContracts/SecureShopContracts/ViewModels/ComponentViewModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopContracts.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/Secure/SecureShopDataModels/SecureShopDataModels.sln b/Secure/SecureShopDataModels/SecureShopDataModels.sln deleted file mode 100644 index e807d33..0000000 --- a/Secure/SecureShopDataModels/SecureShopDataModels.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32929.385 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecureShopDataModels", "SecureShopDataModels\SecureShopDataModels.csproj", "{11A90603-8AA1-4B6F-A4EE-8B70AB4A918F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {11A90603-8AA1-4B6F-A4EE-8B70AB4A918F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {11A90603-8AA1-4B6F-A4EE-8B70AB4A918F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {11A90603-8AA1-4B6F-A4EE-8B70AB4A918F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {11A90603-8AA1-4B6F-A4EE-8B70AB4A918F}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E488F989-C9BB-4B7D-A085-2CA125E0D019} - EndGlobalSection -EndGlobal diff --git a/Secure/SecureShopDataModels/SecureShopDataModels/IId.cs b/Secure/SecureShopDataModels/SecureShopDataModels/IId.cs deleted file mode 100644 index 146ace0..0000000 --- a/Secure/SecureShopDataModels/SecureShopDataModels/IId.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SecureShopDataModels -{ - public interface IId - { - int Id { get; } - } -} \ No newline at end of file diff --git a/Secure/SecureShopDataModels/SecureShopDataModels/Models/IComponentModel.cs b/Secure/SecureShopDataModels/SecureShopDataModels/Models/IComponentModel.cs deleted file mode 100644 index 0dd5ac2..0000000 --- a/Secure/SecureShopDataModels/SecureShopDataModels/Models/IComponentModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopDataModels.Models -{ - public interface IComponentModel:IId - { - string ComponentName { get;} - double Cost { get;} - } -} diff --git a/Secure/SecureShopDataModels/SecureShopDataModels/Models/ISecureModel.cs b/Secure/SecureShopDataModels/SecureShopDataModels/Models/ISecureModel.cs deleted file mode 100644 index 1594273..0000000 --- a/Secure/SecureShopDataModels/SecureShopDataModels/Models/ISecureModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using SecureShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopDataModels.Models -{ - public interface ISecureModel:IId - { - string SecureName { get; } - double Price { get; } - Dictionary SecureComponents { get; } - } -} diff --git a/Secure/SecureShopDataModels/SecureShopDataModels/SecureShopDataModels.csproj b/Secure/SecureShopDataModels/SecureShopDataModels/SecureShopDataModels.csproj deleted file mode 100644 index 27ac386..0000000 --- a/Secure/SecureShopDataModels/SecureShopDataModels/SecureShopDataModels.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/Secure/SecureShopListImplement/Models/Order.cs b/Secure/SecureShopListImplement/Models/Order.cs deleted file mode 100644 index 9920f61..0000000 --- a/Secure/SecureShopListImplement/Models/Order.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SecureShopListImplement.Models -{ - public class Order - { - } -}