LabWork02InWork

This commit is contained in:
cleverman1337 2024-12-18 14:27:42 +04:00
parent f4ae3d879a
commit 827f1e4f05
12 changed files with 170 additions and 65 deletions

View File

@ -32,8 +32,8 @@
buttonCancel = new Button();
labelName = new Label();
labelCount = new Label();
textBoxName = new TextBox();
numericUpDownCount = new NumericUpDown();
comboBoxMaterial = new ComboBox();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout();
//
@ -75,13 +75,6 @@
labelCount.TabIndex = 4;
labelCount.Text = "Count";
//
// textBoxName
//
textBoxName.Location = new Point(124, 46);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(120, 23);
textBoxName.TabIndex = 7;
//
// numericUpDownCount
//
numericUpDownCount.Location = new Point(124, 97);
@ -89,18 +82,27 @@
numericUpDownCount.Size = new Size(120, 23);
numericUpDownCount.TabIndex = 8;
//
// FormMaterialSpent
// comboBoxMaterial
//
comboBoxMaterial.FormattingEnabled = true;
comboBoxMaterial.Location = new Point(123, 43);
comboBoxMaterial.Name = "comboBoxMaterial";
comboBoxMaterial.Size = new Size(121, 23);
comboBoxMaterial.TabIndex = 9;
comboBoxMaterial.SelectedIndexChanged += comboBoxMaterial_SelectedIndexChanged;
//
// FormMaterialSupply
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(304, 204);
Controls.Add(comboBoxMaterial);
Controls.Add(numericUpDownCount);
Controls.Add(textBoxName);
Controls.Add(labelCount);
Controls.Add(labelName);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Name = "FormMaterialSpent";
Name = "FormMaterialSupply";
Text = "FormMaterialSpent";
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
ResumeLayout(false);
@ -115,5 +117,7 @@
private Label labelCount;
private TextBox textBoxName;
private NumericUpDown numericUpDownCount;
private ComboBox comboBoxMaterial;
private ComboBox comboBox1;
}
}

View File

@ -9,13 +9,21 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectCarpentryWorkshop.Entities;
using ProjectCarpentryWorkshop.Repositories;
using ProjectCarpentryWorkshop.Repositories.Implementations;
namespace ProjectCarpentryWorkshop.Forms
{
public partial class FormMaterialSupply : Form
{
private readonly IMaterialSupplyRepository _materialSpentRepository;
IMaterialRepository materialRepository;
private int? _materialSpentId;
private void comboBoxMaterial_SelectedIndexChanged(object sender, EventArgs e)
{
}
public int Id
{
set
@ -27,7 +35,7 @@ namespace ProjectCarpentryWorkshop.Forms
{
throw new InvalidDataException(nameof(materialSpent));
}
textBoxName.Text = materialSpent.Name;
comboBoxMaterial.DataSource = materialRepository.ReadMaterials();
numericUpDownCount.Value = materialSpent.Count;
_materialSpentId = value;
}
@ -69,5 +77,7 @@ namespace ProjectCarpentryWorkshop.Forms
}
}
private void buttonCancel_Click_1(object sender, EventArgs e) => Close();
}
}

View File

@ -131,7 +131,7 @@
ColumnCount.HeaderText = "Count";
ColumnCount.Name = "ColumnCount";
//
// FormOrderProduct
// FormOrderProduction
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
@ -143,7 +143,7 @@
Controls.Add(labelStatus);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Name = "FormOrderProduct";
Name = "FormOrderProduction";
Text = "FormOrder";
groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();

View File

@ -16,6 +16,8 @@ namespace ProjectCarpentryWorkshop.Forms
{
public partial class FormOrderProduction : Form
{
private readonly IOrderRepository _orderRepository;
public FormOrderProduction(IOrderRepository orderRepository, IProductionRepository productRepository)
{
@ -58,5 +60,7 @@ namespace ProjectCarpentryWorkshop.Forms
}
return list;
}
}
}

View File

@ -1,6 +1,10 @@
using ProjectCarpentryWorkshop.Repositories.Implementations;
using ProjectCarpentryWorkshop.Repositories;
using Unity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Unity.Microsoft.Logging;
namespace ProjectCarpentryWorkshop
{
@ -20,13 +24,29 @@ namespace ProjectCarpentryWorkshop
private static IUnityContainer CreateContainer()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory())); //add logger in unity
container.RegisterType<IMaterialRepository, MaterialRepository>();
container.RegisterType<IMaterialSupplyRepository, MaterialSupplyRepository>();
container.RegisterType<IOrderRepository, OrderRepository>();
container.RegisterType<IProductionRepository, ProductionRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory(); //serlog logger
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
}
}

View File

@ -9,7 +9,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" 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="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
@ -27,4 +34,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCarpentryWorkshop.Repositories;
public interface IConnectionString
{
public string connectionString {get;}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCarpentryWorkshop.Repositories.Implementations;
public class ConnectionString : IConnectionString
{
public string connectionString => "";
}

View File

@ -1,4 +1,5 @@
using ProjectCarpentryWorkshop.Entities;
using Microsoft.Extensions.Logging;
using ProjectCarpentryWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,8 +10,19 @@ namespace ProjectCarpentryWorkshop.Repositories.Implementations;
public class MaterialRepository : IMaterialRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<MaterialRepository> _logger;
public MaterialRepository(IConnectionString connectionString, ILogger<MaterialRepository>logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateMaterial(Material material)
{
_logger.LogInformation("Добавление материала");
_logger.LogDebug();
}
public void DeleteMaterial(int id)

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/workshop_log.txt",
"rollingInterval": "Day"
}
}
]
}
}