From e845460393934a7e267e051a67612ab2c109821c Mon Sep 17 00:00:00 2001 From: DeerElk Date: Thu, 20 Jun 2024 02:41:23 +0400 Subject: [PATCH] lab1-hard --- .gitignore | 1 + .../Confectionery/FormCreateOrder.Designer.cs | 232 +++++----- .../Confectionery/FormMain.Designer.cs | 34 +- Confectionery/Confectionery/FormMain.cs | 22 +- .../Confectionery/FormPastry.Designer.cs | 396 +++++++++--------- .../Confectionery/FormShop.Designer.cs | 212 ++++++++++ Confectionery/Confectionery/FormShop.cs | 119 ++++++ Confectionery/Confectionery/FormShop.resx | 120 ++++++ .../Confectionery/FormShops.Designer.cs | 125 ++++++ Confectionery/Confectionery/FormShops.cs | 115 +++++ Confectionery/Confectionery/FormShops.resx | 120 ++++++ .../Confectionery/FormSupply.Designer.cs | 157 +++++++ Confectionery/Confectionery/FormSupply.cs | 133 ++++++ Confectionery/Confectionery/FormSupply.resx | 120 ++++++ Confectionery/Confectionery/Program.cs | 12 +- .../BusinessLogics/ShopLogic.cs | 169 ++++++++ .../BindingModels/ShopBindingModel.cs | 13 + .../BusinessLogicsContracts/IShopLogic.cs | 16 + .../SearchModels/ShopSearchModel.cs | 8 + .../StoragesContracts/IShopStorage.cs | 16 + .../ViewModels/ShopViewModel.cs | 17 + .../Models/IShopModel.cs | 10 + .../DataListSingleton.cs | 6 +- .../Implements/ShopStorage.cs | 101 +++++ .../ConfectioneryListImplement/Models/Shop.cs | 48 +++ 25 files changed, 1994 insertions(+), 328 deletions(-) create mode 100644 Confectionery/Confectionery/FormShop.Designer.cs create mode 100644 Confectionery/Confectionery/FormShop.cs create mode 100644 Confectionery/Confectionery/FormShop.resx create mode 100644 Confectionery/Confectionery/FormShops.Designer.cs create mode 100644 Confectionery/Confectionery/FormShops.cs create mode 100644 Confectionery/Confectionery/FormShops.resx create mode 100644 Confectionery/Confectionery/FormSupply.Designer.cs create mode 100644 Confectionery/Confectionery/FormSupply.cs create mode 100644 Confectionery/Confectionery/FormSupply.resx create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs create mode 100644 Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs create mode 100644 Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs create mode 100644 Confectionery/ConfectioneryDataModels/Models/IShopModel.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Shop.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..e41ed9d 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/Confectionery/ImplementationExtensions diff --git a/Confectionery/Confectionery/FormCreateOrder.Designer.cs b/Confectionery/Confectionery/FormCreateOrder.Designer.cs index 377b38d..e98b106 100644 --- a/Confectionery/Confectionery/FormCreateOrder.Designer.cs +++ b/Confectionery/Confectionery/FormCreateOrder.Designer.cs @@ -20,125 +20,125 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #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() - { - labelPastry = new Label(); - labelCount = new Label(); - labelSum = new Label(); - comboBoxPastry = new ComboBox(); - textBoxCount = new TextBox(); - textBoxSum = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelPastry - // - labelPastry.AutoSize = true; - labelPastry.Location = new Point(16, 21); - labelPastry.Name = "labelPastry"; - labelPastry.Size = new Size(84, 25); - labelPastry.TabIndex = 0; - labelPastry.Text = "Изделие:"; - // - // labelCount - // - labelCount.AutoSize = true; - labelCount.Location = new Point(16, 66); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(111, 25); - labelCount.TabIndex = 1; - labelCount.Text = "Количество:"; - // - // labelSum - // - labelSum.AutoSize = true; - labelSum.Location = new Point(16, 112); - labelSum.Name = "labelSum"; - labelSum.Size = new Size(71, 25); - labelSum.TabIndex = 2; - labelSum.Text = "Сумма:"; - // - // comboBoxPastry - // - comboBoxPastry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - comboBoxPastry.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxPastry.FormattingEnabled = true; - comboBoxPastry.Location = new Point(170, 21); - comboBoxPastry.Name = "comboBoxPastry"; - comboBoxPastry.Size = new Size(396, 33); - comboBoxPastry.TabIndex = 3; - comboBoxPastry.SelectedIndexChanged += ComboBoxPastry_SelectedIndexChanged; - // - // textBoxCount - // - textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxCount.Location = new Point(170, 66); - textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(396, 31); - textBoxCount.TabIndex = 4; - textBoxCount.TextChanged += TextBoxCount_TextChanged; - // - // textBoxSum - // - textBoxSum.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxSum.Location = new Point(170, 112); - textBoxSum.Name = "textBoxSum"; - textBoxSum.ReadOnly = true; - textBoxSum.Size = new Size(396, 31); - textBoxSum.TabIndex = 5; - // - // buttonSave - // - buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(336, 148); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(112, 34); - buttonSave.TabIndex = 6; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // buttonCancel - // - buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(454, 148); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(112, 34); - buttonCancel.TabIndex = 7; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // FormCreateOrder - // - AutoScaleDimensions = new SizeF(10F, 25F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(578, 194); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxSum); - Controls.Add(textBoxCount); - Controls.Add(comboBoxPastry); - Controls.Add(labelSum); - Controls.Add(labelCount); - Controls.Add(labelPastry); - Name = "FormCreateOrder"; - Text = "Создание заказа"; - Load += FormCreateOrder_Load; - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelPastry = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxPastry = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelPastry + // + labelPastry.AutoSize = true; + labelPastry.Location = new Point(16, 21); + labelPastry.Name = "labelPastry"; + labelPastry.Size = new Size(84, 25); + labelPastry.TabIndex = 0; + labelPastry.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(16, 66); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(111, 25); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(16, 112); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(71, 25); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // comboBoxPastry + // + comboBoxPastry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxPastry.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPastry.FormattingEnabled = true; + comboBoxPastry.Location = new Point(170, 21); + comboBoxPastry.Name = "comboBoxPastry"; + comboBoxPastry.Size = new Size(396, 33); + comboBoxPastry.TabIndex = 3; + comboBoxPastry.SelectedIndexChanged += ComboBoxPastry_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxCount.Location = new Point(170, 66); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(396, 31); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxSum.Location = new Point(170, 112); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(396, 31); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(336, 148); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(112, 34); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(454, 148); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 34); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(578, 194); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPastry); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelPastry); + Name = "FormCreateOrder"; + Text = "Создание заказа"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Label labelPastry; + private Label labelPastry; private Label labelCount; private Label labelSum; private ComboBox comboBoxPastry; diff --git a/Confectionery/Confectionery/FormMain.Designer.cs b/Confectionery/Confectionery/FormMain.Designer.cs index f9b4147..e1d1137 100644 --- a/Confectionery/Confectionery/FormMain.Designer.cs +++ b/Confectionery/Confectionery/FormMain.Designer.cs @@ -38,7 +38,9 @@ referencesToolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem(); pastriesToolStripMenuItem = new ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + shopsToolStripMenuItem = new ToolStripMenuItem(); + supplyToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -121,8 +123,8 @@ // // referencesToolStripMenuItem // - referencesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastriesToolStripMenuItem }); - referencesToolStripMenuItem.Name = "referencesToolStripMenuItem"; + referencesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastriesToolStripMenuItem, shopsToolStripMenuItem, supplyToolStripMenuItem }); + referencesToolStripMenuItem.Name = "referencesToolStripMenuItem"; referencesToolStripMenuItem.Size = new Size(139, 29); referencesToolStripMenuItem.Text = "Справочники"; // @@ -139,10 +141,24 @@ pastriesToolStripMenuItem.Size = new Size(298, 34); pastriesToolStripMenuItem.Text = "Кондитерские изделия"; pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(10F, 25F); + // + // shopsToolStripMenuItem + // + shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + shopsToolStripMenuItem.Size = new Size(298, 34); + shopsToolStripMenuItem.Text = "Магазины"; + shopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // supplyToolStripMenuItem + // + supplyToolStripMenuItem.Name = "supplyToolStripMenuItem"; + supplyToolStripMenuItem.Size = new Size(298, 34); + supplyToolStripMenuItem.Text = "Поставки"; + supplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1154, 442); Controls.Add(menuStrip); @@ -175,5 +191,7 @@ private ToolStripMenuItem referencesToolStripMenuItem; private ToolStripMenuItem pastriesToolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem; - } + private ToolStripMenuItem shopsToolStripMenuItem; + private ToolStripMenuItem supplyToolStripMenuItem; + } } \ No newline at end of file diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs index 31ae8de..5ea0a41 100644 --- a/Confectionery/Confectionery/FormMain.cs +++ b/Confectionery/Confectionery/FormMain.cs @@ -60,7 +60,27 @@ namespace ConfectioneryView form.ShowDialog(); } } - private void ButtonCreateOrder_Click(object sender, EventArgs e) + private void ShopsToolStripMenuItem_Click(object sender, + EventArgs e) + { + var service = Program.ServiceProvider?.GetService( + typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void SupplyToolStripMenuItem_Click(object sender, + EventArgs e) + { + var service = Program.ServiceProvider?.GetService( + typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService( typeof(FormCreateOrder)); diff --git a/Confectionery/Confectionery/FormPastry.Designer.cs b/Confectionery/Confectionery/FormPastry.Designer.cs index b6b2990..e3af955 100644 --- a/Confectionery/Confectionery/FormPastry.Designer.cs +++ b/Confectionery/Confectionery/FormPastry.Designer.cs @@ -20,207 +20,207 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - labelName = new Label(); - labelPrice = new Label(); - textBoxName = new TextBox(); - textBoxPrice = new TextBox(); - groupBox = new GroupBox(); - buttonRef = new Button(); - buttonDel = new Button(); - buttonUpd = new Button(); - buttonAdd = new Button(); - dataGridView = new DataGridView(); - id = new DataGridViewTextBoxColumn(); - Component = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); - buttonCancel = new Button(); - buttonSave = new Button(); - groupBox.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(16, 21); - labelName.Name = "labelName"; - labelName.Size = new Size(94, 25); - labelName.TabIndex = 0; - labelName.Text = "Название:"; - // - // labelPrice - // - labelPrice.AutoSize = true; - labelPrice.Location = new Point(16, 66); - labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(103, 25); - labelPrice.TabIndex = 1; - labelPrice.Text = "Стоимость:"; - // - // textBoxName - // - textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxName.Location = new Point(170, 21); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(396, 31); - textBoxName.TabIndex = 2; - // - // textBoxPrice - // - textBoxPrice.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxPrice.Location = new Point(170, 66); - textBoxPrice.Name = "textBoxPrice"; - textBoxPrice.Size = new Size(160, 31); - textBoxPrice.TabIndex = 3; - // - // groupBox - // - groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - groupBox.Controls.Add(buttonRef); - groupBox.Controls.Add(buttonDel); - groupBox.Controls.Add(buttonUpd); - groupBox.Controls.Add(buttonAdd); - groupBox.Controls.Add(dataGridView); - groupBox.Location = new Point(16, 112); - groupBox.Name = "groupBox"; - groupBox.Size = new Size(850, 286); - groupBox.TabIndex = 4; - groupBox.TabStop = false; - groupBox.Text = "Компоненты"; - // - // buttonRef - // - buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRef.Location = new Point(732, 215); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(112, 56); - buttonRef.TabIndex = 4; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // buttonDel - // - buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonDel.Location = new Point(732, 153); - buttonDel.Name = "buttonDel"; - buttonDel.Size = new Size(112, 56); - buttonDel.TabIndex = 3; - buttonDel.Text = "Удалить"; - buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += ButtonDel_Click; - // - // buttonUpd - // - buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonUpd.Location = new Point(732, 91); - buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(112, 56); - buttonUpd.TabIndex = 2; - buttonUpd.Text = "Изменить"; - buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += ButtonUpd_Click; - // - // buttonAdd - // - buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonAdd.Location = new Point(732, 29); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(112, 56); - buttonAdd.TabIndex = 1; - buttonAdd.Text = "Добавить"; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.BackgroundColor = SystemColors.Window; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, Component, Count }); - dataGridView.Location = new Point(6, 29); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(720, 251); - dataGridView.TabIndex = 0; - // - // id - // - id.HeaderText = "id"; - id.MinimumWidth = 6; - id.Name = "id"; - id.Visible = false; - // - // Component - // - Component.FillWeight = 200F; - Component.HeaderText = "Компонент"; - Component.MinimumWidth = 6; - Component.Name = "Component"; - // - // Count - // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - // - // buttonCancel - // - buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(754, 404); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(112, 34); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // buttonSave - // - buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(636, 404); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(112, 34); - buttonSave.TabIndex = 6; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // FormPastry - // - AutoScaleDimensions = new SizeF(10F, 25F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(878, 444); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(groupBox); - Controls.Add(textBoxPrice); - Controls.Add(textBoxName); - Controls.Add(labelPrice); - Controls.Add(labelName); - Name = "FormPastry"; - Text = "Кондитерское изделие"; - Load += FormPastry_Load; - Click += FormPastry_Load; - groupBox.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + id = new DataGridViewTextBoxColumn(); + Component = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonSave = new Button(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(94, 25); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(16, 66); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(103, 25); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxName.Location = new Point(170, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(396, 31); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxPrice.Location = new Point(170, 66); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(160, 31); + textBoxPrice.TabIndex = 3; + // + // groupBox + // + groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBox.Controls.Add(buttonRef); + groupBox.Controls.Add(buttonDel); + groupBox.Controls.Add(buttonUpd); + groupBox.Controls.Add(buttonAdd); + groupBox.Controls.Add(dataGridView); + groupBox.Location = new Point(16, 112); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(850, 286); + groupBox.TabIndex = 4; + groupBox.TabStop = false; + groupBox.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(732, 215); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(112, 56); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDel.Location = new Point(732, 153); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(112, 56); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(732, 91); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(112, 56); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(732, 29); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(112, 56); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, Component, Count }); + dataGridView.Location = new Point(6, 29); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(720, 251); + dataGridView.TabIndex = 0; + // + // id + // + id.HeaderText = "id"; + id.MinimumWidth = 6; + id.Name = "id"; + id.Visible = false; + // + // Component + // + Component.FillWeight = 200F; + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(754, 404); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 34); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(636, 404); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(112, 34); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormPastry + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(878, 444); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(groupBox); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormPastry"; + Text = "Кондитерское изделие"; + Load += FormPastry_Load; + Click += FormPastry_Load; + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Label labelName; + private Label labelName; private Label labelPrice; private TextBox textBoxName; private TextBox textBoxPrice; diff --git a/Confectionery/Confectionery/FormShop.Designer.cs b/Confectionery/Confectionery/FormShop.Designer.cs new file mode 100644 index 0000000..ff8f9c0 --- /dev/null +++ b/Confectionery/Confectionery/FormShop.Designer.cs @@ -0,0 +1,212 @@ +namespace ConfectioneryView +{ + partial class FormShop + { + /// + /// 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() + { + dateTimePicker = new DateTimePicker(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + NameLabel = new Label(); + AdressLabel = new Label(); + DateLabel = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + PastryName = new DataGridViewTextBoxColumn(); + Price = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + dateTimePicker.Location = new Point(170, 111); + dateTimePicker.Margin = new Padding(4, 5, 4, 5); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(396, 31); + dateTimePicker.TabIndex = 0; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxName.Location = new Point(170, 21); + textBoxName.Margin = new Padding(4, 5, 4, 5); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(396, 31); + textBoxName.TabIndex = 1; + // + // textBoxAddress + // + textBoxAddress.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxAddress.Location = new Point(170, 66); + textBoxAddress.Margin = new Padding(4, 5, 4, 5); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(396, 31); + textBoxAddress.TabIndex = 2; + // + // NameLabel + // + NameLabel.AutoSize = true; + NameLabel.Location = new Point(16, 21); + NameLabel.Margin = new Padding(4, 0, 4, 0); + NameLabel.Name = "NameLabel"; + NameLabel.Size = new Size(94, 25); + NameLabel.TabIndex = 3; + NameLabel.Text = "Название:"; + // + // AdressLabel + // + AdressLabel.AutoSize = true; + AdressLabel.Location = new Point(16, 66); + AdressLabel.Margin = new Padding(4, 0, 4, 0); + AdressLabel.Name = "AdressLabel"; + AdressLabel.Size = new Size(66, 25); + AdressLabel.TabIndex = 4; + AdressLabel.Text = "Адрес:"; + // + // DateLabel + // + DateLabel.AutoSize = true; + DateLabel.Location = new Point(16, 111); + DateLabel.Margin = new Padding(4, 0, 4, 0); + DateLabel.Name = "DateLabel"; + DateLabel.Size = new Size(53, 25); + DateLabel.TabIndex = 5; + DateLabel.Text = "Дата:"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(636, 404); + buttonSave.Margin = new Padding(4, 5, 4, 5); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(112, 34); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(754, 404); + buttonCancel.Margin = new Padding(4, 5, 4, 5); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 34); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, PastryName, Price, Count }); + dataGridView.Location = new Point(16, 156); + dataGridView.Margin = new Padding(4, 5, 4, 5); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(850, 238); + dataGridView.TabIndex = 8; + // + // ID + // + ID.HeaderText = "id"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 125; + // + // PastryName + // + PastryName.HeaderText = "Название"; + PastryName.MinimumWidth = 6; + PastryName.Name = "PastryName"; + PastryName.ReadOnly = true; + PastryName.Width = 150; + // + // Price + // + Price.HeaderText = "Цена"; + Price.MinimumWidth = 6; + Price.Name = "Price"; + Price.ReadOnly = true; + Price.Width = 125; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.ReadOnly = true; + Count.Width = 125; + // + // FormShop + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(878, 444); + Controls.Add(dataGridView); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(DateLabel); + Controls.Add(AdressLabel); + Controls.Add(NameLabel); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(dateTimePicker); + Margin = new Padding(4, 5, 4, 5); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePicker; + private TextBox textBoxName; + private TextBox textBoxAddress; + private Label NameLabel; + private Label AdressLabel; + private Label DateLabel; + private Button buttonSave; + private Button buttonCancel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn PastryName; + private DataGridViewTextBoxColumn Price; + private DataGridViewTextBoxColumn Count; + } +} diff --git a/Confectionery/Confectionery/FormShop.cs b/Confectionery/Confectionery/FormShop.cs new file mode 100644 index 0000000..14ac000 --- /dev/null +++ b/Confectionery/Confectionery/FormShop.cs @@ -0,0 +1,119 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; +namespace ConfectioneryView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _pastries; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement( + new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAddress.Text = shop.Address; + dateTimePicker.Text = shop.DateOpen.ToString(); + _pastries = shop.ShopPastries; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_pastries != null) + { + foreach (var Pastry in _pastries) + { + dataGridView.Rows.Add(new object[] { + Pastry.Key, Pastry.Value.Item1.PastryName, + Pastry.Value.Item1.Price, Pastry.Value.Item2 }); + } + } + } + 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = dateTimePicker.Value.Date, + ShopPastries = _pastries + }; + 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); + } + } + } +} diff --git a/Confectionery/Confectionery/FormShop.resx b/Confectionery/Confectionery/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/Confectionery/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/Confectionery/FormShops.Designer.cs b/Confectionery/Confectionery/FormShops.Designer.cs new file mode 100644 index 0000000..4f69d44 --- /dev/null +++ b/Confectionery/Confectionery/FormShops.Designer.cs @@ -0,0 +1,125 @@ +namespace ConfectioneryView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonRef = new Button(); + buttonDel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 5, 4, 5); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(742, 444); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(754, 12); + buttonAdd.Margin = new Padding(4, 5, 4, 5); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(112, 56); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(754, 74); + buttonUpd.Margin = new Padding(4, 5, 4, 5); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(112, 56); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(754, 136); + buttonRef.Margin = new Padding(4, 5, 4, 5); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(112, 56); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDel.Location = new Point(754, 198); + buttonDel.Margin = new Padding(4, 5, 4, 5); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(112, 56); + buttonDel.TabIndex = 4; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(878, 444); + Controls.Add(buttonDel); + Controls.Add(buttonRef); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(4, 5, 4, 5); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonRef; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormShops.cs b/Confectionery/Confectionery/FormShops.cs new file mode 100644 index 0000000..c788c40 --- /dev/null +++ b/Confectionery/Confectionery/FormShops.cs @@ -0,0 +1,115 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +namespace ConfectioneryView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic 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["ShopName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Address"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateOpen"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopPastries"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + var tmp = Convert.ToInt32( + dataGridView.SelectedRows[0].Cells["Id"].Value); + form._id = Convert.ToInt32( + dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) + == DialogResult.Yes) + { + int id = Convert.ToInt32( + dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception( + "Ошибка при удалении. " + + "Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/Confectionery/Confectionery/FormShops.resx b/Confectionery/Confectionery/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/Confectionery/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/Confectionery/FormSupply.Designer.cs b/Confectionery/Confectionery/FormSupply.Designer.cs new file mode 100644 index 0000000..920507f --- /dev/null +++ b/Confectionery/Confectionery/FormSupply.Designer.cs @@ -0,0 +1,157 @@ +namespace ConfectioneryView +{ + partial class FormSupply + { + /// + /// 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() + { + comboBoxShop = new ComboBox(); + comboBoxPastry = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelShop = new Label(); + labelPastry = new Label(); + labelCount = new Label(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(229, 21); + comboBoxShop.Margin = new Padding(4, 5, 4, 5); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(337, 33); + comboBoxShop.TabIndex = 0; + // + // comboBoxPastry + // + comboBoxPastry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxPastry.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPastry.FormattingEnabled = true; + comboBoxPastry.Location = new Point(229, 66); + comboBoxPastry.Margin = new Padding(4, 5, 4, 5); + comboBoxPastry.Name = "comboBoxPastry"; + comboBoxPastry.Size = new Size(337, 33); + comboBoxPastry.TabIndex = 1; + // + // textBoxCount + // + textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxCount.Location = new Point(229, 112); + textBoxCount.Margin = new Padding(4, 5, 4, 5); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(337, 31); + textBoxCount.TabIndex = 2; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(336, 148); + buttonSave.Margin = new Padding(4, 5, 4, 5); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(112, 34); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(454, 148); + buttonCancel.Margin = new Padding(4, 5, 4, 5); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 34); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(16, 21); + labelShop.Margin = new Padding(4, 0, 4, 0); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(85, 25); + labelShop.TabIndex = 5; + labelShop.Text = "Магазин:"; + // + // labelPastry + // + labelPastry.AutoSize = true; + labelPastry.Location = new Point(16, 66); + labelPastry.Margin = new Padding(4, 0, 4, 0); + labelPastry.Name = "labelPastry"; + labelPastry.Size = new Size(201, 25); + labelPastry.TabIndex = 6; + labelPastry.Text = "Кондитерское изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(16, 112); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(111, 25); + labelCount.TabIndex = 7; + labelCount.Text = "Количество:"; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(578, 194); + Controls.Add(labelCount); + Controls.Add(labelPastry); + Controls.Add(labelShop); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPastry); + Controls.Add(comboBoxShop); + Margin = new Padding(4, 5, 4, 5); + Name = "FormSupply"; + Text = "Поставки"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxPastry; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private Label labelShop; + private Label labelPastry; + private Label labelCount; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormSupply.cs b/Confectionery/Confectionery/FormSupply.cs new file mode 100644 index 0000000..b265d05 --- /dev/null +++ b/Confectionery/Confectionery/FormSupply.cs @@ -0,0 +1,133 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +namespace ConfectioneryView +{ + public partial class FormSupply : Form + { + private readonly List? _pastryList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IPastryLogic _pastryLogic; + public int ShopId + { + get + { + return Convert.ToInt32(comboBoxShop.SelectedValue); + } + set + { + comboBoxShop.SelectedValue = value; + } + } + public int PastryId + { + get + { + return Convert.ToInt32(comboBoxPastry.SelectedValue); + } + set + { + comboBoxPastry.SelectedValue = value; + } + } + public IPastryModel? PastryModel + { + get + { + if (_pastryList == null) + { + return null; + } + foreach (var elem in _pastryList) + { + if (elem.Id == PastryId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormSupply(IPastryLogic PastryLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _pastryLogic = PastryLogic; + _pastryList = PastryLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_pastryList != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = _pastryList; + comboBoxPastry.SelectedItem = null; + } + if (_shopsList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopsList; + comboBoxShop.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите кондитерское изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int count = Convert.ToInt32(textBoxCount.Text); + + bool res = _shopLogic.MakeSupply( + new ShopSearchModel() + { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, + _pastryLogic.ReadElement(new() + { Id = Convert.ToInt32(comboBoxPastry.SelectedValue) }), + count + ); + if (!res) + { + throw new Exception("Ошибка при пополнении. " + + "Дополнительная информация в логах"); + } + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception err) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/Confectionery/FormSupply.resx b/Confectionery/Confectionery/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/Confectionery/FormSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/Confectionery/Program.cs b/Confectionery/Confectionery/Program.cs index ca20fc5..d83f579 100644 --- a/Confectionery/Confectionery/Program.cs +++ b/Confectionery/Confectionery/Program.cs @@ -5,6 +5,7 @@ using ConfectioneryListImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using PastriesShopBusinessLogic.BusinessLogics; namespace ConfectioneryView { internal static class Program @@ -36,16 +37,21 @@ namespace ConfectioneryView 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(); + services.AddTransient(); + services.AddTransient(); + } } } diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..bd41055 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,169 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; +namespace PastriesShopBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + public List ReadList(ShopSearchModel model) + { + _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", + model?.Name, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : + _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + + } + public bool MakeSupply(ShopSearchModel model, + IPastryModel Pastry, int count) + { + _logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", + model.Name, model.Id); + if (model == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(model)); + } + if (Pastry == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(Pastry)); + } + if (count <= 0) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException( + "Количество должно быть положительным числом"); + } + ShopViewModel curModel = ReadElement(model); + if (curModel == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(curModel)); + } + if (curModel.ShopPastries.TryGetValue(Pastry.Id, out var pair)) + { + curModel.ShopPastries[Pastry.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopPastries.Add(Pastry.Id, (Pastry, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopPastries = curModel.ShopPastries, + }); + _logger.LogInformation( + "Success. PastryName:{PastryName}. Id:{Id}. Supply:{count}", + Pastry.PastryName, Pastry.Id, count); + return true; + } + public ShopViewModel ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", + model.Name, model.Id); + var element = _shopStorage.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(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адресса магазина", + nameof(model.Address)); + } + if (model.DateOpen == null) + { + throw new ArgumentNullException("Нет даты открытия магазина", + nameof(model.DateOpen)); + } + _logger.LogInformation( + "Shop. ShopName:{ShopName}.Address:{Address}. " + + "DateOpen:{DateOpen}. Id: { Id}", model.ShopName, + model.Address, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..982e2c7 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,13 @@ +using ConfectioneryDataModels.Models; +namespace ConfectioneryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public DateTime DateOpen { get; set; } + public Dictionary + ShopPastries { get; set; } = new(); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..6768b35 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,16 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(ShopSearchModel model, IPastryModel pastry, int count); + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..744bc90 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace ConfectioneryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..dca3812 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,16 @@ +using ConfectioneryDataModels.Models; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..8154be5 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,17 @@ +using ConfectioneryDataModels.Models; +using System.ComponentModel; +namespace ConfectioneryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } + public Dictionary + ShopPastries { get; set; } = new(); + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IShopModel.cs b/Confectionery/ConfectioneryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..0932fcd --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IShopModel.cs @@ -0,0 +1,10 @@ +namespace ConfectioneryDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary ShopPastries { get; } + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs index 88e7f95..64b1674 100644 --- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -7,12 +7,14 @@ namespace ConfectioneryListImplement public List Components { get; set; } public List Orders { get; set; } public List Pastries { get; set; } - private DataListSingleton() + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Pastries = new List(); - } + Shops = new List(); + } public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..cabf009 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,101 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +namespace ConfectioneryListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && + shop.ShopName == model.Name) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Shop.cs b/Confectionery/ConfectioneryListImplement/Models/Shop.cs new file mode 100644 index 0000000..41cf032 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Shop.cs @@ -0,0 +1,48 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +namespace ConfectioneryListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime DateOpen { get; private set; } + public Dictionary + ShopPastries { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopPastries = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopPastries = model.ShopPastries; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopPastries = ShopPastries + }; + } +} \ No newline at end of file -- 2.25.1