laba2_hard

This commit is contained in:
Дмитрий Блохин 2024-06-16 23:15:45 +04:00
parent bd5299546e
commit fef056226a
21 changed files with 990 additions and 293 deletions

View File

@ -17,11 +17,15 @@ namespace FishFactoryBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopLogic _shopLogic;
private readonly ICannedStorage _cannedStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, ICannedStorage cannedStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopLogic = shopLogic;
_cannedStorage = cannedStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
@ -66,7 +70,24 @@ namespace FishFactoryBusinessLogic.BusinessLogics
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
model.Status = status;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
var canned = _cannedStorage.GetElement(new() { Id = element.CannedId });
if (canned == null)
{
throw new ArgumentNullException(nameof(canned));
}
if (!_shopLogic.AddCanned(canned, element.Count))
{
throw new Exception($"AddCanned operation failed. Shop is full.");
}
}
else
{
model.DateImplement = element.DateImplement;
}
CheckModel(model, false);
_orderStorage.Update(model);
return true;
}

View File

@ -98,6 +98,12 @@ namespace FishFactoryBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
}
if (model.MaxCountCanned < 0)
{
throw new ArgumentException(
"Максимальное количество консервы в магазине не может быть меньше нуля",
nameof(model.MaxCountCanned));
}
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
@ -128,6 +134,10 @@ namespace FishFactoryBusinessLogic.BusinessLogics
_logger.LogWarning("AddCannedInShop element not found");
return false;
}
if (element.MaxCountCanned - element.ListCanned.Select(x => x.Value.Item2).Sum() < count)
{
throw new ArgumentNullException("Магазин переполнен", nameof(count));
}
_logger.LogInformation("AddCannedInShop find. Id:{Id}", element.Id);
if (element.ListCanned.TryGetValue(Canned.Id, out var pair))
@ -150,9 +160,61 @@ namespace FishFactoryBusinessLogic.BusinessLogics
Address = element.Address,
ShopName = element.ShopName,
DateOpening = element.DateOpening,
MaxCountCanned = element.MaxCountCanned,
ListCanned = element.ListCanned
});
return true;
}
public bool AddCanned(ICannedModel model, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
throw new ArgumentException("Количество консерв должно быть больше 0", nameof(count));
}
var freeCount = _shopStorage.GetFullList()
.Select(x => x.MaxCountCanned - x.ListCanned
.Select(p => p.Value.Item2).Sum()).Sum() - count;
if (freeCount < 0)
{
_logger.LogInformation("AddCanned. Не удалось добавить изделия в магазины, они переполнены.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
int countFree = shop.MaxCountCanned - shop.ListCanned.Select(x => x.Value.Item2).Sum();
if (countFree < count)
{
if (!AddCannedInShop(new() { Id = shop.Id }, model, countFree))
{
_logger.LogWarning("AddCannedInShop operation failed.");
return false;
}
count -= countFree;
}
else
{
if (!AddCannedInShop(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddCannedInShop operation failed.");
return false;
}
count = 0;
}
if (count == 0)
{
return true;
}
}
return false;
}
public bool SellCanned(ICannedModel model, int count)
{
return _shopStorage.SellCanned(model, count);
}
}
}

View File

@ -15,6 +15,7 @@ namespace FishFactoryContracts.BindingModels
public string Address { get; set; } = string.Empty;
public DateTime DateOpening { get; set; } = DateTime.Now;
public int MaxCountCanned { get; set; }
public Dictionary<int, (ICannedModel, int)> ListCanned
{

View File

@ -18,5 +18,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool AddCannedInShop(ShopSearchModel model, ICannedModel canned, int count);
bool AddCanned(ICannedModel canned, int count);
bool SellCanned(ICannedModel canned, int count);
}
}

View File

@ -1,6 +1,7 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -17,5 +18,6 @@ namespace FishFactoryContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SellCanned(ICannedModel model, int count);
}
}

View File

@ -19,6 +19,8 @@ namespace FishFactoryContracts.ViewModels
[DisplayName("Дата открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;
[DisplayName("Максимальное количество консерв")]
public int MaxCountCanned { get; set; }
public Dictionary<int, (ICannedModel, int)> ListCanned
{

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,6 +12,7 @@ namespace FishFactoryDataModels.Models
string ShopName { get; }
string Address { get; }
DateTime DateOpening { get; }
int MaxCountCanned { get; }
Dictionary<int, (ICannedModel, int)> ListCanned { get; }
}
}

View File

@ -14,9 +14,11 @@ namespace FishFactoryFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string CannedFileName = "Canned.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Canned> Canneds { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -44,11 +46,13 @@ namespace FishFactoryFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveCannedes() => SaveData(Canneds, CannedFileName, "Canneds", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Canneds = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
}
}

View File

@ -0,0 +1,107 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using FishFactoryFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(x => x.GetViewModel).ToList();
}
public List<ShopViewModel> 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 element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Shops.Remove(element);
source.SaveShops();
return element.GetViewModel;
}
return null;
}
public bool SellCanned(ICannedModel model, int count)
{
if (source.Shops.Select(x => x.ListCanned.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < count)
{
return false;
}
foreach (var shop in source.Shops.Where(x => x.ListCanned.ContainsKey(model.Id)))
{
int countInCurrentShop = shop.ListCanned[model.Id].Item2;
if (countInCurrentShop <= count)
{
shop.ListCanned.Remove(model.Id);
count -= countInCurrentShop;
}
else
{
shop.ListCanned[model.Id] = (shop.ListCanned[model.Id].Item1, countInCurrentShop - count);
count = 0;
}
if (count == 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -35,7 +35,8 @@ namespace FishFactoryFileImplement.Models
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public static Order? Create(XElement element)

View File

@ -0,0 +1,108 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpening { get; private set; }
public int MaxCountCanned { get; private set; }
public Dictionary<int, int> CountCanned
{
get;
private set;
} = new();
private Dictionary<int, (ICannedModel, int)>? _shopCanned = null;
public Dictionary<int, (ICannedModel, int)> ListCanned
{
get
{
if (_shopCanned == null)
{
var source = DataFileSingleton.GetInstance();
_shopCanned =
CountCanned.ToDictionary(x => x.Key,
y => ((source.Canneds.FirstOrDefault(z => z.Id == y.Key) as ICannedModel)!, y.Value));
}
return _shopCanned;
}
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
MaxCountCanned = model.MaxCountCanned,
DateOpening = model.DateOpening,
CountCanned = model.ListCanned.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
MaxCountCanned = Convert.ToInt32(element.Element("MaxCountCanned")!.Value),
CountCanned = element.Element("ListCanned")!.Elements("Canned").ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpening = model.DateOpening;
MaxCountCanned = model.MaxCountCanned;
CountCanned = model.ListCanned.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopCanned = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
ListCanned = ListCanned,
DateOpening = DateOpening,
MaxCountCanned = MaxCountCanned,
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpening", DateOpening),
new XElement("MaxCountCanned", MaxCountCanned),
new XElement("ListCanned", CountCanned.Select(x => new XElement("Canned",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -2,6 +2,7 @@
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using FishFactoryListImplement.Models;
using System;
using System.Collections.Generic;
@ -103,5 +104,9 @@ namespace FishFactoryListImplement.Implements
}
return null;
}
public bool SellCanned(ICannedModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -54,5 +54,6 @@ namespace FishFactoryListImplement.Models
ListCanned = ListCanned,
DateOpening = DateOpening,
};
public int MaxCountCanned => throw new NotImplementedException();
}
}

View File

@ -0,0 +1,119 @@
namespace FishFactoryView
{
partial class FormSellCanned
{
/// <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()
{
comboBoxCanned = new ComboBox();
textBoxCount = new TextBox();
labelCanned = new Label();
labelCount = new Label();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// comboBoxCanned
//
comboBoxCanned.FormattingEnabled = true;
comboBoxCanned.Location = new Point(162, 27);
comboBoxCanned.Name = "comboBoxCanned";
comboBoxCanned.Size = new Size(244, 28);
comboBoxCanned.TabIndex = 0;
//
// textBoxCount
//
textBoxCount.Location = new Point(162, 81);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(244, 27);
textBoxCount.TabIndex = 1;
//
// labelCanned
//
labelCanned.AutoSize = true;
labelCanned.Location = new Point(25, 30);
labelCanned.Name = "labelCanned";
labelCanned.Size = new Size(76, 20);
labelCanned.TabIndex = 2;
labelCanned.Text = "Консерва";
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(25, 84);
labelCount.Name = "labelCount";
labelCount.Size = new Size(90, 20);
labelCount.TabIndex = 3;
labelCount.Text = "Количество";
//
// buttonSave
//
buttonSave.Location = new Point(162, 150);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(300, 150);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormSellCanned
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(418, 191);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelCount);
Controls.Add(labelCanned);
Controls.Add(textBoxCount);
Controls.Add(comboBoxCanned);
Name = "FormSellCanned";
Text = "Продажа консервы";
Load += FormSellCanned_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox comboBoxCanned;
private TextBox textBoxCount;
private Label labelCanned;
private Label labelCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,90 @@
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
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 FishFactoryView
{
public partial class FormSellCanned : Form
{
private readonly ILogger _logger;
private readonly ICannedLogic _logicCanned;
private readonly IShopLogic _logicShop;
public FormSellCanned(ILogger<FormSellCanned> logger, ICannedLogic logicCanned, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicCanned = logicCanned;
_logicShop = logicShop;
}
private void FormSellCanned_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка списка консервы для продажи");
try
{
var list = _logicCanned.ReadList(null);
if (list != null)
{
comboBoxCanned.DisplayMember = "CannedName";
comboBoxCanned.ValueMember = "Id";
comboBoxCanned.DataSource = list;
comboBoxCanned.SelectedItem = null;
}
}
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(textBoxCount.Text))
{
MessageBox.Show("Заполните поле 'Количество'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxCanned.SelectedValue == null)
{
MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Продажа консерв");
try
{
var operationResult = _logicShop.SellCanned(_logicCanned.ReadElement(new CannedSearchModel()
{
Id = Convert.ToInt32(comboBoxCanned.SelectedValue)
})!, 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();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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

@ -32,15 +32,18 @@
textBoxAddress = new TextBox();
dateTimePicker = new DateTimePicker();
dataGridView = new DataGridView();
ColumnId = new DataGridViewTextBoxColumn();
ColumnCannedName = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
labelName = new Label();
labelAddress = new Label();
labelDate = new Label();
buttonSave = new Button();
buttonCancel = new Button();
ColumnId = new DataGridViewTextBoxColumn();
ColumnCannedName = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
numericUpDownCount = new NumericUpDown();
labelCount = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout();
//
// textBoxShop
@ -68,60 +71,13 @@
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnCannedName, ColumnCount });
dataGridView.Location = new Point(12, 147);
dataGridView.Location = new Point(12, 191);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(659, 309);
dataGridView.TabIndex = 3;
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(225, 15);
labelName.Name = "labelName";
labelName.Size = new Size(147, 20);
labelName.TabIndex = 4;
labelName.Text = "Название магазина";
//
// labelAddress
//
labelAddress.AutoSize = true;
labelAddress.Location = new Point(225, 60);
labelAddress.Name = "labelAddress";
labelAddress.Size = new Size(51, 20);
labelAddress.TabIndex = 5;
labelAddress.Text = "Адрес";
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(225, 105);
labelDate.Name = "labelDate";
labelDate.Size = new Size(110, 20);
labelDate.TabIndex = 6;
labelDate.Text = "Дата открытия";
//
// buttonSave
//
buttonSave.Location = new Point(411, 467);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 7;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(549, 467);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// ColumnId
//
ColumnId.HeaderText = "Id";
@ -144,11 +100,77 @@
ColumnCount.Name = "ColumnCount";
ColumnCount.Width = 125;
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(202, 15);
labelName.Name = "labelName";
labelName.Size = new Size(147, 20);
labelName.TabIndex = 4;
labelName.Text = "Название магазина";
//
// labelAddress
//
labelAddress.AutoSize = true;
labelAddress.Location = new Point(202, 60);
labelAddress.Name = "labelAddress";
labelAddress.Size = new Size(51, 20);
labelAddress.TabIndex = 5;
labelAddress.Text = "Адрес";
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(202, 105);
labelDate.Name = "labelDate";
labelDate.Size = new Size(110, 20);
labelDate.TabIndex = 6;
labelDate.Text = "Дата открытия";
//
// buttonSave
//
buttonSave.Location = new Point(415, 506);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 7;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(554, 506);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// numericUpDownCount
//
numericUpDownCount.Location = new Point(394, 148);
numericUpDownCount.Maximum = new decimal(new int[] { 500, 0, 0, 0 });
numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(277, 27);
numericUpDownCount.TabIndex = 9;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(202, 150);
labelCount.Name = "labelCount";
labelCount.Size = new Size(170, 20);
labelCount.TabIndex = 10;
labelCount.Text = "Вместимость магазина";
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(683, 508);
ClientSize = new Size(683, 547);
Controls.Add(labelCount);
Controls.Add(numericUpDownCount);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelDate);
@ -162,6 +184,7 @@
Text = "Создание магазина";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -180,5 +203,7 @@
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnCannedName;
private DataGridViewTextBoxColumn ColumnCount;
private NumericUpDown numericUpDownCount;
private Label labelCount;
}
}

View File

@ -48,6 +48,7 @@ namespace FishFactoryView
textBoxShop.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePicker.Text = view.DateOpening.ToString();
numericUpDownCount.Value = view.MaxCountCanned;
_shopListCanned = view.ListCanned ?? new Dictionary<int, (ICannedModel, int)>();
LoadData();
}
@ -103,6 +104,7 @@ namespace FishFactoryView
ShopName = textBoxShop.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePicker.Value.Date,
MaxCountCanned = (int)numericUpDownCount.Value,
ListCanned = _shopListCanned
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);

View File

@ -40,6 +40,7 @@
консервыToolStripMenuItem = new ToolStripMenuItem();
ShopsToolStripMenuItem = new ToolStripMenuItem();
ButtonAddCannedInShop = new Button();
buttonSellCanned = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
@ -124,21 +125,21 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(224, 26);
компонентыToolStripMenuItem.Size = new Size(182, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
//
// консервыToolStripMenuItem
//
консервыToolStripMenuItem.Name = онсервыToolStripMenuItem";
консервыToolStripMenuItem.Size = new Size(224, 26);
консервыToolStripMenuItem.Size = new Size(182, 26);
консервыToolStripMenuItem.Text = "Консервы";
консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click;
//
// ShopsToolStripMenuItem
//
ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem";
ShopsToolStripMenuItem.Size = new Size(224, 26);
ShopsToolStripMenuItem.Size = new Size(182, 26);
ShopsToolStripMenuItem.Text = "Магазины";
ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
//
@ -152,11 +153,22 @@
ButtonAddCannedInShop.UseVisualStyleBackColor = true;
ButtonAddCannedInShop.Click += ButtonAddCannedInShop_Click;
//
// buttonSellCanned
//
buttonSellCanned.Location = new Point(885, 434);
buttonSellCanned.Name = "buttonSellCanned";
buttonSellCanned.Size = new Size(179, 29);
buttonSellCanned.TabIndex = 9;
buttonSellCanned.Text = "Продать консервы";
buttonSellCanned.UseVisualStyleBackColor = true;
buttonSellCanned.Click += buttonSellCanned_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1076, 487);
Controls.Add(buttonSellCanned);
Controls.Add(ButtonAddCannedInShop);
Controls.Add(button5);
Controls.Add(button4);
@ -189,5 +201,6 @@
private ToolStripMenuItem консервыToolStripMenuItem;
private ToolStripMenuItem ShopsToolStripMenuItem;
private Button ButtonAddCannedInShop;
private Button buttonSellCanned;
}
}

View File

@ -174,5 +174,14 @@ MessageBoxIcon.Error);
form.ShowDialog();
}
}
private void buttonSellCanned_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellCanned));
if (service is FormSellCanned form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -52,6 +52,7 @@ namespace FishFactoryView
services.AddTransient<FormShops>();
services.AddTransient<FormShop>();
services.AddTransient<FormShopCanned>();
services.AddTransient<FormSellCanned>();
}
}
}