Последняя надежда на жизнь и стипуху)
This commit is contained in:
parent
089d3869a2
commit
3e9cc267e1
@ -1,15 +1,27 @@
|
||||
namespace Publication.Entites;
|
||||
using System.ComponentModel;
|
||||
|
||||
public class Orders
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime OrderDate { get; set; }
|
||||
|
||||
[DisplayName("Описание")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
[DisplayName("ФИО заказчика")]
|
||||
public string CustomerName { get; set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public int PublishingHouseId { get; set; }
|
||||
|
||||
|
||||
[DisplayName("Название издательства")]
|
||||
public string PublishingHouseName { get; set; } = string.Empty;
|
||||
|
||||
public static Orders CreateEntity(int id, string description, int customerId, int publishingHouseId)
|
||||
{
|
||||
|
@ -1,23 +1,36 @@
|
||||
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
||||
using System.ComponentModel;
|
||||
using Unity;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Publication.Entites;
|
||||
|
||||
public class PrintingHouses
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[DisplayName("Телефон")]
|
||||
public string Phone { get; set; }
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int MaterialsId { get; set; }
|
||||
|
||||
[DisplayName("Материалы")]
|
||||
public string MaterialName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Название")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
[Browsable (false)]
|
||||
public IEnumerable<PrintingHouseOrders> printingHouseOrder { get; set; } = [];
|
||||
|
||||
[DisplayName("Продукты")]
|
||||
[DisplayName("Заказы")]
|
||||
public string Product => printingHouseOrder != null ?
|
||||
string.Join(", ", printingHouseOrder.Select(x => $"{x} {x.Count}")) : string.Empty;
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
namespace Publication.Entites;
|
||||
using System.ComponentModel;
|
||||
|
||||
public class PublishingHouse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[DisplayName("Рабочий телефон")]
|
||||
public string WorkPhone { get; set; }
|
||||
public static PublishingHouse CreateEntity(int id, string title, string address, string workPhone)
|
||||
{
|
||||
|
@ -106,5 +106,9 @@ public partial class FormCustomers : Form
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource = customerRepository.ReadCustomers();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = customerRepository.ReadCustomers();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,11 @@ public partial class FormMaterials : Form
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource = materialRepository.ReadMaterials();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = materialRepository.ReadMaterials();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -48,5 +48,11 @@ public partial class FormOrders : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView1.DataSource = orderRepository.ReadOrders();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = orderRepository.ReadOrders();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
|
||||
//dataGridView1.Columns["DateReceipt"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
}
|
||||
}
|
||||
|
@ -87,5 +87,9 @@ public partial class FormPrintingHouses : Form
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource = printingHouseRepository.ReadPrintingHouses();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = printingHouseRepository.ReadPrintingHouses();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
}
|
||||
|
@ -107,5 +107,9 @@ public partial class FormPublishingHouses : Form
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource = publisingHouseRepository.ReadPublishingHouses();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = publisingHouseRepository.ReadPublishingHouses();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
}
|
||||
|
39
Publication/Reports/QueryBuilder.cs
Normal file
39
Publication/Reports/QueryBuilder.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Publication.Reports;
|
||||
|
||||
public class QueryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public QueryBuilder()
|
||||
{
|
||||
_builder = new();
|
||||
}
|
||||
|
||||
public QueryBuilder AddCondition(string condition)
|
||||
{
|
||||
if (_builder.Length > 0)
|
||||
{
|
||||
_builder.Append(" AND ");
|
||||
}
|
||||
|
||||
_builder.Append(condition);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Build()
|
||||
{
|
||||
if (_builder.Length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return $"WHERE {_builder}";
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ public class MaterialRepository : IMaterialRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(connectionRepository.GetConnection);
|
||||
var querySelect = "SELECT * FROM Material";
|
||||
var querySelect = @"SELECT * FROM Material";
|
||||
var materials = connection.Query<Materials>(querySelect);
|
||||
logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials));
|
||||
return materials;
|
||||
|
@ -4,6 +4,7 @@ using Npgsql;
|
||||
using Publication.Entites;
|
||||
using Dapper;
|
||||
using System.Data.SqlClient;
|
||||
using Publication.Reports;
|
||||
|
||||
namespace Publication.Repositories.Implementations;
|
||||
|
||||
@ -38,11 +39,25 @@ public class OrderRepository : IOrderRepository
|
||||
|
||||
public IEnumerable<Orders> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? customerId = null, int? publishingHouseId = null)
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("fa.FeedingDate >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("fa.FeedingDate <= @dateTo");
|
||||
}
|
||||
|
||||
logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(connectionRepository.GetConnection);
|
||||
var querySelect = "SELECT * FROM Orders";
|
||||
var querySelect = @"SELECT ord.*, cst.FullName as CustomerName, ph.Title as PublishingHouseName
|
||||
FROM Orders ord
|
||||
INNER JOIN Customer cst ON ord.CustomerId = cst.Id
|
||||
INNER JOIN PublishingHouse ph ON ord.PublishingHouseId = ph.Id
|
||||
";
|
||||
var orders = connection.Query<Orders>(querySelect);
|
||||
logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders));
|
||||
return orders;
|
||||
|
@ -76,9 +76,10 @@ public class PrintingHouseRepository : IPrintingHouseRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(connectionRepository.GetConnection);
|
||||
var querySelect = @"SELECT ph.*, pho.OrderId, pho.Count
|
||||
var querySelect = @"SELECT ph.*, pho.OrderId, pho.Count, mt.material AS MaterialName
|
||||
FROM PrintingHouses ph
|
||||
INNER JOIN PrintingHouseOrders pho ON pho.PrintingHouseId = ph.Id";
|
||||
INNER JOIN PrintingHouseOrders pho ON pho.PrintingHouseId = ph.Id
|
||||
INNER JOIN Material mt ON ph.materialsId = mt.Id";
|
||||
var printingHouses = connection.Query<TempPrintingHouseOrders>(querySelect);
|
||||
logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(printingHouses));
|
||||
return printingHouses.GroupBy(x => x.Id, y => y,
|
||||
|
Loading…
x
Reference in New Issue
Block a user