diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index f1639fc..9de2964 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopView", "B EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{C6F64BD8-13F0-459D-AC7E-DFEDBE30C09A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{99CF0DD1-5945-426C-9343-461A72204B74}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {C6F64BD8-13F0-459D-AC7E-DFEDBE30C09A}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6F64BD8-13F0-459D-AC7E-DFEDBE30C09A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6F64BD8-13F0-459D-AC7E-DFEDBE30C09A}.Release|Any CPU.Build.0 = Release|Any CPU + {99CF0DD1-5945-426C-9343-461A72204B74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99CF0DD1-5945-426C-9343-461A72204B74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99CF0DD1-5945-426C-9343-461A72204B74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99CF0DD1-5945-426C-9343-461A72204B74}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index dde6f18..672c48b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -70,31 +70,30 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics } private void CheckModel(OrderBindingModel model, bool withParams = true) { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.ManufactureId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор компьютера", nameof(model.ManufactureId)); - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество компьютеров в заказе должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); - } - _logger.LogInformation("Order. OrderId: {Id}.Sum: {Sum}. ManufactureId: {ManufactureId}", model.Id, model.Sum, model.ManufactureId); - } - - private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) - { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ManufactureId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор компьютера", nameof(model.ManufactureId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество компьютеров в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderId: {Id}.Sum: {Sum}. ManufactureId: {ManufactureId}", model.Id, model.Sum, model.ManufactureId); + } + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (viewModel == null) { @@ -131,5 +130,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics } return true; } - } + } +} } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index 450d630..e10724e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -111,7 +111,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - if (count <= 0) + if (count < 0) { throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } @@ -157,7 +157,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics } if (count <= 0) { - throw new ArgumentException("Количество поездок должно быть больше 0", nameof(count)); + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } _logger.LogInformation("AddManufactures. ShopName:{ShopName}. Id:{Id}", model.ManufactureName, model.Id); var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ListManufacture.Select(x => x.Value.Item2).Sum()).Sum(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs new file mode 100644 index 0000000..776fac0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs @@ -0,0 +1,23 @@ +using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace BlacksmithWorkshopDatabaseImplement +{ + public class BlacksmithWorkshopDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=BlacksmithWorkshopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet<Component> Components { set; get; } + public virtual DbSet<Manufacture> Manufactures { set; get; } + public virtual DbSet<ManufactureComponent> ManufactureComponents { set; get; } + public virtual DbSet<Order> Orders { set; get; } + public virtual DbSet<Shop> Shops { set; get; } + public virtual DbSet<ShopManufacture> ListManufacture { set; get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj new file mode 100644 index 0000000..190cb8e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj @@ -0,0 +1,23 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4"> + <PrivateAssets>all</PrivateAssets> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + </PackageReference> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" /> + <ProjectReference Include="..\BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj" /> + </ItemGroup> + +</Project> diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e071b83 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs @@ -0,0 +1,74 @@ +using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + public List<ComponentViewModel> GetFullList() + { + using var context = new BlacksmithWorkshopDatabase(); + return context.Components.Select(x => x.GetViewModel).ToList(); + } + public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel).ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new BlacksmithWorkshopDatabase(); + context.Components.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var component = context.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Components.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..1f7c23d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,86 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ManufactureStorage : IManufactureStorage + { + public List<ManufactureViewModel> GetFullList() + { + using var context = new BlacksmithWorkshopDatabase(); + return context.Manufactures.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); + } + public List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return new(); + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Manufactures.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.ManufactureName.Contains(model.ManufactureName)).ToList() + .Select(x => x.GetViewModel).ToList(); + } + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && + !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Manufactures.Include(x => x.Components).ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; + } + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var newManufacture = Manufacture.Create(context, model); + if (newManufacture == null) + { + return null; + } + context.Manufactures.Add(newManufacture); + context.SaveChanges(); + return newManufacture.GetViewModel; + } + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var manufacture = context.Manufactures.FirstOrDefault(rec => + rec.Id == model.Id); + if (manufacture == null) + { + return null; + } + manufacture.Update(model); + context.SaveChanges(); + manufacture.UpdateComponents(context, model); + transaction.Commit(); + return manufacture.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var element = context.Manufactures.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Manufactures.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..8f0489a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,73 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.EntityFrameworkCore; +using BlacksmithWorkshopDatabaseImplement.Models; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Orders.Include(x => x.Manufacture).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + context.Orders.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Orders.Include(x => x.Manufacture).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + public List<OrderViewModel> GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Orders.Include(x => x.Manufacture).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + public List<OrderViewModel> GetFullList() + { + using var context = new BlacksmithWorkshopDatabase(); + return context.Orders.Include(x => x.Manufacture).Select(x => x.GetViewModel).ToList(); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + using var context = new BlacksmithWorkshopDatabase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + return context.Orders.Include(x => x.Manufacture).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.Orders.Include(x => x.Manufacture).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..dc78840 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,149 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StorageContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopDataModels.Models; + + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List<ShopViewModel> GetFullList() + { + using var context = new BlacksmithWorkshopDatabase(); + return context.Shops + .Include(x => x.Manufactures) + .ThenInclude(x => x.Manufacture) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List<ShopViewModel> GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Shops + .Include(x => x.Manufactures) + .ThenInclude(x => x.Manufacture) + .Where(x => x.ShopName.Contains(model.ShopName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDatabase(); + return context.Shops + .Include(x => x.Manufactures) + .ThenInclude(x => x.Manufacture) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdateManufactures(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new BlacksmithWorkshopDatabase(); + var element = context.Shops + .Include(x => x.Manufactures) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + public bool SellManufactures(IManufactureModel model, int count) + { + using var context = new BlacksmithWorkshopDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shops = context.ListManufacture + .Include(x => x.Shop) + .ToList() + .Where(rec => rec.ManufactureId == model.Id); + if (shops == null) + { + return false; + } + foreach (var shop in shops) + { + if (shop.Count < count) + { + shop.Count = 0; + count -= shop.Count; + } + else + { + shop.Count = shop.Count - count; + count -= count; + } + if (count == 0) + { + context.SaveChanges(); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230319151606_InitMigration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230319151606_InitMigration.Designer.cs new file mode 100644 index 0000000..b5af788 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230319151606_InitMigration.Designer.cs @@ -0,0 +1,171 @@ +// <auto-generated /> +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDatabase))] + [Migration("20230319151606_InitMigration")] + partial class InitMigration + { + /// <inheritdoc /> + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<double>("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<double>("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("ComponentId") + .HasColumnType("int"); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<DateTime>("DateCreate") + .HasColumnType("datetime2"); + + b.Property<DateTime?>("DateImplement") + .HasColumnType("datetime2"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.Property<int>("Status") + .HasColumnType("int"); + + b.Property<double>("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230319151606_InitMigration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230319151606_InitMigration.cs new file mode 100644 index 0000000..b69af54 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230319151606_InitMigration.cs @@ -0,0 +1,125 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + /// <inheritdoc /> + public partial class InitMigration : Migration + { + /// <inheritdoc /> + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false), + Cost = table.Column<double>(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Manufactures", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureName = table.Column<string>(type: "nvarchar(max)", nullable: false), + Price = table.Column<double>(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Manufactures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ManufactureComponents", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column<int>(type: "int", nullable: false), + ComponentId = table.Column<int>(type: "int", nullable: false), + Count = table.Column<int>(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ManufactureComponents", x => x.Id); + table.ForeignKey( + name: "FK_ManufactureComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ManufactureComponents_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column<int>(type: "int", nullable: false), + Count = table.Column<int>(type: "int", nullable: false), + Sum = table.Column<double>(type: "float", nullable: false), + Status = table.Column<int>(type: "int", nullable: false), + DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false), + DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ComponentId", + table: "ManufactureComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ManufactureId", + table: "ManufactureComponents", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ManufactureId", + table: "Orders", + column: "ManufactureId"); + } + + /// <inheritdoc /> + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ManufactureComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Manufactures"); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230402133234_Initial.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230402133234_Initial.Designer.cs new file mode 100644 index 0000000..a960b51 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230402133234_Initial.Designer.cs @@ -0,0 +1,248 @@ +// <auto-generated /> +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDatabase))] + [Migration("20230402133234_Initial")] + partial class Initial + { + /// <inheritdoc /> + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<double>("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<double>("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("ComponentId") + .HasColumnType("int"); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<DateTime>("DateCreate") + .HasColumnType("datetime2"); + + b.Property<DateTime?>("DateImplement") + .HasColumnType("datetime2"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.Property<int>("Status") + .HasColumnType("int"); + + b.Property<double>("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<int>("Capacity") + .HasColumnType("int"); + + b.Property<DateTime>("DateOpening") + .HasColumnType("datetime2"); + + b.Property<string>("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.Property<int>("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ListManufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany() + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Manufactures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Manufactures"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230402133234_Initial.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230402133234_Initial.cs new file mode 100644 index 0000000..9ddd6e3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230402133234_Initial.cs @@ -0,0 +1,184 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + /// <inheritdoc /> + public partial class Initial : Migration + { + /// <inheritdoc /> + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false), + Cost = table.Column<double>(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Manufactures", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureName = table.Column<string>(type: "nvarchar(max)", nullable: false), + Price = table.Column<double>(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Manufactures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false), + Address = table.Column<string>(type: "nvarchar(max)", nullable: false), + DateOpening = table.Column<DateTime>(type: "datetime2", nullable: false), + Capacity = table.Column<int>(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ManufactureComponents", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column<int>(type: "int", nullable: false), + ComponentId = table.Column<int>(type: "int", nullable: false), + Count = table.Column<int>(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ManufactureComponents", x => x.Id); + table.ForeignKey( + name: "FK_ManufactureComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ManufactureComponents_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column<int>(type: "int", nullable: false), + Count = table.Column<int>(type: "int", nullable: false), + Sum = table.Column<double>(type: "float", nullable: false), + Status = table.Column<int>(type: "int", nullable: false), + DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false), + DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ListManufacture", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopId = table.Column<int>(type: "int", nullable: false), + ManufactureId = table.Column<int>(type: "int", nullable: false), + Count = table.Column<int>(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ListManufacture", x => x.Id); + table.ForeignKey( + name: "FK_ListManufacture_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ListManufacture_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ListManufacture_ManufactureId", + table: "ListManufacture", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_ListManufacture_ShopId", + table: "ListManufacture", + column: "ShopId"); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ComponentId", + table: "ManufactureComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ManufactureId", + table: "ManufactureComponents", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ManufactureId", + table: "Orders", + column: "ManufactureId"); + } + + /// <inheritdoc /> + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ListManufacture"); + + migrationBuilder.DropTable( + name: "ManufactureComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Shops"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Manufactures"); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs new file mode 100644 index 0000000..abdd86a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs @@ -0,0 +1,245 @@ +// <auto-generated /> +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDatabase))] + partial class BlacksmithWorkshopDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<double>("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<double>("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("ComponentId") + .HasColumnType("int"); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<DateTime>("DateCreate") + .HasColumnType("datetime2"); + + b.Property<DateTime?>("DateImplement") + .HasColumnType("datetime2"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.Property<int>("Status") + .HasColumnType("int"); + + b.Property<double>("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<int>("Capacity") + .HasColumnType("int"); + + b.Property<DateTime>("DateOpening") + .HasColumnType("datetime2"); + + b.Property<string>("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<int>("Count") + .HasColumnType("int"); + + b.Property<int>("ManufactureId") + .HasColumnType("int"); + + b.Property<int>("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ListManufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany() + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Manufactures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Manufactures"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs new file mode 100644 index 0000000..cc61a50 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs @@ -0,0 +1,56 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + [Required] + public string ComponentName { get; private set; } = string.Empty; + [Required] + public double Cost { get; set; } + [ForeignKey("ComponentId")] + public virtual List<ManufactureComponent> ManufactureComponents { get; set; } = new(); + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component Create(ComponentViewModel model) + { + return new Component + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs new file mode 100644 index 0000000..08ed6ec --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs @@ -0,0 +1,91 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class Manufacture : IManufactureModel + { + public int Id { get; set; } + [Required] + public string ManufactureName { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + private Dictionary<int, (IComponentModel, int)>? _manufactureComponents = null; + [NotMapped] + public Dictionary<int, (IComponentModel, int)> ManufactureComponents + { + get + { + if (_manufactureComponents == null) + { + _manufactureComponents = Components + .ToDictionary(recPC => recPC.ComponentId, recPC => + (recPC.Component as IComponentModel, recPC.Count)); + } + return _manufactureComponents; + } + } + [ForeignKey("ManufactureId")] + public virtual List<ManufactureComponent> Components { get; set; } = new(); + [ForeignKey("ManufactureId")] + public virtual List<Order> Orders { get; set; } = new(); + public static Manufacture Create(BlacksmithWorkshopDatabase context, ManufactureBindingModel model) + { + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + Components = model.ManufactureComponents.Select(x => new ManufactureComponent + { + Component = context.Components.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(ManufactureBindingModel model) + { + ManufactureName = model.ManufactureName; + Price = model.Price; + } + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureComponents = ManufactureComponents + }; + public void UpdateComponents(BlacksmithWorkshopDatabase context, ManufactureBindingModel model) + { + var manufactureComponents = context.ManufactureComponents.Where(rec => + rec.ManufactureId == model.Id).ToList(); + if (manufactureComponents != null && manufactureComponents.Count > 0) + { // удалили те, которых нет в модели + context.ManufactureComponents.RemoveRange(manufactureComponents.Where(rec + => !model.ManufactureComponents.ContainsKey(rec.ComponentId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateComponent in manufactureComponents) + { + updateComponent.Count = model.ManufactureComponents[updateComponent.ComponentId].Item2; + model.ManufactureComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var manufacture = context.Manufactures.First(x => x.Id == Id); + foreach (var pc in model.ManufactureComponents) + { + context.ManufactureComponents.Add(new ManufactureComponent + { + Manufacture = manufacture, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _manufactureComponents = null; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs new file mode 100644 index 0000000..327592d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class ManufactureComponent + { + public int Id { get; set; } + [Required] + public int ManufactureId { get; set; } + [Required] + public int ComponentId { get; set; } + [Required] + public int Count { get; set; } + public virtual Component Component { get; set; } = new(); + public virtual Manufacture Manufacture { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..0090640 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -0,0 +1,68 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; set; } + [Required] + public int ManufactureId { get; set; } + [Required] + public int Count { get; set; } + [Required] + public double Sum { get; set; } + [Required] + public OrderStatus Status { get; set; } + [Required] + public DateTime DateCreate { get; set; } + public DateTime? DateImplement { get; set; } + public virtual Manufacture Manufacture { get; set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ManufactureId = ManufactureId, + ManufactureName = Manufacture.ManufactureName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..5b4fc5e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + [Required] + public string ShopName { get; set; } = string.Empty; + [Required] + public string Address { get; set; } = string.Empty; + [Required] + public DateTime DateOpening { get; set; } + [Required] + public int Capacity { get; set; } + private Dictionary<int, (IManufactureModel, int)>? _listManufacture = null; + [NotMapped] + public Dictionary<int, (IManufactureModel, int)> ListManufacture + { + get + { + if (_listManufacture == null) + { + _listManufacture = Manufactures.ToDictionary(recST => recST.ManufactureId, recST => (recST.Manufacture as IManufactureModel, recST.Count)); + } + return _listManufacture; + } + } + [ForeignKey("ShopId")] + public virtual List<ShopManufacture> Manufactures { get; set; } = new(); + public static Shop Create(BlacksmithWorkshopDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + Capacity = model.Capacity, + Manufactures = model.ListManufacture.Select(x => new ShopManufacture + { + Manufacture = context.Manufactures.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + Capacity = model.Capacity; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + Capacity = Capacity, + ListManufacture = ListManufacture + }; + public void UpdateManufactures(BlacksmithWorkshopDatabase context, ShopBindingModel model) + { + var shopManufactures = context.ListManufacture.Where(rec => rec.ShopId == model.Id).ToList(); + if (shopManufactures != null && ListManufacture.Count > 0) + { // удалили те, которых нет в модели + context.ListManufacture.RemoveRange(shopManufactures.Where(rec => !model.ListManufacture.ContainsKey(rec.ManufactureId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateManufacture in shopManufactures) + { + updateManufacture.Count = model.ListManufacture[updateManufacture.ManufactureId].Item2; + model.ListManufacture.Remove(updateManufacture.ManufactureId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var st in model.ListManufacture) + { + context.ListManufacture.Add(new ShopManufacture + { + Shop = shop, + Manufacture = context.Manufactures.First(x => x.Id == st.Key), + Count = st.Value.Item2 + }); + context.SaveChanges(); + } + _listManufacture = null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs new file mode 100644 index 0000000..d879a02 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class ShopManufacture + { + public int Id { get; set; } + [Required] + public int ShopId { get; set; } + [Required] + public int ManufactureId { get; set; } + [Required] + public int Count { get; set; } + public virtual Manufacture Manufacture { get; set; } = new(); + public virtual Shop Shop { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj index 476b7ee..3cf23aa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj @@ -9,13 +9,18 @@ </PropertyGroup> <ItemGroup> + <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4"> + <PrivateAssets>all</PrivateAssets> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + </PackageReference> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> - <PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" /> + <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\BlacksmithListImplement\BlacksmithWorkshopListImplement.csproj" /> <ProjectReference Include="..\BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj" /> + <ProjectReference Include="..\BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj" /> <ProjectReference Include="..\BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj" /> </ItemGroup> diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs index 63793fa..3c05a8b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs @@ -55,7 +55,7 @@ namespace BlacksmithWorkshopView }); if (manufacture == null) { - throw new Exception("Изделие не найдено. Дополнительная информация в логах."); + throw new Exception("Поездка не найдена. Дополнительная информация в логах."); } var operationResult = _shopLogic.SellManufactures( model: manufacture, diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs index 8591dbd..e860cd7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs @@ -1,212 +1,220 @@ namespace BlacksmithWorkshopView { - partial class FormShop - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; + partial class FormShop + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - buttonSave = new Button(); - buttonCancel = new Button(); - textBoxAddress = new TextBox(); - labelTime = new Label(); - labelAddress = new Label(); - dataGridView = new DataGridView(); - ColumnID = new DataGridViewTextBoxColumn(); - ColumnManufactureName = new DataGridViewTextBoxColumn(); - ColumnCount = new DataGridViewTextBoxColumn(); - labelShop = new Label(); - textBoxShop = new TextBox(); - dateTimePicker = new DateTimePicker(); - numericUpDownCapacity = new NumericUpDown(); - label1 = new Label(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); - SuspendLayout(); - // - // buttonSave - // - buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(578, 302); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(120, 22); - buttonSave.TabIndex = 17; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // buttonCancel - // - buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(703, 302); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(103, 23); - buttonCancel.TabIndex = 16; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(159, 27); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(221, 23); - textBoxAddress.TabIndex = 14; - // - // labelTime - // - labelTime.AutoSize = true; - labelTime.Location = new Point(386, 9); - labelTime.Name = "labelTime"; - labelTime.Size = new Size(87, 15); - labelTime.TabIndex = 13; - labelTime.Text = "Дата открытия"; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(159, 9); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(40, 15); - labelAddress.TabIndex = 12; - labelAddress.Text = "Адрес"; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnManufactureName, ColumnCount }); - dataGridView.Location = new Point(12, 56); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 62; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(794, 240); - dataGridView.TabIndex = 11; - // - // ColumnID - // - ColumnID.HeaderText = "ID"; - ColumnID.MinimumWidth = 8; - ColumnID.Name = "ColumnID"; - ColumnID.Visible = false; - ColumnID.Width = 150; - // - // ColumnManufactureName - // - ColumnManufactureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ColumnManufactureName.HeaderText = "Поездка"; - ColumnManufactureName.MinimumWidth = 8; - ColumnManufactureName.Name = "ColumnManufactureName"; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.MinimumWidth = 8; - ColumnCount.Name = "ColumnCount"; - ColumnCount.Width = 150; - // - // labelShop - // - labelShop.AutoSize = true; - labelShop.Location = new Point(12, 9); - labelShop.Name = "labelShop"; - labelShop.Size = new Size(54, 15); - labelShop.TabIndex = 9; - labelShop.Text = "Магазин"; - // - // textBoxShop - // - textBoxShop.Location = new Point(12, 27); - textBoxShop.Name = "textBoxShop"; - textBoxShop.Size = new Size(141, 23); - textBoxShop.TabIndex = 18; - // - // dateTimePicker - // - dateTimePicker.Location = new Point(386, 27); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(207, 23); - dateTimePicker.TabIndex = 19; - // - // numericUpDownCapacity - // - numericUpDownCapacity.Location = new Point(599, 27); - numericUpDownCapacity.Name = "numericUpDownCapacity"; - numericUpDownCapacity.Size = new Size(207, 23); - numericUpDownCapacity.TabIndex = 20; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(599, 9); - label1.Name = "label1"; - label1.Size = new Size(80, 15); - label1.TabIndex = 21; - label1.Text = "Вместимость"; - // - // FormShop - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(818, 337); - Controls.Add(label1); - Controls.Add(numericUpDownCapacity); - Controls.Add(dateTimePicker); - Controls.Add(textBoxShop); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(textBoxAddress); - Controls.Add(labelTime); - Controls.Add(labelAddress); - Controls.Add(dataGridView); - Controls.Add(labelShop); - Name = "FormShop"; - Text = "Магазин"; - Load += FormShop_Load; - Click += FormShop_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxAddress = new TextBox(); + labelTime = new Label(); + labelAddress = new Label(); + dataGridView = new DataGridView(); + ColumnID = new DataGridViewTextBoxColumn(); + ColumnManufactureName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + labelShop = new Label(); + textBoxShop = new TextBox(); + dateTimePicker = new DateTimePicker(); + numericUpDownCapacity = new NumericUpDown(); + label1 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(661, 403); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(137, 29); + buttonSave.TabIndex = 17; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(803, 403); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(118, 31); + buttonCancel.TabIndex = 16; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(182, 36); + textBoxAddress.Margin = new Padding(3, 4, 3, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(252, 27); + textBoxAddress.TabIndex = 14; + // + // labelTime + // + labelTime.AutoSize = true; + labelTime.Location = new Point(441, 12); + labelTime.Name = "labelTime"; + labelTime.Size = new Size(110, 20); + labelTime.TabIndex = 13; + labelTime.Text = "Дата открытия"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(182, 12); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(51, 20); + labelAddress.TabIndex = 12; + labelAddress.Text = "Адрес"; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnManufactureName, ColumnCount }); + dataGridView.Location = new Point(14, 75); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(907, 320); + dataGridView.TabIndex = 11; + // + // ColumnID + // + ColumnID.HeaderText = "ID"; + ColumnID.MinimumWidth = 8; + ColumnID.Name = "ColumnID"; + ColumnID.Visible = false; + ColumnID.Width = 150; + // + // ColumnManufactureName + // + ColumnManufactureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnManufactureName.HeaderText = "Изделие"; + ColumnManufactureName.MinimumWidth = 8; + ColumnManufactureName.Name = "ColumnManufactureName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 8; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 150; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(14, 12); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(69, 20); + labelShop.TabIndex = 9; + labelShop.Text = "Магазин"; + // + // textBoxShop + // + textBoxShop.Location = new Point(14, 36); + textBoxShop.Margin = new Padding(3, 4, 3, 4); + textBoxShop.Name = "textBoxShop"; + textBoxShop.Size = new Size(161, 27); + textBoxShop.TabIndex = 18; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(441, 36); + dateTimePicker.Margin = new Padding(3, 4, 3, 4); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(236, 27); + dateTimePicker.TabIndex = 19; + // + // numericUpDownCapacity + // + numericUpDownCapacity.Location = new Point(685, 36); + numericUpDownCapacity.Margin = new Padding(3, 4, 3, 4); + numericUpDownCapacity.Name = "numericUpDownCapacity"; + numericUpDownCapacity.Size = new Size(237, 27); + numericUpDownCapacity.TabIndex = 20; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(685, 12); + label1.Name = "label1"; + label1.Size = new Size(100, 20); + label1.TabIndex = 21; + label1.Text = "Вместимость"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(935, 449); + Controls.Add(label1); + Controls.Add(numericUpDownCapacity); + Controls.Add(dateTimePicker); + Controls.Add(textBoxShop); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxAddress); + Controls.Add(labelTime); + Controls.Add(labelAddress); + Controls.Add(dataGridView); + Controls.Add(labelShop); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + Click += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Button buttonSave; - private Button buttonCancel; - private TextBox textBoxAddress; - private Label labelTime; - private Label labelAddress; - private DataGridView dataGridView; - private Label labelShop; - private TextBox textBoxShop; - private DateTimePicker dateTimePicker; - private DataGridViewTextBoxColumn ColumnID; - private DataGridViewTextBoxColumn ColumnManufactureName; - private DataGridViewTextBoxColumn ColumnCount; - private NumericUpDown numericUpDownCapacity; - private Label label1; - } + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxAddress; + private Label labelTime; + private Label labelAddress; + private DataGridView dataGridView; + private Label labelShop; + private TextBox textBoxShop; + private DateTimePicker dateTimePicker; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnManufactureName; + private DataGridViewTextBoxColumn ColumnCount; + private NumericUpDown numericUpDownCapacity; + private Label label1; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs index 054042f..18f9ddf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs @@ -16,118 +16,118 @@ using BlacksmithWorkshopDataModels.Models; namespace BlacksmithWorkshopView { - public partial class FormShop : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - private int? _id; - private Dictionary<int, (IManufactureModel, int)> _shopListManufacture; - public int Id { set { _id = value; } } - public FormShop(ILogger<FormShop> logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _shopListManufacture = new(); - } - private void FormShop_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Загрузка магазина"); - try - { - var view = _logic.ReadElement(new ShopSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxShop.Text = view.ShopName; - textBoxAddress.Text = view.Address; - dateTimePicker.Text = view.DateOpening.ToString(); - numericUpDownCapacity.Value = view.Capacity; - _shopListManufacture = view.ListManufacture ?? new Dictionary<int, (IManufactureModel, int)>(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка магазина"); - try - { - if (_shopListManufacture != null) - { - dataGridView.Rows.Clear(); - foreach (var elem in _shopListManufacture) - { - dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ManufactureName, elem.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + private Dictionary<int, (IManufactureModel, int)> _shopListManufacture; + public int Id { set { _id = value; } } + public FormShop(ILogger<FormShop> logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopListManufacture = new(); + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxShop.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); + numericUpDownCapacity.Value = view.Capacity; + _shopListManufacture = view.ListManufacture ?? new Dictionary<int, (IManufactureModel, int)>(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка магазина"); + try + { + if (_shopListManufacture != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopListManufacture) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ManufactureName, elem.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxShop.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxAddress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (numericUpDownCapacity.Value <= 0) - { - MessageBox.Show("Вместимость должна быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение магазина"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxShop.Text, - Address = textBoxAddress.Text, - DateOpening = dateTimePicker.Value.Date, - Capacity = (int)numericUpDownCapacity.Value, - ListManufacture = _shopListManufacture - }; - 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxShop.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (numericUpDownCapacity.Value <= 0) + { + MessageBox.Show("Вместимость должна быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value.Date, + Capacity = (int)numericUpDownCapacity.Value, + ListManufacture = _shopListManufacture + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs index 50eee25..b793d77 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs @@ -2,7 +2,7 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogics; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StorageContracts; using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopFileImplement.Implements; +using BlacksmithWorkshopDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging;