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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,10 @@
using ProjectCarpentryWorkshop.Repositories.Implementations; using ProjectCarpentryWorkshop.Repositories.Implementations;
using ProjectCarpentryWorkshop.Repositories; using ProjectCarpentryWorkshop.Repositories;
using Unity; using Unity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Unity.Microsoft.Logging;
namespace ProjectCarpentryWorkshop namespace ProjectCarpentryWorkshop
{ {
@ -20,13 +24,29 @@ namespace ProjectCarpentryWorkshop
private static IUnityContainer CreateContainer() private static IUnityContainer CreateContainer()
{ {
var container = new UnityContainer(); var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory())); //add logger in unity
container.RegisterType<IMaterialRepository, MaterialRepository>(); container.RegisterType<IMaterialRepository, MaterialRepository>();
container.RegisterType<IMaterialSupplyRepository, MaterialSupplyRepository>(); container.RegisterType<IMaterialSupplyRepository, MaterialSupplyRepository>();
container.RegisterType<IOrderRepository, OrderRepository>(); container.RegisterType<IOrderRepository, OrderRepository>();
container.RegisterType<IProductionRepository, ProductionRepository>(); container.RegisterType<IProductionRepository, ProductionRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container; 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> </PropertyGroup>
<ItemGroup> <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" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -27,4 +34,10 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,8 +10,19 @@ namespace ProjectCarpentryWorkshop.Repositories.Implementations;
public class MaterialRepository : IMaterialRepository 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) public void CreateMaterial(Material material)
{ {
_logger.LogInformation("Добавление материала");
_logger.LogDebug();
} }
public void DeleteMaterial(int id) 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"
}
}
]
}
}