error
This commit is contained in:
parent
7758c9be8c
commit
6f6b08f5cf
@ -14,14 +14,17 @@ public class Material
|
||||
[DisplayName("Номеер поставки")]
|
||||
public int ArrivalMaterialID { get; private set; }
|
||||
|
||||
[DisplayName("Количество переданного")]
|
||||
|
||||
public string CountToProduct => MaterialForProducts != null ?
|
||||
string.Join(", ", MaterialForProducts.Select(x => $"{x.Name}{x.Count}")) :
|
||||
string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<MaterialForProduct> MaterialForProducts { get; private set; }
|
||||
public IEnumerable<MaterialForProduct> MaterialForProducts { get; set; } = [];
|
||||
|
||||
[DisplayName("Количество переданного")]
|
||||
public string CountToProduct => MaterialForProducts != null ?
|
||||
string.Join(", ", MaterialForProducts.Select(x => $"{x.ProductID}{x.Count}")) :
|
||||
string.Empty;
|
||||
|
||||
|
||||
|
||||
[DisplayName("Дата передачи в производство")]
|
||||
public DateTime DateArrivalToProduct { get; private set; }
|
||||
|
@ -1,20 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class MaterialForProduct
|
||||
{
|
||||
public int ProductID { get; private set; }
|
||||
public int MaterialID { get; private set; }
|
||||
|
||||
public string Name { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
|
||||
public static MaterialForProduct CreateDependenceMaterialsToProduct(int productID, int materialsId, int count)
|
||||
public static MaterialForProduct CreateDependenceMaterialsToProduct( int materialsId, int productID, int count)
|
||||
{
|
||||
return new MaterialForProduct { ProductID = productID, MaterialID = materialsId, Count = count};
|
||||
}
|
||||
|
@ -62,11 +62,10 @@ namespace ProductionInCehOTP.Forms.Material_Forms
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(MaterialForProduct.CreateDependenceMaterialsToProduct(0,
|
||||
Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.
|
||||
ToInt32(row.Cells["ColumnCountMaterial"].Value)));
|
||||
list.Add(MaterialForProduct.CreateDependenceMaterialsToProduct(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value)
|
||||
, Convert.ToInt32(row.Cells["ColumnCountMaterial"].Value)));
|
||||
}
|
||||
return list.GroupBy(x => x.MaterialID, x => x.Count, (id,countes) =>
|
||||
return list.GroupBy(x => x.ProductID, x => x.Count, (id,countes) =>
|
||||
MaterialForProduct.CreateDependenceMaterialsToProduct(0,id,countes.Sum())).ToList();
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ namespace ProductionInCehOTP.Forms.Material_Forms
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
var gh = _materialRepository.GetMaterials();
|
||||
dataGridViewData.DataSource = _materialRepository.GetMaterials();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["DateArrivalToProduct"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
|
@ -22,11 +22,14 @@ public class MaterialRepository : IMaterialReposirory
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<Material> GetMaterials(DateTime? StartDate = null, DateTime? EndDate = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
_logger.LogInformation("Получение всех объектов материалов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var builder = new QueryBuilder();
|
||||
if (StartDate.HasValue)
|
||||
{
|
||||
@ -36,43 +39,45 @@ public class MaterialRepository : IMaterialReposirory
|
||||
{
|
||||
builder.AddCondition("mat.Datearrivaltoproduct <= @EndDate");
|
||||
}
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = $@"
|
||||
SELECT
|
||||
mat.*,
|
||||
mfp.Count,
|
||||
pr.Name as ""MatForproduct""
|
||||
from material mat
|
||||
inner join material_product mfp on mfp.MaterialId = mat.id
|
||||
left join product pr on pr.productiontypeid = mfp.productid
|
||||
{ builder.Build()}";
|
||||
var materialDict = new Dictionary<int, List<MaterialForProduct>>();
|
||||
|
||||
var material = connection.Query<Material, MaterialForProduct, Material>(querySelect,
|
||||
(matat, material) =>
|
||||
var query = @$"
|
||||
SELECT
|
||||
mat.Id AS Id,
|
||||
mat.Name AS Name,
|
||||
mat.ArrivalMaterialiD AS ArrivalMaterialID,
|
||||
mat.DateArrivalToProduct AS DateArrivalToProduct,
|
||||
mfp.ProductID AS ProductId,
|
||||
mfp.MaterialID AS MaterialIdDependency,
|
||||
mfp.Count AS CountToProduct
|
||||
FROM material mat
|
||||
LEFT JOIN material_product mfp ON mat.Id = mfp.MaterialID
|
||||
{builder.Build()}";
|
||||
|
||||
var MaterialForProductCountDict = new Dictionary<int, List<MaterialForProduct>>();
|
||||
|
||||
var materials = connection.Query<Material, MaterialForProduct, Material>(
|
||||
query,
|
||||
(material, materialForProduct) =>
|
||||
{
|
||||
if (!materialDict.TryGetValue(matat.Id, out var frr))
|
||||
if (!MaterialForProductCountDict.TryGetValue(material.Id, out var forProduct))
|
||||
{
|
||||
frr = [];
|
||||
materialDict.Add(matat.Id, frr);
|
||||
forProduct = [];
|
||||
MaterialForProductCountDict.Add(material.Id, forProduct);
|
||||
}
|
||||
frr.Add(material);
|
||||
return matat;
|
||||
}, splitOn: "MatForproduct", param: new {StartDate, EndDate});
|
||||
_logger.LogDebug("Полученные объекты {json}", JsonConvert.SerializeObject(material));
|
||||
return materialDict.Select(x =>
|
||||
{
|
||||
var fr = material.First(y => y.Id == x.Key);
|
||||
fr.SetMaterialForProduct(x.Value);
|
||||
return fr;
|
||||
}).ToArray();
|
||||
forProduct.Add(materialForProduct);
|
||||
return material;
|
||||
},
|
||||
splitOn: "MaterialIdDependency"
|
||||
).Distinct().ToList();
|
||||
|
||||
_logger.LogDebug("Полученные объекты материалов: {json}", JsonConvert.SerializeObject(materials));
|
||||
return materials;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
_logger.LogError(ex, "Ошибка при получении объектов материалов");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void TransferMaterial(Material material)
|
||||
@ -85,12 +90,14 @@ left join product pr on pr.productiontypeid = mfp.productid
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO MATERIAL (NAME, ARRIVALMATERIALID, DateArrivalToProduct)
|
||||
VALUES (@NAME, @ARRIVALMATERIALID, @DateArrivalToProduct);
|
||||
SELECT MAX(Id) FROM MATERIAL";
|
||||
var materialID =
|
||||
connection.QueryFirst<int>(queryInsert, material, transaction);
|
||||
var materialID = connection.QueryFirst<int>(queryInsert, material, transaction);
|
||||
|
||||
var querySubInsert = @"
|
||||
INSERT INTO MATERIAL_PRODUCT (PRODUCTID, MATERIALID, COUNT)
|
||||
VALUES (@PRODUCTID,@MATERIALID, @COUNT)";
|
||||
@ -98,8 +105,8 @@ VALUES (@PRODUCTID,@MATERIALID, @COUNT)";
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
elem.ProductID,
|
||||
materialID,
|
||||
elem.ProductID,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user