Сделанно
This commit is contained in:
parent
2a5fb215e3
commit
8bd98a4525
@ -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("Сотрудник")]
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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";
|
||||
|
||||
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
||||
comboBoxEmployee.DisplayMember = "Name";
|
||||
comboBoxEmployee.DisplayMember = "FullName";
|
||||
comboBoxEmployee.ValueMember = "Id";
|
||||
|
||||
dateTimePickerEnd.Format = DateTimePickerFormat.Custom;
|
||||
|
@ -1,108 +1,112 @@
|
||||
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
|
||||
{
|
||||
public partial class FormAppointments : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IAppointmentRepository _appointmentRepository;
|
||||
public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
_appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository));
|
||||
}
|
||||
private void FormAppointments_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormAppointment>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormAppointment>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList()
|
||||
{
|
||||
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";
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridView.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
namespace ITServiceManager.Forms;
|
||||
|
||||
private void buttonRemove_Click(object sender, EventArgs e)
|
||||
public partial class FormAppointments : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IAppointmentRepository _appointmentRepository;
|
||||
public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
_appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository));
|
||||
}
|
||||
private void FormAppointments_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormAppointment>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormAppointment>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _appointmentRepository.ReadAppointments();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd.MM.yyyy HH:mm";
|
||||
dataGridView.CellFormatting += (sender, e) =>
|
||||
{
|
||||
if (dataGridView.Columns[e.ColumnIndex].Name == "EndDate")
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_appointmentRepository.DeleteAppointment(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
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)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridView.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void buttonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_appointmentRepository.DeleteAppointment(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user