From 34a190211b2f3cd619539eb227886f279cd414c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 5 Mar 2024 22:24:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BB=D0=BE=D0=B9=20=D1=85=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B2=20=D0=B1=D0=B0=D0=B7=D0=B5=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20+=20=D1=81=D0=BB=D0=BE=D0=B9=20=D1=81=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TransportCompany/TransportCompany.sln | 14 +- .../BusinessLogics/TransportationLogic.cs | 7 + .../ViewModels/TransportationViewModel.cs | 12 +- .../Implements/CargoStorage.cs | 79 ++++++ .../Implements/DriverStorage.cs | 79 ++++++ .../Implements/PointStorage.cs | 79 ++++++ .../Implements/TransportStorage.cs | 79 ++++++ .../Implements/TransportationStorage.cs | 100 ++++++++ .../20240305163445_InitialCreate.Designer.cs | 231 ++++++++++++++++++ .../20240305163445_InitialCreate.cs | 167 +++++++++++++ .../TransportCompanyDatabaseModelSnapshot.cs | 228 +++++++++++++++++ .../Models/Cargo.cs | 61 +++++ .../Models/Driver.cs | 61 +++++ .../Models/Point.cs | 65 +++++ .../Models/Transport.cs | 67 +++++ .../Models/Transportation.cs | 95 +++++++ .../TransportCompanyDatabase.cs | 38 +++ .../TransportCompanyDatabaseImplement.csproj | 23 ++ .../Implements/CargoStorage.cs | 40 +-- .../Implements/DriverStorage.cs | 40 +-- .../Implements/PointStorage.cs | 40 +-- .../Implements/TransportStorage.cs | 40 +-- .../Implements/TransportationStorage.cs | 38 +-- .../FormCargo.Designer.cs | 124 ++++++++++ .../TransportCompanyView/FormCargo.cs | 90 +++++++ .../TransportCompanyView/FormCargo.resx | 120 +++++++++ .../FormCargos.Designer.cs | 137 +++++++++++ .../TransportCompanyView/FormCargos.cs | 105 ++++++++ .../TransportCompanyView/FormCargos.resx | 120 +++++++++ .../FormCreateTransportation.Designer.cs | 211 ++++++++++++++++ .../FormCreateTransportation.cs | 157 ++++++++++++ .../FormCreateTransportation.resx | 120 +++++++++ .../FormDriver.Designer.cs | 118 +++++++++ .../TransportCompanyView/FormDriver.cs | 99 ++++++++ .../TransportCompanyView/FormDriver.resx | 120 +++++++++ .../FormDrivers.Designer.cs | 137 +++++++++++ .../TransportCompanyView/FormDrivers.cs | 116 +++++++++ .../TransportCompanyView/FormDrivers.resx | 120 +++++++++ .../TransportCompanyView/FormMain.Designer.cs | 194 +++++++++++++++ .../TransportCompanyView/FormMain.cs | 183 ++++++++++++++ .../TransportCompanyView/FormMain.resx | 123 ++++++++++ .../FormPoint.Designer.cs | 118 +++++++++ .../TransportCompanyView/FormPoint.cs | 99 ++++++++ .../TransportCompanyView/FormPoint.resx | 120 +++++++++ .../FormPoints.Designer.cs | 137 +++++++++++ .../TransportCompanyView/FormPoints.cs | 116 +++++++++ .../TransportCompanyView/FormPoints.resx | 120 +++++++++ .../FormTransport.Designer.cs | 140 +++++++++++ .../TransportCompanyView/FormTransport.cs | 106 ++++++++ .../TransportCompanyView/FormTransport.resx | 120 +++++++++ .../FormTransports.Designer.cs | 137 +++++++++++ .../TransportCompanyView/FormTransports.cs | 117 +++++++++ .../TransportCompanyView/FormTransports.resx | 120 +++++++++ .../TransportCompanyView/Program.cs | 47 +++- .../TransportCompanyView.csproj | 28 +++ .../TransportCompanyView/nlog.config | 15 ++ 56 files changed, 5507 insertions(+), 110 deletions(-) create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Implements/CargoStorage.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Implements/DriverStorage.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Implements/PointStorage.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportStorage.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportationStorage.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.Designer.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Migrations/TransportCompanyDatabaseModelSnapshot.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Models/Cargo.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Models/Driver.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Models/Point.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Models/Transport.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/Models/Transportation.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabase.cs create mode 100644 TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabaseImplement.csproj create mode 100644 TransportCompany/TransportCompanyView/FormCargo.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormCargo.cs create mode 100644 TransportCompany/TransportCompanyView/FormCargo.resx create mode 100644 TransportCompany/TransportCompanyView/FormCargos.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormCargos.cs create mode 100644 TransportCompany/TransportCompanyView/FormCargos.resx create mode 100644 TransportCompany/TransportCompanyView/FormCreateTransportation.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormCreateTransportation.cs create mode 100644 TransportCompany/TransportCompanyView/FormCreateTransportation.resx create mode 100644 TransportCompany/TransportCompanyView/FormDriver.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormDriver.cs create mode 100644 TransportCompany/TransportCompanyView/FormDriver.resx create mode 100644 TransportCompany/TransportCompanyView/FormDrivers.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormDrivers.cs create mode 100644 TransportCompany/TransportCompanyView/FormDrivers.resx create mode 100644 TransportCompany/TransportCompanyView/FormMain.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormMain.cs create mode 100644 TransportCompany/TransportCompanyView/FormMain.resx create mode 100644 TransportCompany/TransportCompanyView/FormPoint.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormPoint.cs create mode 100644 TransportCompany/TransportCompanyView/FormPoint.resx create mode 100644 TransportCompany/TransportCompanyView/FormPoints.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormPoints.cs create mode 100644 TransportCompany/TransportCompanyView/FormPoints.resx create mode 100644 TransportCompany/TransportCompanyView/FormTransport.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormTransport.cs create mode 100644 TransportCompany/TransportCompanyView/FormTransport.resx create mode 100644 TransportCompany/TransportCompanyView/FormTransports.Designer.cs create mode 100644 TransportCompany/TransportCompanyView/FormTransports.cs create mode 100644 TransportCompany/TransportCompanyView/FormTransports.resx create mode 100644 TransportCompany/TransportCompanyView/nlog.config diff --git a/TransportCompany/TransportCompany.sln b/TransportCompany/TransportCompany.sln index 7eeab62..dde6447 100644 --- a/TransportCompany/TransportCompany.sln +++ b/TransportCompany/TransportCompany.sln @@ -5,13 +5,15 @@ VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyView", "TransportCompanyView\TransportCompanyView.csproj", "{6DBE2D7A-A9FD-4FBC-BD54-28FDBB359F7A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyDataModels", "TransportCompanyDataModels\TransportCompanyDataModels.csproj", "{49B3AF87-E6E5-4B8C-B2B6-EC3BD9509DA2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyDataModels", "TransportCompanyDataModels\TransportCompanyDataModels.csproj", "{49B3AF87-E6E5-4B8C-B2B6-EC3BD9509DA2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyContracts", "TransportCompanyContracts\TransportCompanyContracts.csproj", "{842017C2-FA27-4317-8C12-5CF64C85F2E0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyContracts", "TransportCompanyContracts\TransportCompanyContracts.csproj", "{842017C2-FA27-4317-8C12-5CF64C85F2E0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyBusinessLogic", "TransportCompanyBusinessLogic\TransportCompanyBusinessLogic.csproj", "{49A4EC0D-8412-42E4-B4C1-3B5FDDEF0D70}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyBusinessLogic", "TransportCompanyBusinessLogic\TransportCompanyBusinessLogic.csproj", "{49A4EC0D-8412-42E4-B4C1-3B5FDDEF0D70}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyListImplement", "TransportCompanyListImplement\TransportCompanyListImplement.csproj", "{0772D7CB-D2B3-4DCD-8135-734AB2F00A04}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyListImplement", "TransportCompanyListImplement\TransportCompanyListImplement.csproj", "{0772D7CB-D2B3-4DCD-8135-734AB2F00A04}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyDatabaseImplement", "TransportCompanyDatabaseImplement\TransportCompanyDatabaseImplement.csproj", "{E88D7676-7B0F-4D65-8C8F-C8EA376EA7B1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {0772D7CB-D2B3-4DCD-8135-734AB2F00A04}.Debug|Any CPU.Build.0 = Debug|Any CPU {0772D7CB-D2B3-4DCD-8135-734AB2F00A04}.Release|Any CPU.ActiveCfg = Release|Any CPU {0772D7CB-D2B3-4DCD-8135-734AB2F00A04}.Release|Any CPU.Build.0 = Release|Any CPU + {E88D7676-7B0F-4D65-8C8F-C8EA376EA7B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E88D7676-7B0F-4D65-8C8F-C8EA376EA7B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E88D7676-7B0F-4D65-8C8F-C8EA376EA7B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E88D7676-7B0F-4D65-8C8F-C8EA376EA7B1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs index eda237b..456a0b0 100644 --- a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs @@ -95,6 +95,13 @@ namespace TransportCompanyBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(element)); } + model.DriverId = element.DriverId; + model.CargoId = element.CargoId; + model.TransportId = element.TransportId; + model.PointToId = element.PointToId; + model.PointFromId = element.PointFromId; + model.Count = element.Count; + model.ArrivalDate = element.ArrivalDate; model.Status = element.Status; if (requiredStatus - model.Status == 1) { diff --git a/TransportCompany/TransportCompanyContracts/ViewModels/TransportationViewModel.cs b/TransportCompany/TransportCompanyContracts/ViewModels/TransportationViewModel.cs index 460ec82..409e339 100644 --- a/TransportCompany/TransportCompanyContracts/ViewModels/TransportationViewModel.cs +++ b/TransportCompany/TransportCompanyContracts/ViewModels/TransportationViewModel.cs @@ -27,16 +27,16 @@ namespace TransportCompanyContracts.ViewModels [DisplayName("Количество")] public int Count { get; set; } - public int PointToId { get; set; } - - [DisplayName("Откуда")] - public string PointNameTo { get; set; } = string.Empty; - public int PointFromId { get; set; } - [DisplayName("Куда")] + [DisplayName("Откуда")] public string PointNameFrom { get; set; } = string.Empty; + public int PointToId { get; set; } + + [DisplayName("Куда")] + public string PointNameTo { get; set; } = string.Empty; + [DisplayName("Статус")] public TransportationStatus Status { get; set; } = TransportationStatus.Неизвестен; diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Implements/CargoStorage.cs b/TransportCompany/TransportCompanyDatabaseImplement/Implements/CargoStorage.cs new file mode 100644 index 0000000..917e7fe --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Implements/CargoStorage.cs @@ -0,0 +1,79 @@ +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplement.Models; + +namespace TransportCompanyDatabaseImplement.Implements +{ + public class CargoStorage : ICargoStorage + { + public List GetFullList() + { + using var context = new TransportCompanyDatabase(); + return context.Cargos.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(CargoSearchModel model) + { + if (string.IsNullOrEmpty(model.CargoName)) + { + return new(); + } + using var context = new TransportCompanyDatabase(); + return context.Cargos.Where(x => x.CargoName.Contains(model.CargoName)).Select(x => x.GetViewModel).ToList(); + } + + public CargoViewModel? GetElement(CargoSearchModel model) + { + if (string.IsNullOrEmpty(model.CargoName) && !model.Id.HasValue) + { + return null; + } + using var context = new TransportCompanyDatabase(); + return context.Cargos.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.CargoName) && x.CargoName == model.CargoName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public CargoViewModel? Insert(CargoBindingModel model) + { + var newComponent = Cargo.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new TransportCompanyDatabase(); + context.Cargos.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public CargoViewModel? Update(CargoBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var component = context.Cargos.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public CargoViewModel? Delete(CargoBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var element = context.Cargos.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Cargos.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Implements/DriverStorage.cs b/TransportCompany/TransportCompanyDatabaseImplement/Implements/DriverStorage.cs new file mode 100644 index 0000000..4f135df --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Implements/DriverStorage.cs @@ -0,0 +1,79 @@ +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplement.Models; + +namespace TransportCompanyDatabaseImplement.Implements +{ + public class DriverStorage : IDriverStorage + { + public List GetFullList() + { + using var context = new TransportCompanyDatabase(); + return context.Drivers.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(DriverSearchModel model) + { + if (string.IsNullOrEmpty(model.DriverFio)) + { + return new(); + } + using var context = new TransportCompanyDatabase(); + return context.Drivers.Where(x => x.DriverFio.Contains(model.DriverFio)).Select(x => x.GetViewModel).ToList(); + } + + public DriverViewModel? GetElement(DriverSearchModel model) + { + if (string.IsNullOrEmpty(model.DriverFio) && !model.Id.HasValue) + { + return null; + } + using var context = new TransportCompanyDatabase(); + return context.Drivers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.DriverFio) && x.DriverFio == model.DriverFio) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public DriverViewModel? Insert(DriverBindingModel model) + { + var newComponent = Driver.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new TransportCompanyDatabase(); + context.Drivers.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public DriverViewModel? Update(DriverBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var component = context.Drivers.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public DriverViewModel? Delete(DriverBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var element = context.Drivers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Drivers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Implements/PointStorage.cs b/TransportCompany/TransportCompanyDatabaseImplement/Implements/PointStorage.cs new file mode 100644 index 0000000..e5691f5 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Implements/PointStorage.cs @@ -0,0 +1,79 @@ +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplement.Models; + +namespace TransportCompanyDatabaseImplement.Implements +{ + public class PointStorage : IPointStorage + { + public List GetFullList() + { + using var context = new TransportCompanyDatabase(); + return context.Points.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(PointSearchModel model) + { + if (string.IsNullOrEmpty(model.PointName)) + { + return new(); + } + using var context = new TransportCompanyDatabase(); + return context.Points.Where(x => x.PointName.Contains(model.PointName)).Select(x => x.GetViewModel).ToList(); + } + + public PointViewModel? GetElement(PointSearchModel model) + { + if (string.IsNullOrEmpty(model.PointName) && !model.Id.HasValue) + { + return null; + } + using var context = new TransportCompanyDatabase(); + return context.Points.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.PointName) && x.PointName == model.PointName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public PointViewModel? Insert(PointBindingModel model) + { + var newComponent = Point.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new TransportCompanyDatabase(); + context.Points.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public PointViewModel? Update(PointBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var component = context.Points.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public PointViewModel? Delete(PointBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var element = context.Points.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Points.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportStorage.cs b/TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportStorage.cs new file mode 100644 index 0000000..3a56d58 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportStorage.cs @@ -0,0 +1,79 @@ +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplement.Models; + +namespace TransportCompanyDatabaseImplement.Implements +{ + public class TransportStorage : ITransportStorage + { + public List GetFullList() + { + using var context = new TransportCompanyDatabase(); + return context.Transports.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(TransportSearchModel model) + { + if (string.IsNullOrEmpty(model.Model)) + { + return new(); + } + using var context = new TransportCompanyDatabase(); + return context.Transports.Where(x => x.Model.Contains(model.Model)).Select(x => x.GetViewModel).ToList(); + } + + public TransportViewModel? GetElement(TransportSearchModel model) + { + if (string.IsNullOrEmpty(model.Model) && !model.Id.HasValue) + { + return null; + } + using var context = new TransportCompanyDatabase(); + return context.Transports.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Model) && x.Model == model.Model) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public TransportViewModel? Insert(TransportBindingModel model) + { + var newComponent = Transport.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new TransportCompanyDatabase(); + context.Transports.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public TransportViewModel? Update(TransportBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var component = context.Transports.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public TransportViewModel? Delete(TransportBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var element = context.Transports.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Transports.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportationStorage.cs b/TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportationStorage.cs new file mode 100644 index 0000000..2f54ebd --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Implements/TransportationStorage.cs @@ -0,0 +1,100 @@ +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace TransportCompanyDatabaseImplement.Implements +{ + public class TransportationStorage : ITransportationStorage + { + public List GetFullList() + { + using var context = new TransportCompanyDatabase(); + return context.Transportations + .Include(x => x.Cargo) + .Include(x => x.Driver) + .Include(x => x.PointFrom) + .Include(x => x.PointTo) + .Include(x => x.Transport) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(TransportationSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new TransportCompanyDatabase(); + return context.Transportations + .Include(x => x.Cargo) + .Include(x => x.Driver) + .Include(x => x.PointFrom) + .Include(x => x.PointTo) + .Include(x => x.Transport) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public TransportationViewModel? GetElement(TransportationSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new TransportCompanyDatabase(); + return context.Transportations + .Include(x => x.Cargo) + .Include(x => x.Driver) + .Include(x => x.PointFrom) + .Include(x => x.PointTo) + .Include(x => x.Transport) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public TransportationViewModel? Insert(TransportationBindingModel model) + { + using var context = new TransportCompanyDatabase(); + if (model == null) + return null; + var newOrder = Transportation.Create(context, model); + if (newOrder == null) + { + return null; + } + context.Transportations.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; + } + + public TransportationViewModel? Update(TransportationBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var order = context.Transportations.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return order.GetViewModel; + } + + public TransportationViewModel? Delete(TransportationBindingModel model) + { + using var context = new TransportCompanyDatabase(); + var order = context.Transportations.FirstOrDefault(rec => rec.Id == model.Id); + if (order != null) + { + context.Transportations.Remove(order); + context.SaveChanges(); + return order.GetViewModel; + } + return null; + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.Designer.cs b/TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.Designer.cs new file mode 100644 index 0000000..a4141f7 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.Designer.cs @@ -0,0 +1,231 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TransportCompanyDatabaseImplement; + +#nullable disable + +namespace TransportCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(TransportCompanyDatabase))] + [Migration("20240305163445_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Cargo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CargoName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Weight") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Cargos"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Driver", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DriverFio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Drivers"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Point", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PointName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Points"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("LoadCapacity") + .HasColumnType("int"); + + b.Property("Model") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StateNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Transports"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transportation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ArrivalDate") + .HasColumnType("datetime2"); + + b.Property("CargoId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DepartureDate") + .HasColumnType("datetime2"); + + b.Property("DriverId") + .HasColumnType("int"); + + b.Property("PointFromId") + .HasColumnType("int"); + + b.Property("PointToId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("TransportId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CargoId"); + + b.HasIndex("DriverId"); + + b.HasIndex("PointFromId"); + + b.HasIndex("PointToId"); + + b.HasIndex("TransportId"); + + b.ToTable("Transportations"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transportation", b => + { + b.HasOne("TransportCompanyDatabaseImplement.Models.Cargo", "Cargo") + .WithMany("Transportations") + .HasForeignKey("CargoId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Driver", "Driver") + .WithMany("Transportations") + .HasForeignKey("DriverId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Point", "PointFrom") + .WithMany("TransportationsFrom") + .HasForeignKey("PointFromId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Point", "PointTo") + .WithMany("TransportationsTo") + .HasForeignKey("PointToId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Transport", "Transport") + .WithMany("Transportations") + .HasForeignKey("TransportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Cargo"); + + b.Navigation("Driver"); + + b.Navigation("PointFrom"); + + b.Navigation("PointTo"); + + b.Navigation("Transport"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Cargo", b => + { + b.Navigation("Transportations"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Driver", b => + { + b.Navigation("Transportations"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Point", b => + { + b.Navigation("TransportationsFrom"); + + b.Navigation("TransportationsTo"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transport", b => + { + b.Navigation("Transportations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.cs b/TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.cs new file mode 100644 index 0000000..23fb468 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Migrations/20240305163445_InitialCreate.cs @@ -0,0 +1,167 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace TransportCompanyDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Cargos", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CargoName = table.Column(type: "nvarchar(max)", nullable: false), + Weight = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cargos", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Drivers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DriverFio = table.Column(type: "nvarchar(max)", nullable: false), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Drivers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Points", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PointName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Points", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Transports", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Model = table.Column(type: "nvarchar(max)", nullable: false), + LoadCapacity = table.Column(type: "int", nullable: false), + StateNumber = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Transports", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Transportations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DriverId = table.Column(type: "int", nullable: false), + TransportId = table.Column(type: "int", nullable: false), + CargoId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + PointToId = table.Column(type: "int", nullable: false), + PointFromId = table.Column(type: "int", nullable: false), + Status = table.Column(type: "int", nullable: false), + DepartureDate = table.Column(type: "datetime2", nullable: false), + ArrivalDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Transportations", x => x.Id); + table.ForeignKey( + name: "FK_Transportations_Cargos_CargoId", + column: x => x.CargoId, + principalTable: "Cargos", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Transportations_Drivers_DriverId", + column: x => x.DriverId, + principalTable: "Drivers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Transportations_Points_PointFromId", + column: x => x.PointFromId, + principalTable: "Points", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Transportations_Points_PointToId", + column: x => x.PointToId, + principalTable: "Points", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Transportations_Transports_TransportId", + column: x => x.TransportId, + principalTable: "Transports", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Transportations_CargoId", + table: "Transportations", + column: "CargoId"); + + migrationBuilder.CreateIndex( + name: "IX_Transportations_DriverId", + table: "Transportations", + column: "DriverId"); + + migrationBuilder.CreateIndex( + name: "IX_Transportations_PointFromId", + table: "Transportations", + column: "PointFromId"); + + migrationBuilder.CreateIndex( + name: "IX_Transportations_PointToId", + table: "Transportations", + column: "PointToId"); + + migrationBuilder.CreateIndex( + name: "IX_Transportations_TransportId", + table: "Transportations", + column: "TransportId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Transportations"); + + migrationBuilder.DropTable( + name: "Cargos"); + + migrationBuilder.DropTable( + name: "Drivers"); + + migrationBuilder.DropTable( + name: "Points"); + + migrationBuilder.DropTable( + name: "Transports"); + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Migrations/TransportCompanyDatabaseModelSnapshot.cs b/TransportCompany/TransportCompanyDatabaseImplement/Migrations/TransportCompanyDatabaseModelSnapshot.cs new file mode 100644 index 0000000..052fccb --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Migrations/TransportCompanyDatabaseModelSnapshot.cs @@ -0,0 +1,228 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TransportCompanyDatabaseImplement; + +#nullable disable + +namespace TransportCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(TransportCompanyDatabase))] + partial class TransportCompanyDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Cargo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CargoName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Weight") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Cargos"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Driver", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DriverFio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Drivers"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Point", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PointName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Points"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("LoadCapacity") + .HasColumnType("int"); + + b.Property("Model") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StateNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Transports"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transportation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ArrivalDate") + .HasColumnType("datetime2"); + + b.Property("CargoId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DepartureDate") + .HasColumnType("datetime2"); + + b.Property("DriverId") + .HasColumnType("int"); + + b.Property("PointFromId") + .HasColumnType("int"); + + b.Property("PointToId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("TransportId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CargoId"); + + b.HasIndex("DriverId"); + + b.HasIndex("PointFromId"); + + b.HasIndex("PointToId"); + + b.HasIndex("TransportId"); + + b.ToTable("Transportations"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transportation", b => + { + b.HasOne("TransportCompanyDatabaseImplement.Models.Cargo", "Cargo") + .WithMany("Transportations") + .HasForeignKey("CargoId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Driver", "Driver") + .WithMany("Transportations") + .HasForeignKey("DriverId") + .OnDelete(DeleteBehavior.ClientSetNull) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Point", "PointFrom") + .WithMany("TransportationsFrom") + .HasForeignKey("PointFromId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Point", "PointTo") + .WithMany("TransportationsTo") + .HasForeignKey("PointToId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("TransportCompanyDatabaseImplement.Models.Transport", "Transport") + .WithMany("Transportations") + .HasForeignKey("TransportId") + .OnDelete(DeleteBehavior.ClientSetNull) + .IsRequired(); + + b.Navigation("Cargo"); + + b.Navigation("Driver"); + + b.Navigation("PointFrom"); + + b.Navigation("PointTo"); + + b.Navigation("Transport"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Cargo", b => + { + b.Navigation("Transportations"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Driver", b => + { + b.Navigation("Transportations"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Point", b => + { + b.Navigation("TransportationsFrom"); + + b.Navigation("TransportationsTo"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplement.Models.Transport", b => + { + b.Navigation("Transportations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Models/Cargo.cs b/TransportCompany/TransportCompanyDatabaseImplement/Models/Cargo.cs new file mode 100644 index 0000000..a4609a1 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Models/Cargo.cs @@ -0,0 +1,61 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDataModels.Models; + +namespace TransportCompanyDatabaseImplement.Models +{ + public class Cargo : ICargoModel + { + public int Id { get; private set; } + [Required] + public string CargoName { get; private set; } = string.Empty; + [Required] + public int Weight { get; private set; } + + [ForeignKey("CargoId")] + public virtual List Transportations { get; set; } = new(); + + public static Cargo? Create(CargoBindingModel model) + { + if (model == null) + { + return null; + } + return new Cargo() + { + Id = model.Id, + CargoName = model.CargoName, + Weight = model.Weight + }; + } + + public static Cargo Create(CargoViewModel model) + { + return new Cargo + { + Id = model.Id, + CargoName = model.CargoName, + Weight = model.Weight + }; + } + + public void Update(CargoBindingModel model) + { + if (model == null) + { + return; + } + CargoName = model.CargoName; + Weight = model.Weight; + } + + public CargoViewModel GetViewModel => new() + { + Id = Id, + CargoName = CargoName, + Weight = Weight + }; + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Models/Driver.cs b/TransportCompany/TransportCompanyDatabaseImplement/Models/Driver.cs new file mode 100644 index 0000000..cc1618b --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Models/Driver.cs @@ -0,0 +1,61 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDataModels.Models; + +namespace TransportCompanyDatabaseImplement.Models +{ + public class Driver : IDriverModel + { + public int Id { get; private set; } + [Required] + public string DriverFio { get; private set; } = string.Empty; + [Required] + public string PhoneNumber { get; private set; } = string.Empty; + + [ForeignKey("DriverId")] + public virtual List Transportations { get; set; } = new(); + + public static Driver? Create(DriverBindingModel model) + { + if (model == null) + { + return null; + } + return new Driver() + { + Id = model.Id, + DriverFio = model.DriverFio, + PhoneNumber = model.PhoneNumber + }; + } + + public static Driver Create(DriverViewModel model) + { + return new Driver + { + Id = model.Id, + DriverFio = model.DriverFio, + PhoneNumber = model.PhoneNumber + }; + } + + public void Update(DriverBindingModel model) + { + if (model == null) + { + return; + } + DriverFio = model.DriverFio; + PhoneNumber = model.PhoneNumber; + } + + public DriverViewModel GetViewModel => new() + { + Id = Id, + DriverFio = DriverFio, + PhoneNumber = PhoneNumber + }; + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Models/Point.cs b/TransportCompany/TransportCompanyDatabaseImplement/Models/Point.cs new file mode 100644 index 0000000..ee1e10a --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Models/Point.cs @@ -0,0 +1,65 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDataModels.Models; + +namespace TransportCompanyDatabaseImplement.Models +{ + public class Point : IPointModel + { + public int Id { get; private set; } + [Required] + public string PointName { get; private set; } = string.Empty; + [Required] + public string Address { get; private set; } = string.Empty; + + [ForeignKey("PointToId")] + public virtual List TransportationsTo { get; set; } = new(); + + [ForeignKey("PointFromId")] + public virtual List TransportationsFrom { get; set; } = new(); + + + public static Point? Create(PointBindingModel model) + { + if (model == null) + { + return null; + } + return new Point() + { + Id = model.Id, + PointName = model.PointName, + Address = model.Address + }; + } + + public static Point Create(PointViewModel model) + { + return new Point + { + Id = model.Id, + PointName = model.PointName, + Address = model.Address + }; + } + + public void Update(PointBindingModel model) + { + if (model == null) + { + return; + } + PointName = model.PointName; + Address = model.Address; + } + + public PointViewModel GetViewModel => new() + { + Id = Id, + PointName = PointName, + Address = Address + }; + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Models/Transport.cs b/TransportCompany/TransportCompanyDatabaseImplement/Models/Transport.cs new file mode 100644 index 0000000..b98b980 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Models/Transport.cs @@ -0,0 +1,67 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDataModels.Models; + +namespace TransportCompanyDatabaseImplement.Models +{ + public class Transport : ITransportModel + { + public int Id { get; private set; } + [Required] + public string Model { get; private set; } = string.Empty; + [Required] + public int LoadCapacity { get; private set; } + [Required] + public string StateNumber { get; private set; } = string.Empty; + + [ForeignKey("TransportId")] + public virtual List Transportations { get; set; } = new(); + + public static Transport? Create(TransportBindingModel model) + { + if (model == null) + { + return null; + } + return new Transport() + { + Id = model.Id, + Model = model.Model, + LoadCapacity = model.LoadCapacity, + StateNumber = model.StateNumber + }; + } + + public static Transport Create(TransportViewModel model) + { + return new Transport() + { + Id = model.Id, + Model = model.Model, + LoadCapacity = model.LoadCapacity, + StateNumber = model.StateNumber + }; + } + + public void Update(TransportBindingModel model) + { + if (model == null) + { + return; + } + Model = model.Model; + LoadCapacity = model.LoadCapacity; + StateNumber = model.StateNumber; + } + + public TransportViewModel GetViewModel => new() + { + Id = Id, + Model = Model, + LoadCapacity = LoadCapacity, + StateNumber = StateNumber + }; + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/Models/Transportation.cs b/TransportCompany/TransportCompanyDatabaseImplement/Models/Transportation.cs new file mode 100644 index 0000000..79de49b --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/Models/Transportation.cs @@ -0,0 +1,95 @@ +using System.ComponentModel.DataAnnotations; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDataModels.Enums; +using TransportCompanyDataModels.Models; + +namespace TransportCompanyDatabaseImplement.Models +{ + public class Transportation : ITransportationModel + { + public int Id { get; private set; } + + [Required] + public int DriverId { get; private set; } + public virtual Driver Driver { get; set; } = new(); + + [Required] + public int TransportId { get; private set; } + public virtual Transport Transport { get; set; } = new(); + + [Required] + public int CargoId { get; private set; } + public virtual Cargo Cargo { get; set; } = new(); + + [Required] + public int Count { get; private set; } + + [Required] + public int PointToId { get; private set; } + public virtual Point PointTo { get; set; } = new(); + + [Required] + public int PointFromId { get; private set; } + public virtual Point PointFrom { get; set; } = new(); + + [Required] + public TransportationStatus Status { get; private set; } = TransportationStatus.Неизвестен; + + [Required] + public DateTime DepartureDate { get; private set; } = DateTime.Now; + + public DateTime? ArrivalDate { get; private set; } + + public static Transportation? Create(TransportCompanyDatabase context, TransportationBindingModel model) + { + return new Transportation() + { + Id = model.Id, + DriverId = model.DriverId, + Driver = context.Drivers.First(x => x.Id == model.DriverId), + TransportId = model.TransportId, + Transport = context.Transports.First(x => x.Id == model.TransportId), + CargoId = model.CargoId, + Cargo = context.Cargos.First(x => x.Id == model.CargoId), + Count = model.Count, + PointToId = model.PointToId, + PointTo = context.Points.First(x => x.Id == model.PointToId), + PointFromId = model.PointFromId, + PointFrom = context.Points.First(x => x.Id == model.PointFromId), + Status = model.Status, + DepartureDate = model.DepartureDate, + ArrivalDate = model.ArrivalDate, + }; + } + + public void Update(TransportationBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + ArrivalDate = model.ArrivalDate; + } + + public TransportationViewModel GetViewModel => new() + { + Id = Id, + DriverId = DriverId, + DriverFio = Driver.DriverFio, + TransportId = TransportId, + Model = Transport.Model, + CargoId = CargoId, + CargoName = Cargo.CargoName, + Count = Count, + PointToId = PointToId, + PointNameTo = PointTo.PointName, + PointFromId = PointFromId, + PointNameFrom = PointFrom.PointName, + Status = Status, + DepartureDate = DepartureDate, + ArrivalDate = ArrivalDate, + }; + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabase.cs b/TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabase.cs new file mode 100644 index 0000000..65144f4 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabase.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using TransportCompanyDatabaseImplement.Models; + +namespace TransportCompanyDatabaseImplement +{ + public class TransportCompanyDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-M2G96S06\SQLEXPRESS;Initial Catalog=TransportCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Cargos { set; get; } + public virtual DbSet Drivers { set; get; } + public virtual DbSet Points { set; get; } + public virtual DbSet Transports { set; get; } + public virtual DbSet Transportations { set; get; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasOne(t => t.PointTo) + .WithMany(p => p.TransportationsTo) + .HasForeignKey(t => t.PointToId) + .OnDelete(DeleteBehavior.Restrict); + + modelBuilder.Entity() + .HasOne(t => t.PointFrom) + .WithMany(p => p.TransportationsFrom) + .HasForeignKey(t => t.PointFromId) + .OnDelete(DeleteBehavior.Restrict); + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabaseImplement.csproj b/TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabaseImplement.csproj new file mode 100644 index 0000000..20a0cd4 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplement/TransportCompanyDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs index f882d0b..b046f5d 100644 --- a/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs +++ b/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs @@ -18,9 +18,9 @@ namespace TransportCompanyListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var component in _source.Cargos) + foreach (var cargo in _source.Cargos) { - result.Add(component.GetViewModel); + result.Add(cargo.GetViewModel); } return result; } @@ -32,11 +32,11 @@ namespace TransportCompanyListImplement.Implements { return result; } - foreach (var component in _source.Cargos) + foreach (var cargo in _source.Cargos) { - if (component.CargoName.Contains(model.CargoName)) + if (cargo.CargoName.Contains(model.CargoName)) { - result.Add(component.GetViewModel); + result.Add(cargo.GetViewModel); } } return result; @@ -48,12 +48,12 @@ namespace TransportCompanyListImplement.Implements { return null; } - foreach (var component in _source.Cargos) + foreach (var cargo in _source.Cargos) { - if ((!string.IsNullOrEmpty(model.CargoName) && component.CargoName == model.CargoName) || - (model.Id.HasValue && component.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.CargoName) && cargo.CargoName == model.CargoName) || + (model.Id.HasValue && cargo.Id == model.Id)) { - return component.GetViewModel; + return cargo.GetViewModel; } } return null; @@ -62,30 +62,30 @@ namespace TransportCompanyListImplement.Implements public CargoViewModel? Insert(CargoBindingModel model) { model.Id = 1; - foreach (var component in _source.Cargos) + foreach (var cargo in _source.Cargos) { - if (model.Id <= component.Id) + if (model.Id <= cargo.Id) { - model.Id = component.Id + 1; + model.Id = cargo.Id + 1; } } - var newComponent = Cargo.Create(model); - if (newComponent == null) + var newCargo = Cargo.Create(model); + if (newCargo == null) { return null; } - _source.Cargos.Add(newComponent); - return newComponent.GetViewModel; + _source.Cargos.Add(newCargo); + return newCargo.GetViewModel; } public CargoViewModel? Update(CargoBindingModel model) { - foreach (var component in _source.Cargos) + foreach (var cargo in _source.Cargos) { - if (component.Id == model.Id) + if (cargo.Id == model.Id) { - component.Update(model); - return component.GetViewModel; + cargo.Update(model); + return cargo.GetViewModel; } } return null; diff --git a/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs index 3a4fe68..9e1e925 100644 --- a/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs +++ b/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs @@ -18,9 +18,9 @@ namespace TransportCompanyListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var pizzas in _source.Drivers) + foreach (var driver in _source.Drivers) { - result.Add(pizzas.GetViewModel); + result.Add(driver.GetViewModel); } return result; } @@ -32,11 +32,11 @@ namespace TransportCompanyListImplement.Implements { return result; } - foreach (var pizzas in _source.Drivers) + foreach (var driver in _source.Drivers) { - if (pizzas.DriverFio.Contains(model.DriverFio)) + if (driver.DriverFio.Contains(model.DriverFio)) { - result.Add(pizzas.GetViewModel); + result.Add(driver.GetViewModel); } } return result; @@ -48,12 +48,12 @@ namespace TransportCompanyListImplement.Implements { return null; } - foreach (var pizzas in _source.Drivers) + foreach (var driver in _source.Drivers) { - if ((!string.IsNullOrEmpty(model.DriverFio) && pizzas.DriverFio == model.DriverFio) || - (model.Id.HasValue && pizzas.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.DriverFio) && driver.DriverFio == model.DriverFio) || + (model.Id.HasValue && driver.Id == model.Id)) { - return pizzas.GetViewModel; + return driver.GetViewModel; } } return null; @@ -62,30 +62,30 @@ namespace TransportCompanyListImplement.Implements public DriverViewModel? Insert(DriverBindingModel model) { model.Id = 1; - foreach (var pizzas in _source.Drivers) + foreach (var driver in _source.Drivers) { - if (model.Id <= pizzas.Id) + if (model.Id <= driver.Id) { - model.Id = pizzas.Id + 1; + model.Id = driver.Id + 1; } } - var newPizzas = Driver.Create(model); - if (newPizzas == null) + var newDriver = Driver.Create(model); + if (newDriver == null) { return null; } - _source.Drivers.Add(newPizzas); - return newPizzas.GetViewModel; + _source.Drivers.Add(newDriver); + return newDriver.GetViewModel; } public DriverViewModel? Update(DriverBindingModel model) { - foreach (var pizzas in _source.Drivers) + foreach (var driver in _source.Drivers) { - if (pizzas.Id == model.Id) + if (driver.Id == model.Id) { - pizzas.Update(model); - return pizzas.GetViewModel; + driver.Update(model); + return driver.GetViewModel; } } return null; diff --git a/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs index cc63fee..44eaa41 100644 --- a/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs +++ b/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs @@ -18,9 +18,9 @@ namespace TransportCompanyListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var pizzas in _source.Points) + foreach (var point in _source.Points) { - result.Add(pizzas.GetViewModel); + result.Add(point.GetViewModel); } return result; } @@ -32,11 +32,11 @@ namespace TransportCompanyListImplement.Implements { return result; } - foreach (var pizzas in _source.Points) + foreach (var point in _source.Points) { - if (pizzas.PointName.Contains(model.PointName)) + if (point.PointName.Contains(model.PointName)) { - result.Add(pizzas.GetViewModel); + result.Add(point.GetViewModel); } } return result; @@ -48,12 +48,12 @@ namespace TransportCompanyListImplement.Implements { return null; } - foreach (var pizzas in _source.Points) + foreach (var point in _source.Points) { - if ((!string.IsNullOrEmpty(model.PointName) && pizzas.PointName == model.PointName) || - (model.Id.HasValue && pizzas.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.PointName) && point.PointName == model.PointName) || + (model.Id.HasValue && point.Id == model.Id)) { - return pizzas.GetViewModel; + return point.GetViewModel; } } return null; @@ -62,30 +62,30 @@ namespace TransportCompanyListImplement.Implements public PointViewModel? Insert(PointBindingModel model) { model.Id = 1; - foreach (var pizzas in _source.Points) + foreach (var point in _source.Points) { - if (model.Id <= pizzas.Id) + if (model.Id <= point.Id) { - model.Id = pizzas.Id + 1; + model.Id = point.Id + 1; } } - var newPizzas = Point.Create(model); - if (newPizzas == null) + var newPoint = Point.Create(model); + if (newPoint == null) { return null; } - _source.Points.Add(newPizzas); - return newPizzas.GetViewModel; + _source.Points.Add(newPoint); + return newPoint.GetViewModel; } public PointViewModel? Update(PointBindingModel model) { - foreach (var pizzas in _source.Points) + foreach (var point in _source.Points) { - if (pizzas.Id == model.Id) + if (point.Id == model.Id) { - pizzas.Update(model); - return pizzas.GetViewModel; + point.Update(model); + return point.GetViewModel; } } return null; diff --git a/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs index af65699..34e6e93 100644 --- a/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs +++ b/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs @@ -18,9 +18,9 @@ namespace TransportCompanyListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var pizzas in _source.Transports) + foreach (var transport in _source.Transports) { - result.Add(pizzas.GetViewModel); + result.Add(transport.GetViewModel); } return result; } @@ -32,11 +32,11 @@ namespace TransportCompanyListImplement.Implements { return result; } - foreach (var pizzas in _source.Transports) + foreach (var transport in _source.Transports) { - if (pizzas.Model.Contains(model.Model)) + if (transport.Model.Contains(model.Model)) { - result.Add(pizzas.GetViewModel); + result.Add(transport.GetViewModel); } } return result; @@ -48,12 +48,12 @@ namespace TransportCompanyListImplement.Implements { return null; } - foreach (var pizzas in _source.Transports) + foreach (var transport in _source.Transports) { - if ((!string.IsNullOrEmpty(model.Model) && pizzas.Model == model.Model) || - (model.Id.HasValue && pizzas.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.Model) && transport.Model == model.Model) || + (model.Id.HasValue && transport.Id == model.Id)) { - return pizzas.GetViewModel; + return transport.GetViewModel; } } return null; @@ -62,30 +62,30 @@ namespace TransportCompanyListImplement.Implements public TransportViewModel? Insert(TransportBindingModel model) { model.Id = 1; - foreach (var pizzas in _source.Transports) + foreach (var transport in _source.Transports) { - if (model.Id <= pizzas.Id) + if (model.Id <= transport.Id) { - model.Id = pizzas.Id + 1; + model.Id = transport.Id + 1; } } - var newPizzas = Transport.Create(model); - if (newPizzas == null) + var newTransport = Transport.Create(model); + if (newTransport == null) { return null; } - _source.Transports.Add(newPizzas); - return newPizzas.GetViewModel; + _source.Transports.Add(newTransport); + return newTransport.GetViewModel; } public TransportViewModel? Update(TransportBindingModel model) { - foreach (var pizzas in _source.Transports) + foreach (var transport in _source.Transports) { - if (pizzas.Id == model.Id) + if (transport.Id == model.Id) { - pizzas.Update(model); - return pizzas.GetViewModel; + transport.Update(model); + return transport.GetViewModel; } } return null; diff --git a/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs index 154a015..db04838 100644 --- a/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs +++ b/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs @@ -18,9 +18,9 @@ namespace TransportCompanyListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var order in _source.Transportations) + foreach (var transportation in _source.Transportations) { - result.Add(AttachDetails(order.GetViewModel)); + result.Add(AttachDetails(transportation.GetViewModel)); } return result; } @@ -32,11 +32,11 @@ namespace TransportCompanyListImplement.Implements { return result; } - foreach (var order in _source.Transportations) + foreach (var transportation in _source.Transportations) { - if (order.Id == model.Id) + if (transportation.Id == model.Id) { - result.Add(AttachDetails(order.GetViewModel)); + result.Add(AttachDetails(transportation.GetViewModel)); } } return result; @@ -48,11 +48,11 @@ namespace TransportCompanyListImplement.Implements { return null; } - foreach (var order in _source.Transportations) + foreach (var transportation in _source.Transportations) { - if (model.Id.HasValue && order.Id == model.Id) + if (model.Id.HasValue && transportation.Id == model.Id) { - return AttachDetails(order.GetViewModel); + return AttachDetails(transportation.GetViewModel); } } return null; @@ -61,30 +61,30 @@ namespace TransportCompanyListImplement.Implements public TransportationViewModel? Insert(TransportationBindingModel model) { model.Id = 1; - foreach (var order in _source.Transportations) + foreach (var transportation in _source.Transportations) { - if (model.Id <= order.Id) + if (model.Id <= transportation.Id) { - model.Id = order.Id + 1; + model.Id = transportation.Id + 1; } } - var newOrder = Transportation.Create(model); - if (newOrder == null) + var newTransportation = Transportation.Create(model); + if (newTransportation == null) { return null; } - _source.Transportations.Add(newOrder); - return AttachDetails(newOrder.GetViewModel); + _source.Transportations.Add(newTransportation); + return AttachDetails(newTransportation.GetViewModel); } public TransportationViewModel? Update(TransportationBindingModel model) { - foreach (var order in _source.Transportations) + foreach (var transportation in _source.Transportations) { - if (order.Id == model.Id) + if (transportation.Id == model.Id) { - order.Update(model); - return AttachDetails(order.GetViewModel); + transportation.Update(model); + return AttachDetails(transportation.GetViewModel); } } return null; diff --git a/TransportCompany/TransportCompanyView/FormCargo.Designer.cs b/TransportCompany/TransportCompanyView/FormCargo.Designer.cs new file mode 100644 index 0000000..1731c35 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCargo.Designer.cs @@ -0,0 +1,124 @@ +namespace TransportCompanyView +{ + partial class FormCargo + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxWeight = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 7); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(86, 7); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(321, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxCost + // + this.textBoxWeight.Location = new System.Drawing.Point(86, 32); + this.textBoxWeight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxWeight.Name = "textBoxWeight"; + this.textBoxWeight.Size = new System.Drawing.Size(117, 23); + this.textBoxWeight.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(10, 32); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Вес"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(150, 68); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(114, 30); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(287, 68); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(119, 30); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(418, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxWeight); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCargo"; + this.Text = "Груз"; + this.Load += new System.EventHandler(this.FormCargo_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxWeight; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormCargo.cs b/TransportCompany/TransportCompanyView/FormCargo.cs new file mode 100644 index 0000000..9835f16 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCargo.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; +using TransportCompanyContracts.SearchModels; + +namespace TransportCompanyView +{ + public partial class FormCargo : Form + { + private readonly ILogger _logger; + private readonly ICargoLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormCargo(ILogger logger, ICargoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCargo_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение груза"); + var view = _logic.ReadElement(new CargoSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.CargoName; + textBoxWeight.Text = view.Weight.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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxWeight.Text)) + { + MessageBox.Show("Заполните вес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение груза"); + try + { + var model = new CargoBindingModel + { + Id = _id ?? 0, + CargoName = textBoxName.Text, + Weight = Convert.ToInt32(textBoxWeight.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/TransportCompany/TransportCompanyView/FormCargo.resx b/TransportCompany/TransportCompanyView/FormCargo.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCargo.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormCargos.Designer.cs b/TransportCompany/TransportCompanyView/FormCargos.Designer.cs new file mode 100644 index 0000000..8af29b9 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCargos.Designer.cs @@ -0,0 +1,137 @@ +namespace TransportCompanyView +{ + partial class FormCargos + { + /// + /// 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonUpdate); + this.ToolsPanel.Controls.Add(this.buttonDelete); + this.ToolsPanel.Controls.Add(this.buttonEdit); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(532, 9); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.TabIndex = 1; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(27, 154); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(110, 27); + this.buttonUpdate.TabIndex = 3; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(27, 106); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(110, 27); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(27, 57); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 27); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(27, 12); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCargos"; + this.Text = "Грузы"; + this.Load += new System.EventHandler(this.FormCargos_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormCargos.cs b/TransportCompany/TransportCompanyView/FormCargos.cs new file mode 100644 index 0000000..f8b6d37 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCargos.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; + +namespace TransportCompanyView +{ + public partial class FormCargos : Form + { + private readonly ILogger _logger; + private readonly ICargoLogic _logic; + + public FormCargos(ILogger logger, ICargoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCargos_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["CargoName"].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(FormCargo)); + if (service is FormCargo 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(FormCargo)); + if (service is FormCargo 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 CargoBindingModel + { + 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/TransportCompany/TransportCompanyView/FormCargos.resx b/TransportCompany/TransportCompanyView/FormCargos.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCargos.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormCreateTransportation.Designer.cs b/TransportCompany/TransportCompanyView/FormCreateTransportation.Designer.cs new file mode 100644 index 0000000..f7760cf --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCreateTransportation.Designer.cs @@ -0,0 +1,211 @@ +namespace TransportCompanyView +{ + partial class FormCreateTransportation + { + /// + /// 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() + { + labelCargo = new Label(); + comboBoxCargo = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + comboBoxDriver = new ComboBox(); + labelDriver = new Label(); + comboBoxTransport = new ComboBox(); + labelTransport = new Label(); + comboBoxPointFrom = new ComboBox(); + labelPointFrom = new Label(); + comboBoxPointTo = new ComboBox(); + labelPointTo = new Label(); + SuspendLayout(); + // + // labelCargo + // + labelCargo.AutoSize = true; + labelCargo.Location = new Point(11, 15); + labelCargo.Name = "labelCargo"; + labelCargo.Size = new Size(39, 20); + labelCargo.TabIndex = 0; + labelCargo.Text = "Груз"; + // + // comboBoxCargo + // + comboBoxCargo.FormattingEnabled = true; + comboBoxCargo.Location = new Point(115, 12); + comboBoxCargo.Name = "comboBoxCargo"; + comboBoxCargo.Size = new Size(358, 28); + comboBoxCargo.TabIndex = 1; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(11, 49); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество: "; + // + // textBoxCount + // + textBoxCount.Location = new Point(115, 45); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(358, 27); + textBoxCount.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(355, 227); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(110, 32); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(239, 227); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(110, 32); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // comboBoxDriver + // + comboBoxDriver.FormattingEnabled = true; + comboBoxDriver.Location = new Point(115, 78); + comboBoxDriver.Name = "comboBoxDriver"; + comboBoxDriver.Size = new Size(358, 28); + comboBoxDriver.TabIndex = 9; + // + // labelDriver + // + labelDriver.AutoSize = true; + labelDriver.Location = new Point(11, 81); + labelDriver.Name = "labelDriver"; + labelDriver.Size = new Size(74, 20); + labelDriver.TabIndex = 8; + labelDriver.Text = "Водитель"; + // + // comboBoxTransport + // + comboBoxTransport.FormattingEnabled = true; + comboBoxTransport.Location = new Point(115, 112); + comboBoxTransport.Name = "comboBoxTransport"; + comboBoxTransport.Size = new Size(358, 28); + comboBoxTransport.TabIndex = 11; + // + // labelTransport + // + labelTransport.AutoSize = true; + labelTransport.Location = new Point(11, 115); + labelTransport.Name = "labelTransport"; + labelTransport.Size = new Size(68, 20); + labelTransport.TabIndex = 10; + labelTransport.Text = "Машина"; + // + // comboBoxPointFrom + // + comboBoxPointFrom.FormattingEnabled = true; + comboBoxPointFrom.Location = new Point(115, 146); + comboBoxPointFrom.Name = "comboBoxPointFrom"; + comboBoxPointFrom.Size = new Size(358, 28); + comboBoxPointFrom.TabIndex = 13; + // + // labelPointFrom + // + labelPointFrom.AutoSize = true; + labelPointFrom.Location = new Point(11, 149); + labelPointFrom.Name = "labelPointFrom"; + labelPointFrom.Size = new Size(56, 20); + labelPointFrom.TabIndex = 12; + labelPointFrom.Text = "Откуда"; + // + // comboBoxPointTo + // + comboBoxPointTo.FormattingEnabled = true; + comboBoxPointTo.Location = new Point(115, 180); + comboBoxPointTo.Name = "comboBoxPointTo"; + comboBoxPointTo.Size = new Size(358, 28); + comboBoxPointTo.TabIndex = 15; + // + // labelPointTo + // + labelPointTo.AutoSize = true; + labelPointTo.Location = new Point(11, 183); + labelPointTo.Name = "labelPointTo"; + labelPointTo.Size = new Size(41, 20); + labelPointTo.TabIndex = 14; + labelPointTo.Text = "Куда"; + // + // FormCreateTransportation + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(485, 271); + Controls.Add(comboBoxPointTo); + Controls.Add(labelPointTo); + Controls.Add(comboBoxPointFrom); + Controls.Add(labelPointFrom); + Controls.Add(comboBoxTransport); + Controls.Add(labelTransport); + Controls.Add(comboBoxDriver); + Controls.Add(labelDriver); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxCargo); + Controls.Add(labelCargo); + Name = "FormCreateTransportation"; + Text = "Транспортировка"; + Load += new System.EventHandler(FormCreateTransportation_Load); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCargo; + private ComboBox comboBoxCargo; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + private ComboBox comboBoxDriver; + private Label labelDriver; + private ComboBox comboBoxTransport; + private Label labelTransport; + private ComboBox comboBoxPointFrom; + private Label labelPointFrom; + private ComboBox comboBoxPointTo; + private Label labelPointTo; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormCreateTransportation.cs b/TransportCompany/TransportCompanyView/FormCreateTransportation.cs new file mode 100644 index 0000000..62efe2a --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCreateTransportation.cs @@ -0,0 +1,157 @@ +using Microsoft.Extensions.Logging; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; +using TransportCompanyContracts.ViewModels; + +namespace TransportCompanyView +{ + public partial class FormCreateTransportation : Form + { + private readonly ILogger _logger; + private readonly ICargoLogic _logicC; + private readonly IDriverLogic _logicD; + private readonly ITransportLogic _logicT; + private readonly IPointLogic _logicP; + private readonly ITransportationLogic _logicTt; + private List? _cargoList; + private List? _driverList; + private List? _transportList; + private List? _pointFromList; + private List? _pointToList; + + public FormCreateTransportation(ILogger logger, ICargoLogic logicC, IDriverLogic logicD, ITransportLogic logicT, IPointLogic logicP, ITransportationLogic logicTt) + { + InitializeComponent(); + _logger = logger; + _logicC = logicC; + _logicD = logicD; + _logicT = logicT; + _logicP = logicP; + _logicTt = logicTt; + } + + private void FormCreateTransportation_Load(object sender, EventArgs e) + { + _cargoList = _logicC.ReadList(null); + _driverList = _logicD.ReadList(null); + _transportList = _logicT.ReadList(null); + _pointFromList = _logicP.ReadList(null); + _pointToList = _logicP.ReadList(null); + + if (_cargoList != null) + { + comboBoxCargo.DisplayMember = "CargoName"; + comboBoxCargo.ValueMember = "Id"; + comboBoxCargo.DataSource = _cargoList; + comboBoxCargo.SelectedItem = null; + _logger.LogInformation("Загрузка грузов для транспортировки"); + } + + if (_driverList != null) + { + comboBoxDriver.DisplayMember = "DriverFio"; + comboBoxDriver.ValueMember = "Id"; + comboBoxDriver.DataSource = _driverList; + comboBoxDriver.SelectedItem = null; + _logger.LogInformation("Загрузка водителей для транспортировки"); + } + + if (_transportList != null) + { + comboBoxTransport.DisplayMember = "Model"; + comboBoxTransport.ValueMember = "Id"; + comboBoxTransport.DataSource = _transportList; + comboBoxTransport.SelectedItem = null; + _logger.LogInformation("Загрузка машин для транспортировки"); + } + + if (_pointFromList != null) + { + comboBoxPointFrom.DisplayMember = "PointName"; + comboBoxPointFrom.ValueMember = "Id"; + comboBoxPointFrom.DataSource = _pointFromList; + comboBoxPointFrom.SelectedItem = null; + _logger.LogInformation("Загрузка пунктов отправления для транспортировки"); + } + + if (_pointToList != null) + { + comboBoxPointTo.DisplayMember = "PointName"; + comboBoxPointTo.ValueMember = "Id"; + comboBoxPointTo.DataSource = _pointToList; + comboBoxPointTo.SelectedItem = null; + _logger.LogInformation("Загрузка пунктов прибытия для транспортировки"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxCargo.SelectedValue == null) + { + MessageBox.Show("Выберите груз", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните количество груза", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDriver.SelectedValue == null) + { + MessageBox.Show("Выберите водителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxTransport.SelectedValue == null) + { + MessageBox.Show("Выберите машину", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPointFrom.SelectedValue == null) + { + MessageBox.Show("Выберите пункт отправки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPointTo.SelectedValue == null) + { + MessageBox.Show("Выберите пункт прибытия", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание транспортировки"); + try + { + var operationResult = _logicTt.CreateTransportation(new TransportationBindingModel + { + DriverId = Convert.ToInt32(comboBoxDriver.SelectedValue), + TransportId = Convert.ToInt32(comboBoxTransport.SelectedValue), + CargoId = Convert.ToInt32(comboBoxCargo.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + PointToId = Convert.ToInt32(comboBoxPointTo.SelectedValue), + PointFromId = Convert.ToInt32(comboBoxPointFrom.SelectedValue), + }); + 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/TransportCompany/TransportCompanyView/FormCreateTransportation.resx b/TransportCompany/TransportCompanyView/FormCreateTransportation.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormCreateTransportation.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormDriver.Designer.cs b/TransportCompany/TransportCompanyView/FormDriver.Designer.cs new file mode 100644 index 0000000..9d210eb --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormDriver.Designer.cs @@ -0,0 +1,118 @@ +namespace TransportCompanyView +{ + partial class FormDriver + { + /// + /// 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() + { + labelName = new Label(); + textBoxFio = new TextBox(); + textBoxPhoneNumber = new TextBox(); + labelPhoneNumber = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(11, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(45, 20); + labelName.TabIndex = 0; + labelName.Text = "ФИО:"; + // + // textBoxFio + // + textBoxFio.Location = new Point(98, 9); + textBoxFio.Name = "textBoxFio"; + textBoxFio.Size = new Size(366, 27); + textBoxFio.TabIndex = 1; + // + // textBoxPhoneNumber + // + textBoxPhoneNumber.Location = new Point(98, 43); + textBoxPhoneNumber.Name = "textBoxPhoneNumber"; + textBoxPhoneNumber.Size = new Size(366, 27); + textBoxPhoneNumber.TabIndex = 3; + // + // labelPhoneNumber + // + labelPhoneNumber.AutoSize = true; + labelPhoneNumber.Location = new Point(11, 43); + labelPhoneNumber.Name = "labelPhoneNumber"; + labelPhoneNumber.Size = new Size(69, 20); + labelPhoneNumber.TabIndex = 2; + labelPhoneNumber.Text = "Телефон"; + // + // buttonSave + // + buttonSave.Location = new Point(171, 91); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(130, 40); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(328, 91); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(136, 40); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormDriver + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(478, 141); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxPhoneNumber); + Controls.Add(labelPhoneNumber); + Controls.Add(textBoxFio); + Controls.Add(labelName); + Name = "FormDriver"; + Text = "Водитель"; + Load += FormCargo_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxFio; + private TextBox textBoxPhoneNumber; + private Label labelPhoneNumber; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormDriver.cs b/TransportCompany/TransportCompanyView/FormDriver.cs new file mode 100644 index 0000000..bbd7e4b --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormDriver.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; +using TransportCompanyContracts.SearchModels; + +namespace TransportCompanyView +{ + public partial class FormDriver : Form + { + private readonly ILogger _logger; + private readonly IDriverLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormDriver(ILogger logger, IDriverLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCargo_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение водителя"); + var view = _logic.ReadElement(new DriverSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.DriverFio; + textBoxPhoneNumber.Text = view.PhoneNumber; + } + } + 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(textBoxFio.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPhoneNumber.Text)) + { + MessageBox.Show("Заполните номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение водителя"); + try + { + var model = new DriverBindingModel + { + Id = _id ?? 0, + DriverFio = textBoxFio.Text, + PhoneNumber = textBoxPhoneNumber.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/TransportCompany/TransportCompanyView/FormDriver.resx b/TransportCompany/TransportCompanyView/FormDriver.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormDriver.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormDrivers.Designer.cs b/TransportCompany/TransportCompanyView/FormDrivers.Designer.cs new file mode 100644 index 0000000..07cb7e0 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormDrivers.Designer.cs @@ -0,0 +1,137 @@ +namespace TransportCompanyView +{ + partial class FormDrivers + { + /// + /// 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonUpdate); + this.ToolsPanel.Controls.Add(this.buttonDelete); + this.ToolsPanel.Controls.Add(this.buttonEdit); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(532, 9); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.TabIndex = 1; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(27, 154); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(110, 27); + this.buttonUpdate.TabIndex = 3; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(27, 106); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(110, 27); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(27, 57); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 27); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(27, 12); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCargos"; + this.Text = "Водители"; + this.Load += new System.EventHandler(this.FormDrivers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormDrivers.cs b/TransportCompany/TransportCompanyView/FormDrivers.cs new file mode 100644 index 0000000..f4e0000 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormDrivers.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; + +namespace TransportCompanyView +{ + public partial class FormDrivers : Form + { + private readonly ILogger _logger; + private readonly IDriverLogic _logic; + + public FormDrivers(ILogger logger, IDriverLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDrivers_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; + var halfWidth = dataGridView.Width / 2; + dataGridView.Columns["DriverFio"].Width = halfWidth; + dataGridView.Columns["PhoneNumber"].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(FormDriver)); + if (service is FormDriver 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(FormDriver)); + if (service is FormDriver 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 DriverBindingModel + { + 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/TransportCompany/TransportCompanyView/FormDrivers.resx b/TransportCompany/TransportCompanyView/FormDrivers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormDrivers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormMain.Designer.cs b/TransportCompany/TransportCompanyView/FormMain.Designer.cs new file mode 100644 index 0000000..84890f3 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormMain.Designer.cs @@ -0,0 +1,194 @@ +namespace TransportCompanyView +{ + 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() + { + menuStrip1 = new MenuStrip(); + bookToolStripMenuItem = new ToolStripMenuItem(); + ingridientsToolStripMenuItem = new ToolStripMenuItem(); + pizzasToolStripMenuItem = new ToolStripMenuItem(); + машиныToolStripMenuItem = new ToolStripMenuItem(); + пунктыToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { bookToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(6, 3, 0, 3); + menuStrip1.Size = new Size(1594, 30); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // bookToolStripMenuItem + // + bookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ingridientsToolStripMenuItem, pizzasToolStripMenuItem, машиныToolStripMenuItem, пунктыToolStripMenuItem }); + bookToolStripMenuItem.Name = "bookToolStripMenuItem"; + bookToolStripMenuItem.Size = new Size(108, 24); + bookToolStripMenuItem.Text = "Справочник"; + // + // ingridientsToolStripMenuItem + // + ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem"; + ingridientsToolStripMenuItem.Size = new Size(158, 26); + ingridientsToolStripMenuItem.Text = "Грузы"; + ingridientsToolStripMenuItem.Click += CargosToolStripMenuItem_Click; + // + // pizzasToolStripMenuItem + // + pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem"; + pizzasToolStripMenuItem.Size = new Size(158, 26); + pizzasToolStripMenuItem.Text = "Водители"; + pizzasToolStripMenuItem.Click += DriversToolStripMenuItem_Click; + // + // машиныToolStripMenuItem + // + машиныToolStripMenuItem.Name = "машиныToolStripMenuItem"; + машиныToolStripMenuItem.Size = new Size(158, 26); + машиныToolStripMenuItem.Text = "Машины"; + машиныToolStripMenuItem.Click += TransportsToolStripMenuItem_Click; + // + // пунктыToolStripMenuItem + // + пунктыToolStripMenuItem.Name = "пунктыToolStripMenuItem"; + пунктыToolStripMenuItem.Size = new Size(158, 26); + пунктыToolStripMenuItem.Text = "Пункты"; + пунктыToolStripMenuItem.Click += PointsToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(11, 31); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(1305, 381); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1334, 72); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(247, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать транспортировку"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonFormCreateTransportation_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(1334, 124); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(247, 29); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на доставку"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonDeliveredTransportation_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(1334, 173); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(247, 29); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Груз прибыл"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonArrivedTransportation_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1334, 226); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(247, 29); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Груз отгружен"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonShippedTransportation_Click; + // + // buttonRef + // + buttonRef.Location = new Point(1334, 281); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(247, 29); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1594, 425); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Транспортная компания"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem bookToolStripMenuItem; + private ToolStripMenuItem ingridientsToolStripMenuItem; + private ToolStripMenuItem pizzasToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private ToolStripMenuItem машиныToolStripMenuItem; + private ToolStripMenuItem пунктыToolStripMenuItem; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormMain.cs b/TransportCompany/TransportCompanyView/FormMain.cs new file mode 100644 index 0000000..d39e2c2 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormMain.cs @@ -0,0 +1,183 @@ +using Microsoft.Extensions.Logging; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; + +namespace TransportCompanyView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly ITransportationLogic _transportationLogic; + + public FormMain(ILogger logger, ITransportationLogic transportationLogic) + { + InitializeComponent(); + _logger = logger; + _transportationLogic = transportationLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _transportationLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["DriverId"].Visible = false; + dataGridView.Columns["TransportId"].Visible = false; + dataGridView.Columns["PointToId"].Visible = false; + dataGridView.Columns["PointFromId"].Visible = false; + dataGridView.Columns["CargoId"].Visible = false; + dataGridView.Columns["DriverFio"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft; + dataGridView.Columns["Model"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft; + dataGridView.Columns["CargoName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft; + + dataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True; + dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; + } + _logger.LogInformation("Загрузка транспортировок"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки транспортировок"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CargosToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCargos)); + if (service is FormCargos form) + { + form.ShowDialog(); + } + } + + private void DriversToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDrivers)); + if (service is FormDrivers form) + { + form.ShowDialog(); + } + } + + private void PointsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPoints)); + if (service is FormPoints form) + { + form.ShowDialog(); + } + } + + private void TransportsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransports)); + if (service is FormTransports form) + { + form.ShowDialog(); + } + } + + private void ButtonFormCreateTransportation_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateTransportation)); + if (service is FormCreateTransportation form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonDeliveredTransportation_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _transportationLogic.DeliveredTransportation(new TransportationBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonArrivedTransportation_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _transportationLogic.ArrivedTransportation(new TransportationBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonShippedTransportation_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _transportationLogic.ShippedTransportation(new TransportationBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ No{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TransportCompany/TransportCompanyView/FormMain.resx b/TransportCompany/TransportCompanyView/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormPoint.Designer.cs b/TransportCompany/TransportCompanyView/FormPoint.Designer.cs new file mode 100644 index 0000000..6c9d9d9 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormPoint.Designer.cs @@ -0,0 +1,118 @@ +namespace TransportCompanyView +{ + partial class FormPoint + { + /// + /// 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() + { + labelName = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + labelAddress = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(11, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(45, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(98, 9); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(366, 27); + textBoxName.TabIndex = 1; + // + // textBoxPhoneNumber + // + textBoxAddress.Location = new Point(98, 43); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(366, 27); + textBoxAddress.TabIndex = 3; + // + // labelPhoneNumber + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(11, 43); + labelAddress.Name = "labelPhoneNumber"; + labelAddress.Size = new Size(69, 20); + labelAddress.TabIndex = 2; + labelAddress.Text = "Адрес"; + // + // buttonSave + // + buttonSave.Location = new Point(171, 91); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(130, 40); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(328, 91); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(136, 40); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormDriver + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(478, 141); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxAddress); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Name = "FormPoint"; + Text = "Пункт"; + Load += FormCargo_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAddress; + private Label labelAddress; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormPoint.cs b/TransportCompany/TransportCompanyView/FormPoint.cs new file mode 100644 index 0000000..a51d6ed --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormPoint.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; +using TransportCompanyContracts.SearchModels; + +namespace TransportCompanyView +{ + public partial class FormPoint : Form + { + private readonly ILogger _logger; + private readonly IPointLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormPoint(ILogger logger, IPointLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCargo_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение пункта"); + var view = _logic.ReadElement(new PointSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PointName; + textBoxAddress.Text = view.Address; + } + } + 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; + } + _logger.LogInformation("Сохранение пункта"); + try + { + var model = new PointBindingModel + { + Id = _id ?? 0, + PointName = textBoxName.Text, + Address = textBoxAddress.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/TransportCompany/TransportCompanyView/FormPoint.resx b/TransportCompany/TransportCompanyView/FormPoint.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormPoint.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormPoints.Designer.cs b/TransportCompany/TransportCompanyView/FormPoints.Designer.cs new file mode 100644 index 0000000..aa8d348 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormPoints.Designer.cs @@ -0,0 +1,137 @@ +namespace TransportCompanyView +{ + partial class FormPoints + { + /// + /// 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonUpdate); + this.ToolsPanel.Controls.Add(this.buttonDelete); + this.ToolsPanel.Controls.Add(this.buttonEdit); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(532, 9); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.TabIndex = 1; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(27, 154); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(110, 27); + this.buttonUpdate.TabIndex = 3; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(27, 106); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(110, 27); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(27, 57); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 27); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(27, 12); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormPoints"; + this.Text = "Пункты"; + this.Load += new System.EventHandler(this.FormDrivers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormPoints.cs b/TransportCompany/TransportCompanyView/FormPoints.cs new file mode 100644 index 0000000..634d2df --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormPoints.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; + +namespace TransportCompanyView +{ + public partial class FormPoints : Form + { + private readonly ILogger _logger; + private readonly IPointLogic _logic; + + public FormPoints(ILogger logger, IPointLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDrivers_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; + var halfWidth = dataGridView.Width / 2; + dataGridView.Columns["PointName"].Width = halfWidth; + dataGridView.Columns["Address"].Width = halfWidth; + } + _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(FormPoint)); + if (service is FormPoint 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(FormPoint)); + if (service is FormPoint 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 PointBindingModel + { + 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/TransportCompany/TransportCompanyView/FormPoints.resx b/TransportCompany/TransportCompanyView/FormPoints.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormPoints.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormTransport.Designer.cs b/TransportCompany/TransportCompanyView/FormTransport.Designer.cs new file mode 100644 index 0000000..b35efb7 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormTransport.Designer.cs @@ -0,0 +1,140 @@ +namespace TransportCompanyView +{ + partial class FormTransport + { + /// + /// 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() + { + labelName = new Label(); + textBoxName = new TextBox(); + textBoxStateNumber = new TextBox(); + labelAddress = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxLoadCapacity = new TextBox(); + labelLoadCapacity = new Label(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(11, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(117, 9); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(347, 27); + textBoxName.TabIndex = 1; + // + // textBoxStateNumber + // + textBoxStateNumber.Location = new Point(117, 75); + textBoxStateNumber.Name = "textBoxStateNumber"; + textBoxStateNumber.Size = new Size(347, 27); + textBoxStateNumber.TabIndex = 3; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(11, 75); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(85, 20); + labelAddress.TabIndex = 2; + labelAddress.Text = "Гос. номер"; + // + // buttonSave + // + buttonSave.Location = new Point(172, 118); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(130, 40); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(328, 118); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(136, 40); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxLoadCapacity + // + textBoxLoadCapacity.Location = new Point(117, 42); + textBoxLoadCapacity.Name = "textBoxLoadCapacity"; + textBoxLoadCapacity.Size = new Size(101, 27); + textBoxLoadCapacity.TabIndex = 7; + // + // labelLoadCapacity + // + labelLoadCapacity.AutoSize = true; + labelLoadCapacity.Location = new Point(11, 42); + labelLoadCapacity.Name = "labelLoadCapacity"; + labelLoadCapacity.Size = new Size(100, 20); + labelLoadCapacity.TabIndex = 6; + labelLoadCapacity.Text = "Вместимость"; + // + // FormTransport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(478, 170); + Controls.Add(textBoxLoadCapacity); + Controls.Add(labelLoadCapacity); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxStateNumber); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Name = "FormTransport"; + Text = "Машина"; + Load += FormTransport_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxStateNumber; + private Label labelAddress; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxLoadCapacity; + private Label labelLoadCapacity; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormTransport.cs b/TransportCompany/TransportCompanyView/FormTransport.cs new file mode 100644 index 0000000..c94a2b2 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormTransport.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; +using TransportCompanyContracts.SearchModels; + +namespace TransportCompanyView +{ + public partial class FormTransport : Form + { + private readonly ILogger _logger; + private readonly ITransportLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormTransport(ILogger logger, ITransportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormTransport_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение пункта"); + var view = _logic.ReadElement(new TransportSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Model; + textBoxLoadCapacity.Text = view.LoadCapacity.ToString(); + 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(textBoxName.Text)) + { + MessageBox.Show("Заполните модель", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxLoadCapacity.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 TransportBindingModel + { + Id = _id ?? 0, + Model = textBoxName.Text, + LoadCapacity = Convert.ToInt32(textBoxLoadCapacity.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(); + } + } +} diff --git a/TransportCompany/TransportCompanyView/FormTransport.resx b/TransportCompany/TransportCompanyView/FormTransport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormTransport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/FormTransports.Designer.cs b/TransportCompany/TransportCompanyView/FormTransports.Designer.cs new file mode 100644 index 0000000..584b648 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormTransports.Designer.cs @@ -0,0 +1,137 @@ +namespace TransportCompanyView +{ + partial class FormTransports + { + /// + /// 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonUpdate); + this.ToolsPanel.Controls.Add(this.buttonDelete); + this.ToolsPanel.Controls.Add(this.buttonEdit); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(532, 9); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.TabIndex = 1; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(27, 154); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(110, 27); + this.buttonUpdate.TabIndex = 3; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(27, 106); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(110, 27); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(27, 57); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 27); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(27, 12); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormTransports"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormTransports_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/FormTransports.cs b/TransportCompany/TransportCompanyView/FormTransports.cs new file mode 100644 index 0000000..1cc2d61 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormTransports.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.BusinessLogicsContracts; + +namespace TransportCompanyView +{ + public partial class FormTransports : Form + { + private readonly ILogger _logger; + private readonly ITransportLogic _logic; + + public FormTransports(ILogger logger, ITransportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormTransports_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; + var halfWidth = dataGridView.Width / 3; + dataGridView.Columns["Model"].Width = halfWidth; + dataGridView.Columns["LoadCapacity"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["StateNumber"].Width = halfWidth; + } + _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(FormTransport)); + if (service is FormTransport 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(FormTransport)); + if (service is FormTransport 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 TransportBindingModel + { + 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/TransportCompany/TransportCompanyView/FormTransports.resx b/TransportCompany/TransportCompanyView/FormTransports.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportCompany/TransportCompanyView/FormTransports.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TransportCompany/TransportCompanyView/Program.cs b/TransportCompany/TransportCompanyView/Program.cs index fc8835a..ccfd0dd 100644 --- a/TransportCompany/TransportCompanyView/Program.cs +++ b/TransportCompany/TransportCompanyView/Program.cs @@ -1,7 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using TransportCompanyBusinessLogic.BusinessLogics; +using TransportCompanyContracts.BusinessLogicsContracts; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyDatabaseImplement.Implements; +using TransportCompanyView; + namespace TransportCompanyView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,41 @@ namespace TransportCompanyView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + 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/TransportCompany/TransportCompanyView/TransportCompanyView.csproj b/TransportCompany/TransportCompanyView/TransportCompanyView.csproj index b57c89e..92d04b3 100644 --- a/TransportCompany/TransportCompanyView/TransportCompanyView.csproj +++ b/TransportCompany/TransportCompanyView/TransportCompanyView.csproj @@ -8,4 +8,32 @@ enable + + + + + + + Always + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TransportCompany/TransportCompanyView/nlog.config b/TransportCompany/TransportCompanyView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/TransportCompany/TransportCompanyView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file