депенденси менеджер.....

This commit is contained in:
malimova 2024-06-02 22:35:59 +04:00
parent 78d1fd1d8c
commit ab12dc2571
5 changed files with 93 additions and 141 deletions

View File

@ -1,5 +1,6 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -26,15 +27,12 @@ namespace ConfectioneryView
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormComponent>();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void FormComponents_Load(object sender, EventArgs e)
{
@ -58,17 +56,14 @@ namespace ConfectioneryView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormComponent>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonDel_Click(object sender, EventArgs e)

View File

@ -1,5 +1,6 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -47,13 +48,10 @@ namespace ConfectioneryView
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
@ -61,14 +59,11 @@ namespace ConfectioneryView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
var form = DependencyManager.Instance.Resolve<FormImplementer>();
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

@ -2,6 +2,7 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using ConfectioneryContracts.DI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -51,29 +52,20 @@ namespace ConfectioneryView
}
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormComponents>();
form.ShowDialog();
}
private void pastryToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPastrys));
if (service is FormPastrys form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormPastrys>();
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 buttonTakeOrderInWork_Click(object sender, EventArgs e)
@ -161,21 +153,14 @@ namespace ConfectioneryView
private void componentPastryToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents));
if (service is FormReportPastryComponents form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormReportPastryComponents>();
form.ShowDialog();
}
private void ordersListToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormReportOrders>();
form.ShowDialog();
}
private void pastrysListToolStripMenuItem_Click(object sender, EventArgs e)
@ -194,35 +179,26 @@ namespace ConfectioneryView
private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormClients>();
form.ShowDialog();
}
private void implementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormImplementers>();
form.ShowDialog();
}
private void startWorkToolStripMenuItem_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 mailToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMail));
if (service is FormMail form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormMail>();
form.ShowDialog();
}
private void createBackupToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,5 +1,6 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.DI;
using ConfectioneryContracts.SearchModels;
using ConfectioneryDataModels.Models;
using Microsoft.Extensions.Logging;
@ -148,55 +149,45 @@ namespace ConfectioneryView
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
if (service is FormPastryComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Добавление нового компонента:{ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
if (_pastryComponents.ContainsKey(form.Id))
{
_pastryComponents[form.Id] = (form.ComponentModel,
form.Count);
}
else
{
_pastryComponents.Add(form.Id, (form.ComponentModel,
form.Count));
}
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormPastryComponent>();
if (form.ShowDialog() == DialogResult.OK)
{
return;
}
_logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
if (_pastryComponents.ContainsKey(form.Id))
{
_pastryComponents[form.Id] = (form.ComponentModel,
form.Count);
}
else
{
_pastryComponents.Add(form.Id, (form.ComponentModel,
form.Count));
}
LoadData();
}
private void buttonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
if (service is FormPastryComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _pastryComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_pastryComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
if (dataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormPastryComponent>();
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _pastryComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
_pastryComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
private void buttonDel_Click(object sender, EventArgs e)
{

View File

@ -10,6 +10,7 @@ using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.DI;
namespace ConfectioneryView
{
@ -44,30 +45,24 @@ namespace ConfectioneryView
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
if (service is FormPastry form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormPastry>();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void buttonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
if (service is FormPastry form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormPastry>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonDel_Click(object sender, EventArgs e)