diff --git a/.gitignore b/.gitignore index ca1c7a3..39a68c3 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,5 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml + +/TravelCompany/ImplementationExtensions \ No newline at end of file diff --git a/TravelCompany/TravelCompany/DataGridViewExtension.cs b/TravelCompany/TravelCompany/DataGridViewExtension.cs new file mode 100644 index 0000000..39be5bc --- /dev/null +++ b/TravelCompany/TravelCompany/DataGridViewExtension.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; + +namespace TravelCompany +{ + public 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/TravelCompany/TravelCompany/FormClients.cs b/TravelCompany/TravelCompany/FormClients.cs index 59e92e7..fae10c7 100644 --- a/TravelCompany/TravelCompany/FormClients.cs +++ b/TravelCompany/TravelCompany/FormClients.cs @@ -33,19 +33,14 @@ namespace TravelCompany { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Обновление списка клиентов"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки списка клиентов!"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } diff --git a/TravelCompany/TravelCompany/FormConditions.cs b/TravelCompany/TravelCompany/FormConditions.cs index 6a870a8..9ea649c 100644 --- a/TravelCompany/TravelCompany/FormConditions.cs +++ b/TravelCompany/TravelCompany/FormConditions.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.DI; namespace TravelCompany { @@ -27,26 +28,19 @@ namespace TravelCompany { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ConditionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка условий"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки условия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCondition)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCondition form) { if (form.ShowDialog() == DialogResult.OK) @@ -59,8 +53,7 @@ namespace TravelCompany { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCondition)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCondition form) { form.Id = diff --git a/TravelCompany/TravelCompany/FormImplementers.cs b/TravelCompany/TravelCompany/FormImplementers.cs index c6b6ba8..b0045b5 100644 --- a/TravelCompany/TravelCompany/FormImplementers.cs +++ b/TravelCompany/TravelCompany/FormImplementers.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.DI; namespace TravelCompany { @@ -32,25 +33,21 @@ namespace TravelCompany { 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) { _logger.LogError(ex, "Ошибка загрузки исполнителей"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } + } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -64,7 +61,7 @@ namespace TravelCompany { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/TravelCompany/TravelCompany/FormMain.Designer.cs b/TravelCompany/TravelCompany/FormMain.Designer.cs index 0e0bc37..d7c1583 100644 --- a/TravelCompany/TravelCompany/FormMain.Designer.cs +++ b/TravelCompany/TravelCompany/FormMain.Designer.cs @@ -40,12 +40,13 @@ this.условияПоПоездкамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.почтаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьБэкапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); this.ButtonOrderReady = 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(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); @@ -72,7 +73,8 @@ this.справочникиToolStripMenuItem, this.отчетToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.почтаToolStripMenuItem}); + this.почтаToolStripMenuItem, + this.создатьБэкапToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -94,28 +96,28 @@ // условияToolStripMenuItem // this.условияToolStripMenuItem.Name = "условияToolStripMenuItem"; - this.условияToolStripMenuItem.Size = new System.Drawing.Size(185, 26); + this.условияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.условияToolStripMenuItem.Text = "Условия"; this.условияToolStripMenuItem.Click += new System.EventHandler(this.условияToolStripMenuItem_Click); // // путешествияToolStripMenuItem // this.путешествияToolStripMenuItem.Name = "путешествияToolStripMenuItem"; - this.путешествияToolStripMenuItem.Size = new System.Drawing.Size(185, 26); + this.путешествияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.путешествияToolStripMenuItem.Text = "Путешествия"; this.путешествияToolStripMenuItem.Click += new System.EventHandler(this.путешествияToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(185, 26); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // // исполнителиToolStripMenuItem // this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(185, 26); + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.исполнителиToolStripMenuItem.Text = "Исполнители"; this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); // @@ -157,6 +159,20 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); // + // почтаToolStripMenuItem + // + this.почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + this.почтаToolStripMenuItem.Size = new System.Drawing.Size(65, 24); + this.почтаToolStripMenuItem.Text = "Почта"; + this.почтаToolStripMenuItem.Click += new System.EventHandler(this.почтаToolStripMenuItem_Click); + // + // создатьБэкапToolStripMenuItem + // + this.создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem"; + this.создатьБэкапToolStripMenuItem.Size = new System.Drawing.Size(128, 24); + this.создатьБэкапToolStripMenuItem.Text = "Создать бэк-ап"; + this.создатьБэкапToolStripMenuItem.Click += new System.EventHandler(this.создатьБэкапToolStripMenuItem_Click); + // // buttonCreateOrder // this.buttonCreateOrder.Location = new System.Drawing.Point(1224, 36); @@ -212,13 +228,6 @@ this.ButtonRef.UseVisualStyleBackColor = true; this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // почтаToolStripMenuItem - // - this.почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - this.почтаToolStripMenuItem.Size = new System.Drawing.Size(65, 24); - this.почтаToolStripMenuItem.Text = "Почта"; - this.почтаToolStripMenuItem.Click += new System.EventHandler(this.почтаToolStripMenuItem_Click); - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -264,5 +273,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem создатьБэкапToolStripMenuItem; } } \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormMain.cs b/TravelCompany/TravelCompany/FormMain.cs index 370ea1c..9784c1f 100644 --- a/TravelCompany/TravelCompany/FormMain.cs +++ b/TravelCompany/TravelCompany/FormMain.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Logging; +using TravelCompanyBusinessLogic.BusinessLogic; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.DI; @@ -12,13 +14,16 @@ namespace TravelCompany private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, + IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _reportLogic = reportLogic; _logger = logger; _orderLogic = orderLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -29,17 +34,7 @@ namespace TravelCompany _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["TravelId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ClientEmail"].Visible = false; - dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); } catch (Exception ex) { @@ -50,7 +45,7 @@ namespace TravelCompany private void условияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormConditions)); + var service = DependencyManager.Instance.Resolve(); if (service is FormConditions form) { form.ShowDialog(); @@ -59,7 +54,7 @@ namespace TravelCompany private void buttonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -144,7 +139,7 @@ namespace TravelCompany private void путешествияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravels)); + var service = DependencyManager.Instance.Resolve(); if (service is FormTravels form) { form.ShowDialog(); @@ -167,8 +162,7 @@ namespace TravelCompany private void ConditionTravelsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportTravelConditions)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportTravelConditions form) { form.ShowDialog(); @@ -176,7 +170,7 @@ namespace TravelCompany } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -185,7 +179,7 @@ namespace TravelCompany private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -194,8 +188,7 @@ namespace TravelCompany private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic - )) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -203,7 +196,7 @@ namespace TravelCompany private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -212,11 +205,39 @@ namespace TravelCompany private void почтаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMail)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMail 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); + } + + } + } } } diff --git a/TravelCompany/TravelCompany/FormTravel.cs b/TravelCompany/TravelCompany/FormTravel.cs index a02c63d..b6e41ca 100644 --- a/TravelCompany/TravelCompany/FormTravel.cs +++ b/TravelCompany/TravelCompany/FormTravel.cs @@ -12,6 +12,7 @@ using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.SearchModels; using TravelCompanyDataModels.Models; using Microsoft.Extensions.Logging; +using TravelCompanyContracts.DI; namespace TravelCompany { @@ -62,24 +63,17 @@ namespace TravelCompany _logger.LogInformation("Загрузка компонент изделия"); try { - if (_travelConditions != null) - { - dataGridView.Rows.Clear(); - foreach (var pc in _travelConditions) - { - dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ConditionName, pc.Value.Item2 }); - } - textBoxPrice.Text = CalcPrice().ToString(); - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка путешествий"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + _logger.LogError(ex, "Ошибка загрузки путешествий"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - + private double CalcPrice() { double price = 0; @@ -172,7 +166,7 @@ namespace TravelCompany private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravelCondition)); + var service = DependencyManager.Instance.Resolve(); if (service is FormTravelCondition form) { if (form.ShowDialog() == DialogResult.OK) @@ -201,7 +195,7 @@ namespace TravelCompany { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravelCondition)); + var service = DependencyManager.Instance.Resolve < FormTravelCondition>(); if (service is FormTravelCondition form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/TravelCompany/TravelCompany/FormTravels.cs b/TravelCompany/TravelCompany/FormTravels.cs index 55b79e0..c31dca2 100644 --- a/TravelCompany/TravelCompany/FormTravels.cs +++ b/TravelCompany/TravelCompany/FormTravels.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.DI; namespace TravelCompany { @@ -27,15 +28,7 @@ namespace TravelCompany { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["TravelConditions"].Visible = false; - dataGridView.Columns["TravelName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка путешествий"); } catch (Exception ex) @@ -47,7 +40,7 @@ namespace TravelCompany } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); + var service = DependencyManager.Instance.Resolve(); if (service is FormTravel form) { if (form.ShowDialog() == DialogResult.OK) @@ -60,8 +53,7 @@ namespace TravelCompany { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormTravel)); + var service = DependencyManager.Instance.Resolve(); if (service is FormTravel form) { form.Id = diff --git a/TravelCompany/TravelCompany/Program.cs b/TravelCompany/TravelCompany/Program.cs index 40f6dc2..c614688 100644 --- a/TravelCompany/TravelCompany/Program.cs +++ b/TravelCompany/TravelCompany/Program.cs @@ -3,19 +3,19 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.StoragesContracts; -using TravelCompanyDatabaseImplement.Implements; using TravelCompanyBusinessLogic.BusinessLogic; using TravelCompanyBusinessLogic.OfficePackage.Implements; using TravelCompanyBusinessLogic.OfficePackage; using TravelCompanyBusinessLogic.MailWorker; using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.DI; + namespace TravelCompany { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -26,11 +26,10 @@ namespace TravelCompany // 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, @@ -45,50 +44,49 @@ namespace TravelCompany } 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) + + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.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.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(); - services.AddSingleton(); + + 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(); + 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); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/BackUpLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..b1e4ade --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,107 @@ +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; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyDataModels; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + 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(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(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/TravelCompany/TravelCompanyContracts/Attributes/ColumnAttribute.cs b/TravelCompany/TravelCompanyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..3bcdd47 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/Attributes/GridViewAutoSize.cs b/TravelCompany/TravelCompanyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..6e5ec62 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/BackUpSaveBinidngModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..175884f --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IBackUpLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..7a77d6c --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.BindingModels; + +namespace TravelCompanyContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/DependencyManager.cs b/TravelCompany/TravelCompanyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..717d83c --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/DependencyManager.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/DI/IDependencyContainer.cs b/TravelCompany/TravelCompanyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..9278d34 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/DI/IImplementationExtension.cs b/TravelCompany/TravelCompanyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..bbf03ae --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/TravelCompany/TravelCompanyContracts/DI/ServiceProviderLoader.cs b/TravelCompany/TravelCompanyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..e16addd --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.DI +{ + /// + /// Загрузчик данных + /// + public static partial 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/TravelCompany/TravelCompanyContracts/DI/UnityDependencyContainer.cs b/TravelCompany/TravelCompanyContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..7380d85 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/DI/UnityDependencyContainer.cs @@ -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 TravelCompanyContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly UnityContainer _unityContainer; + + public UnityDependencyContainer() + { + _unityContainer = new UnityContainer(); + } + public void AddLogging(Action configure) + { + _unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + if (isSingle) _unityContainer.RegisterSingleton(); + else _unityContainer.RegisterType(); + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) _unityContainer.RegisterSingleton(); + else _unityContainer.RegisterType(); + } + + public T Resolve() + { + return _unityContainer.Resolve(); + } + } +} diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/IBackUpInfo.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..d54b1ad --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj index 78baecb..c97c971 100644 --- a/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj +++ b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs index b23ad51..281504e 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ClientViewModel.cs @@ -4,18 +4,20 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; using TravelCompanyDataModels.Models; namespace TravelCompanyContracts.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; } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs index c6834be..d29347f 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs @@ -6,15 +6,17 @@ using System.Text; using System.Threading.Tasks; using TravelCompanyDataModels.Models; using System.ComponentModel; +using TravelCompanyContracts.Attributes; namespace TravelCompanyContracts.ViewModels { public class ConditionViewModel : IConditionModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название условия")] + [Column(title: "Название условия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ConditionName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public double Cost { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs index 1c11a25..44729ea 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ImplementerViewModel.cs @@ -4,20 +4,22 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; using TravelCompanyDataModels.Models; namespace TravelCompanyContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "ФИО", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = String.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = String.Empty; + [Column(title: "Стаж работы", width: 120)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 120)] public int Qualification { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs index a402198..d192ee3 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/MessageInfoViewModel.cs @@ -4,21 +4,26 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using TravelCompanyContracts.Attributes; using TravelCompanyDataModels.Models; namespace TravelCompanyContracts.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; + + public int Id { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs index 0f1e78f..b8df376 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs @@ -6,34 +6,37 @@ using System.Threading.Tasks; using TravelCompanyDataModels.Enums; using TravelCompanyDataModels.Models; using System.ComponentModel; - +using TravelCompanyContracts.Attributes; namespace TravelCompanyContracts.ViewModels { public class OrderViewModel { - [DisplayName("Номер")] + [Column(title: "Номер")] public int Id { get; set; } + [Column(visible: false)] public int TravelId { get; set; } - [DisplayName("Путешествие")] + [Column(title: "Путешествие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string TravelName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 60)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 100)] public double Sum { get; set; } - public int? ImplementerId { get; set; } - [DisplayName("ФИО Исполнителя")] - public string? ImplementerFIO { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Email клиента")] + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string? ImplementerFIO { get; set; } + [Column(visible: false)] public string ClientEmail { get; set; } = string.Empty; - [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; } + [Column(visible: false)] public int ClientId { get; set; } } diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs index 7473cff..fbcf37d 100644 --- a/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs +++ b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs @@ -5,16 +5,19 @@ using System.Text; using System.Threading.Tasks; using TravelCompanyDataModels.Models; using System.ComponentModel; +using TravelCompanyContracts.Attributes; namespace TravelCompanyContracts.ViewModels { public class TravelViewModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название путешествия")] + [Column(title: "Название путешествия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string TravelName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public double Price { get; set; } + [Column(visible: false)] public Dictionary TravelConditions { get; diff --git a/TravelCompany/TravelCompanyDatabaseImplement/DatabaseImplementationExtension.cs b/TravelCompany/TravelCompanyDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..dee4a11 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.DI; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyDatabaseImplement.Implements; + +namespace TravelCompanyDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 3; + 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/TravelCompany/TravelCompanyDatabaseImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..c00eb53 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.StoragesContracts; + +namespace TravelCompanyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new TravelCompanyDatabase(); + 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/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs index bdbebfc..5e8153d 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using TravelCompanyContracts.BindingModels; @@ -10,15 +11,19 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { + [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; set; } = string.Empty; - + [DataMember] public int Id { get; private set; } public static Client? Create(ClientBindingModel? model) diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Condition.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Condition.cs index 7c4e891..defb509 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Condition.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Condition.cs @@ -9,15 +9,19 @@ using TravelCompanyContracts.ViewModels; using TravelCompanyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; - +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Condition : IConditionModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ConditionName { get; private set; } = string.Empty; + [DataMember] [Required] public double Cost { get; set; } [ForeignKey("ConditionId")] diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs index 1e7536f..936d884 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Implementer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using TravelCompanyContracts.BindingModels; @@ -10,14 +11,19 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [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; } public int Id { get; private set; } diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs index 07a4c48..b40213f 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/MessageInfo.cs @@ -8,21 +8,29 @@ using System.Threading.Tasks; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.ViewModels; using TravelCompanyDataModels.Models; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.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; diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs index d43c200..a07b673 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using TravelCompanyContracts.BindingModels; @@ -11,24 +12,34 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public int TravelId { get; set; } + [DataMember] [Required] public int Count { get; set; } + [DataMember] [Required] public double Sum { get; set; } + [DataMember] [Required] public OrderStatus Status { get; set; } + [DataMember] [Required] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } public Travel Travel { get; 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(); diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs index 05d9520..14ce881 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs @@ -9,14 +9,19 @@ using TravelCompanyContracts.ViewModels; using TravelCompanyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TravelCompanyDatabaseImplement.Models { + [DataContract] public class Travel : ITravelModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] public string TravelName { get; set; } = string.Empty; + [DataMember] [Required] public double Price { get; set; } private Dictionary? _travelConditions = null; diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj index 6403995..53605c4 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/TravelCompany/TravelCompanyFileImplement/FileImplementationExtension.cs b/TravelCompany/TravelCompanyFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..52fd829 --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/FileImplementationExtension.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.DI; +using TravelCompanyFileImplement.Implements; + +namespace TravelCompanyFileImplement +{ + 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/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..4e21598 --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.StoragesContracts; + +namespace TravelCompanyFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public readonly DataFileSingleton _source; + + public BackUpInfo() + { + _source = DataFileSingleton.GetInstance(); + } + + public List? GetList() 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?)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; + } + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Client.cs b/TravelCompany/TravelCompanyFileImplement/Models/Client.cs index ae2b7e2..848ad13 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Client.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Client.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -10,11 +11,16 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyFileImplement.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) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Condition.cs b/TravelCompany/TravelCompanyFileImplement/Models/Condition.cs index c5944a1..b53f7d8 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Condition.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Condition.cs @@ -1,20 +1,24 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -using TravelCompanyDataModels.Models; +using System.Xml.Linq; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.ViewModels; -using System.Xml.Linq; - +using TravelCompanyDataModels.Models; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Condition : IConditionModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ConditionName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Condition? Create(ConditionBindingModel model) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs b/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs index 9ff6a92..3a2b1ec 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -10,12 +11,18 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { + [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; } + [DataMember] public int Id { get; private set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs index 749a0b2..454130d 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -10,13 +11,20 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyFileImplement.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) diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Order.cs b/TravelCompany/TravelCompanyFileImplement/Models/Order.cs index 2515aea..5bdae59 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Order.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Order.cs @@ -2,6 +2,7 @@ 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; @@ -12,16 +13,26 @@ using TravelCompanyDataModels.Models; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int TravelId { get; set; } + [DataMember] public int Count { get; set; } + [DataMember] public double Sum { get; set; } + [DataMember] public OrderStatus Status { get; set; } + [DataMember] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } public static Order? Create(OrderBindingModel model) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs b/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs index 4e1f059..0aaf01f 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs @@ -1,21 +1,27 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -using TravelCompanyDataModels.Models; -using TravelCompanyContracts.ViewModels; -using TravelCompanyContracts.BindingModels; using System.Xml.Linq; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Travel : ITravelModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string TravelName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } + [DataMember] public Dictionary Conditions { get; private set; } = new(); private Dictionary? _travelConditions = null; public Dictionary TravelConditions diff --git a/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj b/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj index 44dc3c0..52ae684 100644 --- a/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj +++ b/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj @@ -13,4 +13,8 @@ + + + + diff --git a/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f321224 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.StoragesContracts; + +namespace TravelCompanyListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/ListImplementationExtension.cs b/TravelCompany/TravelCompanyListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..b215239 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.DI; +using TravelCompanyListImplement.Implements; +using TravelCompanyListImplement.Models; + +namespace TravelCompanyListImplement +{ + 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/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs index 91c86a9..1d0046d 100644 --- a/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs +++ b/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs @@ -44,5 +44,7 @@ namespace TravelCompanyListImplement.Models Subject = Subject, DateDelivery = DateDelivery }; + + public int Id { get; set; } } } diff --git a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj index 9ba85b1..b4c9a9d 100644 --- a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj +++ b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj @@ -11,4 +11,8 @@ + + + +