diff --git a/.gitignore b/.gitignore
index ca1c7a3..1ce540f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+*.dll
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj
index 0093495..de2efce 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj
@@ -27,7 +27,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs
new file mode 100644
index 0000000..1da18aa
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs
@@ -0,0 +1,45 @@
+using BlacksmithWorkshopContracts.Attributes;
+
+namespace BlacksmithWorkshopView
+{
+ internal static class DataGridViewExtension
+ {
+ public static void FillandConfigGrid(this DataGridView grid, List? 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;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs
index b81aff1..cd7b768 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs
@@ -22,13 +22,7 @@ namespace BlacksmithWorkshopView
{
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)
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs
index 4a1561e..ada7462 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs
@@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
@@ -22,13 +23,7 @@ namespace BlacksmithWorkshopView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["Id"].Visible = false;
- dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
@@ -39,27 +34,21 @@ namespace BlacksmithWorkshopView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
- if (service is FormComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
- if (service is FormComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs
index ca1e4c3..3eec99a 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs
@@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
@@ -22,13 +23,7 @@ namespace BlacksmithWorkshopView
{
try
{
- var list = _implementerLogic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- //dataGridView.Columns["Id"].Visible = false;
- //dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridView.FillandConfigGrid(_implementerLogic.ReadList(null));
_logger.LogInformation("Загрузка сотрудников");
}
catch (Exception ex)
@@ -39,27 +34,21 @@ namespace BlacksmithWorkshopView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
- if (service is FormImplementer form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
- if (service is FormImplementer form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
index 13936eb..3e69517 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
@@ -18,10 +18,7 @@ namespace BlacksmithWorkshopView
try
{
_logger.LogInformation("Загрузка списка писем");
- dataGridView.DataSource = _messageLogic.ReadList(null);
- dataGridView.Columns["MessageId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.FillandConfigGrid(_messageLogic.ReadList(null));
}
catch (Exception ex)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
index cd4bbac..e3c7874 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
@@ -39,11 +39,12 @@
this.reportManufactureComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.doWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.mailsToolStripMenuItem = 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.mailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.backupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@@ -54,7 +55,8 @@
this.refbooksToolStripMenuItem,
this.reportsToolStripMenuItem,
this.doWorkToolStripMenuItem,
- this.mailsToolStripMenuItem});
+ this.mailsToolStripMenuItem,
+ this.backupToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1795, 24);
@@ -138,6 +140,13 @@
this.doWorkToolStripMenuItem.Text = "Запуск работ";
this.doWorkToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click);
//
+ // mailsToolStripMenuItem
+ //
+ this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem";
+ this.mailsToolStripMenuItem.Size = new System.Drawing.Size(62, 20);
+ this.mailsToolStripMenuItem.Text = "Письма";
+ this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click);
+ //
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
@@ -181,12 +190,12 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
- // mailsToolStripMenuItem
+ // backupToolStripMenuItem
//
- this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem";
- this.mailsToolStripMenuItem.Size = new System.Drawing.Size(62, 20);
- this.mailsToolStripMenuItem.Text = "Письма";
- this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click);
+ this.backupToolStripMenuItem.Name = "backupToolStripMenuItem";
+ this.backupToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
+ this.backupToolStripMenuItem.Text = "Бэкап";
+ this.backupToolStripMenuItem.Click += new System.EventHandler(this.BackupToolStripMenuItem_Click);
//
// FormMain
//
@@ -228,5 +237,6 @@
private ToolStripMenuItem implementersToolStripMenuItem;
private ToolStripMenuItem doWorkToolStripMenuItem;
private ToolStripMenuItem mailsToolStripMenuItem;
+ private ToolStripMenuItem backupToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
index 0e83f74..d12c208 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
@@ -1,6 +1,7 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
@@ -13,7 +14,8 @@ namespace BlacksmithWorkshopView
private readonly IReportLogic _reportLogic;
private readonly IImplementerLogic _implementerLogic;
private readonly IWorkProcess _workProcess;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic, IMessageInfoLogic messageInfoLogic)
+ private readonly IBackupLogic _backupLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic, IMessageInfoLogic messageInfoLogic, IBackupLogic backupLogic)
{
InitializeComponent();
_logger = logger;
@@ -21,6 +23,7 @@ namespace BlacksmithWorkshopView
_reportLogic = reportLogic;
_workProcess = workProcess;
_implementerLogic = implementerLogic;
+ _backupLogic = backupLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
@@ -31,15 +34,7 @@ namespace BlacksmithWorkshopView
_logger.LogInformation("Загрузка заказов");
try
{
- var list = _orderLogic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["ManufactureId"].Visible = false;
- dataGridView.Columns["ImplementerId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
}
catch (Exception ex)
{
@@ -49,28 +44,19 @@ namespace BlacksmithWorkshopView
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
- if (service is FormComponents form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
private void ManufacturesToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormManufactures));
- if (service is FormManufactures form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
- if (service is FormCreateOrder form)
- {
- form.ShowDialog();
- LoadData();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
@@ -166,39 +152,27 @@ namespace BlacksmithWorkshopView
}
private void ReportManufactureComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormReportManufactureComponents));
- if (service is FormReportManufactureComponents form)
- {
- form.ShowDialog();
- LoadData();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
}
private void ReportOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
- if (service is FormReportOrders form)
- {
- form.ShowDialog();
- LoadData();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormClients));
- if (service is FormClients form)
- {
- form.ShowDialog();
- LoadData();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
}
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
- if (service is FormImplementers form)
- {
- form.ShowDialog();
- LoadData();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
}
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
@@ -207,11 +181,18 @@ namespace BlacksmithWorkshopView
private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormMails));
- if (service is FormMails form)
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
+ }
+
+ private void BackupToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ using var dialog = new FolderBrowserDialog();
+ if (dialog.ShowDialog() == DialogResult.OK)
{
- form.ShowDialog();
- LoadData();
+ _backupLogic.CreateBackup(new() { FolderName = dialog.SelectedPath});
+ MessageBox.Show("Бэкап сохранен", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs
index 26db474..526331f 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs
@@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.DI;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopDataModels.Models;
using Microsoft.Extensions.Logging;
@@ -70,48 +71,42 @@ namespace BlacksmithWorkshopView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent));
- if (service is FormManufactureComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
+ if (form.ComponentModel == null)
{
- if (form.ComponentModel == null)
- {
- return;
- }
- _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
- if (_manufactureComponents.ContainsKey(form.Id))
- {
- _manufactureComponents[form.Id] = (form.ComponentModel, form.Count);
- }
- else
- {
- _manufactureComponents.Add(form.Id, (form.ComponentModel, form.Count));
- }
- LoadData();
+ return;
}
+ _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_manufactureComponents.ContainsKey(form.Id))
+ {
+ _manufactureComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _manufactureComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent));
- if (service is FormManufactureComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _manufactureComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
{
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
- form.Id = id;
- form.Count = _manufactureComponents[id].Item2;
- if (form.ShowDialog() == DialogResult.OK)
+ if (form.ComponentModel == null)
{
- if (form.ComponentModel == null)
- {
- return;
- }
- _logger.LogInformation("Изменение компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count);
- _manufactureComponents[form.Id] = (form.ComponentModel, form.Count);
- LoadData();
+ return;
}
+ _logger.LogInformation("Изменение компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count);
+ _manufactureComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
}
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs
index 429a101..941a1fa 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs
@@ -1,5 +1,6 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
@@ -22,14 +23,7 @@ namespace BlacksmithWorkshopView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["Id"].Visible = false;
- dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- dataGridView.Columns["ManufactureComponents"].Visible = false;
- }
+ dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
@@ -40,27 +34,21 @@ namespace BlacksmithWorkshopView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormManufacture));
- if (service is FormManufacture form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormManufacture));
- if (service is FormManufacture form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
index 1273bd2..0161216 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
@@ -6,9 +6,7 @@ using BlacksmithWorkShopBusinessLogic.BusinessLogics;
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
-using BlacksmithWorkshopContracts.StoragesContracts;
-using BlacksmithWorkshopDatabaseImplement.Implements;
-using Microsoft.Extensions.DependencyInjection;
+using BlacksmithWorkshopContracts.DI;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
@@ -16,20 +14,16 @@ namespace BlacksmithWorkshopView
{
internal static class Program
{
- private static ServiceProvider? _serviceProvider;
- public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread]
static void Main()
{
// 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();
+ var mailSender = DependencyManager.Instance.Resolve();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@@ -44,50 +38,47 @@ namespace BlacksmithWorkshopView
}
catch (Exception ex)
{
- var logger = _serviceProvider.GetService();
+ var logger = DependencyManager.Instance.Resolve();
logger?.LogError(ex, " ");
}
- Application.Run(_serviceProvider.GetRequiredService());
+ Application.Run(DependencyManager.Instance.Resolve());
}
- private static void ConfigureServices(ServiceCollection services)
- {
- services.AddLogging(option =>
- {
- option.SetMinimumLevel(LogLevel.Information);
- option.AddNLog("nlog.config");
- });
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddSingleton();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ private static void InitDependency()
+ {
+ DependencyManager.InitDependency();
+ DependencyManager.Instance.AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType(true);
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
}
- private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck();
+
+ private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck();
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs
new file mode 100644
index 0000000..342ef23
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs
@@ -0,0 +1,96 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopDataModels;
+using Microsoft.Extensions.Logging;
+using System.IO.Compression;
+using System.Reflection;
+using System.Runtime.Serialization.Json;
+
+namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
+{
+ public class BackupLogic : IBackupLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IBackupInfo _BackupInfo;
+ public BackupLogic(ILogger logger, IBackupInfo BackupInfo)
+ {
+ _logger = logger;
+ _BackupInfo = BackupInfo;
+ }
+ public void CreateBackup(BackupSaveBindingModel 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(string folderName) where T : class, new()
+ {
+ var records = _BackupInfo.GetList();
+ if (records == null)
+ {
+ _logger.LogWarning("{type} type get null list", typeof(T).Name);
+ return;
+ }
+ var jsonFormatter = new DataContractJsonSerializer(typeof(List));
+ using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
+ jsonFormatter.WriteObject(fs, records);
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs
new file mode 100644
index 0000000..68c8093
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs
@@ -0,0 +1,20 @@
+namespace BlacksmithWorkshopContracts.Attributes
+{
+ [AttributeUsage(AttributeTargets.Property)]
+ public class ColumnAttribute : Attribute
+ {
+ 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;
+ }
+ 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; }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs
new file mode 100644
index 0000000..797be4d
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs
@@ -0,0 +1,14 @@
+namespace BlacksmithWorkshopContracts.Attributes
+{
+ public enum GridViewAutoSize
+ {
+ NotSet = 0,
+ None = 1,
+ ColumnHeader = 2,
+ AllCellsExceptHeader = 4,
+ AllCells = 6,
+ DisplayedCellsExceptHeader = 8,
+ DisplayedCells = 10,
+ Fill = 16
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackupSaveBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackupSaveBindingModel.cs
new file mode 100644
index 0000000..b335377
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackupSaveBindingModel.cs
@@ -0,0 +1,7 @@
+namespace BlacksmithWorkshopContracts.BindingModels
+{
+ public class BackupSaveBindingModel
+ {
+ public string FolderName { get; set; } = string.Empty;
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs
index 04ca249..c24935f 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel.cs
@@ -4,6 +4,7 @@ namespace BlacksmithWorkshopContracts.BindingModels
{
public class MessageInfoBindingModel : IMessageInfoModel
{
+ public int Id { get; set; }
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
public string SenderName { get; set; } = string.Empty;
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj
index f685e06..2216d57 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj
@@ -6,6 +6,12 @@
enable
+
+
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackupLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackupLogic.cs
new file mode 100644
index 0000000..b40435f
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackupLogic.cs
@@ -0,0 +1,9 @@
+using BlacksmithWorkshopContracts.BindingModels;
+
+namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
+{
+ public interface IBackupLogic
+ {
+ void CreateBackup(BackupSaveBindingModel model);
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs
new file mode 100644
index 0000000..006ed57
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs
@@ -0,0 +1,69 @@
+using ConfectioneryContracts.DI;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopContracts.DI
+{
+ ///
+ /// Менеджер для работы с зависимостями
+ ///
+ public class DependencyManager
+ {
+ private readonly IDependencyContainer _dependencyManager;
+ private static DependencyManager? _manager;
+ private static readonly object _locjObject = new();
+ private DependencyManager()
+ {
+ _dependencyManager = new UnityDependencyContainer();
+ }
+ public static DependencyManager Instance
+ {
+ get
+ {
+ if (_manager == null)
+ {
+ lock (_locjObject)
+ {
+ _manager = new DependencyManager();
+ }
+ }
+ return _manager;
+ }
+ }
+ ///
+ /// Иницализация библиотек, в которых идут установки зависомстей
+ ///
+ public static void InitDependency()
+ {
+ var ext = ServiceProviderLoader.GetImplementationExtensions();
+ if (ext == null)
+ {
+ throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
+ }
+ // регистрируем зависимости
+ ext.RegisterServices();
+ }
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure);
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle);
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle);
+ ///
+ /// Получение класса со всеми зависмостями
+ ///
+ ///
+ ///
+ public T Resolve() => _dependencyManager.Resolve();
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs
new file mode 100644
index 0000000..76d89af
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs
@@ -0,0 +1,32 @@
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopContracts.DI
+{
+ public interface IDependencyContainer
+ {
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ void AddLogging(Action configure);
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ ///
+ void RegisterType(bool isSingle) where U : class, T where T : class;
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ void RegisterType(bool isSingle) where T : class;
+ ///
+ /// Получение класса со всеми зависмостями
+ ///
+ ///
+ ///
+ T Resolve();
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IIpmlementationExtention.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IIpmlementationExtention.cs
new file mode 100644
index 0000000..a8b9121
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IIpmlementationExtention.cs
@@ -0,0 +1,11 @@
+namespace BlacksmithWorkshopContracts.DI
+{
+ public interface IImplementationExtension
+ {
+ public int Priority { get; }
+ ///
+ /// Регистрация сервисов
+ ///
+ public void RegisterServices();
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs
new file mode 100644
index 0000000..e0b8f80
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs
@@ -0,0 +1,51 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopContracts.DI
+{
+ public class ServiceDependencyContainer : IDependencyContainer
+ {
+ private ServiceProvider? _serviceProvider;
+ private readonly ServiceCollection _serviceCollection;
+ public ServiceDependencyContainer()
+ {
+ _serviceCollection = new();
+ }
+ public void AddLogging(Action configure)
+ {
+ _serviceCollection.AddLogging(configure);
+ }
+ public void RegisterType(bool isSingle) where U : class, T where T : class
+ {
+ if (isSingle)
+ {
+ _serviceCollection.AddSingleton();
+ }
+ else
+ {
+ _serviceCollection.AddTransient();
+ }
+ _serviceProvider = null;
+ }
+ public void RegisterType(bool isSingle) where T : class
+ {
+ if (isSingle)
+ {
+ _serviceCollection.AddSingleton();
+ }
+ else
+ {
+ _serviceCollection.AddTransient();
+ }
+ _serviceProvider = null;
+ }
+ public T Resolve()
+ {
+ if (_serviceProvider == null)
+ {
+ _serviceProvider = _serviceCollection.BuildServiceProvider();
+ }
+ return _serviceProvider.GetService()!;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs
new file mode 100644
index 0000000..d8fc324
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs
@@ -0,0 +1,53 @@
+using System.Reflection;
+
+namespace BlacksmithWorkshopContracts.DI
+{
+ public class ServiceProviderLoader
+ {
+ ///
+ /// Загрузка всех классов-реализаций IImplementationExtension
+ ///
+ ///
+ 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";
+ }
+
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs
new file mode 100644
index 0000000..d1cbf87
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/UnityDependencyContainer.cs
@@ -0,0 +1,33 @@
+using BlacksmithWorkshopContracts.DI;
+using Microsoft.Extensions.Logging;
+using Unity;
+using Unity.Microsoft.Logging;
+
+namespace ConfectioneryContracts.DI
+{
+ public class UnityDependencyContainer : IDependencyContainer
+ {
+ private readonly IUnityContainer _container;
+ public UnityDependencyContainer()
+ {
+ _container = new UnityContainer();
+ }
+ public void AddLogging(Action configure)
+ {
+ var factory = LoggerFactory.Create(configure);
+ _container.AddExtension(new LoggingExtension(factory));
+ }
+ public void RegisterType(bool isSingle) where T : class
+ {
+ _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
+ }
+ public T Resolve()
+ {
+ return _container.Resolve();
+ }
+ void IDependencyContainer.RegisterType(bool isSingle)
+ {
+ _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
+ }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackupInfo.cs
new file mode 100644
index 0000000..3d087f0
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackupInfo.cs
@@ -0,0 +1,8 @@
+namespace BlacksmithWorkshopContracts.StoragesContracts
+{
+ public interface IBackupInfo
+ {
+ List? GetList() where T : class, new();
+ Type? GetTypeByModelInterface(string modelInterfaceName);
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs
index e6dbc79..2aee158 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs
@@ -1,16 +1,17 @@
-using BlacksmithWorkshopDataModels.Models;
-using System.ComponentModel;
+using BlacksmithWorkshopContracts.Attributes;
+using BlacksmithWorkshopDataModels.Models;
namespace BlacksmithWorkshopContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
+ [Column(visible: false)]
public int Id { get; set; }
- [DisplayName("ФИО клиента")]
+ [Column(title: "ФИО клиента", width: 150)]
public string ClientFIO { get; set; } = string.Empty;
- [DisplayName("Логин (эл. почта)")]
+ [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Email { get; set; } = string.Empty;
- [DisplayName("Пароль")]
- public string Password { get; set; } = string.Empty;
+ [Column(title: "Пароль", width: 150)]
+ public string Password { get; set; } = string.Empty;
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs
index 945cc46..32b1a67 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs
@@ -1,14 +1,16 @@
-using BlacksmithWorkshopDataModels.Models;
+using BlacksmithWorkshopContracts.Attributes;
+using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel;
namespace BlacksmithWorkshopContracts.ViewModels
{
public class ComponentViewModel : IComponentModel
{
- public int Id { get; set; }
- [DisplayName("Название компонента")]
- public string ComponentName { get; set; } = string.Empty;
- [DisplayName("Цена")]
- public double Cost { get; set; }
+ [Column(visible: false)]
+ public int Id { get; set; }
+ [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ComponentName { get; set; } = string.Empty;
+ [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 150)]
+ public double Cost { get; set; }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs
index 4a9acfd..08bc925 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs
@@ -1,18 +1,20 @@
-using BlacksmithWorkshopDataModels.Models;
+using BlacksmithWorkshopContracts.Attributes;
+using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel;
namespace BlacksmithWorkshopContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
+ [Column(visible: false)]
public int Id { get; set; }
- [DisplayName("Имя")]
+ [Column(title: "Имя", width: 150, 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: 150)]
public int WorkExperience { get; set; }
- [DisplayName("Квалификация")]
+ [Column(title: "Квалификация", width: 150)]
public int Qualification { get; set; }
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs
index 25732a6..f9c86fb 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs
@@ -1,15 +1,18 @@
-using BlacksmithWorkshopDataModels.Models;
+using BlacksmithWorkshopContracts.Attributes;
+using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel;
namespace BlacksmithWorkshopContracts.ViewModels
{
public class ManufactureViewModel : IManufactureModel
{
- public int Id { get; set; }
- [DisplayName("Название изделия")]
- public string ManufactureName { get; set; } = string.Empty;
- [DisplayName("Цена")]
- public double Price { get; set; }
- public Dictionary ManufactureComponents { get; set; } = new();
+ [Column(visible: false)]
+ public int Id { get; set; }
+ [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ManufactureName { get; set; } = string.Empty;
+ [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 150)]
+ public double Price { get; set; }
+ [Column(visible: false)]
+ public Dictionary ManufactureComponents { get; set; } = new();
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs
index 6e5054c..1708292 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs
@@ -1,19 +1,24 @@
-using BlacksmithWorkshopDataModels.Models;
+using BlacksmithWorkshopContracts.Attributes;
+using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel;
namespace BlacksmithWorkshopContracts.ViewModels
{
public class MessageInfoViewModel : IMessageInfoModel
{
+ [Column(visible: false)]
+ public int Id { get; set; }
+ [Column(visible: false)]
public string MessageId { get; set; } = string.Empty;
+ [Column(visible: false)]
public int? ClientId { get; set; }
- [DisplayName("Отправитель")]
+ [Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty;
- [DisplayName("Дата")]
+ [Column(title: "Дата", width: 150)]
public DateTime DateDelivery { get; set; } = DateTime.Now;
- [DisplayName("Заголовок")]
+ [Column(title: "Заголовок", width: 150)]
public string Subject { get; set; } = string.Empty;
- [DisplayName("Текст")]
+ [Column(title: "Текст", width: 150, gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty;
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
index 8e6e8e3..e9d2f78 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
@@ -1,4 +1,5 @@
-using BlacksmithWorkshopDataModels.Enums;
+using BlacksmithWorkshopContracts.Attributes;
+using BlacksmithWorkshopDataModels.Enums;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel;
@@ -6,26 +7,29 @@ namespace BlacksmithWorkshopContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
- [DisplayName("Номер")]
- public int Id { get; set; }
- public int ManufactureId { get; set; }
- public int ClientId { get; set; }
- [DisplayName("Изделие")]
- public string ManufactureName { get; set; } = string.Empty;
- [DisplayName("Количество")]
- public int Count { get; set; }
- [DisplayName("Сумма")]
- public double Sum { get; set; }
- [DisplayName("Статус")]
- public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
- [DisplayName("Дата создания")]
- public DateTime DateCreate { get; set; } = DateTime.Now;
- [DisplayName("Дата выполнения")]
- public DateTime? DateImplement { get; set; }
- [DisplayName("Клиент")]
+ [Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 100, isUseAutoSize: true)]
+ public int Id { get; set; }
+ [Column(visible: false)]
+ public int ManufactureId { get; set; }
+ [Column(visible: false)]
+ public int ClientId { get; set; }
+ [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ManufactureName { get; set; } = string.Empty;
+ [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 100)]
+ public int Count { get; set; }
+ [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 100)]
+ public double Sum { get; set; }
+ [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 100)]
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ [Column(title: "Дата создания", gridViewAutoSize: GridViewAutoSize.ColumnHeader, isUseAutoSize: true)]
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ [Column(title: "Дата выполнения", gridViewAutoSize: GridViewAutoSize.ColumnHeader, isUseAutoSize: true)]
+ public DateTime? DateImplement { get; set; }
+ [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 500, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty;
+ [Column(visible: false)]
public int? ImplementerId { get; set; }
- [DisplayName("Исполнитель")]
+ [Column(title: "Исполнитель", gridViewAutoSize: GridViewAutoSize.ColumnHeader, width: 150, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty;
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs
index c4d7246..5ca9a6c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs
@@ -1,6 +1,6 @@
namespace BlacksmithWorkshopDataModels.Models
{
- public interface IMessageInfoModel
+ public interface IMessageInfoModel : IId
{
string MessageId { get; }
int? ClientId { get; }
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs
new file mode 100644
index 0000000..9a25a11
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs
@@ -0,0 +1,29 @@
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopDatabaseImplement.Implements;
+
+namespace BlacksmithWorkshopDatabaseImplement
+{
+ public class BackupInfo : IBackupInfo
+ {
+ public List? GetList() where T : class, new()
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Set().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;
+ }
+
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
index a5d5c4a..7080457 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -19,4 +19,8 @@
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/DatabaseImplementationExtention.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/DatabaseImplementationExtention.cs
new file mode 100644
index 0000000..617362e
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/DatabaseImplementationExtention.cs
@@ -0,0 +1,21 @@
+using BlacksmithWorkshopContracts.DI;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopDatabaseImplement.Implements;
+
+namespace BlacksmithWorkshopDatabaseImplement
+{
+ public class DatabaseImplementationExtention : IImplementationExtension
+ {
+ public int Priority => 2;
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/BackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/BackupInfo.cs
new file mode 100644
index 0000000..264706f
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/BackupInfo.cs
@@ -0,0 +1,28 @@
+using BlacksmithWorkshopContracts.StoragesContracts;
+
+namespace BlacksmithWorkshopDatabaseImplement.Implements
+{
+ public class BackupInfo : IBackupInfo
+ {
+ public List? GetList() where T : class, new()
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Set().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;
+ }
+
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Client.cs
index c135fa5..87e24e8 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Client.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Client.cs
@@ -3,16 +3,22 @@ using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.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 Email { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Component.cs
index b89c52d..152b2bf 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Component.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Component.cs
@@ -3,14 +3,19 @@ using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
+ [DataContract]
public class Component : IComponentModel
{
+ [DataMember]
public int Id {get; private set;}
+ [DataMember]
[Required]
public string ComponentName { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public double Cost { get; set; }
[ForeignKey("ComponentId")]
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs
index ea3eaba..0bc344c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs
@@ -3,18 +3,25 @@ using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
+ [DataContract]
public class Implementer : IImplementerModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public string Password { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public int WorkExperience { get; private set; }
+ [DataMember]
[Required]
public int Qualification { get; private set; }
//Привязываем исполнителя к заказам один ко многим
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Manufacture.cs
index e9aaf67..ffa8b2c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Manufacture.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Manufacture.cs
@@ -3,14 +3,19 @@ using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
+ [DataContract]
public class Manufacture : IManufactureModel
{
+ [DataMember]
public int Id { get; set; }
+ [DataMember]
[Required]
public string ManufactureName { get; set; } = string.Empty;
+ [DataMember]
[Required]
public double Price { get; set; }
private Dictionary? _manufactureComponents = null;
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/ManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/ManufactureComponent.cs
index ec51192..5a0f207 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/ManufactureComponent.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/ManufactureComponent.cs
@@ -1,14 +1,20 @@
using System.ComponentModel.DataAnnotations;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
+ [DataContract]
public class ManufactureComponent
{
+ [DataMember]
public int Id { get; set; }
+ [DataMember]
[Required]
public int ManufactureId { get; set; }
+ [DataMember]
[Required]
public int ComponentId { get; set; }
+ [DataMember]
[Required]
public int Count { get; set; }
public virtual Component Component { get; set; } = new();
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/MessageInfo.cs
index 66a38f4..7ec4915 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/MessageInfo.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/MessageInfo.cs
@@ -2,20 +2,27 @@
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
+ [DataContract]
public class MessageInfo : IMessageInfoModel
{
+ [DataMember]
[Key]
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; }
+ [DataMember]
[Required]
public string SenderName { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
+ [DataMember]
[Required]
public string Subject { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public string Body { get; private set; } = string.Empty;
public Client? Client { get; private set; }
@@ -44,5 +51,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
SenderName = SenderName,
DateDelivery = DateDelivery,
};
+
+ public int Id => throw new NotImplementedException();
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs
index c217dda..ba7a58e 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs
@@ -3,23 +3,33 @@ using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Enums;
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
+using System.Runtime.Serialization;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
+ [DataContract]
public class Order : IOrderModel
{
+ [DataMember]
public int Id { get; set; }
+ [DataMember]
[Required]
public int ManufactureId { get; set; }
+ [DataMember]
[Required]
public int Count { get; private set; }
+ [DataMember]
[Required]
public double Sum { get; private set; }
+ [DataMember]
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+ [DataMember]
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
+ [DataMember]
public DateTime? DateImplement { get; private set; }
+ [DataMember]
[Required]
public int ClientId { get; private set; }
[Required]
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
index 4b2145e..cd5cbb9 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
@@ -10,4 +10,8 @@
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs
new file mode 100644
index 0000000..8fc53c3
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/FileImplementationExtension.cs
@@ -0,0 +1,21 @@
+using BlacksmithWorkshopContracts.DI;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopFileImplement.Implements;
+
+namespace BlacksmithWorkshopFileImplement
+{
+ public class FileImplementationExtension : IImplementationExtension
+ {
+ public int Priority => 1;
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackupInfo.cs
new file mode 100644
index 0000000..9228ce8
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/BackupInfo.cs
@@ -0,0 +1,28 @@
+using BlacksmithWorkshopContracts.StoragesContracts;
+
+namespace BlacksmithWorkshopFileImplement.Implements
+{
+ public class BackupInfo : IBackupInfo
+ {
+ public List? GetList() where T : class, new()
+ {
+ var source = DataFileSingleton.GetInstance();
+ return (List?)source.GetType().GetProperties()
+ .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
+ ?.GetValue(source);
+ }
+ 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;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs
index 1a3e560..b9bb21c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs
@@ -1,15 +1,21 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
+ [DataContract]
public class Client : IClientModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string ClientFIO { get; private set; } = string.Empty;
+ [DataMember]
public string Email { get; private set; } = string.Empty;
+ [DataMember]
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel model)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Component.cs
index a3aa6cc..e4134be 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Component.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Component.cs
@@ -1,15 +1,20 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
+ [DataContract]
public class Component : IComponentModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string ComponentName { get; private set; } = string.Empty;
+ [DataMember]
public double Cost {get; set; }
public static Component? Create(ComponentBindingModel model)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs
index 49b3d73..dbe27f9 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs
@@ -1,16 +1,23 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
+ [DataContract]
public class Implementer : IImplementerModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
+ [DataMember]
public string Password { get; private set; } = string.Empty;
+ [DataMember]
public int WorkExperience { get; private set; }
+ [DataMember]
public int Qualification { get; private set; }
public static Implementer? Create(XElement element)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs
index 2ae1b94..33e46c6 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs
@@ -1,16 +1,22 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
+ [DataContract]
public class Manufacture : IManufactureModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string ManufactureName { get; private set; } = string.Empty;
+ [DataMember]
public double Price { get; private set; }
public Dictionary Components { get; private set; } = new();
private Dictionary? _manufactureComponents = null;
+ [DataMember]
public Dictionary ManufactureComponents
{
get
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs
index 3542396..0274ebd 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/MessageInfo.cs
@@ -1,17 +1,25 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
+ [DataContract]
public class MessageInfo : IMessageInfoModel
{
+ [DataMember]
public string MessageId { get; private set; } = string.Empty;
+ [DataMember]
public int? ClientId { get; private set; }
+ [DataMember]
public string SenderName { get; private set; } = string.Empty;
+ [DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
+ [DataMember]
public string Subject { get; private set; } = string.Empty;
+ [DataMember]
public string Body { get; private set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
{
@@ -62,5 +70,6 @@ namespace BlacksmithWorkshopFileImplement.Models
new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery)
);
+ public int Id => throw new NotImplementedException();
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
index 55d50b4..4ff762b 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
@@ -3,20 +3,31 @@ using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Enums;
using BlacksmithWorkshopDataModels.Models;
using System.Reflection;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
+ [DataContract]
public class Order : IOrderModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public int ManufactureId {get; private set; }
+ [DataMember]
public int Count { get; private set; }
+ [DataMember]
public double Sum { get; private set; }
+ [DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+ [DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
+ [DataMember]
public DateTime? DateImplement { get; private set; }
+ [DataMember]
public int ClientId { get; private set; }
+ [DataMember]
public int? ImplementerId { get; set; }
public static Order? Create(OrderBindingModel? model)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj
index b65badc..e2ea568 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -11,4 +11,8 @@
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs
new file mode 100644
index 0000000..da9d37e
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs
@@ -0,0 +1,17 @@
+using BlacksmithWorkshopContracts.StoragesContracts;
+
+namespace BlacksmithWorkshopListImplement.Implements
+{
+ internal class BackupInfo : IBackupInfo
+ {
+ public List? GetList() where T : class, new()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Type? GetTypeByModelInterface(string modelInterfaceName)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs
index 6adac20..3bc53e0 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/MessageInfoStorage.cs
@@ -43,6 +43,7 @@ namespace BlacksmithWorkshopListImplement.Implements
}
return null;
}
+
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
var newMessage = MessageInfo.Create(model);
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs
new file mode 100644
index 0000000..e49c63b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs
@@ -0,0 +1,21 @@
+using BlacksmithWorkshopContracts.DI;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopListImplement.Implements;
+
+namespace BlacksmithWorkshopListImplement
+{
+ public class ListImplementationExtension : IImplementationExtension
+ {
+ public int Priority => 0;
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs
index 1d72b96..ac25771 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs
@@ -37,5 +37,6 @@ namespace BlacksmithWorkshopListImplement.Models
SenderName = SenderName,
DateDelivery = DateDelivery
};
+ public int Id => throw new NotImplementedException();
}
}