ISEbd-21 Melnikov I. O. Lab Work 02 Advanced #16

Closed
Igor-Melnikov wants to merge 5 commits from lab2adv into lab1adv
29 changed files with 1227 additions and 10 deletions

View File

@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessL
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{D57FFF62-0A87-4995-9693-317A94689469}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{0FFB9D8A-1B02-4622-AD31-DB88F4201350}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -39,6 +41,10 @@ Global
{D57FFF62-0A87-4995-9693-317A94689469}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D57FFF62-0A87-4995-9693-317A94689469}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D57FFF62-0A87-4995-9693-317A94689469}.Release|Any CPU.Build.0 = Release|Any CPU
{0FFB9D8A-1B02-4622-AD31-DB88F4201350}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FFB9D8A-1B02-4622-AD31-DB88F4201350}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FFB9D8A-1B02-4622-AD31-DB88F4201350}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FFB9D8A-1B02-4622-AD31-DB88F4201350}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -26,6 +26,7 @@
<ItemGroup>
<ProjectReference Include="..\BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj" />
</ItemGroup>

View File

@ -40,6 +40,7 @@
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.buttonFillStore = new System.Windows.Forms.Button();
this.buttonSellManufacture = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -67,21 +68,21 @@
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.componentsToolStripMenuItem.Text = "Компоненты";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// manufacturesToolStripMenuItem
//
this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem";
this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.manufacturesToolStripMenuItem.Text = "Изделия";
this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click);
//
// storesToolStripMenuItem
//
this.storesToolStripMenuItem.Name = "storesToolStripMenuItem";
this.storesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.storesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.storesToolStripMenuItem.Text = "Магазины";
this.storesToolStripMenuItem.Click += new System.EventHandler(this.StoresToolStripMenuItem_Click);
//
@ -161,11 +162,22 @@
this.buttonFillStore.UseVisualStyleBackColor = true;
this.buttonFillStore.Click += new System.EventHandler(this.ButtonFillStore_Click);
//
// buttonSellManufacture
//
this.buttonSellManufacture.Location = new System.Drawing.Point(814, 201);
this.buttonSellManufacture.Name = "buttonSellManufacture";
this.buttonSellManufacture.Size = new System.Drawing.Size(282, 23);
this.buttonSellManufacture.TabIndex = 3;
this.buttonSellManufacture.Text = "Продать изделие";
this.buttonSellManufacture.UseVisualStyleBackColor = true;
this.buttonSellManufacture.Click += new System.EventHandler(this.ButtonSellManufacture_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1108, 504);
this.Controls.Add(this.buttonSellManufacture);
this.Controls.Add(this.buttonFillStore);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
@ -200,5 +212,6 @@
private Button buttonRef;
private ToolStripMenuItem storesToolStripMenuItem;
private Button buttonFillStore;
private Button buttonSellManufacture;
}
}

View File

@ -162,5 +162,13 @@ namespace BlacksmithWorkshopView
form.ShowDialog();
}
}
private void ButtonSellManufacture_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture));
if (service is FormSellManufacture form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,121 @@
namespace BlacksmithWorkshopView
{
partial class FormSellManufacture
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSell = new System.Windows.Forms.Button();
this.labelCount = new System.Windows.Forms.Label();
this.labelManufacture = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.comboBoxManufacture = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(256, 70);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 15;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(175, 70);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(75, 23);
this.buttonSell.TabIndex = 16;
this.buttonSell.Text = "Продать";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(12, 44);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(72, 15);
this.labelCount.TabIndex = 13;
this.labelCount.Text = "Количество";
//
// labelManufacture
//
this.labelManufacture.AutoSize = true;
this.labelManufacture.Location = new System.Drawing.Point(12, 15);
this.labelManufacture.Name = "labelManufacture";
this.labelManufacture.Size = new System.Drawing.Size(53, 15);
this.labelManufacture.TabIndex = 14;
this.labelManufacture.Text = "Изделие";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(107, 41);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(224, 23);
this.textBoxCount.TabIndex = 12;
//
// comboBoxManufacture
//
this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxManufacture.FormattingEnabled = true;
this.comboBoxManufacture.Location = new System.Drawing.Point(107, 12);
this.comboBoxManufacture.Name = "comboBoxManufacture";
this.comboBoxManufacture.Size = new System.Drawing.Size(224, 23);
this.comboBoxManufacture.TabIndex = 11;
//
// FormSellManufacture
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(347, 107);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelManufacture);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxManufacture);
this.Name = "FormSellManufacture";
this.Text = "Продажа изделия";
this.Load += new System.EventHandler(this.FormFillStore_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSell;
private Label labelCount;
private Label labelManufacture;
private TextBox textBoxCount;
private ComboBox comboBoxManufacture;
}
}

View File

@ -0,0 +1,65 @@
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
{
public partial class FormSellManufacture : Form
{
private readonly ILogger _logger;
private readonly IStoreLogic _logicS;
private readonly IManufactureLogic _logicM;
public FormSellManufacture(ILogger<FormCreateOrder> logger, IStoreLogic logicS, IManufactureLogic logicM)
{
InitializeComponent();
_logger = logger;
_logicS = logicS;
_logicM = logicM;
}
private void FormFillStore_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка изделий");
var listM = _logicM.ReadList(null);
if (listM != null)
{
comboBoxManufacture.DisplayMember = "ManufactureName";
comboBoxManufacture.ValueMember = "Id";
comboBoxManufacture.DataSource = listM;
comboBoxManufacture.SelectedItem = null;
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (comboBoxManufacture.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (Convert.ToInt32(textBoxCount.Text) <= 0)
{
MessageBox.Show("Количество должно быть больше нуля", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var count = Convert.ToInt32(textBoxCount.Text);
var manufacture = _logicM.ReadElement(new()
{
Id = Convert.ToInt32(comboBoxManufacture.SelectedValue)
});
if (manufacture == null || !_logicS.SellManufactures(manufacture, count))
{
MessageBox.Show("Не удалось продать изделия. Информацию смотрите в логах", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -40,6 +40,8 @@
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnPrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.textBoxMaxManufactures = new System.Windows.Forms.TextBox();
this.labelMaxManufactures = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
@ -143,6 +145,22 @@
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.Name = "ColumnCount";
//
// textBoxMaxManufactures
//
this.textBoxMaxManufactures.Location = new System.Drawing.Point(493, 15);
this.textBoxMaxManufactures.Name = "textBoxMaxManufactures";
this.textBoxMaxManufactures.Size = new System.Drawing.Size(132, 23);
this.textBoxMaxManufactures.TabIndex = 4;
//
// labelMaxManufactures
//
this.labelMaxManufactures.AutoSize = true;
this.labelMaxManufactures.Location = new System.Drawing.Point(400, 18);
this.labelMaxManufactures.Name = "labelMaxManufactures";
this.labelMaxManufactures.Size = new System.Drawing.Size(87, 15);
this.labelMaxManufactures.TabIndex = 6;
this.labelMaxManufactures.Text = "Макс. изделий";
//
// FormStore
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -154,8 +172,10 @@
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.labelOpeningDate);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelMaxManufactures);
this.Controls.Add(this.labelName);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxMaxManufactures);
this.Controls.Add(this.textBoxName);
this.Name = "FormStore";
this.Text = "Магазин";
@ -180,5 +200,7 @@
private DataGridViewTextBoxColumn ColumnManufactureName;
private DataGridViewTextBoxColumn ColumnPrice;
private DataGridViewTextBoxColumn ColumnCount;
private TextBox textBoxMaxManufactures;
private Label labelMaxManufactures;
}
}

View File

@ -38,6 +38,7 @@ namespace BlacksmithWorkshopView
textBoxName.Text = view.StoreName;
textBoxAddress.Text = view.Address;
dateTimePicker.Value = view.OpeningDate;
textBoxMaxManufactures.Text = view.MaxManufactures.ToString();
}
LoadData();
}
@ -89,6 +90,21 @@ namespace BlacksmithWorkshopView
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMaxManufactures.Text))
{
MessageBox.Show("Заполните максимальное количество изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int maxManufactures;
try//штоб программа не упала
{
maxManufactures = Convert.ToInt32(textBoxMaxManufactures.Text);
}
catch
{
MessageBox.Show("Неверное значение в поле Макс. изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
@ -97,7 +113,8 @@ namespace BlacksmithWorkshopView
Id = _id ?? 0,
StoreName = textBoxName.Text,
Address = textBoxAddress.Text,
OpeningDate = dateTimePicker.Value
OpeningDate = dateTimePicker.Value,
MaxManufactures = maxManufactures
};
var operationResult = _id.HasValue ? _logicS.Update(model) : _logicS.Create(model);
if (!operationResult)

View File

@ -3,7 +3,7 @@ using BlacksmithWorkShopBusinessLogic.BusinessLogics;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopListImplement.Implements;
using BlacksmithWorkshopFileImplement.Implements;
using BlacksmithWorkshopView;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -51,6 +51,7 @@ namespace BlacksmithWorkshopView
services.AddTransient<FormStore>();
services.AddTransient<FormStores>();
services.AddTransient<FormFillStore>();
services.AddTransient<FormSellManufacture>();
}
}
}

View File

@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
@ -12,10 +13,14 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IManufactureStorage _manufactureStorage;
private readonly IStoreLogic _storeLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IManufactureStorage manufactureStorage, IStoreLogic storeLogic)
{
_logger = logger;
_orderStorage = orderStorage;
_manufactureStorage = manufactureStorage;
_storeLogic = storeLogic;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
@ -48,7 +53,22 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
{
return true;
}
}
if (newstatus == OrderStatus.Выдан)
{
if (vm == null)
{
return false;
}
var manufacture = _manufactureStorage.GetElement(new ManufactureSearchModel
{
Id = vm.ManufactureId
});
if (manufacture == null || !_storeLogic.FillStore(manufacture, vm.Count))
{
throw new Exception("Не удалось заполнить магазины");
}
}
}
_logger.LogWarning($"Changing order status of order {model.Id} to {newstatus} failed");
return false;
}

View File

@ -6,6 +6,7 @@ using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using Microsoft.Extensions.Logging;
using System.Security.Cryptography.X509Certificates;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
@ -109,6 +110,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
_logger.LogWarning("Store with id {Id} not found", model.Id);
return false;
}
var placeLeft = _storeStorage.GetPlaceLeft(selectedStore);
if (placeLeft < count)
{
_logger.LogWarning("Store with id {Id} can't accomodate {Count} items", model.Id, count);
return false;
}
//ищем изделие в магазине
if (selectedStore.Manufactures.TryGetValue(manufacture.Id, out var manufactureInStore))
{
@ -142,7 +149,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет адреса магазина", nameof(model.StoreName));
}
_logger.LogInformation("Store. StoreName: {StoreName}. Address: {Address}. Id: {Id}", model.StoreName, model.Address, model.Id);
var element = _storeStorage.GetElement(new StoreSearchModel//проверка на уникальность
var element = _storeStorage.GetElement(new StoreSearchModel
{
StoreName = model.StoreName
});
@ -150,6 +157,59 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
if (model.MaxManufactures <= 0)
{
throw new ArgumentException("Максимальное количество изделий не может быть меньше единицы", nameof(model.MaxManufactures));
}
}
public int GetFreePlace(int count)
{
int result;
var stores = _storeStorage.GetFullList();
result = stores//Получаем общее число свободных мест в магазине
.Select(x => x.MaxManufactures/*максимальное число мест в магазине*/ - x.Manufactures.Select(m => m.Value.Item2).Sum()).Sum()/*количество занятых мест до добавления изделия*/;
result -= count;//Получаем общее число свободных мест после добавления изделия
return result;
}
public bool FillStore(IManufactureModel manufacture, int count)
{
if (count <= 0)
{
_logger.LogWarning("Количество добавляемых изделий должно быть больше 0.");
return false;
}
var freePlaces = GetFreePlace(count);
if (freePlaces < 0)
{
_logger.LogInformation("Магазины переполнены.");
return false;
}
foreach (var store in _storeStorage.GetFullList())//добавляем изделие во все магазины
{
var cnt = Math.Min(count, store.MaxManufactures - store.Manufactures.Select(x => x.Value.Item2).Sum());
if (cnt <= 0)
{
continue;
}
if (!AddManufacture(manufacture, new StoreSearchModel()
{
Id = store.Id
}, cnt))
{
_logger.LogWarning("При добавлении изделий произошла ошибка");
return false;
}
count -= cnt;
if (count == 0)
{
return true;
}
}
return true;
}
public bool SellManufactures(IManufactureModel manufacture, int count)
{
return _storeStorage.SellManufacture(manufacture, count);
}
}
}

View File

@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.BindingModels
/// Изделия в магазине
/// </summary>
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
public int MaxManufactures { get; set; }
}
}

View File

@ -20,5 +20,8 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
/// <param name="count">Количество изделий</param>
/// <returns></returns>
bool AddManufacture(IManufactureModel manufacture, StoreSearchModel model, int count);
int GetFreePlace(int count);
bool FillStore(IManufactureModel manufacture, int count);
public bool SellManufactures(IManufactureModel manufacture, int needCount);
}
}

View File

@ -13,5 +13,20 @@ namespace BlacksmithWorkshopContracts.StoragesContracts
StoreViewModel? Insert(StoreBindingModel model);
StoreViewModel? Update(StoreBindingModel model);
StoreViewModel? Delete(StoreBindingModel model);
/// <summary>
/// Проверка наличия изделия в нужном количестве
/// </summary>
/// <param name="manufacture">Изделие</param>
/// <param name="count">Количество</param>
/// <returns></returns>
bool HasManufactures(IManufactureModel manufacture, int count);
/// <summary>
/// Продажа изделия в нужном количестве
/// </summary>
/// <param name="manufacture">Изделие</param>
/// <param name="count">Количество</param>
/// <returns></returns>
bool SellManufacture(IManufactureModel manufacture, int count);
int GetPlaceLeft(IStoreModel store);
}
}

View File

@ -17,5 +17,7 @@ namespace BlacksmithWorkshopContracts.ViewModels
/// Изделия в магазине
/// </summary>
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
[DisplayName("Макс. изделий")]
public int MaxManufactures { get; set; }
}
}

View File

@ -6,5 +6,6 @@
string Address { get; }
DateTime OpeningDate { get; }
Dictionary<int, (IManufactureModel, int)> Manufactures { get; }
int MaxManufactures { get; }
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,51 @@
using BlacksmithWorkshopFileImplement.Models;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement
{
internal class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ManufactureFileName = "Manufacture.xml";
private readonly string StoreFileName = "Store.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Manufacture> Manufactures { get; private set; }
public List<Store> Stores { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, "Manufactures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveStores() => SaveData(Stores, StoreFileName, "Stores", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Stores = LoadData(StoreFileName, "Store", x => Store.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,76 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataFileSingleton source;
public ComponentStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
return source.Components
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
return source.Components
.Where(x => x.ComponentName.Contains(model.ComponentName))
.Select(x => x.GetViewModel)
.ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
source.Components.Add(newComponent);
source.SaveComponents();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
source.SaveComponents();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Components.Remove(element);
source.SaveComponents();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,76 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class ManufactureStorage : IManufactureStorage
{
private readonly DataFileSingleton source;
public ManufactureStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ManufactureViewModel> GetFullList()
{
return source.Manufactures
.Select(x => x.GetViewModel)
.ToList();
}
public List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model)
{
if (string.IsNullOrEmpty(model.ManufactureName))
{
return new();
}
return source.Manufactures
.Where(x => x.ManufactureName.Contains(model.ManufactureName))
.Select(x => x.GetViewModel)
.ToList();
}
public ManufactureViewModel? GetElement(ManufactureSearchModel model)
{
if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue)
{
return null;
}
return source.Manufactures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ManufactureViewModel? Insert(ManufactureBindingModel model)
{
model.Id = source.Manufactures.Count > 0 ? source.Manufactures.Max(x => x.Id) + 1 : 1;
var newManufacture = Manufacture.Create(model);
if (newManufacture == null)
{
return null;
}
source.Manufactures.Add(newManufacture);
source.SaveManufactures();
return newManufacture.GetViewModel;
}
public ManufactureViewModel? Update(ManufactureBindingModel model)
{
var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == model.Id);
if (manufacture == null)
{
return null;
}
manufacture.Update(model);
source.SaveManufactures();
return manufacture.GetViewModel;
}
public ManufactureViewModel? Delete(ManufactureBindingModel model)
{
var element = source.Manufactures.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Manufactures.Remove(element);
source.SaveManufactures();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,87 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
using System.Collections.Generic;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
private OrderViewModel AddManufactureName (OrderViewModel model)
{
model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty;
return model;
}
public List<OrderViewModel> GetFullList()
{
return source.Orders
.Select(x => AddManufactureName(x.GetViewModel))
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model.Id == null)
{
return new();
}
return source.Orders
.Where(x => x.Id == model.Id)
.Select(x => AddManufactureName(x.GetViewModel))
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
var order = source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
if (order == null)
{
return null;
}
return AddManufactureName(order);
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
source.Orders.Add(newOrder);
source.SaveOrders();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
source.SaveOrders();
return order.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Orders.Remove(element);
source.SaveOrders();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,126 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using BlacksmithWorkshopFileImplement.Models;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class StoreStorage : IStoreStorage
{
private readonly DataFileSingleton source;
public StoreStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<StoreViewModel> GetFullList()
{
return source.Stores
.Select(x => x.GetViewModel)
.ToList();
}
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
{
if (model.Id.HasValue)//сначала ищем по Id
{
return source.Stores
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (!string.IsNullOrEmpty(model.StoreName))//далее по названию магазина
{
return source.Stores
.Where(x => x.StoreName.Contains(model.StoreName))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public StoreViewModel? GetElement(StoreSearchModel model)
{
if (model.Id.HasValue)//сначала ищем по Id
{
return source.Stores
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
else if (!string.IsNullOrEmpty(model.StoreName))//далее по названию магазина
{
return source.Stores
.FirstOrDefault(x => x.StoreName.Contains(model.StoreName))?.GetViewModel;
}
return null;
}
public StoreViewModel? Insert(StoreBindingModel model)
{
model.Id = source.Stores.Count > 0 ? source.Stores.Max(x => x.Id) + 1 : 1;
var newStore = Store.Create(model);
if (newStore == null)
{
return null;
}
source.Stores.Add(newStore);
source.SaveStores();
return newStore.GetViewModel;
}
public StoreViewModel? Update(StoreBindingModel model)
{
var store = source.Stores.FirstOrDefault(x => x.StoreName == model.StoreName);
if (store == null)
{
return null;
}
store.Update(model);
source.SaveStores();
return store.GetViewModel;
}
public StoreViewModel? Delete(StoreBindingModel model)
{
var element = source.Stores.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Stores.Remove(element);
source.SaveStores();
return element.GetViewModel;
}
return null;
}
public bool HasManufactures(IManufactureModel manufacture, int count)
{
var currentCount = source.Stores
.Select(x => x.Manufactures
.FirstOrDefault(x => x.Key == manufacture.Id).Value.Item2)
.Sum();
return currentCount >= count;
}
public bool SellManufacture(IManufactureModel manufacture, int count)
{
if (!HasManufactures(manufacture, count))
{
return false;
}
foreach (var store in source.Stores.Where(x => x.Manufactures.ContainsKey(manufacture.Id)))
Review

Значение можно получить через LINQ-запрос

Значение можно получить через LINQ-запрос
{
var difference = Math.Min(store.Manufactures[manufacture.Id].Item2, count);
store.Manufactures[manufacture.Id] = (store.Manufactures[manufacture.Id].Item1, store.Manufactures[manufacture.Id].Item2 - difference);
count -= difference;
if (count <= 0)
{
return true;
}
}
return true;
}
public int GetPlaceLeft(IStoreModel model)
{
var store = source.Stores.FirstOrDefault(x => x.Id == model.Id);
if (store == null)
{
return 0;
}
return store.MaxManufactures - store.Manufactures.Select(x => x.Value.Item2).Sum();
}
}
}

View File

@ -0,0 +1,63 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost {get; set; }
public static Component? Create(ComponentBindingModel model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
public XElement GetXElement => new
(
"Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString())
);
}
}

View File

@ -0,0 +1,94 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
public class Manufacture : IManufactureModel
{
public int Id { get; private set; }
public string ManufactureName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _manufactureComponents = null;
public Dictionary<int, (IComponentModel, int)> ManufactureComponents
{
get
{
if (_manufactureComponents == null)
{
var source = DataFileSingleton.GetInstance();
_manufactureComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
y.Value));
}
return _manufactureComponents;
}
}
public static Manufacture? Create(ManufactureBindingModel model)
{
if (model == null)
{
return null;
}
return new Manufacture()
{
Id = model.Id,
ManufactureName = model.ManufactureName,
Price = model.Price,
Components = model.ManufactureComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Manufacture? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Manufacture()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureName = element.Element("ManufactureName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("ManufactureComponents")!.Elements("ManufactureComponent") .ToDictionary
(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value)
)
};
}
public void Update(ManufactureBindingModel model)
{
if (model == null)
{
return;
}
ManufactureName = model.ManufactureName;
Price = model.Price;
Components = model.ManufactureComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_manufactureComponents = null;
}
public ManufactureViewModel GetViewModel => new()
{
Id = Id,
ManufactureName = ManufactureName,
Price = Price,
ManufactureComponents = ManufactureComponents
};
public XElement GetXElement => new
(
"Manufacture",
new XAttribute("Id", Id),
new XElement("ManufactureName", ManufactureName),
new XElement("Price", Price.ToString()),
new XElement("ManufactureComponents", Components.Select
(x => new XElement
(
"ManufactureComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value)
)
).ToArray())
);
}
}

View File

@ -0,0 +1,91 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Enums;
using BlacksmithWorkshopDataModels.Models;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ManufactureId {get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ManufactureId = model.ManufactureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
DateTime? dateImplement = null;
if (element.Element("DateImplement")!.Value != "")
{
dateImplement = Convert.ToDateTime(element.Element("DateImplement")!.Value);
}
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = dateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
if (model.DateImplement != null)
{
DateImplement = model.DateImplement;
}
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ManufactureId = ManufactureId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
public XElement GetXElement => new
(
"Order",
new XAttribute("Id", Id),
new XElement("ManufactureId", ManufactureId),
new XElement("Count", Count),
new XElement("Sum", Sum),
new XElement("Status", (int)Status),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement)
);
}
}

View File

@ -0,0 +1,107 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.Diagnostics;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
public class Store : IStoreModel
{
public int Id { get; private set; }
public string StoreName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; } = DateTime.Now;
public Dictionary<int, int> SavedManufactures { get; private set; } = new();
private Dictionary<int, (IManufactureModel, int)>? _manufactures = null;
public Dictionary<int, (IManufactureModel, int)> Manufactures
{
get
{
if (_manufactures == null)
{
var source = DataFileSingleton.GetInstance();
_manufactures = SavedManufactures.ToDictionary(x => x.Key, y =>
((source.Manufactures.FirstOrDefault(z => z.Id == y.Key) as IManufactureModel)!,
y.Value));
}
return _manufactures;
}
}
public int MaxManufactures { get; private set; }
public static Store? Create(StoreBindingModel model)
{
if (model == null)
{
return null;
}
return new Store()
{
Id = model.Id,
StoreName = model.StoreName,
Address = model.Address,
OpeningDate = model.OpeningDate,
SavedManufactures = model.Manufactures.ToDictionary(x => x.Value.Item1.Id, x => x.Value.Item2),
MaxManufactures = model.MaxManufactures,
};
}
public static Store? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Store()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
StoreName = element.Element("StoreName")!.Value,
Address = element.Element("Address")!.Value,
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
SavedManufactures = element.Element("Manufactures")!.Elements("Manufacture").ToDictionary
(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value)
),
MaxManufactures = Convert.ToInt32(element.Element("MaxManufactures")!.Value)
};
}
public void Update(StoreBindingModel model)
{
if (model == null)
{
return;
}
StoreName = model.StoreName;
Address = model.Address;
OpeningDate= model.OpeningDate;
SavedManufactures = model.Manufactures.ToDictionary(x => x.Value.Item1.Id, x => x.Value.Item2);
_manufactures = null;
}
public StoreViewModel GetViewModel => new()
{
Id = Id,
StoreName = StoreName,
Address = Address,
OpeningDate = OpeningDate,
Manufactures = Manufactures,
MaxManufactures = MaxManufactures
};
public XElement GetXElement => new
(
"Store",
new XAttribute("Id", Id),
new XElement("StoreName", StoreName),
new XElement("Address", Address),
new XElement("OpeningDate", OpeningDate),
new XElement("Manufactures", SavedManufactures.Select
(x => new XElement
(
"Manufacture",
new XElement("Key", x.Key),
new XElement("Value", x.Value)
)
).ToArray()),
new XElement("MaxManufactures", MaxManufactures)
);
}
}

View File

@ -100,5 +100,18 @@ namespace BlacksmithWorkshopListImplement.Implements
}
return null;
}
public bool HasManufactures(IManufactureModel manufacture, int count)
{
throw new NotImplementedException("Не применяется в данной реализации");
}
public bool SellManufacture(IManufactureModel manufacture, int count)
{
throw new NotImplementedException("Не применяется в данной реализации");
}
public int GetPlaceLeft(IStoreModel store)
{
throw new NotImplementedException("Не применяется в данной реализации");
}
}
}

View File

@ -11,6 +11,7 @@ namespace BlacksmithWorkshopListImplement.Models
public string Address { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; private set; } = new();
public int MaxManufactures { get; private set; }
public static Store? Create(StoreBindingModel? model)
{
if (model == null)
@ -23,7 +24,8 @@ namespace BlacksmithWorkshopListImplement.Models
StoreName = model.StoreName,
Address = model.Address,
OpeningDate = model.OpeningDate,
Manufactures = new()
Manufactures = new(),
MaxManufactures = model.MaxManufactures
};
}
public void Update(StoreBindingModel? model)
@ -36,6 +38,7 @@ namespace BlacksmithWorkshopListImplement.Models
Address = model.Address;
OpeningDate = model.OpeningDate;
Manufactures = model.Manufactures;
MaxManufactures = model.MaxManufactures;
}
public StoreViewModel GetViewModel => new()
{
@ -43,7 +46,8 @@ namespace BlacksmithWorkshopListImplement.Models
StoreName = StoreName,
Address = Address,
OpeningDate = OpeningDate,
Manufactures = Manufactures
Manufactures = Manufactures,
MaxManufactures = MaxManufactures
};
}
}