From ead53755b1310bbb9a58667ffd14417f7621eb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 12 Feb 2023 15:11:10 +0400 Subject: [PATCH 01/18] =?UTF-8?q?=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=201=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormMain.Designer.cs | 25 ++- .../PrecastConcretePlant/FormMain.cs | 21 +- .../FormReinforcedShop.Designer.cs | 151 ++++++++++++++ .../FormReinforcedShop.cs | 100 ++++++++++ .../FormReinforcedShop.resx | 60 ++++++ .../PrecastConcretePlant/FormShop.Designer.cs | 188 ++++++++++++++++++ .../PrecastConcretePlant/FormShop.cs | 156 +++++++++++++++ .../PrecastConcretePlant/FormShop.resx | 69 +++++++ .../FormShops.Designer.cs | 121 +++++++++++ .../PrecastConcretePlant/FormShops.cs | 106 ++++++++++ .../PrecastConcretePlant/FormShops.resx | 60 ++++++ .../PrecastConcretePlant/Program.cs | 6 + .../BusinessLogic/ShopLogic.cs | 167 ++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 26 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 30 +++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 113 +++++++++++ .../Models/Shop.cs | 63 ++++++ 22 files changed, 1535 insertions(+), 2 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShop.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShops.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShops.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index ac209e1..f4d7170 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -38,6 +38,8 @@ this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); + this.ButtonAddReinforcedInShop = new System.Windows.Forms.Button(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 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правочники"; @@ -134,11 +137,29 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // + // ButtonAddReinforcedInShop + // + this.ButtonAddReinforcedInShop.Location = new System.Drawing.Point(905, 228); + this.ButtonAddReinforcedInShop.Name = "ButtonAddReinforcedInShop"; + this.ButtonAddReinforcedInShop.Size = new System.Drawing.Size(125, 42); + this.ButtonAddReinforcedInShop.TabIndex = 7; + this.ButtonAddReinforcedInShop.Text = "Пополнение магазина"; + this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true; + this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_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); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1042, 450); + this.Controls.Add(this.ButtonAddReinforcedInShop); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.OrderReadyButton); @@ -169,5 +190,7 @@ private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; + private Button ButtonAddReinforcedInShop; + private ToolStripMenuItem магазиныToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 1282e31..5ecb94c 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using ConfectioneryView; +using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantDataModels.Enums; @@ -196,5 +197,23 @@ namespace PrecastConcretePlantView { LoadData(); } + + private void ButtonAddReinforcedInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedShop)); + if (service is FormReinforcedShop form) + { + form.ShowDialog(); + } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs new file mode 100644 index 0000000..abe81e2 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs @@ -0,0 +1,151 @@ +namespace ConfectioneryView +{ + partial class FormReinforcedShop + { + /// + /// 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.comboBoxReinforced = new System.Windows.Forms.ComboBox(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(214, 17); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(222, 23); + this.comboBoxShop.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(84, 20); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(124, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Выбранный магазин:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 47); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(196, 15); + this.label2.TabIndex = 4; + this.label2.Text = "Изделие которое нужно добавить:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(133, 73); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(75, 15); + this.label3.TabIndex = 5; + this.label3.Text = "Количество:"; + // + // comboBoxReinforced + // + this.comboBoxReinforced.FormattingEnabled = true; + this.comboBoxReinforced.Location = new System.Drawing.Point(214, 44); + this.comboBoxReinforced.Name = "comboBoxReinforced"; + this.comboBoxReinforced.Size = new System.Drawing.Size(222, 23); + this.comboBoxReinforced.TabIndex = 6; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(215, 71); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 1410065408, + 2, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(221, 23); + this.numericUpDownCount.TabIndex = 7; + // + // 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(280, 123); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 8; + 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(361, 123); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormReinforcedShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(448, 158); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxReinforced); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.label1); + this.Name = "FormReinforcedShop"; + this.Text = "Пополнение магазина"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxReinforced; + private NumericUpDown numericUpDownCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs new file mode 100644 index 0000000..b19772d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections; +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 ConfectioneryView +{ + public partial class FormReinforcedShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly IReinforcedLogic _reinforcedLogic; + private readonly List? _listShops; + private readonly List? _listReinforcedies; + + public FormReinforcedShop(ILogger logger, IShopLogic shopLogic, IReinforcedLogic reinforcedLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _reinforcedLogic = reinforcedLogic; + _logger = logger; + _listShops = shopLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "Name"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + + _listReinforcedies = reinforcedLogic.ReadList(null); + if (_listReinforcedies != null) + { + comboBoxReinforced.DisplayMember = "Reinforcedies"; + comboBoxReinforced.ValueMember= "Id"; + comboBoxReinforced.DataSource = _listReinforcedies; + 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 resultOperation = _shopLogic.AddReinforced( + model: new() { Id = (int)comboBoxShop.SelectedValue }, + reinforced: reinforced, + count: (int)numericUpDownCount.Value + ); + if (!resultOperation) + { + throw new Exception("Ошибка при добавлении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.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/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs new file mode 100644 index 0000000..694a22f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -0,0 +1,188 @@ +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() + { + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.PastryName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.textBoxDateOpening = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(116, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Название магазина:"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(12, 27); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(141, 23); + this.comboBoxShop.TabIndex = 1; + this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); + // + // 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.PastryName, + this.Price, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 64); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(583, 213); + this.dataGridView.TabIndex = 2; + // + // PastryName + // + this.PastryName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.PastryName.HeaderText = "Имя изделия"; + this.PastryName.Name = "PastryName"; + // + // Price + // + this.Price.HeaderText = "Цена"; + this.Price.Name = "Price"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(159, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(97, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Адрес магазина:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(386, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(100, 15); + this.label3.TabIndex = 4; + this.label3.Text = "Время открытия:"; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(159, 27); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.TabIndex = 5; + // + // textBoxDateOpening + // + this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); + this.textBoxDateOpening.Name = "textBoxDateOpening"; + this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23); + this.textBoxDateOpening.TabIndex = 6; + // + // 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(492, 283); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.TabIndex = 7; + 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(366, 284); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(607, 317); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxDateOpening); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.label1); + 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 Label label1; + private ComboBox comboBoxShop; + private DataGridView dataGridView; + private Label label2; + private Label label3; + private TextBox textBoxAddress; + private TextBox textBoxDateOpening; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn PastryName; + private DataGridViewTextBoxColumn Price; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs new file mode 100644 index 0000000..fd2db82 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -0,0 +1,156 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormShop : Form + { + private readonly List? _listShops; + private readonly IShopLogic _logic; + private readonly ILogger _logger; + + public int Id + { + get; set; + } + + private IShopModel? GetShop(int id) + { + if (_listShops == null) + { + return null; + } + foreach (var elem in _listShops) + { + if (elem.Id == id) + { + return elem; + } + } + return null; + } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _listShops = logic.ReadList(null); + _logic = logic; + if (_listShops != null) + { + comboBoxShop.DisplayMember = "Reinforcedies"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + } + + private void LoadData(bool extendDate = true) + { + try + { + var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); + if (model != null) + { + comboBoxShop.Text = model.Name; + textBoxAddress.Text = model.Address; + textBoxDateOpening.Text = Convert.ToString(model.DateOpening); + dataGridView.Rows.Clear(); + foreach (var el in model.Reinforcedies.Values) + { + dataGridView.Rows.Add(new object[]{el.Item1.ReinforcedName, el.Item1.Price, el.Item2 }); + } + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) + { + LoadData(false); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(comboBoxShop.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); + ShopBindingModel model = new() + { + Name = comboBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTime + }; + var vmodel = GetShop(Id); + bool operationResult = false; + + if (vmodel != null) + { + model.Id = vmodel.Id; + operationResult = _logic.Update(model); + } + else + { + operationResult = _logic.Create(model); + } + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx new file mode 100644 index 0000000..c4ce247 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs new file mode 100644 index 0000000..d2ce2f6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs @@ -0,0 +1,121 @@ +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() + { + 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(685, 202); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 37); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDel.Location = new System.Drawing.Point(685, 151); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 33); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpd.Location = new System.Drawing.Point(685, 102); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 34); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAdd.Location = new System.Drawing.Point(685, 57); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 30); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // 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.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(540, 379); + this.dataGridView.TabIndex = 10; + // + // FormViewShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(787, 403); + 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 = "FormViewShops"; + 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/PrecastConcretePlant/FormShops.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs new file mode 100644 index 0000000..3967822 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantView; + +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 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["Reinforcedies"].Visible = false; + dataGridView.Columns["Name"].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/PrecastConcretePlant/FormShops.resx b/PrecastConcretePlant/PrecastConcretePlant/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/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/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 8b8845d..06ff656 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -6,6 +6,7 @@ using PrecastConcretePlantListImplement.Implements; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using PrecastConcretePlantBusinessLogic.PrecastConcretePlantBusinessLogic.BusinessLogic; +using ConfectioneryView; namespace PrecastConcretePlantView { @@ -34,9 +35,11 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -44,6 +47,9 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..4022fa5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,167 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +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?.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 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); + model.Reinforcedies = new(); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model, false); + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.Name)); + } + 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.Name)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.Name)); + } + _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + model.Name, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id && element.Name == model.Name) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddReinforced(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.Name, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddReinforcedInShop element not found"); + return false; + } + _logger.LogInformation("AddReinforcedInShop find. Id:{Id}", element.Id); + + + if (element.Reinforcedies.TryGetValue(reinforced.Id, out var pair)) + { + element.Reinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); + _logger.LogInformation( + "AddReinforcedInShop. Has been added {count} {reinforced} in {ShopName}", + count, reinforced.ReinforcedName, element.Name); + } + else + { + element.Reinforcedies[reinforced.Id] = (reinforced, count); + _logger.LogInformation( + "AddReinforcedInShop. Has been added {count} new Reinforced {reinforced} in {ShopName}", + count, reinforced.ReinforcedName, element.Name); + } + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + Name = element.Name, + DateOpening = element.DateOpening, + Reinforcedies = element.Reinforcedies + }); + return true; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..e589473 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public string Name { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary Reinforcedies + { + get; + set; + } = new(); + + public int Id { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..f1a5e90 --- /dev/null +++ b/PrecastConcretePlant/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 AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..c08ab42 --- /dev/null +++ b/PrecastConcretePlant/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? Name { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..e8efac3 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..9527906 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,30 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + [DisplayName("Название магазина")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Время открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary Reinforcedies + { + get; + set; + } = new(); + + public int Id { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..d2ff837 --- /dev/null +++ b/PrecastConcretePlant/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 Name { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary Reinforcedies { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs index 9353b4e..8c30fd4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlant/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/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..4922ebe --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -0,0 +1,113 @@ +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 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; + } + + 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.Name == model.Name) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.Name.Contains(model.Name ?? string.Empty)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + 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; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs new file mode 100644 index 0000000..07bbef3 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -0,0 +1,63 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Shop : IShopModel + { + public string Name { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary Reinforcedies + { + get; + private set; + } = new(); + + public int Id { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + DateOpening = model.DateOpening, + Reinforcedies = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + Reinforcedies = model.Reinforcedies; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + Reinforcedies = Reinforcedies, + DateOpening = DateOpening, + }; + } +} From e9156f6bba5b197be1b49d9ab8be911bbc4bacae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 12 Feb 2023 15:32:26 +0400 Subject: [PATCH 02/18] Fix textBox --- .../FormReinforcedShop.cs | 2 +- .../PrecastConcretePlant/FormShop.Designer.cs | 20 ++--- .../PrecastConcretePlant/FormShop.resx | 75 ++++++++++++++++-- .../PrecastConcretePlant/FormShop.resx.bak | 78 +++++++++++++++++++ 4 files changed, 157 insertions(+), 18 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormShop.resx.bak diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs index b19772d..565cc8c 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs @@ -40,7 +40,7 @@ namespace ConfectioneryView _listReinforcedies = reinforcedLogic.ReadList(null); if (_listReinforcedies != null) { - comboBoxReinforced.DisplayMember = "Reinforcedies"; + comboBoxReinforced.DisplayMember = "ReinforcedName"; comboBoxReinforced.ValueMember= "Id"; comboBoxReinforced.DataSource = _listReinforcedies; comboBoxReinforced.SelectedItem = null; diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index 694a22f..16290c0 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -37,9 +37,9 @@ this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.textBoxAddress = new System.Windows.Forms.TextBox(); - this.textBoxDateOpening = new System.Windows.Forms.TextBox(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxDateOpening = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // @@ -118,13 +118,6 @@ this.textBoxAddress.Size = new System.Drawing.Size(221, 23); this.textBoxAddress.TabIndex = 5; // - // textBoxDateOpening - // - this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); - this.textBoxDateOpening.Name = "textBoxDateOpening"; - this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23); - this.textBoxDateOpening.TabIndex = 6; - // // buttonCancel // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); @@ -147,14 +140,21 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // + // textBoxDateOpening + // + this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); + this.textBoxDateOpening.Name = "textBoxDateOpening"; + this.textBoxDateOpening.Size = new System.Drawing.Size(200, 23); + this.textBoxDateOpening.TabIndex = 9; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(607, 317); + this.Controls.Add(this.textBoxDateOpening); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxDateOpening); this.Controls.Add(this.textBoxAddress); this.Controls.Add(this.label3); this.Controls.Add(this.label2); @@ -178,11 +178,11 @@ private Label label2; private Label label3; private TextBox textBoxAddress; - private TextBox textBoxDateOpening; private Button buttonCancel; private Button buttonSave; private DataGridViewTextBoxColumn PastryName; private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Count; + private DateTimePicker textBoxDateOpening; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx index c4ce247..63a5b60 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx @@ -1,4 +1,64 @@ - + + + @@ -57,13 +117,14 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + True - - + + True - - + + True - + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx.bak b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx.bak new file mode 100644 index 0000000..7dafd55 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx.bak @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file From 51991ea3873bcd84bb1bfa0503dae9dded7bb7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Mon, 27 Feb 2023 23:04:50 +0400 Subject: [PATCH 03/18] =?UTF-8?q?=D0=A8=D0=B0=D0=B3=201.=20=D0=9F=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BB=D0=B5=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B5=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcretePlant/PrecastConcretePlant/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 94ed819..71a4472 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -5,8 +5,8 @@ using PrecastConcretePlantContracts.StoragesContracts; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using PrecastConcretePlantBusinessLogic.PrecastConcretePlantBusinessLogic.BusinessLogic; -using ConfectioneryView; using PrecastConcretePlantFileImplement.Implements; +using ConfectioneryView; namespace PrecastConcretePlantView { From 98f5f1b41d2697e1ae62f38ef5c59a90f5dcaada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 12 Mar 2023 17:46:52 +0400 Subject: [PATCH 04/18] =?UTF-8?q?=D0=A8=D0=B0=D0=B3=201.=20=D0=A1=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormMain.Designer.cs | 29 +++-- .../PrecastConcretePlant/FormMain.cs | 10 ++ .../FormSellReinforced.Designer.cs | 119 ++++++++++++++++++ .../FormSellReinforced.cs | 94 ++++++++++++++ .../FormSellReinforced.resx | 60 +++++++++ .../PrecastConcretePlant/FormShop.Designer.cs | 34 ++++- .../PrecastConcretePlant/FormShop.cs | 10 +- .../PrecastConcretePlant/FormShop.resx | 74 +---------- .../PrecastConcretePlant/FormShops.cs | 2 +- .../PrecastConcretePlant/Program.cs | 1 + .../BusinessLogic/OrderLogic.cs | 38 ++++-- .../BusinessLogic/ShopLogic.cs | 101 ++++++++++++--- .../BindingModels/ShopBindingModel.cs | 8 +- .../BusinessLogicsContracts/IShopLogic.cs | 3 + .../StoragesContracts/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 12 +- .../Models/IShopModel.cs | 3 +- .../DataFileSingleton.cs | 4 + .../Implements/ShopStorage.cs | 112 +++++++++++++++++ .../Models/Shop.cs | 107 ++++++++++++++++ .../Implements/ShopStorage.cs | 6 +- .../Models/Shop.cs | 13 +- 22 files changed, 706 insertions(+), 136 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index f4d7170..a192575 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -32,6 +32,7 @@ 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(); @@ -39,7 +40,7 @@ this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); this.ButtonAddReinforcedInShop = new System.Windows.Forms.Button(); - this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SellPackageButton = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -67,17 +68,24 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(145, 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.Size = new System.Drawing.Size(145, 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.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -147,18 +155,22 @@ this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true; this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click); // - // магазиныToolStripMenuItem + // SellPackageButton // - 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); + this.SellPackageButton.Location = new System.Drawing.Point(905, 276); + this.SellPackageButton.Name = "SellPackageButton"; + this.SellPackageButton.Size = new System.Drawing.Size(125, 29); + this.SellPackageButton.TabIndex = 8; + this.SellPackageButton.Text = "Продать изделие"; + this.SellPackageButton.UseVisualStyleBackColor = true; + this.SellPackageButton.Click += new System.EventHandler(this.SellPackageButton_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1042, 450); + this.Controls.Add(this.SellPackageButton); this.Controls.Add(this.ButtonAddReinforcedInShop); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); @@ -192,5 +204,6 @@ private Button UpdateListButton; private Button ButtonAddReinforcedInShop; private ToolStripMenuItem магазиныToolStripMenuItem; + private Button SellPackageButton; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 051196c..33f7247 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -216,5 +216,15 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + + private void SellPackageButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced)); + + if (service is FormSellReinforced form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs new file mode 100644 index 0000000..f09082b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs @@ -0,0 +1,119 @@ +namespace PrecastConcretePlantView +{ + partial class FormSellReinforced + { + /// + /// 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.ReinforcedLabel = new System.Windows.Forms.Label(); + this.QuantityLabel = new System.Windows.Forms.Label(); + this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox(); + this.QuantityTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ReinforcedLabel + // + this.ReinforcedLabel.AutoSize = true; + this.ReinforcedLabel.Location = new System.Drawing.Point(12, 18); + this.ReinforcedLabel.Name = "ReinforcedLabel"; + this.ReinforcedLabel.Size = new System.Drawing.Size(56, 15); + this.ReinforcedLabel.TabIndex = 0; + this.ReinforcedLabel.Text = "Изделие:"; + // + // QuantityLabel + // + this.QuantityLabel.AutoSize = true; + this.QuantityLabel.Location = new System.Drawing.Point(12, 51); + this.QuantityLabel.Name = "QuantityLabel"; + this.QuantityLabel.Size = new System.Drawing.Size(75, 15); + this.QuantityLabel.TabIndex = 1; + this.QuantityLabel.Text = "Количество:"; + // + // ReindorcedСomboBox + // + this.ReindorcedСomboBox.FormattingEnabled = true; + this.ReindorcedСomboBox.Location = new System.Drawing.Point(88, 15); + this.ReindorcedСomboBox.Name = "ReindorcedСomboBox"; + this.ReindorcedСomboBox.Size = new System.Drawing.Size(184, 23); + this.ReindorcedСomboBox.TabIndex = 2; + // + // QuantityTextBox + // + this.QuantityTextBox.Location = new System.Drawing.Point(88, 48); + this.QuantityTextBox.Name = "QuantityTextBox"; + this.QuantityTextBox.Size = new System.Drawing.Size(184, 23); + this.QuantityTextBox.TabIndex = 3; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(72, 100); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(97, 29); + this.SaveButton.TabIndex = 4; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(175, 100); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(97, 29); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellReinforced + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 141); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.QuantityTextBox); + this.Controls.Add(this.ReindorcedСomboBox); + this.Controls.Add(this.QuantityLabel); + this.Controls.Add(this.ReinforcedLabel); + this.Name = "FormSellReinforced"; + this.Text = "Продать Изделие"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ReinforcedLabel; + private Label QuantityLabel; + private ComboBox ReindorcedСomboBox; + private TextBox QuantityTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs new file mode 100644 index 0000000..4188396 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs @@ -0,0 +1,94 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; + +namespace PrecastConcretePlantView +{ + public partial class FormSellReinforced : Form + { + private readonly ILogger _logger; + private readonly IReinforcedLogic _logicReinforced; + private readonly IShopLogic _logicShop; + public FormSellReinforced(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicReinforced = logicReinforced; + _logicShop = logicShop; + LoadData(); + } + + private void FormSellReinforced_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Loading reinforcediss for sale."); + + try + { + var list = _logicReinforced.ReadList(null); + if (list != null) + { + ReindorcedСomboBox.DisplayMember = "ReinforcedName"; + ReindorcedСomboBox.ValueMember = "Id"; + ReindorcedСomboBox.DataSource = list; + ReindorcedСomboBox.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "List loading error."); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(QuantityTextBox.Text)) + { + MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (ReindorcedСomboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Product sale."); + + try + { + var operationResult = _logicShop.SellReinforced(_logicReinforced.ReadElement(new ReinforcedSearchModel() + { + Id = Convert.ToInt32(ReindorcedСomboBox.SelectedValue) + })!, Convert.ToInt32(QuantityTextBox.Text)); + + if (!operationResult) + { + throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Product sale error."); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.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/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index 16290c0..d74a4af 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -40,7 +40,10 @@ this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); this.textBoxDateOpening = new System.Windows.Forms.DateTimePicker(); + this.ReinforcedMaxCountLable = new System.Windows.Forms.Label(); + this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit(); this.SuspendLayout(); // // label1 @@ -71,10 +74,10 @@ this.PastryName, this.Price, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(12, 64); + this.dataGridView.Location = new System.Drawing.Point(12, 116); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(583, 213); + this.dataGridView.Size = new System.Drawing.Size(583, 249); this.dataGridView.TabIndex = 2; // // PastryName @@ -121,7 +124,7 @@ // 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(492, 283); + this.buttonCancel.Location = new System.Drawing.Point(492, 371); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(103, 23); this.buttonCancel.TabIndex = 7; @@ -132,7 +135,7 @@ // 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(366, 284); + this.buttonSave.Location = new System.Drawing.Point(366, 372); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(120, 22); this.buttonSave.TabIndex = 8; @@ -147,11 +150,29 @@ this.textBoxDateOpening.Size = new System.Drawing.Size(200, 23); this.textBoxDateOpening.TabIndex = 9; // + // ReinforcedMaxCountLable + // + this.ReinforcedMaxCountLable.AutoSize = true; + this.ReinforcedMaxCountLable.Location = new System.Drawing.Point(12, 53); + this.ReinforcedMaxCountLable.Name = "ReinforcedMaxCountLable"; + this.ReinforcedMaxCountLable.Size = new System.Drawing.Size(140, 15); + this.ReinforcedMaxCountLable.TabIndex = 10; + this.ReinforcedMaxCountLable.Text = "Вместимость магазина: "; + // + // VolumeNumericUpDown + // + this.VolumeNumericUpDown.Location = new System.Drawing.Point(12, 71); + this.VolumeNumericUpDown.Name = "VolumeNumericUpDown"; + this.VolumeNumericUpDown.Size = new System.Drawing.Size(141, 23); + this.VolumeNumericUpDown.TabIndex = 11; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(607, 317); + this.ClientSize = new System.Drawing.Size(607, 405); + this.Controls.Add(this.VolumeNumericUpDown); + this.Controls.Add(this.ReinforcedMaxCountLable); this.Controls.Add(this.textBoxDateOpening); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); @@ -165,6 +186,7 @@ this.Text = "Просмотр изделий магазина"; this.Load += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -184,5 +206,7 @@ private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Count; private DateTimePicker textBoxDateOpening; + private Label ReinforcedMaxCountLable; + private NumericUpDown VolumeNumericUpDown; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index fd2db82..fa9a530 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -52,7 +52,7 @@ namespace ConfectioneryView _logic = logic; if (_listShops != null) { - comboBoxShop.DisplayMember = "Reinforcedies"; + comboBoxShop.DisplayMember = "Name"; comboBoxShop.ValueMember = "Id"; comboBoxShop.DataSource = _listShops; comboBoxShop.SelectedItem = null; @@ -69,8 +69,9 @@ namespace ConfectioneryView comboBoxShop.Text = model.Name; textBoxAddress.Text = model.Address; textBoxDateOpening.Text = Convert.ToString(model.DateOpening); + VolumeNumericUpDown.Value = model.ReinforcedMaxCount; dataGridView.Rows.Clear(); - foreach (var el in model.Reinforcedies.Values) + foreach (var el in model.ShopReinforcedies.Values) { dataGridView.Rows.Add(new object[]{el.Item1.ReinforcedName, el.Item1.Price, el.Item2 }); } @@ -104,7 +105,7 @@ namespace ConfectioneryView MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение изделия"); + _logger.LogInformation("Сохранение магазина"); try { DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); @@ -112,7 +113,8 @@ namespace ConfectioneryView { Name = comboBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTime + DateOpening = dateTime, + ReinforcedMaxCount = (int)VolumeNumericUpDown.Value }; var vmodel = GetShop(Id); bool operationResult = false; diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx index 63a5b60..36577c7 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx @@ -1,64 +1,4 @@ - - - + @@ -117,14 +57,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + True - - + + True - - - True - + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs index 3967822..c00af8d 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs @@ -29,7 +29,7 @@ namespace ConfectioneryView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["Reinforcedies"].Visible = false; + dataGridView.Columns["ShopReinforcedies"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 71a4472..8ab1233 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -49,6 +49,7 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index d308c19..ea0ea78 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -17,11 +17,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopLogic _shopLogic; + private readonly IReinforcedStorage _reinforcedStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _reinforcedStorage = reinforcedStorage; } public bool CreateOrder(OrderBindingModel model) @@ -48,19 +51,38 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (model.Status + 1 != newStatus) + if (viewModel == null) { - _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); - return false; + throw new ArgumentNullException(nameof(model)); } - model.Status = newStatus; + if (viewModel.Status + 1 != newStatus) - if (model.Status == OrderStatus.Выдан) + model.Status = newStatus; + + if (model.Status == OrderStatus.Готов) + { model.DateImplement = DateTime.Now; + var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId }); + if (reinforced == null) + { + throw new ArgumentNullException(nameof(reinforced)); + } + + if (!_shopLogic.AddReinforced(reinforced, viewModel.Count)) + { + throw new Exception($"AddReinforced operation failed. Shop is full."); + } + } + else + { + model.DateImplement = viewModel.DateImplement; + } + + CheckModel(model, false); if (_orderStorage.Update(model) == null) { model.Status--; diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 4022fa5..4e6aaa7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -25,7 +25,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } public List? ReadList(ShopSearchModel? model) { - _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ", + _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ", model?.Name, model?.Id); var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); @@ -43,7 +43,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", + _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -57,7 +57,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); - model.Reinforcedies = new(); + model.ShopReinforcedies = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -65,6 +65,10 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } return true; } + public bool SellReinforced(IReinforcedModel reinforced, int count) + { + return _shopStorage.SellReinforced(reinforced, count); + } public bool Update(ShopBindingModel model) { CheckModel(model, false); @@ -73,6 +77,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } + if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -106,7 +111,11 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } - _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + if (model.ReinforcedMaxCount < 0) + { + throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount)); + } + _logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}", model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { @@ -124,43 +133,95 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } + if (count <= 0) { - throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddReinforcedInShop. ShopName:{ShopName}.Id:{ Id}", - model.Name, model.Id); + + _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); + if (element == null) { - _logger.LogWarning("AddReinforcedInShop element not found"); + _logger.LogWarning("AddReinforced element not found"); return false; } - _logger.LogInformation("AddReinforcedInShop find. Id:{Id}", element.Id); - - if (element.Reinforcedies.TryGetValue(reinforced.Id, out var pair)) + if (element.ReinforcedMaxCount - element.ShopReinforcedies.Select(x => x.Value.Item2).Sum() < count) { - element.Reinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); - _logger.LogInformation( - "AddReinforcedInShop. Has been added {count} {reinforced} in {ShopName}", - count, reinforced.ReinforcedName, element.Name); + throw new ArgumentNullException("Магазин переполнен", nameof(count)); + } + + _logger.LogInformation("AddReinforced find. Id:{Id}", element.Id); + + if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair)) + { + element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); + _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } else { - element.Reinforcedies[reinforced.Id] = (reinforced, count); - _logger.LogInformation( - "AddReinforcedInShop. Has been added {count} new Reinforced {reinforced} in {ShopName}", - count, reinforced.ReinforcedName, element.Name); + element.ShopReinforcedies[reinforced.Id] = (reinforced, count); + _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } + _shopStorage.Update(new() { Id = element.Id, Address = element.Address, Name = element.Name, DateOpening = element.DateOpening, - Reinforcedies = element.Reinforcedies + ReinforcedMaxCount = element.ReinforcedMaxCount, + ShopReinforcedies = element.ShopReinforcedies, }); + + return true; + } + public bool AddReinforced(IReinforcedModel reinforced, int count) + { + if (reinforced == null) + { + throw new ArgumentNullException(nameof(reinforced)); + } + + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + } + + var freePlaces = _shopStorage.GetFullList() + .Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies + .Select(p => p.Value.Item2).Sum()).Sum() - count; + + if (freePlaces < 0) + { + _logger.LogInformation("AddReinforced. Failed to add reinforced to shop. It's full."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum()); + + if (temp <= 0) + { + continue; + } + + if (!AddReinforced(new() { Id = shop.Id }, reinforced, temp)) + { + _logger.LogWarning("An error occurred while adding reinforced to shops"); + return false; + } + + count -= temp; + + if (count == 0) + { + return true; + } + } return true; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index e589473..2c89326 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -15,12 +15,10 @@ namespace PrecastConcretePlantContracts.BindingModels public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Reinforcedies - { - get; - set; - } = new(); + public Dictionary ShopReinforcedies { get; set; } = new(); + public int Id { get; set; } + public int ReinforcedMaxCount { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index f1a5e90..f55386f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,8 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count); + bool AddReinforced(IReinforcedModel reinforced, int quantity); + bool SellReinforced(IReinforcedModel reinforced, int quantity); + } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs index e8efac3..142cb4f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace PrecastConcretePlantContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellReinforced(IReinforcedModel model, int quantity); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 9527906..1708dfc 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -17,13 +17,13 @@ namespace PrecastConcretePlantContracts.ViewModels public string Address { get; set; } = string.Empty; [DisplayName("Время открытия")] - public DateTime DateOpening { get; set; } = DateTime.Now; + public DateTime DateOpening { get; set; } + + [DisplayName("Вместимость магазина")] + public int ReinforcedMaxCount { get; set; } + + public Dictionary ShopReinforcedies { get; set; } = new(); - public Dictionary Reinforcedies - { - get; - set; - } = new(); public int Id { get; set; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index d2ff837..42ac617 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantDataModels.Models string Name { get; } string Address { get; } DateTime DateOpening { get; } - Dictionary Reinforcedies { get; } + Dictionary ShopReinforcedies { get; } + public int ReinforcedMaxCount { get; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs index 7a32b41..b68cfdd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -15,9 +15,11 @@ namespace PrecastConcretePlantFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string ReinforcedFileName = "Reinforced.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Reinforceds { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -32,6 +34,7 @@ namespace PrecastConcretePlantFileImplement "Reinforceds", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => @@ -39,6 +42,7 @@ namespace PrecastConcretePlantFileImplement Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..19f21ac --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,112 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Name) && x.Name == + model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return source.Shops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public bool SellReinforced(IReinforcedModel model, int quantity) + { + if (source.Shops.Select(x => x.ShopReinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) + { + return false; + } + foreach (var shop in source.Shops.Where(x => x.ShopReinforcedies.ContainsKey(model.Id))) + { + int QuantityInCurrentShop = shop.ShopReinforcedies[model.Id].Item2; + if (QuantityInCurrentShop <= quantity) + { + shop.ShopReinforcedies.Remove(model.Id); + quantity -= QuantityInCurrentShop; + } + else + { + shop.ShopReinforcedies[model.Id] = (shop.ShopReinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); + quantity = 0; + } + if (quantity == 0) + { + return true; + } + } + return false; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs new file mode 100644 index 0000000..d262c11 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -0,0 +1,107 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Shop : IShopModel + { + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + public Dictionary Reinforcedies { get; private set; } = new(); + + public Dictionary _shopReinforcedies = null; + public Dictionary ShopReinforcedies + { + get + { + if (_shopReinforcedies == null) + { + var source = DataFileSingleton.GetInstance(); + _shopReinforcedies = Reinforcedies.ToDictionary(x => x.Key, y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value)); + } + return _shopReinforcedies; + } + } + + public int Id { get; private set; } + + public int ReinforcedMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + ReinforcedMaxCount = model.ReinforcedMaxCount, + DateOpening = model.DateOpening, + Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value), + Reinforcedies = element.Element("ShopReinforcedies")!.Elements("Reinforced").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + ReinforcedMaxCount = model.ReinforcedMaxCount; + Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopReinforcedies = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + ShopReinforcedies = ShopReinforcedies, + DateOpening = DateOpening, + ReinforcedMaxCount = ReinforcedMaxCount, + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening), + new XElement("ReinforcedMaxCount", ReinforcedMaxCount), + new XElement("ShopReinforcedies", Reinforcedies + .Select(x => new XElement("Reinforced", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index 4922ebe..5a8cbb5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; using PrecastConcretePlantListImplement.Models; using System; using System.Collections.Generic; @@ -32,7 +33,10 @@ namespace PrecastConcretePlantListImplement.Implements } return null; } - + public bool SellReinforced(IReinforcedModel model, int quantity) + { + throw new NotImplementedException(); + } public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index 07bbef3..a8895f2 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -17,11 +17,7 @@ namespace PrecastConcretePlantListImplement.Models public DateTime DateOpening { get; private set; } - public Dictionary Reinforcedies - { - get; - private set; - } = new(); + public Dictionary ShopReinforcedies { get; private set; } = new(); public int Id { get; private set; } @@ -37,7 +33,7 @@ namespace PrecastConcretePlantListImplement.Models Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, - Reinforcedies = new() + ShopReinforcedies = new() }; } public void Update(ShopBindingModel? model) @@ -49,15 +45,16 @@ namespace PrecastConcretePlantListImplement.Models Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; - Reinforcedies = model.Reinforcedies; + ShopReinforcedies = model.ShopReinforcedies; } public ShopViewModel GetViewModel => new() { Id = Id, Name = Name, Address = Address, - Reinforcedies = Reinforcedies, + ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening, }; + public int ReinforcedMaxCount => throw new NotImplementedException(); } } From 1d143d28460d899f57130d6612fd59fc38941e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 12 Mar 2023 17:51:19 +0400 Subject: [PATCH 05/18] =?UTF-8?q?=D0=A8=D0=B0=D0=B3=202.=20Fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormMain.Designer.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index a192575..f481712 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -40,7 +40,7 @@ this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); this.ButtonAddReinforcedInShop = new System.Windows.Forms.Button(); - this.SellPackageButton = new System.Windows.Forms.Button(); + this.SellReinforcedButton = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -155,22 +155,22 @@ this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true; this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click); // - // SellPackageButton + // SellReinforcedButton // - this.SellPackageButton.Location = new System.Drawing.Point(905, 276); - this.SellPackageButton.Name = "SellPackageButton"; - this.SellPackageButton.Size = new System.Drawing.Size(125, 29); - this.SellPackageButton.TabIndex = 8; - this.SellPackageButton.Text = "Продать изделие"; - this.SellPackageButton.UseVisualStyleBackColor = true; - this.SellPackageButton.Click += new System.EventHandler(this.SellPackageButton_Click); + this.SellReinforcedButton.Location = new System.Drawing.Point(905, 276); + this.SellReinforcedButton.Name = "SellReinforcedButton"; + this.SellReinforcedButton.Size = new System.Drawing.Size(125, 29); + this.SellReinforcedButton.TabIndex = 8; + this.SellReinforcedButton.Text = "Продать изделие"; + this.SellReinforcedButton.UseVisualStyleBackColor = true; + this.SellReinforcedButton.Click += new System.EventHandler(this.SellPackageButton_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1042, 450); - this.Controls.Add(this.SellPackageButton); + this.Controls.Add(this.SellReinforcedButton); this.Controls.Add(this.ButtonAddReinforcedInShop); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); @@ -204,6 +204,6 @@ private Button UpdateListButton; private Button ButtonAddReinforcedInShop; private ToolStripMenuItem магазиныToolStripMenuItem; - private Button SellPackageButton; + private Button SellReinforcedButton; } } \ No newline at end of file From aff68c7469bd47ee175815bbbbdb1326e6ec2684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 14 Mar 2023 11:24:23 +0400 Subject: [PATCH 06/18] =?UTF-8?q?=D0=A8=D0=B0=D0=B3=202.=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=8E=20-=20=20fix=20"=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcretePlant/PrecastConcretePlant/FormMain.cs | 2 +- .../BusinessLogic/OrderLogic.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 33f7247..91f1105 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -168,7 +168,7 @@ namespace PrecastConcretePlantView try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { + { Id = id, ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value), ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(), diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index ea0ea78..fc3415c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -59,12 +59,17 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } - model.Status = newStatus; + model.Status = newStatus; if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; + var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId }); if (reinforced == null) @@ -83,10 +88,12 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } CheckModel(model, false); + if (_orderStorage.Update(model) == null) { model.Status--; _logger.LogWarning("Update operation failed"); + return false; } From 0311b850f6c341eae8d3fbc6dc43eb79678ea2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Mon, 27 Mar 2023 11:00:22 +0400 Subject: [PATCH 07/18] =?UTF-8?q?=D0=A8=D0=B0=D0=B3=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9-=D1=82=D0=BE=20=D1=82=D0=B0=D0=BC.=20Reinforcedies?= =?UTF-8?q?=20->=20Reinforceds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcretePlant/PrecastConcretePlant/FormMain.cs | 2 +- .../BusinessLogic/ReportLogic.cs | 8 ++++---- .../OfficePackage/AbstractSaveToWord.cs | 2 +- .../OfficePackage/HelperModels/WordInfo.cs | 2 +- .../BusinessLogicsContracts/IReportLogic.cs | 2 +- ...ion.Designer.cs => 20230327065744_Restart.Designer.cs} | 4 ++-- ...6175226_InitMigration.cs => 20230327065744_Restart.cs} | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) rename PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/{20230226175226_InitMigration.Designer.cs => 20230327065744_Restart.Designer.cs} (98%) rename PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/{20230226175226_InitMigration.cs => 20230327065744_Restart.cs} (99%) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index e2c309e..27bd923 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -205,7 +205,7 @@ namespace PrecastConcretePlantView using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) { - _reportLogic.SaveReinforcediesToWordFile(new ReportBindingModel + _reportLogic.SaveReinforcedsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs index 4509982..657a345 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs @@ -34,9 +34,9 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public List GetReinforcedComponents() { var components = _componentStorage.GetFullList(); - var reinforcedies = _reinforcedStorage.GetFullList(); + var reinforceds = _reinforcedStorage.GetFullList(); var list = new List(); - foreach (var reinforced in reinforcedies) + foreach (var reinforced in reinforceds) { var record = new ReportReinforcedComponentViewModel { @@ -75,13 +75,13 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic .ToList(); } - public void SaveReinforcediesToWordFile(ReportBindingModel model) + public void SaveReinforcedsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список документов", - Reinforcedies = _reinforcedStorage.GetFullList() + Reinforceds = _reinforcedStorage.GetFullList() }); } public void SaveReinforcedComponentToExcelFile(ReportBindingModel model) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs index feb38c4..033f1b0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -22,7 +22,7 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage JustificationType = WordJustificationType.Center } }); - foreach (var reinforced in info.Reinforcedies) + foreach (var reinforced in info.Reinforceds) { CreateParagraph(new WordParagraph { diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 7f35891..48a059e 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -11,6 +11,6 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List Reinforcedies { get; set; } = new(); + public List Reinforceds { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs index 0c63b71..176f587 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs @@ -12,7 +12,7 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts { List GetReinforcedComponents(); List GetOrders(ReportBindingModel model); - void SaveReinforcediesToWordFile(ReportBindingModel model); + void SaveReinforcedsToWordFile(ReportBindingModel model); void SaveReinforcedComponentToExcelFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model); } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327065744_Restart.Designer.cs similarity index 98% rename from PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs rename to PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327065744_Restart.Designer.cs index 20c2331..dd0a7df 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327065744_Restart.Designer.cs @@ -12,8 +12,8 @@ using PrecastConcretePlantDatabaseImplement; namespace PrecastConcretePlantDatabaseImplement.Migrations { [DbContext(typeof(PrecastConcretePlantDataBase))] - [Migration("20230226175226_InitMigration")] - partial class InitMigration + [Migration("20230327065744_Restart")] + partial class Restart { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327065744_Restart.cs similarity index 99% rename from PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs rename to PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327065744_Restart.cs index b82c188..d6af164 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230327065744_Restart.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace PrecastConcretePlantDatabaseImplement.Migrations { /// - public partial class InitMigration : Migration + public partial class Restart : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) From a5815975cd0210beb3e7501ddcd328fbbbbeb7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 28 Mar 2023 09:59:30 +0400 Subject: [PATCH 08/18] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormShop.Designer.cs | 66 ++++++---- .../PrecastConcretePlant/FormShop.cs | 118 +++++++----------- 2 files changed, 85 insertions(+), 99 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index d74a4af..ca6cec6 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -49,20 +49,19 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Location = new System.Drawing.Point(14, 12); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(116, 15); + this.label1.Size = new System.Drawing.Size(150, 20); this.label1.TabIndex = 0; this.label1.Text = "Название магазина:"; // // comboBoxShop // - this.comboBoxShop.FormattingEnabled = true; - this.comboBoxShop.Location = new System.Drawing.Point(12, 27); + this.comboBoxShop.Location = new System.Drawing.Point(14, 39); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxShop.Name = "comboBoxShop"; - this.comboBoxShop.Size = new System.Drawing.Size(141, 23); - this.comboBoxShop.TabIndex = 1; - this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); + this.comboBoxShop.Size = new System.Drawing.Size(138, 28); + this.comboBoxShop.TabIndex = 12; // // dataGridView // @@ -74,59 +73,68 @@ this.PastryName, this.Price, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(12, 116); + this.dataGridView.Location = new System.Drawing.Point(14, 155); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(583, 249); + this.dataGridView.Size = new System.Drawing.Size(666, 332); this.dataGridView.TabIndex = 2; // // PastryName // this.PastryName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.PastryName.HeaderText = "Имя изделия"; + this.PastryName.MinimumWidth = 6; this.PastryName.Name = "PastryName"; // // Price // this.Price.HeaderText = "Цена"; + this.Price.MinimumWidth = 6; this.Price.Name = "Price"; + this.Price.Width = 125; // // Count // this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; this.Count.Name = "Count"; + this.Count.Width = 125; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(159, 9); + this.label2.Location = new System.Drawing.Point(182, 12); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(97, 15); + this.label2.Size = new System.Drawing.Size(124, 20); this.label2.TabIndex = 3; this.label2.Text = "Адрес магазина:"; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(386, 9); + this.label3.Location = new System.Drawing.Point(441, 12); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(100, 15); + this.label3.Size = new System.Drawing.Size(126, 20); this.label3.TabIndex = 4; this.label3.Text = "Время открытия:"; // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(159, 27); + this.textBoxAddress.Location = new System.Drawing.Point(182, 36); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.Size = new System.Drawing.Size(252, 27); this.textBoxAddress.TabIndex = 5; // // 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(492, 371); + this.buttonCancel.Location = new System.Drawing.Point(562, 495); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.Size = new System.Drawing.Size(118, 31); this.buttonCancel.TabIndex = 7; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; @@ -135,9 +143,10 @@ // 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(366, 372); + this.buttonSave.Location = new System.Drawing.Point(418, 496); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.Size = new System.Drawing.Size(137, 29); this.buttonSave.TabIndex = 8; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; @@ -145,32 +154,34 @@ // // textBoxDateOpening // - this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); + this.textBoxDateOpening.Location = new System.Drawing.Point(441, 36); + this.textBoxDateOpening.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxDateOpening.Name = "textBoxDateOpening"; - this.textBoxDateOpening.Size = new System.Drawing.Size(200, 23); + this.textBoxDateOpening.Size = new System.Drawing.Size(228, 27); this.textBoxDateOpening.TabIndex = 9; // // ReinforcedMaxCountLable // this.ReinforcedMaxCountLable.AutoSize = true; - this.ReinforcedMaxCountLable.Location = new System.Drawing.Point(12, 53); + this.ReinforcedMaxCountLable.Location = new System.Drawing.Point(14, 71); this.ReinforcedMaxCountLable.Name = "ReinforcedMaxCountLable"; - this.ReinforcedMaxCountLable.Size = new System.Drawing.Size(140, 15); + this.ReinforcedMaxCountLable.Size = new System.Drawing.Size(177, 20); this.ReinforcedMaxCountLable.TabIndex = 10; this.ReinforcedMaxCountLable.Text = "Вместимость магазина: "; // // VolumeNumericUpDown // - this.VolumeNumericUpDown.Location = new System.Drawing.Point(12, 71); + this.VolumeNumericUpDown.Location = new System.Drawing.Point(14, 95); + this.VolumeNumericUpDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.VolumeNumericUpDown.Name = "VolumeNumericUpDown"; - this.VolumeNumericUpDown.Size = new System.Drawing.Size(141, 23); + this.VolumeNumericUpDown.Size = new System.Drawing.Size(161, 27); this.VolumeNumericUpDown.TabIndex = 11; // // FormShop // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(607, 405); + this.ClientSize = new System.Drawing.Size(694, 540); this.Controls.Add(this.VolumeNumericUpDown); this.Controls.Add(this.ReinforcedMaxCountLable); this.Controls.Add(this.textBoxDateOpening); @@ -182,6 +193,7 @@ this.Controls.Add(this.dataGridView); this.Controls.Add(this.comboBoxShop); this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormShop"; this.Text = "Просмотр изделий магазина"; this.Load += new System.EventHandler(this.FormShop_Load); diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index fa9a530..17af0d7 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.ViewModels; using PrecastConcretePlantDataModels.Models; using System; @@ -19,127 +20,75 @@ namespace ConfectioneryView { public partial class FormShop : Form { - private readonly List? _listShops; private readonly IShopLogic _logic; private readonly ILogger _logger; - - public int Id - { - get; set; - } - - private IShopModel? GetShop(int id) - { - if (_listShops == null) - { - return null; - } - foreach (var elem in _listShops) - { - if (elem.Id == id) - { - return elem; - } - } - return null; - } - + private int? _id; + private Dictionary _listShops; + public int Id { set { _id = value; } } public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); _logger = logger; - _listShops = logic.ReadList(null); + _listShops = new(); _logic = logic; - if (_listShops != null) - { - comboBoxShop.DisplayMember = "Name"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _listShops; - comboBoxShop.SelectedItem = null; - } } private void LoadData(bool extendDate = true) { + _logger.LogInformation("Загрузка изделий магазина"); try { - var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); - if (model != null) - { - comboBoxShop.Text = model.Name; - textBoxAddress.Text = model.Address; - textBoxDateOpening.Text = Convert.ToString(model.DateOpening); - VolumeNumericUpDown.Value = model.ReinforcedMaxCount; + if (_listShops != null) + { dataGridView.Rows.Clear(); - foreach (var el in model.ShopReinforcedies.Values) + foreach (var elem in _listShops) { - dataGridView.Rows.Add(new object[]{el.Item1.ReinforcedName, el.Item1.Price, el.Item2 }); + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ReinforcedName, elem.Value.Item2 }); } } - _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки магазинов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) - { - LoadData(false); - } - private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(comboBoxShop.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxAddress.Text)) { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Сохранение магазина"); try { - DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); - ShopBindingModel model = new() + var model = new ShopBindingModel { + Id = _id ?? 0, Name = comboBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTime, + DateOpening = textBoxDateOpening.Value.Date, ReinforcedMaxCount = (int)VolumeNumericUpDown.Value }; - var vmodel = GetShop(Id); - bool operationResult = false; - - if (vmodel != null) - { - model.Id = vmodel.Id; - operationResult = _logic.Update(model); - } - else - { - operationResult = _logic.Create(model); - } + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -152,7 +101,32 @@ namespace ConfectioneryView private void FormShop_Load(object sender, EventArgs e) { - LoadData(); + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + comboBoxShop.Text = view.Name; + textBoxAddress.Text = view.Address; + textBoxDateOpening.Text = view.DateOpening.ToString(); + VolumeNumericUpDown.Value = view.ReinforcedMaxCount; + _listShops = view.ShopReinforcedies ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } } From c393b3eb9bb117b1149255bc33ae6dcc88683edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 28 Mar 2023 10:02:27 +0400 Subject: [PATCH 09/18] fix name --- PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs | 2 +- PrecastConcretePlant/PrecastConcretePlant/FormMain.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index f481712..e07bf37 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -163,7 +163,7 @@ this.SellReinforcedButton.TabIndex = 8; this.SellReinforcedButton.Text = "Продать изделие"; this.SellReinforcedButton.UseVisualStyleBackColor = true; - this.SellReinforcedButton.Click += new System.EventHandler(this.SellPackageButton_Click); + this.SellReinforcedButton.Click += new System.EventHandler(this.SellReinforcedButton_Click); // // FormMain // diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 91f1105..f62fdd6 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -217,7 +217,7 @@ namespace PrecastConcretePlantView } } - private void SellPackageButton_Click(object sender, EventArgs e) + private void SellReinforcedButton_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced)); From e78c13eb5103fb1febb87764c034e4e648efeb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 28 Mar 2023 10:53:40 +0400 Subject: [PATCH 10/18] =?UTF-8?q?=D0=9F=D0=A4=D0=B8=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormShop.cs | 2 +- .../BusinessLogic/ShopLogic.cs | 16 +-- .../BindingModels/ShopBindingModel.cs | 4 +- .../ViewModels/ShopViewModel.cs | 2 +- .../Models/IShopModel.cs | 5 +- .../Implements/ReinforcedStorage.cs | 14 +-- .../Models/Reinforced.cs | 2 +- .../Models/Shop.cs | 118 ++++++++++++++++++ .../Models/ShopReinforced.cs | 23 ++++ .../PrecastConcretePlantDataBase.cs | 4 +- .../Implements/ShopStorage.cs | 10 +- .../Models/Shop.cs | 8 +- .../Models/Shop.cs | 8 +- 13 files changed, 180 insertions(+), 36 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index 17af0d7..05b91b4 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -116,7 +116,7 @@ namespace ConfectioneryView textBoxAddress.Text = view.Address; textBoxDateOpening.Text = view.DateOpening.ToString(); VolumeNumericUpDown.Value = view.ReinforcedMaxCount; - _listShops = view.ShopReinforcedies ?? new Dictionary(); + _listShops = view.Reinforcedies ?? new Dictionary(); LoadData(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 4e6aaa7..c1d9bd5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -57,7 +57,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); - model.ShopReinforcedies = new(); + model.Reinforcedies = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -148,21 +148,21 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic return false; } - if (element.ReinforcedMaxCount - element.ShopReinforcedies.Select(x => x.Value.Item2).Sum() < count) + if (element.ReinforcedMaxCount - element.Reinforcedies.Select(x => x.Value.Item2).Sum() < count) { throw new ArgumentNullException("Магазин переполнен", nameof(count)); } _logger.LogInformation("AddReinforced find. Id:{Id}", element.Id); - if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair)) + if (element.Reinforcedies.TryGetValue(reinforced.Id, out var pair)) { - element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); + element.Reinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } else { - element.ShopReinforcedies[reinforced.Id] = (reinforced, count); + element.Reinforcedies[reinforced.Id] = (reinforced, count); _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } @@ -173,7 +173,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic Name = element.Name, DateOpening = element.DateOpening, ReinforcedMaxCount = element.ReinforcedMaxCount, - ShopReinforcedies = element.ShopReinforcedies, + Reinforcedies = element.Reinforcedies, }); return true; @@ -191,7 +191,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } var freePlaces = _shopStorage.GetFullList() - .Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies + .Select(x => x.ReinforcedMaxCount - x.Reinforcedies .Select(p => p.Value.Item2).Sum()).Sum() - count; if (freePlaces < 0) @@ -202,7 +202,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic foreach (var shop in _shopStorage.GetFullList()) { - var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum()); + var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.Reinforcedies.Select(x => x.Value.Item2).Sum()); if (temp <= 0) { diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index 2c89326..f1a1afb 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -12,13 +12,13 @@ namespace PrecastConcretePlantContracts.BindingModels public string Name { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; + public int ReinforcedMaxCount { get; set; } public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary ShopReinforcedies { get; set; } = new(); + public Dictionary Reinforcedies { get; set; } = new(); public int Id { get; set; } - public int ReinforcedMaxCount { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 1708dfc..6505969 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -22,7 +22,7 @@ namespace PrecastConcretePlantContracts.ViewModels [DisplayName("Вместимость магазина")] public int ReinforcedMaxCount { get; set; } - public Dictionary ShopReinforcedies { get; set; } = new(); + public Dictionary Reinforcedies { get; set; } = new(); public int Id { get; set; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index 42ac617..0e723cf 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -10,8 +10,9 @@ namespace PrecastConcretePlantDataModels.Models { string Name { get; } string Address { get; } - DateTime DateOpening { get; } - Dictionary ShopReinforcedies { get; } public int ReinforcedMaxCount { get; } + DateTime DateOpening { get; } + Dictionary Reinforcedies { get; } + } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs index 50c3dd6..1925846 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs @@ -19,11 +19,11 @@ namespace PrecastConcretePlantDatabaseImplement.Implements { using var context = new PrecastConcretePlantDataBase(); - var element = context.Reinforceds.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Reinforcedies.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.Reinforceds.Remove(element); + context.Reinforcedies.Remove(element); context.SaveChanges(); return element.GetViewModel; } @@ -40,7 +40,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements using var context = new PrecastConcretePlantDataBase(); - return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Reinforcedies.Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(ReinforcedSearchModel model) @@ -52,14 +52,14 @@ namespace PrecastConcretePlantDatabaseImplement.Implements using var context = new PrecastConcretePlantDataBase(); - return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.ReinforcedName.Contains(model.ReinforcedName)).ToList().Select(x => x.GetViewModel).ToList(); + return context.Reinforcedies.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.ReinforcedName.Contains(model.ReinforcedName)).ToList().Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new PrecastConcretePlantDataBase(); - return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); + return context.Reinforcedies.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); } public ReinforcedViewModel? Insert(ReinforcedBindingModel model) @@ -73,7 +73,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return null; } - context.Reinforceds.Add(newReinforced); + context.Reinforcedies.Add(newReinforced); context.SaveChanges(); return newReinforced.GetViewModel; @@ -87,7 +87,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements try { - var reinforced = context.Reinforceds.FirstOrDefault(rec => rec.Id == model.Id); + var reinforced = context.Reinforcedies.FirstOrDefault(rec => rec.Id == model.Id); if (reinforced == null) { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs index b7978a0..1c91633 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs @@ -87,7 +87,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models context.SaveChanges(); } - var reinforced = context.Reinforceds.First(x => x.Id == Id); + var reinforced = context.Reinforcedies.First(x => x.Id == Id); foreach (var pc in model.ReinforcedComponents) { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..08512ff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs @@ -0,0 +1,118 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Models +{ + public class Shop : IShopModel + { + [Required] + public string Name { get; private set; } = string.Empty; + + [Required] + public string Address { get; private set; } = string.Empty; + + [Required] + public int ReinforcedMaxCount { get; private set; } + + public DateTime DateOpening { get; private set; } + + private Dictionary? _cachedReinforcedies = null; + [NotMapped] + public Dictionary Reinforcedies + { + get + { + if (_cachedReinforcedies == null) + { + using var context = new PrecastConcretePlantDataBase(); + _cachedReinforcedies = ShopReinforcedies + .ToDictionary(x => x.ReinforcedId, x => (context.Reinforcedies + .FirstOrDefault(y => y.Id == x.ReinforcedId)! as IReinforcedModel, x.Count)); + } + return _cachedReinforcedies; + } + } + + public int Id { get; private set; } + + [ForeignKey("ShopId")] + public virtual List ShopReinforcedies { get; set; } = new(); + + public static Shop? Create(PrecastConcretePlantDataBase context, ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + DateOpening = model.DateOpening, + ReinforcedMaxCount = model.ReinforcedMaxCount, + ShopReinforcedies = model.Reinforcedies.Select(x => new ShopReinforced + { + Reinforced = context.Reinforcedies.FirstOrDefault(y => y.Id == x.Key)!, + Count = x.Value.Item2, + }).ToList() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + Reinforcedies = Reinforcedies, + DateOpening = DateOpening, + ReinforcedMaxCount = ReinforcedMaxCount, + }; + + public void UpdateReinforcedies(PrecastConcretePlantDataBase context, ShopBindingModel model) + { + var shopReinforcedies = context.ShopReinforcedies + .Where(rec => rec.ShopId == model.Id) + .ToList(); + + if (shopReinforcedies != null && shopReinforcedies.Count > 0) + { + context.ShopReinforcedies + .RemoveRange(shopReinforcedies + .Where(rec => !model.Reinforcedies + .ContainsKey(rec.ReinforcedId))); + + foreach (var updateReinforced in shopReinforcedies.Where(x => model.Reinforcedies.ContainsKey(x.ReinforcedId))) + { + updateReinforced.Count = model.Reinforcedies[updateReinforced.ReinforcedId].Item2; + model.Reinforcedies.Remove(updateReinforced.ReinforcedId); + } + } + var shop = context.Shops.First(x => x.Id == model.Id); + shop.ShopReinforcedies.AddRange(model.Reinforcedies.Select(x => new ShopReinforced + { + Reinforced = context.Reinforcedies.First(y => y.Id == x.Key), + Count = x.Value.Item2, + }).Except(shopReinforcedies ?? new())); + context.SaveChanges(); + _cachedReinforcedies = null; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs new file mode 100644 index 0000000..8f00eda --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Models +{ + public class ShopReinforced + { + public int Id { get; set; } + [Required] + public int ReinforcedId { get; set; } + [Required] + public int ShopId { get; set; } + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + public virtual Reinforced Reinforced { get; set; } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs index 0e7da02..7403d77 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs @@ -19,8 +19,10 @@ namespace PrecastConcretePlantDatabaseImplement base.OnConfiguring(optionsBuilder); } public virtual DbSet Components { set; get; } - public virtual DbSet Reinforceds { set; get; } + public virtual DbSet Reinforcedies { set; get; } public virtual DbSet ReinforcedComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Shops { set; get; } + public virtual DbSet ShopReinforcedies { set; get; } } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs index 19f21ac..c3d76db 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -72,21 +72,21 @@ namespace PrecastConcretePlantFileImplement.Implements public bool SellReinforced(IReinforcedModel model, int quantity) { - if (source.Shops.Select(x => x.ShopReinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) + if (source.Shops.Select(x => x.Reinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) { return false; } - foreach (var shop in source.Shops.Where(x => x.ShopReinforcedies.ContainsKey(model.Id))) + foreach (var shop in source.Shops.Where(x => x.Reinforcedies.ContainsKey(model.Id))) { - int QuantityInCurrentShop = shop.ShopReinforcedies[model.Id].Item2; + int QuantityInCurrentShop = shop.Reinforcedies[model.Id].Item2; if (QuantityInCurrentShop <= quantity) { - shop.ShopReinforcedies.Remove(model.Id); + shop.Reinforcedies.Remove(model.Id); quantity -= QuantityInCurrentShop; } else { - shop.ShopReinforcedies[model.Id] = (shop.ShopReinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); + shop.Reinforcedies[model.Id] = (shop.Reinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); quantity = 0; } if (quantity == 0) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs index d262c11..4c07c94 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -19,7 +19,7 @@ namespace PrecastConcretePlantFileImplement.Models public Dictionary Reinforcedies { get; private set; } = new(); public Dictionary _shopReinforcedies = null; - public Dictionary ShopReinforcedies + public Dictionary Reinforcedies { get { @@ -49,7 +49,7 @@ namespace PrecastConcretePlantFileImplement.Models Address = model.Address, ReinforcedMaxCount = model.ReinforcedMaxCount, DateOpening = model.DateOpening, - Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2) + Reinforcedies = model.Reinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2) }; } public static Shop? Create(XElement element) @@ -80,7 +80,7 @@ namespace PrecastConcretePlantFileImplement.Models Address = model.Address; DateOpening = model.DateOpening; ReinforcedMaxCount = model.ReinforcedMaxCount; - Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2); + Reinforcedies = model.Reinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2); _shopReinforcedies = null; } public ShopViewModel GetViewModel => new() @@ -88,7 +88,7 @@ namespace PrecastConcretePlantFileImplement.Models Id = Id, Name = Name, Address = Address, - ShopReinforcedies = ShopReinforcedies, + Reinforcedies = Reinforcedies, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, }; diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index a8895f2..58b6d45 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -17,7 +17,7 @@ namespace PrecastConcretePlantListImplement.Models public DateTime DateOpening { get; private set; } - public Dictionary ShopReinforcedies { get; private set; } = new(); + public Dictionary Reinforcedies { get; private set; } = new(); public int Id { get; private set; } @@ -33,7 +33,7 @@ namespace PrecastConcretePlantListImplement.Models Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, - ShopReinforcedies = new() + Reinforcedies = new() }; } public void Update(ShopBindingModel? model) @@ -45,14 +45,14 @@ namespace PrecastConcretePlantListImplement.Models Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; - ShopReinforcedies = model.ShopReinforcedies; + Reinforcedies = model.Reinforcedies; } public ShopViewModel GetViewModel => new() { Id = Id, Name = Name, Address = Address, - ShopReinforcedies = ShopReinforcedies, + Reinforcedies = Reinforcedies, DateOpening = DateOpening, }; public int ReinforcedMaxCount => throw new NotImplementedException(); From ff8c9169cb592b72e340e334a7d519fc6e3bcf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 9 Apr 2023 18:26:39 +0400 Subject: [PATCH 11/18] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D1=8B=20=D1=81=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormShop.cs | 6 +- .../BusinessLogic/ShopLogic.cs | 42 ++--- .../BindingModels/ShopBindingModel.cs | 4 +- .../SearchModels/ShopSearchModel.cs | 2 +- .../ViewModels/ShopViewModel.cs | 4 +- .../Models/IShopModel.cs | 4 +- .../Implements/ShopStorage.cs | 160 ++++++++++++++++ .../20230226175226_InitMigration.Designer.cs | 175 ------------------ .../20230226175226_InitMigration.cs | 126 ------------- ...ecastConcretePlantDataBaseModelSnapshot.cs | 172 ----------------- .../Models/Shop.cs | 98 +++++----- .../Implements/ShopStorage.cs | 10 +- .../Models/Shop.cs | 20 +- .../Implements/ShopStorage.cs | 10 +- .../Models/Shop.cs | 16 +- 15 files changed, 262 insertions(+), 587 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index 05b91b4..5f8fdc0 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -72,7 +72,7 @@ namespace ConfectioneryView var model = new ShopBindingModel { Id = _id ?? 0, - Name = comboBoxShop.Text, + ShopName = comboBoxShop.Text, Address = textBoxAddress.Text, DateOpening = textBoxDateOpening.Value.Date, ReinforcedMaxCount = (int)VolumeNumericUpDown.Value @@ -112,11 +112,11 @@ namespace ConfectioneryView }); if (view != null) { - comboBoxShop.Text = view.Name; + comboBoxShop.Text = view.ShopName; textBoxAddress.Text = view.Address; textBoxDateOpening.Text = view.DateOpening.ToString(); VolumeNumericUpDown.Value = view.ReinforcedMaxCount; - _listShops = view.Reinforcedies ?? new Dictionary(); + _listShops = view.ShopReinforcedies ?? new Dictionary(); LoadData(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index c1d9bd5..58c1e0e 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -26,7 +26,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public List? ReadList(ShopSearchModel? model) { _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ", - model?.Name, model?.Id); + model?.ShopName, model?.Id); var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); if (list == null) @@ -44,7 +44,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", - model.Name, model.Id); + model.ShopName, model.Id); var element = _shopStorage.GetElement(model); if (element == null) { @@ -57,7 +57,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); - model.Reinforcedies = new(); + model.ShopReinforcedies = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -72,10 +72,10 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Update(ShopBindingModel model) { CheckModel(model, false); - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { throw new ArgumentNullException("Нет названия магазина", - nameof(model.Name)); + nameof(model.ShopName)); } if (_shopStorage.Update(model) == null) @@ -106,22 +106,22 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { throw new ArgumentNullException("Нет названия магазина", - nameof(model.Name)); + nameof(model.ShopName)); } if (model.ReinforcedMaxCount < 0) { throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount)); } _logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}", - model.Name, model.Address, model.Id); + model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - Name = model.Name + ShopName = model.ShopName }); - if (element != null && element.Id != model.Id && element.Name == model.Name) + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } @@ -139,7 +139,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id); + _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.ShopName, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -148,32 +148,32 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic return false; } - if (element.ReinforcedMaxCount - element.Reinforcedies.Select(x => x.Value.Item2).Sum() < count) + if (element.ReinforcedMaxCount - element.ShopReinforcedies.Select(x => x.Value.Item2).Sum() < count) { throw new ArgumentNullException("Магазин переполнен", nameof(count)); } _logger.LogInformation("AddReinforced find. Id:{Id}", element.Id); - if (element.Reinforcedies.TryGetValue(reinforced.Id, out var pair)) + if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair)) { - element.Reinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); - _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); + element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); + _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.ShopName); } else { - element.Reinforcedies[reinforced.Id] = (reinforced, count); - _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); + element.ShopReinforcedies[reinforced.Id] = (reinforced, count); + _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.ShopName); } _shopStorage.Update(new() { Id = element.Id, Address = element.Address, - Name = element.Name, + ShopName = element.ShopName, DateOpening = element.DateOpening, ReinforcedMaxCount = element.ReinforcedMaxCount, - Reinforcedies = element.Reinforcedies, + ShopReinforcedies = element.ShopReinforcedies, }); return true; @@ -191,7 +191,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } var freePlaces = _shopStorage.GetFullList() - .Select(x => x.ReinforcedMaxCount - x.Reinforcedies + .Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies .Select(p => p.Value.Item2).Sum()).Sum() - count; if (freePlaces < 0) @@ -202,7 +202,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic foreach (var shop in _shopStorage.GetFullList()) { - var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.Reinforcedies.Select(x => x.Value.Item2).Sum()); + var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum()); if (temp <= 0) { diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index f1a1afb..854bf31 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -9,14 +9,14 @@ namespace PrecastConcretePlantContracts.BindingModels { public class ShopBindingModel : IShopModel { - public string Name { get; set; } = string.Empty; + public string ShopName { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; public int ReinforcedMaxCount { get; set; } public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Reinforcedies { get; set; } = new(); + public Dictionary ShopReinforcedies { get; set; } = new(); public int Id { get; set; } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs index c08ab42..b46f4a9 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs @@ -9,6 +9,6 @@ namespace PrecastConcretePlantContracts.SearchModels public class ShopSearchModel { public int? Id { get; set; } - public string? Name { get; set; } + public string? ShopName { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 6505969..c079c2f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -11,7 +11,7 @@ namespace PrecastConcretePlantContracts.ViewModels public class ShopViewModel : IShopModel { [DisplayName("Название магазина")] - public string Name { get; set; } = string.Empty; + public string ShopName { get; set; } = string.Empty; [DisplayName("Адрес магазина")] public string Address { get; set; } = string.Empty; @@ -22,7 +22,7 @@ namespace PrecastConcretePlantContracts.ViewModels [DisplayName("Вместимость магазина")] public int ReinforcedMaxCount { get; set; } - public Dictionary Reinforcedies { get; set; } = new(); + public Dictionary ShopReinforcedies { get; set; } = new(); public int Id { get; set; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index 0e723cf..fb03ab3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -8,11 +8,11 @@ namespace PrecastConcretePlantDataModels.Models { public interface IShopModel : IId { - string Name { get; } + string ShopName { get; } string Address { get; } public int ReinforcedMaxCount { get; } DateTime DateOpening { get; } - Dictionary Reinforcedies { get; } + Dictionary ShopReinforcedies { get; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..ede4607 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,160 @@ +using Microsoft.EntityFrameworkCore; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDatabaseImplement.Models; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new PrecastConcretePlantDataBase(); + return context.Shops + .Include(x => x.Reinforcedies) + .ThenInclude(x => x.Reinforced) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new PrecastConcretePlantDataBase(); + return context.Shops + .Include(x => x.Reinforcedies) + .ThenInclude(x => x.Reinforced) + .Where(x => x.ShopName.Contains(model.ShopName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + using var context = new PrecastConcretePlantDataBase(); + return context.Shops + .Include(x => x.Reinforcedies) + .ThenInclude(x => x.Reinforced) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdateReinforcedies(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var element = context.Shops + .Include(x => x.Reinforcedies) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public bool SellReinforcedies(IReinforcedModel model, int count) + { + using var context = new PrecastConcretePlantDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shops = context.ShopReinforcedies + .Include(x => x.Shop) + .ToList() + .Where(rec => rec.ReinforcedId == model.Id); + if (shops == null) + { + return false; + } + foreach (var shop in shops) + { + if (shop.Count < count) + { + shop.Count = 0; + count -= shop.Count; + } + else + { + shop.Count = shop.Count - count; + count -= count; + } + if (count == 0) + { + + context.SaveChanges(); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public bool SellReinforced(IReinforcedModel model, int quantity) + { + throw new NotImplementedException(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs deleted file mode 100644 index 20c2331..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.Designer.cs +++ /dev/null @@ -1,175 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PrecastConcretePlantDatabaseImplement; - -#nullable disable - -namespace PrecastConcretePlantDatabaseImplement.Migrations -{ - [DbContext(typeof(PrecastConcretePlantDataBase))] - [Migration("20230226175226_InitMigration")] - partial class InitMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Reinforceds"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Orders") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") - .WithMany("ReinforcedComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Components") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Navigation("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs deleted file mode 100644 index b82c188..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230226175226_InitMigration.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace PrecastConcretePlantDatabaseImplement.Migrations -{ - /// - public partial class InitMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComponentName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Reinforceds", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Reinforceds", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ReinforcedId = table.Column(type: "int", nullable: false), - ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - Status = table.Column(type: "int", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Reinforceds_ReinforcedId", - column: x => x.ReinforcedId, - principalTable: "Reinforceds", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ReinforcedComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ReinforcedId = table.Column(type: "int", nullable: false), - ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ReinforcedComponents", x => x.Id); - table.ForeignKey( - name: "FK_ReinforcedComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ReinforcedComponents_Reinforceds_ReinforcedId", - column: x => x.ReinforcedId, - principalTable: "Reinforceds", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ReinforcedId", - table: "Orders", - column: "ReinforcedId"); - - migrationBuilder.CreateIndex( - name: "IX_ReinforcedComponents_ComponentId", - table: "ReinforcedComponents", - column: "ComponentId"); - - migrationBuilder.CreateIndex( - name: "IX_ReinforcedComponents_ReinforcedId", - table: "ReinforcedComponents", - column: "ReinforcedId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "ReinforcedComponents"); - - migrationBuilder.DropTable( - name: "Components"); - - migrationBuilder.DropTable( - name: "Reinforceds"); - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs deleted file mode 100644 index 9f8ee2e..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs +++ /dev/null @@ -1,172 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PrecastConcretePlantDatabaseImplement; - -#nullable disable - -namespace PrecastConcretePlantDatabaseImplement.Migrations -{ - [DbContext(typeof(PrecastConcretePlantDataBase))] - partial class PrecastConcretePlantDataBaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Reinforceds"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Orders") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") - .WithMany("ReinforcedComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Components") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Navigation("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs index 08512ff..a551341 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs @@ -13,106 +13,94 @@ namespace PrecastConcretePlantDatabaseImplement.Models { public class Shop : IShopModel { + public int Id { get; set; } [Required] - public string Name { get; private set; } = string.Empty; - + public string ShopName { get; set; } = string.Empty; [Required] - public string Address { get; private set; } = string.Empty; - + public string Address { get; set; } = string.Empty; [Required] - public int ReinforcedMaxCount { get; private set; } + public DateTime DateOpening { get; set; } + [Required] + public int ReinforcedMaxCount { get; set; } - public DateTime DateOpening { get; private set; } + private Dictionary? _shopReinforcedies = null; - private Dictionary? _cachedReinforcedies = null; [NotMapped] - public Dictionary Reinforcedies + public Dictionary ShopReinforcedies { get { - if (_cachedReinforcedies == null) + if (_shopReinforcedies == null) { - using var context = new PrecastConcretePlantDataBase(); - _cachedReinforcedies = ShopReinforcedies - .ToDictionary(x => x.ReinforcedId, x => (context.Reinforcedies - .FirstOrDefault(y => y.Id == x.ReinforcedId)! as IReinforcedModel, x.Count)); + _shopReinforcedies = Reinforcedies.ToDictionary(recST => recST.ReinforcedId, recST => (recST.Reinforced as IReinforcedModel, recST.Count)); } - return _cachedReinforcedies; + return _shopReinforcedies; } } - - public int Id { get; private set; } - [ForeignKey("ShopId")] - public virtual List ShopReinforcedies { get; set; } = new(); - - public static Shop? Create(PrecastConcretePlantDataBase context, ShopBindingModel? model) + public virtual List Reinforcedies { get; set; } = new(); + public static Shop Create(PrecastConcretePlantDataBase context, ShopBindingModel model) { - if (model == null) - { - return null; - } return new Shop() { Id = model.Id, - Name = model.Name, + ShopName = model.ShopName, Address = model.Address, DateOpening = model.DateOpening, ReinforcedMaxCount = model.ReinforcedMaxCount, - ShopReinforcedies = model.Reinforcedies.Select(x => new ShopReinforced + Reinforcedies = model.ShopReinforcedies.Select(x => new ShopReinforced { - Reinforced = context.Reinforcedies.FirstOrDefault(y => y.Id == x.Key)!, - Count = x.Value.Item2, + Reinforced = context.Reinforcedies.First(y => y.Id == x.Key), + Count = x.Value.Item2 }).ToList() }; } - public void Update(ShopBindingModel? model) + + public void Update(ShopBindingModel model) { - if (model == null) - { - return; - } - Name = model.Name; + ShopName = model.ShopName; Address = model.Address; DateOpening = model.DateOpening; + ReinforcedMaxCount = model.ReinforcedMaxCount; } + public ShopViewModel GetViewModel => new() { Id = Id, - Name = Name, + ShopName = ShopName, Address = Address, - Reinforcedies = Reinforcedies, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, + ShopReinforcedies = ShopReinforcedies }; public void UpdateReinforcedies(PrecastConcretePlantDataBase context, ShopBindingModel model) { - var shopReinforcedies = context.ShopReinforcedies - .Where(rec => rec.ShopId == model.Id) - .ToList(); - + var shopReinforcedies = context.ShopReinforcedies.Where(rec => rec.ShopId == model.Id).ToList(); if (shopReinforcedies != null && shopReinforcedies.Count > 0) - { - context.ShopReinforcedies - .RemoveRange(shopReinforcedies - .Where(rec => !model.Reinforcedies - .ContainsKey(rec.ReinforcedId))); + { + context.ShopReinforcedies.RemoveRange(shopReinforcedies.Where(rec => !model.ShopReinforcedies.ContainsKey(rec.ReinforcedId))); + context.SaveChanges(); - foreach (var updateReinforced in shopReinforcedies.Where(x => model.Reinforcedies.ContainsKey(x.ReinforcedId))) + foreach (var updateReinforced in shopReinforcedies) { - updateReinforced.Count = model.Reinforcedies[updateReinforced.ReinforcedId].Item2; - model.Reinforcedies.Remove(updateReinforced.ReinforcedId); + updateReinforced.Count = model.ShopReinforcedies[updateReinforced.ReinforcedId].Item2; + model.ShopReinforcedies.Remove(updateReinforced.ReinforcedId); } + context.SaveChanges(); } - var shop = context.Shops.First(x => x.Id == model.Id); - shop.ShopReinforcedies.AddRange(model.Reinforcedies.Select(x => new ShopReinforced + var shop = context.Shops.First(x => x.Id == Id); + foreach (var st in model.ShopReinforcedies) { - Reinforced = context.Reinforcedies.First(y => y.Id == x.Key), - Count = x.Value.Item2, - }).Except(shopReinforcedies ?? new())); - context.SaveChanges(); - _cachedReinforcedies = null; + context.ShopReinforcedies.Add(new ShopReinforced + { + Shop = shop, + Reinforced = context.Reinforcedies.First(x => x.Id == st.Key), + Count = st.Value.Item2 + }); + context.SaveChanges(); + } + _shopReinforcedies = null; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs index c3d76db..2a95924 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -34,22 +34,22 @@ namespace PrecastConcretePlantFileImplement.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) { return null; } return source.Shops.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Name) && x.Name == - model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == + model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { return new(); } - return source.Shops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs index 4c07c94..b39ab4e 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -12,14 +12,14 @@ namespace PrecastConcretePlantFileImplement.Models { public class Shop : IShopModel { - public string Name { get; private set; } = string.Empty; + public string ShopName { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; public DateTime DateOpening { get; private set; } public Dictionary Reinforcedies { get; private set; } = new(); public Dictionary _shopReinforcedies = null; - public Dictionary Reinforcedies + public Dictionary ShopReinforcedies { get { @@ -45,11 +45,11 @@ namespace PrecastConcretePlantFileImplement.Models return new Shop() { Id = model.Id, - Name = model.Name, + ShopName = model.ShopName, Address = model.Address, ReinforcedMaxCount = model.ReinforcedMaxCount, DateOpening = model.DateOpening, - Reinforcedies = model.Reinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2) + Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2) }; } public static Shop? Create(XElement element) @@ -61,7 +61,7 @@ namespace PrecastConcretePlantFileImplement.Models return new() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - Name = element.Element("Name")!.Value, + ShopName = element.Element("Name")!.Value, Address = element.Element("Address")!.Value, DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value), @@ -76,25 +76,25 @@ namespace PrecastConcretePlantFileImplement.Models { return; } - Name = model.Name; + ShopName = model.ShopName; Address = model.Address; DateOpening = model.DateOpening; ReinforcedMaxCount = model.ReinforcedMaxCount; - Reinforcedies = model.Reinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2); + Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2); _shopReinforcedies = null; } public ShopViewModel GetViewModel => new() { Id = Id, - Name = Name, + ShopName = ShopName, Address = Address, - Reinforcedies = Reinforcedies, + ShopReinforcedies = Reinforcedies, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, }; public XElement GetXElement => new("Shop", new XAttribute("Id", Id), - new XElement("Name", Name), + new XElement("Name", ShopName), new XElement("Address", Address), new XElement("DateOpening", DateOpening), new XElement("ReinforcedMaxCount", ReinforcedMaxCount), diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index 5a8cbb5..cdd8b15 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -39,14 +39,14 @@ namespace PrecastConcretePlantListImplement.Implements } public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) { return null; } foreach (var shop in _source.Shops) { - if ((!string.IsNullOrEmpty(model.Name) && - shop.Name == model.Name) || + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id)) { return shop.GetViewModel; @@ -58,13 +58,13 @@ namespace PrecastConcretePlantListImplement.Implements public List GetFilteredList(ShopSearchModel model) { var result = new List(); - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { return result; } foreach (var shop in _source.Shops) { - if (shop.Name.Contains(model.Name ?? string.Empty)) + if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) { result.Add(shop.GetViewModel); } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index 58b6d45..a1fb8e0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -11,13 +11,13 @@ namespace PrecastConcretePlantListImplement.Models { public class Shop : IShopModel { - public string Name { get; private set; } = string.Empty; + public string ShopName { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; public DateTime DateOpening { get; private set; } - public Dictionary Reinforcedies { get; private set; } = new(); + public Dictionary ShopReinforcedies { get; private set; } = new(); public int Id { get; private set; } @@ -30,10 +30,10 @@ namespace PrecastConcretePlantListImplement.Models return new Shop() { Id = model.Id, - Name = model.Name, + ShopName = model.ShopName, Address = model.Address, DateOpening = model.DateOpening, - Reinforcedies = new() + ShopReinforcedies = new() }; } public void Update(ShopBindingModel? model) @@ -42,17 +42,17 @@ namespace PrecastConcretePlantListImplement.Models { return; } - Name = model.Name; + ShopName = model.ShopName; Address = model.Address; DateOpening = model.DateOpening; - Reinforcedies = model.Reinforcedies; + ShopReinforcedies = model.ShopReinforcedies; } public ShopViewModel GetViewModel => new() { Id = Id, - Name = Name, + ShopName = ShopName, Address = Address, - Reinforcedies = Reinforcedies, + ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening, }; public int ReinforcedMaxCount => throw new NotImplementedException(); From d8c56a9723b2012650b320f2c3018e26fdea0fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 9 Apr 2023 19:05:11 +0400 Subject: [PATCH 12/18] =?UTF-8?q?=D0=9E=D1=87=D0=B5=D0=BD=D1=8C=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81.=20=D0=9C=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=B7=D0=B0=20FileImplements=20=D0=B8=20?= =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BA=D0=B0=D0=BA=D0=BE=D0=B9=20=D1=82?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BA=D0=BE=D0=BB=20=D1=81=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormMain.cs | 2 +- .../FormReinforcedShop.Designer.cs | 2 +- .../FormReinforcedShop.cs | 2 +- .../PrecastConcretePlant/FormShop.Designer.cs | 2 +- .../PrecastConcretePlant/FormShop.cs | 6 +- .../FormShops.Designer.cs | 2 +- .../PrecastConcretePlant/FormShops.cs | 2 +- .../BusinessLogic/ShopLogic.cs | 26 +- .../BindingModels/ShopBindingModel.cs | 2 +- .../SearchModels/ShopSearchModel.cs | 2 +- .../ViewModels/ShopViewModel.cs | 2 +- .../Models/IShopModel.cs | 2 +- .../Implements/ShopStorage.cs | 8 +- .../20230409150055_FirstMigr.Designer.cs | 252 ++++++++++++++++++ .../Migrations/20230409150055_FirstMigr.cs | 185 +++++++++++++ ...ecastConcretePlantDataBaseModelSnapshot.cs | 249 +++++++++++++++++ .../Models/Shop.cs | 8 +- .../PrecastConcretePlantDataBase.cs | 2 +- .../Implements/ShopStorage.cs | 20 +- .../Models/Shop.cs | 14 +- .../Implements/ShopStorage.cs | 10 +- .../Models/Shop.cs | 8 +- 22 files changed, 747 insertions(+), 61 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index f62fdd6..b9a1692 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -1,4 +1,4 @@ -using ConfectioneryView; + using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs index abe81e2..ece5061 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs @@ -1,4 +1,4 @@ -namespace ConfectioneryView +namespace PrecastConcretePlantView { partial class FormReinforcedShop { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs index 565cc8c..e8122ce 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs @@ -12,7 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace ConfectioneryView +namespace PrecastConcretePlantView { public partial class FormReinforcedShop : Form { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index ca6cec6..00602f5 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -1,4 +1,4 @@ -namespace ConfectioneryView +namespace PrecastConcretePlantView { partial class FormShop { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index 5f8fdc0..e1a4b16 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -16,7 +16,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace ConfectioneryView +namespace PrecastConcretePlantView { public partial class FormShop : Form { @@ -72,7 +72,7 @@ namespace ConfectioneryView var model = new ShopBindingModel { Id = _id ?? 0, - ShopName = comboBoxShop.Text, + Name = comboBoxShop.Text, Address = textBoxAddress.Text, DateOpening = textBoxDateOpening.Value.Date, ReinforcedMaxCount = (int)VolumeNumericUpDown.Value @@ -112,7 +112,7 @@ namespace ConfectioneryView }); if (view != null) { - comboBoxShop.Text = view.ShopName; + comboBoxShop.Text = view.Name; textBoxAddress.Text = view.Address; textBoxDateOpening.Text = view.DateOpening.ToString(); VolumeNumericUpDown.Value = view.ReinforcedMaxCount; diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs index d2ce2f6..c9657ae 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs @@ -1,4 +1,4 @@ -namespace ConfectioneryView +namespace PrecastConcretePlantView { partial class FormShops { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs index c00af8d..b3fb52f 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs @@ -3,7 +3,7 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantView; -namespace ConfectioneryView +namespace PrecastConcretePlantView { public partial class FormShops : Form { diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 58c1e0e..4e6aaa7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -26,7 +26,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public List? ReadList(ShopSearchModel? model) { _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ", - model?.ShopName, model?.Id); + model?.Name, model?.Id); var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); if (list == null) @@ -44,7 +44,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", - model.ShopName, model.Id); + model.Name, model.Id); var element = _shopStorage.GetElement(model); if (element == null) { @@ -72,10 +72,10 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Update(ShopBindingModel model) { CheckModel(model, false); - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); + nameof(model.Name)); } if (_shopStorage.Update(model) == null) @@ -106,22 +106,22 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); + nameof(model.Name)); } if (model.ReinforcedMaxCount < 0) { throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount)); } _logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}", - model.ShopName, model.Address, model.Id); + model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - ShopName = model.ShopName + Name = model.Name }); - if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + if (element != null && element.Id != model.Id && element.Name == model.Name) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } @@ -139,7 +139,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.ShopName, model.Id); + _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -158,19 +158,19 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair)) { element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); - _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.ShopName); + _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } else { element.ShopReinforcedies[reinforced.Id] = (reinforced, count); - _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.ShopName); + _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } _shopStorage.Update(new() { Id = element.Id, Address = element.Address, - ShopName = element.ShopName, + Name = element.Name, DateOpening = element.DateOpening, ReinforcedMaxCount = element.ReinforcedMaxCount, ShopReinforcedies = element.ShopReinforcedies, diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index 854bf31..9d4213f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -9,7 +9,7 @@ namespace PrecastConcretePlantContracts.BindingModels { public class ShopBindingModel : IShopModel { - public string ShopName { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; public int ReinforcedMaxCount { get; set; } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs index b46f4a9..c08ab42 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs @@ -9,6 +9,6 @@ namespace PrecastConcretePlantContracts.SearchModels public class ShopSearchModel { public int? Id { get; set; } - public string? ShopName { get; set; } + public string? Name { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index c079c2f..1708dfc 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -11,7 +11,7 @@ namespace PrecastConcretePlantContracts.ViewModels public class ShopViewModel : IShopModel { [DisplayName("Название магазина")] - public string ShopName { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; [DisplayName("Адрес магазина")] public string Address { get; set; } = string.Empty; diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index fb03ab3..5d055cf 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -8,7 +8,7 @@ namespace PrecastConcretePlantDataModels.Models { public interface IShopModel : IId { - string ShopName { get; } + string Name { get; } string Address { get; } public int ReinforcedMaxCount { get; } DateTime DateOpening { get; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs index ede4607..184e57a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs @@ -28,7 +28,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public List GetFilteredList(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { return new(); } @@ -36,7 +36,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return context.Shops .Include(x => x.Reinforcedies) .ThenInclude(x => x.Reinforced) - .Where(x => x.ShopName.Contains(model.ShopName)) + .Where(x => x.Name.Contains(model.Name)) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -44,7 +44,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) { return null; } @@ -52,7 +52,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return context.Shops .Include(x => x.Reinforcedies) .ThenInclude(x => x.Reinforced) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs new file mode 100644 index 0000000..150bb1c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDatabaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDataBase))] + [Migration("20230409150055_FirstMigr")] + partial class FirstMigr + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReinforcedMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopReinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Shop", "Shop") + .WithMany("Reinforcedies") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Navigation("Reinforcedies"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs new file mode 100644 index 0000000..14e43b1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs @@ -0,0 +1,185 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + /// + public partial class FirstMigr : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Reinforcedies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Reinforcedies", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOpening = table.Column(type: "datetime2", nullable: false), + ReinforcedMaxCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedId = table.Column(type: "int", nullable: false), + ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Reinforcedies_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforcedies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ReinforcedComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReinforcedComponents", x => x.Id); + table.ForeignKey( + name: "FK_ReinforcedComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ReinforcedComponents_Reinforcedies_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforcedies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ShopReinforcedies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopReinforcedies", x => x.Id); + table.ForeignKey( + name: "FK_ShopReinforcedies_Reinforcedies_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforcedies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopReinforcedies_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ReinforcedId", + table: "Orders", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ReinforcedComponents_ComponentId", + table: "ReinforcedComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ReinforcedComponents_ReinforcedId", + table: "ReinforcedComponents", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopReinforcedies_ReinforcedId", + table: "ShopReinforcedies", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopReinforcedies_ShopId", + table: "ShopReinforcedies", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "ReinforcedComponents"); + + migrationBuilder.DropTable( + name: "ShopReinforcedies"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Reinforcedies"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs new file mode 100644 index 0000000..1f2e84a --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs @@ -0,0 +1,249 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDatabaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDataBase))] + partial class PrecastConcretePlantDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReinforcedMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopReinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Shop", "Shop") + .WithMany("Reinforcedies") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Navigation("Reinforcedies"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs index a551341..4b737e8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs @@ -15,7 +15,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models { public int Id { get; set; } [Required] - public string ShopName { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; [Required] public string Address { get; set; } = string.Empty; [Required] @@ -44,7 +44,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models return new Shop() { Id = model.Id, - ShopName = model.ShopName, + Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, ReinforcedMaxCount = model.ReinforcedMaxCount, @@ -58,7 +58,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models public void Update(ShopBindingModel model) { - ShopName = model.ShopName; + Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; ReinforcedMaxCount = model.ReinforcedMaxCount; @@ -67,7 +67,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models public ShopViewModel GetViewModel => new() { Id = Id, - ShopName = ShopName, + Name = Name, Address = Address, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs index 7403d77..320c1e6 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs @@ -14,7 +14,7 @@ namespace PrecastConcretePlantDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=MAKSIM\SQLEXPRESS;Initial Catalog=PrecastConcretePlantDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=MAKSIM\SQLEXPRESS;Initial Catalog=PrecastConcretePlantDataBaseFullHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs index 2a95924..19f21ac 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -34,22 +34,22 @@ namespace PrecastConcretePlantFileImplement.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) { return null; } return source.Shops.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == - model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + (!string.IsNullOrEmpty(model.Name) && x.Name == + model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { return new(); } - return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + return source.Shops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); } public List GetFullList() @@ -72,21 +72,21 @@ namespace PrecastConcretePlantFileImplement.Implements public bool SellReinforced(IReinforcedModel model, int quantity) { - if (source.Shops.Select(x => x.Reinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) + if (source.Shops.Select(x => x.ShopReinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) { return false; } - foreach (var shop in source.Shops.Where(x => x.Reinforcedies.ContainsKey(model.Id))) + foreach (var shop in source.Shops.Where(x => x.ShopReinforcedies.ContainsKey(model.Id))) { - int QuantityInCurrentShop = shop.Reinforcedies[model.Id].Item2; + int QuantityInCurrentShop = shop.ShopReinforcedies[model.Id].Item2; if (QuantityInCurrentShop <= quantity) { - shop.Reinforcedies.Remove(model.Id); + shop.ShopReinforcedies.Remove(model.Id); quantity -= QuantityInCurrentShop; } else { - shop.Reinforcedies[model.Id] = (shop.Reinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); + shop.ShopReinforcedies[model.Id] = (shop.ShopReinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); quantity = 0; } if (quantity == 0) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs index b39ab4e..d262c11 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -12,7 +12,7 @@ namespace PrecastConcretePlantFileImplement.Models { public class Shop : IShopModel { - public string ShopName { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; public DateTime DateOpening { get; private set; } @@ -45,7 +45,7 @@ namespace PrecastConcretePlantFileImplement.Models return new Shop() { Id = model.Id, - ShopName = model.ShopName, + Name = model.Name, Address = model.Address, ReinforcedMaxCount = model.ReinforcedMaxCount, DateOpening = model.DateOpening, @@ -61,7 +61,7 @@ namespace PrecastConcretePlantFileImplement.Models return new() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ShopName = element.Element("Name")!.Value, + Name = element.Element("Name")!.Value, Address = element.Element("Address")!.Value, DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value), @@ -76,7 +76,7 @@ namespace PrecastConcretePlantFileImplement.Models { return; } - ShopName = model.ShopName; + Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; ReinforcedMaxCount = model.ReinforcedMaxCount; @@ -86,15 +86,15 @@ namespace PrecastConcretePlantFileImplement.Models public ShopViewModel GetViewModel => new() { Id = Id, - ShopName = ShopName, + Name = Name, Address = Address, - ShopReinforcedies = Reinforcedies, + ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, }; public XElement GetXElement => new("Shop", new XAttribute("Id", Id), - new XElement("Name", ShopName), + new XElement("Name", Name), new XElement("Address", Address), new XElement("DateOpening", DateOpening), new XElement("ReinforcedMaxCount", ReinforcedMaxCount), diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index cdd8b15..5a8cbb5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -39,14 +39,14 @@ namespace PrecastConcretePlantListImplement.Implements } public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) { return null; } foreach (var shop in _source.Shops) { - if ((!string.IsNullOrEmpty(model.ShopName) && - shop.ShopName == model.ShopName) || + if ((!string.IsNullOrEmpty(model.Name) && + shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id)) { return shop.GetViewModel; @@ -58,13 +58,13 @@ namespace PrecastConcretePlantListImplement.Implements public List GetFilteredList(ShopSearchModel model) { var result = new List(); - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { return result; } foreach (var shop in _source.Shops) { - if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) + if (shop.Name.Contains(model.Name ?? string.Empty)) { result.Add(shop.GetViewModel); } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index a1fb8e0..a8895f2 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -11,7 +11,7 @@ namespace PrecastConcretePlantListImplement.Models { public class Shop : IShopModel { - public string ShopName { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; @@ -30,7 +30,7 @@ namespace PrecastConcretePlantListImplement.Models return new Shop() { Id = model.Id, - ShopName = model.ShopName, + Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, ShopReinforcedies = new() @@ -42,7 +42,7 @@ namespace PrecastConcretePlantListImplement.Models { return; } - ShopName = model.ShopName; + Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; ShopReinforcedies = model.ShopReinforcedies; @@ -50,7 +50,7 @@ namespace PrecastConcretePlantListImplement.Models public ShopViewModel GetViewModel => new() { Id = Id, - ShopName = ShopName, + Name = Name, Address = Address, ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening, From 85cf33de529ec2f7ff2dbedcae354ba503e45bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 9 Apr 2023 19:30:00 +0400 Subject: [PATCH 13/18] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=BB=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B,=20=D0=B0?= =?UTF-8?q?=20=D1=82=D0=BE=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D0=BE=20:(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormSellReinforced.Designer.cs | 50 +++++++++++-------- .../FormSellReinforced.cs | 37 +++++++------- .../Implements/ShopStorage.cs | 6 +-- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs index f09082b..4326b57 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs @@ -31,49 +31,45 @@ this.ReinforcedLabel = new System.Windows.Forms.Label(); this.QuantityLabel = new System.Windows.Forms.Label(); this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox(); - this.QuantityTextBox = new System.Windows.Forms.TextBox(); this.SaveButton = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); this.SuspendLayout(); // // ReinforcedLabel // this.ReinforcedLabel.AutoSize = true; - this.ReinforcedLabel.Location = new System.Drawing.Point(12, 18); + this.ReinforcedLabel.Location = new System.Drawing.Point(14, 24); this.ReinforcedLabel.Name = "ReinforcedLabel"; - this.ReinforcedLabel.Size = new System.Drawing.Size(56, 15); + this.ReinforcedLabel.Size = new System.Drawing.Size(71, 20); this.ReinforcedLabel.TabIndex = 0; this.ReinforcedLabel.Text = "Изделие:"; // // QuantityLabel // this.QuantityLabel.AutoSize = true; - this.QuantityLabel.Location = new System.Drawing.Point(12, 51); + this.QuantityLabel.Location = new System.Drawing.Point(14, 68); this.QuantityLabel.Name = "QuantityLabel"; - this.QuantityLabel.Size = new System.Drawing.Size(75, 15); + this.QuantityLabel.Size = new System.Drawing.Size(93, 20); this.QuantityLabel.TabIndex = 1; this.QuantityLabel.Text = "Количество:"; // // ReindorcedСomboBox // this.ReindorcedСomboBox.FormattingEnabled = true; - this.ReindorcedСomboBox.Location = new System.Drawing.Point(88, 15); + this.ReindorcedСomboBox.Location = new System.Drawing.Point(101, 20); + this.ReindorcedСomboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ReindorcedСomboBox.Name = "ReindorcedСomboBox"; - this.ReindorcedСomboBox.Size = new System.Drawing.Size(184, 23); + this.ReindorcedСomboBox.Size = new System.Drawing.Size(210, 28); this.ReindorcedСomboBox.TabIndex = 2; // - // QuantityTextBox - // - this.QuantityTextBox.Location = new System.Drawing.Point(88, 48); - this.QuantityTextBox.Name = "QuantityTextBox"; - this.QuantityTextBox.Size = new System.Drawing.Size(184, 23); - this.QuantityTextBox.TabIndex = 3; - // // SaveButton // - this.SaveButton.Location = new System.Drawing.Point(72, 100); + this.SaveButton.Location = new System.Drawing.Point(82, 133); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.SaveButton.Name = "SaveButton"; - this.SaveButton.Size = new System.Drawing.Size(97, 29); + this.SaveButton.Size = new System.Drawing.Size(111, 39); this.SaveButton.TabIndex = 4; this.SaveButton.Text = "Сохранить"; this.SaveButton.UseVisualStyleBackColor = true; @@ -81,27 +77,37 @@ // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(175, 100); + this.ButtonCancel.Location = new System.Drawing.Point(200, 133); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(97, 29); + this.ButtonCancel.Size = new System.Drawing.Size(111, 39); this.ButtonCancel.TabIndex = 5; this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(113, 68); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(198, 27); + this.numericUpDownCount.TabIndex = 7; + // // FormSellReinforced // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 141); + this.ClientSize = new System.Drawing.Size(325, 188); + this.Controls.Add(this.numericUpDownCount); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.SaveButton); - this.Controls.Add(this.QuantityTextBox); this.Controls.Add(this.ReindorcedСomboBox); this.Controls.Add(this.QuantityLabel); this.Controls.Add(this.ReinforcedLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormSellReinforced"; this.Text = "Продать Изделие"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -112,8 +118,8 @@ private Label ReinforcedLabel; private Label QuantityLabel; private ComboBox ReindorcedСomboBox; - private TextBox QuantityTextBox; private Button SaveButton; private Button ButtonCancel; + private NumericUpDown numericUpDownCount; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs index 4188396..f814ce2 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.SearchModels; @@ -47,40 +48,42 @@ namespace PrecastConcretePlantView private void SaveButton_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(QuantityTextBox.Text)) - { - MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (ReindorcedСomboBox.SelectedValue == null) { MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - - _logger.LogInformation("Product sale."); - + if (string.IsNullOrEmpty(numericUpDownCount.Text)) + { + MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа изделий"); try { - var operationResult = _logicShop.SellReinforced(_logicReinforced.ReadElement(new ReinforcedSearchModel() + var reinforced = _logicReinforced.ReadElement(new() { - Id = Convert.ToInt32(ReindorcedСomboBox.SelectedValue) - })!, Convert.ToInt32(QuantityTextBox.Text)); - + Id = (int)ReindorcedСomboBox.SelectedValue + }); + if (reinforced == null) + { + throw new Exception("Изделие не найдено. Дополнительная информация в логах."); + } + var operationResult = _logicShop.SellReinforced( + reinforced: reinforced, + quantity: (int)numericUpDownCount.Value + ); if (!operationResult) { - throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах."); + throw new Exception("Ошибка при продаже изделий. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; - Close(); } catch (Exception ex) { - _logger.LogError(ex, "Product sale error."); + _logger.LogError(ex, "Ошибка сохранения поездки"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs index 184e57a..b694e88 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs @@ -108,7 +108,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return null; } - public bool SellReinforcedies(IReinforcedModel model, int count) + public bool SellReinforced(IReinforcedModel model, int count) { using var context = new PrecastConcretePlantDataBase(); using var transaction = context.Database.BeginTransaction(); @@ -152,9 +152,5 @@ namespace PrecastConcretePlantDatabaseImplement.Implements } } - public bool SellReinforced(IReinforcedModel model, int quantity) - { - throw new NotImplementedException(); - } } } From e052065c9ba53c05d7b1064651a873176defb18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 9 Apr 2023 23:56:42 +0400 Subject: [PATCH 14/18] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ecastConcretePlantDataBaseModelSnapshot.cs | 249 ------------------ 1 file changed, 249 deletions(-) delete mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs deleted file mode 100644 index 1f2e84a..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs +++ /dev/null @@ -1,249 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PrecastConcretePlantDatabaseImplement; - -#nullable disable - -namespace PrecastConcretePlantDatabaseImplement.Migrations -{ - [DbContext(typeof(PrecastConcretePlantDataBase))] - partial class PrecastConcretePlantDataBaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Reinforcedies"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("DateOpening") - .HasColumnType("datetime2"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ReinforcedMaxCount") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Shops"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.Property("ShopId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ReinforcedId"); - - b.HasIndex("ShopId"); - - b.ToTable("ShopReinforcedies"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Orders") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") - .WithMany("ReinforcedComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Components") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany() - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Shop", "Shop") - .WithMany("Reinforcedies") - .HasForeignKey("ShopId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Reinforced"); - - b.Navigation("Shop"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Navigation("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => - { - b.Navigation("Reinforcedies"); - }); -#pragma warning restore 612, 618 - } - } -} From 478eb1d5dab93fc7d05b05bdaa720dbf6885d7d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Mon, 10 Apr 2023 00:13:32 +0400 Subject: [PATCH 15/18] Fix from --- .../PrecastConcretePlant/FormMain.Designer.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index 5f4a91f..8fdf192 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -58,7 +58,7 @@ this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); - this.MenuStrip.Size = new System.Drawing.Size(1191, 30); + this.MenuStrip.Size = new System.Drawing.Size(1209, 30); this.MenuStrip.TabIndex = 0; this.MenuStrip.Text = "menuStrip1"; // @@ -75,19 +75,22 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26); - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); 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(182, 26); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -209,7 +212,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1042, 450); + this.ClientSize = new System.Drawing.Size(1209, 450); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.OrderReadyButton); @@ -236,11 +239,18 @@ private ToolStripMenuItem СправочникиToolStripMenuItem; private ToolStripMenuItem ИзделияToolStripMenuItem; private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem списокДокументовToolStripMenuItem; + private ToolStripMenuItem компонентыПоДокументамToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; private DataGridView DataGridView; private Button CreateOrderButton; private Button TakeOrderInWorkButton; private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; + public Button ButtonAddReinforcedInShop; + public Button SellReinforcedButton; } } \ No newline at end of file From 450a1d6313a6954f866d24137a2f2a4e66bd93e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 11 Apr 2023 00:09:25 +0400 Subject: [PATCH 16/18] LabWork04_hard :< --- .../PrecastConcretePlant/FormMain.Designer.cs | 72 +++++++-- .../PrecastConcretePlant/FormMain.cs | 73 ++++++--- .../FormReportGroupOrders.Designer.cs | 141 ++++++++++++++++++ .../FormReportGroupOrders.cs | 91 +++++++++++ .../FormReportGroupOrders.resx | 120 +++++++++++++++ .../FormReportShopReinforcedies.Designer.cs | 113 ++++++++++++++ .../FormReportShopReinforcedies.cs | 80 ++++++++++ .../FormReportShopReinforcedies.resx | 60 ++++++++ .../PrecastConcretePlant/Program.cs | 13 +- .../BusinessLogic/ReportLogic.cs | 84 ++++++++++- .../OfficePackage/AbstractSaveToExcel.cs | 121 ++++++++++++++- .../OfficePackage/AbstractSaveToPdf.cs | 56 +++++-- .../OfficePackage/AbstractSaveToWord.cs | 56 ++++++- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../HelperModels/ExcelInfoReinforced.cs | 20 +++ .../OfficePackage/HelperModels/PdfInfo.cs | 2 +- .../HelperModels/PdfInfoOrders.cs | 29 ++++ .../OfficePackage/HelperModels/WordInfo.cs | 3 +- .../HelperModels/WordInfoTable.cs | 16 ++ .../OfficePackage/Implements/SaveToWord.cs | 106 +++++++++---- .../BusinessLogicsContracts/IReportLogic.cs | 5 + .../ViewModels/ReportGroupOrdersViewModel.cs | 16 ++ ... => ReportReinforcedComponentViewModel.cs} | 0 .../ReportShopReinforcedViewModel.cs | 16 ++ 24 files changed, 1207 insertions(+), 88 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs rename PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/{ReportComponentBlankViewModel.cs => ReportReinforcedComponentViewModel.cs} (100%) create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index 8fdf192..ce4055a 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -37,14 +37,18 @@ 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.магазиныСИзделиями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.ButtonAddReinforcedInShop = new System.Windows.Forms.Button(); this.SellReinforcedButton = new System.Windows.Forms.Button(); + this.buttonSellReinforced = new System.Windows.Forms.Button(); + this.buttonAddReinforcedInShop = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -90,13 +94,18 @@ // this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокДокументовToolStripMenuItem, this.компонентыПоДокументамToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); + this.списокЗаказовToolStripMenuItem, + this.списокМагазиновToolStripMenuItem, + this.магазиныСИзделиямиToolStripMenuItem, + this.списокГруппЗаказовToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -122,6 +131,27 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(292, 26); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + // + // магазиныСИзделиямиToolStripMenuItem + // + this.магазиныСИзделиямиToolStripMenuItem.Name = "магазиныСИзделиямиToolStripMenuItem"; + this.магазиныСИзделиямиToolStripMenuItem.Size = new System.Drawing.Size(292, 26); + this.магазиныСИзделиямиToolStripMenuItem.Text = "Магазины с изделиями"; + this.магазиныСИзделиямиToolStripMenuItem.Click += new System.EventHandler(this.магазиныСИзделиямиToolStripMenuItem_Click); + // + // списокГруппЗаказовToolStripMenuItem + // + this.списокГруппЗаказовToolStripMenuItem.Name = "списокГруппЗаказовToolStripMenuItem"; + this.списокГруппЗаказовToolStripMenuItem.Size = new System.Drawing.Size(292, 26); + this.списокГруппЗаказовToolStripMenuItem.Text = "Список групп заказов"; + this.списокГруппЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокГруппЗаказовToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -188,16 +218,6 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // ButtonAddReinforcedInShop - // - this.ButtonAddReinforcedInShop.Location = new System.Drawing.Point(905, 228); - this.ButtonAddReinforcedInShop.Name = "ButtonAddReinforcedInShop"; - this.ButtonAddReinforcedInShop.Size = new System.Drawing.Size(125, 42); - this.ButtonAddReinforcedInShop.TabIndex = 7; - this.ButtonAddReinforcedInShop.Text = "Пополнение магазина"; - this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true; - this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click); - // // SellReinforcedButton // this.SellReinforcedButton.Location = new System.Drawing.Point(905, 276); @@ -208,11 +228,33 @@ this.SellReinforcedButton.UseVisualStyleBackColor = true; this.SellReinforcedButton.Click += new System.EventHandler(this.SellReinforcedButton_Click); // + // buttonSellReinforced + // + this.buttonSellReinforced.Location = new System.Drawing.Point(1034, 303); + this.buttonSellReinforced.Name = "buttonSellReinforced"; + this.buttonSellReinforced.Size = new System.Drawing.Size(143, 45); + this.buttonSellReinforced.TabIndex = 7; + this.buttonSellReinforced.Text = "Продать изделие"; + this.buttonSellReinforced.UseVisualStyleBackColor = true; + this.buttonSellReinforced.Click += new System.EventHandler(this.buttonSellReinforced_Click); + // + // buttonAddReinforcedInShop + // + this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(1034, 354); + this.buttonAddReinforcedInShop.Name = "buttonAddReinforcedInShop"; + this.buttonAddReinforcedInShop.Size = new System.Drawing.Size(143, 55); + this.buttonAddReinforcedInShop.TabIndex = 8; + this.buttonAddReinforcedInShop.Text = "Пополнение магазина"; + this.buttonAddReinforcedInShop.UseVisualStyleBackColor = true; + this.buttonAddReinforcedInShop.Click += new System.EventHandler(this.buttonAddReinforcedInShop_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1209, 450); + this.Controls.Add(this.buttonAddReinforcedInShop); + this.Controls.Add(this.buttonSellReinforced); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.OrderReadyButton); @@ -250,7 +292,11 @@ private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; - public Button ButtonAddReinforcedInShop; public Button SellReinforcedButton; + private Button buttonSellReinforced; + private Button buttonAddReinforcedInShop; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem магазиныСИзделиямиToolStripMenuItem; + private ToolStripMenuItem списокГруппЗаказовToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index f4e4232..53ba19f 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -1,5 +1,6 @@  using Microsoft.Extensions.Logging; +using PrecastConcretePlant; using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; @@ -201,23 +202,6 @@ namespace PrecastConcretePlantView LoadData(); } - private void ButtonAddReinforcedInShop_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedShop)); - if (service is FormReinforcedShop form) - { - form.ShowDialog(); - } - } - - private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } private void SellReinforcedButton_Click(object sender, EventArgs e) { @@ -259,5 +243,60 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + + private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsTableToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void магазиныСИзделиямиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopReinforcedies)); + if (service is FormReportShopReinforcedies form) + { + form.ShowDialog(); + } + } + + private void списокГруппЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupOrders)); + if (service is FormReportGroupOrders form) + { + form.ShowDialog(); + } + } + + private void buttonSellReinforced_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced)); + if (service is FormSellReinforced form) + { + form.ShowDialog(); + } + } + + private void buttonAddReinforcedInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedShop)); + if (service is FormReinforcedShop form) + { + form.ShowDialog(); + } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs new file mode 100644 index 0000000..e6e53d4 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs @@ -0,0 +1,141 @@ +namespace PrecastConcretePlant +{ + partial class FormReportGroupOrders + { + /// + /// 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.panel = new System.Windows.Forms.Panel(); + this.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.labelFrom = new System.Windows.Forms.Label(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(1031, 40); + this.panel.TabIndex = 0; + // + // buttonToPdf + // + this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonToPdf.Location = new System.Drawing.Point(878, 8); + this.buttonToPdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(139, 27); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "В Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(476, 8); + this.buttonMake.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(139, 27); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(237, 7); + this.dateTimePickerTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(208, 10); + this.labelTo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(21, 15); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(37, 7); + this.dateTimePickerFrom.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(14, 10); + this.labelFrom.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(15, 15); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "С"; + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1031, 647); + this.Controls.Add(this.panel); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Name = "FormReportOrders"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel; + private System.Windows.Forms.Button buttonToPdf; + private System.Windows.Forms.Button buttonMake; + private System.Windows.Forms.DateTimePicker dateTimePickerTo; + private System.Windows.Forms.Label labelTo; + private System.Windows.Forms.DateTimePicker dateTimePickerFrom; + private System.Windows.Forms.Label labelFrom; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs new file mode 100644 index 0000000..b79c648 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs @@ -0,0 +1,91 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace PrecastConcretePlant +{ + public partial class FormReportGroupOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportGroupOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetGroupOrders(new ReportBindingModel + { + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", + $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.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/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs new file mode 100644 index 0000000..5d38bfe --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs @@ -0,0 +1,113 @@ +namespace PrecastConcretePlant +{ + partial class FormReportShopReinforcedies + { + /// + /// 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(); + buttonSaveToExcel = new Button(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnPastry = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnPastry, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 47); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.Size = new Size(616, 510); + dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(14, 14); + buttonSaveToExcel.Margin = new Padding(4, 3, 4, 3); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(186, 27); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // ColumnShop + // + ColumnShop.HeaderText = "Магазин"; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + ColumnShop.Width = 200; + // + // ColumnPastry + // + ColumnPastry.HeaderText = "Изделие"; + ColumnPastry.Name = "ColumnPastry"; + ColumnPastry.ReadOnly = true; + ColumnPastry.Width = 200; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShopPastries + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(616, 557); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormReportShopPastries"; + Text = "Изделия с компонентами"; + Load += FormReportShopReinforcedies_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnPastry; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs new file mode 100644 index 0000000..07645a0 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs @@ -0,0 +1,80 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlant +{ + public partial class FormReportShopReinforcedies : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportShopReinforcedies(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShopReinforcedies_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopReinforcedies(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Reinforcedies) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(new object[] { "Загруженность", "", Math.Round(elem.Workload * 100, 2).ToString() + "%" }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка изделий по компонентам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopReinforcedToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка изделий по компонентам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.resx b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.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/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 0f9f86e..7f1461d 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -8,6 +8,7 @@ using PrecastConcretePlantBusinessLogic.PrecastConcretePlantBusinessLogic.Busine using PrecastConcretePlantDatabaseImplement.Implements; using PrecastConcretePlantBusinessLogic.OfficePackage.Implements; using PrecastConcretePlantBusinessLogic.OfficePackage; +using PrecastConcretePlant; namespace PrecastConcretePlantView { @@ -41,10 +42,12 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -52,6 +55,14 @@ namespace PrecastConcretePlantView 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/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs index 657a345..2b3d274 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs @@ -17,16 +17,18 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { private readonly IComponentStorage _componentStorage; private readonly IReinforcedStorage _reinforcedStorage; + private readonly IShopStorage _shopStorage; private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _reinforcedStorage = reinforcedStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; + _shopStorage = shopStorage; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } @@ -81,12 +83,12 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { FileName = model.FileName, Title = "Список документов", - Reinforceds = _reinforcedStorage.GetFullList() + Reinforcedies = _reinforcedStorage.GetFullList() }); } public void SaveReinforcedComponentToExcelFile(ReportBindingModel model) { - _saveToExcel.CreateReport(new ExcelInfo + _saveToExcel.CreateReportReinforced(new ExcelInfoReinforced { FileName = model.FileName, Title = "Список документов", @@ -96,7 +98,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public void SaveOrdersToPdfFile(ReportBindingModel model) { - _saveToPdf.CreateDoc(new PdfInfo + _saveToPdf.CreateDocOrders(new PdfInfoOrders { FileName = model.FileName, Title = "Список заказов", @@ -106,5 +108,79 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic }); } + public List GetShopReinforcedies() + { + var shops = _shopStorage.GetFullList(); + + var reinforcedies = _reinforcedStorage.GetFullList(); + + var list = new List(); + + foreach (var shop in shops) + { + var record = new ReportShopReinforcedViewModel + { + ShopName = shop.Name, + Reinforcedies = new List>(), + TotalCount = 0 + }; + foreach (var reinforced in reinforcedies) + { + if (shop.ShopReinforcedies.ContainsKey(reinforced.Id)) + { + record.Reinforcedies.Add(new(reinforced.ReinforcedName, shop.ShopReinforcedies[reinforced.Id].Item2)); + record.TotalCount += shop.ShopReinforcedies[reinforced.Id].Item2; + } + } + record.Workload = record.TotalCount / (double)shop.ReinforcedMaxCount; + list.Add(record); + } + + return list; + } + public List GetGroupOrders(ReportBindingModel model) + { + return _orderStorage.GetFullList() + .GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportGroupOrdersViewModel + { + Date = x.Key, + Count = x.Count(), + Sum = x.Sum(y => y.Sum) + }).ToList(); + } + + + public void SaveShopsTableToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDocTable(new WordInfoTable + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveGroupOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список сгруппированных заказов по датам", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetGroupOrders(model) + }); + } + + public void SaveShopReinforcedToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReportShop(new ExcelInfo + { + FileName = model.FileName, + Title = "Список магазинов", + ShopReinforcedies = GetShopReinforcedies() + }); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index c6bdec8..1ab43bb 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -10,9 +10,10 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcel { - public void CreateReport(ExcelInfo info) + public void CreateReportShop(ExcelInfo info) { CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -20,11 +21,99 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage Text = info.Title, StyleInfo = ExcelStyleInfoType.Title }); + MergeCells(new ExcelMergeParameters { CellFromName = "A1", CellToName = "C1" }); + + uint rowIndex = 2; + foreach (var pc in info.ShopReinforcedies) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Shop, Count) in pc.Reinforcedies) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Shop, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Загруженность", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Workload.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + public void CreateReportReinforced(ExcelInfoReinforced info) + { + CreateExcel(new() { FileName = info.FileName }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; foreach (var pc in info.ReinforcedComponents) { @@ -36,15 +125,17 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var (Component, Count) in pc.Components) + + foreach (var (Reinforced, Count) in pc.Components) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = Component, + Text = Reinforced, StyleInfo = ExcelStyleInfoType.TextWithBorder }); + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", @@ -52,8 +143,10 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage Text = Count.ToString(), StyleInfo = ExcelStyleInfoType.TextWithBorder }); + rowIndex++; } + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -70,12 +163,32 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage }); rowIndex++; } - SaveExcel(info); + + SaveExcel(new()); } + /// + /// Создание excel-файла + /// + /// protected abstract void CreateExcel(ExcelInfo info); + + /// + /// Добавляем новую ячейку в лист + /// + /// protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + /// + /// Объединение ячеек + /// + /// protected abstract void MergeCells(ExcelMergeParameters excelParams); + + /// + /// Сохранение файла + /// + /// protected abstract void SaveExcel(ExcelInfo info); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 018b5f8..f94023c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -13,47 +13,79 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage public void CreateDoc(PdfInfo info) { CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { - Text = info.Title, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); - CreateParagraph(new PdfParagraph - { - Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "4cm" }); + + CreateTable(new List { "3cm", "4cm", "5cm" }); + CreateRow(new PdfRowParameters { - Texts = new List { "Номер", "Дата заказа", "Изделие", "Сумма", "Статус" }, + Texts = new List { "Дата", "Количество", "Сумма" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + foreach (var order in info.Orders) { CreateRow(new PdfRowParameters { - Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ReinforcedName, order.Sum.ToString(), order.Status }, + Texts = new List { order.Date.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + + public void CreateDocOrders(PdfInfoOrders info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { - Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", + Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Right + ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "2cm", "3cm", "6cm", "4cm", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата заказа", "Изделие", "Статус заказа", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ReinforcedName, Convert.ToString(order.Status), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + SavePdf(info); } protected abstract void CreatePdf(PdfInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfInfo info); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 033f1b0..6446c33 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -10,9 +10,10 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { - public void CreateDoc(WordInfo info) + public void CreateDocTable(WordInfoTable info) { CreateWord(info); + CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, @@ -22,14 +23,48 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage JustificationType = WordJustificationType.Center } }); - foreach (var reinforced in info.Reinforceds) + + CreateTable(new() + { + ("Название", 3000), + ("Дата", null), + ("Адрес открытия", 4500), + }, + info.Shops + .Select(x => new List + { + x.Name, + Convert.ToString(x.DateOpening), + x.Address, + }) + .ToList()); + + SaveWord(info); + } + + public void CreateDoc(WordInfo info) + { + CreateWord(new() { FileName = info.FileName }); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + foreach (var reinforced in info.Reinforcedies) { CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> - {(reinforced.ReinforcedName + " - ", new WordTextProperties { Size = "24", Bold = true}), - (reinforced.Price.ToString(), new WordTextProperties { Size = "24", })}, - + { + (reinforced.ReinforcedName , new WordTextProperties { Size = "24", Bold = true}), + (" - цена: " + reinforced.Price.ToString(), new WordTextProperties { Size = "24" }) + }, TextProperties = new WordTextProperties { Size = "24", @@ -37,10 +72,15 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage } }); } - SaveWord(info); + + SaveWord(new()); } - protected abstract void CreateWord(WordInfo info); + + protected abstract void CreateWord(WordInfoTable info); + protected abstract void CreateParagraph(WordParagraph paragraph); - protected abstract void SaveWord(WordInfo info); + + protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows); + protected abstract void SaveWord(WordInfoTable info); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 47e064f..ae8bda4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -11,6 +11,6 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List ReinforcedComponents { get; set; } = new(); + public List ShopReinforcedies { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs new file mode 100644 index 0000000..9d196e8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs @@ -0,0 +1,20 @@ +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoReinforced + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ReinforcedComponents + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index a67ae02..a565372 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -13,6 +13,6 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List Orders { get; set; } = new(); + public List Orders { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs new file mode 100644 index 0000000..8bf0344 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs @@ -0,0 +1,29 @@ +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfoOrders + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Orders { get; set; } = new(); + + public static implicit operator PdfInfo(PdfInfoOrders orders) + { + return new PdfInfo() + { + DateFrom = orders.DateFrom, + DateTo = orders.DateTo, + FileName = orders.FileName, + Title = orders.Title + }; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 48a059e..1fd6ab5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List Reinforceds { get; set; } = new(); + public List Reinforcedies { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs new file mode 100644 index 0000000..e5820b7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs @@ -0,0 +1,16 @@ +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoTable + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs index b6d7c6f..cfc86e3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -3,26 +3,22 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using PrecastConcretePlantBusinessLogic.OfficePackage.HelperEnums; using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection.Metadata; -using System.Text; -using System.Threading.Tasks; -using static System.Net.Mime.MediaTypeNames; -using Document = DocumentFormat.OpenXml.Wordprocessing.Document; -using Text = DocumentFormat.OpenXml.Wordprocessing.Text; + namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements { public class SaveToWord : AbstractSaveToWord { private WordprocessingDocument? _wordDocument; + private Body? _docBody; - - private static JustificationValues - GetJustificationValues(WordJustificationType type) + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) { return type switch { @@ -32,54 +28,68 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements }; } + /// + /// Настройки страницы + /// + /// private static SectionProperties CreateSectionProperties() { var properties = new SectionProperties(); + var pageSize = new PageSize { Orient = PageOrientationValues.Portrait }; + properties.AppendChild(pageSize); + return properties; } - private static ParagraphProperties? - CreateParagraphProperties(WordTextProperties? paragraphProperties) + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) { if (paragraphProperties == null) { return null; } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() { Val = GetJustificationValues(paragraphProperties.JustificationType) }); + properties.AppendChild(new SpacingBetweenLines { LineRule = LineSpacingRuleValues.Auto }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); if (!string.IsNullOrEmpty(paragraphProperties.Size)) { - paragraphMarkRunProperties.AppendChild(new FontSize - { - Val = - paragraphProperties.Size - }); + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); } properties.AppendChild(paragraphMarkRunProperties); + return properties; } - protected override void CreateWord(WordInfo info) + protected override void CreateWord(WordInfoTable info) { _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); _docBody = mainPart.Document.AppendChild(new Body()); } + protected override void CreateParagraph(WordParagraph paragraph) { if (_docBody == null || paragraph == null) @@ -89,9 +99,11 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements var docParagraph = new Paragraph(); docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) { var docRun = new Run(); + var properties = new RunProperties(); properties.AppendChild(new FontSize { Val = run.Item2.Size }); if (run.Item2.Bold) @@ -99,24 +111,66 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements properties.AppendChild(new Bold()); } docRun.AppendChild(properties); - docRun.AppendChild(new Text - { - Text = run.Item1, - Space = SpaceProcessingModeValues.Preserve - }); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + docParagraph.AppendChild(docRun); } + _docBody.AppendChild(docParagraph); } - protected override void SaveWord(WordInfo info) + + protected override void SaveWord(WordInfoTable info) { if (_docBody == null || _wordDocument == null) { return; } _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Close(); } + + private static TableCell GetTableCell(string text, int? widthCell = null) + { + + TableCell cell = new(new Paragraph(new Run(new Text(text)))); + if (widthCell != null) + { + cell.Append(new TableCellProperties() + { + TableCellWidth = new() { Width = widthCell.ToString() } + }); + } + return cell; + } + + protected override void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows) + { + if (_docBody == null) + { + return; + } + Table table = new(); + TableProperties tblProp = new TableProperties( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 } + ) + ); + table.AppendChild(tblProp); + + table.Append(new TableRow(nameAndWidthColumns.Select(x => GetTableCell(x.Item1, x.Item2)))); + + table.Append(rows.Select(x => new TableRow(x.Select(y => GetTableCell(y))))); + + _docBody.Append(table); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs index 176f587..9eed1b0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs @@ -10,10 +10,15 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts { public interface IReportLogic { + List GetShopReinforcedies(); List GetReinforcedComponents(); List GetOrders(ReportBindingModel model); + List GetGroupOrders(ReportBindingModel model); void SaveReinforcedsToWordFile(ReportBindingModel model); void SaveReinforcedComponentToExcelFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsTableToWordFile(ReportBindingModel model); + void SaveShopReinforcedToExcelFile(ReportBindingModel model); + void SaveGroupOrdersToPdfFile(ReportBindingModel model); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs new file mode 100644 index 0000000..3389be6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportGroupOrdersViewModel + { + public int Id { get; set; } + public DateTime Date { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportComponentBlankViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportReinforcedComponentViewModel.cs similarity index 100% rename from PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportComponentBlankViewModel.cs rename to PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportReinforcedComponentViewModel.cs diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs new file mode 100644 index 0000000..e1e3e8e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportShopReinforcedViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List> Reinforcedies { get; set; } = new(); + public double Workload { get; set; } + } +} From fbb8838012d47feff754d5f8a876ac3e218532bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 13 Apr 2023 10:43:20 +0400 Subject: [PATCH 17/18] =?UTF-8?q?fix=20pdf=20=D0=B8=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormReportGroupOrders.Designer.cs | 75 +-- .../FormReportGroupOrders.cs | 30 +- .../FormReportGroupOrders.resx | 62 +-- .../ReportGroupOrders.rdlc | 463 ++++++++++++++++++ .../BusinessLogic/ReportLogic.cs | 16 +- .../OfficePackage/AbstractSaveToPdf.cs | 90 ++-- .../OfficePackage/HelperModels/PdfInfo.cs | 4 +- .../HelperModels/PdfInfoOrders.cs | 1 + .../OfficePackage/Implements/SaveToPdf.cs | 22 +- .../BusinessLogicsContracts/IReportLogic.cs | 2 +- .../ViewModels/ReportGroupOrdersViewModel.cs | 1 - 11 files changed, 569 insertions(+), 197 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/ReportGroupOrders.rdlc diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs index e6e53d4..87b354b 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs @@ -31,10 +31,6 @@ this.panel = new System.Windows.Forms.Panel(); this.buttonToPdf = new System.Windows.Forms.Button(); this.buttonMake = new System.Windows.Forms.Button(); - this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); - this.labelTo = new System.Windows.Forms.Label(); - this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); - this.labelFrom = new System.Windows.Forms.Label(); this.panel.SuspendLayout(); this.SuspendLayout(); // @@ -42,24 +38,20 @@ // this.panel.Controls.Add(this.buttonToPdf); this.panel.Controls.Add(this.buttonMake); - this.panel.Controls.Add(this.dateTimePickerTo); - this.panel.Controls.Add(this.labelTo); - this.panel.Controls.Add(this.dateTimePickerFrom); - this.panel.Controls.Add(this.labelFrom); this.panel.Dock = System.Windows.Forms.DockStyle.Top; this.panel.Location = new System.Drawing.Point(0, 0); - this.panel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); this.panel.Name = "panel"; - this.panel.Size = new System.Drawing.Size(1031, 40); + this.panel.Size = new System.Drawing.Size(1178, 53); this.panel.TabIndex = 0; // // buttonToPdf // this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonToPdf.Location = new System.Drawing.Point(878, 8); - this.buttonToPdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonToPdf.Location = new System.Drawing.Point(1003, 11); + this.buttonToPdf.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); this.buttonToPdf.Name = "buttonToPdf"; - this.buttonToPdf.Size = new System.Drawing.Size(139, 27); + this.buttonToPdf.Size = new System.Drawing.Size(159, 36); this.buttonToPdf.TabIndex = 5; this.buttonToPdf.Text = "В Pdf"; this.buttonToPdf.UseVisualStyleBackColor = true; @@ -67,63 +59,26 @@ // // buttonMake // - this.buttonMake.Location = new System.Drawing.Point(476, 8); - this.buttonMake.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake.Location = new System.Drawing.Point(544, 11); + this.buttonMake.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); this.buttonMake.Name = "buttonMake"; - this.buttonMake.Size = new System.Drawing.Size(139, 27); + this.buttonMake.Size = new System.Drawing.Size(159, 36); this.buttonMake.TabIndex = 4; this.buttonMake.Text = "Сформировать"; this.buttonMake.UseVisualStyleBackColor = true; this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); // - // dateTimePickerTo + // FormReportGroupOrders // - this.dateTimePickerTo.Location = new System.Drawing.Point(237, 7); - this.dateTimePickerTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.dateTimePickerTo.Name = "dateTimePickerTo"; - this.dateTimePickerTo.Size = new System.Drawing.Size(163, 23); - this.dateTimePickerTo.TabIndex = 3; - // - // labelTo - // - this.labelTo.AutoSize = true; - this.labelTo.Location = new System.Drawing.Point(208, 10); - this.labelTo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.labelTo.Name = "labelTo"; - this.labelTo.Size = new System.Drawing.Size(21, 15); - this.labelTo.TabIndex = 2; - this.labelTo.Text = "по"; - // - // dateTimePickerFrom - // - this.dateTimePickerFrom.Location = new System.Drawing.Point(37, 7); - this.dateTimePickerFrom.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.dateTimePickerFrom.Name = "dateTimePickerFrom"; - this.dateTimePickerFrom.Size = new System.Drawing.Size(163, 23); - this.dateTimePickerFrom.TabIndex = 1; - // - // labelFrom - // - this.labelFrom.AutoSize = true; - this.labelFrom.Location = new System.Drawing.Point(14, 10); - this.labelFrom.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.labelFrom.Name = "labelFrom"; - this.labelFrom.Size = new System.Drawing.Size(15, 15); - this.labelFrom.TabIndex = 0; - this.labelFrom.Text = "С"; - // - // FormReportOrders - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1031, 647); + this.ClientSize = new System.Drawing.Size(1178, 863); this.Controls.Add(this.panel); - this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.Name = "FormReportOrders"; + this.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.Name = "FormReportGroupOrders"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Заказы"; this.panel.ResumeLayout(false); - this.panel.PerformLayout(); this.ResumeLayout(false); } @@ -133,9 +88,5 @@ private System.Windows.Forms.Panel panel; private System.Windows.Forms.Button buttonToPdf; private System.Windows.Forms.Button buttonMake; - private System.Windows.Forms.DateTimePicker dateTimePickerTo; - private System.Windows.Forms.Label labelTo; - private System.Windows.Forms.DateTimePicker dateTimePickerFrom; - private System.Windows.Forms.Label labelFrom; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs index b79c648..69c2bac 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs @@ -30,27 +30,14 @@ namespace PrecastConcretePlant private void ButtonMake_Click(object sender, EventArgs e) { - if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) - { - MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } try { - var dataSource = _logic.GetGroupOrders(new ReportBindingModel - { - DateFrom = dateTimePickerFrom.Value, - DateTo = dateTimePickerTo.Value - }); + var dataSource = _logic.GetGroupOrders(); var source = new ReportDataSource("DataSetOrders", dataSource); reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Add(source); - var parameters = new[] { new ReportParameter("ReportParameterPeriod", - $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; - reportViewer.LocalReport.SetParameters(parameters); - reportViewer.RefreshReport(); - _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + _logger.LogInformation("Загрузка списка заказов на весь период по датам"); } catch (Exception ex) { @@ -61,23 +48,16 @@ namespace PrecastConcretePlant private void ButtonToPdf_Click(object sender, EventArgs e) { - if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) - { - MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; if (dialog.ShowDialog() == DialogResult.OK) { try { - _logic.SaveOrdersToPdfFile(new ReportBindingModel + _logic.SaveGroupOrdersToPdfFile(new ReportBindingModel { - FileName = dialog.FileName, - DateFrom = dateTimePickerFrom.Value, - DateTo = dateTimePickerTo.Value + FileName = dialog.FileName }); - _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + _logger.LogInformation("Сохранение списка заказов на весь период по датам"); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx index 1af7de1..f298a7b 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PrecastConcretePlant/PrecastConcretePlant/ReportGroupOrders.rdlc b/PrecastConcretePlant/PrecastConcretePlant/ReportGroupOrders.rdlc new file mode 100644 index 0000000..5977266 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/ReportGroupOrders.rdlc @@ -0,0 +1,463 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + ConfectioneryContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + Date + System.DateTime + + + Count + System.Int32 + + + Sum + System.Double + + + + ConfectioneryContracts.ViewModels + ReportOrdersViewModel + ConfectioneryContracts.ViewModels.ReportOrdersViewModel, ConfectioneryContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 1cm + 1cm + 12.40104cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Заказы + + + + + + + 1cm + 12.40104cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.21438cm + + + 3.53188cm + + + 4.35209cm + + + + + 0.6cm + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Date.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Count.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 11.09835cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 6.6508cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 9.1508cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +