Сделанно
This commit is contained in:
parent
2a5fb215e3
commit
8bd98a4525
@ -9,7 +9,7 @@ public class Appointment
|
|||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public int EmployeeId { get; private set; }
|
public int EmployeeId { get; private set; }
|
||||||
|
|
||||||
[Browsable(false)]
|
[DisplayName("Номер заказа")]
|
||||||
public int OrderId { get; private set; }
|
public int OrderId { get; private set; }
|
||||||
|
|
||||||
[DisplayName("Сотрудник")]
|
[DisplayName("Сотрудник")]
|
||||||
|
@ -43,17 +43,4 @@ public class Order
|
|||||||
OrderService = orderService
|
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class OrderService
|
|||||||
public int Quantity { get; private set; }
|
public int Quantity { get; private set; }
|
||||||
public DateTime ExecutionDate { 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
|
return new OrderService
|
||||||
{
|
{
|
||||||
|
@ -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; }
|
|
||||||
}
|
|
@ -42,7 +42,7 @@ namespace ITServiceManager.Forms
|
|||||||
comboBoxOrder.ValueMember = "Id";
|
comboBoxOrder.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
||||||
comboBoxEmployee.DisplayMember = "Name";
|
comboBoxEmployee.DisplayMember = "FullName";
|
||||||
comboBoxEmployee.ValueMember = "Id";
|
comboBoxEmployee.ValueMember = "Id";
|
||||||
|
|
||||||
dateTimePickerEnd.Format = DateTimePickerFormat.Custom;
|
dateTimePickerEnd.Format = DateTimePickerFormat.Custom;
|
||||||
|
@ -1,18 +1,8 @@
|
|||||||
using ITServiceManager.Repositories;
|
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;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
{
|
|
||||||
public partial class FormAppointments : Form
|
public partial class FormAppointments : Form
|
||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
private readonly IUnityContainer _container;
|
||||||
@ -69,8 +59,23 @@ namespace ITServiceManager.Forms
|
|||||||
{
|
{
|
||||||
dataGridView.DataSource = _appointmentRepository.ReadAppointments();
|
dataGridView.DataSource = _appointmentRepository.ReadAppointments();
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd.MM.yyyy HH:mm";
|
||||||
dataGridView.Columns["EndDate"].DefaultCellStyle.Format = "dd MMMM 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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
@ -105,5 +110,4 @@ namespace ITServiceManager.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ public partial class FormOrder : Form
|
|||||||
{
|
{
|
||||||
continue;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +95,11 @@ namespace ITServiceManager.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridView.DataSource =
|
private void LoadList()
|
||||||
_serviceRepository.ReadServices();
|
{
|
||||||
|
dataGridView.DataSource = _serviceRepository.ReadServices();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -29,7 +29,7 @@ public class TableReport
|
|||||||
.AddHeader("Сводка по обслуживанию услуг", 0, 3)
|
.AddHeader("Сводка по обслуживанию услуг", 0, 3)
|
||||||
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
|
.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();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -48,9 +48,9 @@ public class TableReport
|
|||||||
.SelectMany(order => order.OrderService
|
.SelectMany(order => order.OrderService
|
||||||
.Select(service => new
|
.Select(service => new
|
||||||
{
|
{
|
||||||
EmployeeId = _appointmentRepository
|
EmployeeName = _appointmentRepository
|
||||||
.ReadAppointments()
|
.ReadAppointments()
|
||||||
.FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeId,
|
.FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeName,
|
||||||
Date = order.Date,
|
Date = order.Date,
|
||||||
Quantity = service.Quantity
|
Quantity = service.Quantity
|
||||||
}))
|
}))
|
||||||
@ -58,7 +58,8 @@ public class TableReport
|
|||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(
|
.Union(
|
||||||
data
|
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(
|
.Union(
|
||||||
[["Всего", string.Empty, data.Sum(x => x.Quantity).ToString()]])
|
[["Всего", string.Empty, data.Sum(x => x.Quantity).ToString()]])
|
||||||
.ToList();
|
.ToList();
|
||||||
|
@ -4,7 +4,7 @@ namespace ITServiceManager.Repositories;
|
|||||||
|
|
||||||
public interface IOrderRepository
|
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 CreateOrder(Order order);
|
||||||
void DeleteOrder(int id);
|
void DeleteOrder(int id);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,9 @@ public class AppointmentRepository : IAppointmentRepository
|
|||||||
builder.AddCondition("ap.dateEnd >= @dateTo");
|
builder.AddCondition("ap.dateEnd >= @dateTo");
|
||||||
}
|
}
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @$"SELECT ap.*, e.Name as 'EmployeeName'
|
var querySelect = @$"
|
||||||
FROM Employees ap JOIN Employees e ON e.id = ap.EmployeeId
|
SELECT ap.*, CONCAT(e.LastName, ' ', e.FirstName) as EmployeeName
|
||||||
|
FROM Appointments ap LEFT JOIN Employees e ON e.id = ap.EmployeeId;
|
||||||
{builder.Build()}";
|
{builder.Build()}";
|
||||||
var appointment = connection.Query<Appointment>(querySelect, new { employeeId, dateFrom, dateTo});
|
var appointment = connection.Query<Appointment>(querySelect, new { employeeId, dateFrom, dateTo});
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(appointment));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(appointment));
|
||||||
|
@ -24,25 +24,24 @@ public class OrderRepository : IOrderRepository
|
|||||||
var builder = new QueryBuilder();
|
var builder = new QueryBuilder();
|
||||||
if (dateFrom.HasValue)
|
if (dateFrom.HasValue)
|
||||||
{
|
{
|
||||||
builder.AddCondition("Orders.Date >= @dateForm");
|
builder.AddCondition("o.Date >= @dateFrom");
|
||||||
}
|
}
|
||||||
if (dateTo.HasValue)
|
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);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @$"
|
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
|
FROM Orders AS o
|
||||||
LEFT JOIN Companies c on c.Id = o.CompanyId
|
LEFT JOIN Companies c on c.Id = o.CompanyId
|
||||||
INNER JOIN Order_Service AS os ON o.id = os.orderId
|
INNER JOIN Order_Service AS os ON o.id = os.orderId
|
||||||
LEFT JOIN Services s on s.Id = os.ServiceId
|
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 orderDict = new Dictionary<int, List<OrderService>>();
|
||||||
|
|
||||||
var orders = connection.Query<Order, OrderService, Order>(querySelect,
|
var orders = connection.Query<Order, OrderService, Order>(querySelect,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user