material not work com 4
This commit is contained in:
parent
74bda6e3f8
commit
64db0e8a91
@ -1,12 +1,17 @@
|
||||
using ProductionInCehOTP.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class ArrivalMaterials
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Дата")]
|
||||
public DateTime Date { get; private set; }
|
||||
[DisplayName("Перечь поставленных материалов")]
|
||||
public NameOfMaterials Name { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; private set; }
|
||||
|
||||
public static ArrivalMaterials CreateArrivalMaterials(int id, DateTime Date, NameOfMaterials name, int count)
|
||||
|
@ -1,16 +1,31 @@
|
||||
|
||||
using ProductionInCehOTP.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class Material
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Материал")]
|
||||
public NameOfMaterials Name { get; private set; }
|
||||
|
||||
[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; }
|
||||
|
||||
[DisplayName("Дата передачи в производство")]
|
||||
public DateTime DateArrivalToProduct { get; private set; }
|
||||
|
||||
public static Material TransferMaterial(int id, NameOfMaterials name, int arrivalMaterialsID, DateTime dateArrivalToProduct,IEnumerable<MaterialForProduct> materialForProducts )
|
||||
{
|
||||
return new Material
|
||||
@ -23,16 +38,12 @@ public class Material
|
||||
};
|
||||
}
|
||||
|
||||
public static Material TransferMaterial(TempMaterialForProduct tempMaterialForProduct, IEnumerable<MaterialForProduct> materialForProducts)
|
||||
public void SetMaterialForProduct(IEnumerable<MaterialForProduct> materialForProducts)
|
||||
{
|
||||
return new Material
|
||||
if(materialForProducts != null && materialForProducts.Any())
|
||||
{
|
||||
Id = tempMaterialForProduct.ID,
|
||||
Name = tempMaterialForProduct.Name,
|
||||
ArrivalMaterialID = tempMaterialForProduct.ArrivalMaterialID,
|
||||
DateArrivalToProduct = tempMaterialForProduct.DateArrivalToProduct,
|
||||
MaterialForProducts = materialForProducts
|
||||
};
|
||||
MaterialForProducts = materialForProducts;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ 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)
|
||||
|
@ -1,10 +1,17 @@
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class PlanWork
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Запланированное количество готовой продукции")]
|
||||
public int Plan { get; private set; }
|
||||
|
||||
[DisplayName("Дата установки плана")]
|
||||
public DateTime Date { get; private set; } = DateTime.Now;
|
||||
|
||||
[Browsable(false)]
|
||||
public int WorkerId { get; private set; }
|
||||
|
||||
public IEnumerable<PlanWorkForProduct> PlanWorkForProducts { get; private set; } = [];
|
||||
|
@ -1,13 +1,22 @@
|
||||
using ProductionInCehOTP.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class Product
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Наименование продукта")]
|
||||
public string Name { get; private set; }
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public int Price { get; private set; }
|
||||
|
||||
[DisplayName("Официальный регистрационный номер")]
|
||||
public string ProductionId { get; private set; }
|
||||
|
||||
[DisplayName("Наименование типа изделия")]
|
||||
public NameOfProductTypes ProductionTypeID { get; private set; }
|
||||
|
||||
public static Product CreateProducts(int id, string name, int price, string productionId, NameOfProductTypes productionType)
|
||||
|
@ -1,21 +0,0 @@
|
||||
using ProductionInCehOTP.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class TempMaterialForProduct
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
public NameOfMaterials Name { get; private set; }
|
||||
public int ArrivalMaterialID { get; private set; }
|
||||
|
||||
public int MaterialID { get; private set; }
|
||||
|
||||
public DateTime DateArrivalToProduct { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
}
|
@ -1,13 +1,24 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ProductionInCehOTP.Entities;
|
||||
|
||||
public class Worker
|
||||
{
|
||||
|
||||
public int Id { get; private set; }
|
||||
[Browsable(false)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[DisplayName("ФИО(разряд)")]
|
||||
public string NameClass => $"{Name}({Class})";
|
||||
|
||||
[DisplayName("Рабочий стаж")]
|
||||
public DateTime Experience { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int Class { get; private set; }
|
||||
|
||||
[DisplayName("Дневная норма выработки")]
|
||||
public int PlanWork { get; private set; }
|
||||
|
||||
public static Worker CreateWorker(int id, string name, DateTime experience, int classOfWorker, int planWorkID)
|
||||
|
@ -82,8 +82,12 @@ namespace ProductionInCehOTP.Forms.ArrivalsMaterials_Forms
|
||||
}
|
||||
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _arrivalMaterialsRepository.GetArrivalMaterials();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _arrivalMaterialsRepository.GetArrivalMaterials();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -32,6 +32,9 @@ namespace ProductionInCehOTP.Forms.Material_Forms
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _materialRepository.GetMaterials();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["DateArrivalToProduct"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
|
||||
}
|
||||
|
||||
private void FormMaterials_Load(object sender, EventArgs e)
|
||||
|
@ -28,7 +28,7 @@ namespace ProductionInCehOTP.Forms
|
||||
ColumnProduct.ValueMember = "Id";
|
||||
|
||||
comboBoxName.DataSource = workerRepository.GetWorkers();
|
||||
comboBoxName.DisplayMember = "Name";
|
||||
comboBoxName.DisplayMember = "NameClass";
|
||||
comboBoxName.ValueMember = "Id";
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace ProductionInCehOTP.Forms.PlanWork_Forms
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IPlanWorkRepository _planWorkRepository;
|
||||
public FormPlansWork(IUnityContainer container,IPlanWorkRepository planWorkRepository)
|
||||
public FormPlansWork(IUnityContainer container, IPlanWorkRepository planWorkRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
@ -40,8 +40,13 @@ namespace ProductionInCehOTP.Forms.PlanWork_Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка добавления элемента", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _planWorkRepository.GetPlanWorks();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _planWorkRepository.GetPlanWorks();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dddd.MM.yyyy";
|
||||
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -93,7 +93,11 @@ namespace ProductionInCehOTP.Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _productRepository.GetProducts();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _productRepository.GetProducts();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -81,8 +81,14 @@ namespace ProductionInCehOTP.Forms
|
||||
}
|
||||
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _workerRepository.GetWorkers();
|
||||
private void LoadList()
|
||||
{
|
||||
|
||||
dataGridViewData.DataSource = _workerRepository.GetWorkers();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["DateArrivalToProduct"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -29,16 +29,32 @@ public class MaterialRepository : IMaterialReposirory
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT mat.*, mp.MaterialID, mp.Count
|
||||
FROM Material mat
|
||||
INNER JOIN material_product mp ON mp.MaterialID = mat.id";
|
||||
var material =
|
||||
connection.Query<TempMaterialForProduct>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(material));
|
||||
SELECT mat.*,
|
||||
mfp.Count as countofmaterialtoproduct,
|
||||
pr.Name as nameofproduct
|
||||
from material mat
|
||||
inner join material_product mfp on mfp.MaterialId = mat.id
|
||||
left join product pr on pr.productiontypeid = mfp.productid";
|
||||
var materialDict = new Dictionary<int, List<MaterialForProduct>>();
|
||||
|
||||
return material.GroupBy(x => x.ID, y => y,
|
||||
(key, value) => Material.TransferMaterial(value.First(), value.Select(z => MaterialForProduct.CreateDependenceMaterialsToProduct(0,z.MaterialID, z.Count)))).ToList();
|
||||
var material = connection.Query<Material, MaterialForProduct, Material>(querySelect,
|
||||
(matat, material) =>
|
||||
{
|
||||
if (!materialDict.TryGetValue(matat.Id, out var frr))
|
||||
{
|
||||
frr = [];
|
||||
materialDict.Add(matat.Id, frr);
|
||||
}
|
||||
frr.Add(material);
|
||||
return matat;
|
||||
}, splitOn: "Count", param: new {name, arrivalMaterialsid});
|
||||
_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();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user