lab6.done

This commit is contained in:
Danil Markov 2023-04-11 00:22:09 +04:00
parent e6867ecc4c
commit 21b457bde8
47 changed files with 2281 additions and 522 deletions

View File

@ -0,0 +1,129 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModel.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.BusinessLogics
{
public class ImplementerLogic : IImplementerLogic
{
private readonly ILogger _logger;
private readonly IImplementerStorage _implementerStorage;
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
{
_logger = logger;
_implementerStorage = implementerStorage;
}
public bool Create(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ImplementerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_implementerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}",
model.ImplementerFIO, model.Id);
var element = _implementerStorage.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<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
{
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id);
var list = (model == null) ? _implementerStorage.GetFullList() :
_implementerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.WorkExperience < 0)
{
throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience));
}
if (model.Qualification < 0)
{
throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO));
}
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
throw new ArgumentNullException("Нет фио исполнителя", nameof(model.ImplementerFIO));
}
_logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO);
var element = _implementerStorage.GetElement(new ImplementerSearchModel
{
ImplementerFIO = model.ImplementerFIO,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Исполнитель с таким фио уже есть");
}
}
}
}

View File

@ -1,4 +1,5 @@
using LawFirmContracts.BindingModels; using DocumentFormat.OpenXml.EMMA;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts; using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels; using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts; using LawFirmContracts.StoragesContracts;
@ -47,11 +48,18 @@ namespace LawFirmBusinessLogic.BusinessLogics
return false; return false;
} }
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); model.DateCreate = viewModel.DateCreate;
if (model.Status == OrderStatus.Готов)
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
else else
{ {
model.DateImplement = viewModel.DateImplement; model.DateImplement = viewModel.DateImplement;
} }
if (viewModel.ImplementerId.HasValue)
model.ImplementerId = viewModel.ImplementerId;
model.DocumentId= viewModel.DocumentId;
model.Sum = viewModel.Sum;
model.Count= viewModel.Count;
CheckModel(model); CheckModel(model);
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
@ -87,7 +95,23 @@ namespace LawFirmBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count:{Count}", list.Count); _logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list; return list;
} }
private void CheckModel(OrderBindingModel model, bool withParams = true) public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{ {
if (model == null) if (model == null)
{ {

View File

@ -0,0 +1,147 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.BusinessLogics
{
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(IImplementerLogic implementerLogic, IOrderLogic
orderLogic)
{
_orderLogic = orderLogic;
var implementers = implementerLogic.ReadList(null);
if (implementers == null)
{
_logger.LogWarning("DoWork. Implementers is null");
return;
}
var orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = 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));
}
}
/// <summary>
/// Иммитация работы исполнителя
/// </summary>
/// <param name="implementer"></param>
/// <param name="orders"></param>
private async Task WorkerWorkAsync(ImplementerViewModel implementer,
List<OrderViewModel> orders)
{
if (_orderLogic == null || implementer == null)
{
return;
}
await RunOrderInWork(implementer);
await Task.Run(() =>
{
foreach (var order in orders)
{
try
{
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
// пытаемся назначить заказ на исполнителя
_orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = order.Id,
ImplementerId = implementer.Id
});
// делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100,
1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = order.Id
});
}
// кто-то мог уже перехватить заказ, игнорируем ошибку
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
// заканчиваем выполнение имитации в случае иной ошибки
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
});
}
/// <summary>
/// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
/// </summary>
/// <param name="implementer"></param>
/// <returns></returns>
private async Task RunOrderInWork(ImplementerViewModel implementer)
{
if (_orderLogic == null || implementer == null)
{
return;
}
try
{
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
{
ImplementerId = implementer.Id,
OrderStatus = OrderStatus.Выполняется
}));
if (runOrder == null)
{
return;
}
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}",implementer.Id, runOrder.Id);
// доделываем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) *
runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}",
implementer.Id, runOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = runOrder.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
// заказа может не быть, просто игнорируем ошибку
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
// а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
}
}

View File

@ -0,0 +1,21 @@
using LawFirmDataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class ImplementerBindingModel : IImplementerModel
{
public int Id { get; set; }
public string ImplementerFIO { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; }
public int Qualification { get; set; }
}
}

View File

@ -8,7 +8,8 @@ namespace LawFirmContracts.BindingModels
public int Id { get; set; } public int Id { get; set; }
public int DocumentId { get; set; } public int DocumentId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int Count { get; set; } public int? ImplementerId { get; set; }
public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);

View File

@ -0,0 +1,24 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BusinessLogicsContracts
{
public interface IImplementerLogic
{
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
bool Create(ImplementerBindingModel model);
bool Update(ImplementerBindingModel model);
bool Delete(ImplementerBindingModel model);
}
}

View File

@ -7,7 +7,8 @@ namespace LawFirmContracts.BusinessLogicsContracts
public interface IOrderLogic public interface IOrderLogic
{ {
List<OrderViewModel>? ReadList(OrderSearchModel? model); List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model); OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model); bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model);

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BusinessLogicsContracts
{
public interface IWorkProcess
{
/// <summary>
/// Запуск работ
/// </summary>
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.SearchModels
{
public class ImplementerSearchModel
{
public int? Id { get; set; }
public string? ImplementerFIO { get; set; }
public string? Password { get; set; }
}
}

View File

@ -1,4 +1,6 @@
namespace LawFirmContracts.SearchModels using LawFirmDataModels.Enums;
namespace LawFirmContracts.SearchModels
{ {
public class OrderSearchModel public class OrderSearchModel
{ {
@ -6,5 +8,7 @@
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
} public int? ImplementerId { get; set; }
public OrderStatus? OrderStatus { get; set; }
}
} }

View File

@ -0,0 +1,26 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.StoragesContracts
{
public interface IImplementerStorage
{
List<ImplementerViewModel> GetFullList();
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
ImplementerViewModel? GetElement(ImplementerSearchModel model);
ImplementerViewModel? Insert(ImplementerBindingModel model);
ImplementerViewModel? Update(ImplementerBindingModel model);
ImplementerViewModel? Delete(ImplementerBindingModel model);
}
}

View File

@ -0,0 +1,27 @@
using LawFirmDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
public int Id { get; set; }
[DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
[DisplayName("Стаж работы")]
public int WorkExperience { get; set; }
[DisplayName("Квалификация")]
public int Qualification { get; set; }
}
}

View File

@ -9,11 +9,14 @@ namespace LawFirmContracts.ViewModels
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
public int DocumentId { get; set; } public int DocumentId { get; set; }
[DisplayName("Документ")] public int? ImplementerId { get; set; }
[DisplayName("Документ")]
public int ClientId { get; set; } public int ClientId { get; set; }
[DisplayName("Данные клиента")] [DisplayName("Данные клиента")]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Документ")] [DisplayName("Фамилия исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Документ")]
public string DocumentName { get; set; } = string.Empty; public string DocumentName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModel.Models
{
public interface IImplementerModel
{
string ImplementerFIO { get; }
string Password { get; }
int WorkExperience { get; }
int Qualification { get; }
}
}

View File

@ -10,5 +10,6 @@ namespace LawFirmDataModels.Models
OrderStatus Status { get; } OrderStatus Status { get; }
DateTime DateCreate { get; } DateTime DateCreate { get; }
DateTime? DateImplement { get; } DateTime? DateImplement { get; }
} int? ImplementerId { get; }
}
} }

View File

@ -0,0 +1,95 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
using var context = new LawFirmDatabase();
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
context.Implementers.Remove(res);
context.SaveChanges();
}
return res?.GetViewModel;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
using var context = new LawFirmDatabase();
if (model.Id.HasValue)
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null)
return context.Implementers
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.ImplementerFIO != null)
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально)
{
using var context = new LawFirmDatabase();
return context.Implementers
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ImplementerViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
return context.Implementers.Select(x => x.GetViewModel).ToList();
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
using var context = new LawFirmDatabase();
var res = Implementer.Create(model);
if (res != null)
{
context.Implementers.Add(res);
context.SaveChanges();
}
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
using var context = new LawFirmDatabase();
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
res.Update(model);
context.SaveChanges();
}
return res?.GetViewModel;
}
}
}

View File

@ -13,35 +13,42 @@ namespace LawFirmDatabaseImplement.Implements
{ {
using var context = new LawFirmDatabase(); using var context = new LawFirmDatabase();
var element = context.Orders var element = context.Orders
.Include(x => x.Client)
.Include(x => x.Implementer)
.Include(x => x.Document)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {
var deletedElement = context.Orders
.Include(x => x.Document)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element); context.Orders.Remove(element);
context.SaveChanges(); context.SaveChanges();
return deletedElement; return element.GetViewModel;
} }
return null; return null;
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) using var context = new LawFirmDatabase();
{ if (model.Id.HasValue)
return null; {
} return context.Orders
.Include(x => x.Document)
using var context = new LawFirmDatabase(); .Include(x => x.Client)
.Include(x => x.Implementer)
return context.Orders .FirstOrDefault(x => x.Id == model.Id)
.Include(x => x.Document) ?.GetViewModel;
.Include(x => x.Client) }
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
?.GetViewModel; {
} return context.Orders
.Include(x => x.Document)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus)
?.GetViewModel;
}
return null;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
@ -73,6 +80,16 @@ namespace LawFirmDatabaseImplement.Implements
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
else if (model.OrderStatus.HasValue)
{
return context.Orders
.Include(x => x.Document)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Status == model.OrderStatus)
.Select(x => x.GetViewModel)
.ToList();
}
else else
{ {
return new(); return new();
@ -85,34 +102,37 @@ namespace LawFirmDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Document) .Include(x => x.Document)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
var newOrder = Order.Create(model); var newOrder = Order.Create(model);
if (newOrder == null) if (newOrder == null)
{ {
return null; return null;
} }
using var context = new LawFirmDatabase();
using var context = new LawFirmDatabase(); context.Orders.Add(newOrder);
context.SaveChanges();
context.Orders.Add(newOrder); return context.Orders
context.SaveChanges(); .Include(x => x.Document)
return context.Orders .Include(x => x.Client)
.Include(x => x.Document) .FirstOrDefault(x => x.Id == newOrder.Id)
.Include(x => x.Client) ?.GetViewModel;
.FirstOrDefault(x => x.Id == newOrder.Id) }
?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
using var context = new LawFirmDatabase(); using var context = new LawFirmDatabase();
var order = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); var order = context.Orders
.Include(x => x.Client)
.Include(x => x.Implementer)
.Include(x => x.Document)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null) if (order == null)
{ {
@ -120,11 +140,7 @@ namespace LawFirmDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders return order.GetViewModel;
.Include(x => x.Document)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
} }
} }
} }

View File

@ -23,5 +23,6 @@ namespace LawFirmDatabaseImplement
public virtual DbSet<DocumentBlank> DocumentBlanks { set; get; } public virtual DbSet<DocumentBlank> DocumentBlanks { set; get; }
public virtual DbSet<Order> Orders { set; get; } public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; } public virtual DbSet<Client> Clients { set; get; }
} public virtual DbSet<Implementer> Implementers { set; get; }
}
} }

View File

@ -21,4 +21,8 @@
<ProjectReference Include="..\LawFirmDataModel\LawFirmDataModel.csproj" /> <ProjectReference Include="..\LawFirmDataModel\LawFirmDataModel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project> </Project>

View File

@ -1,171 +0,0 @@
// <auto-generated />
using System;
using LawFirmDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
[Migration("20230313153615_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BlankName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Blanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Documents");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BlankId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("DocumentId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("BlankId");
b.HasIndex("DocumentId");
b.ToTable("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
b.Property<int>("DocumentId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.ToTable("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
.WithMany("DocumentBlanks")
.HasForeignKey("BlankId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Blanks")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Blank");
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Orders")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Navigation("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Navigation("Blanks");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,69 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class addClient : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ClientId",
table: "Orders",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropIndex(
name: "IX_Orders_ClientId",
table: "Orders");
migrationBuilder.DropColumn(
name: "ClientId",
table: "Orders");
}
}
}

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace LawFirmDatabaseImplement.Migrations namespace LawFirmDatabaseImplement.Migrations
{ {
[DbContext(typeof(LawFirmDatabase))] [DbContext(typeof(LawFirmDatabase))]
[Migration("20230327180815_addClient")] [Migration("20230410191616_Lab6")]
partial class addClient partial class Lab6
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -116,6 +116,33 @@ namespace LawFirmDatabaseImplement.Migrations
b.ToTable("DocumentBlanks"); b.ToTable("DocumentBlanks");
}); });
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b => modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -139,6 +166,9 @@ namespace LawFirmDatabaseImplement.Migrations
b.Property<int>("DocumentId") b.Property<int>("DocumentId")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<int?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("integer"); .HasColumnType("integer");
@ -151,6 +181,8 @@ namespace LawFirmDatabaseImplement.Migrations
b.HasIndex("DocumentId"); b.HasIndex("DocumentId");
b.HasIndex("ImplementerId");
b.ToTable("Orders"); b.ToTable("Orders");
}); });
@ -187,9 +219,15 @@ namespace LawFirmDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Document"); b.Navigation("Document");
b.Navigation("Implementer");
}); });
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b => modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
@ -208,6 +246,11 @@ namespace LawFirmDatabaseImplement.Migrations
b.Navigation("Orders"); b.Navigation("Orders");
}); });
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace LawFirmDatabaseImplement.Migrations namespace LawFirmDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialCreate : Migration public partial class Lab6 : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -26,6 +26,21 @@ namespace LawFirmDatabaseImplement.Migrations
table.PrimaryKey("PK_Blanks", x => x.Id); table.PrimaryKey("PK_Blanks", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Documents", name: "Documents",
columns: table => new columns: table => new
@ -40,6 +55,22 @@ namespace LawFirmDatabaseImplement.Migrations
table.PrimaryKey("PK_Documents", x => x.Id); table.PrimaryKey("PK_Documents", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "Implementers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
WorkExperience = table.Column<int>(type: "integer", nullable: false),
Qualification = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "DocumentBlanks", name: "DocumentBlanks",
columns: table => new columns: table => new
@ -74,21 +105,34 @@ namespace LawFirmDatabaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DocumentId = table.Column<int>(type: "integer", nullable: false), DocumentId = table.Column<int>(type: "integer", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false), Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false), Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false), Status = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ImplementerId = table.Column<int>(type: "integer", nullable: true),
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true) DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Orders", x => x.Id); 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( table.ForeignKey(
name: "FK_Orders_Documents_DocumentId", name: "FK_Orders_Documents_DocumentId",
column: x => x.DocumentId, column: x => x.DocumentId,
principalTable: "Documents", principalTable: "Documents",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Implementers_ImplementerId",
column: x => x.ImplementerId,
principalTable: "Implementers",
principalColumn: "Id");
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
@ -101,10 +145,20 @@ namespace LawFirmDatabaseImplement.Migrations
table: "DocumentBlanks", table: "DocumentBlanks",
column: "DocumentId"); column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_DocumentId", name: "IX_Orders_DocumentId",
table: "Orders", table: "Orders",
column: "DocumentId"); column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
} }
/// <inheritdoc /> /// <inheritdoc />
@ -119,8 +173,14 @@ namespace LawFirmDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Blanks"); name: "Blanks");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Documents"); name: "Documents");
migrationBuilder.DropTable(
name: "Implementers");
} }
} }
} }

View File

@ -113,6 +113,33 @@ namespace LawFirmDatabaseImplement.Migrations
b.ToTable("DocumentBlanks"); b.ToTable("DocumentBlanks");
}); });
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b => modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -136,6 +163,9 @@ namespace LawFirmDatabaseImplement.Migrations
b.Property<int>("DocumentId") b.Property<int>("DocumentId")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<int?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("integer"); .HasColumnType("integer");
@ -148,6 +178,8 @@ namespace LawFirmDatabaseImplement.Migrations
b.HasIndex("DocumentId"); b.HasIndex("DocumentId");
b.HasIndex("ImplementerId");
b.ToTable("Orders"); b.ToTable("Orders");
}); });
@ -184,9 +216,15 @@ namespace LawFirmDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Document"); b.Navigation("Document");
b.Navigation("Implementer");
}); });
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b => modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
@ -205,6 +243,11 @@ namespace LawFirmDatabaseImplement.Migrations
b.Navigation("Orders"); b.Navigation("Orders");
}); });
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

View File

@ -0,0 +1,65 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
[ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; private set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFIO = model.ImplementerFIO,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFIO = model.ImplementerFIO;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFIO = ImplementerFIO,
WorkExperience = WorkExperience,
};
}
}

View File

@ -21,11 +21,12 @@ namespace LawFirmDatabaseImplement.Models
public OrderStatus Status { get; set; } public OrderStatus Status { get; set; }
[Required] [Required]
public DateTime DateCreate { get; set; } public DateTime DateCreate { get; set; }
public int? ImplementerId { get; private set; }
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
public virtual Document Document { get; set; } public virtual Document Document { get; set; }
public virtual Client Client { get; set; } public virtual Client Client { get; set; }
public int Id { get; set; } public virtual Implementer? Implementer { get; private set; }
public int Id { get; set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
@ -41,8 +42,9 @@ namespace LawFirmDatabaseImplement.Models
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement DateImplement = model.DateImplement,
}; ImplementerId = model.ImplementerId,
};
} }
public void Update(OrderBindingModel? model) public void Update(OrderBindingModel? model)
@ -51,22 +53,30 @@ namespace LawFirmDatabaseImplement.Models
{ {
return; return;
} }
Status = model.Status; DocumentId = model.DocumentId;
DateImplement = model.DateImplement; Count = model.Count;
} Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
Id = model.Id;
}
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
DocumentId = DocumentId, DocumentId = DocumentId,
ClientId = ClientId, ClientId = ClientId,
ClientFIO = Client.ClientFIO, ClientFIO = Client.ClientFIO,
Count = Count, ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, DateImplement = DateImplement,
DocumentName = Document.DocumentName DocumentName = Document.DocumentName,
}; ImplementerId = ImplementerId
};
} }
} }

View File

@ -10,13 +10,15 @@ namespace LawFirmFileImplement
private readonly string OrderFileName = "Order.xml"; private readonly string OrderFileName = "Order.xml";
private readonly string DocumentFileName = "Document.xml"; private readonly string DocumentFileName = "Document.xml";
private readonly string ClientFileName = "Client.xml"; private readonly string ClientFileName = "Client.xml";
private readonly string ImplementerFileName = "Implementer.xml";
public List<Blank> Blanks { get; private set; } public List<Blank> Blanks { get; private set; }
public List<Order> Orders { get; private set; } public List<Order> Orders { get; private set; }
public List<Document> Documents { get; private set; } public List<Document> Documents { get; private set; }
public List<Client> Clients { get; private set; } public List<Client> Clients { get; private set; }
public List<Implementer> Implementers { get; private set; }
public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance()
{ {
if (instance == null) if (instance == null)
{ {
@ -28,14 +30,15 @@ namespace LawFirmFileImplement
public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
Orders = new List<Order>(); Orders = new List<Order>();
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
} Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Func<XElement, T> selectFunction) Func<XElement, T> selectFunction)
{ {

View File

@ -0,0 +1,96 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataFileSingleton _source;
public ImplementerStorage()
{
_source = DataFileSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
_source.Implementers.Remove(res);
_source.SaveImplementers();
}
return res?.GetViewModel;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (model.Id.HasValue)
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null)
return _source.Implementers
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.ImplementerFIO != null)
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально)
{
return _source.Implementers
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ImplementerViewModel> GetFullList()
{
return _source.Implementers.Select(x => x.GetViewModel).ToList();
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
var res = Implementer.Create(model);
if (res != null)
{
_source.Implementers.Add(res);
_source.SaveImplementers();
}
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
res.Update(model);
_source.SaveImplementers();
}
return res?.GetViewModel;
}
}
}

View File

@ -33,7 +33,14 @@ namespace LawFirmFileImplement.Implements
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
var result = GetElement(model); if (!model.Id.HasValue && model.OrderStatus.HasValue)
{
return _source.Orders
.Where(x => model.OrderStatus == x.Status)
.Select(x => x.GetViewModel)
.ToList();
}
var result = GetElement(model);
return result != null ? new() { result } : new(); return result != null ? new() { result } : new();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
@ -42,8 +49,20 @@ namespace LawFirmFileImplement.Implements
{ {
return null; return null;
} }
if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
return _source.Orders.FirstOrDefault(x => {
return _source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
model.OrderStatus == x.Status)
?.GetViewModel;
}
if (model.ImplementerId.HasValue)
{
return _source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
return _source.Orders.FirstOrDefault(x =>
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel; (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
private OrderViewModel GetViewModel(Order order) private OrderViewModel GetViewModel(Order order)

View File

@ -0,0 +1,85 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmFileImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
ImplementerFIO = element.Element("FIO")!.Value,
Password = element.Element("Password")!.Value,
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
};
}
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFIO = model.ImplementerFIO,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFIO = model.ImplementerFIO;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFIO = ImplementerFIO,
};
public XElement GetXElement => new("Client",
new XAttribute("Id", Id),
new XElement("Password", Password),
new XElement("FIO", ImplementerFIO),
new XElement("Qualification", Qualification),
new XElement("WorkExperience", WorkExperience)
);
}
}

View File

@ -11,7 +11,8 @@ namespace LawFirmFileImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
public int DocumentId { get; private set; } public int DocumentId { get; private set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int Count { get; private set; } public int? ImplementerId { get; set; }
public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
@ -32,7 +33,8 @@ namespace LawFirmFileImplement.Models
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement, DateImplement = model.DateImplement,
}; ImplementerId = model.ImplementerId
};
} }
public static Order? Create(XElement element) public static Order? Create(XElement element)
{ {
@ -40,13 +42,19 @@ namespace LawFirmFileImplement.Models
{ {
return null; return null;
} }
var order = new Order() var dateImplement = element.Element("DateImplement")!.Value;
var order = new Order()
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value) Sum = Convert.ToDouble(element.Element("Sum")!.Value),
}; Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
};
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
order.DateImplement = dateImpl; order.DateImplement = dateImpl;
@ -63,9 +71,15 @@ namespace LawFirmFileImplement.Models
{ {
return; return;
} }
Status = model.Status; DocumentId = model.DocumentId;
DateImplement = model.DateImplement; Count = model.Count;
} Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
ImplementerId = model.ImplementerId;
DateImplement = model.DateImplement;
Id = model.Id;
}
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
DocumentId = DocumentId, DocumentId = DocumentId,
@ -76,6 +90,7 @@ namespace LawFirmFileImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
Id = Id, Id = Id,
Status = Status, Status = Status,
ImplementerId= ImplementerId
}; };
public XElement GetXElement => new("Order", public XElement GetXElement => new("Order",
new XAttribute("Id", Id), new XAttribute("Id", Id),
@ -84,7 +99,8 @@ namespace LawFirmFileImplement.Models
new XElement("Sum", Sum.ToString()), new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()), new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()), new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString())); new XElement("DateImplement", DateImplement.ToString()),
new XElement("ImplementerId", ImplementerId));
} }
} }

View File

@ -9,14 +9,16 @@ namespace LawFirmListImplement
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Document> Documents { get; set; } public List<Document> Documents { get; set; }
public List<Client> Clients { get; set; } public List<Client> Clients { get; set; }
public List<Implementer> Implementers { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Blanks = new List<Blank>(); Blanks = new List<Blank>();
Orders = new List<Order>(); Orders = new List<Order>();
Documents = new List<Document>(); Documents = new List<Document>();
Clients = new List<Client>(); Clients = new List<Client>();
} Implementers = new List<Implementer>();
}
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {
if (_instance == null) if (_instance == null)

View File

@ -0,0 +1,119 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmListImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataListSingleton _source;
public ImplementerStorage()
{
_source = DataListSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
for (int i = 0; i < _source.Implementers.Count; ++i)
{
if (_source.Implementers[i].Id == model.Id)
{
var element = _source.Implementers[i];
_source.Implementers.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
foreach (var x in _source.Implementers)
{
if (model.Id.HasValue && x.Id == model.Id)
return x.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null &&
x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))
return x.GetViewModel;
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
return x.GetViewModel;
}
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
// На случай если при расширении проекта фио не будет уникальным
// (по заданию оно уникально)
List<ImplementerViewModel> result = new();
if (model.ImplementerFIO != null)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
{
result.Add(implementer.GetViewModel);
}
}
}
return result;
}
public List<ImplementerViewModel> GetFullList()
{
var result = new List<ImplementerViewModel>();
foreach (var implementer in _source.Implementers)
{
result.Add(implementer.GetViewModel);
}
return result;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = 1;
foreach (var implementer in _source.Implementers)
{
if (model.Id <= implementer.Id)
{
model.Id = implementer.Id + 1;
}
}
var res = Implementer.Create(model);
if (res != null)
{
_source.Implementers.Add(res);
}
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
implementer.Update(model);
return implementer.GetViewModel;
}
}
return null;
}
}
}

View File

@ -32,10 +32,10 @@ namespace LawFirmListImplement.Implements
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
if (order.Id == model.Id || if (order.Id == model.Id ||
model.DateFrom <= order.DateCreate && model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo ||
order.DateCreate <= model.DateTo || model.ClientId.HasValue && order.ClientId == model.ClientId ||
model.ClientId.HasValue && model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId ||
order.ClientId == model.ClientId) model.OrderStatus.HasValue && model.OrderStatus == order.Status)
{ {
result.Add(GetViewModel(order)); result.Add(GetViewModel(order));
} }
@ -51,11 +51,20 @@ namespace LawFirmListImplement.Implements
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
if (model.Id.HasValue && order.Id == model.Id) if (order.Id == model.Id)
{ {
return GetViewModel(order); return GetViewModel(order);
} }
} else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue &&
order.ImplementerId == model.ImplementerId && model.OrderStatus == order.Status)
{
return GetViewModel(order);
}
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
{
return GetViewModel(order);
}
}
return null; return null;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -0,0 +1,60 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmListImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFIO = model.ImplementerFIO,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFIO = model.ImplementerFIO;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFIO = ImplementerFIO,
};
}
}

View File

@ -10,7 +10,8 @@ namespace LawFirmListImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
public int DocumentId { get; private set; } public int DocumentId { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int Count { get; private set; } public int? ImplementerId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
@ -30,8 +31,9 @@ namespace LawFirmListImplement.Models
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement DateImplement = model.DateImplement,
}; ImplementerId = model.ImplementerId,
};
} }
public void Update(OrderBindingModel? model) public void Update(OrderBindingModel? model)
{ {
@ -39,9 +41,15 @@ namespace LawFirmListImplement.Models
{ {
return; return;
} }
Status = model.Status; DocumentId = model.DocumentId;
DateImplement = model.DateImplement; Count = model.Count;
} Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
Id = model.Id;
}
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
@ -51,7 +59,8 @@ namespace LawFirmListImplement.Models
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement DateImplement = DateImplement,
ImplementerId = ImplementerId
}; };
} }
} }

View File

@ -0,0 +1,102 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
namespace LawFirmRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ImplementerController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IImplementerLogic _logic;
public ImplementerController(IOrderLogic order, IImplementerLogic logic,
ILogger<ImplementerController> logger)
{
_logger = logger;
_order = order;
_logic = logic;
}
[HttpGet]
public ImplementerViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ImplementerSearchModel
{
ImplementerFIO = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка авторизации сотрудника");
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetNewOrders()
{
try
{
return _order.ReadList(new OrderSearchModel
{
OrderStatus = OrderStatus.Принят
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения новых заказов");
throw;
}
}
[HttpGet]
public OrderViewModel? GetImplementerOrder(int implementerId)
{
try
{
return _order.ReadElement(new OrderSearchModel
{
ImplementerId = implementerId
});
}
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;
}
}
}
}

View File

@ -25,7 +25,22 @@ namespace LawFirmView
_logicO = logicO; _logicO = logicO;
_clientLogic = clientLogic; _clientLogic = clientLogic;
_list = logicD.ReadList(null); _list = logicD.ReadList(null);
} if (_list != null)
{
comboBoxDocument.DisplayMember = "PastryName";
comboBoxDocument.ValueMember = "Id";
comboBoxDocument.DataSource = _list;
comboBoxDocument.SelectedItem = null;
}
var clients = _clientLogic.ReadList(null);
if (clients != null)
{
comboBoxClient.DisplayMember = "clientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = clients;
comboBoxClient.SelectedItem = null;
}
}
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
{ {
_logger.LogInformation("Загрузка документов для заказа"); _logger.LogInformation("Загрузка документов для заказа");

View File

@ -0,0 +1,173 @@
namespace LawFirmView
{
partial class FormImplementer
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
textBoxFio = new TextBox();
textBoxPassword = new TextBox();
numericUpDownWorkExperience = new NumericUpDown();
numericUpDownQualification = new NumericUpDown();
buttonCancel = new Button();
buttonSave = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownQualification).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(79, 12);
label1.Name = "label1";
label1.Size = new Size(37, 15);
label1.TabIndex = 0;
label1.Text = "ФИО:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(69, 41);
label2.Name = "label2";
label2.Size = new Size(52, 15);
label2.TabIndex = 1;
label2.Text = "Пароль:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(78, 68);
label3.Name = "label3";
label3.Size = new Size(38, 15);
label3.TabIndex = 2;
label3.Text = "Стаж:";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(25, 97);
label4.Name = "label4";
label4.Size = new Size(91, 15);
label4.TabIndex = 3;
label4.Text = "Квалификация:";
//
// textBoxFio
//
textBoxFio.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxFio.Location = new Point(127, 9);
textBoxFio.Name = "textBoxFio";
textBoxFio.Size = new Size(271, 23);
textBoxFio.TabIndex = 4;
//
// textBoxPassword
//
textBoxPassword.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxPassword.Location = new Point(127, 38);
textBoxPassword.Name = "textBoxPassword";
textBoxPassword.PasswordChar = '*';
textBoxPassword.Size = new Size(271, 23);
textBoxPassword.TabIndex = 5;
//
// numericUpDownWorkExperience
//
numericUpDownWorkExperience.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
numericUpDownWorkExperience.Location = new Point(127, 66);
numericUpDownWorkExperience.Name = "numericUpDownWorkExperience";
numericUpDownWorkExperience.Size = new Size(271, 23);
numericUpDownWorkExperience.TabIndex = 6;
//
// numericUpDownQualification
//
numericUpDownQualification.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
numericUpDownQualification.Location = new Point(127, 95);
numericUpDownQualification.Name = "numericUpDownQualification";
numericUpDownQualification.Size = new Size(271, 23);
numericUpDownQualification.TabIndex = 7;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(309, 138);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(89, 33);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(214, 138);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(89, 33);
buttonSave.TabIndex = 9;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// FormImplementer
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(410, 183);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
Controls.Add(numericUpDownQualification);
Controls.Add(numericUpDownWorkExperience);
Controls.Add(textBoxPassword);
Controls.Add(textBoxFio);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormImplementer";
Text = "Добавление / Редактирование исполнителя";
Load += FormImplementer_Load;
((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownQualification).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private TextBox textBoxFio;
private TextBox textBoxPassword;
private NumericUpDown numericUpDownWorkExperience;
private NumericUpDown numericUpDownQualification;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,101 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormImplementer : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxFio.Text = view.ImplementerFIO;
textBoxPassword.Text = view.Password;
numericUpDownQualification.Value = view.Qualification;
numericUpDownWorkExperience.Value = view.WorkExperience;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
MessageBox.Show("Заполните пароль", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxFio.Text))
{
MessageBox.Show("Заполните фио", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение исполнителя");
try
{
var model = new ImplementerBindingModel
{
Id = _id ?? 0,
ImplementerFIO = textBoxFio.Text,
Password = textBoxPassword.Text,
Qualification = (int)numericUpDownQualification.Value,
WorkExperience = (int)numericUpDownWorkExperience.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -28,182 +28,200 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonCreateOrder = new System.Windows.Forms.Button(); this.startWorksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout(); this.buttonIssuedOrder = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.buttonUpdate = new System.Windows.Forms.Button();
this.SuspendLayout(); this.menuStrip1.SuspendLayout();
// ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
// menuStrip1 this.SuspendLayout();
// //
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { // menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem, this.справочникиToolStripMenuItem,
this.отчетыToolStripMenuItem}); this.отчетыToolStripMenuItem,
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.startWorksToolStripMenuItem});
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Size = new System.Drawing.Size(800, 24); this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.TabIndex = 0; this.menuStrip1.Size = new System.Drawing.Size(800, 24);
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.TabIndex = 0;
// this.menuStrip1.Text = "menuStrip1";
// справочникиToolStripMenuItem //
// // справочникиToolStripMenuItem
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { //
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.бланкиToolStripMenuItem, this.бланкиToolStripMenuItem,
this.документыToolStripMenuItem, this.документыToolStripMenuItem,
this.клиентыToolStripMenuItem}); this.клиентыToolStripMenuItem,
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.исполнителиToolStripMenuItem});
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Text = "Справочники"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
// this.справочникиToolStripMenuItem.Text = "Справочники";
// бланкиToolStripMenuItem //
// // бланкиToolStripMenuItem
this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; //
this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem";
this.бланкиToolStripMenuItem.Text = "Бланки"; this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click); this.бланкиToolStripMenuItem.Text = "Бланки";
// this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click);
// документыToolStripMenuItem //
// // документыToolStripMenuItem
this.документыToolStripMenuItem.Name = окументыToolStripMenuItem"; //
this.документыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.документыToolStripMenuItem.Name = окументыToolStripMenuItem";
this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click); this.документыToolStripMenuItem.Text = "Документы";
// this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click);
// клиентыToolStripMenuItem //
// // клиентыToolStripMenuItem
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; //
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); this.клиентыToolStripMenuItem.Text = "Клиенты";
// this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
// отчетыToolStripMenuItem //
// // исполнителиToolStripMenuItem
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { //
this.исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.исполнителиToolStripMenuItem.Text = "Исполнители";
this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
//
// отчетыToolStripMenuItem
//
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.списокКомпонентовToolStripMenuItem, this.списокКомпонентовToolStripMenuItem,
this.компонентыПоИзделиямToolStripMenuItem, this.компонентыПоИзделиямToolStripMenuItem,
this.списокЗаказовToolStripMenuItem}); this.списокЗаказовToolStripMenuItem});
this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 20);
this.отчетыToolStripMenuItem.Text = "Отчеты"; this.отчетыToolStripMenuItem.Text = "Отчеты";
// //
// списокКомпонентовToolStripMenuItem // списокКомпонентовToolStripMenuItem
// //
this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(218, 22); this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; this.списокКомпонентовToolStripMenuItem.Text = "Список компонентов";
this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.BlanksReportToolStripMenuItem_Click); this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.BlanksReportToolStripMenuItem_Click);
// //
// компонентыПоИзделиямToolStripMenuItem // компонентыПоИзделиямToolStripMenuItem
// //
this.компонентыПоИзделиямToolStripMenuItem.Name = омпонентыПоИзделиямToolStripMenuItem"; this.компонентыПоИзделиямToolStripMenuItem.Name = омпонентыПоИзделиямToolStripMenuItem";
this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(218, 22); this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; this.компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям";
this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.DocumentBlanksReportToolStripMenuItem_Click); this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.DocumentBlanksReportToolStripMenuItem_Click);
// //
// списокЗаказовToolStripMenuItem // списокЗаказовToolStripMenuItem
// //
this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(218, 22); this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Text = "Список заказов";
this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersReportToolStripMenuItem_Click); this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersReportToolStripMenuItem_Click);
// //
// dataGridView // startWorksToolStripMenuItem
// //
this.dataGridView.AllowUserToAddRows = false; this.startWorksToolStripMenuItem.Name = "startWorksToolStripMenuItem";
this.dataGridView.AllowUserToDeleteRows = false; this.startWorksToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
this.dataGridView.BackgroundColor = System.Drawing.Color.White; this.startWorksToolStripMenuItem.Text = "Запуск работ";
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.startWorksToolStripMenuItem.Click += new System.EventHandler(this.StartWorksToolStripMenuItem_Click);
this.dataGridView.Location = new System.Drawing.Point(12, 27); //
this.dataGridView.Name = "dataGridView"; // dataGridView
this.dataGridView.ReadOnly = true; //
this.dataGridView.RowTemplate.Height = 25; this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.Size = new System.Drawing.Size(566, 411); this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.TabIndex = 1; this.dataGridView.BackgroundColor = System.Drawing.Color.White;
// this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
// buttonCreateOrder this.dataGridView.Location = new System.Drawing.Point(12, 27);
// this.dataGridView.Name = "dataGridView";
this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27); this.dataGridView.ReadOnly = true;
this.buttonCreateOrder.Name = "buttonCreateOrder"; this.dataGridView.RowTemplate.Height = 25;
this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23); this.dataGridView.Size = new System.Drawing.Size(566, 411);
this.buttonCreateOrder.TabIndex = 2; this.dataGridView.TabIndex = 1;
this.buttonCreateOrder.Text = "Создать заказ"; //
this.buttonCreateOrder.UseVisualStyleBackColor = true; // buttonCreateOrder
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); //
// this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27);
// buttonTakeOrderInWork this.buttonCreateOrder.Name = "buttonCreateOrder";
// this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23);
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56); this.buttonCreateOrder.TabIndex = 2;
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; this.buttonCreateOrder.Text = "Создать заказ";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23); this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.TabIndex = 3; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; //
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; // buttonTakeOrderInWork
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); //
// this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56);
// buttonOrderReady this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
// this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23);
this.buttonOrderReady.Location = new System.Drawing.Point(605, 85); this.buttonTakeOrderInWork.TabIndex = 3;
this.buttonOrderReady.Name = "buttonOrderReady"; this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonOrderReady.Size = new System.Drawing.Size(168, 23); this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonOrderReady.TabIndex = 4; this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
this.buttonOrderReady.Text = "Заказ готов"; //
this.buttonOrderReady.UseVisualStyleBackColor = true; // buttonOrderReady
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); //
// this.buttonOrderReady.Location = new System.Drawing.Point(605, 85);
// buttonIssuedOrder this.buttonOrderReady.Name = "buttonOrderReady";
// this.buttonOrderReady.Size = new System.Drawing.Size(168, 23);
this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114); this.buttonOrderReady.TabIndex = 4;
this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonOrderReady.Text = "Заказ готов";
this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23); this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.TabIndex = 5; this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
this.buttonIssuedOrder.Text = "Заказ выдан"; //
this.buttonIssuedOrder.UseVisualStyleBackColor = true; // buttonIssuedOrder
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); //
// this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114);
// buttonUpdate this.buttonIssuedOrder.Name = "buttonIssuedOrder";
// this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23);
this.buttonUpdate.Location = new System.Drawing.Point(605, 143); this.buttonIssuedOrder.TabIndex = 5;
this.buttonUpdate.Name = "buttonUpdate"; this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonUpdate.Size = new System.Drawing.Size(168, 23); this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonUpdate.TabIndex = 6; this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
this.buttonUpdate.Text = "Обновить список"; //
this.buttonUpdate.UseVisualStyleBackColor = true; // buttonUpdate
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); //
// this.buttonUpdate.Location = new System.Drawing.Point(605, 143);
// FormMain this.buttonUpdate.Name = "buttonUpdate";
// this.buttonUpdate.Size = new System.Drawing.Size(168, 23);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.buttonUpdate.TabIndex = 6;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.buttonUpdate.Text = "Обновить список";
this.ClientSize = new System.Drawing.Size(800, 450); this.buttonUpdate.UseVisualStyleBackColor = true;
this.Controls.Add(this.buttonUpdate); this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click);
this.Controls.Add(this.buttonIssuedOrder); //
this.Controls.Add(this.buttonOrderReady); // FormMain
this.Controls.Add(this.buttonTakeOrderInWork); //
this.Controls.Add(this.buttonCreateOrder); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.Controls.Add(this.dataGridView); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.menuStrip1); this.ClientSize = new System.Drawing.Size(800, 450);
this.MainMenuStrip = this.menuStrip1; this.Controls.Add(this.buttonUpdate);
this.Name = "FormMain"; this.Controls.Add(this.buttonIssuedOrder);
this.Text = "Юридическая фирма"; this.Controls.Add(this.buttonOrderReady);
this.Load += new System.EventHandler(this.FormMain_Load); this.Controls.Add(this.buttonTakeOrderInWork);
this.menuStrip1.ResumeLayout(false); this.Controls.Add(this.buttonCreateOrder);
this.menuStrip1.PerformLayout(); this.Controls.Add(this.dataGridView);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.Controls.Add(this.menuStrip1);
this.ResumeLayout(false); this.MainMenuStrip = this.menuStrip1;
this.PerformLayout(); this.Name = "FormMain";
this.Text = "Юридическая фирма";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
} }
@ -224,5 +242,7 @@
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem;
} private ToolStripMenuItem startWorksToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem;
}
} }

View File

@ -12,13 +12,18 @@ namespace LawFirmView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic) public FormMain(ILogger<FormMain> logger,
IOrderLogic orderLogic,
IReportLogic reportLogic,
IWorkProcess workProcess)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_workProcess = workProcess;
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
{ {
@ -35,8 +40,9 @@ namespace LawFirmView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["DocumentId"].Visible = false; dataGridView.Columns["DocumentId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
} dataGridView.Columns["ImplementerId"].Visible = false;
_logger.LogInformation("Загрузка прошла успешно"); }
_logger.LogInformation("Загрузка прошла успешно");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -182,11 +188,9 @@ e)
MessageBoxIcon.Information); MessageBoxIcon.Information);
} }
} }
private void DocumentBlanksReportToolStripMenuItem_Click(object sender, private void DocumentBlanksReportToolStripMenuItem_Click(object sender, EventArgs e)
EventArgs e)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks));
Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks));
if (service is FormReportDocumentBlanks form) if (service is FormReportDocumentBlanks form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -209,5 +213,21 @@ e)
form.ShowDialog(); form.ShowDialog();
} }
} }
}
private void StartWorksToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers));
if (service is FormViewImplementers form)
{
form.ShowDialog();
}
}
}
} }

View File

@ -0,0 +1,121 @@
namespace LawFirmView
{
partial class FormViewImplementers
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonRef
//
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRef.Location = new System.Drawing.Point(391, 209);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(90, 37);
this.buttonRef.TabIndex = 9;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDel.Location = new System.Drawing.Point(391, 158);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(90, 33);
this.buttonDel.TabIndex = 8;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUpd.Location = new System.Drawing.Point(391, 109);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(90, 34);
this.buttonUpd.TabIndex = 7;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAdd.Location = new System.Drawing.Point(391, 64);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(90, 30);
this.buttonAdd.TabIndex = 6;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(343, 302);
this.dataGridView.TabIndex = 5;
//
// FormViewImplementers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(512, 319);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormViewImplementers";
this.Text = "Просмотр списка исполнителей";
this.Load += new System.EventHandler(this.FormViewImplementers_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,110 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
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 LawFirmView
{
public partial class FormViewImplementers : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
public FormViewImplementers(ILogger<FormViewImplementers> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormViewImplementers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
}
_logger.LogInformation("Загрузка исполнителей");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки исполнителей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление исполнителя");
try
{
if (!_logic.Delete(new ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления исполнителя");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -39,14 +39,17 @@ namespace LawFirmView
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDocumentStorage, DocumentStorage>(); services.AddTransient<IDocumentStorage, DocumentStorage>();
services.AddTransient<IClientStorage, ClientStorage>(); services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IBlankLogic, BlankLogic>(); services.AddTransient<IBlankLogic, BlankLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDocumentLogic, DocumentLogic>(); services.AddTransient<IDocumentLogic, DocumentLogic>();
services.AddTransient<IReportLogic, ReportLogic>(); services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>(); services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
@ -60,6 +63,8 @@ namespace LawFirmView
services.AddTransient<FormReportDocumentBlanks>(); services.AddTransient<FormReportDocumentBlanks>();
services.AddTransient<FormReportOrders>(); services.AddTransient<FormReportOrders>();
services.AddTransient<FormViewClients>(); services.AddTransient<FormViewClients>();
} services.AddTransient<FormViewImplementers>();
services.AddTransient<FormImplementer>();
}
} }
} }