ПИбд-22 Морозов Д.В. Лабораторная 4 #9
@ -1,6 +1,7 @@
|
||||
using ProjectRepairCompany.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,9 +11,17 @@ namespace ProjectRepairCompany.Entities;
|
||||
public class Detail
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название детали")]
|
||||
public string NameDetail { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество деталей")]
|
||||
public int NumberDetail { get; private set; }
|
||||
|
||||
[DisplayName("Стоимость детали")]
|
||||
public double PriceDetail { get; private set; }
|
||||
|
||||
[DisplayName("Свойства детали")]
|
||||
public DetailProperties DetailProperties { get; private set; }
|
||||
|
||||
public static Detail CreateEntity(int id, string nameDetail, int numberDetail, double priceDetail, DetailProperties detailProperties)
|
||||
|
@ -1,17 +1,19 @@
|
||||
using ProjectRepairCompany.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectRepairCompany.Entities;
|
||||
|
||||
public class Master
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("ФИО работника")]
|
||||
public string MasterName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата начала работы")]
|
||||
public DateTime StartDate { get; private set; }
|
||||
|
||||
[DisplayName("Должность")]
|
||||
public MasterPost MasterPost { get; private set; }
|
||||
|
||||
public static Master CreateEntity(int id, string masterName, DateTime startDate, MasterPost masterPost)
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,13 +9,34 @@ namespace ProjectRepairCompany.Entities;
|
||||
|
||||
public class Order
|
||||
{
|
||||
[DisplayName("Номер заказа")]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Дата заказа")]
|
||||
public DateTime OrderDate { get; private set; }
|
||||
|
||||
[DisplayName("Дата начала выполнения ремонта")]
|
||||
public DateTime DateCompletion { get; private set; }
|
||||
|
||||
[DisplayName("Дата выполнения заказа")]
|
||||
public DateTime DateIssue { get; private set; }
|
||||
|
||||
[DisplayName("Стоимость заказа")]
|
||||
public int FullPrice { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int MasterId { get; private set; }
|
||||
public IEnumerable<OrderDetail> OrderDetails { get; private set; } = [];
|
||||
|
||||
[DisplayName("Работник")]
|
||||
public string MasterName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Детали и кол-во")]
|
||||
public string OrderAndDetail => OrderDetails != null && OrderDetails.Any()
|
||||
? string.Join(", ", OrderDetails.Select(od => $"{od.DetailName}: {od.DetailCount}"))
|
||||
: "Нет данных";
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<OrderDetail> OrderDetails { get; set; } = [];
|
||||
|
||||
public static Order CreateOperation(int id, int fullPrice, int masterId, DateTime dateCompletion,
|
||||
DateTime dateIssue, IEnumerable<OrderDetail> orderDetails)
|
||||
@ -30,18 +52,14 @@ public class Order
|
||||
OrderDetails = orderDetails
|
||||
};
|
||||
}
|
||||
public static Order CreateOperation(TempOrderDetail tempOrderDetail, IEnumerable<OrderDetail> orderDetails)
|
||||
|
||||
public void SetOrderDetails(IEnumerable<OrderDetail> orderDetails)
|
||||
{
|
||||
return new Order
|
||||
if (orderDetails != null && orderDetails.Any())
|
||||
{
|
||||
Id = tempOrderDetail.Id,
|
||||
OrderDate = tempOrderDetail.OrderDate,
|
||||
DateCompletion = tempOrderDetail.DateCompletion,
|
||||
DateIssue = tempOrderDetail.DateIssue,
|
||||
FullPrice = tempOrderDetail.FullPrice,
|
||||
MasterId = tempOrderDetail.MasterId,
|
||||
OrderDetails = orderDetails
|
||||
};
|
||||
OrderDetails = orderDetails;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairCompany.Entities;
|
||||
namespace ProjectRepairCompany.Entities;
|
||||
|
||||
public class OrderDetail
|
||||
{
|
||||
public int OrderId { get; private set; }
|
||||
public int DetailId { get; private set; }
|
||||
public int DetailCount { get; private set; }
|
||||
public string DetailName { get; private set; } = string.Empty;
|
||||
|
||||
public static OrderDetail CreateOperation(int orderId, int detailId, int detailCount)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,7 +10,11 @@ namespace ProjectRepairCompany.Entities;
|
||||
public class Storage
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName ("Адрес склада")]
|
||||
public string StorageAddress { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Вместимость склада")]
|
||||
public int Capacity { get; private set; }
|
||||
|
||||
public static Storage CreateEntity(int id, string storageAddress, int capacity)
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,11 +9,23 @@ namespace ProjectRepairCompany.Entities;
|
||||
|
||||
public class StorageDetail
|
||||
{
|
||||
[Browsable(false)]
|
||||
public int StorageId { get; private set; }
|
||||
[Browsable(false)]
|
||||
public int DetailId { get; private set; }
|
||||
|
||||
[DisplayName("Количество деталей")]
|
||||
public int DetailCount { get; private set; }
|
||||
|
||||
[DisplayName("Дата поступления")]
|
||||
public DateTime SupplyDate { get; private set; } // Дата поступления деталей
|
||||
|
||||
[DisplayName("Адрес склада")]
|
||||
public string StorageAddress { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Название детали")]
|
||||
public string DetailName { get; private set; } = string.Empty;
|
||||
|
||||
public static StorageDetail CreateOperation(int storageId, int detailId, int detailCount, DateTime supplyDate)
|
||||
{
|
||||
return new StorageDetail
|
||||
|
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairCompany.Entities;
|
||||
|
||||
public class TempOrderDetail
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public DateTime OrderDate { get; private set; }
|
||||
public DateTime DateCompletion { get; private set; }
|
||||
public DateTime DateIssue { get; private set; }
|
||||
public int FullPrice { get; private set; }
|
||||
public int MasterId { get; private set; }
|
||||
public int DetailId { get; private set; }
|
||||
public int DetailCount { get; private set; }
|
||||
|
||||
}
|
@ -97,6 +97,7 @@ namespace ProjectRepairCompany.Forms
|
||||
try
|
||||
{
|
||||
dataGridView.DataSource = _detailRepository.ReadDetails();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -96,6 +96,8 @@ namespace ProjectRepairCompany.Forms
|
||||
try
|
||||
{
|
||||
dataGridView.DataSource = _masterRepository.ReadMasters();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -41,18 +41,18 @@
|
||||
panel1.Controls.Add(ButtonDel);
|
||||
panel1.Controls.Add(ButtonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(871, 0);
|
||||
panel1.Location = new Point(1169, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(193, 450);
|
||||
panel1.Size = new Size(193, 397);
|
||||
panel1.TabIndex = 2;
|
||||
//
|
||||
// ButtonDel
|
||||
//
|
||||
ButtonDel.BackgroundImage = Properties.Resources.Ic_remove_circle_48px_svg;
|
||||
ButtonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonDel.Location = new Point(42, 213);
|
||||
ButtonDel.Location = new Point(42, 188);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(117, 83);
|
||||
ButtonDel.Size = new Size(117, 73);
|
||||
ButtonDel.TabIndex = 1;
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
@ -61,9 +61,9 @@
|
||||
//
|
||||
ButtonAdd.BackgroundImage = Properties.Resources._43_436254_plus_green_plus_icon_png;
|
||||
ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonAdd.Location = new Point(42, 20);
|
||||
ButtonAdd.Location = new Point(42, 18);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(117, 74);
|
||||
ButtonAdd.Size = new Size(117, 65);
|
||||
ButtonAdd.TabIndex = 0;
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
@ -83,14 +83,14 @@
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(871, 450);
|
||||
dataGridView.Size = new Size(1169, 397);
|
||||
dataGridView.TabIndex = 3;
|
||||
//
|
||||
// FormOrders
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1064, 450);
|
||||
ClientSize = new Size(1362, 397);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormOrders";
|
||||
|
@ -48,6 +48,7 @@ namespace ProjectRepairCompany.Forms
|
||||
try
|
||||
{
|
||||
dataGridView.DataSource = _storageDetailRepository.ReadStorageDetails();
|
||||
dataGridView.Columns["SupplyDate"].DefaultCellStyle.Format = "dd.MM.yyyy hh:mm";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -92,7 +92,10 @@ namespace ProjectRepairCompany.Forms
|
||||
|
||||
|
||||
}
|
||||
private void LoadList() => dataGridView.DataSource = _storageRepository.ReadStorages();
|
||||
private void LoadList() {
|
||||
dataGridView.DataSource = _storageRepository.ReadStorages();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -27,8 +27,8 @@ public class ChartReport
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Заказы мастера")
|
||||
.AddPieChart("Выполненные заказы", GetData(dateTime))
|
||||
.AddHeader("Заказы выполненные мастерами")
|
||||
.AddPieChart($"Выполненные заказы за {dateTime:dd MMMM yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -41,13 +41,12 @@ public class ChartReport
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _orderRepository
|
||||
.ReadOrders()
|
||||
.Where(x => x.DateIssue.Date == dateTime.Date)
|
||||
.GroupBy(x => x.MasterId, (key, group) => new {
|
||||
Id = key,
|
||||
.ReadOrders(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||
.GroupBy(x => x.MasterName, (key, group) => new {
|
||||
MasterName = key,
|
||||
Count = group.Count()
|
||||
})
|
||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
.Select(x => (x.MasterName.ToString(), (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ internal class ExcelBuilder
|
||||
for (var j = 0; j < data.Last().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.Last()[j],
|
||||
StyleIndex.SimpleTextWithBorder);
|
||||
StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
return this;
|
||||
|
@ -44,56 +44,46 @@ internal class TableReport
|
||||
|
||||
private List<string[]> GetData(int masterId, string masterName, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
|
||||
var orders = _orderRepository
|
||||
.ReadOrders()
|
||||
.Where(order => order.MasterId == masterId && order.DateIssue >= startDate && order.DateIssue <= endDate)
|
||||
.ToList();
|
||||
.ReadOrders(startDate, endDate, masterId)
|
||||
.ToList();
|
||||
|
||||
if (!orders.Any())
|
||||
return new List<string[]> { Headers };
|
||||
|
||||
var detailsData = orders
|
||||
.Select(order => new
|
||||
{
|
||||
MasterName = masterName,
|
||||
OrderId = order.Id,
|
||||
OrderDate = order.DateIssue,
|
||||
Details = string.Join(", ", order.OrderDetails.Select(d => $"ID: {d.DetailId} Кол-во: {d.DetailCount}")),
|
||||
FullPrice = order.FullPrice
|
||||
|
||||
OrderId = order.Id,
|
||||
Details = string.Join(", ", order.OrderDetails.Select(d => $"Деталь: {d.DetailName} Кол-во: {d.DetailCount}")),
|
||||
FullPrice = order.FullPrice
|
||||
})
|
||||
.OrderBy(detail => detail.OrderDate)
|
||||
.ToList();
|
||||
|
||||
.ToList();
|
||||
|
||||
var result = new List<string[]> { Headers };
|
||||
|
||||
result.AddRange(detailsData.Select(detail => new string[]
|
||||
{
|
||||
detail.MasterName,
|
||||
detail.OrderId.ToString(),
|
||||
detail.OrderDate.ToString("dd.MM.yyyy"),
|
||||
detail.Details.ToString(),
|
||||
detail.FullPrice.ToString()
|
||||
detail.MasterName,
|
||||
detail.OrderId.ToString(),
|
||||
detail.OrderDate.ToString("dd.MM.yyyy"),
|
||||
detail.Details.ToString(),
|
||||
detail.FullPrice.ToString()
|
||||
}));
|
||||
|
||||
|
||||
result.Add(new string[]
|
||||
{
|
||||
"Итого",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
detailsData.Sum(d => d.FullPrice).ToString()
|
||||
"Итого",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
detailsData.Sum(d => d.FullPrice).ToString()
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -64,7 +64,6 @@ public class OrderRepository : IOrderRepository
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeleteOrder(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта с Id {OrderId}", id);
|
||||
@ -90,7 +89,6 @@ public class OrderRepository : IOrderRepository
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Order ReadOrderById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
@ -112,23 +110,74 @@ public class OrderRepository : IOrderRepository
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? masterId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
|
||||
if (masterId.HasValue)
|
||||
{
|
||||
builder.AddCondition("o.MasterId = @masterId");
|
||||
}
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("o.DateIssue >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("o.DateIssue <= @dateTo");
|
||||
}
|
||||
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"
|
||||
SELECT o.*, od.DetailId, od.DetailCount From ""Order"" o
|
||||
LEFT JOIN OrderDetail od ON o.Id = od.OrderId";
|
||||
var orders = connection.Query<TempOrderDetail>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders));
|
||||
return orders.GroupBy(x => x.Id, y => y,
|
||||
(key,value) => Order.CreateOperation(value.First(),
|
||||
value.Select(z => OrderDetail.CreateOperation(0, z.DetailId, z.DetailCount)))).ToList();
|
||||
var querySelect = @$"
|
||||
SELECT
|
||||
o.Id AS Id,
|
||||
o.OrderDate,
|
||||
o.DateCompletion,
|
||||
o.DateIssue,
|
||||
o.FullPrice,
|
||||
o.MasterId,
|
||||
m.MasterName AS MasterName,
|
||||
od.DetailId,
|
||||
od.DetailCount,
|
||||
d.namedetail AS DetailName
|
||||
FROM ""Order"" o
|
||||
LEFT JOIN OrderDetail od ON o.Id = od.OrderId
|
||||
LEFT JOIN Detail d ON d.Id = od.DetailId
|
||||
LEFT JOIN Master m ON m.Id = o.MasterId
|
||||
{builder.Build()}
|
||||
ORDER BY o.DateIssue";
|
||||
|
||||
var orderDict = new Dictionary<int, Order>();
|
||||
|
||||
connection.Query<Order, OrderDetail, Order>(querySelect,
|
||||
(order, orderDetail) =>
|
||||
{
|
||||
if (!orderDict.TryGetValue(order.Id, out var existingOrder))
|
||||
{
|
||||
existingOrder = order;
|
||||
existingOrder.OrderDetails = new List<OrderDetail>();
|
||||
orderDict.Add(existingOrder.Id, existingOrder);
|
||||
}
|
||||
|
||||
if (orderDetail != null)
|
||||
{
|
||||
((List<OrderDetail>)existingOrder.OrderDetails).Add(orderDetail);
|
||||
}
|
||||
|
||||
return existingOrder;
|
||||
},
|
||||
splitOn: "DetailId",
|
||||
param: new { dateForm, dateTo, masterId });
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orderDict.Values));
|
||||
|
||||
return orderDict.Values.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -139,4 +188,4 @@ LEFT JOIN OrderDetail od ON o.Id = od.OrderId";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
internal 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}";
|
||||
}
|
||||
}
|
@ -48,7 +48,15 @@ VALUES (@StorageId, @DetailId, @DetailCount, @SupplyDate)";
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM StorageDetail";
|
||||
var querySelect = @"SELECT
|
||||
sd.*,
|
||||
s.StorageAddress as ""StorageAddress"",
|
||||
d.NameDetail as ""DetailName""
|
||||
FROM StorageDetail sd
|
||||
LEFT JOIN Storage s ON s.Id = sd.StorageId
|
||||
LEFT JOIN Detail d ON d.Id = sd.DetailId
|
||||
WHERE (@storageId IS NULL OR sd.StorageId = @storageId)
|
||||
AND (@detailId IS NULL OR sd.DetailId = @detailId)";
|
||||
var storageDetails = connection.Query<StorageDetail>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(storageDetails));
|
||||
return storageDetails;
|
||||
|
Loading…
x
Reference in New Issue
Block a user