Начал добавлять формы многие-ко-многим.

This commit is contained in:
Артём Алейкин 2023-05-08 13:51:25 +04:00
parent e52b239c08
commit 16e907326c
51 changed files with 4418 additions and 24 deletions

View File

@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101 VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestaurantView", "RestaurantView\RestaurantView.csproj", "{6784A2BC-8BA1-48A3-992B-DC0EA755469B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestaurantView", "RestaurantView\RestaurantView.csproj", "{6784A2BC-8BA1-48A3-992B-DC0EA755469B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestaurantDataModels", "RestaurantDataModels\RestaurantDataModels.csproj", "{A7888AAA-C1CD-4580-A204-E6720AF49931}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestaurantDataModels", "RestaurantDataModels\RestaurantDataModels.csproj", "{A7888AAA-C1CD-4580-A204-E6720AF49931}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestaurantContracts", "RestaurantContracts\RestaurantContracts.csproj", "{288FB1A3-E6D0-42B2-BA20-463E03F922B4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestaurantContracts", "RestaurantContracts\RestaurantContracts.csproj", "{288FB1A3-E6D0-42B2-BA20-463E03F922B4}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestaurantBusinessLogic", "RestaurantBusinessLogic\RestaurantBusinessLogic.csproj", "{F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestaurantBusinessLogic", "RestaurantBusinessLogic\RestaurantBusinessLogic.csproj", "{F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestaurantDatabaseImplement", "RestaurantDatabaseImplement\RestaurantDatabaseImplement.csproj", "{DFC11A85-B4CA-4315-8CF4-F8B0F53FB7F2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}.Debug|Any CPU.Build.0 = Debug|Any CPU {F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}.Release|Any CPU.ActiveCfg = Release|Any CPU {F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}.Release|Any CPU.Build.0 = Release|Any CPU {F3A63C5F-2BAE-4E69-895C-62FC1A7C556D}.Release|Any CPU.Build.0 = Release|Any CPU
{DFC11A85-B4CA-4315-8CF4-F8B0F53FB7F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFC11A85-B4CA-4315-8CF4-F8B0F53FB7F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFC11A85-B4CA-4315-8CF4-F8B0F53FB7F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFC11A85-B4CA-4315-8CF4-F8B0F53FB7F2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,112 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
using RestaurantContracts.SearchModels;
using RestaurantContracts.StoragesContracts;
using RestaurantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
private readonly IClientStorage _clientStorage;
public ClientLogic(IClientStorage clientStorage)
{
_clientStorage = clientStorage;
}
public bool Create(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
if (_clientStorage.Delete(model) == null)
{
return false;
}
return true;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _clientStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FirstName))
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.FirstName));
}
if (string.IsNullOrEmpty(model.LastName))
{
throw new ArgumentNullException("Нет фамилии клиента", nameof(model.LastName));
}
if (string.IsNullOrEmpty(model.Number))
{
throw new ArgumentNullException("Нет номера клиента", nameof(model.Number));
}
var element = _clientStorage.GetElement(new ClientSearchModel
{
FirstName = model.FirstName,
LastName = model.LastName,
Number = model.Number,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с такими параметрами уже есть");
}
}
}
}

View File

@ -94,6 +94,7 @@ namespace RestaurantBusinessLogic.BusinessLogics
} }
var element = _orderStorage.GetElement(new OrderSearchModel var element = _orderStorage.GetElement(new OrderSearchModel
{ {
ClientId = model.ClientId,
Date = model.Date, Date = model.Date,
}); });
if (element != null && element.Id != model.Id) if (element != null && element.Id != model.Id)

View File

@ -15,7 +15,7 @@ namespace RestaurantContracts.BindingModels
public int Count { get; set; } public int Count { get; set; }
public Dictionary<int, (IProviderModel, int)> ComponentProviders { get; set; } = new(); public Dictionary<int, (IProviderModel, int, DateTime)> ComponentProviders { get; set; } = new();
public int Id { get; set; } public int Id { get; set; }
} }

View File

@ -21,6 +21,6 @@ namespace RestaurantContracts.ViewModels
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }
public Dictionary<int, (IProviderModel, int)> ComponentProviders { get; set; } = new(); public Dictionary<int, (IProviderModel, int, DateTime)> ComponentProviders { get; set; } = new();
} }
} }

View File

@ -14,6 +14,6 @@ namespace RestaurantDataModels.Models
int Count { get; } int Count { get; }
Dictionary<int, (IProviderModel, int)> ComponentProviders { get; } Dictionary<int, (IProviderModel, int, DateTime)> ComponentProviders { get; }
} }
} }

View File

@ -0,0 +1,107 @@
using Microsoft.EntityFrameworkCore;
using RestaurantContracts.BindingModels;
using RestaurantContracts.SearchModels;
using RestaurantContracts.StoragesContracts;
using RestaurantContracts.ViewModels;
using RestaurantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Clients
.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
context.Clients.Remove(element);
return element.GetViewModel;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new RestaurantDatabase();
return context.Clients
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
using var context = new RestaurantDatabase();
if (model.Id.HasValue)
{
return context.Clients
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Number != null)
{
return context.Clients
.Where(x => x.Number == model.Number)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.FirstName != null && model.LastName != null)
{
return context.Clients
.Where(x => (x.FirstName == model.FirstName && x.LastName == model.LastName))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
}
public List<ClientViewModel> GetFullList()
{
using var context = new RestaurantDatabase();
return context.Clients
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new RestaurantDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Clients
.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return element.GetViewModel;
}
}
}

View File

@ -0,0 +1,113 @@
using Microsoft.EntityFrameworkCore;
using RestaurantContracts.BindingModels;
using RestaurantContracts.SearchModels;
using RestaurantContracts.StoragesContracts;
using RestaurantContracts.ViewModels;
using RestaurantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
public List<ComponentViewModel> GetFullList()
{
using var context = new RestaurantDatabase();
return context.Components
.Include(x => x.Providers)
.ThenInclude(x => x.Provider)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
using var context = new RestaurantDatabase();
if (model.Id.HasValue)
{
return context.Components
.Include(x => x.Providers)
.ThenInclude(x => x.ProviderId)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Name != null)
{
return context.Components
.Include(x => x.Providers)
.ThenInclude(x => x.ProviderId)
.Where(x => x.Name == model.Name)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) &&
!model.Id.HasValue)
{
return null;
}
using var context = new RestaurantDatabase();
return context.Components
.Include(x => x.Providers)
.ThenInclude(x => x.Provider)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) &&
x.Name == model.Name) ||
(model.Id.HasValue && x.Id ==
model.Id))
?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
using var context = new RestaurantDatabase();
var newComponent = Component.Create(context, model);
if (newComponent == null)
{
return null;
}
context.Components.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Components
.Include(x => x.Providers)
.ThenInclude(x => x.ProviderId)
.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return GetElement(new ComponentSearchModel { Id = element.Id });
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Components
.Include(x => x.Providers)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Components.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,125 @@
using Microsoft.EntityFrameworkCore;
using RestaurantContracts.BindingModels;
using RestaurantContracts.SearchModels;
using RestaurantContracts.StoragesContracts;
using RestaurantContracts.ViewModels;
using RestaurantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public List<OrderViewModel> GetFullList()
{
using var context = new RestaurantDatabase();
return context.Orders
.Include(x => x.Client)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
using var context = new RestaurantDatabase();
if (model.Id.HasValue)
{
return context.Orders
.Include(x => x.Products)
.ThenInclude(x => x.ProductId)
.Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ClientId.HasValue)
{
return context.Orders
.Include(x => x.Products)
.ThenInclude(x => x.ProductId)
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Date.HasValue)
{
return context.Orders
.Include(x => x.Products)
.ThenInclude(x => x.ProductId)
.Include(x => x.Client)
.Where(x => x.Date == model.Date)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new RestaurantDatabase();
return context.Orders
.Include(x => x.Client)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new RestaurantDatabase();
var newOrder = Order.Create(context, model);
if (newOrder == null)
{
return null;
}
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Orders
.Include(x => x.Client)
.Include(x => x.Products)
.ThenInclude(x => x.ProductId)
.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return GetElement(new OrderSearchModel { Id = element.Id });
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Orders
.Include(x => x.Client)
.Include(x => x.Products)
.ThenInclude(x => x.ProductId)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,121 @@
using Microsoft.EntityFrameworkCore;
using RestaurantContracts.BindingModels;
using RestaurantContracts.SearchModels;
using RestaurantContracts.StoragesContracts;
using RestaurantContracts.ViewModels;
using RestaurantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Implements
{
public class ProductStorage : IProductStorage
{
public List<ProductViewModel> GetFullList()
{
using var context = new RestaurantDatabase();
return context.Products
.Include(x => x.Components)
.ThenInclude(x => x.ComponentId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{
using var context = new RestaurantDatabase();
if (model.Id.HasValue)
{
return context.Products
.Include(x => x.Components)
.ThenInclude(x => x.ComponentId)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Type != null)
{
return context.Products
.Include(x => x.Components)
.ThenInclude(x => x.ComponentId)
.Where(x => x.Type == model.Type)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
}
public ProductViewModel? GetElement(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Type) &&
!model.Id.HasValue)
{
return null;
}
using var context = new RestaurantDatabase();
return context.Products
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Type) &&
x.Type == model.Type) ||
(model.Id.HasValue && x.Id ==
model.Id))
?.GetViewModel;
}
public ProductViewModel? Insert(ProductBindingModel model)
{
using var context = new RestaurantDatabase();
var newProduct = Product.Create(context, model);
if (newProduct == null)
{
return null;
}
context.Products.Add(newProduct);
context.SaveChanges();
return newProduct.GetViewModel;
}
public ProductViewModel? Update(ProductBindingModel model)
{
using var context = new RestaurantDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var product = context.Products.FirstOrDefault(rec =>
rec.Id == model.Id);
if (product == null)
{
return null;
}
product.Update(model);
context.SaveChanges();
product.UpdateComponents(context, model);
transaction.Commit();
return product.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ProductViewModel? Delete(ProductBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Products
.Include(x => x.Components)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Products.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,97 @@
using Microsoft.EntityFrameworkCore;
using RestaurantContracts.BindingModels;
using RestaurantContracts.SearchModels;
using RestaurantContracts.StoragesContracts;
using RestaurantContracts.ViewModels;
using RestaurantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Implements
{
public class ProviderStorage : IProviderStorage
{
public List<ProviderViewModel> GetFullList()
{
using var context = new RestaurantDatabase();
return context.Providers.Select(x => x.GetViewModel).ToList();
}
public List<ProviderViewModel> GetFilteredList(ProviderSearchModel model)
{
using var context = new RestaurantDatabase();
if (model.Id.HasValue)
{
return context.Providers
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Name != null)
{
return context.Providers
.Where(x => x.Name == model.Name)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
}
public ProviderViewModel? GetElement(ProviderSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new RestaurantDatabase();
return context.Providers
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ProviderViewModel? Insert(ProviderBindingModel model)
{
var newProvider = Provider.Create(model);
if (newProvider == null)
{
return null;
}
using var context = new RestaurantDatabase();
context.Providers.Add(newProvider);
context.SaveChanges();
return newProvider.GetViewModel;
}
public ProviderViewModel? Update(ProviderBindingModel model)
{
using var context = new RestaurantDatabase();
var Provider = context.Providers.FirstOrDefault(x => x.Id == model.Id);
if (Provider == null)
{
return null;
}
Provider.Update(model);
context.SaveChanges();
return Provider.GetViewModel;
}
public ProviderViewModel? Delete(ProviderBindingModel model)
{
using var context = new RestaurantDatabase();
var element = context.Providers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Providers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,319 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using RestaurantDatabaseImplement;
#nullable disable
namespace RestaurantDatabaseImplement.Migrations
{
[DbContext(typeof(RestaurantDatabase))]
[Migration("20230506075636_migr1")]
partial class migr1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Number")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Price")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ComponentProvider", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int>("ProviderId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ProviderId");
b.ToTable("ComponentProviders");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int>("Price")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Orders");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.OrderProduct", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("OrderId")
.HasColumnType("integer");
b.Property<int>("ProductId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderProducts");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("Price")
.HasColumnType("integer");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ProductComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("ProductId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ProductId");
b.ToTable("ProductComponents");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Provider", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Providers");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ComponentProvider", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Component", "Component")
.WithMany("Providers")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RestaurantDatabaseImplement.Models.Provider", "Provider")
.WithMany("ComponentProviders")
.HasForeignKey("ProviderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Provider");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.OrderProduct", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Order", "Order")
.WithMany("Products")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RestaurantDatabaseImplement.Models.Product", "Product")
.WithMany("OrderProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ProductComponent", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Component", "Component")
.WithMany("ProductComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RestaurantDatabaseImplement.Models.Product", "Product")
.WithMany("Components")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Product");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Component", b =>
{
b.Navigation("ProductComponents");
b.Navigation("Providers");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Product", b =>
{
b.Navigation("Components");
b.Navigation("OrderProducts");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Provider", b =>
{
b.Navigation("ComponentProviders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,241 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace RestaurantDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class migr1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
Number = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Price = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Type = table.Column<string>(type: "text", nullable: false),
Price = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Providers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Providers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column<int>(type: "integer", nullable: false),
Price = table.Column<int>(type: "integer", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProductComponents",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProductId = table.Column<int>(type: "integer", nullable: false),
ComponentId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProductComponents", x => x.Id);
table.ForeignKey(
name: "FK_ProductComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProductComponents_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ComponentProviders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ComponentId = table.Column<int>(type: "integer", nullable: false),
ProviderId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ComponentProviders", x => x.Id);
table.ForeignKey(
name: "FK_ComponentProviders_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ComponentProviders_Providers_ProviderId",
column: x => x.ProviderId,
principalTable: "Providers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "OrderProducts",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OrderId = table.Column<int>(type: "integer", nullable: false),
ProductId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OrderProducts", x => x.Id);
table.ForeignKey(
name: "FK_OrderProducts_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_OrderProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ComponentProviders_ComponentId",
table: "ComponentProviders",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_ComponentProviders_ProviderId",
table: "ComponentProviders",
column: "ProviderId");
migrationBuilder.CreateIndex(
name: "IX_OrderProducts_OrderId",
table: "OrderProducts",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_OrderProducts_ProductId",
table: "OrderProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_ProductComponents_ComponentId",
table: "ProductComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_ProductComponents_ProductId",
table: "ProductComponents",
column: "ProductId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ComponentProviders");
migrationBuilder.DropTable(
name: "OrderProducts");
migrationBuilder.DropTable(
name: "ProductComponents");
migrationBuilder.DropTable(
name: "Providers");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Products");
migrationBuilder.DropTable(
name: "Clients");
}
}
}

View File

@ -0,0 +1,316 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using RestaurantDatabaseImplement;
#nullable disable
namespace RestaurantDatabaseImplement.Migrations
{
[DbContext(typeof(RestaurantDatabase))]
partial class RestaurantDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Number")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Price")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ComponentProvider", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int>("ProviderId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ProviderId");
b.ToTable("ComponentProviders");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int>("Price")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Orders");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.OrderProduct", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("OrderId")
.HasColumnType("integer");
b.Property<int>("ProductId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderProducts");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("Price")
.HasColumnType("integer");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ProductComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("ProductId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ProductId");
b.ToTable("ProductComponents");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Provider", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Providers");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ComponentProvider", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Component", "Component")
.WithMany("Providers")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RestaurantDatabaseImplement.Models.Provider", "Provider")
.WithMany("ComponentProviders")
.HasForeignKey("ProviderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Provider");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.OrderProduct", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Order", "Order")
.WithMany("Products")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RestaurantDatabaseImplement.Models.Product", "Product")
.WithMany("OrderProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.ProductComponent", b =>
{
b.HasOne("RestaurantDatabaseImplement.Models.Component", "Component")
.WithMany("ProductComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RestaurantDatabaseImplement.Models.Product", "Product")
.WithMany("Components")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Product");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Component", b =>
{
b.Navigation("ProductComponents");
b.Navigation("Providers");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Product", b =>
{
b.Navigation("Components");
b.Navigation("OrderProducts");
});
modelBuilder.Entity("RestaurantDatabaseImplement.Models.Provider", b =>
{
b.Navigation("ComponentProviders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,60 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.ViewModels;
using RestaurantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class Client : IClientModel
{
[Required]
public string FirstName { get; set; } = string.Empty;
[Required]
public string LastName { get; set; } = string.Empty;
[Required]
public string Number { get; set; } = string.Empty;
public int Id { get; set; }
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
FirstName = model.FirstName,
LastName = model.LastName,
Number = model.Number,
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
FirstName = model.FirstName;
LastName = model.LastName;
Number = model.Number;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
FirstName = FirstName,
LastName = LastName,
Number = Number,
};
}
}

View File

@ -0,0 +1,116 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.ViewModels;
using RestaurantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class Component : IComponentModel
{
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public int Price { get; private set; }
[Required]
public int Count { get; private set; }
private Dictionary<int, (IProviderModel, int, DateTime)>? _componentProviders = null;
[NotMapped]
public Dictionary<int, (IProviderModel, int, DateTime)> ComponentProviders
{
get
{
if (_componentProviders == null)
{
_componentProviders = Providers.ToDictionary(recPC => recPC.ProviderId, recPC =>
(recPC.Provider as IProviderModel, recPC.Count, recPC.Date));
}
return _componentProviders;
}
}
[ForeignKey("ComponentId")]
public virtual List<ComponentProvider> Providers { get; set; } = new();
public int Id { get; private set; }
[ForeignKey("ComponentId")]
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
public static Component? Create(RestaurantDatabase context, ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
Name = model.Name,
Price = model.Price,
Count = model.Count,
Providers = model.ComponentProviders.Select(x => new ComponentProvider
{
Provider = context.Providers.First(y => y.Id == x.Key),
Count = x.Value.Item2,
Date = x.Value.Item3
}).ToList()
};
}
public void Update(ComponentBindingModel? model)
{
Name = model.Name;
Price = model.Price;
Count = model.Count;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Price = Price,
Count = Count,
ComponentProviders = ComponentProviders,
};
public void UpdateComponents(RestaurantDatabase context, ComponentBindingModel model)
{
var ComponentProviders = context.ComponentProviders.Where(rec => rec.ComponentId == model.Id).ToList();
if (ComponentProviders != null && ComponentProviders.Count > 0)
{ // удалили те, которых нет в модели
context.ComponentProviders.RemoveRange(ComponentProviders.Where(rec => !model.ComponentProviders.ContainsKey(rec.ProviderId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateComponent in ComponentProviders)
{
updateComponent.Count = model.ComponentProviders[updateComponent.ProviderId].Item2;
model.ComponentProviders.Remove(updateComponent.ProviderId);
}
context.SaveChanges();
}
var Component = context.Components.First(x => x.Id == Id);
foreach (var pc in model.ComponentProviders)
{
context.ComponentProviders.Add(new ComponentProvider
{
Component = Component,
Provider = context.Providers.First(x => x.Id == pc.Key),
Count = pc.Value.Item2,
Date = pc.Value.Item3 // ??????
});
context.SaveChanges();
}
_componentProviders = null;
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class ComponentProvider
{
public int Id { get; set; }
[Required]
public int ComponentId { get; set; }
public virtual Component Component { get; set; } = new();
[Required]
public int ProviderId { get; set; }
public virtual Provider Provider { get; set; } = new();
[Required]
public int Count { get; set; }
[Required]
public DateTime Date { get; set; }
}
}

View File

@ -0,0 +1,110 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.ViewModels;
using RestaurantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class Order : IOrderModel
{
[Required]
public int ClientId { get; set; }
public virtual Client Client { get; set; } = new();
[Required]
public int Price { get; set; }
[Required]
public DateTime Date { get; set; }
private Dictionary<int, (IProductModel, int)>? _orderProducts = null;
[NotMapped]
public Dictionary<int, (IProductModel, int)> OrderProducts
{
get
{
if (_orderProducts == null)
{
_orderProducts = Products.ToDictionary(recPC => recPC.ProductId, recPC =>
(recPC.Product as IProductModel, recPC.Count));
}
return _orderProducts;
}
}
[ForeignKey("OrderId")]
public virtual List<OrderProduct> Products { get; set; } = new();
public int Id { get; set; }
public static Order? Create(RestaurantDatabase context, OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ClientId = model.ClientId,
Price = model.Price,
Date = model.Date,
Products = model.OrderProducts.Select(x => new OrderProduct
{
Product = context.Products.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(OrderBindingModel? model)
{
Date = model.Date;
Price = model.Price;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
Price = Price,
Date = Date,
};
public void UpdateComponents(RestaurantDatabase context, OrderBindingModel model)
{
var OrderProducts = context.OrderProducts.Where(rec => rec.OrderId == model.Id).ToList();
if (OrderProducts != null && OrderProducts.Count > 0)
{ // удалили те, которых нет в модели
context.OrderProducts.RemoveRange(OrderProducts.Where(rec => !model.OrderProducts.ContainsKey(rec.ProductId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateComponent in OrderProducts)
{
updateComponent.Count = model.OrderProducts[updateComponent.ProductId].Item2;
model.OrderProducts.Remove(updateComponent.ProductId);
}
context.SaveChanges();
}
var Order = context.Orders.First(x => x.Id == Id);
foreach (var pc in model.OrderProducts)
{
context.OrderProducts.Add(new OrderProduct
{
Order = Order,
Product = context.Products.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_orderProducts = null;
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class OrderProduct
{
public int Id { get; set; }
[Required]
public int OrderId { get; set; }
public virtual Order Order { get; set; } = new();
[Required]
public int ProductId { get; set; }
public virtual Product Product { get; set; } = new();
[Required]
public int Count { get; set; }
}
}

View File

@ -0,0 +1,113 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.ViewModels;
using RestaurantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class Product : IProductModel
{
[Required]
public string Type { get; private set; } = string.Empty;
[Required]
public int Price { get; private set; }
[Required]
public int Count { get; private set; }
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
[NotMapped]
public Dictionary<int, (IComponentModel, int)> ProductComponents
{
get
{
if (_productComponents == null)
{
_productComponents = Components.ToDictionary(recPC => recPC.ComponentId, recPC =>
(recPC.Component as IComponentModel, recPC.Count));
}
return _productComponents;
}
}
public int Id { get; private set; }
[ForeignKey("ProductId")]
public virtual List<ProductComponent> Components { get; private set; } = new();
[ForeignKey("ProductId")]
public virtual List<OrderProduct> OrderProducts { get; private set; } = new();
public static Product? Create(RestaurantDatabase context, ProductBindingModel? model)
{
if (model == null)
{
return null;
}
return new Product()
{
Id = model.Id,
Type = model.Type,
Price = model.Price,
Components = model.ProductComponents.Select(x => new ProductComponent
{
Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(ProductBindingModel? model)
{
Type = model.Type;
Price = model.Price;
Count = model.Count;
}
public ProductViewModel GetViewModel => new()
{
Id = Id,
Type = Type,
Price = Price,
Count = Count,
ProductComponents = ProductComponents
};
public void UpdateComponents(RestaurantDatabase context, ProductBindingModel model)
{
var ProductComponents = context.ProductComponents.Where(rec => rec.ProductId == model.Id).ToList();
if (ProductComponents != null && ProductComponents.Count > 0)
{ // удалили те, которых нет в модели
context.ProductComponents.RemoveRange(ProductComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateComponent in ProductComponents)
{
updateComponent.Count = model.ProductComponents[updateComponent.ComponentId].Item2;
model.ProductComponents.Remove(updateComponent.ComponentId);
}
context.SaveChanges();
}
var Product = context.Products.First(x => x.Id == Id);
foreach (var pc in model.ProductComponents)
{
context.ProductComponents.Add(new ProductComponent
{
Product = Product,
Component = context.Components.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_productComponents = null;
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class ProductComponent
{
public int Id { get; set; }
[Required]
public int ProductId { get; set; }
public virtual Product Product { get; set; } = new();
[Required]
public int ComponentId { get; set; }
public virtual Component Component { get; set; } = new();
[Required]
public int Count { get; set; }
}
}

View File

@ -0,0 +1,71 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.ViewModels;
using RestaurantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement.Models
{
public class Provider : IProviderModel
{
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public string Address { get; private set; } = string.Empty;
public int Id { get; private set; }
[ForeignKey("ProviderId")]
public virtual List<ComponentProvider> ComponentProviders { get; set; } = new();
public static Provider? Create(ProviderBindingModel model)
{
if (model == null)
{
return null;
}
return new Provider()
{
Id = model.Id,
Name = model.Name,
Address = model.Address
};
}
public static Provider Create(ProviderViewModel model)
{
if (model == null)
{
return null;
}
return new Provider()
{
Id = model.Id,
Name = model.Name,
Address = model.Address
};
}
public void Update(ProviderBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Address = model.Address;
}
public ProviderViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Address = Address
};
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using RestaurantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RestaurantDatabaseImplement
{
public class RestaurantDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"
Host=localhost;
Port=5432;
Database=RestaurantDatabase;
Username=postgres;
Password=postgres");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Product> Products { set; get; }
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
public virtual DbSet<Provider> Providers { set; get; }
public virtual DbSet<ComponentProvider> ComponentProviders { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -0,0 +1,27 @@
<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.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RestaurantContracts\RestaurantContracts.csproj" />
<ProjectReference Include="..\RestaurantDataModels\RestaurantDataModels.csproj" />
</ItemGroup>
</Project>

View File

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

View File

@ -0,0 +1,141 @@
namespace RestaurantView
{
partial class FormClient
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelFirstName = new System.Windows.Forms.Label();
this.labelLastName = new System.Windows.Forms.Label();
this.labelNumber = new System.Windows.Forms.Label();
this.textBoxFirstName = new System.Windows.Forms.TextBox();
this.textBoxLastName = new System.Windows.Forms.TextBox();
this.textBoxNumber = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(53, 160);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(105, 37);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(214, 160);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(121, 37);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Отменить";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// labelFirstName
//
this.labelFirstName.AutoSize = true;
this.labelFirstName.Location = new System.Drawing.Point(46, 25);
this.labelFirstName.Name = "labelFirstName";
this.labelFirstName.Size = new System.Drawing.Size(34, 15);
this.labelFirstName.TabIndex = 2;
this.labelFirstName.Text = "Имя:";
//
// labelLastName
//
this.labelLastName.AutoSize = true;
this.labelLastName.Location = new System.Drawing.Point(19, 70);
this.labelLastName.Name = "labelLastName";
this.labelLastName.Size = new System.Drawing.Size(61, 15);
this.labelLastName.TabIndex = 3;
this.labelLastName.Text = "Фамилия:";
//
// labelNumber
//
this.labelNumber.AutoSize = true;
this.labelNumber.Location = new System.Drawing.Point(32, 113);
this.labelNumber.Name = "labelNumber";
this.labelNumber.Size = new System.Drawing.Size(48, 15);
this.labelNumber.TabIndex = 4;
this.labelNumber.Text = "Номер:";
//
// textBoxFirstName
//
this.textBoxFirstName.Location = new System.Drawing.Point(86, 22);
this.textBoxFirstName.Name = "textBoxFirstName";
this.textBoxFirstName.Size = new System.Drawing.Size(273, 23);
this.textBoxFirstName.TabIndex = 5;
//
// textBoxLastName
//
this.textBoxLastName.Location = new System.Drawing.Point(86, 67);
this.textBoxLastName.Name = "textBoxLastName";
this.textBoxLastName.Size = new System.Drawing.Size(273, 23);
this.textBoxLastName.TabIndex = 6;
//
// textBoxNumber
//
this.textBoxNumber.Location = new System.Drawing.Point(86, 110);
this.textBoxNumber.Name = "textBoxNumber";
this.textBoxNumber.Size = new System.Drawing.Size(273, 23);
this.textBoxNumber.TabIndex = 7;
//
// FormClient
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(393, 215);
this.Controls.Add(this.textBoxNumber);
this.Controls.Add(this.textBoxLastName);
this.Controls.Add(this.textBoxFirstName);
this.Controls.Add(this.labelNumber);
this.Controls.Add(this.labelLastName);
this.Controls.Add(this.labelFirstName);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Name = "FormClient";
this.Text = "Клиент";
this.Load += new System.EventHandler(this.FormClient_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private Label labelFirstName;
private Label labelLastName;
private Label labelNumber;
private TextBox textBoxFirstName;
private TextBox textBoxLastName;
private TextBox textBoxNumber;
}
}

View File

@ -0,0 +1,89 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
using RestaurantContracts.SearchModels;
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 RestaurantView
{
public partial class FormClient : Form
{
private readonly IClientLogic _clientLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormClient(IClientLogic clientLogic)
{
InitializeComponent();
_clientLogic = clientLogic;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormClient_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _clientLogic.ReadElement(new ClientSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxFirstName.Text = view.FirstName;
textBoxLastName.Text = view.LastName;
textBoxNumber.Text = view.Number;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxFirstName.Text) && string.IsNullOrEmpty(textBoxLastName.Text) && string.IsNullOrEmpty(textBoxNumber.Text))
{
MessageBox.Show("Введены не все данные.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new ClientBindingModel
{
Id = _id ?? 0,
FirstName = textBoxFirstName.Text,
LastName = textBoxLastName.Text,
Number = textBoxNumber.Text
};
var operationResult = _id.HasValue ? _clientLogic.Update(model) : _clientLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,114 @@
namespace RestaurantView
{
partial class FormClients
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonRef = 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(0, 0);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(728, 479);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(746, 42);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(85, 38);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(746, 110);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(85, 36);
this.buttonDel.TabIndex = 2;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(746, 175);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(85, 33);
this.buttonUpd.TabIndex = 3;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonChange_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(746, 240);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(85, 30);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormClients
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(852, 478);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormClients";
this.Text = "Клиенты";
this.Load += new System.EventHandler(this.FormClients_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonDel;
private Button buttonUpd;
private Button buttonRef;
}
}

View File

@ -0,0 +1,106 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
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 RestaurantView
{
public partial class FormClients : Form
{
private readonly IClientLogic _clientLogic;
public FormClients(IClientLogic clientLogic)
{
InitializeComponent();
_clientLogic = clientLogic;
}
private void LoadData()
{
try
{
var list = _clientLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClient));
if (service is FormClient form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClient));
if (service is FormClient form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_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);
try
{
if (!_clientLogic.Delete(new ClientBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormClients_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,246 @@
namespace RestaurantView
{
partial class FormComponent
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelName = new System.Windows.Forms.Label();
this.labelPrice = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxPrice = new System.Windows.Forms.TextBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Provider = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(233, 519);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(92, 33);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(380, 519);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(87, 33);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Отменить";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(30, 25);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(62, 15);
this.labelName.TabIndex = 2;
this.labelName.Text = "Название:";
//
// labelPrice
//
this.labelPrice.AutoSize = true;
this.labelPrice.Location = new System.Drawing.Point(54, 68);
this.labelPrice.Name = "labelPrice";
this.labelPrice.Size = new System.Drawing.Size(38, 15);
this.labelPrice.TabIndex = 3;
this.labelPrice.Text = "Цена:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(17, 113);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(75, 15);
this.labelCount.TabIndex = 4;
this.labelCount.Text = "Количество:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(98, 22);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(295, 23);
this.textBoxName.TabIndex = 5;
//
// textBoxPrice
//
this.textBoxPrice.Enabled = false;
this.textBoxPrice.Location = new System.Drawing.Point(98, 65);
this.textBoxPrice.Name = "textBoxPrice";
this.textBoxPrice.Size = new System.Drawing.Size(295, 23);
this.textBoxPrice.TabIndex = 6;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(98, 110);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(295, 23);
this.textBoxCount.TabIndex = 7;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonRef);
this.groupBox1.Controls.Add(this.buttonUpd);
this.groupBox1.Controls.Add(this.buttonDel);
this.groupBox1.Controls.Add(this.buttonAdd);
this.groupBox1.Controls.Add(this.dataGridView);
this.groupBox1.Location = new System.Drawing.Point(30, 186);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(622, 292);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Поставщики";
//
// dataGridView1
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Id,
this.Provider,
this.Count});
this.dataGridView.Location = new System.Drawing.Point(6, 22);
this.dataGridView.Name = "dataGridView1";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(466, 251);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(512, 22);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(512, 79);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(75, 23);
this.buttonDel.TabIndex = 2;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(512, 136);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
this.buttonUpd.TabIndex = 3;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(512, 194);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(75, 23);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
//
// Id
//
this.Id.HeaderText = "Id";
this.Id.Name = "Id";
this.Id.Visible = false;
//
// Provider
//
this.Provider.HeaderText = "Поставщик";
this.Provider.Name = "Provider";
this.Provider.Width = 200;
//
// Count
//
this.Count.HeaderText = "Количество";
this.Count.Name = "Count";
this.Count.Width = 200;
//
// FormComponent
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(679, 590);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.textBoxPrice);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelPrice);
this.Controls.Add(this.labelName);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Name = "FormComponent";
this.Text = "Компонент";
this.Load += new System.EventHandler(this.FormComponent_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private Label labelName;
private Label labelPrice;
private Label labelCount;
private TextBox textBoxName;
private TextBox textBoxPrice;
private TextBox textBoxCount;
private GroupBox groupBox1;
private Button buttonRef;
private Button buttonUpd;
private Button buttonDel;
private Button buttonAdd;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn Id;
private DataGridViewTextBoxColumn Provider;
private DataGridViewTextBoxColumn Count;
}
}

View File

@ -0,0 +1,114 @@
using RestaurantBusinessLogic.BusinessLogics;
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
using RestaurantContracts.SearchModels;
using RestaurantDataModels.Models;
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 RestaurantView
{
public partial class FormComponent : Form
{
private readonly IComponentLogic _componentLogic;
private Dictionary<int, (IProviderModel, int, DateTime)> _componentProviders;
private int? _id;
public int Id { set { _id = value; } }
public FormComponent(IComponentLogic componentLogic)
{
InitializeComponent();
_componentLogic = componentLogic;
_componentProviders = new Dictionary<int, (IProviderModel, int, DateTime)>();
}
private void FormComponent_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _componentLogic.ReadElement(new ComponentSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.Name;
textBoxPrice.Text = view.Price.ToString();
textBoxCount.Text = view.Count.ToString();
_componentProviders = view.ComponentProviders ?? new Dictionary<int, (IProviderModel, int, DateTime)>();
LoadData();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text) && string.IsNullOrEmpty(textBoxPrice.Text) && string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Введены не все данные.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new ComponentBindingModel
{
Id = _id ?? 0,
Name = textBoxName.Text,
Price = int.Parse(textBoxPrice.Text),
Count = int.Parse(textBoxCount.Text)
};
var operationResult = _id.HasValue ? _componentLogic.Update(model) : _componentLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
}
private void LoadData()
{
try
{
if (_componentProviders != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _componentProviders)
{
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2, pc.Value.Item3 });
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,78 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Provider.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Provider.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

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

View File

@ -0,0 +1,92 @@
using RestaurantContracts.BusinessLogicsContracts;
using RestaurantContracts.ViewModels;
using RestaurantDataModels.Models;
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 RestaurantView
{
public partial class FormComponentProvider : Form
{
private readonly List<ProviderViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxComponent.SelectedValue);
}
set
{
comboBoxComponent.SelectedValue = value;
}
}
public IProviderModel? ProviderModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); }
}
public FormComponentProvider(IProviderLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxProvider.DisplayMember = "ComponentName";
comboBoxProvider.ValueMember = "Id";
comboBoxProvider.DataSource = _list;
comboBoxProvider.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComponent.SelectedValue == null)
{
MessageBox.Show("Выберите компонент", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,114 @@
namespace RestaurantView
{
partial class FormComponents
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button();
this.buttonRef = 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(0, 0);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(531, 432);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(549, 36);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(88, 49);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(549, 114);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(88, 47);
this.buttonDel.TabIndex = 2;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// buttonChange
//
this.buttonChange.Location = new System.Drawing.Point(549, 190);
this.buttonChange.Name = "buttonChange";
this.buttonChange.Size = new System.Drawing.Size(88, 42);
this.buttonChange.TabIndex = 3;
this.buttonChange.Text = "Изменить";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.ButtonChange_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(549, 260);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(88, 40);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormComponents
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(655, 432);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonChange);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormComponents";
this.Text = "Компоненты";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonDel;
private Button buttonChange;
private Button buttonRef;
}
}

View File

@ -0,0 +1,108 @@
using RestaurantBusinessLogic.BusinessLogics;
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
using System;
using System.Collections.Concurrent;
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 RestaurantView
{
public partial class FormComponents : Form
{
private readonly IComponentLogic _componentLogic;
public FormComponents(IComponentLogic componentLogic)
{
InitializeComponent();
_componentLogic = componentLogic;
}
private void FormComponents_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _componentLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_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);
try
{
if (!_componentLogic.Delete(new ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,121 @@
namespace RestaurantView
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.ClientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ProvidersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(0, 63);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(1162, 559);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(977, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(174, 45);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Создать заказ";
this.buttonAdd.UseVisualStyleBackColor = true;
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ClientsToolStripMenuItem,
this.ProvidersToolStripMenuItem,
this.ComponentsToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1163, 24);
this.menuStrip1.TabIndex = 2;
this.menuStrip1.Text = "menuStrip1";
//
// ClientsToolStripMenuItem
//
this.ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem";
this.ClientsToolStripMenuItem.Size = new System.Drawing.Size(67, 20);
this.ClientsToolStripMenuItem.Text = "Клиенты";
this.ClientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
//
// ProvidersToolStripMenuItem
//
this.ProvidersToolStripMenuItem.Name = "ProvidersToolStripMenuItem";
this.ProvidersToolStripMenuItem.Size = new System.Drawing.Size(89, 20);
this.ProvidersToolStripMenuItem.Text = "Поставщики";
this.ProvidersToolStripMenuItem.Click += new System.EventHandler(this.ProvidersToolStripMenuItem_Click);
//
// ComponentsToolStripMenuItem
//
this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(90, 20);
this.ComponentsToolStripMenuItem.Text = "Компоненты";
this.ComponentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1163, 634);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Заказы";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private MenuStrip menuStrip1;
private ToolStripMenuItem ClientsToolStripMenuItem;
private ToolStripMenuItem ProvidersToolStripMenuItem;
private ToolStripMenuItem ComponentsToolStripMenuItem;
}
}

View File

@ -0,0 +1,73 @@
using RestaurantContracts.BusinessLogicsContracts;
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 RestaurantView
{
public partial class FormMain : Form
{
private readonly IOrderLogic _orderLogic;
public FormMain(IOrderLogic orderLogic)
{
InitializeComponent();
_orderLogic = orderLogic;
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void ProvidersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProviders));
if (service is FormProviders form)
{
form.ShowDialog();
}
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,119 @@
namespace RestaurantView
{
partial class FormProvider
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelName = new System.Windows.Forms.Label();
this.labelAddress = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(51, 135);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(97, 31);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(202, 135);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(113, 31);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Отменить";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(22, 31);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(62, 15);
this.labelName.TabIndex = 2;
this.labelName.Text = "Название:";
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(32, 80);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(49, 15);
this.labelAddress.TabIndex = 3;
this.labelAddress.Text = "Адресс:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(90, 28);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(248, 23);
this.textBoxName.TabIndex = 4;
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(90, 77);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(248, 23);
this.textBoxAddress.TabIndex = 5;
//
// FormProvider
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(376, 186);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelName);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Name = "FormProvider";
this.Text = "Поставщик";
this.Load += new System.EventHandler(this.FormProvider_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private Label labelName;
private Label labelAddress;
private TextBox textBoxName;
private TextBox textBoxAddress;
}
}

View File

@ -0,0 +1,88 @@
using RestaurantBusinessLogic.BusinessLogics;
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
using RestaurantContracts.SearchModels;
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 RestaurantView
{
public partial class FormProvider : Form
{
private readonly IProviderLogic _providerLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormProvider(IProviderLogic providerLogic)
{
InitializeComponent();
_providerLogic = providerLogic;
}
private void FormProvider_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _providerLogic.ReadElement(new ProviderSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.Name;
textBoxAddress.Text = view.Address;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text) && string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Введены не все данные.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new ProviderBindingModel
{
Id = _id ?? 0,
Name = textBoxName.Text,
Address = textBoxAddress.Text,
};
var operationResult = _id.HasValue ? _providerLogic.Update(model) : _providerLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,114 @@
namespace RestaurantView
{
partial class FormProviders
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonRef = 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(0, 0);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(665, 450);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(682, 42);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(106, 35);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(682, 111);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(106, 33);
this.buttonDel.TabIndex = 2;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(682, 181);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(106, 35);
this.buttonUpd.TabIndex = 3;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonChange_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(682, 252);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(106, 41);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormProviders
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormProviders";
this.Text = "Поставщики";
this.Load += new System.EventHandler(this.FormProviders_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonDel;
private Button buttonUpd;
private Button buttonRef;
}
}

View File

@ -0,0 +1,106 @@
using RestaurantContracts.BindingModels;
using RestaurantContracts.BusinessLogicsContracts;
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 RestaurantView
{
public partial class FormProviders : Form
{
private readonly IProviderLogic _providerLogic;
public FormProviders(IProviderLogic providerLogic)
{
InitializeComponent();
_providerLogic = providerLogic;
}
private void LoadData()
{
try
{
var list = _providerLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
if (service is FormProvider form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
if (service is FormProvider form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_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);
try
{
if (!_providerLogic.Delete(new ProviderBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormProviders_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,7 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using RestaurantBusinessLogic.BusinessLogics;
using RestaurantContracts.BusinessLogicsContracts;
using RestaurantContracts.StoragesContracts;
using RestaurantDatabaseImplement.Implements;
using System;
namespace RestaurantView namespace RestaurantView
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
@ -11,7 +20,33 @@ namespace RestaurantView
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IProductStorage, ProductStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IProviderStorage, ProviderStorage>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IProductLogic, ProductLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IProviderLogic, ProviderLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormClients>();
services.AddTransient<FormClient>();
services.AddTransient<FormProvider>();
services.AddTransient<FormProviders>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
} }
} }
} }

View File

@ -8,4 +8,18 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RestaurantBusinessLogic\RestaurantBusinessLogic.csproj" />
<ProjectReference Include="..\RestaurantContracts\RestaurantContracts.csproj" />
<ProjectReference Include="..\RestaurantDatabaseImplement\RestaurantDatabaseImplement.csproj" />
</ItemGroup>
</Project> </Project>