Правки по зависимостям.

This commit is contained in:
Programmist73 2023-04-29 13:35:30 +04:00
parent 8028c36b1a
commit 7097dab600
7 changed files with 163 additions and 122 deletions

View File

@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -58,14 +59,11 @@ namespace BlacksmithWorkshop
private void ButtonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form)
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
@ -73,16 +71,13 @@ namespace BlacksmithWorkshop
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form)
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
}

View File

@ -1,6 +1,7 @@
using BlacksmithWorkshopBusinessLogic.BusinessLogic;
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.DI;
using BlacksmithWorkshopDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
@ -73,34 +74,24 @@ namespace BlacksmithWorkshop
private void WorkPieceToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWorkPieces));
var form = DependencyManager.Instance.Resolve<FormWorkPieces>();
if (service is FormWorkPieces form)
{
form.ShowDialog();
}
form.ShowDialog();
}
private void ManufactureToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufactures));
var form = DependencyManager.Instance.Resolve<FormManufactures>();
if (service is FormManufactures form)
{
form.ShowDialog();
}
form.ShowDialog();
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
form.ShowDialog();
LoadData();
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
@ -156,59 +147,45 @@ namespace BlacksmithWorkshop
private void WorkPieceManufacturesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportManufactureWorkPieces));
var form = DependencyManager.Instance.Resolve<FormReportManufactureWorkPieces>();
form.ShowDialog();
if (service is FormReportManufactureWorkPieces form)
{
form.ShowDialog();
}
}
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
var form = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form)
{
form.ShowDialog();
}
form.ShowDialog();
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
var form = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormClients form)
{
form.ShowDialog();
}
form.ShowDialog();
}
private void StartingWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>()!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ImplementerToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
var form = DependencyManager.Instance.Resolve<FormImplementers>();
if (service is FormImplementers form)
{
form.ShowDialog();
}
form.ShowDialog();
}
private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
var form = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form)
{
form.ShowDialog();
}
form.ShowDialog();
}
private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.DI;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopDataModels.Models;
using Microsoft.Extensions.Logging;
@ -89,30 +90,27 @@ namespace BlacksmithWorkshop
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece));
if (service is FormManufactureWorkPiece form)
var form = DependencyManager.Instance.Resolve<FormManufactureWorkPiece>();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
if (form.WorkPieceModel == null)
{
if (form.WorkPieceModel == null)
{
return;
}
_logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count);
if (_manufactureWorkPieces.ContainsKey(form.Id))
{
_manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count);
}
else
{
_manufactureWorkPieces.Add(form.Id, (form.WorkPieceModel, form.Count));
}
LoadData();
return;
}
_logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count);
if (_manufactureWorkPieces.ContainsKey(form.Id))
{
_manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count);
}
else
{
_manufactureWorkPieces.Add(form.Id, (form.WorkPieceModel, form.Count));
}
LoadData();
}
}
@ -120,26 +118,23 @@ namespace BlacksmithWorkshop
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece));
var form = DependencyManager.Instance.Resolve<FormManufactureWorkPiece>();
if (service is FormManufactureWorkPiece form)
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _manufactureWorkPieces[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _manufactureWorkPieces[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
if (form.WorkPieceModel == null)
{
if (form.WorkPieceModel == null)
{
return;
}
_logger.LogInformation("Изменение компонента:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count);
_manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count);
LoadData();
return;
}
_logger.LogInformation("Изменение компонента:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count);
_manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count);
LoadData();
}
}
}

View File

@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -58,14 +59,11 @@ namespace BlacksmithWorkshop
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufacture));
var form = DependencyManager.Instance.Resolve<FormManufacture>();
if (service is FormManufacture form)
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
@ -73,16 +71,13 @@ namespace BlacksmithWorkshop
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufacture));
var form = DependencyManager.Instance.Resolve<FormManufacture>();
if (service is FormManufacture form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}

View File

@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -57,14 +58,11 @@ namespace BlacksmithWorkshop
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece));
var form = DependencyManager.Instance.Resolve<FormWorkPiece>();
if (service is FormWorkPiece form)
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
@ -73,15 +71,12 @@ namespace BlacksmithWorkshop
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece));
if (service is FormWorkPiece form)
var form = DependencyManager.Instance.Resolve<FormWorkPiece>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
}

View File

@ -0,0 +1,62 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopContracts.DI
{
public class ServiceDependencyContainer : IDependencyContainer
{
private ServiceProvider? _serviceProvider;
private readonly ServiceCollection _serviceCollection;
public ServiceDependencyContainer()
{
_serviceCollection = new ServiceCollection();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
_serviceCollection.AddLogging(configure);
}
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T, U>();
}
else
{
_serviceCollection.AddTransient<T, U>();
}
_serviceProvider = null;
}
public void RegisterType<T>(bool isSingle) where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T>();
}
else
{
_serviceCollection.AddTransient<T>();
}
_serviceProvider = null;
}
public T Resolve<T>()
{
if (_serviceProvider == null)
{
_serviceProvider = _serviceCollection.BuildServiceProvider();
}
return _serviceProvider.GetService<T>()!;
}
}
}

View File

@ -0,0 +1,22 @@
using BlacksmithWorkshopContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
throw new NotImplementedException();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
throw new NotImplementedException();
}
}
}