From 3153d5bffc55689576ca178d2c9b95b3b5e66629 Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 21:53:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/MaterialReplenishment.cs | 6 +-- .../FormMaterialReplenishment.Designer.cs | 40 ++++++++++++++----- .../Forms/FormMaterialReplenishment.cs | 9 ++--- .../MaterialReplenishmentRepository.cs | 6 +-- ProjectAtelier/Reports/ChartReport.cs | 2 +- ProjectAtelier/Reports/TableReport.cs | 4 +- .../OrderMaterialsRepository.cs | 4 +- 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/ProjectAtelier/Entities/MaterialReplenishment.cs b/ProjectAtelier/Entities/MaterialReplenishment.cs index 65fa020..47de9e2 100644 --- a/ProjectAtelier/Entities/MaterialReplenishment.cs +++ b/ProjectAtelier/Entities/MaterialReplenishment.cs @@ -12,9 +12,9 @@ public class MaterialReplenishment public int Count { get; private set; } public DateTime DataTime { get; private set; } - public int IDMaterial { get; private set; } + 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 { @@ -22,7 +22,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 d37af7c..4ccf41a 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs @@ -36,13 +36,15 @@ label1 = new Label(); dateTimePicker = new DateTimePicker(); label3 = new Label(); + textBoxName = new TextBox(); + label4 = new Label(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // // label2 // label2.AutoSize = true; - label2.Location = new Point(77, 130); + label2.Location = new Point(73, 186); label2.Name = "label2"; label2.Size = new Size(90, 20); label2.TabIndex = 1; @@ -50,14 +52,14 @@ // // numericUpDownCount // - numericUpDownCount.Location = new Point(212, 123); + numericUpDownCount.Location = new Point(212, 184); numericUpDownCount.Name = "numericUpDownCount"; numericUpDownCount.Size = new Size(150, 27); numericUpDownCount.TabIndex = 3; // // buttonAdd // - buttonAdd.Location = new Point(77, 197); + buttonAdd.Location = new Point(73, 255); buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(107, 53); @@ -68,7 +70,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(231, 197); + buttonCancel.Location = new Point(228, 255); buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(117, 53); @@ -80,7 +82,7 @@ // comboBoxMaterial // comboBoxMaterial.FormattingEnabled = true; - comboBoxMaterial.Location = new Point(210, 76); + comboBoxMaterial.Location = new Point(211, 127); comboBoxMaterial.Name = "comboBoxMaterial"; comboBoxMaterial.Size = new Size(151, 28); comboBoxMaterial.TabIndex = 6; @@ -88,11 +90,11 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(77, 76); + label1.Location = new Point(73, 135); label1.Name = "label1"; - label1.Size = new Size(103, 20); + label1.Size = new Size(78, 20); label1.TabIndex = 7; - label1.Text = "ID материала"; + label1.Text = "Mатериал"; // // dateTimePicker // @@ -110,11 +112,29 @@ label3.TabIndex = 9; label3.Text = "Дата"; // + // textBoxName + // + textBoxName.Location = new Point(210, 78); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(152, 27); + textBoxName.TabIndex = 10; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(77, 85); + label4.Name = "label4"; + label4.Size = new Size(156, 20); + label4.TabIndex = 11; + label4.Text = "Название материала"; + // // FormMaterialReplenishment // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(411, 273); + ClientSize = new Size(502, 363); + Controls.Add(label4); + Controls.Add(textBoxName); Controls.Add(label3); Controls.Add(dateTimePicker); Controls.Add(label1); @@ -144,5 +164,7 @@ private Label label1; private DateTimePicker dateTimePicker; private Label label3; + private TextBox textBoxName; + private Label label4; } } \ No newline at end of file diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.cs index c242774..dee0b25 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.cs @@ -30,10 +30,10 @@ 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) @@ -58,9 +58,8 @@ 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); } private void ButtonAdd_Click_1(object sender, EventArgs e) diff --git a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs index b617e6d..da8dd38 100644 --- a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs +++ b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs @@ -29,8 +29,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) @@ -93,7 +93,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 db0c5cb..3b60b97 100644 --- a/ProjectAtelier/Reports/ChartReport.cs +++ b/ProjectAtelier/Reports/ChartReport.cs @@ -35,7 +35,7 @@ class ChartReport return _materialReplenishmentRepository .ReadMaterialsSpent() .Where(x => x.DataTime.Date == dateTime.Date) - .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 3674429..b6db724 100644 --- a/ProjectAtelier/Reports/TableReport.cs +++ b/ProjectAtelier/Reports/TableReport.cs @@ -48,7 +48,7 @@ internal class TableReport { var data = _materialReplenishmentRepository .ReadMaterialsSpent() - .Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.IDMaterial == materialId) + .Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.Name == _materialRepository.ReadMaterialById(materialId).Name) .Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null }) .Union( _orderMaterialsRepository @@ -65,5 +65,3 @@ internal class TableReport .ToList(); } } -//.Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.Name == _materialRepository.ReadMaterialById(materialId).Name) -// .Select(x => new { Date = x.DateReplenishment, CountIn = (int?)x.Count , CountOut = (int?)null }) \ No newline at end of file diff --git a/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs b/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs index 7252b54..ca507fc 100644 --- a/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs +++ b/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs @@ -21,7 +21,9 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @" - SELECT orders.*, materials.id AS materialid, pm.count*op.count AS count + SELECT +orders.datatime AS DataOrder, +orders.*, materials.id AS materialid, pm.count*op.count AS count FROM orders INNER JOIN order_products AS op ON orders.id = op.orderid INNER JOIN products ON op.productid = products.id