Compare commits
11 Commits
LabWork4
...
LabWork4Ha
| Author | SHA1 | Date | |
|---|---|---|---|
| 42fcf4bce6 | |||
| 6d7b87aee9 | |||
| b14c24addc | |||
| 9ab19f0bb0 | |||
| 2e0bf741a9 | |||
| ec67110d7c | |||
| ed1504beb1 | |||
| 313cd7b2c1 | |||
| 3923eacebd | |||
| 1a02b213fd | |||
| 322fd334ca |
@@ -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("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,14 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
public OrderLogic(ILogger<ComponentLogic> logger, 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)
|
||||
@@ -58,7 +62,16 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
model.Status = newStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
{
|
||||
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@ using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
@@ -15,6 +17,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
private readonly ICarStorage _carStorage;
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly ICarShopStorage _carShopStorage;
|
||||
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
|
||||
@@ -22,16 +25,27 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
|
||||
private readonly AbstractShopToExcell _saveShopToExcel;
|
||||
|
||||
private readonly AbstractShopToWord _saveShopToWord;
|
||||
|
||||
private readonly AbstractOrdersCountToPDF _saveOrdersToPdf;
|
||||
public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
|
||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf,
|
||||
ICarShopStorage carShopStorage, AbstractOrdersCountToPDF abstractOrdersCountToPDF, AbstractShopToExcell abstractShopToExcell,
|
||||
AbstractShopToWord abstractShopToWord)
|
||||
{
|
||||
_carStorage = carStorage;
|
||||
_componentStorage = componentStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_carShopStorage = carShopStorage;
|
||||
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
_saveShopToWord = abstractShopToWord;
|
||||
_saveShopToExcel = abstractShopToExcell;
|
||||
_saveOrdersToPdf = abstractOrdersCountToPDF;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -131,5 +145,75 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
Orders = GetOrders(model)
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportShopCarViewModel> GetShopCars()
|
||||
{
|
||||
var shops = _carShopStorage.GetFullList();
|
||||
|
||||
var cars = _carStorage.GetFullList();
|
||||
|
||||
var list = new List<ReportShopCarViewModel>();
|
||||
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
var record = new ReportShopCarViewModel
|
||||
{
|
||||
ShopName = shop.ShopName,
|
||||
Cars = new List<(string, int)>(),
|
||||
TotalCount = 0
|
||||
};
|
||||
foreach (var car in cars)
|
||||
{
|
||||
if (shop.Cars.ContainsKey(car.Id))
|
||||
{
|
||||
record.Cars.Add(new(car.CarName, shop.Cars[car.Id].Item2));
|
||||
record.TotalCount += shop.Cars[car.Id].Item2;
|
||||
}
|
||||
}
|
||||
|
||||
list.Add(record);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ReportAllOrdersViewModel> GetOrdersAll()
|
||||
{
|
||||
var orders = _orderStorage.GetFullList().OrderBy(x => x.DateCreate).ToList();
|
||||
var list = orders.GroupBy(x => x.DateCreate.Date)
|
||||
.Select(g => new ReportAllOrdersViewModel { DateCreate=g.Key, Count = g.Count(), Sum = g.Sum(g=>g.Sum) })
|
||||
.ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveShopToWord.CreateDoc(new ShopWordInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список магазинов",
|
||||
Shops = _carShopStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveShopCarsToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveShopToExcel.CreateReport(new ShopExcelInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список машин в магазинах",
|
||||
ShopCars = GetShopCars()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveAllOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveOrdersToPdf.CreateDoc(new ShopPdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список заказов",
|
||||
Orders = GetOrdersAll()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperEnums;
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractOrdersCountToPDF
|
||||
{
|
||||
public void CreateDoc(ShopPdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "3cm", "3cm", "3cm"});
|
||||
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Дата заказа", "Кол-во машин", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
foreach (var order in info.Orders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { order.DateCreate.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreatePdf(ShopPdfInfo info);
|
||||
|
||||
/// <summary>
|
||||
/// Создание параграфа с текстом
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="style"></param>
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
|
||||
/// <summary>
|
||||
/// Создание таблицы
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="style"></param>
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
|
||||
/// <summary>
|
||||
/// Создание и заполнение строки
|
||||
/// </summary>
|
||||
/// <param name="rowParameters"></param>
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SavePdf(ShopPdfInfo info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperEnums;
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractShopToExcell
|
||||
{
|
||||
public void CreateReport(ShopExcelInfo info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint rowIndex = 2;
|
||||
foreach (var pc in info.ShopCars)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.ShopName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
|
||||
foreach (var (Car, Count) in pc.Cars)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Car,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание excel-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreateExcel(ShopExcelInfo info);
|
||||
|
||||
/// <summary>
|
||||
/// Добавляем новую ячейку в лист
|
||||
/// </summary>
|
||||
/// <param name="cellParameters"></param>
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
|
||||
/// <summary>
|
||||
/// Объединение ячеек
|
||||
/// </summary>
|
||||
/// <param name="mergeParameters"></param>
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SaveExcel(ShopExcelInfo info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperEnums;
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractShopToWord
|
||||
{
|
||||
protected Table table;
|
||||
public void CreateDoc(ShopWordInfo info)
|
||||
{
|
||||
CreateWord(info);
|
||||
|
||||
|
||||
|
||||
foreach (var shop in info.Shops)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (shop.ShopName, new WordTextProperties { Size = "24", Bold=true,}),
|
||||
(shop.Adress, new WordTextProperties { Size = "24", Bold=false,}),
|
||||
(shop.DateOpen.ToString(), new WordTextProperties { Size = "24", Bold = false, }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreateWord(ShopWordInfo info);
|
||||
|
||||
/// <summary>
|
||||
/// Создание абзаца с текстом
|
||||
/// </summary>
|
||||
/// <param name="paragraph"></param>
|
||||
/// <returns></returns>
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SaveWord(ShopWordInfo info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ShopExcelInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<ReportShopCarViewModel> ShopCars { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ShopPdfInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<ReportAllOrdersViewModel> Orders { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ShopWordInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<CarShopViewModel> Shops { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperEnums;
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveOrderCountToPdf : AbstractOrdersCountToPDF
|
||||
{
|
||||
private Document? _document;
|
||||
|
||||
private Section? _section;
|
||||
|
||||
private Table? _table;
|
||||
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание стилей для документа
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
|
||||
protected override void CreatePdf(ShopPdfInfo info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateRow(PdfRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SavePdf(ShopPdfInfo info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperEnums;
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveShopsToExcel : AbstractShopToExcell
|
||||
{
|
||||
private SpreadsheetDocument? _spreadsheetDocument;
|
||||
|
||||
private SharedStringTablePart? _shareStringPart;
|
||||
|
||||
private Worksheet? _worksheet;
|
||||
|
||||
/// <summary>
|
||||
/// Настройка стилей для файла
|
||||
/// </summary>
|
||||
/// <param name="workbookpart"></param>
|
||||
private static void CreateStyles(WorkbookPart workbookpart)
|
||||
{
|
||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||
sp.Stylesheet = new Stylesheet();
|
||||
|
||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||
|
||||
var fontUsual = new Font();
|
||||
fontUsual.Append(new FontSize() { Val = 12D });
|
||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
var fontTitle = new Font();
|
||||
fontTitle.Append(new Bold());
|
||||
fontTitle.Append(new FontSize() { Val = 14D });
|
||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
fonts.Append(fontUsual);
|
||||
fonts.Append(fontTitle);
|
||||
|
||||
var fills = new Fills() { Count = 2U };
|
||||
|
||||
var fill1 = new Fill();
|
||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||
|
||||
var fill2 = new Fill();
|
||||
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
||||
|
||||
fills.Append(fill1);
|
||||
fills.Append(fill2);
|
||||
|
||||
var borders = new Borders() { Count = 2U };
|
||||
|
||||
var borderNoBorder = new Border();
|
||||
borderNoBorder.Append(new LeftBorder());
|
||||
borderNoBorder.Append(new RightBorder());
|
||||
borderNoBorder.Append(new TopBorder());
|
||||
borderNoBorder.Append(new BottomBorder());
|
||||
borderNoBorder.Append(new DiagonalBorder());
|
||||
|
||||
var borderThin = new Border();
|
||||
|
||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
||||
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
||||
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
borderThin.Append(leftBorder);
|
||||
borderThin.Append(rightBorder);
|
||||
borderThin.Append(topBorder);
|
||||
borderThin.Append(bottomBorder);
|
||||
borderThin.Append(new DiagonalBorder());
|
||||
|
||||
borders.Append(borderNoBorder);
|
||||
borders.Append(borderThin);
|
||||
|
||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
|
||||
|
||||
cellStyleFormats.Append(cellFormatStyle);
|
||||
|
||||
var cellFormats = new CellFormats() { Count = 3U };
|
||||
var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true };
|
||||
var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true };
|
||||
var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true };
|
||||
|
||||
cellFormats.Append(cellFormatFont);
|
||||
cellFormats.Append(cellFormatFontAndBorder);
|
||||
cellFormats.Append(cellFormatTitle);
|
||||
|
||||
var cellStyles = new CellStyles() { Count = 1U };
|
||||
|
||||
cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U });
|
||||
|
||||
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U };
|
||||
|
||||
var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };
|
||||
|
||||
var stylesheetExtensionList = new StylesheetExtensionList();
|
||||
|
||||
var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
|
||||
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||
stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" });
|
||||
|
||||
var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" };
|
||||
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||
stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" });
|
||||
|
||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||
|
||||
sp.Stylesheet.Append(fonts);
|
||||
sp.Stylesheet.Append(fills);
|
||||
sp.Stylesheet.Append(borders);
|
||||
sp.Stylesheet.Append(cellStyleFormats);
|
||||
sp.Stylesheet.Append(cellFormats);
|
||||
sp.Stylesheet.Append(cellStyles);
|
||||
sp.Stylesheet.Append(differentialFormats);
|
||||
sp.Stylesheet.Append(tableStyles);
|
||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение номера стиля из типа
|
||||
/// </summary>
|
||||
/// <param name="styleInfo"></param>
|
||||
/// <returns></returns>
|
||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||
{
|
||||
return styleInfo switch
|
||||
{
|
||||
ExcelStyleInfoType.Title => 2U,
|
||||
ExcelStyleInfoType.TextWithBroder => 1U,
|
||||
ExcelStyleInfoType.Text => 0U,
|
||||
_ => 0U,
|
||||
};
|
||||
}
|
||||
|
||||
protected override void CreateExcel(ShopExcelInfo info)
|
||||
{
|
||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
|
||||
// Создаем книгу (в ней хранятся листы)
|
||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||
workbookpart.Workbook = new Workbook();
|
||||
|
||||
CreateStyles(workbookpart);
|
||||
|
||||
// Получаем/создаем хранилище текстов для книги
|
||||
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
||||
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||
|
||||
// Создаем SharedStringTable, если его нет
|
||||
if (_shareStringPart.SharedStringTable == null)
|
||||
{
|
||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||
}
|
||||
|
||||
// Создаем лист в книгу
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||
|
||||
// Добавляем лист в книгу
|
||||
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||
var sheet = new Sheet()
|
||||
{
|
||||
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||
SheetId = 1,
|
||||
Name = "Лист"
|
||||
};
|
||||
sheets.Append(sheet);
|
||||
|
||||
_worksheet = worksheetPart.Worksheet;
|
||||
}
|
||||
|
||||
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null || _shareStringPart == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
||||
if (sheetData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ищем строку, либо добавляем ее
|
||||
Row row;
|
||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||
{
|
||||
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||
sheetData.Append(row);
|
||||
}
|
||||
|
||||
// Ищем нужную ячейку
|
||||
Cell cell;
|
||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
||||
{
|
||||
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Все ячейки должны быть последовательно друг за другом расположены
|
||||
// нужно определить, после какой вставлять
|
||||
Cell? refCell = null;
|
||||
foreach (Cell rowCell in row.Elements<Cell>())
|
||||
{
|
||||
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
|
||||
{
|
||||
refCell = rowCell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var newCell = new Cell() { CellReference = excelParams.CellReference };
|
||||
row.InsertBefore(newCell, refCell);
|
||||
|
||||
cell = newCell;
|
||||
}
|
||||
|
||||
// вставляем новый текст
|
||||
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
||||
_shareStringPart.SharedStringTable.Save();
|
||||
|
||||
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||
}
|
||||
|
||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MergeCells mergeCells;
|
||||
|
||||
if (_worksheet.Elements<MergeCells>().Any())
|
||||
{
|
||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||
}
|
||||
else
|
||||
{
|
||||
mergeCells = new MergeCells();
|
||||
|
||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
|
||||
}
|
||||
else
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
|
||||
}
|
||||
}
|
||||
|
||||
var mergeCell = new MergeCell()
|
||||
{
|
||||
Reference = new StringValue(excelParams.Merge)
|
||||
};
|
||||
mergeCells.Append(mergeCell);
|
||||
}
|
||||
|
||||
protected override void SaveExcel(ShopExcelInfo info)
|
||||
{
|
||||
if (_spreadsheetDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||
_spreadsheetDocument.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperEnums;
|
||||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using DocumentFormat.OpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveShopsToWord : AbstractShopToWord
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
|
||||
private Body? _docBody;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение типа выравнивания
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Настройки страницы
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
|
||||
properties.AppendChild(pageSize);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Задание форматирования для абзаца
|
||||
/// </summary>
|
||||
/// <param name="paragraphProperties"></param>
|
||||
/// <returns></returns>
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var properties = new ParagraphProperties();
|
||||
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
|
||||
properties.AppendChild(new Indentation());
|
||||
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected override void CreateWord(ShopWordInfo info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
CreateTable(info.Title);
|
||||
|
||||
}
|
||||
private void CreateTable(string Title)
|
||||
{
|
||||
table = new Table();
|
||||
TableProperties tblProp = new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 24 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 24 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 24 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 24 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 24 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 24 }
|
||||
)
|
||||
);
|
||||
table.AppendChild<TableProperties>(tblProp);
|
||||
TableRow tr = new TableRow();
|
||||
TableCell tc1 = new TableCell();
|
||||
tc1.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));
|
||||
tc1.Append(new Paragraph(new Run(new Text("Название"))));
|
||||
tr.Append(tc1);
|
||||
TableCell tc2 = new TableCell();
|
||||
tc2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));
|
||||
tc2.Append(new Paragraph(new Run(new Text("Адрес"))));
|
||||
tr.Append(tc2);
|
||||
TableCell tc3 = new TableCell();
|
||||
tc3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));
|
||||
tc3.Append(new Paragraph(new Run(new Text("Дата открытия"))));
|
||||
tr.Append(tc3);
|
||||
table.Append(tr);
|
||||
}
|
||||
private void CreateRow(List<Run> paragraphs)
|
||||
{
|
||||
TableRow tr = new TableRow();
|
||||
foreach (var paragraph in paragraphs)
|
||||
{
|
||||
TableCell tc = new TableCell();
|
||||
tc.Append(new Paragraph (paragraph));
|
||||
tc.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));
|
||||
tr.Append(tc);
|
||||
}
|
||||
table.Append(tr);
|
||||
}
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
List<Run> paragraphs = new List<Run>();
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
|
||||
paragraphs.Add(docRun);
|
||||
}
|
||||
CreateRow(paragraphs);
|
||||
}
|
||||
|
||||
protected override void SaveWord(ShopWordInfo info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_wordDocument.MainDocumentPart!.Document.Append(table);
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
|
||||
|
||||
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
|
||||
_wordDocument.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,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);
|
||||
}
|
||||
}
|
||||
@@ -40,5 +40,15 @@ namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
List<ReportShopCarViewModel> GetShopCars();
|
||||
List<ReportAllOrdersViewModel> GetOrdersAll();
|
||||
void SaveShopsToWordFile(ReportBindingModel model);
|
||||
|
||||
|
||||
void SaveShopCarsToExcelFile(ReportBindingModel model);
|
||||
|
||||
|
||||
void SaveAllOrdersToPdfFile(ReportBindingModel 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 CarShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ShopName { 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,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,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantContracts.ViewModel
|
||||
{
|
||||
public class ReportAllOrdersViewModel
|
||||
{
|
||||
public double Sum { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public int Count { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantContracts.ViewModel
|
||||
{
|
||||
public class ReportShopCarViewModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
public List<(string Car, int Count)> Cars { get; set; } = new();
|
||||
}
|
||||
}
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,13 @@ namespace AutomobilePlantListImplement
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -37,4 +37,13 @@
|
||||
<ProjectReference Include="..\AutomobilePlantDataBaseImplements\AutomobilePlantDataBaseImplements.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="FormReportOrdersCount.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Update="FormReportShopCars.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
80
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
80
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
@@ -32,16 +32,23 @@
|
||||
this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.componentCarsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.отчетыПоМагазинамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.содержимоеМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.всеЗаказыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.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();
|
||||
@@ -51,7 +58,8 @@
|
||||
this.MenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.СправочникиToolStripMenuItem,
|
||||
this.отчетыToolStripMenuItem});
|
||||
this.отчетыToolStripMenuItem,
|
||||
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);
|
||||
@@ -63,7 +71,8 @@
|
||||
//
|
||||
this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ИзделияToolStripMenuItem,
|
||||
this.КомпонентыToolStripMenuItem});
|
||||
this.КомпонентыToolStripMenuItem,
|
||||
this.магазиныToolStripMenuItem});
|
||||
this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
|
||||
this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
|
||||
this.СправочникиToolStripMenuItem.Text = "Cправочники";
|
||||
@@ -82,6 +91,13 @@
|
||||
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.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@@ -113,6 +129,37 @@
|
||||
this.ordersToolStripMenuItem.Text = "Список заказов";
|
||||
this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
|
||||
//
|
||||
// отчетыПоМагазинам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(176, 24);
|
||||
this.отчетыПоМагазинамToolStripMenuItem.Text = "Отчеты по магазинам";
|
||||
//
|
||||
// списокМагазиновToolStripMenuItem
|
||||
//
|
||||
this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem";
|
||||
this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(262, 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(262, 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(262, 26);
|
||||
this.всеЗаказыToolStripMenuItem.Text = "Все заказы";
|
||||
this.всеЗаказыToolStripMenuItem.Click += new System.EventHandler(this.всеЗаказыToolStripMenuItem_Click);
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
@@ -179,11 +226,33 @@
|
||||
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);
|
||||
@@ -221,5 +290,12 @@
|
||||
private ToolStripMenuItem componentCarsToolStripMenuItem;
|
||||
private ToolStripMenuItem ordersToolStripMenuItem;
|
||||
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button AddShopCarButton;
|
||||
private Button Sellbutton;
|
||||
private ToolStripMenuItem отчетыПоМагазинамToolStripMenuItem;
|
||||
private ToolStripMenuItem списокМагазиновToolStripMenuItem;
|
||||
private ToolStripMenuItem содержимоеМагазиновToolStripMenuItem;
|
||||
private ToolStripMenuItem всеЗаказыToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
@@ -227,5 +227,65 @@ namespace AutomobilePlant
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void содержимоеМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopCars));
|
||||
if (service is FormReportShopCars form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void всеЗаказыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrdersCount));
|
||||
if (service is FormReportOrdersCount form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
75
AutomobilePlant/AutomobilePlant/FormReportOrdersCount.cs
Normal file
75
AutomobilePlant/AutomobilePlant/FormReportOrdersCount.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
|
||||
namespace AbstractShopView
|
||||
{
|
||||
public partial class FormReportOrdersCount : Form
|
||||
{
|
||||
private readonly ReportViewer reportViewer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IReportLogic _logic;
|
||||
|
||||
public FormReportOrdersCount(ILogger<FormReportOrders> logger, IReportLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
reportViewer = new ReportViewer
|
||||
{
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrderCount.rdlc", FileMode.Open));
|
||||
Controls.Clear();
|
||||
Controls.Add(reportViewer);
|
||||
Controls.Add(panel);
|
||||
}
|
||||
|
||||
private void ButtonMake_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
try
|
||||
{
|
||||
var dataSource = _logic.GetOrdersAll();
|
||||
var source = new ReportDataSource("DataSetAllOrders", dataSource);
|
||||
reportViewer.LocalReport.DataSources.Clear();
|
||||
reportViewer.LocalReport.DataSources.Add(source);
|
||||
|
||||
reportViewer.RefreshReport();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonToPdf_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveAllOrdersToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName,
|
||||
|
||||
});
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
92
AutomobilePlant/AutomobilePlant/FormReportOrdersCount.designer.cs
generated
Normal file
92
AutomobilePlant/AutomobilePlant/FormReportOrdersCount.designer.cs
generated
Normal file
@@ -0,0 +1,92 @@
|
||||
namespace AbstractShopView
|
||||
{
|
||||
partial class FormReportOrdersCount
|
||||
{
|
||||
/// <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.panel = new System.Windows.Forms.Panel();
|
||||
this.buttonToPdf = new System.Windows.Forms.Button();
|
||||
this.buttonMake = new System.Windows.Forms.Button();
|
||||
this.panel.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
this.panel.Controls.Add(this.buttonToPdf);
|
||||
this.panel.Controls.Add(this.buttonMake);
|
||||
this.panel.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
|
||||
this.panel.Name = "panel";
|
||||
this.panel.Size = new System.Drawing.Size(1178, 53);
|
||||
this.panel.TabIndex = 0;
|
||||
//
|
||||
// buttonToPdf
|
||||
//
|
||||
this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonToPdf.Location = new System.Drawing.Point(1003, 11);
|
||||
this.buttonToPdf.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
|
||||
this.buttonToPdf.Name = "buttonToPdf";
|
||||
this.buttonToPdf.Size = new System.Drawing.Size(159, 36);
|
||||
this.buttonToPdf.TabIndex = 5;
|
||||
this.buttonToPdf.Text = "В Pdf";
|
||||
this.buttonToPdf.UseVisualStyleBackColor = true;
|
||||
this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click);
|
||||
//
|
||||
// buttonMake
|
||||
//
|
||||
this.buttonMake.Location = new System.Drawing.Point(14, 11);
|
||||
this.buttonMake.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
|
||||
this.buttonMake.Name = "buttonMake";
|
||||
this.buttonMake.Size = new System.Drawing.Size(159, 36);
|
||||
this.buttonMake.TabIndex = 4;
|
||||
this.buttonMake.Text = "Сформировать";
|
||||
this.buttonMake.UseVisualStyleBackColor = true;
|
||||
this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click);
|
||||
//
|
||||
// FormReportOrdersCount
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1178, 863);
|
||||
this.Controls.Add(this.panel);
|
||||
this.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
|
||||
this.Name = "FormReportOrdersCount";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Заказы";
|
||||
this.panel.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Panel panel;
|
||||
private System.Windows.Forms.Button buttonToPdf;
|
||||
private System.Windows.Forms.Button buttonMake;
|
||||
}
|
||||
}
|
||||
60
AutomobilePlant/AutomobilePlant/FormReportOrdersCount.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormReportOrdersCount.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>
|
||||
122
AutomobilePlant/AutomobilePlant/FormReportShopCars.Designer.cs
generated
Normal file
122
AutomobilePlant/AutomobilePlant/FormReportShopCars.Designer.cs
generated
Normal file
@@ -0,0 +1,122 @@
|
||||
namespace AutomobilePlant
|
||||
{
|
||||
partial class FormReportShopCars
|
||||
{
|
||||
/// <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.buttonSaveToExcel = new System.Windows.Forms.Button();
|
||||
this.ColumnCar = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.AllowUserToAddRows = false;
|
||||
this.dataGridView.AllowUserToDeleteRows = false;
|
||||
this.dataGridView.AllowUserToOrderColumns = true;
|
||||
this.dataGridView.AllowUserToResizeColumns = false;
|
||||
this.dataGridView.AllowUserToResizeRows = false;
|
||||
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.ColumnCar,
|
||||
this.ColumnComponent,
|
||||
this.ColumnCount});
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 63);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.dataGridView.MultiSelect = false;
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.ReadOnly = true;
|
||||
this.dataGridView.RowHeadersVisible = false;
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.Size = new System.Drawing.Size(704, 680);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonSaveToExcel
|
||||
//
|
||||
this.buttonSaveToExcel.Location = new System.Drawing.Point(16, 18);
|
||||
this.buttonSaveToExcel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonSaveToExcel.Name = "buttonSaveToExcel";
|
||||
this.buttonSaveToExcel.Size = new System.Drawing.Size(212, 35);
|
||||
this.buttonSaveToExcel.TabIndex = 1;
|
||||
this.buttonSaveToExcel.Text = "Сохранить в Excel";
|
||||
this.buttonSaveToExcel.UseVisualStyleBackColor = true;
|
||||
this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click);
|
||||
//
|
||||
// ColumnCar
|
||||
//
|
||||
this.ColumnCar.HeaderText = "Машина";
|
||||
this.ColumnCar.MinimumWidth = 6;
|
||||
this.ColumnCar.Name = "ColumnCar";
|
||||
this.ColumnCar.ReadOnly = true;
|
||||
this.ColumnCar.Width = 200;
|
||||
//
|
||||
// ColumnComponent
|
||||
//
|
||||
this.ColumnComponent.HeaderText = "Детали";
|
||||
this.ColumnComponent.MinimumWidth = 6;
|
||||
this.ColumnComponent.Name = "ColumnComponent";
|
||||
this.ColumnComponent.ReadOnly = true;
|
||||
this.ColumnComponent.Width = 200;
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
this.ColumnCount.HeaderText = "Количество";
|
||||
this.ColumnCount.MinimumWidth = 6;
|
||||
this.ColumnCount.Name = "ColumnCount";
|
||||
this.ColumnCount.ReadOnly = true;
|
||||
this.ColumnCount.Width = 125;
|
||||
//
|
||||
// FormReportCarComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(704, 743);
|
||||
this.Controls.Add(this.buttonSaveToExcel);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.Name = "FormReportCarComponents";
|
||||
this.Text = "Компоненты по машинам";
|
||||
this.Load += new System.EventHandler(this.FormReportCarComponents_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView dataGridView;
|
||||
private System.Windows.Forms.Button buttonSaveToExcel;
|
||||
private DataGridViewTextBoxColumn ColumnCar;
|
||||
private DataGridViewTextBoxColumn ColumnComponent;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
}
|
||||
}
|
||||
79
AutomobilePlant/AutomobilePlant/FormReportShopCars.cs
Normal file
79
AutomobilePlant/AutomobilePlant/FormReportShopCars.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
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 FormReportShopCars : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IReportLogic _logic;
|
||||
|
||||
public FormReportShopCars(ILogger<FormReportShopCars> logger, IReportLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormReportCarComponents_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dict = _logic.GetShopCars();
|
||||
if (dict != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var elem in dict)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" });
|
||||
foreach (var listElem in elem.Cars)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
|
||||
}
|
||||
dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
|
||||
dataGridView.Rows.Add(Array.Empty<object>());
|
||||
}
|
||||
}
|
||||
_logger.LogInformation("Загрузка списка машин по компонентам");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка машин по компонентам");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSaveToExcel_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveShopCarsToExcelFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName
|
||||
});
|
||||
_logger.LogInformation("Сохранение списка машин по компонентам");
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка машин по компонентам");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
AutomobilePlant/AutomobilePlant/FormReportShopCars.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormReportShopCars.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>
|
||||
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 = DateTime.SpecifyKind(DateOpenPicker.Value, DateTimeKind.Utc) ,
|
||||
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;
|
||||
}
|
||||
}
|
||||
56
AutomobilePlant/AutomobilePlant/FormShopSell.cs
Normal file
56
AutomobilePlant/AutomobilePlant/FormShopSell.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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 });
|
||||
bool Faith = _carShopStorage.TrySell(car, (int)CountnumericUpDown.Value);
|
||||
if(Faith)
|
||||
MessageBox.Show("Все ок!");
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Ууууу, шо-то ты перестарался");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
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>
|
||||
@@ -40,6 +40,7 @@ namespace AutomobilePlant
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ICarStorage, CarStorage>();
|
||||
services.AddTransient<ICarShopStorage, CarShopStorage>();
|
||||
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
@@ -49,6 +50,11 @@ namespace AutomobilePlant
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddTransient<AbstractShopToWord, SaveShopsToWord>();
|
||||
services.AddTransient<AbstractOrdersCountToPDF, SaveOrderCountToPdf>();
|
||||
services.AddTransient<AbstractShopToExcell, SaveShopsToExcel>();
|
||||
|
||||
services.AddTransient<ICarShopLogic, CarShopLogic>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
@@ -57,8 +63,16 @@ namespace AutomobilePlant
|
||||
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>();
|
||||
services.AddTransient<FormReportCarComponents>();
|
||||
services.AddTransient<FormReportShopCars>();
|
||||
services.AddTransient<FormReportOrders>();
|
||||
services.AddTransient<FormReportOrdersCount>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace AutomobilePlantDataBaseImplements
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Server=PostgreSQL;Host=localhost;Port=5432;Database=AutoPlantDataBase;Username=postgres;Password=postgres");
|
||||
optionsBuilder.UseNpgsql("Server=PostgreSQL;Host=localhost;Port=5432;Database=AutoPlantDataBaseHard;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
@@ -27,5 +27,7 @@ namespace AutomobilePlantDataBaseImplements
|
||||
public virtual DbSet<CarComponent> CarComponents { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<CarShop> CarShops { set; get; }
|
||||
public virtual DbSet<ShopCar> ShopCars { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataBaseImplements.Models;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Implements
|
||||
{
|
||||
public class CarShopStorage : ICarShopStorage
|
||||
{
|
||||
public CarShopViewModel? Delete(CarShopBindingModel model)
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
var element = context.CarShops
|
||||
.Include(x => x.ShopCars)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.CarShops.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CarShopViewModel? GetElement(CarShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AutoPlantDataBase();
|
||||
return context.CarShops
|
||||
.Include(x => x.ShopCars)
|
||||
.ThenInclude(x => x.Car)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName.Contains(model.ShopName)) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CarShopViewModel> GetFilteredList(CarShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AutoPlantDataBase();
|
||||
return context.CarShops
|
||||
.Include(x => x.ShopCars)
|
||||
.ThenInclude(x => x.Car)
|
||||
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CarShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
return context.CarShops
|
||||
.Include(x => x.ShopCars)
|
||||
.ThenInclude(x => x.Car)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CarShopViewModel? Insert(CarShopBindingModel model)
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
var newShop = CarShop.Create(context, model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.CarShops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool TrySell(ICarModel car, int quantity)
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
var shops = GetFullList();
|
||||
bool check = false;
|
||||
try
|
||||
{
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
if (shop.Cars.ContainsKey(car.Id))
|
||||
{
|
||||
if (shop.Cars[car.Id].Item2 > quantity)
|
||||
{
|
||||
shop.Cars[car.Id] = (shop.Cars[car.Id].Item1, shop.Cars[car.Id].Item2 - quantity);
|
||||
quantity = 0;
|
||||
check = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
quantity -= shop.Cars[car.Id].Item2;
|
||||
shop.Cars.Remove(car.Id);
|
||||
|
||||
}
|
||||
var shopFromDB = context.CarShops.FirstOrDefault(rec => rec.Id == shop.Id);
|
||||
shopFromDB.UpdateCars(context, new CarShopBindingModel
|
||||
{
|
||||
ShopName = shop.ShopName,
|
||||
Adress = shop.Adress,
|
||||
DateOpen = shop.DateOpen,
|
||||
Fullness = shop.Fullness,
|
||||
Id = shop.Id,
|
||||
Cars = shop.Cars,
|
||||
});
|
||||
if (check)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if (quantity == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public CarShopViewModel? Update(CarShopBindingModel model)
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var shop = context.CarShops.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
shop.UpdateCars(context, model);
|
||||
transaction.Commit();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
254
AutomobilePlant/AutomobilePlantDataBaseImplements/Migrations/20230502080521_Shops.Designer.cs
generated
Normal file
254
AutomobilePlant/AutomobilePlantDataBaseImplements/Migrations/20230502080521_Shops.Designer.cs
generated
Normal file
@@ -0,0 +1,254 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AutomobilePlantDataBaseImplements;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoPlantDataBase))]
|
||||
[Migration("20230502080521_Shops")]
|
||||
partial class Shops
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CarName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("CarComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarShop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Adress")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Fullness")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("CarShops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CarName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.ShopCar", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarComponent", b =>
|
||||
{
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.Car", "Car")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.Component", "Component")
|
||||
.WithMany("CarComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.Car", "car")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("car");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.ShopCar", b =>
|
||||
{
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.Car", "Car")
|
||||
.WithMany("ShopCars")
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.CarShop", "CarShop")
|
||||
.WithMany("ShopCars")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("CarShop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Car", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("ShopCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarShop", b =>
|
||||
{
|
||||
b.Navigation("ShopCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("CarComponents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Shops : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CarShops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ShopName = table.Column<string>(type: "text", nullable: false),
|
||||
Adress = table.Column<string>(type: "text", nullable: false),
|
||||
DateOpen = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
Fullness = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CarShops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopCars",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ShopId = table.Column<int>(type: "integer", nullable: false),
|
||||
CarId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopCars", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopCars_CarShops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "CarShops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopCars_Cars_CarId",
|
||||
column: x => x.CarId,
|
||||
principalTable: "Cars",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopCars_CarId",
|
||||
table: "ShopCars",
|
||||
column: "CarId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopCars_ShopId",
|
||||
table: "ShopCars",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopCars");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "CarShops");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,33 @@ namespace AutomobilePlantDataBaseImplements.Migrations
|
||||
b.ToTable("CarComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarShop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Adress")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Fullness")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("CarShops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -125,6 +152,32 @@ namespace AutomobilePlantDataBaseImplements.Migrations
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.ShopCar", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarComponent", b =>
|
||||
{
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.Car", "Car")
|
||||
@@ -155,11 +208,37 @@ namespace AutomobilePlantDataBaseImplements.Migrations
|
||||
b.Navigation("car");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.ShopCar", b =>
|
||||
{
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.Car", "Car")
|
||||
.WithMany("ShopCars")
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutomobilePlantDataBaseImplements.Models.CarShop", "CarShop")
|
||||
.WithMany("ShopCars")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("CarShop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Car", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("ShopCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.CarShop", b =>
|
||||
{
|
||||
b.Navigation("ShopCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutomobilePlantDataBaseImplements.Models.Component", b =>
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace AutomobilePlantDataBaseImplements.Models
|
||||
|
||||
[ForeignKey("CarId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
[ForeignKey("CarId")]
|
||||
public virtual List<ShopCar> ShopCars { get; set; } = new();
|
||||
|
||||
public static Car Create(AutoPlantDataBase context, CarBindingModel model)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Models
|
||||
{
|
||||
public class CarShop : ICarShop
|
||||
{
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Adress { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime DateOpen { get; set; }
|
||||
[Required]
|
||||
public int Fullness { get; set; }
|
||||
public Dictionary<int, (ICarModel, int)> _ShopCars = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ICarModel, int)> Cars
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ShopCars == null)
|
||||
{
|
||||
_ShopCars = ShopCars
|
||||
.ToDictionary(recPC => recPC.CarId, recPC => (recPC.Car as ICarModel, recPC.Count));
|
||||
}
|
||||
return _ShopCars;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("ShopId")]
|
||||
public virtual List<ShopCar> ShopCars { get; set; } = new();
|
||||
public static CarShop Create(AutoPlantDataBase context, CarShopBindingModel model)
|
||||
{
|
||||
return new CarShop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Adress = model.Adress,
|
||||
DateOpen = model.DateOpen,
|
||||
Fullness = model.Fullness,
|
||||
ShopCars = model.Cars.Select(x => new ShopCar
|
||||
{
|
||||
Car = context.Cars.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CarShopBindingModel model)
|
||||
{
|
||||
ShopName = model.ShopName;
|
||||
Adress = model.Adress;
|
||||
Fullness = model.Fullness;
|
||||
|
||||
}
|
||||
|
||||
public CarShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Adress = Adress,
|
||||
DateOpen = DateOpen,
|
||||
Fullness = Fullness,
|
||||
Cars = Cars
|
||||
};
|
||||
|
||||
public void UpdateCars(AutoPlantDataBase context, CarShopBindingModel model)
|
||||
{
|
||||
var shopCars = context.ShopCars.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (shopCars != null && shopCars.Count > 0)
|
||||
{
|
||||
context.ShopCars.RemoveRange(shopCars.Where(rec => !model.Cars.ContainsKey(rec.CarId)));
|
||||
context.SaveChanges();
|
||||
shopCars = context.ShopCars.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
foreach (var updateCar in shopCars)
|
||||
{
|
||||
updateCar.Count = model.Cars[updateCar.CarId].Item2;
|
||||
model.Cars.Remove(updateCar.CarId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
var shop = context.CarShops.First(x => x.Id == Id);
|
||||
foreach (var pc in model.Cars)
|
||||
{
|
||||
context.ShopCars.Add(new ShopCar
|
||||
{
|
||||
CarShop = shop,
|
||||
Car = context.Cars.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_ShopCars = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Models
|
||||
{
|
||||
public class ShopCar
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CarId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual CarShop CarShop { get; set; } = new();
|
||||
|
||||
public virtual Car Car { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,11 @@ namespace AutomomilePlantFileImplement
|
||||
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)
|
||||
@@ -29,6 +31,8 @@ namespace AutomomilePlantFileImplement
|
||||
"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()
|
||||
@@ -38,6 +42,7 @@ namespace AutomomilePlantFileImplement
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs
Normal file
117
AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomomilePlantFileImplement.Models
|
||||
{
|
||||
public class CarShop : ICarShop
|
||||
|
||||
{
|
||||
public string ShopName {get; set;} = String.Empty;
|
||||
|
||||
public string Adress { get; set; } = String.Empty;
|
||||
|
||||
public DateTime DateOpen { get; set; }
|
||||
|
||||
public int Fullness { get; set; }
|
||||
|
||||
public Dictionary<int, int> ShopCars { get; set; } = new();
|
||||
private Dictionary<int, (ICarModel, int)> _cars = null;
|
||||
|
||||
public int Id { get; set; }
|
||||
public Dictionary<int, (ICarModel, int)> Cars
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cars == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_cars = ShopCars.ToDictionary(x => x.Key, y =>
|
||||
((source.Cars.FirstOrDefault(z => z.Id == y.Key) as ICarModel)!,
|
||||
y.Value));
|
||||
}
|
||||
return _cars;
|
||||
}
|
||||
}
|
||||
public static CarShop? Create(CarShopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new CarShop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Fullness = model.Fullness,
|
||||
Adress = model.Adress,
|
||||
DateOpen = model.DateOpen,
|
||||
ShopCars = model.Cars.ToDictionary(x => x.Key, x
|
||||
=> x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static CarShop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new CarShop()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ShopName = element.Element("ShopName")!.Value,
|
||||
Adress = element.Element("Adress")!.Value,
|
||||
DateOpen = DateTime.Parse(element.Element("DateOpen")!.Value),
|
||||
Fullness = Convert.ToInt32(element.Element("Fullness")!.Value),
|
||||
ShopCars =
|
||||
element.Element("Cars")!.Elements("ShopCar")
|
||||
.ToDictionary(x =>
|
||||
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||
Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(CarShopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Adress = model.Adress;
|
||||
Fullness = model.Fullness;
|
||||
ShopCars = model.Cars.ToDictionary(x => x.Key, x =>
|
||||
x.Value.Item2);
|
||||
_cars = null;
|
||||
}
|
||||
public CarShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Adress = Adress,
|
||||
DateOpen = DateOpen,
|
||||
Fullness = Fullness,
|
||||
Cars = Cars
|
||||
};
|
||||
public XElement GetXElement => new("CarShop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Adress", Adress),
|
||||
new XElement("DateOpen", DateOpen.ToString()),
|
||||
new XElement("Fullness", Fullness.ToString()),
|
||||
new XElement("Cars", ShopCars.Select(x =>
|
||||
new XElement("ShopCar",
|
||||
|
||||
new XElement("Key", x.Key),
|
||||
|
||||
new XElement("Value", x.Value)))
|
||||
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user