Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
0bdd8aa43c | |||
bde3649b0a | |||
a7d4a71224 | |||
a7965424a7 |
@ -1,25 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34511.84
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshop", "AutoWorkshop\AutoWorkshop.csproj", "{839ECA1B-76A2-47C8-A1E6-9521B159678C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{839ECA1B-76A2-47C8-A1E6-9521B159678C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{839ECA1B-76A2-47C8-A1E6-9521B159678C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{839ECA1B-76A2-47C8-A1E6-9521B159678C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{839ECA1B-76A2-47C8-A1E6-9521B159678C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E8A48BA8-9649-47B3-9F42-1545CD5D085F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -1,11 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
39
AutoWorkshop/AutoWorkshop/Form1.Designer.cs
generated
39
AutoWorkshop/AutoWorkshop/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace AutoWorkshop
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace AutoWorkshop
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
namespace AutoWorkshop
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
17
AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj
Normal file
17
AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
125
AutoWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
125
AutoWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
|
||||
public ComponentLogic(ILogger<ComponentLogic> Logger, IComponentStorage ComponentStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_componentStorage = ComponentStorage;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}",
|
||||
Model?.ComponentName, Model?.Id);
|
||||
|
||||
var List = Model is null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}",
|
||||
Model.ComponentName, Model.Id);
|
||||
|
||||
var Element = _componentStorage.GetElement(Model);
|
||||
|
||||
if (Element is null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement element found. Id:{Id}", Element.Id);
|
||||
return Element;
|
||||
}
|
||||
|
||||
public bool Create(ComponentBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_componentStorage.Insert(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ComponentBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_componentStorage.Update(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ComponentBindingModel Model)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
|
||||
|
||||
if (_componentStorage.Delete(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ComponentBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(Model.ComponentName));
|
||||
|
||||
if (Model.Cost <= 0)
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(Model.Cost));
|
||||
|
||||
_logger.LogInformation("Repair. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}",
|
||||
Model.ComponentName, Model.Cost, Model.Id);
|
||||
|
||||
var Element = _componentStorage.GetElement(new ComponentSearchModel
|
||||
{
|
||||
ComponentName = Model.ComponentName
|
||||
});
|
||||
|
||||
if (Element != null && Element.Id != Model.Id)
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
133
AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
133
AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_orderStorage = OrderStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", Model?.Id);
|
||||
var List = Model is null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel Model)
|
||||
{
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ChangeOrderStatus(OrderBindingModel Model, OrderStatus NewStatus)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
|
||||
var Order = _orderStorage.GetElement(new OrderSearchModel { Id = Model.Id });
|
||||
|
||||
if (Order == null)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.Ready);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel Model)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.Delivered);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (Model.Count <= 0)
|
||||
throw new ArgumentNullException("Количество ремонтов в заказе быть больше 0", nameof(Model.Count));
|
||||
|
||||
if (Model.Sum <= 0)
|
||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(Model.Sum));
|
||||
|
||||
_logger.LogInformation("Order. RepairId:{RepairId}. Count:{Count}. Sum:{Sum}. " +
|
||||
"Status:{Status}. DateCreate:{DateCreate}. DateImplement:{DateImplement}. Id: {Id}",
|
||||
Model.RepairId, Model.Count, Model.Sum, Model.Status, Model.DateCreate,
|
||||
Model.DateImplement, Model.Id);
|
||||
}
|
||||
}
|
||||
}
|
125
AutoWorkshopBusinessLogic/BusinessLogics/RepairLogic.cs
Normal file
125
AutoWorkshopBusinessLogic/BusinessLogics/RepairLogic.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class RepairLogic : IRepairLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IRepairStorage _repairStorage;
|
||||
|
||||
public RepairLogic(ILogger<RepairLogic> Logger, IRepairStorage RepairStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_repairStorage = RepairStorage;
|
||||
}
|
||||
|
||||
public List<RepairViewModel>? ReadList(RepairSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. RepairName:{RepairName}. Id:{Id}",
|
||||
Model?.RepairName, Model?.Id);
|
||||
|
||||
var List = Model is null ? _repairStorage.GetFullList() : _repairStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public RepairViewModel? ReadElement(RepairSearchModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
_logger.LogInformation("ReadElement. RepairName:{RepairName}. Id:{Id}",
|
||||
Model.RepairName, Model.Id);
|
||||
|
||||
var Element = _repairStorage.GetElement(Model);
|
||||
|
||||
if (Element is null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement element found. Id:{Id}", Element.Id);
|
||||
return Element;
|
||||
}
|
||||
|
||||
public bool Create(RepairBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_repairStorage.Insert(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(RepairBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_repairStorage.Update(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(RepairBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
|
||||
|
||||
if (_repairStorage.Delete(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(RepairBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(Model.RepairName))
|
||||
throw new ArgumentNullException("Нет названия ремонта", nameof(Model.RepairName));
|
||||
|
||||
if (Model.Price <= 0)
|
||||
throw new ArgumentNullException("Стоимость ремонта должна быть больше 0", nameof(Model.Price));
|
||||
|
||||
_logger.LogInformation("Repair. RepairName:{RepairName}. Price:{Price}. Id: {Id}",
|
||||
Model.RepairName, Model.Price, Model.Id);
|
||||
|
||||
var Element = _repairStorage.GetElement(new RepairSearchModel
|
||||
{
|
||||
RepairName = Model.RepairName
|
||||
});
|
||||
|
||||
if (Element != null && Element.Id != Model.Id)
|
||||
throw new InvalidOperationException("Ремонт с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
13
AutoWorkshopContracts/AutoWorkshopContracts.csproj
Normal file
13
AutoWorkshopContracts/AutoWorkshopContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
11
AutoWorkshopContracts/BindingModels/ComponentBindingModel.cs
Normal file
11
AutoWorkshopContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
16
AutoWorkshopContracts/BindingModels/OrderBindingModel.cs
Normal file
16
AutoWorkshopContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int RepairId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
16
AutoWorkshopContracts/BindingModels/RepairBindingModel.cs
Normal file
16
AutoWorkshopContracts/BindingModels/RepairBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class RepairBindingModel : IRepairModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string RepairName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? Model);
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel Model);
|
||||
bool Create(ComponentBindingModel Model);
|
||||
bool Update(ComponentBindingModel Model);
|
||||
bool Delete(ComponentBindingModel Model);
|
||||
}
|
||||
}
|
15
AutoWorkshopContracts/BusinessLogicContracts/IOrderLogic.cs
Normal file
15
AutoWorkshopContracts/BusinessLogicContracts/IOrderLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? Model);
|
||||
bool CreateOrder(OrderBindingModel Model);
|
||||
bool TakeOrderInWork(OrderBindingModel Model);
|
||||
bool FinishOrder(OrderBindingModel Model);
|
||||
bool DeliveryOrder(OrderBindingModel Model);
|
||||
}
|
||||
}
|
15
AutoWorkshopContracts/BusinessLogicContracts/IRepairLogic.cs
Normal file
15
AutoWorkshopContracts/BusinessLogicContracts/IRepairLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IRepairLogic
|
||||
{
|
||||
List<RepairViewModel>? ReadList(RepairSearchModel? Model);
|
||||
RepairViewModel? ReadElement(RepairSearchModel Model);
|
||||
bool Create(RepairBindingModel Model);
|
||||
bool Update(RepairBindingModel Model);
|
||||
bool Delete(RepairBindingModel Model);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
7
AutoWorkshopContracts/SearchModels/OrderSearchModel.cs
Normal file
7
AutoWorkshopContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
8
AutoWorkshopContracts/SearchModels/RepairSearchModel.cs
Normal file
8
AutoWorkshopContracts/SearchModels/RepairSearchModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class RepairSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? RepairName { get; set; }
|
||||
}
|
||||
}
|
16
AutoWorkshopContracts/StoragesContracts/IComponentStorage.cs
Normal file
16
AutoWorkshopContracts/StoragesContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel Model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel Model);
|
||||
ComponentViewModel? Update(ComponentBindingModel Model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel Model);
|
||||
}
|
||||
}
|
16
AutoWorkshopContracts/StoragesContracts/IOrderStorage.cs
Normal file
16
AutoWorkshopContracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel Model);
|
||||
OrderViewModel? GetElement(OrderSearchModel Model);
|
||||
OrderViewModel? Insert(OrderBindingModel Model);
|
||||
OrderViewModel? Update(OrderBindingModel Model);
|
||||
OrderViewModel? Delete(OrderBindingModel Model);
|
||||
}
|
||||
}
|
16
AutoWorkshopContracts/StoragesContracts/IRepairStorage.cs
Normal file
16
AutoWorkshopContracts/StoragesContracts/IRepairStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IRepairStorage
|
||||
{
|
||||
List<RepairViewModel> GetFullList();
|
||||
List<RepairViewModel> GetFilteredList(RepairSearchModel Model);
|
||||
RepairViewModel? GetElement(RepairSearchModel Model);
|
||||
RepairViewModel? Insert(RepairBindingModel Model);
|
||||
RepairViewModel? Update(RepairBindingModel Model);
|
||||
RepairViewModel? Delete(RepairBindingModel Model);
|
||||
}
|
||||
}
|
16
AutoWorkshopContracts/ViewModels/ComponentViewModel.cs
Normal file
16
AutoWorkshopContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
32
AutoWorkshopContracts/ViewModels/OrderViewModel.cs
Normal file
32
AutoWorkshopContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int RepairId { get; set; }
|
||||
|
||||
[DisplayName("Ремонт")]
|
||||
public string RepairName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
22
AutoWorkshopContracts/ViewModels/RepairViewModel.cs
Normal file
22
AutoWorkshopContracts/ViewModels/RepairViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class RepairViewModel : IRepairModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название ремонта")]
|
||||
public string RepairName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
9
AutoWorkshopDataModels/AutoWorkshopDataModels.csproj
Normal file
9
AutoWorkshopDataModels/AutoWorkshopDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
11
AutoWorkshopDataModels/Enums/OrderStatus.cs
Normal file
11
AutoWorkshopDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace AutoWorkshopDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Undefined = -1,
|
||||
Accepted,
|
||||
BeingProcessed,
|
||||
Ready,
|
||||
Delivered,
|
||||
}
|
||||
}
|
8
AutoWorkshopDataModels/Models/IComponentModel.cs
Normal file
8
AutoWorkshopDataModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
7
AutoWorkshopDataModels/Models/IId.cs
Normal file
7
AutoWorkshopDataModels/Models/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
14
AutoWorkshopDataModels/Models/IOrderModel.cs
Normal file
14
AutoWorkshopDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int RepairId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
9
AutoWorkshopDataModels/Models/IRepairModel.cs
Normal file
9
AutoWorkshopDataModels/Models/IRepairModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface IRepairModel : IId
|
||||
{
|
||||
string RepairName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> RepairComponents { get; }
|
||||
}
|
||||
}
|
30
AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
Normal file
30
AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement
|
||||
{
|
||||
public class AutoWorkshopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder OptionsBuilder)
|
||||
{
|
||||
if (OptionsBuilder.IsConfigured == false)
|
||||
{
|
||||
OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop;Username=postgres;Password=postgres");
|
||||
}
|
||||
|
||||
base.OnConfiguring(OptionsBuilder);
|
||||
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
|
||||
public virtual DbSet<Repair> Repairs { set; get; }
|
||||
|
||||
public virtual DbSet<RepairComponent> RepairComponents { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="netcore-psql-util" Version="1.2.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
82
AutoWorkshopDatabaseImplement/Implements/ComponentStorage.cs
Normal file
82
AutoWorkshopDatabaseImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.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;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Components
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.ComponentName) && x.ComponentName == Model.ComponentName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel Model)
|
||||
{
|
||||
var NewComponent = Component.Create(Model);
|
||||
|
||||
if (NewComponent == null)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
Context.Components.Add(NewComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Component = Context.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Component.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Component = Context.Components.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Context.Components.Remove(Component);
|
||||
Context.SaveChanges();
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
94
AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs
Normal file
94
AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Where(x => x.Id == Model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Order = Context.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Order.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Order = Context.Orders.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Context.Orders.Remove(Order);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
109
AutoWorkshopDatabaseImplement/Implements/RepairStorage.cs
Normal file
109
AutoWorkshopDatabaseImplement/Implements/RepairStorage.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class RepairStorage : IRepairStorage
|
||||
{
|
||||
public List<RepairViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFilteredList(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName))
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.RepairName.Contains(Model.RepairName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public RepairViewModel? GetElement(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.RepairName) && x.RepairName == Model.RepairName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Insert(RepairBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var NewRepair = Repair.Create(Context, Model);
|
||||
if (NewRepair == null)
|
||||
return null;
|
||||
|
||||
Context.Repairs.Add(NewRepair);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewRepair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Update(RepairBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
using var Transaction = Context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var Repair = Context.Repairs.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
Repair.Update(Model);
|
||||
Context.SaveChanges();
|
||||
Repair.UpdateComponents(Context, Model);
|
||||
|
||||
Transaction.Commit();
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public RepairViewModel? Delete(RepairBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Repair = Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
Context.Repairs.Remove(Repair);
|
||||
Context.SaveChanges();
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
171
AutoWorkshopDatabaseImplement/Migrations/20240504064327_InitialCreate.Designer.cs
generated
Normal file
171
AutoWorkshopDatabaseImplement/Migrations/20240504064327_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AutoWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoWorkshopDatabase))]
|
||||
[Migration("20240504064327_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ComponentName = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Repairs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairName = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Repairs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "RepairComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_RepairComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_RepairComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_RepairComponents_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_RepairId",
|
||||
table: "Orders",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RepairComponents_ComponentId",
|
||||
table: "RepairComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RepairComponents_RepairId",
|
||||
table: "RepairComponents",
|
||||
column: "RepairId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "RepairComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Repairs");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AutoWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoWorkshopDatabase))]
|
||||
partial class AutoWorkshopDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
61
AutoWorkshopDatabaseImplement/Models/Component.cs
Normal file
61
AutoWorkshopDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<RepairComponent> RepairComponents { get; set; } = new();
|
||||
|
||||
public static Component? Create(ComponentBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Component Create(ComponentViewModel Model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = Model.Id,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
ComponentName = Model.ComponentName;
|
||||
Cost = Model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
70
AutoWorkshopDatabaseImplement/Models/Order.cs
Normal file
70
AutoWorkshopDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; private set; }
|
||||
|
||||
public virtual Repair Repair { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Undefined;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
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 void Update(OrderBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
RepairName = Repair.RepairName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
106
AutoWorkshopDatabaseImplement/Models/Repair.cs
Normal file
106
AutoWorkshopDatabaseImplement/Models/Repair.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Repair : IRepairModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string RepairName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _repairComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_repairComponents == null)
|
||||
{
|
||||
_repairComponents = Components.ToDictionary(RepComp => RepComp.ComponentId, RepComp =>
|
||||
(RepComp.Component as IComponentModel, RepComp.Count));
|
||||
}
|
||||
|
||||
return _repairComponents;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<RepairComponent> Components { get; set; } = new();
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Repair Create(AutoWorkshopDatabase Context, RepairBindingModel Model)
|
||||
{
|
||||
return new Repair()
|
||||
{
|
||||
Id = Model.Id,
|
||||
RepairName = Model.RepairName,
|
||||
Price = Model.Price,
|
||||
Components = Model.RepairComponents.Select(x => new RepairComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RepairBindingModel Model)
|
||||
{
|
||||
RepairName = Model.RepairName;
|
||||
Price = Model.Price;
|
||||
}
|
||||
|
||||
public RepairViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairName = RepairName,
|
||||
Price = Price,
|
||||
RepairComponents = RepairComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(AutoWorkshopDatabase Context, RepairBindingModel Model)
|
||||
{
|
||||
var RepairComponents = Context.RepairComponents.Where(rec => rec.RepairId == Model.Id).ToList();
|
||||
|
||||
if (RepairComponents != null && RepairComponents.Count > 0)
|
||||
{
|
||||
Context.RepairComponents.RemoveRange(RepairComponents.Where(rec => !Model.RepairComponents.ContainsKey(rec.ComponentId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
foreach (var ComponentToUpdate in RepairComponents)
|
||||
{
|
||||
ComponentToUpdate.Count = Model.RepairComponents[ComponentToUpdate.ComponentId].Item2;
|
||||
Model.RepairComponents.Remove(ComponentToUpdate.ComponentId);
|
||||
}
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
var Repair = Context.Repairs.First(x => x.Id == Id);
|
||||
|
||||
foreach (var RepairComponent in Model.RepairComponents)
|
||||
{
|
||||
Context.RepairComponents.Add(new RepairComponent
|
||||
{
|
||||
Repair = Repair,
|
||||
Component = Context.Components.First(x => x.Id == RepairComponent.Key),
|
||||
Count = RepairComponent.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
_repairComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
22
AutoWorkshopDatabaseImplement/Models/RepairComponent.cs
Normal file
22
AutoWorkshopDatabaseImplement/Models/RepairComponent.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class RepairComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
|
||||
public virtual Repair Repair { get; set; } = new();
|
||||
}
|
||||
}
|
14
AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj
Normal file
14
AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
59
AutoWorkshopFileImplement/DataFileSingleton.cs
Normal file
59
AutoWorkshopFileImplement/DataFileSingleton.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
AutoWorkshopFileImplement/Implements/ComponentStorage.cs
Normal file
82
AutoWorkshopFileImplement/Implements/ComponentStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
96
AutoWorkshopFileImplement/Implements/OrderStorage.cs
Normal file
96
AutoWorkshopFileImplement/Implements/OrderStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
80
AutoWorkshopFileImplement/Implements/RepairStorage.cs
Normal file
80
AutoWorkshopFileImplement/Implements/RepairStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
65
AutoWorkshopFileImplement/Models/Component.cs
Normal file
65
AutoWorkshopFileImplement/Models/Component.cs
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
90
AutoWorkshopFileImplement/Models/Order.cs
Normal file
90
AutoWorkshopFileImplement/Models/Order.cs
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
90
AutoWorkshopFileImplement/Models/Repair.cs
Normal file
90
AutoWorkshopFileImplement/Models/Repair.cs
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
14
AutoWorkshopImplement/AutoWorkshopListImplement.csproj
Normal file
14
AutoWorkshopImplement/AutoWorkshopListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
32
AutoWorkshopImplement/DataListSingleton.cs
Normal file
32
AutoWorkshopImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
|
||||
public List<Component> Components { get; set; }
|
||||
|
||||
public List<Order> Orders { get; set; }
|
||||
|
||||
public List<Repair> Repairs { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Repairs = new List<Repair>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
116
AutoWorkshopImplement/Implements/ComponentStorage.cs
Normal file
116
AutoWorkshopImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<ComponentViewModel>();
|
||||
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
Result.Add(Component.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
var Result = new List<ComponentViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
return Result;
|
||||
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if (Component.ComponentName.Contains(Model.ComponentName))
|
||||
{
|
||||
Result.Add(Component.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(Model.ComponentName)
|
||||
&& Component.ComponentName == Model.ComponentName)
|
||||
|| (Model.Id.HasValue && Component.Id == Model.Id))
|
||||
{
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if (Model.Id <= Component.Id)
|
||||
{
|
||||
Model.Id = Component.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewComponent = Component.Create(Model);
|
||||
|
||||
if (NewComponent == null)
|
||||
return null;
|
||||
|
||||
_source.Components.Add(NewComponent);
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if (Component.Id == Model.Id)
|
||||
{
|
||||
Component.Update(Model);
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Components.Count; ++i)
|
||||
{
|
||||
if (_source.Components[i].Id == Model.Id)
|
||||
{
|
||||
var Element = _source.Components[i];
|
||||
_source.Components.RemoveAt(i);
|
||||
|
||||
return Element.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
126
AutoWorkshopImplement/Implements/OrderStorage.cs
Normal file
126
AutoWorkshopImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<OrderViewModel>();
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
Result.Add(JoinRepairName(Order.GetViewModel));
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
var Result = new List<OrderViewModel>();
|
||||
|
||||
if (!Model.Id.HasValue)
|
||||
return Result;
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
{
|
||||
Result.Add(JoinRepairName(Order.GetViewModel));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
{
|
||||
return JoinRepairName(Order.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Model.Id <= Order.Id)
|
||||
{
|
||||
Model.Id = Order.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
_source.Orders.Add(NewOrder);
|
||||
return JoinRepairName(NewOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
{
|
||||
Order.Update(Model);
|
||||
return JoinRepairName(Order.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||
{
|
||||
if (_source.Orders[i].Id == Model.Id)
|
||||
{
|
||||
var Element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
116
AutoWorkshopImplement/Implements/RepairStorage.cs
Normal file
116
AutoWorkshopImplement/Implements/RepairStorage.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Implements
|
||||
{
|
||||
public class RepairStorage : IRepairStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public RepairStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<RepairViewModel>();
|
||||
|
||||
foreach (var Repair in _source.Repairs)
|
||||
{
|
||||
Result.Add(Repair.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFilteredList(RepairSearchModel Model)
|
||||
{
|
||||
var Result = new List<RepairViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(Model.RepairName))
|
||||
return Result;
|
||||
|
||||
foreach (var Repair in _source.Repairs)
|
||||
{
|
||||
if (Repair.RepairName.Contains(Model.RepairName))
|
||||
{
|
||||
Result.Add(Repair.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public RepairViewModel? GetElement(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Repair in _source.Repairs)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(Model.RepairName)
|
||||
&& Repair.RepairName == Model.RepairName)
|
||||
|| (Model.Id.HasValue && Repair.Id == Model.Id))
|
||||
{
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RepairViewModel? Insert(RepairBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Repair in _source.Repairs)
|
||||
{
|
||||
if (Model.Id <= Repair.Id)
|
||||
{
|
||||
Model.Id = Repair.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewRepair = Repair.Create(Model);
|
||||
|
||||
if (NewRepair == null)
|
||||
return null;
|
||||
|
||||
_source.Repairs.Add(NewRepair);
|
||||
return NewRepair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Update(RepairBindingModel Model)
|
||||
{
|
||||
foreach (var Repair in _source.Repairs)
|
||||
{
|
||||
if (Repair.Id == Model.Id)
|
||||
{
|
||||
Repair.Update(Model);
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RepairViewModel? Delete(RepairBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Repairs.Count; ++i)
|
||||
{
|
||||
if (_source.Repairs[i].Id == Model.Id)
|
||||
{
|
||||
var Element = _source.Repairs[i];
|
||||
_source.Repairs.RemoveAt(i);
|
||||
|
||||
return Element.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
44
AutoWorkshopImplement/Models/Component.cs
Normal file
44
AutoWorkshopImplement/Models/Component.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.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 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
|
||||
};
|
||||
}
|
||||
}
|
65
AutoWorkshopImplement/Models/Order.cs
Normal file
65
AutoWorkshopImplement/Models/Order.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.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; } = OrderStatus.Undefined;
|
||||
|
||||
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 void Update(OrderBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
RepairId = Model.RepairId;
|
||||
Count = Model.Count;
|
||||
Sum = Model.Sum;
|
||||
Status = Model.Status;
|
||||
DateCreate = Model.DateCreate;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
53
AutoWorkshopImplement/Models/Repair.cs
Normal file
53
AutoWorkshopImplement/Models/Repair.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.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, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
|
||||
public static Repair? Create(RepairBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Repair()
|
||||
{
|
||||
Id = Model.Id,
|
||||
RepairName = Model.RepairName,
|
||||
Price = Model.Price,
|
||||
RepairComponents = Model.RepairComponents
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RepairBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
RepairName = Model.RepairName;
|
||||
Price = Model.Price;
|
||||
RepairComponents = Model.RepairComponents;
|
||||
}
|
||||
|
||||
public RepairViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairName = RepairName,
|
||||
Price = Price,
|
||||
RepairComponents = RepairComponents
|
||||
};
|
||||
}
|
||||
}
|
23
AutoWorkshopView/AutoWorkshopView.csproj
Normal file
23
AutoWorkshopView/AutoWorkshopView.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<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>
|
118
AutoWorkshopView/Forms/FormComponent.Designer.cs
generated
Normal file
118
AutoWorkshopView/Forms/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,118 @@
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
partial class FormComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
ComponentNameLabel = new Label();
|
||||
ComponentPriceLabel = new Label();
|
||||
ComponentNameTextBox = new TextBox();
|
||||
ComponentPriceTextBox = new TextBox();
|
||||
CancelButton = new Button();
|
||||
SaveButton = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ComponentNameLabel
|
||||
//
|
||||
ComponentNameLabel.AutoSize = true;
|
||||
ComponentNameLabel.Location = new Point(12, 15);
|
||||
ComponentNameLabel.Name = "ComponentNameLabel";
|
||||
ComponentNameLabel.Size = new Size(62, 15);
|
||||
ComponentNameLabel.TabIndex = 0;
|
||||
ComponentNameLabel.Text = "Название:";
|
||||
//
|
||||
// ComponentPriceLabel
|
||||
//
|
||||
ComponentPriceLabel.AutoSize = true;
|
||||
ComponentPriceLabel.Location = new Point(12, 44);
|
||||
ComponentPriceLabel.Name = "ComponentPriceLabel";
|
||||
ComponentPriceLabel.Size = new Size(38, 15);
|
||||
ComponentPriceLabel.TabIndex = 1;
|
||||
ComponentPriceLabel.Text = "Цена:";
|
||||
//
|
||||
// ComponentNameTextBox
|
||||
//
|
||||
ComponentNameTextBox.Location = new Point(80, 12);
|
||||
ComponentNameTextBox.Name = "ComponentNameTextBox";
|
||||
ComponentNameTextBox.Size = new Size(221, 23);
|
||||
ComponentNameTextBox.TabIndex = 2;
|
||||
//
|
||||
// ComponentPriceTextBox
|
||||
//
|
||||
ComponentPriceTextBox.Location = new Point(80, 41);
|
||||
ComponentPriceTextBox.Name = "ComponentPriceTextBox";
|
||||
ComponentPriceTextBox.Size = new Size(140, 23);
|
||||
ComponentPriceTextBox.TabIndex = 3;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(226, 74);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 4;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += ButtonCancel_Click;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(145, 74);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(75, 23);
|
||||
SaveButton.TabIndex = 5;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += ButtonSave_Click;
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(324, 110);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(ComponentPriceTextBox);
|
||||
Controls.Add(ComponentNameTextBox);
|
||||
Controls.Add(ComponentPriceLabel);
|
||||
Controls.Add(ComponentNameLabel);
|
||||
Name = "FormComponent";
|
||||
Text = "Компонент";
|
||||
Load += FormComponent_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label ComponentNameLabel;
|
||||
private Label ComponentPriceLabel;
|
||||
private TextBox ComponentNameTextBox;
|
||||
private TextBox ComponentPriceTextBox;
|
||||
private Button CancelButton;
|
||||
private Button SaveButton;
|
||||
}
|
||||
}
|
95
AutoWorkshopView/Forms/FormComponent.cs
Normal file
95
AutoWorkshopView/Forms/FormComponent.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
public partial class FormComponent : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
private int? _id;
|
||||
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormComponent(ILogger<FormComponent> Logger, IComponentLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_logic = Logic;
|
||||
}
|
||||
|
||||
private void FormComponent_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Получение компонента");
|
||||
var View = _logic.ReadElement(new ComponentSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
|
||||
if (View != null)
|
||||
{
|
||||
ComponentNameTextBox.Text = View.ComponentName;
|
||||
ComponentPriceTextBox.Text = View.Cost.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ComponentNameTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение компонента");
|
||||
|
||||
try
|
||||
{
|
||||
var model = new ComponentBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ComponentName = ComponentNameTextBox.Text,
|
||||
Cost = Convert.ToDouble(ComponentPriceTextBox.Text)
|
||||
};
|
||||
|
||||
var OperationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
AutoWorkshopView/Forms/FormComponent.resx
Normal file
120
AutoWorkshopView/Forms/FormComponent.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
112
AutoWorkshopView/Forms/FormComponents.Designer.cs
generated
Normal file
112
AutoWorkshopView/Forms/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,112 @@
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
partial class FormComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
DataGridView = new DataGridView();
|
||||
AddButton = new Button();
|
||||
ChangeButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
RefreshButton = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Location = new Point(12, 12);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.Size = new Size(369, 350);
|
||||
DataGridView.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(387, 12);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(126, 23);
|
||||
AddButton.TabIndex = 1;
|
||||
AddButton.Text = "Добавить";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += AddButton_Click;
|
||||
//
|
||||
// ChangeButton
|
||||
//
|
||||
ChangeButton.Location = new Point(387, 41);
|
||||
ChangeButton.Name = "ChangeButton";
|
||||
ChangeButton.Size = new Size(126, 23);
|
||||
ChangeButton.TabIndex = 2;
|
||||
ChangeButton.Text = "Изменить";
|
||||
ChangeButton.UseVisualStyleBackColor = true;
|
||||
ChangeButton.Click += ChangeButton_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(387, 70);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(126, 23);
|
||||
DeleteButton.TabIndex = 3;
|
||||
DeleteButton.Text = "Удалить";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += DeleteButton_Click;
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
RefreshButton.Location = new Point(387, 99);
|
||||
RefreshButton.Name = "RefreshButton";
|
||||
RefreshButton.Size = new Size(126, 23);
|
||||
RefreshButton.TabIndex = 4;
|
||||
RefreshButton.Text = "Обновить";
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += RefreshButton_Click;
|
||||
//
|
||||
// ComponentsForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(525, 374);
|
||||
Controls.Add(RefreshButton);
|
||||
Controls.Add(DeleteButton);
|
||||
Controls.Add(ChangeButton);
|
||||
Controls.Add(AddButton);
|
||||
Controls.Add(DataGridView);
|
||||
Name = "ComponentsForm";
|
||||
Text = "Компоненты";
|
||||
Load += ComponentsForm_Load;
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView DataGridView;
|
||||
private Button AddButton;
|
||||
private Button ChangeButton;
|
||||
private Button DeleteButton;
|
||||
private Button RefreshButton;
|
||||
}
|
||||
}
|
112
AutoWorkshopView/Forms/FormComponents.cs
Normal file
112
AutoWorkshopView/Forms/FormComponents.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
public partial class FormComponents : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
public FormComponents(ILogger<FormComponents> Logger, IComponentLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = Logger;
|
||||
_logic = Logic;
|
||||
}
|
||||
|
||||
private void ComponentsForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var List = _logic.ReadList(null);
|
||||
|
||||
if (List != null)
|
||||
{
|
||||
DataGridView.DataSource = List;
|
||||
DataGridView.Columns["Id"].Visible = false;
|
||||
DataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
|
||||
if (Service is FormComponent Form)
|
||||
{
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (Service is FormComponent Form)
|
||||
{
|
||||
Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление компонента");
|
||||
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ComponentBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
120
AutoWorkshopView/Forms/FormComponents.resx
Normal file
120
AutoWorkshopView/Forms/FormComponents.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
145
AutoWorkshopView/Forms/FormCreateOrder.Designer.cs
generated
Normal file
145
AutoWorkshopView/Forms/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,145 @@
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
partial class FormCreateOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
RepairComboBox = new ComboBox();
|
||||
CountTextBox = new TextBox();
|
||||
SumTextBox = new TextBox();
|
||||
SaveButton = new Button();
|
||||
CancelButton = new Button();
|
||||
RepairLabel = new Label();
|
||||
CountLabel = new Label();
|
||||
SumLabel = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// RepairComboBox
|
||||
//
|
||||
RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
RepairComboBox.FormattingEnabled = true;
|
||||
RepairComboBox.Location = new Point(103, 12);
|
||||
RepairComboBox.Name = "RepairComboBox";
|
||||
RepairComboBox.Size = new Size(232, 23);
|
||||
RepairComboBox.TabIndex = 0;
|
||||
RepairComboBox.SelectedIndexChanged += RepairComboBox_SelectedIndexChanged;
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
CountTextBox.Location = new Point(103, 41);
|
||||
CountTextBox.Name = "CountTextBox";
|
||||
CountTextBox.Size = new Size(232, 23);
|
||||
CountTextBox.TabIndex = 1;
|
||||
CountTextBox.TextChanged += CountTextBox_TextChanged;
|
||||
//
|
||||
// SumTextBox
|
||||
//
|
||||
SumTextBox.Location = new Point(103, 70);
|
||||
SumTextBox.Name = "SumTextBox";
|
||||
SumTextBox.ReadOnly = true;
|
||||
SumTextBox.Size = new Size(232, 23);
|
||||
SumTextBox.TabIndex = 2;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(173, 107);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(81, 23);
|
||||
SaveButton.TabIndex = 3;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(260, 107);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 4;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += CancelButton_Click;
|
||||
//
|
||||
// RepairLabel
|
||||
//
|
||||
RepairLabel.AutoSize = true;
|
||||
RepairLabel.Location = new Point(12, 15);
|
||||
RepairLabel.Name = "RepairLabel";
|
||||
RepairLabel.Size = new Size(51, 15);
|
||||
RepairLabel.TabIndex = 5;
|
||||
RepairLabel.Text = "Ремонт:";
|
||||
//
|
||||
// CountLabel
|
||||
//
|
||||
CountLabel.AutoSize = true;
|
||||
CountLabel.Location = new Point(12, 44);
|
||||
CountLabel.Name = "CountLabel";
|
||||
CountLabel.Size = new Size(75, 15);
|
||||
CountLabel.TabIndex = 6;
|
||||
CountLabel.Text = "Количество:";
|
||||
//
|
||||
// SumLabel
|
||||
//
|
||||
SumLabel.AutoSize = true;
|
||||
SumLabel.Location = new Point(12, 73);
|
||||
SumLabel.Name = "SumLabel";
|
||||
SumLabel.Size = new Size(48, 15);
|
||||
SumLabel.TabIndex = 7;
|
||||
SumLabel.Text = "Сумма:";
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(348, 142);
|
||||
Controls.Add(SumLabel);
|
||||
Controls.Add(CountLabel);
|
||||
Controls.Add(RepairLabel);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(SumTextBox);
|
||||
Controls.Add(CountTextBox);
|
||||
Controls.Add(RepairComboBox);
|
||||
Name = "FormCreateOrder";
|
||||
Text = "Создание заказа";
|
||||
Load += FormCreateOrder_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox RepairComboBox;
|
||||
private TextBox CountTextBox;
|
||||
private TextBox SumTextBox;
|
||||
private Button SaveButton;
|
||||
private Button CancelButton;
|
||||
private Label RepairLabel;
|
||||
private Label CountLabel;
|
||||
private Label SumLabel;
|
||||
}
|
||||
}
|
128
AutoWorkshopView/Forms/FormCreateOrder.cs
Normal file
128
AutoWorkshopView/Forms/FormCreateOrder.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
public partial class FormCreateOrder : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRepairLogic _repairLogic;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> Logger, IRepairLogic RepairLogic, IOrderLogic OrderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_repairLogic = RepairLogic;
|
||||
_orderLogic = OrderLogic;
|
||||
}
|
||||
|
||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка ремонтов для заказа");
|
||||
|
||||
try
|
||||
{
|
||||
var List = _repairLogic.ReadList(null);
|
||||
if (List != null)
|
||||
{
|
||||
RepairComboBox.DisplayMember = "RepairName";
|
||||
RepairComboBox.ValueMember = "Id";
|
||||
RepairComboBox.DataSource = List;
|
||||
RepairComboBox.SelectedItem = null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Ремонты загружены");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки ремонтов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CalcSum()
|
||||
{
|
||||
if (RepairComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(RepairComboBox.SelectedValue);
|
||||
var Repair = _repairLogic.ReadElement(new RepairSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
int Count = Convert.ToInt32(CountTextBox.Text);
|
||||
|
||||
SumTextBox.Text = Math.Round(Count * (Repair?.Price ?? 0), 2).ToString();
|
||||
|
||||
_logger.LogInformation("Расчет суммы заказа");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CountTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (RepairComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Создание заказа");
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
RepairId = Convert.ToInt32(RepairComboBox.SelectedValue),
|
||||
Count = Convert.ToInt32(CountTextBox.Text),
|
||||
Sum = Convert.ToDouble(SumTextBox.Text)
|
||||
});
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void RepairComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
}
|
||||
}
|
120
AutoWorkshopView/Forms/FormCreateOrder.resx
Normal file
120
AutoWorkshopView/Forms/FormCreateOrder.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
227
AutoWorkshopView/Forms/FormRepair.Designer.cs
generated
Normal file
227
AutoWorkshopView/Forms/FormRepair.Designer.cs
generated
Normal file
@ -0,0 +1,227 @@
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
partial class FormRepair
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
NameLabel = new Label();
|
||||
PriceLabel = new Label();
|
||||
NameTextBox = new TextBox();
|
||||
PriceTextBox = new TextBox();
|
||||
ComponentsGroupBox = new GroupBox();
|
||||
RefreshButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
UpdateButton = new Button();
|
||||
AddButton = new Button();
|
||||
DataGridView = new DataGridView();
|
||||
IdColumn = new DataGridViewTextBoxColumn();
|
||||
ComponentNameColumn = new DataGridViewTextBoxColumn();
|
||||
CountColumn = new DataGridViewTextBoxColumn();
|
||||
SaveButton = new Button();
|
||||
CancelButton = new Button();
|
||||
ComponentsGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// NameLabel
|
||||
//
|
||||
NameLabel.AutoSize = true;
|
||||
NameLabel.Location = new Point(12, 9);
|
||||
NameLabel.Name = "NameLabel";
|
||||
NameLabel.Size = new Size(59, 15);
|
||||
NameLabel.TabIndex = 0;
|
||||
NameLabel.Text = "Название";
|
||||
//
|
||||
// PriceLabel
|
||||
//
|
||||
PriceLabel.AutoSize = true;
|
||||
PriceLabel.Location = new Point(12, 35);
|
||||
PriceLabel.Name = "PriceLabel";
|
||||
PriceLabel.Size = new Size(35, 15);
|
||||
PriceLabel.TabIndex = 1;
|
||||
PriceLabel.Text = "Цена";
|
||||
//
|
||||
// NameTextBox
|
||||
//
|
||||
NameTextBox.Location = new Point(77, 6);
|
||||
NameTextBox.Name = "NameTextBox";
|
||||
NameTextBox.Size = new Size(237, 23);
|
||||
NameTextBox.TabIndex = 2;
|
||||
//
|
||||
// PriceTextBox
|
||||
//
|
||||
PriceTextBox.Location = new Point(77, 32);
|
||||
PriceTextBox.Name = "PriceTextBox";
|
||||
PriceTextBox.ReadOnly = true;
|
||||
PriceTextBox.Size = new Size(100, 23);
|
||||
PriceTextBox.TabIndex = 3;
|
||||
//
|
||||
// ComponentsGroupBox
|
||||
//
|
||||
ComponentsGroupBox.Controls.Add(RefreshButton);
|
||||
ComponentsGroupBox.Controls.Add(DeleteButton);
|
||||
ComponentsGroupBox.Controls.Add(UpdateButton);
|
||||
ComponentsGroupBox.Controls.Add(AddButton);
|
||||
ComponentsGroupBox.Controls.Add(DataGridView);
|
||||
ComponentsGroupBox.Location = new Point(12, 64);
|
||||
ComponentsGroupBox.Name = "ComponentsGroupBox";
|
||||
ComponentsGroupBox.Size = new Size(582, 287);
|
||||
ComponentsGroupBox.TabIndex = 4;
|
||||
ComponentsGroupBox.TabStop = false;
|
||||
ComponentsGroupBox.Text = "Компоненты";
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
RefreshButton.Location = new Point(481, 109);
|
||||
RefreshButton.Name = "RefreshButton";
|
||||
RefreshButton.Size = new Size(75, 23);
|
||||
RefreshButton.TabIndex = 4;
|
||||
RefreshButton.Text = "Обновить";
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += RefreshButton_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(481, 80);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(75, 23);
|
||||
DeleteButton.TabIndex = 3;
|
||||
DeleteButton.Text = "Удалить";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += DeleteButton_Click;
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
UpdateButton.Location = new Point(481, 51);
|
||||
UpdateButton.Name = "UpdateButton";
|
||||
UpdateButton.Size = new Size(75, 23);
|
||||
UpdateButton.TabIndex = 2;
|
||||
UpdateButton.Text = "Изменить";
|
||||
UpdateButton.UseVisualStyleBackColor = true;
|
||||
UpdateButton.Click += UpdateButton_Click;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(481, 22);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(75, 23);
|
||||
AddButton.TabIndex = 1;
|
||||
AddButton.Text = "Добавить";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += AddButton_Click;
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, ComponentNameColumn, CountColumn });
|
||||
DataGridView.Location = new Point(6, 22);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.RowHeadersWidth = 51;
|
||||
DataGridView.Size = new Size(442, 259);
|
||||
DataGridView.TabIndex = 0;
|
||||
//
|
||||
// IdColumn
|
||||
//
|
||||
IdColumn.HeaderText = "Column1";
|
||||
IdColumn.MinimumWidth = 6;
|
||||
IdColumn.Name = "IdColumn";
|
||||
IdColumn.Visible = false;
|
||||
IdColumn.Width = 6;
|
||||
//
|
||||
// ComponentNameColumn
|
||||
//
|
||||
ComponentNameColumn.HeaderText = "Компонент";
|
||||
ComponentNameColumn.MinimumWidth = 6;
|
||||
ComponentNameColumn.Name = "ComponentNameColumn";
|
||||
ComponentNameColumn.Width = 300;
|
||||
//
|
||||
// CountColumn
|
||||
//
|
||||
CountColumn.HeaderText = "Количество";
|
||||
CountColumn.MinimumWidth = 6;
|
||||
CountColumn.Name = "CountColumn";
|
||||
CountColumn.Width = 125;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(438, 363);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(75, 23);
|
||||
SaveButton.TabIndex = 5;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(519, 363);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 6;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormRepair
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(606, 398);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(ComponentsGroupBox);
|
||||
Controls.Add(PriceTextBox);
|
||||
Controls.Add(NameTextBox);
|
||||
Controls.Add(PriceLabel);
|
||||
Controls.Add(NameLabel);
|
||||
Name = "FormRepair";
|
||||
Text = "Ремонт";
|
||||
Load += FormRepair_Load;
|
||||
ComponentsGroupBox.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label NameLabel;
|
||||
private Label PriceLabel;
|
||||
private TextBox NameTextBox;
|
||||
private TextBox PriceTextBox;
|
||||
private GroupBox ComponentsGroupBox;
|
||||
private Button RefreshButton;
|
||||
private Button DeleteButton;
|
||||
private Button UpdateButton;
|
||||
private Button AddButton;
|
||||
private DataGridView DataGridView;
|
||||
private DataGridViewTextBoxColumn IdColumn;
|
||||
private DataGridViewTextBoxColumn ComponentNameColumn;
|
||||
private DataGridViewTextBoxColumn CountColumn;
|
||||
private Button SaveButton;
|
||||
private Button CancelButton;
|
||||
}
|
||||
}
|
236
AutoWorkshopView/Forms/FormRepair.cs
Normal file
236
AutoWorkshopView/Forms/FormRepair.cs
Normal file
@ -0,0 +1,236 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
public partial class FormRepair : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IRepairLogic _logic;
|
||||
|
||||
private int? _id;
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)> _repairComponents;
|
||||
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormRepair(ILogger<FormRepair> Logger, IRepairLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = Logger;
|
||||
_logic = Logic;
|
||||
_repairComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
}
|
||||
|
||||
private void FormRepair_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка ремонта");
|
||||
|
||||
try
|
||||
{
|
||||
var View = _logic.ReadElement(new RepairSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
|
||||
if (View != null)
|
||||
{
|
||||
NameTextBox.Text = View.RepairName;
|
||||
PriceTextBox.Text = View.Price.ToString();
|
||||
|
||||
_repairComponents = View.RepairComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки ремонта");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка компонентов ремонта");
|
||||
|
||||
try
|
||||
{
|
||||
if (_repairComponents != null)
|
||||
{
|
||||
DataGridView.Rows.Clear();
|
||||
foreach (var Comp in _repairComponents)
|
||||
{
|
||||
DataGridView.Rows.Add(new object[] { Comp.Key, Comp.Value.Item1.ComponentName, Comp.Value.Item2 });
|
||||
}
|
||||
|
||||
PriceTextBox.Text = CalcPrice().ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов ремонта");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent));
|
||||
|
||||
if (Service is FormRepairComponent Form)
|
||||
{
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (Form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", Form.ComponentModel.ComponentName, Form.Count);
|
||||
|
||||
if (_repairComponents.ContainsKey(Form.Id))
|
||||
{
|
||||
_repairComponents[Form.Id] = (Form.ComponentModel, Form.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repairComponents.Add(Form.Id, (Form.ComponentModel, Form.Count));
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent));
|
||||
if (service is FormRepairComponent Form)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
|
||||
Form.Id = id;
|
||||
Form.Count = _repairComponents[id].Item2;
|
||||
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (Form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", Form.ComponentModel.ComponentName, Form.Count);
|
||||
_repairComponents[Form.Id] = (Form.ComponentModel, Form.Count);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_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));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(NameTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(PriceTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_repairComponents == null || _repairComponents.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение ремонта");
|
||||
|
||||
try
|
||||
{
|
||||
var Мodel = new RepairBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
RepairName = NameTextBox.Text,
|
||||
Price = Convert.ToDouble(PriceTextBox.Text),
|
||||
RepairComponents = _repairComponents
|
||||
};
|
||||
|
||||
var OperationResult = _id.HasValue ? _logic.Update(Мodel) : _logic.Create(Мodel);
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения ремонта");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private double CalcPrice()
|
||||
{
|
||||
double Price = 0;
|
||||
|
||||
foreach (var Elem in _repairComponents)
|
||||
{
|
||||
Price += ((Elem.Value.Item1?.Cost ?? 0) * Elem.Value.Item2);
|
||||
}
|
||||
|
||||
return Math.Round(Price * 1.1, 2);
|
||||
}
|
||||
}
|
||||
}
|
120
AutoWorkshopView/Forms/FormRepair.resx
Normal file
120
AutoWorkshopView/Forms/FormRepair.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
119
AutoWorkshopView/Forms/FormRepairComponent.Designer.cs
generated
Normal file
119
AutoWorkshopView/Forms/FormRepairComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
partial class FormRepairComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
ComponentLabel = new Label();
|
||||
CountLabel = new Label();
|
||||
CountTextBox = new TextBox();
|
||||
ComboBox = new ComboBox();
|
||||
SaveButton = new Button();
|
||||
CancelButton = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ComponentLabel
|
||||
//
|
||||
ComponentLabel.AutoSize = true;
|
||||
ComponentLabel.Location = new Point(14, 15);
|
||||
ComponentLabel.Name = "ComponentLabel";
|
||||
ComponentLabel.Size = new Size(72, 15);
|
||||
ComponentLabel.TabIndex = 0;
|
||||
ComponentLabel.Text = "Компонент:";
|
||||
//
|
||||
// CountLabel
|
||||
//
|
||||
CountLabel.AutoSize = true;
|
||||
CountLabel.Location = new Point(14, 46);
|
||||
CountLabel.Name = "CountLabel";
|
||||
CountLabel.Size = new Size(75, 15);
|
||||
CountLabel.TabIndex = 1;
|
||||
CountLabel.Text = "Количество:";
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
CountTextBox.Location = new Point(95, 43);
|
||||
CountTextBox.Name = "CountTextBox";
|
||||
CountTextBox.Size = new Size(292, 23);
|
||||
CountTextBox.TabIndex = 2;
|
||||
//
|
||||
// ComboBox
|
||||
//
|
||||
ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
ComboBox.FormattingEnabled = true;
|
||||
ComboBox.Location = new Point(95, 12);
|
||||
ComboBox.Name = "ComboBox";
|
||||
ComboBox.Size = new Size(292, 23);
|
||||
ComboBox.TabIndex = 3;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(231, 81);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(75, 23);
|
||||
SaveButton.TabIndex = 4;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += ButtonSave_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(312, 81);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 5;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormRepairComponent
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(407, 120);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(ComboBox);
|
||||
Controls.Add(CountTextBox);
|
||||
Controls.Add(CountLabel);
|
||||
Controls.Add(ComponentLabel);
|
||||
Name = "FormRepairComponent";
|
||||
Text = "Компонент ремонта";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label ComponentLabel;
|
||||
private Label CountLabel;
|
||||
private TextBox CountTextBox;
|
||||
private ComboBox ComboBox;
|
||||
private Button SaveButton;
|
||||
private Button CancelButton;
|
||||
}
|
||||
}
|
89
AutoWorkshopView/Forms/FormRepairComponent.cs
Normal file
89
AutoWorkshopView/Forms/FormRepairComponent.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
public partial class FormRepairComponent : Form
|
||||
{
|
||||
private readonly List<ComponentViewModel>? _list;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(ComboBox.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
ComboBox.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IComponentModel? ComponentModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var Elem in _list)
|
||||
{
|
||||
if (Elem.Id == Id)
|
||||
{
|
||||
return Elem;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return Convert.ToInt32(CountTextBox.Text); }
|
||||
set { CountTextBox.Text = value.ToString(); }
|
||||
}
|
||||
|
||||
public FormRepairComponent(IComponentLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_list = Logic.ReadList(null);
|
||||
|
||||
if (_list != null)
|
||||
{
|
||||
ComboBox.DisplayMember = "ComponentName";
|
||||
ComboBox.ValueMember = "Id";
|
||||
ComboBox.DataSource = _list;
|
||||
ComboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
AutoWorkshopView/Forms/FormRepairComponent.resx
Normal file
120
AutoWorkshopView/Forms/FormRepairComponent.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
113
AutoWorkshopView/Forms/FormRepairs.Designer.cs
generated
Normal file
113
AutoWorkshopView/Forms/FormRepairs.Designer.cs
generated
Normal file
@ -0,0 +1,113 @@
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
partial class FormRepairs
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
DataGridView = new DataGridView();
|
||||
AddButton = new Button();
|
||||
UpdateButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
RefreshButton = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Location = new Point(12, 12);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.RowHeadersWidth = 51;
|
||||
DataGridView.Size = new Size(379, 426);
|
||||
DataGridView.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(397, 12);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(148, 29);
|
||||
AddButton.TabIndex = 1;
|
||||
AddButton.Text = "Добавить";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += AddButton_Click;
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
UpdateButton.Location = new Point(397, 47);
|
||||
UpdateButton.Name = "UpdateButton";
|
||||
UpdateButton.Size = new Size(148, 29);
|
||||
UpdateButton.TabIndex = 2;
|
||||
UpdateButton.Text = "Изменить";
|
||||
UpdateButton.UseVisualStyleBackColor = true;
|
||||
UpdateButton.Click += UpdateButton_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(397, 82);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(148, 29);
|
||||
DeleteButton.TabIndex = 3;
|
||||
DeleteButton.Text = "Удалить";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += DeleteButton_Click;
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
RefreshButton.Location = new Point(397, 117);
|
||||
RefreshButton.Name = "RefreshButton";
|
||||
RefreshButton.Size = new Size(148, 29);
|
||||
RefreshButton.TabIndex = 4;
|
||||
RefreshButton.Text = "Обновить";
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += RefreshButton_Click;
|
||||
//
|
||||
// FormRepairs
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(557, 450);
|
||||
Controls.Add(RefreshButton);
|
||||
Controls.Add(DeleteButton);
|
||||
Controls.Add(UpdateButton);
|
||||
Controls.Add(AddButton);
|
||||
Controls.Add(DataGridView);
|
||||
Name = "FormRepairs";
|
||||
Text = "Ремонты";
|
||||
Load += FormRepairs_Load;
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView DataGridView;
|
||||
private Button AddButton;
|
||||
private Button UpdateButton;
|
||||
private Button DeleteButton;
|
||||
private Button RefreshButton;
|
||||
}
|
||||
}
|
114
AutoWorkshopView/Forms/FormRepairs.cs
Normal file
114
AutoWorkshopView/Forms/FormRepairs.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView.Forms
|
||||
{
|
||||
public partial class FormRepairs : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRepairLogic _logic;
|
||||
|
||||
public FormRepairs(ILogger<FormRepairs> Logger, IRepairLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_logic = Logic;
|
||||
}
|
||||
|
||||
private void FormRepairs_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var List = _logic.ReadList(null);
|
||||
|
||||
if (List != null)
|
||||
{
|
||||
DataGridView.DataSource = List;
|
||||
DataGridView.Columns["Id"].Visible = false;
|
||||
DataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
DataGridView.Columns["RepairComponents"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка ремонта");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки ремонта");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormRepair));
|
||||
|
||||
if (Service is FormRepair Form)
|
||||
{
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormRepair));
|
||||
|
||||
if (Service is FormRepair Form)
|
||||
{
|
||||
var Temp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление ремонта");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new RepairBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления ремонта");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
179
AutoWorkshopView/MainForm.Designer.cs
generated
Normal file
179
AutoWorkshopView/MainForm.Designer.cs
generated
Normal file
@ -0,0 +1,179 @@
|
||||
namespace AutoWorkshopView
|
||||
{
|
||||
partial class MainForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
MenuStrip = new MenuStrip();
|
||||
ToolStripMenu = new ToolStripMenuItem();
|
||||
ComponentsStripMenuItem = new ToolStripMenuItem();
|
||||
RepairStripMenuItem = new ToolStripMenuItem();
|
||||
DataGridView = new DataGridView();
|
||||
CreateOrderButton = new Button();
|
||||
TakeInWorkButton = new Button();
|
||||
ReadyButton = new Button();
|
||||
IssuedButton = new Button();
|
||||
RefreshButton = new Button();
|
||||
MenuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// MenuStrip
|
||||
//
|
||||
MenuStrip.ImageScalingSize = new Size(20, 20);
|
||||
MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu });
|
||||
MenuStrip.Location = new Point(0, 0);
|
||||
MenuStrip.Name = "MenuStrip";
|
||||
MenuStrip.Padding = new Padding(5, 2, 0, 2);
|
||||
MenuStrip.Size = new Size(1134, 24);
|
||||
MenuStrip.TabIndex = 0;
|
||||
MenuStrip.Text = "TopMenuStrip";
|
||||
//
|
||||
// ToolStripMenu
|
||||
//
|
||||
ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { ComponentsStripMenuItem, RepairStripMenuItem });
|
||||
ToolStripMenu.Name = "ToolStripMenu";
|
||||
ToolStripMenu.Size = new Size(94, 20);
|
||||
ToolStripMenu.Text = "Справочники";
|
||||
//
|
||||
// ComponentsStripMenuItem
|
||||
//
|
||||
ComponentsStripMenuItem.Name = "ComponentsStripMenuItem";
|
||||
ComponentsStripMenuItem.Size = new Size(145, 22);
|
||||
ComponentsStripMenuItem.Text = "Компоненты";
|
||||
ComponentsStripMenuItem.Click += ComponentsStripMenuItem_Click;
|
||||
//
|
||||
// RepairStripMenuItem
|
||||
//
|
||||
RepairStripMenuItem.Name = "RepairStripMenuItem";
|
||||
RepairStripMenuItem.Size = new Size(145, 22);
|
||||
RepairStripMenuItem.Text = "Ремонты";
|
||||
RepairStripMenuItem.Click += RepairsStripMenuItem_Click;
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Location = new Point(10, 23);
|
||||
DataGridView.Margin = new Padding(3, 2, 3, 2);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.RowHeadersWidth = 51;
|
||||
DataGridView.Size = new Size(881, 305);
|
||||
DataGridView.TabIndex = 1;
|
||||
//
|
||||
// CreateOrderButton
|
||||
//
|
||||
CreateOrderButton.Location = new Point(897, 23);
|
||||
CreateOrderButton.Margin = new Padding(3, 2, 3, 2);
|
||||
CreateOrderButton.Name = "CreateOrderButton";
|
||||
CreateOrderButton.Size = new Size(227, 30);
|
||||
CreateOrderButton.TabIndex = 2;
|
||||
CreateOrderButton.Text = "Создать заказ";
|
||||
CreateOrderButton.UseVisualStyleBackColor = true;
|
||||
CreateOrderButton.Click += CreateOrderButton_Click;
|
||||
//
|
||||
// TakeInWorkButton
|
||||
//
|
||||
TakeInWorkButton.Location = new Point(897, 57);
|
||||
TakeInWorkButton.Margin = new Padding(3, 2, 3, 2);
|
||||
TakeInWorkButton.Name = "TakeInWorkButton";
|
||||
TakeInWorkButton.Size = new Size(227, 30);
|
||||
TakeInWorkButton.TabIndex = 3;
|
||||
TakeInWorkButton.Text = "Отдать заказ в работу";
|
||||
TakeInWorkButton.UseVisualStyleBackColor = true;
|
||||
TakeInWorkButton.Click += TakeOrderInWorkButton_Click;
|
||||
//
|
||||
// ReadyButton
|
||||
//
|
||||
ReadyButton.Location = new Point(897, 91);
|
||||
ReadyButton.Margin = new Padding(3, 2, 3, 2);
|
||||
ReadyButton.Name = "ReadyButton";
|
||||
ReadyButton.Size = new Size(227, 30);
|
||||
ReadyButton.TabIndex = 4;
|
||||
ReadyButton.Text = "Заказ готов";
|
||||
ReadyButton.UseVisualStyleBackColor = true;
|
||||
ReadyButton.Click += OrderReadyButton_Click;
|
||||
//
|
||||
// IssuedButton
|
||||
//
|
||||
IssuedButton.Location = new Point(897, 125);
|
||||
IssuedButton.Margin = new Padding(3, 2, 3, 2);
|
||||
IssuedButton.Name = "IssuedButton";
|
||||
IssuedButton.Size = new Size(227, 30);
|
||||
IssuedButton.TabIndex = 5;
|
||||
IssuedButton.Text = "Заказ выдан";
|
||||
IssuedButton.UseVisualStyleBackColor = true;
|
||||
IssuedButton.Click += OrderDeliveredButton_Click;
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
RefreshButton.Location = new Point(897, 159);
|
||||
RefreshButton.Margin = new Padding(3, 2, 3, 2);
|
||||
RefreshButton.Name = "RefreshButton";
|
||||
RefreshButton.Size = new Size(227, 30);
|
||||
RefreshButton.TabIndex = 6;
|
||||
RefreshButton.Text = "Обновить";
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += RefreshButton_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1134, 338);
|
||||
Controls.Add(RefreshButton);
|
||||
Controls.Add(IssuedButton);
|
||||
Controls.Add(ReadyButton);
|
||||
Controls.Add(TakeInWorkButton);
|
||||
Controls.Add(CreateOrderButton);
|
||||
Controls.Add(DataGridView);
|
||||
Controls.Add(MenuStrip);
|
||||
MainMenuStrip = MenuStrip;
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "MainForm";
|
||||
Text = "Основная форма";
|
||||
Load += MainForm_Load;
|
||||
MenuStrip.ResumeLayout(false);
|
||||
MenuStrip.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MenuStrip MenuStrip;
|
||||
private ToolStripMenuItem ToolStripMenu;
|
||||
private ToolStripMenuItem ComponentsStripMenuItem;
|
||||
private ToolStripMenuItem RepairStripMenuItem;
|
||||
private DataGridView DataGridView;
|
||||
private Button CreateOrderButton;
|
||||
private Button TakeInWorkButton;
|
||||
private Button ReadyButton;
|
||||
private Button IssuedButton;
|
||||
private Button RefreshButton;
|
||||
}
|
||||
}
|
168
AutoWorkshopView/MainForm.cs
Normal file
168
AutoWorkshopView/MainForm.cs
Normal file
@ -0,0 +1,168 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopView.Forms;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
public MainForm(ILogger<MainForm> Logger, IOrderLogic OrderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_orderLogic = OrderLogic;
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
|
||||
try
|
||||
{
|
||||
var List = _orderLogic.ReadList(null);
|
||||
|
||||
if (List != null)
|
||||
{
|
||||
DataGridView.DataSource = List;
|
||||
DataGridView.Columns["RepairId"].Visible = false;
|
||||
DataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateOrderButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
|
||||
if (Service is FormCreateOrder Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void TakeOrderInWorkButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OrderReadyButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OrderDeliveredButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
123
AutoWorkshopView/MainForm.resx
Normal file
123
AutoWorkshopView/MainForm.resx
Normal file
@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="MenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
53
AutoWorkshopView/Program.cs
Normal file
53
AutoWorkshopView/Program.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using AutoWorkshopBusinessLogic.BusinessLogics;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopDatabaseImplement.Implements;
|
||||
using AutoWorkshopView.Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
||||
var Services = new ServiceCollection();
|
||||
ConfigureServices(Services);
|
||||
|
||||
_serviceProvider = Services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection Services)
|
||||
{
|
||||
Services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
|
||||
Services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
Services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
Services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
Services.AddTransient<IRepairLogic, RepairLogic>();
|
||||
|
||||
Services.AddTransient<MainForm>();
|
||||
Services.AddTransient<FormComponent>();
|
||||
Services.AddTransient<FormComponents>();
|
||||
Services.AddTransient<FormCreateOrder>();
|
||||
Services.AddTransient<FormRepair>();
|
||||
Services.AddTransient<FormRepairComponent>();
|
||||
Services.AddTransient<FormRepairs>();
|
||||
}
|
||||
}
|
||||
}
|
15
AutoWorkshopView/nlog.config
Normal file
15
AutoWorkshopView/nlog.config
Normal 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>
|
Loading…
Reference in New Issue
Block a user