Done
This commit is contained in:
parent
5cf96bc97c
commit
05af47ecf6
7
ClassLibrary1/Class1.cs
Normal file
7
ClassLibrary1/Class1.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace ClassLibrary1
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
9
ClassLibrary1/ClassLibrary1.csproj
Normal file
9
ClassLibrary1/ClassLibrary1.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
7
CustomersDataModels/IId.cs
Normal file
7
CustomersDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace ShopDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
10
CustomersDataModels/Models/ICustomerModel.cs
Normal file
10
CustomersDataModels/Models/ICustomerModel.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace ShopDataModels.Models
|
||||
{
|
||||
public interface ICustomerModel : IId
|
||||
{
|
||||
string FIO { get; }
|
||||
string PhotoFilePath { get; }
|
||||
string Email { get; }
|
||||
string ProductCategoryName { get; }
|
||||
}
|
||||
}
|
13
CustomersDataModels/Models/IProductCategoryModel.cs
Normal file
13
CustomersDataModels/Models/IProductCategoryModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShopDataModels.Models
|
||||
{
|
||||
public interface IProductCategoryModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
9
CustomersDataModels/ShopDataModels.csproj
Normal file
9
CustomersDataModels/ShopDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
64
ShopBusinessLogic/BusinessLogics/CustomerLogic.cs
Normal file
64
ShopBusinessLogic/BusinessLogics/CustomerLogic.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.BusinessLogicsContracts;
|
||||
using ShopContracts.SearchModels;
|
||||
using ShopContracts.StoragesContracts;
|
||||
using ShopContracts.ViewModels;
|
||||
|
||||
namespace ShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CustomerLogic : ICustomerLogic
|
||||
{
|
||||
private readonly ICustomerStorage _customerStorage;
|
||||
public CustomerLogic(ICustomerStorage studentStorage)
|
||||
{
|
||||
_customerStorage = studentStorage;
|
||||
}
|
||||
public void CreateOrUpdate(CustomerBindingModel model)
|
||||
{
|
||||
var element = _customerStorage.GetElement(
|
||||
new CustomerBindingModel
|
||||
{
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
PhotoFilePath = model.PhotoFilePath,
|
||||
ProductCategoryName = model.ProductCategoryName,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new Exception("Клиент с таким именем уже существует.");
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
_customerStorage.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
_customerStorage.Insert(model);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(CustomerBindingModel model)
|
||||
{
|
||||
var element = _customerStorage.GetElement(new CustomerBindingModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("Клиент не найден");
|
||||
}
|
||||
_customerStorage.Delete(model);
|
||||
}
|
||||
|
||||
public List<CustomerViewModel> Read(CustomerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return _customerStorage.GetFullList();
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return new List<CustomerViewModel> { _customerStorage.GetElement(model) };
|
||||
}
|
||||
return _customerStorage.GetFilteredList(model);
|
||||
}
|
||||
}
|
||||
}
|
63
ShopBusinessLogic/BusinessLogics/ProductCategoryLogic.cs
Normal file
63
ShopBusinessLogic/BusinessLogics/ProductCategoryLogic.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.BusinessLogicsContracts;
|
||||
using ShopContracts.SearchModels;
|
||||
using ShopContracts.StoragesContracts;
|
||||
using ShopContracts.ViewModels;
|
||||
|
||||
|
||||
namespace ShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ProductCategoryLogic : IProductCategoryLogic
|
||||
{
|
||||
private readonly IProductCategoryStorage _productCategoryStorage;
|
||||
public ProductCategoryLogic(IProductCategoryStorage productCategoryStorage)
|
||||
{
|
||||
_productCategoryStorage = productCategoryStorage;
|
||||
}
|
||||
|
||||
public void CreateOrUpdate(ProductCategoryBindingModel model)
|
||||
{
|
||||
var element = _productCategoryStorage.GetElement(
|
||||
new ProductCategoryBindingModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new Exception("Такая категория продуктов уже существует");
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
_productCategoryStorage.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
_productCategoryStorage.Insert(model);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(ProductCategoryBindingModel model)
|
||||
{
|
||||
var element = _productCategoryStorage.GetElement(new ProductCategoryBindingModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("Категория продуктов не найдено");
|
||||
}
|
||||
_productCategoryStorage.Delete(model);
|
||||
}
|
||||
|
||||
public List<ProductCategoryViewModel> Read(ProductCategoryBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return _productCategoryStorage.GetFullList();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new List<ProductCategoryViewModel> { _productCategoryStorage.GetElement(model) };
|
||||
}
|
||||
return _productCategoryStorage.GetFilteredList(model);
|
||||
}
|
||||
}
|
||||
}
|
17
ShopBusinessLogic/ShopBusinessLogic.csproj
Normal file
17
ShopBusinessLogic/ShopBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ShopContracts\ShopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
13
ShopContracts/BindingModels/CustomerBindingModel.cs
Normal file
13
ShopContracts/BindingModels/CustomerBindingModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using ShopDataModels.Models;
|
||||
|
||||
namespace ShopContracts.BindingModels
|
||||
{
|
||||
public class CustomerBindingModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string FIO { get; set; }
|
||||
public string PhotoFilePath { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string ProductCategoryName { get; set; }
|
||||
}
|
||||
}
|
10
ShopContracts/BindingModels/ProductCategoryBindingModel.cs
Normal file
10
ShopContracts/BindingModels/ProductCategoryBindingModel.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using ShopDataModels.Models;
|
||||
|
||||
namespace ShopContracts.BindingModels
|
||||
{
|
||||
public class ProductCategoryBindingModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
13
ShopContracts/BusinessLogicsContracts/ICustomerLogic.cs
Normal file
13
ShopContracts/BusinessLogicsContracts/ICustomerLogic.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.SearchModels;
|
||||
using ShopContracts.ViewModels;
|
||||
|
||||
namespace ShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ICustomerLogic
|
||||
{
|
||||
List<CustomerViewModel> Read(CustomerBindingModel? model);
|
||||
void CreateOrUpdate(CustomerBindingModel model);
|
||||
void Delete(CustomerBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.SearchModels;
|
||||
using ShopContracts.ViewModels;
|
||||
|
||||
namespace ShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IProductCategoryLogic
|
||||
{
|
||||
List<ProductCategoryViewModel> Read(ProductCategoryBindingModel? model);
|
||||
void CreateOrUpdate(ProductCategoryBindingModel model);
|
||||
void Delete(ProductCategoryBindingModel model);
|
||||
}
|
||||
}
|
11
ShopContracts/SearchModels/CustomerSearchModel.cs
Normal file
11
ShopContracts/SearchModels/CustomerSearchModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace ShopContracts.SearchModels
|
||||
{
|
||||
public class CustomerSearchModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FIO { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string PhotoFilePath { get; set; }
|
||||
public string DirectionName { get; set; }
|
||||
}
|
||||
}
|
8
ShopContracts/SearchModels/ProductCategorySearchModel.cs
Normal file
8
ShopContracts/SearchModels/ProductCategorySearchModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace ShopContracts.SearchModels
|
||||
{
|
||||
public class ProductCategorySearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
13
ShopContracts/ShopContracts.csproj
Normal file
13
ShopContracts/ShopContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CustomersDataModels\ShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
16
ShopContracts/StoragesContracts/ICustomerStorage.cs
Normal file
16
ShopContracts/StoragesContracts/ICustomerStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.SearchModels;
|
||||
using ShopContracts.ViewModels;
|
||||
|
||||
namespace ShopContracts.StoragesContracts
|
||||
{
|
||||
public interface ICustomerStorage
|
||||
{
|
||||
List<CustomerViewModel> GetFullList();
|
||||
List<CustomerViewModel> GetFilteredList(CustomerBindingModel model);
|
||||
CustomerViewModel? GetElement(CustomerBindingModel model);
|
||||
void Insert(CustomerBindingModel model);
|
||||
void Update(CustomerBindingModel model);
|
||||
void Delete(CustomerBindingModel model);
|
||||
}
|
||||
}
|
15
ShopContracts/StoragesContracts/IProductCategoryStorage.cs
Normal file
15
ShopContracts/StoragesContracts/IProductCategoryStorage.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.ViewModels;
|
||||
|
||||
namespace ShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IProductCategoryStorage
|
||||
{
|
||||
List<ProductCategoryViewModel> GetFullList();
|
||||
List<ProductCategoryViewModel> GetFilteredList(ProductCategoryBindingModel model);
|
||||
ProductCategoryViewModel GetElement(ProductCategoryBindingModel model);
|
||||
void Insert(ProductCategoryBindingModel model);
|
||||
void Update(ProductCategoryBindingModel model);
|
||||
void Delete(ProductCategoryBindingModel model);
|
||||
}
|
||||
}
|
18
ShopContracts/ViewModels/CustomerViewModel.cs
Normal file
18
ShopContracts/ViewModels/CustomerViewModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.ComponentModel;
|
||||
using ShopDataModels.Models;
|
||||
|
||||
namespace ShopContracts.ViewModels
|
||||
{
|
||||
public class CustomerViewModel : ICustomerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО покупателя")]
|
||||
public string FIO { get; set; }
|
||||
[DisplayName("Путь к фото")]
|
||||
public string PhotoFilePath { get; set; }
|
||||
[DisplayName("Электронная почта")]
|
||||
public string Email { get; set; }
|
||||
[DisplayName("Категория товара")]
|
||||
public string ProductCategoryName { get; set; }
|
||||
}
|
||||
}
|
12
ShopContracts/ViewModels/ProductCategoryViewModel.cs
Normal file
12
ShopContracts/ViewModels/ProductCategoryViewModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel;
|
||||
using ShopDataModels.Models;
|
||||
|
||||
namespace ShopContracts.ViewModels
|
||||
{
|
||||
public class ProductCategoryViewModel : IProductCategoryModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название категории товаров")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
119
ShopDatabaseImplement/Implements/CustomerStorage.cs
Normal file
119
ShopDatabaseImplement/Implements/CustomerStorage.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.StoragesContracts;
|
||||
using ShopContracts.ViewModels;
|
||||
using ShopDatabaseImplement;
|
||||
using ShopDatabaseImplement.Models;
|
||||
|
||||
namespace ShopDatabaseImplement.Implements
|
||||
{
|
||||
public class CustomerStorage : ICustomerStorage
|
||||
{
|
||||
public void Delete(CustomerBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
var customer = context.Customers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (customer != null)
|
||||
{
|
||||
context.Customers.Remove(customer);
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Клиент не найден");
|
||||
}
|
||||
}
|
||||
|
||||
public CustomerViewModel GetElement(CustomerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ShopDatabase();
|
||||
var customer = context.Customers
|
||||
.ToList()
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
return customer != null ? CreateModel(customer) : null;
|
||||
}
|
||||
|
||||
public List<CustomerViewModel> GetFilteredList(CustomerBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
return context.Customers
|
||||
.Where(customer => customer.FIO.Contains(model.FIO))
|
||||
.ToList()
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CustomerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ShopDatabase();
|
||||
return context.Customers
|
||||
.ToList()
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void Insert(CustomerBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
context.Customers.Add(CreateModel(model, new Customer()));
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(CustomerBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var student = context.Customers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (student == null)
|
||||
{
|
||||
throw new Exception("Клиент не найден");
|
||||
}
|
||||
CreateModel(model, student);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static Customer CreateModel(CustomerBindingModel model, Customer customer)
|
||||
{
|
||||
customer.FIO = model.FIO;
|
||||
customer.PhotoFilePath = model.PhotoFilePath;
|
||||
customer.Email = model.Email;
|
||||
customer.ProductCategoryName = model.ProductCategoryName;
|
||||
|
||||
return customer;
|
||||
}
|
||||
|
||||
private CustomerViewModel CreateModel(Customer customer)
|
||||
{
|
||||
return new CustomerViewModel
|
||||
{
|
||||
Id = customer.Id,
|
||||
FIO = customer.FIO,
|
||||
PhotoFilePath = customer.PhotoFilePath,
|
||||
Email = customer.Email,
|
||||
ProductCategoryName = customer.ProductCategoryName,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
116
ShopDatabaseImplement/Implements/ProductCategoryStorage.cs
Normal file
116
ShopDatabaseImplement/Implements/ProductCategoryStorage.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.StoragesContracts;
|
||||
using ShopContracts.ViewModels;
|
||||
using ShopDatabaseImplement;
|
||||
using ShopDatabaseImplement.Models;
|
||||
|
||||
namespace ShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ProductCategoryStorage : IProductCategoryStorage
|
||||
{
|
||||
public void Delete(ProductCategoryBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
var productCategory = context.ProductCategorys.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (productCategory != null)
|
||||
{
|
||||
context.ProductCategorys.Remove(productCategory);
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Категория товаров не найдено");
|
||||
}
|
||||
}
|
||||
|
||||
public ProductCategoryViewModel GetElement(ProductCategoryBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ShopDatabase();
|
||||
|
||||
var productCategory = context.ProductCategorys
|
||||
.ToList()
|
||||
.FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
|
||||
return productCategory != null ? CreateModel(productCategory) : null;
|
||||
}
|
||||
|
||||
|
||||
public List<ProductCategoryViewModel> GetFilteredList(ProductCategoryBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ShopDatabase();
|
||||
return context.ProductCategorys
|
||||
.Where(rec => rec.Name.Contains(model.Name))
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ProductCategoryViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ShopDatabase();
|
||||
return context.ProductCategorys
|
||||
.Select(CreateModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void Insert(ProductCategoryBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
context.ProductCategorys.Add(CreateModel(model, new ProductCategory()));
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(ProductCategoryBindingModel model)
|
||||
{
|
||||
var context = new ShopDatabase();
|
||||
var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var productCategory = context.ProductCategorys.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (productCategory == null)
|
||||
{
|
||||
throw new Exception("Категория товаров не найдено");
|
||||
}
|
||||
CreateModel(model, productCategory);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static ProductCategory CreateModel(ProductCategoryBindingModel model, ProductCategory productCategory)
|
||||
{
|
||||
productCategory.Name = model.Name;
|
||||
return productCategory;
|
||||
}
|
||||
|
||||
private static ProductCategoryViewModel CreateModel(ProductCategory productCategory)
|
||||
{
|
||||
return new ProductCategoryViewModel
|
||||
{
|
||||
Id = productCategory.Id,
|
||||
Name = productCategory.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
75
ShopDatabaseImplement/Migrations/20241003095628_InitialCreate.Designer.cs
generated
Normal file
75
ShopDatabaseImplement/Migrations/20241003095628_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using ShopDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ShopDatabase))]
|
||||
[Migration("20241003095628_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ShopDatabaseImplement.Models.Customer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhotoFilePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ProductCategoryName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Customers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ShopDatabaseImplement.Models.ProductCategory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ProductCategorys");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ShopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Customers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
FIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
PhotoFilePath = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ProductCategoryName = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Customers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductCategorys",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductCategorys", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Customers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductCategorys");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using ShopDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ShopDatabase))]
|
||||
partial class ShopDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ShopDatabaseImplement.Models.Customer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhotoFilePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ProductCategoryName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Customers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ShopDatabaseImplement.Models.ProductCategory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ProductCategorys");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
16
ShopDatabaseImplement/Models/Customer.cs
Normal file
16
ShopDatabaseImplement/Models/Customer.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
namespace ShopDatabaseImplement.Models
|
||||
{
|
||||
public class Customer
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string FIO { get; set; }
|
||||
[Required]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
public string PhotoFilePath { get; set; }
|
||||
[Required]
|
||||
public string ProductCategoryName { get; set; }
|
||||
}
|
||||
}
|
12
ShopDatabaseImplement/Models/ProductCategory.cs
Normal file
12
ShopDatabaseImplement/Models/ProductCategory.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ShopDataModels.Models;
|
||||
|
||||
namespace ShopDatabaseImplement.Models
|
||||
{
|
||||
public class ProductCategory
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
19
ShopDatabaseImplement/ShopDatabase.cs
Normal file
19
ShopDatabaseImplement/ShopDatabase.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShopDatabaseImplement.Models;
|
||||
|
||||
namespace ShopDatabaseImplement
|
||||
{
|
||||
public class ShopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=ShopDatabase;;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Customer> Customers { set; get; }
|
||||
public virtual DbSet<ProductCategory> ProductCategorys { set; get; }
|
||||
}
|
||||
}
|
27
ShopDatabaseImplement/ShopDatabaseImplement.csproj
Normal file
27
ShopDatabaseImplement/ShopDatabaseImplement.csproj
Normal 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.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CustomersDataModels\ShopDataModels.csproj" />
|
||||
<ProjectReference Include="..\ShopContracts\ShopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
20
ShopView/ShopView.csproj
Normal file
20
ShopView/ShopView.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
<PackageReference Include="NLog" Version="5.2.5" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,9 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35027.167
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COP", "WinFormsLibrary1\COP.csproj", "{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShopDataModels", "CustomersDataModels\ShopDataModels.csproj", "{1AAF8752-0281-4ADF-B1CA-21DB683C09F0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsComponents", "TestsComponents\TestsComponents.csproj", "{C720866B-F5B4-4063-931A-2DB4A35DD888}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShopContracts", "ShopContracts\ShopContracts.csproj", "{3F5E14F5-BE59-47DC-B5BA-7E0786E26439}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShopBusinessLogic", "ShopBusinessLogic\ShopBusinessLogic.csproj", "{A2ACE5E0-A039-4712-91E9-4751734971C3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShopDatabaseImplement", "ShopDatabaseImplement\ShopDatabaseImplement.csproj", "{C488F532-5E96-46D9-9E68-451D5A4E6343}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShopView", "WinFormsLibrary2\ShopView.csproj", "{48DA6809-1C4D-4264-8B81-4609BCE0A44A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -13,14 +19,26 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1AAF8752-0281-4ADF-B1CA-21DB683C09F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1AAF8752-0281-4ADF-B1CA-21DB683C09F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1AAF8752-0281-4ADF-B1CA-21DB683C09F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1AAF8752-0281-4ADF-B1CA-21DB683C09F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3F5E14F5-BE59-47DC-B5BA-7E0786E26439}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3F5E14F5-BE59-47DC-B5BA-7E0786E26439}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F5E14F5-BE59-47DC-B5BA-7E0786E26439}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3F5E14F5-BE59-47DC-B5BA-7E0786E26439}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A2ACE5E0-A039-4712-91E9-4751734971C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A2ACE5E0-A039-4712-91E9-4751734971C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A2ACE5E0-A039-4712-91E9-4751734971C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A2ACE5E0-A039-4712-91E9-4751734971C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C488F532-5E96-46D9-9E68-451D5A4E6343}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C488F532-5E96-46D9-9E68-451D5A4E6343}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C488F532-5E96-46D9-9E68-451D5A4E6343}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C488F532-5E96-46D9-9E68-451D5A4E6343}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48DA6809-1C4D-4264-8B81-4609BCE0A44A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48DA6809-1C4D-4264-8B81-4609BCE0A44A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48DA6809-1C4D-4264-8B81-4609BCE0A44A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48DA6809-1C4D-4264-8B81-4609BCE0A44A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
180
WinFormsLibrary2/FormCustomer.Designer.cs
generated
Normal file
180
WinFormsLibrary2/FormCustomer.Designer.cs
generated
Normal file
@ -0,0 +1,180 @@
|
||||
namespace ShopView
|
||||
{
|
||||
partial class FormCustomer
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
textBoxFIO = new TextBox();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
emailField1 = new Lab1.EmailField();
|
||||
groupBox1 = new GroupBox();
|
||||
myListBox1 = new KOP.MyListBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
buttonAddPhoto = new Button();
|
||||
pictureBox = new PictureBox();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxFIO
|
||||
//
|
||||
textBoxFIO.Location = new Point(120, 36);
|
||||
textBoxFIO.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxFIO.Name = "textBoxFIO";
|
||||
textBoxFIO.Size = new Size(244, 27);
|
||||
textBoxFIO.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(74, 40);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(42, 20);
|
||||
label1.TabIndex = 1;
|
||||
label1.Text = "ФИО";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(61, 98);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(143, 20);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = "Электронная почта";
|
||||
//
|
||||
// emailField1
|
||||
//
|
||||
emailField1.EmailExample = null;
|
||||
emailField1.EmailRegex = null;
|
||||
emailField1.Location = new Point(210, 87);
|
||||
emailField1.Margin = new Padding(3, 4, 3, 4);
|
||||
emailField1.Name = "emailField1";
|
||||
emailField1.Size = new Size(154, 51);
|
||||
emailField1.TabIndex = 4;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(myListBox1);
|
||||
groupBox1.Location = new Point(14, 144);
|
||||
groupBox1.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Size = new Size(414, 200);
|
||||
groupBox1.TabIndex = 5;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Категория товаров";
|
||||
//
|
||||
// myListBox1
|
||||
//
|
||||
myListBox1.Location = new Point(6, 27);
|
||||
myListBox1.Name = "myListBox1";
|
||||
myListBox1.SelectedItem = "";
|
||||
myListBox1.Size = new Size(301, 166);
|
||||
myListBox1.TabIndex = 1;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(249, 620);
|
||||
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(86, 31);
|
||||
buttonSave.TabIndex = 6;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(342, 620);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(86, 31);
|
||||
buttonCancel.TabIndex = 7;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonAddPhoto
|
||||
//
|
||||
buttonAddPhoto.Location = new Point(14, 352);
|
||||
buttonAddPhoto.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddPhoto.Name = "buttonAddPhoto";
|
||||
buttonAddPhoto.Size = new Size(411, 31);
|
||||
buttonAddPhoto.TabIndex = 8;
|
||||
buttonAddPhoto.Text = "Загрузить фото";
|
||||
buttonAddPhoto.UseVisualStyleBackColor = true;
|
||||
buttonAddPhoto.Click += buttonAddPhoto_Click;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Location = new Point(14, 391);
|
||||
pictureBox.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(410, 221);
|
||||
pictureBox.TabIndex = 9;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormCustomer
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(439, 667);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(buttonAddPhoto);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(groupBox1);
|
||||
Controls.Add(emailField1);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(textBoxFIO);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormCustomer";
|
||||
Text = "Клиент";
|
||||
Load += FormCustomer_Load;
|
||||
groupBox1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxFIO;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Lab1.EmailField emailField1;
|
||||
private GroupBox groupBox1;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Button buttonAddPhoto;
|
||||
private PictureBox pictureBox;
|
||||
private KOP.MyListBox myListBox1;
|
||||
}
|
||||
}
|
187
WinFormsLibrary2/FormCustomer.cs
Normal file
187
WinFormsLibrary2/FormCustomer.cs
Normal file
@ -0,0 +1,187 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.ComponentModel;
|
||||
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.BusinessLogicsContracts;
|
||||
using Lab1;
|
||||
using System;
|
||||
using Lab1.VisualComponents.Exceptions;
|
||||
|
||||
|
||||
|
||||
namespace ShopView
|
||||
{
|
||||
public partial class FormCustomer : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICustomerLogic _customerLogic;
|
||||
private readonly IProductCategoryLogic _productCategoryLogic;
|
||||
private string imagePath;
|
||||
BindingList<ProductCategoryBindingModel> _list;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
private string? _item;
|
||||
|
||||
List<string> productCategory = new();
|
||||
public FormCustomer(ILogger<FormCustomer> logger, ICustomerLogic customerLogic, IProductCategoryLogic productCategoryLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_customerLogic = customerLogic;
|
||||
_productCategoryLogic = productCategoryLogic;
|
||||
imagePath = "";
|
||||
_list = new BindingList<ProductCategoryBindingModel>();
|
||||
emailField1.EmailRegex = "^\\S+@\\S+\\.\\S+$";
|
||||
emailField1.EmailExample = "example@mail.ru";
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxFIO.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(emailField1.Value))
|
||||
{
|
||||
MessageBox.Show("Введите почту!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
catch (IsNotMatchRegexException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (pictureBox.Image == null)
|
||||
{
|
||||
MessageBox.Show("Загрузите фото", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение студента");
|
||||
try
|
||||
{
|
||||
_customerLogic.CreateOrUpdate(new CustomerBindingModel
|
||||
{
|
||||
Id = _id,
|
||||
FIO = textBoxFIO.Text,
|
||||
PhotoFilePath = imagePath,
|
||||
Email = emailField1.Value,
|
||||
ProductCategoryName = myListBox1.SelectedItem
|
||||
}); ;
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения студента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void FormCustomer_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _customerLogic.Read(new CustomerBindingModel { Id = _id.Value })?.FirstOrDefault();
|
||||
if (view != null)
|
||||
{
|
||||
textBoxFIO.Text = view.FIO ;
|
||||
|
||||
var textBoxField = typeof(EmailField).GetField("textBox1",
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Instance);
|
||||
|
||||
if (textBoxField?.GetValue(emailField1) is TextBox innerTextBox)
|
||||
{
|
||||
innerTextBox.Text = view.Email;
|
||||
}
|
||||
|
||||
|
||||
imagePath = view.PhotoFilePath;
|
||||
|
||||
if (!string.IsNullOrEmpty(view.PhotoFilePath) && File.Exists(view.PhotoFilePath))
|
||||
{
|
||||
pictureBox.Image = Image.FromFile(view.PhotoFilePath);
|
||||
}
|
||||
|
||||
string[] dirs = view.ProductCategoryName.Split(";");
|
||||
foreach (var dir in dirs)
|
||||
{
|
||||
myListBox1.SelectedItem = dir;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Клиент с указанным ID не найден.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при загрузке данных клиента.");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка категории товаров");
|
||||
try
|
||||
{
|
||||
var list = _productCategoryLogic.Read(null);
|
||||
myListBox1.Clear();
|
||||
productCategory.Clear();
|
||||
_list.Clear();
|
||||
if (list != null)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
productCategory.Add(item.Name);
|
||||
_list.Add(new ProductCategoryBindingModel
|
||||
{
|
||||
Id = item.Id,
|
||||
Name = item.Name,
|
||||
});
|
||||
}
|
||||
}
|
||||
myListBox1.AddItems(productCategory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки категории товаров");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAddPhoto_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new()
|
||||
{
|
||||
Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"
|
||||
};
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
imagePath = openFileDialog.FileName;
|
||||
pictureBox.Image = Image.FromFile(imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsLibrary2/FormCustomer.resx
Normal file
120
WinFormsLibrary2/FormCustomer.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
68
WinFormsLibrary2/FormHandbooks.Designer.cs
generated
Normal file
68
WinFormsLibrary2/FormHandbooks.Designer.cs
generated
Normal file
@ -0,0 +1,68 @@
|
||||
namespace ShopView
|
||||
{
|
||||
partial class FormHandbooks
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.BackgroundColor = SystemColors.Control;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(490, 396);
|
||||
dataGridView.TabIndex = 0;
|
||||
dataGridView.CellEndEdit += dataGridView_CellEndEdit;
|
||||
dataGridView.KeyDown += dataGridView_KeyDown;
|
||||
//
|
||||
// FormHandbooks
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(490, 396);
|
||||
Controls.Add(dataGridView);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormHandbooks";
|
||||
Text = "Категория товаров";
|
||||
Load += FormHandbooks_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
110
WinFormsLibrary2/FormHandbooks.cs
Normal file
110
WinFormsLibrary2/FormHandbooks.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System.ComponentModel;
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace ShopView
|
||||
{
|
||||
public partial class FormHandbooks : Form
|
||||
{
|
||||
private readonly IProductCategoryLogic _logic;
|
||||
BindingList<ProductCategoryBindingModel> _list;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormHandbooks(IProductCategoryLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logic = logic;
|
||||
_list = new BindingList<ProductCategoryBindingModel>();
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
}
|
||||
|
||||
private void FormHandbooks_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.Read(null);
|
||||
_list.Clear();
|
||||
foreach (var item in list)
|
||||
{
|
||||
_list.Add(new ProductCategoryBindingModel
|
||||
{
|
||||
Id = item.Id,
|
||||
Name = item.Name,
|
||||
});
|
||||
}
|
||||
if (_list != null)
|
||||
{
|
||||
dataGridView.DataSource = _list;
|
||||
dataGridView.Columns[0].Visible = false;
|
||||
dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
var typeName = (string)dataGridView.CurrentRow.Cells[1].Value;
|
||||
if (!string.IsNullOrEmpty(typeName))
|
||||
{
|
||||
if (dataGridView.CurrentRow.Cells[0].Value != null)
|
||||
{
|
||||
_logic.CreateOrUpdate(new ProductCategoryBindingModel()
|
||||
{
|
||||
Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value),
|
||||
Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logic.CreateOrUpdate(new ProductCategoryBindingModel()
|
||||
{
|
||||
Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void dataGridView_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyData == Keys.Insert)
|
||||
{
|
||||
if (dataGridView.Rows.Count == 0)
|
||||
{
|
||||
_list.Add(new ProductCategoryBindingModel());
|
||||
dataGridView.DataSource = new BindingList<ProductCategoryBindingModel>(_list);
|
||||
dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1];
|
||||
return;
|
||||
}
|
||||
if (dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1].Value != null)
|
||||
{
|
||||
_list.Add(new ProductCategoryBindingModel());
|
||||
dataGridView.DataSource = new BindingList<ProductCategoryBindingModel>(_list);
|
||||
dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1];
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.KeyData == Keys.Delete)
|
||||
{
|
||||
if (MessageBox.Show("Удалить выбранный элемент", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_logic.Delete(new ProductCategoryBindingModel() { Id = (int)dataGridView.CurrentRow.Cells[0].Value });
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsLibrary2/FormHandbooks.resx
Normal file
120
WinFormsLibrary2/FormHandbooks.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
156
WinFormsLibrary2/FormMain.Designer.cs
generated
Normal file
156
WinFormsLibrary2/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,156 @@
|
||||
namespace ShopView
|
||||
{
|
||||
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.components = new System.ComponentModel.Container();
|
||||
this.tableOfValues = new KOP.MyTable();
|
||||
this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.создатьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.изменитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.удалитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.создатьПростойДокументToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.создатьДокументСТаблицейToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.excelComponent = new COP.ExcelComponent(this.components);
|
||||
this.gistogramPdfComponent = new KOP.PDFComponents.PdfChartComponent(this.components);
|
||||
this.componentWord = new Lab1.LogicalComponents.TableDocument(this.components);
|
||||
this.contextMenuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tableOfValues
|
||||
//
|
||||
this.tableOfValues.ContextMenuStrip = this.contextMenuStrip;
|
||||
this.tableOfValues.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tableOfValues.Location = new System.Drawing.Point(0, 0);
|
||||
this.tableOfValues.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.tableOfValues.Name = "tableOfValues";
|
||||
this.tableOfValues.IndexProperty = -1;
|
||||
this.tableOfValues.Size = new System.Drawing.Size(405, 302);
|
||||
this.tableOfValues.TabIndex = 0;
|
||||
//
|
||||
// contextMenuStrip
|
||||
//
|
||||
this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.создатьToolStripMenuItem,
|
||||
this.изменитьToolStripMenuItem,
|
||||
this.удалитьToolStripMenuItem,
|
||||
this.справочникиToolStripMenuItem,
|
||||
this.создатьПростойДокументToolStripMenuItem,
|
||||
this.создатьДокументСТаблицейToolStripMenuItem,
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem});
|
||||
this.contextMenuStrip.Name = "contextMenuStrip";
|
||||
this.contextMenuStrip.Size = new System.Drawing.Size(296, 158);
|
||||
//
|
||||
// создатьToolStripMenuItem
|
||||
//
|
||||
this.создатьToolStripMenuItem.Name = "создатьToolStripMenuItem";
|
||||
this.создатьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A)));
|
||||
this.создатьToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.создатьToolStripMenuItem.Text = "Создать";
|
||||
this.создатьToolStripMenuItem.Click += new System.EventHandler(this.СоздатьToolStripMenuItem_Click);
|
||||
//
|
||||
// изменитьToolStripMenuItem
|
||||
//
|
||||
this.изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem";
|
||||
this.изменитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U)));
|
||||
this.изменитьToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.изменитьToolStripMenuItem.Text = "Изменить";
|
||||
this.изменитьToolStripMenuItem.Click += new System.EventHandler(this.ИзменитьToolStripMenuItem_Click);
|
||||
//
|
||||
// удалитьToolStripMenuItem
|
||||
//
|
||||
this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
|
||||
this.удалитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D)));
|
||||
this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.удалитьToolStripMenuItem.Text = "Удалить";
|
||||
this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.УдалитьToolStripMenuItem_Click);
|
||||
//
|
||||
// справочникиToolStripMenuItem
|
||||
//
|
||||
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
this.справочникиToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
|
||||
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.справочникиToolStripMenuItem.Text = "Справочники";
|
||||
this.справочникиToolStripMenuItem.Click += new System.EventHandler(this.СправочникиToolStripMenuItem_Click);
|
||||
//
|
||||
// создатьПростойДокументToolStripMenuItem
|
||||
//
|
||||
this.создатьПростойДокументToolStripMenuItem.Name = "создатьПростойДокументToolStripMenuItem";
|
||||
this.создатьПростойДокументToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
|
||||
this.создатьПростойДокументToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.создатьПростойДокументToolStripMenuItem.Text = "Создать excel с фото";
|
||||
this.создатьПростойДокументToolStripMenuItem.Click += new System.EventHandler(this.СоздатьExcelСФотоToolStripMenuItem_Click);
|
||||
//
|
||||
// создатьДокументСТаблицейToolStripMenuItem
|
||||
//
|
||||
this.создатьДокументСТаблицейToolStripMenuItem.Name = "создатьДокументСТаблицейToolStripMenuItem";
|
||||
this.создатьДокументСТаблицейToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T)));
|
||||
this.создатьДокументСТаблицейToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.создатьДокументСТаблицейToolStripMenuItem.Text = "Создать документ с таблицей";
|
||||
this.создатьДокументСТаблицейToolStripMenuItem.Click += new System.EventHandler(this.СоздатьДокументСТаблицейToolStripMenuItem_Click);
|
||||
//
|
||||
// создатьДокументСДиаграммойToolStripMenuItem
|
||||
//
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem.Name = "создатьДокументСДиаграммойToolStripMenuItem";
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem.Text = "Создать документ с диаграммой";
|
||||
this.создатьДокументСДиаграммойToolStripMenuItem.Click += new System.EventHandler(this.СоздатьДокументСДиаграммойToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(405, 302);
|
||||
this.Controls.Add(this.tableOfValues);
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Магазин";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
this.contextMenuStrip.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private KOP.MyTable tableOfValues;
|
||||
private ContextMenuStrip contextMenuStrip;
|
||||
private ToolStripMenuItem создатьToolStripMenuItem;
|
||||
private ToolStripMenuItem изменитьToolStripMenuItem;
|
||||
private ToolStripMenuItem удалитьToolStripMenuItem;
|
||||
private ToolStripMenuItem создатьПростойДокументToolStripMenuItem;
|
||||
private ToolStripMenuItem создатьДокументСТаблицейToolStripMenuItem;
|
||||
private ToolStripMenuItem создатьДокументСДиаграммойToolStripMenuItem;
|
||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||
private COP.ExcelComponent excelComponent;
|
||||
private KOP.PDFComponents.PdfChartComponent gistogramPdfComponent;
|
||||
private Lab1.LogicalComponents.TableDocument componentWord;
|
||||
}
|
||||
}
|
278
WinFormsLibrary2/FormMain.cs
Normal file
278
WinFormsLibrary2/FormMain.cs
Normal file
@ -0,0 +1,278 @@
|
||||
using COP;
|
||||
using COP.Info;
|
||||
using KOP;
|
||||
using Lab1;
|
||||
using static Lab1.LogicalComponents.TableDocument;
|
||||
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Lab1.LogicalComponents.SupportClasses;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using KOP.PDFComponents.OfficePackage;
|
||||
using System.Windows.Forms;
|
||||
using ShopBusinessLogic.BusinessLogics;
|
||||
using ShopContracts.BindingModels;
|
||||
using ShopContracts.BusinessLogicsContracts;
|
||||
using ShopContracts.SearchModels;
|
||||
using ShopContracts.ViewModels;
|
||||
using static COP.ExcelComponent;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||||
using LegendPosition = KOP.PDFComponents.Enums.LegendPosition;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using KOP.Addition;
|
||||
using KOP.PDFComponents;
|
||||
|
||||
namespace ShopView
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICustomerLogic _customerLogic;
|
||||
private readonly IProductCategoryLogic _productCategoryLogic;
|
||||
public FormMain(ILogger<FormMain> logger, ICustomerLogic customerLogic, IProductCategoryLogic productCategoryLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_customerLogic = customerLogic;
|
||||
_productCategoryLogic = productCategoryLogic;
|
||||
Configure();
|
||||
}
|
||||
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
try
|
||||
{
|
||||
tableOfValues.ClearRows();
|
||||
var list = _customerLogic.Read(null);
|
||||
if (list != null)
|
||||
{
|
||||
tableOfValues.AddRows(list);
|
||||
}
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки клиентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
|
||||
{
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void СоздатьToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCustomer));
|
||||
if (service is FormCustomer form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void Configure()
|
||||
{
|
||||
ColumnInfo ci1 = new ColumnInfo("ID", 100, false, "Id");
|
||||
ColumnInfo ci2 = new ColumnInfo("FIO", 100, true, "ФИО");
|
||||
ColumnInfo ci3 = new ColumnInfo("ProductCategoryName", 80, true, "Категория товара");
|
||||
ColumnInfo ci5 = new ColumnInfo("PhotoFilePath", 80, false, "PhotoFilePath");
|
||||
ColumnInfo ci4 = new ColumnInfo("Email", 80, true, "Электронная почта");
|
||||
List<ColumnInfo> lst = new List<ColumnInfo>();
|
||||
lst.Add(ci1);
|
||||
lst.Add(ci2);
|
||||
lst.Add(ci3);
|
||||
lst.Add(ci4);
|
||||
lst.Add(ci5);
|
||||
tableOfValues.ColumnConfiguration(new TableConfiguration(lst));
|
||||
}
|
||||
|
||||
private void ИзменитьToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCustomer));
|
||||
tableOfValues.IndexProperty = tableOfValues.myDataGridView.CurrentRow.Index;
|
||||
if (service is FormCustomer form)
|
||||
{
|
||||
if (tableOfValues.IndexProperty != -1)
|
||||
{
|
||||
var selectedCustomer = tableOfValues.GetUser<CustomerSearchModel>();
|
||||
form.Id = Convert.ToInt32(selectedCustomer.Id);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Выберите клиента для редактирования");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void УдалитьToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
tableOfValues.IndexProperty = tableOfValues.myDataGridView.CurrentRow.Index;
|
||||
var selectedCustomer = tableOfValues.GetUser<CustomerSearchModel>();
|
||||
int id = Convert.ToInt32(selectedCustomer.Id);
|
||||
try
|
||||
{
|
||||
_customerLogic.Delete(new CustomerBindingModel { Id = id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void СоздатьExcelСФотоToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var list = _customerLogic.Read(null);
|
||||
List<ImageInfo> images = new();
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "xlsx|*.xlsx"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (list != null)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
images.Add(new ImageInfo() { FilePath = item.PhotoFilePath });
|
||||
}
|
||||
}
|
||||
ExcelImageInfo info = new(dialog.FileName, "Документ с фотографиями клиентов", images);
|
||||
excelComponent.GenerateExcelWithImages(info);
|
||||
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void СоздатьДокументСТаблицейToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var list = _customerLogic.Read(null);
|
||||
List<CustomerBindingModel> data = new();
|
||||
List<int[]> mergedColumns = new()
|
||||
{
|
||||
new int[] { 1, 2 }
|
||||
};
|
||||
|
||||
|
||||
List<ColumnDefinition> columnDefinitions = new()
|
||||
{
|
||||
new ColumnDefinition { Header = "ID", PropertyName = "Id", Weight = 11 },
|
||||
new ColumnDefinition { Header = "Личные данные", PropertyName = "PersonalData", Weight = 11 },
|
||||
new ColumnDefinition { Header = "Личные данные", PropertyName = "PersonalData1", Weight = 11 },
|
||||
new ColumnDefinition { Header = "Категория товаров", PropertyName = "ProductCategoryName", Weight = 21 }
|
||||
};
|
||||
|
||||
List<ColumnDefinition> columnDefinitions2 = new()
|
||||
{
|
||||
new ColumnDefinition { Header = "ID", PropertyName = "Id", Weight = 11 },
|
||||
new ColumnDefinition { Header = "ФИО", PropertyName = "FIO", Weight = 11 },
|
||||
new ColumnDefinition { Header = "Электронная почта", PropertyName = "Email", Weight = 70 },
|
||||
new ColumnDefinition { Header = "Категория товаров", PropertyName = "ProductCategoryName", Weight = 21 }
|
||||
};
|
||||
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (list != null)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
data.Add(new CustomerBindingModel() { Id = item.Id, FIO = item.FIO, Email = item.Email, ProductCategoryName = item.ProductCategoryName});
|
||||
}
|
||||
}
|
||||
TableDocumentInfo<CustomerBindingModel> tableWord = new(dialog.FileName, "Таблица с клиентами", columnDefinitions, columnDefinitions2, data, mergedColumns);
|
||||
Lab1.LogicalComponents.TableDocument.CreateTable(tableWord);
|
||||
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void СоздатьДокументСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var listCustomers = _customerLogic.Read(null);
|
||||
var listProductCategorys = _productCategoryLogic.Read(null);
|
||||
List<(string, int)> data = new();
|
||||
var Data = new Dictionary<string, int[]>();
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "pdf|*.pdf"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < listProductCategorys.Count; i++)
|
||||
{
|
||||
int count = 0;
|
||||
for (int j = 0; j < listCustomers.Count; j++)
|
||||
{
|
||||
string[] dirs = listCustomers[j].ProductCategoryName.Split(";");
|
||||
foreach (var dir in dirs)
|
||||
{
|
||||
if (dir == listProductCategorys[i].Name) count++;
|
||||
}
|
||||
}
|
||||
data.Add((listProductCategorys[i].Name, count));
|
||||
}
|
||||
if (data != null)
|
||||
{
|
||||
foreach (var item in data)
|
||||
{
|
||||
Data.Add(item.Item1, new[] {item.Item2 });
|
||||
|
||||
}
|
||||
}
|
||||
PdfChartComponent pdfChartComponent = new PdfChartComponent();
|
||||
pdfChartComponent.CreateDocument(dialog.FileName, "Histogram", "Customers-ProductCategorys", LegendPosition.Right, Data);
|
||||
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void СправочникиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormHandbooks));
|
||||
if (service is FormHandbooks form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
126
WinFormsLibrary2/FormMain.resx
Normal file
126
WinFormsLibrary2/FormMain.resx
Normal file
@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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="excelComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentWord.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>185, 17</value>
|
||||
</metadata>
|
||||
</root>
|
45
WinFormsLibrary2/Program.cs
Normal file
45
WinFormsLibrary2/Program.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using System;
|
||||
using ShopBusinessLogic.BusinessLogics;
|
||||
using ShopContracts.BusinessLogicsContracts;
|
||||
using ShopContracts.StoragesContracts;
|
||||
using ShopDatabaseImplement.Implements;
|
||||
|
||||
|
||||
namespace ShopView
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IProductCategoryStorage, ProductCategoryStorage>();
|
||||
services.AddTransient<ICustomerStorage, CustomerStorage>();
|
||||
services.AddTransient<IProductCategoryLogic, ProductCategoryLogic>();
|
||||
services.AddTransient<ICustomerLogic, CustomerLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormCustomer>();
|
||||
services.AddTransient<FormHandbooks>();
|
||||
}
|
||||
}
|
||||
}
|
31
WinFormsLibrary2/ShopView.csproj
Normal file
31
WinFormsLibrary2/ShopView.csproj
Normal file
@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<OutputType>WinExe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="COP" Version="1.0.0" />
|
||||
<PackageReference Include="KOP" Version="1.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
<PackageReference Include="NLog" Version="5.2.5" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
||||
<PackageReference Include="ToNu" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ShopBusinessLogic\ShopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\ShopContracts\ShopContracts.csproj" />
|
||||
<ProjectReference Include="..\ShopDatabaseImplement\ShopDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user