diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 1c793e7..0834832 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{58737D93-9A12-4D07-BF3F-86AC512CE626}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.Build.0 = Release|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 8844615..f51fc76 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -17,6 +17,7 @@ + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index aac79d3..b740d55 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -94,7 +94,7 @@ namespace BlacksmithWorkshop { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - + try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel @@ -204,4 +204,4 @@ namespace BlacksmithWorkshop } } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 99ba26a..8e76a27 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,19 +1,19 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogic; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopListImplement.Implements; +using BlacksmithWorkshopFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System.Drawing; - namespace BlacksmithWorkshop { internal static class Program { private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -28,6 +28,7 @@ namespace BlacksmithWorkshop _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index ad0169d..ab54224 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -131,7 +131,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); //если не смогли найти указанный заказ по его Id - if(viewModel == null) + if (viewModel == null) { throw new ArgumentNullException(nameof(model)); } @@ -146,7 +146,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic model.Status = newOrderStatus; //проверка на выдачу - if(model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Выдан) { model.DateImplement = DateTime.Now; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj new file mode 100644 index 0000000..b65badc --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..b6628a3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using BlacksmithWorkshopFileImplement.Models; + +namespace BlacksmithWorkshopFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + + private readonly string WorkPieceFileName = "WorkPiece.xml"; + + private readonly string OrderFileName = "Order.xml"; + + private readonly string ManufactureFileName = "Manufacture.xml"; + + public List WorkPieces { get; private set; } + + public List Orders { get; private set; } + + public List Manufactures { get; private set; } + + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + + return instance; + } + + public void SaveWorkPieces() => SaveData(WorkPieces, WorkPieceFileName, "WorkPieces", x => x.GetXElement); + + public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, "Manufactures", x => x.GetXElement); + + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!; + Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + + return new List(); + } + + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..56f4c07 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,97 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + //реализация интерфейса хранилища изделий + public class ManufactureStorage : IManufactureStorage + { + private readonly DataFileSingleton source; + + public ManufactureStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Manufactures.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return new(); + } + + return source.Manufactures.Where(x => x.ManufactureName.Contains(model.ManufactureName)).Select(x => x.GetViewModel).ToList(); + } + + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue) + { + return null; + } + + return source.Manufactures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + model.Id = source.Manufactures.Count > 0 ? source.Manufactures.Max(x => x.Id) + 1 : 1; + + var newManufacture = Manufacture.Create(model); + + if (newManufacture == null) + { + return null; + } + + source.Manufactures.Add(newManufacture); + source.SaveManufactures(); + + return newManufacture.GetViewModel; + } + + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + + if (manufacture == null) + { + return null; + } + + manufacture.Update(model); + source.SaveManufactures(); + + return manufacture.GetViewModel; + } + + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + var element = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Manufactures.Remove(element); + source.SaveManufactures(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..250a67e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,111 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + //реализация интерфейса хранилища заказов + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Orders.Select(x => GetViewModel(x)).ToList(); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + return source.Orders.FirstOrDefault(x =>(model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + //для загрузки названий изделия в заказе + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + + var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == order.ManufactureId); + + if(manufacture != null) + { + viewModel.ManufactureName = manufacture.ManufactureName; + } + + return viewModel; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + source.Orders.Add(newOrder); + source.SaveOrders(); + + return GetViewModel(newOrder); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (order == null) + { + return null; + } + + order.Update(model); + source.SaveOrders(); + + return GetViewModel(order); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + + return GetViewModel(element); + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs new file mode 100644 index 0000000..b4e6084 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs @@ -0,0 +1,98 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + //реализация интерфейса хранилища заготовок + public class WorkPieceStorage : IWorkPieceStorage + { + private readonly DataFileSingleton source; + + public WorkPieceStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.WorkPieces.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(WorkPieceSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkPieceName)) + { + return new(); + } + + return source.WorkPieces.Where(x => x.WorkPieceName.Contains(model.WorkPieceName)).Select(x => x.GetViewModel).ToList(); + } + + public WorkPieceViewModel? GetElement(WorkPieceSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkPieceName) && !model.Id.HasValue) + { + return null; + } + + return source.WorkPieces.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkPieceName) && x.WorkPieceName == model.WorkPieceName) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public WorkPieceViewModel? Insert(WorkPieceBindingModel model) + { + model.Id = source.WorkPieces.Count > 0 ? source.WorkPieces.Max(x => x.Id) + 1 : 1; + + var newWorkPiece = WorkPiece.Create(model); + + if (newWorkPiece == null) + { + return null; + } + + source.WorkPieces.Add(newWorkPiece); + source.SaveWorkPieces(); + + return newWorkPiece.GetViewModel; + } + + public WorkPieceViewModel? Update(WorkPieceBindingModel model) + { + var workPiece = source.WorkPieces.FirstOrDefault(x => x.Id == model.Id); + + if (workPiece == null) + { + return null; + } + + workPiece.Update(model); + source.SaveWorkPieces(); + + return workPiece.GetViewModel; + } + + public WorkPieceViewModel? Delete(WorkPieceBindingModel model) + { + var element = source.WorkPieces.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.WorkPieces.Remove(element); + source.SaveWorkPieces(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs new file mode 100644 index 0000000..fb73403 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs @@ -0,0 +1,108 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + //класс реализующий интерфейс модели изделия + public class Manufacture : IManufactureModel + { + public int Id { get; private set; } + + public string ManufactureName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary WorkPieces { get; private set; } = new(); + + + private Dictionary? _manufactureWorkPieces = null; + + public Dictionary ManufactureWorkPieces + { + get + { + if (_manufactureWorkPieces == null) + { + var source = DataFileSingleton.GetInstance(); + + _manufactureWorkPieces = WorkPieces.ToDictionary(x => x.Key, + y => ((source.WorkPieces.FirstOrDefault(z => z.Id == y.Key) as IWorkPieceModel)!, y.Value)); + } + + return _manufactureWorkPieces; + } + } + + public static Manufacture? Create(ManufactureBindingModel model) + { + if (model == null) + { + return null; + } + + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + WorkPieces = model.ManufactureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Manufacture? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new Manufacture() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ManufactureName = element.Element("ManufactureName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureWorkPieces").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ManufactureBindingModel model) + { + if (model == null) + { + return; + } + + ManufactureName = model.ManufactureName; + Price = model.Price; + WorkPieces = model.ManufactureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2); + _manufactureWorkPieces = null; + } + + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureWorkPieces = ManufactureWorkPieces + }; + + public XElement GetXElement => new("Manufacture", + new XAttribute("Id", Id), + new XElement("ManufactureName", ManufactureName), + new XElement("Price", Price.ToString()), + new XElement("ManufactureWorkPieces", WorkPieces.Select( + x => new XElement("ManufactureWorkPieces", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs new file mode 100644 index 0000000..dbd7ffe --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -0,0 +1,103 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + //класс, реализующий интерфейс модели заказа + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ManufactureId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + 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), + ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.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), + 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, + ManufactureId = ManufactureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ManufactureId", ManufactureId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs new file mode 100644 index 0000000..b4f6a61 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs @@ -0,0 +1,76 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + //реализация интерфейса модели заготовки + public class WorkPiece : IWorkPieceModel + { + public int Id { get; private set; } + + public string WorkPieceName { get; private set; } = string.Empty; + + public double Cost { get; set; } + + public static WorkPiece? Create(WorkPieceBindingModel model) + { + if (model == null) + { + return null; + } + + return new WorkPiece() + { + Id = model.Id, + WorkPieceName = model.WorkPieceName, + Cost = model.Cost + }; + } + + public static WorkPiece? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new WorkPiece() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + WorkPieceName = element.Element("WorkPieceName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(WorkPieceBindingModel model) + { + if (model == null) + { + return; + } + + WorkPieceName = model.WorkPieceName; + Cost = model.Cost; + } + + public WorkPieceViewModel GetViewModel => new() + { + Id = Id, + WorkPieceName = WorkPieceName, + Cost = Cost + }; + + public XElement GetXElement => new("WorkPiece", + new XAttribute("Id", Id), + new XElement("WorkPieceName", WorkPieceName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs index ed71631..70c563b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopListImplement.Models { - //класс реализующий интерфейс модели изделия + //класс, реализующий интерфейс модели изделия public class Manufacture : IManufactureModel { //методы set делаем приватным, чтобы исключить неразрешённые манипуляции