Lisov N.A LabWork1 #1

Closed
1yuee wants to merge 5 commits from LabWork01 into main
63 changed files with 4027 additions and 50 deletions

View File

@ -0,0 +1,127 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierBusinessLogic.BusinessLogic
{
public class DressLogic : IDressLogic
{
private readonly ILogger _logger;
private readonly IDressStorage _dressStorage;
public DressLogic(ILogger<DressLogic> logger, IDressStorage dressStorage)
{
_logger = logger;
_dressStorage = dressStorage;
}
public bool Create(DressBindingModel model)
{
CheckModel(model);
if(_dressStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DressBindingModel model)
{
CheckModel(model);
if (_dressStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DressBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. ID:{ID}", model.ID);
if (_dressStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public DressViewModel? ReadElement(DressSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DressName:{DressName}.ID:{ ID}", model.DressName, model.ID);
var element = _dressStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
return element;
}
public List<DressViewModel>? ReadList(DressSearchModel? model)
{
_logger.LogInformation("ReadList. DressName:{DressName}. ID:{ ID}", model?.DressName, model?.ID);
var list = model == null ? _dressStorage.GetFullList() : _dressStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(DressBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.DressName))
{
throw new ArgumentNullException("Invalid name of dress",nameof(model.DressName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Price of dress should be higher than 0", nameof(model.Price));
}
_logger.LogInformation("Product. DressName:{DressName}. Cost:{Cost}. ID: {ID}", model.DressName, model.Price, model.ID);
var element = _dressStorage.GetElement(new DressSearchModel
{
DressName = model.DressName,
});
if (element != null && element.ID != model.ID)
{
throw new InvalidOperationException("Product with such name already exists");
}
}
}
}

View File

@ -0,0 +1,131 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierBusinessLogic.BusinessLogic
{
public class MaterialLogic : IMaterialLogic
{
private readonly ILogger _logger;
private readonly IMaterialStorage _componentStorage;
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public bool Create(MaterialBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(MaterialBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(MaterialBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. ID:{ID}", model.ID);
if (_componentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public MaterialViewModel? ReadElement(MaterialSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}.ID:{ ID}", model.ComponentName, model.ID);
var element = _componentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
return element;
}
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. ID:{ ID}", model?.ComponentName, model?.ID);
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(MaterialBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ComponentName))
{
throw new ArgumentNullException("Invalid name of component", nameof(model.ComponentName));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Price of component should be higher than 0", nameof(model.Cost));
}
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. ID: { ID} ", model.ComponentName, model.Cost, model.ID);
var element = _componentStorage.GetElement(new MaterialSearchModel
{
ComponentName = model.ComponentName
});
if (element != null && element.ID != model.ID)
{
throw new InvalidOperationException("Component with such name already exists.");
}
}
}
}

View File

@ -0,0 +1,131 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Unknown)
{
_logger.LogWarning("Insert operation failed");
return false;
}
model.Status = OrderStatus.Accepted;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool GivenOrder(OrderBindingModel model)
Review

Логика методов передачи заказа в работу, выполнении заказ и выдачи заказа схожа, нужно это учитывать

Логика методов передачи заказа в работу, выполнении заказ и выдачи заказа схожа, нужно это учитывать
{
CheckModel(model, false);
_logger.LogInformation("Update to given status. ID:{ID}", model.ID);
if (model.Status != OrderStatus.Ready)
{
_logger.LogWarning("Update operation failed");
return false;
}
model.Status = OrderStatus.Given;
model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
return true;
}
public bool ReadyOrder(OrderBindingModel model)
{
CheckModel(model,false);
_logger.LogInformation("Update to ready status. ID:{ID}", model.ID);
if ( model.Status != OrderStatus.InProcess)
{
_logger.LogWarning("Update operation failed");
return false;
}
model.Status = OrderStatus.Ready;
_orderStorage.Update(model);
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model,false);
_logger.LogInformation("Update to in process status. ID:{ID}", model.ID);
if (model.Status != OrderStatus.Accepted)
{
_logger.LogWarning("Update operation failed");
return false;
}
model.Status = OrderStatus.InProcess;
_orderStorage.Update(model);
return true;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. OrderID:{ID}",model?.ID);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Order. OrderID: { ID} ",model.ID);
var element = _orderStorage.GetElement(new OrderSearchModel
{
ID = model.ID
});
if (element != null && element.ID == model.ID)
{
throw new InvalidOperationException("Order with such name already exists.");
}
}
}
}

View 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="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DressAtelierContracts\DressAtelierContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,20 @@
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.BindingModels
{
public class DressBindingModel : IDressModel
{
public int ID { get; set; }
public string DressName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IMaterialModel, int)> DressComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierDataModels.Models;
namespace DressAtelierContracts.BindingModels
{
public class MaterialBindingModel : IMaterialModel
{
public int ID { get; set; }
public string ComponentName { get; set; } = string.Empty;
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using DressAtelierDataModels.Enums;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int ID { get; set; }
public int DressID { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.BusinessLogicContracts
{
public interface IDressLogic
{
List<DressViewModel>? ReadList(DressSearchModel? model);
DressViewModel? ReadElement(DressSearchModel model);
bool Create(DressBindingModel model);
bool Update(DressBindingModel model);
bool Delete(DressBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.ViewModels;
namespace DressAtelierContracts.BusinessLogicContracts
{
public interface IMaterialLogic
{
List<MaterialViewModel>? ReadList(MaterialSearchModel? model);
MaterialViewModel? ReadElement(MaterialSearchModel model);
bool Create(MaterialBindingModel model);
bool Update(MaterialBindingModel model);
bool Delete(MaterialBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool ReadyOrder(OrderBindingModel model);
bool GivenOrder(OrderBindingModel model);
}
}

View 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="..\DressAtelierDataModels\DressAtelierDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.SearchModels
{
public class DressSearchModel
{
public int? ID { get; set; }
public string? DressName { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.SearchModels
{
public class MaterialSearchModel
{
public int? ID { get; set; }
public string? ComponentName { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.SearchModels
{
public class OrderSearchModel
{
public int? ID { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.StorageContracts
{
public interface IDressStorage
{
List<DressViewModel> GetFullList();
List<DressViewModel> GetFilteredList(DressSearchModel model);
DressViewModel? GetElement(DressSearchModel model);
DressViewModel? Insert(DressBindingModel model);
DressViewModel? Delete(DressBindingModel model);
DressViewModel? Update(DressBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using DressAtelierContracts.ViewModels;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.StorageContracts
{
public interface IMaterialStorage
{
List<MaterialViewModel> GetFullList();
List<MaterialViewModel> GetFilteredList(MaterialSearchModel model);
MaterialViewModel? GetElement(MaterialSearchModel model);
MaterialViewModel? Insert(MaterialBindingModel model);
MaterialViewModel? Update(MaterialBindingModel model);
MaterialViewModel? Delete(MaterialBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.StorageContracts
{
public interface IOrderStorage
{
List<OrderViewModel>? GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
}
}

View File

@ -0,0 +1,23 @@
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.ViewModels
{
public class DressViewModel : IDressModel
{
[DisplayName("Name of dress")]
public string DressName { get; set; } = string.Empty;
[DisplayName("Cost")]
public double Price { get; set; }
public Dictionary<int, (IMaterialModel, int)> DressComponents { get; set; } = new();
public int ID { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
namespace DressAtelierContracts.ViewModels
{
public class MaterialViewModel : IMaterialModel
{
[DisplayName("Name of component")]
public string ComponentName { get; set; } = string.Empty;
[DisplayName("Cost")]
public double Cost { get; set; }
public int ID { get; set; }
}
}

View File

@ -0,0 +1,38 @@
using DressAtelierDataModels.Enums;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("ID")]
public int ID { get; set; }
public int DressID { get; set; }
[DisplayName("DressName")]
public string DressName { get; set; }
[DisplayName("Quantity")]
public int Count { get; set; }
[DisplayName("Overall price")]
public double Sum { get; set; }
[DisplayName("Status")]
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
[DisplayName("Date of creation")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Date of implementation")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierDataModels.Enums
{
public enum OrderStatus
{
Unknown = -1,
Accepted = 0,
InProcess = 1,
Ready = 2,
Given = 3
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierDataModels
{
public interface IID
{
int ID { get; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierDataModels.Models
{
public interface IDressModel : IID
{
string DressName { get; }
double Price { get; }
Dictionary<int,(IMaterialModel,int)> DressComponents { get; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierDataModels.Models
{
public interface IMaterialModel : IID
{
string ComponentName { get; }
double Cost { get; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierDataModels.Enums;
namespace DressAtelierDataModels.Models
{
public interface IOrderModel :IID
{
int DressID { get;}
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
}

View File

@ -0,0 +1,31 @@
using DressAtelierListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierListImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Material> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Dress> Dresses { get; set; }
private DataListSingleton()
{
Components = new List<Material>();
Orders = new List<Order>();
Dresses = new List<Dress>();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DressAtelierContracts\DressAtelierContracts.csproj" />
<ProjectReference Include="..\DressAtelierDataModels\DressAtelierDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierListImplement.Models;
namespace DressAtelierListImplement.Implements
{
public class DressStorage : IDressStorage
{
private readonly DataListSingleton _source;
public DressStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<DressViewModel> GetFullList()
{
var result = new List<DressViewModel>();
foreach (var material in _source.Dresses)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<DressViewModel> GetFilteredList(DressSearchModel model)
{
var result = new List<DressViewModel>();
if (string.IsNullOrEmpty(model.DressName))
{
return result;
}
foreach (var dress in _source.Dresses)
{
if (dress.DressName.Contains(model.DressName))
{
result.Add(dress.GetViewModel);
}
}
return result;
}
public DressViewModel? GetElement(DressSearchModel model)
{
if (string.IsNullOrEmpty(model.DressName) && !model.ID.HasValue)
{
return null;
}
foreach (var dress in _source.Dresses)
{
if ((!string.IsNullOrEmpty(model.DressName) && dress.DressName == model.DressName) || (model.ID.HasValue && dress.ID == model.ID))
{
return dress.GetViewModel;
}
}
return null;
}
public DressViewModel? Insert(DressBindingModel model)
{
model.ID = 1;
foreach (var dress in _source.Dresses)
{
if (model.ID <= dress.ID)
{
model.ID = dress.ID + 1;
}
}
var newComponent = Dress.Create(model);
if (newComponent == null)
{
return null;
}
_source.Dresses.Add(newComponent);
return newComponent.GetViewModel;
}
public DressViewModel? Update(DressBindingModel model)
{
foreach (var dress in _source.Dresses)
{
if (dress.ID == model.ID)
{
dress.Update(model);
return dress.GetViewModel;
}
}
return null;
}
public DressViewModel? Delete(DressBindingModel model)
{
for (int i = 0; i < _source.Dresses.Count; ++i)
{
if (_source.Dresses[i].ID == model.ID)
{
var element = _source.Dresses[i];
_source.Dresses.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierListImplement.Models;
namespace DressAtelierListImplement.Implements
{
public class MaterialStorage : IMaterialStorage
{
private readonly DataListSingleton _source;
public MaterialStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<MaterialViewModel> GetFullList()
{
var result = new List<MaterialViewModel>();
foreach (var material in _source.Components)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
{
var result = new List<MaterialViewModel>();
if (string.IsNullOrEmpty(model.ComponentName))
{
return result;
}
foreach (var component in _source.Components)
{
if (component.ComponentName.Contains(model.ComponentName))
{
result.Add(component.GetViewModel);
}
}
return result;
}
public MaterialViewModel? GetElement(MaterialSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.ID.HasValue)
{
return null;
}
foreach (var component in _source.Components)
{
if ((!string.IsNullOrEmpty(model.ComponentName) &&
component.ComponentName == model.ComponentName) || (model.ID.HasValue && component.ID == model.ID))
{
return component.GetViewModel;
}
}
return null;
}
public MaterialViewModel? Insert(MaterialBindingModel model)
{
model.ID = 1;
foreach (var component in _source.Components)
{
if (model.ID <= component.ID)
{
model.ID = component.ID + 1;
}
}
var newComponent = Material.Create(model);
if (newComponent == null)
{
return null;
}
_source.Components.Add(newComponent);
return newComponent.GetViewModel;
}
public MaterialViewModel? Update(MaterialBindingModel model)
{
foreach (var component in _source.Components)
{
if (component.ID == model.ID)
{
component.Update(model);
return component.GetViewModel;
}
}
return null;
}
public MaterialViewModel? Delete(MaterialBindingModel model)
{
for (int i = 0; i < _source.Components.Count; ++i)
{
if (_source.Components[i].ID == model.ID)
{
var element = _source.Components[i];
_source.Components.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierListImplement.Models;
namespace DressAtelierListImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataListSingleton _source;
public OrderStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(ReceiveDressName(order.GetViewModel));
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.ID.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if (order.ID == model.ID)
{
result.Add(ReceiveDressName(order.GetViewModel));
}
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.ID.HasValue)
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.ID.HasValue && order.ID == model.ID)
{
return ReceiveDressName(order.GetViewModel);
}
}
return null;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.ID = 1;
foreach (var order in _source.Orders)
{
if (model.ID <= order.ID)
{
model.ID = order.ID + 1;
}
}
var newComponent = Order.Create(model);
if (newComponent == null)
{
return null;
}
_source.Orders.Add(newComponent);
return ReceiveDressName(newComponent.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel model)
{
foreach (var order in _source.Orders)
{
if (order.ID == model.ID)
{
order.Update(model);
return ReceiveDressName(order.GetViewModel);
}
}
return null;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
for (int i = 0; i < _source.Orders.Count; ++i)
{
if (_source.Orders[i].ID == model.ID)
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return ReceiveDressName(element.GetViewModel);
}
}
return null;
}
private OrderViewModel? ReceiveDressName(OrderViewModel model)
{
var dress = _source.Dresses.Find(un => un.ID == model.ID);
model.DressName = dress == null ? "" : dress.DressName;
return model;
}
}
}

View File

@ -0,0 +1,58 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierListImplement.Models
{
public class Dress : IDressModel
{
public int ID { get; private set; }
public string DressName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IMaterialModel, int)> DressComponents { get; private set; } = new Dictionary<int, (IMaterialModel, int)>();
public static Dress? Create(DressBindingModel? model)
{
if (model == null)
{
return null;
}
return new Dress()
{
ID = model.ID,
DressName = model.DressName,
Price = model.Price,
DressComponents = model.DressComponents
};
}
public void Update(DressBindingModel? model)
{
if (model == null)
{
return;
}
DressName = model.DressName;
Price = model.Price;
DressComponents = model.DressComponents;
}
public DressViewModel GetViewModel => new()
{
ID = ID,
DressName = DressName,
Price = Price,
DressComponents = DressComponents
};
}
}

View File

@ -0,0 +1,49 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierListImplement.Models
{
public class Material : IMaterialModel
{
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public int ID { get; private set; }
public static Material? Create(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new Material()
{
ID = model.ID,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(MaterialBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public MaterialViewModel GetViewModel => new()
{
ID = ID,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,77 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Enums;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierListImplement.Models
{
public class Order : IOrderModel
{
public int ID { get; private set; }
public int DressID { get; private set; }
public int Count {get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
ID = model.ID,
DressID = model.DressID,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
DressID = model.DressID;
Review

Не требуется обновлять все данные, только статус и дату выполнения

Не требуется обновлять все данные, только статус и дату выполнения
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
ID = ID,
DressID = DressID,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -1,39 +0,0 @@
namespace SewingDresses
{
partial class Form1
{
/// <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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

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

230
SewingDresses/FormDress.Designer.cs generated Normal file
View File

@ -0,0 +1,230 @@
namespace SewingDresses
{
partial class FormDress
{
/// <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.nameDressLabel = new System.Windows.Forms.Label();
this.priceDressLabel = new System.Windows.Forms.Label();
this.nameDressTextBox = new System.Windows.Forms.TextBox();
this.priceDressTextBox = new System.Windows.Forms.TextBox();
this.materialsGroupBox = new System.Windows.Forms.GroupBox();
this.RefreshButton = new System.Windows.Forms.Button();
this.deleteButton = new System.Windows.Forms.Button();
this.changeButton = new System.Windows.Forms.Button();
this.AddButton = new System.Windows.Forms.Button();
this.dressGridView = new System.Windows.Forms.DataGridView();
this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnMaterial = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnQuantity = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.saveButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.materialsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dressGridView)).BeginInit();
this.SuspendLayout();
//
// nameDressLabel
//
this.nameDressLabel.AutoSize = true;
this.nameDressLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.nameDressLabel.Location = new System.Drawing.Point(12, 9);
this.nameDressLabel.Name = "nameDressLabel";
this.nameDressLabel.Size = new System.Drawing.Size(66, 25);
this.nameDressLabel.TabIndex = 0;
this.nameDressLabel.Text = "Name:";
//
// priceDressLabel
//
this.priceDressLabel.AutoSize = true;
this.priceDressLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.priceDressLabel.Location = new System.Drawing.Point(12, 46);
this.priceDressLabel.Name = "priceDressLabel";
this.priceDressLabel.Size = new System.Drawing.Size(58, 25);
this.priceDressLabel.TabIndex = 1;
this.priceDressLabel.Text = "Price:";
//
// nameDressTextBox
//
this.nameDressTextBox.Location = new System.Drawing.Point(84, 11);
this.nameDressTextBox.Name = "nameDressTextBox";
this.nameDressTextBox.Size = new System.Drawing.Size(287, 23);
this.nameDressTextBox.TabIndex = 2;
//
// priceDressTextBox
//
this.priceDressTextBox.Location = new System.Drawing.Point(84, 48);
this.priceDressTextBox.Name = "priceDressTextBox";
this.priceDressTextBox.ReadOnly = true;
this.priceDressTextBox.Size = new System.Drawing.Size(178, 23);
this.priceDressTextBox.TabIndex = 3;
//
// materialsGroupBox
//
this.materialsGroupBox.Controls.Add(this.RefreshButton);
this.materialsGroupBox.Controls.Add(this.deleteButton);
this.materialsGroupBox.Controls.Add(this.changeButton);
this.materialsGroupBox.Controls.Add(this.AddButton);
this.materialsGroupBox.Controls.Add(this.dressGridView);
this.materialsGroupBox.Location = new System.Drawing.Point(16, 89);
this.materialsGroupBox.Name = "materialsGroupBox";
this.materialsGroupBox.Size = new System.Drawing.Size(770, 301);
this.materialsGroupBox.TabIndex = 4;
this.materialsGroupBox.TabStop = false;
this.materialsGroupBox.Text = "Materials";
//
// RefreshButton
//
this.RefreshButton.Location = new System.Drawing.Point(638, 225);
this.RefreshButton.Name = "RefreshButton";
this.RefreshButton.Size = new System.Drawing.Size(103, 36);
this.RefreshButton.TabIndex = 4;
this.RefreshButton.Text = "Refresh";
this.RefreshButton.UseVisualStyleBackColor = true;
this.RefreshButton.Click += new System.EventHandler(this.ButtonRefresh_Click);
//
// deleteButton
//
this.deleteButton.Location = new System.Drawing.Point(638, 168);
this.deleteButton.Name = "deleteButton";
this.deleteButton.Size = new System.Drawing.Size(103, 36);
this.deleteButton.TabIndex = 3;
this.deleteButton.Text = "Delete";
this.deleteButton.UseVisualStyleBackColor = true;
this.deleteButton.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// changeButton
//
this.changeButton.Location = new System.Drawing.Point(638, 110);
this.changeButton.Name = "changeButton";
this.changeButton.Size = new System.Drawing.Size(103, 36);
this.changeButton.TabIndex = 2;
this.changeButton.Text = "Change";
this.changeButton.UseVisualStyleBackColor = true;
this.changeButton.Click += new System.EventHandler(this.ButtonUpdate_Click);
//
// AddButton
//
this.AddButton.Location = new System.Drawing.Point(638, 56);
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(103, 36);
this.AddButton.TabIndex = 1;
this.AddButton.Text = "Add";
this.AddButton.UseVisualStyleBackColor = true;
this.AddButton.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dressGridView
//
this.dressGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dressGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnID,
this.ColumnMaterial,
this.ColumnQuantity});
this.dressGridView.Location = new System.Drawing.Point(6, 22);
this.dressGridView.Name = "dressGridView";
this.dressGridView.RowTemplate.Height = 25;
this.dressGridView.Size = new System.Drawing.Size(588, 273);
this.dressGridView.TabIndex = 0;
//
// ColumnID
//
this.ColumnID.HeaderText = "ID";
this.ColumnID.Name = "ColumnID";
this.ColumnID.Visible = false;
//
// ColumnMaterial
//
this.ColumnMaterial.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnMaterial.HeaderText = "Material";
this.ColumnMaterial.Name = "ColumnMaterial";
//
// ColumnQuantity
//
this.ColumnQuantity.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnQuantity.HeaderText = "Quantity";
this.ColumnQuantity.Name = "ColumnQuantity";
//
// saveButton
//
this.saveButton.Location = new System.Drawing.Point(562, 407);
this.saveButton.Name = "saveButton";
this.saveButton.Size = new System.Drawing.Size(89, 31);
this.saveButton.TabIndex = 5;
this.saveButton.Text = "Save";
this.saveButton.UseVisualStyleBackColor = true;
this.saveButton.Click += new System.EventHandler(this.ButtonSave_Click);
//
// cancelButton
//
this.cancelButton.Location = new System.Drawing.Point(657, 407);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(89, 31);
this.cancelButton.TabIndex = 6;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormDress
//
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.cancelButton);
this.Controls.Add(this.saveButton);
this.Controls.Add(this.materialsGroupBox);
this.Controls.Add(this.priceDressTextBox);
this.Controls.Add(this.nameDressTextBox);
this.Controls.Add(this.priceDressLabel);
this.Controls.Add(this.nameDressLabel);
this.Name = "FormDress";
this.Text = "FormDress";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
this.Load += new System.EventHandler(this.FormDress_Load);
this.materialsGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dressGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label nameDressLabel;
private Label priceDressLabel;
private TextBox nameDressTextBox;
private TextBox priceDressTextBox;
private GroupBox materialsGroupBox;
private Button RefreshButton;
private Button deleteButton;
private Button changeButton;
private Button AddButton;
private DataGridView dressGridView;
private DataGridViewTextBoxColumn ColumnID;
private DataGridViewTextBoxColumn ColumnMaterial;
private DataGridViewTextBoxColumn ColumnQuantity;
private Button saveButton;
private Button cancelButton;
}
}

229
SewingDresses/FormDress.cs Normal file
View File

@ -0,0 +1,229 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using DressAtelierDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SewingDresses
{
public partial class FormDress : Form
{
private readonly ILogger _logger;
private readonly IDressLogic _logic;
private int? _id;
private Dictionary<int, (IMaterialModel, int)> _dressComponents;
public int ID { set { _id = value; } }
public FormDress(ILogger<FormDress> logger, IDressLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_dressComponents = new Dictionary<int, (IMaterialModel, int)>();
}
private void FormDress_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Downloading dresses");
try
{
var view = _logic.ReadElement(new DressSearchModel
{
ID = _id.Value,
});
if (view != null)
{
nameDressTextBox.Text = view.DressName;
priceDressTextBox.Text = view.Price.ToString();
_dressComponents = view.DressComponents ?? new Dictionary<int, (IMaterialModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Downloading dress error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Downloading material for dress");
try
{
if (_dressComponents != null)
{
dressGridView.Rows.Clear();
foreach (var pc in _dressComponents)
{
dressGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
}
priceDressTextBox.Text = CalcPrice().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error downloading material for dress");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDressMaterial));
if (service is FormDressMaterial form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.MaterialModel == null)
{
return;
}
_logger.LogInformation("Adding new material: { ComponentName}- { Count}", form.MaterialModel.ComponentName, form.Count);
if (_dressComponents.ContainsKey(form.ID))
{
_dressComponents[form.ID] = (form.MaterialModel, form.Count);
}
else
{
_dressComponents.Add(form.ID, (form.MaterialModel, form.Count));
}
LoadData();
}
}
}
private void ButtonUpdate_Click(object sender, EventArgs e)
{
if (dressGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDressMaterial));
if (service is FormDressMaterial form)
{
int id = Convert.ToInt32(dressGridView.SelectedRows[0].Cells[0].Value);
form.ID = id;
form.Count = _dressComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.MaterialModel == null)
{
return;
}
_logger.LogInformation("Changing material:{ ComponentName}- { Count}", form.MaterialModel.ComponentName, form.Count);
_dressComponents[form.ID] = (form.MaterialModel,form.Count);
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (dressGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Delete record?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Deletion material:{ ComponentName} - { Count}", dressGridView.SelectedRows[0].Cells[1].Value);
_dressComponents?.Remove(Convert.ToInt32(dressGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(nameDressTextBox.Text))
{
MessageBox.Show("Fill field name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(priceDressTextBox.Text))
{
MessageBox.Show("Fill field price", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
if (_dressComponents == null || _dressComponents.Count == 0)
{
MessageBox.Show("Fill materials", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving dress");
try
{
var model = new DressBindingModel
{
ID = _id ?? 0,
DressName = nameDressTextBox.Text,
Price = Convert.ToDouble(priceDressTextBox.Text),
DressComponents = _dressComponents
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Saving error. Extra information in logs.");
}
MessageBox.Show("Saving was succesfull", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Saving dress error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private double CalcPrice()
{
double price = 0;
foreach (var elem in _dressComponents)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}
return Math.Round(price * 1.1, 2);
}
}
}

View File

@ -0,0 +1,69 @@
<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="ColumnID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnMaterial.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnQuantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,122 @@
namespace SewingDresses
{
partial class FormDressMaterial
{
/// <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.materialNameLabel = new System.Windows.Forms.Label();
this.materialQuantityLabel = new System.Windows.Forms.Label();
this.materialComboBox = new System.Windows.Forms.ComboBox();
this.quantityTextBox = new System.Windows.Forms.TextBox();
this.saveButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// materialNameLabel
//
this.materialNameLabel.AutoSize = true;
this.materialNameLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.materialNameLabel.Location = new System.Drawing.Point(12, 19);
this.materialNameLabel.Name = "materialNameLabel";
this.materialNameLabel.Size = new System.Drawing.Size(86, 25);
this.materialNameLabel.TabIndex = 0;
this.materialNameLabel.Text = "Material:";
//
// materialQuantityLabel
//
this.materialQuantityLabel.AutoSize = true;
this.materialQuantityLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.materialQuantityLabel.Location = new System.Drawing.Point(12, 63);
this.materialQuantityLabel.Name = "materialQuantityLabel";
this.materialQuantityLabel.Size = new System.Drawing.Size(88, 25);
this.materialQuantityLabel.TabIndex = 1;
this.materialQuantityLabel.Text = "Quantity:";
//
// materialComboBox
//
this.materialComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.materialComboBox.FormattingEnabled = true;
this.materialComboBox.Location = new System.Drawing.Point(123, 19);
this.materialComboBox.Name = "materialComboBox";
this.materialComboBox.Size = new System.Drawing.Size(342, 23);
this.materialComboBox.TabIndex = 2;
//
// quantityTextBox
//
this.quantityTextBox.Location = new System.Drawing.Point(123, 63);
this.quantityTextBox.Name = "quantityTextBox";
this.quantityTextBox.Size = new System.Drawing.Size(342, 23);
this.quantityTextBox.TabIndex = 3;
//
// saveButton
//
this.saveButton.Location = new System.Drawing.Point(275, 104);
this.saveButton.Name = "saveButton";
this.saveButton.Size = new System.Drawing.Size(92, 23);
this.saveButton.TabIndex = 4;
this.saveButton.Text = "Save";
this.saveButton.UseVisualStyleBackColor = true;
this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
//
// cancelButton
//
this.cancelButton.Location = new System.Drawing.Point(373, 104);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(92, 23);
this.cancelButton.TabIndex = 5;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// FormDressMaterial
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(477, 129);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.saveButton);
this.Controls.Add(this.quantityTextBox);
this.Controls.Add(this.materialComboBox);
this.Controls.Add(this.materialQuantityLabel);
this.Controls.Add(this.materialNameLabel);
this.Name = "FormDressMaterial";
this.Text = "FormDressMaterial";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label materialNameLabel;
private Label materialQuantityLabel;
private ComboBox materialComboBox;
private TextBox quantityTextBox;
private Button saveButton;
private Button cancelButton;
}
}

View File

@ -0,0 +1,105 @@
using DressAtelierContracts.ViewModels;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.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;
using DressAtelierDataModels.Models;
using DressAtelierContracts.BusinessLogicContracts;
namespace SewingDresses
{
public partial class FormDressMaterial : Form
{
private readonly List<MaterialViewModel>? _list;
public int ID
{
get
{
return Convert.ToInt32(materialComboBox.SelectedValue);
}
set
{
materialComboBox.SelectedValue = value;
}
}
public IMaterialModel? MaterialModel
{
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(quantityTextBox.Text);
}
set
{
quantityTextBox.Text = value.ToString();
}
}
public FormDressMaterial(IMaterialLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
materialComboBox.DisplayMember = "ComponentName";
materialComboBox.ValueMember = "ID";
materialComboBox.DataSource = _list;
materialComboBox.SelectedItem = null;
}
}
private void saveButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(quantityTextBox.Text))
{
MessageBox.Show("Fill quantity field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (materialComboBox.SelectedValue == null)
{
MessageBox.Show("Choose material", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void cancelButton_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>

115
SewingDresses/FormDresses.Designer.cs generated Normal file
View File

@ -0,0 +1,115 @@
namespace SewingDresses
{
partial class FormDresses
{
/// <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.dressGridView = new System.Windows.Forms.DataGridView();
this.ButtonAdd = new System.Windows.Forms.Button();
this.ButtonChange = new System.Windows.Forms.Button();
this.ButtonDelete = new System.Windows.Forms.Button();
this.ButtonRefresh = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dressGridView)).BeginInit();
this.SuspendLayout();
//
// dressGridView
//
this.dressGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
this.dressGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dressGridView.Location = new System.Drawing.Point(2, 2);
this.dressGridView.Name = "dressGridView";
this.dressGridView.RowTemplate.Height = 25;
this.dressGridView.Size = new System.Drawing.Size(605, 447);
this.dressGridView.TabIndex = 0;
//
// ButtonAdd
//
this.ButtonAdd.Location = new System.Drawing.Point(661, 30);
this.ButtonAdd.Name = "ButtonAdd";
this.ButtonAdd.Size = new System.Drawing.Size(92, 35);
this.ButtonAdd.TabIndex = 1;
this.ButtonAdd.Text = "Add";
this.ButtonAdd.UseVisualStyleBackColor = true;
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// ButtonChange
//
this.ButtonChange.Location = new System.Drawing.Point(661, 85);
this.ButtonChange.Name = "ButtonChange";
this.ButtonChange.Size = new System.Drawing.Size(92, 35);
this.ButtonChange.TabIndex = 2;
this.ButtonChange.Text = "Change";
this.ButtonChange.UseVisualStyleBackColor = true;
this.ButtonChange.Click += new System.EventHandler(this.ButtonUpdate_Click);
//
// ButtonDelete
//
this.ButtonDelete.Location = new System.Drawing.Point(661, 142);
this.ButtonDelete.Name = "ButtonDelete";
this.ButtonDelete.Size = new System.Drawing.Size(92, 35);
this.ButtonDelete.TabIndex = 3;
this.ButtonDelete.Text = "Delete";
this.ButtonDelete.UseVisualStyleBackColor = true;
this.ButtonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// ButtonRefresh
//
this.ButtonRefresh.Location = new System.Drawing.Point(661, 204);
this.ButtonRefresh.Name = "ButtonRefresh";
this.ButtonRefresh.Size = new System.Drawing.Size(92, 35);
this.ButtonRefresh.TabIndex = 4;
this.ButtonRefresh.Text = "Refresh";
this.ButtonRefresh.UseVisualStyleBackColor = true;
this.ButtonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
//
// FormDresses
//
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.ButtonRefresh);
this.Controls.Add(this.ButtonDelete);
this.Controls.Add(this.ButtonChange);
this.Controls.Add(this.ButtonAdd);
this.Controls.Add(this.dressGridView);
this.Name = "FormDresses";
this.Text = "FormDresses";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
this.Load += new System.EventHandler(this.FormDresses_Load);
((System.ComponentModel.ISupportInitialize)(this.dressGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dressGridView;
private Button ButtonAdd;
private Button ButtonChange;
private Button ButtonDelete;
private Button ButtonRefresh;
}
}

View File

@ -0,0 +1,119 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SewingDresses
{
public partial class FormDresses : Form
{
private readonly ILogger _logger;
private readonly IDressLogic _logic;
public FormDresses(ILogger<FormDresses> logger, IDressLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormDresses_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dressGridView.DataSource = list;
dressGridView.Columns["ID"].Visible = false;
dressGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dressGridView.Columns["DressComponents"].Visible = false;
}
_logger.LogInformation("Loading dresses");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading dresses");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDress));
if (service is FormDress form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpdate_Click(object sender, EventArgs e)
{
if (dressGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDress));
if (service is FormDress form)
{
form.ID = Convert.ToInt32(dressGridView.SelectedRows[0].Cells["ID"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (dressGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dressGridView.SelectedRows[0].Cells["ID"].Value);
_logger.LogInformation("Dress deletion");
try
{
if (!_logic.Delete(new DressBindingModel
{
ID = id
}))
{
throw new Exception("Deletion error. Extra information in logs.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Dress deletion error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRefresh_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>

175
SewingDresses/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,175 @@
namespace SewingDresses
{
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.menuStrip = new System.Windows.Forms.MenuStrip();
this.directoriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.createOrderButton = new System.Windows.Forms.Button();
this.processOrderButton = new System.Windows.Forms.Button();
this.readyOrderButton = new System.Windows.Forms.Button();
this.givenOrderButton = new System.Windows.Forms.Button();
this.refreshOrdersButton = new System.Windows.Forms.Button();
this.materialsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dressesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.directoriesToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(800, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
// directoriesToolStripMenuItem
//
this.directoriesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.materialsToolStripMenuItem,
this.dressesToolStripMenuItem});
this.directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem";
this.directoriesToolStripMenuItem.Size = new System.Drawing.Size(75, 20);
this.directoriesToolStripMenuItem.Text = "Directories";
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(2, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(631, 420);
this.dataGridView.TabIndex = 1;
//
// createOrderButton
//
this.createOrderButton.Location = new System.Drawing.Point(652, 89);
this.createOrderButton.Name = "createOrderButton";
this.createOrderButton.Size = new System.Drawing.Size(117, 34);
this.createOrderButton.TabIndex = 2;
this.createOrderButton.Text = "Create order";
this.createOrderButton.UseVisualStyleBackColor = true;
this.createOrderButton.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// processOrderButton
//
this.processOrderButton.Location = new System.Drawing.Point(652, 145);
this.processOrderButton.Name = "processOrderButton";
this.processOrderButton.Size = new System.Drawing.Size(117, 34);
this.processOrderButton.TabIndex = 3;
this.processOrderButton.Text = "Order\'s in process";
this.processOrderButton.UseVisualStyleBackColor = true;
this.processOrderButton.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// readyOrderButton
//
this.readyOrderButton.Location = new System.Drawing.Point(652, 203);
this.readyOrderButton.Name = "readyOrderButton";
this.readyOrderButton.Size = new System.Drawing.Size(117, 34);
this.readyOrderButton.TabIndex = 4;
this.readyOrderButton.Text = "Order\'s ready";
this.readyOrderButton.UseVisualStyleBackColor = true;
this.readyOrderButton.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// givenOrderButton
//
this.givenOrderButton.Location = new System.Drawing.Point(652, 259);
this.givenOrderButton.Name = "givenOrderButton";
this.givenOrderButton.Size = new System.Drawing.Size(117, 34);
this.givenOrderButton.TabIndex = 5;
this.givenOrderButton.Text = "Order\'s given";
this.givenOrderButton.UseVisualStyleBackColor = true;
this.givenOrderButton.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// refreshOrdersButton
//
this.refreshOrdersButton.Location = new System.Drawing.Point(652, 321);
this.refreshOrdersButton.Name = "refreshOrdersButton";
this.refreshOrdersButton.Size = new System.Drawing.Size(117, 34);
this.refreshOrdersButton.TabIndex = 6;
this.refreshOrdersButton.Text = "Refresh list";
this.refreshOrdersButton.UseVisualStyleBackColor = true;
this.refreshOrdersButton.Click += new System.EventHandler(this.ButtonRef_Click);
//
// materialsToolStripMenuItem
//
this.materialsToolStripMenuItem.Name = "materialsToolStripMenuItem";
this.materialsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.materialsToolStripMenuItem.Text = "Materials";
this.materialsToolStripMenuItem.Click += new System.EventHandler(this.materialsToolStripMenuItem_Click);
//
// dressesToolStripMenuItem
//
this.dressesToolStripMenuItem.Name = "dressesToolStripMenuItem";
this.dressesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.dressesToolStripMenuItem.Text = "Dresses";
this.dressesToolStripMenuItem.Click += new System.EventHandler(this.dressesToolStripMenuItem_Click);
//
// FormMain
//
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.refreshOrdersButton);
this.Controls.Add(this.givenOrderButton);
this.Controls.Add(this.readyOrderButton);
this.Controls.Add(this.processOrderButton);
this.Controls.Add(this.createOrderButton);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMain";
this.Text = "FormMain";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip;
private ToolStripMenuItem directoriesToolStripMenuItem;
private DataGridView dataGridView;
private Button createOrderButton;
private Button processOrderButton;
private Button readyOrderButton;
private Button givenOrderButton;
private Button refreshOrdersButton;
private ToolStripMenuItem materialsToolStripMenuItem;
private ToolStripMenuItem dressesToolStripMenuItem;
}
}

190
SewingDresses/FormMain.cs Normal file
View File

@ -0,0 +1,190 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SewingDresses
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
_logger.LogInformation("Downloading orders");
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["DressID"].Visible = false;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error downloading orders");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void materialsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaterials));
if (service is FormMaterials form)
{
form.ShowDialog();
}
}
private void dressesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDresses));
if (service is FormDresses form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrderCreation));
if (service is FormOrderCreation form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value);
_logger.LogInformation("Order №{id}. Changing status to 'In process'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
ID = id,
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
MessageBox.Show("Order must be in 'Accepted' state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new Exception("Saving Error. Extra information in logs.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error transferring order into process");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value);
_logger.LogInformation("Order №{id}. Changing status to 'Ready'", id);
try
{
var operationResult = _orderLogic.ReadyOrder(new OrderBindingModel
{
ID = id,
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
MessageBox.Show("Order must be in 'InProcess' state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new Exception("Saving error. Extra information in logs.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in giving ready status to order");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value);
_logger.LogInformation("Order №{id}. Changing status to 'Given'",id);
try
{
var operationResult = _orderLogic.GivenOrder(new OrderBindingModel
{
ID = id,
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
MessageBox.Show("Order must be in 'Ready' state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new Exception("Saving error. Extra information in logs.");
}
_logger.LogInformation("Order №{id} is given", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in giving 'Is given' status to order");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

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="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

121
SewingDresses/FormMaterial.Designer.cs generated Normal file
View File

@ -0,0 +1,121 @@
namespace SewingDresses
{
partial class FormMaterial
{
/// <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.componentNameTextBox = new System.Windows.Forms.TextBox();
this.componentPriceTextBox = new System.Windows.Forms.TextBox();
this.componentNameLabel = new System.Windows.Forms.Label();
this.priceComponentLabel = new System.Windows.Forms.Label();
this.saveComponentButton = new System.Windows.Forms.Button();
this.cancelComponentButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// componentNameTextBox
//
this.componentNameTextBox.Location = new System.Drawing.Point(120, 26);
this.componentNameTextBox.Name = "componentNameTextBox";
this.componentNameTextBox.Size = new System.Drawing.Size(300, 23);
this.componentNameTextBox.TabIndex = 0;
//
// componentPriceTextBox
//
this.componentPriceTextBox.Location = new System.Drawing.Point(120, 68);
this.componentPriceTextBox.Name = "componentPriceTextBox";
this.componentPriceTextBox.Size = new System.Drawing.Size(158, 23);
this.componentPriceTextBox.TabIndex = 1;
//
// componentNameLabel
//
this.componentNameLabel.AutoSize = true;
this.componentNameLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.componentNameLabel.Location = new System.Drawing.Point(31, 24);
this.componentNameLabel.Name = "componentNameLabel";
this.componentNameLabel.Size = new System.Drawing.Size(66, 25);
this.componentNameLabel.TabIndex = 2;
this.componentNameLabel.Text = "Name:";
//
// priceComponentLabel
//
this.priceComponentLabel.AutoSize = true;
this.priceComponentLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.priceComponentLabel.Location = new System.Drawing.Point(31, 66);
this.priceComponentLabel.Name = "priceComponentLabel";
this.priceComponentLabel.Size = new System.Drawing.Size(58, 25);
this.priceComponentLabel.TabIndex = 3;
this.priceComponentLabel.Text = "Price:";
//
// saveComponentButton
//
this.saveComponentButton.Location = new System.Drawing.Point(289, 117);
this.saveComponentButton.Name = "saveComponentButton";
this.saveComponentButton.Size = new System.Drawing.Size(80, 25);
this.saveComponentButton.TabIndex = 4;
this.saveComponentButton.Text = "Save";
this.saveComponentButton.UseVisualStyleBackColor = true;
this.saveComponentButton.Click += new System.EventHandler(this.ButtonSave_Click);
//
// cancelComponentButton
//
this.cancelComponentButton.Location = new System.Drawing.Point(375, 117);
this.cancelComponentButton.Name = "cancelComponentButton";
this.cancelComponentButton.Size = new System.Drawing.Size(80, 25);
this.cancelComponentButton.TabIndex = 5;
this.cancelComponentButton.Text = "Cancel";
this.cancelComponentButton.UseVisualStyleBackColor = true;
this.cancelComponentButton.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormMaterial
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(466, 154);
this.Controls.Add(this.cancelComponentButton);
this.Controls.Add(this.saveComponentButton);
this.Controls.Add(this.priceComponentLabel);
this.Controls.Add(this.componentNameLabel);
this.Controls.Add(this.componentPriceTextBox);
this.Controls.Add(this.componentNameTextBox);
this.Name = "FormMaterial";
this.Text = "Material";
this.Load += new System.EventHandler(this.FormComponent_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox componentNameTextBox;
private TextBox componentPriceTextBox;
private Label componentNameLabel;
private Label priceComponentLabel;
private Button saveComponentButton;
private Button cancelComponentButton;
}
}

View File

@ -0,0 +1,97 @@
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.BindingModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SewingDresses
{
public partial class FormMaterial : Form
{
private readonly ILogger _logger;
private readonly IMaterialLogic _logic;
private int? _id;
public int ID { set { _id = value; } }
public FormMaterial(ILogger<FormMaterial> logger, IMaterialLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormComponent_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Receiving component");
var view = _logic.ReadElement(new MaterialSearchModel
{
ID = _id.Value
});
if (view != null)
{
componentNameTextBox.Text = view.ComponentName;
componentPriceTextBox.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error receiving component");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(componentNameTextBox.Text))
{
MessageBox.Show("Fill name field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving component");
try
{
var model = new MaterialBindingModel
{
ID = _id ?? 0,
ComponentName = componentNameTextBox.Text,
Cost = Convert.ToDouble(componentPriceTextBox.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Error during saving. Extra info in logs.");
}
MessageBox.Show("Saving was succesful", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error saving component");
MessageBox.Show(ex.Message, "Error", 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>

115
SewingDresses/FormMaterials.Designer.cs generated Normal file
View File

@ -0,0 +1,115 @@
namespace SewingDresses
{
partial class FormMaterials
{
/// <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.materialGridView = new System.Windows.Forms.DataGridView();
this.addMaterialButton = new System.Windows.Forms.Button();
this.changeMaterialButton = new System.Windows.Forms.Button();
this.deleteMaterialButton = new System.Windows.Forms.Button();
this.refreshMaterialsButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.materialGridView)).BeginInit();
this.SuspendLayout();
//
// materialGridView
//
this.materialGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
this.materialGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.materialGridView.Location = new System.Drawing.Point(1, 2);
this.materialGridView.Name = "materialGridView";
this.materialGridView.RowTemplate.Height = 25;
this.materialGridView.Size = new System.Drawing.Size(608, 449);
this.materialGridView.TabIndex = 0;
//
// addMaterialButton
//
this.addMaterialButton.Location = new System.Drawing.Point(659, 12);
this.addMaterialButton.Name = "addMaterialButton";
this.addMaterialButton.Size = new System.Drawing.Size(105, 23);
this.addMaterialButton.TabIndex = 1;
this.addMaterialButton.Text = "Add";
this.addMaterialButton.UseVisualStyleBackColor = true;
this.addMaterialButton.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// changeMaterialButton
//
this.changeMaterialButton.Location = new System.Drawing.Point(659, 51);
this.changeMaterialButton.Name = "changeMaterialButton";
this.changeMaterialButton.Size = new System.Drawing.Size(105, 23);
this.changeMaterialButton.TabIndex = 2;
this.changeMaterialButton.Text = "Change";
this.changeMaterialButton.UseVisualStyleBackColor = true;
this.changeMaterialButton.Click += new System.EventHandler(this.ButtonUpdate_Click);
//
// deleteMaterialButton
//
this.deleteMaterialButton.Location = new System.Drawing.Point(659, 94);
this.deleteMaterialButton.Name = "deleteMaterialButton";
this.deleteMaterialButton.Size = new System.Drawing.Size(105, 23);
this.deleteMaterialButton.TabIndex = 3;
this.deleteMaterialButton.Text = "Delete";
this.deleteMaterialButton.UseVisualStyleBackColor = true;
this.deleteMaterialButton.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// refreshMaterialsButton
//
this.refreshMaterialsButton.Location = new System.Drawing.Point(659, 132);
this.refreshMaterialsButton.Name = "refreshMaterialsButton";
this.refreshMaterialsButton.Size = new System.Drawing.Size(105, 23);
this.refreshMaterialsButton.TabIndex = 4;
this.refreshMaterialsButton.Text = "Refresh";
this.refreshMaterialsButton.UseVisualStyleBackColor = true;
this.refreshMaterialsButton.Click += new System.EventHandler(this.ButtonRefresh_Click);
//
// FormMaterials
//
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.refreshMaterialsButton);
this.Controls.Add(this.deleteMaterialButton);
this.Controls.Add(this.changeMaterialButton);
this.Controls.Add(this.addMaterialButton);
this.Controls.Add(this.materialGridView);
this.Name = "FormMaterials";
this.Text = "Materials";
this.Load += new System.EventHandler(this.FormMaterials_Load);
((System.ComponentModel.ISupportInitialize)(this.materialGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView materialGridView;
private Button addMaterialButton;
private Button changeMaterialButton;
private Button deleteMaterialButton;
private Button refreshMaterialsButton;
}
}

View File

@ -0,0 +1,119 @@
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SewingDresses
{
public partial class FormMaterials : Form
{
private readonly ILogger _logger;
private readonly IMaterialLogic _logic;
public FormMaterials(ILogger<FormMaterials> logger, IMaterialLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormMaterials_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
materialGridView.DataSource = list;
materialGridView.Columns["ID"].Visible = false;
materialGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Loading materials");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading materials");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaterial));
if (service is FormMaterial form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpdate_Click(object sender, EventArgs e)
{
if (materialGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaterial));
if (service is FormMaterial form)
{
form.ID = Convert.ToInt32(materialGridView.SelectedRows[0].Cells["ID"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (materialGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Delete record?", "Question",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(materialGridView.SelectedRows[0].Cells["ID"].Value);
_logger.LogInformation("Material deletion");
try
{
if (!_logic.Delete(new MaterialBindingModel
{
ID = id
}))
{
throw new Exception("Deletion error. Extra information in logs.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Material deletion error");
MessageBox.Show(ex.Message, "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRefresh_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,149 @@
namespace SewingDresses
{
partial class FormOrderCreation
{
/// <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.dressLabel = new System.Windows.Forms.Label();
this.quantityLabel = new System.Windows.Forms.Label();
this.priceLabel = new System.Windows.Forms.Label();
this.dressComboBox = new System.Windows.Forms.ComboBox();
this.quantityTextBox = new System.Windows.Forms.TextBox();
this.priceTextBox = new System.Windows.Forms.TextBox();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// dressLabel
//
this.dressLabel.AutoSize = true;
this.dressLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.dressLabel.Location = new System.Drawing.Point(12, 9);
this.dressLabel.Name = "dressLabel";
this.dressLabel.Size = new System.Drawing.Size(82, 25);
this.dressLabel.TabIndex = 0;
this.dressLabel.Text = "Product:";
//
// quantityLabel
//
this.quantityLabel.AutoSize = true;
this.quantityLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.quantityLabel.Location = new System.Drawing.Point(12, 50);
this.quantityLabel.Name = "quantityLabel";
this.quantityLabel.Size = new System.Drawing.Size(88, 25);
this.quantityLabel.TabIndex = 1;
this.quantityLabel.Text = "Quantity:";
//
// priceLabel
//
this.priceLabel.AutoSize = true;
this.priceLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.priceLabel.Location = new System.Drawing.Point(12, 90);
this.priceLabel.Name = "priceLabel";
this.priceLabel.Size = new System.Drawing.Size(56, 25);
this.priceLabel.TabIndex = 2;
this.priceLabel.Text = "Total:";
//
// dressComboBox
//
this.dressComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.dressComboBox.FormattingEnabled = true;
this.dressComboBox.Location = new System.Drawing.Point(114, 12);
this.dressComboBox.Name = "dressComboBox";
this.dressComboBox.Size = new System.Drawing.Size(320, 23);
this.dressComboBox.TabIndex = 3;
this.dressComboBox.SelectedIndexChanged += new System.EventHandler(this.DressComboBox_SelectedIndexChanged);
//
// quantityTextBox
//
this.quantityTextBox.Location = new System.Drawing.Point(114, 52);
this.quantityTextBox.Name = "quantityTextBox";
this.quantityTextBox.Size = new System.Drawing.Size(320, 23);
this.quantityTextBox.TabIndex = 4;
this.quantityTextBox.TextChanged += new System.EventHandler(this.QuantityTextBox_TextChanged);
//
// priceTextBox
//
this.priceTextBox.Location = new System.Drawing.Point(114, 90);
this.priceTextBox.Name = "priceTextBox";
this.priceTextBox.ReadOnly = true;
this.priceTextBox.Size = new System.Drawing.Size(320, 23);
this.priceTextBox.TabIndex = 5;
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(220, 138);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(100, 32);
this.ButtonSave.TabIndex = 6;
this.ButtonSave.Text = "Save";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(334, 138);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(100, 32);
this.ButtonCancel.TabIndex = 7;
this.ButtonCancel.Text = "Cancel";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormOrderCreation
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(446, 181);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.priceTextBox);
this.Controls.Add(this.quantityTextBox);
this.Controls.Add(this.dressComboBox);
this.Controls.Add(this.priceLabel);
this.Controls.Add(this.quantityLabel);
this.Controls.Add(this.dressLabel);
this.Name = "FormOrderCreation";
this.Text = "FormOrderCreation";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
this.Load += new System.EventHandler(this.FormOrderCreation_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label dressLabel;
private Label quantityLabel;
private Label priceLabel;
private ComboBox dressComboBox;
private TextBox quantityTextBox;
private TextBox priceTextBox;
private Button ButtonSave;
private Button ButtonCancel;
}
}

View File

@ -0,0 +1,130 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SewingDresses
{
public partial class FormOrderCreation : Form
{
private readonly ILogger _logger;
private readonly IDressLogic _logicDress;
private readonly IOrderLogic _logicOrder;
public FormOrderCreation(ILogger<FormOrderCreation> logger, IDressLogic logicP, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicDress = logicP;
_logicOrder = logicO;
}
private void FormOrderCreation_Load(object sender, EventArgs e)
{
_logger.LogInformation("Downloading dresses for order");
try
{
var _list = _logicDress.ReadList(null);
if (_list != null)
{
dressComboBox.DisplayMember = "DressName";
dressComboBox.ValueMember = "ID";
dressComboBox.DataSource = _list;
dressComboBox.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Downloading dresses for order error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (dressComboBox.SelectedValue != null &&
!string.IsNullOrEmpty(quantityTextBox.Text))
{
try
{
int id = Convert.ToInt32(dressComboBox.SelectedValue);
var dress = _logicDress.ReadElement(new DressSearchModel
{
ID = id,
});
int count = Convert.ToInt32(quantityTextBox.Text);
priceTextBox.Text = Math.Round(count * (dress?.Price ?? 0), 2).ToString();
_logger.LogInformation("Calculating total of order");
}
catch (Exception ex)
{
_logger.LogError(ex, "Calculation total of order error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private void QuantityTextBox_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void DressComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(quantityTextBox.Text))
{
MessageBox.Show("Fill quantity field", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (dressComboBox.SelectedValue == null)
{
MessageBox.Show("Choose dress", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Creation of order");
try
{
var operationResult = _logicOrder.CreateOrder(new OrderBindingModel
{
DressID = Convert.ToInt32(dressComboBox.SelectedValue),
Count = Convert.ToInt32(quantityTextBox.Text),
Sum = Convert.ToDouble(priceTextBox.Text)
});
if (!operationResult)
{
throw new Exception("Creating of order error.Extra information in logs.");
}
MessageBox.Show("Saving was succesfull", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Creation of order error");
MessageBox.Show(ex.Message, "Error", 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

@ -1,7 +1,19 @@
using DressAtelierBusinessLogic.BusinessLogic;
using DressAtelierContracts.BusinessLogicContracts;
using DressAtelierContracts.StorageContracts;
using DressAtelierListImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
namespace SewingDresses namespace SewingDresses
{ {
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 +23,33 @@ namespace SewingDresses
// 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.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IMaterialStorage, MaterialStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDressStorage, DressStorage>();
services.AddTransient<IMaterialLogic, MaterialLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDressLogic, DressLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormMaterial>();
services.AddTransient<FormMaterials>();
services.AddTransient<FormOrderCreation>();
services.AddTransient<FormDress>();
services.AddTransient<FormDressMaterial>();
services.AddTransient<FormDresses>();
}
} }
} }

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SewingDresses.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SewingDresses.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -8,4 +8,48 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="BusinessLogic\**" />
<EmbeddedResource Remove="BusinessLogic\**" />
<None Remove="BusinessLogic\**" />
</ItemGroup>
<ItemGroup>
<None Remove="nlog.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DressAtelierBusinessLogic\DressAtelierBusinessLogic.csproj" />
<ProjectReference Include="..\DressAtelierContracts\DressAtelierContracts.csproj" />
<ProjectReference Include="..\DressAtelierDataModels\DressAtelierDataModels.csproj" />
<ProjectReference Include="..\DressAtelierListImplement\DressAtelierListImplement.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>

View File

@ -5,6 +5,14 @@ VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingDresses", "SewingDresses.csproj", "{477532B4-09CB-45E7-9AE5-652CAE3E340C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingDresses", "SewingDresses.csproj", "{477532B4-09CB-45E7-9AE5-652CAE3E340C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DressAtelierDataModels", "..\DressAtelierDataModels\DressAtelierDataModels.csproj", "{2D48D801-8A00-4FFE-B995-8090A65D0A07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DressAtelierContracts", "..\DressAtelierContracts\DressAtelierContracts.csproj", "{5500343A-5929-4C91-8509-D0E5F65D19BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DressAtelierBusinessLogic", "..\DressAtelierBusinessLogic\DressAtelierBusinessLogic.csproj", "{535CDE3E-E0FB-4389-905D-B23C8BA13044}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DressAtelierListImplement", "..\DressAtelierListImplement\DressAtelierListImplement.csproj", "{1A88E277-E50A-45C5-89FA-677EBCD2EF63}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -15,6 +23,22 @@ Global
{477532B4-09CB-45E7-9AE5-652CAE3E340C}.Debug|Any CPU.Build.0 = Debug|Any CPU {477532B4-09CB-45E7-9AE5-652CAE3E340C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{477532B4-09CB-45E7-9AE5-652CAE3E340C}.Release|Any CPU.ActiveCfg = Release|Any CPU {477532B4-09CB-45E7-9AE5-652CAE3E340C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{477532B4-09CB-45E7-9AE5-652CAE3E340C}.Release|Any CPU.Build.0 = Release|Any CPU {477532B4-09CB-45E7-9AE5-652CAE3E340C}.Release|Any CPU.Build.0 = Release|Any CPU
{2D48D801-8A00-4FFE-B995-8090A65D0A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D48D801-8A00-4FFE-B995-8090A65D0A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D48D801-8A00-4FFE-B995-8090A65D0A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D48D801-8A00-4FFE-B995-8090A65D0A07}.Release|Any CPU.Build.0 = Release|Any CPU
{5500343A-5929-4C91-8509-D0E5F65D19BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5500343A-5929-4C91-8509-D0E5F65D19BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5500343A-5929-4C91-8509-D0E5F65D19BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5500343A-5929-4C91-8509-D0E5F65D19BF}.Release|Any CPU.Build.0 = Release|Any CPU
{535CDE3E-E0FB-4389-905D-B23C8BA13044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{535CDE3E-E0FB-4389-905D-B23C8BA13044}.Debug|Any CPU.Build.0 = Debug|Any CPU
{535CDE3E-E0FB-4389-905D-B23C8BA13044}.Release|Any CPU.ActiveCfg = Release|Any CPU
{535CDE3E-E0FB-4389-905D-B23C8BA13044}.Release|Any CPU.Build.0 = Release|Any CPU
{1A88E277-E50A-45C5-89FA-677EBCD2EF63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A88E277-E50A-45C5-89FA-677EBCD2EF63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A88E277-E50A-45C5-89FA-677EBCD2EF63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A88E277-E50A-45C5-89FA-677EBCD2EF63}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

13
SewingDresses/nlog.config Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>