начало

This commit is contained in:
Егор Пыжов 2024-12-09 13:27:29 +04:00
parent e14cdc0cfc
commit 5dbc07fdc5
13 changed files with 129 additions and 9 deletions

View File

@ -1,11 +1,24 @@
namespace ITServiceManager.Entities;
using System.ComponentModel;
namespace ITServiceManager.Entities;
public class Appointment
{
public int Id { get; private set; }
[Browsable(false)]
public int EmployeeId { get; private set; }
[Browsable(false)]
public int OrderId { get; private set; }
[DisplayName("Сотрудник")]
public string EmployeeName { get; private set; } = string.Empty;
[DisplayName("Дата назначения")]
public DateTime StartDate { get; private set; }
[DisplayName("Дата окончания")]
public DateTime? EndDate { get; private set; }
public static Appointment CreateOperation(int id, int orderId, int employeeId, DateTime appointmentStartDate, DateTime? appointmentEndDate)

View File

@ -1,10 +1,15 @@
namespace ITServiceManager.Entities;
using System.ComponentModel;
namespace ITServiceManager.Entities;
public class Company
{
public int Id { get; private set; }
[DisplayName("Название")]
public string Name { get; private set; } = string.Empty;
[DisplayName("Адресс")]
public string Address { get; private set; } = string.Empty;
public static Company CreateEntity(int id, string companyName, string addres)

View File

@ -1,12 +1,21 @@
using ITServiceManager.Entities.Enums;
using System.ComponentModel;
namespace ITServiceManager.Entities;
public class Employee
{
public int Id { get; private set; }
[DisplayName("Имя")]
public string FirstName { get; private set; } = string.Empty;
[DisplayName("Фамилия")]
public string LastName { get; private set; } = string.Empty;
public string FullName => $"{LastName} {FirstName}";
[DisplayName("Должность")]
public EmployeePost? Position { get; private set; }
public static Employee CreateEntity(int id, string employeeFirstName, string employeeLastName, EmployeePost employeePosition)

View File

@ -1,12 +1,28 @@
namespace ITServiceManager.Entities;
using System.ComponentModel;
namespace ITServiceManager.Entities;
public class Order
{
public int Id { get; private set; }
[Browsable(false)]
public int CompanyId { get; private set; }
[DisplayName("Дата")]
public DateTime Date { get; private set; }
[DisplayName("Сумма")]
public decimal Price { get; private set; }
[DisplayName("Название компании")]
public string CompanyName { get; private set; } = string.Empty;
[DisplayName("Услуги")]
public string Services => OrderService != null ?
string.Join(", ", OrderService.Select(x => $"{x.ServiceName} {x.Quantity}")) : string.Empty;
[Browsable(false)]
public IEnumerable<OrderService> OrderService { get; private set; } = [];
public static Order CreateOperation(int id, int companyId, decimal orderPrice, IEnumerable<OrderService> orderService)

View File

@ -5,6 +5,7 @@ public class OrderService
public int Id { get; private set; }
public int OrderId { get; private set; }
public int ServiceId { get; private set; }
public string ServiceName { get; private set; } = string.Empty;
public int Quantity { get; private set; }
public DateTime ExecutionDate { get; private set; }

View File

@ -1,11 +1,16 @@
using ITServiceManager.Entities.Enums;
using System.ComponentModel;
namespace ITServiceManager.Entities;
public class Service
{
public int Id { get; private set; }
[DisplayName("Тип услуги")]
public ServiceType ServiceType { get; private set; }
[DisplayName("Описание")]
public string Description { get; private set; } = string.Empty;
public static Service CreateEntity(int id, ServiceType type, string description)

View File

@ -38,7 +38,7 @@ namespace ITServiceManager.Forms
throw new ArgumentNullException(nameof(appointmentRepository));
comboBoxOrder.DataSource = orderRepository.ReadOrders();
comboBoxOrder.DisplayMember = "Name";
comboBoxOrder.DisplayMember = "FullName";
comboBoxOrder.ValueMember = "Id";
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();

View File

@ -65,7 +65,13 @@ namespace ITServiceManager.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _appointmentRepository.ReadAppointments();
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;

View File

@ -85,7 +85,11 @@ namespace ITServiceManager.Forms
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _companyRepository.ReadCompanies();
private void LoadList()
{
dataGridView.DataSource = _companyRepository.ReadCompanies();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;

View File

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

View File

@ -65,7 +65,12 @@ namespace ITServiceManager.Forms
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrders();
private void LoadList()
{
dataGridView.DataSource = _orderRepository.ReadOrders();
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Date"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;

View File

@ -22,6 +22,28 @@ public class OrderRepository : IOrderRepository
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var builder = new QueryBuilder();
if (dateForm.HasValue)
{
builder.AddCondition("fa.FeedingDate >= @dateForm");
}
if (dateTo.HasValue)
{
builder.AddCondition("fa.FeedingDate <= @dateTo");
}
if (feedId.HasValue)
{
builder.AddCondition("fa.FeedId = @feedId");
}
if (employeeId.HasValue)
{
builder.AddCondition("fa.EmployeeId = @employeeId");
}
if (animalId.HasValue)
{
builder.AddCondition("fa.AnimalId = @animalId");
}
var querySelect = @"
SELECT o.*, os.serviceId, os.quantity
FROM Orders AS o

View File

@ -0,0 +1,29 @@
using System.Text;
namespace ITServiceManager.Repositories.Implementations;
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}";
}
}