крякнул, плюнул и надежно склеил скотчем

This commit is contained in:
Леонид Малафеев 2024-05-05 22:05:04 +04:00
parent 50958317dd
commit 49c8023f82
22 changed files with 1426 additions and 698 deletions

View File

@ -4,6 +4,7 @@ using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.StoragesContracts;
using JewelryStoreContracts.ViewModels;
using JewerlyStoreDataModels.Enums;
using JewerlyStoreDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -18,11 +19,17 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
private readonly IJewelStorage _jewelStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IJewelStorage jewelStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_shopLogic = shopLogic;
_jewelStorage = jewelStorage;
}
public bool CreateOrder(OrderBindingModel model)
@ -85,8 +92,19 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
}
}
model.Status = OrderStatus.Готов;
var jewel = _jewelStorage.GetElement(new JewelSearchModel() { Id = model.JewelId });
if (jewel == null)
{
_logger.LogWarning("Status change error. Jewel not found");
return false;
}
if (!CheckSupply(jewel, model.Count))
{
_logger.LogWarning("Status change error. Shop doesnt have jeweles");
return false;
}
_orderStorage.Update(model);
return true;
}
@ -132,5 +150,65 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
throw new InvalidOperationException("Заказ с таким ID уже существует");
}
}
public bool CheckSupply(IJewelModel jewel, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check supply operation error. Jewel count < 0");
return false;
}
int Capacity = _shopStorage.GetFullList().Select(x => x.MaxCountJewels).Sum();
int currentCount = _shopStorage.GetFullList().Select(x => x.ShopJewels.Select(y => y.Value.Item2).Sum()).Sum();
int freeSpace = Capacity - currentCount;
if (freeSpace < count)
{
_logger.LogWarning("Check supply error. No place for new Jewels");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.MaxCountJewels;
foreach (var doc in shop.ShopJewels)
{
freeSpace -= doc.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace >= count)
{
if (_shopLogic.AddJewel(new()
{
Id = shop.Id
}, jewel, count))
{
count = 0;
}
else
{
_logger.LogWarning("Supply error");
return false;
}
}
else
{
if (_shopLogic.AddJewel(new() { Id = shop.Id }, jewel, freeSpace))
count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -144,9 +144,15 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
Address = element.Address,
ShopName = element.ShopName,
DateOpen = element.DateOpen,
MaxCountJewels = element.MaxCountJewels,
ShopJewels = element.ShopJewels
});
return true;
}
}
public bool SellJewels(IJewelModel jewel, int count)
{
return _shopStorage.SellJewels(jewel, count);
}
}
}

View File

@ -13,6 +13,7 @@ namespace JewelryStoreContracts.BindingModels
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; } = DateTime.Now;
public Dictionary<int, (IJewelModel, int)> ShopJewels { get; set; } = new();
public int Id { get; set; }
public int MaxCountJewels { get; set; }
public int Id { get; set; }
}
}

View File

@ -18,5 +18,6 @@ namespace JewelryStoreContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool AddJewel(ShopSearchModel model, IJewelModel Jewel, int count);
}
bool SellJewels(IJewelModel model, int count);
}
}

View File

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

View File

@ -18,7 +18,9 @@ namespace JewelryStoreContracts.ViewModels
[DisplayName("Дата открытия")]
public DateTime DateOpen { get; set; } = DateTime.Now;
public Dictionary<int, (IJewelModel, int)> ShopJewels { get; set; } = new();
[DisplayName("Макс. кол-во изделий")]
public int MaxCountJewels { get; set; }
public Dictionary<int, (IJewelModel, int)> ShopJewels { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -3,6 +3,7 @@ using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.StoragesContracts;
using JewelryStoreContracts.ViewModels;
using JewelryStoreListImplement.Models;
using JewerlyStoreDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -108,5 +109,10 @@ namespace JewelryStoreListImplement.Implements
}
return null;
}
}
public bool SellJewels (IJewelModel jewel, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -16,7 +16,8 @@ namespace JewelryStoreListImplement.Models
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; }
public int Id { get; set; }
public int MaxCountJewels { get; private set; }
public int Id { get; set; }
public Dictionary<int, (IJewelModel, int)> ShopJewels { get; private set; } = new Dictionary<int, (IJewelModel, int)>();
public static Shop? Create(ShopBindingModel? model)
@ -31,7 +32,8 @@ namespace JewelryStoreListImplement.Models
ShopName = model.ShopName,
Address = model.Address,
DateOpen = model.DateOpen,
ShopJewels = model.ShopJewels
MaxCountJewels = model.MaxCountJewels,
ShopJewels = model.ShopJewels
};
}
@ -44,7 +46,8 @@ namespace JewelryStoreListImplement.Models
ShopName = model.ShopName;
Address = model.Address;
DateOpen = model.DateOpen;
ShopJewels = model.ShopJewels;
MaxCountJewels = model.MaxCountJewels;
ShopJewels = model.ShopJewels;
}
public ShopViewModel GetViewModel => new()
@ -53,7 +56,8 @@ namespace JewelryStoreListImplement.Models
ShopName = ShopName,
Address = Address,
DateOpen = DateOpen,
ShopJewels = ShopJewels
};
ShopJewels = ShopJewels,
MaxCountJewels = MaxCountJewels
};
}
}

View File

@ -11,6 +11,7 @@ namespace JewerlyStoreDataModels.Models
string ShopName { get; }
string Address { get; }
DateTime DateOpen { get; }
Dictionary<int, (IJewelModel, int)> ShopJewels { get; }
int MaxCountJewels { get; }
Dictionary<int, (IJewelModel, int)> ShopJewels { get; }
}
}

View File

@ -15,9 +15,11 @@ namespace JewerlyStoreFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string JewelFileName = "Jewel.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Jewel> Jewels { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
@ -34,11 +36,14 @@ namespace JewerlyStoreFileImplement
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, OrderFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.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,134 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.StoragesContracts;
using JewelryStoreContracts.ViewModels;
using JewerlyStoreDataModels.Models;
using JewerlyStoreFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JewerlyStoreFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.Shops
.Select(x => x.GetViewModel)
.Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty))
.ToList();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(shop => shop.GetViewModel).ToList();
}
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)
{
return null;
}
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
public bool SellJewels(IJewelModel model, int count)
{
var jewel = source.Jewels.FirstOrDefault(x => x.Id == model.Id);
if (jewel == null)
{
return false;
}
int countStore = source.Shops
.SelectMany(x => x.ShopJewels)
.Where(y => y.Key == model.Id)
.Sum(y => y.Value.Item2);
if (count > countStore)
return false;
foreach (var shop in source.Shops)
{
var jewels = shop.ShopJewels;
foreach (var c in jewels.Where(x => x.Value.Item1.Id == jewel.Id))
{
int min = Math.Min(c.Value.Item2, count);
jewels[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
count -= min;
if (count <= 0)
break;
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
MaxCountJewels = shop.MaxCountJewels,
DateOpen = shop.DateOpen,
ShopJewels = jewels
});
source.SaveShops();
if (count <= 0)
return true;
}
return true;
}
}
}

View File

@ -0,0 +1,116 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.ViewModels;
using JewerlyStoreDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace JewerlyStoreFileImplement.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 int MaxCountJewels { get; private set; }
public DateTime DateOpen { get; private set; }
public Dictionary<int, int> Jewels { get; private set; } = new();
private Dictionary<int, (IJewelModel, int)>? _shopJewels = null;
public Dictionary<int, (IJewelModel, int)> ShopJewels
{
get
{
if (_shopJewels == null)
{
var source = DataFileSingleton.GetInstance();
_shopJewels = Jewels.ToDictionary(
x => x.Key,
y => ((source.Jewels.FirstOrDefault(z => z.Id == y.Key) as IJewelModel)!, y.Value)
);
}
return _shopJewels;
}
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
MaxCountJewels = model.MaxCountJewels,
DateOpen = model.DateOpen,
Jewels = model.ShopJewels.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
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,
MaxCountJewels = Convert.ToInt32(element.Element("MaxCountJewels")!.Value),
DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value),
Jewels = element.Element("ShopJewels")!.Elements("ShopJewel").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;
MaxCountJewels = model.MaxCountJewels;
DateOpen = model.DateOpen;
if (model.ShopJewels.Count > 0)
{
Jewels = model.ShopJewels.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopJewels = null;
}
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
MaxCountJewels = MaxCountJewels,
DateOpen = DateOpen,
ShopJewels = ShopJewels,
};
public XElement GetXElement => new(
"Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("MaxCountJewels", MaxCountJewels),
new XElement("DateOpening", DateOpen.ToString()),
new XElement("ShopJewels", Jewels.Select(x =>
new XElement("ShopJewel",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

@ -1,198 +1,209 @@
namespace JewelryStoreView
namespace JewerlyStoreView
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
partial class FormMain
{
/// <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);
}
/// <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
#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()
{
dataGridView = new DataGridView();
menuStripMain = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделияToolStripMenuItem = new ToolStripMenuItem();
магазинToolStripMenuItem = new ToolStripMenuItem();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRefresh = new Button();
buttonAddJewel = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStripMain.SuspendLayout();
SuspendLayout();
//
// dataGridView
//
dataGridView.BackgroundColor = SystemColors.Control;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 31);
dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(762, 407);
dataGridView.TabIndex = 0;
//
// menuStripMain
//
menuStripMain.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
menuStripMain.Location = new Point(0, 0);
menuStripMain.Name = "menuStripMain";
menuStripMain.Size = new Size(1021, 24);
menuStripMain.TabIndex = 2;
menuStripMain.Text = "menuStripMain";
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазинToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
//
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(145, 22);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click_1;
//
// изделияToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
изделияToolStripMenuItem.Size = new Size(145, 22);
изделияToolStripMenuItem.Text = "Изделия";
изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click;
//
// магазинToolStripMenuItem
//
магазинToolStripMenuItem.Name = агазинToolStripMenuItem";
магазинToolStripMenuItem.Size = new Size(145, 22);
магазинToolStripMenuItem.Text = "Магазины";
магазинToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(836, 31);
buttonCreateOrder.Margin = new Padding(2);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(147, 34);
buttonCreateOrder.TabIndex = 3;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(836, 81);
buttonTakeOrderInWork.Margin = new Padding(2);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(147, 36);
buttonTakeOrderInWork.TabIndex = 4;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(836, 132);
buttonOrderReady.Margin = new Padding(2);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(147, 34);
buttonOrderReady.TabIndex = 5;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(836, 183);
buttonIssuedOrder.Margin = new Padding(2);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(147, 35);
buttonIssuedOrder.TabIndex = 6;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// buttonRefresh
//
buttonRefresh.Location = new Point(836, 234);
buttonRefresh.Margin = new Padding(2);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(147, 39);
buttonRefresh.TabIndex = 7;
buttonRefresh.Text = "Обновить список";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonAddJewel
//
buttonAddJewel.Location = new Point(836, 287);
buttonAddJewel.Name = "buttonAddJewel";
buttonAddJewel.Size = new Size(147, 35);
buttonAddJewel.TabIndex = 8;
buttonAddJewel.Text = "Добавить украшение";
buttonAddJewel.UseVisualStyleBackColor = true;
buttonAddJewel.Click += ButtonAddJewel_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1021, 450);
Controls.Add(buttonAddJewel);
Controls.Add(buttonRefresh);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(menuStripMain);
Controls.Add(dataGridView);
MainMenuStrip = menuStripMain;
Name = "FormMain";
Text = "Ювелирный";
Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
menuStripMain.ResumeLayout(false);
menuStripMain.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
menuStrip = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделиеToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
продажаИзделийToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonUpd = new Button();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаИзделийToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(5, 2, 0, 2);
menuStrip.Size = new Size(1003, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, магазиныToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
//
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(145, 22);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// изделиеToolStripMenuItem
//
изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem";
изделиеToolStripMenuItem.Size = new Size(145, 22);
изделиеToolStripMenuItem.Text = "Изделие";
изделиеToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(145, 22);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
//
// пополнениеМагазинаToolStripMenuItem
//
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
пополнениеМагазинаToolStripMenuItem.Size = new Size(143, 20);
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазиныToolStripMenuItem_Click;
//
// продажаИзделийToolStripMenuItem
//
продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem";
продажаИзделийToolStripMenuItem.Size = new Size(117, 20);
продажаИзделийToolStripMenuItem.Text = "Продажа изделий";
продажаИзделийToolStripMenuItem.Click += sellJewelsToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(10, 23);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(802, 305);
dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(817, 44);
buttonCreateOrder.Margin = new Padding(3, 2, 3, 2);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(175, 28);
buttonCreateOrder.TabIndex = 2;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(817, 84);
buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(175, 28);
buttonTakeOrderInWork.TabIndex = 3;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(817, 124);
buttonOrderReady.Margin = new Padding(3, 2, 3, 2);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(175, 28);
buttonOrderReady.TabIndex = 4;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(817, 166);
buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(175, 28);
buttonIssuedOrder.TabIndex = 5;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(817, 208);
buttonUpd.Margin = new Padding(3, 2, 3, 2);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(175, 28);
buttonUpd.TabIndex = 6;
buttonUpd.Text = "Обновить список";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1003, 338);
Controls.Add(buttonUpd);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Margin = new Padding(3, 2, 3, 2);
Name = "FormMain";
Text = "Ювелирный";
Load += FormMain_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
#endregion
private DataGridView dataGridView;
private MenuStrip menuStripMain;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
private ToolStripMenuItem магазинToolStripMenuItem;
private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRefresh;
private Button buttonAddJewel;
}
private MenuStrip menuStrip;
private ToolStripMenuItem справочникиToolStripMenuItem;
private DataGridView dataGridView;
private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonUpd;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделиеToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private ToolStripMenuItem продажаИзделийToolStripMenuItem;
}
}

View File

@ -1,7 +1,7 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreView;
using JewerlyStoreDataModels.Enums;
using JewerlyStoreView;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -13,188 +13,184 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JewelryStoreView
namespace JewerlyStoreView
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public partial class FormMain : Form
{
private readonly ILogger _logger;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private readonly IOrderLogic _orderLogic;
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["JewelId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["JewelId"].Visible = false;
dataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Orders loading");
}
catch (Exception ex)
{
_logger.LogError(ex, "Orders loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void sellJewelsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
if (service is FormShopSell form)
{
form.ShowDialog();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = id,
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
private void ЗакускаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormJewels));
if (service is FormJewels form)
{
form.ShowDialog();
}
}
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ПополнениеМагазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddJewel));
if (service is FormAddJewel form)
{
form.ShowDialog();
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = id,
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void компонентыToolStripMenuItem_Click_1(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error taking an order to work");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void изделияToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormJewels));
if (service is FormJewels form)
{
form.ShowDialog();
}
}
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Order readiness marking error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonAddJewel_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddJewel));
if (service is FormAddJewel form)
{
form.ShowDialog();
LoadData();
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Order №{id} issued", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Order issue marking error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
LoadData();
}
private OrderBindingModel CreateBindingModel(int id)
{
return new OrderBindingModel
{
Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = (System.DateTime)dataGridView.SelectedRows[0].Cells["DateCreate"].Value,
};
}
}
}

View File

@ -117,10 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStripMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>40, 22</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>64</value>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1,188 +1,214 @@
namespace JewerlyStoreView
{
partial class FormShop
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
partial class FormShop
{
/// <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);
}
/// <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
#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.labelShop = new System.Windows.Forms.Label();
this.labelAddress = new System.Windows.Forms.Label();
this.labelDate = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(12, 21);
this.labelShop.Name = "labelShop";
this.labelShop.Size = new System.Drawing.Size(69, 20);
this.labelShop.TabIndex = 0;
this.labelShop.Text = "Магазин";
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(195, 21);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(51, 20);
this.labelAddress.TabIndex = 1;
this.labelAddress.Text = "Адрес";
//
// labelDate
//
this.labelDate.AutoSize = true;
this.labelDate.Location = new System.Drawing.Point(474, 21);
this.labelDate.Name = "labelDate";
this.labelDate.Size = new System.Drawing.Size(110, 20);
this.labelDate.TabIndex = 2;
this.labelDate.Text = "Дата открытия";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(12, 44);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(160, 27);
this.textBoxName.TabIndex = 3;
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(195, 44);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(246, 27);
this.textBoxAddress.TabIndex = 4;
//
// dateTimePickerDateOpen
//
this.dateTimePickerDateOpen.Location = new System.Drawing.Point(474, 44);
this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen";
this.dateTimePickerDateOpen.Size = new System.Drawing.Size(250, 27);
this.dateTimePickerDateOpen.TabIndex = 5;
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.JewelName,
this.Count});
this.dataGridView.Location = new System.Drawing.Point(12, 77);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(712, 330);
this.dataGridView.TabIndex = 6;
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(490, 413);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(111, 29);
this.ButtonSave.TabIndex = 7;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(630, 413);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 8;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// ID
//
this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ID.HeaderText = "ID";
this.ID.MinimumWidth = 6;
this.ID.Name = "ID";
this.ID.Visible = false;
//
// JewelName
//
this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.JewelName.HeaderText = "JewelName";
this.JewelName.MinimumWidth = 6;
this.JewelName.Name = "JewelName";
//
// Count
//
this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Count.HeaderText = "Count";
this.Count.MinimumWidth = 6;
this.Count.Name = "Count";
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(740, 450);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.dateTimePickerDateOpen);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelDate);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelShop);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelShop = new Label();
labelAddress = new Label();
labelDate = new Label();
textBoxName = new TextBox();
textBoxAddress = new TextBox();
dateTimePickerDateOpen = new DateTimePicker();
dataGridView = new DataGridView();
ID = new DataGridViewTextBoxColumn();
JewelName = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn();
ButtonSave = new Button();
ButtonCancel = new Button();
labelMaxCountPrinteds = new Label();
textBoxMaxCount = new TextBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// labelShop
//
labelShop.AutoSize = true;
labelShop.Location = new Point(10, 16);
labelShop.Name = "labelShop";
labelShop.Size = new Size(54, 15);
labelShop.TabIndex = 0;
labelShop.Text = "Магазин";
//
// labelAddress
//
labelAddress.AutoSize = true;
labelAddress.Location = new Point(171, 16);
labelAddress.Name = "labelAddress";
labelAddress.Size = new Size(40, 15);
labelAddress.TabIndex = 1;
labelAddress.Text = "Адрес";
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(415, 16);
labelDate.Name = "labelDate";
labelDate.Size = new Size(87, 15);
labelDate.TabIndex = 2;
labelDate.Text = "Дата открытия";
//
// textBoxName
//
textBoxName.Location = new Point(10, 33);
textBoxName.Margin = new Padding(3, 2, 3, 2);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(140, 23);
textBoxName.TabIndex = 3;
//
// textBoxAddress
//
textBoxAddress.Location = new Point(171, 33);
textBoxAddress.Margin = new Padding(3, 2, 3, 2);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(216, 23);
textBoxAddress.TabIndex = 4;
//
// dateTimePickerDateOpen
//
dateTimePickerDateOpen.Location = new Point(415, 33);
dateTimePickerDateOpen.Margin = new Padding(3, 2, 3, 2);
dateTimePickerDateOpen.Name = "dateTimePickerDateOpen";
dateTimePickerDateOpen.Size = new Size(219, 23);
dateTimePickerDateOpen.TabIndex = 5;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, JewelName, Count });
dataGridView.Location = new Point(10, 105);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(623, 248);
dataGridView.TabIndex = 6;
//
// ID
//
ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ID.HeaderText = "ID";
ID.MinimumWidth = 6;
ID.Name = "ID";
ID.Visible = false;
//
// JewelName
//
JewelName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
JewelName.HeaderText = "JewelName";
JewelName.MinimumWidth = 6;
JewelName.Name = "JewelName";
//
// Count
//
Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
Count.HeaderText = "Count";
Count.MinimumWidth = 6;
Count.Name = "Count";
//
// ButtonSave
//
ButtonSave.Location = new Point(448, 357);
ButtonSave.Margin = new Padding(3, 2, 3, 2);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(97, 22);
ButtonSave.TabIndex = 7;
ButtonSave.Text = "Сохранить";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// ButtonCancel
//
ButtonCancel.Location = new Point(551, 357);
ButtonCancel.Margin = new Padding(3, 2, 3, 2);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(82, 22);
ButtonCancel.TabIndex = 8;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// labelMaxCountPrinteds
//
labelMaxCountPrinteds.Location = new Point(10, 68);
labelMaxCountPrinteds.Name = "labelMaxCountPrinteds";
labelMaxCountPrinteds.Size = new Size(140, 30);
labelMaxCountPrinteds.TabIndex = 10;
labelMaxCountPrinteds.Text = "Максимальное количество изделий :";
//
// textBoxMaxCount
//
textBoxMaxCount.Location = new Point(155, 78);
textBoxMaxCount.Margin = new Padding(3, 2, 3, 2);
textBoxMaxCount.Name = "textBoxMaxCount";
textBoxMaxCount.Size = new Size(219, 23);
textBoxMaxCount.TabIndex = 11;
//
// FormShop
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(659, 426);
Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(dataGridView);
Controls.Add(dateTimePickerDateOpen);
Controls.Add(textBoxAddress);
Controls.Add(textBoxName);
Controls.Add(labelDate);
Controls.Add(labelAddress);
Controls.Add(labelShop);
Controls.Add(textBoxMaxCount);
Controls.Add(labelMaxCountPrinteds);
Margin = new Padding(3, 2, 3, 2);
Name = "FormShop";
Text = "Магазин";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
}
#endregion
#endregion
private Label labelShop;
private Label labelAddress;
private Label labelDate;
private Label labelMaxCountPrinteds;
private TextBox textBoxMaxCount;
private TextBox textBoxName;
private TextBox textBoxAddress;
private DateTimePicker dateTimePickerDateOpen;
private DataGridView dataGridView;
private Button ButtonSave;
private Button ButtonCancel;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn JewelName;
private DataGridViewTextBoxColumn Count;
private Label labelShop;
private Label labelAddress;
private Label labelDate;
private TextBox textBoxName;
private TextBox textBoxAddress;
private DateTimePicker dateTimePickerDateOpen;
private DataGridView dataGridView;
private Button ButtonSave;
private Button ButtonCancel;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn JewelName;
private DataGridViewTextBoxColumn Count;
}
}
}

View File

@ -15,117 +15,124 @@ using System.Windows.Forms;
namespace JewerlyStoreView
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
private Dictionary<int, (IJewelModel, int)> _shopJewels;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopJewels = new Dictionary<int, (IJewelModel, int)>();
}
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
private Dictionary<int, (IJewelModel, int)> _shopJewels;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopJewels = new Dictionary<int, (IJewelModel, int)>();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new ShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address.ToString();
dateTimePickerDateOpen.Text = view.DateOpen.ToString();
_shopJewels = view.ShopJewels ?? new Dictionary<int, (IJewelModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка изделий магазина");
try
{
if (_shopJewels != null)
{
dataGridView.Rows.Clear();
foreach (var element in _shopJewels)
{
dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.JewelName, element.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new ShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address.ToString();
dateTimePickerDateOpen.Text = view.DateOpen.ToString();
textBoxMaxCount.Text = view.MaxCountJewels.ToString();
_shopJewels = view.ShopJewels ?? new Dictionary<int, (IJewelModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка изделий магазина");
try
{
if (_shopJewels != null)
{
dataGridView.Rows.Clear();
foreach (var element in _shopJewels)
{
dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.JewelName, element.Value.Item2 });
}
}
}
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(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(dateTimePickerDateOpen.Text))
{
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text),
ShopJewels = _shopJewels
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
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 ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(dateTimePickerDateOpen.Text))
{
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMaxCount.Text))
{
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text),
MaxCountJewels = Convert.ToInt32(textBoxMaxCount.Text),
ShopJewels = _shopJewels
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
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();
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,119 @@
namespace JewerlyStoreView
{
partial class FormShopSell
{
/// <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()
{
labelJewel = new Label();
labelCount = new Label();
comboBoxJewel = new ComboBox();
textBoxCount = new TextBox();
buttonCancel = new Button();
buttonSell = new Button();
SuspendLayout();
//
// labelJewel
//
labelJewel.AutoSize = true;
labelJewel.Location = new Point(12, 9);
labelJewel.Name = "labelJewel";
labelJewel.Size = new Size(56, 15);
labelJewel.TabIndex = 0;
labelJewel.Text = "Изделие:";
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(12, 38);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 1;
labelCount.Text = "Количество:";
//
// comboBoxJewel
//
comboBoxJewel.FormattingEnabled = true;
comboBoxJewel.Location = new Point(88, 6);
comboBoxJewel.Name = "comboBoxJewel";
comboBoxJewel.Size = new Size(297, 23);
comboBoxJewel.TabIndex = 2;
//
// textBoxCount
//
textBoxCount.Location = new Point(88, 35);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(297, 23);
textBoxCount.TabIndex = 3;
//
// buttonCancel
//
buttonCancel.Location = new Point(310, 64);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSell
//
buttonSell.Location = new Point(229, 64);
buttonSell.Name = "buttonSell";
buttonSell.Size = new Size(75, 23);
buttonSell.TabIndex = 5;
buttonSell.Text = "Продать";
buttonSell.UseVisualStyleBackColor = true;
buttonSell.Click += buttonSell_Click;
//
// FormShopSell
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(397, 93);
Controls.Add(buttonSell);
Controls.Add(buttonCancel);
Controls.Add(textBoxCount);
Controls.Add(comboBoxJewel);
Controls.Add(labelCount);
Controls.Add(labelJewel);
Name = "FormShopSell";
Text = "Продажа";
Load += FormShopSell_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelJewel;
private Label labelCount;
private ComboBox comboBoxJewel;
private TextBox textBoxCount;
private Button buttonCancel;
private Button buttonSell;
}
}

View File

@ -0,0 +1,95 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts;
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 JewerlyStoreView
{
public partial class FormShopSell : Form
{
private readonly ILogger _logger;
private readonly IJewelLogic _logicJewel;
private readonly IShopLogic _logicShop;
public FormShopSell(ILogger<FormShopSell> logger, IJewelLogic logicJewel, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicJewel = logicJewel;
_logicShop = logicShop;
}
private void FormShopSell_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка изделий для продажи");
try
{
var list = _logicJewel.ReadList(null);
if (list != null)
{
comboBoxJewel.DisplayMember = "JewelName";
comboBoxJewel.ValueMember = "Id";
comboBoxJewel.DataSource = list;
comboBoxJewel.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSell_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxJewel.SelectedValue == null)
{
MessageBox.Show("Выберите изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание продажи");
try
{
var operationResult = _logicShop.SellJewels(
new JewelBindingModel
{
Id = Convert.ToInt32(comboBoxJewel.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

@ -54,6 +54,7 @@ namespace JewelryStoreView
services.AddTransient<FormAddJewel>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
}
services.AddTransient<FormShopSell>();
}
}
}