PIbd-21 Lab2-Hard BlokhinDA FishFactory Hard #15
5
.gitignore
vendored
5
.gitignore
vendored
@ -14,6 +14,11 @@
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# dll файлы
|
||||
*.dll
|
||||
|
||||
/FishFactory/ImplementationExtensions
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
|
@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic",
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{7BD43CA5-83F9-4A5D-AA53-B4A6293BFE79}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{1039795B-684B-4D67-92F7-CEB309C6CEC2}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{1039795B-684B-4D67-92F7-CEB309C6CEC2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryFileImplement", "FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{CA570C72-5BB7-47F1-8B3E-B71F94D7BF4E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{1039795B-684B-4D67-92F7-CEB309C6CEC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1039795B-684B-4D67-92F7-CEB309C6CEC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1039795B-684B-4D67-92F7-CEB309C6CEC2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CA570C72-5BB7-47F1-8B3E-B71F94D7BF4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CA570C72-5BB7-47F1-8B3E-B71F94D7BF4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CA570C72-5BB7-47F1-8B3E-B71F94D7BF4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CA570C72-5BB7-47F1-8B3E-B71F94D7BF4E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -17,11 +17,15 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly ICannedStorage _cannedStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, ICannedStorage cannedStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_cannedStorage = cannedStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
@ -66,8 +70,25 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
||||
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
|
||||
}
|
||||
model.Status = status;
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
var canned = _cannedStorage.GetElement(new() { Id = element.CannedId });
|
||||
if (canned == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(canned));
|
||||
}
|
||||
if (!_shopLogic.AddCanned(canned, element.Count))
|
||||
{
|
||||
throw new Exception($"AddCanned operation failed. Shop is full.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = element.DateImplement;
|
||||
}
|
||||
CheckModel(model, false);
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,12 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||
}
|
||||
if (model.MaxCountCanned < 0)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Максимальное количество консервы в магазине не может быть меньше нуля",
|
||||
nameof(model.MaxCountCanned));
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
|
||||
model.ShopName, model.Address, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
@ -128,6 +134,10 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("AddCannedInShop element not found");
|
||||
return false;
|
||||
}
|
||||
if (element.MaxCountCanned - element.ListCanned.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
throw new ArgumentNullException("Магазин переполнен", nameof(count));
|
||||
}
|
||||
_logger.LogInformation("AddCannedInShop find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.ListCanned.TryGetValue(Canned.Id, out var pair))
|
||||
@ -150,9 +160,61 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
||||
Address = element.Address,
|
||||
ShopName = element.ShopName,
|
||||
DateOpening = element.DateOpening,
|
||||
MaxCountCanned = element.MaxCountCanned,
|
||||
ListCanned = element.ListCanned
|
||||
});
|
||||
return true;
|
||||
}
|
||||
public bool AddCanned(ICannedModel model, int count)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество консерв должно быть больше 0", nameof(count));
|
||||
}
|
||||
var freeCount = _shopStorage.GetFullList()
|
||||
.Select(x => x.MaxCountCanned - x.ListCanned
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - count;
|
||||
if (freeCount < 0)
|
||||
{
|
||||
_logger.LogInformation("AddCanned. Не удалось добавить изделия в магазины, они переполнены.");
|
||||
return false;
|
||||
}
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
int countFree = shop.MaxCountCanned - shop.ListCanned.Select(x => x.Value.Item2).Sum();
|
||||
if (countFree < count)
|
||||
{
|
||||
if (!AddCannedInShop(new() { Id = shop.Id }, model, countFree))
|
||||
{
|
||||
_logger.LogWarning("AddCannedInShop operation failed.");
|
||||
return false;
|
||||
}
|
||||
count -= countFree;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AddCannedInShop(new() { Id = shop.Id }, model, count))
|
||||
{
|
||||
_logger.LogWarning("AddCannedInShop operation failed.");
|
||||
return false;
|
||||
}
|
||||
count = 0;
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SellCanned(ICannedModel model, int count)
|
||||
{
|
||||
return _shopStorage.SellCanned(model, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace FishFactoryContracts.BindingModels
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
public int MaxCountCanned { get; set; }
|
||||
|
||||
public Dictionary<int, (ICannedModel, int)> ListCanned
|
||||
{
|
||||
|
@ -18,5 +18,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool AddCannedInShop(ShopSearchModel model, ICannedModel canned, int count);
|
||||
bool AddCanned(ICannedModel canned, int count);
|
||||
bool SellCanned(ICannedModel canned, int count);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,5 +18,6 @@ namespace FishFactoryContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellCanned(ICannedModel model, int count);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ namespace FishFactoryContracts.ViewModels
|
||||
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
[DisplayName("Максимальное количество консерв")]
|
||||
public int MaxCountCanned { get; set; }
|
||||
|
||||
public Dictionary<int, (ICannedModel, int)> ListCanned
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -11,6 +12,7 @@ namespace FishFactoryDataModels.Models
|
||||
string ShopName { get; }
|
||||
string Address { get; }
|
||||
DateTime DateOpening { get; }
|
||||
int MaxCountCanned { get; }
|
||||
Dictionary<int, (ICannedModel, int)> ListCanned { get; }
|
||||
}
|
||||
}
|
||||
|
58
FishFactory/FishFactoryFileImplement/DataFileSingleton.cs
Normal file
58
FishFactory/FishFactoryFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using FishFactoryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FishFactoryFileImplement
|
||||
{
|
||||
internal class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string CannedFileName = "Canned.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Canned> Canneds { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
return new List<T>();
|
||||
|
||||
}
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveCannedes() => SaveData(Canneds, CannedFileName, "Canneds", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Canneds = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryDataModels\FishFactoryDataModels.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,74 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Implements
|
||||
{
|
||||
public class CannedStorage : ICannedStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public CannedStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<CannedViewModel> GetFullList()
|
||||
{
|
||||
return source.Canneds.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<CannedViewModel> GetFilteredList(CannedSearchModel model)
|
||||
{
|
||||
return source.Canneds.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public CannedViewModel? GetElement(CannedSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Canneds.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CannedName) && x.CannedName == model.CannedName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public CannedViewModel? Insert(CannedBindingModel model)
|
||||
{
|
||||
model.Id = source.Canneds.Count > 0 ? source.Canneds.Max(x => x.Id) + 1 : 1;
|
||||
var newCanned = Canned.Create(model);
|
||||
if (newCanned == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Canneds.Add(newCanned);
|
||||
source.SaveCannedes();
|
||||
return newCanned.GetViewModel;
|
||||
}
|
||||
public CannedViewModel? Update(CannedBindingModel model)
|
||||
{
|
||||
var component = source.Canneds.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveCannedes();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public CannedViewModel? Delete(CannedBindingModel model)
|
||||
{
|
||||
var component = source.Canneds.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Canneds.Remove(component);
|
||||
source.SaveCannedes();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Remove(component);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => AcessDressesStorage(x.GetViewModel)).ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
return source.Orders.Where(x => x.Id == model.Id)
|
||||
.Select(x => AcessDressesStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var component = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveOrders();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var component = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Remove(component);
|
||||
source.SaveOrders();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public OrderViewModel AcessDressesStorage(OrderViewModel model)
|
||||
{
|
||||
var component = source.Canneds.FirstOrDefault(x => x.Id == model.CannedId);
|
||||
model.CannedName = component.CannedName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
107
FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs
Normal file
107
FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Models;
|
||||
using FishFactoryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ShopStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return source.Shops.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops.Where(x =>
|
||||
x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName ==
|
||||
model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Add(newShop);
|
||||
source.SaveShops();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Shops.Remove(element);
|
||||
source.SaveShops();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellCanned(ICannedModel model, int count)
|
||||
{
|
||||
if (source.Shops.Select(x => x.ListCanned.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var shop in source.Shops.Where(x => x.ListCanned.ContainsKey(model.Id)))
|
||||
{
|
||||
int countInCurrentShop = shop.ListCanned[model.Id].Item2;
|
||||
if (countInCurrentShop <= count)
|
||||
{
|
||||
shop.ListCanned.Remove(model.Id);
|
||||
count -= countInCurrentShop;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ListCanned[model.Id] = (shop.ListCanned[model.Id].Item1, countInCurrentShop - count);
|
||||
count = 0;
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
82
FishFactory/FishFactoryFileImplement/Models/Canned.cs
Normal file
82
FishFactory/FishFactoryFileImplement/Models/Canned.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Models
|
||||
{
|
||||
public class Canned : ICannedModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string CannedName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
private Dictionary<int, (IComponentModel, int)>? _cannedComponents = null;
|
||||
public Dictionary<int, (IComponentModel, int)> CannedComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cannedComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_cannedComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||
}
|
||||
return _cannedComponents;
|
||||
}
|
||||
}
|
||||
public static Canned? Create(CannedBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Canned()
|
||||
{
|
||||
Id = model.Id,
|
||||
CannedName = model.CannedName,
|
||||
Price = model.Price,
|
||||
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Canned? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{ return null; }
|
||||
return new Canned()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")?.Value),
|
||||
CannedName = element.Element("CannedName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value, new System.Globalization.CultureInfo("en-US")),
|
||||
Components = element.Element("CannedComponents")!.Elements("CannedComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(CannedBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CannedName = model.CannedName;
|
||||
Price = model.Price;
|
||||
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_cannedComponents = null;
|
||||
}
|
||||
public CannedViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CannedName = CannedName,
|
||||
Price = Price,
|
||||
CannedComponents = CannedComponents
|
||||
};
|
||||
public XElement GetXElement => new("Canned",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("CannedName", CannedName),
|
||||
new XElement("Price", Price),
|
||||
new XElement("CannedComponents", Components.Select(x => new XElement("CannedComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
|
||||
}
|
||||
}
|
64
FishFactory/FishFactoryFileImplement/Models/Component.cs
Normal file
64
FishFactory/FishFactoryFileImplement/Models/Component.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
public double Cost { get; private set; }
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public static Component? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ComponentName = element.Element("ComponentName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value, new System.Globalization.CultureInfo("en-US"))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{ return; }
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
public XElement GetXElement => new("Component",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString()));
|
||||
}
|
||||
}
|
||||
|
88
FishFactory/FishFactoryFileImplement/Models/Order.cs
Normal file
88
FishFactory/FishFactoryFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Enums;
|
||||
using FishFactoryDataModels.Models;
|
||||
using System.Data;
|
||||
using System.Xml.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int CannedId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
CannedId = model.CannedId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
};
|
||||
}
|
||||
public static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var dateImplement = element.Element("DateImplement")?.Value;
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
CannedId = Convert.ToInt32(element.Element("CannedId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value, new System.Globalization.CultureInfo("en-US")),
|
||||
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")?.Value),
|
||||
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement)
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CannedId = CannedId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("CannedId", CannedId),
|
||||
new XElement("Count", Count),
|
||||
new XElement("Sum", Sum),
|
||||
new XElement("Status", Status - OrderStatus.Принят),
|
||||
new XElement("DateCreate", DateCreate),
|
||||
new XElement("DateImplement", DateImplement));
|
||||
}
|
||||
}
|
108
FishFactory/FishFactoryFileImplement/Models/Shop.cs
Normal file
108
FishFactory/FishFactoryFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FishFactoryFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public DateTime DateOpening { get; private set; }
|
||||
public int MaxCountCanned { get; private set; }
|
||||
public Dictionary<int, int> CountCanned
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
|
||||
private Dictionary<int, (ICannedModel, int)>? _shopCanned = null;
|
||||
public Dictionary<int, (ICannedModel, int)> ListCanned
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopCanned == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopCanned =
|
||||
CountCanned.ToDictionary(x => x.Key,
|
||||
y => ((source.Canneds.FirstOrDefault(z => z.Id == y.Key) as ICannedModel)!, y.Value));
|
||||
}
|
||||
return _shopCanned;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
MaxCountCanned = model.MaxCountCanned,
|
||||
DateOpening = model.DateOpening,
|
||||
CountCanned = model.ListCanned.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ShopName = element.Element("ShopName")!.Value,
|
||||
Address = element.Element("Address")!.Value,
|
||||
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||
MaxCountCanned = Convert.ToInt32(element.Element("MaxCountCanned")!.Value),
|
||||
CountCanned = element.Element("ListCanned")!.Elements("Canned").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
MaxCountCanned = model.MaxCountCanned;
|
||||
CountCanned = model.ListCanned.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopCanned = null;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
ListCanned = ListCanned,
|
||||
DateOpening = DateOpening,
|
||||
MaxCountCanned = MaxCountCanned,
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Address", Address),
|
||||
new XElement("DateOpening", DateOpening),
|
||||
new XElement("MaxCountCanned", MaxCountCanned),
|
||||
new XElement("ListCanned", CountCanned.Select(x => new XElement("Canned",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))).ToArray()));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using FishFactoryDataModels.Models;
|
||||
using FishFactoryListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -103,5 +104,9 @@ namespace FishFactoryListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public bool SellCanned(ICannedModel model, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,5 +54,6 @@ namespace FishFactoryListImplement.Models
|
||||
ListCanned = ListCanned,
|
||||
DateOpening = DateOpening,
|
||||
};
|
||||
public int MaxCountCanned => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryFileImplement\FishFactoryFileImplement.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
119
FishFactory/FishFactoryView/FormSellCanned.Designer.cs
generated
Normal file
119
FishFactory/FishFactoryView/FormSellCanned.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace FishFactoryView
|
||||
{
|
||||
partial class FormSellCanned
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
comboBoxCanned = new ComboBox();
|
||||
textBoxCount = new TextBox();
|
||||
labelCanned = new Label();
|
||||
labelCount = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxCanned
|
||||
//
|
||||
comboBoxCanned.FormattingEnabled = true;
|
||||
comboBoxCanned.Location = new Point(162, 27);
|
||||
comboBoxCanned.Name = "comboBoxCanned";
|
||||
comboBoxCanned.Size = new Size(244, 28);
|
||||
comboBoxCanned.TabIndex = 0;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(162, 81);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(244, 27);
|
||||
textBoxCount.TabIndex = 1;
|
||||
//
|
||||
// labelCanned
|
||||
//
|
||||
labelCanned.AutoSize = true;
|
||||
labelCanned.Location = new Point(25, 30);
|
||||
labelCanned.Name = "labelCanned";
|
||||
labelCanned.Size = new Size(76, 20);
|
||||
labelCanned.TabIndex = 2;
|
||||
labelCanned.Text = "Консерва";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(25, 84);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(90, 20);
|
||||
labelCount.TabIndex = 3;
|
||||
labelCount.Text = "Количество";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(162, 150);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 4;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(300, 150);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormSellCanned
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(418, 191);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelCanned);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(comboBoxCanned);
|
||||
Name = "FormSellCanned";
|
||||
Text = "Продажа консервы";
|
||||
Load += FormSellCanned_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxCanned;
|
||||
private TextBox textBoxCount;
|
||||
private Label labelCanned;
|
||||
private Label labelCount;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
90
FishFactory/FishFactoryView/FormSellCanned.cs
Normal file
90
FishFactory/FishFactoryView/FormSellCanned.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FishFactoryView
|
||||
{
|
||||
public partial class FormSellCanned : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICannedLogic _logicCanned;
|
||||
private readonly IShopLogic _logicShop;
|
||||
|
||||
public FormSellCanned(ILogger<FormSellCanned> logger, ICannedLogic logicCanned, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicCanned = logicCanned;
|
||||
_logicShop = logicShop;
|
||||
}
|
||||
|
||||
private void FormSellCanned_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка списка консервы для продажи");
|
||||
try
|
||||
{
|
||||
var list = _logicCanned.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxCanned.DisplayMember = "CannedName";
|
||||
comboBoxCanned.ValueMember = "Id";
|
||||
comboBoxCanned.DataSource = list;
|
||||
comboBoxCanned.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка консерв");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле 'Количество'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxCanned.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Продажа консерв");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.SellCanned(_logicCanned.ReadElement(new CannedSearchModel()
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxCanned.SelectedValue)
|
||||
})!, Convert.ToInt32(textBoxCount.Text));
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при продаже консервы. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка продажи консервы");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
FishFactory/FishFactoryView/FormSellCanned.resx
Normal file
120
FishFactory/FishFactoryView/FormSellCanned.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
377
FishFactory/FishFactoryView/FormShop.Designer.cs
generated
377
FishFactory/FishFactoryView/FormShop.Designer.cs
generated
@ -1,184 +1,209 @@
|
||||
namespace FishFactoryView
|
||||
{
|
||||
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()
|
||||
{
|
||||
textBoxShop = new TextBox();
|
||||
textBoxAddress = new TextBox();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
dataGridView = new DataGridView();
|
||||
labelName = new Label();
|
||||
labelAddress = new Label();
|
||||
labelDate = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
ColumnId = new DataGridViewTextBoxColumn();
|
||||
ColumnCannedName = new DataGridViewTextBoxColumn();
|
||||
ColumnCount = new DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxShop
|
||||
//
|
||||
textBoxShop.Location = new Point(394, 12);
|
||||
textBoxShop.Name = "textBoxShop";
|
||||
textBoxShop.Size = new Size(277, 27);
|
||||
textBoxShop.TabIndex = 0;
|
||||
//
|
||||
// textBoxAddress
|
||||
//
|
||||
textBoxAddress.Location = new Point(394, 57);
|
||||
textBoxAddress.Name = "textBoxAddress";
|
||||
textBoxAddress.Size = new Size(277, 27);
|
||||
textBoxAddress.TabIndex = 1;
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(394, 100);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(277, 27);
|
||||
dateTimePicker.TabIndex = 2;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnCannedName, ColumnCount });
|
||||
dataGridView.Location = new Point(12, 147);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(659, 309);
|
||||
dataGridView.TabIndex = 3;
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(225, 15);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(147, 20);
|
||||
labelName.TabIndex = 4;
|
||||
labelName.Text = "Название магазина";
|
||||
//
|
||||
// labelAddress
|
||||
//
|
||||
labelAddress.AutoSize = true;
|
||||
labelAddress.Location = new Point(225, 60);
|
||||
labelAddress.Name = "labelAddress";
|
||||
labelAddress.Size = new Size(51, 20);
|
||||
labelAddress.TabIndex = 5;
|
||||
labelAddress.Text = "Адрес";
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(225, 105);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(110, 20);
|
||||
labelDate.TabIndex = 6;
|
||||
labelDate.Text = "Дата открытия";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(411, 467);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 7;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(549, 467);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 8;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// ColumnId
|
||||
//
|
||||
ColumnId.HeaderText = "Id";
|
||||
ColumnId.MinimumWidth = 6;
|
||||
ColumnId.Name = "ColumnId";
|
||||
ColumnId.Visible = false;
|
||||
ColumnId.Width = 125;
|
||||
//
|
||||
// ColumnCannedName
|
||||
//
|
||||
ColumnCannedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
ColumnCannedName.HeaderText = "Консерва";
|
||||
ColumnCannedName.MinimumWidth = 6;
|
||||
ColumnCannedName.Name = "ColumnCannedName";
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
ColumnCount.HeaderText = "Количество";
|
||||
ColumnCount.MinimumWidth = 6;
|
||||
ColumnCount.Name = "ColumnCount";
|
||||
ColumnCount.Width = 125;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(683, 508);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(labelAddress);
|
||||
Controls.Add(labelName);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(dateTimePicker);
|
||||
Controls.Add(textBoxAddress);
|
||||
Controls.Add(textBoxShop);
|
||||
Name = "FormShop";
|
||||
Text = "Создание магазина";
|
||||
Load += FormShop_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
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()
|
||||
{
|
||||
textBoxShop = new TextBox();
|
||||
textBoxAddress = new TextBox();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
dataGridView = new DataGridView();
|
||||
ColumnId = new DataGridViewTextBoxColumn();
|
||||
ColumnCannedName = new DataGridViewTextBoxColumn();
|
||||
ColumnCount = new DataGridViewTextBoxColumn();
|
||||
labelName = new Label();
|
||||
labelAddress = new Label();
|
||||
labelDate = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
numericUpDownCount = new NumericUpDown();
|
||||
labelCount = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxShop
|
||||
//
|
||||
textBoxShop.Location = new Point(394, 12);
|
||||
textBoxShop.Name = "textBoxShop";
|
||||
textBoxShop.Size = new Size(277, 27);
|
||||
textBoxShop.TabIndex = 0;
|
||||
//
|
||||
// textBoxAddress
|
||||
//
|
||||
textBoxAddress.Location = new Point(394, 57);
|
||||
textBoxAddress.Name = "textBoxAddress";
|
||||
textBoxAddress.Size = new Size(277, 27);
|
||||
textBoxAddress.TabIndex = 1;
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(394, 100);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(277, 27);
|
||||
dateTimePicker.TabIndex = 2;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnCannedName, ColumnCount });
|
||||
dataGridView.Location = new Point(12, 191);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(659, 309);
|
||||
dataGridView.TabIndex = 3;
|
||||
//
|
||||
// ColumnId
|
||||
//
|
||||
ColumnId.HeaderText = "Id";
|
||||
ColumnId.MinimumWidth = 6;
|
||||
ColumnId.Name = "ColumnId";
|
||||
ColumnId.Visible = false;
|
||||
ColumnId.Width = 125;
|
||||
//
|
||||
// ColumnCannedName
|
||||
//
|
||||
ColumnCannedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
ColumnCannedName.HeaderText = "Консерва";
|
||||
ColumnCannedName.MinimumWidth = 6;
|
||||
ColumnCannedName.Name = "ColumnCannedName";
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
ColumnCount.HeaderText = "Количество";
|
||||
ColumnCount.MinimumWidth = 6;
|
||||
ColumnCount.Name = "ColumnCount";
|
||||
ColumnCount.Width = 125;
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(202, 15);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(147, 20);
|
||||
labelName.TabIndex = 4;
|
||||
labelName.Text = "Название магазина";
|
||||
//
|
||||
// labelAddress
|
||||
//
|
||||
labelAddress.AutoSize = true;
|
||||
labelAddress.Location = new Point(202, 60);
|
||||
labelAddress.Name = "labelAddress";
|
||||
labelAddress.Size = new Size(51, 20);
|
||||
labelAddress.TabIndex = 5;
|
||||
labelAddress.Text = "Адрес";
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(202, 105);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(110, 20);
|
||||
labelDate.TabIndex = 6;
|
||||
labelDate.Text = "Дата открытия";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(415, 506);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 7;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(554, 506);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 8;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
numericUpDownCount.Location = new Point(394, 148);
|
||||
numericUpDownCount.Maximum = new decimal(new int[] { 500, 0, 0, 0 });
|
||||
numericUpDownCount.Name = "numericUpDownCount";
|
||||
numericUpDownCount.Size = new Size(277, 27);
|
||||
numericUpDownCount.TabIndex = 9;
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(202, 150);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(170, 20);
|
||||
labelCount.TabIndex = 10;
|
||||
labelCount.Text = "Вместимость магазина";
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(683, 547);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(numericUpDownCount);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(labelAddress);
|
||||
Controls.Add(labelName);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(dateTimePicker);
|
||||
Controls.Add(textBoxAddress);
|
||||
Controls.Add(textBoxShop);
|
||||
Name = "FormShop";
|
||||
Text = "Создание магазина";
|
||||
Load += FormShop_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxShop;
|
||||
private TextBox textBoxAddress;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private DataGridView dataGridView;
|
||||
private Label labelName;
|
||||
private Label labelAddress;
|
||||
private Label labelDate;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private DataGridViewTextBoxColumn ColumnId;
|
||||
private DataGridViewTextBoxColumn ColumnCannedName;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
}
|
||||
private TextBox textBoxShop;
|
||||
private TextBox textBoxAddress;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private DataGridView dataGridView;
|
||||
private Label labelName;
|
||||
private Label labelAddress;
|
||||
private Label labelDate;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private DataGridViewTextBoxColumn ColumnId;
|
||||
private DataGridViewTextBoxColumn ColumnCannedName;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private NumericUpDown numericUpDownCount;
|
||||
private Label labelCount;
|
||||
}
|
||||
}
|
@ -15,116 +15,118 @@ using System.Windows.Forms;
|
||||
|
||||
namespace FishFactoryView
|
||||
{
|
||||
public partial class FormShop : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
private int? _id;
|
||||
private Dictionary<int, (ICannedModel, int)> _shopListCanned;
|
||||
public int Id { set { _id = value; } }
|
||||
public partial class FormShop : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
private int? _id;
|
||||
private Dictionary<int, (ICannedModel, int)> _shopListCanned;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_shopListCanned = new();
|
||||
}
|
||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_shopListCanned = new();
|
||||
}
|
||||
|
||||
private void FormShop_Load(object sender, EventArgs e)
|
||||
{
|
||||
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)
|
||||
{
|
||||
textBoxShop.Text = view.ShopName;
|
||||
textBoxAddress.Text = view.Address;
|
||||
dateTimePicker.Text = view.DateOpening.ToString();
|
||||
_shopListCanned = view.ListCanned ?? new Dictionary<int, (ICannedModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка магазина");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new ShopSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxShop.Text = view.ShopName;
|
||||
textBoxAddress.Text = view.Address;
|
||||
dateTimePicker.Text = view.DateOpening.ToString();
|
||||
numericUpDownCount.Value = view.MaxCountCanned;
|
||||
_shopListCanned = view.ListCanned ?? new Dictionary<int, (ICannedModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка консервы магазина");
|
||||
try
|
||||
{
|
||||
if (_shopListCanned != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var elem in _shopListCanned)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.CannedName, elem.Value.Item2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки консерв магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка консервы магазина");
|
||||
try
|
||||
{
|
||||
if (_shopListCanned != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var elem in _shopListCanned)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.CannedName, elem.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(textBoxShop.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ShopName = textBoxShop.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpening = dateTimePicker.Value.Date,
|
||||
ListCanned = _shopListCanned
|
||||
};
|
||||
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(textBoxShop.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ShopName = textBoxShop.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpening = dateTimePicker.Value.Date,
|
||||
MaxCountCanned = (int)numericUpDownCount.Value,
|
||||
ListCanned = _shopListCanned
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
FishFactory/FishFactoryView/MainForm.Designer.cs
generated
19
FishFactory/FishFactoryView/MainForm.Designer.cs
generated
@ -40,6 +40,7 @@
|
||||
консервыToolStripMenuItem = new ToolStripMenuItem();
|
||||
ShopsToolStripMenuItem = new ToolStripMenuItem();
|
||||
ButtonAddCannedInShop = new Button();
|
||||
buttonSellCanned = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
@ -124,21 +125,21 @@
|
||||
// компонентыToolStripMenuItem
|
||||
//
|
||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||
компонентыToolStripMenuItem.Size = new Size(224, 26);
|
||||
компонентыToolStripMenuItem.Size = new Size(182, 26);
|
||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||
компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
|
||||
//
|
||||
// консервыToolStripMenuItem
|
||||
//
|
||||
консервыToolStripMenuItem.Name = "консервыToolStripMenuItem";
|
||||
консервыToolStripMenuItem.Size = new Size(224, 26);
|
||||
консервыToolStripMenuItem.Size = new Size(182, 26);
|
||||
консервыToolStripMenuItem.Text = "Консервы";
|
||||
консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click;
|
||||
//
|
||||
// ShopsToolStripMenuItem
|
||||
//
|
||||
ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem";
|
||||
ShopsToolStripMenuItem.Size = new Size(224, 26);
|
||||
ShopsToolStripMenuItem.Size = new Size(182, 26);
|
||||
ShopsToolStripMenuItem.Text = "Магазины";
|
||||
ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
|
||||
//
|
||||
@ -152,11 +153,22 @@
|
||||
ButtonAddCannedInShop.UseVisualStyleBackColor = true;
|
||||
ButtonAddCannedInShop.Click += ButtonAddCannedInShop_Click;
|
||||
//
|
||||
// buttonSellCanned
|
||||
//
|
||||
buttonSellCanned.Location = new Point(885, 434);
|
||||
buttonSellCanned.Name = "buttonSellCanned";
|
||||
buttonSellCanned.Size = new Size(179, 29);
|
||||
buttonSellCanned.TabIndex = 9;
|
||||
buttonSellCanned.Text = "Продать консервы";
|
||||
buttonSellCanned.UseVisualStyleBackColor = true;
|
||||
buttonSellCanned.Click += buttonSellCanned_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1076, 487);
|
||||
Controls.Add(buttonSellCanned);
|
||||
Controls.Add(ButtonAddCannedInShop);
|
||||
Controls.Add(button5);
|
||||
Controls.Add(button4);
|
||||
@ -189,5 +201,6 @@
|
||||
private ToolStripMenuItem консервыToolStripMenuItem;
|
||||
private ToolStripMenuItem ShopsToolStripMenuItem;
|
||||
private Button ButtonAddCannedInShop;
|
||||
private Button buttonSellCanned;
|
||||
}
|
||||
}
|
@ -174,5 +174,14 @@ MessageBoxIcon.Error);
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void buttonSellCanned_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellCanned));
|
||||
if (service is FormSellCanned form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using FishFactoryBusinessLogic.BusinessLogics;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryListImplement.Implements;
|
||||
using FishFactoryFileImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
@ -52,6 +52,7 @@ namespace FishFactoryView
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShopCanned>();
|
||||
services.AddTransient<FormSellCanned>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user