2lab done
This commit is contained in:
parent
b4d7679154
commit
b618ea277e
@ -11,7 +11,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLo
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplement", "FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj", "{332092CD-AA0D-475A-88A2-2E887E29E56A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyView", "FurnitureAssemblyView\FurnitureAssemblyView.csproj", "{77944C5A-53FC-437B-A563-E7C09C769859}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyView", "FurnitureAssemblyView\FurnitureAssemblyView.csproj", "{77944C5A-53FC-437B-A563-E7C09C769859}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{8DA61C13-D732-4AA0-8D0A-3569022681D2} = {8DA61C13-D732-4AA0-8D0A-3569022681D2}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{8DA61C13-D732-4AA0-8D0A-3569022681D2}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{7A1F9F2F-DDA5-4C97-8FAA-149D5372365D} = {7A1F9F2F-DDA5-4C97-8FAA-149D5372365D}
|
||||
{A5F526DF-C1CD-4FCA-87E6-BDB447FF959C} = {A5F526DF-C1CD-4FCA-87E6-BDB447FF959C}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -39,6 +48,10 @@ Global
|
||||
{77944C5A-53FC-437B-A563-E7C09C769859}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{77944C5A-53FC-437B-A563-E7C09C769859}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{77944C5A-53FC-437B-A563-E7C09C769859}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8DA61C13-D732-4AA0-8D0A-3569022681D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8DA61C13-D732-4AA0-8D0A-3569022681D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8DA61C13-D732-4AA0-8D0A-3569022681D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8DA61C13-D732-4AA0-8D0A-3569022681D2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,69 @@
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement
|
||||
{
|
||||
internal class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
|
||||
private readonly string WorkPieceFileName = "WorkPiece.xml";
|
||||
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
|
||||
private readonly string FurnitureFileName = "Furniture.xml";
|
||||
|
||||
public List<WorkPiece> WorkPieces { get; private set; }
|
||||
|
||||
public List<Order> Orders { get; private set; }
|
||||
|
||||
public List<Furniture> Furnitures { 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 SaveFurnitures() => SaveData(Furnitures, FurnitureFileName, "Furnitures", x => x.GetXElement);
|
||||
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!;
|
||||
Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.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,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,96 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
public class FurnitureStorage : IFurnitureStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public FurnitureStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<FurnitureViewModel> GetFullList()
|
||||
{
|
||||
return source.Furnitures.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<FurnitureViewModel> GetFilteredList(FurnitureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.FurnitureName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Furnitures.Where(x => x.FurnitureName.Contains(model.FurnitureName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public FurnitureViewModel? GetElement(FurnitureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.FurnitureName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Furnitures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.FurnitureName) && x.FurnitureName == model.FurnitureName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public FurnitureViewModel? Insert(FurnitureBindingModel model)
|
||||
{
|
||||
model.Id = source.Furnitures.Count > 0 ? source.Furnitures.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newFurniture = Furniture.Create(model);
|
||||
|
||||
if (newFurniture == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Furnitures.Add(newFurniture);
|
||||
source.SaveFurnitures();
|
||||
|
||||
return newFurniture.GetViewModel;
|
||||
}
|
||||
|
||||
public FurnitureViewModel? Update(FurnitureBindingModel model)
|
||||
{
|
||||
var furniture = source.Furnitures.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (furniture == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
furniture.Update(model);
|
||||
source.SaveFurnitures();
|
||||
|
||||
return furniture.GetViewModel;
|
||||
}
|
||||
|
||||
public FurnitureViewModel? Delete(FurnitureBindingModel model)
|
||||
{
|
||||
var element = source.Furnitures.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
source.Furnitures.Remove(element);
|
||||
source.SaveFurnitures();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.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 furniture = source.Furnitures.FirstOrDefault(x => x.Id == order.FurnitureId);
|
||||
|
||||
if (furniture != null)
|
||||
{
|
||||
viewModel.FurnitureName = furniture.FurnitureName;
|
||||
}
|
||||
|
||||
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,96 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.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,106 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
public class Furniture : IFurnitureModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string FurnitureName { 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)>? _furnitureWorkPieces = null;
|
||||
|
||||
public Dictionary<int, (IWorkPieceModel, int)> FurnitureWorkPieces
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_furnitureWorkPieces == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
|
||||
_furnitureWorkPieces = WorkPieces.ToDictionary(x => x.Key,
|
||||
y => ((source.WorkPieces.FirstOrDefault(z => z.Id == y.Key) as IWorkPieceModel)!, y.Value));
|
||||
}
|
||||
|
||||
return _furnitureWorkPieces;
|
||||
}
|
||||
}
|
||||
|
||||
public static Furniture? Create(FurnitureBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Furniture()
|
||||
{
|
||||
Id = model.Id,
|
||||
FurnitureName = model.FurnitureName,
|
||||
Price = model.Price,
|
||||
WorkPieces = model.FurnitureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Furniture? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Furniture()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
FurnitureName = element.Element("FurnitureName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
WorkPieces = element.Element("FurnitureWorkPieces")!.Elements("FurnitureWorkPieces").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
y => Convert.ToInt32(y.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(FurnitureBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FurnitureName = model.FurnitureName;
|
||||
Price = model.Price;
|
||||
WorkPieces = model.FurnitureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_furnitureWorkPieces = null;
|
||||
}
|
||||
|
||||
public FurnitureViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FurnitureName = FurnitureName,
|
||||
Price = Price,
|
||||
FurnitureWorkPieces = FurnitureWorkPieces
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Furniture",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("FurnitureName", FurnitureName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("FurnitureWorkPieces", WorkPieces.Select(
|
||||
x => new XElement("FurnitureWorkPieces",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))
|
||||
).ToArray()));
|
||||
}
|
||||
}
|
100
FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs
Normal file
100
FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int FurnitureId { 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,
|
||||
FurnitureId = model.FurnitureId,
|
||||
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),
|
||||
FurnitureId = Convert.ToInt32(element.Element("FurnitureId")!.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,
|
||||
FurnitureId = FurnitureId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("FurnitureId", FurnitureId.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,74 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.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()));
|
||||
}
|
||||
}
|
@ -28,79 +28,82 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonAdd = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonDelete = new Button();
|
||||
buttonRef = new Button();
|
||||
dataGridView = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonRef = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(640, 35);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(116, 50);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
this.buttonAdd.Location = new System.Drawing.Point(560, 26);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(102, 38);
|
||||
this.buttonAdd.TabIndex = 0;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(640, 105);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(116, 50);
|
||||
buttonUpdate.TabIndex = 1;
|
||||
buttonUpdate.Text = "Изменить";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += ButtonUpdate_Click;
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(560, 79);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(102, 38);
|
||||
this.buttonUpdate.TabIndex = 1;
|
||||
this.buttonUpdate.Text = "Изменить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(640, 175);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(116, 50);
|
||||
buttonDelete.TabIndex = 2;
|
||||
buttonDelete.Text = "Удалить";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += ButtonDelete_Click;
|
||||
this.buttonDelete.Location = new System.Drawing.Point(560, 131);
|
||||
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(102, 38);
|
||||
this.buttonDelete.TabIndex = 2;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
buttonRef.Location = new Point(640, 245);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(116, 50);
|
||||
buttonRef.TabIndex = 3;
|
||||
buttonRef.Text = "Обновить";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += ButtonRef_Click;
|
||||
this.buttonRef.Location = new System.Drawing.Point(560, 184);
|
||||
this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonRef.Name = "buttonRef";
|
||||
this.buttonRef.Size = new System.Drawing.Size(102, 38);
|
||||
this.buttonRef.TabIndex = 3;
|
||||
this.buttonRef.Text = "Обновить";
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// 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(604, 426);
|
||||
dataGridView.TabIndex = 4;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(10, 9);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(528, 320);
|
||||
this.dataGridView.TabIndex = 4;
|
||||
//
|
||||
// FormFurnitures
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(781, 450);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonAdd);
|
||||
Name = "FormFurnitures";
|
||||
Text = "Изделия";
|
||||
Load += FormFurnitures_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(683, 338);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.buttonRef);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormFurnitures";
|
||||
this.Text = "Изделия";
|
||||
this.Load += new System.EventHandler(this.FormFurnitures_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -132,14 +132,14 @@
|
||||
// workPieceToolStripMenuItem
|
||||
//
|
||||
this.workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem";
|
||||
this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
|
||||
this.workPieceToolStripMenuItem.Text = "Заготовки";
|
||||
this.workPieceToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceToolStripMenuItem_Click);
|
||||
//
|
||||
// furnitureToolStripMenuItem
|
||||
//
|
||||
this.furnitureToolStripMenuItem.Name = "furnitureToolStripMenuItem";
|
||||
this.furnitureToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.furnitureToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
|
||||
this.furnitureToolStripMenuItem.Text = "Изделия";
|
||||
this.furnitureToolStripMenuItem.Click += new System.EventHandler(this.FurnitureToolStripMenuItem_Click);
|
||||
//
|
||||
@ -159,6 +159,7 @@
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Сборка мебели";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
|
@ -17,6 +17,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using FurnitureAssemblyBusinessLogic.BussinessLogic;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyListImplement.Implements;
|
||||
using FurnitureAssemblyFileImplement.Implements;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
Loading…
Reference in New Issue
Block a user