связь магазина с консервами не работает, Карл!
This commit is contained in:
parent
f1e72c79c4
commit
5ed952ff3a
15
FishFactory/FormMain.Designer.cs
generated
15
FishFactory/FormMain.Designer.cs
generated
@ -35,6 +35,7 @@
|
||||
консервыToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
toolStripLabelReplenish2 = new ToolStripLabel();
|
||||
toolStripLabelSale = new ToolStripLabel();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
@ -48,7 +49,7 @@
|
||||
// toolStrip1
|
||||
//
|
||||
toolStrip1.ImageScalingSize = new Size(20, 20);
|
||||
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripLabelReplenish2 });
|
||||
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripLabelReplenish2, toolStripLabelSale });
|
||||
toolStrip1.Location = new Point(0, 0);
|
||||
toolStrip1.Name = "toolStrip1";
|
||||
toolStrip1.Size = new Size(1206, 27);
|
||||
@ -90,10 +91,17 @@
|
||||
//
|
||||
toolStripLabelReplenish2.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||
toolStripLabelReplenish2.Name = "toolStripLabelReplenish2";
|
||||
toolStripLabelReplenish2.Size = new Size(168, 24);
|
||||
toolStripLabelReplenish2.Text = "Пополнение магазина";
|
||||
toolStripLabelReplenish2.Size = new Size(98, 24);
|
||||
toolStripLabelReplenish2.Text = "Пополнение";
|
||||
toolStripLabelReplenish2.Click += toolStripLabelReplenish_Click;
|
||||
//
|
||||
// toolStripLabelSale
|
||||
//
|
||||
toolStripLabelSale.Name = "toolStripLabelSale";
|
||||
toolStripLabelSale.Size = new Size(145, 24);
|
||||
toolStripLabelSale.Text = "Продажа консервы";
|
||||
toolStripLabelSale.Click += toolStripLabelSale_Click;
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
@ -204,5 +212,6 @@
|
||||
private ToolStripMenuItem консервыToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripLabel toolStripLabelReplenish2;
|
||||
private ToolStripLabel toolStripLabelSale;
|
||||
}
|
||||
}
|
@ -76,6 +76,15 @@ namespace FishFactory.Forms
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void toolStripLabelSale_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSale));
|
||||
if (service is FormShopSale form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
119
FishFactory/FormShopSale.Designer.cs
generated
Normal file
119
FishFactory/FormShopSale.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace FishFactory.Forms
|
||||
{
|
||||
partial class FormShopSale
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonSell = new Button();
|
||||
buttonCancel = new Button();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
comboBoxCanned = new ComboBox();
|
||||
textBoxCount = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
buttonSell.Location = new Point(237, 109);
|
||||
buttonSell.Name = "buttonSell";
|
||||
buttonSell.Size = new Size(118, 33);
|
||||
buttonSell.TabIndex = 0;
|
||||
buttonSell.Text = "Продать";
|
||||
buttonSell.UseVisualStyleBackColor = true;
|
||||
buttonSell.Click += buttonSell_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(378, 109);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(118, 33);
|
||||
buttonCancel.TabIndex = 1;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(20, 23);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(79, 20);
|
||||
label1.TabIndex = 2;
|
||||
label1.Text = "Консерва:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(20, 66);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(93, 20);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = "Количество:";
|
||||
//
|
||||
// comboBoxCanned
|
||||
//
|
||||
comboBoxCanned.FormattingEnabled = true;
|
||||
comboBoxCanned.Location = new Point(128, 20);
|
||||
comboBoxCanned.Name = "comboBoxCanned";
|
||||
comboBoxCanned.Size = new Size(325, 28);
|
||||
comboBoxCanned.TabIndex = 4;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(128, 63);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(325, 27);
|
||||
textBoxCount.TabIndex = 5;
|
||||
//
|
||||
// FormShopSale
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(516, 151);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(comboBoxCanned);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSell);
|
||||
Name = "FormShopSale";
|
||||
Text = "Продажа консерв";
|
||||
Load += FormShopSale_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSell;
|
||||
private Button buttonCancel;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private ComboBox comboBoxCanned;
|
||||
private TextBox textBoxCount;
|
||||
}
|
||||
}
|
78
FishFactory/FormShopSale.cs
Normal file
78
FishFactory/FormShopSale.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
|
||||
namespace FishFactory.Forms
|
||||
{
|
||||
public partial class FormShopSale : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICannedLogic _logicC;
|
||||
private readonly IShopLogic _logicS;
|
||||
private List<CannedViewModel> _cannedList = new List<CannedViewModel>();
|
||||
|
||||
public FormShopSale(ILogger<FormShopSale> logger, ICannedLogic logicC, IShopLogic logicS)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicC = logicC;
|
||||
_logicS = logicS;
|
||||
}
|
||||
|
||||
private void FormShopSale_Load(object sender, EventArgs e)
|
||||
{
|
||||
_cannedList = _logicC.ReadList(null);
|
||||
if (_cannedList != null)
|
||||
{
|
||||
comboBoxCanned.DisplayMember = "CannedName";
|
||||
comboBoxCanned.ValueMember = "Id";
|
||||
comboBoxCanned.DataSource = _cannedList;
|
||||
comboBoxCanned.SelectedItem = null;
|
||||
_logger.LogInformation("Загрузка консерв для продажи");
|
||||
}
|
||||
}
|
||||
private void buttonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxCanned.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание покупки");
|
||||
try
|
||||
{
|
||||
bool sale = _logicS.Sale(new ReplenishSearchModel
|
||||
{
|
||||
CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue),
|
||||
Count = Convert.ToInt32(textBoxCount.Text)
|
||||
});
|
||||
if (sale)
|
||||
{
|
||||
_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();
|
||||
}
|
||||
}
|
||||
}
|
120
FishFactory/FormShopSale.resx
Normal file
120
FishFactory/FormShopSale.resx
Normal 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>
|
@ -53,6 +53,7 @@ namespace FishFactory
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShopReplenish>();
|
||||
services.AddTransient<FormShopSale>();
|
||||
}
|
||||
}
|
||||
}
|
@ -115,13 +115,29 @@ namespace FishFactoryBusinessLogic.BusinessLogic
|
||||
});
|
||||
if (canned == null)
|
||||
{
|
||||
throw new ArgumentException($"Поставка: Товар с id:{model.CannedId} не найденн");
|
||||
throw new ArgumentException($"Поставка: Товар с id:{model.CannedId} не найден");
|
||||
}
|
||||
shop.ShopCanneds.Add(model.CannedId, (canned, model.Count));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Sale(ReplenishSearchModel model)
|
||||
{
|
||||
if (!model.CannedId.HasValue || !model.Count.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_logger.LogInformation("Check canned count in all shops");
|
||||
if (_shopStorage.Sale(model))
|
||||
{
|
||||
_logger.LogInformation("Selling success");
|
||||
return true;
|
||||
}
|
||||
_logger.LogInformation("Selling failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -11,6 +11,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool Sale(ReplenishSearchModel model);
|
||||
bool Replenish(ReplenishBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,10 @@ namespace FishFactoryContracts.ViewModels
|
||||
[DisplayName("Название")]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
[DisplayName("Адрес")]
|
||||
public int CapacityCanned { get; set; }
|
||||
[DisplayName("Вместимость")]
|
||||
public string Adress { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Вместимость")]
|
||||
public int CapacityCanned { get; set; }
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
public Dictionary<int, (ICannedModel, int)> ShopCanneds { get; set; } = new();
|
||||
|
@ -93,7 +93,7 @@ namespace FishFactoryFileImplement.Implements
|
||||
{
|
||||
shop.Canneds.Remove(model.CannedId.Value);
|
||||
}
|
||||
else if (remains < 0)
|
||||
else
|
||||
{
|
||||
shop.Canneds[model.CannedId.Value] = -remains;
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ namespace FishFactoryFileImplement.Models
|
||||
Adress = model.Adress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
CapacityCanned = model.CapacityCanned;
|
||||
_shopCanneds = null;
|
||||
}
|
||||
|
||||
public void CannedsUpdate()
|
||||
@ -93,7 +94,9 @@ namespace FishFactoryFileImplement.Models
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Adress", Adress),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("CapacityCanned", CapacityCanned.ToString())
|
||||
new XElement("CapacityCanned", CapacityCanned.ToString()),
|
||||
new XElement("ShopCanneds", Canneds.Select(
|
||||
x => new XElement("ShopCanned", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user