From bde3649b0a2f9607d5553319b38a941272c2e8fa Mon Sep 17 00:00:00 2001 From: asoc1al Date: Sun, 26 May 2024 12:44:22 +0400 Subject: [PATCH] . --- AutoWorkshop/AutoWorkshopView.csproj | 19 ---- .../AutoWorkshopBusinessLogic.csproj | 4 +- .../BusinessLogics/ComponentLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 107 ++++++++---------- .../AutoWorkshopContracts.csproj | 4 +- .../BindingModels/OrderBindingModel.cs | 4 +- ...tBindingModel.cs => RepairBindingModel.cs} | 0 .../ViewModels/ComponentViewModel.cs | 6 +- .../ViewModels/OrderViewModel.cs | 2 +- .../ViewModels/RepairViewModel.cs | 8 +- .../AutoWorkshopDataModels.csproj | 4 +- .../AutoWorkshopFileImplement.csproj | 14 +++ .../DataFileSingleton.cs | 59 ++++++++++ .../Implements/ComponentStorage.cs | 82 ++++++++++++++ .../Implements/OrderStorage.cs | 96 ++++++++++++++++ .../Implements/RepairStorage.cs | 80 +++++++++++++ AutoWorkshopFileImplement/Models/Component.cs | 65 +++++++++++ AutoWorkshopFileImplement/Models/Order.cs | 90 +++++++++++++++ AutoWorkshopFileImplement/Models/Repair.cs | 90 +++++++++++++++ .../AutoWorkshopListImplement.csproj | 4 +- .../Implements/OrderStorage.cs | 24 ++-- AutoWorkshopView/AutoWorkshopView.csproj | 14 ++- AutoWorkshopView/Class1.cs | 5 - .../Forms/FormComponent.Designer.cs | 0 .../Forms/FormComponent.cs | 1 - .../Forms/FormComponent.resx | 0 .../Forms/FormComponents.Designer.cs | 0 .../Forms/FormComponents.cs | 0 .../Forms/FormComponents.resx | 0 .../Forms/FormCreateOrder.Designer.cs | 2 +- .../Forms/FormCreateOrder.cs | 35 +++--- .../Forms/FormCreateOrder.resx | 0 .../Forms/FormRepair.Designer.cs | 0 .../Forms/FormRepair.cs | 9 +- .../Forms/FormRepair.resx | 0 .../Forms/FormRepairComponent.Designer.cs | 1 + .../Forms/FormRepairComponent.cs | 0 .../Forms/FormRepairComponent.resx | 0 .../Forms/FormRepairs.Designer.cs | 2 +- .../Forms/FormRepairs.cs | 0 .../MainForm.Designer.cs | 44 +++---- .../MainForm.cs | 54 ++++----- .../MainForm.resx | 0 {AutoWorkshop => AutoWorkshopView}/Program.cs | 3 +- AutoWorkshopView/nlog.config | 15 +++ 45 files changed, 751 insertions(+), 198 deletions(-) delete mode 100644 AutoWorkshop/AutoWorkshopView.csproj rename AutoWorkshopContracts/BindingModels/{ProductBindingModel.cs => RepairBindingModel.cs} (100%) create mode 100644 AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj create mode 100644 AutoWorkshopFileImplement/DataFileSingleton.cs create mode 100644 AutoWorkshopFileImplement/Implements/ComponentStorage.cs create mode 100644 AutoWorkshopFileImplement/Implements/OrderStorage.cs create mode 100644 AutoWorkshopFileImplement/Implements/RepairStorage.cs create mode 100644 AutoWorkshopFileImplement/Models/Component.cs create mode 100644 AutoWorkshopFileImplement/Models/Order.cs create mode 100644 AutoWorkshopFileImplement/Models/Repair.cs delete mode 100644 AutoWorkshopView/Class1.cs rename {AutoWorkshop => AutoWorkshopView}/Forms/FormComponent.Designer.cs (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormComponent.cs (99%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormComponent.resx (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormComponents.Designer.cs (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormComponents.cs (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormComponents.resx (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormCreateOrder.Designer.cs (98%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormCreateOrder.cs (82%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormCreateOrder.resx (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepair.Designer.cs (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepair.cs (98%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepair.resx (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepairComponent.Designer.cs (98%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepairComponent.cs (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepairComponent.resx (100%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepairs.Designer.cs (99%) rename {AutoWorkshop => AutoWorkshopView}/Forms/FormRepairs.cs (100%) rename {AutoWorkshop => AutoWorkshopView}/MainForm.Designer.cs (83%) rename {AutoWorkshop => AutoWorkshopView}/MainForm.cs (81%) rename {AutoWorkshop => AutoWorkshopView}/MainForm.resx (100%) rename {AutoWorkshop => AutoWorkshopView}/Program.cs (97%) create mode 100644 AutoWorkshopView/nlog.config diff --git a/AutoWorkshop/AutoWorkshopView.csproj b/AutoWorkshop/AutoWorkshopView.csproj deleted file mode 100644 index 3a78229..0000000 --- a/AutoWorkshop/AutoWorkshopView.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - - - - - - - - - \ No newline at end of file diff --git a/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj b/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj index 8483a93..a7b458f 100644 --- a/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj +++ b/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs index 71539e0..b1736de 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -84,7 +84,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public bool Delete(ComponentBindingModel Model) { - CheckModel(Model); + CheckModel(Model, false); _logger.LogInformation("Delete. Id:{Id}", Model.Id); if (_componentStorage.Delete(Model) is null) diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 9e5cf5a..246c491 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -31,7 +31,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics return null; } - _logger.LogInformation("ReadList. Count:{Count}", List.Count); + _logger.LogInformation("ReadList. Count: {Count}", List.Count); return List; } @@ -39,6 +39,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics { CheckModel(Model); + if (Model.Status != OrderStatus.Undefined) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + Model.Status = OrderStatus.Accepted; + if (_orderStorage.Insert(Model) is null) { _logger.LogWarning("Insert operation failed"); @@ -48,81 +56,58 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics return true; } - public bool TakeOrderInWork(OrderBindingModel Model) + private bool ChangeOrderStatus(OrderBindingModel Model, OrderStatus NewStatus) { - CheckModel(Model); + CheckModel(Model, false); - var Element = _orderStorage.GetElement(new OrderSearchModel - { - Id = Model.Id - }); - - if (Element is null) - throw new InvalidOperationException("Заказ с таким идентификатором не существует"); - - Element.Status = OrderStatus.Accepted; - - if (_orderStorage.Update(Model) is null) + var Order = _orderStorage.GetElement(new OrderSearchModel { Id = Model.Id }); + + if (Order == null) { - _logger.LogWarning("Update operation failed"); + _logger.LogWarning("Change status operation failed. Order not found"); + return false; + } + + if (Order.Status + 1 != NewStatus) + { + _logger.LogWarning("Change status operation failed. Incorrect new status: {NewStatus}. Current status: {currStatus}", + NewStatus, Order.Status); + return false; + } + + Model.RepairId = Order.RepairId; + Model.Count = Order.Count; + Model.Sum = Order.Sum; + Model.DateCreate = Order.DateCreate; + Model.Status = NewStatus; + + if (Model.Status == OrderStatus.Ready) + Model.DateImplement = DateTime.Now; + else + Model.DateImplement = Order.DateImplement; + + if (_orderStorage.Update(Model) == null) + { + _logger.LogWarning("Change status operation failed"); return false; } return true; } + public bool TakeOrderInWork(OrderBindingModel Model) + { + return ChangeOrderStatus(Model, OrderStatus.BeingProcessed); + } + public bool FinishOrder(OrderBindingModel Model) { - CheckModel(Model); - - var Element = _orderStorage.GetElement(new OrderSearchModel - { - Id = Model.Id - }); - - if (Element is null) - throw new InvalidOperationException("Заказ с таким идентификатором не существует"); - - if (Element.Status != OrderStatus.BeingProcessed) - { - _logger.LogWarning("FinishOrder. Invalid status"); - return false; - } - - if (_orderStorage.Update(Model) is null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - - return true; + return ChangeOrderStatus(Model, OrderStatus.Ready); } public bool DeliveryOrder(OrderBindingModel Model) { - CheckModel(Model); - - var Element = _orderStorage.GetElement(new OrderSearchModel - { - Id = Model.Id - }); - - if (Element is null) - throw new InvalidOperationException("Заказ с таким идентификатором не существует"); - - if (Element.Status != OrderStatus.Ready) - { - _logger.LogWarning("DeliveryOrder. Invalid status"); - return false; - } - - if (_orderStorage.Update(Model) is null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - - return true; + return ChangeOrderStatus(Model, OrderStatus.Delivered); } private void CheckModel(OrderBindingModel Model, bool WithParams = true) diff --git a/AutoWorkshopContracts/AutoWorkshopContracts.csproj b/AutoWorkshopContracts/AutoWorkshopContracts.csproj index 7c2e15c..bf4f9d2 100644 --- a/AutoWorkshopContracts/AutoWorkshopContracts.csproj +++ b/AutoWorkshopContracts/AutoWorkshopContracts.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable diff --git a/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs b/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs index 88305f3..161742f 100644 --- a/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -1,5 +1,5 @@ -using AutoWorkshopDataModels.Models; -using AutoWorkshopDataModels.Enums; +using AutoWorkshopDataModels.Enums; +using AutoWorkshopDataModels.Models; namespace AutoWorkshopContracts.BindingModels { diff --git a/AutoWorkshopContracts/BindingModels/ProductBindingModel.cs b/AutoWorkshopContracts/BindingModels/RepairBindingModel.cs similarity index 100% rename from AutoWorkshopContracts/BindingModels/ProductBindingModel.cs rename to AutoWorkshopContracts/BindingModels/RepairBindingModel.cs diff --git a/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs b/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs index 6efe022..ead047b 100644 --- a/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -6,11 +6,11 @@ namespace AutoWorkshopContracts.ViewModels public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название компонента")] - + + [DisplayName("Название компонента")] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [DisplayName("Цена")] public double Cost { get; set; } } } diff --git a/AutoWorkshopContracts/ViewModels/OrderViewModel.cs b/AutoWorkshopContracts/ViewModels/OrderViewModel.cs index 1a4c4fe..69c83f0 100644 --- a/AutoWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/OrderViewModel.cs @@ -11,7 +11,7 @@ namespace AutoWorkshopContracts.ViewModels public int RepairId { get; set; } - [DisplayName("Ремонт")] + [DisplayName("Ремонт")] public string RepairName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/AutoWorkshopContracts/ViewModels/RepairViewModel.cs b/AutoWorkshopContracts/ViewModels/RepairViewModel.cs index 5551506..d0a5f54 100644 --- a/AutoWorkshopContracts/ViewModels/RepairViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/RepairViewModel.cs @@ -6,11 +6,11 @@ namespace AutoWorkshopContracts.ViewModels public class RepairViewModel : IRepairModel { public int Id { get; set; } - [DisplayName("Название изделия")] - + + [DisplayName("Название ремонта")] public string RepairName { get; set; } = string.Empty; - [DisplayName("Цена")] - + + [DisplayName("Цена")] public double Price { get; set; } public Dictionary RepairComponents diff --git a/AutoWorkshopDataModels/AutoWorkshopDataModels.csproj b/AutoWorkshopDataModels/AutoWorkshopDataModels.csproj index 132c02c..fa71b7a 100644 --- a/AutoWorkshopDataModels/AutoWorkshopDataModels.csproj +++ b/AutoWorkshopDataModels/AutoWorkshopDataModels.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable diff --git a/AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj b/AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj new file mode 100644 index 0000000..06be0dc --- /dev/null +++ b/AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/AutoWorkshopFileImplement/DataFileSingleton.cs b/AutoWorkshopFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..266f506 --- /dev/null +++ b/AutoWorkshopFileImplement/DataFileSingleton.cs @@ -0,0 +1,59 @@ +using AutoWorkshopFileImplement.Models; +using System.Xml.Linq; + +namespace AutoWorkshopFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? _instance; + + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string RepairFileName = "Repair.xml"; + + public List Components { get; private set; } + + public List Orders { get; private set; } + + public List Repairs { get; private set; } + + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + + public static DataFileSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataFileSingleton(); + } + + return _instance; + } + + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SaveRepairs() => SaveData(Repairs, RepairFileName, "Repairs", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + 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/AutoWorkshopFileImplement/Implements/ComponentStorage.cs b/AutoWorkshopFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..752a95a --- /dev/null +++ b/AutoWorkshopFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,82 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopFileImplement.Models; + +namespace AutoWorkshopFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton _source; + + public ComponentStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Components.Select(x => x.GetViewModel).ToList(); + } + + public List 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 Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id); + + if (Component == null) + return null; + + _source.Components.Remove(Component); + _source.SaveComponents(); + + return Component.GetViewModel; + } + } +} diff --git a/AutoWorkshopFileImplement/Implements/OrderStorage.cs b/AutoWorkshopFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..54f0d0b --- /dev/null +++ b/AutoWorkshopFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,96 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopFileImplement.Models; +using System.Reflection; + +namespace AutoWorkshopFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton _source; + + public OrderStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Orders.Select(x => AddRepairName(x.GetViewModel)).ToList(); + } + + public List GetFilteredList(OrderSearchModel Model) + { + if (!Model.Id.HasValue) + return new(); + + return _source.Orders.Where(x => x.Id == Model.Id).Select(x => AddRepairName(x.GetViewModel)).ToList(); + } + + 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 AddRepairName(Element.GetViewModel); + } + + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel Model) + { + if (!Model.Id.HasValue) + return null; + + var Order = _source.Orders.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id)); + + if (Order == null) + return null; + + return AddRepairName(Order.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 AddRepairName(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 AddRepairName(Order.GetViewModel); + } + + private OrderViewModel AddRepairName(OrderViewModel Model) + { + var SelectedRepair = _source.Repairs.FirstOrDefault(x => x.Id == Model.RepairId); + + Model.RepairName = SelectedRepair?.RepairName ?? string.Empty; + return Model; + } + } +} diff --git a/AutoWorkshopFileImplement/Implements/RepairStorage.cs b/AutoWorkshopFileImplement/Implements/RepairStorage.cs new file mode 100644 index 0000000..0fcd3da --- /dev/null +++ b/AutoWorkshopFileImplement/Implements/RepairStorage.cs @@ -0,0 +1,80 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopFileImplement.Models; + +namespace AutoWorkshopFileImplement.Implements +{ + public class RepairStorage : IRepairStorage + { + private readonly DataFileSingleton _source; + + public RepairStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Repairs.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(RepairSearchModel Model) + { + if (string.IsNullOrEmpty(Model.RepairName)) + return new(); + + return _source.Repairs.Where(x => x.RepairName.Contains(Model.RepairName)).Select(x => x.GetViewModel).ToList(); + } + + public RepairViewModel? GetElement(RepairSearchModel Model) + { + if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue) + return null; + + return _source.Repairs.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.RepairName) && x.RepairName == Model.RepairName) || (Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel; + } + + public RepairViewModel? Insert(RepairBindingModel Model) + { + Model.Id = _source.Repairs.Count > 0 ? _source.Repairs.Max(x => x.Id) + 1 : 1; + + var NewRepair = Repair.Create(Model); + + if (NewRepair == null) + return null; + + _source.Repairs.Add(NewRepair); + _source.SaveRepairs(); + + return NewRepair.GetViewModel; + } + + public RepairViewModel? Update(RepairBindingModel Model) + { + var Repair = _source.Repairs.FirstOrDefault(x => x.Id == Model.Id); + + if (Repair == null) + return null; + + Repair.Update(Model); + _source.SaveRepairs(); + + return Repair.GetViewModel; + } + + public RepairViewModel? Delete(RepairBindingModel Model) + { + var Repair = _source.Repairs.FirstOrDefault(x => x.Id == Model.Id); + + if (Repair == null) + return null; + + _source.Repairs.Remove(Repair); + _source.SaveRepairs(); + + return Repair.GetViewModel; + } + } +} diff --git a/AutoWorkshopFileImplement/Models/Component.cs b/AutoWorkshopFileImplement/Models/Component.cs new file mode 100644 index 0000000..383028b --- /dev/null +++ b/AutoWorkshopFileImplement/Models/Component.cs @@ -0,0 +1,65 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; +using System.Xml.Linq; + +namespace AutoWorkshopFileImplement.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 is null) + return null; + + return new Component() + { + Id = Model.Id, + ComponentName = Model.ComponentName, + Cost = Model.Cost + }; + } + + public static Component? Create(XElement Element) + { + if (Element is 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 is 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()) + ); + } +} diff --git a/AutoWorkshopFileImplement/Models/Order.cs b/AutoWorkshopFileImplement/Models/Order.cs new file mode 100644 index 0000000..97a67fd --- /dev/null +++ b/AutoWorkshopFileImplement/Models/Order.cs @@ -0,0 +1,90 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Enums; +using AutoWorkshopDataModels.Models; +using System.Xml.Linq; + +namespace AutoWorkshopFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int RepairId { 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 is null) + return null; + + return new Order() + { + Id = Model.Id, + RepairId = Model.RepairId, + Count = Model.Count, + Sum = Model.Sum, + Status = Model.Status, + DateCreate = Model.DateCreate, + DateImplement = Model.DateImplement + }; + } + + public static Order? Create(XElement Element) + { + if (Element is null) + return null; + + return new Order() + { + Id = Convert.ToInt32(Element.Attribute("Id")!.Value), + RepairId = Convert.ToInt32(Element.Element("RepairId")!.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 is null) + return; + + Status = Model.Status; + DateImplement = Model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + RepairId = RepairId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new( + "Order", + new XAttribute("Id", Id), + new XElement("RepairId", RepairId), + 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/AutoWorkshopFileImplement/Models/Repair.cs b/AutoWorkshopFileImplement/Models/Repair.cs new file mode 100644 index 0000000..ee7b2f3 --- /dev/null +++ b/AutoWorkshopFileImplement/Models/Repair.cs @@ -0,0 +1,90 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; +using System.Xml.Linq; + +namespace AutoWorkshopFileImplement.Models +{ + public class Repair : IRepairModel + { + public int Id { get; private set; } + + public string RepairName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary Components { get; private set; } = new(); + + private Dictionary? _RepairComponents = null; + + public Dictionary RepairComponents + { + get + { + if (_RepairComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _RepairComponents = Components.ToDictionary(x => + x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + } + return _RepairComponents; + } + } + + public static Repair? Create(RepairBindingModel Model) + { + if (Model is null) + return null; + + return new Repair() + { + Id = Model.Id, + RepairName = Model.RepairName, + Price = Model.Price, + Components = Model.RepairComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Repair? Create(XElement Element) + { + if (Element is null) + return null; + + return new Repair() + { + Id = Convert.ToInt32(Element.Attribute("Id")!.Value), + RepairName = Element.Element("RepairName")!.Value, + Price = Convert.ToDouble(Element.Element("Price")!.Value), + Components = Element.Element("RepairComponents")!.Elements("RepairComponent").ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(RepairBindingModel Model) + { + if (Model is null) + return; + + RepairName = Model.RepairName; + Price = Model.Price; + Components = Model.RepairComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _RepairComponents = null; + } + + public RepairViewModel GetViewModel => new() + { + Id = Id, + RepairName = RepairName, + Price = Price, + RepairComponents = RepairComponents + }; + + public XElement GetXElement => new( + "Repair", + new XAttribute("Id", Id), + new XElement("RepairName", RepairName), + new XElement("Price", Price.ToString()), + new XElement("RepairComponents", Components.Select(x => + new XElement("RepairComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()) + ); + } +} diff --git a/AutoWorkshopImplement/AutoWorkshopListImplement.csproj b/AutoWorkshopImplement/AutoWorkshopListImplement.csproj index 6deaaf6..06be0dc 100644 --- a/AutoWorkshopImplement/AutoWorkshopListImplement.csproj +++ b/AutoWorkshopImplement/AutoWorkshopListImplement.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable diff --git a/AutoWorkshopImplement/Implements/OrderStorage.cs b/AutoWorkshopImplement/Implements/OrderStorage.cs index 838bd47..53ee90e 100644 --- a/AutoWorkshopImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopImplement/Implements/OrderStorage.cs @@ -21,7 +21,7 @@ namespace AutoWorkshopListImplement.Implements foreach (var Order in _source.Orders) { - Result.Add(Order.GetViewModel); + Result.Add(JoinRepairName(Order.GetViewModel)); } return Result; @@ -38,7 +38,7 @@ namespace AutoWorkshopListImplement.Implements { if (Order.Id == Model.Id) { - Result.Add(Order.GetViewModel); + Result.Add(JoinRepairName(Order.GetViewModel)); break; } } @@ -55,7 +55,7 @@ namespace AutoWorkshopListImplement.Implements { if (Order.Id == Model.Id) { - return Order.GetViewModel; + return JoinRepairName(Order.GetViewModel); } } @@ -79,7 +79,7 @@ namespace AutoWorkshopListImplement.Implements return null; _source.Orders.Add(NewOrder); - return NewOrder.GetViewModel; + return JoinRepairName(NewOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel Model) @@ -89,7 +89,7 @@ namespace AutoWorkshopListImplement.Implements if (Order.Id == Model.Id) { Order.Update(Model); - return Order.GetViewModel; + return JoinRepairName(Order.GetViewModel); } } @@ -105,12 +105,22 @@ namespace AutoWorkshopListImplement.Implements var Element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return Element.GetViewModel; + return JoinRepairName(Element.GetViewModel); } } return null; } + + private OrderViewModel JoinRepairName(OrderViewModel Model) + { + var SelectedRepair = _source.Repairs.Find(reinforced => reinforced.Id == Model.RepairId); + + if (SelectedRepair != null) + { + Model.RepairName = SelectedRepair.RepairName; + } + return Model; + } } } - \ No newline at end of file diff --git a/AutoWorkshopView/AutoWorkshopView.csproj b/AutoWorkshopView/AutoWorkshopView.csproj index 060aa1c..b76dcff 100644 --- a/AutoWorkshopView/AutoWorkshopView.csproj +++ b/AutoWorkshopView/AutoWorkshopView.csproj @@ -1,10 +1,20 @@  - net6.0-windows + WinExe + net8.0-windows7.0 enable true enable - + + + + + + + + + + \ No newline at end of file diff --git a/AutoWorkshopView/Class1.cs b/AutoWorkshopView/Class1.cs deleted file mode 100644 index 7439ed6..0000000 --- a/AutoWorkshopView/Class1.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AutoWorkshopView; - -public class Class1 -{ -} diff --git a/AutoWorkshop/Forms/FormComponent.Designer.cs b/AutoWorkshopView/Forms/FormComponent.Designer.cs similarity index 100% rename from AutoWorkshop/Forms/FormComponent.Designer.cs rename to AutoWorkshopView/Forms/FormComponent.Designer.cs diff --git a/AutoWorkshop/Forms/FormComponent.cs b/AutoWorkshopView/Forms/FormComponent.cs similarity index 99% rename from AutoWorkshop/Forms/FormComponent.cs rename to AutoWorkshopView/Forms/FormComponent.cs index d79e3bf..1b0a14f 100644 --- a/AutoWorkshop/Forms/FormComponent.cs +++ b/AutoWorkshopView/Forms/FormComponent.cs @@ -2,7 +2,6 @@ using AutoWorkshopContracts.BusinessLogicContracts; using AutoWorkshopContracts.SearchModels; using Microsoft.Extensions.Logging; -using System.Windows.Forms; namespace AutoWorkshopView.Forms { diff --git a/AutoWorkshop/Forms/FormComponent.resx b/AutoWorkshopView/Forms/FormComponent.resx similarity index 100% rename from AutoWorkshop/Forms/FormComponent.resx rename to AutoWorkshopView/Forms/FormComponent.resx diff --git a/AutoWorkshop/Forms/FormComponents.Designer.cs b/AutoWorkshopView/Forms/FormComponents.Designer.cs similarity index 100% rename from AutoWorkshop/Forms/FormComponents.Designer.cs rename to AutoWorkshopView/Forms/FormComponents.Designer.cs diff --git a/AutoWorkshop/Forms/FormComponents.cs b/AutoWorkshopView/Forms/FormComponents.cs similarity index 100% rename from AutoWorkshop/Forms/FormComponents.cs rename to AutoWorkshopView/Forms/FormComponents.cs diff --git a/AutoWorkshop/Forms/FormComponents.resx b/AutoWorkshopView/Forms/FormComponents.resx similarity index 100% rename from AutoWorkshop/Forms/FormComponents.resx rename to AutoWorkshopView/Forms/FormComponents.resx diff --git a/AutoWorkshop/Forms/FormCreateOrder.Designer.cs b/AutoWorkshopView/Forms/FormCreateOrder.Designer.cs similarity index 98% rename from AutoWorkshop/Forms/FormCreateOrder.Designer.cs rename to AutoWorkshopView/Forms/FormCreateOrder.Designer.cs index a84b1ea..7ac6681 100644 --- a/AutoWorkshop/Forms/FormCreateOrder.Designer.cs +++ b/AutoWorkshopView/Forms/FormCreateOrder.Designer.cs @@ -40,6 +40,7 @@ // // RepairComboBox // + RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList; RepairComboBox.FormattingEnabled = true; RepairComboBox.Location = new Point(103, 12); RepairComboBox.Name = "RepairComboBox"; @@ -62,7 +63,6 @@ SumTextBox.ReadOnly = true; SumTextBox.Size = new Size(232, 23); SumTextBox.TabIndex = 2; - SumTextBox.TextChanged += SumTextBox_TextChanged; // // SaveButton // diff --git a/AutoWorkshop/Forms/FormCreateOrder.cs b/AutoWorkshopView/Forms/FormCreateOrder.cs similarity index 82% rename from AutoWorkshop/Forms/FormCreateOrder.cs rename to AutoWorkshopView/Forms/FormCreateOrder.cs index 1440327..24ad884 100644 --- a/AutoWorkshop/Forms/FormCreateOrder.cs +++ b/AutoWorkshopView/Forms/FormCreateOrder.cs @@ -8,38 +8,38 @@ namespace AutoWorkshopView.Forms public partial class FormCreateOrder : Form { private readonly ILogger _logger; - private readonly IRepairLogic _logicI; - private readonly IOrderLogic _logicO; + private readonly IRepairLogic _repairLogic; + private readonly IOrderLogic _orderLogic; - public FormCreateOrder(ILogger Logger, IRepairLogic LogicI, IOrderLogic LogicO) + public FormCreateOrder(ILogger Logger, IRepairLogic RepairLogic, IOrderLogic OrderLogic) { InitializeComponent(); _logger = Logger; - _logicI = LogicI; - _logicO = LogicO; + _repairLogic = RepairLogic; + _orderLogic = OrderLogic; } private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка ремонта для заказа"); + _logger.LogInformation("Загрузка ремонтов для заказа"); try { - var list = _logicI.ReadList(null); - if (list != null) + var List = _repairLogic.ReadList(null); + if (List != null) { RepairComboBox.DisplayMember = "RepairName"; RepairComboBox.ValueMember = "Id"; - RepairComboBox.DataSource = list; + RepairComboBox.DataSource = List; RepairComboBox.SelectedItem = null; } - _logger.LogInformation("Ремонт загружен"); + _logger.LogInformation("Ремонты загружены"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки ремонта"); + _logger.LogError(ex, "Ошибка загрузки ремонтов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -51,13 +51,13 @@ namespace AutoWorkshopView.Forms try { int id = Convert.ToInt32(RepairComboBox.SelectedValue); - var Repair = _logicI.ReadElement(new RepairSearchModel + var Repair = _repairLogic.ReadElement(new RepairSearchModel { Id = id }); - int count = Convert.ToInt32(CountTextBox.Text); + int Count = Convert.ToInt32(CountTextBox.Text); - SumTextBox.Text = Math.Round(count * (Repair?.Price ?? 0), 2).ToString(); + SumTextBox.Text = Math.Round(Count * (Repair?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } @@ -74,11 +74,6 @@ namespace AutoWorkshopView.Forms CalcSum(); } - private void SumTextBox_TextChanged(object sender, EventArgs e) - { - CalcSum(); - } - private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(CountTextBox.Text)) @@ -97,7 +92,7 @@ namespace AutoWorkshopView.Forms try { - var OperationResult = _logicO.CreateOrder(new OrderBindingModel + var OperationResult = _orderLogic.CreateOrder(new OrderBindingModel { RepairId = Convert.ToInt32(RepairComboBox.SelectedValue), Count = Convert.ToInt32(CountTextBox.Text), diff --git a/AutoWorkshop/Forms/FormCreateOrder.resx b/AutoWorkshopView/Forms/FormCreateOrder.resx similarity index 100% rename from AutoWorkshop/Forms/FormCreateOrder.resx rename to AutoWorkshopView/Forms/FormCreateOrder.resx diff --git a/AutoWorkshop/Forms/FormRepair.Designer.cs b/AutoWorkshopView/Forms/FormRepair.Designer.cs similarity index 100% rename from AutoWorkshop/Forms/FormRepair.Designer.cs rename to AutoWorkshopView/Forms/FormRepair.Designer.cs diff --git a/AutoWorkshop/Forms/FormRepair.cs b/AutoWorkshopView/Forms/FormRepair.cs similarity index 98% rename from AutoWorkshop/Forms/FormRepair.cs rename to AutoWorkshopView/Forms/FormRepair.cs index 422ec24..8752f0f 100644 --- a/AutoWorkshop/Forms/FormRepair.cs +++ b/AutoWorkshopView/Forms/FormRepair.cs @@ -97,13 +97,11 @@ namespace AutoWorkshopView.Forms if (_repairComponents.ContainsKey(Form.Id)) { - _repairComponents[Form.Id] = (Form.ComponentModel, - Form.Count); + _repairComponents[Form.Id] = (Form.ComponentModel, Form.Count); } else { - _repairComponents.Add(Form.Id, (Form.ComponentModel, - Form.Count)); + _repairComponents.Add(Form.Id, (Form.ComponentModel, Form.Count)); } LoadData(); @@ -146,7 +144,8 @@ namespace AutoWorkshopView.Forms { try { - _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", DataGridView.SelectedRows[0].Cells[1].Value); + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", DataGridView.SelectedRows[0].Cells[1].Value, + DataGridView.SelectedRows[0].Cells[2].Value); _repairComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value)); } diff --git a/AutoWorkshop/Forms/FormRepair.resx b/AutoWorkshopView/Forms/FormRepair.resx similarity index 100% rename from AutoWorkshop/Forms/FormRepair.resx rename to AutoWorkshopView/Forms/FormRepair.resx diff --git a/AutoWorkshop/Forms/FormRepairComponent.Designer.cs b/AutoWorkshopView/Forms/FormRepairComponent.Designer.cs similarity index 98% rename from AutoWorkshop/Forms/FormRepairComponent.Designer.cs rename to AutoWorkshopView/Forms/FormRepairComponent.Designer.cs index 360d6c1..74a0abf 100644 --- a/AutoWorkshop/Forms/FormRepairComponent.Designer.cs +++ b/AutoWorkshopView/Forms/FormRepairComponent.Designer.cs @@ -63,6 +63,7 @@ // // ComboBox // + ComboBox.DropDownStyle = ComboBoxStyle.DropDownList; ComboBox.FormattingEnabled = true; ComboBox.Location = new Point(95, 12); ComboBox.Name = "ComboBox"; diff --git a/AutoWorkshop/Forms/FormRepairComponent.cs b/AutoWorkshopView/Forms/FormRepairComponent.cs similarity index 100% rename from AutoWorkshop/Forms/FormRepairComponent.cs rename to AutoWorkshopView/Forms/FormRepairComponent.cs diff --git a/AutoWorkshop/Forms/FormRepairComponent.resx b/AutoWorkshopView/Forms/FormRepairComponent.resx similarity index 100% rename from AutoWorkshop/Forms/FormRepairComponent.resx rename to AutoWorkshopView/Forms/FormRepairComponent.resx diff --git a/AutoWorkshop/Forms/FormRepairs.Designer.cs b/AutoWorkshopView/Forms/FormRepairs.Designer.cs similarity index 99% rename from AutoWorkshop/Forms/FormRepairs.Designer.cs rename to AutoWorkshopView/Forms/FormRepairs.Designer.cs index d530879..3d21ff0 100644 --- a/AutoWorkshop/Forms/FormRepairs.Designer.cs +++ b/AutoWorkshopView/Forms/FormRepairs.Designer.cs @@ -96,7 +96,7 @@ Controls.Add(AddButton); Controls.Add(DataGridView); Name = "FormRepairs"; - Text = "FormRepairs"; + Text = "Ремонты"; Load += FormRepairs_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); ResumeLayout(false); diff --git a/AutoWorkshop/Forms/FormRepairs.cs b/AutoWorkshopView/Forms/FormRepairs.cs similarity index 100% rename from AutoWorkshop/Forms/FormRepairs.cs rename to AutoWorkshopView/Forms/FormRepairs.cs diff --git a/AutoWorkshop/MainForm.Designer.cs b/AutoWorkshopView/MainForm.Designer.cs similarity index 83% rename from AutoWorkshop/MainForm.Designer.cs rename to AutoWorkshopView/MainForm.Designer.cs index ff58bb9..bf9bc04 100644 --- a/AutoWorkshop/MainForm.Designer.cs +++ b/AutoWorkshopView/MainForm.Designer.cs @@ -49,9 +49,9 @@ MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; MenuStrip.Padding = new Padding(5, 2, 0, 2); - MenuStrip.Size = new Size(1134, 24); + MenuStrip.Size = new Size(947, 24); MenuStrip.TabIndex = 0; - MenuStrip.Text = "menuStrip1"; + MenuStrip.Text = "TopMenuStrip"; // // ToolStripMenu // @@ -63,16 +63,16 @@ // ComponentsStripMenuItem // ComponentsStripMenuItem.Name = "ComponentsStripMenuItem"; - ComponentsStripMenuItem.Size = new Size(180, 22); + ComponentsStripMenuItem.Size = new Size(145, 22); ComponentsStripMenuItem.Text = "Компоненты"; - ComponentsStripMenuItem.Click += КомпонентыStripMenuItem_Click; + ComponentsStripMenuItem.Click += ComponentsStripMenuItem_Click; // // RepairStripMenuItem // RepairStripMenuItem.Name = "RepairStripMenuItem"; - RepairStripMenuItem.Size = new Size(180, 22); + RepairStripMenuItem.Size = new Size(145, 22); RepairStripMenuItem.Text = "Ремонты"; - RepairStripMenuItem.Click += МороженноеStripMenuItem_Click; + RepairStripMenuItem.Click += RepairsStripMenuItem_Click; // // DataGridView // @@ -81,15 +81,15 @@ DataGridView.Margin = new Padding(3, 2, 3, 2); DataGridView.Name = "DataGridView"; DataGridView.RowHeadersWidth = 51; - DataGridView.Size = new Size(881, 305); + DataGridView.Size = new Size(770, 305); DataGridView.TabIndex = 1; // // CreateOrderButton // - CreateOrderButton.Location = new Point(897, 23); + CreateOrderButton.Location = new Point(786, 23); CreateOrderButton.Margin = new Padding(3, 2, 3, 2); CreateOrderButton.Name = "CreateOrderButton"; - CreateOrderButton.Size = new Size(227, 30); + CreateOrderButton.Size = new Size(157, 30); CreateOrderButton.TabIndex = 2; CreateOrderButton.Text = "Создать заказ"; CreateOrderButton.UseVisualStyleBackColor = true; @@ -97,43 +97,43 @@ // // TakeInWorkButton // - TakeInWorkButton.Location = new Point(897, 57); + TakeInWorkButton.Location = new Point(786, 57); TakeInWorkButton.Margin = new Padding(3, 2, 3, 2); TakeInWorkButton.Name = "TakeInWorkButton"; - TakeInWorkButton.Size = new Size(227, 30); + TakeInWorkButton.Size = new Size(157, 30); TakeInWorkButton.TabIndex = 3; TakeInWorkButton.Text = "Отдать заказ в работу"; TakeInWorkButton.UseVisualStyleBackColor = true; - TakeInWorkButton.Click += TakeInWorkButton_Click; + TakeInWorkButton.Click += TakeOrderInWorkButton_Click; // // ReadyButton // - ReadyButton.Location = new Point(897, 91); + ReadyButton.Location = new Point(786, 91); ReadyButton.Margin = new Padding(3, 2, 3, 2); ReadyButton.Name = "ReadyButton"; - ReadyButton.Size = new Size(227, 30); + ReadyButton.Size = new Size(157, 30); ReadyButton.TabIndex = 4; ReadyButton.Text = "Заказ готов"; ReadyButton.UseVisualStyleBackColor = true; - ReadyButton.Click += ReadyButton_Click; + ReadyButton.Click += OrderReadyButton_Click; // // IssuedButton // - IssuedButton.Location = new Point(897, 125); + IssuedButton.Location = new Point(786, 125); IssuedButton.Margin = new Padding(3, 2, 3, 2); IssuedButton.Name = "IssuedButton"; - IssuedButton.Size = new Size(227, 30); + IssuedButton.Size = new Size(157, 30); IssuedButton.TabIndex = 5; IssuedButton.Text = "Заказ выдан"; IssuedButton.UseVisualStyleBackColor = true; - IssuedButton.Click += IssuedButton_Click; + IssuedButton.Click += OrderDeliveredButton_Click; // // RefreshButton // - RefreshButton.Location = new Point(897, 159); + RefreshButton.Location = new Point(786, 159); RefreshButton.Margin = new Padding(3, 2, 3, 2); RefreshButton.Name = "RefreshButton"; - RefreshButton.Size = new Size(227, 30); + RefreshButton.Size = new Size(157, 30); RefreshButton.TabIndex = 6; RefreshButton.Text = "Обновить"; RefreshButton.UseVisualStyleBackColor = true; @@ -143,7 +143,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1134, 338); + ClientSize = new Size(947, 338); Controls.Add(RefreshButton); Controls.Add(IssuedButton); Controls.Add(ReadyButton); @@ -154,7 +154,7 @@ MainMenuStrip = MenuStrip; Margin = new Padding(3, 2, 3, 2); Name = "MainForm"; - Text = "MainForm"; + Text = "Основная форма"; Load += MainForm_Load; MenuStrip.ResumeLayout(false); MenuStrip.PerformLayout(); diff --git a/AutoWorkshop/MainForm.cs b/AutoWorkshopView/MainForm.cs similarity index 81% rename from AutoWorkshop/MainForm.cs rename to AutoWorkshopView/MainForm.cs index 0df3bc2..66ff9a1 100644 --- a/AutoWorkshop/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -1,6 +1,5 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.BusinessLogicContracts; -using AutoWorkshopDataModels.Enums; using AutoWorkshopView.Forms; using Microsoft.Extensions.Logging; @@ -18,16 +17,6 @@ namespace AutoWorkshopView _orderLogic = OrderLogic; } - private void КомпонентыStripMenuItem_Click(object sender, EventArgs e) - { - var Service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - - if (Service is FormComponents Form) - { - Form.ShowDialog(); - } - } - private void MainForm_Load(object sender, EventArgs e) { LoadData(); @@ -36,11 +25,11 @@ namespace AutoWorkshopView private void LoadData() { _logger.LogInformation("Загрузка заказов"); - + try { var List = _orderLogic.ReadList(null); - + if (List != null) { DataGridView.DataSource = List; @@ -57,10 +46,20 @@ namespace AutoWorkshopView } } - private void МороженноеStripMenuItem_Click(object sender, EventArgs e) + private void ComponentsStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + + if (Service is FormComponents Form) + { + Form.ShowDialog(); + } + } + + private void RepairsStripMenuItem_Click(object sender, EventArgs e) { var Service = Program.ServiceProvider?.GetService(typeof(FormRepairs)); - + if (Service is FormRepairs Form) { Form.ShowDialog(); @@ -78,20 +77,7 @@ namespace AutoWorkshopView } } - private OrderBindingModel CreateBindingModel(int id, bool isDone = false) - { - return new OrderBindingModel - { - Id = id, - RepairId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["RepairId"].Value), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }; - } - - private void TakeInWorkButton_Click(object sender, EventArgs e) + private void TakeOrderInWorkButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { @@ -101,7 +87,7 @@ namespace AutoWorkshopView try { - var OperationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + var OperationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!OperationResult) { @@ -119,7 +105,7 @@ namespace AutoWorkshopView } - private void ReadyButton_Click(object sender, EventArgs e) + private void OrderReadyButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { @@ -129,7 +115,7 @@ namespace AutoWorkshopView try { - var OperationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + var OperationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!OperationResult) { @@ -146,7 +132,7 @@ namespace AutoWorkshopView } } - private void IssuedButton_Click(object sender, EventArgs e) + private void OrderDeliveredButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { @@ -156,7 +142,7 @@ namespace AutoWorkshopView try { - var OperationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + var OperationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!OperationResult) { diff --git a/AutoWorkshop/MainForm.resx b/AutoWorkshopView/MainForm.resx similarity index 100% rename from AutoWorkshop/MainForm.resx rename to AutoWorkshopView/MainForm.resx diff --git a/AutoWorkshop/Program.cs b/AutoWorkshopView/Program.cs similarity index 97% rename from AutoWorkshop/Program.cs rename to AutoWorkshopView/Program.cs index 60e854b..bad6fb6 100644 --- a/AutoWorkshop/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -1,7 +1,7 @@ using AutoWorkshopBusinessLogic.BusinessLogics; using AutoWorkshopContracts.BusinessLogicContracts; using AutoWorkshopContracts.StoragesContracts; -using AutoWorkshopListImplement.Implements; +using AutoWorkshopFileImplement.Implements; using AutoWorkshopView.Forms; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -40,6 +40,7 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); diff --git a/AutoWorkshopView/nlog.config b/AutoWorkshopView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/AutoWorkshopView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file