PIbd-24 Antonova A.A. LabWork_4 #4
@ -55,17 +55,11 @@ public class Invoice
|
||||
};
|
||||
}
|
||||
|
||||
public static Invoice CreateOperation(TempInvoiceProduct tempInvoiceProduct, IEnumerable<InvoiceProduct> products)
|
||||
public void SetInvoiceProducts(IEnumerable<InvoiceProduct> products)
|
||||
{
|
||||
return new Invoice
|
||||
if (products != null && products.Any())
|
||||
{
|
||||
ID = tempInvoiceProduct.ID,
|
||||
ClientID = tempInvoiceProduct.ClientID,
|
||||
AvailabilityOfPromotionalCode = tempInvoiceProduct.AvailabilityOfPromotionalCode,
|
||||
DiscountPercentage = tempInvoiceProduct.DiscountPercentage,
|
||||
SellingPrice = tempInvoiceProduct.SellingPrice,
|
||||
DateInvoice = tempInvoiceProduct.DateInvoice,
|
||||
Products = products
|
||||
};
|
||||
Products = products;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCompanyFurniture.Entities;
|
||||
|
||||
public class TempInvoiceProduct
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
public int ClientID { get; private set; }
|
||||
|
||||
public int AvailabilityOfPromotionalCode { get; private set; }
|
||||
|
||||
public int DiscountPercentage { get; private set; }
|
||||
|
||||
public int SellingPrice { get; private set; }
|
||||
|
||||
public DateTime DateInvoice { get; private set; }
|
||||
|
||||
public int ProductID { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
}
|
@ -91,7 +91,11 @@ namespace ProjectCompanyFurniture.Forms
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||
dataGridViewData.Columns["ID"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -70,7 +70,11 @@ namespace ProjectCompanyFurniture.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _invoiceRepository.ReadInvoices();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _invoiceRepository.ReadInvoices();
|
||||
dataGridViewData.Columns["ID"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -80,7 +80,12 @@ namespace ProjectCompanyFurniture.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _manufacturerRepository.ReadManufacturers();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _manufacturerRepository.ReadManufacturers();
|
||||
dataGridViewData.Columns["ID"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -50,7 +50,12 @@ namespace ProjectCompanyFurniture.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _productMovementRepository.ReadProductMovements();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _productMovementRepository.ReadProductMovements();
|
||||
dataGridViewData.Columns["ID"].Visible = false;
|
||||
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,13 @@ namespace ProjectCompanyFurniture.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProducts();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _productRepository.ReadProducts();
|
||||
dataGridViewData.Columns["ID"].Visible = false;
|
||||
dataGridViewData.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -86,11 +86,27 @@ public class InvoiceRepository : IInvoiceRepository
|
||||
FROM Invoices inv
|
||||
INNER JOIN InvoiceProducts ipr ON ipr.InvoiceID = inv.ID
|
||||
INNER JOIN Clients cl ON inv.ClientID = cl.ID";
|
||||
var invoices = connection.Query<TempInvoiceProduct>(querySelect);
|
||||
var productDict = new Dictionary<int, List<InvoiceProduct>>();
|
||||
var invoices = connection.Query<Invoice, InvoiceProduct, Invoice>(querySelect,
|
||||
(invoice, invoiceProducts) =>
|
||||
{
|
||||
if (!productDict.TryGetValue(invoice.ID, out var pr))
|
||||
{
|
||||
pr = [];
|
||||
productDict.Add(invoice.ID, pr);
|
||||
}
|
||||
pr.Add(invoiceProducts);
|
||||
return invoice;
|
||||
}, splitOn: "ProductID", param: new {dateForm, dateTo});
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(invoices));
|
||||
return invoices.GroupBy(x => x.ID, y => y,
|
||||
(key, value) => Invoice.CreateOperation(value.First(),
|
||||
value.Select(z => InvoiceProduct.CreateElement(0, z.ProductID, z.Count)))).ToList();
|
||||
|
||||
return productDict.Select(x =>
|
||||
{
|
||||
var pr = invoices.First(y => y.ID == x.Key);
|
||||
pr.SetInvoiceProducts(x.Value);
|
||||
return pr;
|
||||
}).ToArray();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
x
Reference in New Issue
Block a user