From 894c3a3485d5446e6421f7d27d5a2a6b786a06ef Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 23:02:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=9A=D0=9E=D0=9D=D0=A7=D0=90=D0=A2?= =?UTF-8?q?=D0=95=D0=9B=D0=AC=D0=9D=D0=AB=D0=95=20=D0=9F=D0=A0=D0=90=D0=92?= =?UTF-8?q?=D0=9A=D0=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/MaterialReplenishment.cs | 8 +++--- .../FormMaterialReplenishment.Designer.cs | 26 +++++++++++++++++-- .../Forms/FormMaterialReplenishment.cs | 8 +++--- .../IMaterialReplenishmentRepository.cs | 2 +- .../MaterialReplenishmentRepository.cs | 14 +++++----- ProjectAtelier/Reports/ChartReport.cs | 2 +- ProjectAtelier/Reports/TableReport.cs | 2 +- .../OrderMaterialsRepository.cs | 6 ++--- 8 files changed, 45 insertions(+), 23 deletions(-) diff --git a/ProjectAtelier/Entities/MaterialReplenishment.cs b/ProjectAtelier/Entities/MaterialReplenishment.cs index 4f7a6b9..8dd10ca 100644 --- a/ProjectAtelier/Entities/MaterialReplenishment.cs +++ b/ProjectAtelier/Entities/MaterialReplenishment.cs @@ -17,11 +17,11 @@ public class MaterialReplenishment [DisplayName("Дата пополнения")] public DateTime DataTime { get; private set; } - [DisplayName("Название")] - public int IDMaterial { get; private set; } + [DisplayName("Ткань")] + public string Name { get; private set; } = string.Empty; - public static MaterialReplenishment CreateOperation(int id, int count, DateTime dataTime, int idmaterial) + public static MaterialReplenishment CreateOperation(int id, int count, DateTime dataTime, string name) { return new MaterialReplenishment { @@ -29,7 +29,7 @@ public class MaterialReplenishment Count = count, DataTime = dataTime, - IDMaterial = idmaterial + Name = name }; } diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs index d3955ab..69fe451 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs @@ -36,6 +36,8 @@ label1 = new Label(); dateTimePicker = new DateTimePicker(); label3 = new Label(); + label4 = new Label(); + textBoxName = new TextBox(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // @@ -80,7 +82,7 @@ // comboBoxMaterial // comboBoxMaterial.FormattingEnabled = true; - comboBoxMaterial.Location = new Point(211, 125); + comboBoxMaterial.Location = new Point(210, 153); comboBoxMaterial.Name = "comboBoxMaterial"; comboBoxMaterial.Size = new Size(151, 28); comboBoxMaterial.TabIndex = 6; @@ -88,7 +90,7 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(28, 125); + label1.Location = new Point(28, 156); label1.Name = "label1"; label1.Size = new Size(78, 20); label1.TabIndex = 7; @@ -110,11 +112,29 @@ label3.TabIndex = 9; label3.Text = "Дата"; // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(28, 106); + label4.Name = "label4"; + label4.Size = new Size(77, 20); + label4.TabIndex = 10; + label4.Text = "Название"; + // + // textBoxName + // + textBoxName.Location = new Point(212, 94); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(150, 27); + textBoxName.TabIndex = 11; + // // FormMaterialReplenishment // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(490, 404); + Controls.Add(textBoxName); + Controls.Add(label4); Controls.Add(label3); Controls.Add(dateTimePicker); Controls.Add(label1); @@ -144,5 +164,7 @@ private Label label1; private DateTimePicker dateTimePicker; private Label label3; + private Label label4; + private TextBox textBoxName; } } \ No newline at end of file diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.cs index 28c94bd..a6703c8 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.cs @@ -30,9 +30,9 @@ namespace ProjectAtelier.Forms { throw new InvalidDataException(nameof(materialReplenishment)); } - + textBoxName.Text = materialReplenishment.Name; numericUpDownCount.Value = materialReplenishment.Count; - comboBoxMaterial.SelectedValue = materialReplenishment.IDMaterial; // Устанавливаем выбранный материал + //comboBoxMaterial.SelectedValue = materialReplenishment.Name; // Устанавливаем выбранный материал dateTimePicker.Value = materialReplenishment.DataTime; // Устанавливаем выбранную дату и время _materialReplenishmentId = value; } @@ -58,9 +58,9 @@ 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, selectedMaterialId); + return MaterialReplenishment.CreateOperation(id, Convert.ToInt32(numericUpDownCount.Value), selectedDateTime, textBoxName.Text); } diff --git a/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs b/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs index 8dab275..338e18d 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, int? idmaterial = null); + IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? materialName = 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 8760616..6bf888c 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, IDMaterial) - VALUES (@Count, @DataTime, @IDMaterial)"; + INSERT INTO MaterialReplenishment (Count, DataTime, Name) + VALUES (@Count, @DataTime, @Name)"; 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, int? idmaterial = null) + public IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? materialName = null) { var builder = new QueryBuilder(); if (dateForm.HasValue) @@ -75,9 +75,9 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository { builder.AddCondition("DataTime <= @dateTo"); } - if (idmaterial != null) + if ( materialName != null) { - builder.AddCondition("IDMaterial = @idmaterial"); + builder.AddCondition("Name = @materialName"); } _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, idmaterial }); + var materials = connection.Query(querySelect, new { dateForm, dateTo, materialName }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials)); return materials; } @@ -110,7 +110,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository SET Count=@Count, DataTime=@DataTime, - IDMaterial=@IDMaterial + Name=@Name WHERE Id=@Id"; connection.Execute(queryUpdate, material); } diff --git a/ProjectAtelier/Reports/ChartReport.cs b/ProjectAtelier/Reports/ChartReport.cs index aee47b4..a216a67 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.IDMaterial, (key, group) => new { Id = key, Count = group.Sum(x => x.Count) }) + .GroupBy(x => x.Name, (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 8c40c14..520d41a 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, idmaterial: _materialRepository.ReadMaterialById(materialId).Id) + .ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, materialName: _materialRepository.ReadMaterialById(materialId).Name) .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 17c350d..62a1b4a 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(); @@ -30,12 +30,12 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository } if (matid.HasValue) { - builder.AddCondition("materialid = @matid"); + builder.AddCondition("materialid = @matid"); } 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