From 9dee2a70272960fea32f7be07102f4e636b1e062 Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 21:09:46 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectAtelier/Entities/Client.cs | 7 ++++ ProjectAtelier/Entities/Material.cs | 7 ++++ .../Entities/MaterialReplenishment.cs | 15 +++++-- ProjectAtelier/Entities/Order.cs | 23 ++++++++++ ProjectAtelier/Entities/OrderProduct.cs | 2 +- ProjectAtelier/Entities/Product.cs | 27 +++++++++++- ProjectAtelier/Entities/ProductMaterial.cs | 6 +-- ProjectAtelier/Forms/FormClient.cs | 5 +-- ProjectAtelier/Forms/FormClientS.cs | 8 +++- .../FormMaterialReplenishment.Designer.cs | 42 ++++++++++++++----- .../Forms/FormMaterialReplenishment.cs | 13 +++--- ProjectAtelier/Forms/FormMaterialS.cs | 7 +++- .../Forms/FormMaterialSReplenishmentS.cs | 7 +++- ProjectAtelier/Forms/FormOrderS.Designer.cs | 6 +-- ProjectAtelier/Forms/FormOrderS.cs | 8 +++- ProjectAtelier/Forms/FormProductOrder.cs | 4 +- ProjectAtelier/Forms/FormProducts.cs | 7 +++- .../IMaterialReplenishmentRepository.cs | 2 +- .../MaterialReplenishmentRepository.cs | 29 ++++++++++--- ProjectAtelier/Reports/ChartReport.cs | 11 +++-- ProjectAtelier/Reports/DocReport.cs | 4 +- ProjectAtelier/Reports/PdfBuilder.cs | 3 +- ProjectAtelier/Reports/TableReport.cs | 14 +++---- .../Repositories/IOrderMaterialsRepository.cs | 2 +- .../OrderMaterialsRepository.cs | 27 +++++++++--- .../Implementations/OrderRepository.cs | 32 ++++++++++++-- .../Implementations/ProductRepository.cs | 33 +++++++++++++-- .../Implementations/QueryBuilder.cs | 33 +++++++++++++++ 28 files changed, 305 insertions(+), 79 deletions(-) create mode 100644 ProjectAtelier/Repositories/Implementations/QueryBuilder.cs diff --git a/ProjectAtelier/Entities/Client.cs b/ProjectAtelier/Entities/Client.cs index 5519b98..34d17e8 100644 --- a/ProjectAtelier/Entities/Client.cs +++ b/ProjectAtelier/Entities/Client.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,8 +10,14 @@ namespace ProjectAtelier.Entities; public class Client { public int Id { get; set; } + + [DisplayName("Имя клиента")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Телефон клиента")] public string Phone { get; private set; } = string.Empty; + + [DisplayName("Гендер")] public Gender Gender { get; private set; } // Используем flag Gender public static Client CreateEntity(int id, string name, string phone, Gender gender) diff --git a/ProjectAtelier/Entities/Material.cs b/ProjectAtelier/Entities/Material.cs index bd12b00..057a16a 100644 --- a/ProjectAtelier/Entities/Material.cs +++ b/ProjectAtelier/Entities/Material.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,8 +10,14 @@ namespace ProjectAtelier.Entities; public class Material { public int Id { get; private set; } + + [DisplayName("Название материала")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Количество для использования")] public int UseCount { get; private set; } + + [DisplayName("Количество на складе")] public int CountInWareHouse { get; private set; } public static Material CreateEntity(int id, string name,int usecount, int countInWarehouse) { diff --git a/ProjectAtelier/Entities/MaterialReplenishment.cs b/ProjectAtelier/Entities/MaterialReplenishment.cs index 65fa020..d5ce389 100644 --- a/ProjectAtelier/Entities/MaterialReplenishment.cs +++ b/ProjectAtelier/Entities/MaterialReplenishment.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,13 +9,19 @@ namespace ProjectAtelier.Entities; public class MaterialReplenishment { public int Id { get; private set; } - + + + [DisplayName("Количество")] public int Count { get; private set; } + + [DisplayName("Дата пополнения")] public DateTime DataTime { get; private set; } - 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 { @@ -22,7 +29,7 @@ public class MaterialReplenishment Count = count, DataTime = dataTime, - IDMaterial = idmaterial + Name = name }; } diff --git a/ProjectAtelier/Entities/Order.cs b/ProjectAtelier/Entities/Order.cs index 3df3220..5caa556 100644 --- a/ProjectAtelier/Entities/Order.cs +++ b/ProjectAtelier/Entities/Order.cs @@ -1,15 +1,31 @@ using System; using System.Collections.Generic; +using System.ComponentModel; namespace ProjectAtelier.Entities; public class Order { public int Id { get; private set; } + + [DisplayName("Дата заказа")] public DateTime DataTime { get; private set; } + + [DisplayName("Статус заказа")] public OrderStatus Status { get; private set; } + + [DisplayName("Характеристика")] public string Characteristic { get; private set; } = string.Empty; + + + [DisplayName("Изделия")] + public string Products => OrderProduct != null ? + string.Join(", ", OrderProduct.Select(x => $"{x.ProductName} {x.Count}")) : string.Empty; + + [Browsable(false)] public IEnumerable OrderProduct { get; private set; } = []; + + [DisplayName("Номер(id) клиента")] public int IdClient { get; private set; } public static Order CreateOperation(int id, OrderStatus status, string characteristic, IEnumerable orderProduct, int idClient, DateTime dateTime) @@ -24,4 +40,11 @@ public class Order IdClient = idClient }; } + public void SetProductMaterial(IEnumerable orderProduct) + { + if (orderProduct != null && orderProduct.Any()) + { + OrderProduct = orderProduct; + } + } } \ No newline at end of file diff --git a/ProjectAtelier/Entities/OrderProduct.cs b/ProjectAtelier/Entities/OrderProduct.cs index 340fd82..bb02553 100644 --- a/ProjectAtelier/Entities/OrderProduct.cs +++ b/ProjectAtelier/Entities/OrderProduct.cs @@ -10,7 +10,7 @@ namespace ProjectAtelier.Entities; { public int Id { get; private set; } public int ProductId { get; private set; } - + public string ProductName { get; private set; } = string.Empty; public int Count { get; private set; } public static OrderProduct CreateOperation(int id, int productId, int count) { diff --git a/ProjectAtelier/Entities/Product.cs b/ProjectAtelier/Entities/Product.cs index f845731..c344178 100644 --- a/ProjectAtelier/Entities/Product.cs +++ b/ProjectAtelier/Entities/Product.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,23 +10,45 @@ namespace ProjectAtelier.Entities; public class Product { public int Id { get; set; } + + [DisplayName("Название")] public string Name { get; set; } = string.Empty; - + + [DisplayName("Вид")] public ProductView View{ get; set; } + + public string FullProductName => $"{Name} {View}"; + + [DisplayName("Количество ")] public int CountMaterial { get; set; } + + + [DisplayName("Материалы")] + public string Products => ProductMaterial != null ? + string.Join(", ", ProductMaterial.Select(x => $"{x.MaterialName} {x.Count}")) : string.Empty; + + [Browsable(false)] public IEnumerable ProductMaterial { get; set; } = []; + + public static Product CreateEntity(int id, string name, ProductView view, int countmaterial, IEnumerable productMaterial) { return new Product { Id = id, Name = name, - View = view, CountMaterial = countmaterial, ProductMaterial = productMaterial }; } + public void SetProductMaterial(IEnumerable productMaterial) + { + if (productMaterial != null && productMaterial.Any()) + { + ProductMaterial = productMaterial; + } + } } diff --git a/ProjectAtelier/Entities/ProductMaterial.cs b/ProjectAtelier/Entities/ProductMaterial.cs index 1fe1c77..71c4c4e 100644 --- a/ProjectAtelier/Entities/ProductMaterial.cs +++ b/ProjectAtelier/Entities/ProductMaterial.cs @@ -9,16 +9,16 @@ namespace ProjectAtelier.Entities; public class ProductMaterial { public int Id { get; private set; } - //public int ProductId { get; private set; } + public int MaterialId { get; set; } + public string MaterialName { get; private set; } = string.Empty; public int Count { get; set; } - public static ProductMaterial CreateOperation(int id, /*int productId*/ int materialid, int count) + public static ProductMaterial CreateOperation(int id, int materialid, int count) { return new ProductMaterial { Id = id, - //ProductId = productId, MaterialId = materialid, Count = count }; diff --git a/ProjectAtelier/Forms/FormClient.cs b/ProjectAtelier/Forms/FormClient.cs index 0e509a4..4d4d216 100644 --- a/ProjectAtelier/Forms/FormClient.cs +++ b/ProjectAtelier/Forms/FormClient.cs @@ -29,10 +29,7 @@ namespace ProjectAtelier.Forms { throw new InvalidDataException(nameof(client)); } - //textBoxName.Text = client.Name; - //textBoxPhone.Text = client.Phone; - //SetCheckedListBoxGender(client.Gender); // Устанавливаем выбранные элементы - //_clientId = value;/////////////////////////////// + foreach (Gender elem in Enum.GetValues(typeof(Gender))) { if ((elem & client.Gender) != 0) diff --git a/ProjectAtelier/Forms/FormClientS.cs b/ProjectAtelier/Forms/FormClientS.cs index aeef57c..7ec7ec9 100644 --- a/ProjectAtelier/Forms/FormClientS.cs +++ b/ProjectAtelier/Forms/FormClientS.cs @@ -1,4 +1,5 @@ using ProjectAtelier.Repositories; +using ProjectAtelier.Repositories.Implementations; using Unity; namespace ProjectAtelier.Forms @@ -76,7 +77,12 @@ namespace ProjectAtelier.Forms MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void LoadList() => dataGridView.DataSource = _clientRepository.ReadClients(); + + private void LoadList() + { + dataGridView.DataSource = _clientRepository.ReadClients(); + dataGridView.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs index d37af7c..32692bf 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(); + label4 = new Label(); + textBoxName = new TextBox(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // // label2 // label2.AutoSize = true; - label2.Location = new Point(77, 130); + label2.Location = new Point(28, 201); 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, 201); numericUpDownCount.Name = "numericUpDownCount"; numericUpDownCount.Size = new Size(150, 27); numericUpDownCount.TabIndex = 3; // // buttonAdd // - buttonAdd.Location = new Point(77, 197); + buttonAdd.Location = new Point(77, 280); 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(227, 280); 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(210, 136); 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(28, 139); label1.Name = "label1"; - label1.Size = new Size(103, 20); + label1.Size = new Size(78, 20); label1.TabIndex = 7; - label1.Text = "ID материала"; + label1.Text = "Материал"; // // dateTimePicker // @@ -104,17 +106,35 @@ // label3 // label3.AutoSize = true; - label3.Location = new Point(77, 33); + label3.Location = new Point(28, 31); label3.Name = "label3"; label3.Size = new Size(41, 20); label3.TabIndex = 9; label3.Text = "Дата"; // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(28, 93); + label4.Name = "label4"; + label4.Size = new Size(156, 20); + label4.TabIndex = 10; + label4.Text = "Название материала"; + // + // textBoxName + // + textBoxName.Location = new Point(210, 86); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(151, 27); + textBoxName.TabIndex = 11; + // // FormMaterialReplenishment // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(411, 273); + 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 c242774..d92b31b 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.cs @@ -16,7 +16,7 @@ namespace ProjectAtelier.Forms public partial class FormMaterialReplenishment : Form { private readonly IMaterialReplenishmentRepository _materialReplenishmentRepository; - private readonly IMaterialRepository _materialRepository; // Добавляем репозиторий для материалов + private readonly IMaterialRepository _materialRepository; private int? _materialReplenishmentId; public int Id @@ -30,10 +30,11 @@ 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 +59,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); } private void ButtonAdd_Click_1(object sender, EventArgs e) diff --git a/ProjectAtelier/Forms/FormMaterialS.cs b/ProjectAtelier/Forms/FormMaterialS.cs index f7a8ecb..4e81261 100644 --- a/ProjectAtelier/Forms/FormMaterialS.cs +++ b/ProjectAtelier/Forms/FormMaterialS.cs @@ -85,7 +85,12 @@ namespace ProjectAtelier.Forms MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void LoadList() => dataGridView.DataSource = _materialRepository.ReadMaterials(); + + private void LoadList() + { + dataGridView.DataSource = _materialRepository.ReadMaterials(); + dataGridView.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectAtelier/Forms/FormMaterialSReplenishmentS.cs b/ProjectAtelier/Forms/FormMaterialSReplenishmentS.cs index a0e8034..d46bff0 100644 --- a/ProjectAtelier/Forms/FormMaterialSReplenishmentS.cs +++ b/ProjectAtelier/Forms/FormMaterialSReplenishmentS.cs @@ -64,7 +64,12 @@ namespace ProjectAtelier.Forms MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void LoadList() => dataGridView.DataSource = _materialSpentRepository.ReadMaterialsSpent(); + private void LoadList() + { + dataGridView.DataSource = _materialSpentRepository.ReadMaterialsSpent(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["DataTime"].DefaultCellStyle.Format = "dd MMMM yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectAtelier/Forms/FormOrderS.Designer.cs b/ProjectAtelier/Forms/FormOrderS.Designer.cs index 6a8e8d7..cc4ce30 100644 --- a/ProjectAtelier/Forms/FormOrderS.Designer.cs +++ b/ProjectAtelier/Forms/FormOrderS.Designer.cs @@ -53,7 +53,7 @@ dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(706, 511); + dataGridView.Size = new Size(706, 534); dataGridView.TabIndex = 2; // // panel @@ -61,7 +61,7 @@ panel.Anchor = AnchorStyles.Right; panel.Controls.Add(ButtonRemove); panel.Controls.Add(ButtonAdd); - panel.Location = new Point(712, 0); + panel.Location = new Point(711, 12); panel.Name = "panel"; panel.Size = new Size(186, 511); panel.TabIndex = 4; @@ -92,7 +92,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(901, 511); + ClientSize = new Size(900, 534); Controls.Add(panel); Controls.Add(dataGridView); Name = "FormOrderS"; diff --git a/ProjectAtelier/Forms/FormOrderS.cs b/ProjectAtelier/Forms/FormOrderS.cs index 28e88d6..37ce20d 100644 --- a/ProjectAtelier/Forms/FormOrderS.cs +++ b/ProjectAtelier/Forms/FormOrderS.cs @@ -57,7 +57,13 @@ namespace ProjectAtelier.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["DataTime"].DefaultCellStyle.Format = "dd MMMM yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectAtelier/Forms/FormProductOrder.cs b/ProjectAtelier/Forms/FormProductOrder.cs index ba7844a..a4000a7 100644 --- a/ProjectAtelier/Forms/FormProductOrder.cs +++ b/ProjectAtelier/Forms/FormProductOrder.cs @@ -27,12 +27,12 @@ namespace ProjectAtelier.Forms comboBoxClient.ValueMember = "Id"; ColumProduct.DataSource = productRepository.ReadProducts(); - ColumProduct.DisplayMember = "View"; + ColumProduct.DisplayMember = "FullProductName"; ColumProduct.ValueMember = "Id"; // Инициализация DateTimePicker dateTimePicker.Format = DateTimePickerFormat.Custom; - dateTimePicker.CustomFormat = "yyyy-MM-dd HH:mm:ss"; + dateTimePicker.CustomFormat = "yyyy-MM-dd "; dateTimePicker.Value = DateTime.Now; // Устанавливаем текущую дату и время по умолчанию diff --git a/ProjectAtelier/Forms/FormProducts.cs b/ProjectAtelier/Forms/FormProducts.cs index c4321b5..8e8d494 100644 --- a/ProjectAtelier/Forms/FormProducts.cs +++ b/ProjectAtelier/Forms/FormProducts.cs @@ -84,7 +84,12 @@ namespace ProjectAtelier.Forms MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void LoadList() => dataGridView.DataSource = _productRepository.ReadProducts(); + private void LoadList() + { + dataGridView.DataSource = _productRepository.ReadProducts(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FullProductName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs b/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs index 69ed20e..561097d 100644 --- a/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs +++ b/ProjectAtelier/REPOSITORY/IMaterialReplenishmentRepository.cs @@ -9,7 +9,7 @@ namespace ProjectAtelier.REPOSITORY; public interface IMaterialReplenishmentRepository { - IEnumerable ReadMaterialsSpent(); + IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? nameMaterial = 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 b617e6d..c2f69c4 100644 --- a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs +++ b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Npgsql; using ProjectAtelier.Entities; using ProjectAtelier.Repositories; +using ProjectAtelier.Repositories.Implementations; using System; using System.Collections.Generic; using System.Linq; @@ -29,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) @@ -63,14 +64,30 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository throw; } } - public IEnumerable ReadMaterialsSpent() + public IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? nameMaterial = null) { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("DataTime >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("DataTime <= @dateTo"); + } + if (nameMaterial != null) + { + builder.AddCondition("Name = @nameMaterial"); + } + _logger.LogInformation("Получение всех объектов"); try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM MaterialReplenishment"; - var materials = connection.Query(querySelect); + var querySelect = @$" + SELECT * FROM MaterialReplenishment + {builder.Build()}"; + var materials = connection.Query(querySelect, new { dateForm, dateTo, nameMaterial }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials)); return materials; } @@ -93,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 db0c5cb..a216a67 100644 --- a/ProjectAtelier/Reports/ChartReport.cs +++ b/ProjectAtelier/Reports/ChartReport.cs @@ -20,7 +20,7 @@ class ChartReport { new PdfBuilder(filePath) .AddHeader("Пополенение материала") - .AddPieChart("Виды материалов", GetData(dateTime)) + .AddPieChart($"Пополнение материала на {dateTime:dd MMMM yyyy}", GetData(dateTime)) .Build(); return true; } @@ -33,10 +33,9 @@ class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { 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) }) - .Select(x => (x.Id.ToString(), (double)x.Count)) - .ToList(); + .ReadMaterialsSpent(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1)) + .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/DocReport.cs b/ProjectAtelier/Reports/DocReport.cs index b7a75bb..ac575bf 100644 --- a/ProjectAtelier/Reports/DocReport.cs +++ b/ProjectAtelier/Reports/DocReport.cs @@ -65,7 +65,7 @@ internal class DocReport private List GetMaterials() { return [ - ["Название", "Используемое количество ", "Количество на складе"], + ["Название материала", "Используемое количество ", "Количество на складе"], .. _materialRepository .ReadMaterials() .Select(x => new string[] { x.Name, x.UseCount.ToString(), x.CountInWareHouse.ToString() }), @@ -74,7 +74,7 @@ internal class DocReport private List GetClients() { return [ - ["Название", "Телефон", "Гендер"], + ["Имя клиента", "Телефон", "Гендер"], .. _clientRepository .ReadClients() .Select(x => new string[] { x.Name, x.Phone.ToString(), x.Gender.ToString() }), diff --git a/ProjectAtelier/Reports/PdfBuilder.cs b/ProjectAtelier/Reports/PdfBuilder.cs index 902aa91..f660f27 100644 --- a/ProjectAtelier/Reports/PdfBuilder.cs +++ b/ProjectAtelier/Reports/PdfBuilder.cs @@ -11,6 +11,7 @@ internal class PdfBuilder { private readonly string _filePath; private readonly Document _document; + public PdfBuilder(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) @@ -74,4 +75,4 @@ internal class PdfBuilder headerStyle.Font.Bold = true; headerStyle.Font.Size = 14; } -} +} \ No newline at end of file diff --git a/ProjectAtelier/Reports/TableReport.cs b/ProjectAtelier/Reports/TableReport.cs index 3674429..f077ff2 100644 --- a/ProjectAtelier/Reports/TableReport.cs +++ b/ProjectAtelier/Reports/TableReport.cs @@ -32,7 +32,7 @@ internal class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по движению материала", 0, 3) - .AddParagraph("за период", 0) + .AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0) .AddTable([10, 15, 15], GetData(materialId, startDate, endDate)) .Build(); return true; @@ -47,23 +47,19 @@ internal class TableReport private List GetData(int materialId, DateTime startDate, DateTime endDate) { var data = _materialReplenishmentRepository - .ReadMaterialsSpent() - .Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.IDMaterial == materialId) + .ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, nameMaterial: _materialRepository.ReadMaterialById(materialId).Name) .Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null }) .Union( _orderMaterialsRepository - .ReadOrders(materialId) - .Where(x => x.DataOrder >= startDate && x.DataOrder <= endDate) + .ReadOrders(dateForm: startDate, dateTo: endDate, matid: materialId) .Select(x => new { Date = x.DataOrder, CountIn = (int?)null, CountOut = (int?)x.Count })) .OrderBy(x => x.Date); return new List() { item } .Union( data - .Select(x => new string[] { x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.CountIn?.ToString("N0") ?? string.Empty, x.CountOut?.ToString("N0") ?? string.Empty })) .Union( - [["Всего", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) + [["Всего", data.Sum(x => x.CountIn ?? 0).ToString("N0"), data.Sum(x => x.CountOut ?? 0).ToString("N0")]]) .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/IOrderMaterialsRepository.cs b/ProjectAtelier/Repositories/IOrderMaterialsRepository.cs index c438029..2c37acf 100644 --- a/ProjectAtelier/Repositories/IOrderMaterialsRepository.cs +++ b/ProjectAtelier/Repositories/IOrderMaterialsRepository.cs @@ -9,5 +9,5 @@ namespace ProjectAtelier.Repositories; public interface IOrderMaterialsRepository { - IEnumerable ReadOrders(int id); + IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? matid = null); } \ No newline at end of file diff --git a/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs b/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs index 7252b54..3204078 100644 --- a/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs +++ b/ProjectAtelier/Repositories/Implementations/OrderMaterialsRepository.cs @@ -17,18 +17,35 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository _logger = logger; } - public IEnumerable ReadOrders(int matid) + public IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? matid = null) { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("orders.datatime >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("orders.datatime <= @dateTo"); + } + if (matid.HasValue) + { + builder.AddCondition("materialid = @matid"); + } using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @" - SELECT orders.*, materials.id AS materialid, pm.count*op.count AS count + var querySelect = @$" + 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 INNER JOIN product_materials AS pm ON products.id = pm.productid INNER JOIN materials ON pm.materialid = materials.id - Where materials.id = @matid"; - var orderMaterials = connection.Query(querySelect, new { matid }); + {builder.Build()}"; + var orderMaterials = connection.Query(querySelect, new { dateForm, dateTo, matid }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orderMaterials)); return orderMaterials; } diff --git a/ProjectAtelier/Repositories/Implementations/OrderRepository.cs b/ProjectAtelier/Repositories/Implementations/OrderRepository.cs index dca53c1..21ebbfe 100644 --- a/ProjectAtelier/Repositories/Implementations/OrderRepository.cs +++ b/ProjectAtelier/Repositories/Implementations/OrderRepository.cs @@ -81,10 +81,34 @@ public class OrderRepository : IOrderRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM Orders"; - var order = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order)); - return order; + var querySelect = @" + SELECT orders.*, products.id AS productid, products.name AS productname, 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"; + + var productsDict = new Dictionary>(); + + var products = + connection.Query(querySelect, (order, orderProducts) => + { + if (!productsDict.TryGetValue(order.Id, out var frr)) + { + frr = []; + productsDict.Add(order.Id, frr); + } + frr.Add(orderProducts); + return order; + }, splitOn: "productid", param: new { dateForm, dateTo, orderStatus, orderId }); + + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(products)); + + return productsDict.Select(x => + { + var fr = products.First(y => y.Id == x.Key); + fr.SetProductMaterial(x.Value); + return fr; + }).ToArray(); } catch (Exception ex) { diff --git a/ProjectAtelier/Repositories/Implementations/ProductRepository.cs b/ProjectAtelier/Repositories/Implementations/ProductRepository.cs index 87e2ddc..5793b0e 100644 --- a/ProjectAtelier/Repositories/Implementations/ProductRepository.cs +++ b/ProjectAtelier/Repositories/Implementations/ProductRepository.cs @@ -80,10 +80,35 @@ public class ProductRepository : IProductRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM Products"; - var product = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(product)); - return product; + var querySelect = @" + SELECT products.*, materials.id AS materialid, materials.name AS materialname, pm.count AS count + FROM products + INNER JOIN product_materials AS pm ON products.id = pm.productid + INNER JOIN materials ON pm.materialid = materials.id"; + + var materialsDict = new Dictionary>(); + + var materials = + connection.Query(querySelect, (product, productsMaterials) => + { + if (!materialsDict.TryGetValue(product.Id, out var frr)) + { + frr = []; + materialsDict.Add(product.Id, frr); + } + frr.Add(productsMaterials); + return product; + }, splitOn: "materialid"); + + + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials)); + + return materialsDict.Select(x => + { + var fr = materials.First(y => y.Id == x.Key); + fr.SetProductMaterial(x.Value); + return fr; + }).ToArray(); } catch (Exception ex) { diff --git a/ProjectAtelier/Repositories/Implementations/QueryBuilder.cs b/ProjectAtelier/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..98f99ee --- /dev/null +++ b/ProjectAtelier/Repositories/Implementations/QueryBuilder.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAtelier.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}"; + } +} -- 2.25.1 From 9b07eaa4c8bd8539f2d788c6e82ab4d728040dcf Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 21:31:51 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=203=20=D0=BB=D0=B0=D0=B1=D1=83,?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=8D=D0=BE=D1=82=D0=BC=D1=83=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D1=8F=D0=B5=D0=BC=20=D1=82=D0=BE,=20=D1=87=D1=82?= =?UTF-8?q?=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8,=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=BC=20=D0=B2=D0=B5=D1=80=D0=BD=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectAtelier/Entities/MaterialReplenishment.cs | 6 +++--- ProjectAtelier/Forms/FormMaterialReplenishment.cs | 10 +++++----- .../REPOSITORY/IMaterialReplenishmentRepository.cs | 2 +- .../MaterialReplenishmentRepository.cs | 14 +++++++------- ProjectAtelier/Reports/ChartReport.cs | 2 +- ProjectAtelier/Reports/TableReport.cs | 2 +- .../Implementations/OrderMaterialsRepository.cs | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) 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 -- 2.25.1 From 5c03e7047898553e944922e39450f2749b19f41a Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 21:36:27 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A2=D0=9E=D0=96=D0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMaterialReplenishment.Designer.cs | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs index 32692bf..d3955ab 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs @@ -36,8 +36,6 @@ label1 = new Label(); dateTimePicker = new DateTimePicker(); label3 = new Label(); - label4 = new Label(); - textBoxName = new TextBox(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // @@ -82,7 +80,7 @@ // comboBoxMaterial // comboBoxMaterial.FormattingEnabled = true; - comboBoxMaterial.Location = new Point(210, 136); + comboBoxMaterial.Location = new Point(211, 125); comboBoxMaterial.Name = "comboBoxMaterial"; comboBoxMaterial.Size = new Size(151, 28); comboBoxMaterial.TabIndex = 6; @@ -90,7 +88,7 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(28, 139); + label1.Location = new Point(28, 125); label1.Name = "label1"; label1.Size = new Size(78, 20); label1.TabIndex = 7; @@ -112,29 +110,11 @@ label3.TabIndex = 9; label3.Text = "Дата"; // - // label4 - // - label4.AutoSize = true; - label4.Location = new Point(28, 93); - label4.Name = "label4"; - label4.Size = new Size(156, 20); - label4.TabIndex = 10; - label4.Text = "Название материала"; - // - // textBoxName - // - textBoxName.Location = new Point(210, 86); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(151, 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); @@ -164,7 +144,5 @@ private Label label1; private DateTimePicker dateTimePicker; private Label label3; - private Label label4; - private TextBox textBoxName; } } \ No newline at end of file -- 2.25.1 From cdaf425319834279a9778a791b2a2f9acd708208 Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 22:34:35 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8(=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B8=D1=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormMaterialReplenishment.Designer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs index 4ccf41a..c25cfa8 100644 --- a/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs +++ b/ProjectAtelier/Forms/FormMaterialReplenishment.Designer.cs @@ -44,7 +44,7 @@ // label2 // label2.AutoSize = true; - label2.Location = new Point(73, 186); + label2.Location = new Point(28, 186); label2.Name = "label2"; label2.Size = new Size(90, 20); label2.TabIndex = 1; @@ -90,7 +90,7 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(73, 135); + label1.Location = new Point(24, 145); label1.Name = "label1"; label1.Size = new Size(78, 20); label1.TabIndex = 7; @@ -106,7 +106,7 @@ // label3 // label3.AutoSize = true; - label3.Location = new Point(77, 33); + label3.Location = new Point(28, 31); label3.Name = "label3"; label3.Size = new Size(41, 20); label3.TabIndex = 9; @@ -122,7 +122,7 @@ // label4 // label4.AutoSize = true; - label4.Location = new Point(77, 85); + label4.Location = new Point(24, 85); label4.Name = "label4"; label4.Size = new Size(156, 20); label4.TabIndex = 11; -- 2.25.1 From 894c3a3485d5446e6421f7d27d5a2a6b786a06ef Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 19 Dec 2024 23:02:25 +0300 Subject: [PATCH 5/6] =?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 -- 2.25.1 From c5759f33e94f6709b544063ea31d5c661a2c191e Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Fri, 20 Dec 2024 10:59:30 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=BD=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectAtelier/Entities/Order.cs | 5 ++++- .../Implementations/MaterialReplenishmentRepository.cs | 6 +++--- ProjectAtelier/Reports/ExcelBuilder.cs | 5 +++-- ProjectAtelier/Reports/TableReport.cs | 5 +++-- .../Repositories/Implementations/OrderRepository.cs | 7 +++++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ProjectAtelier/Entities/Order.cs b/ProjectAtelier/Entities/Order.cs index 5caa556..f8f6e92 100644 --- a/ProjectAtelier/Entities/Order.cs +++ b/ProjectAtelier/Entities/Order.cs @@ -25,8 +25,11 @@ public class Order [Browsable(false)] public IEnumerable OrderProduct { get; private set; } = []; - [DisplayName("Номер(id) клиента")] + + [Browsable(false)] public int IdClient { get; private set; } + [DisplayName("Имя клиента")] + public string NameClient { get; private set; } = string.Empty; public static Order CreateOperation(int id, OrderStatus status, string characteristic, IEnumerable orderProduct, int idClient, DateTime dateTime) { diff --git a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs index 6bf888c..5e66d89 100644 --- a/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs +++ b/ProjectAtelier/REPOSITORY/Implementations/MaterialReplenishmentRepository.cs @@ -66,10 +66,10 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository } public IEnumerable ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? materialName = null) { - var builder = new QueryBuilder(); - if (dateForm.HasValue) + var builder = new QueryBuilder(); + if (dateForm.HasValue) { - builder.AddCondition("DataTime >= @dateForm"); + builder.AddCondition("DataTime >= @dateForm"); } if (dateTo.HasValue) { diff --git a/ProjectAtelier/Reports/ExcelBuilder.cs b/ProjectAtelier/Reports/ExcelBuilder.cs index 30862d4..9274f57 100644 --- a/ProjectAtelier/Reports/ExcelBuilder.cs +++ b/ProjectAtelier/Reports/ExcelBuilder.cs @@ -34,14 +34,15 @@ internal class ExcelBuilder _rowIndex = 1; } - public ExcelBuilder AddHeader(string header, int startIndex, int count) + public ExcelBuilder AddHeader(string headerPrefix, string materialName, int startIndex, int count) { + string header = $"{headerPrefix}{materialName}"; CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder); for (int i = startIndex + 1; i < startIndex + count; ++i) { CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); } - + _mergeCells.Append(new MergeCell() { Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}") diff --git a/ProjectAtelier/Reports/TableReport.cs b/ProjectAtelier/Reports/TableReport.cs index 520d41a..90bd4db 100644 --- a/ProjectAtelier/Reports/TableReport.cs +++ b/ProjectAtelier/Reports/TableReport.cs @@ -30,9 +30,10 @@ internal class TableReport { try { + var materialName = _materialRepository.ReadMaterialById(materialId).Name; new ExcelBuilder(filePath) - .AddHeader("Сводка по движению материала", 0, 3) - .AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0) + .AddHeader("Сводка по движению материала- ", materialName, 0, 3) + .AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0) .AddTable([10, 15, 15], GetData(materialId, startDate, endDate)) .Build(); return true; diff --git a/ProjectAtelier/Repositories/Implementations/OrderRepository.cs b/ProjectAtelier/Repositories/Implementations/OrderRepository.cs index 21ebbfe..bcf4288 100644 --- a/ProjectAtelier/Repositories/Implementations/OrderRepository.cs +++ b/ProjectAtelier/Repositories/Implementations/OrderRepository.cs @@ -1,4 +1,5 @@ using Dapper; +using DocumentFormat.OpenXml.Drawing; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; @@ -82,10 +83,12 @@ public class OrderRepository : IOrderRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @" - SELECT orders.*, products.id AS productid, products.name AS productname, op.count AS count + SELECT orders.*, clients.name AS NameClient, products.id AS productid, products.name AS productname, 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"; + INNER JOIN products ON op.productid = products.id + + INNER JOIN clients ON orders.idclient = clients.id"; var productsDict = new Dictionary>(); -- 2.25.1