diff --git a/Subd/BusinessLogic/BusinessLogic/CarBL.cs b/Subd/BusinessLogic/BusinessLogic/CarBL.cs index 2651927..6f68a6f 100644 --- a/Subd/BusinessLogic/BusinessLogic/CarBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/CarBL.cs @@ -16,6 +16,7 @@ namespace BusinessBL.BusinessBL { private readonly ILogger _logger; private readonly ICarStorage _carStorage; + public CarBL(ILogger logger, ICarStorage carStorage) { _logger = logger; diff --git a/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs b/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs index 57b48e5..d046300 100644 --- a/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs @@ -16,10 +16,14 @@ namespace BusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IVoyageStorage _voyageStorage; - public VoyageBL(ILogger logger, IVoyageStorage voyageStorage) + private readonly IRouteStorage _routeStorage; + private readonly ICompanyStorage _companyStorage; + public VoyageBL(ILogger logger, IVoyageStorage voyageStorage,IRouteStorage routeStorage,ICompanyStorage companyStorage) { _logger = logger; _voyageStorage = voyageStorage; + _routeStorage = routeStorage; + _companyStorage = companyStorage; } public List? ReadList(VoyageSM? model) { @@ -108,5 +112,59 @@ namespace BusinessLogic.BusinessLogic } } + public List GetTopDrivers() + { + + var list = _voyageStorage.GetFilteredList(new VoyageSM + { + + DateStart = DateTime.SpecifyKind(DateTime.Now.AddYears(-1), DateTimeKind.Utc), + DateEnd = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + + }); + + List reportList = new List(); + Dictionary humans = new Dictionary(); + foreach(var item in list) + { + if(!humans.ContainsKey(item.HumanId)) + { + humans.Add(item.HumanId, (item.HumanName, item.Km)); + }else + { + humans[item.HumanId] = (item.HumanName, humans[item.HumanId].Item2 + item.Km); + } + } + foreach (var human in humans) + reportList.Add(new ReportHuman { Name = human.Value.Item1, Length = human.Value.Item2 }); + return reportList; + } + + public List? GetCompanysPath() + { + var list = _voyageStorage.GetFullList(); + List reportList = new List(); + Dictionary< (int? , int ?),int? > companies = new Dictionary<(int?, int?), int?>(); + foreach(var company in list) + { + if (!companies.ContainsKey((company.CompanyId,company.RouteId))) + { + companies.Add((company.CompanyId, company.RouteId),1); + } + else + { + + companies[(company.CompanyId, company.RouteId)] = (companies[(company.CompanyId, company.RouteId)].Value + 1); + + } + } + foreach(var compan in companies) + { + + reportList.Add(new ReportCompany { Title = _companyStorage.GetElement(new CompanySM { Id = compan.Key.Item1 }).Title, Details = _routeStorage.GetElement(new RouteSM { Id = compan.Key.Item2 }).Title, Count = compan.Value}); + } + + return reportList; + } } } diff --git a/Subd/Contracts/BindingModels/CarBM.cs b/Subd/Contracts/BindingModels/CarBM.cs index 75ff234..63dfe1d 100644 --- a/Subd/Contracts/BindingModels/CarBM.cs +++ b/Subd/Contracts/BindingModels/CarBM.cs @@ -15,7 +15,7 @@ namespace Contracts.BindingModels public int? StatusId { get; set; } - public string StatusTitle { get; set; } = string.Empty; + public string? StatusTitle { get; set; } = string.Empty; public int Id { get; set; } } diff --git a/Subd/Contracts/BindingModels/CompanyBM.cs b/Subd/Contracts/BindingModels/CompanyBM.cs index 618a77e..1f05048 100644 --- a/Subd/Contracts/BindingModels/CompanyBM.cs +++ b/Subd/Contracts/BindingModels/CompanyBM.cs @@ -13,7 +13,7 @@ namespace Contracts.BindingModels public int? StatusId {get; set; } - public string StatusTitle { get; set; } = string.Empty; + public string? StatusTitle { get; set; } = string.Empty; public int Id { get; set; } } diff --git a/Subd/Contracts/BindingModels/HumanBM.cs b/Subd/Contracts/BindingModels/HumanBM.cs index e3aee98..0bb8e6e 100644 --- a/Subd/Contracts/BindingModels/HumanBM.cs +++ b/Subd/Contracts/BindingModels/HumanBM.cs @@ -15,7 +15,7 @@ namespace Contracts.BindingModels public int? StatusId { get; set; } - public string StatusTitle { get; set; } = string.Empty; + public string? StatusTitle { get; set; } = string.Empty; public int Id { get; set; } } diff --git a/Subd/Contracts/BindingModels/VoyageBM.cs b/Subd/Contracts/BindingModels/VoyageBM.cs index 15b2184..d5da825 100644 --- a/Subd/Contracts/BindingModels/VoyageBM.cs +++ b/Subd/Contracts/BindingModels/VoyageBM.cs @@ -11,16 +11,17 @@ namespace Contracts.BindingModels { public int? CarId { get; set; } - public string CarName { get; set; } = string.Empty; + public string? CarName { get; set; } = string.Empty; public int? HumanId { get; set; } - public string HumanName { get; set; } = string.Empty; + public string? HumanName { get; set; } = string.Empty; public int? CompanyId { get; set; } - public string CompanyName { get; set; } = string.Empty; + public string? CompanyName { get; set; } = string.Empty; + public string? RouteName { get; set; } = string.Empty; public int? RouteId { get; set; } public DateOnly? DateStart { get; set; } diff --git a/Subd/Contracts/BusinessLogic/IVoyageLogic.cs b/Subd/Contracts/BusinessLogic/IVoyageLogic.cs index 2073eb2..a3988ca 100644 --- a/Subd/Contracts/BusinessLogic/IVoyageLogic.cs +++ b/Subd/Contracts/BusinessLogic/IVoyageLogic.cs @@ -13,8 +13,9 @@ namespace Contracts.BusinessLogic { List? ReadList(VoyageSM model); VoyageVM? ReadElement(VoyageSM model); + List? GetTopDrivers(); bool Create(VoyageBM model); - + public List? GetCompanysPath(); bool Delete(VoyageBM model); } } diff --git a/Subd/Contracts/Storage/IVoyageStorage.cs b/Subd/Contracts/Storage/IVoyageStorage.cs index 317c16a..8a51a3b 100644 --- a/Subd/Contracts/Storage/IVoyageStorage.cs +++ b/Subd/Contracts/Storage/IVoyageStorage.cs @@ -13,6 +13,7 @@ namespace Contracts.Storage { List GetFullList(); List GetFilteredList(VoyageSM model); + VoyageVM? GetElement(VoyageSM model); VoyageVM? Insert(VoyageBM model); diff --git a/Subd/Contracts/ViewModels/CarVM.cs b/Subd/Contracts/ViewModels/CarVM.cs index 24e6dfb..dc6e5cd 100644 --- a/Subd/Contracts/ViewModels/CarVM.cs +++ b/Subd/Contracts/ViewModels/CarVM.cs @@ -10,6 +10,8 @@ namespace Contracts.ViewModels { public class CarVM : ICar { + [DisplayName("Номер")] + public int Id { get; set; } [DisplayName("Модель")] public string Model { get; set; } = string.Empty; [DisplayName("Грузоподъемность")] @@ -17,8 +19,7 @@ namespace Contracts.ViewModels public int? StatusId { get; set; } [DisplayName("Статус")] - public string StatusTitle { get; set; } = string.Empty; - [DisplayName("Номер")] - public int Id { get; set; } + public string? StatusTitle { get; set; } = string.Empty; + } } diff --git a/Subd/Contracts/ViewModels/CompanyVM.cs b/Subd/Contracts/ViewModels/CompanyVM.cs index 0ed366f..5750b7a 100644 --- a/Subd/Contracts/ViewModels/CompanyVM.cs +++ b/Subd/Contracts/ViewModels/CompanyVM.cs @@ -15,7 +15,7 @@ namespace Contracts.ViewModels public int? StatusId { get; set; } [DisplayName("Статус")] - public string StatusTitle { get; set; } = string.Empty; + public string? StatusTitle { get; set; } = string.Empty; [DisplayName("Номер")] public int Id { get; set; } } diff --git a/Subd/Contracts/ViewModels/HumanVM.cs b/Subd/Contracts/ViewModels/HumanVM.cs index 31d640f..022097b 100644 --- a/Subd/Contracts/ViewModels/HumanVM.cs +++ b/Subd/Contracts/ViewModels/HumanVM.cs @@ -17,7 +17,7 @@ namespace Contracts.ViewModels public int? StatusId { get; set; } [DisplayName("Статус")] - public string StatusTitle { get; set; } = string.Empty; + public string? StatusTitle { get; set; } = string.Empty; [DisplayName("Номер")] public int Id { get; set; } } diff --git a/Subd/Contracts/ViewModels/ReportCompany.cs b/Subd/Contracts/ViewModels/ReportCompany.cs new file mode 100644 index 0000000..fee22c8 --- /dev/null +++ b/Subd/Contracts/ViewModels/ReportCompany.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class ReportCompany + { + [DisplayName("Название")] + public string Title { get; set; } + [DisplayName("Маршруты")] + public string? Details { get; set; } + [DisplayName("поездок")] + public int? Count { get; set; } + } +} diff --git a/Subd/Contracts/ViewModels/ReportHuman.cs b/Subd/Contracts/ViewModels/ReportHuman.cs new file mode 100644 index 0000000..ec4470e --- /dev/null +++ b/Subd/Contracts/ViewModels/ReportHuman.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class ReportHuman + { + [DisplayName("ФИО")] + public string? Name { get; set; } + [DisplayName("Расстояние")] + public int? Length { get; set; } + } +} diff --git a/Subd/Contracts/ViewModels/VoyageVM.cs b/Subd/Contracts/ViewModels/VoyageVM.cs index 7673d10..5ad8b63 100644 --- a/Subd/Contracts/ViewModels/VoyageVM.cs +++ b/Subd/Contracts/ViewModels/VoyageVM.cs @@ -12,16 +12,18 @@ namespace Contracts.ViewModels { public int? CarId { get; set; } [DisplayName("Машина")] - public string CarName { get; set; } = string.Empty; + public string? CarName { get; set; } = string.Empty; public int? HumanId { get; set; } [DisplayName("Водитель")] - public string HumanName { get; set; } = string.Empty; - + public string? HumanName { get; set; } = string.Empty; + [DisplayName("Расстояние")] + public int? Km { get; set; } public int? CompanyId { get; set; } [DisplayName("Заказчик")] public string CompanyName { get; set; } = string.Empty; - + [DisplayName("Маршрут")] + public string? RouteName { get; set; } = string.Empty; public int? RouteId { get; set; } [DisplayName("Дата выезда")] public DateOnly? DateStart { get; set; } diff --git a/Subd/DataBase/Car.cs b/Subd/DataBase/Car.cs index e562934..6118793 100644 --- a/Subd/DataBase/Car.cs +++ b/Subd/DataBase/Car.cs @@ -3,6 +3,7 @@ using Contracts.ViewModels; using DataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; namespace DataBase; @@ -35,8 +36,9 @@ public partial class Car : ICar public virtual Status? Status { get; set; } public virtual ICollection Voyages { get; set; } = new List(); - - public string StatusTitle { get; set; } =string.Empty; + [NotMapped] + public string? StatusTitle { get; set; } = string.Empty; + public static Car Create(LogisticContext context, CarBM model) { @@ -46,7 +48,7 @@ public partial class Car : ICar Model = model.Model, Tonnage = model.Tonnage, StatusId= model.StatusId, - StatusTitle = model.StatusTitle + StatusTitle = model.StatusTitle, }; } @@ -64,6 +66,6 @@ public partial class Car : ICar Model = Model, Tonnage = Tonnage, StatusId = StatusId , - StatusTitle=StatusTitle, + StatusTitle = Status?.Title }; } diff --git a/Subd/DataBase/Company.cs b/Subd/DataBase/Company.cs index cc1ef51..489e2ea 100644 --- a/Subd/DataBase/Company.cs +++ b/Subd/DataBase/Company.cs @@ -3,6 +3,7 @@ using Contracts.ViewModels; using DataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace DataBase; @@ -29,8 +30,8 @@ public partial class Company : ICompany public virtual Status? Status { get; set; } public virtual ICollection Voyages { get; set; } = new List(); - - public string StatusTitle { get; set; } = string.Empty; + [NotMapped] + public string? StatusTitle { get; set; } = string.Empty; public static Company Create(LogisticContext context, CompanyBM model) { return new Company() @@ -55,6 +56,6 @@ public partial class Company : ICompany Id = Id, Title = Title, StatusId = StatusId, - StatusTitle = StatusTitle + StatusTitle = Status?.Title }; } diff --git a/Subd/DataBase/Human.cs b/Subd/DataBase/Human.cs index 1bc4c47..fb9d79e 100644 --- a/Subd/DataBase/Human.cs +++ b/Subd/DataBase/Human.cs @@ -4,6 +4,7 @@ using Contracts.ViewModels; using DataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace DataBase; @@ -35,8 +36,9 @@ public partial class Human : IHuman public virtual Status? Status { get; set; } public virtual ICollection Voyages { get; set; } = new List(); - - public string StatusTitle { get; set; } = string.Empty; + [NotMapped] + public string? StatusTitle { get; set; } = string.Empty; + public static Human Create(LogisticContext context, HumanBM model) { return new Human() @@ -63,6 +65,6 @@ public partial class Human : IHuman Name = Name, Phone = Phone, StatusId = StatusId, - StatusTitle = StatusTitle + StatusTitle = Status?.Title }; } diff --git a/Subd/DataBase/Implements/CarStorage.cs b/Subd/DataBase/Implements/CarStorage.cs index fc166e4..151810c 100644 --- a/Subd/DataBase/Implements/CarStorage.cs +++ b/Subd/DataBase/Implements/CarStorage.cs @@ -16,10 +16,12 @@ namespace DataBase.Implements public List GetFullList() { using var context = new LogisticContext(); - return context.Cars.FromSqlRaw("Select * From Car") + return context.Cars.FromSqlRaw("Select * from Car") + .Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); + } public List GetFilteredList(CarSM model) @@ -31,13 +33,15 @@ namespace DataBase.Implements using var context = new LogisticContext(); if(model.StatusId.HasValue) return context.Cars - .FromSqlRaw("Select * FROM Car WHERE StatusId = {0}",model.StatusId) + .FromSqlRaw("Select * FROM Car WHERE status_id = {0}", model.StatusId) + .Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); else return context.Cars .FromSqlRaw("Select * FROM Car WHERE Tonnage >= {0}", model.Tonnage) + .Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); diff --git a/Subd/DataBase/Implements/CompanyStorage.cs b/Subd/DataBase/Implements/CompanyStorage.cs index 0143c57..41423ce 100644 --- a/Subd/DataBase/Implements/CompanyStorage.cs +++ b/Subd/DataBase/Implements/CompanyStorage.cs @@ -17,6 +17,7 @@ namespace DataBase.Implements { using var context = new LogisticContext(); return context.Companies.FromSqlRaw("Select * From Company") + .Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -30,7 +31,8 @@ namespace DataBase.Implements } using var context = new LogisticContext(); return context.Companies - .FromSqlRaw("Select * FROM Company WHERE StatusId = {0}", model.StatusId) + .FromSqlRaw("Select * FROM Company WHERE status_id = {0}", model.StatusId) + .Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); diff --git a/Subd/DataBase/Implements/HumanStorage.cs b/Subd/DataBase/Implements/HumanStorage.cs index 3542bb0..3c76744 100644 --- a/Subd/DataBase/Implements/HumanStorage.cs +++ b/Subd/DataBase/Implements/HumanStorage.cs @@ -16,7 +16,7 @@ namespace DataBase.Implements public List GetFullList() { using var context = new LogisticContext(); - return context.Humans.FromSqlRaw("Select * From Human") + return context.Humans.FromSqlRaw("Select * From Human").Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -30,7 +30,7 @@ namespace DataBase.Implements } using var context = new LogisticContext(); return context.Humans - .FromSqlRaw("Select * FROM Human WHERE StatusId = {0}", model.StatusId) + .FromSqlRaw("Select * FROM Human WHERE status_id = {0}", model.StatusId).Include(u => u.Status) .ToList() .Select(x => x.GetViewModel) .ToList(); diff --git a/Subd/DataBase/Implements/RouteStorage.cs b/Subd/DataBase/Implements/RouteStorage.cs index ffeef52..f4a8900 100644 --- a/Subd/DataBase/Implements/RouteStorage.cs +++ b/Subd/DataBase/Implements/RouteStorage.cs @@ -16,7 +16,7 @@ namespace DataBase.Implements public List GetFullList() { using var context = new LogisticContext(); - return context.Routes.FromSqlRaw("Select * From Route") + return context.Routes.FromSqlRaw("Select * From Route").Include(u => u.PlaceStartNavigation).Include(a => a.PlaceEndNavigation) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -31,18 +31,18 @@ namespace DataBase.Implements using var context = new LogisticContext(); if(model.Length.HasValue) return context.Routes - .FromSqlRaw("Select * FROM Route WHERE Length <= {0}", model.Length) + .FromSqlRaw("Select * FROM Route WHERE Length <= {0}", model.Length).Include(u => u.PlaceStartNavigation).Include(a => a.PlaceEndNavigation) .ToList() .Select(x => x.GetViewModel) .ToList(); else if(model.Start.HasValue) return context.Routes - .FromSqlRaw("Select * FROM Route WHERE PlaceStart = {0} ", model.Start) + .FromSqlRaw("Select * FROM Route WHERE PlaceStart = {0} ", model.Start).Include(u => u.PlaceStartNavigation).Include(a => a.PlaceEndNavigation) .ToList() .Select(x => x.GetViewModel) .ToList(); return context.Routes - .FromSqlRaw("Select * FROM Route WHERE PlaceEnd = {0} ", model.End) + .FromSqlRaw("Select * FROM Route WHERE PlaceEnd = {0} ", model.End).Include(u => u.PlaceStartNavigation).Include(a => a.PlaceEndNavigation) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -55,9 +55,12 @@ namespace DataBase.Implements return null; } using var context = new LogisticContext(); - return context.Routes - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.Start.HasValue && model.End.HasValue && x.PlaceEnd == model.End && x.PlaceStart == model.Start )) - ?.GetViewModel; + var mid = context.Routes.FromSqlRaw("Select * from Route r where r.id = {0}", model.Id).Include(u => u.PlaceStartNavigation).Include(a => a.PlaceEndNavigation).ToList(); + + if (mid.Count == 0) + return null; + var res = mid[0]?.GetViewModel; + return res; } public RouteVM? Insert(RouteBM model) diff --git a/Subd/DataBase/Implements/VoyageStorage.cs b/Subd/DataBase/Implements/VoyageStorage.cs index d735c2c..cf9a57b 100644 --- a/Subd/DataBase/Implements/VoyageStorage.cs +++ b/Subd/DataBase/Implements/VoyageStorage.cs @@ -2,6 +2,7 @@ using Contracts.SearchModel; using Contracts.Storage; using Contracts.ViewModels; +using DataModels.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -17,6 +18,9 @@ namespace DataBase.Implements { using var context = new LogisticContext(); return context.Voyages.FromSqlRaw("Select * From Voyage") + .Include(u => u.Car).Include(u => u.Company).Include(u => u.Human) + .Include(u => u.Route).ThenInclude(u => u.PlaceStartNavigation) + .Include(u => u.Route).ThenInclude(u => u.PlaceEndNavigation) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -30,7 +34,10 @@ namespace DataBase.Implements } using var context = new LogisticContext(); return context.Voyages - .FromSqlRaw("Select * FROM Voyage WHERE DateStart > {0} AND DateEnd < {1}", model.DateStart,model.DateEnd) + .FromSqlRaw("Select * FROM Voyage WHERE date_start > {0} AND date_end < {1}", model.DateStart,model.DateEnd) + .Include(u => u.Car).Include(u => u.Company).Include(u => u.Human) + .Include(u => u.Route).ThenInclude(u => u.PlaceStartNavigation) + .Include(u => u.Route).ThenInclude(u => u.PlaceEndNavigation) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -46,6 +53,7 @@ namespace DataBase.Implements using var context = new LogisticContext(); return context.Voyages .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } @@ -77,5 +85,6 @@ namespace DataBase.Implements } return null; } + } } diff --git a/Subd/DataBase/Route.cs b/Subd/DataBase/Route.cs index 20aad5e..920b94f 100644 --- a/Subd/DataBase/Route.cs +++ b/Subd/DataBase/Route.cs @@ -3,6 +3,7 @@ using Contracts.ViewModels; using DataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace DataBase; @@ -37,6 +38,7 @@ public partial class Route : IRoute public virtual ICollection Voyages { get; set; } = new List(); + [NotMapped] public string Title { get; set; }=string.Empty; public static Route Create(LogisticContext context, RouteBM model) @@ -48,23 +50,22 @@ public partial class Route : IRoute Length = model.Length, PlaceStart = model.PlaceStart, PlaceEnd = model.PlaceEnd, - + + }; } public void Update(RouteBM model) { Title = model.Title; - - } public RouteVM GetViewModel => new() { Id = Id, - Title = Title, Length = Length, PlaceStart = PlaceStart, PlaceEnd = PlaceEnd, + Title = PlaceStartNavigation?.Title + " - " + PlaceEndNavigation?.Title }; } diff --git a/Subd/DataBase/Status.cs b/Subd/DataBase/Status.cs index b9f94cc..500856b 100644 --- a/Subd/DataBase/Status.cs +++ b/Subd/DataBase/Status.cs @@ -1,5 +1,6 @@ using Contracts.BindingModels; using Contracts.ViewModels; +using DataModels.Models; using System; using System.Collections.Generic; @@ -8,7 +9,7 @@ namespace DataBase; /// /// Таблица статусов /// -public partial class Status +public partial class Status : IStatus { /// /// Айди статуса diff --git a/Subd/DataBase/Voyage.cs b/Subd/DataBase/Voyage.cs index 25a25b2..c155f66 100644 --- a/Subd/DataBase/Voyage.cs +++ b/Subd/DataBase/Voyage.cs @@ -3,6 +3,7 @@ using Contracts.ViewModels; using DataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace DataBase; @@ -53,12 +54,16 @@ public partial class Voyage : IVoyage public virtual Human? Human { get; set; } public virtual Route? Route { get; set; } - - public string CarName { get; set; } = string.Empty; - - public string HumanName { get; set; } = string.Empty; - - public string CompanyName { get; set; } = string.Empty; + [NotMapped] + public string? CarName { get; set; } = string.Empty; + [NotMapped] + public string? HumanName { get; set; } = string.Empty; + [NotMapped] + public string? CompanyName { get; set; } = string.Empty; + [NotMapped] + public string? RouteName { get; set; } = string.Empty; + [NotMapped] + public int? Km { get; set; } public static Voyage Create(LogisticContext context, VoyageBM model) { return new Voyage() @@ -73,8 +78,8 @@ public partial class Voyage : IVoyage CarName=model.CarName, HumanName=model.HumanName, CompanyName=model.CompanyName, - - + RouteName = model.RouteName + }; } @@ -90,9 +95,15 @@ public partial class Voyage : IVoyage RouteId = RouteId, DateStart = DateStart, DateEnd = DateEnd, - CarName = CarName, - HumanName = HumanName, - CompanyName = CompanyName, - + CarName = Car?.Model, + HumanName = Human?.Name, + CompanyName = Company?.Title, + RouteName = Route?.PlaceStartNavigation?.Title + " - " + Route?.PlaceStartNavigation?.Title, + Km = Route?.Length + }; + public VoyageVM GetReportVM => new() + { + HumanName=Human?.Name, + Km=Km }; } diff --git a/Subd/Forms/Form1.Designer.cs b/Subd/Forms/Form1.Designer.cs deleted file mode 100644 index 8bc8bcd..0000000 --- a/Subd/Forms/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Forms -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Subd/Forms/Form1.cs b/Subd/Forms/Form1.cs deleted file mode 100644 index d7a7cd9..0000000 --- a/Subd/Forms/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Forms -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Subd/Forms/Form1.resx b/Subd/Forms/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Subd/Forms/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/Subd/Forms/FormCar.Designer.cs b/Subd/Forms/FormCar.Designer.cs new file mode 100644 index 0000000..b9c0bbd --- /dev/null +++ b/Subd/Forms/FormCar.Designer.cs @@ -0,0 +1,197 @@ +namespace Forms +{ + partial class FormCar + { + /// + /// 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.ModelLabel = new System.Windows.Forms.Label(); + this.ModelTextBox = new System.Windows.Forms.TextBox(); + this.CostLabel = new System.Windows.Forms.Label(); + this.TonnageTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.Statuslabel = new System.Windows.Forms.Label(); + this.StatuscomboBox = new System.Windows.Forms.ComboBox(); + this.TenPlusbutton = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.Timelabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ModelLabel + // + this.ModelLabel.AutoSize = true; + this.ModelLabel.Location = new System.Drawing.Point(22, 20); + this.ModelLabel.Name = "ModelLabel"; + this.ModelLabel.Size = new System.Drawing.Size(84, 20); + this.ModelLabel.TabIndex = 0; + this.ModelLabel.Text = "Название: "; + // + // ModelTextBox + // + this.ModelTextBox.Location = new System.Drawing.Point(103, 16); + this.ModelTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ModelTextBox.Name = "ModelTextBox"; + this.ModelTextBox.Size = new System.Drawing.Size(238, 27); + this.ModelTextBox.TabIndex = 2; + // + // CostLabel + // + this.CostLabel.AutoSize = true; + this.CostLabel.Location = new System.Drawing.Point(22, 71); + this.CostLabel.Name = "CostLabel"; + this.CostLabel.Size = new System.Drawing.Size(144, 20); + this.CostLabel.TabIndex = 3; + this.CostLabel.Text = "Грузоподъемность:"; + // + // TonnageTextBox + // + this.TonnageTextBox.Location = new System.Drawing.Point(22, 95); + this.TonnageTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.TonnageTextBox.Name = "TonnageTextBox"; + this.TonnageTextBox.Size = new System.Drawing.Size(238, 27); + this.TonnageTextBox.TabIndex = 4; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(165, 218); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(268, 218); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // Statuslabel + // + this.Statuslabel.AutoSize = true; + this.Statuslabel.Location = new System.Drawing.Point(22, 147); + this.Statuslabel.Name = "Statuslabel"; + this.Statuslabel.Size = new System.Drawing.Size(59, 20); + this.Statuslabel.TabIndex = 7; + this.Statuslabel.Text = "Статус: "; + // + // StatuscomboBox + // + this.StatuscomboBox.FormattingEnabled = true; + this.StatuscomboBox.Location = new System.Drawing.Point(123, 147); + this.StatuscomboBox.Name = "StatuscomboBox"; + this.StatuscomboBox.Size = new System.Drawing.Size(151, 28); + this.StatuscomboBox.TabIndex = 8; + this.StatuscomboBox.SelectedIndexChanged += new System.EventHandler(this.StatuscomboBox_SelectedIndexChanged); + // + // TenPlusbutton + // + this.TenPlusbutton.Location = new System.Drawing.Point(32, 218); + this.TenPlusbutton.Name = "TenPlusbutton"; + this.TenPlusbutton.Size = new System.Drawing.Size(94, 29); + this.TenPlusbutton.TabIndex = 9; + this.TenPlusbutton.Text = "+10"; + this.TenPlusbutton.UseVisualStyleBackColor = true; + this.TenPlusbutton.Click += new System.EventHandler(this.TenPlusbutton_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(32, 265); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(116, 20); + this.label1.TabIndex = 10; + this.label1.Text = "Среднее время"; + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(154, 265); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(17, 20); + this.Timelabel.TabIndex = 11; + this.Timelabel.Text = "0"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(177, 265); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(27, 20); + this.label2.TabIndex = 12; + this.label2.Text = "мс"; + // + // FormCar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 305); + this.Controls.Add(this.label2); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.label1); + this.Controls.Add(this.TenPlusbutton); + this.Controls.Add(this.StatuscomboBox); + this.Controls.Add(this.Statuslabel); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.TonnageTextBox); + this.Controls.Add(this.CostLabel); + this.Controls.Add(this.ModelTextBox); + this.Controls.Add(this.ModelLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCar"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ModelLabel; + private TextBox ModelTextBox; + private Label CostLabel; + private TextBox TonnageTextBox; + private Button SaveButton; + private Button ButtonCancel; + private Label Statuslabel; + private ComboBox StatuscomboBox; + private Button TenPlusbutton; + private Label label1; + private Label Timelabel; + private Label label2; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormCar.cs b/Subd/Forms/FormCar.cs new file mode 100644 index 0000000..2cff7ba --- /dev/null +++ b/Subd/Forms/FormCar.cs @@ -0,0 +1,143 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormCar : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + private readonly IStatusLogic _statusLogic; + private int? _id; + public int Id { set { _id = value; } } + string[] ModelName = { "Ural", "Vaz", "T","Min","IS" }; + string[] ModelType = { "V", "34", "Ultra", "Patriot", "30" }; + string[] ModelCat = { "300", "KV", "Cross", "New", "Speed" }; + Random rndModel = new Random(); + public FormCar(ILogger logger, ICarLogic logic, IStatusLogic statusLogic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _statusLogic = statusLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + var statuses = _statusLogic.ReadList(); + if (statuses != null) + { + StatuscomboBox.DisplayMember = "Title"; + StatuscomboBox.ValueMember = "Id"; + StatuscomboBox.DataSource = statuses; + StatuscomboBox.SelectedItem = null; + if (_id.HasValue) + { + _logger.LogInformation("Получение car"); + + var view = _logic.ReadElement(new CarSM + { + Id = _id.Value + }); + + if (view != null) + { + ModelTextBox.Text = view.Model; + TonnageTextBox.Text = view.Tonnage.ToString(); + } + } + + + + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения car"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(ModelTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new CarBM + { + Id = _id ?? 0, + Model = ModelTextBox.Text, + Tonnage = Convert.ToInt32(TonnageTextBox.Text), + StatusId = Convert.ToInt32(StatuscomboBox.SelectedValue), + StatusTitle = StatuscomboBox.Text, + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void StatuscomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void TenPlusbutton_Click(object sender, EventArgs e) + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + for(int i = 0; i < 10; i++) + { + var model = new CarBM + { + Id = _id ?? 0, + Model = ModelName[rndModel.Next(0,4)] + ModelType[rndModel.Next(0, 4)] + ModelCat[rndModel.Next(0, 4)], + Tonnage = rndModel.Next(30,100), + StatusId = rndModel.Next(1,3), + StatusTitle = "", + }; + + var operationResult = _logic.Create(model); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormCar.resx b/Subd/Forms/FormCar.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormCar.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormCars.Designer.cs b/Subd/Forms/FormCars.Designer.cs new file mode 100644 index 0000000..8b3ebd3 --- /dev/null +++ b/Subd/Forms/FormCars.Designer.cs @@ -0,0 +1,121 @@ +namespace Forms +{ + partial class FormCars + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 16); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(669, 95); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(137, 55); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCars"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormCars_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormCars.cs b/Subd/Forms/FormCars.cs new file mode 100644 index 0000000..cfb515b --- /dev/null +++ b/Subd/Forms/FormCars.cs @@ -0,0 +1,121 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; + +namespace Forms +{ + public partial class FormCars : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + + public FormCars(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCars_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["Model"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["StatusId"].Visible = false; + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + + if (service is FormCar form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + + if (service is FormCar form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 CarBM + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Subd/Forms/FormCars.resx b/Subd/Forms/FormCars.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormCars.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormCompanies.Designer.cs b/Subd/Forms/FormCompanies.Designer.cs new file mode 100644 index 0000000..764fc73 --- /dev/null +++ b/Subd/Forms/FormCompanies.Designer.cs @@ -0,0 +1,122 @@ +namespace Forms +{ + partial class FormCompanies + + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 16); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(669, 95); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(137, 55); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCars"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormCompanys_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormCompanies.cs b/Subd/Forms/FormCompanies.cs new file mode 100644 index 0000000..e306785 --- /dev/null +++ b/Subd/Forms/FormCompanies.cs @@ -0,0 +1,121 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; + +namespace Forms +{ + public partial class FormCompanies : Form + { + private readonly ILogger _logger; + private readonly ICompanyLogic _logic; + + public FormCompanies(ILogger logger, ICompanyLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCompanys_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["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["StatusId"].Visible = false; + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCompany)); + + if (service is FormCompany form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCompany)); + + if (service is FormCompany form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 CompanyBM + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Subd/Forms/FormCompanies.resx b/Subd/Forms/FormCompanies.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormCompanies.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormCompany.Designer.cs b/Subd/Forms/FormCompany.Designer.cs new file mode 100644 index 0000000..5ced8f1 --- /dev/null +++ b/Subd/Forms/FormCompany.Designer.cs @@ -0,0 +1,162 @@ +namespace Forms +{ + partial class FormCompany + { + /// + /// 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.ComponentNameLabel = new System.Windows.Forms.Label(); + this.TitleTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.Statuslabel = new System.Windows.Forms.Label(); + this.StatuscomboBox = new System.Windows.Forms.ComboBox(); + this.AddTenbutton = new System.Windows.Forms.Button(); + this.Timelabel = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(84, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "Название: "; + // + // TitleTextBox + // + this.TitleTextBox.Location = new System.Drawing.Point(103, 16); + this.TitleTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.TitleTextBox.Name = "TitleTextBox"; + this.TitleTextBox.Size = new System.Drawing.Size(238, 27); + this.TitleTextBox.TabIndex = 2; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(132, 127); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(255, 127); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // Statuslabel + // + this.Statuslabel.AutoSize = true; + this.Statuslabel.Location = new System.Drawing.Point(22, 79); + this.Statuslabel.Name = "Statuslabel"; + this.Statuslabel.Size = new System.Drawing.Size(59, 20); + this.Statuslabel.TabIndex = 7; + this.Statuslabel.Text = "Статус: "; + // + // StatuscomboBox + // + this.StatuscomboBox.FormattingEnabled = true; + this.StatuscomboBox.Location = new System.Drawing.Point(117, 79); + this.StatuscomboBox.Name = "StatuscomboBox"; + this.StatuscomboBox.Size = new System.Drawing.Size(151, 28); + this.StatuscomboBox.TabIndex = 8; + this.StatuscomboBox.SelectedIndexChanged += new System.EventHandler(this.StatuscomboBox_SelectedIndexChanged); + // + // AddTenbutton + // + this.AddTenbutton.Location = new System.Drawing.Point(12, 129); + this.AddTenbutton.Name = "AddTenbutton"; + this.AddTenbutton.Size = new System.Drawing.Size(94, 29); + this.AddTenbutton.TabIndex = 9; + this.AddTenbutton.Text = "+10"; + this.AddTenbutton.UseVisualStyleBackColor = true; + this.AddTenbutton.Click += new System.EventHandler(this.AddTenbutton_Click); + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(12, 197); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(17, 20); + this.Timelabel.TabIndex = 10; + this.Timelabel.Text = "0"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(35, 197); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(29, 20); + this.label1.TabIndex = 11; + this.label1.Text = "mc"; + // + // FormCompany + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 240); + this.Controls.Add(this.label1); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.AddTenbutton); + this.Controls.Add(this.StatuscomboBox); + this.Controls.Add(this.Statuslabel); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.TitleTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCompany"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox TitleTextBox; + private Button SaveButton; + private Button ButtonCancel; + private Label Statuslabel; + private ComboBox StatuscomboBox; + private Button AddTenbutton; + private Label Timelabel; + private Label label1; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormCompany.cs b/Subd/Forms/FormCompany.cs new file mode 100644 index 0000000..1636bf2 --- /dev/null +++ b/Subd/Forms/FormCompany.cs @@ -0,0 +1,150 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormCompany : Form + { + private readonly ILogger _logger; + private readonly ICompanyLogic _logic; + private readonly IStatusLogic _statusLogic; + private int? _id; + string[] ModelName = { "Ural1 ", "Vaz2 ", "T3 ", "Mi4 ", "IS5 ", "Mash1 ", "Zavod1 ", "Tech2 ", "Patriot2 ", "Indastris3 " }; + string[] ModelType = { "Mash1 ", "Zavod1 ", "Tech2 ", "Patriot2 ", "Indastris3 ", "Mash21 ", "Zavod21 ", "Tech22 ", "Patriot22 ", "Indastris23 " }; + string[] ModelCat = { "Msk", "DD", "Pet", "Uls", "World" }; + Random rndModel = new Random(); + public int Id { set { _id = value; } } + + public FormCompany(ILogger logger, ICompanyLogic logic, IStatusLogic statusLogic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _statusLogic = statusLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + var statuses = _statusLogic.ReadList(); + if (statuses != null) + { + StatuscomboBox.DisplayMember = "Title"; + StatuscomboBox.ValueMember = "Id"; + StatuscomboBox.DataSource = statuses; + StatuscomboBox.SelectedItem = null; + if (_id.HasValue) + { + _logger.LogInformation("Получение company"); + + var view = _logic.ReadElement(new CompanySM + { + Id = _id.Value + }); + + if (view != null) + { + TitleTextBox.Text = view.Title; + + } + } + + + + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения company"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TitleTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new CompanyBM + { + Id = _id ?? 0, + Title = TitleTextBox.Text, + + StatusId = Convert.ToInt32(StatuscomboBox.SelectedValue), + StatusTitle = StatuscomboBox.Text, + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void StatuscomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void AddTenbutton_Click(object sender, EventArgs e) + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + try + { + for (int i = 0; i < 10; i++) + { + var model = new CompanyBM + { + Id = _id ?? 0, + Title = ModelName[rndModel.Next(0, 9)] + ModelType[rndModel.Next(0, 9)] + ModelCat[rndModel.Next(0, 4)], + StatusId = rndModel.Next(1, 3), + StatusTitle = "", + }; + + var operationResult = _logic.Create(model); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + }catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormCompany.resx b/Subd/Forms/FormCompany.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormCompany.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormHuman.Designer.cs b/Subd/Forms/FormHuman.Designer.cs new file mode 100644 index 0000000..195afba --- /dev/null +++ b/Subd/Forms/FormHuman.Designer.cs @@ -0,0 +1,185 @@ +namespace Forms +{ + partial class FormHuman + { + /// + /// 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.ComponentNameLabel = new System.Windows.Forms.Label(); + this.FIOTextBox = new System.Windows.Forms.TextBox(); + this.CostLabel = new System.Windows.Forms.Label(); + this.PhoneTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.Statuslabel = new System.Windows.Forms.Label(); + this.StatuscomboBox = new System.Windows.Forms.ComboBox(); + this.AddTenbutton = new System.Windows.Forms.Button(); + this.Timelabel = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(49, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "ФИО: "; + // + // FIOTextBox + // + this.FIOTextBox.Location = new System.Drawing.Point(103, 16); + this.FIOTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.FIOTextBox.Name = "FIOTextBox"; + this.FIOTextBox.Size = new System.Drawing.Size(238, 27); + this.FIOTextBox.TabIndex = 2; + // + // CostLabel + // + this.CostLabel.AutoSize = true; + this.CostLabel.Location = new System.Drawing.Point(22, 71); + this.CostLabel.Name = "CostLabel"; + this.CostLabel.Size = new System.Drawing.Size(72, 20); + this.CostLabel.TabIndex = 3; + this.CostLabel.Text = "Телефон:"; + // + // PhoneTextBox + // + this.PhoneTextBox.Location = new System.Drawing.Point(22, 95); + this.PhoneTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.PhoneTextBox.Name = "PhoneTextBox"; + this.PhoneTextBox.Size = new System.Drawing.Size(238, 27); + this.PhoneTextBox.TabIndex = 4; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(141, 218); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(255, 218); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // Statuslabel + // + this.Statuslabel.AutoSize = true; + this.Statuslabel.Location = new System.Drawing.Point(22, 147); + this.Statuslabel.Name = "Statuslabel"; + this.Statuslabel.Size = new System.Drawing.Size(59, 20); + this.Statuslabel.TabIndex = 7; + this.Statuslabel.Text = "Статус: "; + // + // StatuscomboBox + // + this.StatuscomboBox.FormattingEnabled = true; + this.StatuscomboBox.Location = new System.Drawing.Point(123, 147); + this.StatuscomboBox.Name = "StatuscomboBox"; + this.StatuscomboBox.Size = new System.Drawing.Size(151, 28); + this.StatuscomboBox.TabIndex = 8; + this.StatuscomboBox.SelectedIndexChanged += new System.EventHandler(this.StatuscomboBox_SelectedIndexChanged); + // + // AddTenbutton + // + this.AddTenbutton.Location = new System.Drawing.Point(12, 218); + this.AddTenbutton.Name = "AddTenbutton"; + this.AddTenbutton.Size = new System.Drawing.Size(94, 29); + this.AddTenbutton.TabIndex = 9; + this.AddTenbutton.Text = "+10"; + this.AddTenbutton.UseVisualStyleBackColor = true; + this.AddTenbutton.Click += new System.EventHandler(this.AddTenbutton_Click); + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(12, 289); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(17, 20); + this.Timelabel.TabIndex = 10; + this.Timelabel.Text = "0"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(44, 289); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(29, 20); + this.label1.TabIndex = 11; + this.label1.Text = "mc"; + // + // FormHuman + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 318); + this.Controls.Add(this.label1); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.AddTenbutton); + this.Controls.Add(this.StatuscomboBox); + this.Controls.Add(this.Statuslabel); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.PhoneTextBox); + this.Controls.Add(this.CostLabel); + this.Controls.Add(this.FIOTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormHuman"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox FIOTextBox; + private Label CostLabel; + private TextBox PhoneTextBox; + private Button SaveButton; + private Button ButtonCancel; + private Label Statuslabel; + private ComboBox StatuscomboBox; + private Button AddTenbutton; + private Label Timelabel; + private Label label1; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormHuman.cs b/Subd/Forms/FormHuman.cs new file mode 100644 index 0000000..c28dd33 --- /dev/null +++ b/Subd/Forms/FormHuman.cs @@ -0,0 +1,143 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormHuman : Form + { + private readonly ILogger _logger; + private readonly IHumanLogic _logic; + private readonly IStatusLogic _statusLogic; + private int? _id; + public int Id { set { _id = value; } } + string[] ModelName = { "Vlad", "Dima", "Kyza", "Oleg", "Egor" }; + string[] ModelType = { "Sergeevich", "Olegovich", "Sanich", "Petrovich", "Vladimirovich" }; + string[] ModelCat = { "Popov", "Antoniv", "Lazarev", "Petrov", "Vasilevich" }; + Random rndModel = new Random(); + public FormHuman(ILogger logger, IHumanLogic logic, IStatusLogic statusLogic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _statusLogic = statusLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + var statuses = _statusLogic.ReadList(); + if (statuses != null) + { + StatuscomboBox.DisplayMember = "Title"; + StatuscomboBox.ValueMember = "Id"; + StatuscomboBox.DataSource = statuses; + StatuscomboBox.SelectedItem = null; + if (_id.HasValue) + { + _logger.LogInformation("Получение human"); + + var view = _logic.ReadElement(new HumanSM + { + Id = _id.Value + }); + + if (view != null) + { + FIOTextBox.Text = view.Name; + PhoneTextBox.Text = view.Phone.ToString(); + } + } + + + + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения human"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new HumanBM + { + Id = _id ?? 0, + Name = FIOTextBox.Text, + Phone = PhoneTextBox.Text, + StatusId = Convert.ToInt32(StatuscomboBox.SelectedValue), + StatusTitle = StatuscomboBox.Text, + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void StatuscomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void AddTenbutton_Click(object sender, EventArgs e) + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + for (int i = 0; i < 10; i++) + { + var model = new HumanBM + { + Id = _id ?? 0, + Name = ModelName[rndModel.Next(0, 4)] + ModelType[rndModel.Next(0, 4)] + ModelCat[rndModel.Next(0, 4)], + Phone = "+" + rndModel.Next(30, 100) + rndModel.Next(30, 100)+ rndModel.Next(30, 100)+ rndModel.Next(30, 100) + rndModel.Next(30, 100)+ rndModel.Next(0, 10), + StatusId = rndModel.Next(1, 3), + StatusTitle = "", + }; + + var operationResult = _logic.Create(model); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormHuman.resx b/Subd/Forms/FormHuman.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormHuman.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormHumans.Designer.cs b/Subd/Forms/FormHumans.Designer.cs new file mode 100644 index 0000000..495fcc6 --- /dev/null +++ b/Subd/Forms/FormHumans.Designer.cs @@ -0,0 +1,121 @@ +namespace Forms +{ + partial class FormHumans + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 16); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(669, 95); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(137, 55); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCars"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormHumans_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormHumans.cs b/Subd/Forms/FormHumans.cs new file mode 100644 index 0000000..6a1fd56 --- /dev/null +++ b/Subd/Forms/FormHumans.cs @@ -0,0 +1,121 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; + +namespace Forms +{ + public partial class FormHumans : Form + { + private readonly ILogger _logger; + private readonly IHumanLogic _logic; + + public FormHumans(ILogger logger, IHumanLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormHumans_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["StatusId"].Visible = false; + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormHuman)); + + if (service is FormHuman form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormHuman)); + + if (service is FormHuman form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 HumanBM + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Subd/Forms/FormHumans.resx b/Subd/Forms/FormHumans.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormHumans.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormMain.Designer.cs b/Subd/Forms/FormMain.Designer.cs new file mode 100644 index 0000000..aa60293 --- /dev/null +++ b/Subd/Forms/FormMain.Designer.cs @@ -0,0 +1,202 @@ +namespace Forms +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.MenuStrip = new System.Windows.Forms.MenuStrip(); + this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компанииToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.маршрутыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.местаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.водителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компанииToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.CreateOrderButton = new System.Windows.Forms.Button(); + this.UpdateListButton = new System.Windows.Forms.Button(); + this.MenuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // MenuStrip + // + this.MenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.СправочникиToolStripMenuItem, + this.отчетыToolStripMenuItem}); + this.MenuStrip.Location = new System.Drawing.Point(0, 0); + this.MenuStrip.Name = "MenuStrip"; + this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); + this.MenuStrip.Size = new System.Drawing.Size(989, 30); + this.MenuStrip.TabIndex = 0; + this.MenuStrip.Text = "menuStrip1"; + // + // СправочникиToolStripMenuItem + // + this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ИзделияToolStripMenuItem, + this.КомпонентыToolStripMenuItem, + this.компанииToolStripMenuItem, + this.маршрутыToolStripMenuItem, + this.местаToolStripMenuItem}); + this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; + this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.СправочникиToolStripMenuItem.Text = "Cправочники"; + // + // ИзделияToolStripMenuItem + // + this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.ИзделияToolStripMenuItem.Text = "Машины"; + this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.МашиныToolStripMenuItem_Click); + // + // КомпонентыToolStripMenuItem + // + this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.КомпонентыToolStripMenuItem.Text = "Водители"; + this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.ВодителиToolStripMenuItem_Click); + // + // компанииToolStripMenuItem + // + this.компанииToolStripMenuItem.Name = "компанииToolStripMenuItem"; + this.компанииToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.компанииToolStripMenuItem.Text = "Компании"; + this.компанииToolStripMenuItem.Click += new System.EventHandler(this.компанииToolStripMenuItem_Click); + // + // маршрутыToolStripMenuItem + // + this.маршрутыToolStripMenuItem.Name = "маршрутыToolStripMenuItem"; + this.маршрутыToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.маршрутыToolStripMenuItem.Text = "Маршруты"; + this.маршрутыToolStripMenuItem.Click += new System.EventHandler(this.маршрутыToolStripMenuItem_Click); + // + // местаToolStripMenuItem + // + this.местаToolStripMenuItem.Name = "местаToolStripMenuItem"; + this.местаToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.местаToolStripMenuItem.Text = "Места"; + this.местаToolStripMenuItem.Click += new System.EventHandler(this.местаToolStripMenuItem_Click); + // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.водителиToolStripMenuItem, + this.компанииToolStripMenuItem1}); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // водителиToolStripMenuItem + // + this.водителиToolStripMenuItem.Name = "водителиToolStripMenuItem"; + this.водителиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.водителиToolStripMenuItem.Text = "Водители"; + this.водителиToolStripMenuItem.Click += new System.EventHandler(this.водителиToolStripMenuItem_Click_1); + // + // компанииToolStripMenuItem1 + // + this.компанииToolStripMenuItem1.Name = "компанииToolStripMenuItem1"; + this.компанииToolStripMenuItem1.Size = new System.Drawing.Size(224, 26); + this.компанииToolStripMenuItem1.Text = "Компании"; + this.компанииToolStripMenuItem1.Click += new System.EventHandler(this.компанииToolStripMenuItem1_Click); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(0, 36); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(825, 561); + this.DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + this.CreateOrderButton.Location = new System.Drawing.Point(831, 199); + this.CreateOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CreateOrderButton.Name = "CreateOrderButton"; + this.CreateOrderButton.Size = new System.Drawing.Size(143, 44); + this.CreateOrderButton.TabIndex = 2; + this.CreateOrderButton.Text = "Создать заказ"; + this.CreateOrderButton.UseVisualStyleBackColor = true; + this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click); + // + // UpdateListButton + // + this.UpdateListButton.Location = new System.Drawing.Point(832, 349); + this.UpdateListButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateListButton.Name = "UpdateListButton"; + this.UpdateListButton.Size = new System.Drawing.Size(143, 44); + this.UpdateListButton.TabIndex = 6; + this.UpdateListButton.Text = "Обновить список"; + this.UpdateListButton.UseVisualStyleBackColor = true; + this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(989, 600); + this.Controls.Add(this.UpdateListButton); + this.Controls.Add(this.CreateOrderButton); + this.Controls.Add(this.DataGridView); + this.Controls.Add(this.MenuStrip); + this.MainMenuStrip = this.MenuStrip; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormMain"; + this.Text = "Автозавод"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.MenuStrip.ResumeLayout(false); + this.MenuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip MenuStrip; + private ToolStripMenuItem СправочникиToolStripMenuItem; + private ToolStripMenuItem ИзделияToolStripMenuItem; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button UpdateListButton; + private ToolStripMenuItem компанииToolStripMenuItem; + private ToolStripMenuItem маршрутыToolStripMenuItem; + private ToolStripMenuItem местаToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem водителиToolStripMenuItem; + private ToolStripMenuItem компанииToolStripMenuItem1; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormMain.cs b/Subd/Forms/FormMain.cs new file mode 100644 index 0000000..b998838 --- /dev/null +++ b/Subd/Forms/FormMain.cs @@ -0,0 +1,152 @@ + +using Contracts.BusinessLogic; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Forms +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IVoyageLogic _voyageLogic; + + + + public FormMain(ILogger logger, IVoyageLogic voyageLogic) + { + InitializeComponent(); + _logger = logger; + _voyageLogic = voyageLogic; + + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка "); + + try + { + var list = _voyageLogic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["HumanId"].Visible = false; + DataGridView.Columns["CarId"].Visible = false; + DataGridView.Columns["CompanyId"].Visible = false; + DataGridView.Columns["RouteId"].Visible = false; + DataGridView.Columns["RouteName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Id"].Visible = false; + } + + _logger.LogInformation("Загрузка "); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ВодителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormHumans)); + + if (service is FormHumans form) + { + form.ShowDialog(); + } + } + + private void МашиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCars)); + + if (service is FormCars form) + { + form.ShowDialog(); + } + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormVoyage)); + + if (service is FormVoyage form) + { + form.ShowDialog(); + LoadData(); + } + } + + + + private void UpdateListButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void компанииToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCompanies)); + + if (service is FormCompanies form) + { + form.ShowDialog(); + } + } + + private void маршрутыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoutes)); + + if (service is FormRoutes form) + { + form.ShowDialog(); + } + } + + private void местаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPlaces)); + + if (service is FormPlaces form) + { + form.ShowDialog(); + } + } + + private void водителиToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportHumans)); + + if (service is FormReportHumans form) + { + form.ShowDialog(); + } + } + + private void компанииToolStripMenuItem1_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportCompanies)); + + if (service is FormReportCompanies form) + { + form.ShowDialog(); + } + } + } +} diff --git a/Subd/Forms/FormMain.resx b/Subd/Forms/FormMain.resx new file mode 100644 index 0000000..a694815 --- /dev/null +++ b/Subd/Forms/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Subd/Forms/FormPlace.Designer.cs b/Subd/Forms/FormPlace.Designer.cs new file mode 100644 index 0000000..607b02d --- /dev/null +++ b/Subd/Forms/FormPlace.Designer.cs @@ -0,0 +1,138 @@ +namespace Forms +{ + partial class FormPlace + { + /// + /// 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.ComponentNameLabel = new System.Windows.Forms.Label(); + this.TitleTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.AddTenbutton = new System.Windows.Forms.Button(); + this.Timelabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(84, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "Название: "; + // + // TitleTextBox + // + this.TitleTextBox.Location = new System.Drawing.Point(103, 16); + this.TitleTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.TitleTextBox.Name = "TitleTextBox"; + this.TitleTextBox.Size = new System.Drawing.Size(238, 27); + this.TitleTextBox.TabIndex = 2; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(137, 101); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(255, 101); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // AddTenbutton + // + this.AddTenbutton.Location = new System.Drawing.Point(22, 101); + this.AddTenbutton.Name = "AddTenbutton"; + this.AddTenbutton.Size = new System.Drawing.Size(94, 29); + this.AddTenbutton.TabIndex = 7; + this.AddTenbutton.Text = "+10"; + this.AddTenbutton.UseVisualStyleBackColor = true; + this.AddTenbutton.Click += new System.EventHandler(this.AddTenbutton_Click); + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(22, 172); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(17, 20); + this.Timelabel.TabIndex = 8; + this.Timelabel.Text = "0"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(45, 172); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 20); + this.label2.TabIndex = 9; + this.label2.Text = "mc"; + // + // FormPlace + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 201); + this.Controls.Add(this.label2); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.AddTenbutton); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.TitleTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormPlace"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox TitleTextBox; + private Button SaveButton; + private Button ButtonCancel; + private Button AddTenbutton; + private Label Timelabel; + private Label label2; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormPlace.cs b/Subd/Forms/FormPlace.cs new file mode 100644 index 0000000..920e2d9 --- /dev/null +++ b/Subd/Forms/FormPlace.cs @@ -0,0 +1,131 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormPlace : Form + { + private readonly ILogger _logger; + private readonly IPlaceLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + string[] ModelName = { "Vlad", "Dimit", "Mos", "Volg", "Peter" }; + string[] ModelType = { "grad", "sk", "vl", "orod", "burg" }; + string[] ModelCat = { "-severniy", "-sanct", "", "-kamchatskiy", "Yar" }; + Random rndModel = new Random(); + public FormPlace(ILogger logger, IPlaceLogic placeLogic) + { + InitializeComponent(); + _logger = logger; + _logic = placeLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + + if (_id.HasValue) + { + _logger.LogInformation("Получение company"); + + var view = _logic.ReadElement(new PlaceSM + { + Id = _id.Value + }); + + if (view != null) + { + TitleTextBox.Text = view.Title; + + } + } + + + + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения company"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TitleTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new PlaceBM + { + Id = _id ?? 0, + Title = TitleTextBox.Text, + + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void PlacecomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void AddTenbutton_Click(object sender, EventArgs e) + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + for (int i = 0; i < 10; i++) + { + var model = new PlaceBM + { + Id = _id ?? 0, + Title = ModelName[rndModel.Next(0, 4)] + ModelType[rndModel.Next(0, 4)] + ModelCat[rndModel.Next(0, 4)], + + }; + + var operationResult = _logic.Create(model); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormPlace.resx b/Subd/Forms/FormPlace.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormPlace.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormPlaces.Designer.cs b/Subd/Forms/FormPlaces.Designer.cs new file mode 100644 index 0000000..fe14703 --- /dev/null +++ b/Subd/Forms/FormPlaces.Designer.cs @@ -0,0 +1,122 @@ +namespace Forms +{ + partial class FormPlaces + + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 16); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(669, 95); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(137, 55); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCars"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormPlacees_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormPlaces.cs b/Subd/Forms/FormPlaces.cs new file mode 100644 index 0000000..9ff9ed5 --- /dev/null +++ b/Subd/Forms/FormPlaces.cs @@ -0,0 +1,121 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; + +namespace Forms +{ + public partial class FormPlaces : Form + { + private readonly ILogger _logger; + private readonly IPlaceLogic _logic; + + public FormPlaces(ILogger logger, IPlaceLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormPlacees_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["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPlace)); + + if (service is FormPlace form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPlace)); + + if (service is FormPlace form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 PlaceBM + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Subd/Forms/FormPlaces.resx b/Subd/Forms/FormPlaces.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormPlaces.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormReportCompanies.Designer.cs b/Subd/Forms/FormReportCompanies.Designer.cs new file mode 100644 index 0000000..2dc9581 --- /dev/null +++ b/Subd/Forms/FormReportCompanies.Designer.cs @@ -0,0 +1,78 @@ +namespace Forms +{ + partial class FormReportCompanies + { + /// + /// 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.timelabel = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(696, 660); + this.DataGridView.TabIndex = 0; + // + // timelabel + // + this.timelabel.AutoSize = true; + this.timelabel.Location = new System.Drawing.Point(742, 436); + this.timelabel.Name = "timelabel"; + this.timelabel.Size = new System.Drawing.Size(50, 20); + this.timelabel.TabIndex = 1; + this.timelabel.Text = "label1"; + // + // FormReportCompanies + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.timelabel); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormReportCompanies"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormReportHumans_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView DataGridView; + private Label timelabel; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormReportCompanies.cs b/Subd/Forms/FormReportCompanies.cs new file mode 100644 index 0000000..452ad2f --- /dev/null +++ b/Subd/Forms/FormReportCompanies.cs @@ -0,0 +1,64 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormReportCompanies : Form + { + private readonly ILogger _logger; + private readonly IVoyageLogic _logic; + + public FormReportCompanies(ILogger logger, IVoyageLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportHumans_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + var list = _logic.GetCompanysPath(); + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + timelabel.Text = time.ToString(); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + } +} diff --git a/Subd/Forms/FormReportCompanies.resx b/Subd/Forms/FormReportCompanies.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormReportCompanies.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormReportHumans.Designer.cs b/Subd/Forms/FormReportHumans.Designer.cs new file mode 100644 index 0000000..8e93c3a --- /dev/null +++ b/Subd/Forms/FormReportHumans.Designer.cs @@ -0,0 +1,78 @@ +namespace Forms +{ + partial class FormReportHumans + { + /// + /// 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.Timelabel = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(696, 660); + this.DataGridView.TabIndex = 0; + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(732, 414); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(50, 20); + this.Timelabel.TabIndex = 1; + this.Timelabel.Text = "label1"; + // + // FormReportHumans + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormReportHumans"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormReportHumans_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView DataGridView; + private Label Timelabel; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormReportHumans.cs b/Subd/Forms/FormReportHumans.cs new file mode 100644 index 0000000..522508e --- /dev/null +++ b/Subd/Forms/FormReportHumans.cs @@ -0,0 +1,64 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormReportHumans : Form + { + private readonly ILogger _logger; + private readonly IVoyageLogic _logic; + + public FormReportHumans(ILogger logger, IVoyageLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportHumans_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + var list = _logic.GetTopDrivers(); + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + } +} diff --git a/Subd/Forms/FormReportHumans.resx b/Subd/Forms/FormReportHumans.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormReportHumans.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormRoute.Designer.cs b/Subd/Forms/FormRoute.Designer.cs new file mode 100644 index 0000000..fbdc81a --- /dev/null +++ b/Subd/Forms/FormRoute.Designer.cs @@ -0,0 +1,184 @@ +namespace Forms +{ + partial class FormRoute + { + /// + /// 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.ComponentNameLabel = new System.Windows.Forms.Label(); + this.LengthTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.Statuslabel = new System.Windows.Forms.Label(); + this.StartcomboBox = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.EndcomboBox = new System.Windows.Forms.ComboBox(); + this.AddTenbutton = new System.Windows.Forms.Button(); + this.Timelabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(13, 145); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(91, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "Расстояние:"; + // + // LengthTextBox + // + this.LengthTextBox.Location = new System.Drawing.Point(103, 145); + this.LengthTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.LengthTextBox.Name = "LengthTextBox"; + this.LengthTextBox.Size = new System.Drawing.Size(238, 27); + this.LengthTextBox.TabIndex = 2; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(159, 218); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(268, 218); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // Statuslabel + // + this.Statuslabel.AutoSize = true; + this.Statuslabel.Location = new System.Drawing.Point(12, 19); + this.Statuslabel.Name = "Statuslabel"; + this.Statuslabel.Size = new System.Drawing.Size(68, 20); + this.Statuslabel.TabIndex = 7; + this.Statuslabel.Text = "Точка 1: "; + // + // StartcomboBox + // + this.StartcomboBox.FormattingEnabled = true; + this.StartcomboBox.Location = new System.Drawing.Point(103, 19); + this.StartcomboBox.Name = "StartcomboBox"; + this.StartcomboBox.Size = new System.Drawing.Size(151, 28); + this.StartcomboBox.TabIndex = 8; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 85); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(68, 20); + this.label1.TabIndex = 9; + this.label1.Text = "Точка 2: "; + // + // EndcomboBox + // + this.EndcomboBox.FormattingEnabled = true; + this.EndcomboBox.Location = new System.Drawing.Point(103, 85); + this.EndcomboBox.Name = "EndcomboBox"; + this.EndcomboBox.Size = new System.Drawing.Size(151, 28); + this.EndcomboBox.TabIndex = 10; + // + // AddTenbutton + // + this.AddTenbutton.Location = new System.Drawing.Point(33, 218); + this.AddTenbutton.Name = "AddTenbutton"; + this.AddTenbutton.Size = new System.Drawing.Size(94, 29); + this.AddTenbutton.TabIndex = 11; + this.AddTenbutton.Text = "+10"; + this.AddTenbutton.UseVisualStyleBackColor = true; + this.AddTenbutton.Click += new System.EventHandler(this.AddTenbutton_Click); + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(30, 278); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(17, 20); + this.Timelabel.TabIndex = 12; + this.Timelabel.Text = "0"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(54, 278); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 20); + this.label2.TabIndex = 13; + this.label2.Text = "mc"; + // + // FormRoute + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 325); + this.Controls.Add(this.label2); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.AddTenbutton); + this.Controls.Add(this.EndcomboBox); + this.Controls.Add(this.label1); + this.Controls.Add(this.StartcomboBox); + this.Controls.Add(this.Statuslabel); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.LengthTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormRoute"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox LengthTextBox; + private Button SaveButton; + private Button ButtonCancel; + private Label Statuslabel; + private ComboBox StartcomboBox; + private Label label1; + private ComboBox EndcomboBox; + private Button AddTenbutton; + private Label Timelabel; + private Label label2; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormRoute.cs b/Subd/Forms/FormRoute.cs new file mode 100644 index 0000000..748bf1d --- /dev/null +++ b/Subd/Forms/FormRoute.cs @@ -0,0 +1,142 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormRoute : Form + { + private readonly ILogger _logger; + private readonly IRouteLogic _logic; + private readonly IPlaceLogic _placeLogic; + private int? _id; + public int Id { set { _id = value; } } + Random rndModel = new Random(); + public FormRoute(ILogger logger, IRouteLogic logic, IPlaceLogic placeLogic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _placeLogic = placeLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + var places = _placeLogic.ReadList(null); + var places2 = _placeLogic.ReadList(null); + if (places != null && places2 !=null) + { + StartcomboBox.DisplayMember = "Title"; + StartcomboBox.ValueMember = "Id"; + StartcomboBox.DataSource = places; + StartcomboBox.SelectedItem = null; + EndcomboBox.DisplayMember = "Title"; + EndcomboBox.ValueMember = "Id"; + EndcomboBox.DataSource = places2; + EndcomboBox.SelectedItem = null; + if (_id.HasValue) + { + _logger.LogInformation("Получение route"); + + var view = _logic.ReadElement(new RouteSM + { + Id = _id.Value + }); + + if (view != null) + { + + LengthTextBox.Text = view.Length.ToString(); + } + } + + + + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения route"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new RouteBM + { + Id = _id ?? 0, + + Length = Convert.ToInt32(LengthTextBox.Text), + PlaceStart = Convert.ToInt32(StartcomboBox.SelectedValue), + PlaceEnd = Convert.ToInt32(EndcomboBox.SelectedValue), + Title = StartcomboBox.Text + " - " + EndcomboBox.Text + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void PlacecomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void AddTenbutton_Click(object sender, EventArgs e) + { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + for (int i = 0; i < 10; i++) + { + var model = new RouteBM + { + Id = _id ?? 0, + Length = rndModel.Next(10,200), + PlaceStart = rndModel.Next(1, _placeLogic.ReadList(null).Count), + PlaceEnd = rndModel.Next(1, _placeLogic.ReadList(null).Count), + + }; + + var operationResult = _logic.Create(model); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormRoute.resx b/Subd/Forms/FormRoute.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormRoute.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormRoutes.Designer.cs b/Subd/Forms/FormRoutes.Designer.cs new file mode 100644 index 0000000..1f292f2 --- /dev/null +++ b/Subd/Forms/FormRoutes.Designer.cs @@ -0,0 +1,107 @@ +namespace Forms +{ + partial class FormRoutes + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 100); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormRoutes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormRoutes"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormRoutes_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormRoutes.cs b/Subd/Forms/FormRoutes.cs new file mode 100644 index 0000000..7e7b7dc --- /dev/null +++ b/Subd/Forms/FormRoutes.cs @@ -0,0 +1,122 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; + +namespace Forms +{ + public partial class FormRoutes : Form + { + private readonly ILogger _logger; + private readonly IRouteLogic _logic; + + public FormRoutes(ILogger logger, IRouteLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormRoutes_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["PlaceStart"].Visible = false; + DataGridView.Columns["PlaceEnd"].Visible = false; + DataGridView.Columns["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoute)); + + if (service is FormRoute form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoute)); + + if (service is FormRoute form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 RouteBM + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Subd/Forms/FormRoutes.resx b/Subd/Forms/FormRoutes.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormRoutes.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormStatus.Designer.cs b/Subd/Forms/FormStatus.Designer.cs new file mode 100644 index 0000000..e6eabff --- /dev/null +++ b/Subd/Forms/FormStatus.Designer.cs @@ -0,0 +1,101 @@ +namespace Forms +{ + partial class FormStatus + { + /// + /// 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.ComponentNameLabel = new System.Windows.Forms.Label(); + this.TitleTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(84, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "Название: "; + // + // TitleTextBox + // + this.TitleTextBox.Location = new System.Drawing.Point(103, 16); + this.TitleTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.TitleTextBox.Name = "TitleTextBox"; + this.TitleTextBox.Size = new System.Drawing.Size(238, 27); + this.TitleTextBox.TabIndex = 2; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(22, 125); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(255, 125); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormStatus + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 193); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.TitleTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormStatus"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox TitleTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormStatus.cs b/Subd/Forms/FormStatus.cs new file mode 100644 index 0000000..c4666bf --- /dev/null +++ b/Subd/Forms/FormStatus.cs @@ -0,0 +1,107 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; + +namespace Forms +{ + public partial class FormStatus : Form + { + private readonly ILogger _logger; + private readonly IStatusLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormStatus(ILogger logger, IStatusLogic statusLogic) + { + InitializeComponent(); + _logger = logger; + _logic = statusLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + + if (_id.HasValue) + { + _logger.LogInformation("Получение company"); + + var view = _logic.ReadElement(new StatusSM + { + Id = _id.Value + }); + + if (view != null) + { + TitleTextBox.Text = view.Title; + + } + } + + + + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения company"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TitleTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new StatusBM + { + Id = _id ?? 0, + Title = TitleTextBox.Text, + + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void StatuscomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormStatus.resx b/Subd/Forms/FormStatus.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormStatus.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormStatuses.Designer.cs b/Subd/Forms/FormStatuses.Designer.cs new file mode 100644 index 0000000..628baec --- /dev/null +++ b/Subd/Forms/FormStatuses.Designer.cs @@ -0,0 +1,122 @@ +namespace Forms +{ + partial class FormStatuses + + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 16); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(669, 95); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(137, 55); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCars"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormStatuses_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormStatuses.cs b/Subd/Forms/FormStatuses.cs new file mode 100644 index 0000000..2c983cf --- /dev/null +++ b/Subd/Forms/FormStatuses.cs @@ -0,0 +1,121 @@ +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 Contracts.BusinessLogic; +using Contracts.BindingModels; + +namespace Forms +{ + public partial class FormStatuses : Form + { + private readonly ILogger _logger; + private readonly IStatusLogic _logic; + + public FormStatuses(ILogger logger, IStatusLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormStatuses_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + + _logger.LogInformation("Загрузка машин"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStatus)); + + if (service is FormStatus form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStatus)); + + if (service is FormStatus form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 StatusBM + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Subd/Forms/FormStatuses.resx b/Subd/Forms/FormStatuses.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormStatuses.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/FormVoyage.Designer.cs b/Subd/Forms/FormVoyage.Designer.cs new file mode 100644 index 0000000..6b78056 --- /dev/null +++ b/Subd/Forms/FormVoyage.Designer.cs @@ -0,0 +1,250 @@ +namespace Forms +{ + partial class FormVoyage + { + /// + /// 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.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.Statuslabel = new System.Windows.Forms.Label(); + this.RoutecomboBox = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.HumancomboBox = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.CarcomboBox = new System.Windows.Forms.ComboBox(); + this.CompanycomboBox = new System.Windows.Forms.ComboBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.AddTenbutton = new System.Windows.Forms.Button(); + this.Timelabel = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(138, 325); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(259, 325); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // Statuslabel + // + this.Statuslabel.AutoSize = true; + this.Statuslabel.Location = new System.Drawing.Point(12, 24); + this.Statuslabel.Name = "Statuslabel"; + this.Statuslabel.Size = new System.Drawing.Size(80, 20); + this.Statuslabel.TabIndex = 7; + this.Statuslabel.Text = "Маршрут: "; + // + // RoutecomboBox + // + this.RoutecomboBox.FormattingEnabled = true; + this.RoutecomboBox.Location = new System.Drawing.Point(115, 24); + this.RoutecomboBox.Name = "RoutecomboBox"; + this.RoutecomboBox.Size = new System.Drawing.Size(151, 28); + this.RoutecomboBox.TabIndex = 8; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 65); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(67, 20); + this.label1.TabIndex = 9; + this.label1.Text = "Водила: "; + // + // HumancomboBox + // + this.HumancomboBox.FormattingEnabled = true; + this.HumancomboBox.Location = new System.Drawing.Point(115, 65); + this.HumancomboBox.Name = "HumancomboBox"; + this.HumancomboBox.Size = new System.Drawing.Size(151, 28); + this.HumancomboBox.TabIndex = 10; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 115); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 20); + this.label2.TabIndex = 11; + this.label2.Text = "Машина: "; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 170); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(88, 20); + this.label3.TabIndex = 12; + this.label3.Text = "Компания: "; + // + // CarcomboBox + // + this.CarcomboBox.FormattingEnabled = true; + this.CarcomboBox.Location = new System.Drawing.Point(115, 115); + this.CarcomboBox.Name = "CarcomboBox"; + this.CarcomboBox.Size = new System.Drawing.Size(151, 28); + this.CarcomboBox.TabIndex = 13; + // + // CompanycomboBox + // + this.CompanycomboBox.FormattingEnabled = true; + this.CompanycomboBox.Location = new System.Drawing.Point(112, 170); + this.CompanycomboBox.Name = "CompanycomboBox"; + this.CompanycomboBox.Size = new System.Drawing.Size(151, 28); + this.CompanycomboBox.TabIndex = 14; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(12, 238); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(52, 20); + this.label4.TabIndex = 15; + this.label4.Text = "Выезд"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(12, 282); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(43, 20); + this.label5.TabIndex = 16; + this.label5.Text = "Срок"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(95, 231); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(250, 27); + this.dateTimePickerFrom.TabIndex = 17; + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(95, 277); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(250, 27); + this.dateTimePickerTo.TabIndex = 18; + // + // AddTenbutton + // + this.AddTenbutton.Location = new System.Drawing.Point(26, 327); + this.AddTenbutton.Name = "AddTenbutton"; + this.AddTenbutton.Size = new System.Drawing.Size(94, 29); + this.AddTenbutton.TabIndex = 19; + this.AddTenbutton.Text = "+10"; + this.AddTenbutton.UseVisualStyleBackColor = true; + this.AddTenbutton.Click += new System.EventHandler(this.AddTenbutton_Click); + // + // Timelabel + // + this.Timelabel.AutoSize = true; + this.Timelabel.Location = new System.Drawing.Point(26, 389); + this.Timelabel.Name = "Timelabel"; + this.Timelabel.Size = new System.Drawing.Size(17, 20); + this.Timelabel.TabIndex = 20; + this.Timelabel.Text = "0"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(50, 389); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(29, 20); + this.label6.TabIndex = 21; + this.label6.Text = "mc"; + // + // FormVoyage + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 433); + this.Controls.Add(this.label6); + this.Controls.Add(this.Timelabel); + this.Controls.Add(this.AddTenbutton); + this.Controls.Add(this.dateTimePickerTo); + this.Controls.Add(this.dateTimePickerFrom); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.CompanycomboBox); + this.Controls.Add(this.CarcomboBox); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.HumancomboBox); + this.Controls.Add(this.label1); + this.Controls.Add(this.RoutecomboBox); + this.Controls.Add(this.Statuslabel); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormVoyage"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button SaveButton; + private Button ButtonCancel; + private Label Statuslabel; + private ComboBox RoutecomboBox; + private Label label1; + private ComboBox HumancomboBox; + private Label label2; + private Label label3; + private ComboBox CarcomboBox; + private ComboBox CompanycomboBox; + private Label label4; + private Label label5; + private DateTimePicker dateTimePickerFrom; + private DateTimePicker dateTimePickerTo; + private Button AddTenbutton; + private Label Timelabel; + private Label label6; + } +} \ No newline at end of file diff --git a/Subd/Forms/FormVoyage.cs b/Subd/Forms/FormVoyage.cs new file mode 100644 index 0000000..e33d354 --- /dev/null +++ b/Subd/Forms/FormVoyage.cs @@ -0,0 +1,173 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogic; +using Contracts.SearchModel; +using DataBase; +using Microsoft.Extensions.Logging; +using NLog.LayoutRenderers; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Forms +{ + public partial class FormVoyage : Form + { + private readonly ILogger _logger; + private readonly IVoyageLogic _logic; + private readonly IRouteLogic _routeLogic; + private readonly ICarLogic _carLogic; + private readonly IHumanLogic _humanLogic; + private readonly ICompanyLogic _companyLogic; + private int? _id; + public int Id { set { _id = value; } } + Random rndModel = new Random(); + public FormVoyage(ILogger logger, IVoyageLogic logic, IRouteLogic routeLogic, ICarLogic carLogic, IHumanLogic humanLogic, ICompanyLogic companyLogic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _routeLogic = routeLogic; + _carLogic = carLogic; + _humanLogic = humanLogic; + _companyLogic = companyLogic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + + try + { + var routes = _routeLogic.ReadList(null); + if (routes != null) + { + RoutecomboBox.DisplayMember = "Title"; + RoutecomboBox.ValueMember = "Id"; + RoutecomboBox.DataSource = routes; + RoutecomboBox.SelectedItem = null; + } + var cars = _carLogic.ReadList(new CarSM { StatusId = 1}); + if (cars != null) + { + CarcomboBox.DisplayMember = "Model"; + CarcomboBox.ValueMember = "Id"; + CarcomboBox.DataSource = cars; + CarcomboBox.SelectedItem = null; + } + var companys = _companyLogic.ReadList(new CompanySM { StatusId =1}); + if (companys != null) + { + CompanycomboBox.DisplayMember = "Title"; + CompanycomboBox.ValueMember = "Id"; + CompanycomboBox.DataSource = companys; + CompanycomboBox.SelectedItem = null; + } + var humans = _humanLogic.ReadList(new HumanSM { StatusId=1}); + if (humans != null) + { + HumancomboBox.DisplayMember = "Name"; + HumancomboBox.ValueMember = "Id"; + HumancomboBox.DataSource = humans; + HumancomboBox.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения voyage"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + + } + + private void SaveButton_Click(object sender, EventArgs e) + { + + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new VoyageBM + { + Id = _id ?? 0, + RouteId = Convert.ToInt32(RoutecomboBox.SelectedValue), + CarId = Convert.ToInt32(CarcomboBox.SelectedValue), + HumanId = Convert.ToInt32(HumancomboBox.SelectedValue), + CompanyId = Convert.ToInt32(CompanycomboBox.SelectedValue), + DateStart = DateOnly.FromDateTime(DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc)), + DateEnd = DateOnly.FromDateTime(DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc)), + }; + + var operationResult = _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + //MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + //DialogResult = DialogResult.OK; + //Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void PlacecomboBox_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void AddTenbutton_Click(object sender, EventArgs e) + { + Stopwatch stopwatch = new Stopwatch(); + try + { + + stopwatch.Start(); + for (int i = 0; i < 10; i++) + { + var dateNew = new DateOnly(rndModel.Next(2000, 2023), rndModel.Next(1, 13), rndModel.Next(1, 30)); + var dateEnd = dateNew.AddMonths(rndModel.Next(1, 30)); + var model = new VoyageBM + { + Id = _id ?? 0, + CarId = rndModel.Next(1, _carLogic.ReadList(null).Count), + CompanyId = rndModel.Next(1, _companyLogic.ReadList(null).Count), + HumanId = rndModel.Next(1, _humanLogic.ReadList(null).Count), + RouteId = rndModel.Next(1, _routeLogic.ReadList(null).Count), + DateStart = dateNew, + DateEnd = dateEnd + + }; + + var operationResult = _logic.Create(model); + } + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + } + catch(Exception ex) + { + stopwatch.Stop(); + var time = stopwatch.ElapsedMilliseconds; + Timelabel.Text = time.ToString(); + MessageBox.Show(ex.Message); + + } + } + } +} \ No newline at end of file diff --git a/Subd/Forms/FormVoyage.resx b/Subd/Forms/FormVoyage.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Subd/Forms/FormVoyage.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Subd/Forms/Forms.csproj b/Subd/Forms/Forms.csproj index ffa6873..c178c26 100644 --- a/Subd/Forms/Forms.csproj +++ b/Subd/Forms/Forms.csproj @@ -18,4 +18,51 @@ + + + + + + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + \ No newline at end of file diff --git a/Subd/Forms/Program.cs b/Subd/Forms/Program.cs index f2ce145..19bd1d8 100644 --- a/Subd/Forms/Program.cs +++ b/Subd/Forms/Program.cs @@ -1,3 +1,9 @@ + +using BusinessBL.BusinessBL; +using BusinessLogic.BusinessLogic; +using Contracts.BusinessLogic; +using Contracts.Storage; +using DataBase.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -21,7 +27,7 @@ namespace Forms var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -30,6 +36,39 @@ namespace Forms 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(); + 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/Subd/Subd/Models/ICar.cs b/Subd/Subd/Models/ICar.cs index a16983a..0522711 100644 --- a/Subd/Subd/Models/ICar.cs +++ b/Subd/Subd/Models/ICar.cs @@ -11,7 +11,7 @@ namespace DataModels.Models string Model { get; } int Tonnage { get; } int? StatusId { get; } - string StatusTitle { get; } + string? StatusTitle { get; } } } diff --git a/Subd/Subd/Models/ICompany.cs b/Subd/Subd/Models/ICompany.cs index f7f366f..9947f4c 100644 --- a/Subd/Subd/Models/ICompany.cs +++ b/Subd/Subd/Models/ICompany.cs @@ -10,6 +10,6 @@ namespace DataModels.Models { string Title { get; } int? StatusId { get; } - string StatusTitle { get; } + string? StatusTitle { get; } } } diff --git a/Subd/Subd/Models/IHuman.cs b/Subd/Subd/Models/IHuman.cs index a3d1dfe..e1f6e21 100644 --- a/Subd/Subd/Models/IHuman.cs +++ b/Subd/Subd/Models/IHuman.cs @@ -11,6 +11,6 @@ namespace DataModels.Models string Name { get; } string Phone { get; } int? StatusId { get; } - string StatusTitle { get; } + string? StatusTitle { get; } } } diff --git a/Subd/Subd/Models/IVoyage.cs b/Subd/Subd/Models/IVoyage.cs index df99058..43f6908 100644 --- a/Subd/Subd/Models/IVoyage.cs +++ b/Subd/Subd/Models/IVoyage.cs @@ -9,11 +9,11 @@ namespace DataModels.Models public interface IVoyage : IId { int? CarId { get; } - string CarName { get; } + string? CarName { get; } int? HumanId { get; } - string HumanName { get; } + string? HumanName { get; } int? CompanyId { get; } - string CompanyName { get; } + string? CompanyName { get; } int? RouteId { get; } DateOnly? DateStart { get; } DateOnly? DateEnd { get; }