From 676d37152fcf9083acae765277e966168749a711 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 20 Feb 2024 01:34:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/FormShop.Designer.cs | 178 ++++++++++++++++++ FishFactory/FormShop.cs | 30 +++ FishFactory/FormShop.resx | 132 +++++++++++++ FishFactory/FormShopReplenish.Designer.cs | 141 ++++++++++++++ FishFactory/FormShopReplenish.cs | 30 +++ FishFactory/FormShopReplenish.resx | 120 ++++++++++++ FishFactory/FormShops.Designer.cs | 120 ++++++++++++ FishFactory/FormShops.cs | 40 ++++ FishFactory/FormShops.resx | 120 ++++++++++++ .../SearchModels/ShopSearchModel.cs | 6 +- .../StoragesContracts/IShopCannedStorage.cs | 12 -- .../StoragesContracts/IShopStorage.cs | 11 +- .../ViewModels/ShopViewModel.cs | 15 +- FishFactoryListImplement/DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 105 +++++++++++ FishFactoryListImplement/Models/Shop.cs | 59 ++++++ 16 files changed, 1103 insertions(+), 18 deletions(-) create mode 100644 FishFactory/FormShop.Designer.cs create mode 100644 FishFactory/FormShop.cs create mode 100644 FishFactory/FormShop.resx create mode 100644 FishFactory/FormShopReplenish.Designer.cs create mode 100644 FishFactory/FormShopReplenish.cs create mode 100644 FishFactory/FormShopReplenish.resx create mode 100644 FishFactory/FormShops.Designer.cs create mode 100644 FishFactory/FormShops.cs create mode 100644 FishFactory/FormShops.resx delete mode 100644 FishFactoryContracts/StoragesContracts/IShopCannedStorage.cs create mode 100644 FishFactoryListImplement/Implements/ShopStorage.cs create mode 100644 FishFactoryListImplement/Models/Shop.cs diff --git a/FishFactory/FormShop.Designer.cs b/FishFactory/FormShop.Designer.cs new file mode 100644 index 0000000..8c47b80 --- /dev/null +++ b/FishFactory/FormShop.Designer.cs @@ -0,0 +1,178 @@ +namespace FishFactory +{ + 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() + { + label1 = new Label(); + label2 = new Label(); + textBoxShopName = new TextBox(); + textBoxAdress = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + dataGridView = new DataGridView(); + CannedName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + label3 = new Label(); + dateTimePicker = new DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 23); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 0; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 67); + label2.Name = "label2"; + label2.Size = new Size(54, 20); + label2.TabIndex = 1; + label2.Text = "Адрес:"; + // + // textBoxShopName + // + textBoxShopName.Location = new Point(103, 20); + textBoxShopName.Name = "textBoxShopName"; + textBoxShopName.Size = new Size(304, 27); + textBoxShopName.TabIndex = 2; + // + // textBoxAdress + // + textBoxAdress.Location = new Point(103, 60); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new Size(304, 27); + textBoxAdress.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(513, 509); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(123, 33); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(663, 509); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(123, 33); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { CannedName, Count }); + dataGridView.Location = new Point(0, 108); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(851, 376); + dataGridView.TabIndex = 6; + // + // CannedName + // + CannedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + CannedName.HeaderText = "Консерва"; + CannedName.MinimumWidth = 6; + CannedName.Name = "CannedName"; + CannedName.ReadOnly = true; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 125; + Count.Name = "Count"; + Count.ReadOnly = true; + Count.Width = 170; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(438, 23); + label3.Name = "label3"; + label3.Size = new Size(113, 20); + label3.TabIndex = 7; + label3.Text = "Дата открытия:"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(557, 20); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(294, 27); + dateTimePicker.TabIndex = 8; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(863, 568); + Controls.Add(dateTimePicker); + Controls.Add(label3); + Controls.Add(dataGridView); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxAdress); + Controls.Add(textBoxShopName); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormShop"; + Text = "Магазин"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxShopName; + private TextBox textBoxAdress; + private Button buttonSave; + private Button buttonCancel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn CannedName; + private DataGridViewTextBoxColumn Count; + private Label label3; + private DateTimePicker dateTimePicker; + } +} \ No newline at end of file diff --git a/FishFactory/FormShop.cs b/FishFactory/FormShop.cs new file mode 100644 index 0000000..c0e3c13 --- /dev/null +++ b/FishFactory/FormShop.cs @@ -0,0 +1,30 @@ +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 FishFactory +{ + public partial class FormShop : Form + { + public FormShop() + { + InitializeComponent(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/FishFactory/FormShop.resx b/FishFactory/FormShop.resx new file mode 100644 index 0000000..aefdb73 --- /dev/null +++ b/FishFactory/FormShop.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/FishFactory/FormShopReplenish.Designer.cs b/FishFactory/FormShopReplenish.Designer.cs new file mode 100644 index 0000000..a9e44d9 --- /dev/null +++ b/FishFactory/FormShopReplenish.Designer.cs @@ -0,0 +1,141 @@ +namespace FishFactory +{ + partial class FormShopReplenish + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + comboBoxShopCanneds = new ComboBox(); + comboBoxCanned = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(23, 33); + label1.Name = "label1"; + label1.Size = new Size(72, 20); + label1.TabIndex = 0; + label1.Text = "Магазин:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(23, 78); + label2.Name = "label2"; + label2.Size = new Size(79, 20); + label2.TabIndex = 1; + label2.Text = "Консерва:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(23, 126); + label3.Name = "label3"; + label3.Size = new Size(93, 20); + label3.TabIndex = 2; + label3.Text = "Количество:"; + // + // comboBoxShopCanneds + // + comboBoxShopCanneds.FormattingEnabled = true; + comboBoxShopCanneds.Location = new Point(140, 33); + comboBoxShopCanneds.Name = "comboBoxShopCanneds"; + comboBoxShopCanneds.Size = new Size(383, 28); + comboBoxShopCanneds.TabIndex = 3; + // + // comboBoxCanned + // + comboBoxCanned.FormattingEnabled = true; + comboBoxCanned.Location = new Point(140, 78); + comboBoxCanned.Name = "comboBoxCanned"; + comboBoxCanned.Size = new Size(383, 28); + comboBoxCanned.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(140, 123); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(199, 27); + textBoxCount.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(281, 175); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(107, 34); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(407, 175); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(107, 34); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormShopReplenish + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(538, 221); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxCanned); + Controls.Add(comboBoxShopCanneds); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormShopReplenish"; + Text = "Пополнение магазина"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxShopCanneds; + private ComboBox comboBoxCanned; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FishFactory/FormShopReplenish.cs b/FishFactory/FormShopReplenish.cs new file mode 100644 index 0000000..b332189 --- /dev/null +++ b/FishFactory/FormShopReplenish.cs @@ -0,0 +1,30 @@ +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 FishFactory +{ + public partial class FormShopReplenish : Form + { + public FormShopReplenish() + { + InitializeComponent(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/FishFactory/FormShopReplenish.resx b/FishFactory/FormShopReplenish.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FishFactory/FormShopReplenish.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/FishFactory/FormShops.Designer.cs b/FishFactory/FormShops.Designer.cs new file mode 100644 index 0000000..1b66f80 --- /dev/null +++ b/FishFactory/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace FishFactory +{ + 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() + { + dataGridView1 = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.AllowUserToAddRows = false; + dataGridView1.AllowUserToDeleteRows = false; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(0, 0); + dataGridView1.Name = "dataGridView1"; + dataGridView1.ReadOnly = true; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.RowTemplate.Height = 29; + dataGridView1.Size = new Size(525, 673); + dataGridView1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.AccessibleRole = AccessibleRole.None; + buttonAdd.Location = new Point(565, 76); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(130, 35); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.AccessibleRole = AccessibleRole.None; + buttonUpd.Location = new Point(565, 130); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(130, 35); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.AccessibleRole = AccessibleRole.None; + buttonDel.Location = new Point(565, 186); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(130, 35); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.AccessibleRole = AccessibleRole.None; + buttonRef.Location = new Point(565, 243); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(130, 35); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(722, 674); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView1); + Name = "FormShops"; + Text = "Список магазинов"; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/FishFactory/FormShops.cs b/FishFactory/FormShops.cs new file mode 100644 index 0000000..aaa2d41 --- /dev/null +++ b/FishFactory/FormShops.cs @@ -0,0 +1,40 @@ +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 FishFactory +{ + public partial class FormShops : Form + { + public FormShops() + { + InitializeComponent(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + + } + + private void buttonDel_Click(object sender, EventArgs e) + { + + } + + private void buttonRef_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/FishFactory/FormShops.resx b/FishFactory/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FishFactory/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/FishFactoryContracts/SearchModels/ShopSearchModel.cs b/FishFactoryContracts/SearchModels/ShopSearchModel.cs index 1bc6f33..6109423 100644 --- a/FishFactoryContracts/SearchModels/ShopSearchModel.cs +++ b/FishFactoryContracts/SearchModels/ShopSearchModel.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace FishFactoryContracts.SearchModels { - internal class ShopSearchModel + public class ShopSearchModel { - punlic int? Id { get; set; } - public string ShopName { get; set; } + public int? Id { get; set; } + public string? ShopName { get; set; } } } diff --git a/FishFactoryContracts/StoragesContracts/IShopCannedStorage.cs b/FishFactoryContracts/StoragesContracts/IShopCannedStorage.cs deleted file mode 100644 index ae176ff..0000000 --- a/FishFactoryContracts/StoragesContracts/IShopCannedStorage.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FishFactoryContracts.StoragesContracts -{ - internal interface IShopCannedStorage - { - } -} diff --git a/FishFactoryContracts/StoragesContracts/IShopStorage.cs b/FishFactoryContracts/StoragesContracts/IShopStorage.cs index 0eb9b09..7c1dfa6 100644 --- a/FishFactoryContracts/StoragesContracts/IShopStorage.cs +++ b/FishFactoryContracts/StoragesContracts/IShopStorage.cs @@ -1,4 +1,7 @@ -using System; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +11,11 @@ namespace FishFactoryContracts.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/FishFactoryContracts/ViewModels/ShopViewModel.cs b/FishFactoryContracts/ViewModels/ShopViewModel.cs index 968df1e..bd93234 100644 --- a/FishFactoryContracts/ViewModels/ShopViewModel.cs +++ b/FishFactoryContracts/ViewModels/ShopViewModel.cs @@ -1,12 +1,23 @@ -using System; +using FishFactoryDataModel.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FishFactoryContracts.ViewModels { - internal class ShopViewModel + public class ShopViewModel { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopCanneds { get; set; } = new(); + } } diff --git a/FishFactoryListImplement/DataListSingleton.cs b/FishFactoryListImplement/DataListSingleton.cs index fd86094..a2ec10e 100644 --- a/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactoryListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace FishFactoryListImplement public List Components { get; set; } public List Orders { get; set; } public List Canneds { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Canneds = new List(); + Shop = new List(); } public static DataListSingleton GetInstance() { diff --git a/FishFactoryListImplement/Implements/ShopStorage.cs b/FishFactoryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..9b19e79 --- /dev/null +++ b/FishFactoryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,105 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.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 (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if (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/FishFactoryListImplement/Models/Shop.cs b/FishFactoryListImplement/Models/Shop.cs new file mode 100644 index 0000000..c5f18d2 --- /dev/null +++ b/FishFactoryListImplement/Models/Shop.cs @@ -0,0 +1,59 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryDataModel.Models; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Models +{ + internal class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } + public DateTime OpeningDate { get; private set; } + public Dictionary ShopCanneds + { + get; + private set; + } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + ShopCanneds = model.ShopCanneds + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopCanneds = ShopCanneds + }; + } +}