From 39127eaa2f5720963a13375dc8dfc88c7e6f19e6 Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 21 Apr 2023 03:43:43 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=BB=D1=801=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcretePlant/FormMain.Designer.cs | 30 ++- PrecastConcretePlant/FormMain.cs | 19 ++ PrecastConcretePlant/FormShop.Designer.cs | 193 ++++++++++++++++++ PrecastConcretePlant/FormShop.cs | 128 ++++++++++++ PrecastConcretePlant/FormShop.resx | 60 ++++++ .../FormShopReinforced.Designer.cs | 151 ++++++++++++++ PrecastConcretePlant/FormShopReinforced.cs | 97 +++++++++ PrecastConcretePlant/FormShopReinforced.resx | 60 ++++++ PrecastConcretePlant/FormShops.Designer.cs | 120 +++++++++++ PrecastConcretePlant/FormShops.cs | 110 ++++++++++ PrecastConcretePlant/FormShops.resx | 60 ++++++ PrecastConcretePlant/Program.cs | 5 + .../BusinessLogic/ShopLogic.cs | 152 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 25 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 29 +++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 107 ++++++++++ .../Models/Shop.cs | 58 ++++++ 22 files changed, 1476 insertions(+), 3 deletions(-) create mode 100644 PrecastConcretePlant/FormShop.Designer.cs create mode 100644 PrecastConcretePlant/FormShop.cs create mode 100644 PrecastConcretePlant/FormShop.resx create mode 100644 PrecastConcretePlant/FormShopReinforced.Designer.cs create mode 100644 PrecastConcretePlant/FormShopReinforced.cs create mode 100644 PrecastConcretePlant/FormShopReinforced.resx create mode 100644 PrecastConcretePlant/FormShops.Designer.cs create mode 100644 PrecastConcretePlant/FormShops.cs create mode 100644 PrecastConcretePlant/FormShops.resx create mode 100644 PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs create mode 100644 PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs create mode 100644 PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs create mode 100644 PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs create mode 100644 PrecastConcretePlantDataModels/Models/IShopModel.cs create mode 100644 PrecastConcretePlantListImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlantListImplement/Models/Shop.cs diff --git a/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/FormMain.Designer.cs index 423d8c2..78e7623 100644 --- a/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/FormMain.Designer.cs @@ -32,12 +32,14 @@ this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); + this.AddShopButton = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +58,8 @@ // this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ИзделияToolStripMenuItem, - this.КомпонентыToolStripMenuItem}); + this.КомпонентыToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.СправочникиToolStripMenuItem.Text = "Cправочники"; @@ -64,17 +67,24 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.ИзделияToolStripMenuItem.Text = "ЖБИ"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -134,11 +144,22 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // + // AddShopButton + // + this.AddShopButton.Location = new System.Drawing.Point(825, 228); + this.AddShopButton.Name = "AddShopButton"; + this.AddShopButton.Size = new System.Drawing.Size(104, 38); + this.AddShopButton.TabIndex = 7; + this.AddShopButton.Text = "Добавить в магазин"; + this.AddShopButton.UseVisualStyleBackColor = true; + this.AddShopButton.Click += new System.EventHandler(this.AddShopButton_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(953, 450); + this.Controls.Add(this.AddShopButton); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.OrderReadyButton); @@ -149,6 +170,7 @@ this.MainMenuStrip = this.MenuStrip; this.Name = "FormMain"; this.Text = "Завод ЖБИ"; + this.Load += new System.EventHandler(this.FormMain_Load); this.MenuStrip.ResumeLayout(false); this.MenuStrip.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); @@ -169,5 +191,7 @@ private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; + private ToolStripMenuItem магазиныToolStripMenuItem; + private Button AddShopButton; } } \ No newline at end of file diff --git a/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/FormMain.cs index 2721deb..86d69c3 100644 --- a/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/FormMain.cs @@ -179,5 +179,24 @@ namespace PrecastConcretePlantView { LoadData(); } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void AddShopButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopReinforced)); + if (service is FormShopReinforced form) + { + form.ShowDialog(); + LoadData(); + } + } } } diff --git a/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/FormShop.Designer.cs new file mode 100644 index 0000000..f1ee35a --- /dev/null +++ b/PrecastConcretePlant/FormShop.Designer.cs @@ -0,0 +1,193 @@ +namespace PrecastConcretePlantView +{ + 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() + { + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.textBoxShop = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelTime = new System.Windows.Forms.Label(); + this.labelAddress = new System.Windows.Forms.Label(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.labelShop = new System.Windows.Forms.Label(); + this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnReinforcedName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(393, 33); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(207, 23); + this.dateTimePicker.TabIndex = 28; + // + // textBoxShop + // + this.textBoxShop.Location = new System.Drawing.Point(19, 33); + this.textBoxShop.Name = "textBoxShop"; + this.textBoxShop.Size = new System.Drawing.Size(141, 23); + this.textBoxShop.TabIndex = 27; + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(372, 308); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.TabIndex = 26; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(497, 308); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.TabIndex = 25; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(166, 33); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.TabIndex = 24; + // + // labelTime + // + this.labelTime.AutoSize = true; + this.labelTime.Location = new System.Drawing.Point(393, 15); + this.labelTime.Name = "labelTime"; + this.labelTime.Size = new System.Drawing.Size(87, 15); + this.labelTime.TabIndex = 23; + this.labelTime.Text = "Дата открытия"; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(166, 15); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(40, 15); + this.labelAddress.TabIndex = 22; + this.labelAddress.Text = "Адрес"; + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnID, + this.ColumnReinforcedName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(19, 62); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(581, 240); + this.dataGridView.TabIndex = 21; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(19, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 20; + this.labelShop.Text = "Магазин"; + // + // ColumnID + // + this.ColumnID.HeaderText = "ID"; + this.ColumnID.MinimumWidth = 8; + this.ColumnID.Name = "ColumnID"; + this.ColumnID.Visible = false; + this.ColumnID.Width = 150; + // + // ColumnReinforcedName + // + this.ColumnReinforcedName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnReinforcedName.HeaderText = "ЖБИ"; + this.ColumnReinforcedName.MinimumWidth = 8; + this.ColumnReinforcedName.Name = "ColumnReinforcedName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 8; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 150; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(618, 347); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxShop); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelTime); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.labelShop); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DateTimePicker dateTimePicker; + private TextBox textBoxShop; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxAddress; + private Label labelTime; + private Label labelAddress; + private DataGridView dataGridView; + private Label labelShop; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnReinforcedName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/FormShop.cs new file mode 100644 index 0000000..d3aec17 --- /dev/null +++ b/PrecastConcretePlant/FormShop.cs @@ -0,0 +1,128 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantDataModels.Models; +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 PrecastConcretePlantView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + private Dictionary _shopReinforceds; + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopReinforceds = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxShop.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); + _shopReinforceds = view.Reinforceds ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка магазина"); + try + { + if (_shopReinforceds != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopReinforceds) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ReinforcedName, elem.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxShop.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 = textBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value.Date, + Reinforceds = _shopReinforceds + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/FormShop.resx b/PrecastConcretePlant/FormShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormShop.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/FormShopReinforced.Designer.cs b/PrecastConcretePlant/FormShopReinforced.Designer.cs new file mode 100644 index 0000000..6c8b8d9 --- /dev/null +++ b/PrecastConcretePlant/FormShopReinforced.Designer.cs @@ -0,0 +1,151 @@ +namespace PrecastConcretePlantView +{ + partial class FormShopReinforced + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.comboBoxReinforced = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelReinforced = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(345, 101); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 23; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(253, 101); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 22; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(89, 66); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 1410065408, + 2, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(344, 23); + this.numericUpDownCount.TabIndex = 21; + // + // comboBoxReinforced + // + this.comboBoxReinforced.FormattingEnabled = true; + this.comboBoxReinforced.Location = new System.Drawing.Point(88, 39); + this.comboBoxReinforced.Name = "comboBoxReinforced"; + this.comboBoxReinforced.Size = new System.Drawing.Size(345, 23); + this.comboBoxReinforced.TabIndex = 20; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(11, 68); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 19; + this.labelCount.Text = "Количество"; + // + // labelReinforced + // + this.labelReinforced.AutoSize = true; + this.labelReinforced.Location = new System.Drawing.Point(31, 42); + this.labelReinforced.Name = "labelReinforced"; + this.labelReinforced.Size = new System.Drawing.Size(34, 15); + this.labelReinforced.TabIndex = 18; + this.labelReinforced.Text = "ЖБИ"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(88, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(345, 23); + this.comboBoxShop.TabIndex = 17; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(28, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 16; + this.labelShop.Text = "Магазин"; + // + // FormShopReinforced + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(446, 136); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxReinforced); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelReinforced); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormShopReinforced"; + this.Text = "Добавление ЖБИ в магазин"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private NumericUpDown numericUpDownCount; + private ComboBox comboBoxReinforced; + private Label labelCount; + private Label labelReinforced; + private ComboBox comboBoxShop; + private Label labelShop; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormShopReinforced.cs b/PrecastConcretePlant/FormShopReinforced.cs new file mode 100644 index 0000000..bc18eed --- /dev/null +++ b/PrecastConcretePlant/FormShopReinforced.cs @@ -0,0 +1,97 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.ViewModels; +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 PrecastConcretePlantView +{ + public partial class FormShopReinforced : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly IReinforcedLogic _reinforcedLogic; + private readonly List? _listShops; + private readonly List? _listReinforced; + + public FormShopReinforced(ILogger logger, IShopLogic shopLogic, IReinforcedLogic reinforcedLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _reinforcedLogic = reinforcedLogic; + _logger = logger; + _listShops = shopLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + _listReinforced = reinforcedLogic.ReadList(null); + if (_listReinforced != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = _listReinforced; + comboBoxReinforced.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите ЖБИ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление ЖБИ в магазин"); + try + { + var reinforced = _reinforcedLogic.ReadElement(new() + { + Id = (int)comboBoxReinforced.SelectedValue + }); + if (reinforced == null) + { + throw new Exception("ЖБИ не найдено. Дополнительная информация в логах."); + } + var operationResult = _shopLogic.AddReinforcedInShop( + model: new() { Id = (int)comboBoxShop.SelectedValue }, + reinforced: reinforced, + count: (int)numericUpDownCount.Value + ); + if (!operationResult) + { + throw new Exception("Ошибка при добавлении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения ЖБИ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/FormShopReinforced.resx b/PrecastConcretePlant/FormShopReinforced.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormShopReinforced.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/FormShops.Designer.cs b/PrecastConcretePlant/FormShops.Designer.cs new file mode 100644 index 0000000..8914f44 --- /dev/null +++ b/PrecastConcretePlant/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace PrecastConcretePlantView +{ + 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() + { + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(467, 139); + this.buttonRef.Margin = new System.Windows.Forms.Padding(2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(84, 30); + this.buttonRef.TabIndex = 10; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(467, 99); + this.buttonDel.Margin = new System.Windows.Forms.Padding(2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(84, 30); + this.buttonDel.TabIndex = 9; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(467, 58); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(84, 30); + this.buttonUpd.TabIndex = 8; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(467, 18); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(84, 30); + this.buttonAdd.TabIndex = 7; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(11, 11); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(433, 269); + this.dataGridView.TabIndex = 6; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(567, 302); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormShops.cs b/PrecastConcretePlant/FormShops.cs new file mode 100644 index 0000000..809e50c --- /dev/null +++ b/PrecastConcretePlant/FormShops.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlant; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +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 PrecastConcretePlantView +{ + 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 FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Reinforceds"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(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) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/FormShops.resx b/PrecastConcretePlant/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/Program.cs index 9f1cda8..701736a 100644 --- a/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/Program.cs @@ -34,9 +34,11 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -44,6 +46,9 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..f63a15e --- /dev/null +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogic +{ + 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: {ShopName}. Id: {Id}", model?.ShopName, 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 ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, 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)); + } + _logger.LogInformation("Shop. ShopName:{0}. Address:{1}. Id:{2}", + model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddReinforcedInShop(ShopSearchModel model, IReinforcedModel reinforced, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество ЖБИ должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddReinforcedInShop. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); + var shop = _shopStorage.GetElement(model); + if (shop == null) + { + _logger.LogWarning("AddReinforcedInShop element not found"); + return false; + } + _logger.LogInformation("AddReinforcedInShop find. Id:{Id}", shop.Id); + + if (shop.Reinforceds.ContainsKey(reinforced.Id)) + { + shop.Reinforceds[reinforced.Id] = (reinforced, count + shop.Reinforceds[reinforced.Id].Item2); + _logger.LogInformation("AddReinforcedInShop. Added {count} {reinforced} to '{ShopName}' shop", + count, reinforced.ReinforcedName, shop.ShopName); + } + else + { + shop.Reinforceds[reinforced.Id] = (reinforced, count); + _logger.LogInformation("AddReinforcedInShop. Added {count} new reinforced {reinforced} to '{ShopName}' shop", + count, reinforced.ReinforcedName, shop.ShopName); + } + _shopStorage.Update(new() + { + Id = shop.Id, + Address = shop.Address, + ShopName = shop.ShopName, + DateOpening = shop.DateOpening, + Reinforceds = shop.Reinforceds + }); + return true; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..9e7e2ff --- /dev/null +++ b/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantContracts.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 DateOpening { get; set; } = DateTime.Now; + + public Dictionary Reinforceds + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..09a9dec --- /dev/null +++ b/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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 AddReinforcedInShop(ShopSearchModel model, IReinforcedModel reinforced, int count); + } +} \ No newline at end of file diff --git a/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..f70953a --- /dev/null +++ b/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..7a9ce30 --- /dev/null +++ b/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..1dcf99e --- /dev/null +++ b/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantContracts.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 DateOpening { get; set; } = DateTime.Now; + + public Dictionary Reinforceds + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlantDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..6f5b4ef --- /dev/null +++ b/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary Reinforceds { get; } + } +} diff --git a/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlantListImplement/DataListSingleton.cs index 591c0d5..ea20c2c 100644 --- a/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace PrecastConcretePlantListImplement public List Components { get; set; } public List Orders { get; set; } public List Reinforceds { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Reinforceds = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlantListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..e5b2dfe --- /dev/null +++ b/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -0,0 +1,107 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.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.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (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/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlantListImplement/Models/Shop.cs new file mode 100644 index 0000000..5619888 --- /dev/null +++ b/PrecastConcretePlantListImplement/Models/Shop.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; + +namespace PrecastConcretePlantListImplement.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 DateOpening { get; private set; } + public Dictionary Reinforceds + { + 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, + DateOpening = model.DateOpening, + Reinforceds = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + Reinforceds = model.Reinforceds; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + Reinforceds = Reinforceds, + DateOpening = DateOpening, + }; + } +}