PIbd22_Kuznetsov_A.V._lab6 #6
@ -0,0 +1,110 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ImplementLogic : IImplementLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementStorage _storage;
|
||||
public ImplementLogic(ILogger<ImplementLogic> logger, IImplementStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
public ImplementViewModel? ReadElement(ImplementSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogInformation("ReadElement. FIO:{ImplementFIO}. Id:{Id}", model.ImplementFIO, model.Id);
|
||||
var element = _storage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public List<ImplementViewModel>? ReadList(ImplementSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
private void CheckModel(ImplementBindingModel? model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO))
|
||||
throw new ArgumentException("Нет ФИО исполнителя", nameof(model.ImplementFIO));
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
||||
}
|
||||
if (model.WorkExperience < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стаж меньше 0", nameof(model.WorkExperience));
|
||||
}
|
||||
if (model.Qualification < 0)
|
||||
{
|
||||
throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification));
|
||||
}
|
||||
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. WorkExperience:{WorkExperience}. Qualification:{Qualification}. Id: {Id} ", model.ImplementFIO, model.Password, model.WorkExperience, model.Qualification, model.Id);
|
||||
var element = _storage.GetElement(new ImplementSearchModel { ImplementFIO = model.ImplementFIO });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с этим именем уже существует");
|
||||
}
|
||||
}
|
||||
public bool Create(ImplementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Insert Imlement");
|
||||
if (_storage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert Error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ImplementBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete Implement Id:{Id}", model.Id);
|
||||
if (_storage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete Error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ImplementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update Implement Id:{Id}", model.Id);
|
||||
if (_storage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update Error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
static readonly object locker = new object();
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
@ -19,6 +20,22 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var elem = _orderStorage.GetElement(model);
|
||||
if (elem == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement found. Id:{Id}", elem.Id);
|
||||
return elem;
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||
@ -32,12 +49,16 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model)
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество заказов должно быть больше нуля");
|
||||
@ -68,6 +89,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
CheckModel (model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
@ -79,6 +101,8 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
_logger.LogWarning("Status change failed");
|
||||
throw new InvalidOperationException("Невозможно перевести состояние заказа");
|
||||
}
|
||||
if (element.ImplementId != null)
|
||||
element.ImplementId = model.ImplementId;
|
||||
model.Status = status;
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
@ -87,7 +111,10 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
lock (locker)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
|
@ -0,0 +1,110 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Enums;
|
||||
|
||||
namespace SewingDressesBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Random _rnd;
|
||||
private IOrderLogic _orderLogic;
|
||||
public WorkModeling(ILogger<WorkModeling> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
public void DoWork(IImplementLogic implementLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementLogic.ReadList(null);
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
||||
if (orders == null || orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||
foreach (var implementer in implementers) {
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
}
|
||||
|
||||
}
|
||||
private async Task WorkerWorkAsync(ImplementViewModel implement, List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null || implement == null)
|
||||
return;
|
||||
await RunOrderInWork(implement);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order in orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implement.Id, order.Id);
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementId = implement.Id
|
||||
});
|
||||
Thread.Sleep(implement.WorkExperience * _rnd.Next(100, 1000) * order.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implement.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementId = implement.Id
|
||||
});
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
Thread.Sleep(implement.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task RunOrderInWork(ImplementViewModel implement)
|
||||
{
|
||||
if (_orderLogic == null || implement == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementId = implement.Id,
|
||||
Status = OrderStatus.Выполняется
|
||||
}));
|
||||
if (runOrder == null)
|
||||
return;
|
||||
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implement.Id, runOrder.Id);
|
||||
Thread.Sleep(implement.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implement.Id, runOrder.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel { Id = runOrder.Id });
|
||||
Thread.Sleep(implement.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning("Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.BindingModels
|
||||
{
|
||||
public class ImplementBindingModel : IImplementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ImplementFIO { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public int WorkExperience { get; set; }
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ namespace SewingDressesContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int DressId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementId { get; set; }
|
||||
public string? ImplementFIO { get; set; } = string.Empty;
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
@ -0,0 +1,20 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IImplementLogic
|
||||
{
|
||||
List<ImplementViewModel>? ReadList(ImplementSearchModel? model);
|
||||
ImplementViewModel? ReadElement(ImplementSearchModel? model);
|
||||
bool Create(ImplementBindingModel? model);
|
||||
bool Update(ImplementBindingModel? model);
|
||||
bool Delete(ImplementBindingModel? model);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ namespace SewingDressesContracts.BusinessLogicsContracts
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IWorkProcess
|
||||
{
|
||||
void DoWork(IImplementLogic implementLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.SearchModels
|
||||
{
|
||||
public class ImplementSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ImplementFIO { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
namespace SewingDressesContracts.SearchModels
|
||||
using SewingDressesDataModels.Enums;
|
||||
|
||||
namespace SewingDressesContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? ImplementId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.StoragesContracts
|
||||
{
|
||||
public interface IImplementStorage
|
||||
{
|
||||
List<ImplementViewModel> GetFullList();
|
||||
List<ImplementViewModel> GetFilteredList(ImplementSearchModel model);
|
||||
ImplementViewModel? GetElement(ImplementSearchModel model);
|
||||
ImplementViewModel? Insert(ImplementBindingModel? model);
|
||||
ImplementViewModel? Update(ImplementBindingModel? model);
|
||||
ImplementViewModel? Delete(ImplementBindingModel? model);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesContracts.ViewModels
|
||||
{
|
||||
public class ImplementViewModel : IImplementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя исполнителя")]
|
||||
public string ImplementFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[DisplayName("Опыт работы")]
|
||||
public int WorkExperience { get; set; }
|
||||
[DisplayName("Квалификация")]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
@ -9,9 +9,12 @@ namespace SewingDressesContracts.ViewModels
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int DressId { get; set; }
|
||||
public int? ImplementId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Имя клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Имя исполнителя")]
|
||||
public string? ImplementFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Платье")]
|
||||
public string DressName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
|
@ -0,0 +1,10 @@
|
||||
namespace SewingDressesDataModels.Models
|
||||
{
|
||||
public interface IImplementModel : IId
|
||||
{
|
||||
string ImplementFIO { get; }
|
||||
string Password { get; }
|
||||
int WorkExperience { get; }
|
||||
int Qualification { get; }
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ namespace SewingDressesDataModels.Models
|
||||
int DressId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementId { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
|
@ -0,0 +1,65 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementStorage : IImplementStorage
|
||||
{
|
||||
public ImplementViewModel? Insert(ImplementBindingModel? model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
var newImplement = Implement.Create(model);
|
||||
if (newImplement == null)
|
||||
return null;
|
||||
context.Implements.Add(newImplement);
|
||||
context.SaveChanges();
|
||||
return newImplement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Update(ImplementBindingModel? model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
if (model == null)
|
||||
return null;
|
||||
var implement = context.Implements.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (implement == null) return null;
|
||||
implement.Update(model);
|
||||
context.SaveChanges();
|
||||
return implement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Delete(ImplementBindingModel? model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
var implement = context.Implements.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (implement == null) return null;
|
||||
context.Implements.Remove(implement);
|
||||
context.SaveChanges();
|
||||
return implement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? GetElement(ImplementSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO) && !model.Id.HasValue)
|
||||
return null;
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Implements.FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO.Equals(model.ImplementFIO)) && (!model.Id.HasValue || model.Id == x.Id))?.GetViewModel;
|
||||
}
|
||||
public List<ImplementViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Implements.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<ImplementViewModel> GetFilteredList(ImplementSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO)) return new();
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Implements.Where(x => x.ImplementFIO.Equals(model.ImplementFIO)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
@ -8,87 +9,76 @@ namespace SewingDressesDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel?> GetFullList()
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
return context.Orders.Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<OrderViewModel?> GetFilteredList(OrderSearchModel model)
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue)
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Status.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SewingDressesDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
else if (model.ClientId.HasValue)
|
||||
return context.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
else if (model.DateFrom != null)
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
||||
else
|
||||
return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.Status.Equals(model.Status)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && (!model.ImplementId.HasValue || !model.Status.HasValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SewingDressesDatabase();
|
||||
return AcessDressesStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context);
|
||||
if (model.Id.HasValue)
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.ImplementId == model.ImplementId && x.Status == model.Status)?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var order = Order.Create(model);
|
||||
using var context = new SewingDressesDatabase();
|
||||
var order = Order.Create(model, context);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SewingDressesDatabase();
|
||||
context.Orders.Add(order);
|
||||
context.SaveChanges();
|
||||
return AcessDressesStorage(order.GetViewModel, context);
|
||||
return order.GetViewModel;
|
||||
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
|
||||
using var context = new SewingDressesDatabase();
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
var order = context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return AcessDressesStorage(order.GetViewModel, context);
|
||||
return order.GetViewModel;
|
||||
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new SewingDressesDatabase();
|
||||
var element = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
var element = context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return AcessDressesStorage(element.GetViewModel, context);
|
||||
}
|
||||
public static OrderViewModel? AcessDressesStorage(OrderViewModel? model, SewingDressesDatabase context)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var dress = context.Dresses.FirstOrDefault(x => x.Id == model.DressId);
|
||||
var client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId);
|
||||
if (client == null || dress == null)
|
||||
return null;
|
||||
model.DressName = dress.DressName;
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
model.ClientId = client.Id;
|
||||
return model;
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
260
SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.Designer.cs
generated
Normal file
260
SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.Designer.cs
generated
Normal file
@ -0,0 +1,260 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SewingDressesDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SewingDressesDatabase))]
|
||||
[Migration("20240418162241_init")]
|
||||
partial class init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("DressName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Dresses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("DressId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("DressId");
|
||||
|
||||
b.ToTable("DressComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("DressId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ImplementId")
|
||||
.IsRequired()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("DressId");
|
||||
|
||||
b.HasIndex("ImplementId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
|
||||
{
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("DressComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("DressId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Dress");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("DressId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Dress");
|
||||
|
||||
b.Navigation("Implement");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("DressComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class init : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Clients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Dresses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
DressName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Dresses", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Implements",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ImplementFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Qualification = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Implements", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DressComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
DressId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DressComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_DressComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_DressComponents_Dresses_DressId",
|
||||
column: x => x.DressId,
|
||||
principalTable: "Dresses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
DressId = table.Column<int>(type: "int", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
||||
ImplementId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Dresses_DressId",
|
||||
column: x => x.DressId,
|
||||
principalTable: "Dresses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Implements_ImplementId",
|
||||
column: x => x.ImplementId,
|
||||
principalTable: "Implements",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DressComponents_ComponentId",
|
||||
table: "DressComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DressComponents_DressId",
|
||||
table: "DressComponents",
|
||||
column: "DressId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_DressId",
|
||||
table: "Orders",
|
||||
column: "DressId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ImplementId",
|
||||
table: "Orders",
|
||||
column: "ImplementId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "DressComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Dresses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Implements");
|
||||
}
|
||||
}
|
||||
}
|
257
SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.Designer.cs
generated
Normal file
257
SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.Designer.cs
generated
Normal file
@ -0,0 +1,257 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SewingDressesDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SewingDressesDatabase))]
|
||||
[Migration("20240418182438_nullab")]
|
||||
partial class nullab
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("DressName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Dresses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("DressId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("DressId");
|
||||
|
||||
b.ToTable("DressComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("DressId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ImplementId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("DressId");
|
||||
|
||||
b.HasIndex("ImplementId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
|
||||
{
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("DressComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("DressId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Dress");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("DressId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Dress");
|
||||
|
||||
b.Navigation("Implement");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("DressComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class nullab : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Implements_ImplementId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ImplementId",
|
||||
table: "Orders",
|
||||
type: "int",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Implements_ImplementId",
|
||||
table: "Orders",
|
||||
column: "ImplementId",
|
||||
principalTable: "Implements",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Implements_ImplementId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ImplementId",
|
||||
table: "Orders",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Implements_ImplementId",
|
||||
table: "Orders",
|
||||
column: "ImplementId",
|
||||
principalTable: "Implements",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
@ -113,6 +113,33 @@ namespace SewingDressesDatabaseImplement.Migrations
|
||||
b.ToTable("DressComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -136,6 +163,9 @@ namespace SewingDressesDatabaseImplement.Migrations
|
||||
b.Property<int>("DressId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ImplementId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
@ -148,6 +178,8 @@ namespace SewingDressesDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("DressId");
|
||||
|
||||
b.HasIndex("ImplementId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
@ -172,17 +204,27 @@ namespace SewingDressesDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Client", null)
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", null)
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("DressId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Dress");
|
||||
|
||||
b.Navigation("Implement");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
|
||||
@ -201,6 +243,11 @@ namespace SewingDressesDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesDatabaseImplement.Models
|
||||
{
|
||||
public class Implement : IImplementModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ImplementFIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int WorkExperience { get; private set; }
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int Qualification { get; private set; }
|
||||
[ForeignKey("ImplementId")]
|
||||
public virtual List<Order>? Orders { get; set; } = new();
|
||||
public static Implement? Create(ImplementBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
return new Implement
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementFIO = model.ImplementFIO,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Password = model.Password,
|
||||
Qualification = model.Qualification,
|
||||
};
|
||||
}
|
||||
public ImplementViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementFIO = ImplementFIO,
|
||||
WorkExperience = WorkExperience,
|
||||
Password = Password,
|
||||
Qualification = Qualification
|
||||
};
|
||||
public void Update(ImplementBindingModel? model)
|
||||
{
|
||||
if (model == null) return;
|
||||
ImplementFIO = model.ImplementFIO;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Password = model.Password;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
public int DressId { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
@ -23,8 +24,11 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Dress Dress { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Implement? Implement { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
public static Order? Create(OrderBindingModel model, SewingDressesDatabase context)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -35,6 +39,10 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
Id = model.Id,
|
||||
DressId = model.DressId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementId = model.ImplementId,
|
||||
Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId)!,
|
||||
Dress = context.Dresses.FirstOrDefault(x => x.Id == model.DressId)!,
|
||||
Implement = model.ImplementId.HasValue ? context.Implements.FirstOrDefault(x => x.Id == model.ImplementId) : null,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -48,13 +56,18 @@ namespace SewingDressesDatabaseImplement.Models
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
ImplementId = model.ImplementId;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DressId = DressId,
|
||||
DressName = Dress.DressName,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementId = ImplementId,
|
||||
ImplementFIO = Implement?.ImplementFIO,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -17,5 +17,6 @@ namespace SewingDressesDatabaseImplement
|
||||
public virtual DbSet<DressComponent> DressComponents { get; set; }
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
public virtual DbSet<Client> Clients { get; set; }
|
||||
public virtual DbSet<Implement> Implements { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,4 @@
|
||||
<ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -10,10 +10,12 @@ namespace SewingDressesFileImplement
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string DressFileName = "Dress.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
private readonly string ImplementFileName = "Implement.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Dress> Dresses { get; private set;}
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Implement> Implements { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -42,12 +44,14 @@ namespace SewingDressesFileImplement
|
||||
public void SaveDresses() => SaveData(Dresses, DressFileName, "Dresses", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
public void SaveImplements() => SaveData(Implements, ImplementFileName, "Implements", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
Implements = LoadData(ImplementFileName, "Implement", x => Implement.Create(x)!)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesFileImplement.Models;
|
||||
|
||||
namespace SewingDressesFileImplement.Implements
|
||||
{
|
||||
public class ImplementStorage : IImplementStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ImplementStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ImplementViewModel> GetFullList()
|
||||
{
|
||||
return source.Implements
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ImplementViewModel> GetFilteredList(ImplementSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Implements
|
||||
.Where(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO.Contains(model.ImplementFIO)) &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ImplementViewModel? GetElement(ImplementSearchModel model)
|
||||
{
|
||||
return source.Implements
|
||||
.FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO == model.ImplementFIO) &&
|
||||
(!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Insert(ImplementBindingModel model)
|
||||
{
|
||||
model.Id = source.Implements.Count > 0 ? source.Implements.Max(x =>
|
||||
x.Id) + 1 : 1;
|
||||
var newImplement = Implement.Create(model);
|
||||
if (newImplement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Implements.Add(newImplement);
|
||||
source.SaveImplements();
|
||||
return newImplement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Update(ImplementBindingModel model)
|
||||
{
|
||||
var Implement = source.Implements.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (Implement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Implement.Update(model);
|
||||
source.SaveImplements();
|
||||
return Implement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Delete(ImplementBindingModel model)
|
||||
{
|
||||
var element = source.Implements.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Implements.Remove(element);
|
||||
source.SaveImplements();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
76
SewingDresses/SewingDressesFileImplement/Models/Implement.cs
Normal file
76
SewingDresses/SewingDressesFileImplement/Models/Implement.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SewingDressesFileImplement.Models
|
||||
{
|
||||
public class Implement : IImplementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ImplementFIO { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public int WorkExperience { get; set; }
|
||||
public int Qualification { get; set; }
|
||||
public static Implement? Create(ImplementBindingModel? model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Implement
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementFIO = model.ImplementFIO,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification,
|
||||
};
|
||||
}
|
||||
public static Implement? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implement()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ImplementFIO = element.Element("ImplementFIO")!.Value,
|
||||
Password = element.Element("Password")!.Value,
|
||||
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
|
||||
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value)
|
||||
};
|
||||
}
|
||||
public XElement GetXElement => new("Implement",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ImplementFIO", ImplementFIO),
|
||||
new XElement("Password", Password),
|
||||
new XElement("Qualification", Qualification.ToString()),
|
||||
new XElement("WorkExperience", WorkExperience.ToString())
|
||||
);
|
||||
public ImplementViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementFIO = ImplementFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
public void Update(ImplementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementFIO = model.ImplementFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ namespace SewingDressesFileImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int DressId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
@ -27,6 +29,8 @@ namespace SewingDressesFileImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
DressId = model.DressId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementId = model.ImplementId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -44,7 +48,9 @@ namespace SewingDressesFileImplement.Models
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
DressId = Convert.ToInt32(element.Element("DressId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
ImplementId = Convert.ToInt32(element.Element("ImplementId")?.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value, new System.Globalization.CultureInfo("en-US")),
|
||||
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")?.Value),
|
||||
@ -64,6 +70,8 @@ namespace SewingDressesFileImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
DressId = DressId,
|
||||
ClientId = ClientId,
|
||||
ImplementId = ImplementId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
@ -73,7 +81,9 @@ namespace SewingDressesFileImplement.Models
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("DressId", DressId),
|
||||
new XElement("Count", Count),
|
||||
new XElement("ClientId", ClientId),
|
||||
new XElement("ImplementId", ImplementId),
|
||||
new XElement("Count", Count),
|
||||
new XElement("Sum", Sum),
|
||||
new XElement("Status", Status - OrderStatus.Принят),
|
||||
new XElement("DateCreate", DateCreate),
|
||||
|
@ -9,12 +9,14 @@ namespace SewingDressesListImplement
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Dress> Dresses { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implement> Implements { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Dresses = new List<Dress>();
|
||||
Clients = new List<Client>();
|
||||
Implements = new List<Implement>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -0,0 +1,103 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.StoragesContracts;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesListImplement.Implements
|
||||
{
|
||||
public class ImplementStorage : IImplementStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ImplementStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<ImplementViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ImplementViewModel>();
|
||||
foreach (var Implement in _source.Implements)
|
||||
{
|
||||
result.Add(Implement.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ImplementViewModel> GetFilteredList(ImplementSearchModel
|
||||
model)
|
||||
{
|
||||
var result = new List<ImplementViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ImplementFIO) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var Implement in _source.Implements)
|
||||
{
|
||||
if (Implement.ImplementFIO.Contains(model.ImplementFIO))
|
||||
{
|
||||
result.Add(Implement.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ImplementViewModel? GetElement(ImplementSearchModel model)
|
||||
{
|
||||
foreach (var Implement in _source.Implements)
|
||||
{
|
||||
if ((string.IsNullOrEmpty(model.ImplementFIO) || Implement.ImplementFIO == model.ImplementFIO) &&
|
||||
(!model.Id.HasValue || Implement.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || Implement.Password == model.Password))
|
||||
{
|
||||
return Implement.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ImplementViewModel? Insert(ImplementBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var Implement in _source.Implements)
|
||||
{
|
||||
if (model.Id <= Implement.Id)
|
||||
{
|
||||
model.Id = Implement.Id + 1;
|
||||
}
|
||||
}
|
||||
var newImplement = Implement.Create(model);
|
||||
if (newImplement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Implements.Add(newImplement);
|
||||
return newImplement.GetViewModel;
|
||||
}
|
||||
public ImplementViewModel? Update(ImplementBindingModel model)
|
||||
{
|
||||
foreach (var Implement in _source.Implements)
|
||||
{
|
||||
if (model.Id == Implement.Id)
|
||||
{
|
||||
Implement.Update(model);
|
||||
return Implement.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ImplementViewModel? Delete(ImplementBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Implements.Count; ++i)
|
||||
{
|
||||
if (_source.Implements[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Implements[i];
|
||||
_source.Implements.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
54
SewingDresses/SewingDressesListImplement/Models/Implement.cs
Normal file
54
SewingDresses/SewingDressesListImplement/Models/Implement.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewingDressesListImplement.Models
|
||||
{
|
||||
public class Implement : IImplementModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ImplementFIO { get; private set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public int WorkExperience { get; set; } = 0;
|
||||
public int Qualification { get; set; } = 0;
|
||||
public static Implement? Create(ImplementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implement()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementFIO = model.ImplementFIO,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
public void Update(ImplementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementFIO = model.ImplementFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
public ImplementViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementFIO = ImplementFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
}
|
@ -9,6 +9,8 @@ namespace SewingDressesListImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int DressId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
@ -25,6 +27,8 @@ namespace SewingDressesListImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
DressId = model.DressId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementId = model.ImplementId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -46,6 +50,8 @@ namespace SewingDressesListImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
DressId = DressId,
|
||||
ClientId = ClientId,
|
||||
ImplementId = ImplementId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -0,0 +1,108 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using SewingDressesContracts.ViewModels;
|
||||
using SewingDressesDataModels.Enums;
|
||||
|
||||
namespace SewingDressesRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ImplementController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderLogic _order;
|
||||
|
||||
private readonly IImplementLogic _logic;
|
||||
|
||||
public ImplementController(IOrderLogic order, IImplementLogic logic, ILogger<ImplementController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ImplementViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ImplementSearchModel
|
||||
{
|
||||
ImplementFIO = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка авторизации сотрудника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetNewOrders()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = OrderStatus.Принят
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения новых заказов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public OrderViewModel? GetImplementOrder(int ImplementId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementId = ImplementId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.TakeOrderInWork(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.FinishOrder(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@ builder.Services.AddTransient<IDressStorage, DressStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IDressLogic, DressLogic>();
|
||||
builder.Services.AddTransient<IImplementStorage, ImplementStorage>();
|
||||
builder.Services.AddTransient<IImplementLogic, ImplementLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
|
@ -7,6 +7,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.18">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
162
SewingDresses/SewingDressesView/ImplementForm.Designer.cs
generated
Normal file
162
SewingDresses/SewingDressesView/ImplementForm.Designer.cs
generated
Normal file
@ -0,0 +1,162 @@
|
||||
namespace SewingDressesView
|
||||
{
|
||||
partial class ImplementForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
textBoxFIO = new TextBox();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
textBoxPassword = new TextBox();
|
||||
label3 = new Label();
|
||||
textBoxQual = new TextBox();
|
||||
label4 = new Label();
|
||||
textBoxExp = new TextBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxFIO
|
||||
//
|
||||
textBoxFIO.Location = new Point(153, 34);
|
||||
textBoxFIO.Name = "textBoxFIO";
|
||||
textBoxFIO.Size = new Size(125, 27);
|
||||
textBoxFIO.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(32, 37);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(39, 20);
|
||||
label1.TabIndex = 1;
|
||||
label1.Text = "Имя";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(32, 89);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(62, 20);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = "Пароль";
|
||||
//
|
||||
// textBoxPassword
|
||||
//
|
||||
textBoxPassword.Location = new Point(153, 86);
|
||||
textBoxPassword.Name = "textBoxPassword";
|
||||
textBoxPassword.Size = new Size(125, 27);
|
||||
textBoxPassword.TabIndex = 2;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(32, 144);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(111, 20);
|
||||
label3.TabIndex = 5;
|
||||
label3.Text = "Квалификация";
|
||||
//
|
||||
// textBoxQual
|
||||
//
|
||||
textBoxQual.Location = new Point(153, 141);
|
||||
textBoxQual.Name = "textBoxQual";
|
||||
textBoxQual.Size = new Size(125, 27);
|
||||
textBoxQual.TabIndex = 4;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(32, 197);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(46, 20);
|
||||
label4.TabIndex = 7;
|
||||
label4.Text = "Опыт";
|
||||
//
|
||||
// textBoxExp
|
||||
//
|
||||
textBoxExp.Location = new Point(153, 194);
|
||||
textBoxExp.Name = "textBoxExp";
|
||||
textBoxExp.Size = new Size(125, 27);
|
||||
textBoxExp.TabIndex = 6;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(334, 32);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 8;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(334, 84);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 9;
|
||||
buttonCancel.Text = "Отменить";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// ImplementForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(451, 237);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(textBoxExp);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(textBoxQual);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(textBoxPassword);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(textBoxFIO);
|
||||
Name = "ImplementForm";
|
||||
Text = "Исполнитель форма";
|
||||
Load += ImplementForm_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxFIO;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private TextBox textBoxPassword;
|
||||
private Label label3;
|
||||
private TextBox textBoxQual;
|
||||
private Label label4;
|
||||
private TextBox textBoxExp;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
111
SewingDresses/SewingDressesView/ImplementForm.cs
Normal file
111
SewingDresses/SewingDressesView/ImplementForm.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SewingDressesView
|
||||
{
|
||||
public partial class ImplementForm : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementLogic _logic;
|
||||
private int? _id;
|
||||
public int ID { set { _id = value; } }
|
||||
public ImplementForm(ILogger<ImplementForm> logger, IImplementLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxFIO.Text))
|
||||
{
|
||||
MessageBox.Show("Empty Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxPassword.Text))
|
||||
{
|
||||
MessageBox.Show("Empty Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxExp.Text))
|
||||
{
|
||||
MessageBox.Show("Empty Experience", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxQual.Text))
|
||||
{
|
||||
MessageBox.Show("Empty Qualification", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Saving Imlement");
|
||||
try
|
||||
{
|
||||
var model = new ImplementBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Password = textBoxPassword.Text,
|
||||
ImplementFIO = textBoxFIO.Text,
|
||||
WorkExperience = Convert.ToInt32(textBoxExp.Text),
|
||||
Qualification = Convert.ToInt32(textBoxQual.Text)
|
||||
};
|
||||
var result = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!result)
|
||||
throw new Exception("Error on saving implement");
|
||||
MessageBox.Show("Saving success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error saving implement");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ImplementForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Init implement");
|
||||
var view = _logic.ReadElement(new ImplementSearchModel
|
||||
{
|
||||
Id = _id.Value,
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxPassword.Text = view.Password;
|
||||
textBoxFIO.Text = view.ImplementFIO;
|
||||
textBoxExp.Text = view.WorkExperience.ToString();
|
||||
textBoxQual.Text = view.Qualification.ToString();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Init implement error");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
120
SewingDresses/SewingDressesView/ImplementForm.resx
Normal file
120
SewingDresses/SewingDressesView/ImplementForm.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>
|
114
SewingDresses/SewingDressesView/ImplementsForm.Designer.cs
generated
Normal file
114
SewingDresses/SewingDressesView/ImplementsForm.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
||||
namespace SewingDressesView
|
||||
{
|
||||
partial class ImplementsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreate = new Button();
|
||||
buttonChange = new Button();
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(17, 18);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(524, 355);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(572, 18);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
buttonChange.Location = new Point(572, 64);
|
||||
buttonChange.Name = "buttonChange";
|
||||
buttonChange.Size = new Size(94, 29);
|
||||
buttonChange.TabIndex = 2;
|
||||
buttonChange.Text = "Изменить";
|
||||
buttonChange.UseVisualStyleBackColor = true;
|
||||
buttonChange.Click += buttonChange_Click;
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(572, 111);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(94, 29);
|
||||
buttonDelete.TabIndex = 3;
|
||||
buttonDelete.Text = "Удалить";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(572, 161);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(94, 29);
|
||||
buttonUpdate.TabIndex = 4;
|
||||
buttonUpdate.Text = "Обновить";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// ImplementsForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(678, 383);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonChange);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "ImplementsForm";
|
||||
Text = "Исполнители";
|
||||
Load += ImplementsForm_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCreate;
|
||||
private Button buttonChange;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
103
SewingDresses/SewingDressesView/ImplementsForm.cs
Normal file
103
SewingDresses/SewingDressesView/ImplementsForm.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SewingDressesContracts.BusinessLogicsContracts;
|
||||
using SewingDressesContracts.BindingModels;
|
||||
using SewingDressesDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SewingDressesView
|
||||
{
|
||||
public partial class ImplementsForm : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementLogic _logic;
|
||||
public ImplementsForm(ILogger<ImplementsForm> logger, IImplementLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Loading employees");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error loading employees");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ImplementForm));
|
||||
if (service is ImplementForm form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ImplementsForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ImplementForm));
|
||||
if (service is ImplementForm form)
|
||||
{
|
||||
form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Delete component: {ComponentName}- {Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||
_logic?.Delete(new ImplementBindingModel{ Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
120
SewingDresses/SewingDressesView/ImplementsForm.resx
Normal file
120
SewingDresses/SewingDressesView/ImplementsForm.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>
|
68
SewingDresses/SewingDressesView/MainForm.Designer.cs
generated
68
SewingDresses/SewingDressesView/MainForm.Designer.cs
generated
@ -30,19 +30,19 @@
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreate = new Button();
|
||||
buttonDoOrder = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
buttonOrderGive = new Button();
|
||||
buttonOrderUpdate = new Button();
|
||||
menuStrip1 = new MenuStrip();
|
||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||
платьяToolStripMenuItem = new ToolStripMenuItem();
|
||||
clientsToolStripMenuItem = new ToolStripMenuItem();
|
||||
исполнителиToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||
DressesReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
|
||||
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
|
||||
clientsToolStripMenuItem = new ToolStripMenuItem();
|
||||
запускРаботToolStripMenuItem = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
@ -67,29 +67,9 @@
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonDoOrder
|
||||
//
|
||||
buttonDoOrder.Location = new Point(854, 130);
|
||||
buttonDoOrder.Name = "buttonDoOrder";
|
||||
buttonDoOrder.Size = new Size(194, 37);
|
||||
buttonDoOrder.TabIndex = 2;
|
||||
buttonDoOrder.Text = "Отдать на выполнение";
|
||||
buttonDoOrder.UseVisualStyleBackColor = true;
|
||||
buttonDoOrder.Click += buttonDoOrder_Click;
|
||||
//
|
||||
// buttonOrderReady
|
||||
//
|
||||
buttonOrderReady.Location = new Point(854, 205);
|
||||
buttonOrderReady.Name = "buttonOrderReady";
|
||||
buttonOrderReady.Size = new Size(194, 37);
|
||||
buttonOrderReady.TabIndex = 3;
|
||||
buttonOrderReady.Text = "Заказ готов";
|
||||
buttonOrderReady.UseVisualStyleBackColor = true;
|
||||
buttonOrderReady.Click += buttonOrderReady_Click;
|
||||
//
|
||||
// buttonOrderGive
|
||||
//
|
||||
buttonOrderGive.Location = new Point(854, 280);
|
||||
buttonOrderGive.Location = new Point(854, 142);
|
||||
buttonOrderGive.Name = "buttonOrderGive";
|
||||
buttonOrderGive.Size = new Size(194, 37);
|
||||
buttonOrderGive.TabIndex = 4;
|
||||
@ -99,7 +79,7 @@
|
||||
//
|
||||
// buttonOrderUpdate
|
||||
//
|
||||
buttonOrderUpdate.Location = new Point(854, 357);
|
||||
buttonOrderUpdate.Location = new Point(854, 219);
|
||||
buttonOrderUpdate.Name = "buttonOrderUpdate";
|
||||
buttonOrderUpdate.Size = new Size(194, 37);
|
||||
buttonOrderUpdate.TabIndex = 5;
|
||||
@ -110,7 +90,7 @@
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem });
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(1096, 28);
|
||||
@ -119,7 +99,7 @@
|
||||
//
|
||||
// справочникиToolStripMenuItem
|
||||
//
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, clientsToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, clientsToolStripMenuItem, исполнителиToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||
справочникиToolStripMenuItem.Text = "Справочники";
|
||||
@ -127,17 +107,31 @@
|
||||
// компонентыToolStripMenuItem
|
||||
//
|
||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||
компонентыToolStripMenuItem.Size = new Size(224, 26);
|
||||
компонентыToolStripMenuItem.Size = new Size(185, 26);
|
||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||
компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||
//
|
||||
// платьяToolStripMenuItem
|
||||
//
|
||||
платьяToolStripMenuItem.Name = "платьяToolStripMenuItem";
|
||||
платьяToolStripMenuItem.Size = new Size(224, 26);
|
||||
платьяToolStripMenuItem.Size = new Size(185, 26);
|
||||
платьяToolStripMenuItem.Text = "Платья";
|
||||
платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click;
|
||||
//
|
||||
// clientsToolStripMenuItem
|
||||
//
|
||||
clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
|
||||
clientsToolStripMenuItem.Size = new Size(185, 26);
|
||||
clientsToolStripMenuItem.Text = "Клиенты";
|
||||
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
|
||||
//
|
||||
// исполнителиToolStripMenuItem
|
||||
//
|
||||
исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
|
||||
исполнителиToolStripMenuItem.Size = new Size(185, 26);
|
||||
исполнителиToolStripMenuItem.Text = "Исполнители";
|
||||
исполнителиToolStripMenuItem.Click += ImplementToolStripMenuItem_Click;
|
||||
//
|
||||
// отчетыToolStripMenuItem
|
||||
//
|
||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DressesReportToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem });
|
||||
@ -166,12 +160,12 @@
|
||||
списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
||||
списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItemReport_Click;
|
||||
//
|
||||
// clientsToolStripMenuItem
|
||||
// запускРаботToolStripMenuItem
|
||||
//
|
||||
clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
|
||||
clientsToolStripMenuItem.Size = new Size(224, 26);
|
||||
clientsToolStripMenuItem.Text = "Клиенты";
|
||||
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
|
||||
запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
|
||||
запускРаботToolStripMenuItem.Size = new Size(114, 24);
|
||||
запускРаботToolStripMenuItem.Text = "Запуск работ";
|
||||
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
@ -180,8 +174,6 @@
|
||||
ClientSize = new Size(1096, 493);
|
||||
Controls.Add(buttonOrderUpdate);
|
||||
Controls.Add(buttonOrderGive);
|
||||
Controls.Add(buttonOrderReady);
|
||||
Controls.Add(buttonDoOrder);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(menuStrip1);
|
||||
@ -200,8 +192,6 @@
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCreate;
|
||||
private Button buttonDoOrder;
|
||||
private Button buttonOrderReady;
|
||||
private Button buttonOrderGive;
|
||||
private Button buttonOrderUpdate;
|
||||
private MenuStrip menuStrip1;
|
||||
@ -213,5 +203,7 @@
|
||||
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
|
||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
||||
private ToolStripMenuItem clientsToolStripMenuItem;
|
||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -11,12 +11,14 @@ namespace SewingDressesView
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
||||
private readonly IWorkProcess _workProcess;
|
||||
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_workProcess = workProcess;
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
@ -28,6 +30,7 @@ namespace SewingDressesView
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["DressId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ImplementId"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Load orders");
|
||||
}
|
||||
@ -65,57 +68,6 @@ namespace SewingDressesView
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDoOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change Status on 'In work'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Change Status on 'In work' error");
|
||||
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("Order №{id}. Change status on 'Ready'",
|
||||
id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(new
|
||||
OrderBindingModel
|
||||
{ Id = id });
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Change status on 'Ready' error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonOrderGive_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -188,5 +140,21 @@ namespace SewingDressesView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ImplementToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ImplementsForm));
|
||||
if (service is ImplementsForm form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementLogic)) as IImplementLogic)!, _orderLogic);
|
||||
MessageBox.Show("Процесс обработки запущен", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,9 @@ namespace SewingDressesView
|
||||
services.AddTransient<IDressLogic, DressLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IImplementLogic, ImplementLogic>();
|
||||
services.AddTransient<IImplementStorage, ImplementStorage>();
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
@ -53,6 +56,8 @@ namespace SewingDressesView
|
||||
services.AddTransient<DressesForm>();
|
||||
services.AddTransient<ReportDressComponentsForm>();
|
||||
services.AddTransient<ReportOrdersForm>();
|
||||
services.AddTransient<ImplementForm>();
|
||||
services.AddTransient<ImplementsForm>();
|
||||
}
|
||||
}
|
||||
}
|
@ -22,4 +22,10 @@
|
||||
<ProjectReference Include="..\SewingDressesDatabaseImplement\SewingDressesDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
18
SewingDresses/SewingDressesView/nlog.config
Normal file
18
SewingDresses/SewingDressesView/nlog.config
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="logs/log-${shortdate}.log" />
|
||||
</targets>
|
||||
<target name="console" xsi:type="Console" layout="Access Log|${level:uppercase=true}|${logger}|${message}">
|
||||
<highlight-row condition="true" foregroundColor="red"/>
|
||||
</target>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="tofile,console" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user