ПИбд-23 Волков Никита Андреевич Лабораторная работа №2 Усложненная #7
@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32825.248
|
VisualStudioVersion = 17.3.32825.248
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "СomputersShopDataModels", "СomputersShopDataModels\СomputersShopDataModels.csproj", "{325A0EEC-AE7D-49D4-9441-4B390F3D47AC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "СomputersShopDataModels", "СomputersShopDataModels\СomputersShopDataModels.csproj", "{325A0EEC-AE7D-49D4-9441-4B390F3D47AC}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopContracts", "ComputersShopContracts\ComputersShopContracts.csproj", "{36B9AA43-8BA7-49B0-845C-2CAE5715670C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopContracts", "ComputersShopContracts\ComputersShopContracts.csproj", "{36B9AA43-8BA7-49B0-845C-2CAE5715670C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopBusinessLogic", "ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj", "{CDFC655D-B1F8-4D87-9400-A0847FCAEAC6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopBusinessLogic", "ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj", "{CDFC655D-B1F8-4D87-9400-A0847FCAEAC6}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopListImplement", "ComputersShopListImplement\ComputersShopListImplement.csproj", "{35DC2893-12C1-417B-9B92-5A18997B47A6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopListImplement", "ComputersShopListImplement\ComputersShopListImplement.csproj", "{35DC2893-12C1-417B-9B92-5A18997B47A6}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopView", "ComputersShopView\ComputersShopView.csproj", "{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopView", "ComputersShopView\ComputersShopView.csproj", "{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopFileImplement", "ComputersShopFileImplement\ComputersShopFileImplement.csproj", "{58BB53D3-F224-451F-B9BD-D1D67ACE7F23}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B0416A4B-CD04-4991-BC00-7FCFC9DEEF73}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{58BB53D3-F224-451F-B9BD-D1D67ACE7F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{58BB53D3-F224-451F-B9BD-D1D67ACE7F23}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{58BB53D3-F224-451F-B9BD-D1D67ACE7F23}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{58BB53D3-F224-451F-B9BD-D1D67ACE7F23}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -17,10 +17,14 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IComputerStorage _computerStorage;
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IComputerStorage computerStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerStorage = computerStorage;
|
||||||
}
|
}
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -52,7 +56,20 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
var computer = _computerStorage.GetElement(new() { Id = viewModel.ComputerId });
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(computer));
|
||||||
|
}
|
||||||
|
if (!_shopLogic.AddComputers(computer, viewModel.Count))
|
||||||
|
{
|
||||||
|
throw new Exception($"AddComputers operation failed - нет места");
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
model.DateImplement = viewModel.DateImplement;
|
model.DateImplement = viewModel.DateImplement;
|
||||||
@ -61,7 +78,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
if (_orderStorage.Update(model) == null)
|
if (_orderStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
model.Status--;
|
model.Status--;
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Change status operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -31,7 +32,8 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
if (quantity <= 0)
|
if (quantity <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
|
return false;
|
||||||
|
throw new ArgumentException("Количество добавляемого компьютера должно быть больше 0", nameof(quantity));
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("AddComputerInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
_logger.LogInformation("AddComputerInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
||||||
@ -43,7 +45,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("AddComputerInShop find. Id:{Id}", element.Id);
|
if (element.Capacity - element.Computers.Select(x => x.Value.Item2).Sum() < quantity)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("В магазине не хватает места", nameof(quantity));
|
||||||
|
}
|
||||||
|
|
||||||
if (element.Computers.TryGetValue(computer.Id, out var pair))
|
if (element.Computers.TryGetValue(computer.Id, out var pair))
|
||||||
{
|
{
|
||||||
@ -62,11 +67,63 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
ShopAddress = element.ShopAddress,
|
ShopAddress = element.ShopAddress,
|
||||||
ShopName = element.ShopName,
|
ShopName = element.ShopName,
|
||||||
DateOpening = element.DateOpening,
|
DateOpening = element.DateOpening,
|
||||||
Computers = element.Computers
|
Computers = element.Computers,
|
||||||
|
Capacity = element.Capacity,
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AddComputers(IComputerModel computer, int quantity)
|
||||||
|
{
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(computer));
|
||||||
|
}
|
||||||
|
if (quantity <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Количество компьютеров должно быть больше 0", nameof(quantity));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("AddComputers. ShopName:{ShopName}. Id:{Id}", computer.ComputerName, computer.Id);
|
||||||
|
var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.Computers.Select(x => x.Value.Item2).Sum()).Sum();
|
||||||
|
if (allFreeQuantity < quantity)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
int freeQuantity = shop.Capacity - shop.Computers.Select(x => x.Value.Item2).Sum();
|
||||||
|
if (freeQuantity <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freeQuantity < quantity)
|
||||||
|
{
|
||||||
|
if (!AddComputer(new() { Id = shop.Id }, computer, freeQuantity))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
quantity -= freeQuantity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!AddComputer(new() { Id = shop.Id }, computer, quantity))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
quantity = 0;
|
||||||
|
}
|
||||||
|
if (quantity == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Create(ShopBindingModel model)
|
public bool Create(ShopBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -131,6 +188,11 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SellComputers(IComputerModel computer, int quantity)
|
||||||
|
{
|
||||||
|
return _shopStorage.SellComputers(computer, quantity);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Update(ShopBindingModel model)
|
public bool Update(ShopBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
|
@ -14,5 +14,6 @@ namespace ComputersShopContracts.BindingModels
|
|||||||
public string ShopAddress { get; set; } = string.Empty;
|
public string ShopAddress { get; set; } = string.Empty;
|
||||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||||
public Dictionary<int, (IComputerModel, int)> Computers { get; set; } = new();
|
public Dictionary<int, (IComputerModel, int)> Computers { get; set; } = new();
|
||||||
|
public int Capacity { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,5 +18,7 @@ namespace ComputersShopContracts.BusinessLogicContracts
|
|||||||
bool Update(ShopBindingModel model);
|
bool Update(ShopBindingModel model);
|
||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
bool AddComputer(ShopSearchModel model, IComputerModel computer, int quantity);
|
bool AddComputer(ShopSearchModel model, IComputerModel computer, int quantity);
|
||||||
|
bool AddComputers(IComputerModel computer, int quantity);
|
||||||
|
bool SellComputers(IComputerModel computer, int quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
using ComputersShopContracts.BindingModels;
|
using ComputersShopContracts.BindingModels;
|
||||||
using ComputersShopContracts.SearchModels;
|
using ComputersShopContracts.SearchModels;
|
||||||
using ComputersShopContracts.ViewModels;
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -17,5 +18,6 @@ namespace ComputersShopContracts.StoragesContracts
|
|||||||
ShopViewModel? Insert(ShopBindingModel model);
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
bool SellComputers(IComputerModel model, int quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,5 +19,7 @@ namespace ComputersShopContracts.ViewModels
|
|||||||
public string ShopAddress { get; set; } = string.Empty;
|
public string ShopAddress { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||||
|
[DisplayName("Вместимость магазина")]
|
||||||
|
public int Capacity { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ComputersShopContracts\ComputersShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\СomputersShopDataModels\СomputersShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,58 @@
|
|||||||
|
using ComputersShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement
|
||||||
|
{
|
||||||
|
public class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string ComputerFileName = "Computer.xml";
|
||||||
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Computer> Computers { get; private set; }
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataFileSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||||
|
public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", 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)!)!;
|
||||||
|
Computers = LoadData(ComputerFileName, "Computer", x => Computer.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)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
return
|
||||||
|
XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||||
|
}
|
||||||
|
return new List<T>();
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.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 element = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Components.Remove(element);
|
||||||
|
source.SaveComponents();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComputerStorage : IComputerStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ComputerStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputerViewModel? GetElement(ComputerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Computers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComputerName) && x.ComputerName == model.ComputerName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ComputerViewModel> GetFilteredList(ComputerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComputerName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Computers.Where(x => x.ComputerName.Contains(model.ComputerName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ComputerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Computers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputerViewModel? Insert(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Computers.Count > 0 ? source.Computers.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newDoc = Computer.Create(model);
|
||||||
|
if (newDoc == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Computers.Add(newDoc);
|
||||||
|
source.SaveComputers();
|
||||||
|
return newDoc.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputerViewModel? Update(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
var document = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (document == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
document.Update(model);
|
||||||
|
source.SaveComputers();
|
||||||
|
return document.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComputerViewModel? Delete(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
var document = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (document == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
document.Update(model);
|
||||||
|
source.SaveComputers();
|
||||||
|
return document.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 GetViewModel(newOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
source.SaveOrders();
|
||||||
|
return GetViewModel(order);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
source.SaveOrders();
|
||||||
|
return GetViewModel(order);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel GetViewModel(Order order)
|
||||||
|
{
|
||||||
|
var viewModel = order.GetViewModel;
|
||||||
|
var comp = source.Computers.FirstOrDefault(comp => comp.Id == order.ComputerId);
|
||||||
|
if (comp != null)
|
||||||
|
{
|
||||||
|
viewModel.ComputerName = comp.ComputerName;
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using ComputersShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
source.Shops.Remove(shop);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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 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 List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops.Select(x => x.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 bool SellComputers(IComputerModel model, int quantity)
|
||||||
|
{
|
||||||
|
int hasCount = source.Shops
|
||||||
|
.SelectMany(x => x.Computers)
|
||||||
|
.Where(pair => pair.Key == model.Id)
|
||||||
|
.Sum(pair => pair.Value.Item2);
|
||||||
|
|
||||||
|
if (hasCount < quantity)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
source.Shops.ForEach(x =>
|
||||||
|
{
|
||||||
|
if (x.Computers.TryGetValue(model.Id, out var pair))
|
||||||
|
{
|
||||||
|
if (quantity >= pair.Item2)
|
||||||
|
{
|
||||||
|
quantity -= pair.Item2;
|
||||||
|
x.Computers[model.Id] = (model, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x.Computers[model.Id] = (model, pair.Item2 - quantity);
|
||||||
|
quantity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
x.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
ShopAddress = x.ShopAddress,
|
||||||
|
Capacity = x.Capacity,
|
||||||
|
DateOpening = x.DateOpening,
|
||||||
|
ShopName = x.ShopName,
|
||||||
|
Computers = x.Computers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
ComputersShop/ComputersShopFileImplement/Models/Component.cs
Normal file
64
ComputersShop/ComputersShopFileImplement/Models/Component.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
public double Cost { get; 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)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
95
ComputersShop/ComputersShopFileImplement/Models/Computer.cs
Normal file
95
ComputersShop/ComputersShopFileImplement/Models/Computer.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Computer : IComputerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ComputerName { 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)>? _ComputerComponents = null;
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_ComputerComponents == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_ComputerComponents = Components.ToDictionary(x => x.Key, y =>
|
||||||
|
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
||||||
|
y.Value));
|
||||||
|
}
|
||||||
|
return _ComputerComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Computer? Create(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Computer()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComputerName = model.ComputerName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.ComputerComponents.ToDictionary(x => x.Key, x
|
||||||
|
=> x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Computer? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Computer()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ComputerName = element.Element("ComputerName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Components =
|
||||||
|
element.Element("ComputerComponents")!.Elements("ComputerComponent")
|
||||||
|
.ToDictionary(x =>
|
||||||
|
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||||
|
Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComputerName = model.ComputerName;
|
||||||
|
Price = model.Price;
|
||||||
|
Components = model.ComputerComponents.ToDictionary(x => x.Key, x =>
|
||||||
|
x.Value.Item2);
|
||||||
|
_ComputerComponents = null;
|
||||||
|
}
|
||||||
|
public ComputerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComputerName = ComputerName,
|
||||||
|
Price = Price,
|
||||||
|
ComputerComponents = ComputerComponents
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Computer",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComputerName", ComputerName),
|
||||||
|
new XElement("Price", Price.ToString()),
|
||||||
|
new XElement("ComputerComponents", Components.Select(x => new XElement("ComputerComponent", new XElement("Key", x.Key), new XElement("Value", x.Value)))
|
||||||
|
|
||||||
|
.ToArray()));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
104
ComputersShop/ComputersShopFileImplement/Models/Order.cs
Normal file
104
ComputersShop/ComputersShopFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Enums;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int ComputerId { get; private set; }
|
||||||
|
|
||||||
|
public int Count { get; private set; }
|
||||||
|
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
|
||||||
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
|
|
||||||
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComputerId = model.ComputerId,
|
||||||
|
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 order = new Order()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value),
|
||||||
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
|
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
||||||
|
};
|
||||||
|
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
||||||
|
|
||||||
|
order.DateImplement = dateImpl;
|
||||||
|
|
||||||
|
if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Status = status;
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComputerId = ComputerId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Order",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComputerId", ComputerId),
|
||||||
|
new XElement("Count", Count.ToString()),
|
||||||
|
new XElement("Sum", Sum.ToString()),
|
||||||
|
new XElement("Status", Status.ToString()),
|
||||||
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
new XElement("DateImplement", DateImplement.ToString()));
|
||||||
|
}
|
||||||
|
}
|
108
ComputersShop/ComputersShopFileImplement/Models/Shop.cs
Normal file
108
ComputersShop/ComputersShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
public string ShopAddress { get; private set; } = string.Empty;
|
||||||
|
public DateTime DateOpening { get; private set; }
|
||||||
|
public int Capacity { get; private set; }
|
||||||
|
public Dictionary<int, int> ComputersCount = new();
|
||||||
|
public Dictionary<int, (IComputerModel, int)>? _computers = null;
|
||||||
|
public Dictionary<int, (IComputerModel, int)> Computers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_computers == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_computers = ComputersCount.ToDictionary(
|
||||||
|
x => x.Key,
|
||||||
|
y => ((source.Computers.FirstOrDefault(z => z.Id == y.Key) as IComputerModel)!,
|
||||||
|
y.Value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _computers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
ShopAddress = model.ShopAddress,
|
||||||
|
DateOpening = model.DateOpening,
|
||||||
|
Capacity = model.Capacity,
|
||||||
|
ComputersCount = model.Computers.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,
|
||||||
|
ShopAddress = element.Element("ShopAddress")!.Value,
|
||||||
|
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||||
|
Capacity = Convert.ToInt32(element.Element("Capacity")!.Value),
|
||||||
|
ComputersCount = element.Element("Computers")!.Elements("Computer")
|
||||||
|
.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;
|
||||||
|
ShopAddress = model.ShopAddress;
|
||||||
|
DateOpening = model.DateOpening;
|
||||||
|
Capacity = model.Capacity;
|
||||||
|
ComputersCount = model.Computers.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_computers = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
ShopAddress = ShopAddress,
|
||||||
|
DateOpening = DateOpening,
|
||||||
|
Capacity = Capacity,
|
||||||
|
Computers = Computers
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("ShopAddress", ShopAddress),
|
||||||
|
new XElement("DateOpening", DateOpening.ToString()),
|
||||||
|
new XElement("Capacity", Capacity.ToString()),
|
||||||
|
new XElement("Computers", ComputersCount.Select(x =>
|
||||||
|
new XElement("Computer",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using ComputersShopContracts.SearchModels;
|
using ComputersShopContracts.SearchModels;
|
||||||
using ComputersShopContracts.StoragesContracts;
|
using ComputersShopContracts.StoragesContracts;
|
||||||
using ComputersShopContracts.ViewModels;
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
using ComputersShopListImplement.Models;
|
using ComputersShopListImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -107,6 +108,11 @@ namespace ComputersShopListImplement.Implements
|
|||||||
return newShop.GetViewModel;
|
return newShop.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SellComputers(IComputerModel model, int quantity)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public ShopViewModel? Update(ShopBindingModel model)
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
{
|
{
|
||||||
foreach (var Shop in _source.Shops)
|
foreach (var Shop in _source.Shops)
|
||||||
|
@ -55,5 +55,7 @@ namespace ComputersShopListImplement.Models
|
|||||||
DateOpening = DateOpening,
|
DateOpening = DateOpening,
|
||||||
Computers = Computers
|
Computers = Computers
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public int Capacity => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj" />
|
<ProjectReference Include="..\ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\ComputersShopContracts\ComputersShopContracts.csproj" />
|
<ProjectReference Include="..\ComputersShopContracts\ComputersShopContracts.csproj" />
|
||||||
<ProjectReference Include="..\ComputersShopListImplement\ComputersShopListImplement.csproj" />
|
<ProjectReference Include="..\ComputersShopFileImplement\ComputersShopFileImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
74
ComputersShop/ComputersShopView/FormMain.Designer.cs
generated
74
ComputersShop/ComputersShopView/FormMain.Designer.cs
generated
@ -29,11 +29,12 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.справочникToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.computerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.computerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.replenishmentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.продатьКомпьютеромToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||||
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||||
@ -47,51 +48,59 @@
|
|||||||
// menuStrip
|
// menuStrip
|
||||||
//
|
//
|
||||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.directoryToolStripMenuItem,
|
this.справочникToolStripMenuItem,
|
||||||
this.replenishmentToolStripMenuItem});
|
this.пополнениеМагазинаToolStripMenuItem,
|
||||||
|
this.продатьКомпьютеромToolStripMenuItem});
|
||||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||||
this.menuStrip.Name = "menuStrip";
|
this.menuStrip.Name = "menuStrip";
|
||||||
this.menuStrip.Size = new System.Drawing.Size(1047, 24);
|
this.menuStrip.Size = new System.Drawing.Size(1047, 24);
|
||||||
this.menuStrip.TabIndex = 0;
|
this.menuStrip.TabIndex = 0;
|
||||||
this.menuStrip.Text = "menuStrip1";
|
this.menuStrip.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
// directoryToolStripMenuItem
|
// справочникToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.справочникToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.computerToolStripMenuItem,
|
this.computerToolStripMenuItem,
|
||||||
this.componentsToolStripMenuItem,
|
this.componentsToolStripMenuItem,
|
||||||
this.shopsToolStripMenuItem});
|
this.магазиныToolStripMenuItem});
|
||||||
this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem";
|
this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem";
|
||||||
this.directoryToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
|
this.справочникToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
|
||||||
this.directoryToolStripMenuItem.Text = "Cправочники";
|
this.справочникToolStripMenuItem.Text = "Справочники";
|
||||||
//
|
//
|
||||||
// computerToolStripMenuItem
|
// computerToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.computerToolStripMenuItem.Name = "computerToolStripMenuItem";
|
this.computerToolStripMenuItem.Name = "computerToolStripMenuItem";
|
||||||
this.computerToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
this.computerToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
this.computerToolStripMenuItem.Text = "Компьютеры";
|
this.computerToolStripMenuItem.Text = "Компьютеры";
|
||||||
this.computerToolStripMenuItem.Click += new System.EventHandler(this.ComputersToolStripMenuItem_Click);
|
this.computerToolStripMenuItem.Click += ComputersToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// componentsToolStripMenuItem
|
// componentsToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
this.componentsToolStripMenuItem.Text = "Компоненты";
|
this.componentsToolStripMenuItem.Text = "Компоненты";
|
||||||
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
|
this.componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// shopsToolStripMenuItem
|
// магазиныToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
|
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
this.shopsToolStripMenuItem.Text = "Магазины";
|
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click);
|
this.магазиныToolStripMenuItem.Click += ShopToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// replenishmentToolStripMenuItem
|
// пополнениеМагазинаToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.replenishmentToolStripMenuItem.Name = "replenishmentToolStripMenuItem";
|
this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
|
||||||
this.replenishmentToolStripMenuItem.Size = new System.Drawing.Size(143, 20);
|
this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(143, 20);
|
||||||
this.replenishmentToolStripMenuItem.Text = "Пополнение магазина";
|
this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||||
this.replenishmentToolStripMenuItem.Click += new System.EventHandler(this.ShopReplenishmentToolStripMenuItem_Click);
|
this.пополнениеМагазинаToolStripMenuItem.Click += shopReplenishmentToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// продатьКомпьютеромToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.продатьКомпьютеромToolStripMenuItem.Name = "продатьКомпьютеромToolStripMenuItem";
|
||||||
|
this.продатьКомпьютеромToolStripMenuItem.Size = new System.Drawing.Size(131, 20);
|
||||||
|
this.продатьКомпьютеромToolStripMenuItem.Text = "Продать компьютер";
|
||||||
|
this.продатьКомпьютеромToolStripMenuItem.Click += ButtonSellComputer_Click;
|
||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
@ -110,7 +119,7 @@
|
|||||||
this.buttonCreateOrder.TabIndex = 2;
|
this.buttonCreateOrder.TabIndex = 2;
|
||||||
this.buttonCreateOrder.Text = "Создать заказ";
|
this.buttonCreateOrder.Text = "Создать заказ";
|
||||||
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
|
this.buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
||||||
//
|
//
|
||||||
// buttonTakeOrderInWork
|
// buttonTakeOrderInWork
|
||||||
//
|
//
|
||||||
@ -120,7 +129,7 @@
|
|||||||
this.buttonTakeOrderInWork.TabIndex = 3;
|
this.buttonTakeOrderInWork.TabIndex = 3;
|
||||||
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||||
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
|
this.buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
||||||
//
|
//
|
||||||
// buttonOrderReady
|
// buttonOrderReady
|
||||||
//
|
//
|
||||||
@ -130,7 +139,7 @@
|
|||||||
this.buttonOrderReady.TabIndex = 4;
|
this.buttonOrderReady.TabIndex = 4;
|
||||||
this.buttonOrderReady.Text = "Заказ готов";
|
this.buttonOrderReady.Text = "Заказ готов";
|
||||||
this.buttonOrderReady.UseVisualStyleBackColor = true;
|
this.buttonOrderReady.UseVisualStyleBackColor = true;
|
||||||
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
|
this.buttonOrderReady.Click += ButtonOrderReady_Click;
|
||||||
//
|
//
|
||||||
// buttonIssuedOrder
|
// buttonIssuedOrder
|
||||||
//
|
//
|
||||||
@ -140,7 +149,7 @@
|
|||||||
this.buttonIssuedOrder.TabIndex = 5;
|
this.buttonIssuedOrder.TabIndex = 5;
|
||||||
this.buttonIssuedOrder.Text = "Заказ выдан";
|
this.buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
|
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||||
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
|
this.buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
||||||
//
|
//
|
||||||
// buttonRef
|
// buttonRef
|
||||||
//
|
//
|
||||||
@ -150,7 +159,7 @@
|
|||||||
this.buttonRef.TabIndex = 6;
|
this.buttonRef.TabIndex = 6;
|
||||||
this.buttonRef.Text = "Обновить список";
|
this.buttonRef.Text = "Обновить список";
|
||||||
this.buttonRef.UseVisualStyleBackColor = true;
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
this.buttonRef.Click += ButtonRef_Click;
|
||||||
//
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
@ -167,7 +176,7 @@
|
|||||||
this.MainMenuStrip = this.menuStrip;
|
this.MainMenuStrip = this.menuStrip;
|
||||||
this.Name = "FormMain";
|
this.Name = "FormMain";
|
||||||
this.Text = "Магазин электроники";
|
this.Text = "Магазин электроники";
|
||||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
Load += FormMain_Load;
|
||||||
this.menuStrip.ResumeLayout(false);
|
this.menuStrip.ResumeLayout(false);
|
||||||
this.menuStrip.PerformLayout();
|
this.menuStrip.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
@ -179,7 +188,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private MenuStrip menuStrip;
|
private MenuStrip menuStrip;
|
||||||
private ToolStripMenuItem directoryToolStripMenuItem;
|
private ToolStripMenuItem справочникToolStripMenuItem;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private Button buttonCreateOrder;
|
private Button buttonCreateOrder;
|
||||||
private Button buttonTakeOrderInWork;
|
private Button buttonTakeOrderInWork;
|
||||||
@ -188,7 +197,8 @@
|
|||||||
private Button buttonRef;
|
private Button buttonRef;
|
||||||
private ToolStripMenuItem computerToolStripMenuItem;
|
private ToolStripMenuItem computerToolStripMenuItem;
|
||||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||||
private ToolStripMenuItem replenishmentToolStripMenuItem;
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
private ToolStripMenuItem shopsToolStripMenuItem;
|
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem продатьКомпьютеромToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,6 +68,7 @@ namespace ComputersShopView
|
|||||||
private void ShopToolStripMenuItem_Click(object sender, EventArgs e)
|
private void ShopToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||||
|
|
||||||
if (service is FormShops form)
|
if (service is FormShops form)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
@ -177,13 +178,25 @@ namespace ComputersShopView
|
|||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
private void ShopReplenishmentToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
|
private void shopReplenishmentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment));
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment));
|
||||||
|
|
||||||
if (service is FormShopReplenishment form)
|
if (service is FormShopReplenishment form)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSellComputer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormSellComputers));
|
||||||
|
if (service is FormSellComputers form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
124
ComputersShop/ComputersShopView/FormSellComputers.Designer.cs
generated
Normal file
124
ComputersShop/ComputersShopView/FormSellComputers.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
partial class FormSellComputers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
ButtonCancel = new Button();
|
||||||
|
comboBoxDocuments = new ComboBox();
|
||||||
|
numericUpDownCount = new NumericUpDown();
|
||||||
|
labelDocument = new Label();
|
||||||
|
labelCount = new Label();
|
||||||
|
ButtonSave = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
ButtonCancel.Location = new Point(233, 60);
|
||||||
|
ButtonCancel.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonCancel.Name = "ButtonCancel";
|
||||||
|
ButtonCancel.Size = new Size(82, 22);
|
||||||
|
ButtonCancel.TabIndex = 1;
|
||||||
|
ButtonCancel.Text = "Отмена";
|
||||||
|
ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// comboBoxDocuments
|
||||||
|
//
|
||||||
|
comboBoxDocuments.FormattingEnabled = true;
|
||||||
|
comboBoxDocuments.Location = new Point(89, 6);
|
||||||
|
comboBoxDocuments.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
comboBoxDocuments.Name = "comboBoxDocuments";
|
||||||
|
comboBoxDocuments.Size = new Size(226, 23);
|
||||||
|
comboBoxDocuments.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// numericUpDownCount
|
||||||
|
//
|
||||||
|
numericUpDownCount.Location = new Point(90, 33);
|
||||||
|
numericUpDownCount.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
numericUpDownCount.Name = "numericUpDownCount";
|
||||||
|
numericUpDownCount.Size = new Size(225, 23);
|
||||||
|
numericUpDownCount.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelDocument
|
||||||
|
//
|
||||||
|
labelDocument.AutoSize = true;
|
||||||
|
labelDocument.Location = new Point(12, 9);
|
||||||
|
labelDocument.Name = "labelDocument";
|
||||||
|
labelDocument.Size = new Size(71, 15);
|
||||||
|
labelDocument.TabIndex = 4;
|
||||||
|
labelDocument.Text = "Компьютер";
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
labelCount.AutoSize = true;
|
||||||
|
labelCount.Location = new Point(11, 35);
|
||||||
|
labelCount.Name = "labelCount";
|
||||||
|
labelCount.Size = new Size(72, 15);
|
||||||
|
labelCount.TabIndex = 5;
|
||||||
|
labelCount.Text = "Количество";
|
||||||
|
//
|
||||||
|
// ButtonSave
|
||||||
|
//
|
||||||
|
ButtonSave.Location = new Point(145, 60);
|
||||||
|
ButtonSave.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonSave.Name = "ButtonSave";
|
||||||
|
ButtonSave.Size = new Size(82, 22);
|
||||||
|
ButtonSave.TabIndex = 6;
|
||||||
|
ButtonSave.Text = "Сохранить";
|
||||||
|
ButtonSave.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSave.Click += ButtonSave_Click;
|
||||||
|
//
|
||||||
|
// FormSellComputers
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(326, 93);
|
||||||
|
Controls.Add(ButtonSave);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(labelDocument);
|
||||||
|
Controls.Add(numericUpDownCount);
|
||||||
|
Controls.Add(comboBoxDocuments);
|
||||||
|
Controls.Add(ButtonCancel);
|
||||||
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
|
Name = "FormSellComputers";
|
||||||
|
Text = "Продажа компьютеров";
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private ComboBox comboBoxDocuments;
|
||||||
|
private NumericUpDown numericUpDownCount;
|
||||||
|
private Label labelDocument;
|
||||||
|
private Label labelCount;
|
||||||
|
private Button ButtonSave;
|
||||||
|
}
|
||||||
|
}
|
86
ComputersShop/ComputersShopView/FormSellComputers.cs
Normal file
86
ComputersShop/ComputersShopView/FormSellComputers.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
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 ComputersShopView
|
||||||
|
{
|
||||||
|
public partial class FormSellComputers : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IComputerLogic _computerLogic;
|
||||||
|
private readonly List<ComputerViewModel>? _listComputer;
|
||||||
|
public FormSellComputers(ILogger<FormSellComputers> logger, IShopLogic shopLogic, IComputerLogic computerLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerLogic = computerLogic;
|
||||||
|
_listComputer = computerLogic.ReadList(null);
|
||||||
|
if (_listComputer != null)
|
||||||
|
{
|
||||||
|
comboBoxDocuments.DisplayMember = "ComputerName";
|
||||||
|
comboBoxDocuments.ValueMember = "Id";
|
||||||
|
comboBoxDocuments.DataSource = _listComputer;
|
||||||
|
comboBoxDocuments.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxDocuments.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(numericUpDownCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Продажа поездок");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var comp = _computerLogic.ReadElement(new()
|
||||||
|
{
|
||||||
|
Id = (int)comboBoxDocuments.SelectedValue
|
||||||
|
});
|
||||||
|
if (comp == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Компьютер не найден. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
var operationResult = _shopLogic.SellComputers(
|
||||||
|
computer: comp,
|
||||||
|
quantity: (int)numericUpDownCount.Value
|
||||||
|
);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/ComputersShopView/FormSellComputers.resx
Normal file
60
ComputersShop/ComputersShopView/FormSellComputers.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
329
ComputersShop/ComputersShopView/FormShop.Designer.cs
generated
329
ComputersShop/ComputersShopView/FormShop.Designer.cs
generated
@ -28,182 +28,195 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
|
labelShop = new Label();
|
||||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
labelAddress = new Label();
|
||||||
this.textBoxAddress = new System.Windows.Forms.TextBox();
|
labelDate = new Label();
|
||||||
this.labelTime = new System.Windows.Forms.Label();
|
textBoxName = new TextBox();
|
||||||
this.labelAddress = new System.Windows.Forms.Label();
|
textBoxAddress = new TextBox();
|
||||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
dateTimePicker = new DateTimePicker();
|
||||||
this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
dataGridView = new DataGridView();
|
||||||
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
ButtonSave = new Button();
|
||||||
this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
ButtonCancel = new Button();
|
||||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
numericUpDownCapacity = new NumericUpDown();
|
||||||
this.labelShop = new System.Windows.Forms.Label();
|
labelCapacity = new Label();
|
||||||
this.buttonSave = new System.Windows.Forms.Button();
|
ID = new DataGridViewTextBoxColumn();
|
||||||
this.buttonCancel = new System.Windows.Forms.Button();
|
DocumentName = new DataGridViewTextBoxColumn();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
Price = new DataGridViewTextBoxColumn();
|
||||||
this.SuspendLayout();
|
Count = new DataGridViewTextBoxColumn();
|
||||||
//
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
// dateTimePicker
|
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit();
|
||||||
//
|
SuspendLayout();
|
||||||
this.dateTimePicker.Location = new System.Drawing.Point(384, 27);
|
|
||||||
this.dateTimePicker.Name = "dateTimePicker";
|
|
||||||
this.dateTimePicker.Size = new System.Drawing.Size(207, 23);
|
|
||||||
this.dateTimePicker.TabIndex = 26;
|
|
||||||
//
|
|
||||||
// textBoxName
|
|
||||||
//
|
|
||||||
this.textBoxName.Location = new System.Drawing.Point(10, 27);
|
|
||||||
this.textBoxName.Name = "textBoxName";
|
|
||||||
this.textBoxName.Size = new System.Drawing.Size(141, 23);
|
|
||||||
this.textBoxName.TabIndex = 25;
|
|
||||||
//
|
|
||||||
// textBoxAddress
|
|
||||||
//
|
|
||||||
this.textBoxAddress.Location = new System.Drawing.Point(158, 27);
|
|
||||||
this.textBoxAddress.Name = "textBoxAddress";
|
|
||||||
this.textBoxAddress.Size = new System.Drawing.Size(221, 23);
|
|
||||||
this.textBoxAddress.TabIndex = 24;
|
|
||||||
//
|
|
||||||
// labelTime
|
|
||||||
//
|
|
||||||
this.labelTime.AutoSize = true;
|
|
||||||
this.labelTime.Location = new System.Drawing.Point(384, 9);
|
|
||||||
this.labelTime.Name = "labelTime";
|
|
||||||
this.labelTime.Size = new System.Drawing.Size(87, 15);
|
|
||||||
this.labelTime.TabIndex = 23;
|
|
||||||
this.labelTime.Text = "Дата открытия";
|
|
||||||
//
|
|
||||||
// labelAddress
|
|
||||||
//
|
|
||||||
this.labelAddress.AutoSize = true;
|
|
||||||
this.labelAddress.Location = new System.Drawing.Point(158, 9);
|
|
||||||
this.labelAddress.Name = "labelAddress";
|
|
||||||
this.labelAddress.Size = new System.Drawing.Size(40, 15);
|
|
||||||
this.labelAddress.TabIndex = 22;
|
|
||||||
this.labelAddress.Text = "Адрес";
|
|
||||||
//
|
|
||||||
// dataGridView
|
|
||||||
//
|
|
||||||
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
||||||
| System.Windows.Forms.AnchorStyles.Left)
|
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
|
||||||
this.ColumnID,
|
|
||||||
this.ColumnManufactureName,
|
|
||||||
this.Price,
|
|
||||||
this.ColumnCount});
|
|
||||||
this.dataGridView.Location = new System.Drawing.Point(10, 56);
|
|
||||||
this.dataGridView.Name = "dataGridView";
|
|
||||||
this.dataGridView.RowHeadersWidth = 62;
|
|
||||||
this.dataGridView.RowTemplate.Height = 25;
|
|
||||||
this.dataGridView.Size = new System.Drawing.Size(581, 327);
|
|
||||||
this.dataGridView.TabIndex = 21;
|
|
||||||
//
|
|
||||||
// ColumnID
|
|
||||||
//
|
|
||||||
this.ColumnID.HeaderText = "ID";
|
|
||||||
this.ColumnID.MinimumWidth = 8;
|
|
||||||
this.ColumnID.Name = "ColumnID";
|
|
||||||
this.ColumnID.Visible = false;
|
|
||||||
this.ColumnID.Width = 150;
|
|
||||||
//
|
|
||||||
// ColumnManufactureName
|
|
||||||
//
|
|
||||||
this.ColumnManufactureName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
this.ColumnManufactureName.HeaderText = "Название компьютера";
|
|
||||||
this.ColumnManufactureName.MinimumWidth = 8;
|
|
||||||
this.ColumnManufactureName.Name = "ColumnManufactureName";
|
|
||||||
//
|
|
||||||
// Price
|
|
||||||
//
|
|
||||||
this.Price.HeaderText = "Цена";
|
|
||||||
this.Price.MinimumWidth = 6;
|
|
||||||
this.Price.Name = "Price";
|
|
||||||
this.Price.Width = 125;
|
|
||||||
//
|
|
||||||
// ColumnCount
|
|
||||||
//
|
|
||||||
this.ColumnCount.HeaderText = "Количество";
|
|
||||||
this.ColumnCount.MinimumWidth = 8;
|
|
||||||
this.ColumnCount.Name = "ColumnCount";
|
|
||||||
this.ColumnCount.Width = 150;
|
|
||||||
//
|
//
|
||||||
// labelShop
|
// labelShop
|
||||||
//
|
//
|
||||||
this.labelShop.AutoSize = true;
|
labelShop.AutoSize = true;
|
||||||
this.labelShop.Location = new System.Drawing.Point(10, 9);
|
labelShop.Location = new Point(10, 16);
|
||||||
this.labelShop.Name = "labelShop";
|
labelShop.Name = "labelShop";
|
||||||
this.labelShop.Size = new System.Drawing.Size(54, 15);
|
labelShop.Size = new Size(54, 15);
|
||||||
this.labelShop.TabIndex = 20;
|
labelShop.TabIndex = 0;
|
||||||
this.labelShop.Text = "Магазин";
|
labelShop.Text = "Магазин";
|
||||||
//
|
//
|
||||||
// buttonSave
|
// labelAddress
|
||||||
//
|
//
|
||||||
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
labelAddress.AutoSize = true;
|
||||||
this.buttonSave.Location = new System.Drawing.Point(363, 392);
|
labelAddress.Location = new Point(156, 16);
|
||||||
this.buttonSave.Name = "buttonSave";
|
labelAddress.Name = "labelAddress";
|
||||||
this.buttonSave.Size = new System.Drawing.Size(120, 22);
|
labelAddress.Size = new Size(40, 15);
|
||||||
this.buttonSave.TabIndex = 28;
|
labelAddress.TabIndex = 1;
|
||||||
this.buttonSave.Text = "Сохранить";
|
labelAddress.Text = "Адрес";
|
||||||
this.buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// labelDate
|
||||||
//
|
//
|
||||||
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
labelDate.AutoSize = true;
|
||||||
this.buttonCancel.Location = new System.Drawing.Point(488, 392);
|
labelDate.Location = new Point(375, 16);
|
||||||
this.buttonCancel.Name = "buttonCancel";
|
labelDate.Name = "labelDate";
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(103, 22);
|
labelDate.Size = new Size(87, 15);
|
||||||
this.buttonCancel.TabIndex = 27;
|
labelDate.TabIndex = 2;
|
||||||
this.buttonCancel.Text = "Отмена";
|
labelDate.Text = "Дата открытия";
|
||||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
//
|
||||||
this.buttonCancel.Click += ButtonCancel_Click;
|
// 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(156, 33);
|
||||||
|
textBoxAddress.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxAddress.Name = "textBoxAddress";
|
||||||
|
textBoxAddress.Size = new Size(216, 23);
|
||||||
|
textBoxAddress.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// dateTimePicker
|
||||||
|
//
|
||||||
|
dateTimePicker.Location = new Point(375, 33);
|
||||||
|
dateTimePicker.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
dateTimePicker.Name = "dateTimePicker";
|
||||||
|
dateTimePicker.Size = new Size(123, 23);
|
||||||
|
dateTimePicker.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, DocumentName, Price, Count });
|
||||||
|
dataGridView.Location = new Point(10, 58);
|
||||||
|
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;
|
||||||
|
//
|
||||||
|
// ButtonSave
|
||||||
|
//
|
||||||
|
ButtonSave.Location = new Point(429, 310);
|
||||||
|
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, 310);
|
||||||
|
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;
|
||||||
|
//
|
||||||
|
// numericUpDownCapacity
|
||||||
|
//
|
||||||
|
numericUpDownCapacity.Location = new Point(513, 33);
|
||||||
|
numericUpDownCapacity.Name = "numericUpDownCapacity";
|
||||||
|
numericUpDownCapacity.Size = new Size(120, 23);
|
||||||
|
numericUpDownCapacity.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// labelCapacity
|
||||||
|
//
|
||||||
|
labelCapacity.AutoSize = true;
|
||||||
|
labelCapacity.Location = new Point(513, 16);
|
||||||
|
labelCapacity.Name = "labelCapacity";
|
||||||
|
labelCapacity.Size = new Size(80, 15);
|
||||||
|
labelCapacity.TabIndex = 10;
|
||||||
|
labelCapacity.Text = "Вместимость";
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
ID.HeaderText = "ID";
|
||||||
|
ID.MinimumWidth = 6;
|
||||||
|
ID.Name = "ID";
|
||||||
|
ID.Visible = false;
|
||||||
|
//
|
||||||
|
// DocumentName
|
||||||
|
//
|
||||||
|
DocumentName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DocumentName.HeaderText = "Название компьютера";
|
||||||
|
DocumentName.MinimumWidth = 6;
|
||||||
|
DocumentName.Name = "DocumentName";
|
||||||
|
//
|
||||||
|
// Price
|
||||||
|
//
|
||||||
|
Price.HeaderText = "Стоимость";
|
||||||
|
Price.Name = "Price";
|
||||||
|
//
|
||||||
|
// Count
|
||||||
|
//
|
||||||
|
Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
Count.HeaderText = "Количество";
|
||||||
|
Count.MinimumWidth = 6;
|
||||||
|
Count.Name = "Count";
|
||||||
//
|
//
|
||||||
// FormShop
|
// FormShop
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(616, 425);
|
ClientSize = new Size(648, 338);
|
||||||
this.Controls.Add(this.buttonSave);
|
Controls.Add(labelCapacity);
|
||||||
this.Controls.Add(this.buttonCancel);
|
Controls.Add(numericUpDownCapacity);
|
||||||
this.Controls.Add(this.dateTimePicker);
|
Controls.Add(ButtonCancel);
|
||||||
this.Controls.Add(this.textBoxName);
|
Controls.Add(ButtonSave);
|
||||||
this.Controls.Add(this.textBoxAddress);
|
Controls.Add(dataGridView);
|
||||||
this.Controls.Add(this.labelTime);
|
Controls.Add(dateTimePicker);
|
||||||
this.Controls.Add(this.labelAddress);
|
Controls.Add(textBoxAddress);
|
||||||
this.Controls.Add(this.dataGridView);
|
Controls.Add(textBoxName);
|
||||||
this.Controls.Add(this.labelShop);
|
Controls.Add(labelDate);
|
||||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
Controls.Add(labelAddress);
|
||||||
this.Name = "FormShop";
|
Controls.Add(labelShop);
|
||||||
this.Text = "Магазин";
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
|
Name = "FormShop";
|
||||||
|
Text = "Магазин";
|
||||||
Load += FormShop_Load;
|
Load += FormShop_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
this.ResumeLayout(false);
|
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit();
|
||||||
this.PerformLayout();
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonCancel_Click1(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private DateTimePicker dateTimePicker;
|
private Label labelShop;
|
||||||
|
private Label labelAddress;
|
||||||
|
private Label labelDate;
|
||||||
private TextBox textBoxName;
|
private TextBox textBoxName;
|
||||||
private TextBox textBoxAddress;
|
private TextBox textBoxAddress;
|
||||||
private Label labelTime;
|
private DateTimePicker dateTimePicker;
|
||||||
private Label labelAddress;
|
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private Label labelShop;
|
private Button ButtonSave;
|
||||||
private Button buttonSave;
|
private Button ButtonCancel;
|
||||||
private Button buttonCancel;
|
private NumericUpDown numericUpDownCapacity;
|
||||||
private DataGridViewTextBoxColumn ColumnID;
|
private Label labelCapacity;
|
||||||
private DataGridViewTextBoxColumn ColumnManufactureName;
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn DocumentName;
|
||||||
private DataGridViewTextBoxColumn Price;
|
private DataGridViewTextBoxColumn Price;
|
||||||
private DataGridViewTextBoxColumn ColumnCount;
|
private DataGridViewTextBoxColumn Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,6 +46,7 @@ namespace ComputersShopView
|
|||||||
textBoxName.Text = view.ShopName;
|
textBoxName.Text = view.ShopName;
|
||||||
textBoxAddress.Text = view.ShopAddress.ToString();
|
textBoxAddress.Text = view.ShopAddress.ToString();
|
||||||
dateTimePicker.Text = view.DateOpening.ToString();
|
dateTimePicker.Text = view.DateOpening.ToString();
|
||||||
|
numericUpDownCapacity.Value = view.Capacity;
|
||||||
_shopComputers = view.Computers ?? new Dictionary<int, (IComputerModel, int)>();
|
_shopComputers = view.Computers ?? new Dictionary<int, (IComputerModel, int)>();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ namespace ComputersShopView
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Сохранение магазина");
|
_logger.LogInformation("Сохранение магазина");
|
||||||
@ -100,6 +101,7 @@ namespace ComputersShopView
|
|||||||
ShopName = textBoxName.Text,
|
ShopName = textBoxName.Text,
|
||||||
ShopAddress = textBoxAddress.Text,
|
ShopAddress = textBoxAddress.Text,
|
||||||
DateOpening = dateTimePicker.Value.Date,
|
DateOpening = dateTimePicker.Value.Date,
|
||||||
|
Capacity = (int)numericUpDownCapacity.Value,
|
||||||
Computers = _shopComputers
|
Computers = _shopComputers
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
|
@ -57,4 +57,7 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -1,11 +1,11 @@
|
|||||||
using ComputersShopBusinessLogic.BusinessLogics;
|
using ComputersShopBusinessLogic.BusinessLogics;
|
||||||
using ComputersShopContracts.BusinessLogicContracts;
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
using ComputersShopContracts.StoragesContracts;
|
using ComputersShopContracts.StoragesContracts;
|
||||||
using ComputersShopListImplement.Implements;
|
using ComputersShopFileImplement.Implements;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
using OrdersShopListImplement.Implements;
|
|
||||||
|
|
||||||
namespace ComputersShopView
|
namespace ComputersShopView
|
||||||
{
|
{
|
||||||
@ -55,6 +55,7 @@ namespace ComputersShopView
|
|||||||
services.AddTransient<FormShop>();
|
services.AddTransient<FormShop>();
|
||||||
services.AddTransient<FormShops>();
|
services.AddTransient<FormShops>();
|
||||||
services.AddTransient<FormShopReplenishment>();
|
services.AddTransient<FormShopReplenishment>();
|
||||||
|
services.AddTransient<FormSellComputers>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ namespace ComputersShopDataModels.Models
|
|||||||
public string ShopName { get; }
|
public string ShopName { get; }
|
||||||
public string ShopAddress { get; }
|
public string ShopAddress { get; }
|
||||||
DateTime DateOpening { get; }
|
DateTime DateOpening { get; }
|
||||||
|
public int Capacity { get; }
|
||||||
Dictionary<int, (IComputerModel, int)> Computers { get; }
|
Dictionary<int, (IComputerModel, int)> Computers { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user