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