PIbd-22. Kozlova A.A. Lab work 02 hard #8

Closed
Nastya_Kozlova wants to merge 4 commits from lab2_hard into lab2_base
20 changed files with 780 additions and 41 deletions
Showing only changes of commit e287003008 - Show all commits

View File

@ -19,10 +19,16 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IReinforcedStorage _reinforcedStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic)
{
_logger = logger;
_orderStorage = orderStorage;
_reinforcedStorage = reinforcedStorage;
_shopLogic = shopLogic;
}
public bool CreateOrder(OrderBindingModel model)
@ -111,10 +117,20 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
newStatus, order.Status);
return false;
}
model.ReinforcedId = order.ReinforcedId;
model.Count = order.Count;
model.Sum = order.Sum;
model.DateCreate = order.DateCreate;
if (newStatus == OrderStatus.Выдан)
{
var reinforced = _reinforcedStorage.GetElement(new ReinforcedSearchModel() { Id = order.ReinforcedId });
if (reinforced == null)
{
_logger.LogWarning("Change status operation failed. Reinforced not found");
return false;
}
if (!_shopLogic.DeliverReinforceds(reinforced, order.Count))
{
_logger.LogWarning("Change status operation failed. Reinforceds delivery operation failed");
return false;
}
}
model.Status = newStatus;
if (model.Status == OrderStatus.Готов)
{

View File

@ -110,6 +110,11 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
_logger.LogWarning("ReplenishShop(GetElement). Element not found");
return false;
}
if (shop.ReinforcedsMax - shop.ShopReinforceds.Sum(x => x.Value.Item2) < count)
{
_logger.LogWarning("ReplenishShop error. No space for new reinforceds");
return false;
}
if (shop.ShopReinforceds.ContainsKey(reinforced.Id))
{
var shopR = shop.ShopReinforceds[reinforced.Id];
@ -130,6 +135,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
ShopName = shop.ShopName,
Address = shop.Address,
DateOpening = shop.DateOpening,
ReinforcedsMax = shop.ReinforcedsMax,
ShopReinforceds = shop.ShopReinforceds,
}) == null)
{
@ -139,6 +145,68 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics
return true;
}
public bool MakeSale(IReinforcedModel model, int count)
{
return _shopStorage.MakeSale(model, count);
}
public bool DeliverReinforceds(IReinforcedModel reinforced, int count)
{
if (count <= 0)
{
_logger.LogWarning("Reinforceds delivery operation failed. Reinforced count <= 0");
return false;
}
var shopList = _shopStorage.GetFullList();
int shopsCapacity = shopList.Sum(x => x.ReinforcedsMax);
int currentReinforceds = shopList.Select(x => x.ShopReinforceds.Sum(y => y.Value.Item2)).Sum();
int freePlaces = shopsCapacity - currentReinforceds;
if (freePlaces < count)
{
_logger.LogWarning("Reinforceds delivery operation failed. No space for new кeinforceds");
return false;
}
foreach (var shop in shopList)
{
freePlaces = shop.ReinforcedsMax - shop.ShopReinforceds.Sum(x => x.Value.Item2);
if (freePlaces == 0)
{
continue;
}
if (freePlaces >= count)
{
if (ReplenishShop(new() { Id = shop.Id }, reinforced, count))
{
count = 0;
}
else
{
_logger.LogWarning("Reinforceds delivery operation failed");
return false;
}
}
else
{
if (ReplenishShop(new() { Id = shop.Id }, reinforced, freePlaces))
{
count -= freePlaces;
}
else
{
_logger.LogWarning("Reinforceds delivery operation failed");
return false;
}
}
if (count == 0)
{
return true;
}
}
return false;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -22,5 +22,6 @@ namespace PrecastConcretePlantContracts.BindingModels
get;
set;
} = new();
public int ReinforcedsMax { get; set; }
}
}

View File

@ -23,5 +23,9 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel model);
bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count);
bool MakeSale(IReinforcedModel model, int count);
bool DeliverReinforceds(IReinforcedModel model, int count);
}
}

View File

@ -1,6 +1,7 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,5 +23,7 @@ namespace PrecastConcretePlantContracts.StoragesContracts
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool MakeSale(IReinforcedModel model, int count);
}
}

View File

@ -26,5 +26,8 @@ namespace PrecastConcretePlantContracts.ViewModels
get;
set;
} = new();
[DisplayName("Максимальное количество изделий")]
public int ReinforcedsMax { get; set; }
}
}

View File

@ -15,5 +15,6 @@ namespace PrecastConcretePlantDataModels.Models
DateTime DateOpening { get; }
Dictionary<int, (IReinforcedModel, int)> ShopReinforceds { get; }
int ReinforcedsMax { get; }
}
}

View File

@ -9,9 +9,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)
@ -23,11 +25,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,137 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
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 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 MakeSale(IReinforcedModel model, int count)
{
var reinforced = source.Reinforceds.FirstOrDefault(x => x.Id == model.Id);
int countInShops = source.Shops.SelectMany(x => x.ShopReinforceds).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0);
if (reinforced == null || countInShops < count)
{
return false;
}
foreach (var shop in source.Shops)
{
var shopReinforceds = shop.ShopReinforceds.Where(x => x.Key == model.Id);
if (shopReinforceds.Any())
{
var shopReinforced = shopReinforceds.First();
int min = Math.Min(shopReinforced.Value.Item2, count);
if (min == shopReinforced.Value.Item2)
{
shop.ShopReinforceds.Remove(shopReinforced.Key);
}
else
{
shop.ShopReinforceds[shopReinforced.Key] = (shopReinforced.Value.Item1, shopReinforced.Value.Item2 - min);
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
DateOpening = shop.DateOpening,
ShopReinforceds = shop.ShopReinforceds,
ReinforcedsMax = shop.ReinforcedsMax
});
count -= min;
if (count <= 0)
{
break;
}
}
}
source.SaveShops();
return true;
}
}
}

View File

@ -0,0 +1,113 @@
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 Address { get; private set; } = string.Empty;
public DateTime DateOpening { get; private set; }
public Dictionary<int, int> Reinforceds { get; private set; } = new();
private Dictionary<int, (IReinforcedModel, int)>? _shopReinforceds = null;
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
{
get
{
if (_shopReinforceds == null)
{
var source = DataFileSingleton.GetInstance();
_shopReinforceds = Reinforceds.ToDictionary(x => x.Key,
y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value));
}
return _shopReinforceds;
}
}
public int ReinforcedsMax { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening,
Reinforceds = model.ShopReinforceds.ToDictionary(x => x.Key, x => x.Value.Item2),
ReinforcedsMax = model.ReinforcedsMax
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
ReinforcedsMax = Convert.ToInt32(element.Element("ReinforcedsMax")!.Value),
Reinforceds = element.Element("ShopReinforceds")!.Elements("ShopReinforced")
.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;
ReinforcedsMax = model.ReinforcedsMax;
Reinforceds = model.ShopReinforceds.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopReinforceds = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
ShopReinforceds = ShopReinforceds,
ReinforcedsMax = ReinforcedsMax
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpening", DateOpening.ToString()),
new XElement("ReinforcedsMax", ReinforcedsMax.ToString()),
new XElement("ShopReinforceds",
Reinforceds.Select(x => new XElement("ShopReinforced",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -2,6 +2,7 @@
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using PrecastConcretePlantListImplement.Models;
using System;
using System.Collections.Generic;
@ -110,5 +111,9 @@ namespace PrecastConcretePlantListImplement.Implements
}
return null;
}
public bool MakeSale(IReinforcedModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -19,6 +19,8 @@ namespace PrecastConcretePlantListImplement.Models
public DateTime DateOpening { get; private set; }
public int ReinforcedsMax { get; set; }
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
{
get;

View File

@ -34,6 +34,7 @@
изделияToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
продажаИзделийToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
@ -47,7 +48,7 @@
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаИзделийToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1257, 28);
@ -64,21 +65,21 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(224, 26);
компонентыToolStripMenuItem.Size = new Size(182, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// изделияToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
изделияToolStripMenuItem.Size = new Size(224, 26);
изделияToolStripMenuItem.Size = new Size(182, 26);
изделияToolStripMenuItem.Text = "Изделия";
изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Size = new Size(182, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
//
@ -89,6 +90,13 @@
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click;
//
// продажаИзделийToolStripMenuItem
//
продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem";
продажаИзделийToolStripMenuItem.Size = new Size(149, 24);
продажаИзделийToolStripMenuItem.Text = "Продажа изделий";
продажаИзделийToolStripMenuItem.Click += продажаИзделийToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
@ -195,5 +203,6 @@
private Button buttonUpd;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private ToolStripMenuItem продажаИзделийToolStripMenuItem;
}
}

View File

@ -79,6 +79,14 @@ namespace PrecastConcretePlantView
form.ShowDialog();
}
}
private void продажаИзделийToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedSale));
if (service is FormReinforcedSale form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service =
@ -151,7 +159,7 @@ namespace PrecastConcretePlantView
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
throw new Exception("Ошибка");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();

View File

@ -0,0 +1,128 @@
namespace PrecastConcretePlantView
{
partial class FormReinforcedSale
{
/// <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()
{
buttonCancel = new Button();
buttonSale = new Button();
textBoxCount = new TextBox();
labelCount = new Label();
comboBoxReinforced = new ComboBox();
labelReinforced = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(289, 111);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 36);
buttonCancel.TabIndex = 17;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSale
//
buttonSale.Location = new Point(182, 111);
buttonSale.Margin = new Padding(5, 4, 5, 4);
buttonSale.Name = "buttonSale";
buttonSale.Size = new Size(101, 36);
buttonSale.TabIndex = 16;
buttonSale.Text = "Продать";
buttonSale.UseVisualStyleBackColor = true;
buttonSale.Click += ButtonSale_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(115, 68);
textBoxCount.Margin = new Padding(5, 4, 5, 4);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(287, 27);
textBoxCount.TabIndex = 15;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(15, 72);
labelCount.Margin = new Padding(5, 0, 5, 0);
labelCount.Name = "labelCount";
labelCount.Size = new Size(93, 20);
labelCount.TabIndex = 14;
labelCount.Text = "Количество:";
//
// comboBoxReinforced
//
comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxReinforced.FormattingEnabled = true;
comboBoxReinforced.Location = new Point(115, 20);
comboBoxReinforced.Margin = new Padding(5, 4, 5, 4);
comboBoxReinforced.Name = "comboBoxReinforced";
comboBoxReinforced.Size = new Size(287, 28);
comboBoxReinforced.TabIndex = 13;
//
// labelReinforced
//
labelReinforced.AutoSize = true;
labelReinforced.Location = new Point(15, 25);
labelReinforced.Margin = new Padding(5, 0, 5, 0);
labelReinforced.Name = "labelReinforced";
labelReinforced.Size = new Size(71, 20);
labelReinforced.TabIndex = 12;
labelReinforced.Text = "Изделие:";
//
// FormReinforcedSale
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(426, 164);
Controls.Add(buttonCancel);
Controls.Add(buttonSale);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxReinforced);
Controls.Add(labelReinforced);
Margin = new Padding(3, 4, 3, 4);
Name = "FormReinforcedSale";
StartPosition = FormStartPosition.CenterScreen;
Text = "Продажа изделий";
Load += FormReinforcedSale_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSale;
private TextBox textBoxCount;
private Label labelCount;
private ComboBox comboBoxReinforced;
private Label labelReinforced;
}
}

View File

@ -0,0 +1,87 @@
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.BindingModels;
using Microsoft.Extensions.Logging;
namespace PrecastConcretePlantView
{
public partial class FormReinforcedSale : Form
{
private readonly ILogger _logger;
private readonly IReinforcedLogic _logicReinforced;
private readonly IShopLogic _logicShop;
public FormReinforcedSale(ILogger<FormShopReplenishment> logger, IReinforcedLogic logicReinforced, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicReinforced = logicReinforced;
_logicShop = logicShop;
}
private void FormReinforcedSale_Load(object sender, EventArgs e)
{
_logger.LogInformation("Reinforceds loading");
try
{
var list = _logicReinforced.ReadList(null);
if (list != null)
{
comboBoxReinforced.DisplayMember = "ReinforcedName";
comboBoxReinforced.ValueMember = "Id";
comboBoxReinforced.DataSource = list;
comboBoxReinforced.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Reinforceds loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSale_Click(object sender, EventArgs e)
{
if (comboBoxReinforced.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Reinforced sale");
try
{
var operationResult = _logicShop.MakeSale(
new ReinforcedBindingModel
{
Id = Convert.ToInt32(comboBoxReinforced.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, "Reinforced sale error");
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

@ -36,11 +36,13 @@
labelOpeningDate = new Label();
groupBoxReinforceds = new GroupBox();
dataGridView = new DataGridView();
buttonSave = new Button();
buttonCancel = new Button();
ColumnId = new DataGridViewTextBoxColumn();
ColumnName = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
textBoxMax = new Label();
textBoxMaximum = new TextBox();
groupBoxReinforceds.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -60,7 +62,7 @@
textBoxName.Location = new Point(105, 9);
textBoxName.Margin = new Padding(5, 4, 5, 4);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(287, 27);
textBoxName.Size = new Size(302, 27);
textBoxName.TabIndex = 2;
//
// labelAddress
@ -78,7 +80,7 @@
textBoxAddress.Location = new Point(105, 49);
textBoxAddress.Margin = new Padding(5, 4, 5, 4);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(287, 27);
textBoxAddress.Size = new Size(302, 27);
textBoxAddress.TabIndex = 4;
//
// dateTimePicker
@ -86,7 +88,7 @@
dateTimePicker.Location = new Point(144, 88);
dateTimePicker.Margin = new Padding(3, 4, 3, 4);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(249, 27);
dateTimePicker.Size = new Size(263, 27);
dateTimePicker.TabIndex = 5;
//
// labelOpeningDate
@ -102,11 +104,11 @@
// groupBoxReinforceds
//
groupBoxReinforceds.Controls.Add(dataGridView);
groupBoxReinforceds.Location = new Point(5, 133);
groupBoxReinforceds.Location = new Point(5, 183);
groupBoxReinforceds.Margin = new Padding(5, 4, 5, 4);
groupBoxReinforceds.Name = "groupBoxReinforceds";
groupBoxReinforceds.Padding = new Padding(5, 4, 5, 4);
groupBoxReinforceds.Size = new Size(536, 384);
groupBoxReinforceds.Size = new Size(536, 395);
groupBoxReinforceds.TabIndex = 7;
groupBoxReinforceds.TabStop = false;
groupBoxReinforceds.Text = "Изделие";
@ -127,31 +129,9 @@
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(522, 356);
dataGridView.Size = new Size(522, 367);
dataGridView.TabIndex = 0;
//
// buttonSave
//
buttonSave.Location = new Point(291, 525);
buttonSave.Margin = new Padding(5, 4, 5, 4);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(101, 36);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(410, 525);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 36);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// ColumnId
//
ColumnId.HeaderText = "Id";
@ -177,11 +157,51 @@
ColumnCount.ReadOnly = true;
ColumnCount.Width = 125;
//
// buttonSave
//
buttonSave.Location = new Point(306, 586);
buttonSave.Margin = new Padding(5, 4, 5, 4);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(101, 36);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(417, 586);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 36);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxMax
//
textBoxMax.AutoSize = true;
textBoxMax.Location = new Point(16, 141);
textBoxMax.Name = "textBoxMax";
textBoxMax.Size = new Size(270, 20);
textBoxMax.TabIndex = 10;
textBoxMax.Text = "Максимальное колличество изделий:";
//
// textBoxMaximum
//
textBoxMaximum.Location = new Point(306, 138);
textBoxMaximum.Name = "textBoxMaximum";
textBoxMaximum.Size = new Size(101, 27);
textBoxMaximum.TabIndex = 11;
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(546, 576);
ClientSize = new Size(546, 635);
Controls.Add(textBoxMaximum);
Controls.Add(textBoxMax);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBoxReinforceds);
@ -217,5 +237,7 @@
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnName;
private DataGridViewTextBoxColumn ColumnCount;
private Label textBoxMax;
private TextBox textBoxMaximum;
}
}

View File

@ -40,6 +40,7 @@ namespace PrecastConcretePlantView
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePicker.Value = view.DateOpening;
textBoxMaximum.Text = view.ReinforcedsMax.ToString();
_shopReinforceds = view.ShopReinforceds ?? new Dictionary<int, (IReinforcedModel, int)>();
LoadData();
}
@ -90,6 +91,11 @@ namespace PrecastConcretePlantView
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMaximum.Text))
{
MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Shop saving");
try
{
@ -99,6 +105,7 @@ namespace PrecastConcretePlantView
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePicker.Value,
ReinforcedsMax = Convert.ToInt32(textBoxMaximum.Text),
ShopReinforceds = _shopReinforceds
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);

View File

@ -54,6 +54,7 @@ namespace PrecastConcretePlantView
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormShopReplenishment>();
services.AddTransient<FormReinforcedSale>();
}
}
}