Compare commits

...

12 Commits

135 changed files with 8559 additions and 51 deletions

View File

@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248 VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConstructionCompanyView", "ConstructionCompanyView\ConstructionCompanyView.csproj", "{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyView", "ConstructionCompanyView\ConstructionCompanyView.csproj", "{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyDataModels", "ConstructionCompanyDataModels\ConstructionCompanyDataModels.csproj", "{78CB5CC6-B587-41DD-B595-13138E6351C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConstructionCompanyContracts", "ConstructionCompanyContracts\ConstructionCompanyContracts.csproj", "{CFB66158-7025-4605-9739-C4A2F07D2EB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConstructionCompanyBusinessLogic", "ConstructionCompanyBusiness\ConstructionCompanyBusinessLogic.csproj", "{FB447245-07E1-4E0D-A4FC-701E295B7575}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConstructionCompanyPsqlImplement", "ConstructionCompanyPsqlImplement\ConstructionCompanyPsqlImplement.csproj", "{A92A2186-2021-4B42-B632-447A45EC3A58}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +23,22 @@ Global
{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Debug|Any CPU.Build.0 = Debug|Any CPU {E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.ActiveCfg = Release|Any CPU {E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.Build.0 = Release|Any CPU {E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.Build.0 = Release|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Release|Any CPU.Build.0 = Release|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Release|Any CPU.Build.0 = Release|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Release|Any CPU.Build.0 = Release|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,106 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly ILogger _logger;
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
{
_logger = logger;
_employeeStorage = employeeStorage;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeName:{EmployeeName}. Id:{Id}", model?.EmployeeName, model?.Id);
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, model.Id);
var element = _employeeStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_employeeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.EmployeeName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.EmployeeName));
}
_logger.LogInformation("Employee. EmployeeName:{EmployeeName}. PositionID:{PositionID}. Id:{Id}", model.EmployeeName, model.PositionID, model.Id);
}
}
}

View File

@ -0,0 +1,92 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class EmployeeOrderLogic : IEmployeeOrderLogic
{
private readonly ILogger _logger;
private readonly IEmployeeOrderStorage _employeeOrderStorage;
public EmployeeOrderLogic(ILogger<EmployeeOrderLogic> logger, IEmployeeOrderStorage employeeOrderStorage)
{
_logger = logger;
_employeeOrderStorage = employeeOrderStorage;
}
public List<EmployeeOrderViewModel>? ReadList(EmployeeOrderSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
var element = _employeeOrderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
return element;
}
public bool Create(EmployeeOrderBindingModel model)
{
CheckModel(model);
if (_employeeOrderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeOrderBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
if (_employeeOrderStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeOrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("EmployeeOrder. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
}
}
}

View File

@ -0,0 +1,122 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class MaterialLogic : IMaterialLogic
{
private readonly ILogger _logger;
private readonly IMaterialStorage _materialStorage;
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage materialStorage)
{
_logger = logger;
_materialStorage = materialStorage;
}
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
{
_logger.LogInformation("ReadList. MaterialName:{MaterialName}. Id:{Id}", model?.MaterialName, model?.Id);
var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MaterialViewModel? ReadElement(MaterialSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. MaterialName:{MaterialName}. Id:{Id}", model.MaterialName, model.Id);
var element = _materialStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(MaterialBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_materialStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MaterialBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MaterialName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.MaterialName));
}
if (model.Quantity < 0)
{
throw new ArgumentNullException("Количество материалов должна быть не меньше 0!", nameof(model.Quantity));
}
_logger.LogInformation("Material. IngredietnName:{MaterialName}. Cost:{Quantity}. Id:{Id}", model.MaterialName, model.Quantity, model.Id);
}
public List<EmployeeViewModel>? ReadEmployeesUsingMaterial(MaterialBindingModel model)
{
CheckModel(model, false);
var list = _materialStorage.GetEmployeesUsingMaterial(model);
if (list == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
return list;
}
}
}

View File

@ -0,0 +1,96 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class MaterialOrderLogic : IMaterialOrderLogic
{
private readonly ILogger _logger;
private readonly IMaterialOrderStorage _employeeOrderStorage;
public MaterialOrderLogic(ILogger<MaterialOrderLogic> logger, IMaterialOrderStorage employeeOrderStorage)
{
_logger = logger;
_employeeOrderStorage = employeeOrderStorage;
}
public List<MaterialOrderViewModel>? ReadList(MaterialOrderSearchModel? model)
{
_logger.LogInformation("ReadList. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MaterialOrderViewModel? ReadElement(MaterialOrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
var element = _employeeOrderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
return element;
}
public bool Create(MaterialOrderBindingModel model)
{
CheckModel(model);
if (_employeeOrderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(MaterialOrderBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
if (_employeeOrderStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MaterialOrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Quantity <= 0)
{
throw new InvalidOperationException("Количество должна быть больше 0!");
}
_logger.LogInformation("MaterialOrder. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
}
}
}

View File

@ -0,0 +1,145 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list.OrderBy(x => x.Id).ToList();
}
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;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Выполняется)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
}
model.Status = OrderStatus.Завершён;
model.DateEnd = DateTime.Today;
_orderStorage.Update(model);
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Принят)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
}
model.Status = OrderStatus.Выполняется;
_orderStorage.Update(model);
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Description))
{
throw new ArgumentNullException("Нет описания заказа", nameof(model.Description));
}
if (string.IsNullOrEmpty(model.Adress))
{
throw new ArgumentNullException("Нет адреса заказа", nameof(model.Adress));
}
if (model.Price <= 0)
{
throw new InvalidOperationException("Цена должна быть больше 0!");
}
if (string.IsNullOrEmpty(model.CustomerNumber))
{
throw new ArgumentNullException("Нет телефона", nameof(model.CustomerNumber));
}
_logger.LogInformation("Order. Description:{Description}. Adress:{Adress}. Price:{Price} Id:{Id}", model.Description, model.Adress, model.Price, model.Id);
}
}
}

View File

@ -0,0 +1,116 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class PositionLogic : IPositionLogic
{
private readonly ILogger _logger;
private readonly IPositionStorage _positionStorage;
public PositionLogic(ILogger<PositionLogic> logger, IPositionStorage positionStorage)
{
_logger = logger;
_positionStorage = positionStorage;
}
public List<PositionViewModel>? ReadList(PositionSearchModel? model)
{
_logger.LogInformation("ReadList. PositionName:{PositionName}. Id:{Id}", model?.PositionName, model?.Id);
var list = model == null ? _positionStorage.GetFullList() : _positionStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PositionViewModel? ReadElement(PositionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PositionName:{PositionName}. Id:{Id}", model.PositionName, model.Id);
var element = _positionStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PositionBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_positionStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PositionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PositionName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.PositionName));
}
if (model.Salary < 0)
{
throw new ArgumentNullException("Зарплата должна быть не меньше 0!", nameof(model.Salary));
}
_logger.LogInformation("Position. IngredietnName:{PositionName}. Salary:{Salary}. Id:{Id}", model.PositionName, model.Salary, model.Id);
}
public List<BrigadeReportViewModel> ReadPositionsAverage(DateTime dateFrom, DateTime dateTo)
{
var list = _positionStorage.GetPositionsAverage(dateFrom, dateTo);
return list;
}
}
}

View File

@ -0,0 +1,105 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class RandomGeneratorLogic : IRandomGeneratorLogic
{
private readonly IMaterialLogic _material;
private readonly IEmployeeLogic _employee;
private readonly IPositionLogic _position;
private readonly IOrderLogic _order;
private readonly IMaterialOrderLogic _materialOrder;
private readonly IEmployeeOrderLogic _employeeOrder;
public RandomGeneratorLogic(IMaterialLogic material, IEmployeeLogic employee, IPositionLogic position, IOrderLogic order, IMaterialOrderLogic materialOrder, IEmployeeOrderLogic employeeOrder)
{
_material = material;
_employee = employee;
_position = position;
_order = order;
_materialOrder = materialOrder;
_employeeOrder = employeeOrder;
}
public void GenerateEmployees()
{
int posInd = 1;
for (int i = 0; i < 200; i++)
{
_employee.Create(new EmployeeBindingModel { EmployeeName = "testEmp" + (i + 1), PositionID = posInd });
posInd++;
if (posInd == 11) posInd = 1;
}
}
public void GenerateEmployeesOrders()
{
for (int i = 1; i <= 200; i++)
{
_employeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = i, OrderId = i});
}
}
public void GenerateMaterialOrders()
{
int quantity = 1;
for (int i = 1; i <= 200; i++)
{
_materialOrder.Create(new MaterialOrderBindingModel { MaterialId = i, OrderId = i, Quantity = quantity});
quantity++;
if (quantity == 7) quantity = 1;
}
}
public void GenerateAdditionalMaterialOrders()
{
Random rand = new Random();
int quantity = 1;
for (int i = 1; i <= 100; i++)
{
int mat = rand.Next(1, 10);
int ord = rand.Next(1, 100);
if (_materialOrder.ReadElement(new MaterialOrderSearchModel { MaterialId = mat, OrderId = ord}) != null)
{
i--;
continue;
}
_materialOrder.Create(new MaterialOrderBindingModel { MaterialId = mat, OrderId = ord, Quantity = quantity });
quantity++;
if (quantity == 7) quantity = 1;
}
}
public void GenerateMaterials()
{
for (int i = 0; i < 200; i++)
{
_material.Create(new MaterialBindingModel { MaterialName = "testMat" + (i + 1), Quantity = 2000 });
}
}
public void GenerateOrders()
{
for (int i = 0; i < 1000; i++)
{
_order.CreateOrder(new OrderBindingModel { Description = "order" + (i + 1), Adress = "dsdsdssd", Price=20000, Status=OrderStatus.Неизвестен, CustomerNumber="+7838347475"});
}
}
public void GeneratePositions()
{
for (int i = 0; i < 20; i++)
{
_position.Create(new PositionBindingModel { PositionName = "testPos" + (i + 1), Salary = 20000 });
}
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,114 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class EmployeeLogic :IEmployeeLogic
{
private readonly ILogger _logger;
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
{
_logger = logger;
_employeeStorage = employeeStorage;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeName:{EmployeeName}. Id:{Id}", model?.EmployeeName, model?.Id);
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, model.Id);
var element = _employeeStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_employeeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.EmployeeName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.EmployeeName));
}
_logger.LogInformation("Employee. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, model.Id);
var element = _employeeStorage.GetElement(new EmployeeSearchModel
{
EmployeeName = model.EmployeeName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Сотрудник с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,118 @@
using ConstructionCompanyContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.BindingModels;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class MaterialLogic : IMaterialLogic
{
private readonly ILogger _logger;
private readonly IMaterialStorage _materialStorage;
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage materialStorage)
{
_logger = logger;
_materialStorage = materialStorage;
}
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
{
_logger.LogInformation("ReadList. MaterialName:{MaterialName}. Id:{Id}", model?.MaterialName, model?.Id);
var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MaterialViewModel? ReadElement(MaterialSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. MaterialName:{MaterialName}. Id:{Id}", model.MaterialName, model.Id);
var element = _materialStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(MaterialBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_materialStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MaterialBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MaterialName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.MaterialName));
}
if (model.Quantity < 0)
{
throw new ArgumentNullException("Колчество материалов должна быть не меньше 0", nameof(model.Quantity));
}
_logger.LogInformation("Material. IngredietnName:{MaterialName}. Quantity:{Quantity}. Id:{Id}", model.MaterialName, model.Quantity, model.Id);
var element = _materialStorage.GetElement(new MaterialSearchModel
{
MaterialName = model.MaterialName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Материал с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,135 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
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;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Выполняется)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
}
model.Status = OrderStatus.Завершён;
_orderStorage.Update(model);
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Принят)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
}
model.Status = OrderStatus.Выполняется;
_orderStorage.Update(model);
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Order. Id:{Id}", model.Id);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Заказ с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,117 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class PositionLogic
{
private readonly ILogger _logger;
private readonly IPositionStorage _positionStorage;
public PositionLogic(ILogger<PositionLogic> logger, IPositionStorage positionStorage)
{
_logger = logger;
_positionStorage = positionStorage;
}
public List<PositionViewModel>? ReadList(PositionSearchModel? model)
{
_logger.LogInformation("ReadList. PositionName:{PositionName}. Id:{Id}", model?.PositionName, model?.Id);
var list = model == null ? _positionStorage.GetFullList() : _positionStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PositionViewModel? ReadElement(PositionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PositionName:{PositionName}. Id:{Id}", model.PositionName, model.Id);
var element = _positionStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PositionBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_positionStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PositionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PositionName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.PositionName));
}
if (model.Salary < 0)
{
throw new ArgumentNullException("Зарплата должна быть не меньше 0", nameof(model.Salary));
}
_logger.LogInformation("Position. PositionName:{PositionName}. Salary:{Salary}. Id:{Id}", model.PositionName, model.Salary, model.Id);
var element = _positionStorage.GetElement(new PositionSearchModel
{
PositionName = model.PositionName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Должность с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,7 @@
namespace ConstructionCompanyBusiness
{
public class Class1
{
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,18 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class EmployeeBindingModel : IEmployeeModel
{
public string EmployeeName { get; set; } = string.Empty;
public int PositionID { get; set; }
public int Id {get; set; }
}
}

View File

@ -0,0 +1,15 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class EmployeeOrderBindingModel : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
public int OrderId { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class MaterialBindingModel : IMaterialModel
{
public string MaterialName { get; set; } = string.Empty;
public int Quantity { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class MaterialOrderBindingModel : IMaterialOrderModel
{
public int MaterialId { get; set; }
public int OrderId { get; set; }
public int Quantity { get; set; }
}
}

View File

@ -0,0 +1,29 @@
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public string Description { get; set; } = string.Empty;
public string Adress { get; set; } = string.Empty;
public double Price { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public string CustomerNumber { get; set; } = string.Empty;
public DateTime DateBegin { get; set; } = DateTime.Now.Date;
public DateTime? DateEnd { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class PositionBindingModel : IPositionModel
{
public string PositionName { get; set; } = string.Empty;
public double Salary { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IEmployeeLogic
{
List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model);
EmployeeViewModel? ReadElement(EmployeeSearchModel model);
bool Create(EmployeeBindingModel model);
bool Update(EmployeeBindingModel model);
bool Delete(EmployeeBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IEmployeeOrderLogic
{
List<EmployeeOrderViewModel>? ReadList(EmployeeOrderSearchModel? model);
EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model);
bool Create(EmployeeOrderBindingModel model);
bool Delete(EmployeeOrderBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IMaterialLogic
{
List<MaterialViewModel>? ReadList(MaterialSearchModel? model);
MaterialViewModel? ReadElement(MaterialSearchModel model);
List<EmployeeViewModel>? ReadEmployeesUsingMaterial(MaterialBindingModel model);
bool Create(MaterialBindingModel model);
bool Update(MaterialBindingModel model);
bool Delete(MaterialBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IMaterialOrderLogic
{
List<MaterialOrderViewModel>? ReadList(MaterialOrderSearchModel? model);
MaterialOrderViewModel? ReadElement(MaterialOrderSearchModel model);
bool Create(MaterialOrderBindingModel model);
bool Delete(MaterialOrderBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IPositionLogic
{
List<PositionViewModel>? ReadList(PositionSearchModel? model);
PositionViewModel? ReadElement(PositionSearchModel model);
List<BrigadeReportViewModel>? ReadPositionsAverage(DateTime dateFrom, DateTime dateTo);
bool Create(PositionBindingModel model);
bool Update(PositionBindingModel model);
bool Delete(PositionBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IRandomGeneratorLogic
{
public void GenerateMaterials();
public void GenerateOrders();
public void GeneratePositions();
public void GenerateEmployees();
public void GenerateEmployeesOrders();
public void GenerateMaterialOrders();
public void GenerateAdditionalMaterialOrders();
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyDataModels\ConstructionCompanyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class EmployeeOrderSearchModel
{
public int? EmployeeId { get; set; }
public int? OrderId { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class EmployeeSearchModel
{
public int? Id { get; set; }
public string? EmployeeName { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class MaterialOrderSearchModel
{
public int? MaterialId { get; set; }
public int? OrderId { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class MaterialSearchModel
{
public int? Id { get; set; }
public string? MaterialName { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class PositionSearchModel
{
public int? Id { get; set; }
public string? PositionName { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IEmployeeOrderStorage
{
List<EmployeeOrderViewModel> GetFullList();
List<EmployeeOrderViewModel> GetFilteredList(EmployeeOrderSearchModel model);
EmployeeOrderViewModel? GetElement(EmployeeOrderSearchModel model);
EmployeeOrderViewModel? Insert(EmployeeOrderBindingModel model);
EmployeeOrderViewModel? Delete(EmployeeOrderBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IEmployeeStorage
{
List<EmployeeViewModel> GetFullList();
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
EmployeeViewModel? GetElement(EmployeeSearchModel model);
EmployeeViewModel? Insert(EmployeeBindingModel model);
EmployeeViewModel? Update(EmployeeBindingModel model);
EmployeeViewModel? Delete(EmployeeBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IMaterialOrderStorage
{
List<MaterialOrderViewModel> GetFullList();
List<MaterialOrderViewModel> GetFilteredList(MaterialOrderSearchModel model);
MaterialOrderViewModel? GetElement(MaterialOrderSearchModel model);
MaterialOrderViewModel? Insert(MaterialOrderBindingModel model);
MaterialOrderViewModel? Delete(MaterialOrderBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IMaterialStorage
{
List<MaterialViewModel> GetFullList();
List<MaterialViewModel> GetFilteredList(MaterialSearchModel model);
List<EmployeeViewModel>? GetEmployeesUsingMaterial(MaterialBindingModel model);
MaterialViewModel? GetElement(MaterialSearchModel model);
MaterialViewModel? Insert(MaterialBindingModel model);
MaterialViewModel? Update(MaterialBindingModel model);
MaterialViewModel? Delete(MaterialBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IPositionStorage
{
List<PositionViewModel> GetFullList();
List<PositionViewModel> GetFilteredList(PositionSearchModel model);
List<BrigadeReportViewModel> GetPositionsAverage(DateTime dateFrom, DateTime dateTo);
PositionViewModel? GetElement(PositionSearchModel model);
PositionViewModel? Insert(PositionBindingModel model);
PositionViewModel? Update(PositionBindingModel model);
PositionViewModel? Delete(PositionBindingModel model);
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class BrigadeReportViewModel
{
public int PositionId { get; set; }
[DisplayName("Название должности")]
public string PositionName { get; set; } = string.Empty;
[DisplayName("Среденее потребление материалров")]
public double materialAvg { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class EmployeeOrderViewModel : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
[DisplayName("ФИО сотрудника")]
public string EmployeeName { get; set; } = string.Empty;
public int OrderId { get; set; }
[DisplayName("Адресс заказа")]
public string OrderAdress { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,22 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class EmployeeViewModel : IEmployeeModel
{
[DisplayName("ФИО")]
public string EmployeeName {get; set;} = string.Empty;
public int PositionID {get; set;}
[DisplayName("Должность")]
public string PositionName { get; set;} = string.Empty;
public int Id { get; set;}
}
}

View File

@ -0,0 +1,22 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class MaterialOrderViewModel : IMaterialOrderModel
{
public int MaterialId { get; set; }
[DisplayName("Адресс заказа")]
public string OrderAdress { get; set; } = string.Empty;
[DisplayName("Название материала")]
public string MaterialName { get; set; } = string.Empty;
public int OrderId { get; set; }
[DisplayName("Количество")]
public int Quantity { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class MaterialViewModel : IMaterialModel
{
[DisplayName("Название материала")]
public string MaterialName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Quantity {get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,31 @@
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
[DisplayName("Описание")]
public string Description {get;set;} = string.Empty;
[DisplayName("Адрес")]
public string Adress {get;set;} = string.Empty;
[DisplayName("Стоимость")]
public double Price { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Телефон заказчика")]
public string CustomerNumber { get; set; } = string.Empty;
[DisplayName("Дата создания")]
public DateTime DateBegin { get; set; } = DateTime.Now.Date;
[DisplayName("Дата выполнения")]
public DateTime? DateEnd { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class PositionViewModel : IPositionModel
{
[DisplayName("Название должности")]
public string PositionName { get; set; } = string.Empty;
[DisplayName("Зарплата")]
public double Salary { get; set; }
public int Id { get; set; }
}
}

View File

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

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Enums
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Завершён = 2
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IEmployeeModel : IId
{
string EmployeeName { get; }
int PositionID { get; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IEmployeeOrderModel
{
int EmployeeId { get; }
int OrderId { get; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IMaterialModel : IId
{
string MaterialName { get; }
int Quantity { get; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IMaterialOrderModel
{
int MaterialId { get; }
int OrderId { get; }
int Quantity { get; }
}
}

View File

@ -0,0 +1,20 @@
using ConstructionCompanyDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IOrderModel : IId
{
string Description { get; }
string Adress { get; }
double Price { get; }
OrderStatus Status { get; }
string CustomerNumber { get; }
DateTime DateBegin { get; }
DateTime? DateEnd { get; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IPositionModel : IId
{
string PositionName { get; }
double Salary { get; }
}
}

View File

@ -0,0 +1,261 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConstructionCompanyPsqlImplement.Models;
using ConstructionCompanyContracts.BindingModels;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using ConstructionCompanyDataModels.Enums;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
namespace ConstructionCompanyPsqlImplement
{
public class ConstructionCompanyDatabase
{
static string connectionString = "Server=192.168.1.35;Port=5432;Database=ConstructionCompanyForwardEngineerd;User Id=postgres;Password=postgres;";
private static ConstructionCompanyDatabase? _instance;
private List<Material> _materials = new List<Material>();
private List<Employee> _employees = new List<Employee>();
private List<Position> _positions = new List<Position>();
private List<Order> _orders = new List<Order>();
private List<EmployeeOrder> _employeeOrders = new List<EmployeeOrder>();
private List<MaterialOrder> _materialOrders = new List<MaterialOrder>();
public List<Material> Materials
{
get
{
refreshDb();
return _materials;
}
}
public List<Employee> Employees
{
get
{
refreshDb();
return _employees;
}
}
public List<Position> Positions
{
get
{
refreshDb();
return _positions;
}
}
public List<Order> Orders
{
get
{
refreshDb();
return _orders;
}
}
public List<EmployeeOrder> EmployeeOrders
{
get
{
refreshDb();
return _employeeOrders;
}
}
public List<MaterialOrder> MaterialOrders
{
get
{
refreshDb();
return _materialOrders;
}
}
public static ConstructionCompanyDatabase GetInstance()
{
if (_instance == null)
{
_instance = new ConstructionCompanyDatabase();
}
return _instance;
}
public void ExecuteSql(string commandString)
{
using var connection = new NpgsqlConnection(connectionString);
connection.Open();
using var command = connection.CreateCommand();
command.CommandText = commandString;
command.ExecuteNonQuery();
refreshDb();
connection.Close();
}
public List<List<string>> ExecuteReader(string commandString, int numOfFields)
{
using var connection = new NpgsqlConnection(connectionString);
connection.Open();
using var commandMaterials = connection.CreateCommand();
commandMaterials.CommandText = commandString;
using var reader = commandMaterials.ExecuteReader();
List<List<string>> res = new List<List<string>>();
while (reader.Read())
{
List<string> item = new List<string>();
for (int i =0; i < numOfFields; i++)
{
item.Add(reader.GetValue(i).ToString());
}
res.Add(item);
}
return res;
}
private void refreshDb()
{
_materials.Clear();
_positions.Clear();
_employees.Clear();
_orders.Clear();
_employeeOrders.Clear();
_materialOrders.Clear();
using var connection = new NpgsqlConnection(connectionString);
connection.Open();
using var commandMaterials = connection.CreateCommand();
commandMaterials.CommandText = "SELECT * FROM material;";
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using var readerMaterials = commandMaterials.ExecuteReader();
stopwatch.Stop();
long materialsTime = stopwatch.ElapsedMilliseconds;
while (readerMaterials.Read())
{
int id = readerMaterials.GetInt32(0);
string name = readerMaterials.GetString(1);
int quantity = readerMaterials.GetInt32(2);
Material? mat = Material.Create(new MaterialBindingModel { Id = id, MaterialName = name, Quantity = quantity });
if (mat != null) _materials.Add(mat);
}
readerMaterials.Close();
using var commandPositions = connection.CreateCommand();
commandPositions.CommandText = "SELECT * FROM position;";
stopwatch.Restart();
using var readerPositions = commandPositions.ExecuteReader();
stopwatch.Stop();
long positionsTime = stopwatch.ElapsedMilliseconds;
while (readerPositions.Read())
{
int id = readerPositions.GetInt32(0);
string name = readerPositions.GetString(1);
double salary = readerPositions.GetDouble(2);
Position? position = Position.Create(new PositionBindingModel { Id = id, PositionName = name, Salary = salary });
if (position != null) _positions.Add(position);
}
readerPositions.Close();
using var commandEmployees = connection.CreateCommand();
commandEmployees.CommandText = "SELECT * FROM employee;";
stopwatch.Restart();
using var readerEmployees = commandEmployees.ExecuteReader();
stopwatch.Stop();
long employeesTime = stopwatch.ElapsedMilliseconds;
while (readerEmployees.Read())
{
int id = readerEmployees.GetInt32(0);
string name = readerEmployees.GetString(1);
int positionId = readerEmployees.GetInt32(2);
Employee? employee = Employee.Create(new EmployeeBindingModel { Id = id, EmployeeName = name, PositionID = positionId }, _positions);
if (employee != null) _employees.Add(employee);
}
readerEmployees.Close();
using var commandOrders = connection.CreateCommand();
commandOrders.CommandText = "SELECT * FROM \"order\";";
stopwatch.Restart();
using var readerOrders = commandOrders.ExecuteReader();
stopwatch.Stop();
long ordersTime = stopwatch.ElapsedMilliseconds;
while (readerOrders.Read())
{
int id = readerOrders.GetInt32(0);
string description = readerOrders.GetString(1);
string adress = readerOrders.GetString(2);
double price = readerOrders.GetDouble(3);
string statusString = readerOrders.GetString(4);
OrderStatus status;
switch (statusString)
{
case "Принят":
status = OrderStatus.Принят;
break;
case "Выполняется":
status = OrderStatus.Выполняется;
break;
case "Завершён":
status = OrderStatus.Завершён;
break;
default:
status = OrderStatus.Неизвестен;
break;
}
string customerNumber = readerOrders.GetString(5);
DateTime dateBegin = readerOrders.GetDateTime(6);
Order? order;
if (status == OrderStatus.Завершён)
{
DateTime? dateEnd = readerOrders.GetDateTime(7);
order = Order.Create(new OrderBindingModel { Id = id, Description = description, Adress = adress, Price = price, Status = status, CustomerNumber = customerNumber, DateBegin = dateBegin, DateEnd = dateEnd });
}
else
{
order = Order.Create(new OrderBindingModel { Id = id, Description = description, Adress = adress, Price = price, Status = status, CustomerNumber = customerNumber, DateBegin = dateBegin});
}
if (order != null) _orders.Add(order);
}
readerOrders.Close();
using var commandEmployeeOrders = connection.CreateCommand();
commandEmployeeOrders.CommandText = "SELECT * FROM employee_order;";
stopwatch.Restart();
using var readerEmployeeOrders = commandEmployeeOrders.ExecuteReader();
stopwatch.Stop();
long employeeOrderTime = stopwatch.ElapsedMilliseconds;
while (readerEmployeeOrders.Read())
{
int employeeId = readerEmployeeOrders.GetInt32(0);
int orderId = readerEmployeeOrders.GetInt32(1);
EmployeeOrder? employeeOrder = EmployeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = employeeId, OrderId = orderId}, _employees, _orders);
if (employeeOrder != null) _employeeOrders.Add(employeeOrder);
}
readerEmployeeOrders.Close();
using var commandMaterialOrders = connection.CreateCommand();
commandMaterialOrders.CommandText = "SELECT * FROM material_order;";
stopwatch.Restart();
using var readerMaterialOrders = commandMaterialOrders.ExecuteReader();
stopwatch.Stop();
long materialOrderTime = stopwatch.ElapsedMilliseconds;
while (readerMaterialOrders.Read())
{
int materialId = readerMaterialOrders.GetInt32(0);
int orderId = readerMaterialOrders.GetInt32(1);
int quantity = readerMaterialOrders.GetInt32(2);
MaterialOrder? materialOrder = MaterialOrder.Create(new MaterialOrderBindingModel { MaterialId = materialId, OrderId = orderId, Quantity = quantity}, _materials, _orders);
if (materialOrder != null) _materialOrders.Add(materialOrder);
}
readerMaterialOrders.Close();
connection.Close();
}
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>9152d6ad-e687-4e3f-836c-fd7263918b1d</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="7.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="7.0.3" />
<PackageReference Include="Npgsql.NodaTime" Version="7.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,78 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class EmployeeOrderStorage : IEmployeeOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public EmployeeOrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<EmployeeOrderViewModel> GetFullList()
{
List<EmployeeOrderViewModel> result = new List<EmployeeOrderViewModel>();
foreach (var material in _source.EmployeeOrders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<EmployeeOrderViewModel> GetFilteredList(EmployeeOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue)
{
return new();
}
List<EmployeeOrderViewModel> result = new List<EmployeeOrderViewModel>();
foreach (var material in _source.EmployeeOrders)
{
if (material.EmployeeId == model.EmployeeId && material.OrderId == model.OrderId) result.Add(material.GetViewModel);
}
return result;
}
public EmployeeOrderViewModel? GetElement(EmployeeOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue)
{
return new();
}
return _source.EmployeeOrders.FirstOrDefault(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId)?.GetViewModel;
}
public EmployeeOrderViewModel? Insert(EmployeeOrderBindingModel model)
{
var command = EmployeeOrder.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newEmployeeOrder = _source.EmployeeOrders[_source.EmployeeOrders.Count - 1];
return newEmployeeOrder.GetViewModel;
}
public EmployeeOrderViewModel? Delete(EmployeeOrderBindingModel model)
{
var command = EmployeeOrder.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedEmployeeOrder = _source.EmployeeOrders.First(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId).GetViewModel;
_source.ExecuteSql(command);
return deletedEmployeeOrder;
}
}
}

View File

@ -0,0 +1,101 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class EmployeeStorage : IEmployeeStorage
{
private readonly ConstructionCompanyDatabase _source;
public EmployeeStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<EmployeeViewModel> GetFullList()
{
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
foreach (var material in _source.Employees)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.EmployeeName))
{
return new();
}
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
if (!string.IsNullOrEmpty(model.EmployeeName))
{
foreach (var material in _source.Employees)
{
if (material.EmployeeName.Equals(model.EmployeeName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Employees)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Employees.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public EmployeeViewModel? Insert(EmployeeBindingModel model)
{
var command = Employee.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newEmployee = _source.Employees[_source.Employees.Count - 1];
return newEmployee.GetViewModel;
}
public EmployeeViewModel? Update(EmployeeBindingModel model)
{
var command = Employee.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedEmployee = _source.Employees.First(x => x.Id == model.Id);
return updatedEmployee.GetViewModel;
}
public EmployeeViewModel? Delete(EmployeeBindingModel model)
{
var command = Employee.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedEmployee = _source.Employees.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedEmployee;
}
}
}

View File

@ -0,0 +1,79 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class MaterialOrderStorage : IMaterialOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public MaterialOrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<MaterialOrderViewModel> GetFullList()
{
List<MaterialOrderViewModel> result = new List<MaterialOrderViewModel>();
foreach (var material in _source.MaterialOrders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialOrderViewModel> GetFilteredList(MaterialOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue)
{
return new();
}
List<MaterialOrderViewModel> result = new List<MaterialOrderViewModel>();
foreach (var material in _source.MaterialOrders)
{
if (material.MaterialId == model.MaterialId && material.OrderId == model.OrderId) result.Add(material.GetViewModel);
}
return result;
}
public MaterialOrderViewModel? GetElement(MaterialOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue)
{
return new();
}
return _source.MaterialOrders.FirstOrDefault(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId)?.GetViewModel;
}
public MaterialOrderViewModel? Insert(MaterialOrderBindingModel model)
{
var command = MaterialOrder.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newMaterialOrder = _source.MaterialOrders[_source.MaterialOrders.Count - 1];
return newMaterialOrder.GetViewModel;
}
public MaterialOrderViewModel? Delete(MaterialOrderBindingModel model)
{
var command = MaterialOrder.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedMaterialOrder = _source.MaterialOrders.First(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId).GetViewModel;
_source.ExecuteSql(command);
return deletedMaterialOrder;
}
}
}

View File

@ -0,0 +1,116 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class MaterialStorage : IMaterialStorage
{
private readonly ConstructionCompanyDatabase _source;
public MaterialStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<MaterialViewModel> GetFullList()
{
List<MaterialViewModel> result = new List<MaterialViewModel>();
foreach (var material in _source.Materials)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
{
if (model == null || !model.Id.HasValue || string.IsNullOrEmpty(model.MaterialName))
{
return new();
}
List<MaterialViewModel> result = new List<MaterialViewModel>();
if (!string.IsNullOrEmpty(model.MaterialName))
{
foreach (var material in _source.Materials)
{
if (material.MaterialName.Equals(model.MaterialName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Materials)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public MaterialViewModel? GetElement(MaterialSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Materials.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public MaterialViewModel? Insert(MaterialBindingModel model)
{
var command = Material.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newMaterial = _source.Materials[_source.Materials.Count - 1];
return newMaterial.GetViewModel;
}
public MaterialViewModel? Update(MaterialBindingModel model)
{
var command = Material.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedMaterial = _source.Materials.First(x => x.Id == model.Id);
return updatedMaterial.GetViewModel;
}
public MaterialViewModel? Delete(MaterialBindingModel model)
{
var command = Material.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedMaterial = _source.Materials.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedMaterial;
}
public List<EmployeeViewModel>? GetEmployeesUsingMaterial(MaterialBindingModel model)
{
var command = Material.GetEmployeeCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var employeesId = _source.ExecuteReader(command, 1);
List<EmployeeViewModel> employees = new List<EmployeeViewModel>();
foreach (var id in employeesId)
{
employees.Add(_source.Employees.First(x => x.Id == Convert.ToInt32(id[0])).GetViewModel);
}
return employees;
}
}
}

View File

@ -0,0 +1,90 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public OrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
List<OrderViewModel> result = new List<OrderViewModel>();
foreach (var material in _source.Orders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
List<OrderViewModel> result = new List<OrderViewModel>();
foreach (var material in _source.Orders)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
var command = Order.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newOrder = _source.Orders[_source.Orders.Count - 1];
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var command = Order.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedOrder = _source.Orders.First(x => x.Id == model.Id);
return updatedOrder.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var command = Order.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedOrder = _source.Orders.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedOrder;
}
}
}

View File

@ -0,0 +1,114 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class PositionStorage : IPositionStorage
{
private readonly ConstructionCompanyDatabase _source;
public PositionStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<PositionViewModel> GetFullList()
{
List<PositionViewModel> result = new List<PositionViewModel>();
foreach (var material in _source.Positions)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<PositionViewModel> GetFilteredList(PositionSearchModel model)
{
if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.PositionName))
{
return new();
}
List<PositionViewModel> result = new List<PositionViewModel>();
if (!string.IsNullOrEmpty(model.PositionName))
{
foreach (var material in _source.Positions)
{
if (material.PositionName.Equals(model.PositionName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Positions)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public PositionViewModel? GetElement(PositionSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Positions.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public PositionViewModel? Insert(PositionBindingModel model)
{
var command = Position.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newPosition = _source.Positions[_source.Positions.Count - 1];
return newPosition.GetViewModel;
}
public PositionViewModel? Update(PositionBindingModel model)
{
var command = Position.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedPosition = _source.Positions.First(x => x.Id == model.Id);
return updatedPosition.GetViewModel;
}
public PositionViewModel? Delete(PositionBindingModel model)
{
var command = Position.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedPosition = _source.Positions.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedPosition;
}
public List<BrigadeReportViewModel> GetPositionsAverage(DateTime dateFrom, DateTime dateTo)
{
var command = Position.PositionsAVGCommnad(dateFrom, dateTo);
var result = _source.ExecuteReader(command, 2);
List<BrigadeReportViewModel> positionsAverages = new List<BrigadeReportViewModel>();
foreach (var posAvgPair in result)
{
string positionName = _source.Positions.First(x => x.Id == Convert.ToInt32(posAvgPair[0])).PositionName;
positionsAverages.Add(new BrigadeReportViewModel { PositionId = Convert.ToInt32(posAvgPair[0]), PositionName = positionName, materialAvg = Convert.ToDouble(posAvgPair[1]) });
}
return positionsAverages;
}
}
}

View File

@ -0,0 +1,76 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Employee : IEmployeeModel
{
public string EmployeeName { get; private set; } = string.Empty;
public int Id { get; private set; }
public int PositionID { get; private set; }
public Position Position { get; set; } = new();
public static Employee? Create(EmployeeBindingModel? model, List<Position> positions)
{
if (model == null)
{
return null;
}
return new Employee()
{
Id = model.Id,
EmployeeName = model.EmployeeName,
PositionID = model.PositionID,
Position = positions.First(x => x.Id == model.PositionID)
};
}
public void Update(EmployeeBindingModel? model)
{
if (model == null)
{
return;
}
EmployeeName = model.EmployeeName;
PositionID = model.PositionID;
}
public static string CreateCommand(EmployeeBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO employee(name, position_id) VALUES(\'{model.EmployeeName}\', {model.PositionID});";
}
public static string UpdateCommand(EmployeeBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE employee SET \"name\" = \'{model.EmployeeName}\', position_id = {model.PositionID} WHERE id = {model.Id}";
}
public static string DeleteCommand(EmployeeBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM employee WHERE id = {model.Id}";
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
EmployeeName = EmployeeName,
PositionID = PositionID,
PositionName = Position.PositionName
};
}
}

View File

@ -0,0 +1,56 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class EmployeeOrder : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
public int OrderId { get; set; }
public Employee Employee { get; set; } = new();
public Order Order { get; set; } = new();
public static EmployeeOrder? Create(EmployeeOrderBindingModel? model, List<Employee> employees, List<Order> orders)
{
if (model == null)
{
return null;
}
return new EmployeeOrder()
{
EmployeeId = model.EmployeeId,
OrderId = model.OrderId,
Employee = employees.First(x => x.Id == model.EmployeeId),
Order = orders.First(x => x.Id == model.OrderId),
};
}
public static string CreateCommand(EmployeeOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO employee_order(employee_id, order_id) VALUES({model.EmployeeId}, {model.OrderId});";
}
public static string DeleteCommand(EmployeeOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM material WHERE employee_id = {model.EmployeeId} AND order_id = {model.OrderId}";
}
public EmployeeOrderViewModel GetViewModel => new()
{
OrderId = OrderId,
EmployeeId = EmployeeId,
OrderAdress = Order.Adress,
EmployeeName = Employee.EmployeeName
};
}
}

View File

@ -0,0 +1,82 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Material : IMaterialModel
{
public string MaterialName {get; private set;} = string.Empty;
public int Quantity { get; set; }
public int Id { get; private set; }
public static Material? Create(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new Material()
{
Id = model.Id,
MaterialName = model.MaterialName,
Quantity = model.Quantity
};
}
public static string CreateCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO material(name, quantity) VALUES(\'{model.MaterialName}\', {model.Quantity});";
}
public static string UpdateCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE material SET \"name\" = \'{model.MaterialName}\', quantity = {model.Quantity} WHERE id = {model.Id}";
}
public static string DeleteCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM material WHERE id = {model.Id}";
}
public static string GetEmployeeCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"SELECT e.id FROM employee e JOIN employee_order ON employee_order.employee_id = e.id JOIN \"order\" ON \"order\".id = employee_order.order_id JOIN material_order ON material_order.order_id = \"order\".id JOIN material mat ON mat.id = material_order.material_id WHERE mat.id = {model.Id};";
}
public void Update(MaterialBindingModel? model)
{
if (model == null)
{
return;
}
MaterialName = model.MaterialName;
Quantity = model.Quantity;
}
public MaterialViewModel GetViewModel => new()
{
Id = Id,
MaterialName = MaterialName,
Quantity = Quantity
};
}
}

View File

@ -0,0 +1,59 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class MaterialOrder : IMaterialOrderModel
{
public int MaterialId { get; set; }
public int OrderId { get; set; }
public int Quantity { get; set; }
public Material Material { get; set; } = new();
public Order Order { get; set; } = new();
public static MaterialOrder? Create(MaterialOrderBindingModel? model, List<Material> materials, List<Order> orders)
{
if (model == null)
{
return null;
}
return new MaterialOrder()
{
MaterialId = model.MaterialId,
OrderId = model.OrderId,
Quantity = model.Quantity,
Material = materials.First(x => x.Id == model.MaterialId),
Order = orders.First(x => x.Id == model.OrderId),
};
}
public static string CreateCommand(MaterialOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO material_order(material_id, order_id, quantiny) VALUES({model.MaterialId}, {model.OrderId}, {model.Quantity});";
}
public static string DeleteCommand(MaterialOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM material WHERE material_id = {model.MaterialId} AND order_id = {model.OrderId}";
}
public MaterialOrderViewModel GetViewModel => new()
{
OrderId = OrderId,
MaterialId = MaterialId,
Quantity = Quantity,
OrderAdress = Order.Adress,
MaterialName = Material.MaterialName
};
}
}

View File

@ -0,0 +1,98 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public string Description { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public string CustomerNumber { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, IOrderModel> OrderEmolyees { get; private set; } = new Dictionary<int, IOrderModel>();
public Dictionary<int, (IMaterialModel, int)> OrderMaterials { get; private set; } = new Dictionary<int, (IMaterialModel, int)>();
public OrderStatus Status { get; private set; }
public DateTime DateBegin { get; private set; }
public DateTime? DateEnd { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
Description = model.Description,
Adress = model.Adress,
CustomerNumber = model.CustomerNumber,
Price = model.Price,
Status = model.Status,
DateBegin = model.DateBegin,
DateEnd = model.DateEnd,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
if (model.DateEnd.HasValue) DateEnd = model.DateEnd;
}
public static string CreateCommand(OrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO \"order\"(description, adress, price, status, " +
$"customer_number, date_begin, date_end) VALUES(\'{model.Description}\', \'{model.Adress}\', {model.Price}, " +
$"\'{model.Status}\', \'{model.CustomerNumber}\', \'{model.DateBegin}\', " +
$"{(model.DateEnd.HasValue ? $"\'{model.DateEnd}\'" : "null")});";
}
public static string UpdateCommand(OrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE \"order\" SET status = \'{model.Status}\', date_end = {(model.DateEnd.HasValue ? $"\'{model.DateEnd}\'" : "null")} " +
$"WHERE id = {model.Id}";
}
public static string DeleteCommand(OrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM \"order\" WHERE id = {model.Id}";
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
Description = Description,
Adress = Adress,
CustomerNumber = CustomerNumber,
Price = Price,
Status = Status,
DateBegin = DateBegin,
DateEnd = DateEnd
};
}
}

View File

@ -0,0 +1,79 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Position : IPositionModel
{
public string PositionName { get; private set; } = string.Empty;
public double Salary { get; set; }
public int Id { get; private set; }
public static Position? Create(PositionBindingModel? model)
{
if (model == null)
{
return null;
}
return new Position()
{
Id = model.Id,
PositionName = model.PositionName,
Salary = model.Salary
};
}
public void Update(PositionBindingModel? model)
{
if (model == null)
{
return;
}
PositionName = model.PositionName;
Salary = model.Salary;
}
public static string CreateCommand(PositionBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO position(name, salary) VALUES(\'{model.PositionName}\', {model.Salary});";
}
public static string UpdateCommand(PositionBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE position SET \"name\" = \'{model.PositionName}\', salary = {model.Salary} WHERE id = {model.Id}";
}
public static string DeleteCommand(PositionBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM postition WHERE id = {model.Id}";
}
public static string PositionsAVGCommnad(DateTime dateFrom, DateTime dateTo)
{
return $"SELECT \"position\".id, AVG(material_order.quantiny) FROM \"position\"\r\nJOIN employee ON employee.position_id = \"position\".id\r\nJOIN employee_order ON employee_order.employee_id = employee.id\r\nJOIN \"order\" ON \"order\".id = employee_order.order_id\r\nJOIN material_order ON material_order.order_id = \"order\".id\r\nJOIN material ON material.id = material_order.material_id\r\nWHERE \"order\".date_begin >= '{dateFrom}' AND \"order\".date_begin <= '{dateTo}'\r\nGROUP BY \"position\".id";
}
public PositionViewModel GetViewModel => new()
{
Id = Id,
PositionName = PositionName,
Salary = Salary
};
}
}

View File

@ -8,4 +8,51 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="Logos\warehouseLogo.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog" Version="5.1.3" />
<PackageReference Include="NLog.Config" Version="4.7.15" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
<PackageReference Include="NLog.Schema" Version="5.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyBusiness\ConstructionCompanyBusinessLogic.csproj" />
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
<ProjectReference Include="..\ConstructionCompanyPsqlImplement\ConstructionCompanyPsqlImplement.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Logos\warehouseLogo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="nlogConstruction.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -1,39 +0,0 @@
namespace ConstructionCompanyView
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace ConstructionCompanyView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,108 @@
namespace ConstructionCompanyView
{
partial class FormBrigadeMenu
{
/// <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.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.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
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.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(645, 28);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// сотрудникиToolStripMenuItem
//
this.сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem";
this.сотрудникиToolStripMenuItem.Size = new System.Drawing.Size(105, 24);
this.сотрудникиToolStripMenuItem.Text = "Сотрудники";
this.сотрудникиToolStripMenuItem.Click += new System.EventHandler(this.сотрудникиToolStripMenuItem_Click);
//
// должностиToolStripMenuItem
//
this.должностиToolStripMenuItem.Name = олжностиToolStripMenuItem";
this.должностиToolStripMenuItem.Size = new System.Drawing.Size(101, 24);
this.должностиToolStripMenuItem.Text = "Должности";
this.должностиToolStripMenuItem.Click += new System.EventHandler(this.должностиToolStripMenuItem_Click);
//
// назначитьНаЗаказToolStripMenuItem
//
this.назначитьНаЗаказToolStripMenuItem.Name = азначитьНаЗаказToolStripMenuItem";
this.назначитьНаЗаказToolStripMenuItem.Size = new System.Drawing.Size(159, 24);
this.назначитьНаЗаказToolStripMenuItem.Text = "Назначить на заказ";
this.назначитьНаЗаказToolStripMenuItem.Click += new System.EventHandler(this.назначитьНаЗаказToolStripMenuItem_Click);
//
// отчётПоДолжностямToolStripMenuItem
//
this.отчётПоДолжностямToolStripMenuItem.Name = "отчётПоДолжностямToolStripMenuItem";
this.отчётПоДолжностямToolStripMenuItem.Size = new System.Drawing.Size(174, 24);
this.отчётПоДолжностямToolStripMenuItem.Text = "Отчёт по должностям";
this.отчётПоДолжностямToolStripMenuItem.Click += new System.EventHandler(this.отчётПоДолжностямToolStripMenuItem_Click);
//
// FormBrigadeMenu
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::ConstructionCompanyView.Properties.Resources.users_viewfinder_solid;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(645, 352);
this.Controls.Add(this.menuStrip1);
this.DoubleBuffered = true;
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormBrigadeMenu";
this.Text = "Бригадир";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem сотрудникиToolStripMenuItem;
private ToolStripMenuItem должностиToolStripMenuItem;
private ToolStripMenuItem назначитьНаЗаказToolStripMenuItem;
private ToolStripMenuItem отчётПоДолжностямToolStripMenuItem;
}
}

View File

@ -0,0 +1,56 @@
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 ConstructionCompanyView
{
public partial class FormBrigadeMenu : Form
{
public FormBrigadeMenu()
{
InitializeComponent();
}
private void сотрудникиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployees));
if (service is FormEmployees form)
{
form.ShowDialog();
}
}
private void назначитьНаЗаказToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployeeOrders));
if (service is FormEmployeeOrders form)
{
form.ShowDialog();
}
}
private void должностиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPositions));
if (service is FormPositions form)
{
form.ShowDialog();
}
}
private void отчётПоДолжностямToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBrigadeReport));
if (service is FormBrigadeReport form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,63 @@
<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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,134 @@
namespace ConstructionCompanyView
{
partial class FormBrigadeReport
{
/// <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.label1 = new System.Windows.Forms.Label();
this.buttonShow = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker();
this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 20);
this.label1.TabIndex = 19;
//
// buttonShow
//
this.buttonShow.Location = new System.Drawing.Point(12, 72);
this.buttonShow.Name = "buttonShow";
this.buttonShow.Size = new System.Drawing.Size(134, 29);
this.buttonShow.TabIndex = 18;
this.buttonShow.Text = "Посчитать";
this.buttonShow.UseVisualStyleBackColor = true;
this.buttonShow.Click += new System.EventHandler(this.buttonShow_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 107);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(680, 366);
this.dataGridView.TabIndex = 20;
//
// dateTimePickerFrom
//
this.dateTimePickerFrom.Location = new System.Drawing.Point(12, 39);
this.dateTimePickerFrom.Name = "dateTimePickerFrom";
this.dateTimePickerFrom.Size = new System.Drawing.Size(218, 27);
this.dateTimePickerFrom.TabIndex = 21;
//
// dateTimePickerTo
//
this.dateTimePickerTo.Location = new System.Drawing.Point(263, 39);
this.dateTimePickerTo.Name = "dateTimePickerTo";
this.dateTimePickerTo.Size = new System.Drawing.Size(222, 27);
this.dateTimePickerTo.TabIndex = 22;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(18, 20);
this.label2.TabIndex = 23;
this.label2.Text = "C";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(263, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 20);
this.label3.TabIndex = 24;
this.label3.Text = "По";
//
// FormBrigadeReport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 485);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.dateTimePickerTo);
this.Controls.Add(this.dateTimePickerFrom);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonShow);
this.Name = "FormBrigadeReport";
this.Text = "Отчёт по использованию материалов должностями с датой";
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private Button buttonShow;
private DataGridView dataGridView;
private DateTimePicker dateTimePickerFrom;
private DateTimePicker dateTimePickerTo;
private Label label2;
private Label label3;
}
}

View File

@ -0,0 +1,51 @@
using ConstructionCompanyContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormBrigadeReport : Form
{
public IPositionLogic _logic;
public FormBrigadeReport(IPositionLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void buttonShow_Click(object sender, EventArgs e)
{
if (dateTimePickerFrom.Value > dateTimePickerTo.Value)
{
MessageBox.Show("Неверно выбраны даты!");
return;
}
try
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var list = _logic.ReadPositionsAverage(dateTimePickerFrom.Value.Date, dateTimePickerTo.Value.Date).OrderBy(x => x.PositionId).ToList();
stopwatch.Stop();
MessageBox.Show(stopwatch.ElapsedMilliseconds.ToString(), "Результат среднего по должностям. Время:");
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["PositionId"].Visible = false;
dataGridView.Columns["PositionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

@ -0,0 +1,120 @@
namespace ConstructionCompanyView
{
partial class FormEmployee
{
/// <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.buttonCancel = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxPosition = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(307, 117);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 9;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(202, 117);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 8;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(135, 6);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(276, 27);
this.textBoxName.TabIndex = 7;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 20);
this.label1.TabIndex = 6;
this.label1.Text = "ФИО";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(86, 20);
this.label2.TabIndex = 10;
this.label2.Text = "Должность";
//
// comboBoxPosition
//
this.comboBoxPosition.FormattingEnabled = true;
this.comboBoxPosition.Location = new System.Drawing.Point(135, 40);
this.comboBoxPosition.Name = "comboBoxPosition";
this.comboBoxPosition.Size = new System.Drawing.Size(276, 28);
this.comboBoxPosition.TabIndex = 11;
//
// FormEmployee
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(423, 165);
this.Controls.Add(this.comboBoxPosition);
this.Controls.Add(this.label2);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.label1);
this.Name = "FormEmployee";
this.Text = "Сотрудник";
this.Load += new System.EventHandler(this.FormEmployee_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonCreate;
private TextBox textBoxName;
private Label label1;
private Label label2;
private ComboBox comboBoxPosition;
}
}

View File

@ -0,0 +1,110 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
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 ConstructionCompanyView
{
public partial class FormEmployee : Form
{
private readonly ILogger _logger;
private readonly IPositionLogic _position;
private readonly IEmployeeLogic _employee;
private List<PositionViewModel>? _list;
private int? _id;
public int Id { set { _id = value; } }
public FormEmployee(ILogger<FormEmployee> logger, IPositionLogic position, IEmployeeLogic employee)
{
InitializeComponent();
_logger = logger;
_position = position;
_employee = employee;
}
private void FormEmployee_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка материалов для заказа");
_list = _position.ReadList(null);
if (_list != null)
{
comboBoxPosition.DisplayMember = "PositionName";
comboBoxPosition.ValueMember = "Id";
comboBoxPosition.DataSource = _list;
comboBoxPosition.SelectedItem = null;
}
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение материала");
var view = _employee.ReadElement(new EmployeeSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.EmployeeName;
comboBoxPosition.SelectedValue = view.PositionID;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения материала");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxPosition.SelectedValue == null)
{
MessageBox.Show("Выбирете должность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение материала");
try
{
var model = new EmployeeBindingModel
{
Id = _id ?? 0,
EmployeeName = textBoxName.Text,
PositionID = Convert.ToInt32(comboBoxPosition.SelectedValue)
};
var operationResult = _id.HasValue ? _employee.Update(model) : _employee.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

@ -0,0 +1,121 @@
namespace ConstructionCompanyView
{
partial class FormEmployeeOrder
{
/// <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.buttonCancel = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.comboBoxOrder = new System.Windows.Forms.ComboBox();
this.comboBoxEmployee = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(296, 115);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 13;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(142, 115);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 12;
this.buttonCreate.Text = "Отправить";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// comboBoxOrder
//
this.comboBoxOrder.FormattingEnabled = true;
this.comboBoxOrder.Location = new System.Drawing.Point(142, 9);
this.comboBoxOrder.Name = "comboBoxOrder";
this.comboBoxOrder.Size = new System.Drawing.Size(248, 28);
this.comboBoxOrder.TabIndex = 11;
//
// comboBoxEmployee
//
this.comboBoxEmployee.FormattingEnabled = true;
this.comboBoxEmployee.Location = new System.Drawing.Point(142, 55);
this.comboBoxEmployee.Name = "comboBoxEmployee";
this.comboBoxEmployee.Size = new System.Drawing.Size(248, 28);
this.comboBoxEmployee.TabIndex = 10;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 55);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 20);
this.label2.TabIndex = 9;
this.label2.Text = "Сотрудник:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(50, 20);
this.label1.TabIndex = 8;
this.label1.Text = "Заказ:";
//
// FormEmployeeOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(436, 159);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.comboBoxOrder);
this.Controls.Add(this.comboBoxEmployee);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FormEmployeeOrder";
this.Text = "Отправка на заказ";
this.Load += new System.EventHandler(this.FormEmployeeOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonCreate;
private ComboBox comboBoxOrder;
private ComboBox comboBoxEmployee;
private Label label2;
private Label label1;
}
}

View File

@ -0,0 +1,99 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
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 ConstructionCompanyView
{
public partial class FormEmployeeOrder : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IEmployeeLogic _employee;
private readonly IEmployeeOrderLogic _employeeOrder;
private List<EmployeeViewModel>? _listE;
private List<OrderViewModel>? _listO;
public FormEmployeeOrder(ILogger<FormEmployeeOrder> logger, IOrderLogic order, IEmployeeLogic employee, IEmployeeOrderLogic employeeOrder)
{
InitializeComponent();
_logger = logger;
_order = order;
_employee = employee;
_employeeOrder = employeeOrder;
}
private void FormEmployeeOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка материалов для заказа");
_listE = _employee.ReadList(null);
if (_listE != null)
{
comboBoxEmployee.DisplayMember = "EmployeeName";
comboBoxEmployee.ValueMember = "Id";
comboBoxEmployee.DataSource = _listE;
comboBoxEmployee.SelectedItem = null;
}
_listO = _order.ReadList(null);
if (_listO != null)
{
comboBoxOrder.DisplayMember = "Adress";
comboBoxOrder.ValueMember = "Id";
comboBoxOrder.DataSource = _listO;
comboBoxOrder.SelectedItem = null;
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
if (comboBoxOrder.SelectedValue == null)
{
MessageBox.Show("Выберите заказ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxEmployee.SelectedValue == null)
{
MessageBox.Show("Выберите материал", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new EmployeeOrderBindingModel
{
EmployeeId = Convert.ToInt32(comboBoxEmployee.SelectedValue),
OrderId = Convert.ToInt32(comboBoxOrder.SelectedValue),
};
var operationResult = _employeeOrder.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);
}
}
}
}

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

@ -0,0 +1,81 @@
namespace ConstructionCompanyView
{
partial class FormEmployeeOrders
{
/// <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.buttonCreate = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(604, 12);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(141, 75);
this.buttonCreate.TabIndex = 14;
this.buttonCreate.Text = "Отправить сотрудника на заказ";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(543, 450);
this.dataGridView.TabIndex = 13;
//
// FormEmployeeOrders
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(768, 450);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.dataGridView);
this.Name = "FormEmployeeOrders";
this.Text = "Назначение сотрудников";
this.Load += new System.EventHandler(this.FormEmployeeOrders_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonCreate;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,65 @@
using ConstructionCompanyContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormEmployeeOrders : Form
{
private readonly ILogger _logger;
private readonly IEmployeeOrderLogic _logic;
public FormEmployeeOrders(ILogger<FormEmployeeOrders> logger, IEmployeeOrderLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormEmployeeOrders_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["EmployeeId"].Visible = false;
dataGridView.Columns["OrderId"].Visible = false;
dataGridView.Columns["EmployeeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка поставок");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки поставок");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployeeOrder));
if (service is FormEmployeeOrder form)
{
if (form.ShowDialog() == DialogResult.OK)
{
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

@ -0,0 +1,120 @@
namespace ConstructionCompanyView
{
partial class FormEmployees
{
/// <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.Location = new System.Drawing.Point(574, 186);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(134, 29);
this.buttonRef.TabIndex = 14;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(574, 128);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(134, 29);
this.buttonDel.TabIndex = 13;
this.buttonDel.Text = "Уволить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(574, 71);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(134, 29);
this.buttonUpd.TabIndex = 12;
this.buttonUpd.Text = "Правка";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(574, 14);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(134, 29);
this.buttonAdd.TabIndex = 11;
this.buttonAdd.Text = "Нанять";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(489, 450);
this.dataGridView.TabIndex = 10;
//
// FormEmployees
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(723, 450);
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 = "FormEmployees";
this.Text = "Сотрудники";
this.Load += new System.EventHandler(this.FormEmployees_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,112 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormEmployees : Form
{
private readonly ILogger _logger;
private readonly IEmployeeLogic _logic;
public FormEmployees(ILogger<FormEmployees> logger, IEmployeeLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormEmployees_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployee));
if (service is FormEmployee 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(FormEmployee));
if (service is FormEmployee 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 EmployeeBindingModel { 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();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["PositionId"].Visible = false;
dataGridView.Columns["EmployeeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка материалов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки материалов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

@ -0,0 +1,114 @@
namespace ConstructionCompanyView
{
partial class FormLogin
{
/// <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.label1 = new System.Windows.Forms.Label();
this.buttonWarehouse = new System.Windows.Forms.Button();
this.buttonManager = new System.Windows.Forms.Button();
this.buttonHR = new System.Windows.Forms.Button();
this.buttonGenerate = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Segoe UI", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.label1.Location = new System.Drawing.Point(318, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 32);
this.label1.TabIndex = 0;
this.label1.Text = "Войти как:";
//
// buttonWarehouse
//
this.buttonWarehouse.Location = new System.Drawing.Point(33, 130);
this.buttonWarehouse.Name = "buttonWarehouse";
this.buttonWarehouse.Size = new System.Drawing.Size(174, 61);
this.buttonWarehouse.TabIndex = 1;
this.buttonWarehouse.Text = "Кладовщик";
this.buttonWarehouse.UseVisualStyleBackColor = true;
this.buttonWarehouse.Click += new System.EventHandler(this.buttonWarehouse_Click);
//
// buttonManager
//
this.buttonManager.Location = new System.Drawing.Point(299, 130);
this.buttonManager.Name = "buttonManager";
this.buttonManager.Size = new System.Drawing.Size(174, 61);
this.buttonManager.TabIndex = 2;
this.buttonManager.Text = "Менеджер";
this.buttonManager.UseVisualStyleBackColor = true;
this.buttonManager.Click += new System.EventHandler(this.buttonManager_Click);
//
// buttonHR
//
this.buttonHR.Location = new System.Drawing.Point(579, 130);
this.buttonHR.Name = "buttonHR";
this.buttonHR.Size = new System.Drawing.Size(174, 61);
this.buttonHR.TabIndex = 3;
this.buttonHR.Text = "Бригадир";
this.buttonHR.UseVisualStyleBackColor = true;
this.buttonHR.Click += new System.EventHandler(this.buttonHR_Click);
//
// buttonGenerate
//
this.buttonGenerate.Location = new System.Drawing.Point(12, 309);
this.buttonGenerate.Name = "buttonGenerate";
this.buttonGenerate.Size = new System.Drawing.Size(154, 29);
this.buttonGenerate.TabIndex = 4;
this.buttonGenerate.Text = "Создать компанию";
this.buttonGenerate.UseVisualStyleBackColor = true;
this.buttonGenerate.Click += new System.EventHandler(this.buttonGenerate_Click);
//
// FormLogin
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.ClientSize = new System.Drawing.Size(784, 350);
this.Controls.Add(this.buttonGenerate);
this.Controls.Add(this.buttonHR);
this.Controls.Add(this.buttonManager);
this.Controls.Add(this.buttonWarehouse);
this.Controls.Add(this.label1);
this.Name = "FormLogin";
this.Text = "Вход";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private Button buttonWarehouse;
private Button buttonManager;
private Button buttonHR;
private Button buttonGenerate;
}
}

View File

@ -0,0 +1,89 @@
using ConstructionCompanyContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormLogin : Form
{
private readonly IRandomGeneratorLogic _random;
public FormLogin(IRandomGeneratorLogic random)
{
InitializeComponent();
_random = random;
}
private void buttonWarehouse_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWarehouseMenu));
if (service is FormWarehouseMenu form)
{
this.Hide();
form.ShowDialog();
this.Show();
}
}
private void buttonManager_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManagerMenu));
if (service is FormManagerMenu form)
{
this.Hide();
form.ShowDialog();
this.Show();
}
}
private void buttonHR_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBrigadeMenu));
if (service is FormBrigadeMenu form)
{
this.Hide();
form.ShowDialog();
this.Show();
}
}
private void buttonGenerate_Click(object sender, EventArgs e)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
_random.GenerateMaterials();
stopwatch.Stop();
long materials = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();
_random.GeneratePositions();
stopwatch.Stop();
long positions = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();
_random.GenerateEmployees();
stopwatch.Stop();
long employees = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();
_random.GenerateOrders();
stopwatch.Stop();
long orders = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();
_random.GenerateEmployeesOrders();
long employeesOrders = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();
_random.GenerateMaterialOrders();
stopwatch.Stop();
long materialOrders = stopwatch.ElapsedMilliseconds;
_random.GenerateAdditionalMaterialOrders();
MessageBox.Show($"materials={materials}, positions={positions}, employees={employees}, orders={orders}, materialOrders={materialOrders}, employeeOrders={employeesOrders}", "Результаты");
MessageBox.Show("Готово!");
}
}
}

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

@ -0,0 +1,78 @@
namespace ConstructionCompanyView
{
partial class FormManagerMenu
{
/// <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.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.заказыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.заказыToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(626, 28);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// заказыToolStripMenuItem
//
this.заказыToolStripMenuItem.Name = аказыToolStripMenuItem";
this.заказыToolStripMenuItem.Size = new System.Drawing.Size(72, 24);
this.заказыToolStripMenuItem.Text = "Заказы";
this.заказыToolStripMenuItem.Click += new System.EventHandler(this.заказыToolStripMenuItem_Click);
//
// FormManagerMenu
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::ConstructionCompanyView.Properties.Resources.cash_register_solid;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(626, 328);
this.Controls.Add(this.menuStrip1);
this.DoubleBuffered = true;
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormManagerMenu";
this.Text = "Менеджмент";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem заказыToolStripMenuItem;
}
}

View File

@ -0,0 +1,29 @@
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 ConstructionCompanyView
{
public partial class FormManagerMenu : Form
{
public FormManagerMenu()
{
InitializeComponent();
}
private void заказыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrders));
if (service is FormOrders form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,66 @@
<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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>82</value>
</metadata>
</root>

View File

@ -0,0 +1,119 @@
namespace ConstructionCompanyView
{
partial class FormMaterial
{
/// <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.label1 = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxQuantity = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(77, 20);
this.label1.TabIndex = 0;
this.label1.Text = "Название";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(108, 6);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(276, 27);
this.textBoxName.TabIndex = 1;
//
// textBoxQuantity
//
this.textBoxQuantity.Location = new System.Drawing.Point(108, 56);
this.textBoxQuantity.Name = "textBoxQuantity";
this.textBoxQuantity.Size = new System.Drawing.Size(113, 27);
this.textBoxQuantity.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 59);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(90, 20);
this.label2.TabIndex = 2;
this.label2.Text = "Количество";
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(202, 117);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 4;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(307, 117);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormMaterial
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(413, 158);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.textBoxQuantity);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.label1);
this.Name = "FormMaterial";
this.Text = "Материал";
this.Load += new System.EventHandler(this.FormMaterial_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private TextBox textBoxName;
private TextBox textBoxQuantity;
private Label label2;
private Button buttonCreate;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,97 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
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 ConstructionCompanyView
{
public partial class FormMaterial : Form
{
private readonly ILogger _logger;
private readonly IMaterialLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormMaterial(ILogger<FormMaterial> logger, IMaterialLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxQuantity.Text))
{
MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение материала");
try
{
var model = new MaterialBindingModel
{
Id = _id ?? 0,
MaterialName = textBoxName.Text,
Quantity = Convert.ToInt32(textBoxQuantity.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormMaterial_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение материала");
var view = _logic.ReadElement(new MaterialSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.MaterialName;
textBoxQuantity.Text = view.Quantity.ToString();
textBoxQuantity.Enabled = false;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения материала");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More