PIbd-21_Kudrinsky_O.S._LabWork_4 #7
@ -1,4 +1,5 @@
|
||||
using ProjectWorkshop.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
@ -6,10 +7,13 @@ public class Assembler
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[DisplayName("ФИО")]
|
||||
public string FullName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Уровень")]
|
||||
public AssemblerRank AssemblerRank { get; private set; }
|
||||
|
||||
[DisplayName("Стаж")]
|
||||
public DateTime WorkExperience { get; private set; }
|
||||
|
||||
public static Assembler CreateEntity(int id, string fullName, AssemblerRank assemblerRank, DateTime? dateTime = null)
|
||||
@ -22,5 +26,4 @@ public class Assembler
|
||||
WorkExperience = dateTime ?? DateTime.Now
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,27 @@
|
||||
namespace ProjectWorkshop.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
public class AssemblerShift
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[DisplayName("Количество часов")]
|
||||
public int WorkHours { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int AssemblerID_Assembler { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ShiftID_Shift { get; private set; }
|
||||
|
||||
[DisplayName("Сборщик")]
|
||||
public string AssemblerName { get; private set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public string ShiftName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime AssemblerShiftDate { get; private set; }
|
||||
|
||||
public static AssemblerShift CreateOperation(int id, int workHours, int assemblerID, int shiftID_Shift, DateTime? shiftDate = null)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectWorkshop.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
@ -6,12 +7,24 @@ public class Assembly
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int AssemblerID_Assembler { get; private set; }
|
||||
|
||||
[DisplayName("Сборщик")]
|
||||
public string AssemblerName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Собранные продукции")]
|
||||
public string Assembles => ProductAssembly != null ?
|
||||
string.Join(", ", ProductAssembly.Select(x => $"{x.ProductName}:{x.Count}")) :
|
||||
string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<ProductAssembly> ProductAssembly { get; private set; } = [];
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime AssemblyDate { get; private set; }
|
||||
|
||||
public static Assembly CreateOperation(int id, int count, int assemblerID, IEnumerable<ProductAssembly> productAssembly, DateTime? assemblyDate = null)
|
||||
@ -26,17 +39,12 @@ public class Assembly
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static Assembly CreateOperation(TempProductAssembly tempProductAssembly, IEnumerable<ProductAssembly> productAssemblies)
|
||||
public void SetProductAssembly(IEnumerable<ProductAssembly> productAssemblies)
|
||||
{
|
||||
return new Assembly
|
||||
if (productAssemblies != null && productAssemblies.Any())
|
||||
{
|
||||
ID = tempProductAssembly.ID,
|
||||
Count = tempProductAssembly.Count,
|
||||
AssemblerID_Assembler = tempProductAssembly.AssemblyID_Assembly,
|
||||
ProductAssembly = productAssemblies,
|
||||
AssemblyDate = tempProductAssembly.AssemblyDate
|
||||
};
|
||||
ProductAssembly = productAssemblies;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectWorkshop.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
@ -6,10 +7,13 @@ public class Product
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string ProductName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; private set; }
|
||||
|
||||
[DisplayName("Тип")]
|
||||
public ProductType ProductType { get; private set; }
|
||||
|
||||
public static Product CreateEntity(int id, string productName, double price, ProductType productType)
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectWorkshop.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
public class ProductAssembly
|
||||
{
|
||||
@ -8,6 +10,8 @@ public class ProductAssembly
|
||||
|
||||
public int AssemblyID_Assembly { get; private set; }
|
||||
|
||||
public string ProductName { get; private set; } = string.Empty;
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public static ProductAssembly CreateElement(int id, int productID, int assemblyID, int count)
|
||||
|
@ -1,9 +1,12 @@
|
||||
namespace ProjectWorkshop.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
public class Shift
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime ShiftDate { get; private set; }
|
||||
|
||||
public static Shift CreateEntity(int id, DateTime? dateTime = null)
|
||||
|
@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectWorkshop.Entities;
|
||||
|
||||
public class TempProductAssembly
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
public int ProductID_Product { get; private set; }
|
||||
|
||||
public int AssemblyID_Assembly { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public DateTime AssemblyDate { get; private set; }
|
||||
}
|
||||
|
@ -49,6 +49,10 @@ namespace ProjectWorkshop.Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewAssemblerShifts.DataSource = _assemblerShiftRepository.ReadAssemblerShifts();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewAssemblerShifts.DataSource = _assemblerShiftRepository.ReadAssemblerShifts();
|
||||
dataGridViewAssemblerShifts.Columns["Id"].Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,8 +96,11 @@ namespace ProjectWorkshop.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewAssemblers.DataSource = _assemblerRepository.ReadAssemblers();
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewAssemblers.DataSource = _assemblerRepository.ReadAssemblers();
|
||||
dataGridViewAssemblers.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -22,7 +22,7 @@ namespace ProjectWorkshop.Forms
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
|
||||
comboBoxAssembler.DataSource = assemblerRepository.ReadAssemblers();
|
||||
comboBoxAssembler.DisplayMember = "Name";
|
||||
comboBoxAssembler.DisplayMember = "FullName";
|
||||
comboBoxAssembler.ValueMember = "ID";
|
||||
}
|
||||
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
|
||||
|
@ -74,8 +74,11 @@ namespace ProjectWorkshop.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewAssemblies.DataSource = _assemblyRepository.ReadAssemblies();
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewAssemblies.DataSource = _assemblyRepository.ReadAssemblies();
|
||||
dataGridViewAssemblies.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -93,8 +93,11 @@ namespace ProjectWorkshop.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewProducts.DataSource = _productRepository.ReadProducts();
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewProducts.DataSource = _productRepository.ReadProducts();
|
||||
dataGridViewProducts.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -92,8 +92,11 @@ namespace ProjectWorkshop.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewShifts.DataSource = _shiftRepository.ReadShifts();
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewShifts.DataSource = _shiftRepository.ReadShifts();
|
||||
dataGridViewShifts.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -32,7 +32,7 @@ namespace ProjectWorkshop.Reports
|
||||
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Сборки изделий")
|
||||
.AddPieChart("Количество сборок по сборщикам", data)
|
||||
.AddPieChart($"Количество сборок по сборщикам {dateTime:dd.MM.yyyy}", data)
|
||||
.Build();
|
||||
|
||||
return true;
|
||||
|
@ -56,15 +56,14 @@ namespace ProjectWorkshop.Reports
|
||||
throw new Exception($"Сборщик с ID {assemblerID} не найден.");
|
||||
|
||||
var shiftData = _assemblerShiftRepository
|
||||
.ReadAssemblerShifts()
|
||||
.Where(x => x.AssemblerShiftDate >= startDate && x.AssemblerShiftDate <= endDate && x.AssemblerID_Assembler == assemblerID)
|
||||
.ReadAssemblerShifts(startDate, endDate, assemblerID)
|
||||
.OrderBy(x => x.AssemblerShiftDate)
|
||||
.ToList();
|
||||
|
||||
var result = new List<string[]>
|
||||
{
|
||||
Headers
|
||||
};
|
||||
{
|
||||
Headers
|
||||
};
|
||||
|
||||
int totalAssemblies = 0;
|
||||
int totalProducts = 0;
|
||||
|
@ -3,7 +3,7 @@ namespace ProjectWorkshop.Repositories;
|
||||
|
||||
public interface IAssemblerShiftRepository
|
||||
{
|
||||
IEnumerable<AssemblerShift> ReadAssemblerShifts(int? workHours = null, int? assemblerID = null, int? shiftID = null);
|
||||
IEnumerable<AssemblerShift> ReadAssemblerShifts(DateTime? dateFrom = null, DateTime? dateTo = null, int? assemblyID = null);
|
||||
|
||||
void CreateAssemblerShift(AssemblerShift assemblerShift);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ namespace ProjectWorkshop.Repositories;
|
||||
|
||||
public interface IAssemblyRepository
|
||||
{
|
||||
IEnumerable<Assembly> ReadAssemblies(DateTime? dateFrom = null, DateTime? dateTo = null, int? productID = null, int? assemblyID = null, int? count = null);
|
||||
IEnumerable<Assembly> ReadAssemblies(DateTime? dateFrom = null, DateTime? dateTo = null, int? assemblyID = null);
|
||||
|
||||
void CreateAssembly(Assembly assembly);
|
||||
|
||||
|
@ -39,15 +39,30 @@ public class AssemblerShiftRepository : IAssemblerShiftRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<AssemblerShift> ReadAssemblerShifts(int? workHours = null, int? assemblerID = null, int? shiftID = null)
|
||||
public IEnumerable<AssemblerShift> ReadAssemblerShifts(DateTime? dateFrom = null, DateTime? dateTo = null, int? assemblyID = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("AssemblerShiftDate >= @dateFrom");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("AssemblerShiftDate <= @dateTo");
|
||||
}
|
||||
if (assemblyID.HasValue)
|
||||
{
|
||||
builder.AddCondition("AssemblerID_Assembler = @assemblyID");
|
||||
}
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM AssemblerShift";
|
||||
var assemblerShifts = connection.Query<AssemblerShift>(querySelect);
|
||||
var querySelect = @$"SELECT asss.*, assr.FullName as AssemblerName FROM AssemblerShift asss
|
||||
LEFT JOIN Assembler assr on assr.Id = asss.AssemblerID_Assembler
|
||||
{builder.Build()}";
|
||||
var assemblerShifts = connection.Query<AssemblerShift>(querySelect, new {dateFrom, dateTo, assemblyID});
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(assemblerShifts));
|
||||
return assemblerShifts;
|
||||
|
@ -86,16 +86,44 @@ public class AssemblyRepository : IAssemblyRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Assembly> ReadAssemblies(DateTime? dateFrom = null, DateTime? dateTo = null, int? id = null, int? assemblyID = null, int? count = null)
|
||||
public IEnumerable<Assembly> ReadAssemblies(DateTime? dateFrom = null, DateTime? dateTo = null, int? assemblyID = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var selectQuery = @"SELECT * FROM Assembly";
|
||||
var assemblies = connection.Query<Assembly>(selectQuery);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(assemblies));
|
||||
return assemblies;
|
||||
var selectQuery = @"SELECT
|
||||
ass.*,
|
||||
assr.FullName as AssemblerName,
|
||||
prass.Count,
|
||||
pr.ProductName as ProductName
|
||||
FROM Assembly ass
|
||||
LEFT JOIN Assembler assr on assr.Id = ass.AssemblerId_Assembler
|
||||
INNER JOIN ProductAssembly prass on ass.Id = prass.AssemblyID_Assembly
|
||||
LEFT JOIN Product pr on pr.Id = prass.ProductID_Product";
|
||||
var assembliesDict = new Dictionary<int, List<ProductAssembly>>();
|
||||
|
||||
var productAssemblies = connection.Query<Assembly, ProductAssembly, Assembly>(selectQuery,
|
||||
(assembly, productAssembly) =>
|
||||
{
|
||||
if (!assembliesDict.TryGetValue(assembly.ID, out var ccf))
|
||||
{
|
||||
ccf = [];
|
||||
assembliesDict.Add(assembly.ID, ccf);
|
||||
}
|
||||
|
||||
ccf.Add(productAssembly);
|
||||
return assembly;
|
||||
}, splitOn: "Count", param: new { dateFrom, dateTo, assemblyID });
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(productAssemblies));
|
||||
|
||||
return assembliesDict.Select(x =>
|
||||
{
|
||||
var cf = productAssemblies.First(y => y.ID == x.Key);
|
||||
cf.SetProductAssembly(x.Value);
|
||||
return cf;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectWorkshop.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}";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user