From 5f00d6e7e07155aa76c929db34fbe712661c7d96 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Sun, 31 Mar 2024 17:27:54 +0400 Subject: [PATCH 01/15] =?UTF-8?q?=D0=97=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B11=20=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=D0=BD=D1=83=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormAddTextile.Designer.cs | 144 ++++++++++++ GarmentFactory/FormAddTextile.cs | 109 ++++++++++ GarmentFactory/FormAddTextile.resx | 120 ++++++++++ GarmentFactory/FormMain.Designer.cs | 26 ++- GarmentFactory/FormMain.cs | 20 ++ GarmentFactory/FormShop.Designer.cs | 205 ++++++++++++++++++ GarmentFactory/FormShop.cs | 133 ++++++++++++ GarmentFactory/FormShop.resx | 129 +++++++++++ GarmentFactory/FormShops.Designer.cs | 116 ++++++++++ GarmentFactory/FormShops.cs | 115 ++++++++++ GarmentFactory/FormShops.resx | 120 ++++++++++ GarmentFactory/FormTextile.Designer.cs | 4 +- GarmentFactory/FormTextiles.Designer.cs | 3 + GarmentFactory/Program.cs | 5 + GarmentFactoryBusinessLogic/ShopLogic.cs | 189 ++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 22 ++ .../BindingModels/SupplyBindingModel.cs | 16 ++ .../BusinessLogicsContracts/IShopLogic.cs | 27 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 26 +++ GarmentFactoryDataModels/Models/IShopModel.cs | 17 ++ .../Models/ISupplyModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 113 ++++++++++ GarmentFactoryListImplement/Models/Shop.cs | 59 +++++ 26 files changed, 1764 insertions(+), 7 deletions(-) create mode 100644 GarmentFactory/FormAddTextile.Designer.cs create mode 100644 GarmentFactory/FormAddTextile.cs create mode 100644 GarmentFactory/FormAddTextile.resx create mode 100644 GarmentFactory/FormShop.Designer.cs create mode 100644 GarmentFactory/FormShop.cs create mode 100644 GarmentFactory/FormShop.resx create mode 100644 GarmentFactory/FormShops.Designer.cs create mode 100644 GarmentFactory/FormShops.cs create mode 100644 GarmentFactory/FormShops.resx create mode 100644 GarmentFactoryBusinessLogic/ShopLogic.cs create mode 100644 GarmentFactoryContracts/BindingModels/ShopBindingModel.cs create mode 100644 GarmentFactoryContracts/BindingModels/SupplyBindingModel.cs create mode 100644 GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 GarmentFactoryContracts/SearchModels/ShopSearchModel.cs create mode 100644 GarmentFactoryContracts/StoragesContracts/IShopStorage.cs create mode 100644 GarmentFactoryContracts/ViewModels/ShopViewModel.cs create mode 100644 GarmentFactoryDataModels/Models/IShopModel.cs create mode 100644 GarmentFactoryDataModels/Models/ISupplyModel.cs create mode 100644 GarmentFactoryListImplement/Implements/ShopStorage.cs create mode 100644 GarmentFactoryListImplement/Models/Shop.cs diff --git a/GarmentFactory/FormAddTextile.Designer.cs b/GarmentFactory/FormAddTextile.Designer.cs new file mode 100644 index 0000000..11c88bb --- /dev/null +++ b/GarmentFactory/FormAddTextile.Designer.cs @@ -0,0 +1,144 @@ +namespace GarmentFactoryView +{ + partial class FormAddTextile + { + /// + /// 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() + { + labelShop = new Label(); + labelCount = new Label(); + labelTextile = new Label(); + comboBoxShop = new ComboBox(); + textBoxCount = new TextBox(); + comboBoxTextile = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(38, 37); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(29, 123); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 3; + labelCount.Text = "Количество:"; + // + // labelTextile + // + labelTextile.AutoSize = true; + labelTextile.Location = new Point(38, 79); + labelTextile.Name = "labelTextile"; + labelTextile.Size = new Size(71, 20); + labelTextile.TabIndex = 2; + labelTextile.Text = "Изделие:"; + // + // comboBoxShop + // + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(140, 37); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(262, 28); + comboBoxShop.TabIndex = 11; + // + // textBoxCount + // + textBoxCount.Location = new Point(140, 123); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(262, 27); + textBoxCount.TabIndex = 10; + // + // comboBoxTextile + // + comboBoxTextile.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTextile.FormattingEnabled = true; + comboBoxTextile.Location = new Point(140, 79); + comboBoxTextile.Name = "comboBoxTextile"; + comboBoxTextile.Size = new Size(262, 28); + comboBoxTextile.TabIndex = 9; + // + // buttonCancel + // + buttonCancel.Location = new Point(342, 181); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 13; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(242, 181); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 12; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormAddTextile + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(455, 222); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxShop); + Controls.Add(textBoxCount); + Controls.Add(comboBoxTextile); + Controls.Add(labelCount); + Controls.Add(labelTextile); + Controls.Add(labelShop); + Name = "FormAddTextile"; + Text = "Пополнение магазина"; + Load += FormAddTextile_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private Label labelCount; + private Label labelTextile; + private ComboBox comboBoxShop; + private TextBox textBoxCount; + private ComboBox comboBoxTextile; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormAddTextile.cs b/GarmentFactory/FormAddTextile.cs new file mode 100644 index 0000000..d234f54 --- /dev/null +++ b/GarmentFactory/FormAddTextile.cs @@ -0,0 +1,109 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.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 GarmentFactoryView +{ + public partial class FormAddTextile : Form + { + private readonly ILogger _logger; + private readonly ITextileLogic _logicT; + private readonly IShopLogic _logicS; + //Списки для ComboBox + private List _shopList = new List(); + private List _textileList = new List(); + public FormAddTextile(ILogger logger, ITextileLogic logicT, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicT = logicT; + _logicS = logicS; + } + + private void FormAddTextile_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _textileList = _logicT.ReadList(null); + + _logger.LogInformation("Загрузка списка магазинов при пополнении"); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + } + + _logger.LogInformation("Загрузка списка товаров при пополнении"); + if (_textileList != null) + { + comboBoxTextile.DisplayMember = "TextileName"; + comboBoxTextile.ValueMember = "Id"; + comboBoxTextile.DataSource = _textileList; + comboBoxTextile.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxTextile.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле \"Количество\"", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Пополнение магазина"); + try + { + var operationResult = _logicS.AddTextile(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + TextileId = Convert.ToInt32(comboBoxTextile.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/GarmentFactory/FormAddTextile.resx b/GarmentFactory/FormAddTextile.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/FormAddTextile.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/GarmentFactory/FormMain.Designer.cs b/GarmentFactory/FormMain.Designer.cs index 7b3dbfb..ddc02c3 100644 --- a/GarmentFactory/FormMain.Designer.cs +++ b/GarmentFactory/FormMain.Designer.cs @@ -38,6 +38,8 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); текстилиToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -116,7 +118,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1169, 28); @@ -125,7 +127,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem, магазиныToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -133,17 +135,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // текстилиToolStripMenuItem // текстилиToolStripMenuItem.Name = "текстилиToolStripMenuItem"; - текстилиToolStripMenuItem.Size = new Size(182, 26); + текстилиToolStripMenuItem.Size = new Size(224, 26); текстилиToolStripMenuItem.Text = "Текстили"; текстилиToolStripMenuItem.Click += текстилиToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -179,5 +195,7 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem текстилиToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/GarmentFactory/FormMain.cs b/GarmentFactory/FormMain.cs index b921a1c..41ce8b7 100644 --- a/GarmentFactory/FormMain.cs +++ b/GarmentFactory/FormMain.cs @@ -68,6 +68,26 @@ namespace GarmentFactoryView } } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile)); + + if (service is FormAddTextile form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/GarmentFactory/FormShop.Designer.cs b/GarmentFactory/FormShop.Designer.cs new file mode 100644 index 0000000..b21893c --- /dev/null +++ b/GarmentFactory/FormShop.Designer.cs @@ -0,0 +1,205 @@ +namespace GarmentFactoryView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelAddress = new Label(); + labelDateOpen = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + groupBoxTextiles = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ColumnTextileName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonSave = new Button(); + groupBoxTextiles.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(30, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 0; + labelName.Text = "Название: "; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(40, 71); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(58, 20); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес: "; + // + // labelDateOpen + // + labelDateOpen.AutoSize = true; + labelDateOpen.Location = new Point(12, 118); + labelDateOpen.Name = "labelDateOpen"; + labelDateOpen.Size = new Size(117, 20); + labelDateOpen.TabIndex = 2; + labelDateOpen.Text = "Дата открытия: "; + // + // textBoxName + // + textBoxName.Location = new Point(135, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(243, 27); + textBoxName.TabIndex = 3; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(135, 68); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(243, 27); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(135, 113); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(243, 27); + dateTimePicker.TabIndex = 5; + // + // groupBoxTextiles + // + groupBoxTextiles.Controls.Add(dataGridView); + groupBoxTextiles.Location = new Point(12, 184); + groupBoxTextiles.Name = "groupBoxTextiles"; + groupBoxTextiles.Size = new Size(651, 306); + groupBoxTextiles.TabIndex = 6; + groupBoxTextiles.TabStop = false; + groupBoxTextiles.Text = "Изделия"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnTextileName, ColumnCount }); + dataGridView.Location = new Point(6, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(633, 274); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "ID"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.ReadOnly = true; + ID.Visible = false; + // + // ColumnTextileName + // + ColumnTextileName.HeaderText = "Изделие"; + ColumnTextileName.MinimumWidth = 6; + ColumnTextileName.Name = "ColumnTextileName"; + ColumnTextileName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // buttonCancel + // + buttonCancel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + buttonCancel.Location = new Point(544, 521); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(103, 40); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + buttonSave.Location = new Point(426, 521); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(103, 40); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(682, 584); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxTextiles); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelDateOpen); + Controls.Add(labelAddress); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxTextiles.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private Label labelDateOpen; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private GroupBox groupBoxTextiles; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnTextileName; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormShop.cs b/GarmentFactory/FormShop.cs new file mode 100644 index 0000000..b09ef63 --- /dev/null +++ b/GarmentFactory/FormShop.cs @@ -0,0 +1,133 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryDataModels.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 GarmentFactoryView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + private Dictionary _shopTextiles; + + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopTextiles = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address.ToString(); + dateTimePicker.Value = view.DateOpen; + _shopTextiles = view.ShopTextiles ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_shopTextiles != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _shopTextiles) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.TextileName, element.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий в магазине"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = dateTimePicker.Value.Date, + ShopTextiles = _shopTextiles + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/GarmentFactory/FormShop.resx b/GarmentFactory/FormShop.resx new file mode 100644 index 0000000..bc99676 --- /dev/null +++ b/GarmentFactory/FormShop.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/GarmentFactory/FormShops.Designer.cs b/GarmentFactory/FormShops.Designer.cs new file mode 100644 index 0000000..1b50209 --- /dev/null +++ b/GarmentFactory/FormShops.Designer.cs @@ -0,0 +1,116 @@ +namespace GarmentFactoryView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(-3, -4); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(640, 455); + dataGridView.TabIndex = 0; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(658, 252); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(120, 40); + buttonRefresh.TabIndex = 12; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(658, 183); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(120, 40); + buttonDelete.TabIndex = 11; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(658, 115); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(120, 40); + buttonUpdate.TabIndex = 10; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(658, 50); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(120, 40); + buttonAdd.TabIndex = 9; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormShops.cs b/GarmentFactory/FormShops.cs new file mode 100644 index 0000000..f8c95d5 --- /dev/null +++ b/GarmentFactory/FormShops.cs @@ -0,0 +1,115 @@ +using GarmentFactory; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.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 GarmentFactoryView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopTextiles"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GarmentFactory/FormShops.resx b/GarmentFactory/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GarmentFactory/FormTextile.Designer.cs b/GarmentFactory/FormTextile.Designer.cs index 5121014..19d22f8 100644 --- a/GarmentFactory/FormTextile.Designer.cs +++ b/GarmentFactory/FormTextile.Designer.cs @@ -138,6 +138,7 @@ // dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3 }); dataGridView.Dock = DockStyle.Left; @@ -159,7 +160,6 @@ Column1.Name = "Column1"; Column1.ReadOnly = true; Column1.Visible = false; - Column1.Width = 125; // // Column2 // @@ -167,7 +167,6 @@ Column2.MinimumWidth = 6; Column2.Name = "Column2"; Column2.ReadOnly = true; - Column2.Width = 125; // // Column3 // @@ -175,7 +174,6 @@ Column3.MinimumWidth = 6; Column3.Name = "Column3"; Column3.ReadOnly = true; - Column3.Width = 125; // // buttonSave // diff --git a/GarmentFactory/FormTextiles.Designer.cs b/GarmentFactory/FormTextiles.Designer.cs index 6b41417..a134efe 100644 --- a/GarmentFactory/FormTextiles.Designer.cs +++ b/GarmentFactory/FormTextiles.Designer.cs @@ -38,6 +38,9 @@ // // dataGridView // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(0, 0); diff --git a/GarmentFactory/Program.cs b/GarmentFactory/Program.cs index 2ff30d3..711a357 100644 --- a/GarmentFactory/Program.cs +++ b/GarmentFactory/Program.cs @@ -48,6 +48,11 @@ namespace GarmentFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/GarmentFactoryBusinessLogic/ShopLogic.cs b/GarmentFactoryBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..0e30de2 --- /dev/null +++ b/GarmentFactoryBusinessLogic/ShopLogic.cs @@ -0,0 +1,189 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + // Хранилище всех магазинов + private readonly IShopStorage _shopStorage; + + private readonly ITextileStorage _textileStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, ITextileStorage textileStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _textileStorage = textileStorage; + } + + // Чтение конкретного магазина + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + // Чтение всех магазинов + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + // Создание магазина + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + // Обновление магазина + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + // Удаление магазина + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + return true; + } + + // Пополнение магазина + public bool AddTextile(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0"); + } + + var shop = _shopStorage.GetElement(new ShopSearchModel{ Id = model.ShopId }); + + if (shop == null) + { + throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден"); + } + + // Если такой товар есть, то прибавление переданного кол-ва + if (shop.ShopTextiles.ContainsKey(model.TextileId)) + { + var oldValue = shop.ShopTextiles[model.TextileId]; + oldValue.Item2 += model.Count; + shop.ShopTextiles[model.TextileId] = oldValue; + } + // Если такого товара нет, то кол-во такого товара равно переданному кол-ву + else + { + var textile = _textileStorage.GetElement(new TextileSearchModel{ Id = model.TextileId }); + if (textile == null) + { + throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден"); + } + shop.ShopTextiles.Add(model.TextileId, (textile, model.Count)); + } + return true; + } + + + + // Проверка данных магазина при добавлении/удалении/обновлении + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + // При удалении проверка дальше не нужна + if (!withParams) + { + return; + } + + // Проверка наличия названия + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Отсутствует название магазина", nameof(model.ShopName)); + } + + // Проверка наличия адреса + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address)); + } + + _logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + + var element = _shopStorage.GetElement(new ShopSearchModel { ShopName = model.ShopName }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs b/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..65eb932 --- /dev/null +++ b/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,22 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary ShopTextiles { get; set; } = new(); + + } +} diff --git a/GarmentFactoryContracts/BindingModels/SupplyBindingModel.cs b/GarmentFactoryContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..ba10711 --- /dev/null +++ b/GarmentFactoryContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int TextileId { get; set; } + public int Count { get; set; } + } +} diff --git a/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..034e475 --- /dev/null +++ b/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,27 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool AddTextile(SupplyBindingModel model); + } +} diff --git a/GarmentFactoryContracts/SearchModels/ShopSearchModel.cs b/GarmentFactoryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..a04e63f --- /dev/null +++ b/GarmentFactoryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs b/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..cad0d17 --- /dev/null +++ b/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/GarmentFactoryContracts/ViewModels/ShopViewModel.cs b/GarmentFactoryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..2645018 --- /dev/null +++ b/GarmentFactoryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,26 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary ShopTextiles { get; set; } = new(); + } +} diff --git a/GarmentFactoryDataModels/Models/IShopModel.cs b/GarmentFactoryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..23646ea --- /dev/null +++ b/GarmentFactoryDataModels/Models/IShopModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + //Изделия в магазине + Dictionary ShopTextiles { get; } + } +} diff --git a/GarmentFactoryDataModels/Models/ISupplyModel.cs b/GarmentFactoryDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..88c2137 --- /dev/null +++ b/GarmentFactoryDataModels/Models/ISupplyModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + //Сущность для связи многие-ко-многим между товарами и магазинами + public class ISupplyModel + { + int ShopId { get; } + int TextileId { get; } + int Count { get; } + } +} diff --git a/GarmentFactoryListImplement/DataListSingleton.cs b/GarmentFactoryListImplement/DataListSingleton.cs index 2ae53af..a3e0efb 100644 --- a/GarmentFactoryListImplement/DataListSingleton.cs +++ b/GarmentFactoryListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace GarmentFactoryListImplement public List Components { get; set; } public List Orders { get; set; } public List Textiles { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Textiles = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/GarmentFactoryListImplement/Implements/ShopStorage.cs b/GarmentFactoryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..a5442ac --- /dev/null +++ b/GarmentFactoryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,113 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/GarmentFactoryListImplement/Models/Shop.cs b/GarmentFactoryListImplement/Models/Shop.cs new file mode 100644 index 0000000..c3911ad --- /dev/null +++ b/GarmentFactoryListImplement/Models/Shop.cs @@ -0,0 +1,59 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpen { get; private set; } + + public Dictionary ShopTextiles { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopTextiles = model.ShopTextiles + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopTextiles = model.ShopTextiles; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopTextiles = ShopTextiles + }; + } +} From 541f31e3a986ff9a2e5cc43f1baa9efc45bd1ff4 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Wed, 17 Apr 2024 11:10:09 +0400 Subject: [PATCH 02/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=201=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 GarmentFactoryFileImplement/Implements/ShopStorage.cs diff --git a/GarmentFactoryFileImplement/Implements/ShopStorage.cs b/GarmentFactoryFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..bf3d4f3 --- /dev/null +++ b/GarmentFactoryFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,14 @@ +using GarmentFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + + } +} From d7a6317852dbcfcfc9b0a61af4bbbeca2ea79a29 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Wed, 24 Apr 2024 21:43:43 +0400 Subject: [PATCH 03/15] =?UTF-8?q?=D0=9D=D0=95=20=D0=94=D0=9E=D0=94=D0=95?= =?UTF-8?q?=D0=9B=D0=90=D0=9B=20=D0=9B=D0=90=D0=91=202=20=D0=A3=D0=A1?= =?UTF-8?q?=D0=9B=D0=9E=D0=96=D0=9D=D0=81=D0=9D=D0=9D=D0=A3=D0=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormMain.Designer.cs | 404 +++++++++-------- GarmentFactory/FormMain.cs | 303 +++++++------ GarmentFactory/FormSellTextile.Designer.cs | 119 +++++ GarmentFactory/FormSellTextile.cs | 87 ++++ GarmentFactory/FormSellTextile.resx | 120 +++++ GarmentFactory/FormShop.Designer.cs | 419 ++++++++++-------- GarmentFactory/FormShop.cs | 212 ++++----- GarmentFactory/Program.cs | 3 +- GarmentFactoryBusinessLogic/OrderLogic.cs | 27 +- GarmentFactoryBusinessLogic/ShopLogic.cs | 20 +- .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 2 + .../SearchModels/SupplySearchModel.cs | 14 + .../StoragesContracts/IShopStorage.cs | 3 + .../ViewModels/ShopViewModel.cs | 5 +- GarmentFactoryDataModels/Models/IShopModel.cs | 4 +- .../DataFileSingleton.cs | 13 +- .../Implements/ShopStorage.cs | 152 ++++++- GarmentFactoryFileImplement/Models/Shop.cs | 111 +++++ .../Implements/ShopStorage.cs | 12 +- GarmentFactoryListImplement/Models/Shop.cs | 17 +- 21 files changed, 1380 insertions(+), 668 deletions(-) create mode 100644 GarmentFactory/FormSellTextile.Designer.cs create mode 100644 GarmentFactory/FormSellTextile.cs create mode 100644 GarmentFactory/FormSellTextile.resx create mode 100644 GarmentFactoryContracts/SearchModels/SupplySearchModel.cs create mode 100644 GarmentFactoryFileImplement/Models/Shop.cs diff --git a/GarmentFactory/FormMain.Designer.cs b/GarmentFactory/FormMain.Designer.cs index ddc02c3..62b7269 100644 --- a/GarmentFactory/FormMain.Designer.cs +++ b/GarmentFactory/FormMain.Designer.cs @@ -1,201 +1,219 @@ namespace GarmentFactoryView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonCompletedOrder = new Button(); - buttonRefresh = new Button(); - menuStrip1 = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - текстилиToolStripMenuItem = new ToolStripMenuItem(); - магазиныToolStripMenuItem = new ToolStripMenuItem(); - пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - menuStrip1.SuspendLayout(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 31); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(950, 425); - dataGridView.TabIndex = 0; - // - // buttonCreateOrder - // - buttonCreateOrder.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonCreateOrder.Location = new Point(977, 80); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(180, 40); - buttonCreateOrder.TabIndex = 1; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonTakeOrderInWork.Location = new Point(977, 147); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(180, 40); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonOrderReady.Location = new Point(977, 217); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(180, 40); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonCompletedOrder - // - buttonCompletedOrder.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonCompletedOrder.Location = new Point(977, 285); - buttonCompletedOrder.Name = "buttonCompletedOrder"; - buttonCompletedOrder.Size = new Size(180, 40); - buttonCompletedOrder.TabIndex = 4; - buttonCompletedOrder.Text = "Заказ выдан"; - buttonCompletedOrder.UseVisualStyleBackColor = true; - buttonCompletedOrder.Click += ButtonCompletedOrder_Click; - // - // buttonRefresh - // - buttonRefresh.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonRefresh.Location = new Point(977, 363); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(180, 40); - buttonRefresh.TabIndex = 5; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1169, 28); - menuStrip1.TabIndex = 7; - menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem, магазиныToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(117, 24); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; - // - // текстилиToolStripMenuItem - // - текстилиToolStripMenuItem.Name = "текстилиToolStripMenuItem"; - текстилиToolStripMenuItem.Size = new Size(224, 26); - текстилиToolStripMenuItem.Text = "Текстили"; - текстилиToolStripMenuItem.Click += текстилиToolStripMenuItem_Click; - // - // магазиныToolStripMenuItem - // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(224, 26); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; - // - // пополнениеМагазинаToolStripMenuItem - // - пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; - пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); - пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; - пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1169, 453); - Controls.Add(menuStrip1); - Controls.Add(buttonRefresh); - Controls.Add(buttonCompletedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - MainMenuStrip = menuStrip1; - Name = "FormMain"; - Text = "Швейная фабрика"; - Load += FormMain_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonCompletedOrder = new Button(); + buttonRefresh = new Button(); + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + текстилиToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem1 = new ToolStripMenuItem(); + продажаТовараToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 31); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(950, 425); + dataGridView.TabIndex = 0; + // + // buttonCreateOrder + // + buttonCreateOrder.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonCreateOrder.Location = new Point(977, 80); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(180, 40); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonTakeOrderInWork.Location = new Point(977, 147); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(180, 40); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonOrderReady.Location = new Point(977, 217); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(180, 40); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonCompletedOrder + // + buttonCompletedOrder.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonCompletedOrder.Location = new Point(977, 285); + buttonCompletedOrder.Name = "buttonCompletedOrder"; + buttonCompletedOrder.Size = new Size(180, 40); + buttonCompletedOrder.TabIndex = 4; + buttonCompletedOrder.Text = "Заказ выдан"; + buttonCompletedOrder.UseVisualStyleBackColor = true; + buttonCompletedOrder.Click += ButtonCompletedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonRefresh.Location = new Point(977, 363); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(180, 40); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1169, 28); + menuStrip1.TabIndex = 7; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem, магазиныToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // текстилиToolStripMenuItem + // + текстилиToolStripMenuItem.Name = "текстилиToolStripMenuItem"; + текстилиToolStripMenuItem.Size = new Size(182, 26); + текстилиToolStripMenuItem.Text = "Текстили"; + текстилиToolStripMenuItem.Click += текстилиToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(182, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { пополнениеМагазинаToolStripMenuItem1, продажаТовараToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Text = "Операции"; + // + // пополнениеМагазинаToolStripMenuItem1 + // + пополнениеМагазинаToolStripMenuItem1.Name = "пополнениеМагазинаToolStripMenuItem1"; + пополнениеМагазинаToolStripMenuItem1.Size = new Size(251, 26); + пополнениеМагазинаToolStripMenuItem1.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem1.Click += пополнениеМагазинаToolStripMenuItem1_Click; + // + // продажаТовараToolStripMenuItem + // + продажаТовараToolStripMenuItem.Name = "продажаТовараToolStripMenuItem"; + продажаТовараToolStripMenuItem.Size = new Size(251, 26); + продажаТовараToolStripMenuItem.Text = "Продажа товара"; + продажаТовараToolStripMenuItem.Click += продажаТовараToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1169, 453); + Controls.Add(menuStrip1); + Controls.Add(buttonRefresh); + Controls.Add(buttonCompletedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Швейная фабрика"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonCompletedOrder; - private Button buttonRefresh; - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem текстилиToolStripMenuItem; - private ToolStripMenuItem магазиныToolStripMenuItem; - private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; - } + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonCompletedOrder; + private Button buttonRefresh; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem текстилиToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem1; + private ToolStripMenuItem продажаТовараToolStripMenuItem; + } } \ No newline at end of file diff --git a/GarmentFactory/FormMain.cs b/GarmentFactory/FormMain.cs index 41ce8b7..310a9f8 100644 --- a/GarmentFactory/FormMain.cs +++ b/GarmentFactory/FormMain.cs @@ -14,159 +14,168 @@ using System.Windows.Forms; namespace GarmentFactoryView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["TextileId"].Visible = false; - dataGridView.Columns["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["TextileId"].Visible = false; + dataGridView.Columns["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } - private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } - } + } - private void текстилиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormTextiles)); - if (service is FormTextiles form) - { - form.ShowDialog(); - } - } + private void текстилиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTextiles)); + if (service is FormTextiles form) + { + form.ShowDialog(); + } + } - private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } + if (service is FormShops form) + { + form.ShowDialog(); + } + } - private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile)); + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonCompletedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } - if (service is FormAddTextile form) - { - form.ShowDialog(); - } - } + private void пополнениеМагазинаToolStripMenuItem1_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile)); - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonCompletedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRefresh_Click(object sender, EventArgs e) - { - LoadData(); - } - } + if (service is FormAddTextile form) + { + form.ShowDialog(); + } + } + + private void продажаТовараToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellTextile)); + if (service is FormSellTextile form) + { + form.ShowDialog(); + } + } + } } diff --git a/GarmentFactory/FormSellTextile.Designer.cs b/GarmentFactory/FormSellTextile.Designer.cs new file mode 100644 index 0000000..c21f0f5 --- /dev/null +++ b/GarmentFactory/FormSellTextile.Designer.cs @@ -0,0 +1,119 @@ +namespace GarmentFactoryView +{ + partial class FormSellTextile + { + /// + /// 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() + { + labelTextile = new Label(); + comboBoxTextile = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonSell = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelTextile + // + labelTextile.AutoSize = true; + labelTextile.Location = new Point(12, 14); + labelTextile.Name = "labelTextile"; + labelTextile.Size = new Size(77, 20); + labelTextile.TabIndex = 0; + labelTextile.Text = "Текстиль: "; + // + // comboBoxTextile + // + comboBoxTextile.FormattingEnabled = true; + comboBoxTextile.Location = new Point(115, 11); + comboBoxTextile.Name = "comboBoxTextile"; + comboBoxTextile.Size = new Size(239, 28); + comboBoxTextile.TabIndex = 1; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 55); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество: "; + // + // textBoxCount + // + textBoxCount.Location = new Point(115, 52); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(239, 27); + textBoxCount.TabIndex = 3; + // + // buttonSell + // + buttonSell.Location = new Point(128, 99); + buttonSell.Name = "buttonSell"; + buttonSell.Size = new Size(94, 29); + buttonSell.TabIndex = 4; + buttonSell.Text = "Продать"; + buttonSell.UseVisualStyleBackColor = true; + buttonSell.Click += ButtonSell_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(242, 99); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSellTextile + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(366, 140); + Controls.Add(buttonCancel); + Controls.Add(buttonSell); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxTextile); + Controls.Add(labelTextile); + Name = "FormSellTextile"; + Text = "Продажа текстиля"; + Load += FormSellingTextile_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelTextile; + private ComboBox comboBoxTextile; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormSellTextile.cs b/GarmentFactory/FormSellTextile.cs new file mode 100644 index 0000000..b2a8705 --- /dev/null +++ b/GarmentFactory/FormSellTextile.cs @@ -0,0 +1,87 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.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 GarmentFactoryView +{ + public partial class FormSellTextile : Form + { + private readonly ILogger _logger; + private readonly ITextileLogic _logicT; + private readonly IShopLogic _logicS; + private List _TextileList = new List(); + + public FormSellTextile(ILogger logger, ITextileLogic logicT, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicT = logicT; + _logicS = logicS; + } + + private void FormSellingTextile_Load(object sender, EventArgs e) + { + _TextileList = _logicT.ReadList(null); + if (_TextileList != null) + { + comboBoxTextile.DisplayMember = "TextileName"; + comboBoxTextile.ValueMember = "Id"; + comboBoxTextile.DataSource = _TextileList; + comboBoxTextile.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для продажи"); + } + } + + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxTextile.SelectedValue == null) + { + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание покупки"); + try + { + bool resout = _logicS.Sell(new SupplySearchModel + { + TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (resout) + { + _logger.LogInformation("Проверка была выполнена"); + MessageBox.Show("Продажа выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + else + { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть выполнена.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + 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/GarmentFactory/FormSellTextile.resx b/GarmentFactory/FormSellTextile.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/FormSellTextile.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/GarmentFactory/FormShop.Designer.cs b/GarmentFactory/FormShop.Designer.cs index b21893c..3e1c300 100644 --- a/GarmentFactory/FormShop.Designer.cs +++ b/GarmentFactory/FormShop.Designer.cs @@ -1,205 +1,230 @@ namespace GarmentFactoryView { - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// 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 + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - labelName = new Label(); - labelAddress = new Label(); - labelDateOpen = new Label(); - textBoxName = new TextBox(); - textBoxAddress = new TextBox(); - dateTimePicker = new DateTimePicker(); - groupBoxTextiles = new GroupBox(); - dataGridView = new DataGridView(); - ID = new DataGridViewTextBoxColumn(); - ColumnTextileName = new DataGridViewTextBoxColumn(); - ColumnCount = new DataGridViewTextBoxColumn(); - buttonCancel = new Button(); - buttonSave = new Button(); - groupBoxTextiles.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(30, 21); - labelName.Name = "labelName"; - labelName.Size = new Size(84, 20); - labelName.TabIndex = 0; - labelName.Text = "Название: "; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(40, 71); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(58, 20); - labelAddress.TabIndex = 1; - labelAddress.Text = "Адрес: "; - // - // labelDateOpen - // - labelDateOpen.AutoSize = true; - labelDateOpen.Location = new Point(12, 118); - labelDateOpen.Name = "labelDateOpen"; - labelDateOpen.Size = new Size(117, 20); - labelDateOpen.TabIndex = 2; - labelDateOpen.Text = "Дата открытия: "; - // - // textBoxName - // - textBoxName.Location = new Point(135, 21); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(243, 27); - textBoxName.TabIndex = 3; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(135, 68); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(243, 27); - textBoxAddress.TabIndex = 4; - // - // dateTimePicker - // - dateTimePicker.Location = new Point(135, 113); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(243, 27); - dateTimePicker.TabIndex = 5; - // - // groupBoxTextiles - // - groupBoxTextiles.Controls.Add(dataGridView); - groupBoxTextiles.Location = new Point(12, 184); - groupBoxTextiles.Name = "groupBoxTextiles"; - groupBoxTextiles.Size = new Size(651, 306); - groupBoxTextiles.TabIndex = 6; - groupBoxTextiles.TabStop = false; - groupBoxTextiles.Text = "Изделия"; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnTextileName, ColumnCount }); - dataGridView.Location = new Point(6, 26); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(633, 274); - dataGridView.TabIndex = 0; - // - // ID - // - ID.HeaderText = "ID"; - ID.MinimumWidth = 6; - ID.Name = "ID"; - ID.ReadOnly = true; - ID.Visible = false; - // - // ColumnTextileName - // - ColumnTextileName.HeaderText = "Изделие"; - ColumnTextileName.MinimumWidth = 6; - ColumnTextileName.Name = "ColumnTextileName"; - ColumnTextileName.ReadOnly = true; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.MinimumWidth = 6; - ColumnCount.Name = "ColumnCount"; - ColumnCount.ReadOnly = true; - // - // buttonCancel - // - buttonCancel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - buttonCancel.Location = new Point(544, 521); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(103, 40); - buttonCancel.TabIndex = 9; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // buttonSave - // - buttonSave.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - buttonSave.Location = new Point(426, 521); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(103, 40); - buttonSave.TabIndex = 8; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // FormShop - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(682, 584); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(groupBoxTextiles); - Controls.Add(dateTimePicker); - Controls.Add(textBoxAddress); - Controls.Add(textBoxName); - Controls.Add(labelDateOpen); - Controls.Add(labelAddress); - Controls.Add(labelName); - Name = "FormShop"; - Text = "Магазин"; - Load += FormShop_Load; - groupBoxTextiles.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelAddress = new Label(); + labelDateOpen = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + groupBoxTextiles = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ColumnTextileName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonSave = new Button(); + numericUpTextileMaxCount = new NumericUpDown(); + label2 = new Label(); + groupBoxTextiles.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpTextileMaxCount).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(30, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 0; + labelName.Text = "Название: "; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(40, 71); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(58, 20); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес: "; + // + // labelDateOpen + // + labelDateOpen.AutoSize = true; + labelDateOpen.Location = new Point(12, 118); + labelDateOpen.Name = "labelDateOpen"; + labelDateOpen.Size = new Size(117, 20); + labelDateOpen.TabIndex = 2; + labelDateOpen.Text = "Дата открытия: "; + // + // textBoxName + // + textBoxName.Location = new Point(135, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(243, 27); + textBoxName.TabIndex = 3; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(135, 68); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(243, 27); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(135, 113); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(243, 27); + dateTimePicker.TabIndex = 5; + // + // groupBoxTextiles + // + groupBoxTextiles.Controls.Add(dataGridView); + groupBoxTextiles.Location = new Point(12, 209); + groupBoxTextiles.Name = "groupBoxTextiles"; + groupBoxTextiles.Size = new Size(651, 306); + groupBoxTextiles.TabIndex = 6; + groupBoxTextiles.TabStop = false; + groupBoxTextiles.Text = "Изделия"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnTextileName, ColumnCount }); + dataGridView.Location = new Point(6, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(633, 274); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "ID"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.ReadOnly = true; + ID.Visible = false; + // + // ColumnTextileName + // + ColumnTextileName.HeaderText = "Изделие"; + ColumnTextileName.MinimumWidth = 6; + ColumnTextileName.Name = "ColumnTextileName"; + ColumnTextileName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // buttonCancel + // + buttonCancel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + buttonCancel.Location = new Point(550, 532); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(103, 40); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + buttonSave.Location = new Point(432, 532); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(103, 40); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // numericUpTextileMaxCount + // + numericUpTextileMaxCount.Location = new Point(135, 163); + numericUpTextileMaxCount.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); + numericUpTextileMaxCount.Name = "numericUpTextileMaxCount"; + numericUpTextileMaxCount.Size = new Size(243, 27); + numericUpTextileMaxCount.TabIndex = 13; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(19, 165); + label2.Name = "label2"; + label2.Size = new Size(103, 20); + label2.TabIndex = 12; + label2.Text = "Вместимость:"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(682, 584); + Controls.Add(numericUpTextileMaxCount); + Controls.Add(label2); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxTextiles); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelDateOpen); + Controls.Add(labelAddress); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxTextiles.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpTextileMaxCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Label labelName; - private Label labelAddress; - private Label labelDateOpen; - private TextBox textBoxName; - private TextBox textBoxAddress; - private DateTimePicker dateTimePicker; - private GroupBox groupBoxTextiles; - private DataGridView dataGridView; - private DataGridViewTextBoxColumn ID; - private DataGridViewTextBoxColumn ColumnTextileName; - private DataGridViewTextBoxColumn ColumnCount; - private Button buttonCancel; - private Button buttonSave; - } + private Label labelName; + private Label labelAddress; + private Label labelDateOpen; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private GroupBox groupBoxTextiles; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnTextileName; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonCancel; + private Button buttonSave; + private NumericUpDown numericUpTextileMaxCount; + private Label label2; + } } \ No newline at end of file diff --git a/GarmentFactory/FormShop.cs b/GarmentFactory/FormShop.cs index b09ef63..62a748c 100644 --- a/GarmentFactory/FormShop.cs +++ b/GarmentFactory/FormShop.cs @@ -15,119 +15,121 @@ using System.Windows.Forms; namespace GarmentFactoryView { - public partial class FormShop : Form - { - private readonly ILogger _logger; + public partial class FormShop : Form + { + private readonly ILogger _logger; - private readonly IShopLogic _logic; + private readonly IShopLogic _logic; - private int? _id; + private int? _id; - public int Id { set { _id = value; } } + public int Id { set { _id = value; } } - private Dictionary _shopTextiles; + private Dictionary _shopTextiles; - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _shopTextiles = new Dictionary(); - } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopTextiles = new Dictionary(); + } - private void FormShop_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Загрузка магазина"); - try - { - var view = _logic.ReadElement(new ShopSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxName.Text = view.ShopName; - textBoxAddress.Text = view.Address.ToString(); - dateTimePicker.Value = view.DateOpen; - _shopTextiles = view.ShopTextiles ?? new Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address.ToString(); + dateTimePicker.Value = view.DateOpen; + numericUpTextileMaxCount.Value = view.TextileMaxCount; + _shopTextiles = view.ShopTextiles ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - private void LoadData() - { - _logger.LogInformation("Загрузка изделий в магазине"); - try - { - if (_shopTextiles != null) - { - dataGridView.Rows.Clear(); - foreach (var element in _shopTextiles) - { - dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.TextileName, element.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки изделий в магазине"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_shopTextiles != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _shopTextiles) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.TextileName, element.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий в магазине"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxAddress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение магазина"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Address = textBoxAddress.Text, - DateOpen = dateTimePicker.Value.Date, - ShopTextiles = _shopTextiles - }; - var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка сохранения магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = dateTimePicker.Value.Date, + ShopTextiles = _shopTextiles, + TextileMaxCount = (int)numericUpTextileMaxCount.Value + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } diff --git a/GarmentFactory/Program.cs b/GarmentFactory/Program.cs index 695fa21..68b4b94 100644 --- a/GarmentFactory/Program.cs +++ b/GarmentFactory/Program.cs @@ -55,6 +55,7 @@ namespace GarmentFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } } } \ No newline at end of file diff --git a/GarmentFactoryBusinessLogic/OrderLogic.cs b/GarmentFactoryBusinessLogic/OrderLogic.cs index 37c087a..f0556fc 100644 --- a/GarmentFactoryBusinessLogic/OrderLogic.cs +++ b/GarmentFactoryBusinessLogic/OrderLogic.cs @@ -19,14 +19,16 @@ namespace GarmentFactoryBusinessLogic private readonly ILogger _logger; //Хранение всех заказов private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } + private readonly IShopStorage _shopStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) + { + _logger = logger; + _orderStorage = orderStorage; + _shopStorage = shopStorage; + } - //Чтение всего списка заказов - public List? ReadList(OrderSearchModel? model) + //Чтение всего списка заказов + public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); @@ -133,7 +135,16 @@ namespace GarmentFactoryBusinessLogic //Перевод заказа в состояние выдачи (окончательное завершение) public bool DeliveryOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выдан); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockShops(new SupplyBindingModel { TextileId = order.TextileId, Count = order.Count })) + { + throw new ArgumentException("Недостаточно места"); + } + return ChangeStatus(model, OrderStatus.Выдан); } } } diff --git a/GarmentFactoryBusinessLogic/ShopLogic.cs b/GarmentFactoryBusinessLogic/ShopLogic.cs index 0e30de2..18b47fc 100644 --- a/GarmentFactoryBusinessLogic/ShopLogic.cs +++ b/GarmentFactoryBusinessLogic/ShopLogic.cs @@ -127,7 +127,7 @@ namespace GarmentFactoryBusinessLogic { throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден"); } - + // Если такой товар есть, то прибавление переданного кол-ва if (shop.ShopTextiles.ContainsKey(model.TextileId)) { @@ -149,7 +149,6 @@ namespace GarmentFactoryBusinessLogic } - // Проверка данных магазина при добавлении/удалении/обновлении private void CheckModel(ShopBindingModel model, bool withParams = true) { @@ -185,5 +184,20 @@ namespace GarmentFactoryBusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } - } + + public bool Sell(SupplySearchModel model) + { + if (!model.TextileId.HasValue || !model.Count.HasValue) + { + return false; + } + if (_shopStorage.Sell(model)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } + } } diff --git a/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs b/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs index 65eb932..fa5a97f 100644 --- a/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs +++ b/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs @@ -18,5 +18,6 @@ namespace GarmentFactoryContracts.BindingModels public Dictionary ShopTextiles { get; set; } = new(); + public int TextileMaxCount { get; set; } } } diff --git a/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs index 034e475..17b5974 100644 --- a/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -23,5 +23,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); bool AddTextile(SupplyBindingModel model); + + bool Sell(SupplySearchModel model); } } diff --git a/GarmentFactoryContracts/SearchModels/SupplySearchModel.cs b/GarmentFactoryContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..360c8a8 --- /dev/null +++ b/GarmentFactoryContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class SupplySearchModel + { + public int? TextileId { get; set; } + public int? Count { get; set; } + } +} diff --git a/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs b/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs index cad0d17..4a57af3 100644 --- a/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs +++ b/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs @@ -17,5 +17,8 @@ namespace GarmentFactoryContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool Sell(SupplySearchModel model); + //Пополнение магаз-ов + bool RestockShops(SupplyBindingModel model); } } diff --git a/GarmentFactoryContracts/ViewModels/ShopViewModel.cs b/GarmentFactoryContracts/ViewModels/ShopViewModel.cs index 2645018..1853fb6 100644 --- a/GarmentFactoryContracts/ViewModels/ShopViewModel.cs +++ b/GarmentFactoryContracts/ViewModels/ShopViewModel.cs @@ -22,5 +22,8 @@ namespace GarmentFactoryContracts.ViewModels public DateTime DateOpen { get; set; } = DateTime.Now; public Dictionary ShopTextiles { get; set; } = new(); - } + + [DisplayName("Вместимость")] + public int TextileMaxCount { get; set; } + } } diff --git a/GarmentFactoryDataModels/Models/IShopModel.cs b/GarmentFactoryDataModels/Models/IShopModel.cs index 23646ea..538079f 100644 --- a/GarmentFactoryDataModels/Models/IShopModel.cs +++ b/GarmentFactoryDataModels/Models/IShopModel.cs @@ -13,5 +13,7 @@ namespace GarmentFactoryDataModels.Models DateTime DateOpen { get; } //Изделия в магазине Dictionary ShopTextiles { get; } - } + //макс. кол-во изделий + int TextileMaxCount { get; } + } } diff --git a/GarmentFactoryFileImplement/DataFileSingleton.cs b/GarmentFactoryFileImplement/DataFileSingleton.cs index a15d72e..90c144d 100644 --- a/GarmentFactoryFileImplement/DataFileSingleton.cs +++ b/GarmentFactoryFileImplement/DataFileSingleton.cs @@ -14,10 +14,12 @@ namespace GarmentFactoryFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string TextileFileName = "Textile.xml"; - public List Components { get; private set; } + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Textiles { get; private set; } - public static DataFileSingleton GetInstance() + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -28,13 +30,14 @@ namespace GarmentFactoryFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveTextiles() => SaveData(Textiles, TextileFileName, "Textiles", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - - private DataFileSingleton() + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Textiles = LoadData(TextileFileName, "Textile", x => Textile.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/GarmentFactoryFileImplement/Implements/ShopStorage.cs b/GarmentFactoryFileImplement/Implements/ShopStorage.cs index bf3d4f3..d7adf7c 100644 --- a/GarmentFactoryFileImplement/Implements/ShopStorage.cs +++ b/GarmentFactoryFileImplement/Implements/ShopStorage.cs @@ -1,4 +1,8 @@ -using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +13,152 @@ namespace GarmentFactoryFileImplement.Implements { public class ShopStorage : IShopStorage { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + + public bool Sell(SupplySearchModel model) + { + if (model == null || !model.TextileId.HasValue || !model.Count.HasValue) + { + return false; + } + + int remainingSpace = source.Shops.Select(x => x.Textiles.ContainsKey(model.TextileId.Value) ? x.Textiles[model.TextileId.Value] : 0).Sum(); + + if (remainingSpace < model.Count) + { + return false; + } + + var shops = source.Shops.Where(x => x.Textiles.ContainsKey(model.TextileId.Value)).OrderByDescending(x => x.Textiles[model.TextileId.Value]).ToList(); + + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.Textiles[model.TextileId.Value]; + if (residue > 0) + { + shop.Textiles.Remove(model.TextileId.Value); + shop.TextilesUpdate(); + model.Count = residue; + } + else + { + if (residue == 0) + { + shop.Textiles.Remove(model.TextileId.Value); + } + else + { + shop.Textiles[model.TextileId.Value] = -residue; + } + shop.TextilesUpdate(); + source.SaveShops(); + return true; + } + } + source.SaveShops(); + return false; + } + + public bool RestockShops(SupplyBindingModel model) + { + if (model == null || source.Shops.Select(x => x.TextileMaxCount - x.ShopTextiles.Select(y => y.Value.Item2).Sum()).Sum() < model.Count) + { + return false; + } + //для каждого магазина, где есть ещё место + foreach (Shop shop in source.Shops.Where(shop => shop.TextileMaxCount - shop.ShopTextiles.Sum(x => x.Value.Item2) > 0)) + { + //подсчёт свободных мест + int free_places = shop.TextileMaxCount - shop.ShopTextiles.Select(x => x.Value.Item2).Sum(); + free_places = Math.Min(free_places, model.Count); + model.Count -= free_places; + + if (shop.Textiles.ContainsKey(model.TextileId)) + { + shop.Textiles[model.TextileId] += free_places; + } + + else + { + shop.Textiles.Add(model.TextileId, free_places); + } + + shop.TextilesUpdate(); + + if (model.Count == 0) + { + source.SaveShops(); + return true; + } + } + return false; + } } } diff --git a/GarmentFactoryFileImplement/Models/Shop.cs b/GarmentFactoryFileImplement/Models/Shop.cs new file mode 100644 index 0000000..27f7010 --- /dev/null +++ b/GarmentFactoryFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace GarmentFactoryFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime DateOpen { get; private set; } + public Dictionary Textiles { get; private set; } = new(); + private Dictionary? _shopTextiles = null; + + public Dictionary ShopTextiles + { + get + { + if (_shopTextiles == null) + { + var source = DataFileSingleton.GetInstance(); + _shopTextiles = Textiles.ToDictionary(x => x.Key, y => ((source.Textiles.FirstOrDefault(z => z.Id == y.Key) as ITextileModel)!, y.Value)); + } + return _shopTextiles; + } + } + + public int TextileMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + Textiles = model.ShopTextiles.ToDictionary(x => x.Key, x => x.Value.Item2), + TextileMaxCount = model.TextileMaxCount + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + Textiles = element.Element("ShopTextiles")!.Elements("ShopTextile")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + TextileMaxCount = Convert.ToInt32(element.Element("TextileMaxCount")!.Value) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + TextileMaxCount = model.TextileMaxCount; + Textiles = model.ShopTextiles.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopTextiles = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopTextiles = ShopTextiles, + TextileMaxCount = TextileMaxCount + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", DateOpen.ToString()), + new XElement("ShopTextiles", Textiles.Select( + x => new XElement("ShopTextile", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("TextileMaxCount", TextileMaxCount.ToString()) + ); + + public void TextilesUpdate() + { + _shopTextiles = null; + } + } +} diff --git a/GarmentFactoryListImplement/Implements/ShopStorage.cs b/GarmentFactoryListImplement/Implements/ShopStorage.cs index a5442ac..4b3395b 100644 --- a/GarmentFactoryListImplement/Implements/ShopStorage.cs +++ b/GarmentFactoryListImplement/Implements/ShopStorage.cs @@ -109,5 +109,15 @@ namespace GarmentFactoryListImplement.Implements } return null; } - } + + public bool Sell (SupplySearchModel model) + { + throw new NotImplementedException(); + } + + public bool RestockShops(SupplyBindingModel model) + { + throw new NotImplementedException(); + } + } } diff --git a/GarmentFactoryListImplement/Models/Shop.cs b/GarmentFactoryListImplement/Models/Shop.cs index c3911ad..34f85e3 100644 --- a/GarmentFactoryListImplement/Models/Shop.cs +++ b/GarmentFactoryListImplement/Models/Shop.cs @@ -20,7 +20,10 @@ namespace GarmentFactoryListImplement.Models public Dictionary ShopTextiles { get; private set; } = new(); - public static Shop? Create(ShopBindingModel? model) + public int TextileMaxCount { get; private set; } + + + public static Shop? Create(ShopBindingModel? model) { if (model == null) { @@ -33,7 +36,8 @@ namespace GarmentFactoryListImplement.Models ShopName = model.ShopName, Address = model.Address, DateOpen = model.DateOpen, - ShopTextiles = model.ShopTextiles + ShopTextiles = model.ShopTextiles, + TextileMaxCount = model.TextileMaxCount }; } public void Update(ShopBindingModel? model) @@ -46,14 +50,17 @@ namespace GarmentFactoryListImplement.Models Address = model.Address; DateOpen = model.DateOpen; ShopTextiles = model.ShopTextiles; - } + TextileMaxCount = model.TextileMaxCount; + + } public ShopViewModel GetViewModel => new() { Id = Id, ShopName = ShopName, Address = Address, DateOpen = DateOpen, - ShopTextiles = ShopTextiles - }; + ShopTextiles = ShopTextiles, + TextileMaxCount = TextileMaxCount + }; } } From 28b5ed2cfe8fdf399bc912b3aba6a516a3f6902c Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Thu, 9 May 2024 17:22:02 +0400 Subject: [PATCH 04/15] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormAddTextile.cs | 2 +- GarmentFactory/Program.cs | 9 +-- GarmentFactoryBusinessLogic/OrderLogic.cs | 2 + GarmentFactoryBusinessLogic/ShopLogic.cs | 66 ++++++++++++------- .../BusinessLogicsContracts/IShopLogic.cs | 2 +- .../StoragesContracts/IShopStorage.cs | 1 + .../Implements/ShopStorage.cs | 3 +- 7 files changed, 54 insertions(+), 31 deletions(-) diff --git a/GarmentFactory/FormAddTextile.cs b/GarmentFactory/FormAddTextile.cs index d234f54..0b26d2b 100644 --- a/GarmentFactory/FormAddTextile.cs +++ b/GarmentFactory/FormAddTextile.cs @@ -78,7 +78,7 @@ namespace GarmentFactoryView _logger.LogInformation("Пополнение магазина"); try { - var operationResult = _logicS.AddTextile(new SupplyBindingModel + var operationResult = _logicS.MakeSupply(new SupplyBindingModel { ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue), diff --git a/GarmentFactory/Program.cs b/GarmentFactory/Program.cs index 68b4b94..9302db5 100644 --- a/GarmentFactory/Program.cs +++ b/GarmentFactory/Program.cs @@ -38,20 +38,21 @@ namespace GarmentFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/GarmentFactoryBusinessLogic/OrderLogic.cs b/GarmentFactoryBusinessLogic/OrderLogic.cs index f0556fc..9d6d131 100644 --- a/GarmentFactoryBusinessLogic/OrderLogic.cs +++ b/GarmentFactoryBusinessLogic/OrderLogic.cs @@ -140,6 +140,8 @@ namespace GarmentFactoryBusinessLogic { throw new ArgumentNullException(nameof(order)); } + + //Если нельзя пополнить магазины таким кол-вом товаров (не хавтает места), то статус не меняем if (!_shopStorage.RestockShops(new SupplyBindingModel { TextileId = order.TextileId, Count = order.Count })) { throw new ArgumentException("Недостаточно места"); diff --git a/GarmentFactoryBusinessLogic/ShopLogic.cs b/GarmentFactoryBusinessLogic/ShopLogic.cs index 18b47fc..21ddadf 100644 --- a/GarmentFactoryBusinessLogic/ShopLogic.cs +++ b/GarmentFactoryBusinessLogic/ShopLogic.cs @@ -109,7 +109,7 @@ namespace GarmentFactoryBusinessLogic } // Пополнение магазина - public bool AddTextile(SupplyBindingModel model) + public bool MakeSupply(SupplyBindingModel model) { if (model == null) { @@ -121,34 +121,52 @@ namespace GarmentFactoryBusinessLogic throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0"); } - var shop = _shopStorage.GetElement(new ShopSearchModel{ Id = model.ShopId }); + var textile = _textileStorage.GetElement(new TextileSearchModel { Id = model.TextileId }); + if (textile == null) + { + throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден"); + } - if (shop == null) + var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.ShopId }); + if (shop == null) + { + throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден"); + } + + int countTextilesInShop = shop.ShopTextiles.Select(x => x.Value.Item2).Sum(); + + //Если в текущий магазин помещается столько товаров + if (countTextilesInShop + model.Count <= shop.TextileMaxCount) { - throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден"); - } - - // Если такой товар есть, то прибавление переданного кол-ва - if (shop.ShopTextiles.ContainsKey(model.TextileId)) - { - var oldValue = shop.ShopTextiles[model.TextileId]; - oldValue.Item2 += model.Count; - shop.ShopTextiles[model.TextileId] = oldValue; - } - // Если такого товара нет, то кол-во такого товара равно переданному кол-ву - else - { - var textile = _textileStorage.GetElement(new TextileSearchModel{ Id = model.TextileId }); - if (textile == null) + // Если такой товар есть, то прибавление переданного кол-ва + if (shop.ShopTextiles.ContainsKey(model.TextileId)) + { + var oldValue = shop.ShopTextiles[model.TextileId]; + oldValue.Item2 += model.Count; + shop.ShopTextiles[model.TextileId] = oldValue; + } + // Если такого товара нет, то кол-во такого товара равно переданному кол-ву + else + { + shop.ShopTextiles.Add(model.TextileId, (textile, model.Count)); + } + + _shopStorage.Update(new() { - throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден"); - } - shop.ShopTextiles.Add(model.TextileId, (textile, model.Count)); - } - return true; + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + ShopTextiles = shop.ShopTextiles, + TextileMaxCount = shop.TextileMaxCount, + }); + return true; + } + //Если не поместилось столько товара + _logger.LogWarning("Required shop is overflowed"); + return false; } - // Проверка данных магазина при добавлении/удалении/обновлении private void CheckModel(ShopBindingModel model, bool withParams = true) { diff --git a/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs index 17b5974..7f43b4d 100644 --- a/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -22,7 +22,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool AddTextile(SupplyBindingModel model); + bool MakeSupply(SupplyBindingModel model); bool Sell(SupplySearchModel model); } diff --git a/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs b/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs index 4a57af3..1d8cce9 100644 --- a/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs +++ b/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs @@ -17,6 +17,7 @@ namespace GarmentFactoryContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + //Продажа изделий в нужном кол-ве bool Sell(SupplySearchModel model); //Пополнение магаз-ов bool RestockShops(SupplyBindingModel model); diff --git a/GarmentFactoryListImplement/Implements/ShopStorage.cs b/GarmentFactoryListImplement/Implements/ShopStorage.cs index 4b3395b..d28bf04 100644 --- a/GarmentFactoryListImplement/Implements/ShopStorage.cs +++ b/GarmentFactoryListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using GarmentFactoryContracts.SearchModels; using GarmentFactoryContracts.StoragesContracts; using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; using GarmentFactoryListImplement.Models; using System; using System.Collections.Generic; @@ -110,7 +111,7 @@ namespace GarmentFactoryListImplement.Implements return null; } - public bool Sell (SupplySearchModel model) + public bool Sell(SupplySearchModel model) { throw new NotImplementedException(); } From 0fee694fcee640d6fa5c91eb1a7d7fe57a24dd5a Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Tue, 14 May 2024 18:31:19 +0400 Subject: [PATCH 05/15] --- .../Implements/ShopStorage.cs | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/GarmentFactoryFileImplement/Implements/ShopStorage.cs b/GarmentFactoryFileImplement/Implements/ShopStorage.cs index d7adf7c..6d3c1a3 100644 --- a/GarmentFactoryFileImplement/Implements/ShopStorage.cs +++ b/GarmentFactoryFileImplement/Implements/ShopStorage.cs @@ -6,6 +6,7 @@ using GarmentFactoryFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -128,26 +129,38 @@ namespace GarmentFactoryFileImplement.Implements public bool RestockShops(SupplyBindingModel model) { - if (model == null || source.Shops.Select(x => x.TextileMaxCount - x.ShopTextiles.Select(y => y.Value.Item2).Sum()).Sum() < model.Count) + //подсчёт свободных мест через сумму свободных мест в каждом магазине + //в каждом магазине кол-во свободных мест = макс. кол-во - занятые места + int totalFreeSpace = source.Shops + .Select(x => x.TextileMaxCount - x.ShopTextiles.Select(y => y.Value.Item2).Sum()) + .Sum(); + + //если места не хватает + if (totalFreeSpace < model.Count) { return false; } - //для каждого магазина, где есть ещё место - foreach (Shop shop in source.Shops.Where(shop => shop.TextileMaxCount - shop.ShopTextiles.Sum(x => x.Value.Item2) > 0)) + + foreach (Shop shop in source.Shops) { - //подсчёт свободных мест - int free_places = shop.TextileMaxCount - shop.ShopTextiles.Select(x => x.Value.Item2).Sum(); - free_places = Math.Min(free_places, model.Count); - model.Count -= free_places; + int freeSpace = shop.TextileMaxCount - shop.ShopTextiles.Select(x => x.Value.Item2).Sum(); + + if (freeSpace <= 0) + { + continue; + } + + freeSpace = Math.Min(freeSpace, model.Count); + model.Count -= freeSpace; if (shop.Textiles.ContainsKey(model.TextileId)) { - shop.Textiles[model.TextileId] += free_places; + shop.Textiles[model.TextileId] += freeSpace; } - + else { - shop.Textiles.Add(model.TextileId, free_places); + shop.Textiles.Add(model.TextileId, freeSpace); } shop.TextilesUpdate(); From 82f417b9c383b7b12a00613192a4833259d71bb9 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Tue, 14 May 2024 21:35:50 +0400 Subject: [PATCH 06/15] =?UTF-8?q?=D0=97=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B13=20=D1=83=D1=81=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 243 ++++++++++++++++++ .../Models/Shop.cs | 136 ++++++++++ .../Models/ShopTextile.cs | 27 ++ 3 files changed, 406 insertions(+) create mode 100644 GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs create mode 100644 GarmentFactoryDatabaseImplement/Models/Shop.cs create mode 100644 GarmentFactoryDatabaseImplement/Models/ShopTextile.cs diff --git a/GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs b/GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..23d87c4 --- /dev/null +++ b/GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,243 @@ +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryDatabaseImplement.Models; + +namespace GarmentFactoryDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new GarmentFactoryDatabase(); + return context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + + using var context = new GarmentFactoryDatabase(); + + return context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .Where(x => x.ShopName.Contains(model.ShopName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return new(); + } + + using var context = new GarmentFactoryDatabase(); + + return context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + + context.Shops.Add(newShop); + context.SaveChanges(); + + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + + 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.UpdateTextiles(context, model); + + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + var element = context.Shops + .Include(x => x.Textiles) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + //продажа текстиля из магазинов + public bool Sell(SupplySearchModel model) + { + using var context = new GarmentFactoryDatabase(); + using var transaction = context.Database.BeginTransaction(); + + try + { + //поиск всех магаз-ов, в кот. есть нужный текстиль (сортировка: сначала те, где его больше) + var shopsWithThisTextile = context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .ToList() + .Where(x => x.ShopTextiles.ContainsKey(model.TextileId.Value)) + .OrderByDescending(x => x.ShopTextiles[model.TextileId.Value].Item2) + .ToList(); + + foreach (var shop in shopsWithThisTextile) + { + //сколько надо будет этого текстиля, если продать все из текущего магазина + int thisTextileNeeded = model.Count.Value - shop.ShopTextiles[model.TextileId.Value].Item2; + + //если ещё надо будет + if (thisTextileNeeded > 0) + { + //полное удаление этого текстиля из этого магазина + shop.ShopTextiles.Remove(model.TextileId.Value); + shop.DictionaryTextilesUpdate(context); + context.SaveChanges(); + + model.Count = thisTextileNeeded; + } + else + { + //если в этом магазине ровно столько, сколько надо + if (thisTextileNeeded == 0) + { + shop.ShopTextiles.Remove(model.TextileId.Value); + } + //если в этом магазине больше, чем надо + else + { + //уменьшение в этом магазине этого текстиля на нужное кол-во + var textileAndCount = shop.ShopTextiles[model.TextileId.Value]; + textileAndCount.Item2 = -thisTextileNeeded; + shop.ShopTextiles[model.TextileId.Value] = textileAndCount; + } + shop.DictionaryTextilesUpdate(context); + transaction.Commit(); + + return true; + } + } + + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + //пополнение магазинов текстилем + public bool RestockShops(SupplyBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + using var transaction = context.Database.BeginTransaction(); + + //все магазины, где ещё есть свободное место (занятое кол-во < максимально допустимого) + var shops = context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .ToList() + .Where(x => x.ShopTextiles.Select(x => x.Value.Item2).Sum() < x.TextileMaxCount) + .ToList(); + + try + { + foreach (Shop shop in shops) + { + //свободное место в этом магазине + int freeSpace = shop.TextileMaxCount - shop.ShopTextiles.Select(x => x.Value.Item2).Sum(); + + //кол-во кот. надо для этого магазина (либо до макс. кол-ва, либо кол-во, кот. осталось в "поставке" (что меньше)) + int restock = Math.Min(freeSpace, model.Count); + model.Count -= restock; + + //если в этом магазине есть этот текстиль, то изменение его кол-ва + if (shop.ShopTextiles.ContainsKey(model.TextileId)) + { + var textileAndCount = shop.ShopTextiles[model.TextileId]; + textileAndCount.Item2 += restock; + shop.ShopTextiles[model.TextileId] = textileAndCount; + } + //если нет, то добавление в этом кол-ве + else + { + var textile = context.Textiles.First(x => x.Id == model.TextileId); + shop.ShopTextiles.Add(model.TextileId, (textile, restock)); + } + + shop.DictionaryTextilesUpdate(context); + + //если в "поставке" закончились товары, то всё ок + if (model.Count == 0) + { + transaction.Commit(); + return true; + } + } + + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/GarmentFactoryDatabaseImplement/Models/Shop.cs b/GarmentFactoryDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..501a50f --- /dev/null +++ b/GarmentFactoryDatabaseImplement/Models/Shop.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using GarmentFactoryDataModels.Models; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + + [Required] + public string ShopName { get; set; } = string.Empty; + + [Required] + public string Address { get; set; } = string.Empty; + + [Required] + public DateTime DateOpen { get; set; } + + [Required] + public int TextileMaxCount { get; set; } + + [ForeignKey("ShopId")] + public List Textiles { get; set; } = new(); + + private Dictionary? _shopTextiles = null; + + [NotMapped] + public Dictionary ShopTextiles + { + get + { + if (_shopTextiles == null) + { + if (_shopTextiles == null) + { + _shopTextiles = Textiles.ToDictionary(x => x.TextileId, y => (y.Textile as ITextileModel, y.Count)); + } + return _shopTextiles; + } + + return _shopTextiles; + } + } + + public static Shop Create(GarmentFactoryDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + TextileMaxCount = model.TextileMaxCount, + Textiles = model.ShopTextiles.Select(x => new ShopTextile + { + Textile = context.Textiles.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + TextileMaxCount = model.TextileMaxCount; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopTextiles = ShopTextiles, + TextileMaxCount = TextileMaxCount + }; + + public void UpdateTextiles(GarmentFactoryDatabase context, ShopBindingModel model) + { + var ShopTextiles = context.ShopTextiles + .Where(rec => rec.ShopId == model.Id) + .ToList(); + + if (ShopTextiles != null && ShopTextiles.Count > 0) + { + context.ShopTextiles.RemoveRange(ShopTextiles.Where(rec => !model.ShopTextiles.ContainsKey(rec.TextileId))); + context.SaveChanges(); + + ShopTextiles = context.ShopTextiles.Where(rec => rec.ShopId == model.Id).ToList(); + + foreach (var textileToUpdate in ShopTextiles) + { + textileToUpdate.Count = model.ShopTextiles[textileToUpdate.TextileId].Item2; + model.ShopTextiles.Remove(textileToUpdate.TextileId); + } + + context.SaveChanges(); + } + + var Shop = context.Shops.First(x => x.Id == Id); + + foreach (var ShopTextile in model.ShopTextiles) + { + context.ShopTextiles.Add(new ShopTextile + { + Shop = Shop, + Textile = context.Textiles.First(x => x.Id == ShopTextile.Key), + Count = ShopTextile.Value.Item2 + }); + + context.SaveChanges(); + } + + _shopTextiles = null; + } + + public void DictionaryTextilesUpdate(GarmentFactoryDatabase context) + { + UpdateTextiles(context, new ShopBindingModel + { + Id = Id, + ShopTextiles = ShopTextiles + }); + } + } +} diff --git a/GarmentFactoryDatabaseImplement/Models/ShopTextile.cs b/GarmentFactoryDatabaseImplement/Models/ShopTextile.cs new file mode 100644 index 0000000..c4985b6 --- /dev/null +++ b/GarmentFactoryDatabaseImplement/Models/ShopTextile.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 GarmentFactoryDatabaseImplement.Models +{ + public class ShopTextile + { + public int Id { get; set; } + + [Required] + public int TextileId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + + public virtual Textile Textile { get; set; } = new(); + } +} From 8e0cbf292bef71f3bd22739e72d7c7dd44201bfc Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Tue, 14 May 2024 21:38:52 +0400 Subject: [PATCH 07/15] =?UTF-8?q?=D0=97=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B13=20=D1=83=D1=81=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs b/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs index dce2c55..a39000f 100644 --- a/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs +++ b/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs @@ -27,5 +27,9 @@ namespace GarmentFactoryDatabaseImplement public virtual DbSet TextileComponents { set; get; } public virtual DbSet Orders { set; get; } - } + + public virtual DbSet Shops { get; set; } + + public virtual DbSet ShopTextiles { get; set; } + } } From 001688a3a067c652bc2c65b13a833c8fe50f2ff0 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Wed, 15 May 2024 10:03:57 +0400 Subject: [PATCH 08/15] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/GarmentFactoryFileImplement/Implements/ShopStorage.cs b/GarmentFactoryFileImplement/Implements/ShopStorage.cs index 6d3c1a3..fed4ced 100644 --- a/GarmentFactoryFileImplement/Implements/ShopStorage.cs +++ b/GarmentFactoryFileImplement/Implements/ShopStorage.cs @@ -89,34 +89,43 @@ namespace GarmentFactoryFileImplement.Implements { return false; } - - int remainingSpace = source.Shops.Select(x => x.Textiles.ContainsKey(model.TextileId.Value) ? x.Textiles[model.TextileId.Value] : 0).Sum(); - if (remainingSpace < model.Count) + //магазины по степени наполненности (от самого наполненного) с этим текстилем + var shopsWithThisTextile = source.Shops.Where(x => x.Textiles.ContainsKey(model.TextileId.Value)).OrderByDescending(x => x.Textiles[model.TextileId.Value]).ToList(); + + int thisTextileInShops = shopsWithThisTextile.Select(x => x.Textiles[model.TextileId.Value]).Sum(); + + if (thisTextileInShops < model.Count) { return false; } - var shops = source.Shops.Where(x => x.Textiles.ContainsKey(model.TextileId.Value)).OrderByDescending(x => x.Textiles[model.TextileId.Value]).ToList(); - - foreach (var shop in shops) + foreach (var shop in shopsWithThisTextile) { - int residue = model.Count.Value - shop.Textiles[model.TextileId.Value]; - if (residue > 0) + //кол-во необходимых текстилей после возможной продажи всех текстилей + int thisTextileNeed = model.Count.Value - shop.Textiles[model.TextileId.Value]; + + //Если текстиль ещё нужен будет + if (thisTextileNeed > 0) { + //удаление всех текстилей в этом магазине shop.Textiles.Remove(model.TextileId.Value); shop.TextilesUpdate(); - model.Count = residue; + model.Count = thisTextileNeed; } + else { - if (residue == 0) + //Если ровно хватает + if (thisTextileNeed == 0) { shop.Textiles.Remove(model.TextileId.Value); } + //Если нужно меньше, чем есть в магазине else { - shop.Textiles[model.TextileId.Value] = -residue; + //уменьшение кол-ва + shop.Textiles[model.TextileId.Value] = -thisTextileNeed; } shop.TextilesUpdate(); source.SaveShops(); From 60c793c1abb52e9a5a3623bf0f25fcce185e5999 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Wed, 15 May 2024 10:42:54 +0400 Subject: [PATCH 09/15] =?UTF-8?q?=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...515060701_Lab3_Hard_AddedShops.Designer.cs | 248 ++++++++++++++++++ .../20240515060701_Lab3_Hard_AddedShops.cs | 78 ++++++ .../GarmentFactoryDatabaseModelSnapshot.cs | 77 ++++++ 3 files changed, 403 insertions(+) create mode 100644 GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.Designer.cs create mode 100644 GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.cs diff --git a/GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.Designer.cs b/GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.Designer.cs new file mode 100644 index 0000000..cb61d6b --- /dev/null +++ b/GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using GarmentFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace GarmentFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(GarmentFactoryDatabase))] + [Migration("20240515060701_Lab3_Hard_AddedShops")] + partial class Lab3_Hard_AddedShops + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateComplete") + .HasColumnType("datetime2"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TextileId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpen") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TextileMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("TextileId"); + + b.ToTable("ShopTextiles"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("TextileName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Textiles"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("TextileId"); + + b.ToTable("TextileComponents"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany("Orders") + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Textile"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Shop", "Shop") + .WithMany("Textiles") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany() + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Textile"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("TextileComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany("Components") + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Textile"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("TextileComponents"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Navigation("Textiles"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.cs b/GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.cs new file mode 100644 index 0000000..3098a32 --- /dev/null +++ b/GarmentFactoryDatabaseImplement/Migrations/20240515060701_Lab3_Hard_AddedShops.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace GarmentFactoryDatabaseImplement.Migrations +{ + /// + public partial class Lab3_Hard_AddedShops : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOpen = table.Column(type: "datetime2", nullable: false), + TextileMaxCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ShopTextiles", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TextileId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopTextiles", x => x.Id); + table.ForeignKey( + name: "FK_ShopTextiles_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopTextiles_Textiles_TextileId", + column: x => x.TextileId, + principalTable: "Textiles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShopTextiles_ShopId", + table: "ShopTextiles", + column: "ShopId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopTextiles_TextileId", + table: "ShopTextiles", + column: "TextileId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ShopTextiles"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs b/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs index 8547e48..ec9718c 100644 --- a/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs +++ b/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs @@ -75,6 +75,59 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpen") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TextileMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("TextileId"); + + b.ToTable("ShopTextiles"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Property("Id") @@ -132,6 +185,25 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("Textile"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Shop", "Shop") + .WithMany("Textiles") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany() + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Textile"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => { b.HasOne("GarmentFactoryDatabaseImplement.Models.Component", "Component") @@ -156,6 +228,11 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Navigation("Textiles"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); From 366a10630805298a2f6ebc6f05f4076e7d484135 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Fri, 17 May 2024 14:05:17 +0400 Subject: [PATCH 10/15] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=B0=D1=8F=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactoryFileImplement/Implements/ShopStorage.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/GarmentFactoryFileImplement/Implements/ShopStorage.cs b/GarmentFactoryFileImplement/Implements/ShopStorage.cs index fed4ced..e30ebbd 100644 --- a/GarmentFactoryFileImplement/Implements/ShopStorage.cs +++ b/GarmentFactoryFileImplement/Implements/ShopStorage.cs @@ -150,15 +150,12 @@ namespace GarmentFactoryFileImplement.Implements return false; } - foreach (Shop shop in source.Shops) + var shopsWithFreeSpace = source.Shops.Where(x => x.TextileMaxCount - x.ShopTextiles.Select(x => x.Value.Item2).Sum() > 0); + + foreach (Shop shop in shopsWithFreeSpace) { int freeSpace = shop.TextileMaxCount - shop.ShopTextiles.Select(x => x.Value.Item2).Sum(); - if (freeSpace <= 0) - { - continue; - } - freeSpace = Math.Min(freeSpace, model.Count); model.Count -= freeSpace; From 1f48e676f26ecfed393f2b672292676bb91bb038 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Fri, 14 Jun 2024 15:02:43 +0400 Subject: [PATCH 11/15] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BB=D0=B8=D1=8F=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormMain.Designer.cs | 4 ++-- GarmentFactory/FormMain.cs | 2 +- GarmentFactory/Program.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/GarmentFactory/FormMain.Designer.cs b/GarmentFactory/FormMain.Designer.cs index b97857c..64267c1 100644 --- a/GarmentFactory/FormMain.Designer.cs +++ b/GarmentFactory/FormMain.Designer.cs @@ -124,7 +124,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчётыToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1169, 28); @@ -133,7 +133,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem, магазиныToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; diff --git a/GarmentFactory/FormMain.cs b/GarmentFactory/FormMain.cs index 4790f9d..41d91ef 100644 --- a/GarmentFactory/FormMain.cs +++ b/GarmentFactory/FormMain.cs @@ -20,7 +20,7 @@ namespace GarmentFactoryView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; diff --git a/GarmentFactory/Program.cs b/GarmentFactory/Program.cs index ab47384..52a7803 100644 --- a/GarmentFactory/Program.cs +++ b/GarmentFactory/Program.cs @@ -8,7 +8,7 @@ using GarmentFactoryView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; - +using GarmentFactoryBusinessLogic; namespace GarmentFactory { @@ -64,7 +64,7 @@ namespace GarmentFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); services.AddTransient(); } From 2e66e6e59f0f0da85a33400c59db40cfced7a35d Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Fri, 14 Jun 2024 16:14:36 +0400 Subject: [PATCH 12/15] =?UTF-8?q?=D0=9E=D1=82=D1=87=D1=91=D1=82=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=D0=BC?= =?UTF-8?q?=20=D0=B2=20word?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormMain.Designer.cs | 51 ++-- GarmentFactory/FormMain.cs | 236 +++++++++--------- .../BusinessLogics/ReportLogic.cs | 55 +++- .../OfficePackage/AbstractSaveToWord.cs | 50 +++- .../OfficePackage/HelperModels/WordInfo.cs | 3 +- .../HelperModels/WordRowParameters.cs | 15 ++ .../HelperModels/WordShopInfo.cs | 16 ++ .../OfficePackage/IDocument.cs | 14 ++ .../OfficePackage/Implements/SaveToWord.cs | 76 +++++- .../BusinessLogicsContracts/IReportLogic.cs | 4 + .../ViewModels/ReportShopsViewModel.cs | 15 ++ 11 files changed, 395 insertions(+), 140 deletions(-) create mode 100644 GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs create mode 100644 GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs create mode 100644 GarmentFactoryBusinessLogic/OfficePackage/IDocument.cs create mode 100644 GarmentFactoryContracts/ViewModels/ReportShopsViewModel.cs diff --git a/GarmentFactory/FormMain.Designer.cs b/GarmentFactory/FormMain.Designer.cs index 64267c1..ad17815 100644 --- a/GarmentFactory/FormMain.Designer.cs +++ b/GarmentFactory/FormMain.Designer.cs @@ -1,26 +1,26 @@ namespace GarmentFactoryView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify @@ -46,6 +46,7 @@ textilesToolStripMenuItem = new ToolStripMenuItem(); textileComponentsToolStripMenuItem = new ToolStripMenuItem(); ordersToolStripMenuItem = new ToolStripMenuItem(); + магазиныВDocToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -182,7 +183,7 @@ // // отчётыToolStripMenuItem // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem }); + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem }); отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Size = new Size(73, 24); отчётыToolStripMenuItem.Text = "Отчёты"; @@ -208,6 +209,13 @@ ordersToolStripMenuItem.Text = "Заказы"; ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // + // магазиныВDocToolStripMenuItem + // + магазиныВDocToolStripMenuItem.Name = "магазиныВDocToolStripMenuItem"; + магазиныВDocToolStripMenuItem.Size = new Size(274, 26); + магазиныВDocToolStripMenuItem.Text = "Магазины в doc"; + магазиныВDocToolStripMenuItem.Click += магазиныВDocToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -231,7 +239,7 @@ PerformLayout(); } - #endregion + #endregion private DataGridView dataGridView; private Button buttonCreateOrder; @@ -251,5 +259,6 @@ private ToolStripMenuItem textilesToolStripMenuItem; private ToolStripMenuItem textileComponentsToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem магазиныВDocToolStripMenuItem; } } \ No newline at end of file diff --git a/GarmentFactory/FormMain.cs b/GarmentFactory/FormMain.cs index 41d91ef..6803151 100644 --- a/GarmentFactory/FormMain.cs +++ b/GarmentFactory/FormMain.cs @@ -52,15 +52,15 @@ namespace GarmentFactoryView LoadData(); } - private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } - } + } private void текстилиToolStripMenuItem_Click(object sender, EventArgs e) { @@ -102,114 +102,124 @@ namespace GarmentFactoryView - private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } + if (service is FormShops form) + { + form.ShowDialog(); + } + } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonCompletedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRefresh_Click(object sender, EventArgs e) - { - LoadData(); - } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonCompletedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } - private void пополнениеМагазинаToolStripMenuItem1_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile)); + private void пополнениеМагазинаToolStripMenuItem1_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile)); - if (service is FormAddTextile form) - { - form.ShowDialog(); - } - } + if (service is FormAddTextile form) + { + form.ShowDialog(); + } + } - private void продажаТовараToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSellTextile)); - if (service is FormSellTextile form) - { - form.ShowDialog(); - } - } - } + private void продажаТовараToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellTextile)); + if (service is FormSellTextile form) + { + form.ShowDialog(); + } + } + + private void магазиныВDocToolStripMenuItem_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); + } + } + } } diff --git a/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs b/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs index aeb1ad3..c2aa447 100644 --- a/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using GarmentFactoryContracts.ViewModels; namespace GarmentFactoryBusinessLogic.BusinessLogics { @@ -18,16 +19,18 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly ITextileStorage _textileStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ITextileStorage textileStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, + public ReportLogic(ITextileStorage textileStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _textileStorage = textileStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; @@ -106,5 +109,55 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } + + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Textiles = x.ShopTextiles.Select(x => (x.Value.Item1.TextileName, x.Value.Item2)).ToList(), + TotalCount = x.ShopTextiles.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.CreateShopTextilesReport(new ExcelShop + // { + // FileName = model.FileName, + // Title = "Наполненость магазинов", + // ShopTextiles = GetShops() + // }); + //} + + //public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + //{ + // _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + // { + // FileName = model.FileName, + // Title = "Список заказов сгруппированных по дате заказов", + // GroupedOrders = GetGroupedOrders() + // }); + //} } } diff --git a/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs index b5cd100..a91be19 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -1,5 +1,7 @@ using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; +using GarmentFactoryBusinessLogic.OfficePackage; +using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; using System.Linq; @@ -43,11 +45,52 @@ namespace GarmentFactoryBusinessLogic.OfficePackage 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.Address, shop.DateOpen.ToString() }, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Center + } + }); + } + + SaveWord(info); + } + /// /// Создание doc-файла /// /// - protected abstract void CreateWord(WordInfo info); + protected abstract void CreateWord(IDocumentInfo info); /// /// Создание абзаца с текстом @@ -60,6 +103,9 @@ namespace GarmentFactoryBusinessLogic.OfficePackage /// Сохранение файла /// /// - protected abstract void SaveWord(WordInfo info); + protected abstract void SaveWord(IDocumentInfo info); + + protected abstract void CreateTable(List colums); + protected abstract void CreateRow(WordRowParameters rowParameters); } } diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 975a3d4..220e317 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -1,4 +1,5 @@ using GarmentFactoryContracts.ViewModels; +using GarmentFactoryBusinessLogic.OfficePackage; using System; using System.Collections.Generic; using System.Linq; @@ -7,7 +8,7 @@ using System.Threading.Tasks; namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels { - public class WordInfo + public class WordInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs new file mode 100644 index 0000000..1a466a3 --- /dev/null +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs @@ -0,0 +1,15 @@ +using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels +{ + public class WordRowParameters + { + public List Texts { get; set; } = new(); + public WordTextProperties TextProperties { get; set; } = new(); + } +} diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs new file mode 100644 index 0000000..94ce0de --- /dev/null +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs @@ -0,0 +1,16 @@ +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels +{ + public class WordShopInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/GarmentFactoryBusinessLogic/OfficePackage/IDocument.cs b/GarmentFactoryBusinessLogic/OfficePackage/IDocument.cs new file mode 100644 index 0000000..bbb14a9 --- /dev/null +++ b/GarmentFactoryBusinessLogic/OfficePackage/IDocument.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.OfficePackage +{ + public interface IDocumentInfo + { + public string FileName { get; set; } + public string Title { get; set; } + } +} diff --git a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 6305128..05bf2f1 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -85,7 +85,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements return properties; } - protected override void CreateWord(WordInfo info) + protected override void CreateWord(IDocumentInfo info) { _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); @@ -123,7 +123,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements _docBody.AppendChild(docParagraph); } - protected override void SaveWord(WordInfo info) + protected override void SaveWord(IDocumentInfo info) { if (_docBody == null || _wordDocument == null) { @@ -135,5 +135,77 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements _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); + } } } diff --git a/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs b/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs index 5b27402..685ee72 100644 --- a/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs @@ -20,5 +20,9 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); + //void SaveShopsToExcelFile(ReportBindingModel model); + //void SaveGroupedOrdersToPdfFile(ReportBindingModel model); + } } diff --git a/GarmentFactoryContracts/ViewModels/ReportShopsViewModel.cs b/GarmentFactoryContracts/ViewModels/ReportShopsViewModel.cs new file mode 100644 index 0000000..f8e627e --- /dev/null +++ b/GarmentFactoryContracts/ViewModels/ReportShopsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.ViewModels +{ + public class ReportShopsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string textile, int count)> Textiles { get; set; } = new(); + } +} From 576a486a405dcb51c27c0abc63970d24fad67aa2 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Fri, 14 Jun 2024 16:56:48 +0400 Subject: [PATCH 13/15] =?UTF-8?q?=D0=9E=D1=82=D1=87=D1=91=D1=82=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormMain.Designer.cs | 28 +++- GarmentFactory/FormMain.cs | 18 +++ .../FormReportGroupedOrders.Designer.cs | 86 +++++++++++++ GarmentFactory/FormReportGroupedOrders.cs | 80 ++++++++++++ GarmentFactory/FormReportGroupedOrders.resx | 120 ++++++++++++++++++ GarmentFactory/FormReportShops.Designer.cs | 112 ++++++++++++++++ GarmentFactory/FormReportShops.cs | 78 ++++++++++++ GarmentFactory/FormReportShops.resx | 120 ++++++++++++++++++ GarmentFactory/Program.cs | 2 + .../BusinessLogics/ReportLogic.cs | 18 +-- .../OfficePackage/AbstractSaveToExcel.cs | 77 ++++++++++- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../HelperModels/ExcelShopInfo.cs | 16 +++ .../OfficePackage/Implements/SaveToExcel.cs | 4 +- .../OfficePackage/Implements/SaveToWord.cs | 14 +- .../BusinessLogicsContracts/IReportLogic.cs | 4 +- 16 files changed, 752 insertions(+), 27 deletions(-) create mode 100644 GarmentFactory/FormReportGroupedOrders.Designer.cs create mode 100644 GarmentFactory/FormReportGroupedOrders.cs create mode 100644 GarmentFactory/FormReportGroupedOrders.resx create mode 100644 GarmentFactory/FormReportShops.Designer.cs create mode 100644 GarmentFactory/FormReportShops.cs create mode 100644 GarmentFactory/FormReportShops.resx create mode 100644 GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs diff --git a/GarmentFactory/FormMain.Designer.cs b/GarmentFactory/FormMain.Designer.cs index ad17815..273da04 100644 --- a/GarmentFactory/FormMain.Designer.cs +++ b/GarmentFactory/FormMain.Designer.cs @@ -47,6 +47,8 @@ textileComponentsToolStripMenuItem = new ToolStripMenuItem(); ordersToolStripMenuItem = new ToolStripMenuItem(); магазиныВDocToolStripMenuItem = new ToolStripMenuItem(); + загруженностьМагазиновToolStripMenuItem = new ToolStripMenuItem(); + заказыПоДатамToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -183,7 +185,7 @@ // // отчётыToolStripMenuItem // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem }); + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem, загруженностьМагазиновToolStripMenuItem, заказыПоДатамToolStripMenuItem }); отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Size = new Size(73, 24); отчётыToolStripMenuItem.Text = "Отчёты"; @@ -191,31 +193,45 @@ // textilesToolStripMenuItem // textilesToolStripMenuItem.Name = "textilesToolStripMenuItem"; - textilesToolStripMenuItem.Size = new Size(274, 26); + textilesToolStripMenuItem.Size = new Size(276, 26); textilesToolStripMenuItem.Text = "Текстили"; textilesToolStripMenuItem.Click += TextilesToolStripMenuItem_Click; // // textileComponentsToolStripMenuItem // textileComponentsToolStripMenuItem.Name = "textileComponentsToolStripMenuItem"; - textileComponentsToolStripMenuItem.Size = new Size(274, 26); + textileComponentsToolStripMenuItem.Size = new Size(276, 26); textileComponentsToolStripMenuItem.Text = "Текстили с компонентами"; textileComponentsToolStripMenuItem.Click += ComponentTextilesToolStripMenuItem_Click; // // ordersToolStripMenuItem // ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - ordersToolStripMenuItem.Size = new Size(274, 26); + ordersToolStripMenuItem.Size = new Size(276, 26); ordersToolStripMenuItem.Text = "Заказы"; ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // магазиныВDocToolStripMenuItem // магазиныВDocToolStripMenuItem.Name = "магазиныВDocToolStripMenuItem"; - магазиныВDocToolStripMenuItem.Size = new Size(274, 26); + магазиныВDocToolStripMenuItem.Size = new Size(276, 26); магазиныВDocToolStripMenuItem.Text = "Магазины в doc"; магазиныВDocToolStripMenuItem.Click += магазиныВDocToolStripMenuItem_Click; // + // загруженностьМагазиновToolStripMenuItem + // + загруженностьМагазиновToolStripMenuItem.Name = "загруженностьМагазиновToolStripMenuItem"; + загруженностьМагазиновToolStripMenuItem.Size = new Size(276, 26); + загруженностьМагазиновToolStripMenuItem.Text = "Загруженность магазинов"; + загруженностьМагазиновToolStripMenuItem.Click += загруженностьМагазиновToolStripMenuItem_Click; + // + // заказыПоДатамToolStripMenuItem + // + заказыПоДатамToolStripMenuItem.Name = "заказыПоДатамToolStripMenuItem"; + заказыПоДатамToolStripMenuItem.Size = new Size(276, 26); + заказыПоДатамToolStripMenuItem.Text = "Заказы по датам"; + заказыПоДатамToolStripMenuItem.Click += заказыПоДатамToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -260,5 +276,7 @@ private ToolStripMenuItem textileComponentsToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem магазиныВDocToolStripMenuItem; + private ToolStripMenuItem загруженностьМагазиновToolStripMenuItem; + private ToolStripMenuItem заказыПоДатамToolStripMenuItem; } } \ No newline at end of file diff --git a/GarmentFactory/FormMain.cs b/GarmentFactory/FormMain.cs index 6803151..671e91e 100644 --- a/GarmentFactory/FormMain.cs +++ b/GarmentFactory/FormMain.cs @@ -221,5 +221,23 @@ namespace GarmentFactoryView MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } + + private void загруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShops)); + if (service is FormReportShops form) + { + form.ShowDialog(); + } + } + + private void заказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } } } diff --git a/GarmentFactory/FormReportGroupedOrders.Designer.cs b/GarmentFactory/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..911a695 --- /dev/null +++ b/GarmentFactory/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,86 @@ +namespace GarmentFactoryView +{ + 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/GarmentFactory/FormReportGroupedOrders.cs b/GarmentFactory/FormReportGroupedOrders.cs new file mode 100644 index 0000000..28a041b --- /dev/null +++ b/GarmentFactory/FormReportGroupedOrders.cs @@ -0,0 +1,80 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 GarmentFactoryView +{ + 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/GarmentFactory/FormReportGroupedOrders.resx b/GarmentFactory/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GarmentFactory/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/GarmentFactory/FormReportShops.Designer.cs b/GarmentFactory/FormReportShops.Designer.cs new file mode 100644 index 0000000..92476bd --- /dev/null +++ b/GarmentFactory/FormReportShops.Designer.cs @@ -0,0 +1,112 @@ +namespace GarmentFactoryView +{ + partial class FormReportShops + { + /// + /// 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() + { + buttonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnTextile = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(12, 9); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(169, 29); + buttonSaveToExcel.TabIndex = 3; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnTextile, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 47); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(598, 403); + dataGridView.TabIndex = 2; + // + // ColumnShop + // + ColumnShop.FillWeight = 130F; + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 6; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + // + // ColumnTextile + // + ColumnTextile.FillWeight = 140F; + ColumnTextile.HeaderText = "Текстиль"; + ColumnTextile.MinimumWidth = 6; + ColumnTextile.Name = "ColumnTextile"; + ColumnTextile.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.FillWeight = 90F; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(598, 450); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Name = "FormReportShops"; + Text = "Загруженность магазинов"; + Load += FormReportShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnTextile; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormReportShops.cs b/GarmentFactory/FormReportShops.cs new file mode 100644 index 0000000..6429159 --- /dev/null +++ b/GarmentFactory/FormReportShops.cs @@ -0,0 +1,78 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.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 GarmentFactoryView +{ + public partial class FormReportShops : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShops(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShops_Load(object sender, EventArgs e) + { + try + { + var shops = _logic.GetShops(); + if (shops != null) + { + dataGridView.Rows.Clear(); + foreach (var shop in shops) + { + dataGridView.Rows.Add(new object[] { shop.ShopName, "", "" }); + foreach (var textile in shop.Textiles) + { + dataGridView.Rows.Add(new object[] { "", textile.Item1, textile.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", shop.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/GarmentFactory/FormReportShops.resx b/GarmentFactory/FormReportShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/FormReportShops.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/GarmentFactory/Program.cs b/GarmentFactory/Program.cs index 52a7803..ff72909 100644 --- a/GarmentFactory/Program.cs +++ b/GarmentFactory/Program.cs @@ -67,6 +67,8 @@ namespace GarmentFactory services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs b/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs index c2aa447..06dc46e 100644 --- a/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs @@ -140,15 +140,15 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics }); } - //public void SaveShopsToExcelFile(ReportBindingModel model) - //{ - // _saveToExcel.CreateShopTextilesReport(new ExcelShop - // { - // FileName = model.FileName, - // Title = "Наполненость магазинов", - // ShopTextiles = GetShops() - // }); - //} + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopTextilesReport(new ExcelShopInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopTextiles = GetShops() + }); + } //public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) //{ diff --git a/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 6ac7f38..b83a78e 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -80,9 +80,82 @@ namespace GarmentFactoryBusinessLogic.OfficePackage SaveExcel(info); } - protected abstract void CreateExcel(ExcelInfo info); + + public void CreateShopTextilesReport(ExcelShopInfo info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + foreach (var shop_textile in info.ShopTextiles) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = shop_textile.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (textile, count) in shop_textile.Textiles) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = textile, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = shop_textile.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(IDocumentInfo info); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void MergeCells(ExcelMergeParameters excelParams); - protected abstract void SaveExcel(ExcelInfo info); + protected abstract void SaveExcel(IDocumentInfo info); } } diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 1ebdd6d..e8acb1d 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels { - public class ExcelInfo + public class ExcelInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs new file mode 100644 index 0000000..5f056fd --- /dev/null +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs @@ -0,0 +1,16 @@ +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShopInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ShopTextiles { get; set; } = new(); + } +} diff --git a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index b32c1c9..c125141 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -159,7 +159,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements }; } - protected override void CreateExcel(ExcelInfo info) + protected override void CreateExcel(IDocumentInfo info) { _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); // Создание книги (в ней хранятся листы) @@ -288,7 +288,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements mergeCells.Append(mergeCell); } - protected override void SaveExcel(ExcelInfo info) + protected override void SaveExcel(IDocumentInfo info) { if (_spreadsheetDocument == null) { diff --git a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 05bf2f1..6a90822 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -136,13 +136,13 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements _wordDocument.Close(); } - private Table? _lastTable; + private Table? _table; protected override void CreateTable(List columns) { if (_docBody == null) return; - _lastTable = new Table(); + _table = new Table(); var tableProp = new TableProperties(); tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); @@ -155,21 +155,21 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } )); tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); - _lastTable.AppendChild(tableProp); + _table.AppendChild(tableProp); TableGrid tableGrid = new TableGrid(); foreach (var column in columns) { tableGrid.AppendChild(new GridColumn() { Width = column }); } - _lastTable.AppendChild(tableGrid); + _table.AppendChild(tableGrid); - _docBody.AppendChild(_lastTable); + _docBody.AppendChild(_table); } protected override void CreateRow(WordRowParameters rowParameters) { - if (_docBody == null || _lastTable == null) + if (_docBody == null || _table == null) return; TableRow docRow = new TableRow(); @@ -205,7 +205,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements docCell.AppendChild(docParagraph); docRow.AppendChild(docCell); } - _lastTable.AppendChild(docRow); + _table.AppendChild(docRow); } } } diff --git a/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs b/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs index 685ee72..cd762fb 100644 --- a/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs @@ -14,6 +14,8 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts List GetOrders(ReportBindingModel model); + List GetShops(); + void SaveTextilesToWordFile(ReportBindingModel model); void SaveTextileComponentToExcelFile(ReportBindingModel model); @@ -21,7 +23,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts void SaveOrdersToPdfFile(ReportBindingModel model); void SaveShopsToWordFile(ReportBindingModel model); - //void SaveShopsToExcelFile(ReportBindingModel model); + void SaveShopsToExcelFile(ReportBindingModel model); //void SaveGroupedOrdersToPdfFile(ReportBindingModel model); } From 243f9e7db06cb4543bc041c7091ddfd52594f6b7 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Fri, 14 Jun 2024 17:17:44 +0400 Subject: [PATCH 14/15] =?UTF-8?q?=D0=9E=D1=82=D1=87=D1=91=D1=82=20pdf=20+?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/GarmentFactoryView.csproj | 3 + GarmentFactory/ReportGroupedOrders.rdlc | 444 ++++++++++++++++++ .../BusinessLogics/ReportLogic.cs | 36 +- .../OfficePackage/AbstractSaveToPdf.cs | 35 +- .../HelperModels/PdfGroupedOrdersInfo.cs | 16 + .../OfficePackage/HelperModels/PdfInfo.cs | 2 +- .../OfficePackage/Implements/SaveToPdf.cs | 4 +- .../BusinessLogicsContracts/IReportLogic.cs | 4 +- .../ReportGroupedOrdersViewModel.cs | 15 + 9 files changed, 535 insertions(+), 24 deletions(-) create mode 100644 GarmentFactory/ReportGroupedOrders.rdlc create mode 100644 GarmentFactoryBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs create mode 100644 GarmentFactoryContracts/ViewModels/ReportGroupedOrdersViewModel.cs diff --git a/GarmentFactory/GarmentFactoryView.csproj b/GarmentFactory/GarmentFactoryView.csproj index 6b48d02..1ec32c7 100644 --- a/GarmentFactory/GarmentFactoryView.csproj +++ b/GarmentFactory/GarmentFactoryView.csproj @@ -44,6 +44,9 @@ + + Always + Always diff --git a/GarmentFactory/ReportGroupedOrders.rdlc b/GarmentFactory/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..2eaa478 --- /dev/null +++ b/GarmentFactory/ReportGroupedOrders.rdlc @@ -0,0 +1,444 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 20791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + GarmentFactoryContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + OrdersCount + System.Int32 + + + OrdersSum + System.Decimal + + + + GarmentFactoryContracts.ViewModels + ReportGroupedOrdersViewModel + GarmentFactoryContracts.ViewModels.ReportGroupedOrdersViewModel, GarmentFactoryContracts, 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 +