diff --git a/ProjectAtelier/Entities/MaterialReplenishment.cs b/ProjectAtelier/Entities/MaterialReplenishment.cs index d5ce389..4f7a6b9 100644 --- a/ProjectAtelier/Entities/MaterialReplenishment.cs +++ b/ProjectAtelier/Entities/MaterialReplenishment.cs @@ -18,10 +18,10 @@ public class MaterialReplenishment public DateTime DataTime { get; private set; } [DisplayName("Название")] - public string Name { get; private set; } = string.Empty; + public int IDMaterial { get; private set; } - public static MaterialReplenishment CreateOperation(int id, int count, DateTime dataTime, string name) + public static MaterialReplenishment CreateOperation(int id, int count, DateTime dataTime, int idmaterial) { return new MaterialReplenishment { @@ -29,7 +29,7 @@ public class MaterialReplenishment Count = count, DataTime = dataTime, - Name = name + IDMaterial = idmaterial }; } diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.cs index d92b31b..28c94bd 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.cs @@ -31,10 +31,9 @@ namespace ProjectAtelier.Forms throw new InvalidDataException(nameof(materialReplenishment)); } - - textBoxName.Text = materialReplenishment.Name; - comboBoxMaterial.Text = materialReplenishment.Name; numericUpDownCount.Value = materialReplenishment.Count; + comboBoxMaterial.SelectedValue = materialReplenishment.IDMaterial; // Устанавливаем выбранный материал + dateTimePicker.Value = materialReplenishment.DataTime; // Устанавливаем выбранную дату и время _materialReplenishmentId = value; } catch (Exception ex) @@ -59,11 +58,12 @@ namespace ProjectAtelier.Forms private MaterialReplenishment CreateMaterialReplenishment(int id) { - + int selectedMaterialId = (int)comboBoxMaterial.SelectedValue; DateTime selectedDateTime = dateTimePicker.Value; - return MaterialReplenishment.CreateOperation(id, Convert.ToInt32(numericUpDownCount.Value), selectedDateTime, textBoxName.Text); + return MaterialReplenishment.CreateOperation(id, Convert.ToInt32(numericUpDownCount.Value), selectedDateTime, selectedMaterialId); } + private void ButtonAdd_Click_1(object sender, EventArgs e) { try diff --git a/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs b/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs index 561097d..8dab275 100644 --- a/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs +++ b/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs @@ -9,7 +9,7 @@ namespace ProjectAtelier.REPOSITORY; public interface IMaterialReplenishmentRepository { - IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? nameMaterial = null); + IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, int? idmaterial = null); MaterialReplenishment ReadMaterialSpentById(int id); void CreateMaterialSpent(MaterialReplenishment material); void UpdateMaterialSpent(MaterialReplenishment material); diff --git a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs index c2f69c4..8760616 100644 --- a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs +++ b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs @@ -30,8 +30,8 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var queryInsert = @" - INSERT INTO MaterialReplenishment (Count, DataTime, Name) - VALUES (@Count, @DataTime, @Name)"; + INSERT INTO MaterialReplenishment (Count, DataTime, IDMaterial) + VALUES (@Count, @DataTime, @IDMaterial)"; connection.Execute(queryInsert, material); } catch (Exception ex) @@ -64,7 +64,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository throw; } } - public IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? nameMaterial = null) + public IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, int? idmaterial = null) { var builder = new QueryBuilder(); if (dateForm.HasValue) @@ -75,9 +75,9 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository { builder.AddCondition("DataTime <= @dateTo"); } - if (nameMaterial != null) + if (idmaterial != null) { - builder.AddCondition("Name = @nameMaterial"); + builder.AddCondition("IDMaterial = @idmaterial"); } _logger.LogInformation("Получение всех объектов"); @@ -87,7 +87,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository var querySelect = @$" SELECT * FROM MaterialReplenishment {builder.Build()}"; - var materials = connection.Query(querySelect, new { dateForm, dateTo, nameMaterial }); + var materials = connection.Query(querySelect, new { dateForm, dateTo, idmaterial }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials)); return materials; } @@ -110,7 +110,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository SET Count=@Count, DataTime=@DataTime, - Name=@Name + IDMaterial=@IDMaterial WHERE Id=@Id"; connection.Execute(queryUpdate, material); } diff --git a/ProjectAtelier/Reports/ChartReport.cs b/ProjectAtelier/Reports/ChartReport.cs index a216a67..aee47b4 100644 --- a/ProjectAtelier/Reports/ChartReport.cs +++ b/ProjectAtelier/Reports/ChartReport.cs @@ -34,7 +34,7 @@ class ChartReport { return _materialReplenishmentRepository .ReadMaterialsSpent(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1)) - .GroupBy(x => x.Name, (key, group) => new { Id = key, Count = group.Sum(x => x.Count) }) + .GroupBy(x => x.IDMaterial, (key, group) => new { Id = key, Count = group.Sum(x => x.Count) }) .Select(x => (x.Id.ToString(), (double)x.Count)) .ToList(); } diff --git a/ProjectAtelier/Reports/TableReport.cs b/ProjectAtelier/Reports/TableReport.cs index f077ff2..8c40c14 100644 --- a/ProjectAtelier/Reports/TableReport.cs +++ b/ProjectAtelier/Reports/TableReport.cs @@ -47,7 +47,7 @@ internal class TableReport private List GetData(int materialId, DateTime startDate, DateTime endDate) { var data = _materialReplenishmentRepository - .ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, nameMaterial: _materialRepository.ReadMaterialById(materialId).Name) + .ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, idmaterial: _materialRepository.ReadMaterialById(materialId).Id) .Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null }) .Union( _orderMaterialsRepository diff --git a/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs b/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs index 3204078..17c350d 100644 --- a/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs +++ b/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs @@ -16,7 +16,7 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository _connectionString = connectionString; _logger = logger; } - +//orders.datatime AS DataOrder, public IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? matid = null) { var builder = new QueryBuilder(); @@ -35,7 +35,7 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @$" SELECT -orders.datatime AS DataOrder, + orders.*, materials.id AS materialid, pm.count*op.count AS count