Eliseev E.E. LabWork02_Hard #7
@ -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
|
||||
|
@ -17,6 +17,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj" />
|
||||
<ProjectReference Include="..\BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -28,6 +28,7 @@ namespace BlacksmithWorkshop
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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<WorkPiece> WorkPieces { get; private set; }
|
||||
|
||||
public List<Order> Orders { get; private set; }
|
||||
|
||||
public List<Manufacture> 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<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,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<ManufactureViewModel> GetFullList()
|
||||
{
|
||||
return source.Manufactures.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ManufactureViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<WorkPieceViewModel> GetFullList()
|
||||
{
|
||||
return source.WorkPieces.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<WorkPieceViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<int, int> WorkPieces { get; private set; } = new();
|
||||
|
||||
|
||||
private Dictionary<int, (IWorkPieceModel, int)>? _manufactureWorkPieces = null;
|
||||
|
||||
public Dictionary<int, (IWorkPieceModel, int)> 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()));
|
||||
}
|
||||
}
|
@ -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()));
|
||||
}
|
||||
}
|
@ -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()));
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopListImplement.Models
|
||||
{
|
||||
//класс реализующий интерфейс модели изделия
|
||||
//класс, реализующий интерфейс модели изделия
|
||||
public class Manufacture : IManufactureModel
|
||||
{
|
||||
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции
|
||||
|
Loading…
Reference in New Issue
Block a user