Ну точно точно правильная
This commit is contained in:
@@ -17,17 +17,17 @@ namespace ProjectSellPC.Forms.Receipt
|
|||||||
private readonly IUnityContainer _container;
|
private readonly IUnityContainer _container;
|
||||||
private readonly IChequeRepository _ChequeRepository;
|
private readonly IChequeRepository _ChequeRepository;
|
||||||
private readonly IClientRepository _clientRepository;
|
private readonly IClientRepository _clientRepository;
|
||||||
private readonly IProductRepository _productRepository; // Добавляем репозиторий товаров
|
private readonly IProductRepository _productRepository;
|
||||||
|
|
||||||
public ChequeForm(IUnityContainer unityContainer, IChequeRepository ChequeRepository, IClientRepository clientRepository, IProductRepository productRepository)
|
public ChequeForm(IUnityContainer unityContainer, IChequeRepository ChequeRepository, IClientRepository clientRepository, IProductRepository productRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
||||||
_ChequeRepository = ChequeRepository ?? throw new ArgumentNullException(nameof(ChequeRepository));
|
_ChequeRepository = ChequeRepository ?? throw new ArgumentNullException(nameof(ChequeRepository));
|
||||||
_clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
|
_clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
|
||||||
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository)); // Инициализация репозитория товаров
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChequeForm_Load(object sender, EventArgs e)
|
private void ChequeForm_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -39,22 +39,20 @@ namespace ProjectSellPC.Forms.Receipt
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList()
|
private void LoadList()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Получаем все чеки и удаляем дубликаты по ID
|
|
||||||
var cheques = _ChequeRepository.ReadAll()
|
var cheques = _ChequeRepository.ReadAll()
|
||||||
.GroupBy(c => c.Id)
|
.GroupBy(c => c.Id)
|
||||||
.Select(g => g.First())
|
.Select(g => g.First())
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// Загружаем информацию о клиентах
|
|
||||||
foreach (var cheque in cheques)
|
foreach (var cheque in cheques)
|
||||||
{
|
{
|
||||||
cheque.Client = _clientRepository.Read(cheque.ClientId);
|
cheque.Client = _clientRepository.Read(cheque.ClientId);
|
||||||
|
|
||||||
// Загружаем названия товаров для каждого чека
|
|
||||||
foreach (var productInCheque in cheque.Products)
|
foreach (var productInCheque in cheque.Products)
|
||||||
{
|
{
|
||||||
var product = _productRepository.Read(productInCheque.ProductID);
|
var product = _productRepository.Read(productInCheque.ProductID);
|
||||||
@@ -62,28 +60,33 @@ namespace ProjectSellPC.Forms.Receipt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Привязываем данные к DataGridView
|
// Новый формат отображения товаров и количества
|
||||||
ChequesDataGridView.DataSource = cheques.Select(c => new
|
ChequesDataGridView.DataSource = cheques.Select(c => new
|
||||||
{
|
{
|
||||||
Id = c.Id,
|
Id = c.Id,
|
||||||
ClientName = c.Client?.Name ?? "Неизвестно",
|
ClientName = c.Client?.Name ?? "Неизвестно",
|
||||||
PurchaseDate = c.PurchaseDate,
|
PurchaseDate = c.PurchaseDate,
|
||||||
Products = string.Join(", ", c.Products.Select(p => p.ProductName)), // Названия товаров через запятую
|
// Объединяем товары и их количество в одну строку с переносами
|
||||||
Quantities = string.Join(", ", c.Products.Select(p => p.Count.ToString())) // Количество товаров через запятую
|
ProductsWithQuantities = string.Join(Environment.NewLine,
|
||||||
|
c.Products.Select(p => $"{p.ProductName} - {p.Count} шт."))
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
// Настройка столбцов DataGridView
|
// Настройка столбцов DataGridView
|
||||||
ChequesDataGridView.Columns["Id"].HeaderText = "ID";
|
ChequesDataGridView.Columns["Id"].HeaderText = "ID";
|
||||||
ChequesDataGridView.Columns["ClientName"].HeaderText = "Клиент";
|
ChequesDataGridView.Columns["ClientName"].HeaderText = "Клиент";
|
||||||
ChequesDataGridView.Columns["PurchaseDate"].HeaderText = "Дата покупки";
|
ChequesDataGridView.Columns["PurchaseDate"].HeaderText = "Дата покупки";
|
||||||
ChequesDataGridView.Columns["Products"].HeaderText = "Товары";
|
ChequesDataGridView.Columns["ProductsWithQuantities"].HeaderText = "Товары (количество)";
|
||||||
ChequesDataGridView.Columns["Quantities"].HeaderText = "Количество";
|
|
||||||
|
// Настройка высоты строк для отображения многострочного текста
|
||||||
|
ChequesDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
||||||
|
ChequesDataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addButton_Click(object sender, EventArgs e)
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -97,4 +100,4 @@ namespace ProjectSellPC.Forms.Receipt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user