Сделанно

This commit is contained in:
Егор Пыжов 2024-12-10 11:27:20 +04:00
parent 2a5fb215e3
commit 8bd98a4525
12 changed files with 127 additions and 144 deletions

View File

@ -9,7 +9,7 @@ public class Appointment
[Browsable(false)]
public int EmployeeId { get; private set; }
[Browsable(false)]
[DisplayName("Номер заказа")]
public int OrderId { get; private set; }
[DisplayName("Сотрудник")]

View File

@ -43,17 +43,4 @@ public class Order
OrderService = orderService
};
}
public static Order CreateOperation(TempOrder tempOrder, IEnumerable<OrderService> orderService)
{
return new Order
{
Id = tempOrder.Id,
CompanyId = tempOrder.CompanyId,
Date = tempOrder.Date,
Price = tempOrder.Price,
OrderService = orderService
};
}
}

View File

@ -9,7 +9,7 @@ public class OrderService
public int Quantity { get; private set; }
public DateTime ExecutionDate { get; private set; }
public static OrderService CreateOperation(int id, int serviceId, int serviceQuantity, DateTime executionDate)
public static OrderService CreateElement(int id, int serviceId, int serviceQuantity, DateTime executionDate)
{
return new OrderService
{

View File

@ -1,12 +0,0 @@
namespace ITServiceManager.Entities;
public class TempOrder
{
public int Id { get; private set; }
public int CompanyId { get; private set; }
public int ServiceId { get; private set; }
public DateTime Date { get; private set; }
public decimal Price { get; private set; }
public int Quantity { get; private set; }
public DateTime ExecutionTime { get; private set; }
}

View File

@ -42,7 +42,7 @@ namespace ITServiceManager.Forms
comboBoxOrder.ValueMember = "Id";
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
comboBoxEmployee.DisplayMember = "Name";
comboBoxEmployee.DisplayMember = "FullName";
comboBoxEmployee.ValueMember = "Id";
dateTimePickerEnd.Format = DateTimePickerFormat.Custom;

View File

@ -1,20 +1,10 @@
using ITServiceManager.Repositories;
using ITServiceManager.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Unity;
namespace ITServiceManager.Forms
namespace ITServiceManager.Forms;
public partial class FormAppointments : Form
{
public partial class FormAppointments : Form
{
private readonly IUnityContainer _container;
private readonly IAppointmentRepository _appointmentRepository;
public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository)
@ -69,8 +59,23 @@ namespace ITServiceManager.Forms
{
dataGridView.DataSource = _appointmentRepository.ReadAppointments();
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
dataGridView.Columns["EndDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd.MM.yyyy HH:mm";
dataGridView.CellFormatting += (sender, e) =>
{
if (dataGridView.Columns[e.ColumnIndex].Name == "EndDate")
{
if (e.Value == null || e.Value == DBNull.Value)
{
e.Value = "В процессе";
e.FormattingApplied = true;
}
else if (e.Value is DateTime endDate)
{
e.Value = endDate.ToString("dd.MM.yyyy HH:mm");
e.FormattingApplied = true;
}
}
};
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
@ -104,6 +109,5 @@ namespace ITServiceManager.Forms
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -45,9 +45,9 @@ public partial class FormOrder : Form
{
continue;
}
list.Add(OrderService.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnService"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value)));
list.Add(OrderService.CreateElement(0, Convert.ToInt32(row.Cells["ColumnService"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value)));
}
return list;
return list.GroupBy(x => x.ServiceId, x => x.Quantity, (id, quantities) => OrderService.CreateElement(0, id, quantities.Sum(), list.First(x => x.ServiceId == id).ExecutionDate)).ToList();
}
}

View File

@ -95,8 +95,11 @@ namespace ITServiceManager.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource =
_serviceRepository.ReadServices();
private void LoadList()
{
dataGridView.DataSource = _serviceRepository.ReadServices();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;

View File

@ -29,7 +29,7 @@ public class TableReport
.AddHeader("Сводка по обслуживанию услуг", 0, 3)
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
.AddTable([10, 10, 15, 15], GetData(employeeId, startDate, endDate))
.AddTable([10, 10, 15], GetData(employeeId, startDate, endDate))
.Build();
return true;
}
@ -48,9 +48,9 @@ public class TableReport
.SelectMany(order => order.OrderService
.Select(service => new
{
EmployeeId = _appointmentRepository
EmployeeName = _appointmentRepository
.ReadAppointments()
.FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeId,
.FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeName,
Date = order.Date,
Quantity = service.Quantity
}))
@ -58,7 +58,8 @@ public class TableReport
return new List<string[]>() { item }
.Union(
data
.Select(x => new string[] { x.EmployeeId?.ToString() ?? "Не назначен", x.Date.ToString("dd.MM.yyyy"), x.Quantity.ToString()}))
.Select(
x => new string[] { x.EmployeeName ?? "Не назначен", x.Date.ToString("dd.MM.yyyy"), x.Quantity.ToString()}))
.Union(
[["Всего", string.Empty, data.Sum(x => x.Quantity).ToString()]])
.ToList();

View File

@ -4,7 +4,7 @@ namespace ITServiceManager.Repositories;
public interface IOrderRepository
{
IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? serviceId = null, int? companyId = null);
IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? serviceId = null, int? companyId = null);
void CreateOrder(Order order);
void DeleteOrder(int id);
}

View File

@ -41,8 +41,9 @@ public class AppointmentRepository : IAppointmentRepository
builder.AddCondition("ap.dateEnd >= @dateTo");
}
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @$"SELECT ap.*, e.Name as 'EmployeeName'
FROM Employees ap JOIN Employees e ON e.id = ap.EmployeeId
var querySelect = @$"
SELECT ap.*, CONCAT(e.LastName, ' ', e.FirstName) as EmployeeName
FROM Appointments ap LEFT JOIN Employees e ON e.id = ap.EmployeeId;
{builder.Build()}";
var appointment = connection.Query<Appointment>(querySelect, new { employeeId, dateFrom, dateTo});
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(appointment));

View File

@ -24,25 +24,24 @@ public class OrderRepository : IOrderRepository
var builder = new QueryBuilder();
if (dateFrom.HasValue)
{
builder.AddCondition("Orders.Date >= @dateForm");
builder.AddCondition("o.Date >= @dateFrom");
}
if (dateTo.HasValue)
{
builder.AddCondition("Orders.Date <= @dateTo");
builder.AddCondition("o.Date <= @dateTo");
}
if (companyId.HasValue)
if (serviceId.HasValue)
{
builder.AddCondition("Orders.CompanyId = @companyId");
builder.AddCondition("os.ServiceId = @serviceId");
}
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @$"
SELECT o.*, c.Name as CompanyName, os.serviceId, os.quantity, s.ServiceType
SELECT o.*, c.Name as CompanyName, os.serviceId, os.quantity, s.ServiceType as ServiceName
FROM Orders AS o
LEFT JOIN Companies c on c.Id = o.CompanyId
INNER JOIN Order_Service AS os ON o.id = os.orderId
LEFT JOIN Services s on s.Id = os.ServiceId
Where os.serviceId = @serviceId
{builder.Build}";
{builder.Build()}";
var orderDict = new Dictionary<int, List<OrderService>>();
var orders = connection.Query<Order, OrderService, Order>(querySelect,