Compare commits
9 Commits
main
...
LabWork2Ha
Author | SHA1 | Date | |
---|---|---|---|
313cd7b2c1 | |||
3923eacebd | |||
1a02b213fd | |||
322fd334ca | |||
07dc91676c | |||
1cf8894318 | |||
f27ce6cc8e | |||
d81b8cb987 | |||
87d085de2f |
@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractAutoContracts\AutomobilePlantContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,113 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class CarLogic : ICarLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarStorage _carStorage;
|
||||||
|
public CarLogic(ILogger<CarLogic> logger, ICarStorage carStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_carStorage = carStorage;
|
||||||
|
}
|
||||||
|
public List<CarViewModel>? ReadList(CarSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. CarName:{CarName}.Id:{ Id}", model?.CarName, model?.Id);
|
||||||
|
var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public CarViewModel? ReadElement(CarSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. CarName:{CarName}. Id:{ Id}", model.CarName, model.Id);
|
||||||
|
var element = _carStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public bool Create(CarBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_carStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(CarBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_carStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(CarBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_carStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(CarBindingModel model, bool withParams =
|
||||||
|
true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.CarName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия изделия", nameof(model.CarName));
|
||||||
|
}
|
||||||
|
if (model.Price <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.CarName, model.Price, model.Id);
|
||||||
|
var element = _carStorage.GetElement(new CarSearchModel
|
||||||
|
{
|
||||||
|
CarName = model.CarName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Изделие с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,234 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class CarShopLogic : ICarShopLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarShopStorage _shopStorage;
|
||||||
|
public CarShopLogic(ILogger<CarShopLogic> logger, ICarShopStorage shopStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddCar(CarShopSearchModel model, ICarModel car, int quantity)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quantity <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("AddCarInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(model);
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddCarInShop element not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var quantityCars = 0;
|
||||||
|
foreach (var ShopCar in element.Cars)
|
||||||
|
quantityCars += ShopCar.Value.Item2;
|
||||||
|
if((quantityCars + quantity) > element.Fullness)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Превышена максимальная вместимость", nameof(quantity));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_logger.LogInformation("AddCarInShop find. Id:{Id}", element.Id);
|
||||||
|
|
||||||
|
if (element.Cars.TryGetValue(car.Id, out var pair))
|
||||||
|
{
|
||||||
|
element.Cars[car.Id] = (car, quantity + pair.Item2);
|
||||||
|
_logger.LogInformation("AddCarInShop. Has been added {quantity} {car} in {ShopName}", quantity, car.CarName, element.ShopName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
element.Cars[car.Id] = (car, quantity);
|
||||||
|
_logger.LogInformation("AddCarInShop. Has been added {quantity} new Car {car} in {ShopName}", quantity, car.CarName, element.ShopName);
|
||||||
|
}
|
||||||
|
|
||||||
|
_shopStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = element.Id,
|
||||||
|
Adress = element.Adress,
|
||||||
|
ShopName = element.ShopName,
|
||||||
|
DateOpen = element.DateOpen,
|
||||||
|
Fullness = element.Fullness,
|
||||||
|
Cars = element.Cars
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddCar(ICarModel car, int quantity)
|
||||||
|
{
|
||||||
|
if (CheckShops(quantity))
|
||||||
|
{
|
||||||
|
foreach(var shop in ReadList(null))
|
||||||
|
{
|
||||||
|
if(quantity==0) return true;
|
||||||
|
int OccupiedPlaces = 0;
|
||||||
|
foreach(var ShopCar in shop.Cars)
|
||||||
|
{
|
||||||
|
OccupiedPlaces += ShopCar.Value.Item2;
|
||||||
|
}
|
||||||
|
int EmptyPlaces = shop.Fullness - OccupiedPlaces;
|
||||||
|
if(EmptyPlaces > 0)
|
||||||
|
{
|
||||||
|
EmptyPlaces = EmptyPlaces > quantity ? quantity : EmptyPlaces;
|
||||||
|
AddCar(new CarShopSearchModel { Id = shop.Id}, car, EmptyPlaces);
|
||||||
|
quantity -= EmptyPlaces;
|
||||||
|
if (quantity == 0) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CheckShops( int quantity)
|
||||||
|
{
|
||||||
|
foreach(var shop in ReadList(null))
|
||||||
|
{
|
||||||
|
int OccupiedPlaces = 0;
|
||||||
|
foreach(var car in shop.Cars)
|
||||||
|
{
|
||||||
|
OccupiedPlaces += car.Value.Item2;
|
||||||
|
}
|
||||||
|
int EmptyPlaces = shop.Fullness - OccupiedPlaces;
|
||||||
|
quantity -= EmptyPlaces;
|
||||||
|
}
|
||||||
|
if(quantity <= 0)
|
||||||
|
return true;
|
||||||
|
else return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
model.Cars = new();
|
||||||
|
|
||||||
|
if (_shopStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
|
if (_shopStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? ReadElement(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
||||||
|
var element = _shopStorage.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<CarShopViewModel>? ReadList(CarShopSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ", model?.ShopName, model?.Id);
|
||||||
|
|
||||||
|
var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_shopStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(CarShopBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Shop. ShopName:{0}.Adress:{1}. Id: {2}", model.ShopName, model.Adress, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(new CarShopSearchModel
|
||||||
|
{
|
||||||
|
ShopName = model.ShopName
|
||||||
|
});
|
||||||
|
|
||||||
|
if (element != null && element.Id != model.Id && element.ShopName == model.ShopName)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ComponentLogic : IComponentLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentStorage _componentStorage;
|
||||||
|
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage
|
||||||
|
componentStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_componentStorage = componentStorage;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel>? ReadList(ComponentSearchModel? 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;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? ReadElement(ComponentSearchModel 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 bool Create(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_componentStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_componentStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ComponentBindingModel 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;
|
||||||
|
}
|
||||||
|
private void CheckModel(ComponentBindingModel model, bool withParams =
|
||||||
|
true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия компонента",nameof(model.ComponentName));
|
||||||
|
}
|
||||||
|
if (model.Cost <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||||
|
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||||
|
{
|
||||||
|
ComponentName = model.ComponentName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,145 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
|
||||||
|
public class OrderLogic : IOrderLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly ICarShopLogic _carShopLogic;
|
||||||
|
private readonly ICarStorage _carStorage;
|
||||||
|
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, ICarShopLogic carShopLogic, ICarStorage carStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_orderStorage = orderStorage;
|
||||||
|
_carShopLogic = carShopLogic;
|
||||||
|
_carStorage = carStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
|
||||||
|
if (model.Status != OrderStatus.Неизвестен)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.Status = OrderStatus.Принят;
|
||||||
|
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
model.Status = OrderStatus.Неизвестен;
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
|
||||||
|
if (model.Status + 1 != newStatus)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.Status = newStatus;
|
||||||
|
|
||||||
|
if (model.Status == OrderStatus.Выдан)
|
||||||
|
{
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
if (!_carShopLogic.AddCar(_carStorage.GetElement(new CarSearchModel { Id = model.CarId }), model.Count))
|
||||||
|
{
|
||||||
|
model.Status--;
|
||||||
|
_logger.LogWarning("Small places in shops");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
model.Status--;
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, OrderStatus.Выдан);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, OrderStatus.Готов);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||||
|
}
|
||||||
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Order. 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;
|
||||||
|
}
|
||||||
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.Id < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.Count <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.Sum <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractAutoDataModels\AutomobilePlantDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class CarBindingModel : ICarModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string CarName { get; set; } = string.Empty;
|
||||||
|
public double Price { get; set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> CarComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class CarShopBindingModel : ICarShop
|
||||||
|
{
|
||||||
|
public string ShopName { get; set; } = String.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; set; } = String.Empty ;
|
||||||
|
|
||||||
|
public DateTime DateOpen { get; set; } = new();
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ComponentBindingModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutomobilePlantDataModels.Enums;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class OrderBindingModel : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int CarId { get; set; }
|
||||||
|
public string CarName { get; set; } = string.Empty;
|
||||||
|
public int Count { get; set; }
|
||||||
|
public double Sum { get; set; }
|
||||||
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface ICarLogic
|
||||||
|
{
|
||||||
|
List<CarViewModel>? ReadList(CarSearchModel? model);
|
||||||
|
CarViewModel? ReadElement(CarSearchModel model);
|
||||||
|
bool Create(CarBindingModel model);
|
||||||
|
bool Update(CarBindingModel model);
|
||||||
|
bool Delete(CarBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface ICarShopLogic
|
||||||
|
{
|
||||||
|
List<CarShopViewModel>? ReadList(CarShopSearchModel? model);
|
||||||
|
CarShopViewModel? ReadElement(CarShopSearchModel model);
|
||||||
|
bool Create(CarShopBindingModel model);
|
||||||
|
bool Update(CarShopBindingModel model);
|
||||||
|
bool Delete(CarShopBindingModel model);
|
||||||
|
bool AddCar(CarShopSearchModel model, ICarModel car, int quantity);
|
||||||
|
bool CheckShops(int quantity);
|
||||||
|
bool AddCar(ICarModel car, int quantity);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IComponentLogic
|
||||||
|
{
|
||||||
|
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||||
|
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||||
|
bool Create(ComponentBindingModel model);
|
||||||
|
bool Update(ComponentBindingModel model);
|
||||||
|
bool Delete(ComponentBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IOrderLogic
|
||||||
|
{
|
||||||
|
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||||
|
bool CreateOrder(OrderBindingModel model);
|
||||||
|
bool TakeOrderInWork(OrderBindingModel model);
|
||||||
|
bool FinishOrder(OrderBindingModel model);
|
||||||
|
bool DeliveryOrder(OrderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.SearchModel
|
||||||
|
{
|
||||||
|
public class CarSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? CarName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.SearchModel
|
||||||
|
{
|
||||||
|
public class CarShopSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ShopName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.SearchModel
|
||||||
|
{
|
||||||
|
public class ComponentSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ComponentName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.SearchModel
|
||||||
|
{
|
||||||
|
public class OrderSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface ICarShopStorage
|
||||||
|
{
|
||||||
|
List<CarShopViewModel> GetFullList();
|
||||||
|
List<CarShopViewModel> GetFilteredList(CarShopSearchModel model);
|
||||||
|
bool TrySell ( ICarModel car, int quantity);
|
||||||
|
CarShopViewModel? GetElement(CarShopSearchModel model);
|
||||||
|
CarShopViewModel? Insert(CarShopBindingModel model);
|
||||||
|
CarShopViewModel? Update(CarShopBindingModel model);
|
||||||
|
CarShopViewModel? Delete(CarShopBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface ICarStorage
|
||||||
|
{
|
||||||
|
List<CarViewModel> GetFullList();
|
||||||
|
List<CarViewModel> GetFilteredList(CarSearchModel model);
|
||||||
|
CarViewModel? GetElement(CarSearchModel model);
|
||||||
|
CarViewModel? Insert(CarBindingModel model);
|
||||||
|
CarViewModel? Update(CarBindingModel model);
|
||||||
|
CarViewModel? Delete(CarBindingModel model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IComponentStorage
|
||||||
|
{
|
||||||
|
List<ComponentViewModel> GetFullList();
|
||||||
|
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||||
|
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||||
|
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||||
|
ComponentViewModel? Update(ComponentBindingModel model);
|
||||||
|
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IOrderStorage
|
||||||
|
{
|
||||||
|
List<OrderViewModel> GetFullList();
|
||||||
|
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||||
|
OrderViewModel? GetElement(OrderSearchModel model);
|
||||||
|
OrderViewModel? Insert(OrderBindingModel model);
|
||||||
|
OrderViewModel? Update(OrderBindingModel model);
|
||||||
|
OrderViewModel? Delete(OrderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.ViewModel
|
||||||
|
{
|
||||||
|
public class CarShopViewModel : ICarShop
|
||||||
|
{
|
||||||
|
[DisplayName("Название магазина")]
|
||||||
|
public string ShopName { get; set; } = String.Empty;
|
||||||
|
[DisplayName("Адрес")]
|
||||||
|
public string Adress { get; set; } = String.Empty;
|
||||||
|
[DisplayName("Дата открытия")]
|
||||||
|
public DateTime DateOpen { get; set; } = new();
|
||||||
|
[DisplayName("Наполненность")]
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel;
|
||||||
|
namespace AutomobilePlantContracts.ViewModel
|
||||||
|
{
|
||||||
|
public class CarViewModel : ICarModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название изделия")]
|
||||||
|
public string CarName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Price { get; set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> CarComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel;
|
||||||
|
namespace AutomobilePlantContracts.ViewModel
|
||||||
|
{
|
||||||
|
public class ComponentViewModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название компонента")]
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using AutomobilePlantDataModels.Enums;
|
||||||
|
|
||||||
|
namespace AutomobilePlantContracts.ViewModel
|
||||||
|
{
|
||||||
|
public class OrderViewModel : IOrderModel
|
||||||
|
{
|
||||||
|
[DisplayName("Номер")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int CarId { get; set; }
|
||||||
|
[DisplayName("Изделие")]
|
||||||
|
public string CarName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Количество")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
[DisplayName("Сумма")]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
[DisplayName("Статус")]
|
||||||
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
|
[DisplayName("Дата создания")]
|
||||||
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
[DisplayName("Дата выполнения")]
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
18
AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs
Normal file
18
AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantDataModels.Enums
|
||||||
|
{
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Неизвестен = -1,
|
||||||
|
Принят = 0,
|
||||||
|
Выполняется = 1,
|
||||||
|
Готов = 2,
|
||||||
|
Выдан = 3
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
AutomobilePlant/AbstractAutoDataModels/IId.cs
Normal file
13
AutomobilePlant/AbstractAutoDataModels/IId.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantDataModels
|
||||||
|
{
|
||||||
|
public interface IId
|
||||||
|
{
|
||||||
|
int Id { get; }
|
||||||
|
}
|
||||||
|
}
|
16
AutomobilePlant/AbstractAutoDataModels/Models/ICarModel.cs
Normal file
16
AutomobilePlant/AbstractAutoDataModels/Models/ICarModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantDataModels.Models
|
||||||
|
{
|
||||||
|
public interface ICarModel : IId
|
||||||
|
{
|
||||||
|
string CarName { get; }
|
||||||
|
double Price { get; }
|
||||||
|
Dictionary<int, (IComponentModel, int)> CarComponents { get; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
17
AutomobilePlant/AbstractAutoDataModels/Models/ICarShop.cs
Normal file
17
AutomobilePlant/AbstractAutoDataModels/Models/ICarShop.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantDataModels.Models
|
||||||
|
{
|
||||||
|
public interface ICarShop : IId
|
||||||
|
{
|
||||||
|
string ShopName { get; }
|
||||||
|
string Adress { get; }
|
||||||
|
DateTime DateOpen { get; }
|
||||||
|
int Fullness { get; }
|
||||||
|
Dictionary<int, (ICarModel, int)> Cars { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IComponentModel : IId
|
||||||
|
{
|
||||||
|
string ComponentName { get; }
|
||||||
|
double Cost { get; }
|
||||||
|
}
|
||||||
|
}
|
20
AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs
Normal file
20
AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using AutomobilePlantDataModels.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IOrderModel : IId
|
||||||
|
{
|
||||||
|
int CarId { get; }
|
||||||
|
string CarName { get; }
|
||||||
|
int Count { get; }
|
||||||
|
double Sum { get; }
|
||||||
|
OrderStatus Status { get; }
|
||||||
|
DateTime DateCreate { get; }
|
||||||
|
DateTime? DateImplement { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractAutoContracts\AutomobilePlantContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractAutoDataModels\AutomobilePlantDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,33 @@
|
|||||||
|
using AutomobilePlantListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement
|
||||||
|
{
|
||||||
|
public class DataListSingleton
|
||||||
|
{
|
||||||
|
private static DataListSingleton? _instance;
|
||||||
|
public List<Component> Components { get; set; }
|
||||||
|
public List<Order> Orders { get; set; }
|
||||||
|
public List<Car> Cars { get; set; }
|
||||||
|
public List<CarShop> Shops { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Components = new List<Component>();
|
||||||
|
Orders = new List<Order>();
|
||||||
|
Cars = new List<Car>();
|
||||||
|
Shops = new List<CarShop>();
|
||||||
|
}
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
_instance = new DataListSingleton();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using AutomobilePlantListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Implements
|
||||||
|
{
|
||||||
|
public class CarShopStorege : ICarShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public CarShopStorege()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<CarShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<CarShopViewModel>();
|
||||||
|
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<CarShopViewModel> GetFilteredList(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<CarShopViewModel>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.ShopName.Contains(model.ShopName))
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public CarShopViewModel? GetElement(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
|
||||||
|
{
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CarShopViewModel? Insert(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (model.Id <= shop.Id)
|
||||||
|
{
|
||||||
|
model.Id = shop.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newShop = CarShop.Create(model);
|
||||||
|
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_source.Shops.Add(newShop);
|
||||||
|
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? Update(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.Id == model.Id)
|
||||||
|
{
|
||||||
|
shop.Update(model);
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? Delete(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Shops[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Shops[i];
|
||||||
|
_source.Shops.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool TrySell(ICarModel car, int quantity)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Implements
|
||||||
|
{
|
||||||
|
public class CarStorage : ICarStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public CarStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<CarViewModel>();
|
||||||
|
|
||||||
|
foreach (var car in _source.Cars)
|
||||||
|
{
|
||||||
|
result.Add(car.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarViewModel> GetFilteredList(CarSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<CarViewModel>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.CarName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var car in _source.Cars)
|
||||||
|
{
|
||||||
|
if (car.CarName.Contains(model.CarName))
|
||||||
|
{
|
||||||
|
result.Add(car.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? GetElement(CarSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var car in _source.Cars)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.CarName) && car.CarName == model.CarName) || (model.Id.HasValue && car.Id == model.Id))
|
||||||
|
{
|
||||||
|
return car.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? Insert(CarBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
|
||||||
|
foreach (var car in _source.Cars)
|
||||||
|
{
|
||||||
|
if (model.Id <= car.Id)
|
||||||
|
{
|
||||||
|
model.Id = car.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newCar = Car.Create(model);
|
||||||
|
|
||||||
|
if (newCar == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_source.Cars.Add(newCar);
|
||||||
|
|
||||||
|
return newCar.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? Update(CarBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var car in _source.Cars)
|
||||||
|
{
|
||||||
|
if (car.Id == model.Id)
|
||||||
|
{
|
||||||
|
car.Update(model);
|
||||||
|
return car.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? Delete(CarBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Cars.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Cars[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Cars[i];
|
||||||
|
_source.Cars.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
result.Add(component.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
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 ComponentViewModel? GetElement(ComponentSearchModel 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 ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (model.Id <= component.Id)
|
||||||
|
{
|
||||||
|
model.Id = component.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Components.Add(newComponent);
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (component.Id == model.Id)
|
||||||
|
{
|
||||||
|
component.Update(model);
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.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(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 (model.Id.HasValue && order.Id == model.Id)
|
||||||
|
{
|
||||||
|
result.Add(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 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 newOrder = Order.Create(model);
|
||||||
|
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
|
||||||
|
return newOrder.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
order.Update(model);
|
||||||
|
return 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 element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
AutomobilePlant/AbstractAutoListImplement/Models/Car.cs
Normal file
55
AutomobilePlant/AbstractAutoListImplement/Models/Car.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Models
|
||||||
|
{
|
||||||
|
public class Car : ICarModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string CarName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> CarComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
public static Car? Create(CarBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Car()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
CarName = model.CarName,
|
||||||
|
Price = model.Price,
|
||||||
|
CarComponents = model.CarComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(CarBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CarName = model.CarName;
|
||||||
|
Price = model.Price;
|
||||||
|
CarComponents = model.CarComponents;
|
||||||
|
}
|
||||||
|
public CarViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
CarName = CarName,
|
||||||
|
Price = Price,
|
||||||
|
CarComponents = CarComponents
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
61
AutomobilePlant/AbstractAutoListImplement/Models/CarShop.cs
Normal file
61
AutomobilePlant/AbstractAutoListImplement/Models/CarShop.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Models
|
||||||
|
{
|
||||||
|
public class CarShop : ICarShop
|
||||||
|
{
|
||||||
|
public string ShopName { get; private set; } = String.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; private set; } = String.Empty;
|
||||||
|
|
||||||
|
public DateTime DateOpen { get; private set; }
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (ICarModel, int)> Cars { get; private set; } = new ();
|
||||||
|
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public static CarShop? Create(CarShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new CarShop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Adress = model.Adress,
|
||||||
|
DateOpen = model.DateOpen,
|
||||||
|
Cars = new()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(CarShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
DateOpen = model.DateOpen;
|
||||||
|
Cars = model.Cars;
|
||||||
|
}
|
||||||
|
public CarShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
DateOpen = DateOpen,
|
||||||
|
Cars = Cars
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
public static Component? Create(ComponentBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComponentBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComponentName = model.ComponentName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
public ComponentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComponentName = ComponentName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
65
AutomobilePlant/AbstractAutoListImplement/Models/Order.cs
Normal file
65
AutomobilePlant/AbstractAutoListImplement/Models/Order.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Enums;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomobilePlantListImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int CarId { get; private set; }
|
||||||
|
public string CarName { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
|
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,
|
||||||
|
CarId = model.CarId,
|
||||||
|
CarName = model.CarName,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
CarId = CarId,
|
||||||
|
CarName = CarName,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32825.248
|
VisualStudioVersion = 17.3.32825.248
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels", "AbstractAutoDataModels\AutomobilePlantDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AbstractAutoContracts\AutomobilePlantContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantBusinessLogic", "AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomomilePlantFileImplement", "AutomomilePlantFileImplement\AutomomilePlantFileImplement.csproj", "{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -11,10 +21,30 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{2A499DE6-B7DE-4A28-9906-12FC100451F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{2A499DE6-B7DE-4A28-9906-12FC100451F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2A499DE6-B7DE-4A28-9906-12FC100451F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2A499DE6-B7DE-4A28-9906-12FC100451F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3EC099D5-0C5C-43F5-AC6D-09B4D7CE9D72}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<configuration>
|
|
||||||
<startup>
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
|
||||||
</startup>
|
|
||||||
</configuration>
|
|
@ -1,80 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{2A499DE6-B7DE-4A28-9906-12FC100451F0}</ProjectGuid>
|
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>AutomobilePlant</RootNamespace>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<AssemblyName>AutomobilePlant</AssemblyName>
|
<Nullable>enable</Nullable>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<FileAlignment>512</FileAlignment>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
|
||||||
<Deterministic>true</Deterministic>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<None Remove="nlog.config" />
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Deployment" />
|
|
||||||
<Reference Include="System.Drawing" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Windows.Forms" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Form1.cs">
|
<EmbeddedResource Include="nlog.config">
|
||||||
<SubType>Form</SubType>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Compile>
|
|
||||||
<Compile Include="Form1.Designer.cs">
|
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Program.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<None Include="Properties\Settings.settings">
|
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
|
||||||
</None>
|
|
||||||
<Compile Include="Properties\Settings.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Settings.settings</DependentUpon>
|
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\AutomomilePlantFileImplement\AutomomilePlantFileImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
40
AutomobilePlant/AutomobilePlant/Form1.Designer.cs
generated
40
AutomobilePlant/AutomobilePlant/Form1.Designer.cs
generated
@ -1,40 +0,0 @@
|
|||||||
namespace AutomobilePlant
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором форм Windows
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
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 AutomobilePlant
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
252
AutomobilePlant/AutomobilePlant/FormCar.Designer.cs
generated
Normal file
252
AutomobilePlant/AutomobilePlant/FormCar.Designer.cs
generated
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormCar
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
this.CarNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.PriceLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CarNameTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.PriceTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.ComponentsGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
this.UpdateButton = new System.Windows.Forms.Button();
|
||||||
|
this.DeleteButton = new System.Windows.Forms.Button();
|
||||||
|
this.ChangeButton = new System.Windows.Forms.Button();
|
||||||
|
this.AddButton = new System.Windows.Forms.Button();
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.ComponentsGroupBox.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// CarNameLabel
|
||||||
|
//
|
||||||
|
this.CarNameLabel.AutoSize = true;
|
||||||
|
this.CarNameLabel.Location = new System.Drawing.Point(12, 9);
|
||||||
|
this.CarNameLabel.Name = "PackageNameLabel";
|
||||||
|
this.CarNameLabel.Size = new System.Drawing.Size(65, 15);
|
||||||
|
this.CarNameLabel.TabIndex = 0;
|
||||||
|
this.CarNameLabel.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// PriceLabel
|
||||||
|
//
|
||||||
|
this.PriceLabel.AutoSize = true;
|
||||||
|
this.PriceLabel.Location = new System.Drawing.Point(12, 43);
|
||||||
|
this.PriceLabel.Name = "PriceLabel";
|
||||||
|
this.PriceLabel.Size = new System.Drawing.Size(73, 15);
|
||||||
|
this.PriceLabel.TabIndex = 1;
|
||||||
|
this.PriceLabel.Text = "Стоимость: ";
|
||||||
|
//
|
||||||
|
// CarNameTextBox
|
||||||
|
//
|
||||||
|
this.CarNameTextBox.Location = new System.Drawing.Point(83, 6);
|
||||||
|
this.CarNameTextBox.Name = "PackageNameTextBox";
|
||||||
|
this.CarNameTextBox.Size = new System.Drawing.Size(283, 23);
|
||||||
|
this.CarNameTextBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// PriceTextBox
|
||||||
|
//
|
||||||
|
this.PriceTextBox.Location = new System.Drawing.Point(83, 40);
|
||||||
|
this.PriceTextBox.Name = "PriceTextBox";
|
||||||
|
this.PriceTextBox.Size = new System.Drawing.Size(283, 23);
|
||||||
|
this.PriceTextBox.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ComponentsGroupBox
|
||||||
|
//
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.UpdateButton);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.DeleteButton);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.ChangeButton);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.AddButton);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.DataGridView);
|
||||||
|
this.ComponentsGroupBox.Location = new System.Drawing.Point(12, 80);
|
||||||
|
this.ComponentsGroupBox.Name = "ComponentsGroupBox";
|
||||||
|
this.ComponentsGroupBox.Size = new System.Drawing.Size(722, 350);
|
||||||
|
this.ComponentsGroupBox.TabIndex = 5;
|
||||||
|
this.ComponentsGroupBox.TabStop = false;
|
||||||
|
this.ComponentsGroupBox.Text = "Компоненты";
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
this.UpdateButton.Location = new System.Drawing.Point(590, 203);
|
||||||
|
this.UpdateButton.Name = "UpdateButton";
|
||||||
|
this.UpdateButton.Size = new System.Drawing.Size(110, 38);
|
||||||
|
this.UpdateButton.TabIndex = 4;
|
||||||
|
this.UpdateButton.Text = "Обновить";
|
||||||
|
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// DeleteButton
|
||||||
|
//
|
||||||
|
this.DeleteButton.Location = new System.Drawing.Point(590, 143);
|
||||||
|
this.DeleteButton.Name = "DeleteButton";
|
||||||
|
this.DeleteButton.Size = new System.Drawing.Size(110, 38);
|
||||||
|
this.DeleteButton.TabIndex = 3;
|
||||||
|
this.DeleteButton.Text = "Удалить";
|
||||||
|
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||||
|
//
|
||||||
|
// ChangeButton
|
||||||
|
//
|
||||||
|
this.ChangeButton.Location = new System.Drawing.Point(590, 82);
|
||||||
|
this.ChangeButton.Name = "ChangeButton";
|
||||||
|
this.ChangeButton.Size = new System.Drawing.Size(110, 38);
|
||||||
|
this.ChangeButton.TabIndex = 2;
|
||||||
|
this.ChangeButton.Text = "Изменить";
|
||||||
|
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||||
|
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||||
|
//
|
||||||
|
// AddButton
|
||||||
|
//
|
||||||
|
this.AddButton.Location = new System.Drawing.Point(590, 22);
|
||||||
|
this.AddButton.Name = "AddButton";
|
||||||
|
this.AddButton.Size = new System.Drawing.Size(110, 38);
|
||||||
|
this.AddButton.TabIndex = 1;
|
||||||
|
this.AddButton.Text = "Добавить";
|
||||||
|
this.AddButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
|
||||||
|
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
|
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ID,
|
||||||
|
this.ComponentNameField,
|
||||||
|
this.CountField});
|
||||||
|
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
|
||||||
|
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||||
|
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
||||||
|
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(6, 22);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
|
||||||
|
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
|
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(561, 322);
|
||||||
|
this.DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
this.ID.HeaderText = "ID";
|
||||||
|
this.ID.Name = "ID";
|
||||||
|
this.ID.Visible = false;
|
||||||
|
//
|
||||||
|
// ComponentNameField
|
||||||
|
//
|
||||||
|
this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
this.ComponentNameField.HeaderText = "Компонент";
|
||||||
|
this.ComponentNameField.Name = "ComponentNameField";
|
||||||
|
//
|
||||||
|
// CountField
|
||||||
|
//
|
||||||
|
this.CountField.HeaderText = "Количество";
|
||||||
|
this.CountField.Name = "CountField";
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(602, 446);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(110, 34);
|
||||||
|
this.ButtonCancel.TabIndex = 7;
|
||||||
|
this.ButtonCancel.Text = "Отмена";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(486, 446);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(110, 34);
|
||||||
|
this.SaveButton.TabIndex = 8;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// FormCar
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(746, 498);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.ButtonCancel);
|
||||||
|
this.Controls.Add(this.ComponentsGroupBox);
|
||||||
|
this.Controls.Add(this.PriceTextBox);
|
||||||
|
this.Controls.Add(this.CarNameTextBox);
|
||||||
|
this.Controls.Add(this.PriceLabel);
|
||||||
|
this.Controls.Add(this.CarNameLabel);
|
||||||
|
this.Name = "FormCar";
|
||||||
|
this.Text = "Изделие";
|
||||||
|
this.ComponentsGroupBox.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label CarNameLabel;
|
||||||
|
private Label PriceLabel;
|
||||||
|
private TextBox CarNameTextBox;
|
||||||
|
private TextBox PriceTextBox;
|
||||||
|
private GroupBox ComponentsGroupBox;
|
||||||
|
private Button UpdateButton;
|
||||||
|
private Button DeleteButton;
|
||||||
|
private Button ChangeButton;
|
||||||
|
private Button AddButton;
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn ComponentNameField;
|
||||||
|
private DataGridViewTextBoxColumn CountField;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private Button SaveButton;
|
||||||
|
}
|
||||||
|
}
|
223
AutomobilePlant/AutomobilePlant/FormCar.cs
Normal file
223
AutomobilePlant/AutomobilePlant/FormCar.cs
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantDataModels.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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormCar : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
private Dictionary<int, (IComponentModel, int)> _carComponents;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormCar(ILogger<FormCar> logger, ICarLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_carComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
}
|
||||||
|
private void FormCar_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new CarSearchModel
|
||||||
|
{
|
||||||
|
Id =
|
||||||
|
_id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
CarNameTextBox.Text = view.CarName;
|
||||||
|
PriceTextBox.Text = view.Price.ToString();
|
||||||
|
_carComponents = view.CarComponents ?? new
|
||||||
|
Dictionary<int, (IComponentModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компонент изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_carComponents != null)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _carComponents)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
PriceTextBox.Text = CalcPrice().ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service =
|
||||||
|
Program.ServiceProvider?.GetService(typeof(FormCarComponent));
|
||||||
|
if (service is FormCarComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Добавление нового компонента:{ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
if (_carComponents.ContainsKey(form.Id))
|
||||||
|
{
|
||||||
|
_carComponents[form.Id] = (form.ComponentModel,
|
||||||
|
form.Count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_carComponents.Add(form.Id, (form.ComponentModel,
|
||||||
|
form.Count));
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ChangeButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service =
|
||||||
|
Program.ServiceProvider?.GetService(typeof(FormCarComponent));
|
||||||
|
if (service is FormCarComponent form)
|
||||||
|
{
|
||||||
|
int id =
|
||||||
|
Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
|
||||||
|
form.Id = id;
|
||||||
|
form.Count = _carComponents[id].Item2;
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
_carComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DeleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление компонента: {ComponentName} - {Count} ", DataGridView.SelectedRows[0].Cells[1].Value, DataGridView.SelectedRows[0].Cells[2].Value);
|
||||||
|
_carComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(CarNameTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(PriceTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_carComponents == null || _carComponents.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните компоненты", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new CarBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
CarName = CarNameTextBox.Text,
|
||||||
|
Price = Convert.ToDouble(PriceTextBox.Text),
|
||||||
|
CarComponents = _carComponents
|
||||||
|
};
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
|
_logic.Create(model);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
private double CalcPrice()
|
||||||
|
{
|
||||||
|
double price = 0;
|
||||||
|
foreach (var elem in _carComponents)
|
||||||
|
{
|
||||||
|
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||||
|
}
|
||||||
|
return Math.Round(price * 1.1, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
@ -60,6 +60,7 @@
|
|||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
-->
|
-->
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd: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:element name="root" msdata:IsDataSet="true">
|
||||||
<xsd:complexType>
|
<xsd:complexType>
|
||||||
<xsd:choice maxOccurs="unbounded">
|
<xsd:choice maxOccurs="unbounded">
|
||||||
@ -68,9 +69,10 @@
|
|||||||
<xsd:sequence>
|
<xsd:sequence>
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
</xsd:sequence>
|
</xsd:sequence>
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
<xsd:element name="assembly">
|
<xsd:element name="assembly">
|
||||||
@ -85,9 +87,10 @@
|
|||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
<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:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
</xsd:sequence>
|
</xsd:sequence>
|
||||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
<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="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
<xsd:element name="resheader">
|
<xsd:element name="resheader">
|
||||||
@ -109,9 +112,9 @@
|
|||||||
<value>2.0</value>
|
<value>2.0</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<resheader name="reader">
|
<resheader name="reader">
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
</root>
|
</root>
|
124
AutomobilePlant/AutomobilePlant/FormCarComponent.Designer.cs
generated
Normal file
124
AutomobilePlant/AutomobilePlant/FormCarComponent.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormCarComponent
|
||||||
|
{
|
||||||
|
/// <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.ComponentSelectLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CountLabel = new System.Windows.Forms.Label();
|
||||||
|
this.ComponentComboBox = new System.Windows.Forms.ComboBox();
|
||||||
|
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ComponentSelectLabel
|
||||||
|
//
|
||||||
|
this.ComponentSelectLabel.AutoSize = true;
|
||||||
|
this.ComponentSelectLabel.Location = new System.Drawing.Point(30, 27);
|
||||||
|
this.ComponentSelectLabel.Name = "ComponentSelectLabel";
|
||||||
|
this.ComponentSelectLabel.Size = new System.Drawing.Size(95, 20);
|
||||||
|
this.ComponentSelectLabel.TabIndex = 0;
|
||||||
|
this.ComponentSelectLabel.Text = "Компонент: ";
|
||||||
|
//
|
||||||
|
// CountLabel
|
||||||
|
//
|
||||||
|
this.CountLabel.AutoSize = true;
|
||||||
|
this.CountLabel.Location = new System.Drawing.Point(30, 75);
|
||||||
|
this.CountLabel.Name = "CountLabel";
|
||||||
|
this.CountLabel.Size = new System.Drawing.Size(97, 20);
|
||||||
|
this.CountLabel.TabIndex = 1;
|
||||||
|
this.CountLabel.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// ComponentComboBox
|
||||||
|
//
|
||||||
|
this.ComponentComboBox.FormattingEnabled = true;
|
||||||
|
this.ComponentComboBox.Location = new System.Drawing.Point(122, 23);
|
||||||
|
this.ComponentComboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ComponentComboBox.Name = "ComponentComboBox";
|
||||||
|
this.ComponentComboBox.Size = new System.Drawing.Size(217, 28);
|
||||||
|
this.ComponentComboBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// CountTextBox
|
||||||
|
//
|
||||||
|
this.CountTextBox.Location = new System.Drawing.Point(122, 71);
|
||||||
|
this.CountTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CountTextBox.Name = "CountTextBox";
|
||||||
|
this.CountTextBox.Size = new System.Drawing.Size(217, 27);
|
||||||
|
this.CountTextBox.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(152, 131);
|
||||||
|
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(95, 31);
|
||||||
|
this.SaveButton.TabIndex = 4;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(254, 131);
|
||||||
|
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(86, 31);
|
||||||
|
this.ButtonCancel.TabIndex = 5;
|
||||||
|
this.ButtonCancel.Text = "Отмена";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormCarComponent
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(385, 188);
|
||||||
|
this.Controls.Add(this.ButtonCancel);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.CountTextBox);
|
||||||
|
this.Controls.Add(this.ComponentComboBox);
|
||||||
|
this.Controls.Add(this.CountLabel);
|
||||||
|
this.Controls.Add(this.ComponentSelectLabel);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormCarComponent";
|
||||||
|
this.Text = "Компонент изделия";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label ComponentSelectLabel;
|
||||||
|
private Label CountLabel;
|
||||||
|
private ComboBox ComponentComboBox;
|
||||||
|
private TextBox CountTextBox;
|
||||||
|
private Button SaveButton;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
}
|
||||||
|
}
|
91
AutomobilePlant/AutomobilePlant/FormCarComponent.cs
Normal file
91
AutomobilePlant/AutomobilePlant/FormCarComponent.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormCarComponent : Form
|
||||||
|
{
|
||||||
|
private readonly List<ComponentViewModel>? _list;
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return
|
||||||
|
Convert.ToInt32(ComponentComboBox.SelectedValue);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
ComponentComboBox.SelectedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IComponentModel? ComponentModel
|
||||||
|
{
|
||||||
|
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(CountTextBox.Text); }
|
||||||
|
set
|
||||||
|
{ CountTextBox.Text = value.ToString(); }
|
||||||
|
}
|
||||||
|
public FormCarComponent(IComponentLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_list = logic.ReadList(null);
|
||||||
|
if (_list != null)
|
||||||
|
{
|
||||||
|
ComponentComboBox.DisplayMember = "ComponentName";
|
||||||
|
ComponentComboBox.ValueMember = "Id";
|
||||||
|
ComponentComboBox.DataSource = _list;
|
||||||
|
ComponentComboBox.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ComponentComboBox.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компонент", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
120
AutomobilePlant/AutomobilePlant/FormCarComponent.resx
Normal file
120
AutomobilePlant/AutomobilePlant/FormCarComponent.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
121
AutomobilePlant/AutomobilePlant/FormCars.Designer.cs
generated
Normal file
121
AutomobilePlant/AutomobilePlant/FormCars.Designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormCars
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.AddButton = new System.Windows.Forms.Button();
|
||||||
|
this.ChangeButton = new System.Windows.Forms.Button();
|
||||||
|
this.DeleteButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpdateButton = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(1, 1);
|
||||||
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(642, 660);
|
||||||
|
this.DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// AddButton
|
||||||
|
//
|
||||||
|
this.AddButton.Location = new System.Drawing.Point(669, 16);
|
||||||
|
this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.AddButton.Name = "AddButton";
|
||||||
|
this.AddButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.AddButton.TabIndex = 1;
|
||||||
|
this.AddButton.Text = "Добавить";
|
||||||
|
this.AddButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||||
|
//
|
||||||
|
// ChangeButton
|
||||||
|
//
|
||||||
|
this.ChangeButton.Location = new System.Drawing.Point(669, 95);
|
||||||
|
this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ChangeButton.Name = "ChangeButton";
|
||||||
|
this.ChangeButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.ChangeButton.TabIndex = 2;
|
||||||
|
this.ChangeButton.Text = "Изменить";
|
||||||
|
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||||
|
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||||
|
//
|
||||||
|
// DeleteButton
|
||||||
|
//
|
||||||
|
this.DeleteButton.Location = new System.Drawing.Point(669, 173);
|
||||||
|
this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DeleteButton.Name = "DeleteButton";
|
||||||
|
this.DeleteButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.DeleteButton.TabIndex = 3;
|
||||||
|
this.DeleteButton.Text = "Удалить";
|
||||||
|
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
this.UpdateButton.Location = new System.Drawing.Point(669, 255);
|
||||||
|
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.UpdateButton.Name = "UpdateButton";
|
||||||
|
this.UpdateButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.UpdateButton.TabIndex = 4;
|
||||||
|
this.UpdateButton.Text = "Обновить";
|
||||||
|
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// FormCars
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(819, 669);
|
||||||
|
this.Controls.Add(this.UpdateButton);
|
||||||
|
this.Controls.Add(this.DeleteButton);
|
||||||
|
this.Controls.Add(this.ChangeButton);
|
||||||
|
this.Controls.Add(this.AddButton);
|
||||||
|
this.Controls.Add(this.DataGridView);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormCars";
|
||||||
|
this.Text = "Машины";
|
||||||
|
this.Load += new System.EventHandler(this.FormCars_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button AddButton;
|
||||||
|
private Button ChangeButton;
|
||||||
|
private Button DeleteButton;
|
||||||
|
private Button UpdateButton;
|
||||||
|
}
|
||||||
|
}
|
120
AutomobilePlant/AutomobilePlant/FormCars.cs
Normal file
120
AutomobilePlant/AutomobilePlant/FormCars.cs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormCars : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarLogic _logic;
|
||||||
|
|
||||||
|
public FormCars(ILogger<FormCars> logger, ICarLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormCars_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
DataGridView.DataSource = list;
|
||||||
|
DataGridView.Columns["Id"].Visible = false;
|
||||||
|
DataGridView.Columns["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["CarComponents"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка изделий");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделий");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCar));
|
||||||
|
|
||||||
|
if (service is FormCar form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ChangeButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCar));
|
||||||
|
|
||||||
|
if (service is FormCar form)
|
||||||
|
{
|
||||||
|
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DeleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Удаление изделия");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new CarBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormCars.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormCars.resx
Normal 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>
|
123
AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs
generated
Normal file
123
AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.ComponentNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.ComponentNameTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.CostLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CostTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ComponentNameLabel
|
||||||
|
//
|
||||||
|
this.ComponentNameLabel.AutoSize = true;
|
||||||
|
this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20);
|
||||||
|
this.ComponentNameLabel.Name = "ComponentNameLabel";
|
||||||
|
this.ComponentNameLabel.Size = new System.Drawing.Size(84, 20);
|
||||||
|
this.ComponentNameLabel.TabIndex = 0;
|
||||||
|
this.ComponentNameLabel.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// ComponentNameTextBox
|
||||||
|
//
|
||||||
|
this.ComponentNameTextBox.Location = new System.Drawing.Point(103, 16);
|
||||||
|
this.ComponentNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ComponentNameTextBox.Name = "ComponentNameTextBox";
|
||||||
|
this.ComponentNameTextBox.Size = new System.Drawing.Size(238, 27);
|
||||||
|
this.ComponentNameTextBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// CostLabel
|
||||||
|
//
|
||||||
|
this.CostLabel.AutoSize = true;
|
||||||
|
this.CostLabel.Location = new System.Drawing.Point(46, 72);
|
||||||
|
this.CostLabel.Name = "CostLabel";
|
||||||
|
this.CostLabel.Size = new System.Drawing.Size(56, 20);
|
||||||
|
this.CostLabel.TabIndex = 3;
|
||||||
|
this.CostLabel.Text = "Цена: ";
|
||||||
|
//
|
||||||
|
// CostTextBox
|
||||||
|
//
|
||||||
|
this.CostTextBox.Location = new System.Drawing.Point(103, 68);
|
||||||
|
this.CostTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CostTextBox.Name = "CostTextBox";
|
||||||
|
this.CostTextBox.Size = new System.Drawing.Size(238, 27);
|
||||||
|
this.CostTextBox.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(154, 120);
|
||||||
|
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(95, 31);
|
||||||
|
this.SaveButton.TabIndex = 5;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(256, 120);
|
||||||
|
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(86, 31);
|
||||||
|
this.ButtonCancel.TabIndex = 6;
|
||||||
|
this.ButtonCancel.Text = "Отмена";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormComponent
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(375, 167);
|
||||||
|
this.Controls.Add(this.ButtonCancel);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.CostTextBox);
|
||||||
|
this.Controls.Add(this.CostLabel);
|
||||||
|
this.Controls.Add(this.ComponentNameTextBox);
|
||||||
|
this.Controls.Add(this.ComponentNameLabel);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormComponent";
|
||||||
|
this.Text = "Компонент";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label ComponentNameLabel;
|
||||||
|
private TextBox ComponentNameTextBox;
|
||||||
|
private Label CostLabel;
|
||||||
|
private TextBox CostTextBox;
|
||||||
|
private Button SaveButton;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
}
|
||||||
|
}
|
92
AutomobilePlant/AutomobilePlant/FormComponent.cs
Normal file
92
AutomobilePlant/AutomobilePlant/FormComponent.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormComponent : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
|
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormComponent_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение компонента");
|
||||||
|
|
||||||
|
var view = _logic.ReadElement(new ComponentSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
ComponentNameTextBox.Text = view.ComponentName;
|
||||||
|
CostTextBox.Text = view.Cost.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ComponentNameTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Сохранение компонента");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ComponentBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ComponentName = ComponentNameTextBox.Text,
|
||||||
|
Cost = Convert.ToDouble(CostTextBox.Text)
|
||||||
|
};
|
||||||
|
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
|
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
AutomobilePlant/AutomobilePlant/FormComponent.resx
Normal file
120
AutomobilePlant/AutomobilePlant/FormComponent.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
121
AutomobilePlant/AutomobilePlant/FormComponents.Designer.cs
generated
Normal file
121
AutomobilePlant/AutomobilePlant/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormComponents
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.AddButton = new System.Windows.Forms.Button();
|
||||||
|
this.ChangeButton = new System.Windows.Forms.Button();
|
||||||
|
this.DeleteButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpdateButton = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(2, 0);
|
||||||
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(630, 735);
|
||||||
|
this.DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// AddButton
|
||||||
|
//
|
||||||
|
this.AddButton.Location = new System.Drawing.Point(653, 35);
|
||||||
|
this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.AddButton.Name = "AddButton";
|
||||||
|
this.AddButton.Size = new System.Drawing.Size(162, 60);
|
||||||
|
this.AddButton.TabIndex = 1;
|
||||||
|
this.AddButton.Text = "Добавить";
|
||||||
|
this.AddButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||||
|
//
|
||||||
|
// ChangeButton
|
||||||
|
//
|
||||||
|
this.ChangeButton.Location = new System.Drawing.Point(653, 124);
|
||||||
|
this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ChangeButton.Name = "ChangeButton";
|
||||||
|
this.ChangeButton.Size = new System.Drawing.Size(162, 60);
|
||||||
|
this.ChangeButton.TabIndex = 2;
|
||||||
|
this.ChangeButton.Text = "Изменить";
|
||||||
|
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||||
|
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||||
|
//
|
||||||
|
// DeleteButton
|
||||||
|
//
|
||||||
|
this.DeleteButton.Location = new System.Drawing.Point(653, 216);
|
||||||
|
this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DeleteButton.Name = "DeleteButton";
|
||||||
|
this.DeleteButton.Size = new System.Drawing.Size(162, 60);
|
||||||
|
this.DeleteButton.TabIndex = 3;
|
||||||
|
this.DeleteButton.Text = "Удалить";
|
||||||
|
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
this.UpdateButton.Location = new System.Drawing.Point(653, 307);
|
||||||
|
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.UpdateButton.Name = "UpdateButton";
|
||||||
|
this.UpdateButton.Size = new System.Drawing.Size(162, 60);
|
||||||
|
this.UpdateButton.TabIndex = 4;
|
||||||
|
this.UpdateButton.Text = "Обновить";
|
||||||
|
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// FormComponents
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(829, 736);
|
||||||
|
this.Controls.Add(this.UpdateButton);
|
||||||
|
this.Controls.Add(this.DeleteButton);
|
||||||
|
this.Controls.Add(this.ChangeButton);
|
||||||
|
this.Controls.Add(this.AddButton);
|
||||||
|
this.Controls.Add(this.DataGridView);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormComponents";
|
||||||
|
this.Text = "Компоненты";
|
||||||
|
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button AddButton;
|
||||||
|
private Button ChangeButton;
|
||||||
|
private Button DeleteButton;
|
||||||
|
private Button UpdateButton;
|
||||||
|
}
|
||||||
|
}
|
117
AutomobilePlant/AutomobilePlant/FormComponents.cs
Normal file
117
AutomobilePlant/AutomobilePlant/FormComponents.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormComponents : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentLogic _logic;
|
||||||
|
public FormComponents(ILogger<FormComponents> logger, IComponentLogic
|
||||||
|
logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
private void FormComponents_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
DataGridView.DataSource = list;
|
||||||
|
DataGridView.Columns["Id"].Visible = false;
|
||||||
|
DataGridView.Columns["ComponentName"].AutoSizeMode =
|
||||||
|
DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка компонентов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service =
|
||||||
|
Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||||
|
if (service is FormComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ChangeButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service =
|
||||||
|
Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||||
|
if (service is FormComponent form)
|
||||||
|
{
|
||||||
|
form.Id =
|
||||||
|
Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DeleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id =
|
||||||
|
Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Удаление компонента");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new ComponentBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении.Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormComponents.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormComponents.resx
Normal 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>
|
149
AutomobilePlant/AutomobilePlant/FormCreateOrder.Designer.cs
generated
Normal file
149
AutomobilePlant/AutomobilePlant/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormCreateOrder
|
||||||
|
{
|
||||||
|
/// <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.CarNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CountLabel = new System.Windows.Forms.Label();
|
||||||
|
this.SumLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CarComboBox = new System.Windows.Forms.ComboBox();
|
||||||
|
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.SumTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// CarNameLabel
|
||||||
|
//
|
||||||
|
this.CarNameLabel.AutoSize = true;
|
||||||
|
this.CarNameLabel.Location = new System.Drawing.Point(14, 12);
|
||||||
|
this.CarNameLabel.Name = "CarNameLabel";
|
||||||
|
this.CarNameLabel.Size = new System.Drawing.Size(75, 20);
|
||||||
|
this.CarNameLabel.TabIndex = 0;
|
||||||
|
this.CarNameLabel.Text = "Изделие: ";
|
||||||
|
//
|
||||||
|
// CountLabel
|
||||||
|
//
|
||||||
|
this.CountLabel.AutoSize = true;
|
||||||
|
this.CountLabel.Location = new System.Drawing.Point(14, 53);
|
||||||
|
this.CountLabel.Name = "CountLabel";
|
||||||
|
this.CountLabel.Size = new System.Drawing.Size(97, 20);
|
||||||
|
this.CountLabel.TabIndex = 1;
|
||||||
|
this.CountLabel.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// SumLabel
|
||||||
|
//
|
||||||
|
this.SumLabel.AutoSize = true;
|
||||||
|
this.SumLabel.Location = new System.Drawing.Point(14, 96);
|
||||||
|
this.SumLabel.Name = "SumLabel";
|
||||||
|
this.SumLabel.Size = new System.Drawing.Size(62, 20);
|
||||||
|
this.SumLabel.TabIndex = 2;
|
||||||
|
this.SumLabel.Text = "Сумма: ";
|
||||||
|
//
|
||||||
|
// CarComboBox
|
||||||
|
//
|
||||||
|
this.CarComboBox.FormattingEnabled = true;
|
||||||
|
this.CarComboBox.Location = new System.Drawing.Point(106, 8);
|
||||||
|
this.CarComboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CarComboBox.Name = "CarComboBox";
|
||||||
|
this.CarComboBox.Size = new System.Drawing.Size(229, 28);
|
||||||
|
this.CarComboBox.TabIndex = 3;
|
||||||
|
this.CarComboBox.SelectedIndexChanged += new System.EventHandler(this.CarComboBox_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// CountTextBox
|
||||||
|
//
|
||||||
|
this.CountTextBox.Location = new System.Drawing.Point(106, 49);
|
||||||
|
this.CountTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CountTextBox.Name = "CountTextBox";
|
||||||
|
this.CountTextBox.Size = new System.Drawing.Size(229, 27);
|
||||||
|
this.CountTextBox.TabIndex = 4;
|
||||||
|
this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged);
|
||||||
|
//
|
||||||
|
// SumTextBox
|
||||||
|
//
|
||||||
|
this.SumTextBox.Location = new System.Drawing.Point(106, 92);
|
||||||
|
this.SumTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SumTextBox.Name = "SumTextBox";
|
||||||
|
this.SumTextBox.Size = new System.Drawing.Size(229, 27);
|
||||||
|
this.SumTextBox.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(250, 151);
|
||||||
|
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(86, 31);
|
||||||
|
this.ButtonCancel.TabIndex = 6;
|
||||||
|
this.ButtonCancel.Text = "Отменить";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(147, 151);
|
||||||
|
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(97, 31);
|
||||||
|
this.SaveButton.TabIndex = 7;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// FormCreateOrder
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(353, 204);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.ButtonCancel);
|
||||||
|
this.Controls.Add(this.SumTextBox);
|
||||||
|
this.Controls.Add(this.CountTextBox);
|
||||||
|
this.Controls.Add(this.CarComboBox);
|
||||||
|
this.Controls.Add(this.SumLabel);
|
||||||
|
this.Controls.Add(this.CountLabel);
|
||||||
|
this.Controls.Add(this.CarNameLabel);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormCreateOrder";
|
||||||
|
this.Text = "Заказ";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label CarNameLabel;
|
||||||
|
private Label CountLabel;
|
||||||
|
private Label SumLabel;
|
||||||
|
private ComboBox CarComboBox;
|
||||||
|
private TextBox CountTextBox;
|
||||||
|
private TextBox SumTextBox;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private Button SaveButton;
|
||||||
|
}
|
||||||
|
}
|
143
AutomobilePlant/AutomobilePlant/FormCreateOrder.cs
Normal file
143
AutomobilePlant/AutomobilePlant/FormCreateOrder.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormCreateOrder : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarLogic _logicW;
|
||||||
|
private readonly IOrderLogic _logicO;
|
||||||
|
|
||||||
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, ICarLogic logicW, IOrderLogic logicO)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicW = logicW;
|
||||||
|
_logicO = logicO;
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделий для заказа");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicW.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
CarComboBox.DisplayMember = "CarName";
|
||||||
|
CarComboBox.ValueMember = "Id";
|
||||||
|
CarComboBox.DataSource = list;
|
||||||
|
CarComboBox.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CalcSum()
|
||||||
|
{
|
||||||
|
if (CarComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(CarComboBox.SelectedValue);
|
||||||
|
|
||||||
|
var car = _logicW.ReadElement(new CarSearchModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
|
||||||
|
int count = Convert.ToInt32(CountTextBox.Text);
|
||||||
|
SumTextBox.Text = Math.Round(count * (car?.Price ?? 0), 2).ToString();
|
||||||
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CountTextBox_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CarComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CarComboBox.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Создание заказа");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
CarId = Convert.ToInt32(CarComboBox.SelectedValue),
|
||||||
|
CarName = CarComboBox.Text,
|
||||||
|
Count = Convert.ToInt32(CountTextBox.Text),
|
||||||
|
Sum = Convert.ToDouble(SumTextBox.Text)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
AutomobilePlant/AutomobilePlant/FormCreateOrder.resx
Normal file
120
AutomobilePlant/AutomobilePlant/FormCreateOrder.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
220
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
Normal file
220
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormMain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.MenuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.CreateOrderButton = new System.Windows.Forms.Button();
|
||||||
|
this.TakeOrderInWorkButton = new System.Windows.Forms.Button();
|
||||||
|
this.OrderReadyButton = new System.Windows.Forms.Button();
|
||||||
|
this.IssuedOrderButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpdateListButton = new System.Windows.Forms.Button();
|
||||||
|
this.AddShopCarButton = new System.Windows.Forms.Button();
|
||||||
|
this.Sellbutton = new System.Windows.Forms.Button();
|
||||||
|
this.MenuStrip.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// MenuStrip
|
||||||
|
//
|
||||||
|
this.MenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.СправочникиToolStripMenuItem});
|
||||||
|
this.MenuStrip.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.MenuStrip.Name = "MenuStrip";
|
||||||
|
this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
|
||||||
|
this.MenuStrip.Size = new System.Drawing.Size(989, 30);
|
||||||
|
this.MenuStrip.TabIndex = 0;
|
||||||
|
this.MenuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// СправочникиToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.ИзделияToolStripMenuItem,
|
||||||
|
this.КомпонентыToolStripMenuItem,
|
||||||
|
this.магазиныToolStripMenuItem});
|
||||||
|
this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
|
||||||
|
this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
|
||||||
|
this.СправочникиToolStripMenuItem.Text = "Cправочники";
|
||||||
|
//
|
||||||
|
// ИзделияToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
|
||||||
|
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||||
|
this.ИзделияToolStripMenuItem.Text = "Изделия";
|
||||||
|
this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// КомпонентыToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
||||||
|
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||||
|
this.КомпонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
|
this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// магазиныToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
|
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||||
|
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
|
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(0, 36);
|
||||||
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(825, 561);
|
||||||
|
this.DataGridView.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// CreateOrderButton
|
||||||
|
//
|
||||||
|
this.CreateOrderButton.Location = new System.Drawing.Point(832, 37);
|
||||||
|
this.CreateOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CreateOrderButton.Name = "CreateOrderButton";
|
||||||
|
this.CreateOrderButton.Size = new System.Drawing.Size(143, 44);
|
||||||
|
this.CreateOrderButton.TabIndex = 2;
|
||||||
|
this.CreateOrderButton.Text = "Создать заказ";
|
||||||
|
this.CreateOrderButton.UseVisualStyleBackColor = true;
|
||||||
|
this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click);
|
||||||
|
//
|
||||||
|
// TakeOrderInWorkButton
|
||||||
|
//
|
||||||
|
this.TakeOrderInWorkButton.Location = new System.Drawing.Point(832, 111);
|
||||||
|
this.TakeOrderInWorkButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton";
|
||||||
|
this.TakeOrderInWorkButton.Size = new System.Drawing.Size(143, 52);
|
||||||
|
this.TakeOrderInWorkButton.TabIndex = 3;
|
||||||
|
this.TakeOrderInWorkButton.Text = "Отдать на выполнение";
|
||||||
|
this.TakeOrderInWorkButton.UseVisualStyleBackColor = true;
|
||||||
|
this.TakeOrderInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click);
|
||||||
|
//
|
||||||
|
// OrderReadyButton
|
||||||
|
//
|
||||||
|
this.OrderReadyButton.Location = new System.Drawing.Point(832, 195);
|
||||||
|
this.OrderReadyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.OrderReadyButton.Name = "OrderReadyButton";
|
||||||
|
this.OrderReadyButton.Size = new System.Drawing.Size(143, 44);
|
||||||
|
this.OrderReadyButton.TabIndex = 4;
|
||||||
|
this.OrderReadyButton.Text = "Заказ готов";
|
||||||
|
this.OrderReadyButton.UseVisualStyleBackColor = true;
|
||||||
|
this.OrderReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click);
|
||||||
|
//
|
||||||
|
// IssuedOrderButton
|
||||||
|
//
|
||||||
|
this.IssuedOrderButton.Location = new System.Drawing.Point(832, 272);
|
||||||
|
this.IssuedOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.IssuedOrderButton.Name = "IssuedOrderButton";
|
||||||
|
this.IssuedOrderButton.Size = new System.Drawing.Size(143, 44);
|
||||||
|
this.IssuedOrderButton.TabIndex = 5;
|
||||||
|
this.IssuedOrderButton.Text = "Заказ выдан";
|
||||||
|
this.IssuedOrderButton.UseVisualStyleBackColor = true;
|
||||||
|
this.IssuedOrderButton.Click += new System.EventHandler(this.IssuedOrderButton_Click);
|
||||||
|
//
|
||||||
|
// UpdateListButton
|
||||||
|
//
|
||||||
|
this.UpdateListButton.Location = new System.Drawing.Point(832, 349);
|
||||||
|
this.UpdateListButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.UpdateListButton.Name = "UpdateListButton";
|
||||||
|
this.UpdateListButton.Size = new System.Drawing.Size(143, 44);
|
||||||
|
this.UpdateListButton.TabIndex = 6;
|
||||||
|
this.UpdateListButton.Text = "Обновить список";
|
||||||
|
this.UpdateListButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click);
|
||||||
|
//
|
||||||
|
// AddShopCarButton
|
||||||
|
//
|
||||||
|
this.AddShopCarButton.Location = new System.Drawing.Point(832, 416);
|
||||||
|
this.AddShopCarButton.Name = "AddShopCarButton";
|
||||||
|
this.AddShopCarButton.Size = new System.Drawing.Size(143, 56);
|
||||||
|
this.AddShopCarButton.TabIndex = 7;
|
||||||
|
this.AddShopCarButton.Text = "Пополнить магазин";
|
||||||
|
this.AddShopCarButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddShopCarButton.Click += new System.EventHandler(this.AddShopCarButton_Click);
|
||||||
|
//
|
||||||
|
// Sellbutton
|
||||||
|
//
|
||||||
|
this.Sellbutton.Location = new System.Drawing.Point(832, 507);
|
||||||
|
this.Sellbutton.Name = "Sellbutton";
|
||||||
|
this.Sellbutton.Size = new System.Drawing.Size(143, 56);
|
||||||
|
this.Sellbutton.TabIndex = 8;
|
||||||
|
this.Sellbutton.Text = "Продать";
|
||||||
|
this.Sellbutton.UseVisualStyleBackColor = true;
|
||||||
|
this.Sellbutton.Click += new System.EventHandler(this.Sellbutton_Click);
|
||||||
|
//
|
||||||
|
// FormMain
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(989, 600);
|
||||||
|
this.Controls.Add(this.Sellbutton);
|
||||||
|
this.Controls.Add(this.AddShopCarButton);
|
||||||
|
this.Controls.Add(this.UpdateListButton);
|
||||||
|
this.Controls.Add(this.IssuedOrderButton);
|
||||||
|
this.Controls.Add(this.OrderReadyButton);
|
||||||
|
this.Controls.Add(this.TakeOrderInWorkButton);
|
||||||
|
this.Controls.Add(this.CreateOrderButton);
|
||||||
|
this.Controls.Add(this.DataGridView);
|
||||||
|
this.Controls.Add(this.MenuStrip);
|
||||||
|
this.MainMenuStrip = this.MenuStrip;
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormMain";
|
||||||
|
this.Text = "Автозавод";
|
||||||
|
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||||
|
this.MenuStrip.ResumeLayout(false);
|
||||||
|
this.MenuStrip.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private MenuStrip MenuStrip;
|
||||||
|
private ToolStripMenuItem СправочникиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem ИзделияToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem КомпонентыToolStripMenuItem;
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button CreateOrderButton;
|
||||||
|
private Button TakeOrderInWorkButton;
|
||||||
|
private Button OrderReadyButton;
|
||||||
|
private Button IssuedOrderButton;
|
||||||
|
private Button UpdateListButton;
|
||||||
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
|
private Button AddShopCarButton;
|
||||||
|
private Button Sellbutton;
|
||||||
|
}
|
||||||
|
}
|
232
AutomobilePlant/AutomobilePlant/FormMain.cs
Normal file
232
AutomobilePlant/AutomobilePlant/FormMain.cs
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantDataModels.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 AutomobilePlant
|
||||||
|
{
|
||||||
|
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("Загрузка заказов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _orderLogic.ReadList(null);
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
DataGridView.DataSource = list;
|
||||||
|
DataGridView.Columns["CarId"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка заказов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
|
|
||||||
|
if (service is FormComponents form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCars));
|
||||||
|
|
||||||
|
if (service is FormCars form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateOrderButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
|
|
||||||
|
if (service is FormCreateOrder form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TakeOrderInWorkButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
CarId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["CarId"].Value),
|
||||||
|
CarName = DataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(),
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OrderReadyButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
CarId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["CarId"].Value),
|
||||||
|
CarName = DataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(),
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void IssuedOrderButton_Click (object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
CarId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["CarId"].Value),
|
||||||
|
CarName = DataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(),
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateListButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||||
|
|
||||||
|
if (service is FormShops form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddShopCarButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopAdd));
|
||||||
|
|
||||||
|
if (service is FormShopAdd form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Sellbutton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||||
|
|
||||||
|
if (service is FormShopSell form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
AutomobilePlant/AutomobilePlant/FormMain.resx
Normal file
63
AutomobilePlant/AutomobilePlant/FormMain.resx
Normal 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>
|
181
AutomobilePlant/AutomobilePlant/FormShop.Designer.cs
generated
Normal file
181
AutomobilePlant/AutomobilePlant/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormShop
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#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()
|
||||||
|
{
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
this.CarGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.CarNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.UpdateButton = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.CarGroupBox.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// CarGroupBox
|
||||||
|
//
|
||||||
|
this.CarGroupBox.Controls.Add(this.DataGridView);
|
||||||
|
this.CarGroupBox.Location = new System.Drawing.Point(12, 13);
|
||||||
|
this.CarGroupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CarGroupBox.Name = "CarGroupBox";
|
||||||
|
this.CarGroupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.CarGroupBox.Size = new System.Drawing.Size(825, 467);
|
||||||
|
this.CarGroupBox.TabIndex = 5;
|
||||||
|
this.CarGroupBox.TabStop = false;
|
||||||
|
this.CarGroupBox.Text = "машиины";
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
|
||||||
|
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
|
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ID,
|
||||||
|
this.CarNameField,
|
||||||
|
this.CountField});
|
||||||
|
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
|
||||||
|
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||||
|
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
||||||
|
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(7, 29);
|
||||||
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
|
||||||
|
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
|
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
|
||||||
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(762, 429);
|
||||||
|
this.DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
this.ID.HeaderText = "ID";
|
||||||
|
this.ID.MinimumWidth = 6;
|
||||||
|
this.ID.Name = "ID";
|
||||||
|
this.ID.Visible = false;
|
||||||
|
this.ID.Width = 125;
|
||||||
|
//
|
||||||
|
// CarNameField
|
||||||
|
//
|
||||||
|
this.CarNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
this.CarNameField.HeaderText = "Машина";
|
||||||
|
this.CarNameField.MinimumWidth = 6;
|
||||||
|
this.CarNameField.Name = "CarNameField";
|
||||||
|
//
|
||||||
|
// CountField
|
||||||
|
//
|
||||||
|
this.CountField.HeaderText = "Количество";
|
||||||
|
this.CountField.MinimumWidth = 6;
|
||||||
|
this.CountField.Name = "CountField";
|
||||||
|
this.CountField.Width = 125;
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
this.UpdateButton.Location = new System.Drawing.Point(395, 505);
|
||||||
|
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.UpdateButton.Name = "UpdateButton";
|
||||||
|
this.UpdateButton.Size = new System.Drawing.Size(126, 51);
|
||||||
|
this.UpdateButton.TabIndex = 4;
|
||||||
|
this.UpdateButton.Text = "Обновить";
|
||||||
|
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(695, 505);
|
||||||
|
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(126, 45);
|
||||||
|
this.ButtonCancel.TabIndex = 7;
|
||||||
|
this.ButtonCancel.Text = "Отмена";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(548, 505);
|
||||||
|
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(126, 45);
|
||||||
|
this.SaveButton.TabIndex = 8;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// FormShop
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(853, 568);
|
||||||
|
this.Controls.Add(this.UpdateButton);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.ButtonCancel);
|
||||||
|
this.Controls.Add(this.CarGroupBox);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormShop";
|
||||||
|
this.Text = "Магазин";
|
||||||
|
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||||
|
this.CarGroupBox.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private GroupBox CarGroupBox;
|
||||||
|
private Button UpdateButton;
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn CarNameField;
|
||||||
|
private DataGridViewTextBoxColumn CountField;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private Button SaveButton;
|
||||||
|
}
|
||||||
|
}
|
113
AutomobilePlant/AutomobilePlant/FormShop.cs
Normal file
113
AutomobilePlant/AutomobilePlant/FormShop.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantDataModels.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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormShop : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarShopLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
private Dictionary<int, (ICarModel, int)> _carComponents;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormShop(ILogger<FormShop> logger, ICarShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_carComponents = new Dictionary<int, (ICarModel, int)>();
|
||||||
|
}
|
||||||
|
private void FormShop_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new CarShopSearchModel
|
||||||
|
{
|
||||||
|
Id =
|
||||||
|
_id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
_carComponents = view.Cars ?? new
|
||||||
|
Dictionary<int, (ICarModel, int)>();
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка машин магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_carComponents != null)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _carComponents)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.CarName, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки машин магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormShop.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShop.resx
Normal 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>
|
142
AutomobilePlant/AutomobilePlant/FormShopAdd.Designer.cs
generated
Normal file
142
AutomobilePlant/AutomobilePlant/FormShopAdd.Designer.cs
generated
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormShopAdd
|
||||||
|
{
|
||||||
|
/// <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.ShopNameComboBox = new System.Windows.Forms.ComboBox();
|
||||||
|
this.CarComboBox = new System.Windows.Forms.ComboBox();
|
||||||
|
this.NameShopLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CarLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.CountLabel = new System.Windows.Forms.Label();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.CancelButton = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ShopNameComboBox
|
||||||
|
//
|
||||||
|
this.ShopNameComboBox.FormattingEnabled = true;
|
||||||
|
this.ShopNameComboBox.Location = new System.Drawing.Point(113, 41);
|
||||||
|
this.ShopNameComboBox.Name = "ShopNameComboBox";
|
||||||
|
this.ShopNameComboBox.Size = new System.Drawing.Size(233, 28);
|
||||||
|
this.ShopNameComboBox.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// CarComboBox
|
||||||
|
//
|
||||||
|
this.CarComboBox.FormattingEnabled = true;
|
||||||
|
this.CarComboBox.Location = new System.Drawing.Point(113, 93);
|
||||||
|
this.CarComboBox.Name = "CarComboBox";
|
||||||
|
this.CarComboBox.Size = new System.Drawing.Size(233, 28);
|
||||||
|
this.CarComboBox.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// NameShopLabel
|
||||||
|
//
|
||||||
|
this.NameShopLabel.AutoSize = true;
|
||||||
|
this.NameShopLabel.Location = new System.Drawing.Point(12, 44);
|
||||||
|
this.NameShopLabel.Name = "NameShopLabel";
|
||||||
|
this.NameShopLabel.Size = new System.Drawing.Size(69, 20);
|
||||||
|
this.NameShopLabel.TabIndex = 2;
|
||||||
|
this.NameShopLabel.Text = "Магазин";
|
||||||
|
//
|
||||||
|
// CarLabel
|
||||||
|
//
|
||||||
|
this.CarLabel.AutoSize = true;
|
||||||
|
this.CarLabel.Location = new System.Drawing.Point(12, 96);
|
||||||
|
this.CarLabel.Name = "CarLabel";
|
||||||
|
this.CarLabel.Size = new System.Drawing.Size(68, 20);
|
||||||
|
this.CarLabel.TabIndex = 3;
|
||||||
|
this.CarLabel.Text = "Изделие";
|
||||||
|
//
|
||||||
|
// CountTextBox
|
||||||
|
//
|
||||||
|
this.CountTextBox.Location = new System.Drawing.Point(113, 139);
|
||||||
|
this.CountTextBox.Name = "CountTextBox";
|
||||||
|
this.CountTextBox.Size = new System.Drawing.Size(233, 27);
|
||||||
|
this.CountTextBox.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// CountLabel
|
||||||
|
//
|
||||||
|
this.CountLabel.AutoSize = true;
|
||||||
|
this.CountLabel.Location = new System.Drawing.Point(12, 146);
|
||||||
|
this.CountLabel.Name = "CountLabel";
|
||||||
|
this.CountLabel.Size = new System.Drawing.Size(58, 20);
|
||||||
|
this.CountLabel.TabIndex = 5;
|
||||||
|
this.CountLabel.Text = "Кол-во";
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(130, 189);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(94, 44);
|
||||||
|
this.SaveButton.TabIndex = 6;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// CancelButton
|
||||||
|
//
|
||||||
|
this.CancelButton.Location = new System.Drawing.Point(252, 189);
|
||||||
|
this.CancelButton.Name = "CancelButton";
|
||||||
|
this.CancelButton.Size = new System.Drawing.Size(94, 44);
|
||||||
|
this.CancelButton.TabIndex = 7;
|
||||||
|
this.CancelButton.Text = "Закрыть";
|
||||||
|
this.CancelButton.UseVisualStyleBackColor = true;
|
||||||
|
this.CancelButton.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormShopAdd
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(413, 245);
|
||||||
|
this.Controls.Add(this.CancelButton);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.CountLabel);
|
||||||
|
this.Controls.Add(this.CountTextBox);
|
||||||
|
this.Controls.Add(this.CarLabel);
|
||||||
|
this.Controls.Add(this.NameShopLabel);
|
||||||
|
this.Controls.Add(this.CarComboBox);
|
||||||
|
this.Controls.Add(this.ShopNameComboBox);
|
||||||
|
this.Name = "FormShopAdd";
|
||||||
|
this.Text = "FormShopAdd";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private ComboBox ShopNameComboBox;
|
||||||
|
private ComboBox CarComboBox;
|
||||||
|
private Label NameShopLabel;
|
||||||
|
private Label CarLabel;
|
||||||
|
private TextBox CountTextBox;
|
||||||
|
private Label CountLabel;
|
||||||
|
private Button SaveButton;
|
||||||
|
private Button CancelButton;
|
||||||
|
}
|
||||||
|
}
|
104
AutomobilePlant/AutomobilePlant/FormShopAdd.cs
Normal file
104
AutomobilePlant/AutomobilePlant/FormShopAdd.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormShopAdd : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarShopLogic _shopLogic;
|
||||||
|
private readonly ICarLogic _carLogic;
|
||||||
|
private readonly List<CarShopViewModel>? _listShops;
|
||||||
|
private readonly List<CarViewModel>? _listCars;
|
||||||
|
public FormShopAdd(ILogger<FormShopAdd> logger, ICarShopLogic shopLogic, ICarLogic carLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_carLogic = carLogic;
|
||||||
|
_logger = logger;
|
||||||
|
_listShops = shopLogic.ReadList(null);
|
||||||
|
if (_listShops != null)
|
||||||
|
{
|
||||||
|
ShopNameComboBox.DisplayMember = "ShopName";
|
||||||
|
ShopNameComboBox.ValueMember = "Id";
|
||||||
|
ShopNameComboBox.DataSource = _listShops;
|
||||||
|
ShopNameComboBox.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_listCars = carLogic.ReadList(null);
|
||||||
|
if (_listCars != null)
|
||||||
|
{
|
||||||
|
CarComboBox.DisplayMember = "CarName";
|
||||||
|
CarComboBox.ValueMember = "Id";
|
||||||
|
CarComboBox.DataSource = _listCars;
|
||||||
|
CarComboBox.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (ShopNameComboBox.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CarComboBox.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Добавление изделия в магазин");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var car = _carLogic.ReadElement(new()
|
||||||
|
{
|
||||||
|
Id = (int)CarComboBox.SelectedValue
|
||||||
|
});
|
||||||
|
|
||||||
|
if (car == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultOperation = _shopLogic.AddCar(
|
||||||
|
model: new() { Id = (int)ShopNameComboBox.SelectedValue },
|
||||||
|
car: car,
|
||||||
|
quantity: Convert.ToInt32(CountTextBox.Text)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!resultOperation)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormShopAdd.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShopAdd.resx
Normal 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>
|
263
AutomobilePlant/AutomobilePlant/FormShopCar.Designer.cs
generated
Normal file
263
AutomobilePlant/AutomobilePlant/FormShopCar.Designer.cs
generated
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormShopCar
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
|
this.ShopNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.AdressLabel = new System.Windows.Forms.Label();
|
||||||
|
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.AdressTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.ComponentsGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpdateButton = new System.Windows.Forms.Button();
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.DateOpenPicker = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.FullnessnumericUpDown = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.Fullness = new System.Windows.Forms.Label();
|
||||||
|
this.ComponentsGroupBox.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ShopNameLabel
|
||||||
|
//
|
||||||
|
this.ShopNameLabel.AutoSize = true;
|
||||||
|
this.ShopNameLabel.Location = new System.Drawing.Point(14, 12);
|
||||||
|
this.ShopNameLabel.Name = "ShopNameLabel";
|
||||||
|
this.ShopNameLabel.Size = new System.Drawing.Size(84, 20);
|
||||||
|
this.ShopNameLabel.TabIndex = 0;
|
||||||
|
this.ShopNameLabel.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// AdressLabel
|
||||||
|
//
|
||||||
|
this.AdressLabel.AutoSize = true;
|
||||||
|
this.AdressLabel.Location = new System.Drawing.Point(14, 57);
|
||||||
|
this.AdressLabel.Name = "AdressLabel";
|
||||||
|
this.AdressLabel.Size = new System.Drawing.Size(51, 20);
|
||||||
|
this.AdressLabel.TabIndex = 1;
|
||||||
|
this.AdressLabel.Text = "Адрес";
|
||||||
|
//
|
||||||
|
// ShopNameTextBox
|
||||||
|
//
|
||||||
|
this.ShopNameTextBox.Location = new System.Drawing.Point(95, 8);
|
||||||
|
this.ShopNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ShopNameTextBox.Name = "ShopNameTextBox";
|
||||||
|
this.ShopNameTextBox.Size = new System.Drawing.Size(323, 27);
|
||||||
|
this.ShopNameTextBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// AdressTextBox
|
||||||
|
//
|
||||||
|
this.AdressTextBox.Location = new System.Drawing.Point(95, 53);
|
||||||
|
this.AdressTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.AdressTextBox.Name = "AdressTextBox";
|
||||||
|
this.AdressTextBox.Size = new System.Drawing.Size(323, 27);
|
||||||
|
this.AdressTextBox.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ComponentsGroupBox
|
||||||
|
//
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.ButtonCancel);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.SaveButton);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.UpdateButton);
|
||||||
|
this.ComponentsGroupBox.Controls.Add(this.DataGridView);
|
||||||
|
this.ComponentsGroupBox.Location = new System.Drawing.Point(14, 107);
|
||||||
|
this.ComponentsGroupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ComponentsGroupBox.Name = "ComponentsGroupBox";
|
||||||
|
this.ComponentsGroupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ComponentsGroupBox.Size = new System.Drawing.Size(825, 467);
|
||||||
|
this.ComponentsGroupBox.TabIndex = 5;
|
||||||
|
this.ComponentsGroupBox.TabStop = false;
|
||||||
|
this.ComponentsGroupBox.Text = "Машины";
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(674, 232);
|
||||||
|
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(126, 45);
|
||||||
|
this.ButtonCancel.TabIndex = 7;
|
||||||
|
this.ButtonCancel.Text = "Отмена";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(674, 79);
|
||||||
|
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(126, 45);
|
||||||
|
this.SaveButton.TabIndex = 8;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
this.UpdateButton.Location = new System.Drawing.Point(674, 142);
|
||||||
|
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.UpdateButton.Name = "UpdateButton";
|
||||||
|
this.UpdateButton.Size = new System.Drawing.Size(126, 51);
|
||||||
|
this.UpdateButton.TabIndex = 4;
|
||||||
|
this.UpdateButton.Text = "Обновить";
|
||||||
|
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
|
||||||
|
dataGridViewCellStyle4.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
|
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4;
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ID,
|
||||||
|
this.ComponentNameField,
|
||||||
|
this.CountField});
|
||||||
|
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window;
|
||||||
|
dataGridViewCellStyle5.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||||
|
dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
||||||
|
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle5;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(7, 29);
|
||||||
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
|
dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control;
|
||||||
|
dataGridViewCellStyle6.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
|
dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
|
dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
|
dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle6;
|
||||||
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(641, 429);
|
||||||
|
this.DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
this.ID.HeaderText = "ID";
|
||||||
|
this.ID.MinimumWidth = 6;
|
||||||
|
this.ID.Name = "ID";
|
||||||
|
this.ID.Visible = false;
|
||||||
|
this.ID.Width = 125;
|
||||||
|
//
|
||||||
|
// ComponentNameField
|
||||||
|
//
|
||||||
|
this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
this.ComponentNameField.HeaderText = "Машина";
|
||||||
|
this.ComponentNameField.MinimumWidth = 6;
|
||||||
|
this.ComponentNameField.Name = "ComponentNameField";
|
||||||
|
//
|
||||||
|
// CountField
|
||||||
|
//
|
||||||
|
this.CountField.HeaderText = "Количество";
|
||||||
|
this.CountField.MinimumWidth = 6;
|
||||||
|
this.CountField.Name = "CountField";
|
||||||
|
this.CountField.Width = 125;
|
||||||
|
//
|
||||||
|
// DateOpenPicker
|
||||||
|
//
|
||||||
|
this.DateOpenPicker.Location = new System.Drawing.Point(495, 12);
|
||||||
|
this.DateOpenPicker.Name = "DateOpenPicker";
|
||||||
|
this.DateOpenPicker.Size = new System.Drawing.Size(250, 27);
|
||||||
|
this.DateOpenPicker.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// FullnessnumericUpDown
|
||||||
|
//
|
||||||
|
this.FullnessnumericUpDown.Location = new System.Drawing.Point(595, 57);
|
||||||
|
this.FullnessnumericUpDown.Name = "FullnessnumericUpDown";
|
||||||
|
this.FullnessnumericUpDown.Size = new System.Drawing.Size(150, 27);
|
||||||
|
this.FullnessnumericUpDown.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// Fullness
|
||||||
|
//
|
||||||
|
this.Fullness.AutoSize = true;
|
||||||
|
this.Fullness.Location = new System.Drawing.Point(469, 64);
|
||||||
|
this.Fullness.Name = "Fullness";
|
||||||
|
this.Fullness.Size = new System.Drawing.Size(103, 20);
|
||||||
|
this.Fullness.TabIndex = 8;
|
||||||
|
this.Fullness.Text = "Ограничение";
|
||||||
|
//
|
||||||
|
// FormShopCar
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(853, 664);
|
||||||
|
this.Controls.Add(this.Fullness);
|
||||||
|
this.Controls.Add(this.FullnessnumericUpDown);
|
||||||
|
this.Controls.Add(this.DateOpenPicker);
|
||||||
|
this.Controls.Add(this.ComponentsGroupBox);
|
||||||
|
this.Controls.Add(this.AdressTextBox);
|
||||||
|
this.Controls.Add(this.ShopNameTextBox);
|
||||||
|
this.Controls.Add(this.AdressLabel);
|
||||||
|
this.Controls.Add(this.ShopNameLabel);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormShopCar";
|
||||||
|
this.Text = "Изделие";
|
||||||
|
this.Load += new System.EventHandler(this.FormCar_Load);
|
||||||
|
this.ComponentsGroupBox.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label ShopNameLabel;
|
||||||
|
private Label AdressLabel;
|
||||||
|
private TextBox ShopNameTextBox;
|
||||||
|
private TextBox AdressTextBox;
|
||||||
|
private GroupBox ComponentsGroupBox;
|
||||||
|
private Button UpdateButton;
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private Button SaveButton;
|
||||||
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn ComponentNameField;
|
||||||
|
private DataGridViewTextBoxColumn CountField;
|
||||||
|
private DateTimePicker DateOpenPicker;
|
||||||
|
private NumericUpDown FullnessnumericUpDown;
|
||||||
|
private Label Fullness;
|
||||||
|
}
|
||||||
|
}
|
142
AutomobilePlant/AutomobilePlant/FormShopCar.cs
Normal file
142
AutomobilePlant/AutomobilePlant/FormShopCar.cs
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantDataModels.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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormShopCar : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarShopLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
private Dictionary<int, (ICarModel, int)> _cars;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormShopCar(ILogger<FormCar> logger, ICarShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_cars = new Dictionary<int, (ICarModel, int)>();
|
||||||
|
}
|
||||||
|
private void FormCar_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new CarShopSearchModel
|
||||||
|
{
|
||||||
|
Id =
|
||||||
|
_id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
ShopNameTextBox.Text = view.ShopName;
|
||||||
|
AdressTextBox.Text = view.Adress;
|
||||||
|
DateOpenPicker.Value = view.DateOpen;
|
||||||
|
FullnessnumericUpDown.Value = view.Fullness;
|
||||||
|
_cars = view.Cars ?? new
|
||||||
|
Dictionary<int, (ICarModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компонент изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_cars != null)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _cars)
|
||||||
|
{
|
||||||
|
DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.CarName, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ShopNameTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(AdressTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Сохранение изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new CarShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ShopName = ShopNameTextBox.Text,
|
||||||
|
DateOpen = DateOpenPicker.Value,
|
||||||
|
Adress = AdressTextBox.Text,
|
||||||
|
Fullness = (int)FullnessnumericUpDown.Value,
|
||||||
|
Cars = _cars
|
||||||
|
};
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
|
_logic.Create(model);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormShopCar.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShopCar.resx
Normal 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>
|
123
AutomobilePlant/AutomobilePlant/FormShopCreate.Designer.cs
generated
Normal file
123
AutomobilePlant/AutomobilePlant/FormShopCreate.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormShopCreate
|
||||||
|
{
|
||||||
|
/// <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.ShopNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.AdressLabel = new System.Windows.Forms.Label();
|
||||||
|
this.AdressTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.SaveButton = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ShopNameLabel
|
||||||
|
//
|
||||||
|
this.ShopNameLabel.AutoSize = true;
|
||||||
|
this.ShopNameLabel.Location = new System.Drawing.Point(22, 20);
|
||||||
|
this.ShopNameLabel.Name = "ShopNameLabel";
|
||||||
|
this.ShopNameLabel.Size = new System.Drawing.Size(84, 20);
|
||||||
|
this.ShopNameLabel.TabIndex = 0;
|
||||||
|
this.ShopNameLabel.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// ShopNameTextBox
|
||||||
|
//
|
||||||
|
this.ShopNameTextBox.Location = new System.Drawing.Point(103, 16);
|
||||||
|
this.ShopNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ShopNameTextBox.Name = "ShopNameTextBox";
|
||||||
|
this.ShopNameTextBox.Size = new System.Drawing.Size(238, 27);
|
||||||
|
this.ShopNameTextBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// AdressLabel
|
||||||
|
//
|
||||||
|
this.AdressLabel.AutoSize = true;
|
||||||
|
this.AdressLabel.Location = new System.Drawing.Point(46, 72);
|
||||||
|
this.AdressLabel.Name = "AdressLabel";
|
||||||
|
this.AdressLabel.Size = new System.Drawing.Size(58, 20);
|
||||||
|
this.AdressLabel.TabIndex = 3;
|
||||||
|
this.AdressLabel.Text = "Адресс";
|
||||||
|
//
|
||||||
|
// AdressTextBox
|
||||||
|
//
|
||||||
|
this.AdressTextBox.Location = new System.Drawing.Point(103, 68);
|
||||||
|
this.AdressTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.AdressTextBox.Name = "AdressTextBox";
|
||||||
|
this.AdressTextBox.Size = new System.Drawing.Size(238, 27);
|
||||||
|
this.AdressTextBox.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// SaveButton
|
||||||
|
//
|
||||||
|
this.SaveButton.Location = new System.Drawing.Point(154, 120);
|
||||||
|
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SaveButton.Name = "SaveButton";
|
||||||
|
this.SaveButton.Size = new System.Drawing.Size(95, 31);
|
||||||
|
this.SaveButton.TabIndex = 5;
|
||||||
|
this.SaveButton.Text = "Сохранить";
|
||||||
|
this.SaveButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
this.ButtonCancel.Location = new System.Drawing.Point(256, 120);
|
||||||
|
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ButtonCancel.Name = "ButtonCancel";
|
||||||
|
this.ButtonCancel.Size = new System.Drawing.Size(86, 31);
|
||||||
|
this.ButtonCancel.TabIndex = 6;
|
||||||
|
this.ButtonCancel.Text = "Отмена";
|
||||||
|
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormShopCreate
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(375, 167);
|
||||||
|
this.Controls.Add(this.ButtonCancel);
|
||||||
|
this.Controls.Add(this.SaveButton);
|
||||||
|
this.Controls.Add(this.AdressTextBox);
|
||||||
|
this.Controls.Add(this.AdressLabel);
|
||||||
|
this.Controls.Add(this.ShopNameTextBox);
|
||||||
|
this.Controls.Add(this.ShopNameLabel);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormShopCreate";
|
||||||
|
this.Text = "Магазин";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label ShopNameLabel;
|
||||||
|
private TextBox ShopNameTextBox;
|
||||||
|
private Label AdressLabel;
|
||||||
|
private TextBox AdressTextBox;
|
||||||
|
private Button SaveButton;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
}
|
||||||
|
}
|
108
AutomobilePlant/AutomobilePlant/FormShopCreate.cs
Normal file
108
AutomobilePlant/AutomobilePlant/FormShopCreate.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormShopCreate : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarShopLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
|
public FormShopCreate(ILogger<FormShopCreate> logger, ICarShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShopCreate_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение магазина");
|
||||||
|
|
||||||
|
var view = _logic.ReadElement(new CarShopSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
ShopNameTextBox.Text = view.ShopName;
|
||||||
|
AdressTextBox.Text = view.Adress.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ShopNameTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(AdressTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new CarShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ShopName = ShopNameTextBox.Text,
|
||||||
|
Adress = AdressTextBox.Text,
|
||||||
|
DateOpen = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc)
|
||||||
|
};
|
||||||
|
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
|
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormShopCreate.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShopCreate.resx
Normal 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>
|
118
AutomobilePlant/AutomobilePlant/FormShopSell.Designer.cs
generated
Normal file
118
AutomobilePlant/AutomobilePlant/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormShopSell
|
||||||
|
{
|
||||||
|
/// <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.Carlabel = new System.Windows.Forms.Label();
|
||||||
|
this.Countlabel = new System.Windows.Forms.Label();
|
||||||
|
this.CarComboBox = new System.Windows.Forms.ComboBox();
|
||||||
|
this.CountnumericUpDown = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.Sellbutton = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.CountnumericUpDown)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// Carlabel
|
||||||
|
//
|
||||||
|
this.Carlabel.AutoSize = true;
|
||||||
|
this.Carlabel.Location = new System.Drawing.Point(42, 41);
|
||||||
|
this.Carlabel.Name = "Carlabel";
|
||||||
|
this.Carlabel.Size = new System.Drawing.Size(68, 20);
|
||||||
|
this.Carlabel.TabIndex = 0;
|
||||||
|
this.Carlabel.Text = "Машина";
|
||||||
|
//
|
||||||
|
// Countlabel
|
||||||
|
//
|
||||||
|
this.Countlabel.AutoSize = true;
|
||||||
|
this.Countlabel.Location = new System.Drawing.Point(42, 101);
|
||||||
|
this.Countlabel.Name = "Countlabel";
|
||||||
|
this.Countlabel.Size = new System.Drawing.Size(90, 20);
|
||||||
|
this.Countlabel.TabIndex = 1;
|
||||||
|
this.Countlabel.Text = "Количество";
|
||||||
|
//
|
||||||
|
// CarComboBox
|
||||||
|
//
|
||||||
|
this.CarComboBox.FormattingEnabled = true;
|
||||||
|
this.CarComboBox.Location = new System.Drawing.Point(161, 38);
|
||||||
|
this.CarComboBox.Name = "CarComboBox";
|
||||||
|
this.CarComboBox.Size = new System.Drawing.Size(151, 28);
|
||||||
|
this.CarComboBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// CountnumericUpDown
|
||||||
|
//
|
||||||
|
this.CountnumericUpDown.Location = new System.Drawing.Point(175, 99);
|
||||||
|
this.CountnumericUpDown.Minimum = new decimal(new int[] {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.CountnumericUpDown.Name = "CountnumericUpDown";
|
||||||
|
this.CountnumericUpDown.Size = new System.Drawing.Size(137, 27);
|
||||||
|
this.CountnumericUpDown.TabIndex = 3;
|
||||||
|
this.CountnumericUpDown.Value = new decimal(new int[] {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// Sellbutton
|
||||||
|
//
|
||||||
|
this.Sellbutton.Location = new System.Drawing.Point(123, 160);
|
||||||
|
this.Sellbutton.Name = "Sellbutton";
|
||||||
|
this.Sellbutton.Size = new System.Drawing.Size(94, 66);
|
||||||
|
this.Sellbutton.TabIndex = 4;
|
||||||
|
this.Sellbutton.Text = "Продать";
|
||||||
|
this.Sellbutton.UseVisualStyleBackColor = true;
|
||||||
|
this.Sellbutton.Click += new System.EventHandler(this.Sellbutton_Click);
|
||||||
|
//
|
||||||
|
// FormShopSell
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(362, 238);
|
||||||
|
this.Controls.Add(this.Sellbutton);
|
||||||
|
this.Controls.Add(this.CountnumericUpDown);
|
||||||
|
this.Controls.Add(this.CarComboBox);
|
||||||
|
this.Controls.Add(this.Countlabel);
|
||||||
|
this.Controls.Add(this.Carlabel);
|
||||||
|
this.Name = "FormShopSell";
|
||||||
|
this.Text = "FormShopSell";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.CountnumericUpDown)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label Carlabel;
|
||||||
|
private Label Countlabel;
|
||||||
|
private ComboBox CarComboBox;
|
||||||
|
private NumericUpDown CountnumericUpDown;
|
||||||
|
private Button Sellbutton;
|
||||||
|
}
|
||||||
|
}
|
50
AutomobilePlant/AutomobilePlant/FormShopSell.cs
Normal file
50
AutomobilePlant/AutomobilePlant/FormShopSell.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormShopSell : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarLogic _carLogic;
|
||||||
|
private readonly List<CarViewModel>? _listCars;
|
||||||
|
private readonly ICarShopStorage _carShopStorage;
|
||||||
|
public FormShopSell(ILogger<FormShopAdd> logger, ICarLogic carLogic, ICarShopStorage carShopStorage)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_carLogic = carLogic;
|
||||||
|
_logger = logger;
|
||||||
|
_carShopStorage = carShopStorage;
|
||||||
|
_listCars = carLogic.ReadList(null);
|
||||||
|
if (_listCars != null)
|
||||||
|
{
|
||||||
|
CarComboBox.DisplayMember = "CarName";
|
||||||
|
CarComboBox.ValueMember = "Id";
|
||||||
|
CarComboBox.DataSource = _listCars;
|
||||||
|
CarComboBox.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Sellbutton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var car = _carLogic.ReadElement(new CarSearchModel { Id = (int)CarComboBox.SelectedValue });
|
||||||
|
var Faith = _carShopStorage.TrySell(car, (int)CountnumericUpDown.Value);
|
||||||
|
if (Faith)
|
||||||
|
MessageBox.Show("Продажа прошла успешно");
|
||||||
|
else
|
||||||
|
MessageBox.Show("Продажа прошла неудачно");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormShopSell.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShopSell.resx
Normal 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>
|
135
AutomobilePlant/AutomobilePlant/FormShops.Designer.cs
generated
Normal file
135
AutomobilePlant/AutomobilePlant/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
namespace AutomobilePlant
|
||||||
|
{
|
||||||
|
partial class FormShops
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.AddButton = new System.Windows.Forms.Button();
|
||||||
|
this.ChangeButton = new System.Windows.Forms.Button();
|
||||||
|
this.DeleteButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpdateButton = new System.Windows.Forms.Button();
|
||||||
|
this.SeeButton = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// DataGridView
|
||||||
|
//
|
||||||
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.DataGridView.Location = new System.Drawing.Point(1, 1);
|
||||||
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DataGridView.Name = "DataGridView";
|
||||||
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
|
this.DataGridView.Size = new System.Drawing.Size(642, 660);
|
||||||
|
this.DataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// AddButton
|
||||||
|
//
|
||||||
|
this.AddButton.Location = new System.Drawing.Point(669, 16);
|
||||||
|
this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.AddButton.Name = "AddButton";
|
||||||
|
this.AddButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.AddButton.TabIndex = 1;
|
||||||
|
this.AddButton.Text = "Добавить";
|
||||||
|
this.AddButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||||
|
//
|
||||||
|
// ChangeButton
|
||||||
|
//
|
||||||
|
this.ChangeButton.Location = new System.Drawing.Point(669, 95);
|
||||||
|
this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.ChangeButton.Name = "ChangeButton";
|
||||||
|
this.ChangeButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.ChangeButton.TabIndex = 2;
|
||||||
|
this.ChangeButton.Text = "Изменить";
|
||||||
|
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||||
|
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||||
|
//
|
||||||
|
// DeleteButton
|
||||||
|
//
|
||||||
|
this.DeleteButton.Location = new System.Drawing.Point(669, 173);
|
||||||
|
this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.DeleteButton.Name = "DeleteButton";
|
||||||
|
this.DeleteButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.DeleteButton.TabIndex = 3;
|
||||||
|
this.DeleteButton.Text = "Удалить";
|
||||||
|
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
this.UpdateButton.Location = new System.Drawing.Point(669, 255);
|
||||||
|
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.UpdateButton.Name = "UpdateButton";
|
||||||
|
this.UpdateButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.UpdateButton.TabIndex = 4;
|
||||||
|
this.UpdateButton.Text = "Обновить";
|
||||||
|
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// SeeButton
|
||||||
|
//
|
||||||
|
this.SeeButton.Location = new System.Drawing.Point(669, 338);
|
||||||
|
this.SeeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.SeeButton.Name = "SeeButton";
|
||||||
|
this.SeeButton.Size = new System.Drawing.Size(137, 55);
|
||||||
|
this.SeeButton.TabIndex = 5;
|
||||||
|
this.SeeButton.Text = "Посмотреть";
|
||||||
|
this.SeeButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SeeButton.Click += new System.EventHandler(this.SeeButton_Click);
|
||||||
|
//
|
||||||
|
// FormShops
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(819, 669);
|
||||||
|
this.Controls.Add(this.SeeButton);
|
||||||
|
this.Controls.Add(this.UpdateButton);
|
||||||
|
this.Controls.Add(this.DeleteButton);
|
||||||
|
this.Controls.Add(this.ChangeButton);
|
||||||
|
this.Controls.Add(this.AddButton);
|
||||||
|
this.Controls.Add(this.DataGridView);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.Name = "FormShops";
|
||||||
|
this.Text = "Магазины";
|
||||||
|
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView DataGridView;
|
||||||
|
private Button AddButton;
|
||||||
|
private Button ChangeButton;
|
||||||
|
private Button DeleteButton;
|
||||||
|
private Button UpdateButton;
|
||||||
|
private Button SeeButton;
|
||||||
|
}
|
||||||
|
}
|
140
AutomobilePlant/AutomobilePlant/FormShops.cs
Normal file
140
AutomobilePlant/AutomobilePlant/FormShops.cs
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
|
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 AutomobilePlant
|
||||||
|
{
|
||||||
|
public partial class FormShops : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICarShopLogic _logic;
|
||||||
|
|
||||||
|
public FormShops(ILogger<FormShops> logger, ICarShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormComponents_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
DataGridView.DataSource = list;
|
||||||
|
DataGridView.Columns["Id"].Visible = false;
|
||||||
|
DataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["Adress"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DataGridView.Columns["Cars"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка магазинов");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopCar));
|
||||||
|
|
||||||
|
if (service is FormShopCar form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ChangeButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopCar));
|
||||||
|
|
||||||
|
if (service is FormShopCar form)
|
||||||
|
{
|
||||||
|
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DeleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Удаление изделия");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new CarShopBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SeeButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||||
|
|
||||||
|
if (service is FormShop form)
|
||||||
|
{
|
||||||
|
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AutomobilePlant/AutomobilePlant/FormShops.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShops.resx
Normal 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>
|
@ -1,22 +1,63 @@
|
|||||||
using System;
|
using AutomobilePlantBusinessLogic.BusinessLogics;
|
||||||
using System.Collections.Generic;
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||||
using System.Linq;
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
using System.Threading.Tasks;
|
using AutomomilePlantFileImplement.Implements;
|
||||||
using System.Windows.Forms;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace AutomobilePlant
|
namespace AutomobilePlant
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
private static ServiceProvider? _serviceProvider;
|
||||||
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Главная точка входа для приложения.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
// see https://aka.ms/applicationconfiguration.
|
||||||
Application.Run(new Form1());
|
ApplicationConfiguration.Initialize();
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
}
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
services.AddTransient<ICarStorage, CarStorage>();
|
||||||
|
services.AddTransient<ICarShopStorage, CarShopStorage>();
|
||||||
|
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
services.AddTransient<ICarLogic, CarLogic>();
|
||||||
|
services.AddTransient<ICarShopLogic, CarShopLogic>();
|
||||||
|
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormComponent>();
|
||||||
|
services.AddTransient<FormComponents>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
|
services.AddTransient<FormCar>();
|
||||||
|
services.AddTransient<FormCarComponent>();
|
||||||
|
services.AddTransient<FormCars>();
|
||||||
|
services.AddTransient<FormShops>();
|
||||||
|
services.AddTransient<FormShop>();
|
||||||
|
services.AddTransient<FormShopCar>();
|
||||||
|
services.AddTransient<FormShopAdd>();
|
||||||
|
services.AddTransient<FormShopCreate>();
|
||||||
|
services.AddTransient<FormShopSell>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Общие сведения об этой сборке предоставляются следующим набором
|
|
||||||
// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
|
|
||||||
// связанных со сборкой.
|
|
||||||
[assembly: AssemblyTitle("AutomobilePlant")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("AutomobilePlant")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
|
|
||||||
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
|
|
||||||
// COM, следует установить атрибут ComVisible в TRUE для этого типа.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
|
|
||||||
[assembly: Guid("2a499de6-b7de-4a28-9906-12fc100451f0")]
|
|
||||||
|
|
||||||
// Сведения о версии сборки состоят из указанных ниже четырех значений:
|
|
||||||
//
|
|
||||||
// Основной номер версии
|
|
||||||
// Дополнительный номер версии
|
|
||||||
// Номер сборки
|
|
||||||
// Редакция
|
|
||||||
//
|
|
||||||
// Можно задать все значения или принять номера сборки и редакции по умолчанию
|
|
||||||
// используя "*", как показано ниже:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -1,71 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// Этот код создан программным средством.
|
|
||||||
// Версия среды выполнения: 4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если
|
|
||||||
// код создан повторно.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace AutomobilePlant.Properties
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс ресурсов со строгим типом для поиска локализованных строк и пр.
|
|
||||||
/// </summary>
|
|
||||||
// Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder
|
|
||||||
// класс с помощью таких средств, как ResGen или Visual Studio.
|
|
||||||
// Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen
|
|
||||||
// с параметром /str или заново постройте свой VS-проект.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.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 ((resourceMan == null))
|
|
||||||
{
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutomobilePlant.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
// Runtime Version:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace AutomobilePlant.Properties
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
|
||||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
|
||||||
{
|
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
|
||||||
|
|
||||||
public static Settings Default
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return defaultInstance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
|
||||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
|
||||||
<Profiles>
|
|
||||||
<Profile Name="(Default)" />
|
|
||||||
</Profiles>
|
|
||||||
<Settings />
|
|
||||||
</SettingsFile>
|
|
15
AutomobilePlant/AutomobilePlant/nlog.config
Normal file
15
AutomobilePlant/AutomobilePlant/nlog.config
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?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="${basedir}/carlog-${shortdate}.log" />
|
||||||
|
</targets>
|
||||||
|
|
||||||
|
<rules>
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||||
|
</rules>
|
||||||
|
</nlog>
|
||||||
|
</configuration>
|
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractAutoContracts\AutomobilePlantContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractAutoDataModels\AutomobilePlantDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,67 @@
|
|||||||
|
using AutomomilePlantFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement
|
||||||
|
{
|
||||||
|
public class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string CarFileName = "Car.xml";
|
||||||
|
private readonly string CarShopFileName = "CarShop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Car> Cars { get; private set; }
|
||||||
|
public List<CarShop> CarShops { get; private set; }
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataFileSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
public void SaveComponents() => SaveData(Components, ComponentFileName,
|
||||||
|
"Components", x => x.GetXElement);
|
||||||
|
public void SaveCars() => SaveData(Cars, CarFileName,
|
||||||
|
"Cars", x => x.GetXElement);
|
||||||
|
public void SaveCarShops() => SaveData(CarShops, CarShopFileName,
|
||||||
|
"CarShops", x => x.GetXElement);
|
||||||
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x
|
||||||
|
=> x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Components = LoadData(ComponentFileName, "Component", x =>
|
||||||
|
Component.Create(x)!)!;
|
||||||
|
Cars = LoadData(CarFileName, "Car", x =>
|
||||||
|
Car.Create(x)!)!;
|
||||||
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
CarShops = LoadData(CarShopFileName, "CarShop", x => CarShop.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,141 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using AutomomilePlantFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class CarShopStorage : ICarShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public CarShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public CarShopViewModel? Delete(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.CarShops.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.CarShops.Remove(element);
|
||||||
|
source.SaveCarShops();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? GetElement(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.CarShops
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName ==
|
||||||
|
model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarShopViewModel> GetFilteredList(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.CarShops
|
||||||
|
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.CarShops
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? Insert(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.CarShops.Count > 0 ? source.CarShops.Max(x =>
|
||||||
|
x.Id) + 1 : 1;
|
||||||
|
var newCarShop = CarShop.Create(model);
|
||||||
|
if (newCarShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.CarShops.Add(newCarShop);
|
||||||
|
source.SaveCarShops();
|
||||||
|
return newCarShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TrySell(ICarModel car, int quantity)
|
||||||
|
{
|
||||||
|
List<CarShopViewModel> carShops = new List<CarShopViewModel>();
|
||||||
|
int fakeQuantity = quantity;
|
||||||
|
foreach (var shop in GetFullList())
|
||||||
|
{
|
||||||
|
if (shop.Cars.ContainsKey(car.Id) )
|
||||||
|
{
|
||||||
|
carShops.Add(shop);
|
||||||
|
fakeQuantity -= shop.Cars[car.Id].Item2;
|
||||||
|
if(fakeQuantity < 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fakeQuantity > 0)
|
||||||
|
return false;
|
||||||
|
foreach(var shop in carShops)
|
||||||
|
{
|
||||||
|
if(quantity-shop.Cars[car.Id].Item2 < 0)
|
||||||
|
{
|
||||||
|
shop.Cars[car.Id] = (shop.Cars[car.Id].Item1, shop.Cars[car.Id].Item2 - quantity);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
quantity -= shop.Cars[car.Id].Item2;
|
||||||
|
shop.Cars.Remove(car.Id);
|
||||||
|
}
|
||||||
|
Update(new CarShopBindingModel
|
||||||
|
{
|
||||||
|
ShopName = shop.ShopName,
|
||||||
|
Adress = shop.Adress,
|
||||||
|
DateOpen = shop.DateOpen,
|
||||||
|
Fullness = shop.Fullness,
|
||||||
|
Id = shop.Id,
|
||||||
|
Cars = shop.Cars
|
||||||
|
});
|
||||||
|
}
|
||||||
|
; return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? Update(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.CarShops.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveCarShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomomilePlantFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class CarStorage : ICarStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public CarStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public CarViewModel? Delete(CarBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Cars.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Cars.Remove(element);
|
||||||
|
source.SaveCars();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? GetElement(CarSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Cars
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.CarName) && x.CarName ==
|
||||||
|
model.CarName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarViewModel> GetFilteredList(CarSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CarName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Cars
|
||||||
|
.Where(x => x.CarName.Contains(model.CarName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Cars
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? Insert(CarBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Cars.Count > 0 ? source.Cars.Max(x =>
|
||||||
|
x.Id) + 1 : 1;
|
||||||
|
var newCar = Car.Create(model);
|
||||||
|
if (newCar == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Cars.Add(newCar);
|
||||||
|
source.SaveCars();
|
||||||
|
return newCar.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarViewModel? Update(CarBindingModel model)
|
||||||
|
{
|
||||||
|
var car = source.Cars.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (car == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
car.Update(model);
|
||||||
|
source.SaveCars();
|
||||||
|
return car.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomomilePlantFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Components
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Components
|
||||||
|
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Components
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||||
|
model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Components.Count > 0 ? source.Components.Max(x =>
|
||||||
|
x.Id) + 1 : 1;
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Components.Add(newComponent);
|
||||||
|
source.SaveComponents();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel 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 ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Components.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Components.Remove(element);
|
||||||
|
source.SaveComponents();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomomilePlantFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Orders.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Orders.Remove(element);
|
||||||
|
source.SaveOrders();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Orders
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Orders
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Orders
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 newOrder.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
100
AutomobilePlant/AutomomilePlantFileImplement/Models/Car.cs
Normal file
100
AutomobilePlant/AutomomilePlantFileImplement/Models/Car.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Car : ICarModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string CarName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, int> Components { get; private set; } = new();
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _carComponents =
|
||||||
|
null;
|
||||||
|
public Dictionary<int, (IComponentModel, int)> CarComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_carComponents == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_carComponents = Components.ToDictionary(x => x.Key, y =>
|
||||||
|
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
||||||
|
y.Value));
|
||||||
|
}
|
||||||
|
return _carComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Car? Create(CarBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Car()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
CarName = model.CarName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.CarComponents.ToDictionary(x => x.Key, x
|
||||||
|
=> x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Car? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Car()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
CarName = element.Element("CarName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Components =
|
||||||
|
element.Element("CarComponents")!.Elements("CarComponent")
|
||||||
|
.ToDictionary(x =>
|
||||||
|
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||||
|
Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(CarBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CarName = model.CarName;
|
||||||
|
Price = model.Price;
|
||||||
|
Components = model.CarComponents.ToDictionary(x => x.Key, x =>
|
||||||
|
x.Value.Item2);
|
||||||
|
_carComponents = null;
|
||||||
|
}
|
||||||
|
public CarViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
CarName = CarName,
|
||||||
|
Price = Price,
|
||||||
|
CarComponents = CarComponents
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Car",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("CarName", CarName),
|
||||||
|
new XElement("Price", Price.ToString()),
|
||||||
|
new XElement("CarComponents", Components.Select(x =>
|
||||||
|
new XElement("CarComponent",
|
||||||
|
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user