This commit is contained in:
asoc1al 2024-05-26 12:44:22 +04:00
parent a7d4a71224
commit bde3649b0a
45 changed files with 751 additions and 198 deletions

View File

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\AutoWorkshopImplement\AutoWorkshopListImplement.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -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)

View File

@ -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)

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -1,5 +1,5 @@
using AutoWorkshopDataModels.Models;
using AutoWorkshopDataModels.Enums;
using AutoWorkshopDataModels.Enums;
using AutoWorkshopDataModels.Models;
namespace AutoWorkshopContracts.BindingModels
{

View File

@ -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; }
}
}

View File

@ -11,7 +11,7 @@ namespace AutoWorkshopContracts.ViewModels
public int RepairId { get; set; }
[DisplayName("Ремонт")]
[DisplayName("Ремонт")]
public string RepairName { get; set; } = string.Empty;
[DisplayName("Количество")]

View File

@ -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<int, (IComponentModel, int)> RepairComponents

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -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<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Repair> 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<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);
}
}
}
}

View File

@ -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<ComponentViewModel> GetFullList()
{
return _source.Components.Select(x => x.GetViewModel).ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
{
if (string.IsNullOrEmpty(Model.ComponentName))
return new();
return _source.Components.Where(x => x.ComponentName.Contains(Model.ComponentName)).Select(x => x.GetViewModel).ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel Model)
{
if (string.IsNullOrEmpty(Model.ComponentName) && !Model.Id.HasValue)
return null;
return _source.Components.FirstOrDefault(x =>
(!string.IsNullOrEmpty(Model.ComponentName) && x.ComponentName == Model.ComponentName) ||
(Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel Model)
{
Model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1;
var NewComponent = Component.Create(Model);
if (NewComponent == null)
return null;
_source.Components.Add(NewComponent);
_source.SaveComponents();
return NewComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel Model)
{
var Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id);
if (Component == null)
return null;
Component.Update(Model);
_source.SaveComponents();
return Component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel Model)
{
var Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id);
if (Component == null)
return null;
_source.Components.Remove(Component);
_source.SaveComponents();
return Component.GetViewModel;
}
}
}

View File

@ -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<OrderViewModel> GetFullList()
{
return _source.Orders.Select(x => AddRepairName(x.GetViewModel)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
{
if (!Model.Id.HasValue)
return new();
return _source.Orders.Where(x => x.Id == Model.Id).Select(x => 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;
}
}
}

View File

@ -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<RepairViewModel> GetFullList()
{
return _source.Repairs.Select(x => x.GetViewModel).ToList();
}
public List<RepairViewModel> 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;
}
}
}

View File

@ -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())
);
}
}

View File

@ -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())
);
}
}

View File

@ -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<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _RepairComponents = null;
public Dictionary<int, (IComponentModel, int)> 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())
);
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -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;
}
}
}

View File

@ -1,10 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\AutoWorkshopFileImplement\AutoWorkshopFileImplement.csproj" />
<ProjectReference Include="..\AutoWorkshopImplement\AutoWorkshopListImplement.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
</Project>

View File

@ -1,5 +0,0 @@
namespace AutoWorkshopView;
public class Class1
{
}

View File

@ -2,7 +2,6 @@
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace AutoWorkshopView.Forms
{

View File

@ -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
//

View File

@ -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<FormCreateOrder> Logger, IRepairLogic LogicI, IOrderLogic LogicO)
public FormCreateOrder(ILogger<FormCreateOrder> 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),

View File

@ -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));
}

View File

@ -63,6 +63,7 @@
//
// ComboBox
//
ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
ComboBox.FormattingEnabled = true;
ComboBox.Location = new Point(95, 12);
ComboBox.Name = "ComboBox";

View File

@ -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);

View File

@ -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();

View File

@ -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<OrderStatus>(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)
{

View File

@ -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<IComponentLogic, ComponentLogic>();
Services.AddTransient<IOrderLogic, OrderLogic>();
Services.AddTransient<IRepairLogic, RepairLogic>();
Services.AddTransient<MainForm>();
Services.AddTransient<FormComponent>();
Services.AddTransient<FormComponents>();

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>