diff --git a/ClientDataBase.sln b/ClientDataBase.sln new file mode 100644 index 0000000..f5e6109 --- /dev/null +++ b/ClientDataBase.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33110.190 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDView", "SYBDView\SYBDView.csproj", "{9B281F88-62FF-4293-B076-B05C297E0C0E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDDataModels", "SYBDDataModels\SYBDDataModels.csproj", "{32D4AD2F-8068-4F3D-B1F3-A2AEA3777D95}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDContracts", "SYBDContracts\SYBDContracts.csproj", "{EA21505A-306B-426C-8A08-30EA1101757C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDBusinessLogic", "SYBDBusinessLogic\SYBDBusinessLogic.csproj", "{F653B97F-956A-4533-A54D-6EB96AEAD388}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SYBDDatabaseImplement", "SYBDDatabaseImplement\SYBDDatabaseImplement.csproj", "{9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B281F88-62FF-4293-B076-B05C297E0C0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B281F88-62FF-4293-B076-B05C297E0C0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B281F88-62FF-4293-B076-B05C297E0C0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B281F88-62FF-4293-B076-B05C297E0C0E}.Release|Any CPU.Build.0 = Release|Any CPU + {32D4AD2F-8068-4F3D-B1F3-A2AEA3777D95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32D4AD2F-8068-4F3D-B1F3-A2AEA3777D95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32D4AD2F-8068-4F3D-B1F3-A2AEA3777D95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32D4AD2F-8068-4F3D-B1F3-A2AEA3777D95}.Release|Any CPU.Build.0 = Release|Any CPU + {EA21505A-306B-426C-8A08-30EA1101757C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA21505A-306B-426C-8A08-30EA1101757C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA21505A-306B-426C-8A08-30EA1101757C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA21505A-306B-426C-8A08-30EA1101757C}.Release|Any CPU.Build.0 = Release|Any CPU + {F653B97F-956A-4533-A54D-6EB96AEAD388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F653B97F-956A-4533-A54D-6EB96AEAD388}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F653B97F-956A-4533-A54D-6EB96AEAD388}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F653B97F-956A-4533-A54D-6EB96AEAD388}.Release|Any CPU.Build.0 = Release|Any CPU + {9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3F9D10B4-8F7E-4940-A162-1D71929F5E07} + EndGlobalSection +EndGlobal diff --git a/SYBDBusinessLogic/BusinessLogics/AutoLogic.cs b/SYBDBusinessLogic/BusinessLogics/AutoLogic.cs new file mode 100644 index 0000000..262f64b --- /dev/null +++ b/SYBDBusinessLogic/BusinessLogics/AutoLogic.cs @@ -0,0 +1,115 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SYBDBusinessLogic.BusinessLogics +{ + public class AutoLogic : IAutoLogic + { + private readonly ILogger _logger; + + private readonly IAutoStorage _autoStorage; + + public AutoLogic(ILogger logger, IAutoStorage autoStorage) + { + _logger = logger; + _autoStorage = autoStorage; + } + + public List? ReadList(AutoSearchModel? model) + { + _logger.LogInformation("ReadList. StateNumber:{StateNumber}. Id:{Id}", model?.StateNumber, model?.Id); + var list = model == null ? _autoStorage.GetFullList() : _autoStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public AutoViewModel? ReadElement(AutoSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. StateNumber:{StateNumber}. Id:{Id}", model.StateNumber, model.Id); + var element = _autoStorage.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(AutoBindingModel model) + { + CheckModel(model); + if (_autoStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(AutoBindingModel model) + { + CheckModel(model); + if (_autoStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(AutoBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_autoStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(AutoBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Model)) + { + throw new ArgumentNullException("Нет модели", nameof(model.Model)); + } + if (string.IsNullOrEmpty(model.StateNumber)) + { + throw new ArgumentNullException("Нет номеров", nameof(model.StateNumber)); + } + _logger.LogInformation("Auto. Model:{Model}. StateNumber:{StateNumber}. Id:{Id}", model.Model, model.StateNumber, model.Id); + var element = _autoStorage.GetElement(new AutoSearchModel + { + StateNumber = model.StateNumber + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Автомобиль с таким гос номером уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SYBDBusinessLogic/BusinessLogics/ClientLogic.cs b/SYBDBusinessLogic/BusinessLogics/ClientLogic.cs new file mode 100644 index 0000000..99da053 --- /dev/null +++ b/SYBDBusinessLogic/BusinessLogics/ClientLogic.cs @@ -0,0 +1,111 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SYBDBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + + private readonly IClientStorage _clientStorage; + + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } + + public List? ReadList(ClientSearchModel? model) + { + _logger.LogInformation("ReadList. Fullname:{Fullname}. Id:{Id}", model?.Fullname, model?.Id); + var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Fullname:{Fullname}. Id:{Id}", model.Fullname, model.Id); + var element = _clientStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_clientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ClientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Fullname)) + { + throw new ArgumentNullException("Нет ФИО клиента", nameof(model.Fullname)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Нет телефона клиента", nameof(model.Phone)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); + } + _logger.LogInformation("Client. Fullname:{Fullname}. Phone:{Phone}. Email: {Email} Id:{Id}", model.Fullname, model.Phone, model.Email, model.Id); + } + } +} \ No newline at end of file diff --git a/SYBDBusinessLogic/BusinessLogics/InsuranceLogic.cs b/SYBDBusinessLogic/BusinessLogics/InsuranceLogic.cs new file mode 100644 index 0000000..db51bb8 --- /dev/null +++ b/SYBDBusinessLogic/BusinessLogics/InsuranceLogic.cs @@ -0,0 +1,119 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SYBDBusinessLogic.BusinessLogics +{ + public class InsuranceLogic : IInsuranceLogic + { + private readonly ILogger _logger; + + private readonly IInsuranceStorage _insuranceStorage; + + public InsuranceLogic(ILogger logger, IInsuranceStorage insuranceStorage) + { + _logger = logger; + _insuranceStorage = insuranceStorage; + } + + public List? ReadList(InsuranceSearchModel? model) + { + _logger.LogInformation("ReadList. InsuranceName:{Name}. Id:{Id}", model?.Name, model?.Id); + var list = model == null ? _insuranceStorage.GetFullList() : _insuranceStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public InsuranceViewModel? ReadElement(InsuranceSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. InsuranceName:{Name}. Id:{Id}", model.Name, model.Id); + var element = _insuranceStorage.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(InsuranceBindingModel model) + { + CheckModel(model); + if (_insuranceStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(InsuranceBindingModel model) + { + CheckModel(model); + if (_insuranceStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(InsuranceBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_insuranceStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(InsuranceBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия страховой", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса страховой", nameof(model.Address)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Нет телефона страховой", nameof(model.Phone)); + } + _logger.LogInformation("Insurance. Name:{Name}. Address:{Address}.Phone:{Phone}. Id:{Id}", model.Name, model.Address, model.Phone, model.Id); + var element = _insuranceStorage.GetElement(new InsuranceSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Страховая с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SYBDBusinessLogic/BusinessLogics/OrderLogic.cs b/SYBDBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..7c11550 --- /dev/null +++ b/SYBDBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,148 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SYBDBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? 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 Create(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(OrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_orderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, "Выдан"); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, "Готов"); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, "Выполняется"); + } + public bool ChangeStatus(OrderBindingModel model, string newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!((viewModel.Status == "В обработке") && (newStatus == "Выполняется") || (viewModel.Status == "Выполняется") && (newStatus == "Готов") || ((viewModel.Status == "Готов") && (newStatus == "Выдан")))) + { + return false; + } + model.Status = newStatus; + model.WorkerId = viewModel.WorkerId; + model.AutoId = viewModel.AutoId; + model.ClientId = viewModel.ClientId; + model.InsuranceId = viewModel.InsuranceId; + model.Price = viewModel.Price; + model.Description = viewModel.Description; + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + + 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 (model.Price<=0) + { + throw new ArgumentNullException("Стоимость должна быть выше 0", nameof(model.Price)); + } + _logger.LogInformation("Order. Description:{Description}. Price:{Price}.Id:{Id}", model.Description, model.Price, model.Id); + } + } +} \ No newline at end of file diff --git a/SYBDBusinessLogic/BusinessLogics/WorkerLogic.cs b/SYBDBusinessLogic/BusinessLogics/WorkerLogic.cs new file mode 100644 index 0000000..3438eb2 --- /dev/null +++ b/SYBDBusinessLogic/BusinessLogics/WorkerLogic.cs @@ -0,0 +1,117 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SYBDBusinessLogic.BusinessLogics +{ + public class WorkerLogic : IWorkerLogic + { + private readonly ILogger _logger; + + private readonly IWorkerStorage _workerStorage; + public WorkerLogic(ILogger logger, IWorkerStorage workerStorage) + { + _logger = logger; + _workerStorage = workerStorage; + } + public bool Create(WorkerBindingModel model) + { + CheckModel(model); + CheckModel(model); + if (_workerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(WorkerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_workerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public WorkerViewModel? ReadElement(WorkerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Fullname:{Fullname}. Id:{Id}", model.Fullname, model.Id); + var element = _workerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(WorkerSearchModel? model) + { + _logger.LogInformation("ReadList. Fullname:{Fullname}. Id:{Id}", model?.Fullname, model?.Id); + var list = model == null ? _workerStorage.GetFullList() : _workerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(WorkerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Fullname)) + { + throw new ArgumentNullException("Нет ФИО работника", nameof(model.Fullname)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса работника", nameof(model.Address)); + } + if (model.Salary <= 0) + { + throw new ArgumentNullException("Зарплата работника должна быть больше 0", nameof(model.Salary)); + } + _logger.LogInformation("Component. Fullname:{Fullname}. Address:{Address}.Salary:{Salary}. Id:{Id}", model.Fullname, model.Address, model.Salary, model.Id); + var element = _workerStorage.GetElement(new WorkerSearchModel + { + Fullname = model.Fullname + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Работа с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SYBDBusinessLogic/SYBDBusinessLogic.csproj b/SYBDBusinessLogic/SYBDBusinessLogic.csproj new file mode 100644 index 0000000..ceddb1a --- /dev/null +++ b/SYBDBusinessLogic/SYBDBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/SYBDContracts/BindingModels/AutoBindingModel.cs b/SYBDContracts/BindingModels/AutoBindingModel.cs new file mode 100644 index 0000000..e737aa7 --- /dev/null +++ b/SYBDContracts/BindingModels/AutoBindingModel.cs @@ -0,0 +1,12 @@ +using SYBDDataModels.Models; + +namespace SYBDContracts.BindingModels +{ + public class AutoBindingModel : IAutoModel + { + public int Id { get; set; } + public string StateNumber { get; set; } = string.Empty; + public string Model { get; set; } = string.Empty; + + } +} \ No newline at end of file diff --git a/SYBDContracts/BindingModels/ClientBindingModel.cs b/SYBDContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..336f35a --- /dev/null +++ b/SYBDContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,13 @@ +using SYBDDataModels.Models; + +namespace SYBDContracts.BindingModels +{ + public class ClientBindingModel : IClientModel + { + public int Id { get; set; } + public string Fullname { get; set; } = string.Empty; + public string Phone { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + + } +} \ No newline at end of file diff --git a/SYBDContracts/BindingModels/InsuranceBindingModel.cs b/SYBDContracts/BindingModels/InsuranceBindingModel.cs new file mode 100644 index 0000000..e0d8c07 --- /dev/null +++ b/SYBDContracts/BindingModels/InsuranceBindingModel.cs @@ -0,0 +1,14 @@ +using SYBDDataModels.Models; + +namespace SYBDContracts.BindingModels +{ + public class InsuranceBindingModel : IInsuranceModel + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public string Phone { get; set; } = string.Empty; + + + } +} \ No newline at end of file diff --git a/SYBDContracts/BindingModels/OrderBindingModel.cs b/SYBDContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..cac1bd4 --- /dev/null +++ b/SYBDContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using SYBDDataModels.Models; + +namespace SYBDContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + + public int AutoId { get; set; } + public int ClientId { get; set; } + public int InsuranceId { get; set; } + public int WorkerId { get; set; } + public string Description { get; set; } = string.Empty; + public double Price { get; set; } + public string Status { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SYBDContracts/BindingModels/WorkerBindingModel.cs b/SYBDContracts/BindingModels/WorkerBindingModel.cs new file mode 100644 index 0000000..cea520e --- /dev/null +++ b/SYBDContracts/BindingModels/WorkerBindingModel.cs @@ -0,0 +1,13 @@ +using SYBDDataModels.Models; + +namespace SYBDContracts.BindingModels +{ + public class WorkerBindingModel : IWorkerModel + { + public int Id { get; set; } + + public string Fullname { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public int Salary { get; set; } + } +} \ No newline at end of file diff --git a/SYBDContracts/BusinessLogicsContracts/IAutoLogic.cs b/SYBDContracts/BusinessLogicsContracts/IAutoLogic.cs new file mode 100644 index 0000000..adf61a0 --- /dev/null +++ b/SYBDContracts/BusinessLogicsContracts/IAutoLogic.cs @@ -0,0 +1,19 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.BusinessLogicsContracts +{ + public interface IAutoLogic + { + List? ReadList(AutoSearchModel? model); + + AutoViewModel? ReadElement(AutoSearchModel model); + + bool Create(AutoBindingModel model); + + bool Update(AutoBindingModel model); + + bool Delete(AutoBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/BusinessLogicsContracts/IClientLogic.cs b/SYBDContracts/BusinessLogicsContracts/IClientLogic.cs new file mode 100644 index 0000000..c4746de --- /dev/null +++ b/SYBDContracts/BusinessLogicsContracts/IClientLogic.cs @@ -0,0 +1,19 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.BusinessLogicsContracts +{ + public interface IClientLogic + { + List? ReadList(ClientSearchModel? model); + + ClientViewModel? ReadElement(ClientSearchModel model); + + bool Create(ClientBindingModel model); + + bool Update(ClientBindingModel model); + + bool Delete(ClientBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/BusinessLogicsContracts/IInsuranceLogic.cs b/SYBDContracts/BusinessLogicsContracts/IInsuranceLogic.cs new file mode 100644 index 0000000..0261503 --- /dev/null +++ b/SYBDContracts/BusinessLogicsContracts/IInsuranceLogic.cs @@ -0,0 +1,19 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.BusinessLogicsContracts +{ + public interface IInsuranceLogic + { + List? ReadList(InsuranceSearchModel? model); + + InsuranceViewModel? ReadElement(InsuranceSearchModel model); + + bool Create(InsuranceBindingModel model); + + bool Update(InsuranceBindingModel model); + + bool Delete(InsuranceBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/BusinessLogicsContracts/IOrderLogic.cs b/SYBDContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..222c30e --- /dev/null +++ b/SYBDContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,25 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + + OrderViewModel? ReadElement(OrderSearchModel model); + + bool Create(OrderBindingModel model); + + bool Update(OrderBindingModel model); + + bool Delete(OrderBindingModel model); + + bool TakeOrderInWork(OrderBindingModel model); + + bool FinishOrder(OrderBindingModel model); + + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/BusinessLogicsContracts/IWorkerLogic.cs b/SYBDContracts/BusinessLogicsContracts/IWorkerLogic.cs new file mode 100644 index 0000000..7722273 --- /dev/null +++ b/SYBDContracts/BusinessLogicsContracts/IWorkerLogic.cs @@ -0,0 +1,19 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.BusinessLogicsContracts +{ + public interface IWorkerLogic + { + List? ReadList(WorkerSearchModel? model); + + WorkerViewModel? ReadElement(WorkerSearchModel model); + + bool Create(WorkerBindingModel model); + + bool Update(WorkerBindingModel model); + + bool Delete(WorkerBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/SYBDContracts.csproj b/SYBDContracts/SYBDContracts.csproj new file mode 100644 index 0000000..49ef3c4 --- /dev/null +++ b/SYBDContracts/SYBDContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/SYBDContracts/SearchModels/AutoSearchModel.cs b/SYBDContracts/SearchModels/AutoSearchModel.cs new file mode 100644 index 0000000..4b6da56 --- /dev/null +++ b/SYBDContracts/SearchModels/AutoSearchModel.cs @@ -0,0 +1,9 @@ +namespace SYBDContracts.SearchModels +{ + public class AutoSearchModel + { + public int? Id { get; set; } + + public string? StateNumber { get; set; } + } +} \ No newline at end of file diff --git a/SYBDContracts/SearchModels/ClientSearchModel.cs b/SYBDContracts/SearchModels/ClientSearchModel.cs new file mode 100644 index 0000000..7ad7ef5 --- /dev/null +++ b/SYBDContracts/SearchModels/ClientSearchModel.cs @@ -0,0 +1,9 @@ +namespace SYBDContracts.SearchModels +{ + public class ClientSearchModel + { + public int? Id { get; set; } + + public string? Fullname { get; set; } + } +} \ No newline at end of file diff --git a/SYBDContracts/SearchModels/InsuranceSearchModel.cs b/SYBDContracts/SearchModels/InsuranceSearchModel.cs new file mode 100644 index 0000000..a05ef78 --- /dev/null +++ b/SYBDContracts/SearchModels/InsuranceSearchModel.cs @@ -0,0 +1,9 @@ +namespace SYBDContracts.SearchModels +{ + public class InsuranceSearchModel + { + public int? Id { get; set; } + + public string? Name { get; set; } + } +} \ No newline at end of file diff --git a/SYBDContracts/SearchModels/OrderSearchModel.cs b/SYBDContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..0a5f796 --- /dev/null +++ b/SYBDContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace SYBDContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/SYBDContracts/SearchModels/WorkSearchModel.cs b/SYBDContracts/SearchModels/WorkSearchModel.cs new file mode 100644 index 0000000..de3e46b --- /dev/null +++ b/SYBDContracts/SearchModels/WorkSearchModel.cs @@ -0,0 +1,9 @@ +namespace SYBDContracts.SearchModels +{ + public class WorkerSearchModel + { + public int? Id { get; set; } + + public string? Fullname { get; set; } + } +} \ No newline at end of file diff --git a/SYBDContracts/StoragesContracts/IAutoStorage.cs b/SYBDContracts/StoragesContracts/IAutoStorage.cs new file mode 100644 index 0000000..f625c1b --- /dev/null +++ b/SYBDContracts/StoragesContracts/IAutoStorage.cs @@ -0,0 +1,21 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.StoragesContracts +{ + public interface IAutoStorage + { + List GetFullList(); + + List GetFilteredList(AutoSearchModel model); + + AutoViewModel? GetElement(AutoSearchModel model); + + AutoViewModel? Insert(AutoBindingModel model); + + AutoViewModel? Update(AutoBindingModel model); + + AutoViewModel? Delete(AutoBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/StoragesContracts/IClientStorage.cs b/SYBDContracts/StoragesContracts/IClientStorage.cs new file mode 100644 index 0000000..9674a9d --- /dev/null +++ b/SYBDContracts/StoragesContracts/IClientStorage.cs @@ -0,0 +1,21 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.StoragesContracts +{ + public interface IClientStorage + { + List GetFullList(); + + List GetFilteredList(ClientSearchModel model); + + ClientViewModel? GetElement(ClientSearchModel model); + + ClientViewModel? Insert(ClientBindingModel model); + + ClientViewModel? Update(ClientBindingModel model); + + ClientViewModel? Delete(ClientBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/StoragesContracts/IInsuranceStorage.cs b/SYBDContracts/StoragesContracts/IInsuranceStorage.cs new file mode 100644 index 0000000..658ed26 --- /dev/null +++ b/SYBDContracts/StoragesContracts/IInsuranceStorage.cs @@ -0,0 +1,21 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.StoragesContracts +{ + public interface IInsuranceStorage + { + List GetFullList(); + + List GetFilteredList(InsuranceSearchModel model); + + InsuranceViewModel? GetElement(InsuranceSearchModel model); + + InsuranceViewModel? Insert(InsuranceBindingModel model); + + InsuranceViewModel? Update(InsuranceBindingModel model); + + InsuranceViewModel? Delete(InsuranceBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/StoragesContracts/IOrderStorage.cs b/SYBDContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..23f928a --- /dev/null +++ b/SYBDContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + + List GetFilteredList(OrderSearchModel model); + + OrderViewModel? GetElement(OrderSearchModel model); + + OrderViewModel? Insert(OrderBindingModel model); + + OrderViewModel? Update(OrderBindingModel model); + + OrderViewModel? Delete(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/StoragesContracts/IWorkerStorage.cs b/SYBDContracts/StoragesContracts/IWorkerStorage.cs new file mode 100644 index 0000000..e2d4e5e --- /dev/null +++ b/SYBDContracts/StoragesContracts/IWorkerStorage.cs @@ -0,0 +1,21 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.ViewModels; + +namespace SYBDContracts.StoragesContracts +{ + public interface IWorkerStorage + { + List GetFullList(); + + List GetFilteredList(WorkerSearchModel model); + + WorkerViewModel? GetElement(WorkerSearchModel model); + + WorkerViewModel? Insert(WorkerBindingModel model); + + WorkerViewModel? Update(WorkerBindingModel model); + + WorkerViewModel? Delete(WorkerBindingModel model); + } +} \ No newline at end of file diff --git a/SYBDContracts/ViewModels/AutoViewModel.cs b/SYBDContracts/ViewModels/AutoViewModel.cs new file mode 100644 index 0000000..8bbef46 --- /dev/null +++ b/SYBDContracts/ViewModels/AutoViewModel.cs @@ -0,0 +1,16 @@ +using SYBDDataModels.Models; +using System.ComponentModel; + +namespace SYBDContracts.ViewModels +{ + public class AutoViewModel : IAutoModel + { + public int Id { get; set; } + + [DisplayName("Государственный номер")] + public string StateNumber { get; set; } = string.Empty; + + [DisplayName("Модель")] + public string Model { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SYBDContracts/ViewModels/ClientViewModel.cs b/SYBDContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..df4c310 --- /dev/null +++ b/SYBDContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,17 @@ +using SYBDDataModels.Models; +using System.ComponentModel; + +namespace SYBDContracts.ViewModels +{ + public class ClientViewModel : IClientModel + { + public int Id { get; set; } + + [DisplayName("ФИО клиента")] + public string Fullname { get; set; } = string.Empty; + [DisplayName("Телефонный номер")] + public string Phone { get; set; } = string.Empty; + [DisplayName("Почта")] + public string Email { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SYBDContracts/ViewModels/InsuranceViewModel.cs b/SYBDContracts/ViewModels/InsuranceViewModel.cs new file mode 100644 index 0000000..563b2b4 --- /dev/null +++ b/SYBDContracts/ViewModels/InsuranceViewModel.cs @@ -0,0 +1,17 @@ +using SYBDDataModels.Models; +using System.ComponentModel; + +namespace SYBDContracts.ViewModels +{ + public class InsuranceViewModel : IInsuranceModel + { + public int Id { get; set; } + + [DisplayName("Название страховой")] + public string Name { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + [DisplayName("Телефонный номер")] + public string Phone { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SYBDContracts/ViewModels/OrderViewModel.cs b/SYBDContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..6709bc9 --- /dev/null +++ b/SYBDContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,43 @@ +using SYBDDataModels.Models; +using System.ComponentModel; + +namespace SYBDContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + [DisplayName("Номер автомобиля")] + public int AutoId { get; set; } + + [DisplayName("Автомобиль")] + public string AutoModel { get; set; } = string.Empty; + [DisplayName("Номер клиента")] + public int ClientId { get; set; } + + [DisplayName("Клиент")] + public string ClientFullname { get; set; } = string.Empty; + [DisplayName("Номер cтраховой")] + public int InsuranceId { get; set; } + + [DisplayName("Страховая")] + public string InsuranceName { get; set; } = string.Empty; + [DisplayName("Номер работника")] + public int WorkerId { get; set; } + + [DisplayName("Работник")] + public string WorkerFullname { get; set; } = string.Empty; + + [DisplayName("Описание")] + public string Description { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + [DisplayName("Статус")] + public string Status { get; set; } = string.Empty; + + + + } +} \ No newline at end of file diff --git a/SYBDContracts/ViewModels/WorkerViewModel.cs b/SYBDContracts/ViewModels/WorkerViewModel.cs new file mode 100644 index 0000000..a32af91 --- /dev/null +++ b/SYBDContracts/ViewModels/WorkerViewModel.cs @@ -0,0 +1,18 @@ +using SYBDDataModels.Models; +using System.ComponentModel; + +namespace SYBDContracts.ViewModels +{ + public class WorkerViewModel : IWorkerModel + { + public int Id { get; set; } + + [DisplayName("ФИО работника")] + public string Fullname { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + [DisplayName("Зарплата")] + public int Salary { get; set; } + } +} diff --git a/SYBDDataModels/IId.cs b/SYBDDataModels/IId.cs new file mode 100644 index 0000000..caf347a --- /dev/null +++ b/SYBDDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace SYBDDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/SYBDDataModels/Models/IAutoModel.cs b/SYBDDataModels/Models/IAutoModel.cs new file mode 100644 index 0000000..aba1f86 --- /dev/null +++ b/SYBDDataModels/Models/IAutoModel.cs @@ -0,0 +1,8 @@ +namespace SYBDDataModels.Models +{ + public interface IAutoModel : IId + { + string StateNumber { get; } + string Model { get; } + } +} \ No newline at end of file diff --git a/SYBDDataModels/Models/IClientModel.cs b/SYBDDataModels/Models/IClientModel.cs new file mode 100644 index 0000000..9d000ae --- /dev/null +++ b/SYBDDataModels/Models/IClientModel.cs @@ -0,0 +1,12 @@ +namespace SYBDDataModels.Models +{ + public interface IClientModel : IId + { + string Fullname { get; } + + string Phone { get; } + + string Email { get; } + + } +} \ No newline at end of file diff --git a/SYBDDataModels/Models/IInsuranceModel.cs b/SYBDDataModels/Models/IInsuranceModel.cs new file mode 100644 index 0000000..7053dc0 --- /dev/null +++ b/SYBDDataModels/Models/IInsuranceModel.cs @@ -0,0 +1,12 @@ +namespace SYBDDataModels.Models +{ + public interface IInsuranceModel : IId + { + string Name { get; } + + string Address { get; } + + string Phone { get; } + + } +} \ No newline at end of file diff --git a/SYBDDataModels/Models/IOrderModel.cs b/SYBDDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..72406ea --- /dev/null +++ b/SYBDDataModels/Models/IOrderModel.cs @@ -0,0 +1,15 @@ + +namespace SYBDDataModels.Models +{ + public interface IOrderModel : IId + { + int AutoId { get; } + int ClientId{ get; } + int InsuranceId{ get; } + int WorkerId{ get; } + string Description { get; } + string Status { get; } + double Price { get; } + + } +} \ No newline at end of file diff --git a/SYBDDataModels/Models/IWorkerModel.cs b/SYBDDataModels/Models/IWorkerModel.cs new file mode 100644 index 0000000..f90c85d --- /dev/null +++ b/SYBDDataModels/Models/IWorkerModel.cs @@ -0,0 +1,12 @@ +namespace SYBDDataModels.Models +{ + public interface IWorkerModel : IId + { + string Fullname { get; } + + string Address { get; } + + int Salary { get; } + + } +} \ No newline at end of file diff --git a/SYBDDataModels/SYBDDataModels.csproj b/SYBDDataModels/SYBDDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SYBDDataModels/SYBDDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SYBDDatabaseImplement/Implements/AutoStorage.cs b/SYBDDatabaseImplement/Implements/AutoStorage.cs new file mode 100644 index 0000000..4c45a53 --- /dev/null +++ b/SYBDDatabaseImplement/Implements/AutoStorage.cs @@ -0,0 +1,84 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using SYBDDatabaseImplement.Models; + +namespace SYBDDatabaseImplement.Implements +{ + public class AutoStorage : IAutoStorage + { + public List GetFullList() + { + using var context = new SYBDDatabase(); + return context.auto + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(AutoSearchModel model) + { + if (string.IsNullOrEmpty(model.StateNumber)) + { + return new(); + } + using var context = new SYBDDatabase(); + return context.auto + .Where(x => x.StateNumber.Contains(model.StateNumber)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public AutoViewModel? GetElement(AutoSearchModel model) + { + if (string.IsNullOrEmpty(model.StateNumber) && !model.Id.HasValue) + { + return null; + } + using var context = new SYBDDatabase(); + return context.auto + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.StateNumber) && x.StateNumber == model.StateNumber) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public AutoViewModel? Insert(AutoBindingModel model) + { + var newAuto = Auto.Create(model); + if (newAuto == null) + { + return null; + } + using var context = new SYBDDatabase(); + context.auto.Add(newAuto); + context.SaveChanges(); + return newAuto.GetViewModel; + } + + public AutoViewModel? Update(AutoBindingModel model) + { + using var context = new SYBDDatabase(); + var component = context.auto.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public AutoViewModel? Delete(AutoBindingModel model) + { + using var context = new SYBDDatabase(); + var element = context.auto.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.auto.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Implements/ClientStorage.cs b/SYBDDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..a011bd7 --- /dev/null +++ b/SYBDDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,84 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using SYBDDatabaseImplement.Models; + +namespace SYBDDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public List GetFullList() + { + using var context = new SYBDDatabase(); + return context.client + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Fullname)) + { + return new(); + } + using var context = new SYBDDatabase(); + return context.client + .Where(x => x.Fullname.Contains(model.Fullname)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Fullname) && !model.Id.HasValue) + { + return null; + } + using var context = new SYBDDatabase(); + return context.client + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Fullname) && x.Fullname == model.Fullname) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + using var context = new SYBDDatabase(); + context.client.Add(newClient); + context.SaveChanges(); + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new SYBDDatabase(); + var component = context.client.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public ClientViewModel? Delete(ClientBindingModel model) + { + using var context = new SYBDDatabase(); + var element = context.client.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.client.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Implements/InsuranceStorage.cs b/SYBDDatabaseImplement/Implements/InsuranceStorage.cs new file mode 100644 index 0000000..87f131e --- /dev/null +++ b/SYBDDatabaseImplement/Implements/InsuranceStorage.cs @@ -0,0 +1,84 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using SYBDDatabaseImplement.Models; + +namespace SYBDDatabaseImplement.Implements +{ + public class InsuranceStorage : IInsuranceStorage + { + public List GetFullList() + { + using var context = new SYBDDatabase(); + return context.insurance + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(InsuranceSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + using var context = new SYBDDatabase(); + return context.insurance + .Where(x => x.Name.Contains(model.Name)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public InsuranceViewModel? GetElement(InsuranceSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + using var context = new SYBDDatabase(); + return context.insurance + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public InsuranceViewModel? Insert(InsuranceBindingModel model) + { + var newInsurance = Insurance.Create(model); + if (newInsurance == null) + { + return null; + } + using var context = new SYBDDatabase(); + context.insurance.Add(newInsurance); + context.SaveChanges(); + return newInsurance.GetViewModel; + } + + public InsuranceViewModel? Update(InsuranceBindingModel model) + { + using var context = new SYBDDatabase(); + var component = context.insurance.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public InsuranceViewModel? Delete(InsuranceBindingModel model) + { + using var context = new SYBDDatabase(); + var element = context.insurance.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.insurance.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Implements/OrderStorage.cs b/SYBDDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..5146642 --- /dev/null +++ b/SYBDDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,112 @@ +using Microsoft.EntityFrameworkCore; +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using SYBDDatabaseImplement.Models; + +namespace SYBDDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new SYBDDatabase(); + var element = context.order + .Include(x => x.Auto) + .Include(x => x.Client) + .Include(x => x.Insurance) + .Include(x => x.Worker) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.order.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new SYBDDatabase(); + return context.order + .Include(x => x.Auto) + .Include(x => x.Client) + .Include(x => x.Insurance) + .Include(x => x.Worker) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new SYBDDatabase(); + return context.order + .Include(x => x.Auto) + .Include(x => x.Client) + .Include(x => x.Insurance) + .Include(x => x.Worker) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SYBDDatabase(); + return context.order + .Include(x => x.Auto) + .Include(x => x.Client) + .Include(x => x.Insurance) + .Include(x => x.Worker) + .Select(x => x.GetViewModel) + .ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + newOrder.Status = "В обработке"; + using var context = new SYBDDatabase(); + context.order.Add(newOrder); + context.SaveChanges(); + return context.order + .Include(x => x.Auto) + .Include(x => x.Client) + .Include(x => x.Insurance) + .Include(x => x.Worker) + .FirstOrDefault() + ?.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new SYBDDatabase(); + var order = context.order + .Include(x => x.Auto) + .Include(x => x.Client) + .Include(x => x.Insurance) + .Include(x => x.Worker).FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return order.GetViewModel; + } + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Implements/WorkerStorage.cs b/SYBDDatabaseImplement/Implements/WorkerStorage.cs new file mode 100644 index 0000000..4bf9b29 --- /dev/null +++ b/SYBDDatabaseImplement/Implements/WorkerStorage.cs @@ -0,0 +1,84 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.SearchModels; +using SYBDContracts.StoragesContracts; +using SYBDContracts.ViewModels; +using SYBDDatabaseImplement.Models; + +namespace SYBDDatabaseImplement.Implements +{ + public class WorkerStorage : IWorkerStorage + { + public List GetFullList() + { + using var context = new SYBDDatabase(); + return context.worker + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(WorkerSearchModel model) + { + if (string.IsNullOrEmpty(model.Fullname)) + { + return new(); + } + using var context = new SYBDDatabase(); + return context.worker + .Where(x => x.Fullname.Contains(model.Fullname)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public WorkerViewModel? GetElement(WorkerSearchModel model) + { + if (string.IsNullOrEmpty(model.Fullname) && !model.Id.HasValue) + { + return null; + } + using var context = new SYBDDatabase(); + return context.worker + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Fullname) && x.Fullname == model.Fullname) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public WorkerViewModel? Insert(WorkerBindingModel model) + { + var newWorker = Worker.Create(model); + if (newWorker == null) + { + return null; + } + using var context = new SYBDDatabase(); + context.worker.Add(newWorker); + context.SaveChanges(); + return newWorker.GetViewModel; + } + + public WorkerViewModel? Update(WorkerBindingModel model) + { + using var context = new SYBDDatabase(); + var component = context.worker.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public WorkerViewModel? Delete(WorkerBindingModel model) + { + using var context = new SYBDDatabase(); + var element = context.worker.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.worker.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Migrations/20240416144856_InitialCreate.Designer.cs b/SYBDDatabaseImplement/Migrations/20240416144856_InitialCreate.Designer.cs new file mode 100644 index 0000000..707871d --- /dev/null +++ b/SYBDDatabaseImplement/Migrations/20240416144856_InitialCreate.Designer.cs @@ -0,0 +1,221 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using SYBDDatabaseImplement; + +#nullable disable + +namespace SYBDDatabaseImplement.Migrations +{ + [DbContext(typeof(SYBDDatabase))] + [Migration("20240416144856_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.29") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Auto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Model") + .IsRequired() + .HasColumnType("text"); + + b.Property("StateNumber") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Autos"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Fullname") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Insurance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Insurances"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AutoId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("InsuranceId") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("WorkerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AutoId"); + + b.HasIndex("ClientId"); + + b.HasIndex("InsuranceId"); + + b.HasIndex("WorkerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Fullname") + .IsRequired() + .HasColumnType("text"); + + b.Property("Salary") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b => + { + b.HasOne("SYBDDatabaseImplement.Models.Auto", "Auto") + .WithMany("Orders") + .HasForeignKey("AutoId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SYBDDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SYBDDatabaseImplement.Models.Insurance", "Insurance") + .WithMany("Orders") + .HasForeignKey("InsuranceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SYBDDatabaseImplement.Models.Worker", "Worker") + .WithMany("Orders") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Auto"); + + b.Navigation("Client"); + + b.Navigation("Insurance"); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Auto", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Insurance", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Worker", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SYBDDatabaseImplement/Migrations/20240416144856_InitialCreate.cs b/SYBDDatabaseImplement/Migrations/20240416144856_InitialCreate.cs new file mode 100644 index 0000000..159100c --- /dev/null +++ b/SYBDDatabaseImplement/Migrations/20240416144856_InitialCreate.cs @@ -0,0 +1,153 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace SYBDDatabaseImplement.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Autos", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Model = table.Column(type: "text", nullable: false), + StateNumber = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Autos", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Fullname = table.Column(type: "text", nullable: false), + Phone = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Insurances", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Address = table.Column(type: "text", nullable: false), + Phone = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Insurances", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Workers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Fullname = table.Column(type: "text", nullable: false), + Address = table.Column(type: "text", nullable: false), + Salary = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Workers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AutoId = table.Column(type: "integer", nullable: false), + ClientId = table.Column(type: "integer", nullable: false), + InsuranceId = table.Column(type: "integer", nullable: false), + WorkerId = table.Column(type: "integer", nullable: false), + Price = table.Column(type: "double precision", nullable: false), + Description = table.Column(type: "text", nullable: false), + Status = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Autos_AutoId", + column: x => x.AutoId, + principalTable: "Autos", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Insurances_InsuranceId", + column: x => x.InsuranceId, + principalTable: "Insurances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Workers_WorkerId", + column: x => x.WorkerId, + principalTable: "Workers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_AutoId", + table: "Orders", + column: "AutoId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_InsuranceId", + table: "Orders", + column: "InsuranceId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_WorkerId", + table: "Orders", + column: "WorkerId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Autos"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Insurances"); + + migrationBuilder.DropTable( + name: "Workers"); + } + } +} diff --git a/SYBDDatabaseImplement/Migrations/SYBDDatabaseModelSnapshot.cs b/SYBDDatabaseImplement/Migrations/SYBDDatabaseModelSnapshot.cs new file mode 100644 index 0000000..41050ed --- /dev/null +++ b/SYBDDatabaseImplement/Migrations/SYBDDatabaseModelSnapshot.cs @@ -0,0 +1,219 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using SYBDDatabaseImplement; + +#nullable disable + +namespace SYBDDatabaseImplement.Migrations +{ + [DbContext(typeof(SYBDDatabase))] + partial class SYBDDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.29") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Auto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Model") + .IsRequired() + .HasColumnType("text"); + + b.Property("StateNumber") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Autos"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Fullname") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Insurance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Insurances"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AutoId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("InsuranceId") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("WorkerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AutoId"); + + b.HasIndex("ClientId"); + + b.HasIndex("InsuranceId"); + + b.HasIndex("WorkerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Fullname") + .IsRequired() + .HasColumnType("text"); + + b.Property("Salary") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b => + { + b.HasOne("SYBDDatabaseImplement.Models.Auto", "Auto") + .WithMany("Orders") + .HasForeignKey("AutoId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SYBDDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SYBDDatabaseImplement.Models.Insurance", "Insurance") + .WithMany("Orders") + .HasForeignKey("InsuranceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SYBDDatabaseImplement.Models.Worker", "Worker") + .WithMany("Orders") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Auto"); + + b.Navigation("Client"); + + b.Navigation("Insurance"); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Auto", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Insurance", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SYBDDatabaseImplement.Models.Worker", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SYBDDatabaseImplement/Models/Auto.cs b/SYBDDatabaseImplement/Models/Auto.cs new file mode 100644 index 0000000..28edad2 --- /dev/null +++ b/SYBDDatabaseImplement/Models/Auto.cs @@ -0,0 +1,61 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.ViewModels; +using SYBDDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SYBDDatabaseImplement.Models +{ + public class Auto : IAutoModel + { + public int Id { get; private set; } + + [Required] + public string Model { get; private set; } = string.Empty; + + [Required] + public string StateNumber { get; private set; } = string.Empty; + [ForeignKey("AutoId")] + public virtual List Orders { get; set; } = new(); + public static Auto? Create(AutoBindingModel model) + { + if (model == null) + { + return null; + } + return new Auto() + { + Id = model.Id, + Model = model.Model, + StateNumber = model.StateNumber + }; + } + + public static Auto Create(AutoViewModel model) + { + return new Auto + { + Id = model.Id, + Model = model.Model, + StateNumber = model.StateNumber + }; + } + + public void Update(AutoBindingModel model) + { + if (model == null) + { + return; + } + Model = model.Model; + StateNumber = model.StateNumber; + } + + public AutoViewModel GetViewModel => new() + { + Id = Id, + Model = Model, + StateNumber = StateNumber + }; + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Models/Client.cs b/SYBDDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..b2153f6 --- /dev/null +++ b/SYBDDatabaseImplement/Models/Client.cs @@ -0,0 +1,66 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.ViewModels; +using SYBDDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SYBDDatabaseImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + + [Required] + public string Fullname { get; private set; } = string.Empty; + [Required] + public string Phone { get; private set; } = string.Empty; + [Required] + public string Email { get; private set; } = string.Empty; + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + Fullname = model.Fullname, + Phone = model.Phone, + Email= model.Email, + }; + } + + public static Client Create(ClientViewModel model) + { + return new Client + { + Id = model.Id, + Fullname = model.Fullname, + Phone = model.Phone, + Email = model.Email, + }; + } + + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + Fullname = model.Fullname; + Phone = model.Phone; + Email = model.Email; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + Fullname = Fullname, + Phone = Phone, + Email = Email, + }; + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Models/Insurance.cs b/SYBDDatabaseImplement/Models/Insurance.cs new file mode 100644 index 0000000..2584cf7 --- /dev/null +++ b/SYBDDatabaseImplement/Models/Insurance.cs @@ -0,0 +1,68 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.ViewModels; +using SYBDDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SYBDDatabaseImplement.Models +{ + public class Insurance : IInsuranceModel + { + public int Id { get; private set; } + + [Required] + public string Name { get; private set; } = string.Empty; + + [Required] + public string Address { get; private set; } = string.Empty; + + [Required] + public string Phone { get; private set; } = string.Empty; + [ForeignKey("InsuranceId")] + public virtual List Orders { get; set; } = new(); + public static Insurance? Create(InsuranceBindingModel model) + { + if (model == null) + { + return null; + } + return new Insurance() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + Phone = model.Phone, + }; + } + + public static Insurance Create(InsuranceViewModel model) + { + return new Insurance + { + Id = model.Id, + Address = model.Address, + Name = model.Name, + Phone = model.Phone, + }; + } + + public void Update(InsuranceBindingModel model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + Phone = model.Phone; + } + + public InsuranceViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + Phone = Phone, + }; + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Models/Order.cs b/SYBDDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..3711814 --- /dev/null +++ b/SYBDDatabaseImplement/Models/Order.cs @@ -0,0 +1,73 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.ViewModels; +using SYBDDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace SYBDDatabaseImplement.Models +{ + public class Order : IOrderModel + { + [Required] + public int AutoId { get; set; } + [Required] + public int ClientId { get; set; } + [Required] + public int InsuranceId { get; set; } + [Required] + public int WorkerId { get; set; } + + [Required] + public double Price { get; set; } + [Required] + public string Description { get; private set; } = string.Empty; + [Required] + public string Status { get; set; } + + public int Id { get; set; } + + public virtual Auto Auto { get; set; } + public virtual Client Client { get; set; } + public virtual Insurance Insurance { get; set; } + public virtual Worker Worker { get; set; } + + public static Order? Create( OrderBindingModel? model) + { + if (model == null) + return null; + return new Order() + { + Id = model.Id, + AutoId = model.AutoId, + ClientId = model.ClientId, + InsuranceId = model.InsuranceId, + WorkerId = model.WorkerId, + Price = model.Price, + Description = model.Description, + Status = model.Status, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + return; + Status = model.Status; + } + + public OrderViewModel GetViewModel => new() + { + AutoId = AutoId, + AutoModel = Auto.Model, + ClientId = ClientId, + ClientFullname = Client.Fullname, + InsuranceId = InsuranceId, + InsuranceName = Insurance.Name, + WorkerId = WorkerId, + WorkerFullname = Worker.Fullname, + Price = Price, + Description = Description, + Status = Status, + Id = Id, + }; + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/Models/Worker.cs b/SYBDDatabaseImplement/Models/Worker.cs new file mode 100644 index 0000000..86a9f27 --- /dev/null +++ b/SYBDDatabaseImplement/Models/Worker.cs @@ -0,0 +1,58 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.ViewModels; +using SYBDDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SYBDDatabaseImplement.Models +{ + public class Worker : IWorkerModel + { + public int Id { get; set; } + + [Required] + public string Fullname { get; set; } = string.Empty; + + [Required] + public string Address { get; set; } = string.Empty; + [Required] + public int Salary { get; set; } + [ForeignKey("WorkerId")] + public virtual List Orders { get; set; } = new(); + public static Worker Create(WorkerViewModel model) + { + return new Worker + { + Id = model.Id, + Fullname = model.Fullname, + Address = model.Address, + Salary = model.Salary, + }; + } + public static Worker? Create(WorkerBindingModel model) + { + return new Worker() + { + Id = model.Id, + Fullname = model.Fullname, + Address = model.Address, + Salary = model.Salary, + }; + } + + public void Update(WorkerBindingModel model) + { + Fullname = model.Fullname; + Address = model.Address; + Salary = model.Salary; + } + + public WorkerViewModel GetViewModel => new() + { + Id = Id, + Fullname = Fullname, + Address = Address, + Salary = Salary + }; + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/PlumbingRepairDatabase.cs b/SYBDDatabaseImplement/PlumbingRepairDatabase.cs new file mode 100644 index 0000000..6bb8ac7 --- /dev/null +++ b/SYBDDatabaseImplement/PlumbingRepairDatabase.cs @@ -0,0 +1,26 @@ +using SYBDDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace SYBDDatabaseImplement +{ + public class SYBDDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql(@"Host=192.168.225.184;Database=postgres;Username=sardq;"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet auto { set; get; } + + public virtual DbSet client { set; get; } + + public virtual DbSet insurance{ set; get; } + + public virtual DbSet order { set; get; } + public virtual DbSet worker { set; get; } + } +} \ No newline at end of file diff --git a/SYBDDatabaseImplement/SYBDDatabaseImplement.csproj b/SYBDDatabaseImplement/SYBDDatabaseImplement.csproj new file mode 100644 index 0000000..da586d6 --- /dev/null +++ b/SYBDDatabaseImplement/SYBDDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/SYBDView/FormAuto.Designer.cs b/SYBDView/FormAuto.Designer.cs new file mode 100644 index 0000000..df6bfb5 --- /dev/null +++ b/SYBDView/FormAuto.Designer.cs @@ -0,0 +1,125 @@ +namespace SYBDView +{ + partial class FormAuto + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxStateNumber = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxModel = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxStateNumber + // + this.textBoxStateNumber.Location = new System.Drawing.Point(157, 99); + this.textBoxStateNumber.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxStateNumber.Name = "textBoxStateNumber"; + this.textBoxStateNumber.Size = new System.Drawing.Size(257, 31); + this.textBoxStateNumber.TabIndex = 23; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(4, 80); + this.labelPrice.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(160, 50); + this.labelPrice.TabIndex = 22; + this.labelPrice.Text = "Государственный \r\nномер:"; + // + // textBoxModel + // + this.textBoxModel.Location = new System.Drawing.Point(157, 30); + this.textBoxModel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxModel.Name = "textBoxModel"; + this.textBoxModel.Size = new System.Drawing.Size(358, 31); + this.textBoxModel.TabIndex = 21; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(4, 33); + this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 25); + this.labelName.TabIndex = 20; + this.labelName.Text = "Модель:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(414, 162); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 25; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(285, 162); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 24; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormAuto + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(555, 221); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxStateNumber); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.textBoxModel); + this.Controls.Add(this.labelName); + this.Name = "FormAuto"; + this.Text = "Автомобиль"; + this.Load += new System.EventHandler(this.FormAuto_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxStateNumber; + private Label labelPrice; + private TextBox textBoxModel; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SYBDView/FormAuto.cs b/SYBDView/FormAuto.cs new file mode 100644 index 0000000..559a296 --- /dev/null +++ b/SYBDView/FormAuto.cs @@ -0,0 +1,88 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormAuto : Form + { + private readonly ILogger _logger; + + private readonly IAutoLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + + public FormAuto(ILogger logger, IAutoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormAuto_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка автомобилей"); + try + { + var view = _logic.ReadElement(new AutoSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxModel.Text = view.Model; + textBoxStateNumber.Text = view.StateNumber; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки автомобиля"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxModel.Text)) + { + MessageBox.Show("Заполните модель", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxStateNumber.Text)) + { + MessageBox.Show("Заполните гос номер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение автомобиля"); + try + { + var model = new AutoBindingModel + { + Id = _id ?? 0, + Model = textBoxModel.Text, + StateNumber = textBoxStateNumber.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(); + } + } +} \ No newline at end of file diff --git a/SYBDView/FormAuto.resx b/SYBDView/FormAuto.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormAuto.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormAutos.Designer.cs b/SYBDView/FormAutos.Designer.cs new file mode 100644 index 0000000..a54bebc --- /dev/null +++ b/SYBDView/FormAutos.Designer.cs @@ -0,0 +1,127 @@ +namespace SYBDView +{ + partial class FormAutos + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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(779, 241); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + this.buttonRef.TabIndex = 19; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(779, 162); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + this.buttonDel.TabIndex = 18; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(779, 95); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + this.buttonUpd.TabIndex = 17; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(779, 22); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 16; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + 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.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(767, 450); + this.dataGridView.TabIndex = 15; + // + // FormAutos + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(918, 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 = "FormAutos"; + this.Text = "Автомобили"; + this.Load += new System.EventHandler(this.FormAutos_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; + } +} \ No newline at end of file diff --git a/SYBDView/FormAutos.cs b/SYBDView/FormAutos.cs new file mode 100644 index 0000000..5da227b --- /dev/null +++ b/SYBDView/FormAutos.cs @@ -0,0 +1,104 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormAutos : Form + { + public FormAutos(ILogger logger, IAutoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private readonly ILogger _logger; + + private readonly IAutoLogic _logic; + + + private void FormAutos_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Model"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка Работ"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAuto)); + if (service is FormAuto 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(FormAuto)); + if (service is FormAuto 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 AutoBindingModel { 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(); + } + } +} diff --git a/SYBDView/FormAutos.resx b/SYBDView/FormAutos.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormAutos.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormClient.Designer.cs b/SYBDView/FormClient.Designer.cs new file mode 100644 index 0000000..210ce7a --- /dev/null +++ b/SYBDView/FormClient.Designer.cs @@ -0,0 +1,149 @@ +namespace SYBDView +{ + partial class FormClient + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxPhone = new System.Windows.Forms.TextBox(); + this.labelSalary = new System.Windows.Forms.Label(); + this.textBoxEmail = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.textBoxFullname = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxPhone + // + this.textBoxPhone.Location = new System.Drawing.Point(180, 137); + this.textBoxPhone.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxPhone.Name = "textBoxPhone"; + this.textBoxPhone.Size = new System.Drawing.Size(294, 31); + this.textBoxPhone.TabIndex = 29; + // + // labelSalary + // + this.labelSalary.AutoSize = true; + this.labelSalary.Location = new System.Drawing.Point(5, 140); + this.labelSalary.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelSalary.Name = "labelSalary"; + this.labelSalary.Size = new System.Drawing.Size(177, 25); + this.labelSalary.TabIndex = 28; + this.labelSalary.Text = "Телефонный номер:"; + // + // textBoxEmail + // + this.textBoxEmail.Location = new System.Drawing.Point(180, 85); + this.textBoxEmail.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxEmail.Name = "textBoxEmail"; + this.textBoxEmail.Size = new System.Drawing.Size(358, 31); + this.textBoxEmail.TabIndex = 27; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(5, 91); + this.labelAddress.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(66, 25); + this.labelAddress.TabIndex = 26; + this.labelAddress.Text = "Почта:"; + // + // textBoxFullname + // + this.textBoxFullname.Location = new System.Drawing.Point(180, 35); + this.textBoxFullname.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxFullname.Name = "textBoxFullname"; + this.textBoxFullname.Size = new System.Drawing.Size(358, 31); + this.textBoxFullname.TabIndex = 25; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(5, 41); + this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(56, 25); + this.labelName.TabIndex = 24; + this.labelName.Text = "ФИО:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(449, 237); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 31; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(320, 237); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 30; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(579, 285); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxPhone); + this.Controls.Add(this.labelSalary); + this.Controls.Add(this.textBoxEmail); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.textBoxFullname); + this.Controls.Add(this.labelName); + this.Name = "FormClient"; + this.Text = "Клиент"; + this.Load += new System.EventHandler(this.FormClient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPhone; + private Label labelSalary; + private TextBox textBoxEmail; + private Label labelAddress; + private TextBox textBoxFullname; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SYBDView/FormClient.cs b/SYBDView/FormClient.cs new file mode 100644 index 0000000..0ed47d1 --- /dev/null +++ b/SYBDView/FormClient.cs @@ -0,0 +1,95 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormClient : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + + public FormClient(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка клиентов"); + try + { + var view = _logic.ReadElement(new ClientSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFullname.Text = view.Fullname; + textBoxEmail.Text = view.Email; + textBoxPhone.Text = view.Phone; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFullname.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxEmail.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPhone.Text)) + { + MessageBox.Show("Заполните телефон", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ClientBindingModel + { + Id = _id ?? 0, + Fullname = textBoxFullname.Text, + Email = textBoxEmail.Text, + Phone = textBoxPhone.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(); + } + } +} \ No newline at end of file diff --git a/SYBDView/FormClient.resx b/SYBDView/FormClient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormClient.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormClients.Designer.cs b/SYBDView/FormClients.Designer.cs new file mode 100644 index 0000000..3639f85 --- /dev/null +++ b/SYBDView/FormClients.Designer.cs @@ -0,0 +1,127 @@ +namespace SYBDView +{ + partial class FormClients + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + 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.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(583, 450); + this.dataGridView.TabIndex = 6; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(645, 241); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + this.buttonRef.TabIndex = 11; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(645, 174); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + this.buttonDel.TabIndex = 10; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(645, 107); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + this.buttonUpd.TabIndex = 14; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(645, 34); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 13; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Text = "Клиенты"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SYBDView/FormClients.cs b/SYBDView/FormClients.cs new file mode 100644 index 0000000..439169e --- /dev/null +++ b/SYBDView/FormClients.cs @@ -0,0 +1,106 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace SYBDView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Fullname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient 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(FormClient)); + if (service is FormClient 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 ClientBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/SYBDView/FormClients.resx b/SYBDView/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormClients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormCreateOrder.Designer.cs b/SYBDView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..e67d6a2 --- /dev/null +++ b/SYBDView/FormCreateOrder.Designer.cs @@ -0,0 +1,229 @@ +namespace SYBDView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelSum = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxClient = new System.Windows.Forms.ComboBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxDescription = new System.Windows.Forms.TextBox(); + this.labelWork = new System.Windows.Forms.Label(); + this.comboBoxAuto = new System.Windows.Forms.ComboBox(); + this.labelClient = new System.Windows.Forms.Label(); + this.comboBoxWorker = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxInsurance = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(9, 243); + this.labelSum.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(103, 25); + this.labelSum.TabIndex = 12; + this.labelSum.Text = "Стоимость:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(9, 194); + this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(96, 25); + this.labelCount.TabIndex = 10; + this.labelCount.Text = "Описание:"; + // + // comboBoxClient + // + this.comboBoxClient.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxClient.FormattingEnabled = true; + this.comboBoxClient.Location = new System.Drawing.Point(134, 59); + this.comboBoxClient.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboBoxClient.Name = "comboBoxClient"; + this.comboBoxClient.Size = new System.Drawing.Size(359, 33); + this.comboBoxClient.TabIndex = 9; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(367, 291); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(125, 44); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(232, 291); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(125, 44); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxDescription + // + this.textBoxDescription.Location = new System.Drawing.Point(134, 194); + this.textBoxDescription.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.textBoxDescription.Name = "textBoxDescription"; + this.textBoxDescription.Size = new System.Drawing.Size(359, 31); + this.textBoxDescription.TabIndex = 11; + // + // labelWork + // + this.labelWork.AutoSize = true; + this.labelWork.Location = new System.Drawing.Point(9, 64); + this.labelWork.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelWork.Name = "labelWork"; + this.labelWork.Size = new System.Drawing.Size(71, 25); + this.labelWork.TabIndex = 8; + this.labelWork.Text = "Клиент:"; + // + // comboBoxAuto + // + this.comboBoxAuto.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxAuto.FormattingEnabled = true; + this.comboBoxAuto.Location = new System.Drawing.Point(134, 14); + this.comboBoxAuto.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboBoxAuto.Name = "comboBoxAuto"; + this.comboBoxAuto.Size = new System.Drawing.Size(359, 33); + this.comboBoxAuto.TabIndex = 17; + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(9, 19); + this.labelClient.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(118, 25); + this.labelClient.TabIndex = 16; + this.labelClient.Text = "Автомобиль:"; + // + // comboBoxWorker + // + this.comboBoxWorker.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxWorker.FormattingEnabled = true; + this.comboBoxWorker.Location = new System.Drawing.Point(134, 104); + this.comboBoxWorker.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboBoxWorker.Name = "comboBoxWorker"; + this.comboBoxWorker.Size = new System.Drawing.Size(359, 33); + this.comboBoxWorker.TabIndex = 19; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(9, 109); + this.label1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(92, 25); + this.label1.TabIndex = 18; + this.label1.Text = "Работник:"; + // + // comboBoxInsurance + // + this.comboBoxInsurance.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxInsurance.FormattingEnabled = true; + this.comboBoxInsurance.Location = new System.Drawing.Point(134, 149); + this.comboBoxInsurance.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboBoxInsurance.Name = "comboBoxInsurance"; + this.comboBoxInsurance.Size = new System.Drawing.Size(359, 33); + this.comboBoxInsurance.TabIndex = 21; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 154); + this.label2.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(101, 25); + this.label2.TabIndex = 20; + this.label2.Text = "Страховая:"; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(134, 240); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(359, 31); + this.textBoxPrice.TabIndex = 22; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(534, 352); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.comboBoxInsurance); + this.Controls.Add(this.label2); + this.Controls.Add(this.comboBoxWorker); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxAuto); + this.Controls.Add(this.labelClient); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxClient); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxDescription); + this.Controls.Add(this.labelWork); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelSum; + private Label labelCount; + private ComboBox comboBoxClient; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxDescription; + private Label labelWork; + private ComboBox comboBoxAuto; + private Label labelClient; + private ComboBox comboBoxWorker; + private Label label1; + private ComboBox comboBoxInsurance; + private Label label2; + private TextBox textBoxPrice; + } +} \ No newline at end of file diff --git a/SYBDView/FormCreateOrder.cs b/SYBDView/FormCreateOrder.cs new file mode 100644 index 0000000..e5ca4c7 --- /dev/null +++ b/SYBDView/FormCreateOrder.cs @@ -0,0 +1,172 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace SYBDView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IWorkerLogic _logicWorker; + private readonly IAutoLogic _logicAuto; + private readonly IInsuranceLogic _logicInsurance; + + private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicClient; + private int? _id; + public int Id { set { _id = value; } } + public FormCreateOrder(ILogger logger, IWorkerLogic logicW, IOrderLogic logicO, IClientLogic logicClient, IInsuranceLogic logicI, IAutoLogic autoLogic) + { + InitializeComponent(); + _logger = logger; + _logicWorker = logicW; + _logicO = logicO; + _logicClient = logicClient; + _logicAuto = autoLogic; + _logicInsurance = logicI; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + + try + { + var list = _logicWorker.ReadList(null); + if (list != null) + { + comboBoxWorker.DataSource = list; + comboBoxWorker.DisplayMember = "Fullname"; + comboBoxWorker.ValueMember = "Id"; + comboBoxWorker.SelectedItem = null; + } + _logger.LogInformation("Загрузка работ"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + try + { + var list = _logicClient.ReadList(null); + if (list != null) + { + comboBoxClient.DataSource = list; + comboBoxClient.DisplayMember = "Fullname"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.SelectedItem = null; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + try + { + var list = _logicAuto.ReadList(null); + if (list != null) + { + comboBoxAuto.DataSource = list; + comboBoxAuto.DisplayMember = "Model"; + comboBoxAuto.ValueMember = "Id"; + comboBoxAuto.SelectedItem = null; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + try + { + var list = _logicInsurance.ReadList(null); + if (list != null) + { + comboBoxInsurance.DataSource = list; + comboBoxInsurance.DisplayMember = "Name"; + comboBoxInsurance.ValueMember = "Id"; + comboBoxInsurance.SelectedItem = null; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxDescription.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxInsurance.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + + } + if (comboBoxWorker.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxAuto.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.Create(new OrderBindingModel + { + WorkerId = Convert.ToInt32(comboBoxWorker.SelectedValue), + AutoId = Convert.ToInt32(comboBoxAuto.SelectedValue), + InsuranceId = Convert.ToInt32(comboBoxInsurance.SelectedValue), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), + Description = textBoxDescription.Text, + Price = Convert.ToDouble(textBoxPrice.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} + + + + + + \ No newline at end of file diff --git a/SYBDView/FormCreateOrder.resx b/SYBDView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormInsurance.Designer.cs b/SYBDView/FormInsurance.Designer.cs new file mode 100644 index 0000000..94cab7f --- /dev/null +++ b/SYBDView/FormInsurance.Designer.cs @@ -0,0 +1,149 @@ +namespace SYBDView +{ + partial class FormInsurance + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxPhone = new System.Windows.Forms.TextBox(); + this.labelSalary = new System.Windows.Forms.Label(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxPhone + // + this.textBoxPhone.Location = new System.Drawing.Point(182, 123); + this.textBoxPhone.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxPhone.Name = "textBoxPhone"; + this.textBoxPhone.Size = new System.Drawing.Size(294, 31); + this.textBoxPhone.TabIndex = 23; + // + // labelSalary + // + this.labelSalary.AutoSize = true; + this.labelSalary.Location = new System.Drawing.Point(7, 126); + this.labelSalary.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelSalary.Name = "labelSalary"; + this.labelSalary.Size = new System.Drawing.Size(177, 25); + this.labelSalary.TabIndex = 22; + this.labelSalary.Text = "Телефонный номер:"; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(182, 71); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(358, 31); + this.textBoxAddress.TabIndex = 19; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(7, 77); + this.labelAddress.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(66, 25); + this.labelAddress.TabIndex = 18; + this.labelAddress.Text = "Адрес:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(182, 21); + this.textBoxName.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(358, 31); + this.textBoxName.TabIndex = 17; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(7, 27); + this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 16; + this.labelName.Text = "Название:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(451, 227); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 21; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(322, 227); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 20; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormInsurance + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(581, 281); + this.Controls.Add(this.textBoxPhone); + this.Controls.Add(this.labelSalary); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormInsurance"; + this.Text = "Страховая"; + this.Load += new System.EventHandler(this.FormInsurances_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPhone; + private Label labelSalary; + private TextBox textBoxAddress; + private Label labelAddress; + private TextBox textBoxName; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SYBDView/FormInsurance.cs b/SYBDView/FormInsurance.cs new file mode 100644 index 0000000..a40d516 --- /dev/null +++ b/SYBDView/FormInsurance.cs @@ -0,0 +1,93 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormInsurance : Form + { + public FormInsurance(ILogger logger, IInsuranceLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private readonly ILogger _logger; + + private readonly IInsuranceLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + private void FormInsurances_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка страховой"); + try + { + var view = _logic.ReadElement(new InsuranceSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxAddress.Text = view.Address; + textBoxPhone.Text = view.Phone; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки страховой"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPhone.Text)) + { + MessageBox.Show("Заполните телефон", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new InsuranceBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Address = textBoxAddress.Text, + Phone = textBoxPhone.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(); + } + } + } diff --git a/SYBDView/FormInsurance.resx b/SYBDView/FormInsurance.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormInsurance.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormInsurances.Designer.cs b/SYBDView/FormInsurances.Designer.cs new file mode 100644 index 0000000..c240c3e --- /dev/null +++ b/SYBDView/FormInsurances.Designer.cs @@ -0,0 +1,127 @@ +namespace SYBDView +{ + partial class FormInsurances + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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(802, 243); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + this.buttonRef.TabIndex = 19; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(802, 164); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + this.buttonDel.TabIndex = 18; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(802, 97); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + this.buttonUpd.TabIndex = 17; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(802, 24); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 16; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + 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.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(767, 447); + this.dataGridView.TabIndex = 15; + // + // FormInsurances + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(963, 447); + 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 = "FormInsurances"; + this.Text = "Страховые"; + this.Load += new System.EventHandler(this.FormWorks_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; + } +} \ No newline at end of file diff --git a/SYBDView/FormInsurances.cs b/SYBDView/FormInsurances.cs new file mode 100644 index 0000000..097b78d --- /dev/null +++ b/SYBDView/FormInsurances.cs @@ -0,0 +1,104 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormInsurances : Form + { + public FormInsurances(ILogger logger, IInsuranceLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private readonly ILogger _logger; + + private readonly IInsuranceLogic _logic; + + + private void FormWorks_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка Работ"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormInsurance)); + if (service is FormInsurance 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(FormInsurance)); + if (service is FormInsurance 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 InsuranceBindingModel { 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(); + } + } +} \ No newline at end of file diff --git a/SYBDView/FormInsurances.resx b/SYBDView/FormInsurances.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormInsurances.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormMain.Designer.cs b/SYBDView/FormMain.Designer.cs new file mode 100644 index 0000000..a1bf1ec --- /dev/null +++ b/SYBDView/FormMain.Designer.cs @@ -0,0 +1,242 @@ +namespace SYBDView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.работникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.страховыеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCreateOrder.Location = new System.Drawing.Point(1081, 75); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(249, 45); + this.buttonCreateOrder.TabIndex = 7; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(2, 44); + this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(1055, 533); + this.dataGridView.TabIndex = 6; + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); + 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(1377, 33); + this.menuStrip1.TabIndex = 12; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.автомобилиToolStripMenuItem, + this.клиентыToolStripMenuItem, + this.работникиToolStripMenuItem, + this.страховыеToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // автомобилиToolStripMenuItem + // + this.автомобилиToolStripMenuItem.Name = "автомобилиToolStripMenuItem"; + this.автомобилиToolStripMenuItem.Size = new System.Drawing.Size(217, 34); + this.автомобилиToolStripMenuItem.Text = "Автомобили"; + this.автомобилиToolStripMenuItem.Click += new System.EventHandler(this.АвтомобилиToolStripMenuItem_Click); + // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(217, 34); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // работникиToolStripMenuItem + // + this.работникиToolStripMenuItem.Name = "работникиToolStripMenuItem"; + this.работникиToolStripMenuItem.Size = new System.Drawing.Size(217, 34); + this.работникиToolStripMenuItem.Text = "Работники"; + this.работникиToolStripMenuItem.Click += new System.EventHandler(this.РаботникиToolStripMenuItem_Click); + // + // страховыеToolStripMenuItem + // + this.страховыеToolStripMenuItem.Name = "страховыеToolStripMenuItem"; + this.страховыеToolStripMenuItem.Size = new System.Drawing.Size(217, 34); + this.страховыеToolStripMenuItem.Text = "Страховые"; + this.страховыеToolStripMenuItem.Click += new System.EventHandler(this.СтраховыеToolStripMenuItem_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(1081, 516); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(249, 44); + this.buttonRef.TabIndex = 17; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(1081, 437); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(249, 44); + this.buttonDel.TabIndex = 16; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(1081, 370); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(249, 44); + this.buttonUpd.TabIndex = 15; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonIssuedOrder.Location = new System.Drawing.Point(1081, 283); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(249, 45); + this.buttonIssuedOrder.TabIndex = 20; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOrderReady.Location = new System.Drawing.Point(1081, 211); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(249, 45); + this.buttonOrderReady.TabIndex = 19; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1081, 144); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(249, 45); + this.buttonTakeOrderInWork.TabIndex = 18; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1377, 602); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Ремонт труб"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button buttonCreateOrder; + private DataGridView dataGridView; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem автомобилиToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem работникиToolStripMenuItem; + private ToolStripMenuItem страховыеToolStripMenuItem; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonIssuedOrder; + private Button buttonOrderReady; + private Button buttonTakeOrderInWork; + } +} \ No newline at end of file diff --git a/SYBDView/FormMain.cs b/SYBDView/FormMain.cs new file mode 100644 index 0000000..1c47962 --- /dev/null +++ b/SYBDView/FormMain.cs @@ -0,0 +1,207 @@ +using Microsoft.Extensions.Logging; +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; + +namespace SYBDView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["WorkerId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["AutoId"].Visible = false; + dataGridView.Columns["InsuranceId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void АвтомобилиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAutos)); + if (service is FormAutos form) + { + form.ShowDialog(); + } + } + + private void РаботникиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorkers)); + if (service is FormWorkers form) + { + form.ShowDialog(); + } + } + private void СтраховыеToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormInsurances)); + if (service is FormInsurances form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder 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 (!_orderLogic.Delete(new OrderBindingModel { 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 клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + } +} \ No newline at end of file diff --git a/SYBDView/FormMain.resx b/SYBDView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/SYBDView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/SYBDView/FormWorker.Designer.cs b/SYBDView/FormWorker.Designer.cs new file mode 100644 index 0000000..c33c838 --- /dev/null +++ b/SYBDView/FormWorker.Designer.cs @@ -0,0 +1,149 @@ +namespace SYBDView +{ + partial class FormWorker + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.textBoxFullname = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.labelSalary = new System.Windows.Forms.Label(); + this.textBoxSalary = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(126, 64); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(358, 31); + this.textBoxAddress.TabIndex = 10; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(15, 69); + this.labelAddress.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(66, 25); + this.labelAddress.TabIndex = 9; + this.labelAddress.Text = "Адрес:"; + // + // textBoxFullname + // + this.textBoxFullname.Location = new System.Drawing.Point(126, 14); + this.textBoxFullname.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxFullname.Name = "textBoxFullname"; + this.textBoxFullname.Size = new System.Drawing.Size(358, 31); + this.textBoxFullname.TabIndex = 8; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(15, 19); + this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(56, 25); + this.labelName.TabIndex = 7; + this.labelName.Text = "ФИО:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(459, 219); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 13; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(330, 219); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 12; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // labelSalary + // + this.labelSalary.AutoSize = true; + this.labelSalary.Location = new System.Drawing.Point(15, 118); + this.labelSalary.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelSalary.Name = "labelSalary"; + this.labelSalary.Size = new System.Drawing.Size(90, 25); + this.labelSalary.TabIndex = 14; + this.labelSalary.Text = "Зарплата:"; + // + // textBoxSalary + // + this.textBoxSalary.Location = new System.Drawing.Point(126, 118); + this.textBoxSalary.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxSalary.Name = "textBoxSalary"; + this.textBoxSalary.Size = new System.Drawing.Size(227, 31); + this.textBoxSalary.TabIndex = 15; + // + // FormWorker + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(591, 267); + this.Controls.Add(this.textBoxSalary); + this.Controls.Add(this.labelSalary); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.textBoxFullname); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormWorker"; + this.Text = "Работник"; + this.Load += new System.EventHandler(this.FormWork_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxAddress; + private Label labelAddress; + private TextBox textBoxFullname; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + private Label labelSalary; + private TextBox textBoxSalary; + } +} \ No newline at end of file diff --git a/SYBDView/FormWorker.cs b/SYBDView/FormWorker.cs new file mode 100644 index 0000000..02e7f33 --- /dev/null +++ b/SYBDView/FormWorker.cs @@ -0,0 +1,95 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormWorker : Form + { + private readonly ILogger _logger; + + private readonly IWorkerLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + + public FormWorker(ILogger logger, IWorkerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormWork_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка работников"); + try + { + var view = _logic.ReadElement(new WorkerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFullname.Text = view.Fullname; + textBoxAddress.Text = view.Address; + textBoxSalary.Text = view.Salary.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работника"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFullname.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxSalary.Text)) + { + MessageBox.Show("Заполните зарплату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new WorkerBindingModel + { + Id = _id ?? 0, + Fullname = textBoxFullname.Text, + Address = textBoxAddress.Text, + Salary = Convert.ToInt32(textBoxSalary.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(); + } + } +} \ No newline at end of file diff --git a/SYBDView/FormWorker.resx b/SYBDView/FormWorker.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormWorker.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/FormWorkers.Designer.cs b/SYBDView/FormWorkers.Designer.cs new file mode 100644 index 0000000..7e6c8e8 --- /dev/null +++ b/SYBDView/FormWorkers.Designer.cs @@ -0,0 +1,127 @@ +namespace SYBDView +{ + partial class FormWorkers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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(804, 246); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + 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(804, 167); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + 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(804, 100); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + 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(804, 27); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + 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.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(767, 450); + this.dataGridView.TabIndex = 10; + // + // FormWorkers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(943, 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 = "FormWorkers"; + this.Text = "Работники"; + this.Load += new System.EventHandler(this.FormWorks_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; + } +} \ No newline at end of file diff --git a/SYBDView/FormWorkers.cs b/SYBDView/FormWorkers.cs new file mode 100644 index 0000000..bcfc61b --- /dev/null +++ b/SYBDView/FormWorkers.cs @@ -0,0 +1,104 @@ +using SYBDContracts.BindingModels; +using SYBDContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SYBDView +{ + public partial class FormWorkers : Form + { + private readonly ILogger _logger; + + private readonly IWorkerLogic _logic; + + public FormWorkers(ILogger logger, IWorkerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormWorks_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Fullname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка Работ"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorker)); + if (service is FormWorker 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(FormWorker)); + if (service is FormWorker 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 WorkerBindingModel { 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(); + } + } +} \ No newline at end of file diff --git a/SYBDView/FormWorkers.resx b/SYBDView/FormWorkers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SYBDView/FormWorkers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SYBDView/Program.cs b/SYBDView/Program.cs new file mode 100644 index 0000000..e773065 --- /dev/null +++ b/SYBDView/Program.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using SYBDBusinessLogic.BusinessLogics; +using SYBDContracts.BusinessLogicsContracts; +using SYBDContracts.StoragesContracts; +using SYBDDatabaseImplement.Implements; + +namespace SYBDView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/SYBDView/SYBDView.csproj b/SYBDView/SYBDView.csproj new file mode 100644 index 0000000..50d7ffb --- /dev/null +++ b/SYBDView/SYBDView.csproj @@ -0,0 +1,24 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + \ No newline at end of file diff --git a/SYBDView/nlog.config b/SYBDView/nlog.config new file mode 100644 index 0000000..76ffd67 --- /dev/null +++ b/SYBDView/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file