Abazov A. A. LabWork08_Base #9
1
.gitignore
vendored
1
.gitignore
vendored
@ -398,3 +398,4 @@ FodyWeavers.xsd
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
/Confectionery/ImplementationExtensions
|
51
Confectionery/Confectionery/DataGridViewExtension.cs
Normal file
51
Confectionery/Confectionery/DataGridViewExtension.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Confectionery
|
||||
{
|
||||
internal static class DataGridViewExtension
|
||||
{
|
||||
public static void FillAndConfigGrid<T>(this DataGridView grid, List<T>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
grid.DataSource = data;
|
||||
|
||||
var type = typeof(T);
|
||||
var properties = type.GetProperties();
|
||||
foreach (DataGridViewColumn column in grid.Columns)
|
||||
{
|
||||
var property = properties.FirstOrDefault(x => x.Name == column.Name);
|
||||
if (property == null)
|
||||
{
|
||||
throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}");
|
||||
}
|
||||
var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
|
||||
if (attribute == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}");
|
||||
}
|
||||
// ищем нужный нам атрибут
|
||||
if (attribute is ColumnAttribute columnAttr)
|
||||
{
|
||||
column.HeaderText = columnAttr.Title;
|
||||
column.Visible = columnAttr.Visible;
|
||||
if (columnAttr.IsUseAutoSize)
|
||||
{
|
||||
column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
column.Width = columnAttr.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -44,12 +44,12 @@
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.dataGridView.Size = new System.Drawing.Size(489, 449);
|
||||
this.dataGridView.Size = new System.Drawing.Size(605, 449);
|
||||
this.dataGridView.TabIndex = 1;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(529, 12);
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(613, 12);
|
||||
this.buttonRefresh.Name = "buttonRefresh";
|
||||
this.buttonRefresh.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonRefresh.TabIndex = 2;
|
||||
@ -61,7 +61,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(660, 450);
|
||||
this.ClientSize = new System.Drawing.Size(719, 450);
|
||||
this.Controls.Add(this.buttonRefresh);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormClients";
|
||||
|
@ -37,13 +37,7 @@ namespace Confectionery
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -38,7 +38,7 @@
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
this.buttonRef.Location = new System.Drawing.Point(523, 185);
|
||||
this.buttonRef.Location = new System.Drawing.Point(625, 184);
|
||||
this.buttonRef.Name = "buttonRef";
|
||||
this.buttonRef.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonRef.TabIndex = 9;
|
||||
@ -48,7 +48,7 @@
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
this.buttonDel.Location = new System.Drawing.Point(523, 127);
|
||||
this.buttonDel.Location = new System.Drawing.Point(625, 126);
|
||||
this.buttonDel.Name = "buttonDel";
|
||||
this.buttonDel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonDel.TabIndex = 8;
|
||||
@ -58,7 +58,7 @@
|
||||
//
|
||||
// buttonUpd
|
||||
//
|
||||
this.buttonUpd.Location = new System.Drawing.Point(523, 70);
|
||||
this.buttonUpd.Location = new System.Drawing.Point(625, 69);
|
||||
this.buttonUpd.Name = "buttonUpd";
|
||||
this.buttonUpd.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonUpd.TabIndex = 7;
|
||||
@ -68,7 +68,7 @@
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(523, 13);
|
||||
this.buttonAdd.Location = new System.Drawing.Point(625, 12);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonAdd.TabIndex = 6;
|
||||
@ -87,14 +87,14 @@
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.dataGridView.Size = new System.Drawing.Size(489, 449);
|
||||
this.dataGridView.Size = new System.Drawing.Size(618, 449);
|
||||
this.dataGridView.TabIndex = 5;
|
||||
//
|
||||
// FormImplementers
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(628, 450);
|
||||
this.ClientSize = new System.Drawing.Size(727, 450);
|
||||
this.Controls.Add(this.buttonRef);
|
||||
this.Controls.Add(this.buttonDel);
|
||||
this.Controls.Add(this.buttonUpd);
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -33,14 +34,8 @@ namespace Confectionery
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка исполнителей");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -51,7 +46,7 @@ namespace Confectionery
|
||||
|
||||
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 (form.ShowDialog() == DialogResult.OK)
|
||||
@ -65,7 +60,7 @@ namespace Confectionery
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
|
||||
var service = DependencyManager.Instance.Resolve<FormImplementer>();
|
||||
if (service is FormImplementer form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -34,13 +35,7 @@ namespace Confectionery
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -52,7 +47,7 @@ namespace Confectionery
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormIngredient));
|
||||
var service = DependencyManager.Instance.Resolve<FormIngredient>();
|
||||
if (service is FormIngredient form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@ -66,7 +61,7 @@ namespace Confectionery
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormIngredient));
|
||||
var service = DependencyManager.Instance.Resolve<FormIngredient>();
|
||||
if (service is FormIngredient form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -27,14 +27,7 @@ namespace Confectionery
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["MessageId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка писем");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
24
Confectionery/Confectionery/FormMain.Designer.cs
generated
24
Confectionery/Confectionery/FormMain.Designer.cs
generated
@ -39,11 +39,12 @@
|
||||
this.IngredientPastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||
this.buttonRef = new System.Windows.Forms.Button();
|
||||
this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -55,7 +56,8 @@
|
||||
this.справочникиToolStripMenuItem,
|
||||
this.отчётыToolStripMenuItem,
|
||||
this.запускРаботToolStripMenuItem,
|
||||
this.письмаToolStripMenuItem});
|
||||
this.письмаToolStripMenuItem,
|
||||
this.создатьБекапToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1703, 28);
|
||||
@ -139,6 +141,13 @@
|
||||
this.запускРаботToolStripMenuItem.Text = "Запуск работ";
|
||||
this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click);
|
||||
//
|
||||
// письмаToolStripMenuItem
|
||||
//
|
||||
this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
|
||||
this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24);
|
||||
this.письмаToolStripMenuItem.Text = "Письма";
|
||||
this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
|
||||
@ -182,12 +191,12 @@
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
|
||||
//
|
||||
// письмаToolStripMenuItem
|
||||
// создатьБекапToolStripMenuItem
|
||||
//
|
||||
this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
|
||||
this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24);
|
||||
this.письмаToolStripMenuItem.Text = "Письма";
|
||||
this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click);
|
||||
this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem";
|
||||
this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(123, 24);
|
||||
this.создатьБекапToolStripMenuItem.Text = "Создать бекап";
|
||||
this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.создатьБекапToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
@ -229,5 +238,6 @@
|
||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||
private ToolStripMenuItem письмаToolStripMenuItem;
|
||||
private ToolStripMenuItem создатьБекапToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -20,14 +21,16 @@ namespace Confectionery
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
private readonly IWorkProcess _workProcess;
|
||||
private readonly IBackUpLogic _backUpLogic;
|
||||
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_workProcess = workProcess;
|
||||
_backUpLogic = backUpLogic;
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
@ -40,18 +43,7 @@ namespace Confectionery
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
try
|
||||
{
|
||||
var list = _orderLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["PastryId"].Visible = false;
|
||||
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ClientEmail"].Visible = false;
|
||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -62,7 +54,7 @@ namespace Confectionery
|
||||
|
||||
private void ингредиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormIngredients));
|
||||
var service = DependencyManager.Instance.Resolve<FormIngredients>();
|
||||
if (service is FormIngredients form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -71,7 +63,7 @@ namespace Confectionery
|
||||
|
||||
private void изделияToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastries));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastries>();
|
||||
if (service is FormPastries form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -80,7 +72,7 @@ namespace Confectionery
|
||||
|
||||
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)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -175,7 +167,7 @@ namespace Confectionery
|
||||
|
||||
private void IngredientPastriesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryIngredients));
|
||||
var service = DependencyManager.Instance.Resolve<FormReportPastryIngredients>();
|
||||
if (service is FormReportPastryIngredients form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -184,7 +176,7 @@ namespace Confectionery
|
||||
|
||||
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
||||
var service = DependencyManager.Instance.Resolve<FormReportOrders>();
|
||||
if (service is FormReportOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -193,7 +185,7 @@ namespace Confectionery
|
||||
|
||||
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
||||
var service = DependencyManager.Instance.Resolve<FormClients>();
|
||||
if (service is FormClients form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -202,7 +194,7 @@ namespace Confectionery
|
||||
|
||||
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
|
||||
var service = DependencyManager.Instance.Resolve<FormImplementers>();
|
||||
if (service is FormImplementers form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -211,17 +203,37 @@ namespace Confectionery
|
||||
|
||||
private void запускРаботToolStripMenuItem_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 письмаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
|
||||
var service = DependencyManager.Instance.Resolve<FormMails>();
|
||||
if (service is FormMails form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_backUpLogic != null)
|
||||
{
|
||||
var fbd = new FolderBrowserDialog();
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_backUpLogic.CreateBackUp(new BackUpSaveBinidngModel { FolderName = fbd.SelectedPath });
|
||||
MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -34,14 +35,7 @@ namespace Confectionery
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["PastryIngredients"].Visible = false;
|
||||
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка изделий");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -53,7 +47,7 @@ namespace Confectionery
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastry>();
|
||||
if (service is FormPastry form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@ -67,7 +61,7 @@ namespace Confectionery
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastry>();
|
||||
if (service is FormPastry form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -79,7 +80,7 @@ namespace Confectionery
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastryIngredient));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastryIngredient>();
|
||||
if (service is FormPastryIngredient form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@ -106,7 +107,7 @@ namespace Confectionery
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastryIngredient));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastryIngredient>();
|
||||
if (service is FormPastryIngredient form)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
|
@ -9,13 +9,12 @@ using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using ConfectioneryBusinessLogic.MailWorker;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.DI;
|
||||
|
||||
namespace Confectionery
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
@ -26,12 +25,10 @@ namespace Confectionery
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
InitDependency();
|
||||
try
|
||||
{
|
||||
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
|
||||
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
||||
@ -47,54 +44,51 @@ namespace Confectionery
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = _serviceProvider.GetService<ILogger>();
|
||||
var logger = DependencyManager.Instance.Resolve<ILogger>();
|
||||
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
||||
}
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
|
||||
|
||||
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
private static void InitDependency()
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
DependencyManager.InitDependency();
|
||||
|
||||
DependencyManager.Instance.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IIngredientStorage, IngredientStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IPastryStorage, PastryStorage>();
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
services.AddTransient<IIngredientLogic, IngredientLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IPastryLogic, PastryLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormIngredient>();
|
||||
services.AddTransient<FormIngredients>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormPastry>();
|
||||
services.AddTransient<FormPastryIngredient>();
|
||||
services.AddTransient<FormPastries>();
|
||||
services.AddTransient<FormReportPastryIngredients>();
|
||||
services.AddTransient<FormReportOrders>();
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormImplementers>();
|
||||
services.AddTransient<FormImplementer>();
|
||||
services.AddTransient<FormMails>();
|
||||
}
|
||||
|
||||
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
||||
DependencyManager.Instance.RegisterType<IIngredientLogic, IngredientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IPastryLogic, PastryLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<FormMain>();
|
||||
DependencyManager.Instance.RegisterType<FormIngredient>();
|
||||
DependencyManager.Instance.RegisterType<FormIngredients>();
|
||||
DependencyManager.Instance.RegisterType<FormCreateOrder>();
|
||||
DependencyManager.Instance.RegisterType<FormPastry>();
|
||||
DependencyManager.Instance.RegisterType<FormPastryIngredient>();
|
||||
DependencyManager.Instance.RegisterType<FormPastries>();
|
||||
DependencyManager.Instance.RegisterType<FormReportPastryIngredients>();
|
||||
DependencyManager.Instance.RegisterType<FormReportOrders>();
|
||||
DependencyManager.Instance.RegisterType<FormClients>();
|
||||
DependencyManager.Instance.RegisterType<FormImplementers>();
|
||||
DependencyManager.Instance.RegisterType<FormImplementer>();
|
||||
DependencyManager.Instance.RegisterType<FormMails>();
|
||||
}
|
||||
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryDataModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class BackUpLogic : IBackUpLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IBackUpInfo _backUpInfo;
|
||||
|
||||
public BackUpLogic(ILogger<BackUpLogic> logger, IBackUpInfo backUpInfo)
|
||||
{
|
||||
_logger = logger;
|
||||
_backUpInfo = backUpInfo;
|
||||
}
|
||||
|
||||
public void CreateBackUp(BackUpSaveBinidngModel model)
|
||||
{
|
||||
if (_backUpInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("Clear folder");
|
||||
// зачистка папки и удаление старого архива
|
||||
var dirInfo = new DirectoryInfo(model.FolderName);
|
||||
if (dirInfo.Exists)
|
||||
{
|
||||
foreach (var file in dirInfo.GetFiles())
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Delete archive");
|
||||
string fileName = $"{model.FolderName}.zip";
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
// берем метод для сохранения
|
||||
_logger.LogDebug("Get assembly");
|
||||
var typeIId = typeof(IId);
|
||||
var assembly = typeIId.Assembly;
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException("Сборка не найдена", nameof(assembly));
|
||||
}
|
||||
var types = assembly.GetTypes();
|
||||
var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
_logger.LogDebug("Find {count} types", types.Length);
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsInterface && type.GetInterface(typeIId.Name) != null)
|
||||
{
|
||||
var modelType = _backUpInfo.GetTypeByModelInterface(type.Name);
|
||||
if (modelType == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Не найден класс-модель для {type.Name}");
|
||||
}
|
||||
_logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
|
||||
// вызываем метод на выполнение
|
||||
method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Create zip and remove folder");
|
||||
// архивируем
|
||||
ZipFile.CreateFromDirectory(model.FolderName, fileName);
|
||||
// удаляем папку
|
||||
dirInfo.Delete(true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToFile<T>(string folderName) where T : class, new()
|
||||
{
|
||||
var records = _backUpInfo.GetList<T>();
|
||||
if (records == null)
|
||||
{
|
||||
_logger.LogWarning("{type} type get null list", typeof(T).Name);
|
||||
return;
|
||||
}
|
||||
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
|
||||
using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
|
||||
jsonFormatter.WriteObject(fs, records);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ColumnAttribute : Attribute
|
||||
{
|
||||
public string Title { get; private set; }
|
||||
|
||||
public bool Visible { get; private set; }
|
||||
|
||||
public int Width { get; private set; }
|
||||
|
||||
public GridViewAutoSize GridViewAutoSize { get; private set; }
|
||||
|
||||
public bool IsUseAutoSize { get; private set; }
|
||||
|
||||
public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false)
|
||||
{
|
||||
Title = title;
|
||||
Visible = visible;
|
||||
Width = width;
|
||||
GridViewAutoSize = gridViewAutoSize;
|
||||
IsUseAutoSize = isUseAutoSize;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.Attributes
|
||||
{
|
||||
public enum GridViewAutoSize
|
||||
{
|
||||
NotSet = 0,
|
||||
None = 1,
|
||||
ColumnHeader = 2,
|
||||
AllCellsExceptHeader = 4,
|
||||
AllCells = 6,
|
||||
DisplayedCellsExceptHeader = 8,
|
||||
DisplayedCells = 10,
|
||||
Fill = 16
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.BindingModels
|
||||
{
|
||||
public class BackUpSaveBinidngModel
|
||||
{
|
||||
public string FolderName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IBackUpLogic
|
||||
{
|
||||
void CreateBackUp(BackUpSaveBinidngModel model);
|
||||
}
|
||||
}
|
@ -6,6 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
66
Confectionery/ConfectioneryContracts/DI/DependencyManager.cs
Normal file
66
Confectionery/ConfectioneryContracts/DI/DependencyManager.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public class DependencyManager
|
||||
{
|
||||
private readonly IDependancyContainer _dependencyManager;
|
||||
|
||||
private static DependencyManager? _manager;
|
||||
|
||||
private static readonly object _locjObject = new();
|
||||
|
||||
private DependencyManager()
|
||||
{
|
||||
_dependencyManager = new UnityDependancyContainer();
|
||||
}
|
||||
|
||||
public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } }
|
||||
|
||||
/// <summary>
|
||||
/// Иницализация библиотек, в которых идут установки зависомстей
|
||||
/// </summary>
|
||||
public static void InitDependency()
|
||||
{
|
||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||
if (ext == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
}
|
||||
// регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Регистрация логгера
|
||||
/// </summary>
|
||||
/// <param name="configure"></param>
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
public void RegisterType<T, U>(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
|
||||
|
||||
/// <summary>
|
||||
/// Получение класса со всеми зависмостями
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public interface IDependancyContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Регистрация логгера
|
||||
/// </summary>
|
||||
/// <param name="configure"></param>
|
||||
void AddLogging(Action<ILoggingBuilder> configure);
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
/// <param name="isSingle"></param>
|
||||
void RegisterType<T, U>(bool isSingle) where U : class, T where T : class;
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="isSingle"></param>
|
||||
void RegisterType<T>(bool isSingle) where T : class;
|
||||
/// <summary>
|
||||
/// Получение класса со всеми зависмостями
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
T Resolve<T>();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public interface IImplementationExtension
|
||||
{
|
||||
public int Priority { get; }
|
||||
/// <summary>
|
||||
/// Регистрация сервисов
|
||||
/// </summary>
|
||||
public void RegisterServices();
|
||||
}
|
||||
}
|
@ -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 ConfectioneryContracts.DI
|
||||
{
|
||||
public class ServiceDependencyContainer : IDependancyContainer
|
||||
{
|
||||
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>()!;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public class ServiceProviderLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузка всех классов-реализаций IImplementationExtension
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IImplementationExtension? GetImplementationExtensions()
|
||||
{
|
||||
IImplementationExtension? source = null;
|
||||
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
source = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
private static string TryGetImplementationExtensionsFolder()
|
||||
{
|
||||
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions"))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
return $"{directory?.FullName}\\ImplementationExtensions";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Unity.Microsoft.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Unity;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public class UnityDependancyContainer : IDependancyContainer
|
||||
{
|
||||
private readonly UnityContainer _unityContainer;
|
||||
|
||||
public UnityDependancyContainer()
|
||||
{
|
||||
_unityContainer = new UnityContainer();
|
||||
}
|
||||
public void AddLogging(Action<ILoggingBuilder> configure)
|
||||
{
|
||||
_unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure)));
|
||||
}
|
||||
|
||||
void IDependancyContainer.RegisterType<T, U>(bool isSingle)
|
||||
{
|
||||
if (isSingle) _unityContainer.RegisterSingleton<T, U>();
|
||||
else _unityContainer.RegisterType<T, U>();
|
||||
}
|
||||
|
||||
public void RegisterType<T>(bool isSingle) where T : class
|
||||
{
|
||||
if (isSingle) _unityContainer.RegisterSingleton<T>();
|
||||
else _unityContainer.RegisterType<T>();
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
return _unityContainer.Resolve<T>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.StoragesContracts
|
||||
{
|
||||
public interface IBackUpInfo
|
||||
{
|
||||
List<T>? GetList<T>() where T : class, new();
|
||||
|
||||
Type? GetTypeByModelInterface(string modelInterfaceName);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,12 +11,13 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
[Column(title:"ФИО клиента", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Логин (эл. почта)")]
|
||||
[Column(title:"Логин (эл. почта)", width:200)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
[Column(title:"Пароль", width:150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,14 +11,15 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО")]
|
||||
[Column(title:"ФИО", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)]
|
||||
public string ImplementerFIO { get; set; } = String.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
[Column(title:"Пароль", width:150)]
|
||||
public string Password { get; set; } = String.Empty;
|
||||
[DisplayName("Опыт работы")]
|
||||
[Column(title:"Опыт работы", width:120)]
|
||||
public int WorkExperience { get; set; }
|
||||
[DisplayName("Квалификация")]
|
||||
[Column(title:"Квалификация", width:120)]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,10 +11,11 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class IngredientViewModel : IIngredientModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название ингредиента")]
|
||||
[Column(title:"Название ингредиента", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)]
|
||||
public string IngredientName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
[Column(title:"Цена", width:50)]
|
||||
public double Cost { get; set; }
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,15 +11,17 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class MessageInfoViewModel : IMessageInfoModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
[Column(visible:false)]
|
||||
public int? ClientId { get; set; }
|
||||
[DisplayName("Отправитель")]
|
||||
[Column(title:"Отправитель", width:75)]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
[DisplayName("Доставлено")]
|
||||
[Column(title:"Доставлено")]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
[DisplayName("Заголовок")]
|
||||
[Column(title:"Заголовок", width:75)]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
[DisplayName("Текст")]
|
||||
[Column(title:"Текст", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Enums;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Enums;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -11,27 +12,31 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
[Column(title:"Номер")]
|
||||
public int Id { get; set; }
|
||||
[Column(visible:false)]
|
||||
public int PastryId { get; set; }
|
||||
[DisplayName("Кондитерское изделие")]
|
||||
[Column(title:"Кондитерское изделие", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)]
|
||||
public string PastryName { get; set; } = string.Empty;
|
||||
[Column(visible:false)]
|
||||
public int? ImplementerId { get; set; }
|
||||
[DisplayName("Исполнитель")]
|
||||
[Column(title:"Исполнитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string? ImplementerFIO { get; set; }
|
||||
[Column(visible:false)]
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
[Column(title:"ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[Column(visible:false)]
|
||||
public string ClientEmail { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
[Column(title:"Количество", width:100)]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
[Column(title:"Сумма", width:100)]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
[Column(title:"Статус", width:125)]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[DisplayName("Дата создания")]
|
||||
[Column(title:"Дата создания", width: 120)]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[DisplayName("Дата выполнения")]
|
||||
[Column(title:"Дата выполнения", width: 120)]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,11 +11,13 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class PastryViewModel : IPastryModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название кондитерского изделия")]
|
||||
[Column(title:"Название кондитерского изделия", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)]
|
||||
public string PastryName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
[Column(title:"Цена", width:75)]
|
||||
public double Price { get; set; }
|
||||
[Column(visible:false)]
|
||||
public Dictionary<int, (IIngredientModel, int)> PastryIngredients
|
||||
{
|
||||
get;
|
||||
|
@ -20,4 +20,8 @@
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,26 @@
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryDataBaseImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement
|
||||
{
|
||||
public class DataBaseImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 3;
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<IPastryStorage, PastryStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Implements
|
||||
{
|
||||
public class BackUpInfo : IBackUpInfo
|
||||
{
|
||||
public List<T>? GetList<T>() where T : class, new()
|
||||
{
|
||||
using var context = new ConfectioneryDatabase();
|
||||
return context.Set<T>().ToList();
|
||||
}
|
||||
|
||||
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||
{
|
||||
var assembly = typeof(BackUpInfo).Assembly;
|
||||
var types = assembly.GetTypes();
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -6,18 +6,24 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
|
@ -6,20 +6,27 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public int WorkExperience { get; set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public int Qualification { get; set; }
|
||||
[ForeignKey("ImplementerId")]
|
||||
|
@ -6,16 +6,21 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Ingredient : IIngredientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string IngredientName { get; private set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[ForeignKey("IngredientId")]
|
||||
|
@ -6,23 +6,31 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
[DataMember]
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
public int? ClientId { get; set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
|
@ -6,29 +6,40 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public int PastryId { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
public virtual Client Client { get; set; } = new();
|
||||
[DataMember]
|
||||
public int? ImplementerId { get; set; }
|
||||
public virtual Implementer? Implementer { get; set; } = new();
|
||||
[DataMember]
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; }
|
||||
[DataMember]
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(ConfectioneryDatabase context, OrderBindingModel? model)
|
||||
{
|
||||
|
@ -6,19 +6,25 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataBaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Pastry : IPastryModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
[DataMember]
|
||||
[Required]
|
||||
public string PastryName { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IIngredientModel, int)>? _pastryIngredients = null;
|
||||
[DataMember]
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IIngredientModel, int)> PastryIngredients
|
||||
{
|
||||
|
@ -11,4 +11,8 @@
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,26 @@
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryFileImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement
|
||||
{
|
||||
public class FileImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 1;
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<IPastryStorage, PastryStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement.Implements
|
||||
{
|
||||
public class BackUpInfo : IBackUpInfo
|
||||
{
|
||||
public readonly DataFileSingleton _source;
|
||||
|
||||
public BackUpInfo()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<T>? GetList<T>() where T : class, new()
|
||||
{
|
||||
Type type = typeof(T);
|
||||
var list = _source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments().First() == type)?.GetValue(_source);
|
||||
return (List<T>?)list;
|
||||
}
|
||||
|
||||
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||
{
|
||||
var assembly = typeof(BackUpInfo).Assembly;
|
||||
var types = assembly.GetTypes();
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,17 +4,23 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
[DataMember]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
|
@ -5,21 +5,25 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? model)
|
||||
|
@ -5,16 +5,21 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Ingredient : IIngredientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
public string IngredientName { get; private set; } = string.Empty;
|
||||
[DataMember]
|
||||
public double Cost { get; set; }
|
||||
public static Ingredient? Create(IngredientBindingModel model)
|
||||
{
|
||||
|
@ -4,19 +4,27 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
[DataMember]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
public int? ClientId { get; set; }
|
||||
[DataMember]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
[DataMember]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
[DataMember]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
|
@ -5,25 +5,33 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
public int PastryId { get; private set; }
|
||||
[DataMember]
|
||||
public int ClientId { get; private set; }
|
||||
[DataMember]
|
||||
public int? ImplementerId { get; private set; }
|
||||
[DataMember]
|
||||
public int Count { get; private set; }
|
||||
[DataMember]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime DateCreate { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
|
@ -4,17 +4,23 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Pastry
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[DataMember]
|
||||
public string PastryName { get; private set; } = string.Empty;
|
||||
[DataMember]
|
||||
public double Price { get; private set; }
|
||||
[DataMember]
|
||||
public Dictionary<int, int> Ingredients { get; private set; } = new();
|
||||
private Dictionary<int, (IIngredientModel, int)>? _pastryIngredients = null;
|
||||
public Dictionary<int, (IIngredientModel, int)> PastryIngredients
|
||||
|
@ -11,4 +11,8 @@
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,22 @@
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryListImplement.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();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryListImplement.Implements;
|
||||
using ConfectioneryListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryListImplement
|
||||
{
|
||||
public class ListImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 0;
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<IPastryStorage, PastryStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user