lab2_hard сделано и сдано

This commit is contained in:
sofiaivv 2024-06-21 22:58:05 +04:00
parent 0a7ce63e60
commit 9d32a26b53
31 changed files with 1206 additions and 520 deletions

View File

@ -10,6 +10,7 @@ using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using System.Xml.Linq;
namespace PrecastConcretePlantBusinessLogic.BusinessLogics
{
@ -17,10 +18,12 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IShopStorage _shopStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
@ -57,6 +60,22 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
}
public bool DeliveryOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id,
});
if (order == null)
{
throw new ArgumentNullException(nameof(order));
}
if (!_shopStorage.RestockingShops(new SupplyBindingModel
{
ReinforcedId = order.ReinforcedId,
count = order.Count
}))
{
throw new ArgumentException("Недостаточно места в магазинах для поставки");
}
return ChangeStatus(model, OrderStatus.Выдан);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)

View File

@ -118,8 +118,32 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
}
shop.ShopReinforcedes.Add(model.ReinforcedId, (reinforsed, model.count));
}
_shopStorage.Update(new()
{
Id = shop.Id,
ShopName = shop.ShopName,
Adress = shop.Adress,
OpeningDate = shop.OpeningDate,
ShopReinforcedes = shop.ShopReinforcedes,
ReinforcedMaxCount = shop.ReinforcedMaxCount
});
return true;
}
public bool Sale(SupplySearchModel model)
{
if (!model.ReinforcedId.HasValue || !model.Count.HasValue)
{
return false;
}
_logger.LogInformation("Check reinforced count in all shops");
if (_shopStorage.Sale(model))
{
_logger.LogInformation("amount is enough. Selling sucsess");
return true;
}
_logger.LogInformation("amount is insufficient");
return false;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -14,5 +14,6 @@ namespace PrecastConcretePlantContracts.BindingModels
public string Adress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;//Предполагается, что открытие магазина совпадает с добавлением его в Систему.
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedes { get; set; } = new();
public int ReinforcedMaxCount { get; set; }
}
}

View File

@ -17,5 +17,6 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool MakeSupply(SupplyBindingModel model);
bool Sale(SupplySearchModel model);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.SearchModels
{
public class SupplySearchModel
{
public int? ReinforcedId { get; set; }
public int? Count { get; set; }
}
}

View File

@ -17,5 +17,7 @@ namespace PrecastConcretePlantContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool Sale(SupplySearchModel model);
bool RestockingShops(SupplyBindingModel model);
}
}

View File

@ -18,5 +18,7 @@ namespace PrecastConcretePlantContracts.ViewModels
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; }
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedes { get; set; } = new();
[DisplayName("Вместимость")]
public int ReinforcedMaxCount { get; set; }
}
}

View File

@ -1,15 +0,0 @@
using PrecastConcretePlantDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDataModels.Models
{
public interface IComponentModel : IId
{
string ComponentName { get; }
double Cost { get; }
}
}

View File

@ -1,19 +0,0 @@
using PrecastConcretePlantDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDataModels.Models
{
public interface IOrderModel : IId
{
int ReinforcedId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
}

View File

@ -1,16 +0,0 @@
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDataModels.Models
{
public interface IReinforcedModel : IId
{
string ReinforcedName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> ReinforcedComponents { get; }
}
}

View File

@ -14,5 +14,6 @@ namespace PrecastConcretePlantDataModels.Models
string Adress { get; }
DateTime OpeningDate { get; }
Dictionary<int, (IReinforcedModel, int)> ShopReinforcedes { get; }
int ReinforcedMaxCount { get; }
}
}

View File

@ -14,9 +14,11 @@ namespace PrecastConcretePlantFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ReinforcedFileName = "Reinforced.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Reinforced> Reinforceds { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -28,11 +30,13 @@ namespace PrecastConcretePlantFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", 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)!)!;
Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{

View File

@ -0,0 +1,141 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantFileImplement.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 shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop != null)
{
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
return null;
}
public bool Sale(SupplySearchModel model)
{
if (model == null || !model.ReinforcedId.HasValue || !model.Count.HasValue)
return false;
int remainingSpace = source.Shops.Select(x => x.Reinforcedes.ContainsKey(model.ReinforcedId.Value) ? x.Reinforcedes[model.ReinforcedId.Value] : 0).Sum();
if (remainingSpace < model.Count)
{
return false;
}
var shops = source.Shops.Where(x => x.Reinforcedes.ContainsKey(model.ReinforcedId.Value)).OrderByDescending(x => x.Reinforcedes[model.ReinforcedId.Value]).ToList();
foreach (var shop in shops)
{
int residue = model.Count.Value - shop.Reinforcedes[model.ReinforcedId.Value];
if (residue > 0)
{
shop.Reinforcedes.Remove(model.ReinforcedId.Value);
shop.UpdateContent();
model.Count = residue;
}
else
{
if (residue == 0)
shop.Reinforcedes.Remove(model.ReinforcedId.Value);
else
shop.Reinforcedes[model.ReinforcedId.Value] = -residue;
shop.UpdateContent();
source.SaveShops();
return true;
}
}
source.SaveShops();
return false;
}
public bool RestockingShops(SupplyBindingModel model)
{
if (model == null || source.Shops.Select(x => x.ReinforcedMaxCount - x.ShopReinforcedes.Select(y => y.Value.Item2).Sum()).Sum() < model.count)
{
return false;
}
foreach (Shop shop in source.Shops)
{
int difference = shop.ReinforcedMaxCount - shop.ShopReinforcedes.Select(x => x.Value.Item2).Sum();
if (difference <= 0)
continue;
int refill = Math.Min(difference, model.count);
model.count -= refill;
if (shop.Reinforcedes.ContainsKey(model.ReinforcedId))
{
shop.Reinforcedes[model.ReinforcedId] += refill;
}
else
{
shop.Reinforcedes.Add(model.ReinforcedId, refill);
}
shop.UpdateContent();
if (model.count == 0)
{
source.SaveShops();
return true;
}
}
throw new ArgumentException("Непредвиденная ошибка при пополнении магазинов");
}
}
}

View File

@ -0,0 +1,104 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace PrecastConcretePlantFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary<int, int> Reinforcedes { get; private set; } = new();
private Dictionary<int, (IReinforcedModel, int)>? _shopReinforcedes = null;
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedes
{
get
{
if (_shopReinforcedes == null)
{
var source = DataFileSingleton.GetInstance();
_shopReinforcedes = Reinforcedes.ToDictionary(x => x.Key, y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value));
}
return _shopReinforcedes;
}
}
public int ReinforcedMaxCount { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
Reinforcedes = model.ShopReinforcedes.ToDictionary(x => x.Key, x => x.Value.Item2),
ReinforcedMaxCount = model.ReinforcedMaxCount
};
}
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,
Adress = element.Element("Adress")!.Value,
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
Reinforcedes = element.Element("ShopReinforcedes")!.Elements("ShopReinforced")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value)),
ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value)
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
ReinforcedMaxCount = model.ReinforcedMaxCount;
Reinforcedes = model.ShopReinforcedes.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopReinforcedes = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
ShopReinforcedes = ShopReinforcedes,
ReinforcedMaxCount = ReinforcedMaxCount
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Adress", Adress),
new XElement("OpeningDate", OpeningDate.ToString()),
new XElement("ShopReinforcedes", Reinforcedes.Select(
x => new XElement("ShopReinforced", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
new XElement("ReinforcedMaxCount", ReinforcedMaxCount.ToString())
);
public void UpdateContent()
{
//метод придуман для удобного обновления на низком уровне(из хранилища). Фактически меняем мы там Reinforcedes.
_shopReinforcedes = null;
}
}
}

View File

@ -102,5 +102,17 @@ namespace PrecastConcretePlantListImplement.Implements
}
return null;
}
public bool Sale(SupplySearchModel model)
{
throw new NotImplementedException();
}
public bool PresenceCheck(SupplySearchModel model)
{
throw new NotImplementedException();
}
public bool RestockingShops(SupplyBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -74,7 +74,7 @@ namespace PrecastConcretePlantView
});
if (!operationResult)
{
throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах.");
throw new Exception("Магазин заполнен.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;

View File

@ -41,6 +41,7 @@
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
создатьПродажуToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -83,7 +84,7 @@
//
// операцииToolStripMenuItem
//
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьПоставкуToolStripMenuItem });
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьПоставкуToolStripMenuItem, создатьПродажуToolStripMenuItem });
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
операцииToolStripMenuItem.Size = new Size(75, 20);
операцииToolStripMenuItem.Text = "Операции";
@ -155,6 +156,12 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += buttonRef_Click;
//
// создатьПродажуToolStripMenuItem
//
создатьПродажуToolStripMenuItem.Name = "создатьПродажуToolStripMenuItem";
создатьПродажуToolStripMenuItem.Size = new Size(180, 22);
создатьПродажуToolStripMenuItem.Text = "Создать продажу";
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -193,5 +200,6 @@
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem операцииToolStripMenuItem;
private ToolStripMenuItem создатьПоставкуToolStripMenuItem;
private ToolStripMenuItem создатьПродажуToolStripMenuItem;
}
}

View File

@ -1,4 +1,64 @@
<root>
<?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">

View File

@ -0,0 +1,120 @@
namespace PrecastConcretePlantView
{
partial class FormSellingReinforsed
{
/// <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.labelReinforced = new System.Windows.Forms.Label();
this.comboBoxReinforced = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonSell = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelReinforced
//
this.labelReinforced.AutoSize = true;
this.labelReinforced.Location = new System.Drawing.Point(12, 14);
this.labelReinforced.Name = "labelReinforced";
this.labelReinforced.Size = new System.Drawing.Size(75, 20);
this.labelReinforced.TabIndex = 0;
this.labelReinforced.Text = "Изделие: ";
//
// comboBoxReinforced
//
this.comboBoxReinforced.FormattingEnabled = true;
this.comboBoxReinforced.Location = new System.Drawing.Point(115, 11);
this.comboBoxReinforced.Name = "comboBoxReinforced";
this.comboBoxReinforced.Size = new System.Drawing.Size(239, 28);
this.comboBoxReinforced.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 55);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 20);
this.label1.TabIndex = 2;
this.label1.Text = "Количество: ";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(115, 52);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(239, 27);
this.textBoxCount.TabIndex = 3;
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(128, 99);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(94, 29);
this.buttonSell.TabIndex = 4;
this.buttonSell.Text = "Продать";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(242, 99);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormSellingReinforsed
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(366, 140);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBoxReinforced);
this.Controls.Add(this.labelReinforced);
this.Name = "FormSellingReinforsed";
this.Text = "Продажа изделий";
this.Load += new System.EventHandler(this.FormSellingReinforsed_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelReinforced;
private ComboBox comboBoxReinforced;
private Label label1;
private TextBox textBoxCount;
private Button buttonSell;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,83 @@
using Microsoft.Extensions.Logging;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
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 PrecastConcretePlantView
{
public partial class FormSellingReinforsed : Form
{
private readonly ILogger _logger;
private readonly IReinforcedLogic _logicR;
private readonly IShopLogic _logicS;
private List<ReinforcedViewModel> _reinforcedList = new List<ReinforcedViewModel>();
public FormSellingReinforsed(ILogger<FormSellingReinforsed> logger, IReinforcedLogic logicR, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicR = logicR;
_logicS = logicS;
}
private void FormSellingReinforsed_Load(object sender, EventArgs e)
{
_reinforcedList = _logicR.ReadList(null);
if (_reinforcedList != null)
{
comboBoxReinforced.DisplayMember = "ReinforcedName";
comboBoxReinforced.ValueMember = "Id";
comboBoxReinforced.DataSource = _reinforcedList;
comboBoxReinforced.SelectedItem = null;
_logger.LogInformation("Загрузка изделий для продажи");
}
}
private void buttonSell_Click(object sender, EventArgs e)
{
if (comboBoxReinforced.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool resout = _logicS.Sale(new SupplySearchModel
{
ReinforcedId = Convert.ToInt32(comboBoxReinforced.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (resout)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else {
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка создания покупки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

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,7 +40,10 @@
labelAdress = new Label();
textBoxName = new TextBox();
labelName = new Label();
labelMaxCount = new Label();
numericUpDownMaxCount = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownMaxCount).BeginInit();
SuspendLayout();
//
// dateTimePickerOpeningDate
@ -48,7 +51,7 @@
dateTimePickerOpeningDate.Location = new Point(118, 79);
dateTimePickerOpeningDate.Margin = new Padding(3, 2, 3, 2);
dateTimePickerOpeningDate.Name = "dateTimePickerOpeningDate";
dateTimePickerOpeningDate.Size = new Size(216, 23);
dateTimePickerOpeningDate.Size = new Size(165, 23);
dateTimePickerOpeningDate.TabIndex = 17;
//
// labelOpeningDate
@ -155,11 +158,30 @@
labelName.TabIndex = 9;
labelName.Text = "Название: ";
//
// labelMaxCount
//
labelMaxCount.AutoSize = true;
labelMaxCount.Location = new Point(289, 80);
labelMaxCount.Name = "labelMaxCount";
labelMaxCount.Size = new Size(86, 15);
labelMaxCount.TabIndex = 19;
labelMaxCount.Text = "Вместимость: ";
//
// numericUpDownMaxCount
//
numericUpDownMaxCount.Location = new Point(388, 79);
numericUpDownMaxCount.Margin = new Padding(3, 2, 3, 2);
numericUpDownMaxCount.Name = "numericUpDownMaxCount";
numericUpDownMaxCount.Size = new Size(164, 23);
numericUpDownMaxCount.TabIndex = 18;
//
// FormShop
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(563, 352);
Controls.Add(labelMaxCount);
Controls.Add(numericUpDownMaxCount);
Controls.Add(dateTimePickerOpeningDate);
Controls.Add(labelOpeningDate);
Controls.Add(buttonSave);
@ -173,6 +195,7 @@
Text = "Магазин";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownMaxCount).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -191,5 +214,7 @@
private Label labelAdress;
private TextBox textBoxName;
private Label labelName;
private Label labelMaxCount;
private NumericUpDown numericUpDownMaxCount;
}
}

View File

@ -46,6 +46,7 @@ namespace PrecastConcretePlantView
textBoxAdress.Text = view.Adress;
dateTimePickerOpeningDate.Value = view.OpeningDate;
_ShopReinforcedes = view.ShopReinforcedes ?? new Dictionary<int, (IReinforcedModel, int)>();
numericUpDownMaxCount.Value = view.ReinforcedMaxCount;
LoadData();
}
}
@ -96,7 +97,9 @@ namespace PrecastConcretePlantView
Id = _id ?? 0,
ShopName = textBoxName.Text,
Adress = textBoxAdress.Text,
OpeningDate = dateTimePickerOpeningDate.Value
OpeningDate = dateTimePickerOpeningDate.Value,
ReinforcedMaxCount = (int)numericUpDownMaxCount.Value,
ShopReinforcedes = _ShopReinforcedes
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)

View File

@ -1,4 +1,64 @@
<root>
<?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">
@ -66,13 +126,4 @@
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ReinforcedName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -57,6 +57,7 @@ namespace PrecastConcretePlant
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormCreateSupply>();
services.AddTransient<FormSellingReinforsed>();
}
}
}