ПИбд-23 Насыров Артур Газинурович Лабораторная работа №2 #3
159
FlowerShopBusinessLogic/ShopLogic.cs
Normal file
159
FlowerShopBusinessLogic/ShopLogic.cs
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.BusinessLogicsContracts;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopBusinessLogic
|
||||||
|
{
|
||||||
|
public class ShopLogic : IShopLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
|
||||||
|
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> ReadList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, model?.Id);
|
||||||
|
var list = model == null ? _shopStorage.GetFullList() :
|
||||||
|
_shopStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
if (flower == null)
|
||||||
|
throw new ArgumentNullException(nameof(flower));
|
||||||
|
if (count <= 0)
|
||||||
|
throw new ArgumentNullException("Количество должно быть положительным числом");
|
||||||
|
|
||||||
|
var curModel = _shopStorage.GetElement(model);
|
||||||
|
if (curModel == null)
|
||||||
|
throw new ArgumentNullException(nameof(curModel));
|
||||||
|
if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair))
|
||||||
|
{
|
||||||
|
curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curModel.ShopFlowers.Add(flower.Id, (flower, count));
|
||||||
|
}
|
||||||
|
Update(new()
|
||||||
|
{
|
||||||
|
Id = curModel.Id,
|
||||||
|
ShopName = curModel.ShopName,
|
||||||
|
DateOpen = curModel.DateOpen,
|
||||||
|
Address = curModel.Address,
|
||||||
|
ShopFlowers = curModel.ShopFlowers,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel ReadElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_shopStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_shopStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_shopStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия магазина",
|
||||||
|
nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Address))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет адресса магазина",
|
||||||
|
nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
if (model.DateOpen == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет даты открытия магазина",
|
||||||
|
nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Address, model.DateOpen, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||||
|
{
|
||||||
|
Name = model.ShopName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
FlowerShopContracts/BindingModels/ShopBindingModel.cs
Normal file
18
FlowerShopContracts/BindingModels/ShopBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ShopBindingModel : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ShopName { get; set; }
|
||||||
|
public string Address { get; set; }
|
||||||
|
public DateTime DateOpen { get; set; }
|
||||||
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
22
FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
22
FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IShopLogic
|
||||||
|
{
|
||||||
|
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||||
|
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||||
|
bool Create(ShopBindingModel model);
|
||||||
|
bool Update(ShopBindingModel model);
|
||||||
|
bool Delete(ShopBindingModel model);
|
||||||
|
bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count);
|
||||||
|
}
|
||||||
|
}
|
14
FlowerShopContracts/SearchModels/ShopSearchModel.cs
Normal file
14
FlowerShopContracts/SearchModels/ShopSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ShopSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
22
FlowerShopContracts/StoragesContracts/IShopStorage.cs
Normal file
22
FlowerShopContracts/StoragesContracts/IShopStorage.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IShopStorage
|
||||||
|
{
|
||||||
|
List<ShopViewModel> GetFullList();
|
||||||
|
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||||
|
ShopViewModel? GetElement(ShopSearchModel model);
|
||||||
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
22
FlowerShopContracts/ViewModels/ShopViewModel.cs
Normal file
22
FlowerShopContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace FlowerShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ShopViewModel : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название магазина")]
|
||||||
|
public string ShopName { get; set; }
|
||||||
|
[DisplayName("Адрес магазина")]
|
||||||
|
public string Address { get; set; }
|
||||||
|
[DisplayName("Дата открытия")]
|
||||||
|
public DateTime DateOpen { get; set; }
|
||||||
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
16
FlowerShopDataModels/IShopModel.cs
Normal file
16
FlowerShopDataModels/IShopModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IShopModel : IId
|
||||||
|
{
|
||||||
|
string ShopName { get; }
|
||||||
|
string Address { get; }
|
||||||
|
DateTime DateOpen { get; }
|
||||||
|
Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; }
|
||||||
|
}
|
||||||
|
}
|
60
FlowerShopFileImplement/Component.cs
Normal file
60
FlowerShopFileImplement/Component.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.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()));
|
||||||
|
}
|
||||||
|
}
|
92
FlowerShopFileImplement/ComponentStorage.cs
Normal file
92
FlowerShopFileImplement/ComponentStorage.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopFileImplement.Models;
|
||||||
|
using FlowerShopFileImplement.Implements;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
52
FlowerShopFileImplement/DataFileSingleton.cs
Normal file
52
FlowerShopFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using FlowerShopFileImplement.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Implements;
|
||||||
|
|
||||||
|
internal class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string FlowerFileName = "Product.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Flower> Flowers { 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 SaveFlowers() => SaveData(Flowers, FlowerFileName,
|
||||||
|
"Flowers", x => x.GetXElement);
|
||||||
|
public void SaveOrders() => SaveData(Orders, OrderFileName,
|
||||||
|
"Orders", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
|
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!;
|
||||||
|
Orders = LoadData(OrderFileName, "Order", x => Order.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
96
FlowerShopFileImplement/Flower.cs
Normal file
96
FlowerShopFileImplement/Flower.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using FlowerShopFileImplement.Implements;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
namespace FlowerShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Flower : IFlowerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string FlowerName { 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)>? _flowerComponents =
|
||||||
|
null;
|
||||||
|
public Dictionary<int, (IComponentModel, int)> FlowerComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_flowerComponents == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_flowerComponents = Components.ToDictionary(x => x.Key, y =>
|
||||||
|
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
||||||
|
y.Value));
|
||||||
|
}
|
||||||
|
return _flowerComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Flower? Create(FlowerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Flower()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FlowerName = model.FlowerName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.FlowerComponents.ToDictionary(x => x.Key, x
|
||||||
|
=> x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Flower? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Flower()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
FlowerName = element.Element("FlowerName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Components =
|
||||||
|
element.Element("FlowerComponents")!.Elements("FlowerComponent")
|
||||||
|
.ToDictionary(x =>
|
||||||
|
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||||
|
Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(FlowerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FlowerName = model.FlowerName;
|
||||||
|
Price = model.Price;
|
||||||
|
Components = model.FlowerComponents.ToDictionary(x => x.Key, x =>
|
||||||
|
x.Value.Item2);
|
||||||
|
_flowerComponents = null;
|
||||||
|
}
|
||||||
|
public FlowerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
FlowerName = FlowerName,
|
||||||
|
Price = Price,
|
||||||
|
FlowerComponents = FlowerComponents
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Flower",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("FlowerName", FlowerName),
|
||||||
|
new XElement("Price", Price.ToString()),
|
||||||
|
new XElement("FlowerComponents", Components.Select(x =>
|
||||||
|
new XElement("FlowerComponent",
|
||||||
|
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
FlowerShopFileImplement/FlowerShopFileImplement.csproj
Normal file
14
FlowerShopFileImplement/FlowerShopFileImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
94
FlowerShopFileImplement/FlowerStorage.cs
Normal file
94
FlowerShopFileImplement/FlowerStorage.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using FlowerShopFileImplement.Models;
|
||||||
|
using FlowerShopFileImplement.Implements;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class FlowerStorage : IFlowerStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public FlowerStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<FlowerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Flowers
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FlowerViewModel> GetFilteredList(FlowerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FlowerName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Flowers
|
||||||
|
.Where(x => x.FlowerName.Contains(model.FlowerName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlowerViewModel? GetElement(FlowerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FlowerName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Flowers
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.FlowerName) && x.FlowerName ==
|
||||||
|
model.FlowerName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlowerViewModel? Insert(FlowerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Flowers.Count > 0 ? source.Flowers.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newFlower = Flower.Create(model);
|
||||||
|
if (newFlower == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Flowers.Add(newFlower);
|
||||||
|
source.SaveFlowers();
|
||||||
|
return newFlower.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlowerViewModel? Update(FlowerBindingModel model)
|
||||||
|
{
|
||||||
|
var iceCream = source.Flowers.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (iceCream == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
iceCream.Update(model);
|
||||||
|
source.SaveFlowers();
|
||||||
|
return iceCream.GetViewModel;
|
||||||
|
}
|
||||||
|
public FlowerViewModel? Delete(FlowerBindingModel model)
|
||||||
|
{
|
||||||
|
var iceCream = source.Flowers.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (iceCream != null)
|
||||||
|
{
|
||||||
|
source.Flowers.Remove(iceCream);
|
||||||
|
source.SaveFlowers();
|
||||||
|
return iceCream.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
83
FlowerShopFileImplement/Order.cs
Normal file
83
FlowerShopFileImplement/Order.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Enums;
|
||||||
|
using FlowerShopDataModels;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int FlowerId { 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; }
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FlowerId = model.FlowerId,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
FlowerId = Convert.ToInt32(element.Element("FlowerId")!.Value),
|
||||||
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
|
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value.ToString()),
|
||||||
|
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||||
|
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
FlowerId = FlowerId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Order",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("FlowerId", FlowerId),
|
||||||
|
new XElement("Sum", Sum.ToString()),
|
||||||
|
new XElement("Count", Count),
|
||||||
|
new XElement("Status", Status.ToString()),
|
||||||
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
new XElement("DateImplement", DateImplement.ToString())
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
104
FlowerShopFileImplement/OrderStorage.cs
Normal file
104
FlowerShopFileImplement/OrderStorage.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopFileImplement.Models;
|
||||||
|
using FlowerShopFileImplement.Implements;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Orders
|
||||||
|
.Select(x => AccessFlowerStorage(x.GetViewModel))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Orders
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => AccessFlowerStorage(x.GetViewModel))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return AccessFlowerStorage(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 AccessFlowerStorage(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 AccessFlowerStorage(order.GetViewModel);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Orders.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Orders.Remove(element);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AccessFlowerStorage(element.GetViewModel);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel AccessFlowerStorage(OrderViewModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
return null;
|
||||||
|
foreach (var flower in source.Flowers)
|
||||||
|
|||||||
|
{
|
||||||
|
if (flower.Id == model.FlowerId)
|
||||||
|
{
|
||||||
|
model.FlowerName = flower.FlowerName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -13,11 +13,13 @@ namespace FlowerShopListImplement
|
|||||||
public List<Component> Components { get; set; }
|
public List<Component> Components { get; set; }
|
||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Flower> Flowers { get; set; }
|
public List<Flower> Flowers { get; set; }
|
||||||
|
public List<Shop> Shops { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Flowers = new List<Flower>();
|
Flowers = new List<Flower>();
|
||||||
|
Shops = new List<Shop>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
55
FlowerShopListImplement/Shop.cs
Normal file
55
FlowerShopListImplement/Shop.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopListImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; }
|
||||||
|
public string Address { get; private set; }
|
||||||
|
public DateTime DateOpen { get; private set; }
|
||||||
|
public Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; private set; } = new();
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
return null;
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Address = model.Address,
|
||||||
|
DateOpen = model.DateOpen,
|
||||||
|
ShopFlowers = new()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Address = model.Address;
|
||||||
|
DateOpen = model.DateOpen;
|
||||||
|
ShopFlowers = model.ShopFlowers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Address = Address,
|
||||||
|
DateOpen = DateOpen,
|
||||||
|
ShopFlowers = ShopFlowers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
110
FlowerShopListImplement/ShopStorage.cs
Normal file
110
FlowerShopListImplement/ShopStorage.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using FlowerShopListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FlowerShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ShopViewModel>();
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
var result = new List<ShopViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.ShopName.Contains(model.Name))
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.Name) &&
|
||||||
|
shop.ShopName == model.Name) ||
|
||||||
|
(model.Id.HasValue && shop.Id == model.Id))
|
||||||
|
{
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (model.Id <= shop.Id)
|
||||||
|
{
|
||||||
|
model.Id = shop.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Shops.Add(newShop);
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.Id == model.Id)
|
||||||
|
{
|
||||||
|
shop.Update(model);
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Shops[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Shops[i];
|
||||||
|
_source.Shops.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectFlowerShop", "Projec
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{9E7C9D26-3932-4020-893D-1757DB2048B6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{9E7C9D26-3932-4020-893D-1757DB2048B6}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{843D517F-A9AE-4AF9-90C5-DB3E11D576E7}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{843D517F-A9AE-4AF9-90C5-DB3E11D576E7}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopListImplement", "FlowerShopListImplement\FlowerShopListImplement.csproj", "{62DAA9A0-9A71-4117-8D06-8825E1678D9D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopListImplement", "FlowerShopListImplement\FlowerShopListImplement.csproj", "{62DAA9A0-9A71-4117-8D06-8825E1678D9D}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopFileImplement", "FlowerShopFileImplement\FlowerShopFileImplement.csproj", "{0CFC7A18-2E56-4D0B-80AD-F52893222027}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0CFC7A18-2E56-4D0B-80AD-F52893222027}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0CFC7A18-2E56-4D0B-80AD-F52893222027}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0CFC7A18-2E56-4D0B-80AD-F52893222027}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0CFC7A18-2E56-4D0B-80AD-F52893222027}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
2
ProjectFlowerShop/FormFlower.Designer.cs
generated
2
ProjectFlowerShop/FormFlower.Designer.cs
generated
@ -1,6 +1,6 @@
|
|||||||
namespace ProjectFlowerShop
|
namespace ProjectFlowerShop
|
||||||
{
|
{
|
||||||
partial class FormProduct
|
partial class FormFlower
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
@ -15,7 +15,7 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace ProjectFlowerShop
|
namespace ProjectFlowerShop
|
||||||
{
|
{
|
||||||
public partial class FormProduct : Form
|
public partial class FormFlower : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IFlowerLogic _logic;
|
private readonly IFlowerLogic _logic;
|
||||||
@ -23,7 +23,7 @@ namespace ProjectFlowerShop
|
|||||||
private Dictionary<int, (IComponentModel, int)> _flowerComponents;
|
private Dictionary<int, (IComponentModel, int)> _flowerComponents;
|
||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
public FormProduct(ILogger<FormProduct> logger, IFlowerLogic logic)
|
public FormFlower(ILogger<FormFlower> logger, IFlowerLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
@ -53,8 +53,8 @@ namespace ProjectFlowerShop
|
|||||||
|
|
||||||
private void AddButton_Click(object sender, EventArgs e)
|
private void AddButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormProduct));
|
var service = Program.ServiceProvider?.GetService(typeof(FormFlower));
|
||||||
if (service is FormProduct form)
|
if (service is FormFlower form)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
@ -67,8 +67,8 @@ namespace ProjectFlowerShop
|
|||||||
{
|
{
|
||||||
if (DataGridView.SelectedRows.Count == 1)
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormProduct));
|
var service = Program.ServiceProvider?.GetService(typeof(FormFlower));
|
||||||
if (service is FormProduct form)
|
if (service is FormFlower form)
|
||||||
{
|
{
|
||||||
var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
20
ProjectFlowerShop/MainForm.Designer.cs
generated
20
ProjectFlowerShop/MainForm.Designer.cs
generated
@ -32,6 +32,8 @@
|
|||||||
ToolStripMenu = new ToolStripMenuItem();
|
ToolStripMenu = new ToolStripMenuItem();
|
||||||
КомпонентыStripMenuItem = new ToolStripMenuItem();
|
КомпонентыStripMenuItem = new ToolStripMenuItem();
|
||||||
ЦветыStripMenuItem = new ToolStripMenuItem();
|
ЦветыStripMenuItem = new ToolStripMenuItem();
|
||||||
|
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
поставкиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
DataGridView = new DataGridView();
|
DataGridView = new DataGridView();
|
||||||
CreateOrderButton = new Button();
|
CreateOrderButton = new Button();
|
||||||
TakeInWorkButton = new Button();
|
TakeInWorkButton = new Button();
|
||||||
@ -54,7 +56,7 @@
|
|||||||
//
|
//
|
||||||
// ToolStripMenu
|
// ToolStripMenu
|
||||||
//
|
//
|
||||||
ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem });
|
ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem });
|
||||||
ToolStripMenu.Name = "ToolStripMenu";
|
ToolStripMenu.Name = "ToolStripMenu";
|
||||||
ToolStripMenu.Size = new Size(117, 24);
|
ToolStripMenu.Size = new Size(117, 24);
|
||||||
ToolStripMenu.Text = "Справочники";
|
ToolStripMenu.Text = "Справочники";
|
||||||
@ -73,6 +75,20 @@
|
|||||||
ЦветыStripMenuItem.Text = "Цветы";
|
ЦветыStripMenuItem.Text = "Цветы";
|
||||||
ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click;
|
ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
// магазиныToolStripMenuItem
|
||||||
|
//
|
||||||
|
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
|
магазиныToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
|
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// поставкиToolStripMenuItem
|
||||||
|
//
|
||||||
|
поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem";
|
||||||
|
поставкиToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
поставкиToolStripMenuItem.Text = "Поставки";
|
||||||
|
поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// DataGridView
|
// DataGridView
|
||||||
//
|
//
|
||||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
@ -167,5 +183,7 @@
|
|||||||
private Button ReadyButton;
|
private Button ReadyButton;
|
||||||
private Button IssuedButton;
|
private Button IssuedButton;
|
||||||
private Button RefreshButton;
|
private Button RefreshButton;
|
||||||
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem поставкиToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,6 +37,7 @@ namespace ProjectFlowerShop
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e)
|
private void MainForm_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
@ -87,7 +88,7 @@ namespace ProjectFlowerShop
|
|||||||
return new OrderBindingModel
|
return new OrderBindingModel
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
FlowerId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["IceCreamId"].Value),
|
FlowerId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["FlowerId"].Value),
|
||||||
Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||||
Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
|
Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||||
Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||||
@ -179,5 +180,23 @@ namespace ProjectFlowerShop
|
|||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(ShopsForm));
|
||||||
|
if (service is ShopsForm form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void поставкиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(SupplyForm));
|
||||||
|
if (service is SupplyForm form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
using FlowerShopBusinessLogic.BusinessLogic;
|
using FlowerShopBusinessLogic.BusinessLogic;
|
||||||
using FlowerShopContracts.BusinessLogicsContracts;
|
using FlowerShopContracts.BusinessLogicsContracts;
|
||||||
using FlowerShopContracts.StoragesContracts;
|
using FlowerShopContracts.StoragesContracts;
|
||||||
using FlowerShopListImplement.Implements;
|
using FlowerShopFileImplement.Implements;
|
||||||
using ProjectFlowerShop;
|
using ProjectFlowerShop;
|
||||||
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 System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using FlowerShopBusinessLogic;
|
||||||
|
|
||||||
namespace ProjectFlowerShop
|
namespace ProjectFlowerShop
|
||||||
{
|
{
|
||||||
@ -40,13 +41,18 @@ namespace ProjectFlowerShop
|
|||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<IFlowerLogic, FlowerLogic>();
|
services.AddTransient<IFlowerLogic, FlowerLogic>();
|
||||||
|
services.AddTransient<IShopStorage, ShopStorage>();
|
||||||
|
services.AddTransient<IShopLogic, ShopLogic>();
|
||||||
services.AddTransient<MainForm>();
|
services.AddTransient<MainForm>();
|
||||||
services.AddTransient<ComponentForm>();
|
services.AddTransient<ComponentForm>();
|
||||||
services.AddTransient<FormComponents>();
|
services.AddTransient<FormComponents>();
|
||||||
services.AddTransient<FormCreateOrder>();
|
services.AddTransient<FormCreateOrder>();
|
||||||
services.AddTransient<FormProduct>();
|
services.AddTransient<FormFlower>();
|
||||||
services.AddTransient<FormProductComponent>();
|
services.AddTransient<FormFlowerComponent>();
|
||||||
services.AddTransient<FormFlowers>();
|
services.AddTransient<FormFlowers>();
|
||||||
|
services.AddTransient<ShopForm>();
|
||||||
|
services.AddTransient<ShopsForm>();
|
||||||
|
services.AddTransient<SupplyForm>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
<ProjectReference Include="..\FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj" />
|
<ProjectReference Include="..\FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
||||||
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||||
|
<ProjectReference Include="..\FlowerShopFileImplement\FlowerShopFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\FlowerShopListImplement\FlowerShopListImplement.csproj" />
|
<ProjectReference Include="..\FlowerShopListImplement\FlowerShopListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
193
ProjectFlowerShop/ShopForm.Designer.cs
generated
Normal file
193
ProjectFlowerShop/ShopForm.Designer.cs
generated
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
namespace ProjectFlowerShop
|
||||||
|
{
|
||||||
|
partial class ShopForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
DataGridView = new DataGridView();
|
||||||
|
buttonSave = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
textBoxAddress = new TextBox();
|
||||||
|
labelName = new Label();
|
||||||
|
labelAddress = new Label();
|
||||||
|
DateTimePicker = new DateTimePicker();
|
||||||
|
labelDate = new Label();
|
||||||
|
ColumnID = new DataGridViewTextBoxColumn();
|
||||||
|
Name = new DataGridViewTextBoxColumn();
|
||||||
|
Price = new DataGridViewTextBoxColumn();
|
||||||
|
Number = new DataGridViewTextBoxColumn();
|
||||||
|
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, Name, Price, Number });
|
||||||
|
DataGridView.Location = new Point(21, 12);
|
||||||
|
DataGridView.Name = "DataGridView";
|
||||||
|
DataGridView.RowHeadersWidth = 51;
|
||||||
|
DataGridView.RowTemplate.Height = 29;
|
||||||
|
DataGridView.Size = new Size(397, 305);
|
||||||
|
DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
buttonSave.Location = new Point(424, 288);
|
||||||
|
buttonSave.Name = "buttonSave";
|
||||||
|
buttonSave.Size = new Size(123, 29);
|
||||||
|
buttonSave.TabIndex = 1;
|
||||||
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(553, 288);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(116, 29);
|
||||||
|
buttonCancel.TabIndex = 2;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(424, 34);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(245, 27);
|
||||||
|
textBoxName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// textBoxAddress
|
||||||
|
//
|
||||||
|
textBoxAddress.Location = new Point(424, 95);
|
||||||
|
textBoxAddress.Name = "textBoxAddress";
|
||||||
|
textBoxAddress.Size = new Size(245, 27);
|
||||||
|
textBoxAddress.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
labelName.AutoSize = true;
|
||||||
|
labelName.Location = new Point(424, 12);
|
||||||
|
labelName.Name = "labelName";
|
||||||
|
labelName.Size = new Size(77, 20);
|
||||||
|
labelName.TabIndex = 5;
|
||||||
|
labelName.Text = "Название";
|
||||||
|
//
|
||||||
|
// labelAddress
|
||||||
|
//
|
||||||
|
labelAddress.AutoSize = true;
|
||||||
|
labelAddress.Location = new Point(424, 72);
|
||||||
|
labelAddress.Name = "labelAddress";
|
||||||
|
labelAddress.Size = new Size(51, 20);
|
||||||
|
labelAddress.TabIndex = 6;
|
||||||
|
labelAddress.Text = "Адрес";
|
||||||
|
//
|
||||||
|
// DateTimePicker
|
||||||
|
//
|
||||||
|
DateTimePicker.Location = new Point(424, 148);
|
||||||
|
DateTimePicker.Name = "DateTimePicker";
|
||||||
|
DateTimePicker.Size = new Size(245, 27);
|
||||||
|
DateTimePicker.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// labelDate
|
||||||
|
//
|
||||||
|
labelDate.AutoSize = true;
|
||||||
|
labelDate.Location = new Point(424, 125);
|
||||||
|
labelDate.Name = "labelDate";
|
||||||
|
labelDate.Size = new Size(41, 20);
|
||||||
|
labelDate.TabIndex = 8;
|
||||||
|
labelDate.Text = "Дата";
|
||||||
|
//
|
||||||
|
// ColumnID
|
||||||
|
//
|
||||||
|
ColumnID.HeaderText = "ColumnID";
|
||||||
|
ColumnID.MinimumWidth = 6;
|
||||||
|
ColumnID.Name = "ColumnID";
|
||||||
|
ColumnID.Visible = false;
|
||||||
|
ColumnID.Width = 125;
|
||||||
|
//
|
||||||
|
// Name
|
||||||
|
//
|
||||||
|
Name.HeaderText = "Название";
|
||||||
|
Name.MinimumWidth = 6;
|
||||||
|
Name.Name = "Name";
|
||||||
|
Name.Width = 125;
|
||||||
|
//
|
||||||
|
// Price
|
||||||
|
//
|
||||||
|
Price.HeaderText = "Цена";
|
||||||
|
Price.MinimumWidth = 6;
|
||||||
|
Price.Name = "Price";
|
||||||
|
Price.Width = 125;
|
||||||
|
//
|
||||||
|
// Number
|
||||||
|
//
|
||||||
|
Number.HeaderText = "Количество";
|
||||||
|
Number.MinimumWidth = 6;
|
||||||
|
Number.Name = "Number";
|
||||||
|
Number.Width = 125;
|
||||||
|
//
|
||||||
|
// ShopForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(681, 329);
|
||||||
|
Controls.Add(labelDate);
|
||||||
|
Controls.Add(DateTimePicker);
|
||||||
|
Controls.Add(labelAddress);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Controls.Add(textBoxAddress);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(DataGridView);
|
||||||
|
//Name = "ShopForm";
|
||||||
|
Text = "ShopForm";
|
||||||
|
Load += ShopForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxAddress;
|
||||||
|
private Label labelName;
|
||||||
|
private Label labelAddress;
|
||||||
|
private DateTimePicker DateTimePicker;
|
||||||
|
private Label labelDate;
|
||||||
|
private DataGridViewTextBoxColumn ColumnID;
|
||||||
|
private DataGridViewTextBoxColumn Name;
|
||||||
|
private DataGridViewTextBoxColumn Price;
|
||||||
|
private DataGridViewTextBoxColumn Number;
|
||||||
|
}
|
||||||
|
}
|
124
ProjectFlowerShop/ShopForm.cs
Normal file
124
ProjectFlowerShop/ShopForm.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
using FlowerShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
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;
|
||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ProjectFlowerShop
|
||||||
|
{
|
||||||
|
public partial class ShopForm : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
public int? _id;
|
||||||
|
private Dictionary<int, (IFlowerModel, int)> _flowers;
|
||||||
|
public ShopForm(ILogger<ShopForm> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка товаров магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_flowers != null)
|
||||||
|
{
|
||||||
|
foreach (var flower in _flowers)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Add(new object[] { flower.Key, flower.Value.Item1.FlowerName, flower.Value.Item1.Price, flower.Value.Item2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ShopName = textBoxName.Text,
|
||||||
|
Address = textBoxAddress.Text,
|
||||||
|
DateOpen = DateTimePicker.Value.Date,
|
||||||
|
ShopFlowers = _flowers
|
||||||
|
};
|
||||||
|
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 ShopForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shop = _logic.ReadElement(new ShopSearchModel { Id = _id });
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = shop.ShopName;
|
||||||
|
textBoxAddress.Text = shop.Address;
|
||||||
|
DateTimePicker.Text = shop.DateOpen.ToString();
|
||||||
|
_flowers = shop.ShopFlowers;
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
ProjectFlowerShop/ShopForm.resx
Normal file
132
ProjectFlowerShop/ShopForm.resx
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?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>
|
||||||
|
<metadata name="ColumnID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="Name.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="Number.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
114
ProjectFlowerShop/ShopsForm.Designer.cs
generated
Normal file
114
ProjectFlowerShop/ShopsForm.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
namespace ProjectFlowerShop
|
||||||
|
{
|
||||||
|
partial class ShopsForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
DataGridView = new DataGridView();
|
||||||
|
buttonAdd = new Button();
|
||||||
|
buttonChange = new Button();
|
||||||
|
buttonRemove = new Button();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
DataGridView.Location = new Point(12, 12);
|
||||||
|
DataGridView.Name = "DataGridView";
|
||||||
|
DataGridView.RowHeadersWidth = 51;
|
||||||
|
DataGridView.RowTemplate.Height = 29;
|
||||||
|
DataGridView.Size = new Size(531, 426);
|
||||||
|
DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
buttonAdd.Location = new Point(549, 12);
|
||||||
|
buttonAdd.Name = "buttonAdd";
|
||||||
|
buttonAdd.Size = new Size(239, 36);
|
||||||
|
buttonAdd.TabIndex = 1;
|
||||||
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
|
//
|
||||||
|
// buttonChange
|
||||||
|
//
|
||||||
|
buttonChange.Location = new Point(549, 54);
|
||||||
|
buttonChange.Name = "buttonChange";
|
||||||
|
buttonChange.Size = new Size(239, 36);
|
||||||
|
buttonChange.TabIndex = 2;
|
||||||
|
buttonChange.Text = "Изменить";
|
||||||
|
buttonChange.UseVisualStyleBackColor = true;
|
||||||
|
buttonChange.Click += buttonChange_Click;
|
||||||
|
//
|
||||||
|
// buttonRemove
|
||||||
|
//
|
||||||
|
buttonRemove.Location = new Point(549, 96);
|
||||||
|
buttonRemove.Name = "buttonRemove";
|
||||||
|
buttonRemove.Size = new Size(239, 36);
|
||||||
|
buttonRemove.TabIndex = 3;
|
||||||
|
buttonRemove.Text = "Удалить";
|
||||||
|
buttonRemove.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemove.Click += buttonRemove_Click;
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Location = new Point(549, 138);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(239, 36);
|
||||||
|
buttonRefresh.TabIndex = 4;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += buttonRefresh_Click;
|
||||||
|
//
|
||||||
|
// ShopsForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonRefresh);
|
||||||
|
Controls.Add(buttonRemove);
|
||||||
|
Controls.Add(buttonChange);
|
||||||
|
Controls.Add(buttonAdd);
|
||||||
|
Controls.Add(DataGridView);
|
||||||
|
Name = "ShopsForm";
|
||||||
|
Text = "ShopsForm";
|
||||||
|
Load += ShopsForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonChange;
|
||||||
|
private Button buttonRemove;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
}
|
||||||
|
}
|
117
ProjectFlowerShop/ShopsForm.cs
Normal file
117
ProjectFlowerShop/ShopsForm.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ProjectFlowerShop
|
||||||
|
{
|
||||||
|
public partial class ShopsForm : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
public ShopsForm(ILogger<ShopsForm> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
DataGridView.DataSource = list;
|
||||||
|
DataGridView.Columns["Id"].Visible = false;
|
||||||
|
DataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["ShopFlowers"].Visible = false;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка магазинов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(ShopForm));
|
||||||
|
if (service is ShopForm form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShopsForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonChange_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(ShopForm));
|
||||||
|
if (service is ShopForm form)
|
||||||
|
{
|
||||||
|
var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
form._id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRemove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Удаление магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectFlowerShop/ShopsForm.resx
Normal file
120
ProjectFlowerShop/ShopsForm.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>
|
141
ProjectFlowerShop/SupplyForm.Designer.cs
generated
Normal file
141
ProjectFlowerShop/SupplyForm.Designer.cs
generated
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
namespace ProjectFlowerShop
|
||||||
|
{
|
||||||
|
partial class SupplyForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
buttonSave = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
labelShop = new Label();
|
||||||
|
labelFlower = new Label();
|
||||||
|
labelNumber = new Label();
|
||||||
|
comboBoxShop = new ComboBox();
|
||||||
|
comboBoxFlower = new ComboBox();
|
||||||
|
textBoxNumber = new TextBox();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
buttonSave.Location = new Point(195, 186);
|
||||||
|
buttonSave.Name = "buttonSave";
|
||||||
|
buttonSave.Size = new Size(111, 29);
|
||||||
|
buttonSave.TabIndex = 0;
|
||||||
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(312, 186);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(108, 29);
|
||||||
|
buttonCancel.TabIndex = 1;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
|
//
|
||||||
|
// labelShop
|
||||||
|
//
|
||||||
|
labelShop.AutoSize = true;
|
||||||
|
labelShop.Location = new Point(12, 13);
|
||||||
|
labelShop.Name = "labelShop";
|
||||||
|
labelShop.Size = new Size(69, 20);
|
||||||
|
labelShop.TabIndex = 2;
|
||||||
|
labelShop.Text = "Магазин";
|
||||||
|
//
|
||||||
|
// labelFlower
|
||||||
|
//
|
||||||
|
labelFlower.AutoSize = true;
|
||||||
|
labelFlower.Location = new Point(12, 67);
|
||||||
|
labelFlower.Name = "labelFlower";
|
||||||
|
labelFlower.Size = new Size(53, 20);
|
||||||
|
labelFlower.TabIndex = 3;
|
||||||
|
labelFlower.Text = "Цветы";
|
||||||
|
//
|
||||||
|
// labelNumber
|
||||||
|
//
|
||||||
|
labelNumber.AutoSize = true;
|
||||||
|
labelNumber.Location = new Point(12, 121);
|
||||||
|
labelNumber.Name = "labelNumber";
|
||||||
|
labelNumber.Size = new Size(90, 20);
|
||||||
|
labelNumber.TabIndex = 4;
|
||||||
|
labelNumber.Text = "Количество";
|
||||||
|
//
|
||||||
|
// comboBoxShop
|
||||||
|
//
|
||||||
|
comboBoxShop.FormattingEnabled = true;
|
||||||
|
comboBoxShop.Location = new Point(12, 36);
|
||||||
|
comboBoxShop.Name = "comboBoxShop";
|
||||||
|
comboBoxShop.Size = new Size(294, 28);
|
||||||
|
comboBoxShop.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// comboBoxFlower
|
||||||
|
//
|
||||||
|
comboBoxFlower.FormattingEnabled = true;
|
||||||
|
comboBoxFlower.Location = new Point(12, 90);
|
||||||
|
comboBoxFlower.Name = "comboBoxFlower";
|
||||||
|
comboBoxFlower.Size = new Size(294, 28);
|
||||||
|
comboBoxFlower.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// textBoxNumber
|
||||||
|
//
|
||||||
|
textBoxNumber.Location = new Point(12, 144);
|
||||||
|
textBoxNumber.Name = "textBoxNumber";
|
||||||
|
textBoxNumber.Size = new Size(151, 27);
|
||||||
|
textBoxNumber.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// SupplyForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(430, 227);
|
||||||
|
Controls.Add(textBoxNumber);
|
||||||
|
Controls.Add(comboBoxFlower);
|
||||||
|
Controls.Add(comboBoxShop);
|
||||||
|
Controls.Add(labelNumber);
|
||||||
|
Controls.Add(labelFlower);
|
||||||
|
Controls.Add(labelShop);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Name = "SupplyForm";
|
||||||
|
Text = "SupplyForm";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Label labelShop;
|
||||||
|
private Label labelFlower;
|
||||||
|
private Label labelNumber;
|
||||||
|
private ComboBox comboBoxShop;
|
||||||
|
private ComboBox comboBoxFlower;
|
||||||
|
private TextBox textBoxNumber;
|
||||||
|
}
|
||||||
|
}
|
146
ProjectFlowerShop/SupplyForm.cs
Normal file
146
ProjectFlowerShop/SupplyForm.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
using FlowerShopContracts.BusinessLogicsContracts;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
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 ProjectFlowerShop
|
||||||
|
{
|
||||||
|
public partial class SupplyForm : Form
|
||||||
|
{
|
||||||
|
private readonly List<FlowerViewModel>? _flowerList;
|
||||||
|
private readonly List<ShopViewModel>? _shopsList;
|
||||||
|
IShopLogic _shopLogic;
|
||||||
|
IFlowerLogic _flowerLogic;
|
||||||
|
public SupplyForm(IFlowerLogic flowerLogic, IShopLogic shopLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_flowerLogic = flowerLogic;
|
||||||
|
_flowerList = flowerLogic.ReadList(null);
|
||||||
|
_shopsList = shopLogic.ReadList(null);
|
||||||
|
if (_flowerList != null)
|
||||||
|
{
|
||||||
|
comboBoxFlower.DisplayMember = "FlowerName";
|
||||||
|
comboBoxFlower.ValueMember = "Id";
|
||||||
|
comboBoxFlower.DataSource = _flowerList;
|
||||||
|
comboBoxFlower.SelectedItem = null;
|
||||||
|
}
|
||||||
|
if (_shopsList != null)
|
||||||
|
{
|
||||||
|
comboBoxShop.DisplayMember = "ShopName";
|
||||||
|
comboBoxShop.ValueMember = "Id";
|
||||||
|
comboBoxShop.DataSource = _shopsList;
|
||||||
|
comboBoxShop.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int ShopId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Convert.ToInt32(comboBoxShop.SelectedValue);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
comboBoxShop.SelectedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int FlowerId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Convert.ToInt32(comboBoxFlower.SelectedValue);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
comboBoxFlower.SelectedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IFlowerModel? FlowerModel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_flowerList == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var elem in _flowerList)
|
||||||
|
{
|
||||||
|
if (elem.Id == FlowerId)
|
||||||
|
{
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Number
|
||||||
|
{
|
||||||
|
get { return Convert.ToInt32(textBoxNumber.Text); }
|
||||||
|
set { textBoxNumber.Text = value.ToString(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxNumber.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxFlower.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите цветы", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxShop.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int count = Convert.ToInt32(textBoxNumber.Text);
|
||||||
|
|
||||||
|
bool res = _shopLogic.MakeSupply(
|
||||||
|
new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },
|
||||||
|
_flowerLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxFlower.SelectedValue) }),
|
||||||
|
count
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Пополнение прошло успешно");
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception err)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Ошибка пополнения");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectFlowerShop/SupplyForm.resx
Normal file
120
ProjectFlowerShop/SupplyForm.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>
|
Loading…
Reference in New Issue
Block a user
Значение можно получить через LINQ-запрос