Compare commits

...

16 Commits

97 changed files with 7000 additions and 51 deletions

View File

@ -0,0 +1,185 @@
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;
using System.Transactions;
using System.Xml.Linq;
namespace DressAtelierBusinessLogic.BusinessLogic
{
public class AtelierLogic : IAtelierLogic
{
private readonly ILogger _logger;
private readonly IAtelierStorage _atelierStorage;
private readonly IDressStorage _dressStorage;
public AtelierLogic(ILogger<AtelierLogic> logger, IAtelierStorage atelierStorage, IDressStorage dressStorage)
{
_logger = logger;
_atelierStorage = atelierStorage;
_dressStorage = dressStorage;
}
public bool Create(AtelierBindingModel model)
{
CheckAtelier(model);
if(_atelierStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(AtelierBindingModel model)
{
CheckAtelier(model);
if(_atelierStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(AtelierBindingModel model)
{
CheckAtelier(model, false);
_logger.LogInformation("Delete. ID:{ID}", model.ID);
if(_atelierStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public AtelierViewModel? ReadElement(AtelierSearchModel model)
{
if(model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. AtelierName:{Name}.ID:{ ID}", model.Name, model.ID);
var atelier = _atelierStorage.GetElement(model);
if(atelier == null)
{
_logger.LogWarning("ReadElement atelier not found");
return null;
}
_logger.LogInformation("ReadElement find. ID:{ID}", atelier.ID);
return atelier;
}
public List<AtelierViewModel>? ReadList(AtelierSearchModel? model)
{
_logger.LogInformation("ReadList. AtelierName:{AtelierName}. ID:{ ID}", model?.Name, model?.ID);
var list = model == null ? _atelierStorage.GetFullList() : _atelierStorage.GetFilteredList(model);
if(list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckAtelier(AtelierBindingModel model, bool withParams = true)
{
if(model == null)
{
throw new ArgumentNullException(nameof(model));
}
if(!withParams)
{
return;
}
if(string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Invalid atelier name", nameof(model.Name));
}
if(string.IsNullOrEmpty(model.Address))
{
throw new ArgumentNullException("Invalid atelier address", nameof(model.Address));
}
_logger.LogInformation("Atelier. AtelierName:{Name}. Address:{Address}. ID: {ID}", model.Name, model.Address, model.ID);
var element = _atelierStorage.GetElement(new AtelierSearchModel
{
Name = model.Name
});
if(element != null && (element.ID == model.ID))
{
throw new InvalidOperationException("Atelier with such name already exists");
}
}
public bool CheckQuantity(int quantity)
{
return _atelierStorage.CheckDressesQuantity(quantity);
}
public (bool result,int quantity) AddDress(AtelierBindingModel? atelierModel, DressBindingModel dressModel, int quantity)
{
if(dressModel == null || quantity == 0)
{
return (false,-1);
}
var dress = _dressStorage.GetElement(new DressSearchModel
{
ID = dressModel.ID
});
var atelier = _atelierStorage.GetElement(new AtelierSearchModel
{
ID = atelierModel.ID
});
if(!atelier.DressesList.ContainsKey(dress.ID))
{
atelier.DressesList.Add(dress.ID, (dress, 1));
quantity--;
}
while(atelier.DressesList.Sum(x => x.Value.Item2) < atelier.MaxTotalOfDresses && quantity != 0)
{
var qnt = atelier.DressesList[dressModel.ID];
qnt.Item2++;
atelier.DressesList[dressModel.ID] = qnt;
quantity--;
}
atelierModel.Name = atelier.Name;
atelierModel.Address = atelier.Address;
atelierModel.DressesList = atelier.DressesList;
atelierModel.OpeningDate = atelier.OpeningDate;
atelierModel.MaxTotalOfDresses = atelier.MaxTotalOfDresses;
if (_atelierStorage.Update(atelierModel) == null)
{
_logger.LogWarning("Restocking operation failed");
throw new Exception("Something went wrong.");
}
return (true, quantity);
}
public bool SellDress(DressSearchModel model, int quantity)
{
if(_atelierStorage.SellDresses(model,quantity))
{
return true;
}
return false;
}
}
}

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,164 @@
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;
using System.Transactions;
namespace DressAtelierBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IAtelierLogic _atelierLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IAtelierLogic atelierLogic)
{
_logger = logger;
_orderStorage = orderStorage;
_atelierLogic = atelierLogic;
}
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)
{
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;
}
var ateliers = _atelierLogic.ReadList(null);
if (ateliers == null)
{
return false;
}
int quantity = model.Count;
try
{
using (TransactionScope scope = new TransactionScope())
{
if(ateliers.Sum(x => x.MaxTotalOfDresses - x.DressesList.Sum(y => y.Value.Item2)) < quantity)
{
throw new OverflowException("There is not enough space in ateliers");
}
foreach (var atelier in ateliers)
{
quantity = _atelierLogic.AddDress(new AtelierBindingModel { ID = atelier.ID }, new DressBindingModel { ID = model.DressID }, quantity).quantity;
}
model.Status = OrderStatus.Given;
model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
}
}
catch (Exception ex)
{
throw new OverflowException("Shops' storages are full.");
}
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,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierDataModels.Models;
namespace DressAtelierContracts.BindingModels
{
public class AtelierBindingModel : IAtelierModel
{
public string Name { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Today;
public Dictionary<int, (IDressModel, int)> DressesList { get; set; } = new();
public int ID { get; set; }
public int MaxTotalOfDresses { get; set; }
public int CurrentQuantity { 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;
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,23 @@
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 IAtelierLogic
{
List<AtelierViewModel>? ReadList(AtelierSearchModel? model);
AtelierViewModel? ReadElement(AtelierSearchModel model);
(bool result, int quantity) AddDress(AtelierBindingModel atelierModel, DressBindingModel dressModel, int quantity);
bool Create(AtelierBindingModel model);
bool Update(AtelierBindingModel model);
bool Delete(AtelierBindingModel model);
bool CheckQuantity(int quantity);
bool SellDress(DressSearchModel model, int quantity);
}
}

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,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierContracts.SearchModels
{
public class AtelierSearchModel
{
public int? ID { get; set; }
public string? Name { get; set; }
public int? DressID { 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 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,23 @@
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 IAtelierStorage
{
List<AtelierViewModel> GetFullList();
List<AtelierViewModel> GetFilteredList(AtelierSearchModel model);
AtelierViewModel? GetElement(AtelierSearchModel model);
AtelierViewModel? Insert(AtelierBindingModel model);
AtelierViewModel? Update(AtelierBindingModel model);
AtelierViewModel? Delete(AtelierBindingModel model);
bool CheckDressesQuantity(int quantity);
bool SellDresses(DressSearchModel model, int quantity);
}
}

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,26 @@
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 AtelierViewModel : IAtelierModel
{
public int ID { get; set; }
[DisplayName("Name")]
public string Name { get; set; } = string.Empty;
[DisplayName("Address")]
public string Address { get; set; } = string.Empty;
[DisplayName("OpeningDate")]
public DateTime OpeningDate { get; set; } = DateTime.Today;
public Dictionary<int, (IDressModel, int)> DressesList { get; set; } = new();
public int MaxTotalOfDresses { get; set; }
public int CurrentQuantity { get; set; }
}
}

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,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierDataModels.Models
{
public interface IAtelierModel :IID
{
string Name { get; }
string Address { get; }
DateTime OpeningDate { get; }
Dictionary<int,(IDressModel,int)> DressesList { get; }
int MaxTotalOfDresses { get; }
int CurrentQuantity { 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,63 @@
using DressAtelierFileImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DressAtelierFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string MaterialFileName = "Material.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string DressFileName = "Dress.xml";
private readonly string AtelierFileName = "Atelier.xml";
public List<Material> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Dress> Dresses { get; private set; }
public List<Atelier> Ateliers { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveComponents() => SaveData(Components, MaterialFileName,"Components", x => x.GetXElement);
public void SaveDresses() => SaveData(Dresses, DressFileName,"Dresses", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName,"Orders", x => x.GetXElement);
public void SaveAteliers() => SaveData(Ateliers, AtelierFileName, "Atelier", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(MaterialFileName, "Component", x => Material.Create(x)!)!;
Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Ateliers = LoadData(AtelierFileName, "Atelier", x => Atelier.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return
XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string
xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName,
data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

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,168 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
using DressAtelierFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
namespace DressAtelierFileImplement.Implements
{
public class AtelierStorage : IAtelierStorage
{
private readonly DataFileSingleton _source;
public AtelierStorage()
{
_source = DataFileSingleton.GetInstance();
}
public AtelierViewModel? Insert(AtelierBindingModel model)
{
model.ID = _source.Ateliers.Count() > 0 ? _source.Ateliers.Max(x => x.ID) + 1 : 1;
var newAtelier = Atelier.Create(model);
if(newAtelier == null)
{
return null;
}
_source.Ateliers.Add(newAtelier);
_source.SaveAteliers();
return newAtelier.GetViewModel;
}
public AtelierViewModel? Update(AtelierBindingModel model)
{
var atelier = _source.Ateliers.FirstOrDefault(x => x.ID == model.ID);
if(atelier == null)
{
return null;
}
atelier.Update(model);
_source.SaveAteliers();
return atelier.GetViewModel;
}
public AtelierViewModel? Delete(AtelierBindingModel model)
{
var atelier = _source.Ateliers.FirstOrDefault(x => x.ID == model.ID);
if (atelier == null)
{
return null;
}
_source.Ateliers.Remove(atelier);
_source.SaveAteliers();
return atelier.GetViewModel;
}
public AtelierViewModel? GetElement(AtelierSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
{
return null;
}
if(!string.IsNullOrEmpty(model.Name))
{
return _source.Ateliers.FirstOrDefault(x => x.Name.Equals(model.Name))?.GetViewModel;
}
if (model.ID.HasValue)
{
return _source.Ateliers.FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
}
return null;
}
public List<AtelierViewModel> GetFilteredList(AtelierSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.DressID.HasValue)
{
return new();
}
if(!string.IsNullOrEmpty(model.Name))
{
return _source.Ateliers.Where(x => x.Name.Equals(model.Name)).Select(x => x.GetViewModel).ToList();
}
return _source.Ateliers.Where(x => x.DressesList.ContainsKey((int)model.DressID)).Select(x => x.GetViewModel).ToList();
}
public List<AtelierViewModel> GetFullList()
{
return _source.Ateliers.Select(x => x.GetViewModel).ToList();
}
public bool CheckDressesQuantity(int quantity)
{
var ateliers = GetFullList();
foreach(var atelier in ateliers)
{
if (atelier.CurrentQuantity >= atelier.MaxTotalOfDresses || atelier.MaxTotalOfDresses < quantity)
{
return false;
}
}
return true;
}
public bool SellDresses(DressSearchModel model, int quantity)
{
(IDressModel, int) qnt = (null,0);
var ateliers = GetFilteredList(new AtelierSearchModel { DressID = model.ID });
int requiredQuantity = quantity;
try
{
using (TransactionScope scope = new TransactionScope())
{
foreach (var atelier in ateliers)
{
if (requiredQuantity - atelier.DressesList[model.ID.Value].Item2 > 0)
{
requiredQuantity -= atelier.DressesList[model.ID.Value].Item2;
atelier.DressesList.Remove(model.ID.Value);
}
else
{
qnt = atelier.DressesList[model.ID.Value];
qnt.Item2 -= requiredQuantity;
atelier.DressesList[model.ID.Value] = qnt;
requiredQuantity = 0;
}
Update(new AtelierBindingModel
{
ID = atelier.ID,
DressesList = atelier.DressesList
});
}
if (requiredQuantity > 0)
{
throw new Exception("Not enough dresses in ateliers");
}
_source.SaveAteliers();
}
return true;
}
catch (Exception ex)
{
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,85 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierFileImplement.Implements
{
public class DressStorage : IDressStorage
{
private readonly DataFileSingleton _source;
public DressStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<DressViewModel> GetFullList()
{
return _source.Dresses.Select(x => x.GetViewModel).ToList();
}
public List<DressViewModel> GetFilteredList(DressSearchModel model)
{
if (string.IsNullOrEmpty(model.DressName))
{
return new();
}
return _source.Dresses.Where(x => x.DressName.Equals(model.DressName)).Select(x => x.GetViewModel).ToList();
}
public DressViewModel? GetElement(DressSearchModel model)
{
if (string.IsNullOrEmpty(model.DressName) && !model.ID.HasValue)
{
return null;
}
return _source.Dresses.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DressName) && x.DressName == model.DressName) || (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
}
public DressViewModel? Insert(DressBindingModel model)
{
model.ID = _source.Dresses.Count > 0 ? _source.Dresses.Max(x => x.ID) + 1 : 1;
var newDress = Dress.Create(model);
if (newDress == null)
{
return null;
}
_source.Dresses.Add(newDress);
_source.SaveDresses();
return newDress.GetViewModel;
}
public DressViewModel? Update(DressBindingModel model)
{
var dress = _source.Dresses.FirstOrDefault(x => x.ID == model.ID);
if(dress == null)
{
return null;
}
dress.Update(model);
_source.SaveDresses();
return dress.GetViewModel;
}
public DressViewModel? Delete(DressBindingModel model)
{
var dress = _source.Dresses.FirstOrDefault(x=> x.ID == model.ID);
if(dress == null)
{
return null;
}
_source.Dresses.Remove(dress);
_source.SaveDresses();
return dress.GetViewModel;
}
}
}

View File

@ -0,0 +1,84 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierFileImplement.Implements
{
public class MaterialStorage : IMaterialStorage
{
private readonly DataFileSingleton _source;
public MaterialStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<MaterialViewModel> GetFullList()
{
return _source.Components.Select(x => x.GetViewModel).ToList();
}
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
return _source.Components.Where(x => x.ComponentName.Equals(model.ComponentName)).Select(x => x.GetViewModel).ToList();
}
public MaterialViewModel? GetElement(MaterialSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.ID.HasValue)
{
return null;
}
return _source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
}
public MaterialViewModel? Insert(MaterialBindingModel model)
{
model.ID = _source.Components.Count > 0 ? _source.Components.Max(x => x.ID) + 1 : 1;
var newComponent = Material.Create(model);
if (newComponent == null)
{
return null;
}
_source.Components.Add(newComponent);
_source.SaveComponents();
return newComponent.GetViewModel;
}
public MaterialViewModel? Update(MaterialBindingModel model)
{
var component = _source.Components.FirstOrDefault(x => x.ID == model.ID);
if( component == null)
{
return null;
}
component.Update(model);
_source.SaveComponents();
return component.GetViewModel;
}
public MaterialViewModel? Delete(MaterialBindingModel model)
{
var component = _source.Components.FirstOrDefault(x => x.ID == model.ID);
if(component == null)
{
return null;
}
_source.Components.Remove(component);
_source.SaveComponents();
return component.GetViewModel;;
}
}
}

View File

@ -0,0 +1,98 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DressAtelierFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton _source;
public OrderStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
return _source.Orders.Select(x => ReceiveDressName(x)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.ID.HasValue)
{
return new();
}
return _source.Orders.Where(x => x.ID == model.ID).Select(x => ReceiveDressName(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.ID.HasValue)
{
return null;
}
return ReceiveDressName(_source.Orders.FirstOrDefault(x => x.ID == model.ID));
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.ID = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.ID) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
_source.Orders.Add(newOrder);
_source.SaveOrders();
return ReceiveDressName(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = _source.Orders.FirstOrDefault(x => x.ID == model.ID);
if(order == null)
{
return null;
}
order.Update(model);
_source.SaveOrders();
return ReceiveDressName(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var order = _source.Orders.FirstOrDefault(x => x.ID == model.ID);
if(order == null)
{
return null;
}
_source.Orders.Remove(order);
_source.SaveOrders();
return ReceiveDressName(order);
}
private OrderViewModel? ReceiveDressName(Order model)
{
if(model == null)
{
return null;
}
var order = model.GetViewModel;
var dress = _source.Dresses.FirstOrDefault(un => un.ID == model.DressID);
order.DressName = dress == null ? "" : dress.DressName;
return order;
}
}
}

View File

@ -0,0 +1,112 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DressAtelierFileImplement.Models
{
public class Atelier : IAtelierModel
{
public int ID { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; } = DateTime.Now;
public Dictionary<int, (IDressModel, int)> Dresses {
get
{
if(DressesList.Count == 0)
{
var source = DataFileSingleton.GetInstance();
DressesList = CurrentDresses.ToDictionary(x => x.Key, y => ((source.Dresses.FirstOrDefault(z => z.ID == y.Key) as IDressModel)!, y.Value));
}
return DressesList;
}
}
public Dictionary<int, (IDressModel, int)> DressesList { get; private set; } = new();
public int MaxTotalOfDresses { get; private set; }
public Dictionary<int, int> CurrentDresses { get; private set; } = new();
public int CurrentQuantity { get; private set; }
public static Atelier? Create(AtelierBindingModel? atelier)
{
if (atelier == null)
{
return null;
}
return new Atelier()
{
ID = atelier.ID,
Name = atelier.Name,
Address = atelier.Address,
OpeningDate = atelier.OpeningDate,
CurrentDresses = atelier.DressesList.ToDictionary(x => x.Key,x => x.Value.Item2),
DressesList = atelier.DressesList,
CurrentQuantity = atelier.DressesList.Count(),
MaxTotalOfDresses = atelier.MaxTotalOfDresses
};
}
public static Atelier? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Atelier()
{
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
Name = element.Element("Name")!.Value,
Address = element.Element("Address")!.Value,
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
CurrentDresses = element.Element("Dresses")!.Elements("Dress").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)),
MaxTotalOfDresses = Convert.ToInt32(element.Element("MaxTotalOfDresses")!.Value),
CurrentQuantity = Convert.ToInt32(element.Element("CurrentDressesQuantity")!.Value)
};
}
public void Update(AtelierBindingModel? atelier)
{
if (atelier == null)
{
return;
}
CurrentDresses = atelier.DressesList.ToDictionary(x => x.Key, x => x.Value.Item2);
CurrentQuantity = atelier.DressesList.Sum(x => x.Value.Item2);
DressesList = Dresses;
}
public AtelierViewModel GetViewModel => new()
{
ID = ID,
Name = Name,
Address = Address,
OpeningDate = OpeningDate,
DressesList = Dresses,
MaxTotalOfDresses = MaxTotalOfDresses,
CurrentQuantity = CurrentQuantity
};
public XElement GetXElement => new("Atelier", new XAttribute("ID", ID),
new XElement("Name", Name),
new XElement("Address", Address),
new XElement("OpeningDate", OpeningDate.ToString()),
new XElement("Dresses", CurrentDresses.Select(x => new XElement("Dress", new XElement("Key",x.Key), new XElement("Value", x.Value))).ToArray()),
new XElement("MaxTotalOfDresses", MaxTotalOfDresses),
new XElement("CurrentDressesQuantity", CurrentQuantity));
}
}

View File

@ -0,0 +1,103 @@
using DressAtelierDataModels.Models;
using DressAtelierContracts.ViewModels;
using DressAtelierContracts.BindingModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
namespace DressAtelierFileImplement.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, int> Components { get; private set; } = new();
private Dictionary<int, (IMaterialModel, int)>? _dressComponents = null;
public Dictionary<int, (IMaterialModel, int)> DressComponents
{
get
{
if(_dressComponents == null)
{
var source = DataFileSingleton.GetInstance();
_dressComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.ID == y.Key) as IMaterialModel)!, y.Value));
}
return _dressComponents;
}
}
public static Dress? Create(DressBindingModel? model)
{
if (model == null)
{
return null;
}
return new Dress()
{
ID = model.ID,
DressName = model.DressName,
Price = model.Price,
Components = model.DressComponents.ToDictionary(x => x.Key, x
=> x.Value.Item2)
};
}
public static Dress? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Dress()
{
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
DressName = element.Element("DressName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components =
element.Element("DressComponents")!.Elements("DressComponent")
.ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(DressBindingModel? model)
{
if (model == null)
{
return;
}
DressName = model.DressName;
Price = model.Price;
Components = model.DressComponents.ToDictionary(x => x.Key, x =>
x.Value.Item2);
_dressComponents = null;
}
public DressViewModel GetViewModel => new()
{
ID = ID,
DressName = DressName,
Price = Price,
DressComponents = DressComponents
};
public XElement GetXElement => new("Dress",
new XAttribute("ID", ID),
new XElement("DressName", DressName),
new XElement("Price", Price.ToString()),
new XElement("DressComponents", Components.Select(x =>
new XElement("DressComponent",new XElement("Key", x.Key),new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,70 @@
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;
using System.Xml.Linq;
namespace DressAtelierFileImplement.Models
{
public class Material : IMaterialModel
{
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; private 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 static Material? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Material()
{
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
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
};
public XElement GetXElement => new("Component",new XAttribute("ID",ID),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,102 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Enums;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DressAtelierFileImplement.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 static Order? Create(XElement element)
{
if(element == null)
{
return null;
}
return new Order()
{
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
DressID = Convert.ToInt32(element.Element("DressID")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("CreationDate")!.Value),
DateImplement = string.IsNullOrEmpty(element.Element("ImplementationDate")!.Value) ? null : Convert.ToDateTime(element.Element("ImplementationDate")!.Value)
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
DressID = model.DressID;
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
};
public XElement GetXElement => new("Order", new XAttribute("ID", ID),
new XElement("DressID", DressID),
new XElement("Count", Count),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status),
new XElement("CreationDate", DateCreate),
new XElement("ImplementationDate", DateImplement));
}
}

View File

@ -0,0 +1,33 @@
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<Atelier> Ateliers { 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>();
Ateliers = new List<Atelier>();
}
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,112 @@
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.SearchModels;
using DressAtelierContracts.StorageContracts;
using DressAtelierContracts.ViewModels;
using DressAtelierListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierListImplement.Implements
{
public class AtelierStorage : IAtelierStorage
{
private readonly DataListSingleton _source;
public AtelierStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<AtelierViewModel> GetFullList()
{
var result = new List<AtelierViewModel>();
foreach (var atelier in _source.Ateliers)
{
result.Add(atelier.GetViewModel);
}
return result;
}
public List<AtelierViewModel> GetFilteredList(AtelierSearchModel model)
{
var result = new List<AtelierViewModel>();
if(string.IsNullOrEmpty(model.Name))
{
return result;
}
var specificAteliers = _source.Ateliers.Where(atelier => atelier.Name.Equals(model.Name));
if(specificAteliers.Any())
{
result.Add(specificAteliers.ToArray()[0].GetViewModel);
}
return result;
}
public AtelierViewModel? GetElement(AtelierSearchModel model)
{
if(string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
{
return null;
}
if (_source.Ateliers.Where(atelier => (!string.IsNullOrEmpty(model.Name) && atelier.Name.Equals(model.Name)) || (model.ID.HasValue && atelier.ID == model.ID)).Any())
{
return _source.Ateliers.Where(atelier => (!string.IsNullOrEmpty(model.Name) && atelier.Name.Equals(model.Name)) || (model.ID.HasValue && atelier.ID == model.ID)).ToArray()[0].GetViewModel;
}
return null;
}
public AtelierViewModel? Insert(AtelierBindingModel model)
{
model.ID = _source.Ateliers.Count + 1;
var newAtelier = Atelier.Create(model);
if(newAtelier == null)
{
return null;
}
_source.Ateliers.Add(newAtelier);
return newAtelier.GetViewModel;
}
public AtelierViewModel? Update(AtelierBindingModel model)
{
if (_source.Ateliers.Where(atelier => atelier.ID == model.ID).Any())
{
_source.Ateliers.Where(atelier => atelier.ID == model.ID).ToArray()[0].Update(model);
return _source.Ateliers.Where(atelier => atelier.ID == model.ID).ToArray()[0].GetViewModel;
}
return null;
}
public AtelierViewModel? Delete(AtelierBindingModel model)
{
for (int i = 0; i < _source.Ateliers.Count; ++i)
{
if (_source.Ateliers[i].ID == model.ID)
{
var atelier = _source.Ateliers[i];
_source.Ateliers.RemoveAt(i);
return atelier.GetViewModel;
}
}
return null;
}
public bool SellDresses(DressSearchModel model, int quantity)
{
throw new NotImplementedException();
}
public bool CheckDressesQuantity(int quantity)
{
throw new NotImplementedException();
}
}
}

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,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
namespace DressAtelierListImplement.Models
{
public class Atelier :IAtelierModel
{
public int ID { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public int MaxTotalOfDresses { get; private set; }
public int CurrentQuantity { get; private set; }
public DateTime OpeningDate { get; private set; } = DateTime.Today;
public Dictionary<int, (IDressModel, int)> DressesList { get; private set; } = new Dictionary<int, (IDressModel, int)>();
public static Atelier? Create(AtelierBindingModel? atelier)
{
if(atelier == null)
{
return null;
}
return new Atelier()
{
ID = atelier.ID,
Name = atelier.Name,
Address = atelier.Address,
OpeningDate = atelier.OpeningDate,
DressesList = atelier.DressesList,
MaxTotalOfDresses = atelier.MaxTotalOfDresses,
CurrentQuantity = 0
};
}
public void Update(AtelierBindingModel? atelier)
{
if (atelier == null)
{
return;
}
Name = atelier.Name;
Address = atelier.Address;
DressesList = atelier.DressesList;
OpeningDate = atelier.OpeningDate;
MaxTotalOfDresses = atelier.MaxTotalOfDresses;
CurrentQuantity = atelier.DressesList.Sum(x => x.Value.Item2);
}
public AtelierViewModel GetViewModel => new()
{
ID = ID,
Name = Name,
Address = Address,
OpeningDate = OpeningDate,
DressesList = DressesList,
MaxTotalOfDresses = MaxTotalOfDresses,
CurrentQuantity = CurrentQuantity
};
}
}

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;
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();
}
}
}

143
SewingDresses/FormAtelier.Designer.cs generated Normal file
View File

@ -0,0 +1,143 @@
namespace SewingDresses
{
partial class FormAtelier
{
/// <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()
{
cancelButton = new Button();
saveAtelierButton = new Button();
atelierAddressLabel = new Label();
atelierNameLabel = new Label();
atelierAddressTextBox = new TextBox();
atelierNameTextBox = new TextBox();
labelMaxQuantity = new Label();
atelierTextBoxCapacity = new TextBox();
SuspendLayout();
//
// cancelButton
//
cancelButton.Location = new Point(310, 129);
cancelButton.Name = "cancelButton";
cancelButton.Size = new Size(80, 25);
cancelButton.TabIndex = 11;
cancelButton.Text = "Cancel";
cancelButton.UseVisualStyleBackColor = true;
cancelButton.Click += cancelButton_Click;
//
// saveAtelierButton
//
saveAtelierButton.Location = new Point(224, 129);
saveAtelierButton.Name = "saveAtelierButton";
saveAtelierButton.Size = new Size(80, 25);
saveAtelierButton.TabIndex = 10;
saveAtelierButton.Text = "Save";
saveAtelierButton.UseVisualStyleBackColor = true;
saveAtelierButton.Click += saveAtelierButton_Click;
//
// atelierAddressLabel
//
atelierAddressLabel.AutoSize = true;
atelierAddressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
atelierAddressLabel.Location = new Point(1, 46);
atelierAddressLabel.Name = "atelierAddressLabel";
atelierAddressLabel.Size = new Size(83, 25);
atelierAddressLabel.TabIndex = 9;
atelierAddressLabel.Text = "Address:";
//
// atelierNameLabel
//
atelierNameLabel.AutoSize = true;
atelierNameLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
atelierNameLabel.Location = new Point(1, 10);
atelierNameLabel.Name = "atelierNameLabel";
atelierNameLabel.Size = new Size(66, 25);
atelierNameLabel.TabIndex = 8;
atelierNameLabel.Text = "Name:";
//
// atelierAddressTextBox
//
atelierAddressTextBox.Location = new Point(90, 48);
atelierAddressTextBox.Name = "atelierAddressTextBox";
atelierAddressTextBox.Size = new Size(300, 23);
atelierAddressTextBox.TabIndex = 7;
//
// atelierNameTextBox
//
atelierNameTextBox.Location = new Point(90, 12);
atelierNameTextBox.Name = "atelierNameTextBox";
atelierNameTextBox.Size = new Size(300, 23);
atelierNameTextBox.TabIndex = 6;
//
// labelMaxQuantity
//
labelMaxQuantity.AutoSize = true;
labelMaxQuantity.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
labelMaxQuantity.Location = new Point(1, 87);
labelMaxQuantity.Name = "labelMaxQuantity";
labelMaxQuantity.Size = new Size(88, 25);
labelMaxQuantity.TabIndex = 13;
labelMaxQuantity.Text = "Capacity:";
//
// atelierTextBoxCapacity
//
atelierTextBoxCapacity.Location = new Point(90, 87);
atelierTextBoxCapacity.Name = "atelierTextBoxCapacity";
atelierTextBoxCapacity.Size = new Size(41, 23);
atelierTextBoxCapacity.TabIndex = 12;
//
// FormAtelier
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(396, 166);
Controls.Add(labelMaxQuantity);
Controls.Add(atelierTextBoxCapacity);
Controls.Add(cancelButton);
Controls.Add(saveAtelierButton);
Controls.Add(atelierAddressLabel);
Controls.Add(atelierNameLabel);
Controls.Add(atelierAddressTextBox);
Controls.Add(atelierNameTextBox);
Name = "FormAtelier";
Text = "Atelier creation";
Load += FormAtelier_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button cancelButton;
private Button saveAtelierButton;
private Label atelierAddressLabel;
private Label atelierNameLabel;
private TextBox atelierAddressTextBox;
private TextBox atelierNameTextBox;
private Label labelMaxQuantity;
private TextBox atelierTextBoxCapacity;
}
}

View File

@ -0,0 +1,97 @@
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 FormAtelier : Form
{
private readonly ILogger _logger;
private readonly IAtelierLogic _logic;
private int? _id;
public int ID { set { _id = value; } }
public FormAtelier(ILogger<FormAtelier> logger, IAtelierLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormAtelier_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Receiving atelier");
var view = _logic.ReadElement(new AtelierSearchModel
{
ID = _id.Value
});
if (view != null)
{
atelierNameTextBox.Text = view.Name;
atelierAddressTextBox.Text = view.Address;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error receiving atelier");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void saveAtelierButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(atelierNameTextBox.Text) || string.IsNullOrEmpty(atelierAddressTextBox.Text))
{
MessageBox.Show("Fill all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving atelier");
try
{
var model = new AtelierBindingModel
{
ID = _id ?? 0,
Name = atelierNameTextBox.Text,
Address = atelierAddressTextBox.Text,
MaxTotalOfDresses = Convert.ToInt32(atelierTextBoxCapacity.Text),
DressesList = new Dictionary<int, (IDressModel, int)>()
};
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 atelier");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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>

View File

@ -0,0 +1,147 @@
namespace SewingDresses
{
partial class FormAtelierRestocking
{
/// <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()
{
atelierComboBox = new ComboBox();
atelierLabel = new Label();
dressComboBox = new ComboBox();
dressLabel = new Label();
quantityTextBox = new TextBox();
quantityLabel = new Label();
ButtonCancel = new Button();
ButtonSave = new Button();
SuspendLayout();
//
// atelierComboBox
//
atelierComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
atelierComboBox.FormattingEnabled = true;
atelierComboBox.Location = new Point(114, 21);
atelierComboBox.Name = "atelierComboBox";
atelierComboBox.Size = new Size(293, 23);
atelierComboBox.TabIndex = 7;
//
// atelierLabel
//
atelierLabel.AutoSize = true;
atelierLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
atelierLabel.Location = new Point(12, 18);
atelierLabel.Name = "atelierLabel";
atelierLabel.Size = new Size(71, 25);
atelierLabel.TabIndex = 6;
atelierLabel.Text = "Atelier:";
//
// dressComboBox
//
dressComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
dressComboBox.FormattingEnabled = true;
dressComboBox.Location = new Point(114, 69);
dressComboBox.Name = "dressComboBox";
dressComboBox.Size = new Size(320, 23);
dressComboBox.TabIndex = 9;
//
// dressLabel
//
dressLabel.AutoSize = true;
dressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
dressLabel.Location = new Point(12, 66);
dressLabel.Name = "dressLabel";
dressLabel.Size = new Size(82, 25);
dressLabel.TabIndex = 8;
dressLabel.Text = "Product:";
//
// quantityTextBox
//
quantityTextBox.Location = new Point(114, 113);
quantityTextBox.Name = "quantityTextBox";
quantityTextBox.Size = new Size(320, 23);
quantityTextBox.TabIndex = 11;
//
// quantityLabel
//
quantityLabel.AutoSize = true;
quantityLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
quantityLabel.Location = new Point(12, 111);
quantityLabel.Name = "quantityLabel";
quantityLabel.Size = new Size(88, 25);
quantityLabel.TabIndex = 10;
quantityLabel.Text = "Quantity:";
//
// ButtonCancel
//
ButtonCancel.Location = new Point(336, 177);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(100, 32);
ButtonCancel.TabIndex = 13;
ButtonCancel.Text = "Cancel";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// ButtonSave
//
ButtonSave.Location = new Point(222, 177);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(100, 32);
ButtonSave.TabIndex = 12;
ButtonSave.Text = "Save";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// FormAtelierRestocking
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(448, 221);
Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(quantityTextBox);
Controls.Add(quantityLabel);
Controls.Add(dressComboBox);
Controls.Add(dressLabel);
Controls.Add(atelierComboBox);
Controls.Add(atelierLabel);
Name = "FormAtelierRestocking";
Text = "Atelier restocking";
Load += FormAtelierRestocking_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox atelierComboBox;
private Label atelierLabel;
private ComboBox dressComboBox;
private Label dressLabel;
private TextBox quantityTextBox;
private Label quantityLabel;
private Button ButtonCancel;
private Button ButtonSave;
}
}

View File

@ -0,0 +1,134 @@
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 FormAtelierRestocking : Form
{
private readonly IAtelierLogic _logicAtelier;
private readonly IDressLogic _logicDress;
private readonly ILogger _logger;
private int? _id;
private Dictionary<int, (IDressModel, int)> _dressesList;
public int ID { set { _id = value; } }
public FormAtelierRestocking(ILogger<FormAtelierRestocking> logger, IAtelierLogic logicA, IDressLogic logicD)
{
InitializeComponent();
_logicAtelier = logicA;
_logger = logger;
_logicDress = logicD;
_dressesList = new Dictionary<int, (IDressModel, int)>();
}
private void FormAtelierRestocking_Load(object sender, EventArgs e)
{
_logger.LogInformation("Downloading dresses");
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 error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Downloading ateliers");
try
{
var _list = _logicAtelier.ReadList(null);
if (_list != null)
{
atelierComboBox.DisplayMember = "Name";
atelierComboBox.ValueMember = "ID";
atelierComboBox.DataSource = _list;
atelierComboBox.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Downloading ateliers error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(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;
}
if (atelierComboBox.SelectedValue == null)
{
MessageBox.Show("Choose atelier", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Restocking of atelier");
try
{
if(!_logicAtelier.CheckQuantity(Convert.ToInt32(quantityTextBox.Text)))
{
throw new OverflowException("Max capacity is lower than restocking size");
}
_logicAtelier.AddDress(new AtelierBindingModel
{
ID = Convert.ToInt32(atelierComboBox.SelectedValue),
Name = atelierComboBox.Text
},
new DressBindingModel
{
ID = Convert.ToInt32(dressComboBox.SelectedValue),
DressName = dressComboBox.Text,
}, Convert.ToInt32(quantityTextBox.Text));
MessageBox.Show("Saving was succesfull", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Restocking of atelier error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

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

114
SewingDresses/FormAteliers.Designer.cs generated Normal file
View File

@ -0,0 +1,114 @@
namespace SewingDresses
{
partial class FormAteliers
{
/// <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()
{
atelierGridView = new DataGridView();
ButtonDelete = new Button();
ButtonChange = new Button();
ButtonAdd = new Button();
buttonCheckDresses = new Button();
((System.ComponentModel.ISupportInitialize)atelierGridView).BeginInit();
SuspendLayout();
//
// atelierGridView
//
atelierGridView.BackgroundColor = SystemColors.ControlLightLight;
atelierGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
atelierGridView.Location = new Point(1, 2);
atelierGridView.Name = "atelierGridView";
atelierGridView.RowTemplate.Height = 25;
atelierGridView.Size = new Size(598, 447);
atelierGridView.TabIndex = 0;
//
// ButtonDelete
//
ButtonDelete.Location = new Point(652, 148);
ButtonDelete.Name = "ButtonDelete";
ButtonDelete.Size = new Size(92, 35);
ButtonDelete.TabIndex = 6;
ButtonDelete.Text = "Delete";
ButtonDelete.UseVisualStyleBackColor = true;
ButtonDelete.Click += ButtonDelete_Click;
//
// ButtonChange
//
ButtonChange.Location = new Point(652, 91);
ButtonChange.Name = "ButtonChange";
ButtonChange.Size = new Size(92, 35);
ButtonChange.TabIndex = 5;
ButtonChange.Text = "Change";
ButtonChange.UseVisualStyleBackColor = true;
ButtonChange.Click += ButtonChange_Click;
//
// ButtonAdd
//
ButtonAdd.Location = new Point(652, 36);
ButtonAdd.Name = "ButtonAdd";
ButtonAdd.Size = new Size(92, 35);
ButtonAdd.TabIndex = 4;
ButtonAdd.Text = "Add";
ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
//
// buttonCheckDresses
//
buttonCheckDresses.Location = new Point(652, 210);
buttonCheckDresses.Name = "buttonCheckDresses";
buttonCheckDresses.Size = new Size(92, 35);
buttonCheckDresses.TabIndex = 7;
buttonCheckDresses.Text = "Dresses";
buttonCheckDresses.UseVisualStyleBackColor = true;
buttonCheckDresses.Click += buttonCheckDresses_Click;
//
// FormAteliers
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonCheckDresses);
Controls.Add(ButtonDelete);
Controls.Add(ButtonChange);
Controls.Add(ButtonAdd);
Controls.Add(atelierGridView);
Name = "FormAteliers";
Text = "Ateliers";
Load += FormAteliers_Load;
((System.ComponentModel.ISupportInitialize)atelierGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView atelierGridView;
private Button ButtonDelete;
private Button ButtonChange;
private Button ButtonAdd;
private Button buttonCheckDresses;
}
}

View File

@ -0,0 +1,122 @@
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 FormAteliers : Form
{
private readonly ILogger<FormAteliers> _logger;
private readonly IAtelierLogic _logic;
public FormAteliers(ILogger<FormAteliers> logger, IAtelierLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormAteliers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
atelierGridView.DataSource = list;
atelierGridView.Columns["DressesList"].Visible = false;
atelierGridView.Columns["ID"].Visible = false;
}
_logger.LogInformation("Loading atelier");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading atelier");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAtelier));
if (service is FormAtelier form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonChange_Click(object sender, EventArgs e)
{
if (atelierGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAtelier));
if (service is FormAtelier form)
{
form.ID = Convert.ToInt32(atelierGridView.SelectedRows[0].Cells["ID"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (atelierGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(atelierGridView.SelectedRows[0].Cells["ID"].Value);
_logger.LogInformation("Atelier deletion");
try
{
if (!_logic.Delete(new AtelierBindingModel
{
ID = id
}))
{
throw new Exception("Deletion error. Extra information in logs.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Atelier deletion error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonCheckDresses_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCheckDresses));
if (service is FormCheckDresses form)
{
if (form.ShowDialog() == DialogResult.OK)
{
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>

114
SewingDresses/FormCheckDresses.Designer.cs generated Normal file
View File

@ -0,0 +1,114 @@
namespace SewingDresses
{
partial class FormCheckDresses
{
/// <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()
{
atelierComboBox = new ComboBox();
atelierLabel = new Label();
dressesGridView = new DataGridView();
ID = new DataGridViewTextBoxColumn();
DressName = new DataGridViewTextBoxColumn();
Quantity = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dressesGridView).BeginInit();
SuspendLayout();
//
// atelierComboBox
//
atelierComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
atelierComboBox.FormattingEnabled = true;
atelierComboBox.Location = new Point(106, 12);
atelierComboBox.Name = "atelierComboBox";
atelierComboBox.Size = new Size(293, 23);
atelierComboBox.TabIndex = 5;
atelierComboBox.SelectedIndexChanged += atelierComboBox_SelectedIndexChanged;
//
// atelierLabel
//
atelierLabel.AutoSize = true;
atelierLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
atelierLabel.Location = new Point(4, 9);
atelierLabel.Name = "atelierLabel";
atelierLabel.Size = new Size(71, 25);
atelierLabel.TabIndex = 4;
atelierLabel.Text = "Atelier:";
//
// dressesGridView
//
dressesGridView.BackgroundColor = SystemColors.ControlLightLight;
dressesGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dressesGridView.Columns.AddRange(new DataGridViewColumn[] { ID, DressName, Quantity });
dressesGridView.Location = new Point(4, 51);
dressesGridView.Name = "dressesGridView";
dressesGridView.RowTemplate.Height = 25;
dressesGridView.Size = new Size(404, 261);
dressesGridView.TabIndex = 6;
//
// ID
//
ID.HeaderText = "ID";
ID.Name = "ID";
ID.Visible = false;
//
// DressName
//
DressName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DressName.HeaderText = "DressName";
DressName.Name = "DressName";
//
// Quantity
//
Quantity.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
Quantity.HeaderText = "Quantity";
Quantity.Name = "Quantity";
//
// FormCheckDresses
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(411, 314);
Controls.Add(dressesGridView);
Controls.Add(atelierComboBox);
Controls.Add(atelierLabel);
Name = "FormCheckDresses";
Text = "Check dresses";
Load += FormCheckDresses_Load;
((System.ComponentModel.ISupportInitialize)dressesGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox atelierComboBox;
private Label atelierLabel;
private DataGridView dressesGridView;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn DressName;
private DataGridViewTextBoxColumn Quantity;
}
}

View File

@ -0,0 +1,86 @@
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 FormCheckDresses : Form
{
private readonly ILogger _logger;
private readonly IAtelierLogic _logicAtelier;
private readonly IDressLogic _logicDress;
public FormCheckDresses(ILogger<FormCheckDresses> logger, IDressLogic logicD, IAtelierLogic logicA)
{
InitializeComponent();
_logger = logger;
_logicAtelier = logicA;
_logicDress = logicD;
}
private void FormCheckDresses_Load(object sender, EventArgs e)
{
_logger.LogInformation("Downloading ateliers");
try
{
var _list = _logicAtelier.ReadList(null);
if (_list != null)
{
atelierComboBox.DisplayMember = "Name";
atelierComboBox.ValueMember = "ID";
atelierComboBox.DataSource = _list;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Downloading ateliers error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void atelierComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
var atelier = _logicAtelier.ReadElement(new AtelierSearchModel
{
ID = Convert.ToInt32(atelierComboBox.SelectedValue),
Name = atelierComboBox.Text
});
_logger.LogInformation("Downloading dresses for atelier");
try
{
if (atelier.DressesList.Count != 0)
{
dressesGridView.Rows.Clear();
foreach (var dress in atelier.DressesList)
{
dressesGridView.Rows.Add(new object[] { dress.Key, dress.Value.Item1.DressName, dress.Value.Item2 });
}
}
}
catch(Exception ex)
{
_logger.LogError(ex, "Error downloading dresses for atelier");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}

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="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="DressName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Quantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

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

@ -0,0 +1,226 @@
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()
{
nameDressLabel = new Label();
priceDressLabel = new Label();
nameDressTextBox = new TextBox();
priceDressTextBox = new TextBox();
materialsGroupBox = new GroupBox();
RefreshButton = new Button();
deleteButton = new Button();
changeButton = new Button();
AddButton = new Button();
dressGridView = new DataGridView();
ColumnID = new DataGridViewTextBoxColumn();
ColumnMaterial = new DataGridViewTextBoxColumn();
ColumnQuantity = new DataGridViewTextBoxColumn();
saveButton = new Button();
cancelButton = new Button();
materialsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dressGridView).BeginInit();
SuspendLayout();
//
// nameDressLabel
//
nameDressLabel.AutoSize = true;
nameDressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
nameDressLabel.Location = new Point(12, 9);
nameDressLabel.Name = "nameDressLabel";
nameDressLabel.Size = new Size(66, 25);
nameDressLabel.TabIndex = 0;
nameDressLabel.Text = "Name:";
//
// priceDressLabel
//
priceDressLabel.AutoSize = true;
priceDressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
priceDressLabel.Location = new Point(12, 46);
priceDressLabel.Name = "priceDressLabel";
priceDressLabel.Size = new Size(58, 25);
priceDressLabel.TabIndex = 1;
priceDressLabel.Text = "Price:";
//
// nameDressTextBox
//
nameDressTextBox.Location = new Point(84, 11);
nameDressTextBox.Name = "nameDressTextBox";
nameDressTextBox.Size = new Size(287, 23);
nameDressTextBox.TabIndex = 2;
//
// priceDressTextBox
//
priceDressTextBox.Location = new Point(84, 48);
priceDressTextBox.Name = "priceDressTextBox";
priceDressTextBox.ReadOnly = true;
priceDressTextBox.Size = new Size(178, 23);
priceDressTextBox.TabIndex = 3;
//
// materialsGroupBox
//
materialsGroupBox.Controls.Add(RefreshButton);
materialsGroupBox.Controls.Add(deleteButton);
materialsGroupBox.Controls.Add(changeButton);
materialsGroupBox.Controls.Add(AddButton);
materialsGroupBox.Controls.Add(dressGridView);
materialsGroupBox.Location = new Point(16, 89);
materialsGroupBox.Name = "materialsGroupBox";
materialsGroupBox.Size = new Size(770, 301);
materialsGroupBox.TabIndex = 4;
materialsGroupBox.TabStop = false;
materialsGroupBox.Text = "Materials";
//
// RefreshButton
//
RefreshButton.Location = new Point(638, 225);
RefreshButton.Name = "RefreshButton";
RefreshButton.Size = new Size(103, 36);
RefreshButton.TabIndex = 4;
RefreshButton.Text = "Refresh";
RefreshButton.UseVisualStyleBackColor = true;
RefreshButton.Click += ButtonRefresh_Click;
//
// deleteButton
//
deleteButton.Location = new Point(638, 168);
deleteButton.Name = "deleteButton";
deleteButton.Size = new Size(103, 36);
deleteButton.TabIndex = 3;
deleteButton.Text = "Delete";
deleteButton.UseVisualStyleBackColor = true;
deleteButton.Click += ButtonDelete_Click;
//
// changeButton
//
changeButton.Location = new Point(638, 110);
changeButton.Name = "changeButton";
changeButton.Size = new Size(103, 36);
changeButton.TabIndex = 2;
changeButton.Text = "Change";
changeButton.UseVisualStyleBackColor = true;
changeButton.Click += ButtonUpdate_Click;
//
// AddButton
//
AddButton.Location = new Point(638, 56);
AddButton.Name = "AddButton";
AddButton.Size = new Size(103, 36);
AddButton.TabIndex = 1;
AddButton.Text = "Add";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += ButtonAdd_Click;
//
// dressGridView
//
dressGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dressGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnMaterial, ColumnQuantity });
dressGridView.Location = new Point(6, 22);
dressGridView.Name = "dressGridView";
dressGridView.RowTemplate.Height = 25;
dressGridView.Size = new Size(588, 273);
dressGridView.TabIndex = 0;
//
// ColumnID
//
ColumnID.HeaderText = "ID";
ColumnID.Name = "ColumnID";
ColumnID.Visible = false;
//
// ColumnMaterial
//
ColumnMaterial.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnMaterial.HeaderText = "Material";
ColumnMaterial.Name = "ColumnMaterial";
//
// ColumnQuantity
//
ColumnQuantity.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnQuantity.HeaderText = "Quantity";
ColumnQuantity.Name = "ColumnQuantity";
//
// saveButton
//
saveButton.Location = new Point(562, 407);
saveButton.Name = "saveButton";
saveButton.Size = new Size(89, 31);
saveButton.TabIndex = 5;
saveButton.Text = "Save";
saveButton.UseVisualStyleBackColor = true;
saveButton.Click += ButtonSave_Click;
//
// cancelButton
//
cancelButton.Location = new Point(657, 407);
cancelButton.Name = "cancelButton";
cancelButton.Size = new Size(89, 31);
cancelButton.TabIndex = 6;
cancelButton.Text = "Cancel";
cancelButton.UseVisualStyleBackColor = true;
cancelButton.Click += ButtonCancel_Click;
//
// FormDress
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(cancelButton);
Controls.Add(saveButton);
Controls.Add(materialsGroupBox);
Controls.Add(priceDressTextBox);
Controls.Add(nameDressTextBox);
Controls.Add(priceDressLabel);
Controls.Add(nameDressLabel);
Name = "FormDress";
Text = "Dress creation";
Load += FormDress_Load;
materialsGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dressGridView).EndInit();
ResumeLayout(false);
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,121 @@
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()
{
materialNameLabel = new Label();
materialQuantityLabel = new Label();
materialComboBox = new ComboBox();
quantityTextBox = new TextBox();
saveButton = new Button();
cancelButton = new Button();
SuspendLayout();
//
// materialNameLabel
//
materialNameLabel.AutoSize = true;
materialNameLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
materialNameLabel.Location = new Point(12, 19);
materialNameLabel.Name = "materialNameLabel";
materialNameLabel.Size = new Size(86, 25);
materialNameLabel.TabIndex = 0;
materialNameLabel.Text = "Material:";
//
// materialQuantityLabel
//
materialQuantityLabel.AutoSize = true;
materialQuantityLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
materialQuantityLabel.Location = new Point(12, 63);
materialQuantityLabel.Name = "materialQuantityLabel";
materialQuantityLabel.Size = new Size(88, 25);
materialQuantityLabel.TabIndex = 1;
materialQuantityLabel.Text = "Quantity:";
//
// materialComboBox
//
materialComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
materialComboBox.FormattingEnabled = true;
materialComboBox.Location = new Point(123, 19);
materialComboBox.Name = "materialComboBox";
materialComboBox.Size = new Size(342, 23);
materialComboBox.TabIndex = 2;
//
// quantityTextBox
//
quantityTextBox.Location = new Point(123, 63);
quantityTextBox.Name = "quantityTextBox";
quantityTextBox.Size = new Size(342, 23);
quantityTextBox.TabIndex = 3;
//
// saveButton
//
saveButton.Location = new Point(275, 104);
saveButton.Name = "saveButton";
saveButton.Size = new Size(92, 23);
saveButton.TabIndex = 4;
saveButton.Text = "Save";
saveButton.UseVisualStyleBackColor = true;
saveButton.Click += saveButton_Click;
//
// cancelButton
//
cancelButton.Location = new Point(373, 104);
cancelButton.Name = "cancelButton";
cancelButton.Size = new Size(92, 23);
cancelButton.TabIndex = 5;
cancelButton.Text = "Cancel";
cancelButton.UseVisualStyleBackColor = true;
cancelButton.Click += cancelButton_Click;
//
// FormDressMaterial
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(477, 129);
Controls.Add(cancelButton);
Controls.Add(saveButton);
Controls.Add(quantityTextBox);
Controls.Add(materialComboBox);
Controls.Add(materialQuantityLabel);
Controls.Add(materialNameLabel);
Name = "FormDressMaterial";
Text = "Dress material";
ResumeLayout(false);
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>

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

@ -0,0 +1,121 @@
namespace SewingDresses
{
partial class FormDressSelling
{
/// <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()
{
labelDressName = new Label();
labelQuantity = new Label();
textBoxQuantity = new TextBox();
comboBoxDresses = new ComboBox();
buttonSell = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelDressName
//
labelDressName.AutoSize = true;
labelDressName.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold, GraphicsUnit.Point);
labelDressName.Location = new Point(12, 25);
labelDressName.Name = "labelDressName";
labelDressName.Size = new Size(73, 25);
labelDressName.TabIndex = 0;
labelDressName.Text = "DRESS:";
//
// labelQuantity
//
labelQuantity.AutoSize = true;
labelQuantity.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold, GraphicsUnit.Point);
labelQuantity.Location = new Point(12, 72);
labelQuantity.Name = "labelQuantity";
labelQuantity.Size = new Size(109, 25);
labelQuantity.TabIndex = 1;
labelQuantity.Text = "QUANTITY:";
//
// textBoxQuantity
//
textBoxQuantity.Location = new Point(127, 72);
textBoxQuantity.Name = "textBoxQuantity";
textBoxQuantity.Size = new Size(100, 23);
textBoxQuantity.TabIndex = 2;
//
// comboBoxDresses
//
comboBoxDresses.FormattingEnabled = true;
comboBoxDresses.Location = new Point(106, 27);
comboBoxDresses.Name = "comboBoxDresses";
comboBoxDresses.Size = new Size(121, 23);
comboBoxDresses.TabIndex = 3;
//
// buttonSell
//
buttonSell.Location = new Point(161, 134);
buttonSell.Name = "buttonSell";
buttonSell.Size = new Size(75, 23);
buttonSell.TabIndex = 4;
buttonSell.Text = "Sell";
buttonSell.UseVisualStyleBackColor = true;
buttonSell.Click += buttonSell_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(242, 134);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Cancel";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// FormDressSelling
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(329, 169);
Controls.Add(buttonCancel);
Controls.Add(buttonSell);
Controls.Add(comboBoxDresses);
Controls.Add(textBoxQuantity);
Controls.Add(labelQuantity);
Controls.Add(labelDressName);
Name = "FormDressSelling";
Text = "Dress selling";
Load += FormDressSelling_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelDressName;
private Label labelQuantity;
private TextBox textBoxQuantity;
private ComboBox comboBoxDresses;
private Button buttonSell;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,81 @@
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 FormDressSelling : Form
{
private readonly IAtelierLogic _logicAtelier;
private readonly IDressLogic _logicDress;
private readonly ILogger _logger;
private Dictionary<int, (IDressModel, int)> _dressesList;
public FormDressSelling(ILogger<FormAtelierRestocking> logger, IDressLogic logicD, IAtelierLogic logicA)
{
InitializeComponent();
_logger = logger;
_logicDress = logicD;
_dressesList = new Dictionary<int, (IDressModel, int)>();
_logicAtelier = logicA;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void buttonSell_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxQuantity.Text))
{
MessageBox.Show("Fill quantity field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DressSearchModel model = new DressSearchModel { ID = Convert.ToInt32(comboBoxDresses.SelectedValue) };
if(!_logicAtelier.SellDress(model, Convert.ToInt32(textBoxQuantity.Text)))
{
MessageBox.Show("There are not enough of specified dresses.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Dresses were sold.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
private void FormDressSelling_Load(object sender, EventArgs e)
{
_logger.LogInformation("Downloading dresses");
try
{
var _list = _logicDress.ReadList(null);
if (_list != null)
{
comboBoxDresses.DisplayMember = "DressName";
comboBoxDresses.ValueMember = "ID";
comboBoxDresses.DataSource = _list;
comboBoxDresses.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Downloading dresses error");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

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

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

@ -0,0 +1,114 @@
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()
{
dressGridView = new DataGridView();
ButtonAdd = new Button();
ButtonChange = new Button();
ButtonDelete = new Button();
ButtonRefresh = new Button();
((System.ComponentModel.ISupportInitialize)dressGridView).BeginInit();
SuspendLayout();
//
// dressGridView
//
dressGridView.BackgroundColor = SystemColors.ButtonHighlight;
dressGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dressGridView.Location = new Point(2, 2);
dressGridView.Name = "dressGridView";
dressGridView.RowTemplate.Height = 25;
dressGridView.Size = new Size(605, 447);
dressGridView.TabIndex = 0;
//
// ButtonAdd
//
ButtonAdd.Location = new Point(661, 30);
ButtonAdd.Name = "ButtonAdd";
ButtonAdd.Size = new Size(92, 35);
ButtonAdd.TabIndex = 1;
ButtonAdd.Text = "Add";
ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
//
// ButtonChange
//
ButtonChange.Location = new Point(661, 85);
ButtonChange.Name = "ButtonChange";
ButtonChange.Size = new Size(92, 35);
ButtonChange.TabIndex = 2;
ButtonChange.Text = "Change";
ButtonChange.UseVisualStyleBackColor = true;
ButtonChange.Click += ButtonUpdate_Click;
//
// ButtonDelete
//
ButtonDelete.Location = new Point(661, 142);
ButtonDelete.Name = "ButtonDelete";
ButtonDelete.Size = new Size(92, 35);
ButtonDelete.TabIndex = 3;
ButtonDelete.Text = "Delete";
ButtonDelete.UseVisualStyleBackColor = true;
ButtonDelete.Click += ButtonDelete_Click;
//
// ButtonRefresh
//
ButtonRefresh.Location = new Point(661, 204);
ButtonRefresh.Name = "ButtonRefresh";
ButtonRefresh.Size = new Size(92, 35);
ButtonRefresh.TabIndex = 4;
ButtonRefresh.Text = "Refresh";
ButtonRefresh.UseVisualStyleBackColor = true;
ButtonRefresh.Click += ButtonRefresh_Click;
//
// FormDresses
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(ButtonRefresh);
Controls.Add(ButtonDelete);
Controls.Add(ButtonChange);
Controls.Add(ButtonAdd);
Controls.Add(dressGridView);
Name = "FormDresses";
Text = "Dresses list";
Load += FormDresses_Load;
((System.ComponentModel.ISupportInitialize)dressGridView).EndInit();
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>

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

@ -0,0 +1,206 @@
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()
{
menuStrip = new MenuStrip();
directoriesToolStripMenuItem = new ToolStripMenuItem();
materialsToolStripMenuItem = new ToolStripMenuItem();
dressesToolStripMenuItem = new ToolStripMenuItem();
ateliersToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
createOrderButton = new Button();
processOrderButton = new Button();
readyOrderButton = new Button();
givenOrderButton = new Button();
refreshOrdersButton = new Button();
buttonRestocking = new Button();
buttonSell = new Button();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(800, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "menuStrip1";
//
// directoriesToolStripMenuItem
//
directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { materialsToolStripMenuItem, dressesToolStripMenuItem, ateliersToolStripMenuItem });
directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem";
directoriesToolStripMenuItem.Size = new Size(75, 20);
directoriesToolStripMenuItem.Text = "Directories";
//
// materialsToolStripMenuItem
//
materialsToolStripMenuItem.Name = "materialsToolStripMenuItem";
materialsToolStripMenuItem.Size = new Size(122, 22);
materialsToolStripMenuItem.Text = "Materials";
materialsToolStripMenuItem.Click += materialsToolStripMenuItem_Click;
//
// dressesToolStripMenuItem
//
dressesToolStripMenuItem.Name = "dressesToolStripMenuItem";
dressesToolStripMenuItem.Size = new Size(122, 22);
dressesToolStripMenuItem.Text = "Dresses";
dressesToolStripMenuItem.Click += dressesToolStripMenuItem_Click;
//
// ateliersToolStripMenuItem
//
ateliersToolStripMenuItem.Name = "ateliersToolStripMenuItem";
ateliersToolStripMenuItem.Size = new Size(122, 22);
ateliersToolStripMenuItem.Text = "Ateliers";
ateliersToolStripMenuItem.Click += ateliersToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(2, 27);
dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(631, 420);
dataGridView.TabIndex = 1;
//
// createOrderButton
//
createOrderButton.Location = new Point(652, 40);
createOrderButton.Name = "createOrderButton";
createOrderButton.Size = new Size(117, 34);
createOrderButton.TabIndex = 2;
createOrderButton.Text = "Create order";
createOrderButton.UseVisualStyleBackColor = true;
createOrderButton.Click += ButtonCreateOrder_Click;
//
// processOrderButton
//
processOrderButton.Location = new Point(652, 96);
processOrderButton.Name = "processOrderButton";
processOrderButton.Size = new Size(117, 34);
processOrderButton.TabIndex = 3;
processOrderButton.Text = "Order's in process";
processOrderButton.UseVisualStyleBackColor = true;
processOrderButton.Click += ButtonTakeOrderInWork_Click;
//
// readyOrderButton
//
readyOrderButton.Location = new Point(652, 154);
readyOrderButton.Name = "readyOrderButton";
readyOrderButton.Size = new Size(117, 34);
readyOrderButton.TabIndex = 4;
readyOrderButton.Text = "Order's ready";
readyOrderButton.UseVisualStyleBackColor = true;
readyOrderButton.Click += ButtonOrderReady_Click;
//
// givenOrderButton
//
givenOrderButton.Location = new Point(652, 210);
givenOrderButton.Name = "givenOrderButton";
givenOrderButton.Size = new Size(117, 34);
givenOrderButton.TabIndex = 5;
givenOrderButton.Text = "Order's given";
givenOrderButton.UseVisualStyleBackColor = true;
givenOrderButton.Click += ButtonIssuedOrder_Click;
//
// refreshOrdersButton
//
refreshOrdersButton.Location = new Point(652, 272);
refreshOrdersButton.Name = "refreshOrdersButton";
refreshOrdersButton.Size = new Size(117, 34);
refreshOrdersButton.TabIndex = 6;
refreshOrdersButton.Text = "Refresh list";
refreshOrdersButton.UseVisualStyleBackColor = true;
refreshOrdersButton.Click += ButtonRef_Click;
//
// buttonRestocking
//
buttonRestocking.Location = new Point(652, 404);
buttonRestocking.Name = "buttonRestocking";
buttonRestocking.Size = new Size(117, 34);
buttonRestocking.TabIndex = 7;
buttonRestocking.Text = "Store restocking";
buttonRestocking.UseVisualStyleBackColor = true;
buttonRestocking.Click += buttonRestocking_Click;
//
// buttonSell
//
buttonSell.Location = new Point(652, 364);
buttonSell.Name = "buttonSell";
buttonSell.Size = new Size(117, 34);
buttonSell.TabIndex = 8;
buttonSell.Text = "Selling dresses";
buttonSell.UseVisualStyleBackColor = true;
buttonSell.Click += buttonSell_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonSell);
Controls.Add(buttonRestocking);
Controls.Add(refreshOrdersButton);
Controls.Add(givenOrderButton);
Controls.Add(readyOrderButton);
Controls.Add(processOrderButton);
Controls.Add(createOrderButton);
Controls.Add(dataGridView);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormMain";
Text = "Order menu";
Load += FormMain_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
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;
private ToolStripMenuItem ateliersToolStripMenuItem;
private Button buttonRestocking;
private Button buttonSell;
}
}

223
SewingDresses/FormMain.cs Normal file
View File

@ -0,0 +1,223 @@
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 ateliersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAteliers));
if (service is FormAteliers form)
{
form.ShowDialog();
}
}
private void buttonRestocking_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAtelierRestocking));
if (service is FormAtelierRestocking 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["ID"].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["ID"].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["ID"].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 (OverflowException ex)
{
_logger.LogError(ex, "Error in giving 'Is given' status to order");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
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();
}
private void buttonSell_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDressSelling));
if (service is FormDressSelling form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="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,148 @@
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()
{
dressLabel = new Label();
quantityLabel = new Label();
priceLabel = new Label();
dressComboBox = new ComboBox();
quantityTextBox = new TextBox();
priceTextBox = new TextBox();
ButtonSave = new Button();
ButtonCancel = new Button();
SuspendLayout();
//
// dressLabel
//
dressLabel.AutoSize = true;
dressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
dressLabel.Location = new Point(12, 9);
dressLabel.Name = "dressLabel";
dressLabel.Size = new Size(82, 25);
dressLabel.TabIndex = 0;
dressLabel.Text = "Product:";
//
// quantityLabel
//
quantityLabel.AutoSize = true;
quantityLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
quantityLabel.Location = new Point(12, 50);
quantityLabel.Name = "quantityLabel";
quantityLabel.Size = new Size(88, 25);
quantityLabel.TabIndex = 1;
quantityLabel.Text = "Quantity:";
//
// priceLabel
//
priceLabel.AutoSize = true;
priceLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
priceLabel.Location = new Point(12, 90);
priceLabel.Name = "priceLabel";
priceLabel.Size = new Size(56, 25);
priceLabel.TabIndex = 2;
priceLabel.Text = "Total:";
//
// dressComboBox
//
dressComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
dressComboBox.FormattingEnabled = true;
dressComboBox.Location = new Point(114, 12);
dressComboBox.Name = "dressComboBox";
dressComboBox.Size = new Size(320, 23);
dressComboBox.TabIndex = 3;
dressComboBox.SelectedIndexChanged += DressComboBox_SelectedIndexChanged;
//
// quantityTextBox
//
quantityTextBox.Location = new Point(114, 52);
quantityTextBox.Name = "quantityTextBox";
quantityTextBox.Size = new Size(320, 23);
quantityTextBox.TabIndex = 4;
quantityTextBox.TextChanged += QuantityTextBox_TextChanged;
//
// priceTextBox
//
priceTextBox.Location = new Point(114, 90);
priceTextBox.Name = "priceTextBox";
priceTextBox.ReadOnly = true;
priceTextBox.Size = new Size(320, 23);
priceTextBox.TabIndex = 5;
//
// ButtonSave
//
ButtonSave.Location = new Point(220, 138);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(100, 32);
ButtonSave.TabIndex = 6;
ButtonSave.Text = "Save";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// ButtonCancel
//
ButtonCancel.Location = new Point(334, 138);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(100, 32);
ButtonCancel.TabIndex = 7;
ButtonCancel.Text = "Cancel";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// FormOrderCreation
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(446, 181);
Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(priceTextBox);
Controls.Add(quantityTextBox);
Controls.Add(dressComboBox);
Controls.Add(priceLabel);
Controls.Add(quantityLabel);
Controls.Add(dressLabel);
Name = "FormOrderCreation";
Text = "Order creation";
Load += FormOrderCreation_Load;
ResumeLayout(false);
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 DressAtelierFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
namespace SewingDresses
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -11,7 +23,40 @@ namespace SewingDresses
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
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<IAtelierStorage, AtelierStorage>();
services.AddTransient<IMaterialLogic, MaterialLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDressLogic, DressLogic>();
services.AddTransient<IAtelierLogic, AtelierLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormMaterial>();
services.AddTransient<FormMaterials>();
services.AddTransient<FormOrderCreation>();
services.AddTransient<FormDress>();
services.AddTransient<FormDressMaterial>();
services.AddTransient<FormDresses>();
services.AddTransient<FormCheckDresses>();
services.AddTransient<FormAtelier>();
services.AddTransient<FormAteliers>();
services.AddTransient<FormAtelierRestocking>();
services.AddTransient<FormDressSelling>();
}
}
}

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,49 @@
<ImplicitUsings>enable</ImplicitUsings>
</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" />
<ProjectReference Include="..\DressAtelierFileImplement\DressAtelierFileImplement.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>

View File

@ -3,7 +3,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingDresses", "SewingDresses.csproj", "{477532B4-09CB-45E7-9AE5-652CAE3E340C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDresses", "SewingDresses.csproj", "{477532B4-09CB-45E7-9AE5-652CAE3E340C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DressAtelierDataModels", "..\DressAtelierDataModels\DressAtelierDataModels.csproj", "{2D48D801-8A00-4FFE-B995-8090A65D0A07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DressAtelierContracts", "..\DressAtelierContracts\DressAtelierContracts.csproj", "{5500343A-5929-4C91-8509-D0E5F65D19BF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DressAtelierBusinessLogic", "..\DressAtelierBusinessLogic\DressAtelierBusinessLogic.csproj", "{535CDE3E-E0FB-4389-905D-B23C8BA13044}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DressAtelierListImplement", "..\DressAtelierListImplement\DressAtelierListImplement.csproj", "{1A88E277-E50A-45C5-89FA-677EBCD2EF63}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DressAtelierFileImplement", "..\DressAtelierFileImplement\DressAtelierFileImplement.csproj", "{C60D17B6-F4E1-4D5F-95EE-FCDB293E1BA5}"
ProjectSection(ProjectDependencies) = postProject
{2D48D801-8A00-4FFE-B995-8090A65D0A07} = {2D48D801-8A00-4FFE-B995-8090A65D0A07}
{5500343A-5929-4C91-8509-D0E5F65D19BF} = {5500343A-5929-4C91-8509-D0E5F65D19BF}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +29,26 @@ Global
{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.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
{C60D17B6-F4E1-4D5F-95EE-FCDB293E1BA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C60D17B6-F4E1-4D5F-95EE-FCDB293E1BA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C60D17B6-F4E1-4D5F-95EE-FCDB293E1BA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C60D17B6-F4E1-4D5F-95EE-FCDB293E1BA5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
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>