first commit
This commit is contained in:
parent
63f5efce0a
commit
3b13a605a2
115
MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ClientLogic.cs
Normal file
115
MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ClientLogic.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.BusinessLogicsContracts;
|
||||||
|
using MotorPlantContracts.SearchModels;
|
||||||
|
using MotorPlantContracts.StoragesContracts;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace MotorPlantBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ClientLogic : IClientLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IClientStorage _clientStorage;
|
||||||
|
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage
|
||||||
|
clientStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_clientStorage = clientStorage;
|
||||||
|
}
|
||||||
|
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Email:{Email}.Id:{ Id}", model?.Email, model?.Id);
|
||||||
|
var list = model == null ? _clientStorage.GetFullList() :
|
||||||
|
_clientStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Email:{Email}.Id:{ Id}", model.Email, model.Id);
|
||||||
|
var element = _clientStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public bool Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_clientStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_clientStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_clientStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ClientFIO))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет ФИО пользователя",
|
||||||
|
nameof(model.ClientFIO));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет логина (почты) пользователя",
|
||||||
|
nameof(model.Email));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Password:{ Password}. Email:{ Email}. Id: { Id}", model.ClientFIO, model.Password, model.Email, model.Id);
|
||||||
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
|
{
|
||||||
|
Email = model.Email
|
||||||
|
});;
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Пользователь с таким же логином (почтой) уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using MotorPlantDataModels.Models;
|
||||||
|
|
||||||
|
namespace MotorPlantContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ClientBindingModel : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,9 @@ namespace MotorPlantContracts.BindingModels
|
|||||||
|
|
||||||
public int EngineId { get; set; }
|
public int EngineId { get; set; }
|
||||||
|
|
||||||
public int Count { get; set; }
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
|
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantContracts.SearchModels;
|
||||||
|
|
||||||
|
namespace MotorPlantContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IClientLogic
|
||||||
|
{
|
||||||
|
List<ClientViewModel>? ReadList(ClientSearchModel? model);
|
||||||
|
ClientViewModel? ReadElement(ClientSearchModel model);
|
||||||
|
bool Create(ClientBindingModel model);
|
||||||
|
bool Update(ClientBindingModel model);
|
||||||
|
bool Delete(ClientBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace MotorPlantContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ClientSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? Email { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,9 @@
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
|
||||||
public DateTime? DateFrom { get; set; }
|
public int? ClientId { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateFrom { get; set; }
|
||||||
|
|
||||||
public DateTime? DateTo { get; set;}
|
public DateTime? DateTo { get; set;}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.SearchModels;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace MotorPlantContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IClientStorage
|
||||||
|
{
|
||||||
|
List<ClientViewModel> GetFullList();
|
||||||
|
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
|
||||||
|
ClientViewModel? GetElement(ClientSearchModel model);
|
||||||
|
ClientViewModel? Insert(ClientBindingModel model);
|
||||||
|
ClientViewModel? Update(ClientBindingModel model);
|
||||||
|
ClientViewModel? Delete(ClientBindingModel model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
17
MotorPlant/MotorPlantContracts/ViewModels/ClientViewModel.cs
Normal file
17
MotorPlant/MotorPlantContracts/ViewModels/ClientViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using MotorPlantDataModels.Models;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace MotorPlantContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ClientViewModel : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("ФИО клиента")]
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Логин (эл. почта)")]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Пароль")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -17,11 +17,16 @@ namespace MotorPlantContracts.ViewModels
|
|||||||
|
|
||||||
public int EngineId { get; set; }
|
public int EngineId { get; set; }
|
||||||
|
|
||||||
[DisplayName("Изделие")]
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Изделие")]
|
||||||
|
|
||||||
public string EngineName { get; set; } = string.Empty;
|
public string EngineName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Количество")]
|
[DisplayName("ФИО клиента")]
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Количество")]
|
||||||
|
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
9
MotorPlant/MotorPlantDataModels/Models/IClientModel.cs
Normal file
9
MotorPlant/MotorPlantDataModels/Models/IClientModel.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace MotorPlantDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IClientModel : IId
|
||||||
|
{
|
||||||
|
string ClientFIO { get; }
|
||||||
|
string Email { get; }
|
||||||
|
string Password { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,8 @@ namespace MotorPlantDataModels.Models
|
|||||||
public interface IOrderModel : IId
|
public interface IOrderModel : IId
|
||||||
{
|
{
|
||||||
int EngineId { get; }
|
int EngineId { get; }
|
||||||
int Count { get; }
|
int ClientId { get; }
|
||||||
|
int Count { get; }
|
||||||
double Sum { get; }
|
double Sum { get; }
|
||||||
OrderStatus Status { get; }
|
OrderStatus Status { get; }
|
||||||
DateTime DateCreate { get; }
|
DateTime DateCreate { get; }
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.SearchModels;
|
||||||
|
using MotorPlantContracts.StoragesContracts;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace MotorPlantDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ClientStorage : IClientStorage
|
||||||
|
{
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new MotorPlantDatabase();
|
||||||
|
return context.Clients
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new MotorPlantDatabase();
|
||||||
|
return context.Clients
|
||||||
|
.Where(x => x.Email.Contains(model.Email))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new MotorPlantDatabase();
|
||||||
|
return context.Clients
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var newClient = Client.Create(model);
|
||||||
|
if (newClient == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new MotorPlantDatabase();
|
||||||
|
context.Clients.Add(newClient);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newClient.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new MotorPlantDatabase();
|
||||||
|
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
client.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new MotorPlantDatabase();
|
||||||
|
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Clients.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using MotorPlantContracts.BindingModels;
|
||||||
using MotorPlantContracts.BindingModels;
|
|
||||||
using MotorPlantContracts.SearchModels;
|
using MotorPlantContracts.SearchModels;
|
||||||
using MotorPlantContracts.StoragesContracts;
|
using MotorPlantContracts.StoragesContracts;
|
||||||
using MotorPlantContracts.ViewModels;
|
using MotorPlantContracts.ViewModels;
|
||||||
@ -10,87 +9,96 @@ namespace MotorPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new MotorPlantDatabase();
|
using var context = new MotorPlantDatabase();
|
||||||
return context.Orders.Include(x => x.Engine).Select(x => x.GetViewModel).ToList();
|
return context.Orders
|
||||||
}
|
.Select(x => AccessEngineStorage(x.GetViewModel))
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
.ToList();
|
||||||
{
|
}
|
||||||
if (!model.Id.HasValue && !model.DateFrom.HasValue)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
return new();
|
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
||||||
}
|
{
|
||||||
using var context = new MotorPlantDatabase();
|
return new();
|
||||||
if (model.DateFrom.HasValue)
|
}
|
||||||
{
|
using var context = new MotorPlantDatabase();
|
||||||
return context.Orders
|
if (model.Id.HasValue)
|
||||||
.Include(x => x.Engine)
|
return context.Orders.Where(x => x.Id == model.Id).Select(x => AccessEngineStorage(x.GetViewModel)).ToList();
|
||||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
if (model.ClientId.HasValue)
|
||||||
.Select(x => x.GetViewModel)
|
return context.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AccessEngineStorage(x.GetViewModel)).ToList();
|
||||||
.ToList();
|
return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).
|
||||||
}
|
Select(x => AccessEngineStorage(x.GetViewModel)).ToList();
|
||||||
return context.Orders
|
}
|
||||||
.Include(x => x.Engine)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
.Where(x => x.Id == model.Id)
|
{
|
||||||
.Select(x => x.GetViewModel)
|
if (!model.Id.HasValue)
|
||||||
.ToList();
|
{
|
||||||
}
|
return null;
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
}
|
||||||
{
|
using var context = new MotorPlantDatabase();
|
||||||
if (!model.Id.HasValue)
|
return AccessEngineStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
||||||
{
|
}
|
||||||
return null;
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
}
|
{
|
||||||
using var context = new MotorPlantDatabase();
|
var newOrder = Order.Create(model);
|
||||||
return context.Orders.Include(x => x.Engine)
|
if (newOrder == null)
|
||||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
{
|
||||||
}
|
return null;
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
}
|
||||||
{
|
using var context = new MotorPlantDatabase();
|
||||||
var newOrder = Order.Create(model);
|
context.Orders.Add(newOrder);
|
||||||
if (newOrder == null)
|
context.SaveChanges();
|
||||||
{
|
return AccessEngineStorage(newOrder.GetViewModel);
|
||||||
return null;
|
}
|
||||||
}
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
using var context = new MotorPlantDatabase();
|
{
|
||||||
context.Orders.Add(newOrder);
|
using var context = new MotorPlantDatabase();
|
||||||
context.SaveChanges();
|
var order = context.Orders.FirstOrDefault(x => x.Id ==
|
||||||
return context.Orders
|
model.Id);
|
||||||
.Include(x => x.Engine)
|
if (order == null)
|
||||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
{
|
||||||
?.GetViewModel;
|
return null;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
order.Update(model);
|
||||||
{
|
context.SaveChanges();
|
||||||
using var context = new MotorPlantDatabase();
|
return AccessEngineStorage(order.GetViewModel);
|
||||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
}
|
||||||
if (order == null)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return null;
|
using var context = new MotorPlantDatabase();
|
||||||
}
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
order.Update(model);
|
if (element != null)
|
||||||
context.SaveChanges();
|
{
|
||||||
return context.Orders
|
context.Orders.Remove(element);
|
||||||
.Include(x => x.Engine)
|
context.SaveChanges();
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
return AccessEngineStorage(element.GetViewModel);
|
||||||
?.GetViewModel;
|
}
|
||||||
}
|
return null;
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
}
|
||||||
{
|
|
||||||
using var context = new MotorPlantDatabase();
|
public static OrderViewModel AccessEngineStorage(OrderViewModel model)
|
||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
{
|
||||||
if (element != null)
|
if (model == null)
|
||||||
{
|
return null;
|
||||||
var deletedElement = context.Orders
|
using var context = new MotorPlantDatabase();
|
||||||
.Include(x => x.Engine)
|
foreach (var Flower in context.Engines)
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
{
|
||||||
?.GetViewModel;
|
if (Flower.Id == model.EngineId)
|
||||||
context.Orders.Remove(element);
|
{
|
||||||
context.SaveChanges();
|
model.EngineName = Flower.EngineName;
|
||||||
return deletedElement;
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
}
|
foreach (var client in context.Clients)
|
||||||
}
|
{
|
||||||
|
if (client.Id == model.ClientId)
|
||||||
|
{
|
||||||
|
model.ClientFIO = client.ClientFIO;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace MotorPlantDatabaseImplement.Migrations
|
namespace MotorPlantDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(MotorPlantDatabase))]
|
[DbContext(typeof(MotorPlantDatabase))]
|
||||||
[Migration("20240404091307_NewMig")]
|
[Migration("20240407191059_NewMigration1")]
|
||||||
partial class NewMig
|
partial class NewMigration1
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -25,6 +25,31 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClientFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Clients");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -99,6 +124,9 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ClientId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<int>("Count")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
@ -145,13 +173,11 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("MotorPlantDatabaseImplement.Models.Engine", "Engine")
|
b.HasOne("MotorPlantDatabaseImplement.Models.Engine", null)
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("EngineId")
|
.HasForeignKey("EngineId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Engine");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
@ -7,11 +7,26 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace MotorPlantDatabaseImplement.Migrations
|
namespace MotorPlantDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class NewMig : Migration
|
public partial class NewMigration1 : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Clients",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
ClientFIO = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Email = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Password = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Components",
|
name: "Components",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -74,6 +89,7 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
EngineId = table.Column<int>(type: "integer", nullable: false),
|
EngineId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
ClientId = table.Column<int>(type: "integer", nullable: false),
|
||||||
Count = table.Column<int>(type: "integer", nullable: false),
|
Count = table.Column<int>(type: "integer", nullable: false),
|
||||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||||
Status = table.Column<int>(type: "integer", nullable: false),
|
Status = table.Column<int>(type: "integer", nullable: false),
|
||||||
@ -110,6 +126,9 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Clients");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "EngineComponents");
|
name: "EngineComponents");
|
||||||
|
|
@ -22,6 +22,31 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClientFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Clients");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -96,6 +121,9 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ClientId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<int>("Count")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
@ -142,13 +170,11 @@ namespace MotorPlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("MotorPlantDatabaseImplement.Models.Engine", "Engine")
|
b.HasOne("MotorPlantDatabaseImplement.Models.Engine", null)
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("EngineId")
|
.HasForeignKey("EngineId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Engine");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("MotorPlantDatabaseImplement.Models.Component", b =>
|
||||||
|
59
MotorPlant/MotorPlantDatabaseImplement/Models/Client.cs
Normal file
59
MotorPlant/MotorPlantDatabaseImplement/Models/Client.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace MotorPlantDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Client : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string ClientFIO { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Email { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public static Client? Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Client Create(ClientViewModel model)
|
||||||
|
{
|
||||||
|
return new Client
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClientFIO = model.ClientFIO;
|
||||||
|
Email = model.Email;
|
||||||
|
Password = model.Password;
|
||||||
|
}
|
||||||
|
public ClientViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ClientFIO = ClientFIO,
|
||||||
|
Email = Email,
|
||||||
|
Password = Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -10,10 +10,11 @@ namespace MotorPlantDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int EngineId { get; private set; }
|
public int EngineId { get; private set; }
|
||||||
|
|
||||||
[Required]
|
public int ClientId { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
@ -27,8 +28,6 @@ namespace MotorPlantDatabaseImplement.Models
|
|||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
public virtual Engine Engine { get; set; }
|
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -39,7 +38,8 @@ namespace MotorPlantDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
EngineId = model.EngineId,
|
EngineId = model.EngineId,
|
||||||
Count = model.Count,
|
ClientId = model.ClientId,
|
||||||
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
@ -61,12 +61,12 @@ namespace MotorPlantDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
EngineId = EngineId,
|
EngineId = EngineId,
|
||||||
Count = Count,
|
ClientId = ClientId,
|
||||||
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
EngineName = Engine.EngineName
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,5 +19,6 @@ namespace MotorPlantDatabaseImplement
|
|||||||
public virtual DbSet<Engine> Engines { get; set; }
|
public virtual DbSet<Engine> Engines { get; set; }
|
||||||
public virtual DbSet<EngineComponent> EngineComponents { get; set; }
|
public virtual DbSet<EngineComponent> EngineComponents { get; set; }
|
||||||
public virtual DbSet<Order> Orders { get; set; }
|
public virtual DbSet<Order> Orders { get; set; }
|
||||||
}
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -21,8 +21,4 @@
|
|||||||
<ProjectReference Include="..\MotorPlantDataModels\MotorPlantDataModels.csproj" />
|
<ProjectReference Include="..\MotorPlantDataModels\MotorPlantDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Implements\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -13,13 +13,17 @@ namespace MotorPlantFileImplement
|
|||||||
|
|
||||||
private readonly string EngineFileName = "Engine.xml";
|
private readonly string EngineFileName = "Engine.xml";
|
||||||
|
|
||||||
public List<Component> Components { get; private set; }
|
private readonly string ClientFileName = "Client.xml";
|
||||||
|
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
|
|
||||||
public List<Engine> Engines { get; private set; }
|
public List<Engine> Engines { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public List<Client> Clients { get; private set; }
|
||||||
|
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
{
|
{
|
||||||
@ -33,14 +37,17 @@ namespace MotorPlantFileImplement
|
|||||||
|
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
|
||||||
private DataFileSingleton()
|
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||||
|
|
||||||
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Engines = LoadData(EngineFileName, "Engine", x => Engine.Create(x)!)!;
|
Engines = LoadData(EngineFileName, "Engine", x => Engine.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
}
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.SearchModels;
|
||||||
|
using MotorPlantContracts.StoragesContracts;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantFileImplement.Models;
|
||||||
|
|
||||||
|
namespace MotorPlantFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ClientStorage : IClientStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ClientStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Clients
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Clients
|
||||||
|
.Where(x => x.Email.Contains(model.Email))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Clients
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newClient = Client.Create(model);
|
||||||
|
if (newClient == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Clients.Add(newClient);
|
||||||
|
source.SaveClients();
|
||||||
|
return newClient.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var client = source.Clients.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
client.Update(model);
|
||||||
|
source.SaveClients();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Clients.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Clients.Remove(element);
|
||||||
|
source.SaveClients();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,82 +13,76 @@ namespace MotorPlantFileImplement.Implements
|
|||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
private readonly DataFileSingleton source;
|
private readonly DataFileSingleton source;
|
||||||
|
public OrderStorage()
|
||||||
public OrderStorage()
|
{
|
||||||
{
|
source = DataFileSingleton.GetInstance();
|
||||||
source = DataFileSingleton.GetInstance();
|
}
|
||||||
}
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||||
{
|
}
|
||||||
if (!model.Id.HasValue)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
return null;
|
if (model.Id.HasValue)
|
||||||
}
|
return source.Orders.Where(x => x.Id == model.Id)
|
||||||
return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue && !model.DateFrom.HasValue || !model.DateTo.HasValue)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
return source.Orders
|
|
||||||
.Where(x => x.Id == model.Id || (model.DateTo >= x.DateCreate && model.DateFrom <= x.DateCreate))
|
|
||||||
.Select(x => GetViewModel(x))
|
.Select(x => GetViewModel(x))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
if (model.ClientId.HasValue)
|
||||||
|
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList();
|
||||||
|
return source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).
|
||||||
|
Select(x => GetViewModel(x)).ToList();
|
||||||
}
|
}
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
public List<OrderViewModel> GetFullList()
|
{
|
||||||
{
|
if (!model.Id.HasValue)
|
||||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
{
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
|
||||||
{
|
}
|
||||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
var newOrder = Order.Create(model);
|
{
|
||||||
if (newOrder == null)
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
{
|
var newOrder = Order.Create(model);
|
||||||
return null;
|
if (newOrder == null)
|
||||||
}
|
{
|
||||||
source.Orders.Add(newOrder);
|
return null;
|
||||||
source.SaveOrders();
|
}
|
||||||
return GetViewModel(newOrder);
|
source.Orders.Add(newOrder);
|
||||||
}
|
source.SaveOrders();
|
||||||
|
return newOrder.GetViewModel;
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
}
|
||||||
{
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
{
|
||||||
if (order == null)
|
var component = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
{
|
if (component == null)
|
||||||
return null;
|
{
|
||||||
}
|
return null;
|
||||||
order.Update(model);
|
}
|
||||||
source.SaveOrders();
|
component.Update(model);
|
||||||
return GetViewModel(order);
|
source.SaveOrders();
|
||||||
}
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
return null;
|
source.Orders.Remove(element);
|
||||||
}
|
source.SaveOrders();
|
||||||
order.Update(model);
|
return element.GetViewModel;
|
||||||
source.SaveOrders();
|
}
|
||||||
return GetViewModel(order);
|
return null;
|
||||||
}
|
}
|
||||||
|
private OrderViewModel GetViewModel(Order order)
|
||||||
private OrderViewModel GetViewModel(Order order)
|
{
|
||||||
{
|
var viewModel = order.GetViewModel;
|
||||||
var viewModel = order.GetViewModel;
|
var flower = source.Engines.FirstOrDefault(x => x.Id == order.EngineId);
|
||||||
var engine = source.Engines.FirstOrDefault(x => x.Id == order.EngineId);
|
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
||||||
viewModel.EngineName = engine?.EngineName;
|
viewModel.EngineName = flower?.EngineName;
|
||||||
return viewModel;
|
viewModel.ClientFIO = client?.ClientFIO;
|
||||||
}
|
return viewModel;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
66
MotorPlant/MotorPlantFileImplement/Models/Client.cs
Normal file
66
MotorPlant/MotorPlantFileImplement/Models/Client.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace MotorPlantFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Client : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ClientFIO { get; private set; } = string.Empty;
|
||||||
|
public string Email { get; private set; } = string.Empty;
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public static Client? Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Client? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ClientFIO = element.Element("ClientFIO")!.Value,
|
||||||
|
Email = element.Element("Email")!.Value,
|
||||||
|
Password = element.Element("Password")!.Value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClientFIO = model.ClientFIO;
|
||||||
|
Email = model.Email;
|
||||||
|
Password = model.Password;
|
||||||
|
}
|
||||||
|
public ClientViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ClientFIO = ClientFIO,
|
||||||
|
Email = Email,
|
||||||
|
Password = Password,
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Client",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ClientFIO", ClientFIO),
|
||||||
|
new XElement("Email", Email),
|
||||||
|
new XElement("Password", Password));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,8 @@ namespace MotorPlantFileImplement.Models
|
|||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int EngineId { get; private set; }
|
public int EngineId { get; private set; }
|
||||||
public int Count { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
@ -25,6 +26,7 @@ namespace MotorPlantFileImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
EngineId = model.EngineId,
|
EngineId = model.EngineId,
|
||||||
|
ClientId = model.ClientId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -42,7 +44,8 @@ namespace MotorPlantFileImplement.Models
|
|||||||
{
|
{
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
EngineId = Convert.ToInt32(element.Element("EngineId")!.Value),
|
EngineId = Convert.ToInt32(element.Element("EngineId")!.Value),
|
||||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||||
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
||||||
};
|
};
|
||||||
@ -63,14 +66,22 @@ namespace MotorPlantFileImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Status = model.Status;
|
Id = model.Id;
|
||||||
DateImplement = model.DateImplement;
|
EngineId = model.EngineId;
|
||||||
}
|
ClientId = model.ClientId;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
EngineId = EngineId,
|
EngineId = EngineId,
|
||||||
Count = Count,
|
ClientId = ClientId,
|
||||||
|
|
||||||
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
@ -79,7 +90,8 @@ namespace MotorPlantFileImplement.Models
|
|||||||
public XElement GetXElement => new("Order",
|
public XElement GetXElement => new("Order",
|
||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
new XElement("EngineId", EngineId),
|
new XElement("EngineId", EngineId),
|
||||||
new XElement("Count", Count.ToString()),
|
new XElement("ClientId", ClientId.ToString()),
|
||||||
|
new XElement("Count", Count.ToString()),
|
||||||
new XElement("Sum", Sum.ToString()),
|
new XElement("Sum", Sum.ToString()),
|
||||||
new XElement("Status", Status.ToString()),
|
new XElement("Status", Status.ToString()),
|
||||||
new XElement("DateCreate", DateCreate.ToString()),
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
@ -12,14 +12,17 @@ namespace MotorPlantListImplement
|
|||||||
|
|
||||||
public List<Engine> Engines { get; set; }
|
public List<Engine> Engines { get; set; }
|
||||||
|
|
||||||
private DataListSingleton()
|
public List<Client> Clients { get; set; }
|
||||||
|
|
||||||
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Engines = new List<Engine>();
|
Engines = new List<Engine>();
|
||||||
}
|
Clients = new List<Client>();
|
||||||
|
}
|
||||||
|
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (_instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
|
103
MotorPlant/MotorPlantListImplement/Implements/ClientStorage.cs
Normal file
103
MotorPlant/MotorPlantListImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.SearchModels;
|
||||||
|
using MotorPlantContracts.StoragesContracts;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantListImplement.Models;
|
||||||
|
|
||||||
|
namespace MotorPlantListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ClientStorage : IClientStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ClientStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ClientViewModel>();
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
result.Add(client.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<ClientViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (client.Email.Contains(model.Email))
|
||||||
|
{
|
||||||
|
result.Add(client.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.Email) &&
|
||||||
|
client.Email == model.Email) ||
|
||||||
|
(model.Id.HasValue && client.Id == model.Id))
|
||||||
|
{
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (model.Id <= client.Id)
|
||||||
|
{
|
||||||
|
model.Id = client.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newClient = Client.Create(model);
|
||||||
|
if (newClient == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Clients.Add(newClient);
|
||||||
|
return newClient.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (client.Id == model.Id)
|
||||||
|
{
|
||||||
|
client.Update(model);
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Clients.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Clients[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Clients[i];
|
||||||
|
_source.Clients.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -14,109 +14,124 @@ namespace MotorPlantListImplement.Implements
|
|||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public OrderStorage()
|
public OrderStorage()
|
||||||
{
|
{
|
||||||
_source = DataListSingleton.GetInstance();
|
_source = DataListSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
var result = new List<OrderViewModel>();
|
||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
result.Add(AttachEngineName(order.GetViewModel));
|
result.Add(AttachNames(order.GetViewModel));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
var result = new List<OrderViewModel>();
|
||||||
if (model == null || !model.Id.HasValue)
|
if (model == null || !model.Id.HasValue)
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
foreach (var order in _source.Orders)
|
if (model.ClientId.HasValue)
|
||||||
{
|
{
|
||||||
if (order.Id == model.Id || (model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo))
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
result.Add(AttachEngineName(order.GetViewModel));
|
if (order.Id == model.Id && order.ClientId == model.ClientId)
|
||||||
}
|
{
|
||||||
}
|
result.Add(AttachNames(order.GetViewModel));
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
return result;
|
||||||
{
|
}
|
||||||
if (!model.Id.HasValue)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
return null;
|
if (order.Id == model.Id && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||||
}
|
{
|
||||||
foreach (var order in _source.Orders)
|
result.Add(AttachNames(order.GetViewModel));
|
||||||
{
|
}
|
||||||
if (model.Id.HasValue && order.Id == model.Id)
|
}
|
||||||
{
|
return result;
|
||||||
return AttachEngineName(order.GetViewModel);
|
}
|
||||||
}
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
}
|
{
|
||||||
return null;
|
if (!model.Id.HasValue)
|
||||||
}
|
{
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
return null;
|
||||||
{
|
}
|
||||||
model.Id = 1;
|
foreach (var order in _source.Orders)
|
||||||
foreach (var order in _source.Orders)
|
{
|
||||||
{
|
if (model.Id.HasValue && order.Id == model.Id)
|
||||||
if (model.Id <= order.Id)
|
{
|
||||||
{
|
return AttachNames(order.GetViewModel);
|
||||||
model.Id = order.Id + 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
var newOrder = Order.Create(model);
|
}
|
||||||
if (newOrder == null)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return null;
|
model.Id = 1;
|
||||||
}
|
foreach (var order in _source.Orders)
|
||||||
_source.Orders.Add(newOrder);
|
{
|
||||||
return AttachEngineName(newOrder.GetViewModel);
|
if (model.Id <= order.Id)
|
||||||
}
|
{
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
model.Id = order.Id + 1;
|
||||||
{
|
}
|
||||||
foreach (var order in _source.Orders)
|
}
|
||||||
{
|
var newOrder = Order.Create(model);
|
||||||
if (order.Id == model.Id)
|
if (newOrder == null)
|
||||||
{
|
{
|
||||||
order.Update(model);
|
return null;
|
||||||
return AttachEngineName(order.GetViewModel);
|
}
|
||||||
}
|
_source.Orders.Add(newOrder);
|
||||||
}
|
return AttachNames(newOrder.GetViewModel);
|
||||||
return null;
|
}
|
||||||
}
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
{
|
||||||
{
|
foreach (var order in _source.Orders)
|
||||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
{
|
||||||
{
|
if (order.Id == model.Id)
|
||||||
if (_source.Orders[i].Id == model.Id)
|
{
|
||||||
{
|
order.Update(model);
|
||||||
var element = _source.Orders[i];
|
return AttachNames(order.GetViewModel);
|
||||||
_source.Orders.RemoveAt(i);
|
}
|
||||||
return AttachEngineName(element.GetViewModel);
|
}
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
}
|
{
|
||||||
private OrderViewModel AttachEngineName(OrderViewModel model)
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||||
{
|
{
|
||||||
foreach (var Engine in _source.Engines)
|
if (_source.Orders[i].Id == model.Id)
|
||||||
{
|
{
|
||||||
if (Engine.Id == model.EngineId)
|
var element = _source.Orders[i];
|
||||||
{
|
_source.Orders.RemoveAt(i);
|
||||||
model.EngineName = Engine.EngineName;
|
return AttachNames(element.GetViewModel);
|
||||||
return model;
|
}
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
return model;
|
}
|
||||||
}
|
private OrderViewModel AttachNames(OrderViewModel model)
|
||||||
}
|
{
|
||||||
|
foreach (var engine in _source.Engines)
|
||||||
|
{
|
||||||
|
if (engine.Id == model.EngineId)
|
||||||
|
{
|
||||||
|
model.EngineName = engine.EngineName;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (client.Id == model.ClientId)
|
||||||
|
{
|
||||||
|
model.ClientFIO = client.ClientFIO;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
45
MotorPlant/MotorPlantListImplement/Models/Client.cs
Normal file
45
MotorPlant/MotorPlantListImplement/Models/Client.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.ViewModels;
|
||||||
|
using MotorPlantDataModels.Models;
|
||||||
|
|
||||||
|
namespace MotorPlantListImplement.Models
|
||||||
|
{
|
||||||
|
public class Client : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ClientFIO { get; private set; }
|
||||||
|
public string Email { get; private set; }
|
||||||
|
public string Password { get; private set; }
|
||||||
|
public static Client? Create(ClientBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ClientBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClientFIO = model.ClientFIO;
|
||||||
|
Email = model.Email;
|
||||||
|
Password = model.Password;
|
||||||
|
}
|
||||||
|
public ClientViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ClientFIO = ClientFIO,
|
||||||
|
Email = Email,
|
||||||
|
Password = Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,9 @@ namespace MotorPlantListImplement.Models
|
|||||||
|
|
||||||
public int EngineId { get; private set; }
|
public int EngineId { get; private set; }
|
||||||
|
|
||||||
public int Count { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
|
||||||
|
public int Count { get; private set; }
|
||||||
|
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
|
|
||||||
@ -36,7 +38,8 @@ namespace MotorPlantListImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
EngineId = model.EngineId,
|
EngineId = model.EngineId,
|
||||||
Count = model.Count,
|
ClientId = model.ClientId,
|
||||||
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
@ -49,14 +52,21 @@ namespace MotorPlantListImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Status = model.Status;
|
Id = model.Id;
|
||||||
DateImplement = model.DateImplement;
|
EngineId = model.EngineId;
|
||||||
}
|
ClientId = model.ClientId;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
EngineId = EngineId,
|
EngineId = EngineId,
|
||||||
Count = Count,
|
ClientId = ClientId,
|
||||||
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
|
88
MotorPlant/MotorPlantView/FormClients.Designer.cs
generated
Normal file
88
MotorPlant/MotorPlantView/FormClients.Designer.cs
generated
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
namespace MotorPlantView
|
||||||
|
{
|
||||||
|
partial class FormClients
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
buttonRef = new Button();
|
||||||
|
buttonDel = new Button();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
buttonRef.Location = new Point(413, 46);
|
||||||
|
buttonRef.Name = "buttonRef";
|
||||||
|
buttonRef.Size = new Size(103, 28);
|
||||||
|
buttonRef.TabIndex = 9;
|
||||||
|
buttonRef.Text = "Обновить";
|
||||||
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
buttonRef.Click += buttonRef_Click;
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
buttonDel.Location = new Point(413, 12);
|
||||||
|
buttonDel.Name = "buttonDel";
|
||||||
|
buttonDel.Size = new Size(103, 28);
|
||||||
|
buttonDel.TabIndex = 8;
|
||||||
|
buttonDel.Text = "Удалить";
|
||||||
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonDel.Click += buttonDel_Click;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.BackgroundColor = Color.White;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(12, 12);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowTemplate.Height = 25;
|
||||||
|
dataGridView.Size = new Size(345, 426);
|
||||||
|
dataGridView.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// FormClients
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(528, 450);
|
||||||
|
Controls.Add(buttonRef);
|
||||||
|
Controls.Add(buttonDel);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Name = "FormClients";
|
||||||
|
Text = "Клиенты";
|
||||||
|
Load += FormClients_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonRef;
|
||||||
|
private Button buttonDel;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
79
MotorPlant/MotorPlantView/FormClients.cs
Normal file
79
MotorPlant/MotorPlantView/FormClients.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using MotorPlantContracts.BindingModels;
|
||||||
|
using MotorPlantContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace MotorPlantView
|
||||||
|
{
|
||||||
|
public partial class FormClients : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IClientLogic _logic;
|
||||||
|
public FormClients(ILogger<FormClients> logger, IClientLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormClients_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;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка клиентов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки клиентов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonDel_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 ClientBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления клиента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
MotorPlant/MotorPlantView/FormClients.resx
Normal file
120
MotorPlant/MotorPlantView/FormClients.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>
|
304
MotorPlant/MotorPlantView/FormCreateOrder.Designer.cs
generated
304
MotorPlant/MotorPlantView/FormCreateOrder.Designer.cs
generated
@ -1,151 +1,169 @@
|
|||||||
namespace MotorPlantView.Forms
|
namespace MotorPlantView.Forms
|
||||||
{
|
{
|
||||||
partial class FormCreateOrder
|
partial class FormCreateOrder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
label3 = new Label();
|
label3 = new Label();
|
||||||
textBoxCount = new TextBox();
|
textBoxCount = new TextBox();
|
||||||
comboBoxEngine = new ComboBox();
|
comboBoxEngine = new ComboBox();
|
||||||
textBoxSum = new TextBox();
|
textBoxSum = new TextBox();
|
||||||
buttonSave = new Button();
|
buttonSave = new Button();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
SuspendLayout();
|
label4 = new Label();
|
||||||
//
|
comboBoxClient = new ComboBox();
|
||||||
// label1
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
label1.AutoSize = true;
|
// label1
|
||||||
label1.Location = new Point(22, 16);
|
//
|
||||||
label1.Name = "label1";
|
label1.AutoSize = true;
|
||||||
label1.Size = new Size(71, 20);
|
label1.Location = new Point(19, 12);
|
||||||
label1.TabIndex = 0;
|
label1.Name = "label1";
|
||||||
label1.Text = "Изделие:";
|
label1.Size = new Size(56, 15);
|
||||||
//
|
label1.TabIndex = 0;
|
||||||
// label2
|
label1.Text = "Изделие:";
|
||||||
//
|
//
|
||||||
label2.AutoSize = true;
|
// label2
|
||||||
label2.Location = new Point(22, 59);
|
//
|
||||||
label2.Name = "label2";
|
label2.AutoSize = true;
|
||||||
label2.Size = new Size(93, 20);
|
label2.Location = new Point(19, 77);
|
||||||
label2.TabIndex = 1;
|
label2.Name = "label2";
|
||||||
label2.Text = "Количество:";
|
label2.Size = new Size(75, 15);
|
||||||
//
|
label2.TabIndex = 1;
|
||||||
// label3
|
label2.Text = "Количество:";
|
||||||
//
|
//
|
||||||
label3.AutoSize = true;
|
// label3
|
||||||
label3.Location = new Point(22, 93);
|
//
|
||||||
label3.Name = "label3";
|
label3.AutoSize = true;
|
||||||
label3.Size = new Size(58, 20);
|
label3.Location = new Point(19, 103);
|
||||||
label3.TabIndex = 2;
|
label3.Name = "label3";
|
||||||
label3.Text = "Сумма:";
|
label3.Size = new Size(48, 15);
|
||||||
//
|
label3.TabIndex = 2;
|
||||||
// textBoxCount
|
label3.Text = "Сумма:";
|
||||||
//
|
//
|
||||||
textBoxCount.Location = new Point(118, 55);
|
// textBoxCount
|
||||||
textBoxCount.Margin = new Padding(3, 4, 3, 4);
|
//
|
||||||
textBoxCount.Name = "textBoxCount";
|
textBoxCount.Location = new Point(103, 74);
|
||||||
textBoxCount.Size = new Size(281, 27);
|
textBoxCount.Name = "textBoxCount";
|
||||||
textBoxCount.TabIndex = 3;
|
textBoxCount.Size = new Size(246, 23);
|
||||||
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
textBoxCount.TabIndex = 3;
|
||||||
//
|
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
||||||
// comboBoxEngine
|
//
|
||||||
//
|
// comboBoxEngine
|
||||||
comboBoxEngine.FormattingEnabled = true;
|
//
|
||||||
comboBoxEngine.Location = new Point(118, 13);
|
comboBoxEngine.FormattingEnabled = true;
|
||||||
comboBoxEngine.Margin = new Padding(3, 4, 3, 4);
|
comboBoxEngine.Location = new Point(103, 10);
|
||||||
comboBoxEngine.Name = "comboBoxEngine";
|
comboBoxEngine.Name = "comboBoxEngine";
|
||||||
comboBoxEngine.Size = new Size(281, 28);
|
comboBoxEngine.Size = new Size(246, 23);
|
||||||
comboBoxEngine.TabIndex = 4;
|
comboBoxEngine.TabIndex = 4;
|
||||||
comboBoxEngine.SelectedIndexChanged += ComboBoxEngine_SelectedIndexChanged;
|
comboBoxEngine.SelectedIndexChanged += ComboBoxEngine_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// textBoxSum
|
// textBoxSum
|
||||||
//
|
//
|
||||||
textBoxSum.BackColor = SystemColors.ControlLightLight;
|
textBoxSum.BackColor = SystemColors.ControlLightLight;
|
||||||
textBoxSum.Location = new Point(118, 93);
|
textBoxSum.Location = new Point(103, 103);
|
||||||
textBoxSum.Margin = new Padding(3, 4, 3, 4);
|
textBoxSum.Name = "textBoxSum";
|
||||||
textBoxSum.Name = "textBoxSum";
|
textBoxSum.ReadOnly = true;
|
||||||
textBoxSum.ReadOnly = true;
|
textBoxSum.Size = new Size(246, 23);
|
||||||
textBoxSum.Size = new Size(281, 27);
|
textBoxSum.TabIndex = 5;
|
||||||
textBoxSum.TabIndex = 5;
|
//
|
||||||
//
|
// buttonSave
|
||||||
// buttonSave
|
//
|
||||||
//
|
buttonSave.Location = new Point(150, 134);
|
||||||
buttonSave.Location = new Point(171, 135);
|
buttonSave.Name = "buttonSave";
|
||||||
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
buttonSave.Size = new Size(94, 26);
|
||||||
buttonSave.Name = "buttonSave";
|
buttonSave.TabIndex = 6;
|
||||||
buttonSave.Size = new Size(107, 35);
|
buttonSave.Text = "Сохранить";
|
||||||
buttonSave.TabIndex = 6;
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
buttonSave.Text = "Сохранить";
|
buttonSave.Click += buttonSave_Click;
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonSave.Click += buttonSave_Click;
|
// buttonCancel
|
||||||
//
|
//
|
||||||
// buttonCancel
|
buttonCancel.Location = new Point(249, 134);
|
||||||
//
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Location = new Point(285, 135);
|
buttonCancel.Size = new Size(94, 26);
|
||||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
buttonCancel.TabIndex = 7;
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Text = "Отмена";
|
||||||
buttonCancel.Size = new Size(107, 35);
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
buttonCancel.TabIndex = 7;
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
buttonCancel.Text = "Отмена";
|
//
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
// label4
|
||||||
buttonCancel.Click += buttonCancel_Click;
|
//
|
||||||
//
|
label4.AutoSize = true;
|
||||||
// FormCreateOrder
|
label4.Location = new Point(19, 48);
|
||||||
//
|
label4.Name = "label4";
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
label4.Size = new Size(49, 15);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
label4.TabIndex = 14;
|
||||||
ClientSize = new Size(427, 181);
|
label4.Text = "Клиент:";
|
||||||
Controls.Add(buttonCancel);
|
//
|
||||||
Controls.Add(buttonSave);
|
// comboBoxClient
|
||||||
Controls.Add(textBoxSum);
|
//
|
||||||
Controls.Add(comboBoxEngine);
|
comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
Controls.Add(textBoxCount);
|
comboBoxClient.FormattingEnabled = true;
|
||||||
Controls.Add(label3);
|
comboBoxClient.Location = new Point(99, 45);
|
||||||
Controls.Add(label2);
|
comboBoxClient.Name = "comboBoxClient";
|
||||||
Controls.Add(label1);
|
comboBoxClient.Size = new Size(250, 23);
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
comboBoxClient.TabIndex = 13;
|
||||||
Name = "FormCreateOrder";
|
//
|
||||||
Text = "Заказ";
|
// FormCreateOrder
|
||||||
Load += FormCreateOrder_Load;
|
//
|
||||||
ResumeLayout(false);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
PerformLayout();
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
}
|
ClientSize = new Size(374, 195);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Controls.Add(comboBoxClient);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(textBoxSum);
|
||||||
|
Controls.Add(comboBoxEngine);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(label3);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Name = "FormCreateOrder";
|
||||||
|
Text = "Заказ";
|
||||||
|
Load += FormCreateOrder_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Label label1;
|
private Label label1;
|
||||||
private Label label2;
|
private Label label2;
|
||||||
private Label label3;
|
private Label label3;
|
||||||
private TextBox textBoxCount;
|
private TextBox textBoxCount;
|
||||||
private ComboBox comboBoxEngine;
|
private ComboBox comboBoxEngine;
|
||||||
private TextBox textBoxSum;
|
private TextBox textBoxSum;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
}
|
private Label label4;
|
||||||
|
private ComboBox comboBoxClient;
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,107 +5,127 @@ using MotorPlantContracts.BusinessLogicsContracts;
|
|||||||
|
|
||||||
namespace MotorPlantView.Forms
|
namespace MotorPlantView.Forms
|
||||||
{
|
{
|
||||||
public partial class FormCreateOrder : Form
|
public partial class FormCreateOrder : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IEngineLogic _logicP;
|
private readonly IEngineLogic _logicP;
|
||||||
private readonly IOrderLogic _logicO;
|
private readonly IClientLogic _logicC;
|
||||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IEngineLogic logicP, IOrderLogic logicO)
|
private readonly IOrderLogic _logicO;
|
||||||
{
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, IEngineLogic logicP, IClientLogic logicC, IOrderLogic logicO)
|
||||||
InitializeComponent();
|
{
|
||||||
_logger = logger;
|
InitializeComponent();
|
||||||
_logicP = logicP;
|
_logger = logger;
|
||||||
_logicO = logicO;
|
_logicP = logicP;
|
||||||
}
|
_logicC = logicC;
|
||||||
|
_logicO = logicO;
|
||||||
|
}
|
||||||
|
|
||||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
_logger.LogInformation("Загрузка цветов для заказа");
|
||||||
{
|
try
|
||||||
var list = _logicP.ReadList(null);
|
{
|
||||||
if (list != null)
|
var _list = _logicP.ReadList(null);
|
||||||
{
|
if (_list != null)
|
||||||
comboBoxEngine.DisplayMember = "EngineName";
|
{
|
||||||
comboBoxEngine.ValueMember = "Id";
|
comboBoxEngine.DisplayMember = "EngineName";
|
||||||
comboBoxEngine.DataSource = list;
|
comboBoxEngine.ValueMember = "Id";
|
||||||
comboBoxEngine.SelectedItem = null;
|
comboBoxEngine.DataSource = _list;
|
||||||
_logger.LogInformation("Загрузка изделий для заказа");
|
comboBoxEngine.SelectedItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
_logger.LogError(ex, "Ошибка загрузки цветов для заказа");
|
||||||
}
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
private void CalcSum()
|
_logger.LogInformation("Загрузка клиентов для заказа");
|
||||||
{
|
try
|
||||||
if (comboBoxEngine.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
{
|
||||||
{
|
var _list = _logicC.ReadList(null);
|
||||||
try
|
if (_list != null)
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(comboBoxEngine.SelectedValue);
|
comboBoxClient.DisplayMember = "ClientFIO";
|
||||||
var Engine = _logicP.ReadElement(new EngineSearchModel { Id = id });
|
comboBoxClient.ValueMember = "Id";
|
||||||
int count = Convert.ToInt32(textBoxCount.Text);
|
comboBoxClient.DataSource = _list;
|
||||||
textBoxSum.Text = Math.Round(count * (Engine?.Price ?? 0), 2).ToString();
|
comboBoxClient.SelectedItem = null;
|
||||||
_logger.LogInformation("Расчет суммы заказа");
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
_logger.LogError(ex, "Ошибка загрузки клиентов для заказа");
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
private void CalcSum()
|
||||||
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
{
|
||||||
{
|
if (comboBoxEngine.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
CalcSum();
|
{
|
||||||
}
|
try
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(comboBoxEngine.SelectedValue);
|
||||||
|
var Engine = _logicP.ReadElement(new EngineSearchModel { Id = id });
|
||||||
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
textBoxSum.Text = Math.Round(count * (Engine?.Price ?? 0), 2).ToString();
|
||||||
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
private void ComboBoxEngine_SelectedIndexChanged(object sender, EventArgs e)
|
private void ComboBoxEngine_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CalcSum();
|
CalcSum();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonSave_Click(object sender, EventArgs e)
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (comboBoxEngine.SelectedValue == null)
|
if (comboBoxEngine.SelectedValue == null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Создание заказа");
|
_logger.LogInformation("Создание заказа");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||||
{
|
{
|
||||||
EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue),
|
EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue),
|
||||||
Count = Convert.ToInt32(textBoxCount.Text),
|
Count = Convert.ToInt32(textBoxCount.Text),
|
||||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||||
});
|
});
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка создания заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
_logger.LogError(ex, "Ошибка создания заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCancel_Click(object sender, EventArgs e)
|
private void buttonCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
439
MotorPlant/MotorPlantView/FormMain.Designer.cs
generated
439
MotorPlant/MotorPlantView/FormMain.Designer.cs
generated
@ -1,223 +1,232 @@
|
|||||||
namespace MotorPlantView.Forms
|
namespace MotorPlantView.Forms
|
||||||
{
|
{
|
||||||
partial class FormMain
|
partial class FormMain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
toolStrip1 = new ToolStrip();
|
toolStrip1 = new ToolStrip();
|
||||||
toolStripDropDownButton1 = new ToolStripDropDownButton();
|
toolStripDropDownButton1 = new ToolStripDropDownButton();
|
||||||
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
|
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
ДвигателиToolStripMenuItem = new ToolStripMenuItem();
|
ДвигателиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
списокДвигателейToolStripMenuItem = new ToolStripMenuItem();
|
списокДвигателейToolStripMenuItem = new ToolStripMenuItem();
|
||||||
компонентыПоДвигателямToolStripMenuItem = new ToolStripMenuItem();
|
компонентыПоДвигателямToolStripMenuItem = new ToolStripMenuItem();
|
||||||
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
|
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
|
||||||
buttonCreateOrder = new Button();
|
buttonCreateOrder = new Button();
|
||||||
buttonTakeOrderInWork = new Button();
|
buttonTakeOrderInWork = new Button();
|
||||||
buttonOrderReady = new Button();
|
buttonOrderReady = new Button();
|
||||||
buttonIssuedOrder = new Button();
|
buttonIssuedOrder = new Button();
|
||||||
buttonRef = new Button();
|
buttonRef = new Button();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
toolStrip1.SuspendLayout();
|
клиентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
toolStrip1.SuspendLayout();
|
||||||
SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
//
|
SuspendLayout();
|
||||||
// toolStrip1
|
//
|
||||||
//
|
// toolStrip1
|
||||||
toolStrip1.ImageScalingSize = new Size(20, 20);
|
//
|
||||||
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, отчетыToolStripMenuItem });
|
toolStrip1.ImageScalingSize = new Size(20, 20);
|
||||||
toolStrip1.Location = new Point(0, 0);
|
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, отчетыToolStripMenuItem });
|
||||||
toolStrip1.Name = "toolStrip1";
|
toolStrip1.Location = new Point(0, 0);
|
||||||
toolStrip1.Size = new Size(985, 25);
|
toolStrip1.Name = "toolStrip1";
|
||||||
toolStrip1.TabIndex = 0;
|
toolStrip1.Size = new Size(985, 25);
|
||||||
toolStrip1.Text = "toolStrip1";
|
toolStrip1.TabIndex = 0;
|
||||||
//
|
toolStrip1.Text = "toolStrip1";
|
||||||
// toolStripDropDownButton1
|
//
|
||||||
//
|
// toolStripDropDownButton1
|
||||||
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
//
|
||||||
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem });
|
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||||
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
|
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, клиентыToolStripMenuItem });
|
||||||
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
|
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
|
||||||
toolStripDropDownButton1.Size = new Size(88, 22);
|
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
|
||||||
toolStripDropDownButton1.Text = "Справочник";
|
toolStripDropDownButton1.Size = new Size(88, 22);
|
||||||
//
|
toolStripDropDownButton1.Text = "Справочник";
|
||||||
// КомпонентыToolStripMenuItem
|
//
|
||||||
//
|
// КомпонентыToolStripMenuItem
|
||||||
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
//
|
||||||
КомпонентыToolStripMenuItem.Size = new Size(145, 22);
|
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
||||||
КомпонентыToolStripMenuItem.Text = "Компоненты";
|
КомпонентыToolStripMenuItem.Size = new Size(180, 22);
|
||||||
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
КомпонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
//
|
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
||||||
// ДвигателиToolStripMenuItem
|
//
|
||||||
//
|
// ДвигателиToolStripMenuItem
|
||||||
ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem";
|
//
|
||||||
ДвигателиToolStripMenuItem.Size = new Size(145, 22);
|
ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem";
|
||||||
ДвигателиToolStripMenuItem.Text = "Двигатели";
|
ДвигателиToolStripMenuItem.Size = new Size(180, 22);
|
||||||
ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
|
ДвигателиToolStripMenuItem.Text = "Двигатели";
|
||||||
//
|
ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
|
||||||
// отчетыToolStripMenuItem
|
//
|
||||||
//
|
// отчетыToolStripMenuItem
|
||||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокДвигателейToolStripMenuItem, компонентыПоДвигателямToolStripMenuItem, списокЗаказовToolStripMenuItem });
|
//
|
||||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокДвигателейToolStripMenuItem, компонентыПоДвигателямToolStripMenuItem, списокЗаказовToolStripMenuItem });
|
||||||
отчетыToolStripMenuItem.Size = new Size(60, 25);
|
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
отчетыToolStripMenuItem.Size = new Size(60, 25);
|
||||||
//
|
отчетыToolStripMenuItem.Text = "Отчеты";
|
||||||
// списокДвигателейToolStripMenuItem
|
//
|
||||||
//
|
// списокДвигателейToolStripMenuItem
|
||||||
списокДвигателейToolStripMenuItem.Name = "списокДвигателейToolStripMenuItem";
|
//
|
||||||
списокДвигателейToolStripMenuItem.Size = new Size(228, 22);
|
списокДвигателейToolStripMenuItem.Name = "списокДвигателейToolStripMenuItem";
|
||||||
списокДвигателейToolStripMenuItem.Text = "Список двигателей";
|
списокДвигателейToolStripMenuItem.Size = new Size(228, 22);
|
||||||
списокДвигателейToolStripMenuItem.Click += списокДвигателейToolStripMenuItem_Click;
|
списокДвигателейToolStripMenuItem.Text = "Список двигателей";
|
||||||
//
|
списокДвигателейToolStripMenuItem.Click += списокДвигателейToolStripMenuItem_Click;
|
||||||
// компонентыПоДвигателямToolStripMenuItem
|
//
|
||||||
//
|
// компонентыПоДвигателямToolStripMenuItem
|
||||||
компонентыПоДвигателямToolStripMenuItem.Name = "компонентыПоДвигателямToolStripMenuItem";
|
//
|
||||||
компонентыПоДвигателямToolStripMenuItem.Size = new Size(228, 22);
|
компонентыПоДвигателямToolStripMenuItem.Name = "компонентыПоДвигателямToolStripMenuItem";
|
||||||
компонентыПоДвигателямToolStripMenuItem.Text = "Компоненты по двигателям";
|
компонентыПоДвигателямToolStripMenuItem.Size = new Size(228, 22);
|
||||||
компонентыПоДвигателямToolStripMenuItem.Click += компонентыПоДвигателямToolStripMenuItem_Click;
|
компонентыПоДвигателямToolStripMenuItem.Text = "Компоненты по двигателям";
|
||||||
//
|
компонентыПоДвигателямToolStripMenuItem.Click += компонентыПоДвигателямToolStripMenuItem_Click;
|
||||||
// списокЗаказовToolStripMenuItem
|
//
|
||||||
//
|
// списокЗаказовToolStripMenuItem
|
||||||
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
|
//
|
||||||
списокЗаказовToolStripMenuItem.Size = new Size(228, 22);
|
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
|
||||||
списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
списокЗаказовToolStripMenuItem.Size = new Size(228, 22);
|
||||||
списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click;
|
списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
||||||
//
|
списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click;
|
||||||
// buttonCreateOrder
|
//
|
||||||
//
|
// buttonCreateOrder
|
||||||
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
//
|
||||||
buttonCreateOrder.BackColor = SystemColors.ControlLight;
|
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonCreateOrder.Location = new Point(797, 146);
|
buttonCreateOrder.BackColor = SystemColors.ControlLight;
|
||||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
buttonCreateOrder.Location = new Point(797, 146);
|
||||||
buttonCreateOrder.Size = new Size(178, 30);
|
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||||
buttonCreateOrder.TabIndex = 1;
|
buttonCreateOrder.Size = new Size(178, 30);
|
||||||
buttonCreateOrder.Text = "Создать заказ";
|
buttonCreateOrder.TabIndex = 1;
|
||||||
buttonCreateOrder.UseVisualStyleBackColor = false;
|
buttonCreateOrder.Text = "Создать заказ";
|
||||||
buttonCreateOrder.Click += buttonCreateOrder_Click;
|
buttonCreateOrder.UseVisualStyleBackColor = false;
|
||||||
//
|
buttonCreateOrder.Click += buttonCreateOrder_Click;
|
||||||
// buttonTakeOrderInWork
|
//
|
||||||
//
|
// buttonTakeOrderInWork
|
||||||
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
//
|
||||||
buttonTakeOrderInWork.BackColor = SystemColors.ControlLight;
|
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonTakeOrderInWork.Location = new Point(797, 194);
|
buttonTakeOrderInWork.BackColor = SystemColors.ControlLight;
|
||||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
buttonTakeOrderInWork.Location = new Point(797, 194);
|
||||||
buttonTakeOrderInWork.Size = new Size(178, 30);
|
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||||
buttonTakeOrderInWork.TabIndex = 2;
|
buttonTakeOrderInWork.Size = new Size(178, 30);
|
||||||
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
buttonTakeOrderInWork.TabIndex = 2;
|
||||||
buttonTakeOrderInWork.UseVisualStyleBackColor = false;
|
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
|
buttonTakeOrderInWork.UseVisualStyleBackColor = false;
|
||||||
//
|
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
|
||||||
// buttonOrderReady
|
//
|
||||||
//
|
// buttonOrderReady
|
||||||
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
//
|
||||||
buttonOrderReady.BackColor = SystemColors.ControlLight;
|
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonOrderReady.Location = new Point(797, 242);
|
buttonOrderReady.BackColor = SystemColors.ControlLight;
|
||||||
buttonOrderReady.Name = "buttonOrderReady";
|
buttonOrderReady.Location = new Point(797, 242);
|
||||||
buttonOrderReady.Size = new Size(178, 30);
|
buttonOrderReady.Name = "buttonOrderReady";
|
||||||
buttonOrderReady.TabIndex = 3;
|
buttonOrderReady.Size = new Size(178, 30);
|
||||||
buttonOrderReady.Text = "Заказ готов";
|
buttonOrderReady.TabIndex = 3;
|
||||||
buttonOrderReady.UseVisualStyleBackColor = false;
|
buttonOrderReady.Text = "Заказ готов";
|
||||||
buttonOrderReady.Click += buttonOrderReady_Click;
|
buttonOrderReady.UseVisualStyleBackColor = false;
|
||||||
//
|
buttonOrderReady.Click += buttonOrderReady_Click;
|
||||||
// buttonIssuedOrder
|
//
|
||||||
//
|
// buttonIssuedOrder
|
||||||
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
//
|
||||||
buttonIssuedOrder.BackColor = SystemColors.ControlLight;
|
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonIssuedOrder.Location = new Point(797, 287);
|
buttonIssuedOrder.BackColor = SystemColors.ControlLight;
|
||||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
buttonIssuedOrder.Location = new Point(797, 287);
|
||||||
buttonIssuedOrder.Size = new Size(178, 30);
|
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||||
buttonIssuedOrder.TabIndex = 4;
|
buttonIssuedOrder.Size = new Size(178, 30);
|
||||||
buttonIssuedOrder.Text = "Заказ выдан";
|
buttonIssuedOrder.TabIndex = 4;
|
||||||
buttonIssuedOrder.UseVisualStyleBackColor = false;
|
buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
buttonIssuedOrder.Click += buttonIssuedOrder_Click;
|
buttonIssuedOrder.UseVisualStyleBackColor = false;
|
||||||
//
|
buttonIssuedOrder.Click += buttonIssuedOrder_Click;
|
||||||
// buttonRef
|
//
|
||||||
//
|
// buttonRef
|
||||||
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
//
|
||||||
buttonRef.BackColor = SystemColors.ControlLight;
|
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonRef.Location = new Point(797, 100);
|
buttonRef.BackColor = SystemColors.ControlLight;
|
||||||
buttonRef.Name = "buttonRef";
|
buttonRef.Location = new Point(797, 100);
|
||||||
buttonRef.Size = new Size(178, 30);
|
buttonRef.Name = "buttonRef";
|
||||||
buttonRef.TabIndex = 5;
|
buttonRef.Size = new Size(178, 30);
|
||||||
buttonRef.Text = "Обновить список";
|
buttonRef.TabIndex = 5;
|
||||||
buttonRef.UseVisualStyleBackColor = false;
|
buttonRef.Text = "Обновить список";
|
||||||
buttonRef.Click += buttonRef_Click;
|
buttonRef.UseVisualStyleBackColor = false;
|
||||||
//
|
buttonRef.Click += buttonRef_Click;
|
||||||
// dataGridView
|
//
|
||||||
//
|
// dataGridView
|
||||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
//
|
||||||
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
|
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
|
||||||
dataGridView.Location = new Point(0, 26);
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Location = new Point(0, 26);
|
||||||
dataGridView.ReadOnly = true;
|
dataGridView.Name = "dataGridView";
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.ReadOnly = true;
|
||||||
dataGridView.RowTemplate.Height = 24;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.RowTemplate.Height = 24;
|
||||||
dataGridView.Size = new Size(780, 441);
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView.TabIndex = 6;
|
dataGridView.Size = new Size(780, 441);
|
||||||
//
|
dataGridView.TabIndex = 6;
|
||||||
// FormMain
|
//
|
||||||
//
|
// клиентыToolStripMenuItem
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
//
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
||||||
ClientSize = new Size(985, 467);
|
клиентыToolStripMenuItem.Size = new Size(180, 22);
|
||||||
Controls.Add(dataGridView);
|
клиентыToolStripMenuItem.Text = "Клиенты";
|
||||||
Controls.Add(buttonRef);
|
клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click;
|
||||||
Controls.Add(buttonIssuedOrder);
|
//
|
||||||
Controls.Add(buttonOrderReady);
|
// FormMain
|
||||||
Controls.Add(buttonTakeOrderInWork);
|
//
|
||||||
Controls.Add(buttonCreateOrder);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
Controls.Add(toolStrip1);
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
Name = "FormMain";
|
ClientSize = new Size(985, 467);
|
||||||
Text = "Моторный завод";
|
Controls.Add(dataGridView);
|
||||||
Load += FormMain_Load;
|
Controls.Add(buttonRef);
|
||||||
toolStrip1.ResumeLayout(false);
|
Controls.Add(buttonIssuedOrder);
|
||||||
toolStrip1.PerformLayout();
|
Controls.Add(buttonOrderReady);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
Controls.Add(buttonTakeOrderInWork);
|
||||||
ResumeLayout(false);
|
Controls.Add(buttonCreateOrder);
|
||||||
PerformLayout();
|
Controls.Add(toolStrip1);
|
||||||
}
|
Name = "FormMain";
|
||||||
|
Text = "Моторный завод";
|
||||||
|
Load += FormMain_Load;
|
||||||
|
toolStrip1.ResumeLayout(false);
|
||||||
|
toolStrip1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private ToolStrip toolStrip1;
|
private ToolStrip toolStrip1;
|
||||||
private Button buttonCreateOrder;
|
private Button buttonCreateOrder;
|
||||||
private Button buttonTakeOrderInWork;
|
private Button buttonTakeOrderInWork;
|
||||||
private Button buttonOrderReady;
|
private Button buttonOrderReady;
|
||||||
private Button buttonIssuedOrder;
|
private Button buttonIssuedOrder;
|
||||||
private Button buttonRef;
|
private Button buttonRef;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private ToolStripDropDownButton toolStripDropDownButton1;
|
private ToolStripDropDownButton toolStripDropDownButton1;
|
||||||
private ToolStripMenuItem КомпонентыToolStripMenuItem;
|
private ToolStripMenuItem КомпонентыToolStripMenuItem;
|
||||||
private ToolStripMenuItem ДвигателиToolStripMenuItem;
|
private ToolStripMenuItem ДвигателиToolStripMenuItem;
|
||||||
private ToolStripMenuItem отчетыToolStripMenuItem;
|
private ToolStripMenuItem отчетыToolStripMenuItem;
|
||||||
private ToolStripMenuItem списокДвигателейToolStripMenuItem;
|
private ToolStripMenuItem списокДвигателейToolStripMenuItem;
|
||||||
private ToolStripMenuItem компонентыПоДвигателямToolStripMenuItem;
|
private ToolStripMenuItem компонентыПоДвигателямToolStripMenuItem;
|
||||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
||||||
}
|
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,175 +4,185 @@ using MotorPlantContracts.BusinessLogicsContracts;
|
|||||||
|
|
||||||
namespace MotorPlantView.Forms
|
namespace MotorPlantView.Forms
|
||||||
{
|
{
|
||||||
public partial class FormMain : Form
|
public partial class FormMain : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderLogic _orderLogic;
|
private readonly IOrderLogic _orderLogic;
|
||||||
private readonly IReportLogic _reportLogic;
|
private readonly IReportLogic _reportLogic;
|
||||||
|
|
||||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderLogic = orderLogic;
|
_orderLogic = orderLogic;
|
||||||
_reportLogic = reportLogic;
|
_reportLogic = reportLogic;
|
||||||
}
|
}
|
||||||
private void FormMain_Load(object sender, EventArgs e)
|
private void FormMain_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Загрузка заказов");
|
_logger.LogInformation("Загрузка заказов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _orderLogic.ReadList(null);
|
var list = _orderLogic.ReadList(null);
|
||||||
|
|
||||||
if (list != null)
|
if (list != null)
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = list;
|
dataGridView.DataSource = list;
|
||||||
dataGridView.Columns["EngineId"].Visible = false;
|
dataGridView.Columns["EngineId"].Visible = false;
|
||||||
dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["ClientId"].Visible = false;
|
||||||
}
|
dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
|
|
||||||
_logger.LogInformation("Загрузка заказов");
|
if (service is FormComponents form)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
form.ShowDialog();
|
||||||
{
|
}
|
||||||
_logger.LogError(ex, "Ошибка загрузки заказов");
|
}
|
||||||
}
|
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
}
|
{
|
||||||
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
var service = Program.ServiceProvider?.GetService(typeof(FormEngines));
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
|
||||||
|
|
||||||
if (service is FormComponents form)
|
if (service is FormEngines form)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormEngines));
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
|
if (service is FormCreateOrder form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonTakeOrderInWork_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 buttonOrderReady_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 buttonIssuedOrder_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 buttonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
if (service is FormEngines form)
|
private void списокДвигателейToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
||||||
}
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
}
|
{
|
||||||
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
_reportLogic.SaveEngineToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
||||||
{
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
}
|
||||||
if (service is FormCreateOrder form)
|
}
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void buttonTakeOrderInWork_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 buttonOrderReady_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 buttonIssuedOrder_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 buttonRef_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void списокДвигателейToolStripMenuItem_Click(object sender, EventArgs e)
|
private void компонентыПоДвигателямToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
var service = Program.ServiceProvider?.GetService(typeof(FormReportEngineComponents));
|
||||||
if (dialog.ShowDialog() == DialogResult.OK)
|
if (service is FormReportEngineComponents form)
|
||||||
{
|
{
|
||||||
_reportLogic.SaveEngineToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
form.ShowDialog();
|
||||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void компонентыПоДвигателямToolStripMenuItem_Click(object sender, EventArgs e)
|
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportEngineComponents));
|
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
||||||
if (service is FormReportEngineComponents form)
|
if (service is FormReportOrders form)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
|
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
||||||
if (service is FormReportOrders form)
|
if (service is FormClients form)
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
using MotorPlantBusinessLogic.BusinessLogics;
|
using MotorPlantBusinessLogic.BusinessLogics;
|
||||||
using System;
|
|
||||||
using MotorPlantBusinessLogic.BusinessLogic;
|
using MotorPlantBusinessLogic.BusinessLogic;
|
||||||
using MotorPlantBusinessLogic.OfficePackage.Implements;
|
using MotorPlantBusinessLogic.OfficePackage.Implements;
|
||||||
using MotorPlantBusinessLogic.OfficePackage;
|
using MotorPlantBusinessLogic.OfficePackage;
|
||||||
@ -44,14 +43,18 @@ namespace MotorPlantView
|
|||||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
services.AddTransient<IEngineStorage, EngineStorage>();
|
services.AddTransient<IEngineStorage, EngineStorage>();
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
|
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<IEngineLogic, EngineLogic>();
|
services.AddTransient<IEngineLogic, EngineLogic>();
|
||||||
services.AddTransient<IReportLogic, ReportLogic>();
|
services.AddTransient<IReportLogic, ReportLogic>();
|
||||||
|
services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
|
|
||||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
|
||||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
|
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<FormComponent>();
|
services.AddTransient<FormComponent>();
|
||||||
services.AddTransient<FormComponents>();
|
services.AddTransient<FormComponents>();
|
||||||
@ -59,8 +62,9 @@ namespace MotorPlantView
|
|||||||
services.AddTransient<FormEngine>();
|
services.AddTransient<FormEngine>();
|
||||||
services.AddTransient<FormEngineComponent>();
|
services.AddTransient<FormEngineComponent>();
|
||||||
services.AddTransient<FormEngines>();
|
services.AddTransient<FormEngines>();
|
||||||
services.AddTransient<FormReportEngineComponents>();
|
|
||||||
services.AddTransient<FormReportOrders>();
|
services.AddTransient<FormReportOrders>();
|
||||||
|
services.AddTransient<FormReportEngineComponents>();
|
||||||
|
services.AddTransient<FormClients>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user