one step is required

This commit is contained in:
Viltskaa 2023-05-04 16:10:15 +04:00
parent fe06793f3c
commit 8fdc5bc1cc
25 changed files with 389 additions and 263 deletions

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBar namespace SushiBar
{ {
@ -18,39 +19,32 @@ namespace SushiBar
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var service = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) if (service is not { }) return;
{ if (service.ShowDialog() == DialogResult.OK)
if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void ButtonEdit_Click(object sender, EventArgs e) private void ButtonEdit_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count != 1) return;
{ var service = DependencyManager.Instance.Resolve<FormComponent>();
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); if (service is not { }) return;
if (service is FormComponent form) service.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
{ if (service.ShowDialog() == DialogResult.OK)
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
}
private void ButtonRemove_Click(object sender, EventArgs e) private void ButtonRemove_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count != 1) return;
{ if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) DialogResult.Yes) return;
{ var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Delete component"); _logger.LogInformation("Delete component");
try try
{ {
@ -69,8 +63,6 @@ namespace SushiBar
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
}
}
private void ButtonReload_Click(object sender, EventArgs e) private void ButtonReload_Click(object sender, EventArgs e)
{ {

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBar namespace SushiBar
{ {
@ -17,31 +18,24 @@ namespace SushiBar
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var service = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) if (service.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void ButtonEdit_Click(object sender, EventArgs e) private void ButtonEdit_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count != 1) return;
{ var service = DependencyManager.Instance.Resolve<FormImplementer>();
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); if (service == null) return;
if (service is FormImplementer form) service.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
{ if (service.ShowDialog() == DialogResult.OK)
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
}
private void ButtonDelete_Click(object sender, EventArgs e) private void ButtonDelete_Click(object sender, EventArgs e)
{ {

View File

@ -1,7 +1,9 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics; using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.Attributes;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
using SushiBarDataModels.Enums; using SushiBarDataModels.Enums;
namespace SushiBar namespace SushiBar
@ -32,34 +34,15 @@ namespace SushiBar
private void LoadData() private void LoadData()
{ {
_logger.LogInformation("Load components"); _logger.LogInformation("Load components");
try dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SushiId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load orders");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void ButtonCreateOrder_Click(object sender, EventArgs e) private void ButtonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var service = DependencyManager.Instance.Resolve<FormCreateOrder>();
if (service is FormCreateOrder form) service.ShowDialog();
{
form.ShowDialog();
LoadData(); LoadData();
} }
}
private void ButtonSubmit_Click(object sender, EventArgs e) private void ButtonSubmit_Click(object sender, EventArgs e)
{ {
@ -96,9 +79,8 @@ namespace SushiBar
private void ButtonReady_Click(object sender, EventArgs e) private void ButtonReady_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count != 1) return;
{ var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change status on -Ready",id); _logger.LogInformation("Order №{id}. Change status on -Ready",id);
try try
{ {
@ -123,15 +105,13 @@ namespace SushiBar
_logger.LogError(ex, "Error on change status"); _logger.LogError(ex, "Error on change status");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
}
} }
private void ButtonIssue_Click(object sender, EventArgs e) private void ButtonIssue_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count != 1) return;
{ var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change status on -Issued", id); _logger.LogInformation("Order №{id}. Change status on -Issued", id);
try try
{ {
@ -158,7 +138,6 @@ namespace SushiBar
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
}
private void ButtonReload_Click(object sender, EventArgs e) private void ButtonReload_Click(object sender, EventArgs e)
{ {
@ -172,85 +151,61 @@ namespace SushiBar
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var service = DependencyManager.Instance.Resolve<FormComponents>();
if (service is FormComponents form) service.ShowDialog();
{
form.ShowDialog();
}
} }
private void SushiToolStripMenuItem_Click(object sender, EventArgs e) private void SushiToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSushiMoreThenOne)); var service = DependencyManager.Instance.Resolve<FormSushiMoreThenOne>();
service.ShowDialog();
if (service is FormSushiMoreThenOne form)
{
form.ShowDialog();
}
} }
private void ListComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ListComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK) if (dialog.ShowDialog() != DialogResult.OK) return;
{
_reportLogic.SaveSushiToWordFile(new ReportBindingModel _reportLogic.SaveSushiToWordFile(new ReportBindingModel
{ {
FileName = dialog.FileName FileName = dialog.FileName
}); });
MessageBox.Show("Complete", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Complete", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
}
private void ComponentsOnSushiToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentsOnSushiToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSushiOnComponents)); var service = DependencyManager.Instance.Resolve<FormSushiOnComponents>();
if (service is FormSushiOnComponents form) service.ShowDialog();
{
form.ShowDialog();
}
} }
private void ListOrdersToolStripMenuItem_Click(object sender, EventArgs e) private void ListOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); var service = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form) service.ShowDialog();
{
form.ShowDialog();
}
} }
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormClients)); var service = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormClients form) service.ShowDialog();
{
form.ShowDialog();
}
} }
private void StartWorkToolStripMenuItem_Click(object sender, EventArgs e) 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("Process work is started", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Process work is started", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); var service = DependencyManager.Instance.Resolve<FormImplementers>();
if (service is FormImplementers form) service.ShowDialog();
{
form.ShowDialog();
}
} }
private void MailsToolStripMenuItem_Click(object sender, EventArgs e) private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMails)); var service = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form) service.ShowDialog();
{
form.ShowDialog();
}
} }
private void CreateBackupStripMenuItem_Click(object sender, EventArgs e) private void CreateBackupStripMenuItem_Click(object sender, EventArgs e)
@ -266,7 +221,6 @@ namespace SushiBar
{ {
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }
} }

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
@ -27,8 +28,7 @@ namespace SushiBar
_logger.LogInformation("Load components"); _logger.LogInformation("Load components");
try try
{ {
if (_sushiComponents != null) if (_sushiComponents == null) return;
{
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var pc in _sushiComponents) foreach (var pc in _sushiComponents)
{ {
@ -36,7 +36,6 @@ namespace SushiBar
} }
textBoxPrice.Text = CalcPrice().ToString(); textBoxPrice.Text = CalcPrice().ToString();
} }
}
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error loading components for sushi"); _logger.LogError(ex, "Error loading components for sushi");
@ -82,7 +81,7 @@ namespace SushiBar
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); var service = DependencyManager.Instance.Resolve<FormSushiComponent>();
if (service is FormSushiComponent form) if (service is FormSushiComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -109,7 +108,7 @@ namespace SushiBar
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); var service = DependencyManager.Instance.Resolve<FormSushiComponent>();
if (service is FormSushiComponent form) if (service is FormSushiComponent form)
{ {
int id = int id =

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBar namespace SushiBar
{ {
@ -38,7 +39,7 @@ namespace SushiBar
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); var service = DependencyManager.Instance.Resolve<FormSushi>();
if (service is FormSushi form) if (service is FormSushi form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -52,7 +53,7 @@ namespace SushiBar
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); var service = DependencyManager.Instance.Resolve<FormSushi>();
if (service is FormSushi form) if (service is FormSushi form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -1,4 +1,3 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics; using SushiBarBusinessLogic.BusinessLogics;
@ -7,26 +6,20 @@ using SushiBarBusinessLogic.OfficePackage;
using SushiBarBusinessLogic.OfficePackage.Implements; using SushiBarBusinessLogic.OfficePackage.Implements;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.DI;
using SushiBarDatabaseImplement.Implements;
namespace SushiBar namespace SushiBar
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread] [STAThread]
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection(); InitDependency();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
try try
{ {
var mailSender = _serviceProvider.GetService<AbstractMailWorker>(); var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel mailSender?.MailConfig(new MailConfigBindingModel
{ {
MailLogin = MailLogin =
@ -49,56 +42,54 @@ namespace SushiBar
} }
catch(Exception ex) catch(Exception ex)
{ {
var logger = _serviceProvider.GetService<ILogger>(); var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Error on working w/ email"); logger?.LogError(ex, "Error on working w/ email");
} }
Application.Run(_serviceProvider.GetRequiredService<FormMain>()); Application.Run(DependencyManager.Instance.Resolve<FormMain>());
} }
private static void ConfigureServices(IServiceCollection services)
private static void InitDependency()
{ {
services.AddLogging(option => DependencyManager.InitDependency();
DependencyManager.Instance.AddLogging(option =>
{ {
option.SetMinimumLevel(LogLevel.Information); option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config"); option.AddNLog("nlog.config");
}); });
services.AddTransient<IComponentStorage, ComponentStorage>(); DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderStorage, OrderStorage>(); DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiStorage, SushiStorage>(); DependencyManager.Instance.RegisterType<ISushiLogic, SushiLogic>();
services.AddTransient<IClientStorage, ClientStorage>(); DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
services.AddTransient<IImplementerStorage, ImplementerStorage>(); DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
services.AddTransient<IMessageInfoStorage, MessageStorage>(); DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
services.AddTransient<IComponentLogic, ComponentLogic>(); DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IBackUpLogic, BackUpLogic>();
services.AddTransient<IWorkProcess, WorkModeling>(); DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>(); DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); DependencyManager.Instance.RegisterType<FormMain>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); DependencyManager.Instance.RegisterType<FormComponent>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); DependencyManager.Instance.RegisterType<FormComponents>();
services.AddTransient<FormMain>(); DependencyManager.Instance.RegisterType<FormCreateOrder>();
services.AddTransient<FormComponent>(); DependencyManager.Instance.RegisterType<FormSushi>();
services.AddTransient<FormComponents>(); DependencyManager.Instance.RegisterType<FormSushiComponent>();
services.AddTransient<FormCreateOrder>(); DependencyManager.Instance.RegisterType<FormSushiMoreThenOne>();
services.AddTransient<FormSushi>(); DependencyManager.Instance.RegisterType<FormSushiOnComponents>();
services.AddTransient<FormSushiComponent>(); DependencyManager.Instance.RegisterType<FormReportOrders>();
services.AddTransient<FormSushiMoreThenOne>(); DependencyManager.Instance.RegisterType<FormClients>();
services.AddTransient<FormReportOrders>(); DependencyManager.Instance.RegisterType<FormImplementers>();
services.AddTransient<FormSushiOnComponents>(); DependencyManager.Instance.RegisterType<FormImplementer>();
services.AddTransient<FormClients>(); DependencyManager.Instance.RegisterType<FormMails>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormMails>();
} }
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck(); private static void MailCheck(object obj) =>
DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
} }
} }

View File

@ -10,4 +10,5 @@ public class MessageInfoBindingModel : IMessageInfoModel
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public int Id { get; }
} }

View File

@ -0,0 +1,56 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace SushiBarContracts.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,37 @@
using Microsoft.Extensions.Logging;
using Unity;
using Unity.Microsoft.Logging;
namespace SushiBarContracts.DI;
public class UnityDependencyContainer : IDependencyContainer
{
private readonly IUnityContainer _container;
public UnityDependencyContainer()
{
_container = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
var factory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(factory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
}

View File

@ -18,6 +18,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,15 +1,16 @@
using System.ComponentModel; using SushiBarContracts.Attributes;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
namespace SushiBarContracts.ViewModels; namespace SushiBarContracts.ViewModels;
public class ClientViewModel : IClientModel public class ClientViewModel : IClientModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("FIO client")] [Column("FIO client", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ClientFio { get; set; } = string.Empty; public string ClientFio { get; set; } = string.Empty;
[DisplayName("Email")] [Column("Email", width: 150)]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[DisplayName("Password")] [Column("Password", width : 150)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
} }

View File

@ -1,16 +1,15 @@
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
using System.ComponentModel; using SushiBarContracts.Attributes;
namespace SushiBarContracts.ViewModels namespace SushiBarContracts.ViewModels
{ {
public class ComponentViewModel : IComponentModel public class ComponentViewModel : IComponentModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[Column("Name of Component", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
[DisplayName("Name of Component")]
public string ComponentName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
[Column("Cost", width: 80)]
[DisplayName("Cost")]
public double Cost { get; set; } public double Cost { get; set; }
} }

View File

@ -1,20 +1,19 @@
using System.ComponentModel; using System.ComponentModel;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
namespace SushiBarContracts.ViewModels; namespace SushiBarContracts.ViewModels;
public class ImplementerViewModel : IImplementerModel public class ImplementerViewModel : IImplementerModel
{ {
[Column(visible : false)]
public int Id { get; init; } public int Id { get; init; }
[Column("Implementer FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
[DisplayName("Implementer FIO")]
public string ImplementerFio { get; set; } = string.Empty; public string ImplementerFio { get; set; } = string.Empty;
[Column("Password", width: 150)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[Column("Work Experience", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
[DisplayName("Work Experience")]
public int WorkExperience { get; set; } public int WorkExperience { get; set; }
[Column("Qualification", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
[DisplayName("Qualification")]
public int Qualification { get; set; } public int Qualification { get; set; }
} }

View File

@ -1,16 +1,22 @@
using System.ComponentModel; using SushiBarContracts.Attributes;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
namespace SushiBarContracts.ViewModels; namespace SushiBarContracts.ViewModels;
public class MessageInfoViewModel : IMessageInfoModel public class MessageInfoViewModel : IMessageInfoModel
{ {
[Column(visible: false)]
public string MessageId { get; set; } public string MessageId { get; set; }
[Column(visible: false)]
public int? ClientId { get; set; } public int? ClientId { get; set; }
[DisplayName("Sender name")] [Column("Sender name", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
public string SenderName { get; set; } public string SenderName { get; set; }
[DisplayName("Date delivery")] [Column("Date delivery", width: 100)]
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
[Column("Subject", width:150)]
public string Subject { get; set; } public string Subject { get; set; }
[Column("Body", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } public string Body { get; set; }
[Column(visible:false)]
public int Id { get; }
} }

View File

@ -1,40 +1,43 @@
using SushiBarDataModels.Enums; using SushiBarDataModels.Enums;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
using SushiBarContracts.Attributes;
namespace SushiBarContracts.ViewModels namespace SushiBarContracts.ViewModels
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {
[DisplayName("Number")] [Column("Number", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Id { get; init; } public int Id { get; init; }
[Column(visible:false)]
public int SushiId { get; init; } public int SushiId { get; init; }
[Column(visible:false)]
public int ClientId { get; init; } public int ClientId { get; init; }
[Column(visible:false)]
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[DisplayName("Client FIO")] [Column("Client FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ClientFio { get; init; } = string.Empty; public string ClientFio { get; init; } = string.Empty;
[DisplayName("Implementer FIO")] [Column("Implementer FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFio { get; set; } = string.Empty; public string ImplementerFio { get; set; } = string.Empty;
[DisplayName("Name of Product")] [Column("Name of Product", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string SushiName { get; init; } = string.Empty; public string SushiName { get; init; } = string.Empty;
[DisplayName("Count")] [Column("Count", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Sum")] [Column("Sum", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Status")] [Column("Status", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public OrderStatus Status { get; set; } = OrderStatus.Unknown; public OrderStatus Status { get; set; } = OrderStatus.Unknown;
[DisplayName("Date Create")] [Column("Date Create", width:100)]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Date Implement")] [Column("Date Implement", width:100)]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
} }
} }

View File

@ -1,4 +1,6 @@
namespace SushiBarContracts.ViewModels using SushiBarContracts.Attributes;
namespace SushiBarContracts.ViewModels
{ {
public class ReportOrdersViewModel public class ReportOrdersViewModel
{ {

View File

@ -1,17 +1,20 @@
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
using SushiBarContracts.Attributes;
namespace SushiBarContracts.ViewModels namespace SushiBarContracts.ViewModels
{ {
public class SushiViewModel : ISushiModel public class SushiViewModel : ISushiModel
{ {
[Column(visible:false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Name of Product")] [Column("Name of Product", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;
[DisplayName("Cost")] [Column("Cost", width:100)]
public double Price { get; set; } public double Price { get; set; }
[Column(visible:false)]
public Dictionary<int, (IComponentModel, int)> SushiComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> SushiComponents { get; set; } = new();
} }
} }

View File

@ -47,4 +47,6 @@ public class Message : IMessageInfoModel
SenderName = SenderName, SenderName = SenderName,
DateDelivery = DateDelivery, DateDelivery = DateDelivery,
}; };
public int Id { get; }
} }

View File

@ -66,4 +66,6 @@ public class Message : IMessageInfoModel
new XAttribute("SenderName", SenderName), new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery) new XAttribute("DateDelivery", DateDelivery)
); );
public int Id { get; }
} }

View File

@ -1,6 +1,6 @@
namespace SushiBarDataModels.Models; namespace SushiBarDataModels.Models;
public interface IMessageInfoModel public interface IMessageInfoModel : IId
{ {
string MessageId { get; } string MessageId { get; }
int? ClientId { get; } int? ClientId { get; }

View File

@ -0,0 +1,17 @@
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
namespace SushibarListImplement.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();
}
}

View File

@ -0,0 +1,39 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
namespace SushibarListImplement.Implements;
public class ClientStorage : IClientStorage
{
public List<ClientViewModel> GetFullList()
{
throw new NotImplementedException();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel? model)
{
throw new NotImplementedException();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
throw new NotImplementedException();
}
public ClientViewModel? Update(ClientBindingModel model)
{
throw new NotImplementedException();
}
public ClientViewModel? Delete(ClientBindingModel model)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,20 @@
using SushiBarContracts.DI;
using SushiBarContracts.StoragesContracts;
using SushibarListImplement.Implements;
namespace SushibarListImplement;
public class ListImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}

View File

@ -39,4 +39,6 @@ public class Message : IMessageInfoModel
ClientId = ClientId, ClientId = ClientId,
MessageId = MessageId MessageId = MessageId
}; };
public int Id { get; }
} }

View File

@ -11,4 +11,8 @@
<ProjectReference Include="..\SushiBarModels\SushiBarDataModels.csproj" /> <ProjectReference Include="..\SushiBarModels\SushiBarDataModels.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project> </Project>