ИСЭбд-21.Васильева.С.В. 4 лабораторная работа #4
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,8 +10,14 @@ namespace ProjectAtelier.Entities;
|
|||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя клиента")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Телефон клиента")]
|
||||||
public string Phone { get; private set; } = string.Empty;
|
public string Phone { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Гендер")]
|
||||||
public Gender Gender { get; private set; } // Используем flag Gender
|
public Gender Gender { get; private set; } // Используем flag Gender
|
||||||
|
|
||||||
public static Client CreateEntity(int id, string name, string phone, Gender gender)
|
public static Client CreateEntity(int id, string name, string phone, Gender gender)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,8 +10,14 @@ namespace ProjectAtelier.Entities;
|
|||||||
public class Material
|
public class Material
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название материала")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Количество для использования")]
|
||||||
public int UseCount { get; private set; }
|
public int UseCount { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Количество на складе")]
|
||||||
public int CountInWareHouse { get; private set; }
|
public int CountInWareHouse { get; private set; }
|
||||||
public static Material CreateEntity(int id, string name,int usecount, int countInWarehouse)
|
public static Material CreateEntity(int id, string name,int usecount, int countInWarehouse)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,12 +10,18 @@ public class MaterialReplenishment
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
[DisplayName("Количество")]
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата пополнения")]
|
||||||
public DateTime DataTime { get; private set; }
|
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
|
return new MaterialReplenishment
|
||||||
{
|
{
|
||||||
@ -22,7 +29,7 @@ public class MaterialReplenishment
|
|||||||
|
|
||||||
Count = count,
|
Count = count,
|
||||||
DataTime = dataTime,
|
DataTime = dataTime,
|
||||||
IDMaterial = idmaterial
|
Name = name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,31 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectAtelier.Entities;
|
namespace ProjectAtelier.Entities;
|
||||||
|
|
||||||
public class Order
|
public class Order
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата заказа")]
|
||||||
public DateTime DataTime { get; private set; }
|
public DateTime DataTime { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Статус заказа")]
|
||||||
public OrderStatus Status { get; private set; }
|
public OrderStatus Status { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Характеристика")]
|
||||||
public string Characteristic { get; private set; } = string.Empty;
|
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> OrderProduct { get; private set; } = [];
|
public IEnumerable<OrderProduct> OrderProduct { get; private set; } = [];
|
||||||
|
|
||||||
|
[DisplayName("Номер(id) клиента")]
|
||||||
public int IdClient { get; private set; }
|
public int IdClient { get; private set; }
|
||||||
|
|
||||||
public static Order CreateOperation(int id, OrderStatus status, string characteristic, IEnumerable<OrderProduct> orderProduct, int idClient, DateTime dateTime)
|
public static Order CreateOperation(int id, OrderStatus status, string characteristic, IEnumerable<OrderProduct> orderProduct, int idClient, DateTime dateTime)
|
||||||
@ -24,4 +40,11 @@ public class Order
|
|||||||
IdClient = idClient
|
IdClient = idClient
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public void SetProductMaterial(IEnumerable<OrderProduct> orderProduct)
|
||||||
|
{
|
||||||
|
if (orderProduct != null && orderProduct.Any())
|
||||||
|
{
|
||||||
|
OrderProduct = orderProduct;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ namespace ProjectAtelier.Entities;
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int ProductId { get; private set; }
|
public int ProductId { get; private set; }
|
||||||
|
public string ProductName { get; private set; } = string.Empty;
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
public static OrderProduct CreateOperation(int id, int productId, int count)
|
public static OrderProduct CreateOperation(int id, int productId, int count)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,23 +10,45 @@ namespace ProjectAtelier.Entities;
|
|||||||
public class Product
|
public class Product
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Вид")]
|
||||||
public ProductView View{ get; set; }
|
public ProductView View{ get; set; }
|
||||||
|
|
||||||
|
public string FullProductName => $"{Name} {View}";
|
||||||
|
|
||||||
|
[DisplayName("Количество ")]
|
||||||
public int CountMaterial { get; set; }
|
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> ProductMaterial { get; set; } = [];
|
public IEnumerable<ProductMaterial> ProductMaterial { get; set; } = [];
|
||||||
|
|
||||||
|
|
||||||
public static Product CreateEntity(int id, string name, ProductView view, int countmaterial, IEnumerable<ProductMaterial> productMaterial)
|
public static Product CreateEntity(int id, string name, ProductView view, int countmaterial, IEnumerable<ProductMaterial> productMaterial)
|
||||||
{
|
{
|
||||||
return new Product
|
return new Product
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
||||||
View = view,
|
View = view,
|
||||||
CountMaterial = countmaterial,
|
CountMaterial = countmaterial,
|
||||||
ProductMaterial = productMaterial
|
ProductMaterial = productMaterial
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public void SetProductMaterial(IEnumerable<ProductMaterial> productMaterial)
|
||||||
|
{
|
||||||
|
if (productMaterial != null && productMaterial.Any())
|
||||||
|
{
|
||||||
|
ProductMaterial = productMaterial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,16 +9,16 @@ namespace ProjectAtelier.Entities;
|
|||||||
public class ProductMaterial
|
public class ProductMaterial
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
//public int ProductId { get; private set; }
|
|
||||||
public int MaterialId { get; set; }
|
public int MaterialId { get; set; }
|
||||||
|
public string MaterialName { get; private set; } = string.Empty;
|
||||||
public int Count { get; set; }
|
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
|
return new ProductMaterial
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
//ProductId = productId,
|
|
||||||
MaterialId = materialid,
|
MaterialId = materialid,
|
||||||
Count = count
|
Count = count
|
||||||
};
|
};
|
||||||
|
@ -29,10 +29,7 @@ namespace ProjectAtelier.Forms
|
|||||||
{
|
{
|
||||||
throw new InvalidDataException(nameof(client));
|
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)))
|
foreach (Gender elem in Enum.GetValues(typeof(Gender)))
|
||||||
{
|
{
|
||||||
if ((elem & client.Gender) != 0)
|
if ((elem & client.Gender) != 0)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ProjectAtelier.Repositories;
|
using ProjectAtelier.Repositories;
|
||||||
|
using ProjectAtelier.Repositories.Implementations;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectAtelier.Forms
|
namespace ProjectAtelier.Forms
|
||||||
@ -76,7 +77,12 @@ namespace ProjectAtelier.Forms
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -36,13 +36,15 @@
|
|||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
dateTimePicker = new DateTimePicker();
|
dateTimePicker = new DateTimePicker();
|
||||||
label3 = new Label();
|
label3 = new Label();
|
||||||
|
label4 = new Label();
|
||||||
|
textBoxName = new TextBox();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
label2.Location = new Point(77, 130);
|
label2.Location = new Point(28, 201);
|
||||||
label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
label2.Size = new Size(90, 20);
|
label2.Size = new Size(90, 20);
|
||||||
label2.TabIndex = 1;
|
label2.TabIndex = 1;
|
||||||
@ -50,14 +52,14 @@
|
|||||||
//
|
//
|
||||||
// numericUpDownCount
|
// numericUpDownCount
|
||||||
//
|
//
|
||||||
numericUpDownCount.Location = new Point(212, 123);
|
numericUpDownCount.Location = new Point(212, 201);
|
||||||
numericUpDownCount.Name = "numericUpDownCount";
|
numericUpDownCount.Name = "numericUpDownCount";
|
||||||
numericUpDownCount.Size = new Size(150, 27);
|
numericUpDownCount.Size = new Size(150, 27);
|
||||||
numericUpDownCount.TabIndex = 3;
|
numericUpDownCount.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.Location = new Point(77, 197);
|
buttonAdd.Location = new Point(77, 280);
|
||||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(107, 53);
|
buttonAdd.Size = new Size(107, 53);
|
||||||
@ -68,7 +70,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(231, 197);
|
buttonCancel.Location = new Point(227, 280);
|
||||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Size = new Size(117, 53);
|
buttonCancel.Size = new Size(117, 53);
|
||||||
@ -80,7 +82,7 @@
|
|||||||
// comboBoxMaterial
|
// comboBoxMaterial
|
||||||
//
|
//
|
||||||
comboBoxMaterial.FormattingEnabled = true;
|
comboBoxMaterial.FormattingEnabled = true;
|
||||||
comboBoxMaterial.Location = new Point(210, 76);
|
comboBoxMaterial.Location = new Point(210, 136);
|
||||||
comboBoxMaterial.Name = "comboBoxMaterial";
|
comboBoxMaterial.Name = "comboBoxMaterial";
|
||||||
comboBoxMaterial.Size = new Size(151, 28);
|
comboBoxMaterial.Size = new Size(151, 28);
|
||||||
comboBoxMaterial.TabIndex = 6;
|
comboBoxMaterial.TabIndex = 6;
|
||||||
@ -88,11 +90,11 @@
|
|||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
label1.Location = new Point(77, 76);
|
label1.Location = new Point(28, 139);
|
||||||
label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
label1.Size = new Size(103, 20);
|
label1.Size = new Size(78, 20);
|
||||||
label1.TabIndex = 7;
|
label1.TabIndex = 7;
|
||||||
label1.Text = "ID материала";
|
label1.Text = "Материал";
|
||||||
//
|
//
|
||||||
// dateTimePicker
|
// dateTimePicker
|
||||||
//
|
//
|
||||||
@ -104,17 +106,35 @@
|
|||||||
// label3
|
// label3
|
||||||
//
|
//
|
||||||
label3.AutoSize = true;
|
label3.AutoSize = true;
|
||||||
label3.Location = new Point(77, 33);
|
label3.Location = new Point(28, 31);
|
||||||
label3.Name = "label3";
|
label3.Name = "label3";
|
||||||
label3.Size = new Size(41, 20);
|
label3.Size = new Size(41, 20);
|
||||||
label3.TabIndex = 9;
|
label3.TabIndex = 9;
|
||||||
label3.Text = "Дата";
|
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
|
// FormMaterialReplenishment
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(411, 273);
|
ClientSize = new Size(490, 404);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(label4);
|
||||||
Controls.Add(label3);
|
Controls.Add(label3);
|
||||||
Controls.Add(dateTimePicker);
|
Controls.Add(dateTimePicker);
|
||||||
Controls.Add(label1);
|
Controls.Add(label1);
|
||||||
@ -144,5 +164,7 @@
|
|||||||
private Label label1;
|
private Label label1;
|
||||||
private DateTimePicker dateTimePicker;
|
private DateTimePicker dateTimePicker;
|
||||||
private Label label3;
|
private Label label3;
|
||||||
|
private Label label4;
|
||||||
|
private TextBox textBoxName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ namespace ProjectAtelier.Forms
|
|||||||
public partial class FormMaterialReplenishment : Form
|
public partial class FormMaterialReplenishment : Form
|
||||||
{
|
{
|
||||||
private readonly IMaterialReplenishmentRepository _materialReplenishmentRepository;
|
private readonly IMaterialReplenishmentRepository _materialReplenishmentRepository;
|
||||||
private readonly IMaterialRepository _materialRepository; // Добавляем репозиторий для материалов
|
private readonly IMaterialRepository _materialRepository;
|
||||||
private int? _materialReplenishmentId;
|
private int? _materialReplenishmentId;
|
||||||
|
|
||||||
public int Id
|
public int Id
|
||||||
@ -31,9 +31,10 @@ namespace ProjectAtelier.Forms
|
|||||||
throw new InvalidDataException(nameof(materialReplenishment));
|
throw new InvalidDataException(nameof(materialReplenishment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
textBoxName.Text = materialReplenishment.Name;
|
||||||
|
comboBoxMaterial.Text = materialReplenishment.Name;
|
||||||
numericUpDownCount.Value = materialReplenishment.Count;
|
numericUpDownCount.Value = materialReplenishment.Count;
|
||||||
comboBoxMaterial.SelectedValue = materialReplenishment.IDMaterial; // Устанавливаем выбранный материал
|
|
||||||
dateTimePicker.Value = materialReplenishment.DataTime; // Устанавливаем выбранную дату и время
|
|
||||||
_materialReplenishmentId = value;
|
_materialReplenishmentId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -58,9 +59,9 @@ namespace ProjectAtelier.Forms
|
|||||||
|
|
||||||
private MaterialReplenishment CreateMaterialReplenishment(int id)
|
private MaterialReplenishment CreateMaterialReplenishment(int id)
|
||||||
{
|
{
|
||||||
int selectedMaterialId = (int)comboBoxMaterial.SelectedValue;
|
|
||||||
DateTime selectedDateTime = dateTimePicker.Value;
|
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)
|
private void ButtonAdd_Click_1(object sender, EventArgs e)
|
||||||
|
@ -85,7 +85,12 @@ namespace ProjectAtelier.Forms
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -64,7 +64,12 @@ namespace ProjectAtelier.Forms
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
6
ProjectAtelier/Forms/FormOrderS.Designer.cs
generated
6
ProjectAtelier/Forms/FormOrderS.Designer.cs
generated
@ -53,7 +53,7 @@
|
|||||||
dataGridView.RowHeadersVisible = false;
|
dataGridView.RowHeadersVisible = false;
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView.Size = new Size(706, 511);
|
dataGridView.Size = new Size(706, 534);
|
||||||
dataGridView.TabIndex = 2;
|
dataGridView.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// panel
|
// panel
|
||||||
@ -61,7 +61,7 @@
|
|||||||
panel.Anchor = AnchorStyles.Right;
|
panel.Anchor = AnchorStyles.Right;
|
||||||
panel.Controls.Add(ButtonRemove);
|
panel.Controls.Add(ButtonRemove);
|
||||||
panel.Controls.Add(ButtonAdd);
|
panel.Controls.Add(ButtonAdd);
|
||||||
panel.Location = new Point(712, 0);
|
panel.Location = new Point(711, 12);
|
||||||
panel.Name = "panel";
|
panel.Name = "panel";
|
||||||
panel.Size = new Size(186, 511);
|
panel.Size = new Size(186, 511);
|
||||||
panel.TabIndex = 4;
|
panel.TabIndex = 4;
|
||||||
@ -92,7 +92,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(901, 511);
|
ClientSize = new Size(900, 534);
|
||||||
Controls.Add(panel);
|
Controls.Add(panel);
|
||||||
Controls.Add(dataGridView);
|
Controls.Add(dataGridView);
|
||||||
Name = "FormOrderS";
|
Name = "FormOrderS";
|
||||||
|
@ -57,7 +57,13 @@ namespace ProjectAtelier.Forms
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -27,12 +27,12 @@ namespace ProjectAtelier.Forms
|
|||||||
comboBoxClient.ValueMember = "Id";
|
comboBoxClient.ValueMember = "Id";
|
||||||
|
|
||||||
ColumProduct.DataSource = productRepository.ReadProducts();
|
ColumProduct.DataSource = productRepository.ReadProducts();
|
||||||
ColumProduct.DisplayMember = "View";
|
ColumProduct.DisplayMember = "FullProductName";
|
||||||
ColumProduct.ValueMember = "Id";
|
ColumProduct.ValueMember = "Id";
|
||||||
|
|
||||||
// Инициализация DateTimePicker
|
// Инициализация DateTimePicker
|
||||||
dateTimePicker.Format = DateTimePickerFormat.Custom;
|
dateTimePicker.Format = DateTimePickerFormat.Custom;
|
||||||
dateTimePicker.CustomFormat = "yyyy-MM-dd HH:mm:ss";
|
dateTimePicker.CustomFormat = "yyyy-MM-dd ";
|
||||||
dateTimePicker.Value = DateTime.Now; // Устанавливаем текущую дату и время по умолчанию
|
dateTimePicker.Value = DateTime.Now; // Устанавливаем текущую дату и время по умолчанию
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,7 +84,12 @@ namespace ProjectAtelier.Forms
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -9,7 +9,7 @@ namespace ProjectAtelier.REPOSITORY;
|
|||||||
|
|
||||||
public interface IMaterialReplenishmentRepository
|
public interface IMaterialReplenishmentRepository
|
||||||
{
|
{
|
||||||
IEnumerable<MaterialReplenishment> ReadMaterialsSpent();
|
IEnumerable<MaterialReplenishment> ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? nameMaterial = null);
|
||||||
MaterialReplenishment ReadMaterialSpentById(int id);
|
MaterialReplenishment ReadMaterialSpentById(int id);
|
||||||
void CreateMaterialSpent(MaterialReplenishment material);
|
void CreateMaterialSpent(MaterialReplenishment material);
|
||||||
void UpdateMaterialSpent(MaterialReplenishment material);
|
void UpdateMaterialSpent(MaterialReplenishment material);
|
||||||
|
@ -4,6 +4,7 @@ using Newtonsoft.Json;
|
|||||||
using Npgsql;
|
using Npgsql;
|
||||||
using ProjectAtelier.Entities;
|
using ProjectAtelier.Entities;
|
||||||
using ProjectAtelier.Repositories;
|
using ProjectAtelier.Repositories;
|
||||||
|
using ProjectAtelier.Repositories.Implementations;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -29,8 +30,8 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
|
|||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO MaterialReplenishment (Count, DataTime, IDMaterial)
|
INSERT INTO MaterialReplenishment (Count, DataTime, Name)
|
||||||
VALUES (@Count, @DataTime, @IDMaterial)";
|
VALUES (@Count, @DataTime, @Name)";
|
||||||
connection.Execute(queryInsert, material);
|
connection.Execute(queryInsert, material);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -63,14 +64,30 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<MaterialReplenishment> ReadMaterialsSpent()
|
public IEnumerable<MaterialReplenishment> 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("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM MaterialReplenishment";
|
var querySelect = @$"
|
||||||
var materials = connection.Query<MaterialReplenishment>(querySelect);
|
SELECT * FROM MaterialReplenishment
|
||||||
|
{builder.Build()}";
|
||||||
|
var materials = connection.Query<MaterialReplenishment>(querySelect, new { dateForm, dateTo, nameMaterial });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials));
|
||||||
return materials;
|
return materials;
|
||||||
}
|
}
|
||||||
@ -93,7 +110,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
|
|||||||
SET
|
SET
|
||||||
Count=@Count,
|
Count=@Count,
|
||||||
DataTime=@DataTime,
|
DataTime=@DataTime,
|
||||||
IDMaterial=@IDMaterial
|
Name=@Name
|
||||||
WHERE Id=@Id";
|
WHERE Id=@Id";
|
||||||
connection.Execute(queryUpdate, material);
|
connection.Execute(queryUpdate, material);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Пополенение материала")
|
.AddHeader("Пополенение материала")
|
||||||
.AddPieChart("Виды материалов", GetData(dateTime))
|
.AddPieChart($"Пополнение материала на {dateTime:dd MMMM yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -33,9 +33,8 @@ class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _materialReplenishmentRepository
|
return _materialReplenishmentRepository
|
||||||
.ReadMaterialsSpent()
|
.ReadMaterialsSpent(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.DataTime.Date == dateTime.Date)
|
.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))
|
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ internal class DocReport
|
|||||||
private List<string[]> GetMaterials()
|
private List<string[]> GetMaterials()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["Название", "Используемое количество ", "Количество на складе"],
|
["Название материала", "Используемое количество ", "Количество на складе"],
|
||||||
.. _materialRepository
|
.. _materialRepository
|
||||||
.ReadMaterials()
|
.ReadMaterials()
|
||||||
.Select(x => new string[] { x.Name, x.UseCount.ToString(), x.CountInWareHouse.ToString() }),
|
.Select(x => new string[] { x.Name, x.UseCount.ToString(), x.CountInWareHouse.ToString() }),
|
||||||
@ -74,7 +74,7 @@ internal class DocReport
|
|||||||
private List<string[]> GetClients()
|
private List<string[]> GetClients()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["Название", "Телефон", "Гендер"],
|
["Имя клиента", "Телефон", "Гендер"],
|
||||||
.. _clientRepository
|
.. _clientRepository
|
||||||
.ReadClients()
|
.ReadClients()
|
||||||
.Select(x => new string[] { x.Name, x.Phone.ToString(), x.Gender.ToString() }),
|
.Select(x => new string[] { x.Name, x.Phone.ToString(), x.Gender.ToString() }),
|
||||||
|
@ -11,6 +11,7 @@ internal class PdfBuilder
|
|||||||
{
|
{
|
||||||
private readonly string _filePath;
|
private readonly string _filePath;
|
||||||
private readonly Document _document;
|
private readonly Document _document;
|
||||||
|
|
||||||
public PdfBuilder(string filePath)
|
public PdfBuilder(string filePath)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(filePath))
|
if (string.IsNullOrWhiteSpace(filePath))
|
||||||
|
@ -32,7 +32,7 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по движению материала", 0, 3)
|
.AddHeader("Сводка по движению материала", 0, 3)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 15, 15], GetData(materialId, startDate, endDate))
|
.AddTable([10, 15, 15], GetData(materialId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -47,23 +47,19 @@ internal class TableReport
|
|||||||
private List<string[]> GetData(int materialId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int materialId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _materialReplenishmentRepository
|
var data = _materialReplenishmentRepository
|
||||||
.ReadMaterialsSpent()
|
.ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, nameMaterial: _materialRepository.ReadMaterialById(materialId).Name)
|
||||||
.Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.IDMaterial == materialId)
|
|
||||||
.Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null })
|
.Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null })
|
||||||
.Union(
|
.Union(
|
||||||
_orderMaterialsRepository
|
_orderMaterialsRepository
|
||||||
.ReadOrders(materialId)
|
.ReadOrders(dateForm: startDate, dateTo: endDate, matid: materialId)
|
||||||
.Where(x => x.DataOrder >= startDate && x.DataOrder <= endDate)
|
|
||||||
.Select(x => new { Date = x.DataOrder, CountIn = (int?)null, CountOut = (int?)x.Count }))
|
.Select(x => new { Date = x.DataOrder, CountIn = (int?)null, CountOut = (int?)x.Count }))
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date);
|
||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(
|
.Union(
|
||||||
data
|
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(
|
.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();
|
.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 })
|
|
@ -9,5 +9,5 @@ namespace ProjectAtelier.Repositories;
|
|||||||
|
|
||||||
public interface IOrderMaterialsRepository
|
public interface IOrderMaterialsRepository
|
||||||
{
|
{
|
||||||
IEnumerable<TempOrder> ReadOrders(int id);
|
IEnumerable<TempOrder> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? matid = null);
|
||||||
}
|
}
|
@ -17,18 +17,35 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TempOrder> ReadOrders(int matid)
|
public IEnumerable<TempOrder> 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);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
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
|
FROM orders
|
||||||
INNER JOIN order_products AS op ON orders.id = op.orderid
|
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 product_materials AS pm ON products.id = pm.productid
|
INNER JOIN product_materials AS pm ON products.id = pm.productid
|
||||||
INNER JOIN materials ON pm.materialid = materials.id
|
INNER JOIN materials ON pm.materialid = materials.id
|
||||||
Where materials.id = @matid";
|
{builder.Build()}";
|
||||||
var orderMaterials = connection.Query<TempOrder>(querySelect, new { matid });
|
var orderMaterials = connection.Query<TempOrder>(querySelect, new { dateForm, dateTo, matid });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orderMaterials));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orderMaterials));
|
||||||
return orderMaterials;
|
return orderMaterials;
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,34 @@ public class OrderRepository : IOrderRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT * FROM Orders";
|
var querySelect = @"
|
||||||
var order = connection.Query<Order>(querySelect);
|
SELECT orders.*, products.id AS productid, products.name AS productname, op.count AS count
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order));
|
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<int, List<OrderProduct>>();
|
||||||
|
|
||||||
|
var products =
|
||||||
|
connection.Query<Order, OrderProduct, Order>(querySelect, (order, orderProducts) =>
|
||||||
|
{
|
||||||
|
if (!productsDict.TryGetValue(order.Id, out var frr))
|
||||||
|
{
|
||||||
|
frr = [];
|
||||||
|
productsDict.Add(order.Id, frr);
|
||||||
|
}
|
||||||
|
frr.Add(orderProducts);
|
||||||
return order;
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -80,10 +80,35 @@ public class ProductRepository : IProductRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT * FROM Products";
|
var querySelect = @"
|
||||||
var product = connection.Query<Product>(querySelect);
|
SELECT products.*, materials.id AS materialid, materials.name AS materialname, pm.count AS count
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(product));
|
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<int, List<ProductMaterial>>();
|
||||||
|
|
||||||
|
var materials =
|
||||||
|
connection.Query<Product, ProductMaterial, Product>(querySelect, (product, productsMaterials) =>
|
||||||
|
{
|
||||||
|
if (!materialsDict.TryGetValue(product.Id, out var frr))
|
||||||
|
{
|
||||||
|
frr = [];
|
||||||
|
materialsDict.Add(product.Id, frr);
|
||||||
|
}
|
||||||
|
frr.Add(productsMaterials);
|
||||||
return product;
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
33
ProjectAtelier/Repositories/Implementations/QueryBuilder.cs
Normal file
33
ProjectAtelier/Repositories/Implementations/QueryBuilder.cs
Normal file
@ -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}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user