From f2c84d39770f97dac735b1544ef0ef611e585974 Mon Sep 17 00:00:00 2001 From: Alenka Date: Wed, 8 May 2024 22:55:51 +0400 Subject: [PATCH 01/10] =?UTF-8?q?=D0=9D=D0=B0=D0=B4=D0=B5=D1=8E=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BD=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=BC=D0=B0=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/IStoreModel.cs | 17 ++ .../JewelryStore/FormJewels.cs | 6 +- .../JewelryStore/FormMain.Designer.cs | 28 ++- .../JewelryStore/FormMain.cs | 20 ++ .../JewelryStore/FormStore.Designer.cs | 198 ++++++++++++++++++ .../JewelryStore/FormStore.cs | 141 +++++++++++++ .../JewelryStore/FormStore.resx | 60 ++++++ .../FormStoreReplenishment.Designer.cs | 151 +++++++++++++ .../JewelryStore/FormStoreReplenishment.cs | 104 +++++++++ .../JewelryStore/FormStoreReplenishment.resx | 60 ++++++ .../JewelryStore/FormStores.Designer.cs | 122 +++++++++++ .../JewelryStore/FormStores.cs | 122 +++++++++++ .../JewelryStore/FormStores.resx | 60 ++++++ .../JewelryStore/Program.cs | 6 + .../BusinessLogics/OrderLogic.cs | 38 ++-- .../BusinessLogics/StoreLogic.cs | 183 ++++++++++++++++ .../BindingModels/StoreBindingModel.cs | 22 ++ .../BusinessLogicsContracts/IStoreLogic.cs | 22 ++ .../SearchModels/StoreSearchModel.cs | 14 ++ .../StoragesModels/IStoreStorage.cs | 21 ++ .../ViewModels/StoreViewModel.cs | 25 +++ .../DataListSingleton.cs | 2 + .../Implements/StoreStorage.cs | 123 +++++++++++ .../JewelryStoreListImplement/Models/Store.cs | 59 ++++++ 24 files changed, 1573 insertions(+), 31 deletions(-) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.resx create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.resx create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.resx create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs new file mode 100644 index 0000000..ea34e71 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IStoreModel.cs @@ -0,0 +1,17 @@ +using JewelryShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IStoreModel : IId + { + public string StoreName { get; } + public string StoreAdress { get; } + DateTime OpeningDate { get; } + Dictionary Jewels { get; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs index 1ea1cdb..c770810 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs @@ -25,7 +25,6 @@ namespace JewelryStore { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["JewelComponents"].Visible = false; dataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка изделий"); @@ -97,5 +96,10 @@ namespace JewelryStore { LoadData(); } + + private void FormJewels_Load(object sender, EventArgs e) + { + LoadData(); + } } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs index e0e7277..b594b98 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs @@ -32,12 +32,14 @@ this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -46,7 +48,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.СправочникиToolStripMenuItem}); + this.СправочникиToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1121, 33); @@ -57,7 +60,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(139, 29); this.СправочникиToolStripMenuItem.Text = "Справочники"; @@ -65,17 +69,24 @@ // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.ИзделияToolStripMenuItem.Text = "Изделия"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; @@ -137,6 +148,13 @@ this.buttonRefresh.UseVisualStyleBackColor = true; this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); // + // пополнениеМагазинаToolStripMenuItem + // + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(210, 29); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ПополнениеМагазинаToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -172,5 +190,7 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs index d35464d..5a5f7d5 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs @@ -145,5 +145,25 @@ namespace JewelryStore { LoadData(); } + + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStores)); + + if (service is FormStores form) + { + form.ShowDialog(); + } + } + + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); + + if (service is FormStoreReplenishment form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs new file mode 100644 index 0000000..e206d60 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs @@ -0,0 +1,198 @@ +namespace JewelryStore +{ + partial class FormStore + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.StoreNameLabel = new System.Windows.Forms.Label(); + this.StoreAdressLabel = new System.Windows.Forms.Label(); + this.OpeningDateLabel = new System.Windows.Forms.Label(); + this.NameTextBox = new System.Windows.Forms.TextBox(); + this.AdressTextBox = new System.Windows.Forms.TextBox(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.JewelPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.JewelCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(17, 13); + this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(179, 25); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // StoreAdressLabel + // + this.StoreAdressLabel.AutoSize = true; + this.StoreAdressLabel.Location = new System.Drawing.Point(17, 54); + this.StoreAdressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreAdressLabel.Name = "StoreAdressLabel"; + this.StoreAdressLabel.Size = new System.Drawing.Size(151, 25); + this.StoreAdressLabel.TabIndex = 1; + this.StoreAdressLabel.Text = "Адрес магазина: "; + // + // OpeningDateLabel + // + this.OpeningDateLabel.AutoSize = true; + this.OpeningDateLabel.Location = new System.Drawing.Point(17, 99); + this.OpeningDateLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.OpeningDateLabel.Name = "OpeningDateLabel"; + this.OpeningDateLabel.Size = new System.Drawing.Size(140, 25); + this.OpeningDateLabel.TabIndex = 2; + this.OpeningDateLabel.Text = "Дата открытия: "; + // + // NameTextBox + // + this.NameTextBox.Location = new System.Drawing.Point(204, 10); + this.NameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.NameTextBox.Name = "NameTextBox"; + this.NameTextBox.Size = new System.Drawing.Size(247, 31); + this.NameTextBox.TabIndex = 3; + // + // AdressTextBox + // + this.AdressTextBox.Location = new System.Drawing.Point(204, 51); + this.AdressTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AdressTextBox.Name = "AdressTextBox"; + this.AdressTextBox.Size = new System.Drawing.Size(247, 31); + this.AdressTextBox.TabIndex = 4; + // + // DataGridView + // + this.DataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.JewelName, + this.JewelPrice, + this.JewelCount}); + this.DataGridView.Location = new System.Drawing.Point(13, 135); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(802, 365); + this.DataGridView.TabIndex = 6; + // + // JewelName + // + this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.JewelName.HeaderText = "Название изделия"; + this.JewelName.MinimumWidth = 8; + this.JewelName.Name = "JewelName"; + // + // JewelPrice + // + this.JewelPrice.HeaderText = "Цена"; + this.JewelPrice.MinimumWidth = 8; + this.JewelPrice.Name = "JewelPrice"; + this.JewelPrice.Width = 150; + // + // JewelCount + // + this.JewelCount.HeaderText = "Количество"; + this.JewelCount.MinimumWidth = 8; + this.JewelCount.Name = "JewelCount"; + this.JewelCount.Width = 150; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(531, 510); + this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(138, 35); + this.SaveButton.TabIndex = 7; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(677, 510); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(138, 35); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отменить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // OpeningDatePicker + // + this.OpeningDatePicker.Location = new System.Drawing.Point(204, 94); + this.OpeningDatePicker.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.OpeningDatePicker.Name = "OpeningDatePicker"; + this.OpeningDatePicker.Size = new System.Drawing.Size(247, 31); + this.OpeningDatePicker.TabIndex = 9; + // + // FormStore + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(867, 560); + this.Controls.Add(this.OpeningDatePicker); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.DataGridView); + this.Controls.Add(this.AdressTextBox); + this.Controls.Add(this.NameTextBox); + this.Controls.Add(this.OpeningDateLabel); + this.Controls.Add(this.StoreAdressLabel); + this.Controls.Add(this.StoreNameLabel); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormStore"; + this.Text = "Изделия магазина"; + this.Load += new System.EventHandler(this.FormStore_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label StoreAdressLabel; + private Label OpeningDateLabel; + private TextBox NameTextBox; + private TextBox AdressTextBox; + private DataGridView DataGridView; + private Button SaveButton; + private Button ButtonCancel; + private DataGridViewTextBoxColumn JewelName; + private DataGridViewTextBoxColumn JewelPrice; + private DataGridViewTextBoxColumn JewelCount; + private DateTimePicker OpeningDatePicker; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs new file mode 100644 index 0000000..ed123a8 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs @@ -0,0 +1,141 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormStore : Form + { + private readonly List? _listStores; + private readonly IStoreLogic _logic; + private readonly ILogger _logger; + public int Id { get; set; } + + public FormStore(ILogger logger, IStoreLogic logic) + { + InitializeComponent(); + _logger = logger; + _listStores = logic.ReadList(null); + _logic = logic; + } + + private IStoreModel? GetStore(int id) + { + if (_listStores == null) + { + return null; + } + foreach (var elem in _listStores) + { + if (elem.Id == id) + { + return elem; + } + } + return null; + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(AdressTextBox.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение магазина"); + + try + { + DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); + StoreBindingModel model = new() + { + StoreName = NameTextBox.Text, + StoreAdress = AdressTextBox.Text, + OpeningDate = dateTime + }; + var vmodel = GetStore(Id); + bool operationResult = false; + + if (vmodel != null) + { + model.Id = vmodel.Id; + operationResult = _logic.Update(model); + } + else + { + operationResult = _logic.Create(model); + } + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormStore_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData(bool extendDate = true) + { + try + { + var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); + if (model != null) + { + NameTextBox.Text = model.StoreName; + AdressTextBox.Text = model.StoreAdress; + OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); + DataGridView.Rows.Clear(); + foreach (var el in model.Jewels.Values) + { + DataGridView.Rows.Add(new object[] { el.Item1.JewelName, el.Item1.Price, el.Item2 }); + } + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs new file mode 100644 index 0000000..b8cdadd --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.Designer.cs @@ -0,0 +1,151 @@ +namespace JewelryStore +{ + partial class FormStoreReplenishment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.StoreNameLabel = new System.Windows.Forms.Label(); + this.JewelNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.StoreNameComboBox = new System.Windows.Forms.ComboBox(); + this.JewelNameComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(9, 9); + this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(179, 25); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // JewelNameLabel + // + this.JewelNameLabel.AutoSize = true; + this.JewelNameLabel.Location = new System.Drawing.Point(9, 58); + this.JewelNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.JewelNameLabel.Name = "JewelNameLabel"; + this.JewelNameLabel.Size = new System.Drawing.Size(169, 25); + this.JewelNameLabel.TabIndex = 1; + this.JewelNameLabel.Text = "Название изделия: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(9, 107); + this.CountLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(116, 25); + this.CountLabel.TabIndex = 2; + this.CountLabel.Text = "Количество: "; + // + // StoreNameComboBox + // + this.StoreNameComboBox.FormattingEnabled = true; + this.StoreNameComboBox.Location = new System.Drawing.Point(196, 6); + this.StoreNameComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.StoreNameComboBox.Name = "StoreNameComboBox"; + this.StoreNameComboBox.Size = new System.Drawing.Size(272, 33); + this.StoreNameComboBox.TabIndex = 3; + // + // JewelNameComboBox + // + this.JewelNameComboBox.FormattingEnabled = true; + this.JewelNameComboBox.Location = new System.Drawing.Point(196, 55); + this.JewelNameComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.JewelNameComboBox.Name = "JewelNameComboBox"; + this.JewelNameComboBox.Size = new System.Drawing.Size(272, 33); + this.JewelNameComboBox.TabIndex = 4; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(196, 104); + this.CountTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(272, 31); + this.CountTextBox.TabIndex = 5; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(234, 145); + this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(107, 38); + this.SaveButton.TabIndex = 6; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(361, 145); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(107, 38); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormStoreReplenishment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(481, 200); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.JewelNameComboBox); + this.Controls.Add(this.StoreNameComboBox); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.JewelNameLabel); + this.Controls.Add(this.StoreNameLabel); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormStoreReplenishment"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label JewelNameLabel; + private Label CountLabel; + private ComboBox StoreNameComboBox; + private ComboBox JewelNameComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs new file mode 100644 index 0000000..b478d0f --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs @@ -0,0 +1,104 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormStoreReplenishment : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _storeLogic; + private readonly IJewelLogic _jewelLogic; + private readonly List? _listStores; + private readonly List? _listJewels; + public FormStoreReplenishment(ILogger logger, IStoreLogic storeLogic, IJewelLogic jewelLogic) + { + InitializeComponent(); + _storeLogic = storeLogic; + _jewelLogic = jewelLogic; + _logger = logger; + _listStores = storeLogic.ReadList(null); + if (_listStores != null) + { + StoreNameComboBox.DisplayMember = "StoreName"; + StoreNameComboBox.ValueMember = "Id"; + StoreNameComboBox.DataSource = _listStores; + StoreNameComboBox.SelectedItem = null; + } + + _listJewels = jewelLogic.ReadList(null); + if (_listJewels != null) + { + JewelNameComboBox.DisplayMember = "JewelName"; + JewelNameComboBox.ValueMember = "Id"; + JewelNameComboBox.DataSource = _listJewels; + JewelNameComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (StoreNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (JewelNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Добавление изделия в магазин"); + + try + { + var jewel = _jewelLogic.ReadElement(new() + { + Id = (int)JewelNameComboBox.SelectedValue + }); + + if (jewel == null) + { + throw new Exception("Не найдено изделие. Дополнительная информация в логах."); + } + + var resultOperation = _storeLogic.AddJewel( + model: new() { Id = (int)StoreNameComboBox.SelectedValue }, + jewel: jewel, + quantity: Convert.ToInt32(CountTextBox.Text) + ); + + if (!resultOperation) + { + throw new Exception("Ошибка при добавлении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs new file mode 100644 index 0000000..31a8bdf --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.Designer.cs @@ -0,0 +1,122 @@ +namespace JewelryStore +{ + partial class FormStores + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 2); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(768, 452); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(807, 52); + this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(151, 38); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(807, 129); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(151, 38); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(807, 203); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(151, 38); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(807, 277); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(151, 35); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormStores + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(988, 457); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormStores"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormStores_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs new file mode 100644 index 0000000..8c84e6e --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.cs @@ -0,0 +1,122 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormStores : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _logic; + public FormStores(ILogger logger, IStoreLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormStores_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Jewels"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + + try + { + if (!_logic.Delete(new StoreBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStore)); + + if (service is FormStore form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStore)); + + if (service is FormStore form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStores.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs index 30e7668..6858d64 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using JewelryStoreBusinessLogic.BusinessLogics; +using JewelryStoreContracts.StoragesModels; namespace JewelryStore { @@ -35,9 +36,11 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -45,6 +48,9 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index d283ea4..aeba2c9 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -33,43 +33,29 @@ namespace JewelryStoreBusinessLogic.BusinessLogics } public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); - } - private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) { CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (element == null) { - throw new ArgumentNullException(nameof(element)); + _logger.LogWarning("Read operation failed"); + return false; } - model.DateCreate = element.DateCreate; - model.JewelId = element.JewelId; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - if (requiredStatus - model.Status == 1) + if (element.Status != OrderStatus.Готов) { - model.Status = requiredStatus; - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); } - _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); - throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; } - - public bool FinishOrder(OrderBindingModel model) + + public bool FinishOrder(OrderBindingModel model) { CheckModel(model, false); var element = _orderStorage.GetElement(new OrderSearchModel diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs new file mode 100644 index 0000000..08101df --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs @@ -0,0 +1,183 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class StoreLogic : IStoreLogic + { + private readonly ILogger _logger; + private readonly IStoreStorage _storeStorage; + + public StoreLogic(ILogger logger, IStoreStorage storeStorage) + { + _logger = logger; + _storeStorage = storeStorage; + } + + public bool AddJewel(StoreSearchModel model, IJewelModel jewel, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddJewelInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); + var element = _storeStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddJewelInStore element not found"); + return false; + } + + _logger.LogInformation("AddJewelInStore find. Id:{Id}", element.Id); + + if (element.Jewels.TryGetValue(jewel.Id, out var pair)) + { + element.Jewels[jewel.Id] = (jewel, count + pair.Item2); + _logger.LogInformation("AddJewelInStore. Has been added {count} {jewel} in {StoreName}", count, jewel.JewelName, element.StoreName); + } + else + { + element.Jewels[jewel.Id] = (jewel, count); + _logger.LogInformation("AddJewelInStore. Has been added {count} new Jewel {jewel} in {StoreName}", count, jewel.JewelName, element.StoreName); + } + + _storeStorage.Update(new() + { + Id = element.Id, + StoreAdress = element.StoreAdress, + StoreName = element.StoreName, + OpeningDate = element.OpeningDate, + Jewels = element.Jewels + }); + return true; + } + + public bool Create(StoreBindingModel model) + { + CheckModel(model); + model.Jewels = new(); + + if (_storeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(StoreBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_storeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public StoreViewModel? ReadElement(StoreSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); + var element = _storeStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(StoreSearchModel? model) + { + _logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id); + + var list = (model == null) ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(StoreBindingModel model) + { + CheckModel(model, false); + + if (string.IsNullOrEmpty(model.StoreName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + } + + if (_storeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(StoreBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.StoreName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + } + + _logger.LogInformation("Store. StoreName:{StoreName}.StoreAdress:{StoreAdress}. Id: {Id}", model.StoreName, model.StoreAdress, model.Id); + var element = _storeStorage.GetElement(new StoreSearchModel + { + StoreName = model.StoreName + }); + + if (element != null && element.Id != model.Id && element.StoreName == model.StoreName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs new file mode 100644 index 0000000..1db1c82 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs @@ -0,0 +1,22 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class StoreBindingModel : IStoreModel + { + public string StoreName { get; set; } = string.Empty; + + public string StoreAdress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } = DateTime.Now; + + public Dictionary Jewels { get; set; } = new(); + + public int Id { get; set; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs new file mode 100644 index 0000000..d939ba2 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IStoreLogic + { + List? ReadList(StoreSearchModel? model); + StoreViewModel? ReadElement(StoreSearchModel model); + bool Create(StoreBindingModel model); + bool Update(StoreBindingModel model); + bool Delete(StoreBindingModel model); + bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs new file mode 100644 index 0000000..1ffd758 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/StoreSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class StoreSearchModel + { + public int? Id { get; set; } + public string? StoreName { get; set; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs new file mode 100644 index 0000000..46b04e8 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesModels +{ + public interface IStoreStorage + { + List GetFullList(); + List GetFilteredList(StoreSearchModel model); + StoreViewModel? GetElement(StoreSearchModel model); + StoreViewModel? Insert(StoreBindingModel model); + StoreViewModel? Update(StoreBindingModel model); + StoreViewModel? Delete(StoreBindingModel model); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs new file mode 100644 index 0000000..b04091d --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs @@ -0,0 +1,25 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class StoreViewModel : IStoreModel + { + public Dictionary Jewels { get; set; } = new(); + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string StoreName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string StoreAdress { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } = DateTime.Now; + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs index 4630a52..896f93f 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs @@ -8,12 +8,14 @@ namespace JewelryStoreListImplement public List Components { get; set; } public List Orders { get; set; } public List Jewels { get; set; } + public List Stores { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Jewels = new List(); + Stores = new List(); } public static DataListSingleton GetInstance() diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs new file mode 100644 index 0000000..754c185 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs @@ -0,0 +1,123 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class StoreStorage : IStoreStorage + { + private readonly DataListSingleton _source; + public StoreStorage() + { + _source = DataListSingleton.GetInstance(); + } + public StoreViewModel? Delete(StoreBindingModel model) + { + for (int i = 0; i < _source.Stores.Count; ++i) + { + if (_source.Stores[i].Id == model.Id) + { + var element = _source.Stores[i]; + _source.Stores.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public StoreViewModel? GetElement(StoreSearchModel model) + { + if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue) + { + return null; + } + + foreach (var store in _source.Stores) + { + if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id)) + { + return store.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(StoreSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.StoreName)) + { + return result; + } + + foreach (var store in _source.Stores) + { + if (store.StoreName.Contains(model.StoreName)) + { + result.Add(store.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var store in _source.Stores) + { + result.Add(store.GetViewModel); + } + + return result; + } + + public StoreViewModel? Insert(StoreBindingModel model) + { + model.Id = 1; + + foreach (var store in _source.Stores) + { + if (model.Id <= store.Id) + { + model.Id = store.Id + 1; + } + } + + var newStore = Store.Create(model); + + if (newStore == null) + { + return null; + } + + _source.Stores.Add(newStore); + + return newStore.GetViewModel; + } + + public StoreViewModel? Update(StoreBindingModel model) + { + foreach (var store in _source.Stores) + { + if (store.Id == model.Id) + { + store.Update(model); + return store.GetViewModel; + } + } + + return null; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs new file mode 100644 index 0000000..8515902 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs @@ -0,0 +1,59 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Store : IStoreModel + { + public string StoreName { get; private set; } = string.Empty; + public string StoreAdress { get; private set; } = string.Empty; + + public DateTime OpeningDate { get; private set; } + + public Dictionary Jewels { get; private set; } = new(); + + public int Id { get; private set; } + + public static Store? Create(StoreBindingModel? model) + { + if (model == null) + { + return null; + } + return new Store() + { + Id = model.Id, + StoreName = model.StoreName, + StoreAdress = model.StoreAdress, + OpeningDate = model.OpeningDate, + Jewels = new() + }; + } + + public void Update(StoreBindingModel? model) + { + if (model == null) + { + return; + } + StoreName = model.StoreName; + StoreAdress = model.StoreAdress; + OpeningDate = model.OpeningDate; + } + + public StoreViewModel GetViewModel => new() + { + Id = Id, + StoreName = StoreName, + StoreAdress = StoreAdress, + OpeningDate = OpeningDate, + Jewels = Jewels + }; + } +} From 978e041f429d7ecdcdfda3924eda1b3a57df641b Mon Sep 17 00:00:00 2001 From: Alenka Date: Wed, 8 May 2024 23:01:54 +0400 Subject: [PATCH 02/10] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs index c770810..1ea1cdb 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormJewels.cs @@ -25,6 +25,7 @@ namespace JewelryStore { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["JewelComponents"].Visible = false; dataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка изделий"); @@ -96,10 +97,5 @@ namespace JewelryStore { LoadData(); } - - private void FormJewels_Load(object sender, EventArgs e) - { - LoadData(); - } } } \ No newline at end of file From d4d53cbeb5bb819b67c7976f513e2469940e9799 Mon Sep 17 00:00:00 2001 From: Alenka Date: Sat, 11 May 2024 23:03:13 +0400 Subject: [PATCH 03/10] =?UTF-8?q?=D0=9D=D1=83=20=D0=BF=D0=BE=D1=87=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/ISupplyModel.cs | 15 ++ .../JewelryStore/FormCreateSupply.Designer.cs | 143 ++++++++++++ .../JewelryStore/FormCreateSupply.cs | 100 +++++++++ .../JewelryStore/FormCreateSupply.resx | 120 ++++++++++ .../JewelryStore/FormMain.Designer.cs | 7 + .../JewelryStore/FormMain.cs | 18 ++ .../JewelryStore/FormStore.Designer.cs | 6 +- .../JewelryStore/FormStore.cs | 93 ++++---- .../JewelryStore/FormStoreReplenishment.cs | 45 ++-- .../BusinessLogics/StoreLogic.cs | 209 +++++++++--------- .../BindingModels/StoreBindingModel.cs | 1 + .../BindingModels/SupplyBindingModel.cs | 16 ++ .../BusinessLogicsContracts/IStoreLogic.cs | 4 +- .../SearchModels/SupplySearchModel.cs | 14 ++ .../StoragesModels/IStoreStorage.cs | 2 + .../ViewModels/StoreViewModel.cs | 5 + .../Implements/StoreStorage.cs | 173 ++++++++------- .../JewelryStoreListImplement/Models/Store.cs | 7 +- 18 files changed, 703 insertions(+), 275 deletions(-) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.resx create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..1311fc9 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int PizzaId { get; } + int Count { get; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..bd15c13 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs @@ -0,0 +1,143 @@ +namespace JewelryStoreView +{ + partial class FormCreateSupply + { + /// + /// 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.labelShop = new System.Windows.Forms.Label(); + this.labelPizza = new System.Windows.Forms.Label(); + this.comboBoxPizza = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(115, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(344, 28); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(76, 20); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин: "; + // + // labelPizza + // + this.labelPizza.AutoSize = true; + this.labelPizza.Location = new System.Drawing.Point(12, 49); + this.labelPizza.Name = "labelPizza"; + this.labelPizza.Size = new System.Drawing.Size(75, 20); + this.labelPizza.TabIndex = 2; + this.labelPizza.Text = "Изделие: "; + // + // comboBoxPizza + // + this.comboBoxPizza.FormattingEnabled = true; + this.comboBoxPizza.Location = new System.Drawing.Point(115, 46); + this.comboBoxPizza.Name = "comboBoxPizza"; + this.comboBoxPizza.Size = new System.Drawing.Size(344, 28); + this.comboBoxPizza.TabIndex = 3; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 83); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 80); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(344, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(300, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(116, 39); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(168, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(116, 39); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(471, 164); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxPizza); + this.Controls.Add(this.labelPizza); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormCreateSupply"; + this.Text = "Создание поставки"; + this.Load += new System.EventHandler(this.FormCreateSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelPizza; + private ComboBox comboBoxPizza; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs new file mode 100644 index 0000000..09c7d69 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.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; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using JewelryStoreContracts.BindingModels; + +namespace JewelryStoreView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logicP; + private readonly IStoreLogic _logicS; + private List _shopList = new List(); + private List _pizzaList = new List(); + + public FormCreateSupply(ILogger logger, IJewelLogic logicP, IStoreLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _pizzaList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_pizzaList != null) + { + comboBoxPizza.DisplayMember = "PizzaName"; + comboBoxPizza.ValueMember = "Id"; + comboBoxPizza.DataSource = _pizzaList; + comboBoxPizza.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPizza.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs index 67568f1..471b469 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs @@ -33,6 +33,7 @@ this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -195,7 +196,13 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; + private DataGridView dataGridView; + private ToolStripMenuItem transactionToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + + + } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs index 0ca97d1..9be5887 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs @@ -1,6 +1,7 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreDataModels.Enums; +using JewelryStoreView; using Microsoft.Extensions.Logging; using System.Windows.Forms; @@ -93,6 +94,23 @@ namespace JewelryStore } } } + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStores)); + if (service is FormStores form) + { + form.ShowDialog(); + } + } + + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } private void ButtonOrderReady_Click(object sender, EventArgs e) { diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs index e206d60..9c1b44d 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.Designer.cs @@ -38,9 +38,10 @@ this.JewelPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.JewelCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.SaveButton = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); + this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpJewelMaxCount)).BeginInit(); this.SuspendLayout(); // // StoreNameLabel @@ -173,7 +174,6 @@ this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.Name = "FormStore"; this.Text = "Изделия магазина"; - this.Load += new System.EventHandler(this.FormStore_Load); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -194,5 +194,7 @@ private DataGridViewTextBoxColumn JewelPrice; private DataGridViewTextBoxColumn JewelCount; private DateTimePicker OpeningDatePicker; + private DateTimePicker dateTimeOpen; + private NumericUpDown numericUpJewelMaxCount; } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs index ed123a8..61e534a 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs @@ -1,5 +1,6 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.ViewModels; using JewelryStoreDataModels.Models; using Microsoft.Extensions.Logging; @@ -17,35 +18,51 @@ namespace JewelryStore { public partial class FormStore : Form { - private readonly List? _listStores; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _Jewels; + private DateTime? _openingDate = null; private readonly IStoreLogic _logic; private readonly ILogger _logger; - public int Id { get; set; } public FormStore(ILogger logger, IStoreLogic logic) { InitializeComponent(); _logger = logger; - _listStores = logic.ReadList(null); + _Jewels = new Dictionary(); _logic = logic; } - - private IStoreModel? GetStore(int id) + private void FormShop_Load(object sender, EventArgs e) { - if (_listStores == null) + if (_id.HasValue) { - return null; - } - foreach (var elem in _listStores) - { - if (elem.Id == id) + _logger.LogInformation("Загрузка магазина"); + try { - return elem; + var view = _logic.ReadElement(new StoreSearchModel + { + Id = _id.Value + }); + if (view != null) + { + NameTextBox.Text = view.StoreName; + AdressTextBox.Text = view.StoreAdress; + dateTimeOpen.Value = view.OpeningDate; + numericUpJewelMaxCount.Value = view.JewelMaxCount; + _Jewels = view.Jewels ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - return null; } + + private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(NameTextBox.Text)) @@ -53,42 +70,27 @@ namespace JewelryStore MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (string.IsNullOrEmpty(AdressTextBox.Text)) { MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение магазина"); - try { - DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); - StoreBindingModel model = new() + var model = new StoreBindingModel { + Id = _id ?? 0, StoreName = NameTextBox.Text, StoreAdress = AdressTextBox.Text, - OpeningDate = dateTime + OpeningDate = dateTimeOpen.Value, + JewelMaxCount = (int)numericUpJewelMaxCount.Value }; - var vmodel = GetStore(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); DialogResult = DialogResult.OK; Close(); @@ -106,35 +108,28 @@ namespace JewelryStore Close(); } - private void FormStore_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData(bool extendDate = true) + + private void LoadData() { + _logger.LogInformation("Загрузка изделий в магазине"); try { - var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); - if (model != null) + if (_Jewels != null) { - NameTextBox.Text = model.StoreName; - AdressTextBox.Text = model.StoreAdress; - OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); DataGridView.Rows.Clear(); - foreach (var el in model.Jewels.Values) + foreach (var sr in _Jewels) { - DataGridView.Rows.Add(new object[] { el.Item1.JewelName, el.Item1.Price, el.Item2 }); + DataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.PizzaName, sr.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); } } + } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs index b478d0f..10df527 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs @@ -1,4 +1,5 @@ using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.ViewModels; using Microsoft.Extensions.Logging; using System; @@ -47,53 +48,39 @@ namespace JewelryStore private void SaveButton_Click(object sender, EventArgs e) { - if (StoreNameComboBox.SelectedValue == null) - { - MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (JewelNameComboBox.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - - _logger.LogInformation("Добавление изделия в магазин"); - + _logger.LogInformation("Создание покупки"); try { - var jewel = _jewelLogic.ReadElement(new() + bool resout = _storeLogic.Sale(new SupplySearchModel { - Id = (int)JewelNameComboBox.SelectedValue + PizzaId = Convert.ToInt32(JewelNameComboBox.SelectedValue), + Count = Convert.ToInt32(CountTextBox.Text) }); - - if (jewel == null) + if (resout) { - throw new Exception("Не найдено изделие. Дополнительная информация в логах."); + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); } - - var resultOperation = _storeLogic.AddJewel( - model: new() { Id = (int)StoreNameComboBox.SelectedValue }, - jewel: jewel, - quantity: Convert.ToInt32(CountTextBox.Text) - ); - - if (!resultOperation) + else { - throw new Exception("Ошибка при добавлении. Дополнительная информация в логах."); + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); } - - 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); } } + private void ButtonCancel_Click(object sender, EventArgs e) { diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs index 08101df..91ad17b 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs @@ -1,100 +1,43 @@ using JewelryStoreContracts.BindingModels; +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; -using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; -using JewelryStoreDataModels.Models; -using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using JewelryStoreContracts.StoragesModels; -namespace JewelryStoreBusinessLogic.BusinessLogics +namespace PizzeriaBusinessLogic.BusinessLogics { public class StoreLogic : IStoreLogic { private readonly ILogger _logger; - private readonly IStoreStorage _storeStorage; + private readonly IStoreStorage _shopStorage; + private readonly IJewelStorage _pizzaStorage; - public StoreLogic(ILogger logger, IStoreStorage storeStorage) + public StoreLogic(ILogger logger, IStoreStorage shopStorage, IJewelStorage pizzaStorage) { _logger = logger; - _storeStorage = storeStorage; + _shopStorage = shopStorage; + _pizzaStorage = pizzaStorage; } - public bool AddJewel(StoreSearchModel model, IJewelModel jewel, int count) + public List? ReadList(StoreSearchModel? model) { - if (model == null) + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.StoreName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) { - throw new ArgumentNullException(nameof(model)); + _logger.LogWarning("ReadList return null list"); + return null; } - - if (count <= 0) - { - throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); - } - - _logger.LogInformation("AddJewelInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); - var element = _storeStorage.GetElement(model); - - if (element == null) - { - _logger.LogWarning("AddJewelInStore element not found"); - return false; - } - - _logger.LogInformation("AddJewelInStore find. Id:{Id}", element.Id); - - if (element.Jewels.TryGetValue(jewel.Id, out var pair)) - { - element.Jewels[jewel.Id] = (jewel, count + pair.Item2); - _logger.LogInformation("AddJewelInStore. Has been added {count} {jewel} in {StoreName}", count, jewel.JewelName, element.StoreName); - } - else - { - element.Jewels[jewel.Id] = (jewel, count); - _logger.LogInformation("AddJewelInStore. Has been added {count} new Jewel {jewel} in {StoreName}", count, jewel.JewelName, element.StoreName); - } - - _storeStorage.Update(new() - { - Id = element.Id, - StoreAdress = element.StoreAdress, - StoreName = element.StoreName, - OpeningDate = element.OpeningDate, - Jewels = element.Jewels - }); - return true; - } - - public bool Create(StoreBindingModel model) - { - CheckModel(model); - model.Jewels = new(); - - if (_storeStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - - return true; - } - - public bool Delete(StoreBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - - if (_storeStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - - return true; + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } public StoreViewModel? ReadElement(StoreSearchModel model) @@ -103,46 +46,32 @@ namespace JewelryStoreBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - - _logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); - var element = _storeStorage.GetElement(model); - + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.StoreName, 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 List? ReadList(StoreSearchModel? model) + public bool Create(StoreBindingModel model) { - _logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id); - - var list = (model == null) ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model); - - if (list == null) + CheckModel(model); + if (_shopStorage.Insert(model) == null) { - _logger.LogWarning("ReadList return null list"); - return null; + _logger.LogWarning("Insert operation failed"); + return false; } - - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; + return true; } public bool Update(StoreBindingModel model) { - CheckModel(model, false); - - if (string.IsNullOrEmpty(model.StoreName)) - { - throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); - } - - if (_storeStorage.Update(model) == null) + CheckModel(model); + if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -150,34 +79,100 @@ namespace JewelryStoreBusinessLogic.BusinessLogics return true; } + public bool Delete(StoreBindingModel 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; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new StoreSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.Jewels.ContainsKey(model.PizzaId)) + { + var oldValue = shop.Jewels[model.PizzaId]; + oldValue.Item2 += model.Count; + shop.Jewels[model.PizzaId] = oldValue; + } + else + { + var pizza = _pizzaStorage.GetElement(new JewelSearchModel + { + Id = model.PizzaId + }); + if (pizza == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.PizzaId} не найденн"); + } + shop.Jewels.Add(model.PizzaId, (pizza, model.Count)); + } + return true; + } + private void CheckModel(StoreBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - if (!withParams) { return; } - + if (string.IsNullOrEmpty(model.StoreAdress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.StoreAdress)); + } if (string.IsNullOrEmpty(model.StoreName)) { - throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.StoreName)); } - - _logger.LogInformation("Store. StoreName:{StoreName}.StoreAdress:{StoreAdress}. Id: {Id}", model.StoreName, model.StoreAdress, model.Id); - var element = _storeStorage.GetElement(new StoreSearchModel + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.StoreName, model.StoreAdress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new StoreSearchModel { StoreName = model.StoreName }); - - if (element != null && element.Id != model.Id && element.StoreName == model.StoreName) + if (element != null && element.Id != model.Id) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + public bool Sale(SupplySearchModel model) + { + if (!model.PizzaId.HasValue || !model.Count.HasValue) + { + return false; + } + _logger.LogInformation("Check pizza count in all shops"); + if (_shopStorage.Sale(model)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs index 1db1c82..5bc723e 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/StoreBindingModel.cs @@ -18,5 +18,6 @@ namespace JewelryStoreContracts.BindingModels public Dictionary Jewels { get; set; } = new(); public int Id { get; set; } + public int JewelMaxCount { get; set; } } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..a9878b8 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int PizzaId { get; set; } + public int Count { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs index d939ba2..0ffeb39 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs @@ -17,6 +17,8 @@ namespace JewelryStoreContracts.BusinessLogicsContracts bool Create(StoreBindingModel model); bool Update(StoreBindingModel model); bool Delete(StoreBindingModel model); - bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity); + bool MakeSupply(SupplyBindingModel model); + bool Sale(SupplySearchModel model); + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..36462ea --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class SupplySearchModel + { + public int? PizzaId { get; set; } + public int? Count { get; set; } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs index 46b04e8..8a28811 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IStoreStorage.cs @@ -17,5 +17,7 @@ namespace JewelryStoreContracts.StoragesModels StoreViewModel? Insert(StoreBindingModel model); StoreViewModel? Update(StoreBindingModel model); StoreViewModel? Delete(StoreBindingModel model); + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs index b04091d..3318526 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/StoreViewModel.cs @@ -11,6 +11,7 @@ namespace JewelryStoreContracts.ViewModels public class StoreViewModel : IStoreModel { public Dictionary Jewels { get; set; } = new(); + [DisplayName("Вместимость")] public int Id { get; set; } [DisplayName("Название магазина")] @@ -21,5 +22,9 @@ namespace JewelryStoreContracts.ViewModels [DisplayName("Дата открытия")] public DateTime OpeningDate { get; set; } = DateTime.Now; + + public int JewelMaxCount { get; set; } + } + } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs index 754c185..0b75938 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs @@ -1,6 +1,8 @@ using JewelryStoreContracts.BindingModels; +using JewelryStoreListImplement; +using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.SearchModels; -using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; using JewelryStoreListImplement.Models; using System; @@ -8,16 +10,95 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using JewelryStoreContracts.StoragesModels; namespace JewelryStoreListImplement.Implements { - public class StoreStorage : IStoreStorage + public class ShopStorage : IStoreStorage { private readonly DataListSingleton _source; - public StoreStorage() + + public ShopStorage() { _source = DataListSingleton.GetInstance(); } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Stores) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(StoreSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.StoreName)) + { + return result; + } + foreach (var shop in _source.Stores) + { + if (shop.StoreName.Contains(model.StoreName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public StoreViewModel? GetElement(StoreSearchModel model) + { + if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Stores) + { + if ((!string.IsNullOrEmpty(model.StoreName) && shop.StoreName == model.StoreName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public StoreViewModel? Insert(StoreBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Stores) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Store.Create(model); + if (newShop == null) + { + return null; + } + _source.Stores.Add(newShop); + return newShop.GetViewModel; + } + + public StoreViewModel? Update(StoreBindingModel model) + { + foreach (var shop in _source.Stores) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public StoreViewModel? Delete(StoreBindingModel model) { for (int i = 0; i < _source.Stores.Count; ++i) @@ -32,92 +113,14 @@ namespace JewelryStoreListImplement.Implements return null; } - public StoreViewModel? GetElement(StoreSearchModel model) + public bool Sale(SupplySearchModel model) { - if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue) - { - return null; - } - - foreach (var store in _source.Stores) - { - if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id)) - { - return store.GetViewModel; - } - } - - return null; + throw new NotImplementedException(); } - public List GetFilteredList(StoreSearchModel model) + public bool RestockingShops(SupplyBindingModel model) { - var result = new List(); - - if (string.IsNullOrEmpty(model.StoreName)) - { - return result; - } - - foreach (var store in _source.Stores) - { - if (store.StoreName.Contains(model.StoreName)) - { - result.Add(store.GetViewModel); - } - } - - return result; - } - - public List GetFullList() - { - var result = new List(); - - foreach (var store in _source.Stores) - { - result.Add(store.GetViewModel); - } - - return result; - } - - public StoreViewModel? Insert(StoreBindingModel model) - { - model.Id = 1; - - foreach (var store in _source.Stores) - { - if (model.Id <= store.Id) - { - model.Id = store.Id + 1; - } - } - - var newStore = Store.Create(model); - - if (newStore == null) - { - return null; - } - - _source.Stores.Add(newStore); - - return newStore.GetViewModel; - } - - public StoreViewModel? Update(StoreBindingModel model) - { - foreach (var store in _source.Stores) - { - if (store.Id == model.Id) - { - store.Update(model); - return store.GetViewModel; - } - } - - return null; + throw new NotImplementedException(); } } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs index 8515902..07214f0 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Store.cs @@ -19,6 +19,7 @@ namespace JewelryStoreListImplement.Models public Dictionary Jewels { get; private set; } = new(); public int Id { get; private set; } + public int JewelMaxCount { get; private set; } public static Store? Create(StoreBindingModel? model) { @@ -32,7 +33,7 @@ namespace JewelryStoreListImplement.Models StoreName = model.StoreName, StoreAdress = model.StoreAdress, OpeningDate = model.OpeningDate, - Jewels = new() + JewelMaxCount = model.JewelMaxCount, }; } @@ -45,6 +46,7 @@ namespace JewelryStoreListImplement.Models StoreName = model.StoreName; StoreAdress = model.StoreAdress; OpeningDate = model.OpeningDate; + JewelMaxCount = model.JewelMaxCount; } public StoreViewModel GetViewModel => new() @@ -53,7 +55,8 @@ namespace JewelryStoreListImplement.Models StoreName = StoreName, StoreAdress = StoreAdress, OpeningDate = OpeningDate, - Jewels = Jewels + Jewels = Jewels, + JewelMaxCount = JewelMaxCount, }; } } From 2fb3d6961a7ce1723d6fd69b6728b2cf1e48e465 Mon Sep 17 00:00:00 2001 From: Alenka Date: Sat, 11 May 2024 23:20:15 +0400 Subject: [PATCH 04/10] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D1=87=D1=82=D0=BE?= =?UTF-8?q?=20=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/ISupplyModel.cs | 2 +- .../JewelryStore/FormCreateSupply.Designer.cs | 38 +++++++++---------- .../JewelryStore/FormCreateSupply.cs | 20 +++++----- .../JewelryStore/FormStore.cs | 2 +- .../JewelryStore/FormStoreReplenishment.cs | 4 +- .../JewelryStore/Program.cs | 2 +- .../BusinessLogics/StoreLogic.cs | 28 +++++++------- .../BindingModels/SupplyBindingModel.cs | 2 +- .../SearchModels/SupplySearchModel.cs | 2 +- .../Implements/StoreStorage.cs | 4 +- 10 files changed, 52 insertions(+), 52 deletions(-) diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs index 1311fc9..a656f7e 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/ISupplyModel.cs @@ -9,7 +9,7 @@ namespace JewelryStoreDataModels.Models public interface ISupplyModel { int ShopId { get; } - int PizzaId { get; } + int JewelId { get; } int Count { get; } } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs index bd15c13..a94fe8b 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.Designer.cs @@ -30,8 +30,8 @@ { this.comboBoxShop = new System.Windows.Forms.ComboBox(); this.labelShop = new System.Windows.Forms.Label(); - this.labelPizza = new System.Windows.Forms.Label(); - this.comboBoxPizza = new System.Windows.Forms.ComboBox(); + this.labelJewel = new System.Windows.Forms.Label(); + this.comboBoxJewel = new System.Windows.Forms.ComboBox(); this.labelCount = new System.Windows.Forms.Label(); this.textBoxCount = new System.Windows.Forms.TextBox(); this.buttonCancel = new System.Windows.Forms.Button(); @@ -55,22 +55,22 @@ this.labelShop.TabIndex = 1; this.labelShop.Text = "Магазин: "; // - // labelPizza + // labelJewel // - this.labelPizza.AutoSize = true; - this.labelPizza.Location = new System.Drawing.Point(12, 49); - this.labelPizza.Name = "labelPizza"; - this.labelPizza.Size = new System.Drawing.Size(75, 20); - this.labelPizza.TabIndex = 2; - this.labelPizza.Text = "Изделие: "; + this.labelJewel.AutoSize = true; + this.labelJewel.Location = new System.Drawing.Point(12, 49); + this.labelJewel.Name = "labelJewel"; + this.labelJewel.Size = new System.Drawing.Size(75, 20); + this.labelJewel.TabIndex = 2; + this.labelJewel.Text = "Изделие: "; // - // comboBoxPizza + // comboBoxJewel // - this.comboBoxPizza.FormattingEnabled = true; - this.comboBoxPizza.Location = new System.Drawing.Point(115, 46); - this.comboBoxPizza.Name = "comboBoxPizza"; - this.comboBoxPizza.Size = new System.Drawing.Size(344, 28); - this.comboBoxPizza.TabIndex = 3; + this.comboBoxJewel.FormattingEnabled = true; + this.comboBoxJewel.Location = new System.Drawing.Point(115, 46); + this.comboBoxJewel.Name = "comboBoxJewel"; + this.comboBoxJewel.Size = new System.Drawing.Size(344, 28); + this.comboBoxJewel.TabIndex = 3; // // labelCount // @@ -117,8 +117,8 @@ this.Controls.Add(this.buttonCancel); this.Controls.Add(this.textBoxCount); this.Controls.Add(this.labelCount); - this.Controls.Add(this.comboBoxPizza); - this.Controls.Add(this.labelPizza); + this.Controls.Add(this.comboBoxJewel); + this.Controls.Add(this.labelJewel); this.Controls.Add(this.labelShop); this.Controls.Add(this.comboBoxShop); this.Name = "FormCreateSupply"; @@ -133,8 +133,8 @@ private ComboBox comboBoxShop; private Label labelShop; - private Label labelPizza; - private ComboBox comboBoxPizza; + private Label labelJewel; + private ComboBox comboBoxJewel; private Label labelCount; private TextBox textBoxCount; private Button buttonCancel; diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs index 09c7d69..518f149 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormCreateSupply.cs @@ -23,7 +23,7 @@ namespace JewelryStoreView private readonly IJewelLogic _logicP; private readonly IStoreLogic _logicS; private List _shopList = new List(); - private List _pizzaList = new List(); + private List _jewelList = new List(); public FormCreateSupply(ILogger logger, IJewelLogic logicP, IStoreLogic logicS) { @@ -36,7 +36,7 @@ namespace JewelryStoreView private void FormCreateSupply_Load(object sender, EventArgs e) { _shopList = _logicS.ReadList(null); - _pizzaList = _logicP.ReadList(null); + _jewelList = _logicP.ReadList(null); if (_shopList != null) { comboBoxShop.DisplayMember = "ShopName"; @@ -45,13 +45,13 @@ namespace JewelryStoreView comboBoxShop.SelectedItem = null; _logger.LogInformation("Загрузка магазинов для поставок"); } - if (_pizzaList != null) + if (_jewelList != null) { - comboBoxPizza.DisplayMember = "PizzaName"; - comboBoxPizza.ValueMember = "Id"; - comboBoxPizza.DataSource = _pizzaList; - comboBoxPizza.SelectedItem = null; - _logger.LogInformation("Загрузка пиццы для поставок"); + comboBoxJewel.DisplayMember = "JewelName"; + comboBoxJewel.ValueMember = "Id"; + comboBoxJewel.DataSource = _jewelList; + comboBoxJewel.SelectedItem = null; + _logger.LogInformation("Загрузка изделий для поставок"); } } @@ -62,7 +62,7 @@ namespace JewelryStoreView MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (comboBoxPizza.SelectedValue == null) + if (comboBoxJewel.SelectedValue == null) { MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -73,7 +73,7 @@ namespace JewelryStoreView var operationResult = _logicS.MakeSupply(new SupplyBindingModel { ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), - PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + JewelId = Convert.ToInt32(comboBoxJewel.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text) }); if (!operationResult) diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs index 61e534a..5592e36 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStore.cs @@ -119,7 +119,7 @@ namespace JewelryStore DataGridView.Rows.Clear(); foreach (var sr in _Jewels) { - DataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.PizzaName, sr.Value.Item2 }); + DataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.JewelName, sr.Value.Item2 }); } } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs index 10df527..579cd47 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormStoreReplenishment.cs @@ -50,7 +50,7 @@ namespace JewelryStore { if (JewelNameComboBox.SelectedValue == null) { - MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Создание покупки"); @@ -58,7 +58,7 @@ namespace JewelryStore { bool resout = _storeLogic.Sale(new SupplySearchModel { - PizzaId = Convert.ToInt32(JewelNameComboBox.SelectedValue), + JewelId = Convert.ToInt32(JewelNameComboBox.SelectedValue), Count = Convert.ToInt32(CountTextBox.Text) }); if (resout) diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs index 0026b61..6124253 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs @@ -1,11 +1,11 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.StoragesContracts; -using JewelryStoreFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using JewelryStoreBusinessLogic.BusinessLogics; using JewelryStoreContracts.StoragesModels; +using JewelryStoreListImplement.Implements; namespace JewelryStore { diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs index 91ad17b..d3a7134 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs @@ -12,19 +12,19 @@ using System.Text; using System.Threading.Tasks; using JewelryStoreContracts.StoragesModels; -namespace PizzeriaBusinessLogic.BusinessLogics +namespace JewelryStoreBusinessLogic.BusinessLogics { public class StoreLogic : IStoreLogic { private readonly ILogger _logger; private readonly IStoreStorage _shopStorage; - private readonly IJewelStorage _pizzaStorage; + private readonly IJewelStorage _JewelStorage; - public StoreLogic(ILogger logger, IStoreStorage shopStorage, IJewelStorage pizzaStorage) + public StoreLogic(ILogger logger, IStoreStorage shopStorage, IJewelStorage JewelStorage) { _logger = logger; _shopStorage = shopStorage; - _pizzaStorage = pizzaStorage; + _JewelStorage = JewelStorage; } public List? ReadList(StoreSearchModel? model) @@ -109,23 +109,23 @@ namespace PizzeriaBusinessLogic.BusinessLogics { throw new ArgumentException("Магазина не существует"); } - if (shop.Jewels.ContainsKey(model.PizzaId)) + if (shop.Jewels.ContainsKey(model.JewelId)) { - var oldValue = shop.Jewels[model.PizzaId]; + var oldValue = shop.Jewels[model.JewelId]; oldValue.Item2 += model.Count; - shop.Jewels[model.PizzaId] = oldValue; + shop.Jewels[model.JewelId] = oldValue; } else { - var pizza = _pizzaStorage.GetElement(new JewelSearchModel + var Jewel = _JewelStorage.GetElement(new JewelSearchModel { - Id = model.PizzaId + Id = model.JewelId }); - if (pizza == null) + if (Jewel == null) { - throw new ArgumentException($"Поставка: Товар с id:{model.PizzaId} не найденн"); + throw new ArgumentException($"Поставка: Товар с id:{model.JewelId} не найденн"); } - shop.Jewels.Add(model.PizzaId, (pizza, model.Count)); + shop.Jewels.Add(model.JewelId, (Jewel, model.Count)); } return true; } @@ -161,11 +161,11 @@ namespace PizzeriaBusinessLogic.BusinessLogics public bool Sale(SupplySearchModel model) { - if (!model.PizzaId.HasValue || !model.Count.HasValue) + if (!model.JewelId.HasValue || !model.Count.HasValue) { return false; } - _logger.LogInformation("Check pizza count in all shops"); + _logger.LogInformation("Check Jewel count in all shops"); if (_shopStorage.Sale(model)) { _logger.LogInformation("Selling sucsess"); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs index a9878b8..59e4a6a 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/SupplyBindingModel.cs @@ -10,7 +10,7 @@ namespace JewelryStoreContracts.BindingModels public class SupplyBindingModel : ISupplyModel { public int ShopId { get; set; } - public int PizzaId { get; set; } + public int JewelId { get; set; } public int Count { get; set; } } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs index 36462ea..85b8202 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/SupplySearchModel.cs @@ -8,7 +8,7 @@ namespace JewelryStoreContracts.SearchModels { public class SupplySearchModel { - public int? PizzaId { get; set; } + public int? JewelId { get; set; } public int? Count { get; set; } } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs index 0b75938..07c0dd0 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/StoreStorage.cs @@ -14,11 +14,11 @@ using JewelryStoreContracts.StoragesModels; namespace JewelryStoreListImplement.Implements { - public class ShopStorage : IStoreStorage + public class StoreStorage : IStoreStorage { private readonly DataListSingleton _source; - public ShopStorage() + public StoreStorage() { _source = DataListSingleton.GetInstance(); } From c8284d0a196c060f8285929a07e591b0e111ff18 Mon Sep 17 00:00:00 2001 From: Alenka Date: Mon, 17 Jun 2024 13:01:15 +0400 Subject: [PATCH 05/10] start --- .../BusinessLogics/StoreLogic.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs index d3a7134..1a4e0e7 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic.cs @@ -123,11 +123,20 @@ namespace JewelryStoreBusinessLogic.BusinessLogics }); if (Jewel == null) { - throw new ArgumentException($"Поставка: Товар с id:{model.JewelId} не найденн"); + throw new ArgumentException($"Поставка: Товар с id:{model.JewelId} не найден"); } shop.Jewels.Add(model.JewelId, (Jewel, model.Count)); } - return true; + _shopStorage.Update(new StoreBindingModel() + { + Id = shop.Id, + StoreName = shop.StoreName, + StoreAdress = shop.StoreAdress, + OpeningDate = shop.OpeningDate, + Jewels = shop.Jewels, + JewelMaxCount = shop.JewelMaxCount, + }); + return true; } private void CheckModel(StoreBindingModel model, bool withParams = true) From 6d786b57911ad31e6a114364e973139fe65c09bf Mon Sep 17 00:00:00 2001 From: Alenka Date: Mon, 17 Jun 2024 15:40:11 +0400 Subject: [PATCH 06/10] =?UTF-8?q?=D0=9A=D0=B0=D0=B6=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B2=D1=81=D1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JewelryStoreDatabase.cs | 4 +- .../Models/Jewel.cs | 7 +- .../Models/Store.cs | 116 ++++++++++++++++++ .../Models/StoreJewels.cs | 27 ++++ 4 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Store.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/StoreJewels.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs index fb91643..3faa4d1 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs @@ -23,6 +23,8 @@ namespace JewelryStoreDatabaseImplement public virtual DbSet Jewels { set; get; } public virtual DbSet JewelComponents { set; get; } public virtual DbSet Orders { set; get; } - } + public virtual DbSet Shops { get; set; } + public virtual DbSet ShopJewels { get; set; } + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Jewel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Jewel.cs index 79dffdb..e82b97b 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Jewel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Jewel.cs @@ -34,9 +34,12 @@ namespace JewelryStoreDatabaseImplement.Models [ForeignKey("JewelId")] public virtual List Components { get; set; } = new(); [ForeignKey("JewelId")] - public virtual List Orders { get; set; } = new(); - public static Jewel Create(JewelryStoreDatabase context, JewelBindingModel model) + public virtual List Orders { get; set; } = new(); + [ForeignKey("JewelId")] + public virtual List ShopJewels { get; set; } = new(); + + public static Jewel Create(JewelryStoreDatabase context, JewelBindingModel model) { return new Jewel() { diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Store.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Store.cs new file mode 100644 index 0000000..5c58f5b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Store.cs @@ -0,0 +1,116 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace JewelryStoreDatabaseImplement.Models +{ + public class Store : IStoreModel + { + public int Id { get; set; } + public string StoreName { get; set; } = string.Empty; + + public string StoreAdress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } + + public int JewelMaxCount { get; set; } + + + private Dictionary? _shopJewels = null; + + + public Dictionary ShopJewels + { + get + { + if (_shopJewels == null) + { + if (_shopJewels == null) + { + _shopJewels = Jewels + .ToDictionary(recSP => recSP.JewelId, recSP => (recSP.Jewel as IJewelModel, recSP.Count)); + } + return _shopJewels; + } + return _shopJewels; + } + } + + [ForeignKey("ShopId")] + public List Jewels { get; set; } = new(); + + public static Store Create(JewelryStoreDatabase context, StoreBindingModel model) + { + return new Store() + { + Id = model.Id, + StoreName = model.StoreName, + StoreAdress = model.StoreAdress, + OpeningDate = model.OpeningDate, + Jewels = model.Jewels.Select(x => new StoreJewels + { + Jewel = context.Jewels.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + JewelMaxCount = model.JewelMaxCount + }; + } + + public void Update(StoreBindingModel model) + { + StoreName = model.StoreName; + StoreAdress = model.StoreAdress; + OpeningDate = model.OpeningDate; + JewelMaxCount = model.JewelMaxCount; + } + + public StoreViewModel GetViewModel => new() + { + Id = Id, + StoreName = StoreName, + StoreAdress = StoreAdress, + OpeningDate = OpeningDate, + Jewels = Jewels, + JewelMaxCount = JewelMaxCount + }; + + public void UpdateJewels(JewelryStoreDatabase context, StoreBindingModel model) + { + var ShopPizzas = context.ShopJewels.Where(rec => rec.ShopId == model.Id).ToList(); + if (ShopPizzas != null && ShopJewels.Count > 0) + { + context.ShopJewels.RemoveRange(ShopJewels.Where(rec => !model.Jewels.ContainsKey(rec.JewelId))); + context.SaveChanges(); + ShopPizzas = context.ShopJewels.Where(rec => rec.ShopId == model.Id).ToList(); + foreach (var updateJewel in ShopJewels) + { + updateJewel.Count = model.Jewels[updateJewel.JewelId].Item2; + model.Jewels.Remove(updateJewel.JewelId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var ar in model.Jewels) + { + context.ShopJewels.Add(new Jewels + { + Shop = shop, + Jewel = context.Jewels.First(x => x.Id == ar.Key), + Count = ar.Value.Item2 + }); + context.SaveChanges(); + } + _shopJewels = null; + } + + public void PizzasDictionatyUpdate(JewelryStoreDatabase context) + { + UpdateJewels(context, new StoreBindingModel + { + Id = Id, + Jewels = Jewels, + }); + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/StoreJewels.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/StoreJewels.cs new file mode 100644 index 0000000..77789c5 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/StoreJewels.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Models +{ + public class StoreJewels + { + public int Id { get; set; } + + [Required] + public int JewelId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Store Shop { get; set; } = new(); + + public virtual Jewel Jewel { get; set; } = new(); + } +} From 66231c18f8ac52a11bb31b5a8ee09186e5461406 Mon Sep 17 00:00:00 2001 From: Alenka Date: Mon, 17 Jun 2024 15:59:00 +0400 Subject: [PATCH 07/10] =?UTF-8?q?=D0=A2=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/StoreStorage.cs | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/StoreStorage.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/StoreStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/StoreStorage.cs new file mode 100644 index 0000000..f02338b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/StoreStorage.cs @@ -0,0 +1,186 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreDatabaseImplement.Models; + +namespace JewelryStoreDatabaseImplement.Implements +{ + public class StoreStorage : IStoreStorage + { + public List GetFullList() + { + using var context = new JewelryStoreDatabase(); + return context.Shops.Include(x => x.Jewels).ThenInclude(x => x.Jewel).ToList(). + Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(StoreSearchModel model) + { + if (string.IsNullOrEmpty(model.StoreName)) + { + return new(); + } + using var context = new JewelryStoreDatabase(); + return context.Shops.Include(x => x.Jewels).ThenInclude(x => x.Jewel).Where(x => x.ShopName.Contains(model.StoreName)). + ToList().Select(x => x.GetViewModel).ToList(); + } + public StoreViewModel? GetElement(StoreSearchModel model) + { + if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue) + { + return new(); + } + using var context = new JewelryStoreDatabase(); + return context.Shops.Include(x => x.Jewels).ThenInclude(x => x.Jewel) + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.StoreName) && x.ShopName == model.StoreName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public StoreViewModel? Insert(StoreBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var newShop = Store.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + + public StoreViewModel? Update(StoreBindingModel model) + { + using var context = new JewelryStoreDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdateJewels(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public StoreViewModel? Delete(StoreBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var shop = context.Shops.Include(x => x.Jewels).FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + context.Shops.Remove(shop); + context.SaveChanges(); + return shop.GetViewModel; + } + return null; + } + + public bool RestockingShops(SupplyBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var transaction = context.Database.BeginTransaction(); + var Shops = context.Shops.Include(x => x.Jewels).ThenInclude(x => x.Pizza).ToList(). + Where(x => x.JewelMaxCount > x.ShopPizzas.Select(x => x.Value.Item2).Sum()).ToList(); + if (model == null) + { + return false; + } + try + { + foreach (Store shop in Shops) + { + int difference = shop.JewelMaxCount - shop.ShopJewels.Select(x => x.Value.Item2).Sum(); + int refill = Math.Min(difference, model.Count); + model.Count -= refill; + if (shop.ShopJewels.ContainsKey(model.JewelId)) + { + var datePair = shop.ShopJewels[model.JewelId]; + datePair.Item2 += refill; + shop.ShopJewels[model.JewelId] = datePair; + } + else + { + var pizza = context.Jewels.First(x => x.Id == model.JewelId); + shop.ShopJewels.Add(model.JewelId, (jewel, refill)); + } + shop.JewelsDictionatyUpdate(context); + if (model.Count == 0) + { + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public bool Sale(SupplySearchModel model) + { + using var context = new JewelryStoreDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var shops = context.Shops.Include(x => x.Jewels).ThenInclude(x => x.Jewel).ToList(). + Where(x => x.ShopPizzas.ContainsKey(model.JewelId.Value)).OrderByDescending(x => x.ShopPizzas[model.JewelId.Value].Item2).ToList(); + + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.ShopPizzas[model.JewelId.Value].Item2; + if (residue > 0) + { + shop.ShopPizzas.Remove(model.JewelId.Value); + shop.PizzasDictionatyUpdate(context); + context.SaveChanges(); + model.Count = residue; + + } + else + { + if (residue == 0) + shop.ShopPizzas.Remove(model.JewelId.Value); + else + { + var dataPair = shop.ShopPizzas[model.JewelId.Value]; + dataPair.Item2 = -residue; + shop.ShopPizzas[model.JewelId.Value] = dataPair; + } + + shop.JewelsDictionatyUpdate(context); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + } +} From d0cf79c5fd3fff59e938abb47d6c511b2d00cdba Mon Sep 17 00:00:00 2001 From: Alenka Date: Mon, 17 Jun 2024 17:00:42 +0400 Subject: [PATCH 08/10] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=BE=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D0=BD=D1=83=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ReportGroupOrdersViewModel.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportGroupOrdersViewModel.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportGroupOrdersViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportGroupOrdersViewModel.cs new file mode 100644 index 0000000..5d877b5 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportGroupOrdersViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class ReportGroupOrdersViewModel + { + public DateTime Date { get; set; } = DateTime.Now; + public int OrdersCount { get; set; } + public double OrdersSum { get; set; } + } +} From e407466cb1b7c717e6ed7c6afc26b3a948a23e78 Mon Sep 17 00:00:00 2001 From: Alenka Date: Tue, 18 Jun 2024 23:40:08 +0400 Subject: [PATCH 09/10] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5?= =?UTF-8?q?=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JewelryStore/FormMain.cs | 48 ++- .../BusinessLogics/ReportLogic.cs | 86 ++++-- .../OfficePackage/AbstractSaveToExcel.cs | 20 +- .../OfficePackage/AbstractSaveToPdf.cs | 125 ++++---- .../OfficePackage/AbstractSaveToWord.cs | 120 +++++--- .../OfficePackage/HelperModels/ExcelShop.cs | 15 + .../HelperModels/PdfGroupedOrdersInfo.cs | 18 ++ .../HelperModels/WordShopInfo.cs | 16 + .../OfficePackage/IDocument.cs | 14 + .../OfficePackage/Implements/SaveToExcel.cs | 5 +- .../OfficePackage/Implements/SaveToPdf.cs | 179 +++++------ .../OfficePackage/Implements/SaveToWord.cs | 290 +++++++++++------- .../BusinessLogicsContracts/IReportLogic.cs | 38 +-- .../ViewModels/ReportShopsViewModel.cs | 15 + .../Implements/OrderStorage.cs | 2 +- 15 files changed, 603 insertions(+), 388 deletions(-) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/IDocument.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportShopsViewModel.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs index fc706d0..f6dabdf 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs @@ -168,17 +168,16 @@ namespace JewelryStore LoadData(); } - private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormStores)); + private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShop)); + if (service is FormReportShop form) + { + form.ShowDialog(); + } + } - if (service is FormStores form) - { - form.ShowDialog(); - } - } - - private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); @@ -187,5 +186,32 @@ namespace JewelryStore form.ShowDialog(); } } - } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SavePizzasToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void InfoToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } + + } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs index b35db5c..fd13ed6 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using JewelryStoreContracts.StoragesModels; namespace JewelryStoreBusinessLogic.BusinessLogics { @@ -18,23 +19,22 @@ namespace JewelryStoreBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly IJewelStorage _jewelStorage; private readonly IOrderStorage _orderStorage; - private readonly AbstractSaveToExcel _saveToExcel; + private readonly IStoreStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IJewelStorage jewelStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, - AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + IStoreStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _jewelStorage = jewelStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } - /// - /// Получение списка компонент с указанием, в каких изделиях используются - /// - /// + public List GetJewelComponent() { return _jewelStorage.GetFullList().Select(x => new ReportJewelComponentViewModel @@ -44,11 +44,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics TotalCount = x.JewelComponents.Select(x => x.Value.Item2).Sum() }).ToList(); } - /// - /// Получение списка заказов за определенный период - /// - /// - /// + public List GetOrders(ReportBindingModel model) { return _orderStorage.GetFilteredList(new OrderSearchModel @@ -65,10 +61,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics }).ToList(); } - /// - /// Сохранение компонент в файл-Word - /// - /// + public void SaveJewelsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo @@ -78,23 +71,17 @@ namespace JewelryStoreBusinessLogic.BusinessLogics Jewels = _jewelStorage.GetFullList() }); } - /// - /// Сохранение компонент с указаеним продуктов в файл-Excel - /// - /// + public void SaveJewelComponentToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, - Title = "Список компонент", + Title = "Список компонентов", JewelComponents = GetJewelComponent() }); } - /// - /// Сохранение заказов в файл-Pdf - /// - /// + public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo @@ -106,5 +93,54 @@ namespace JewelryStoreBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } - } + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Pizzas = x.ShopPizzas.Select(x => (x.Value.Item1.PizzaName, x.Value.Item2)).ToList(), + TotalCount = x.ShopPizzas.Select(x => x.Value.Item2).Sum() + }).ToList(); + } + + public List GetGroupedOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel + { + Date = x.Key, + OrdersCount = x.Count(), + OrdersSum = x.Select(y => y.Sum).Sum() + }).ToList(); + } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordShopInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopPizzasReport(new ExcelShop + { + FileName = model.FileName, + Title = "Наполненость магазинов", + ShopPizzas = GetShops() + }); + } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + { + FileName = model.FileName, + Title = "Список заказов сгруппированных по дате заказов", + GroupedOrders = GetGroupedOrders() + }); + } + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index d186507..52a2f66 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -77,26 +77,14 @@ namespace JewelryStoreBusinessLogic.OfficePackage } SaveExcel(info); } - /// - /// Создание 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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 7dc85ee..cb03e17 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -12,69 +12,66 @@ namespace JewelryStoreBusinessLogic.OfficePackage { public void CreateDoc(PdfInfo info) { - CreatePdf(info); - CreateParagraph(new PdfParagraph - { - Text = info.Title, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); - CreateParagraph(new PdfParagraph - { - Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal", - 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.JewelName, order.Status.ToString(), order.Sum.ToString() }, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - } - CreateParagraph(new PdfParagraph - { - Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Rigth - }); - SavePdf(info); - } - /// - /// Создание doc-файла - /// - /// - 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); - } + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "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.PizzaName, order.Status.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); + + SavePdf(info); + } + + public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "4cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Кол-во", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + + foreach (var groupedOrder in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + SavePdf(info); + } + + protected abstract void CreatePdf(IDocument info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(IDocument info); + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 0f6eb57..cf04d15 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -12,48 +12,82 @@ namespace JewelryStoreBusinessLogic.OfficePackage { public void CreateDoc(WordInfo info) { - CreateWord(info); - 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 jewel in info.Jewels) - { - CreateParagraph(new WordParagraph - { - Texts = new List<(string, WordTextProperties)> { - (jewel.JewelName, new WordTextProperties { Size = "24", Bold = true}), ("\t"+jewel.Price.ToString(), new WordTextProperties{Size = "24"}) - }, - TextProperties = new WordTextProperties - { - Size = "24", - JustificationType = WordJustificationType.Both - } - }); - } - SaveWord(info); - } - /// - /// Создание doc-файла - /// - /// - protected abstract void CreateWord(WordInfo info); - /// - /// Создание абзаца с текстом - /// - /// - /// - protected abstract void CreateParagraph(WordParagraph paragraph); - /// - /// Сохранение файла - /// - /// - protected abstract void SaveWord(WordInfo info); - } + CreateWord(info); + 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 pizza in info.Jewels) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { + (pizza.JewelName, new WordTextProperties { Size = "24", Bold = true}), + ("\t"+pizza.Price.ToString(), new WordTextProperties{Size = "24"}) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + + public void CreateShopsDoc(WordShopInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + CreateTable(new List { "3000", "3000", "3000" }); + CreateRow(new WordRowParameters + { + Texts = new List { "Название", "Адрес", "Дата открытия" }, + TextProperties = new WordTextProperties + { + Size = "24", + Bold = true, + JustificationType = WordJustificationType.Center + } + }); + + foreach (var shop in info.Shops) + { + CreateRow(new WordRowParameters + { + Texts = new List { shop.ShopName, shop.Adress, shop.OpeningDate.ToString() }, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + + protected abstract void CreateWord(IDocument info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(IDocument info); + protected abstract void CreateTable(List colums); + protected abstract void CreateRow(WordRowParameters rowParameters); + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs new file mode 100644 index 0000000..b20b996 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShop : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ShopPizzas { get; set; } = new(); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs new file mode 100644 index 0000000..3360138 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs @@ -0,0 +1,18 @@ +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels +{ + public class PdfGroupedOrdersInfo + { + 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 GroupedOrders { get; set; } = new(); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs new file mode 100644 index 0000000..d85525f --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs @@ -0,0 +1,16 @@ +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels +{ + public class WordShopInfo : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/IDocument.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/IDocument.cs new file mode 100644 index 0000000..cacc2bb --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/IDocument.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.OfficePackage +{ + public interface IDocument + { + public string FileName { get; set; } + public string Title { get; set; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 324caca..c503792 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -19,10 +19,7 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements private SpreadsheetDocument? _spreadsheetDocument; private SharedStringTablePart? _shareStringPart; private Worksheet? _worksheet; - /// - /// Настройка стилей для файла - /// - /// + private static void CreateStyles(WorkbookPart workbookpart) { var sp = workbookpart.AddNewPart(); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 155e772..36d507a 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -16,90 +16,97 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements private Document? _document; private Section? _section; private Table? _table; - private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) - { - return type switch - { - PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, - PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, - PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, - _ => ParagraphAlignment.Justify, - }; - } - /// - /// Создание стилей для документа - /// - /// - private static void DefineStyles(Document document) - { - var style = document.Styles["Normal"]; - style.Font.Name = "Times New Roman"; - style.Font.Size = 14; - style = document.Styles.AddStyle("NormalTitle", "Normal"); - style.Font.Bold = true; - } - protected override void CreatePdf(PdfInfo info) - { - _document = new Document(); - DefineStyles(_document); - _section = _document.AddSection(); - } - protected override void CreateParagraph(PdfParagraph pdfParagraph) - { - if (_section == null) - { - return; - } - var paragraph = _section.AddParagraph(pdfParagraph.Text); - paragraph.Format.SpaceAfter = "1cm"; - paragraph.Format.Alignment = - GetParagraphAlignment(pdfParagraph.ParagraphAlignment); - paragraph.Style = pdfParagraph.Style; - } - protected override void CreateTable(List columns) - { - if (_document == null) - { - return; - } - _table = _document.LastSection.AddTable(); - foreach (var elem in columns) - { - _table.AddColumn(elem); - } - } - protected override void CreateRow(PdfRowParameters rowParameters) - { - if (_table == null) - { - return; - } - var row = _table.AddRow(); - for (int i = 0; i < rowParameters.Texts.Count; ++i) - { - row.Cells[i].AddParagraph(rowParameters.Texts[i]); - if (!string.IsNullOrEmpty(rowParameters.Style)) - { - row.Cells[i].Style = rowParameters.Style; - } - Unit borderWidth = 0.5; - row.Cells[i].Borders.Left.Width = borderWidth; - row.Cells[i].Borders.Right.Width = borderWidth; - row.Cells[i].Borders.Top.Width = borderWidth; - row.Cells[i].Borders.Bottom.Width = borderWidth; - row.Cells[i].Format.Alignment = - GetParagraphAlignment(rowParameters.ParagraphAlignment); - row.Cells[i].VerticalAlignment = VerticalAlignment.Center; - } - } - protected override void SavePdf(PdfInfo info) - { - var renderer = new PdfDocumentRenderer(true) - { - Document = _document - }; - renderer.RenderDocument(); - renderer.PdfDocument.Save(info.FileName); - } - } + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + + protected override void CreatePdf(IDocument info) + { + _document = new Document(); + DefineStyles(_document); + + _section = _document.AddSection(); + } + + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + + Unit borderWidth = 0.5; + + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + + protected override void SavePdf(IDocument info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToWord.cs index b6c7eaa..2d3ac3f 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -15,115 +15,183 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements { private WordprocessingDocument? _wordDocument; private Body? _docBody; - /// - /// Получение типа выравнивания - /// - /// - /// - private static JustificationValues - GetJustificationValues(WordJustificationType type) - { - return type switch - { - WordJustificationType.Both => JustificationValues.Both, - WordJustificationType.Center => JustificationValues.Center, - _ => JustificationValues.Left, - }; - } - /// - /// Настройки страницы - /// - /// - 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) - { - 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 - }); - } - properties.AppendChild(paragraphMarkRunProperties); - return properties; - } - protected override void CreateWord(WordInfo 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) - { - return; - } - 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) - { - properties.AppendChild(new Bold()); - } - docRun.AppendChild(properties); - docRun.AppendChild(new Text - { - Text = run.Item1, - Space = - SpaceProcessingModeValues.Preserve - }); - docParagraph.AppendChild(docRun); - } - _docBody.AppendChild(docParagraph); - } - protected override void SaveWord(WordInfo info) - { - if (_docBody == null || _wordDocument == null) - { - return; - } - _docBody.AppendChild(CreateSectionProperties()); - _wordDocument.MainDocumentPart!.Document.Save(); - _wordDocument.Close(); - } - } -} + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + 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) + { + 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 }); + } + properties.AppendChild(paragraphMarkRunProperties); + + return properties; + } + + protected override void CreateWord(IDocument 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) + { + return; + } + 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) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + _docBody.AppendChild(docParagraph); + } + + protected override void SaveWord(IDocument info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Close(); + } + + private Table? _lastTable; + protected override void CreateTable(List columns) + { + if (_docBody == null) + return; + + _lastTable = new Table(); + + var tableProp = new TableProperties(); + tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); + tableProp.AppendChild(new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } + )); + tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); + _lastTable.AppendChild(tableProp); + + TableGrid tableGrid = new TableGrid(); + foreach (var column in columns) + { + tableGrid.AppendChild(new GridColumn() { Width = column }); + } + _lastTable.AppendChild(tableGrid); + + _docBody.AppendChild(_lastTable); + } + + protected override void CreateRow(WordRowParameters rowParameters) + { + if (_docBody == null || _lastTable == null) + return; + + TableRow docRow = new TableRow(); + foreach (var column in rowParameters.Texts) + { + var docParagraph = new Paragraph(); + WordParagraph paragraph = new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (column, rowParameters.TextProperties) }, + TextProperties = rowParameters.TextProperties + }; + + 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) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + TableCell docCell = new TableCell(); + docCell.AppendChild(docParagraph); + docRow.AppendChild(docCell); + } + _lastTable.AppendChild(docRow); + } + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IReportLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IReportLogic.cs index f8e90fb..d4faaf3 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IReportLogic.cs @@ -10,32 +10,16 @@ namespace JewelryStoreContracts.BusinessLogicsContracts { public interface IReportLogic { - /// - /// Получение списка компонент с указанием, в каких изделиях используются - /// - /// - List GetJewelComponent(); - /// - /// Получение списка заказов за определенный период - /// - /// - /// - List GetOrders(ReportBindingModel model); - /// - /// Сохранение изделий в файл-Word - /// - /// - void SaveJewelsToWordFile(ReportBindingModel model); - /// - /// Сохранение компонент с указаеним продуктов в файл-Excel - /// - /// - void SaveJewelComponentToExcelFile(ReportBindingModel model); - /// - /// Сохранение заказов в файл-Pdf - /// - /// - void SaveOrdersToPdfFile(ReportBindingModel model); - } + List GetPizzaComponents(); + List GetOrders(ReportBindingModel model); + List GetShops(); + List GetGroupedOrders(); + void SavePizzasToWordFile(ReportBindingModel model); + void SavePizzaComponentToExcelFile(ReportBindingModel model); + void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopsToExcelFile(ReportBindingModel model); + void SaveGroupedOrdersToPdfFile(ReportBindingModel model); + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportShopsViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportShopsViewModel.cs new file mode 100644 index 0000000..b0f48dc --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ReportShopsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class ReportShopsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Jewel, int count)> Pizzas { get; set; } = new(); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs index aada3b1..cc348e2 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs @@ -23,7 +23,7 @@ namespace JewelryStoreDatabaseImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.DateFrom.HasValue || !model.DateTo.HasValue ||!model.Id.HasValue) { return new(); } From 87cf069455caae32861f0734699144aadaa6d679 Mon Sep 17 00:00:00 2001 From: Alenka Date: Wed, 19 Jun 2024 00:13:02 +0400 Subject: [PATCH 10/10] =?UTF-8?q?=D0=96=D0=B5=D1=81=D1=82=D1=8C=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=D0=B0=D1=8F=20=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JewelryStore/FormMain.cs | 3 +- .../FormReportGroupedOrders.Designer.cs | 86 ++++ .../JewelryStore/FormReportGroupedOrders.cs | 80 ++++ .../JewelryStore/FormReportGroupedOrders.resx | 120 +++++ .../JewelryStore/FormReportShop.Designer.cs | 115 +++++ .../JewelryStore/FormReportShop.cs | 78 ++++ .../JewelryStore/FormReportShop.resx | 120 +++++ .../JewelryStore/Program.cs | 22 +- .../JewelryStore/ReportGroupedOrders.rdlc | 441 ++++++++++++++++++ .../BusinessLogics/ReportLogic.cs | 12 +- .../OfficePackage/AbstractSaveToExcel.cs | 212 ++++++--- .../OfficePackage/AbstractSaveToWord.cs | 6 +- .../OfficePackage/HelperModels/ExcelShop.cs | 3 +- .../HelperModels/WordRowParameters.cs | 14 + .../BusinessLogicsContracts/IReportLogic.cs | 6 +- .../ViewModels/ReportShopsViewModel.cs | 2 +- .../Implements/StoreStorage.cs | 20 +- .../Models/Store.cs | 8 +- 18 files changed, 1244 insertions(+), 104 deletions(-) create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.Designer.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.resx create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.Designer.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.cs create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.resx create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStore/ReportGroupedOrders.rdlc create mode 100644 PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs index f6dabdf..95319f8 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs @@ -5,6 +5,7 @@ using JewelryStoreDataModels.Enums; using JewelryStoreView; using Microsoft.Extensions.Logging; using System.Windows.Forms; +using PizzeriaView; namespace JewelryStore { @@ -191,7 +192,7 @@ namespace JewelryStore using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) { - _reportLogic.SavePizzasToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + _reportLogic.SaveJewelsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..f79dd7a --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,86 @@ +namespace PizzeriaView +{ + partial class FormReportGroupedOrders + { + /// + /// 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.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPDF); + this.panel.Controls.Add(this.buttonMake); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(970, 52); + this.panel.TabIndex = 1; + // + // buttonToPDF + // + this.buttonToPDF.Location = new System.Drawing.Point(486, 12); + this.buttonToPDF.Name = "buttonToPDF"; + this.buttonToPDF.Size = new System.Drawing.Size(411, 29); + 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(49, 12); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(377, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // FormReportGroupedOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(970, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportGroupedOrders"; + this.Text = "Отчёт по группированным заказам "; + this.panel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonToPDF; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.cs new file mode 100644 index 0000000..aa29713 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.cs @@ -0,0 +1,80 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupedOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetGroupedOrders(); + var source = new ReportDataSource("DataSetGroupedOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка группированных заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка группированных заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void buttonToPDF_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveGroupedOrdersToPdfFile(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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportGroupedOrders.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.Designer.cs new file mode 100644 index 0000000..540d9fd --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.Designer.cs @@ -0,0 +1,115 @@ +namespace PizzeriaView +{ + partial class FormReportShop + { + /// + /// 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.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnShop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnJewel = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(0, 6); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(223, 29); + this.buttonSaveToExcel.TabIndex = 3; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AllowUserToOrderColumns = true; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnShop, + this.ColumnJewel, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 47); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(598, 403); + this.dataGridView.TabIndex = 2; + // + // ColumnShop + // + this.ColumnShop.FillWeight = 130F; + this.ColumnShop.HeaderText = "Магазин"; + this.ColumnShop.MinimumWidth = 6; + this.ColumnShop.Name = "ColumnShop"; + this.ColumnShop.ReadOnly = true; + + // + this.ColumnJewel.FillWeight = 140F; + this.ColumnJewel.HeaderText = "Украшения"; + this.ColumnJewel.MinimumWidth = 6; + this.ColumnJewel.Name = "ColumnJewel"; + this.ColumnJewel.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.FillWeight = 90F; + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // FormReportShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(598, 450); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportShop"; + this.Text = "Наполненость магазинов"; + this.Load += new System.EventHandler(this.FormReportShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnJewel; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.cs new file mode 100644 index 0000000..a30f5a1 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.cs @@ -0,0 +1,78 @@ +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormReportShop : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShop(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShop_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShops(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Jewels) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + 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.SaveShopsToExcelFile(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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormReportShop.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs index 6124253..0e71b88 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs @@ -6,6 +6,9 @@ using NLog.Extensions.Logging; using JewelryStoreBusinessLogic.BusinessLogics; using JewelryStoreContracts.StoragesModels; using JewelryStoreListImplement.Implements; +using JewelryStoreBusinessLogic.OfficePackage.Implements; +using JewelryStoreBusinessLogic.OfficePackage; +using PizzeriaView; namespace JewelryStore { @@ -13,9 +16,7 @@ namespace JewelryStore { private static ServiceProvider? _serviceProvider; public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// + [STAThread] static void Main() { @@ -37,12 +38,17 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,7 +56,11 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/ReportGroupedOrders.rdlc b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..2ef2b88 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/ReportGroupedOrders.rdlc @@ -0,0 +1,441 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 20791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + PrecastConcretePlantContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + OrdersCount + System.Int32 + + + OrdersSum + System.Decimal + + + + PrecastConcretePlantContracts.ViewModels + ReportGroupOrdersViewModel + PrecastConcretePlantContracts.ViewModels.ReportGroupOrdersViewModel, PrecastConcretePlantContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Отчёт по заказам + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.90406cm + + + 3.97461cm + + + 3.65711cm + + + + + 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!OrdersCount.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersSum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetGroupedOrders + 1.88242cm + 2.68676cm + 1.2cm + 11.53578cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.29409cm + 8.06542cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!OrdersSum.Value, "DataSetGroupedOrders") + + + + + + + 3.29409cm + 10.70653cm + 0.6cm + 3.48072cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +