diff --git a/JewelryStoreContracts/JewelryStoreContracts.sln b/JewelryStoreContracts/JewelryStoreContracts.sln deleted file mode 100644 index 0a627c0..0000000 --- a/JewelryStoreContracts/JewelryStoreContracts.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32825.248 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "JewelryStoreContracts\JewelryStoreContracts.csproj", "{7108FC40-849C-4D04-855E-C36AA217D2D2}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7108FC40-849C-4D04-855E-C36AA217D2D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7108FC40-849C-4D04-855E-C36AA217D2D2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7108FC40-849C-4D04-855E-C36AA217D2D2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7108FC40-849C-4D04-855E-C36AA217D2D2}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7B1C3FD9-70ED-46A2-BCF3-6E7EB65FE7A3} - EndGlobalSection -EndGlobal diff --git a/JewelryStoreContracts/JewelryStoreContracts/Class1.cs b/JewelryStoreContracts/JewelryStoreContracts/Class1.cs deleted file mode 100644 index e5cbec2..0000000 --- a/JewelryStoreContracts/JewelryStoreContracts/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace JewelryStoreContracts -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/JewelryStoreContracts/Project1/Project1.vcxproj b/JewelryStoreContracts/Project1/Project1.vcxproj deleted file mode 100644 index fc12abb..0000000 --- a/JewelryStoreContracts/Project1/Project1.vcxproj +++ /dev/null @@ -1,138 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - 16.0 - Win32Proj - {ee2ca9e3-063f-457f-b3da-05a4624e84ad} - Project1 - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - diff --git a/JewelryStoreContracts/Project1/Project1.vcxproj.filters b/JewelryStoreContracts/Project1/Project1.vcxproj.filters deleted file mode 100644 index 153170c..0000000 --- a/JewelryStoreContracts/Project1/Project1.vcxproj.filters +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/OrderStatus.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Enums/OrderStatus.cs similarity index 100% rename from PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/OrderStatus.cs rename to PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Enums/OrderStatus.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IId.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/IId.cs similarity index 100% rename from PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IId.cs rename to PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/IId.cs diff --git a/JewelryStoreContracts/JewelryStoreContracts/JewelryStoreContracts.csproj b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/JewelryStoreDataModels.csproj similarity index 100% rename from JewelryStoreContracts/JewelryStoreContracts/JewelryStoreContracts.csproj rename to PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/JewelryStoreDataModels.csproj diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IComponentModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IComponentModel.cs similarity index 100% rename from PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IComponentModel.cs rename to PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IComponentModel.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IJewelModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IJewelModel.cs similarity index 100% rename from PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IJewelModel.cs rename to PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IJewelModel.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IOrderModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs similarity index 100% rename from PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/IOrderModel.cs rename to PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs new file mode 100644 index 0000000..ea34e71 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs @@ -0,0 +1,17 @@ +using JewelryShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IStoreModel : IId + { + public string StoreName { get; } + public string StoreAdress { get; } + DateTime OpeningDate { get; } + Dictionary Jewels { get; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore.sln b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore.sln new file mode 100644 index 0000000..a63adc3 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStore", "JewelryStore\JewelryStore.csproj", "{187BBC53-52AA-4C47-B98B-E119AE64ADA4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "JewelryShopDataModels\JewelryStoreDataModels.csproj", "{C6D79969-6DC9-4F60-BCC4-A679CB472595}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreContracts", "JewelryStoreContracts\JewelryStoreContracts.csproj", "{F7C956E1-26FC-4914-9ABC-71A16F88B7E8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{B4D1E829-A99F-47D2-B06D-5042CE058CA9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{12C6B5CD-CE5C-4095-91B8-53A5CB08E780}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {187BBC53-52AA-4C47-B98B-E119AE64ADA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {187BBC53-52AA-4C47-B98B-E119AE64ADA4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {187BBC53-52AA-4C47-B98B-E119AE64ADA4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {187BBC53-52AA-4C47-B98B-E119AE64ADA4}.Release|Any CPU.Build.0 = Release|Any CPU + {C6D79969-6DC9-4F60-BCC4-A679CB472595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6D79969-6DC9-4F60-BCC4-A679CB472595}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6D79969-6DC9-4F60-BCC4-A679CB472595}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6D79969-6DC9-4F60-BCC4-A679CB472595}.Release|Any CPU.Build.0 = Release|Any CPU + {F7C956E1-26FC-4914-9ABC-71A16F88B7E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7C956E1-26FC-4914-9ABC-71A16F88B7E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7C956E1-26FC-4914-9ABC-71A16F88B7E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7C956E1-26FC-4914-9ABC-71A16F88B7E8}.Release|Any CPU.Build.0 = Release|Any CPU + {B4D1E829-A99F-47D2-B06D-5042CE058CA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4D1E829-A99F-47D2-B06D-5042CE058CA9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4D1E829-A99F-47D2-B06D-5042CE058CA9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4D1E829-A99F-47D2-B06D-5042CE058CA9}.Release|Any CPU.Build.0 = Release|Any CPU + {12C6B5CD-CE5C-4095-91B8-53A5CB08E780}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12C6B5CD-CE5C-4095-91B8-53A5CB08E780}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12C6B5CD-CE5C-4095-91B8-53A5CB08E780}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12C6B5CD-CE5C-4095-91B8-53A5CB08E780}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1BFFF75E-EFBE-4748-817D-DF837DAC2E23} + EndGlobalSection +EndGlobal diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.Designer.cs new file mode 100644 index 0000000..182fb3a --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace JewelryStore +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = 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(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(20, 21); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(20, 67); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(57, 25); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(132, 18); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(298, 31); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(132, 64); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(298, 31); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(132, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(318, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(463, 172); + 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.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.cs new file mode 100644 index 0000000..6e964e6 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.cs @@ -0,0 +1,94 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponent.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.Designer.cs new file mode 100644 index 0000000..3977446 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace JewelryStore +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 11); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(525, 427); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(569, 38); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(164, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(569, 107); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(164, 34); + this.buttonRefresh.TabIndex = 2; + this.buttonRefresh.Text = "Изменить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(569, 178); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(164, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(569, 249); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(164, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(756, 450); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.cs new file mode 100644 index 0000000..00a7a46 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.cs @@ -0,0 +1,106 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormComponents.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..dd25676 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace JewelryStore +{ + 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.labelJewel = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxJewel = 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(); + // + // labelJewel + // + this.labelJewel.AutoSize = true; + this.labelJewel.Location = new System.Drawing.Point(17, 20); + this.labelJewel.Name = "labelJewel"; + this.labelJewel.Size = new System.Drawing.Size(84, 25); + this.labelJewel.TabIndex = 0; + this.labelJewel.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(17, 62); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(111, 25); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(17, 107); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(71, 25); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxJewel + // + this.comboBoxJewel.FormattingEnabled = true; + this.comboBoxJewel.Location = new System.Drawing.Point(134, 17); + this.comboBoxJewel.MaxDropDownItems = 100; + this.comboBoxJewel.Name = "comboBoxJewel"; + this.comboBoxJewel.Size = new System.Drawing.Size(291, 33); + this.comboBoxJewel.TabIndex = 3; + this.comboBoxJewel.SelectedIndexChanged += new System.EventHandler(this.ComboBoxJewel_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(134, 62); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(291, 31); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(134, 104); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(291, 31); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(134, 152); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(313, 152); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + 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(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(441, 205); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxJewel); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelJewel); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelJewel; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxJewel; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.cs new file mode 100644 index 0000000..1f1eab4 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.cs @@ -0,0 +1,134 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace JewelryStore +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logicJ; + private readonly IOrderLogic _logicO; + private List? _list; + + public FormCreateOrder(ILogger logger, IJewelLogic logicJ, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicJ = logicJ; + _logicO = logicO; + } + + public int Id { get { return Convert.ToInt32(comboBoxJewel.SelectedValue); } set { comboBoxJewel.SelectedValue = value; } } + + public IJewelModel? JewelModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + _list = _logicJ.ReadList(null); + if (_list != null) + { + comboBoxJewel.DisplayMember = "JewelName"; + comboBoxJewel.ValueMember = "Id"; + comboBoxJewel.DataSource = _list; + comboBoxJewel.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxJewel.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1; + var Jewel = _logicJ.ReadElement(new JewelSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Jewel?.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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxJewel.SelectedValue == null) + { + MessageBox.Show("Выберите драгоценность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + JewelId = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1, + 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 ComboBoxJewel_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.Designer.cs new file mode 100644 index 0000000..f1094b1 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.Designer.cs @@ -0,0 +1,233 @@ +namespace JewelryStore +{ + partial class FormJewel + { + /// + /// 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.JewelId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + 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.groupBox = new System.Windows.Forms.GroupBox(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.groupBox.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.JewelId, + this.ComponentName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 25); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(468, 325); + this.dataGridView.TabIndex = 0; + // + // JewelId + // + this.JewelId.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.JewelId.HeaderText = "Id"; + this.JewelId.MinimumWidth = 8; + this.JewelId.Name = "JewelId"; + this.JewelId.Visible = false; + this.JewelId.Width = 8; + // + // ComponentName + // + this.ComponentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ComponentName.HeaderText = "Компонент"; + this.ComponentName.MinimumWidth = 8; + this.ComponentName.Name = "ComponentName"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 8; + this.Count.Name = "Count"; + this.Count.Width = 150; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(15, 17); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 1; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 60); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(103, 25); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(124, 14); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(267, 31); + this.textBoxName.TabIndex = 3; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(124, 57); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(267, 31); + this.textBoxPrice.TabIndex = 4; + // + // groupBox + // + this.groupBox.Controls.Add(this.buttonUpdate); + this.groupBox.Controls.Add(this.buttonDelete); + this.groupBox.Controls.Add(this.buttonRefresh); + this.groupBox.Controls.Add(this.buttonAdd); + this.groupBox.Controls.Add(this.dataGridView); + this.groupBox.Location = new System.Drawing.Point(15, 94); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(676, 356); + this.groupBox.TabIndex = 5; + this.groupBox.TabStop = false; + this.groupBox.Text = "Компоненты"; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(505, 242); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(141, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(505, 181); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(141, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(505, 118); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(141, 34); + this.buttonRefresh.TabIndex = 2; + this.buttonRefresh.Text = "Изменить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(505, 56); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(141, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(377, 456); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(549, 456); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormJewel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(708, 500); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Controls.Add(this.groupBox); + this.Name = "FormJewel"; + this.Text = "Изделие"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.groupBox.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn JewelId; + private DataGridViewTextBoxColumn ComponentName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.cs new file mode 100644 index 0000000..380cf8d --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.cs @@ -0,0 +1,208 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormJewel : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + private int? _id; + private Dictionary _JewelComponents; + public int Id { set { _id = value; } } + + public FormJewel(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _JewelComponents = new Dictionary(); + } + + private void FormJewel_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new JewelSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.JewelName; + textBoxPrice.Text = view.Price.ToString(); + _JewelComponents = view.JewelComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонентов изделия"); + try + { + if (_JewelComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var jc in _JewelComponents) + { + dataGridView.Rows.Add(new object[] { jc.Key, jc.Value.Item1.ComponentName, jc.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(FormJewelComponent)); + if (service is FormJewelComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_JewelComponents.ContainsKey(form.Id)) + { + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _JewelComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); + if (service is FormJewelComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _JewelComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _JewelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpdate_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 (_JewelComponents == null || _JewelComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new JewelBindingModel + { + Id = _id ?? 0, + JewelName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + JewelComponents = _JewelComponents + }; + 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 _JewelComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.resx new file mode 100644 index 0000000..7cc63c3 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewel.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.Designer.cs new file mode 100644 index 0000000..ebe459c --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace JewelryStore +{ + partial class FormJewelComponent + { + /// + /// 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.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxComponent = 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(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(16, 21); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(107, 25); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Компонент:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(16, 70); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(111, 25); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(148, 18); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(288, 33); + this.comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(148, 67); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(288, 31); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(148, 115); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(324, 115); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormJewelComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(461, 173); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Name = "FormJewelComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.cs new file mode 100644 index 0000000..14fe2ee --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.cs @@ -0,0 +1,84 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; + +namespace JewelryStore +{ + public partial class FormJewelComponent : Form + { + private readonly List? _list; + + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormJewelComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewelComponent.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.Designer.cs new file mode 100644 index 0000000..3d7d620 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.Designer.cs @@ -0,0 +1,116 @@ +namespace JewelryStore +{ + partial class FormJewels + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.GridColor = System.Drawing.SystemColors.Window; + this.dataGridView.Location = new System.Drawing.Point(17, 18); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(467, 333); + this.dataGridView.TabIndex = 0; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(516, 262); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(164, 34); + this.buttonUpdate.TabIndex = 8; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(516, 191); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(164, 34); + this.buttonDelete.TabIndex = 7; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(516, 120); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(164, 34); + this.buttonRefresh.TabIndex = 6; + this.buttonRefresh.Text = "Изменить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(516, 51); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(164, 34); + this.buttonAdd.TabIndex = 5; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormJewels + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(709, 364); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormJewels"; + this.Text = "Изделия"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs new file mode 100644 index 0000000..c770810 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs @@ -0,0 +1,105 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace JewelryStore +{ + public partial class FormJewels : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + + public FormJewels(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["JewelName"].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(FormJewel)); + if (service is FormJewel form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + if (service is FormJewel form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_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 JewelBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormJewels_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs new file mode 100644 index 0000000..b594b98 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs @@ -0,0 +1,196 @@ +namespace JewelryStore +{ + 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.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = 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.buttonRefresh = new System.Windows.Forms.Button(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.СправочникиToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1121, 33); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // СправочникиToolStripMenuItem + // + this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.КомпонентыToolStripMenuItem, + this.ИзделияToolStripMenuItem, + this.магазиныToolStripMenuItem}); + this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; + this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.СправочникиToolStripMenuItem.Text = "Справочники"; + // + // КомпонентыToolStripMenuItem + // + this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.КомпонентыToolStripMenuItem.Text = "Компоненты"; + this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // ИзделияToolStripMenuItem + // + this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.ИзделияToolStripMenuItem.Text = "Изделия"; + this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 36); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(851, 402); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(884, 78); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(210, 34); + 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(884, 150); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(210, 34); + 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(884, 221); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(210, 34); + 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(884, 292); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(210, 34); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(884, 361); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(210, 34); + this.buttonRefresh.TabIndex = 6; + this.buttonRefresh.Text = "Обновить список"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); + // + // пополнениеМагазинаToolStripMenuItem + // + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(210, 29); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ПополнениеМагазинаToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1121, 450); + this.Controls.Add(this.buttonRefresh); + 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.Name = "FormMain"; + this.Text = "Ювелирная лавка"; + 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 КомпонентыToolStripMenuItem; + private ToolStripMenuItem ИзделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs new file mode 100644 index 0000000..5a5f7d5 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs @@ -0,0 +1,169 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace JewelryStore +{ + 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["JewelId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewels)); + if (service is FormJewels form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStores)); + + if (service is FormStores form) + { + form.ShowDialog(); + } + } + + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); + + if (service is FormStoreReplenishment form) + { + form.ShowDialog(); + } + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs new file mode 100644 index 0000000..e206d60 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs @@ -0,0 +1,198 @@ +namespace JewelryStore +{ + partial class FormStore + { + /// + /// 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.StoreNameLabel = new System.Windows.Forms.Label(); + this.StoreAdressLabel = new System.Windows.Forms.Label(); + this.OpeningDateLabel = new System.Windows.Forms.Label(); + this.NameTextBox = new System.Windows.Forms.TextBox(); + this.AdressTextBox = new System.Windows.Forms.TextBox(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.JewelPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.JewelCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(17, 13); + this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(179, 25); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // StoreAdressLabel + // + this.StoreAdressLabel.AutoSize = true; + this.StoreAdressLabel.Location = new System.Drawing.Point(17, 54); + this.StoreAdressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreAdressLabel.Name = "StoreAdressLabel"; + this.StoreAdressLabel.Size = new System.Drawing.Size(151, 25); + this.StoreAdressLabel.TabIndex = 1; + this.StoreAdressLabel.Text = "Адрес магазина: "; + // + // OpeningDateLabel + // + this.OpeningDateLabel.AutoSize = true; + this.OpeningDateLabel.Location = new System.Drawing.Point(17, 99); + this.OpeningDateLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.OpeningDateLabel.Name = "OpeningDateLabel"; + this.OpeningDateLabel.Size = new System.Drawing.Size(140, 25); + this.OpeningDateLabel.TabIndex = 2; + this.OpeningDateLabel.Text = "Дата открытия: "; + // + // NameTextBox + // + this.NameTextBox.Location = new System.Drawing.Point(204, 10); + this.NameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.NameTextBox.Name = "NameTextBox"; + this.NameTextBox.Size = new System.Drawing.Size(247, 31); + this.NameTextBox.TabIndex = 3; + // + // AdressTextBox + // + this.AdressTextBox.Location = new System.Drawing.Point(204, 51); + this.AdressTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AdressTextBox.Name = "AdressTextBox"; + this.AdressTextBox.Size = new System.Drawing.Size(247, 31); + this.AdressTextBox.TabIndex = 4; + // + // DataGridView + // + this.DataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.JewelName, + this.JewelPrice, + this.JewelCount}); + this.DataGridView.Location = new System.Drawing.Point(13, 135); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(802, 365); + this.DataGridView.TabIndex = 6; + // + // JewelName + // + this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.JewelName.HeaderText = "Название изделия"; + this.JewelName.MinimumWidth = 8; + this.JewelName.Name = "JewelName"; + // + // JewelPrice + // + this.JewelPrice.HeaderText = "Цена"; + this.JewelPrice.MinimumWidth = 8; + this.JewelPrice.Name = "JewelPrice"; + this.JewelPrice.Width = 150; + // + // JewelCount + // + this.JewelCount.HeaderText = "Количество"; + this.JewelCount.MinimumWidth = 8; + this.JewelCount.Name = "JewelCount"; + this.JewelCount.Width = 150; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(531, 510); + this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(138, 35); + this.SaveButton.TabIndex = 7; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(677, 510); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(138, 35); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отменить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // OpeningDatePicker + // + this.OpeningDatePicker.Location = new System.Drawing.Point(204, 94); + this.OpeningDatePicker.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.OpeningDatePicker.Name = "OpeningDatePicker"; + this.OpeningDatePicker.Size = new System.Drawing.Size(247, 31); + this.OpeningDatePicker.TabIndex = 9; + // + // FormStore + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(867, 560); + this.Controls.Add(this.OpeningDatePicker); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.DataGridView); + this.Controls.Add(this.AdressTextBox); + this.Controls.Add(this.NameTextBox); + this.Controls.Add(this.OpeningDateLabel); + this.Controls.Add(this.StoreAdressLabel); + this.Controls.Add(this.StoreNameLabel); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormStore"; + this.Text = "Изделия магазина"; + this.Load += new System.EventHandler(this.FormStore_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label StoreAdressLabel; + private Label OpeningDateLabel; + private TextBox NameTextBox; + private TextBox AdressTextBox; + private DataGridView DataGridView; + private Button SaveButton; + private Button ButtonCancel; + private DataGridViewTextBoxColumn JewelName; + private DataGridViewTextBoxColumn JewelPrice; + private DataGridViewTextBoxColumn JewelCount; + private DateTimePicker OpeningDatePicker; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs new file mode 100644 index 0000000..ed123a8 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs @@ -0,0 +1,141 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormStore : Form + { + private readonly List? _listStores; + private readonly IStoreLogic _logic; + private readonly ILogger _logger; + public int Id { get; set; } + + public FormStore(ILogger logger, IStoreLogic logic) + { + InitializeComponent(); + _logger = logger; + _listStores = logic.ReadList(null); + _logic = logic; + } + + private IStoreModel? GetStore(int id) + { + if (_listStores == null) + { + return null; + } + foreach (var elem in _listStores) + { + if (elem.Id == id) + { + return elem; + } + } + return null; + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(AdressTextBox.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение магазина"); + + try + { + DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); + StoreBindingModel model = new() + { + StoreName = NameTextBox.Text, + StoreAdress = AdressTextBox.Text, + OpeningDate = dateTime + }; + var vmodel = GetStore(Id); + bool operationResult = false; + + if (vmodel != null) + { + model.Id = vmodel.Id; + operationResult = _logic.Update(model); + } + else + { + operationResult = _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 void FormStore_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData(bool extendDate = true) + { + try + { + var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); + if (model != null) + { + NameTextBox.Text = model.StoreName; + AdressTextBox.Text = model.StoreAdress; + OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); + DataGridView.Rows.Clear(); + foreach (var el in model.Jewels.Values) + { + DataGridView.Rows.Add(new object[] { el.Item1.JewelName, el.Item1.Price, el.Item2 }); + } + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs new file mode 100644 index 0000000..b8cdadd --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs @@ -0,0 +1,151 @@ +namespace JewelryStore +{ + partial class FormStoreReplenishment + { + /// + /// 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.StoreNameLabel = new System.Windows.Forms.Label(); + this.JewelNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.StoreNameComboBox = new System.Windows.Forms.ComboBox(); + this.JewelNameComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(9, 9); + this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(179, 25); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // JewelNameLabel + // + this.JewelNameLabel.AutoSize = true; + this.JewelNameLabel.Location = new System.Drawing.Point(9, 58); + this.JewelNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.JewelNameLabel.Name = "JewelNameLabel"; + this.JewelNameLabel.Size = new System.Drawing.Size(169, 25); + this.JewelNameLabel.TabIndex = 1; + this.JewelNameLabel.Text = "Название изделия: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(9, 107); + this.CountLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(116, 25); + this.CountLabel.TabIndex = 2; + this.CountLabel.Text = "Количество: "; + // + // StoreNameComboBox + // + this.StoreNameComboBox.FormattingEnabled = true; + this.StoreNameComboBox.Location = new System.Drawing.Point(196, 6); + this.StoreNameComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.StoreNameComboBox.Name = "StoreNameComboBox"; + this.StoreNameComboBox.Size = new System.Drawing.Size(272, 33); + this.StoreNameComboBox.TabIndex = 3; + // + // JewelNameComboBox + // + this.JewelNameComboBox.FormattingEnabled = true; + this.JewelNameComboBox.Location = new System.Drawing.Point(196, 55); + this.JewelNameComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.JewelNameComboBox.Name = "JewelNameComboBox"; + this.JewelNameComboBox.Size = new System.Drawing.Size(272, 33); + this.JewelNameComboBox.TabIndex = 4; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(196, 104); + this.CountTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(272, 31); + this.CountTextBox.TabIndex = 5; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(234, 145); + this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(107, 38); + this.SaveButton.TabIndex = 6; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(361, 145); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(107, 38); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormStoreReplenishment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(481, 200); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.JewelNameComboBox); + this.Controls.Add(this.StoreNameComboBox); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.JewelNameLabel); + this.Controls.Add(this.StoreNameLabel); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormStoreReplenishment"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label JewelNameLabel; + private Label CountLabel; + private ComboBox StoreNameComboBox; + private ComboBox JewelNameComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs new file mode 100644 index 0000000..b478d0f --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs @@ -0,0 +1,104 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormStoreReplenishment : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _storeLogic; + private readonly IJewelLogic _jewelLogic; + private readonly List? _listStores; + private readonly List? _listJewels; + public FormStoreReplenishment(ILogger logger, IStoreLogic storeLogic, IJewelLogic jewelLogic) + { + InitializeComponent(); + _storeLogic = storeLogic; + _jewelLogic = jewelLogic; + _logger = logger; + _listStores = storeLogic.ReadList(null); + if (_listStores != null) + { + StoreNameComboBox.DisplayMember = "StoreName"; + StoreNameComboBox.ValueMember = "Id"; + StoreNameComboBox.DataSource = _listStores; + StoreNameComboBox.SelectedItem = null; + } + + _listJewels = jewelLogic.ReadList(null); + if (_listJewels != null) + { + JewelNameComboBox.DisplayMember = "JewelName"; + JewelNameComboBox.ValueMember = "Id"; + JewelNameComboBox.DataSource = _listJewels; + JewelNameComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (StoreNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (JewelNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Добавление изделия в магазин"); + + try + { + var jewel = _jewelLogic.ReadElement(new() + { + Id = (int)JewelNameComboBox.SelectedValue + }); + + if (jewel == null) + { + throw new Exception("Не найдено изделие. Дополнительная информация в логах."); + } + + var resultOperation = _storeLogic.AddJewel( + model: new() { Id = (int)StoreNameComboBox.SelectedValue }, + jewel: jewel, + quantity: Convert.ToInt32(CountTextBox.Text) + ); + + if (!resultOperation) + { + throw new Exception("Ошибка при добавлении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs new file mode 100644 index 0000000..31a8bdf --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs @@ -0,0 +1,122 @@ +namespace JewelryStore +{ + partial class FormStores + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 2); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(768, 452); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(807, 52); + this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(151, 38); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(807, 129); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(151, 38); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(807, 203); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(151, 38); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(807, 277); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(151, 35); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormStores + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(988, 457); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormStores"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormStores_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs new file mode 100644 index 0000000..8c84e6e --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs @@ -0,0 +1,122 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormStores : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _logic; + public FormStores(ILogger logger, IStoreLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormStores_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["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Jewels"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void DeleteButton_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 StoreBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStore)); + + if (service is FormStore form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStore)); + + if (service is FormStore form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/JewelryStore.csproj b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/JewelryStore.csproj new file mode 100644 index 0000000..cbfa7e5 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/JewelryStore.csproj @@ -0,0 +1,28 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs new file mode 100644 index 0000000..6858d64 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs @@ -0,0 +1,57 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using JewelryStoreBusinessLogic.BusinessLogics; +using JewelryStoreContracts.StoragesModels; + +namespace JewelryStore +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + 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(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/nlog.config b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..a15a2b3 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,113 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs new file mode 100644 index 0000000..c0dd189 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -0,0 +1,118 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class JewelLogic : IJewelLogic + { + private readonly ILogger _logger; + private readonly IJewelStorage _jewelStorage; + + public JewelLogic(ILogger logger, IJewelStorage jewelStorage) + { + _logger = logger; + _jewelStorage = jewelStorage; + } + + public List? ReadList(JewelSearchModel? model) + { + _logger.LogInformation("ReadList. JewelName:{JewelName}. Id:{Id}", model?.JewelName, model?.Id); + var list = model == null ? _jewelStorage.GetFullList() : _jewelStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public JewelViewModel? ReadElement(JewelSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. JewelName:{JewelName}. Id:{Id}", model.JewelName, model.Id); + var element = _jewelStorage.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(JewelBindingModel model) + { + CheckModel(model); + if (_jewelStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(JewelBindingModel model) + { + CheckModel(model); + if (_jewelStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(JewelBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_jewelStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(JewelBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.JewelName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.JewelName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + if (model.JewelComponents == null || model.JewelComponents.Count == 0) + { + throw new ArgumentNullException("Нет компонентов изделия", nameof(model.JewelComponents)); + } + _logger.LogInformation("Jewel. JewelName:{JewelName}. Cost:{Cost}. Id:{Id}", model.JewelName, model.Price, model.Id); + var element = _jewelStorage.GetElement(new JewelSearchModel + { + JewelName = model.JewelName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..aeba2c9 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,144 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Готов) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); + } + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); + } + model.Status = OrderStatus.Готов; + _orderStorage.Update(model); + return true; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Принят) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + } + model.Status = OrderStatus.Выполняется; + _orderStorage.Update(model); + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Заказ с таким ID уже существует"); + } + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs new file mode 100644 index 0000000..08101df --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs @@ -0,0 +1,183 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class StoreLogic : IStoreLogic + { + private readonly ILogger _logger; + private readonly IStoreStorage _storeStorage; + + public StoreLogic(ILogger logger, IStoreStorage storeStorage) + { + _logger = logger; + _storeStorage = storeStorage; + } + + public bool AddJewel(StoreSearchModel model, IJewelModel jewel, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddJewelInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); + var element = _storeStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddJewelInStore element not found"); + return false; + } + + _logger.LogInformation("AddJewelInStore find. Id:{Id}", element.Id); + + if (element.Jewels.TryGetValue(jewel.Id, out var pair)) + { + element.Jewels[jewel.Id] = (jewel, count + pair.Item2); + _logger.LogInformation("AddJewelInStore. Has been added {count} {jewel} in {StoreName}", count, jewel.JewelName, element.StoreName); + } + else + { + element.Jewels[jewel.Id] = (jewel, count); + _logger.LogInformation("AddJewelInStore. Has been added {count} new Jewel {jewel} in {StoreName}", count, jewel.JewelName, element.StoreName); + } + + _storeStorage.Update(new() + { + Id = element.Id, + StoreAdress = element.StoreAdress, + StoreName = element.StoreName, + OpeningDate = element.OpeningDate, + Jewels = element.Jewels + }); + return true; + } + + public bool Create(StoreBindingModel model) + { + CheckModel(model); + model.Jewels = new(); + + if (_storeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(StoreBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_storeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public StoreViewModel? ReadElement(StoreSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); + var element = _storeStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(StoreSearchModel? model) + { + _logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id); + + var list = (model == null) ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(StoreBindingModel model) + { + CheckModel(model, false); + + if (string.IsNullOrEmpty(model.StoreName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + } + + if (_storeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(StoreBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.StoreName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + } + + _logger.LogInformation("Store. StoreName:{StoreName}.StoreAdress:{StoreAdress}. Id: {Id}", model.StoreName, model.StoreAdress, model.Id); + var element = _storeStorage.GetElement(new StoreSearchModel + { + StoreName = model.StoreName + }); + + if (element != null && element.Id != model.Id && element.StoreName == model.StoreName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj new file mode 100644 index 0000000..b375f2f --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..4ebc6b2 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using JewelryStoreDataModels.Models; + +namespace JewelryStoreContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs new file mode 100644 index 0000000..3eceeec --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs @@ -0,0 +1,17 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class JewelBindingModel : IJewelModel + { + public int Id { get; set; } + public string JewelName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary JewelComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..ef863a4 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int JewelId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs new file mode 100644 index 0000000..1db1c82 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs @@ -0,0 +1,22 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class StoreBindingModel : IStoreModel + { + public string StoreName { get; set; } = string.Empty; + + public string StoreAdress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } = DateTime.Now; + + public Dictionary Jewels { get; set; } = new(); + + public int Id { get; set; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..ad21089 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs new file mode 100644 index 0000000..1fec5be --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs @@ -0,0 +1,15 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IJewelLogic + { + List? ReadList(JewelSearchModel? model); + JewelViewModel? ReadElement(JewelSearchModel model); + bool Create(JewelBindingModel model); + bool Update(JewelBindingModel model); + bool Delete(JewelBindingModel model); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..e6afa1a --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs new file mode 100644 index 0000000..d939ba2 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IStoreLogic + { + List? ReadList(StoreSearchModel? model); + StoreViewModel? ReadElement(StoreSearchModel model); + bool Create(StoreBindingModel model); + bool Update(StoreBindingModel model); + bool Delete(StoreBindingModel model); + bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/Class1.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/Class1.cs deleted file mode 100644 index e5cbec2..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace JewelryStoreContracts -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj index 8d911b3..1e0a91c 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -7,11 +7,7 @@ - - - - - + diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..0ab91eb --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace JewelryStoreContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs new file mode 100644 index 0000000..84fd88b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs @@ -0,0 +1,8 @@ +namespace JewelryStoreContracts.SearchModels +{ + public class JewelSearchModel + { + public int? Id { get; set; } + public string? JewelName { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..1639ae0 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace JewelryStoreContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs new file mode 100644 index 0000000..1ffd758 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class StoreSearchModel + { + public int? Id { get; set; } + public string? StoreName { get; set; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IComponentStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IComponentStorage.cs new file mode 100644 index 0000000..5796896 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IComponentStorage.cs @@ -0,0 +1,16 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IJewelStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IJewelStorage.cs new file mode 100644 index 0000000..92cac38 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IJewelStorage.cs @@ -0,0 +1,16 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IJewelStorage + { + List GetFullList(); + List GetFilteredList(JewelSearchModel model); + JewelViewModel? GetElement(JewelSearchModel model); + JewelViewModel? Insert(JewelBindingModel model); + JewelViewModel? Update(JewelBindingModel model); + JewelViewModel? Delete(JewelBindingModel model); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IOrderStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IOrderStorage.cs new file mode 100644 index 0000000..fcd4576 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IOrderStorage.cs @@ -0,0 +1,16 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs new file mode 100644 index 0000000..46b04e8 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesModels +{ + public interface IStoreStorage + { + List GetFullList(); + List GetFilteredList(StoreSearchModel model); + StoreViewModel? GetElement(StoreSearchModel model); + StoreViewModel? Insert(StoreBindingModel model); + StoreViewModel? Update(StoreBindingModel model); + StoreViewModel? Delete(StoreBindingModel model); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..ab46b0a --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using JewelryStoreDataModels.Models; +using System.ComponentModel; + +namespace JewelryStoreContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs new file mode 100644 index 0000000..3fe9d88 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs @@ -0,0 +1,19 @@ +using JewelryStoreDataModels.Models; +using System.ComponentModel; + +namespace JewelryStoreContracts.ViewModels +{ + public class JewelViewModel : IJewelModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string JewelName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary JewelComponents + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..e28a225 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,27 @@ +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System.ComponentModel; + +namespace JewelryStoreContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int JewelId { get; set; } + + [DisplayName("Изделие")] + public string JewelName { 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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs new file mode 100644 index 0000000..b04091d --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs @@ -0,0 +1,25 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class StoreViewModel : IStoreModel + { + public Dictionary Jewels { get; set; } = new(); + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string StoreName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string StoreAdress { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } = DateTime.Now; + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs new file mode 100644 index 0000000..896f93f --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs @@ -0,0 +1,30 @@ +using JewelryStoreListImplement.Models; + +namespace JewelryStoreListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Jewels { get; set; } + public List Stores { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Jewels = new List(); + Stores = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..5d1f604 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,109 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; + +namespace JewelryStoreListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs new file mode 100644 index 0000000..25bcedb --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -0,0 +1,108 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; + +namespace JewelryStoreListImplement.Implements +{ + public class JewelStorage : IJewelStorage + { + private readonly DataListSingleton _source; + + public JewelStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var jewel in _source.Jewels) + { + result.Add(jewel.GetViewModel); + } + return result; + } + + public List GetFilteredList(JewelSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.JewelName)) + { + return result; + } + foreach (var jewel in _source.Jewels) + { + if (jewel.JewelName.Contains(model.JewelName)) + { + result.Add(jewel.GetViewModel); + } + } + return result; + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + foreach (var jewel in _source.Jewels) + { + if ((!string.IsNullOrEmpty(model.JewelName) && jewel.JewelName == model.JewelName) || + (model.Id.HasValue && jewel.Id == model.Id)) + { + return jewel.GetViewModel; + } + } + return null; + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + model.Id = 1; + foreach (var jewel in _source.Jewels) + { + if (model.Id <= jewel.Id) + { + model.Id = jewel.Id + 1; + } + } + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + _source.Jewels.Add(newJewel); + return newJewel.GetViewModel; + } + + public JewelViewModel? Update(JewelBindingModel model) + { + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.Id) + { + jewel.Update(model); + return jewel.GetViewModel; + } + } + return null; + } + + public JewelViewModel? Delete(JewelBindingModel model) + { + for (int i = 0; i < _source.Jewels.Count; ++i) + { + if (_source.Jewels[i].Id == model.Id) + { + var element = _source.Jewels[i]; + _source.Jewels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..6d7c8ae --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -0,0 +1,120 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; + +namespace JewelryStoreListImplement.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(AccessJewelStorage(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AccessJewelStorage(order.GetViewModel)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return AccessJewelStorage(order.GetViewModel); + } + } + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AccessJewelStorage(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AccessJewelStorage(order.GetViewModel); + } + } + return null; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AccessJewelStorage(element.GetViewModel); + } + } + return null; + } + + public OrderViewModel AccessJewelStorage(OrderViewModel model) + { + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.JewelId) + { + model.JewelName = jewel.JewelName; + break; + } + } + return model; + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs new file mode 100644 index 0000000..754c185 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs @@ -0,0 +1,123 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class StoreStorage : IStoreStorage + { + private readonly DataListSingleton _source; + public StoreStorage() + { + _source = DataListSingleton.GetInstance(); + } + public StoreViewModel? Delete(StoreBindingModel model) + { + for (int i = 0; i < _source.Stores.Count; ++i) + { + if (_source.Stores[i].Id == model.Id) + { + var element = _source.Stores[i]; + _source.Stores.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public StoreViewModel? GetElement(StoreSearchModel model) + { + if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue) + { + return null; + } + + foreach (var store in _source.Stores) + { + if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id)) + { + return store.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(StoreSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.StoreName)) + { + return result; + } + + foreach (var store in _source.Stores) + { + if (store.StoreName.Contains(model.StoreName)) + { + result.Add(store.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var store in _source.Stores) + { + result.Add(store.GetViewModel); + } + + return result; + } + + public StoreViewModel? Insert(StoreBindingModel model) + { + model.Id = 1; + + foreach (var store in _source.Stores) + { + if (model.Id <= store.Id) + { + model.Id = store.Id + 1; + } + } + + var newStore = Store.Create(model); + + if (newStore == null) + { + return null; + } + + _source.Stores.Add(newStore); + + return newStore.GetViewModel; + } + + public StoreViewModel? Update(StoreBindingModel model) + { + foreach (var store in _source.Stores) + { + if (store.Id == model.Id) + { + store.Update(model); + return store.GetViewModel; + } + } + + return null; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj new file mode 100644 index 0000000..8995315 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Component.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Component.cs new file mode 100644 index 0000000..45bc5b4 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Component.cs @@ -0,0 +1,44 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Jewel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Jewel.cs new file mode 100644 index 0000000..e9a590d --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Jewel.cs @@ -0,0 +1,52 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreListImplement.Models +{ + public class Jewel : IJewelModel + { + public int Id { get; private set; } + public string JewelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary JewelComponents + { + get; + private set; + } = new Dictionary(); + + public static Jewel? Create(JewelBindingModel? model) + { + if (model == null) + { + return null; + } + return new Jewel() + { + Id = model.Id, + JewelName = model.JewelName, + Price = model.Price, + JewelComponents = model.JewelComponents + }; + } + + public void Update(JewelBindingModel? model) + { + if (model == null) + { + return; + } + JewelName = model.JewelName; + Price = model.Price; + JewelComponents = model.JewelComponents; + } + + public JewelViewModel GetViewModel => new() + { + Id = Id, + JewelName = JewelName, + Price = Price, + JewelComponents = JewelComponents + }; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs new file mode 100644 index 0000000..12f5a72 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs @@ -0,0 +1,60 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int JewelId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + JewelId = model.JewelId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.DateImplement.HasValue) + { + DateImplement = model.DateImplement; + } + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + JewelId = JewelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs new file mode 100644 index 0000000..8515902 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs @@ -0,0 +1,59 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Store : IStoreModel + { + public string StoreName { get; private set; } = string.Empty; + public string StoreAdress { get; private set; } = string.Empty; + + public DateTime OpeningDate { get; private set; } + + public Dictionary Jewels { get; private set; } = new(); + + public int Id { get; private set; } + + public static Store? Create(StoreBindingModel? model) + { + if (model == null) + { + return null; + } + return new Store() + { + Id = model.Id, + StoreName = model.StoreName, + StoreAdress = model.StoreAdress, + OpeningDate = model.OpeningDate, + Jewels = new() + }; + } + + public void Update(StoreBindingModel? model) + { + if (model == null) + { + return; + } + StoreName = model.StoreName; + StoreAdress = model.StoreAdress; + OpeningDate = model.OpeningDate; + } + + public StoreViewModel GetViewModel => new() + { + Id = Id, + StoreName = StoreName, + StoreAdress = StoreAdress, + OpeningDate = OpeningDate, + Jewels = Jewels + }; + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore.sln b/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore.sln deleted file mode 100644 index 3a59696..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32825.248 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PIbd-23_Panina.A.D_JewelryStore", "PIbd-23_Panina.A.D_JewelryStore\PIbd-23_Panina.A.D_JewelryStore.csproj", "{55576344-DD68-4C87-9C23-CF5EECC16E35}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "JewelryStoreContracts\JewelryStoreContracts.csproj", "{827BB4DA-C4AA-44E3-A751-74BDFE59540A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {55576344-DD68-4C87-9C23-CF5EECC16E35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {55576344-DD68-4C87-9C23-CF5EECC16E35}.Debug|Any CPU.Build.0 = Debug|Any CPU - {55576344-DD68-4C87-9C23-CF5EECC16E35}.Release|Any CPU.ActiveCfg = Release|Any CPU - {55576344-DD68-4C87-9C23-CF5EECC16E35}.Release|Any CPU.Build.0 = Release|Any CPU - {827BB4DA-C4AA-44E3-A751-74BDFE59540A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {827BB4DA-C4AA-44E3-A751-74BDFE59540A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {827BB4DA-C4AA-44E3-A751-74BDFE59540A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {827BB4DA-C4AA-44E3-A751-74BDFE59540A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {DA5CE19F-CC4B-4E78-9ACB-0E78895F6777} - EndGlobalSection -EndGlobal diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.Designer.cs deleted file mode 100644 index 686e1f4..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace PIbd_23_Panina.A.D_JewelryStore -{ - 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/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.cs b/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.cs deleted file mode 100644 index f3105b5..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PIbd_23_Panina.A.D_JewelryStore -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.resx b/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/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/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore.csproj b/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore.csproj deleted file mode 100644 index c870326..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - WinExe - net6.0-windows - PIbd_23_Panina.A.D_JewelryStore - enable - true - enable - - - \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Program.cs deleted file mode 100644 index f639202..0000000 --- a/PIbd-23_Panina.A.D_JewelryStore/PIbd-23_Panina.A.D_JewelryStore/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace PIbd_23_Panina.A.D_JewelryStore -{ - 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