labs complited +-

This commit is contained in:
Lazypr0ger 2024-11-28 10:57:27 +03:00
parent c3f1ec8d35
commit b4487e7ae0
20 changed files with 590 additions and 141 deletions

View File

@ -7,7 +7,7 @@ public class Material
{ {
public int Id { get; private set; } public int Id { get; private set; }
public NameOfMaterials Name { get; private set; } public NameOfMaterials Name { get; private set; }
public int ArrivalMaterialsID { get; private set; } public int ArrivalMaterialID { get; private set; }
public IEnumerable<MaterialForProduct> MaterialForProducts { get; private set; } public IEnumerable<MaterialForProduct> MaterialForProducts { get; private set; }
public static Material TransferMaterial(int id, NameOfMaterials name, int arrivalMaterialsID, IEnumerable<MaterialForProduct> materialForProducts ) public static Material TransferMaterial(int id, NameOfMaterials name, int arrivalMaterialsID, IEnumerable<MaterialForProduct> materialForProducts )
{ {
@ -15,7 +15,7 @@ public static Material TransferMaterial(int id, NameOfMaterials name, int arriva
{ {
Id = id, Id = id,
Name = name, Name = name,
ArrivalMaterialsID = arrivalMaterialsID, ArrivalMaterialID = arrivalMaterialsID,
MaterialForProducts = materialForProducts MaterialForProducts = materialForProducts
}; };
} }

View File

@ -6,18 +6,18 @@ public class Worker
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
public DateTime Experiebce { get; private set; } public int Experience { get; private set; }
public int ClassOfWorker { get; private set; } public int Class { get; private set; }
public int PlanWork { get; private set; } public int PlanWork { get; private set; }
public static Worker CreateWorker(int id, string name, DateTime experience, int classOfWorker, int planWorkID) public static Worker CreateWorker(int id, string name, int experience, int classOfWorker, int planWorkID)
{ {
return new Worker return new Worker
{ {
Id = id, Id = id,
Name = name, Name = name,
Experiebce = experience, Experience = experience,
ClassOfWorker = classOfWorker, Class = classOfWorker,
PlanWork = planWorkID PlanWork = planWorkID
}; };
} }

View File

@ -1,4 +1,5 @@
using ProductionInCehOTP.Entities; using Microsoft.Extensions.Logging;
using ProductionInCehOTP.Entities;
using ProductionInCehOTP.Entities.Enums; using ProductionInCehOTP.Entities.Enums;
using ProductionInCehOTP.Repositories; using ProductionInCehOTP.Repositories;
using ProductionInCehOTP.Repositories.Implementations; using ProductionInCehOTP.Repositories.Implementations;
@ -18,6 +19,7 @@ namespace ProductionInCehOTP.Forms
{ {
private readonly IArrivalMaterialsRepository _ArrivalMaterialsrepository; private readonly IArrivalMaterialsRepository _ArrivalMaterialsrepository;
private int? _arrivalId; private int? _arrivalId;
public FormArrivalMaterials(IArrivalMaterialsRepository arrivalMaterialsRepository) public FormArrivalMaterials(IArrivalMaterialsRepository arrivalMaterialsRepository)
{ {
InitializeComponent(); InitializeComponent();
@ -27,8 +29,6 @@ namespace ProductionInCehOTP.Forms
{ {
checkedListBoxMaterials.Items.Add(elem); checkedListBoxMaterials.Items.Add(elem);
} }
} }
public int Id public int Id
{ {

View File

@ -33,12 +33,11 @@
label1 = new Label(); label1 = new Label();
label2 = new Label(); label2 = new Label();
comboBoxNameOfMaterial = new ComboBox(); comboBoxNameOfMaterial = new ComboBox();
numericUpDownArrivalNomber = new NumericUpDown();
dataGridViewMaterialToProduct = new DataGridView(); dataGridViewMaterialToProduct = new DataGridView();
groupBoxMaterialToProduct = new GroupBox();
ColumnProduct = new DataGridViewComboBoxColumn(); ColumnProduct = new DataGridViewComboBoxColumn();
ColumnCountMaterial = new DataGridViewTextBoxColumn(); ColumnCountMaterial = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)numericUpDownArrivalNomber).BeginInit(); groupBoxMaterialToProduct = new GroupBox();
comboBoxNomberArrials = new ComboBox();
((System.ComponentModel.ISupportInitialize)dataGridViewMaterialToProduct).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewMaterialToProduct).BeginInit();
groupBoxMaterialToProduct.SuspendLayout(); groupBoxMaterialToProduct.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -89,13 +88,6 @@
comboBoxNameOfMaterial.Size = new Size(220, 28); comboBoxNameOfMaterial.Size = new Size(220, 28);
comboBoxNameOfMaterial.TabIndex = 5; comboBoxNameOfMaterial.TabIndex = 5;
// //
// numericUpDownArrivalNomber
//
numericUpDownArrivalNomber.Location = new Point(220, 65);
numericUpDownArrivalNomber.Name = "numericUpDownArrivalNomber";
numericUpDownArrivalNomber.Size = new Size(220, 27);
numericUpDownArrivalNomber.TabIndex = 6;
//
// dataGridViewMaterialToProduct // dataGridViewMaterialToProduct
// //
dataGridViewMaterialToProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewMaterialToProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@ -106,16 +98,6 @@
dataGridViewMaterialToProduct.Size = new Size(422, 282); dataGridViewMaterialToProduct.Size = new Size(422, 282);
dataGridViewMaterialToProduct.TabIndex = 7; dataGridViewMaterialToProduct.TabIndex = 7;
// //
// groupBoxMaterialToProduct
//
groupBoxMaterialToProduct.Controls.Add(dataGridViewMaterialToProduct);
groupBoxMaterialToProduct.Location = new Point(12, 98);
groupBoxMaterialToProduct.Name = "groupBoxMaterialToProduct";
groupBoxMaterialToProduct.Size = new Size(434, 314);
groupBoxMaterialToProduct.TabIndex = 8;
groupBoxMaterialToProduct.TabStop = false;
groupBoxMaterialToProduct.Text = "Материалы для продукции";
//
// ColumnProduct // ColumnProduct
// //
ColumnProduct.HeaderText = "Продукт"; ColumnProduct.HeaderText = "Продукт";
@ -132,13 +114,31 @@
ColumnCountMaterial.SortMode = DataGridViewColumnSortMode.NotSortable; ColumnCountMaterial.SortMode = DataGridViewColumnSortMode.NotSortable;
ColumnCountMaterial.Width = 125; ColumnCountMaterial.Width = 125;
// //
// groupBoxMaterialToProduct
//
groupBoxMaterialToProduct.Controls.Add(dataGridViewMaterialToProduct);
groupBoxMaterialToProduct.Location = new Point(12, 98);
groupBoxMaterialToProduct.Name = "groupBoxMaterialToProduct";
groupBoxMaterialToProduct.Size = new Size(434, 314);
groupBoxMaterialToProduct.TabIndex = 8;
groupBoxMaterialToProduct.TabStop = false;
groupBoxMaterialToProduct.Text = "Материалы для продукции";
//
// comboBoxNomberArrials
//
comboBoxNomberArrials.FormattingEnabled = true;
comboBoxNomberArrials.Location = new Point(219, 61);
comboBoxNomberArrials.Name = "comboBoxNomberArrials";
comboBoxNomberArrials.Size = new Size(221, 28);
comboBoxNomberArrials.TabIndex = 9;
//
// FormMaterial // FormMaterial
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(458, 482); ClientSize = new Size(458, 482);
Controls.Add(comboBoxNomberArrials);
Controls.Add(groupBoxMaterialToProduct); Controls.Add(groupBoxMaterialToProduct);
Controls.Add(numericUpDownArrivalNomber);
Controls.Add(comboBoxNameOfMaterial); Controls.Add(comboBoxNameOfMaterial);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
@ -146,7 +146,6 @@
Controls.Add(buttonSave); Controls.Add(buttonSave);
Name = "FormMaterial"; Name = "FormMaterial";
Text = "Материал"; Text = "Материал";
((System.ComponentModel.ISupportInitialize)numericUpDownArrivalNomber).EndInit();
((System.ComponentModel.ISupportInitialize)dataGridViewMaterialToProduct).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewMaterialToProduct).EndInit();
groupBoxMaterialToProduct.ResumeLayout(false); groupBoxMaterialToProduct.ResumeLayout(false);
ResumeLayout(false); ResumeLayout(false);
@ -160,10 +159,10 @@
private Label label1; private Label label1;
private Label label2; private Label label2;
private ComboBox comboBoxNameOfMaterial; private ComboBox comboBoxNameOfMaterial;
private NumericUpDown numericUpDownArrivalNomber;
private DataGridView dataGridViewMaterialToProduct; private DataGridView dataGridViewMaterialToProduct;
private GroupBox groupBoxMaterialToProduct; private GroupBox groupBoxMaterialToProduct;
private DataGridViewComboBoxColumn ColumnProduct; private DataGridViewComboBoxColumn ColumnProduct;
private DataGridViewTextBoxColumn ColumnCountMaterial; private DataGridViewTextBoxColumn ColumnCountMaterial;
private ComboBox comboBoxNomberArrials;
} }
} }

View File

@ -19,7 +19,7 @@ namespace ProductionInCehOTP.Forms.Material_Forms
private readonly IMaterialReposirory _materialRepository; private readonly IMaterialReposirory _materialRepository;
private int? _materialID; private int? _materialID;
public FormMaterial(IMaterialReposirory materialRepository, IProductRepository productRepository) public FormMaterial(IMaterialReposirory materialRepository, IProductRepository productRepository, IArrivalMaterialsRepository arrivalMaterialsRepository)
{ {
InitializeComponent(); InitializeComponent();
_materialRepository = materialRepository ?? _materialRepository = materialRepository ??
@ -28,6 +28,11 @@ namespace ProductionInCehOTP.Forms.Material_Forms
ColumnProduct.DataSource = productRepository.GetProducts(); ColumnProduct.DataSource = productRepository.GetProducts();
ColumnProduct.DisplayMember = "Name"; ColumnProduct.DisplayMember = "Name";
ColumnProduct.ValueMember = "Id"; ColumnProduct.ValueMember = "Id";
comboBoxNomberArrials.DataSource = arrivalMaterialsRepository.GetArrivalMaterials();
comboBoxNomberArrials.DisplayMember = "Id";
comboBoxNomberArrials.ValueMember = "Id";
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
@ -39,7 +44,7 @@ namespace ProductionInCehOTP.Forms.Material_Forms
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
_materialRepository.TransferMaterial(Material.TransferMaterial(0, (NameOfMaterials)comboBoxNameOfMaterial.SelectedItem!, _materialRepository.TransferMaterial(Material.TransferMaterial(0, (NameOfMaterials)comboBoxNameOfMaterial.SelectedItem!,
Convert.ToInt32(numericUpDownArrivalNomber.Value), CreateListMateriaToProductForGrid())); (int)comboBoxNomberArrials.SelectedValue!, CreateListMateriaToProductForGrid()));
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,15 +1,4 @@
using ProductionInCehOTP.Repositories; using ProductionInCehOTP.Repositories;
using ProductionInCehOTP.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Unity; using Unity;
namespace ProductionInCehOTP.Forms.Material_Forms namespace ProductionInCehOTP.Forms.Material_Forms

View File

@ -67,7 +67,7 @@
buttonSave.TabIndex = 10; buttonSave.TabIndex = 10;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click; buttonSave.Click += ButtonSave_Click;
// //
// buttonCensel // buttonCensel
// //
@ -78,7 +78,7 @@
buttonCensel.TabIndex = 11; buttonCensel.TabIndex = 11;
buttonCensel.Text = "Отмена"; buttonCensel.Text = "Отмена";
buttonCensel.UseVisualStyleBackColor = true; buttonCensel.UseVisualStyleBackColor = true;
buttonCensel.Click += buttonCensel_Click; buttonCensel.Click += ButtonCensel_Click;
// //
// numericUpDownPrice // numericUpDownPrice
// //

View File

@ -17,8 +17,6 @@ namespace ProductionInCehOTP.Forms
public partial class FormProduct : Form public partial class FormProduct : Form
{ {
Random rnd = new Random();
int RND;
private readonly IProductRepository _productRepository; private readonly IProductRepository _productRepository;
private int? _productID; private int? _productID;
@ -30,7 +28,7 @@ namespace ProductionInCehOTP.Forms
try try
{ {
var product = _productRepository.GetProductById(value); var product = _productRepository.GetProductById(value);
if (product != null) if (product == null)
{ {
throw new InvalidDataException(nameof(product)); throw new InvalidDataException(nameof(product));
} }
@ -39,7 +37,6 @@ namespace ProductionInCehOTP.Forms
comboBoxProductType.SelectedItem = product.ProductionType; comboBoxProductType.SelectedItem = product.ProductionType;
_productID = value; _productID = value;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -57,7 +54,7 @@ namespace ProductionInCehOTP.Forms
comboBoxProductType.DataSource = Enum.GetValues(typeof(NameOfProductTypes)); comboBoxProductType.DataSource = Enum.GetValues(typeof(NameOfProductTypes));
} }
private void buttonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
{ {
@ -84,9 +81,9 @@ namespace ProductionInCehOTP.Forms
} }
} }
private Product CreateProducts(int id) => Product.CreateProducts(id, textBoxNameOfProduct.Text,Convert.ToInt32(numericUpDownPrice.Value), rnd.Next(0, 100000), (NameOfProductTypes)comboBoxProductType.SelectedItem!); private Product CreateProducts(int id) => Product.CreateProducts(id, textBoxNameOfProduct.Text,Convert.ToInt32(numericUpDownPrice.Value), int.Parse(textBoxOficialID.Text), (NameOfProductTypes)comboBoxProductType.SelectedItem!);
private void buttonCensel_Click(object sender, EventArgs e) => Close(); private void ButtonCensel_Click(object sender, EventArgs e) => Close();

View File

@ -97,7 +97,6 @@ namespace ProductionInCehOTP.Forms
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {
id = 0;
if (dataGridViewData.SelectedRows.Count < 0) if (dataGridViewData.SelectedRows.Count < 0)
{ {
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);

View File

@ -153,7 +153,7 @@
buttonSave.TabIndex = 13; buttonSave.TabIndex = 13;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click; buttonSave.Click += ButtonSave_Click;
// //
// buttonCensel // buttonCensel
// //
@ -163,7 +163,7 @@
buttonCensel.TabIndex = 14; buttonCensel.TabIndex = 14;
buttonCensel.Text = "Отмена"; buttonCensel.Text = "Отмена";
buttonCensel.UseVisualStyleBackColor = true; buttonCensel.UseVisualStyleBackColor = true;
buttonCensel.Click += buttonCensel_Click; buttonCensel.Click += ButtonCensel_Click;
// //
// FormWorker // FormWorker
// //

View File

@ -24,7 +24,37 @@ namespace ProductionInCehOTP.Forms
throw new ArgumentNullException(nameof(workerRepository)); throw new ArgumentNullException(nameof(workerRepository));
} }
private void buttonSave_Click(object sender, EventArgs e) public int WorkerID
{
set
{
try
{
var worker = _workerRepository.GetWorkerById(value);
if (worker == null)
{
throw new InvalidDataException(nameof(worker));
}
string firstname = textBoxFirstName.Text;
string lastname = textBoxLastName.Text;
string Secondname = textBoxSecondName.Text;
string name = String.Concat(firstname, " ", Secondname, " ", lastname);
name = worker.Name;
int ExperienceYear = DateTime.Now.Year - monthCalendarExp.SelectionStart.Year;
ExperienceYear = worker.Experience;
numericUpDownClassOfWorker.Value = worker.Class;
numericUpDownPlan.Value = worker.PlanWork;
_workerID = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
{ {
@ -40,42 +70,18 @@ namespace ProductionInCehOTP.Forms
{ {
_workerRepository.CreateWorker(CreateWorker(0)); _workerRepository.CreateWorker(CreateWorker(0));
} }
Close();
} }
catch(Exception ex) catch(Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка сохранения", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка сохранения", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void buttonCensel_Click(object sender, EventArgs e) => Close(); private void ButtonCensel_Click(object sender, EventArgs e) => Close();
public int WorkerID
{
set
{
try
{
var worker = _workerRepository.GetWorkerById(value);
if (worker != null)
{
throw new InvalidDataException(nameof(worker));
}
string firstname = textBoxFirstName.Text;
string lastname = textBoxLastName.Text;
string Secondname = textBoxSecondName.Text;
string name = String.Concat(firstname," ",Secondname," ",lastname );
name = worker.Name;
monthCalendarExp.DataContext = worker.Experiebce;
numericUpDownClassOfWorker.Value = worker.ClassOfWorker;
numericUpDownPlan.Value = worker.PlanWork;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
private Worker CreateWorker(int workerID) => private Worker CreateWorker(int workerID) =>
Worker.CreateWorker(workerID, Name, Convert.ToDateTime(monthCalendarExp.DataContext), Convert.ToInt32(numericUpDownClassOfWorker.Value), Convert.ToInt32(numericUpDownPlan.Value)); Worker.CreateWorker(workerID, String.Concat(textBoxSecondName.Text, " ", textBoxFirstName.Text," ", textBoxLastName.Text), DateTime.Now.Year - monthCalendarExp.SelectionStart.Year, Convert.ToInt32(numericUpDownClassOfWorker.Value), Convert.ToInt32(numericUpDownPlan.Value));
} }
} }

View File

@ -9,11 +9,17 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.1" />
<PackageReference Include="Serilog" Version="4.1.0" /> <PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="Unity" Version="5.11.10" /> <PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" /> <PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
@ -33,4 +39,10 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -1,3 +1,4 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ProductionInCehOTP.Repositories; using ProductionInCehOTP.Repositories;
using ProductionInCehOTP.Repositories.Implementations; using ProductionInCehOTP.Repositories.Implementations;
@ -24,27 +25,28 @@ namespace ProductionInCehOTP
private static IUnityContainer CreateContainer() private static IUnityContainer CreateContainer()
{ {
var container = new UnityContainer(); var container = new UnityContainer();
//container.AddExtension(new LoggingExtension(CreateLoggerFactory())); container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IConnectionString, ConnectionString>();
container.RegisterType<IArrivalMaterialsRepository, ArrivalMaterialsRepository>(); container.RegisterType<IArrivalMaterialsRepository, ArrivalMaterialsRepository>();
container.RegisterType<IMaterialReposirory, MaterialRepository>(); container.RegisterType<IMaterialReposirory, MaterialRepository>();
container.RegisterType<IProductRepository, ProductRepository>(); container.RegisterType<IProductRepository, ProductRepository>();
container.RegisterType<IPlanWorkRepository, PlanWorkRepository>(); container.RegisterType<IPlanWorkRepository, PlanWorkRepository>();
container.RegisterType<IWorkerRepository, WorkerRepository>(); container.RegisterType<IWorkerRepository, WorkerRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container; return container;
} }
//private static LoggerFactory CreateLoggerFactory() private static LoggerFactory CreateLoggerFactory()
//{ {
// var loggerFactory = new LoggerFactory(); var loggerFactory = new LoggerFactory();
// loggerFactory.AddSerilog(new LoggerConfiguration()) loggerFactory.AddSerilog(new LoggerConfiguration()
// .ReadForm.Configuration(new ConfigurationBuilder()) .ReadFrom.Configuration(new ConfigurationBuilder()
// .SetBasePath(Directory.GetCurrentDirectory()) .SetBasePath(Directory.GetCurrentDirectory())
// .AddJsonFile("appsettings.json") .AddJsonFile("appsettings.json")
// .Build()) .Build())
// .CreateLogger()); .CreateLogger());
// return loggerFactory; return loggerFactory;
}
//}
} }
} }

View File

@ -5,10 +5,10 @@ namespace ProductionInCehOTP.Repositories;
public interface IWorkerRepository public interface IWorkerRepository
{ {
IEnumerable<Worker> GetWorkers(); IEnumerable<Worker> GetWorkers();
Worker GetWorkerById(int id); Worker GetWorkerById(int WorkerID);
void CreateWorker (Worker worker); void CreateWorker (Worker worker);
void UpdateWorker (Worker worker); void UpdateWorker (Worker worker);
void DeleteWorker (int id); void DeleteWorker (int WorkerID);
} }

View File

@ -1,37 +1,139 @@
using ProductionInCehOTP.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProductionInCehOTP.Entities;
using ProductionInCehOTP.Entities.Enums; using ProductionInCehOTP.Entities.Enums;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Net.Http.Json;
using System.Text.Json.Serialization;
namespace ProductionInCehOTP.Repositories.Implementations; namespace ProductionInCehOTP.Repositories.Implementations;
public class ArrivalMaterialsRepository : IArrivalMaterialsRepository public class ArrivalMaterialsRepository : IArrivalMaterialsRepository
{ {
private readonly IConnectionString _connectionString; private readonly IConnectionString _connectionString;
public ArrivalMaterialsRepository(IConnectionString connectionString)
private readonly ILogger<ArrivalMaterialsRepository> _logger;
public ArrivalMaterialsRepository(IConnectionString connectionString , ILogger<ArrivalMaterialsRepository> logger)
{ {
_connectionString = connectionString; _connectionString = connectionString;
_logger = logger;
} }
public void CreateArrivalMaterials(ArrivalMaterials material) public void CreateArrivalMaterials(ArrivalMaterials material)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Оъект: {json}", JsonConvert.SerializeObject(material));
try
{
using var connecntion = new NpgsqlConnection(_connectionString.ConnectionString);
connecntion.Open();
var queryInsert = @"
INSERT INTO ARRIVAL_MATERIALS (DATE, NAME, COUNT)
VALUES (@DATE, @NAME, @COUNT)";
connecntion.Execute(queryInsert, material);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void DeleteArrivalMaterials(int id) public void DeleteArrivalMaterials(int id)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM ARRIVAL_MATERIALS
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
public IEnumerable<ArrivalMaterials> GetArrivalMaterials() public IEnumerable<ArrivalMaterials> GetArrivalMaterials()
{ {
return []; _logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM ARRIVAL_MATERIALS";
var materials = connection.Query<ArrivalMaterials>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(materials));
return materials;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
public ArrivalMaterials GetArrivalMaterialsById(int id) public ArrivalMaterials GetArrivalMaterialsById(int id)
{ {
return ArrivalMaterials.CreateArrivalMaterials(0, DateTime.Now, NameOfMaterials.None, 0); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM ARRIVAL_MATERIALS
WHERE Id=@id";
var material = connection.QueryFirst<ArrivalMaterials>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(material));
return material;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
} }
public void UpdateArrivalMaterials(ArrivalMaterials material) public void UpdateArrivalMaterials(ArrivalMaterials material)
{ {
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(material));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE ARRIVAL_MATERIALS
SET
ID=@ID,
DATE=@DATE,
NAME=@NAME,
COUNT=@COUNT
WHERE Id=@Id";
connection.Execute(queryUpdate, material);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
} }
} }

View File

@ -4,10 +4,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProductionInCehOTP.Repositories.Implementations namespace ProductionInCehOTP.Repositories.Implementations;
public class ConnectionString : IConnectionString
{ {
public class ConnectionString : IConnectionString string IConnectionString.ConnectionString => "Host=127.0.0.1;Port=5432;Username=postgres;Password=daa200513dr;Database=labsto_otp";
{
string IConnectionString.ConnectionString => "";
}
} }

View File

@ -1,11 +1,22 @@
using ProductionInCehOTP.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProductionInCehOTP.Entities;
using ProductionInCehOTP.Entities.Enums; using ProductionInCehOTP.Entities.Enums;
namespace ProductionInCehOTP.Repositories.Implementations; namespace ProductionInCehOTP.Repositories.Implementations;
public class MaterialRepository : IMaterialReposirory public class MaterialRepository : IMaterialReposirory
{ {
private readonly IConnectionString _connectionString;
private readonly ILogger<MaterialRepository> _logger;
public MaterialRepository(IConnectionString connectionString, ILogger<MaterialRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public Material GetMaterialById(int id) public Material GetMaterialById(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -13,11 +24,60 @@ public class MaterialRepository : IMaterialReposirory
public IEnumerable<Material> GetMaterials(NameOfMaterials? name, int? arrivalMaterialsid) public IEnumerable<Material> GetMaterials(NameOfMaterials? name, int? arrivalMaterialsid)
{ {
return []; _logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM MATERIAL";
var material =
connection.Query<Material>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(material));
return material;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
public void TransferMaterial(Material material) public void TransferMaterial(Material material)
{ {
throw new NotImplementedException(); _logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(material));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO MATERIAL (NAME,ARRIVALMATERIALID)
VALUES (@NAME, @ARRIVALMATERIALID);
SELECT MAX(Id) FROM MATERIAL";
var materialID =
connection.QueryFirst<int>(queryInsert, material, transaction);
var querySubInsert = @"
INSERT INTO MATERIAL_PRODUCT (PRODUCTID, MATERIALID, COUNT)
VALUES (@PRODUCTID,@MATERIALID, @COUNT)";
foreach (var elem in material.MaterialForProducts)
{
connection.Execute(querySubInsert, new
{
material,
elem.ProductID,
elem.MaterialID,
elem.Count
}, transaction);
}
transaction.Commit();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
} }

View File

@ -1,16 +1,78 @@
using ProductionInCehOTP.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProductionInCehOTP.Entities;
using System.Data.SqlClient;
namespace ProductionInCehOTP.Repositories.Implementations; namespace ProductionInCehOTP.Repositories.Implementations;
public class PlanWorkRepository : IPlanWorkRepository public class PlanWorkRepository : IPlanWorkRepository
{ {
private readonly IConnectionString _connectionString;
private readonly ILogger<PlanWorkRepository> _logger;
public PlanWorkRepository(IConnectionString connectionString, ILogger<PlanWorkRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreatePlanWork(PlanWork planWork) public void CreatePlanWork(PlanWork planWork)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(planWork));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO PLANWORK (Plan, Date,WorkerID)
VALUES (@Plan, @Date, @WorkerID);
SELECT MAX(Id) FROM PLANWORK";
var PlanWorkID =
connection.QueryFirst<int>(queryInsert, planWork, transaction);
var querySubInsert = @"
INSERT INTO PLANWORK_PRODUCT (PLANWORKID, PRODUCTID, COUNT)
VALUES (@PLANWORKID,@PRODUCTID, @COUNT)";
foreach (var elem in planWork.PlanWorkForProducts)
{
connection.Execute(querySubInsert, new
{
planWork,
elem.PlanWorkId,
elem.ProductId,
elem.Count
}, transaction);
}
transaction.Commit();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void DeletePlanWork(int planId) public void DeletePlanWork(int planId)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", planId);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM PlanWork
WHERE Id=@id";
connection.Execute(queryDelete, new { planId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
@ -20,7 +82,24 @@ public class PlanWorkRepository : IPlanWorkRepository
} }
public IEnumerable<PlanWork> GetPlanWorks() public IEnumerable<PlanWork> GetPlanWorks()
{ {
return []; _logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM PlanWork";
var planwork =
connection.Query<PlanWork>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(planwork));
return planwork;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
} }

View File

@ -1,31 +1,132 @@
using ProductionInCehOTP.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProductionInCehOTP.Entities;
namespace ProductionInCehOTP.Repositories.Implementations; namespace ProductionInCehOTP.Repositories.Implementations;
public class ProductRepository : IProductRepository public class ProductRepository : IProductRepository
{ {
private readonly IConnectionString _connectionString;
private readonly ILogger<ProductRepository> _logger;
public ProductRepository(IConnectionString connectionString, ILogger<ProductRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateProduct(Product product) public void CreateProduct(Product product)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Оъект: {json}", JsonConvert.SerializeObject(product));
try
{
using var connecntion = new NpgsqlConnection(_connectionString.ConnectionString);
connecntion.Open();
var queryInsert = @"
INSERT INTO PRODUCT (NAME,PRICE,PRODUCTIONID, PRODUCTIONTYPEID)
VALUES (@NAME, @PRICE, @PRODUCTIONID, @PRODUCTIONTYPE)";
connecntion.Execute(queryInsert, product);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void DeleteProduct(int productId) public void DeleteProduct(int Id)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", Id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM PRODUCT
WHERE Id=@id";
connection.Execute(queryDelete, new { Id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
public Product GetProductById(int productId) public Product GetProductById(int Id)
{ {
return Product.CreateProducts(0, "", 0, 0, 0); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", Id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM PRODUCT
WHERE Id=@id";
var product = connection.QueryFirst<Product>(querySelect, new
{
Id
});
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(product));
return product;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
} }
public IEnumerable<Product> GetProducts() public IEnumerable<Product> GetProducts()
{ {
return []; _logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM PRODUCT";
var product = connection.Query<Product>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(product));
return product;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
public void UpdateProduct(Product product) public void UpdateProduct(Product product)
{ {
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(product));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE PRODUCT
SET
ID=@Id,
NAME=@Name,
PRICE=@Price,
PRODUCTIONID=@ProductionId,
PRODUCTIONTYPEDID=@ProductionType
WHERE Id=@Id";
connection.Execute(queryUpdate, product);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
} }
} }

View File

@ -1,31 +1,130 @@
using ProductionInCehOTP.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProductionInCehOTP.Entities;
namespace ProductionInCehOTP.Repositories.Implementations; namespace ProductionInCehOTP.Repositories.Implementations;
public class WorkerRepository : IWorkerRepository public class WorkerRepository : IWorkerRepository
{ {
private readonly IConnectionString _connectionString;
private readonly ILogger<ProductRepository> _logger;
public WorkerRepository(IConnectionString connectionString, ILogger<ProductRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateWorker(Worker worker) public void CreateWorker(Worker worker)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Оъект: {json}", JsonConvert.SerializeObject(worker));
try
{
using var connecntion = new NpgsqlConnection(_connectionString.ConnectionString);
connecntion.Open();
var queryInsert = @"
INSERT INTO WORKER (NAME,EXPERIENCE, CLASS, PLANWORK)
VALUES (@NAME, @EXPERIENCE, @CLASS, @PLANWORK)";
connecntion.Execute(queryInsert, worker);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void DeleteWorker(int id) public void DeleteWorker(int Id)
{ {
throw new NotImplementedException(); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", Id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM WORKER
WHERE ID=@Id";
connection.Execute(queryDelete, new { Id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
public Worker GetWorkerById(int id) public Worker GetWorkerById(int Id)
{ {
return Worker.CreateWorker(0, string.Empty, DateTime.Now, 0, 0); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", Id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM WORKER
WHERE ID=@Id";
var worker = connection.QueryFirstOrDefault<Worker>(querySelect, new { id = Id });
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(worker));
return worker;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
} }
public IEnumerable<Worker> GetWorkers() public IEnumerable<Worker> GetWorkers()
{ {
return []; _logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM WORKER";
var worker = connection.Query<Worker>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(worker));
return worker;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
public void UpdateWorker(Worker worker) public void UpdateWorker(Worker worker)
{ {
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(worker));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE WORKER
SET
ID=@Id
NAME=@Name,
EXPERIENCE=@Experience,
CLASS=@Class,
PLANWORK=@PlanWork
WHERE ID=@Id";
connection.Execute(queryUpdate, worker);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
} }
} }