From c554b0dbecaa2e6ad31922e0384e18e195187cc8 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Fri, 28 Apr 2023 16:13:32 +0400 Subject: [PATCH 01/15] =?UTF-8?q?8=20=D0=9B=D0=B0=D0=B1=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D0=B2=D0=B8=D0=B4=D0=B5=D0=BE=20(=D0=B2=D1=80=D0=BE?= =?UTF-8?q?=D0=B4=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + Shipyard/Shipyard/DataGridViewExtension.cs | 51 +++++++++ Shipyard/Shipyard/FormClients.cs | 8 +- Shipyard/Shipyard/FormDetails.cs | 21 ++-- Shipyard/Shipyard/FormImplementers.cs | 21 ++-- Shipyard/Shipyard/FormMain.cs | 61 ++++------- Shipyard/Shipyard/FormShip.cs | 55 +++++----- Shipyard/Shipyard/FormShips.cs | 21 ++-- Shipyard/Shipyard/Program.cs | 82 +++++++------- Shipyard/ShipyardBusinessLogic/BackUpLogic.cs | 103 ++++++++++++++++++ .../Attributes/ColumnAttribute.cs | 31 ++++++ .../Attributes/GridViewAutoSize.cs | 27 +++++ .../BindingModels/BackUpSaveBinidngModel.cs | 13 +++ .../BindingModels/MessageInfoBindingModel.cs | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 14 +++ .../ShipyardContracts/DI/DependencyManager.cs | 66 +++++++++++ .../DI/IDependencyContainer.cs | 40 +++++++ .../DI/IImplementationExtension.cs | 17 +++ .../DI/ServiceDependencyContainer.cs | 62 +++++++++++ .../DI/ServiceProviderLoader.cs | 55 ++++++++++ .../StoragesContracts/IBackUpInfo.cs | 15 +++ .../ViewModels/ClientViewModel.cs | 10 +- .../ViewModels/MessageInfoViewModel.cs | 2 + .../Implements/BackUpInfo.cs | 32 ++++++ .../Models/Message.cs | 1 + .../Models/IMessageInfoModel.cs | 2 +- .../ShipyardFileImplement/Models/Message.cs | 1 + .../Implements/BackUpInfo.cs | 22 ++++ .../ListImplementationExtension.cs | 28 +++++ .../ShipyardListImplement»/Models/Message.cs | 1 + .../ShipyardListImplement.csproj | 4 + 31 files changed, 701 insertions(+), 168 deletions(-) create mode 100644 Shipyard/Shipyard/DataGridViewExtension.cs create mode 100644 Shipyard/ShipyardBusinessLogic/BackUpLogic.cs create mode 100644 Shipyard/ShipyardContracts/Attributes/ColumnAttribute.cs create mode 100644 Shipyard/ShipyardContracts/Attributes/GridViewAutoSize.cs create mode 100644 Shipyard/ShipyardContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 Shipyard/ShipyardContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 Shipyard/ShipyardContracts/DI/DependencyManager.cs create mode 100644 Shipyard/ShipyardContracts/DI/IDependencyContainer.cs create mode 100644 Shipyard/ShipyardContracts/DI/IImplementationExtension.cs create mode 100644 Shipyard/ShipyardContracts/DI/ServiceDependencyContainer.cs create mode 100644 Shipyard/ShipyardContracts/DI/ServiceProviderLoader.cs create mode 100644 Shipyard/ShipyardContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 Shipyard/ShipyardDataBaseImplement/Implements/BackUpInfo.cs create mode 100644 Shipyard/ShipyardListImplement»/Implements/BackUpInfo.cs create mode 100644 Shipyard/ShipyardListImplement»/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..a743e0a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +ImplementationExtensions + # Mono auto generated files mono_crash.* diff --git a/Shipyard/Shipyard/DataGridViewExtension.cs b/Shipyard/Shipyard/DataGridViewExtension.cs new file mode 100644 index 0000000..00fdab4 --- /dev/null +++ b/Shipyard/Shipyard/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using ShipyardContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardView +{ + 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/Shipyard/Shipyard/FormClients.cs b/Shipyard/Shipyard/FormClients.cs index 46f8a93..99e19d9 100644 --- a/Shipyard/Shipyard/FormClients.cs +++ b/Shipyard/Shipyard/FormClients.cs @@ -35,13 +35,7 @@ namespace ShipyardView { 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/Shipyard/Shipyard/FormDetails.cs b/Shipyard/Shipyard/FormDetails.cs index 63faa96..b73a912 100644 --- a/Shipyard/Shipyard/FormDetails.cs +++ b/Shipyard/Shipyard/FormDetails.cs @@ -2,6 +2,7 @@ using Microsoft.VisualBasic.Logging; using ShipyardContracts.BindingModels; using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -51,13 +52,10 @@ namespace ShipyardView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormDetail)); - if (service is FormDetail form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -65,14 +63,11 @@ namespace ShipyardView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormDetail)); - if (service is FormDetail 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/Shipyard/Shipyard/FormImplementers.cs b/Shipyard/Shipyard/FormImplementers.cs index 83903a1..d5b33fc 100644 --- a/Shipyard/Shipyard/FormImplementers.cs +++ b/Shipyard/Shipyard/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using ShipyardContracts.BindingModels; using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -53,13 +54,10 @@ namespace ShipyardView 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(); } } @@ -67,14 +65,11 @@ namespace ShipyardView { 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/Shipyard/Shipyard/FormMain.cs b/Shipyard/Shipyard/FormMain.cs index 40e39df..9e54e17 100644 --- a/Shipyard/Shipyard/FormMain.cs +++ b/Shipyard/Shipyard/FormMain.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using ShipyardContracts.BindingModels; using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.DI; using ShipyardDataModels.Enums; using System; using System.Collections.Generic; @@ -57,30 +58,21 @@ namespace ShipyardView private void ДеталиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormDetails)); - if (service is FormDetails form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void КораблиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShips)); - if (service is FormShips 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) @@ -172,44 +164,32 @@ namespace ShipyardView private void shipDetailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportShipDetails)); - if (service is FormReportShipDetails form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ordersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ИсполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) { _workProcess.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + DependencyManager.Instance.Resolve())!, _orderLogic); MessageBox.Show("Передано на работу","произведен запуск", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -217,11 +197,8 @@ namespace ShipyardView private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } } } diff --git a/Shipyard/Shipyard/FormShip.cs b/Shipyard/Shipyard/FormShip.cs index 0bf1f1f..52c5e68 100644 --- a/Shipyard/Shipyard/FormShip.cs +++ b/Shipyard/Shipyard/FormShip.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using ShipyardContracts.BindingModels; using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.DI; using ShipyardContracts.SearchModels; using ShipyardDataModels.Models; using System; @@ -81,26 +82,23 @@ namespace ShipyardView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShipDetail)); - if (service is FormShipDetail form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.DetailModel == null) { - if (form.DetailModel == null) - { - return; - } - _logger.LogInformation("Добавление нового детали:{ DetailName} - { Count}", form.DetailModel.DetailName, form.Count); - if (_shipDetails.ContainsKey(form.Id)) - { - _shipDetails[form.Id] = (form.DetailModel,form.Count); - } - else - { - _shipDetails.Add(form.Id, (form.DetailModel,form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового детали:{ DetailName} - { Count}", form.DetailModel.DetailName, form.Count); + if (_shipDetails.ContainsKey(form.Id)) + { + _shipDetails[form.Id] = (form.DetailModel,form.Count); + } + else + { + _shipDetails.Add(form.Id, (form.DetailModel,form.Count)); + } + LoadData(); } } @@ -108,22 +106,19 @@ namespace ShipyardView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormShipDetail)); - if (service is FormShipDetail form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _shipDetails[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _shipDetails[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.DetailModel == null) { - if (form.DetailModel == null) - { - return; - } - _logger.LogInformation("Изменение детали: { DetailName} - { Count}", form.DetailModel.DetailName, form.Count); - _shipDetails[form.Id] = (form.DetailModel,form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение детали: { DetailName} - { Count}", form.DetailModel.DetailName, form.Count); + _shipDetails[form.Id] = (form.DetailModel,form.Count); + LoadData(); } } } diff --git a/Shipyard/Shipyard/FormShips.cs b/Shipyard/Shipyard/FormShips.cs index 4b04caf..c2bc1a0 100644 --- a/Shipyard/Shipyard/FormShips.cs +++ b/Shipyard/Shipyard/FormShips.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using ShipyardContracts.BindingModels; using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -51,13 +52,10 @@ namespace ShipyardView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShip)); - if (service is FormShip form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -65,14 +63,11 @@ namespace ShipyardView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormShip)); - if (service is FormShip 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/Shipyard/Shipyard/Program.cs b/Shipyard/Shipyard/Program.cs index bc00fda..3f4e070 100644 --- a/Shipyard/Shipyard/Program.cs +++ b/Shipyard/Shipyard/Program.cs @@ -5,17 +5,15 @@ using ShipyardBusinessLogic.BusinessLogics; using ShipyardBusinessLogic.OfficePackage.Implements; using ShipyardBusinessLogic.OfficePackage; using ShipyardContracts.BusinessLogicsContracts; -using ShipyardContracts.StoragesContracts; -using ShipyardDataBaseImplement.Implements; using ShipyardBusinessLogic.MailWorker; using ShipyardContracts.BindingModels; +using ShipyardBusinessLogic; +using ShipyardContracts.DI; namespace ShipyardView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -26,12 +24,10 @@ namespace ShipyardView // 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, @@ -46,56 +42,52 @@ namespace ShipyardView } 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(); + 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(); - 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(); + 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(); } diff --git a/Shipyard/ShipyardBusinessLogic/BackUpLogic.cs b/Shipyard/ShipyardBusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..fec2360 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/BackUpLogic.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.StoragesContracts; +using ShipyardDataModels; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardBusinessLogic +{ + 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/Shipyard/ShipyardContracts/Attributes/ColumnAttribute.cs b/Shipyard/ShipyardContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..b799c0f --- /dev/null +++ b/Shipyard/ShipyardContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + + public bool Visible { get; private set; } + + public int Width { get; private set; } + + public GridViewAutoSize GridViewAutoSize { get; private set; } + + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/Shipyard/ShipyardContracts/Attributes/GridViewAutoSize.cs b/Shipyard/ShipyardContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..e27b49e --- /dev/null +++ b/Shipyard/ShipyardContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/Shipyard/ShipyardContracts/BindingModels/BackUpSaveBinidngModel.cs b/Shipyard/ShipyardContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..e8b0b8d --- /dev/null +++ b/Shipyard/ShipyardContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/Shipyard/ShipyardContracts/BindingModels/MessageInfoBindingModel.cs b/Shipyard/ShipyardContracts/BindingModels/MessageInfoBindingModel.cs index 8a0e5f1..ce103c7 100644 --- a/Shipyard/ShipyardContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Shipyard/ShipyardContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,6 @@ namespace ShipyardContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + public int Id => throw new NotImplementedException(); } } diff --git a/Shipyard/ShipyardContracts/BusinessLogicsContracts/IBackUpLogic.cs b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..26bd2a2 --- /dev/null +++ b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using ShipyardContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/Shipyard/ShipyardContracts/DI/DependencyManager.cs b/Shipyard/ShipyardContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..6e34b3f --- /dev/null +++ b/Shipyard/ShipyardContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + 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/Shipyard/ShipyardContracts/DI/IDependencyContainer.cs b/Shipyard/ShipyardContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..9b98d42 --- /dev/null +++ b/Shipyard/ShipyardContracts/DI/IDependencyContainer.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.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/Shipyard/ShipyardContracts/DI/IImplementationExtension.cs b/Shipyard/ShipyardContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..cedf2a4 --- /dev/null +++ b/Shipyard/ShipyardContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/Shipyard/ShipyardContracts/DI/ServiceDependencyContainer.cs b/Shipyard/ShipyardContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..f910fc8 --- /dev/null +++ b/Shipyard/ShipyardContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + 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/Shipyard/ShipyardContracts/DI/ServiceProviderLoader.cs b/Shipyard/ShipyardContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..3b57b4a --- /dev/null +++ b/Shipyard/ShipyardContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.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/Shipyard/ShipyardContracts/StoragesContracts/IBackUpInfo.cs b/Shipyard/ShipyardContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..2083567 --- /dev/null +++ b/Shipyard/ShipyardContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/Shipyard/ShipyardContracts/ViewModels/ClientViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ClientViewModel.cs index ba52890..2e45bd6 100644 --- a/Shipyard/ShipyardContracts/ViewModels/ClientViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using ShipyardDataModels.Models; +using ShipyardContracts.Attributes; +using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,16 @@ namespace ShipyardContracts.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("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs index 416f0d9..401abad 100644 --- a/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs @@ -25,5 +25,7 @@ namespace ShipyardContracts.ViewModels [DisplayName("Текст")] public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/Shipyard/ShipyardDataBaseImplement/Implements/BackUpInfo.cs b/Shipyard/ShipyardDataBaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..9a6b4e0 --- /dev/null +++ b/Shipyard/ShipyardDataBaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using ShipyardContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardDataBaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new ShipyardDataBase(); + 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/Shipyard/ShipyardDataBaseImplement/Models/Message.cs b/Shipyard/ShipyardDataBaseImplement/Models/Message.cs index 28ee70f..7ca9063 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Message.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Message.cs @@ -24,6 +24,7 @@ namespace ShipyardDataBaseImplement.Models public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); public static Message? Create(MessageInfoBindingModel model) { diff --git a/Shipyard/ShipyardDataModels/Models/IMessageInfoModel.cs b/Shipyard/ShipyardDataModels/Models/IMessageInfoModel.cs index 02063dd..2e61010 100644 --- a/Shipyard/ShipyardDataModels/Models/IMessageInfoModel.cs +++ b/Shipyard/ShipyardDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ShipyardDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/Shipyard/ShipyardFileImplement/Models/Message.cs b/Shipyard/ShipyardFileImplement/Models/Message.cs index 6804164..2f56845 100644 --- a/Shipyard/ShipyardFileImplement/Models/Message.cs +++ b/Shipyard/ShipyardFileImplement/Models/Message.cs @@ -23,6 +23,7 @@ namespace ShipyardFileImplement.Models public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); public static Message? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/Shipyard/ShipyardListImplement»/Implements/BackUpInfo.cs b/Shipyard/ShipyardListImplement»/Implements/BackUpInfo.cs new file mode 100644 index 0000000..1886374 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using ShipyardContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement_.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/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs b/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs new file mode 100644 index 0000000..2a2697f --- /dev/null +++ b/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs @@ -0,0 +1,28 @@ +using ShipyardContracts.DI; +using ShipyardContracts.StoragesContracts; +using ShipyardListImplement.Implements; +using ShipyardListImplement_.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement_ +{ + 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/Shipyard/ShipyardListImplement»/Models/Message.cs b/Shipyard/ShipyardListImplement»/Models/Message.cs index 99d8e1c..5908058 100644 --- a/Shipyard/ShipyardListImplement»/Models/Message.cs +++ b/Shipyard/ShipyardListImplement»/Models/Message.cs @@ -22,6 +22,7 @@ namespace ShipyardListImplement_.Models public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); public static Message? Create(MessageInfoBindingModel model) { diff --git a/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj b/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj index 22ef310..2a2ea2e 100644 --- a/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj +++ b/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj @@ -24,4 +24,8 @@ + + + + -- 2.25.1 From eef3ca999359f0c50e2ad6434ffa8ed475d3ca5f Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 10:22:48 +0400 Subject: [PATCH 02/15] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=205=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shipyard/Shipyard/FormDetails.cs | 8 +---- Shipyard/Shipyard/FormImplementers.cs | 11 +----- Shipyard/Shipyard/FormMails.cs | 9 +---- Shipyard/Shipyard/FormMain.cs | 9 +---- Shipyard/Shipyard/FormShips.cs | 9 +---- .../ViewModels/DetailViewModel.cs | 8 +++-- .../ViewModels/ImplementerViewModel.cs | 12 ++++--- .../ViewModels/MessageInfoViewModel.cs | 14 +++++--- .../ViewModels/OrderViewModel.cs | 35 +++++++++++++------ .../ViewModels/ShipViewModel.cs | 12 +++++-- 10 files changed, 60 insertions(+), 67 deletions(-) diff --git a/Shipyard/Shipyard/FormDetails.cs b/Shipyard/Shipyard/FormDetails.cs index b73a912..0bd81ab 100644 --- a/Shipyard/Shipyard/FormDetails.cs +++ b/Shipyard/Shipyard/FormDetails.cs @@ -34,13 +34,7 @@ namespace ShipyardView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["DetailName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка деталей"); } catch (Exception ex) diff --git a/Shipyard/Shipyard/FormImplementers.cs b/Shipyard/Shipyard/FormImplementers.cs index d5b33fc..074621a 100644 --- a/Shipyard/Shipyard/FormImplementers.cs +++ b/Shipyard/Shipyard/FormImplementers.cs @@ -33,16 +33,7 @@ namespace ShipyardView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) diff --git a/Shipyard/Shipyard/FormMails.cs b/Shipyard/Shipyard/FormMails.cs index 2010045..2d08854 100644 --- a/Shipyard/Shipyard/FormMails.cs +++ b/Shipyard/Shipyard/FormMails.cs @@ -28,14 +28,7 @@ namespace ShipyardView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/Shipyard/Shipyard/FormMain.cs b/Shipyard/Shipyard/FormMain.cs index 9e54e17..5e7191a 100644 --- a/Shipyard/Shipyard/FormMain.cs +++ b/Shipyard/Shipyard/FormMain.cs @@ -39,14 +39,7 @@ namespace ShipyardView _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ShipId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) diff --git a/Shipyard/Shipyard/FormShips.cs b/Shipyard/Shipyard/FormShips.cs index c2bc1a0..d774bb1 100644 --- a/Shipyard/Shipyard/FormShips.cs +++ b/Shipyard/Shipyard/FormShips.cs @@ -33,14 +33,7 @@ namespace ShipyardView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShipName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ShipDetails"].Visible = false; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка кораблей"); } catch (Exception ex) diff --git a/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs index 3017778..ab2010c 100644 --- a/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs @@ -1,4 +1,5 @@ -using ShipyardDataModels.Models; +using ShipyardContracts.Attributes; +using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -11,10 +12,11 @@ namespace ShipyardContracts.ViewModels { public class DetailViewModel:IDetailModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название детали")] + [Column(title: "Название детали", width: 150)] public string DetailName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } diff --git a/Shipyard/ShipyardContracts/ViewModels/ImplementerViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ImplementerViewModel.cs index dac2447..5d28187 100644 --- a/Shipyard/ShipyardContracts/ViewModels/ImplementerViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using ShipyardDataModels.Models; +using ShipyardContracts.Attributes; +using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace ShipyardContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs index 401abad..52fb5d5 100644 --- a/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using ShipyardDataModels.Models; +using ShipyardContracts.Attributes; +using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,22 +11,25 @@ namespace ShipyardContracts.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: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата письма", width: 150)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] public int Id => throw new NotImplementedException(); } } diff --git a/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs index 5cc48f0..7385717 100644 --- a/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using ShipyardDataModels.Enums; +using ShipyardContracts.Attributes; +using ShipyardDataModels.Enums; using ShipyardDataModels.Models; using System; using System.Collections.Generic; @@ -11,26 +12,40 @@ namespace ShipyardContracts.ViewModels { public class OrderViewModel:IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 150)] public int Id { get; set; } + + [Column(visible: false)] public int ShipId { get; set; } - [DisplayName("Корабль")] + + [Column(title: "Корабль", width: 150)] public string ShipName { get; set; } = string.Empty; + + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("Клиент")] + + [Column(title: "Клиент", width: 150)] public string ClientFIO { get; set; } = string.Empty; + + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + + [Column(title: "Исполнитель", width: 150)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + + [Column(title: "Количество", width: 150)] public int Count { get; set; } - [DisplayName("Сумма")] + + [Column(title: "Сумма", width: 150)] public double Sum { get; set; } - [DisplayName("Статус")] + + [Column(title: "Статус", width: 150)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + + [Column(title: "Дата создания", width: 150)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + + [Column(title: "Дата выполнения", width: 150)] public DateTime? DateImplement { get; set; } } } diff --git a/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs index 07b135f..b95d28b 100644 --- a/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs @@ -1,4 +1,5 @@ -using ShipyardDataModels.Models; +using ShipyardContracts.Attributes; +using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,16 @@ namespace ShipyardContracts.ViewModels { public class ShipViewModel:IShipModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название корабля")] + + [Column(title: "Название корабля", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ShipName { get; set; } = string.Empty; - [DisplayName("Цена")] + + [Column(title: "Цена", width: 150)] public double Price { get; set; } + + [Column(visible: false)] public Dictionary ShipDetails { get; set; } = new(); } } -- 2.25.1 From 241cbfe16d1092635185c3c4ec407eb4cb90e20e Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 10:44:25 +0400 Subject: [PATCH 03/15] =?UTF-8?q?6=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82=3F=3F?= =?UTF-8?q?=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Client.cs | 11 +++++----- .../Models/Detail.cs | 5 +++++ .../Models/Implementer.cs | 7 ++++++ .../Models/Message.cs | 3 +++ .../ShipyardDataBaseImplement/Models/Order.cs | 16 ++++++++++++++ .../ShipyardDataBaseImplement/Models/Ship.cs | 10 +++++++++ .../Implements/BackUpInfo.cs | 22 +++++++++++++++++++ .../ShipyardFileImplement/Models/Client.cs | 9 ++++++++ .../ShipyardFileImplement/Models/Detail.cs | 7 ++++++ .../Models/Implementer.cs | 7 ++++++ .../ShipyardFileImplement/Models/Message.cs | 8 +++++++ .../ShipyardFileImplement/Models/Order.cs | 19 ++++++++++++++++ Shipyard/ShipyardFileImplement/Models/Ship.cs | 9 ++++++++ .../ShipyardListImplement»/Models/Client.cs | 9 ++++++++ .../ShipyardListImplement»/Models/Detail.cs | 7 ++++++ .../Models/Implementer.cs | 7 ++++++ .../ShipyardListImplement»/Models/Message.cs | 8 +++++++ .../ShipyardListImplement»/Models/Order.cs | 19 ++++++++++++++++ .../ShipyardListImplement»/Models/Ship.cs | 7 ++++++ 19 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Client.cs b/Shipyard/ShipyardDataBaseImplement/Models/Client.cs index 9d59234..08d8c93 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Client.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Client.cs @@ -1,24 +1,25 @@ using ShipyardContracts.BindingModels; using ShipyardContracts.ViewModels; using ShipyardDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ShipyardDataBaseImplement.Models { + [DataContract] public class Client:IClientModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ClientFIO { get; set; }= string.Empty; [Required] + [DataMember] public string Email { get; set; }= string.Empty; [Required] + [DataMember] public string Password { get; set; }= string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Detail.cs b/Shipyard/ShipyardDataBaseImplement/Models/Detail.cs index d662338..52a9a38 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Detail.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Detail.cs @@ -9,15 +9,20 @@ using System.Text; using System.Threading.Tasks; using ShipyardContracts.BindingModels; using ShipyardContracts.ViewModels; +using System.Runtime.Serialization; namespace ShipyardDataBaseImplement.Models { + [DataContract] public class Detail:IDetailModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string DetailName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("DetailId")] public virtual List ShipDetails { get; set; } = new(); diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Implementer.cs b/Shipyard/ShipyardDataBaseImplement/Models/Implementer.cs index 75e0517..3383dcb 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Implementer.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Implementer.cs @@ -6,25 +6,32 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardDataBaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ImplementerFIO { get; set; } = String.Empty; [Required] + [DataMember] public string Password { get; set; } = String.Empty; [Required] + [DataMember] public int WorkExperience { get; set; } [Required] + [DataMember] public int Qualification { get; set; } [ForeignKey("ImplementerId")] diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Message.cs b/Shipyard/ShipyardDataBaseImplement/Models/Message.cs index 7ca9063..35258d4 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Message.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Message.cs @@ -5,14 +5,17 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardDataBaseImplement.Models { + [DataContract] public class Message:IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Order.cs b/Shipyard/ShipyardDataBaseImplement/Models/Order.cs index 5d535eb..d4a8750 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Order.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Order.cs @@ -6,27 +6,43 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardDataBaseImplement.Models { + [DataContract] public class Order:IOrderModel { [Required] + [DataMember] public int ShipId { get; set; } + [Required] + [DataMember] public int ClientId { get; set; } + + [DataMember] public int? ImplementerId { get; set; } + [Required] + [DataMember] public int Count { get; set; } + [Required] + [DataMember] public double Sum { get; set; } + [Required] + [DataMember] public OrderStatus Status { get; set; } + [Required] + [DataMember] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } public int Id { get; set; } diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Ship.cs b/Shipyard/ShipyardDataBaseImplement/Models/Ship.cs index aaa5cdc..790190a 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Ship.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Ship.cs @@ -8,18 +8,28 @@ using System.Text; using System.Threading.Tasks; using ShipyardContracts.BindingModels; using ShipyardContracts.ViewModels; +using System.Runtime.Serialization; namespace ShipyardDataBaseImplement.Models { + [DataContract] public class Ship:IShipModel { + [DataMember] public int Id { get; set; } + [Required] + [DataMember] public string ShipName { get; set; } = string.Empty; + [Required] + [DataMember] public double Price { get; set; } + private Dictionary? _shipDetails = null; + [NotMapped] + [DataMember] public Dictionary ShipDetails { get diff --git a/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs b/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..30fc4b7 --- /dev/null +++ b/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using ShipyardContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardFileImplement.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/Shipyard/ShipyardFileImplement/Models/Client.cs b/Shipyard/ShipyardFileImplement/Models/Client.cs index b07f11d..bfb3cae 100644 --- a/Shipyard/ShipyardFileImplement/Models/Client.cs +++ b/Shipyard/ShipyardFileImplement/Models/Client.cs @@ -4,17 +4,26 @@ using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ShipyardFileImplement.Models { + [DataContract] public class Client:IClientModel { + [DataMember] public int Id { get; set; } + + [DataMember] public string ClientFIO { get; set; }= string.Empty; + + [DataMember] public string Email { get; set; }= string.Empty; + + [DataMember] public string Password { get; set; }= string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/Shipyard/ShipyardFileImplement/Models/Detail.cs b/Shipyard/ShipyardFileImplement/Models/Detail.cs index 9ee4aaf..696894b 100644 --- a/Shipyard/ShipyardFileImplement/Models/Detail.cs +++ b/Shipyard/ShipyardFileImplement/Models/Detail.cs @@ -5,16 +5,23 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ShipyardFileImplement.Models { + [DataContract] public class Detail:IDetailModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string DetailName { get; private set; } = string.Empty; + + [DataMember] public double Cost { get; set; } public static Detail? Create(DetailBindingModel model) { diff --git a/Shipyard/ShipyardFileImplement/Models/Implementer.cs b/Shipyard/ShipyardFileImplement/Models/Implementer.cs index a21a45a..a85b7b9 100644 --- a/Shipyard/ShipyardFileImplement/Models/Implementer.cs +++ b/Shipyard/ShipyardFileImplement/Models/Implementer.cs @@ -4,22 +4,29 @@ using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ShipyardFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public string ImplementerFIO { get; set; } = String.Empty; + [DataMember] public string Password { get; set; } = String.Empty; + [DataMember] public int WorkExperience { get; set; } + [DataMember] public int Qualification { get; set; } + [DataMember] public int Id { get; set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/Shipyard/ShipyardFileImplement/Models/Message.cs b/Shipyard/ShipyardFileImplement/Models/Message.cs index 2f56845..b155015 100644 --- a/Shipyard/ShipyardFileImplement/Models/Message.cs +++ b/Shipyard/ShipyardFileImplement/Models/Message.cs @@ -4,24 +4,32 @@ using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ShipyardFileImplement.Models { + [DataContract] public class Message : 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 int Id => throw new NotImplementedException(); public static Message? Create(MessageInfoBindingModel model) diff --git a/Shipyard/ShipyardFileImplement/Models/Order.cs b/Shipyard/ShipyardFileImplement/Models/Order.cs index a780a0e..388c335 100644 --- a/Shipyard/ShipyardFileImplement/Models/Order.cs +++ b/Shipyard/ShipyardFileImplement/Models/Order.cs @@ -2,20 +2,39 @@ using ShipyardContracts.ViewModels; using ShipyardDataModels.Enums; using ShipyardDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace ShipyardFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public int ShipId { get; private set; } + + [DataMember] public int ClientId { get; private set; } + + [DataMember] public int? ImplementerId { get; private set; } + + [DataMember] public int Count { get; private set; } + + [DataMember] public double Sum { get; private set; } + + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/Shipyard/ShipyardFileImplement/Models/Ship.cs b/Shipyard/ShipyardFileImplement/Models/Ship.cs index 091e4b3..38e635b 100644 --- a/Shipyard/ShipyardFileImplement/Models/Ship.cs +++ b/Shipyard/ShipyardFileImplement/Models/Ship.cs @@ -4,19 +4,28 @@ using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ShipyardFileImplement.Models { + [DataContract] public class Ship : IShipModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string ShipName { get; private set; } = string.Empty; + + [DataMember] public double Price { get; private set; } public Dictionary Details { get; private set; } = new(); private Dictionary? _shipDetails = null; + + [DataMember] public Dictionary ShipDetails { get diff --git a/Shipyard/ShipyardListImplement»/Models/Client.cs b/Shipyard/ShipyardListImplement»/Models/Client.cs index 3ff0f37..230b376 100644 --- a/Shipyard/ShipyardListImplement»/Models/Client.cs +++ b/Shipyard/ShipyardListImplement»/Models/Client.cs @@ -6,16 +6,25 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardListImplement.Models { + [DataContract] public class Client :IClientModel { + [DataMember] public int Id { get; set; } + + [DataMember] public string ClientFIO { get; set; }= string.Empty; + + [DataMember] public string Email { get; set; }= string.Empty; + + [DataMember] public string Password { get; set; }= string.Empty; public static Client? Create(ClientBindingModel? model) { diff --git a/Shipyard/ShipyardListImplement»/Models/Detail.cs b/Shipyard/ShipyardListImplement»/Models/Detail.cs index 2e7bc87..123543c 100644 --- a/Shipyard/ShipyardListImplement»/Models/Detail.cs +++ b/Shipyard/ShipyardListImplement»/Models/Detail.cs @@ -5,15 +5,22 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardListImplement.Models { + [DataContract] public class Detail:IDetailModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string DetailName { get; private set; } = string.Empty; + + [DataMember] public double Cost { get; set; } public static Detail? Create(DetailBindingModel? model) { diff --git a/Shipyard/ShipyardListImplement»/Models/Implementer.cs b/Shipyard/ShipyardListImplement»/Models/Implementer.cs index 1f51406..d7e3e9f 100644 --- a/Shipyard/ShipyardListImplement»/Models/Implementer.cs +++ b/Shipyard/ShipyardListImplement»/Models/Implementer.cs @@ -5,22 +5,29 @@ using ShipyardListImplement.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ShipyardListImplement_.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public string ImplementerFIO { get; set; } = String.Empty; + [DataMember] public string Password { get; set; } = String.Empty; + [DataMember] public int WorkExperience { get; set; } + [DataMember] public int Qualification { get; set; } + [DataMember] public int Id { get; set; } public static Implementer? Create(ImplementerBindingModel? model) { diff --git a/Shipyard/ShipyardListImplement»/Models/Message.cs b/Shipyard/ShipyardListImplement»/Models/Message.cs index 5908058..17f17f4 100644 --- a/Shipyard/ShipyardListImplement»/Models/Message.cs +++ b/Shipyard/ShipyardListImplement»/Models/Message.cs @@ -4,23 +4,31 @@ using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardListImplement_.Models { + [DataContract] public class Message : 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 int Id => throw new NotImplementedException(); diff --git a/Shipyard/ShipyardListImplement»/Models/Order.cs b/Shipyard/ShipyardListImplement»/Models/Order.cs index 69bb7a5..885abb6 100644 --- a/Shipyard/ShipyardListImplement»/Models/Order.cs +++ b/Shipyard/ShipyardListImplement»/Models/Order.cs @@ -7,21 +7,40 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardListImplement.Models { + [DataContract] public class Order: IOrderModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public int ShipId { get; private set; } + + [DataMember] public int ClientId {get; private set; } + + [DataMember] public int? ImplementerId { get; private set; } + + [DataMember] public int Count { get; private set; } + + [DataMember] public double Sum { get; private set; } + + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + [DataMember] public DateTime DateCreate { get; private set; }= DateTime.Now; + + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) diff --git a/Shipyard/ShipyardListImplement»/Models/Ship.cs b/Shipyard/ShipyardListImplement»/Models/Ship.cs index 4c526b3..bdfcd8a 100644 --- a/Shipyard/ShipyardListImplement»/Models/Ship.cs +++ b/Shipyard/ShipyardListImplement»/Models/Ship.cs @@ -4,15 +4,22 @@ using ShipyardDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ShipyardListImplement.Models { + [DataContract] public class Ship:IShipModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string ShipName { get; private set; } = string.Empty; + + [DataMember] public double Price { get; private set; } public Dictionary ShipDetails { get; private set; } = new Dictionary(); public static Ship? Create(ShipBindingModel? model) -- 2.25.1 From 59c4185ca72bd04e4d86fbc157041194e40ca51a Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 10:48:45 +0400 Subject: [PATCH 04/15] =?UTF-8?q?7=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82=20(?= =?UTF-8?q?=D0=B8=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=B5-?= =?UTF-8?q?=D1=87=D1=82=D0=BE=20(=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BB=D1=81=D1=8F))?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BackUpInfo.cs | 16 ++++++++++++++-- .../ShipyardListImplement»/Models/Client.cs | 5 ----- .../ShipyardListImplement»/Models/Detail.cs | 4 ---- .../Models/Implementer.cs | 6 ------ .../ShipyardListImplement»/Models/Message.cs | 7 ------- Shipyard/ShipyardListImplement»/Models/Order.cs | 10 ---------- Shipyard/ShipyardListImplement»/Models/Ship.cs | 4 ---- 7 files changed, 14 insertions(+), 38 deletions(-) diff --git a/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs b/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs index 30fc4b7..297c95c 100644 --- a/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs +++ b/Shipyard/ShipyardFileImplement/Implements/BackUpInfo.cs @@ -11,12 +11,24 @@ namespace ShipyardFileImplement.Implements { public List? GetList() where T : class, new() { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + 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/Shipyard/ShipyardListImplement»/Models/Client.cs b/Shipyard/ShipyardListImplement»/Models/Client.cs index 230b376..8f231d5 100644 --- a/Shipyard/ShipyardListImplement»/Models/Client.cs +++ b/Shipyard/ShipyardListImplement»/Models/Client.cs @@ -12,19 +12,14 @@ using System.Threading.Tasks; namespace ShipyardListImplement.Models { - [DataContract] public class Client :IClientModel { - [DataMember] public int Id { get; set; } - [DataMember] public string ClientFIO { get; set; }= string.Empty; - [DataMember] public string Email { get; set; }= string.Empty; - [DataMember] public string Password { get; set; }= string.Empty; public static Client? Create(ClientBindingModel? model) { diff --git a/Shipyard/ShipyardListImplement»/Models/Detail.cs b/Shipyard/ShipyardListImplement»/Models/Detail.cs index 123543c..63a85cb 100644 --- a/Shipyard/ShipyardListImplement»/Models/Detail.cs +++ b/Shipyard/ShipyardListImplement»/Models/Detail.cs @@ -11,16 +11,12 @@ using System.Threading.Tasks; namespace ShipyardListImplement.Models { - [DataContract] public class Detail:IDetailModel { - [DataMember] public int Id { get; private set; } - [DataMember] public string DetailName { get; private set; } = string.Empty; - [DataMember] public double Cost { get; set; } public static Detail? Create(DetailBindingModel? model) { diff --git a/Shipyard/ShipyardListImplement»/Models/Implementer.cs b/Shipyard/ShipyardListImplement»/Models/Implementer.cs index d7e3e9f..4496d33 100644 --- a/Shipyard/ShipyardListImplement»/Models/Implementer.cs +++ b/Shipyard/ShipyardListImplement»/Models/Implementer.cs @@ -12,22 +12,16 @@ using System.Xml.Linq; namespace ShipyardListImplement_.Models { - [DataContract] public class Implementer : IImplementerModel { - [DataMember] public string ImplementerFIO { get; set; } = String.Empty; - [DataMember] public string Password { get; set; } = String.Empty; - [DataMember] public int WorkExperience { get; set; } - [DataMember] public int Qualification { get; set; } - [DataMember] public int Id { get; set; } public static Implementer? Create(ImplementerBindingModel? model) { diff --git a/Shipyard/ShipyardListImplement»/Models/Message.cs b/Shipyard/ShipyardListImplement»/Models/Message.cs index 17f17f4..1b0f6e8 100644 --- a/Shipyard/ShipyardListImplement»/Models/Message.cs +++ b/Shipyard/ShipyardListImplement»/Models/Message.cs @@ -10,25 +10,18 @@ using System.Threading.Tasks; namespace ShipyardListImplement_.Models { - [DataContract] public class Message : 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 int Id => throw new NotImplementedException(); diff --git a/Shipyard/ShipyardListImplement»/Models/Order.cs b/Shipyard/ShipyardListImplement»/Models/Order.cs index 885abb6..a6d1e42 100644 --- a/Shipyard/ShipyardListImplement»/Models/Order.cs +++ b/Shipyard/ShipyardListImplement»/Models/Order.cs @@ -13,34 +13,24 @@ using System.Threading.Tasks; namespace ShipyardListImplement.Models { - [DataContract] public class Order: IOrderModel { - [DataMember] public int Id { get; private set; } - [DataMember] public int ShipId { get; private set; } - [DataMember] public int ClientId {get; private set; } - [DataMember] public int? ImplementerId { get; private set; } - [DataMember] public int Count { get; private set; } - [DataMember] public double Sum { get; private set; } - [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [DataMember] public DateTime DateCreate { get; private set; }= DateTime.Now; - [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) diff --git a/Shipyard/ShipyardListImplement»/Models/Ship.cs b/Shipyard/ShipyardListImplement»/Models/Ship.cs index bdfcd8a..4962741 100644 --- a/Shipyard/ShipyardListImplement»/Models/Ship.cs +++ b/Shipyard/ShipyardListImplement»/Models/Ship.cs @@ -10,16 +10,12 @@ using System.Threading.Tasks; namespace ShipyardListImplement.Models { - [DataContract] public class Ship:IShipModel { - [DataMember] public int Id { get; private set; } - [DataMember] public string ShipName { get; private set; } = string.Empty; - [DataMember] public double Price { get; private set; } public Dictionary ShipDetails { get; private set; } = new Dictionary(); public static Ship? Create(ShipBindingModel? model) -- 2.25.1 From cca089ea7a5e83327922080eb390998a7745df01 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 10:54:29 +0400 Subject: [PATCH 05/15] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20Ex?= =?UTF-8?q?tensions.=20=D0=9A=D0=B0=D0=BA=D0=B0=D1=8F-=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBaseImplementationExtension.cs | 27 +++++++++++++++++++ .../FileImplementationExtension.cs | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs create mode 100644 Shipyard/ShipyardFileImplement/FileImplementationExtension.cs diff --git a/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs b/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs new file mode 100644 index 0000000..deb264a --- /dev/null +++ b/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using ShipyardContracts.DI; +using ShipyardContracts.StoragesContracts; +using ShipyardDataBaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardDataBaseImplement +{ + public class DataBaseImplementationExtension : 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/Shipyard/ShipyardFileImplement/FileImplementationExtension.cs b/Shipyard/ShipyardFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..13e7db2 --- /dev/null +++ b/Shipyard/ShipyardFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using ShipyardContracts.DI; +using ShipyardContracts.StoragesContracts; +using ShipyardFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardFileImplement +{ + 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(); + } + } +} -- 2.25.1 From 168f180b3f813b163345db12b240bc77aef952c3 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 11:35:40 +0400 Subject: [PATCH 06/15] =?UTF-8?q?=D0=9D=D1=83=20=D1=8D=D1=82=D0=BE=20?= =?UTF-8?q?=D0=B2=D0=BE-=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D1=85=20(=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20=D0=B2=D1=81=D0=B5=20=D0=B5?= =?UTF-8?q?=D1=89=D0=B5=20=D0=B5=D1=81=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBaseImplementationExtension.cs | 2 +- .../ShipyardDataBaseImplement.csproj | 6 +++++- Shipyard/ShipyardFileImplement/ShipyardFileImplement.csproj | 4 ++++ .../ShipyardListImplement»/ListImplementationExtension.cs | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs b/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs index deb264a..119f0ff 100644 --- a/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs +++ b/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs @@ -11,7 +11,7 @@ namespace ShipyardDataBaseImplement { public class DataBaseImplementationExtension : IImplementationExtension { - public int Priority => 2; + public int Priority => 0; public void RegisterServices() { diff --git a/Shipyard/ShipyardDataBaseImplement/ShipyardDataBaseImplement.csproj b/Shipyard/ShipyardDataBaseImplement/ShipyardDataBaseImplement.csproj index 39bebaf..64cd830 100644 --- a/Shipyard/ShipyardDataBaseImplement/ShipyardDataBaseImplement.csproj +++ b/Shipyard/ShipyardDataBaseImplement/ShipyardDataBaseImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -19,4 +19,8 @@ + + + + diff --git a/Shipyard/ShipyardFileImplement/ShipyardFileImplement.csproj b/Shipyard/ShipyardFileImplement/ShipyardFileImplement.csproj index 79514f7..78a9e82 100644 --- a/Shipyard/ShipyardFileImplement/ShipyardFileImplement.csproj +++ b/Shipyard/ShipyardFileImplement/ShipyardFileImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs b/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs index 2a2697f..df0db7d 100644 --- a/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs +++ b/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs @@ -12,7 +12,7 @@ namespace ShipyardListImplement_ { public class ListImplementationExtension : IImplementationExtension { - public int Priority => 0; + public int Priority => 2; public void RegisterServices() { -- 2.25.1 From 6f4e8d2e21e5a664de4a68ad34adece5fb37ca2d Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 14:23:49 +0400 Subject: [PATCH 07/15] fix --- .../DataBaseImplementationExtension.cs | 2 +- Shipyard/ShipyardListImplement»/ListImplementationExtension.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs b/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs index 119f0ff..deb264a 100644 --- a/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs +++ b/Shipyard/ShipyardDataBaseImplement/DataBaseImplementationExtension.cs @@ -11,7 +11,7 @@ namespace ShipyardDataBaseImplement { public class DataBaseImplementationExtension : IImplementationExtension { - public int Priority => 0; + public int Priority => 2; public void RegisterServices() { diff --git a/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs b/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs index df0db7d..2a2697f 100644 --- a/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs +++ b/Shipyard/ShipyardListImplement»/ListImplementationExtension.cs @@ -12,7 +12,7 @@ namespace ShipyardListImplement_ { public class ListImplementationExtension : IImplementationExtension { - public int Priority => 2; + public int Priority => 0; public void RegisterServices() { -- 2.25.1 From 53422b3896dab75996ae17774fa7e0a9d15df81b Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 14:53:11 +0400 Subject: [PATCH 08/15] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D1=81=D1=8C=20unity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shipyard/Shipyard/FormMain.Designer.cs | 32 +++++++++++++++++--------- Shipyard/Shipyard/FormMain.cs | 31 ++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Shipyard/Shipyard/FormMain.Designer.cs b/Shipyard/Shipyard/FormMain.Designer.cs index 594c98a..8ac15d4 100644 --- a/Shipyard/Shipyard/FormMain.Designer.cs +++ b/Shipyard/Shipyard/FormMain.Designer.cs @@ -42,8 +42,9 @@ this.shipsDetailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускаРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -88,7 +89,8 @@ this.ToolStripMenuItem, this.отчетыToolStripMenuItem, this.запускаРаботToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.создатьБекапToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1160, 28); @@ -109,28 +111,28 @@ // ДеталиToolStripMenuItem // this.ДеталиToolStripMenuItem.Name = "ДеталиToolStripMenuItem"; - this.ДеталиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.ДеталиToolStripMenuItem.Size = new System.Drawing.Size(185, 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(224, 26); + this.КораблиToolStripMenuItem.Size = new System.Drawing.Size(185, 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(224, 26); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(185, 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(224, 26); + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.исполнителиToolStripMenuItem.Text = "Исполнители"; this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ИсполнителиToolStripMenuItem_Click); // @@ -172,6 +174,13 @@ this.запускаРаботToolStripMenuItem.Text = "Запуск работ"; this.запускаРаботToolStripMenuItem.Click += new System.EventHandler(this.ЗапускРаботToolStripMenuItem_Click); // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -183,12 +192,12 @@ this.dataGridView.Size = new System.Drawing.Size(933, 446); this.dataGridView.TabIndex = 6; // - // письмаToolStripMenuItem + // создатьБекапToolStripMenuItem // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); - this.письмаToolStripMenuItem.Text = "Письма"; - this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(123, 24); + this.создатьБекапToolStripMenuItem.Text = "Создать бекап"; + this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.создатьБекапToolStripMenuItem_Click); // // FormMain // @@ -230,5 +239,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускаРаботToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/Shipyard/Shipyard/FormMain.cs b/Shipyard/Shipyard/FormMain.cs index 5e7191a..c53b499 100644 --- a/Shipyard/Shipyard/FormMain.cs +++ b/Shipyard/Shipyard/FormMain.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using ShipyardBusinessLogic; using ShipyardContracts.BindingModels; using ShipyardContracts.BusinessLogicsContracts; using ShipyardContracts.DI; @@ -21,13 +22,15 @@ namespace ShipyardView 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(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportlogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -193,5 +196,31 @@ namespace ShipyardView var form = DependencyManager.Instance.Resolve(); 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); + } + + } } } -- 2.25.1 From e34c7102333adfe2f905e1c9bdb947a17d36e777 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 14:59:11 +0400 Subject: [PATCH 09/15] =?UTF-8?q?=D0=A2=D0=B8=D0=BF=D0=BE=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DI/UnityDependencyContainer.cs | 38 +++++++++++++++++++ .../ShipyardContracts.csproj | 2 + 2 files changed, 40 insertions(+) create mode 100644 Shipyard/ShipyardContracts/DI/UnityDependencyContainer.cs diff --git a/Shipyard/ShipyardContracts/DI/UnityDependencyContainer.cs b/Shipyard/ShipyardContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..b9213f7 --- /dev/null +++ b/Shipyard/ShipyardContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Logging; +using Unity.Microsoft.Logging; +using Unity; + +namespace ShipyardContracts.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); + } + } +} diff --git a/Shipyard/ShipyardContracts/ShipyardContracts.csproj b/Shipyard/ShipyardContracts/ShipyardContracts.csproj index 45e1102..3acdfe9 100644 --- a/Shipyard/ShipyardContracts/ShipyardContracts.csproj +++ b/Shipyard/ShipyardContracts/ShipyardContracts.csproj @@ -16,6 +16,8 @@ + + -- 2.25.1 From 40e2f9d19bc8493cdc6f8ca4cf209c12188dc154 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sat, 29 Apr 2023 15:08:12 +0400 Subject: [PATCH 10/15] its all --- Shipyard/ShipyardContracts/DI/DependencyManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shipyard/ShipyardContracts/DI/DependencyManager.cs b/Shipyard/ShipyardContracts/DI/DependencyManager.cs index 6e34b3f..daec9d0 100644 --- a/Shipyard/ShipyardContracts/DI/DependencyManager.cs +++ b/Shipyard/ShipyardContracts/DI/DependencyManager.cs @@ -17,7 +17,7 @@ namespace ShipyardContracts.DI private DependencyManager() { - _dependencyManager = new ServiceDependencyContainer(); + _dependencyManager = new UnityDependencyContainer(); } public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } -- 2.25.1 From 9dc1917d512c18faab2f9f870e27607734a62e9e Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sun, 30 Apr 2023 18:03:09 +0400 Subject: [PATCH 11/15] fix --- Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs index 121244b..38dffbd 100644 --- a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs @@ -108,11 +108,11 @@ namespace ShipyardBusinessLogic.BusinessLogics { throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Email)); } - if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$") { throw new ArgumentException("Неправильно введенный email", nameof(model.Email)); } - if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(model.Password, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$") || model.Password.Length < 10 || model.Password.Length > 50) { throw new ArgumentException("Неправильно введенный пароль", nameof(model.Password)); } -- 2.25.1 From 946a10f95b627ad5c4a100f37bafc486c2e914a0 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sun, 30 Apr 2023 18:13:12 +0400 Subject: [PATCH 12/15] FIX --- Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs index 38dffbd..87fe0fe 100644 --- a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ClientLogic.cs @@ -108,7 +108,7 @@ namespace ShipyardBusinessLogic.BusinessLogics { throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Email)); } - if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$") + if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$")) { throw new ArgumentException("Неправильно введенный email", nameof(model.Email)); } -- 2.25.1 From e3e69ff83cc12916539bf05cc336302a55eb75e0 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sun, 30 Apr 2023 19:14:54 +0400 Subject: [PATCH 13/15] fix --- .../20230430150925_ClientMessage.Designer.cs | 298 ++++++++++++++++++ .../20230430150925_ClientMessage.cs | 38 +++ .../ShipyardDataBaseModelSnapshot.cs | 13 + .../Models/Client.cs | 3 + .../Models/Message.cs | 2 +- 5 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs create mode 100644 Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs diff --git a/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs b/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs new file mode 100644 index 0000000..ecbb91f --- /dev/null +++ b/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs @@ -0,0 +1,298 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ShipyardDataBaseImplement; + +#nullable disable + +namespace ShipyardDataBaseImplement.Migrations +{ + [DbContext(typeof(ShipyardDataBase))] + [Migration("20230430150925_ClientMessage")] + partial class ClientMessage + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Detail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("DetailName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Details"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("ShipId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("ShipId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Ship", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ShipName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ships"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.ShipDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DetailId") + .HasColumnType("int"); + + b.Property("ShipId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DetailId"); + + b.HasIndex("ShipId"); + + b.ToTable("ShipDetails"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Message", b => + { + b.HasOne("ShipyardDataBaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Order", b => + { + b.HasOne("ShipyardDataBaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ShipyardDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("ShipyardDataBaseImplement.Models.Ship", "Ship") + .WithMany("Orders") + .HasForeignKey("ShipId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Ship"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.ShipDetail", b => + { + b.HasOne("ShipyardDataBaseImplement.Models.Detail", "Detail") + .WithMany("ShipDetails") + .HasForeignKey("DetailId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ShipyardDataBaseImplement.Models.Ship", "Ship") + .WithMany("Details") + .HasForeignKey("ShipId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Detail"); + + b.Navigation("Ship"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Detail", b => + { + b.Navigation("ShipDetails"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Ship", b => + { + b.Navigation("Details"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs b/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs new file mode 100644 index 0000000..8d23b90 --- /dev/null +++ b/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ShipyardDataBaseImplement.Migrations +{ + /// + public partial class ClientMessage : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Messages_Clients_ClientId", + table: "Messages", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Messages_Clients_ClientId", + table: "Messages"); + + migrationBuilder.DropIndex( + name: "IX_Messages_ClientId", + table: "Messages"); + } + } +} diff --git a/Shipyard/ShipyardDataBaseImplement/Migrations/ShipyardDataBaseModelSnapshot.cs b/Shipyard/ShipyardDataBaseImplement/Migrations/ShipyardDataBaseModelSnapshot.cs index 5da398e..2d43a67 100644 --- a/Shipyard/ShipyardDataBaseImplement/Migrations/ShipyardDataBaseModelSnapshot.cs +++ b/Shipyard/ShipyardDataBaseImplement/Migrations/ShipyardDataBaseModelSnapshot.cs @@ -119,6 +119,8 @@ namespace ShipyardDataBaseImplement.Migrations b.HasKey("MessageId"); + b.HasIndex("ClientId"); + b.ToTable("Messages"); }); @@ -211,6 +213,15 @@ namespace ShipyardDataBaseImplement.Migrations b.ToTable("ShipDetails"); }); + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Message", b => + { + b.HasOne("ShipyardDataBaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("ShipyardDataBaseImplement.Models.Order", b => { b.HasOne("ShipyardDataBaseImplement.Models.Client", "Client") @@ -257,6 +268,8 @@ namespace ShipyardDataBaseImplement.Migrations modelBuilder.Entity("ShipyardDataBaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Client.cs b/Shipyard/ShipyardDataBaseImplement/Models/Client.cs index 08d8c93..ce7130a 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Client.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Client.cs @@ -23,6 +23,9 @@ namespace ShipyardDataBaseImplement.Models public string Password { get; set; }= string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) { if (model == null) diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Message.cs b/Shipyard/ShipyardDataBaseImplement/Models/Message.cs index 35258d4..37a3d7d 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Message.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Message.cs @@ -28,7 +28,7 @@ namespace ShipyardDataBaseImplement.Models public string Body { get; private set; } = string.Empty; public int Id => throw new NotImplementedException(); - + public Client? Client { get; private set; } public static Message? Create(MessageInfoBindingModel model) { if (model == null) -- 2.25.1 From d795c77acf69e30eb5d1a880c0719c194b761f01 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sun, 30 Apr 2023 19:23:42 +0400 Subject: [PATCH 14/15] fix --- .../20230430150925_ClientMessage.Designer.cs | 298 ------------------ .../20230430150925_ClientMessage.cs | 38 --- 2 files changed, 336 deletions(-) delete mode 100644 Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs delete mode 100644 Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs diff --git a/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs b/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs deleted file mode 100644 index ecbb91f..0000000 --- a/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.Designer.cs +++ /dev/null @@ -1,298 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ShipyardDataBaseImplement; - -#nullable disable - -namespace ShipyardDataBaseImplement.Migrations -{ - [DbContext(typeof(ShipyardDataBase))] - [Migration("20230430150925_ClientMessage")] - partial class ClientMessage - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Detail", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("DetailName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Details"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Implementer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImplementerFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Qualification") - .HasColumnType("int"); - - b.Property("WorkExperience") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Implementers"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Message", b => - { - b.Property("MessageId") - .HasColumnType("nvarchar(450)"); - - b.Property("Body") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("DateDelivery") - .HasColumnType("datetime2"); - - b.Property("SenderName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Subject") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("MessageId"); - - b.HasIndex("ClientId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ImplementerId") - .HasColumnType("int"); - - b.Property("ShipId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("ImplementerId"); - - b.HasIndex("ShipId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Ship", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ShipName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Ships"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.ShipDetail", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DetailId") - .HasColumnType("int"); - - b.Property("ShipId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DetailId"); - - b.HasIndex("ShipId"); - - b.ToTable("ShipDetails"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Message", b => - { - b.HasOne("ShipyardDataBaseImplement.Models.Client", "Client") - .WithMany("Messages") - .HasForeignKey("ClientId"); - - b.Navigation("Client"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Order", b => - { - b.HasOne("ShipyardDataBaseImplement.Models.Client", "Client") - .WithMany("Orders") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ShipyardDataBaseImplement.Models.Implementer", "Implementer") - .WithMany("Orders") - .HasForeignKey("ImplementerId"); - - b.HasOne("ShipyardDataBaseImplement.Models.Ship", "Ship") - .WithMany("Orders") - .HasForeignKey("ShipId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Client"); - - b.Navigation("Implementer"); - - b.Navigation("Ship"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.ShipDetail", b => - { - b.HasOne("ShipyardDataBaseImplement.Models.Detail", "Detail") - .WithMany("ShipDetails") - .HasForeignKey("DetailId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ShipyardDataBaseImplement.Models.Ship", "Ship") - .WithMany("Details") - .HasForeignKey("ShipId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Detail"); - - b.Navigation("Ship"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Client", b => - { - b.Navigation("Messages"); - - b.Navigation("Orders"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Detail", b => - { - b.Navigation("ShipDetails"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Implementer", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("ShipyardDataBaseImplement.Models.Ship", b => - { - b.Navigation("Details"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs b/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs deleted file mode 100644 index 8d23b90..0000000 --- a/Shipyard/ShipyardDataBaseImplement/Migrations/20230430150925_ClientMessage.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ShipyardDataBaseImplement.Migrations -{ - /// - public partial class ClientMessage : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateIndex( - name: "IX_Messages_ClientId", - table: "Messages", - column: "ClientId"); - - migrationBuilder.AddForeignKey( - name: "FK_Messages_Clients_ClientId", - table: "Messages", - column: "ClientId", - principalTable: "Clients", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Messages_Clients_ClientId", - table: "Messages"); - - migrationBuilder.DropIndex( - name: "IX_Messages_ClientId", - table: "Messages"); - } - } -} -- 2.25.1 From 37e08197877880b93f351474620c6a3d10a2548a Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Wed, 3 May 2023 08:43:56 +0400 Subject: [PATCH 15/15] fix --- Shipyard/ShipyardDataBaseImplement/Models/Order.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Shipyard/ShipyardDataBaseImplement/Models/Order.cs b/Shipyard/ShipyardDataBaseImplement/Models/Order.cs index d4a8750..8ef9936 100644 --- a/Shipyard/ShipyardDataBaseImplement/Models/Order.cs +++ b/Shipyard/ShipyardDataBaseImplement/Models/Order.cs @@ -45,6 +45,7 @@ namespace ShipyardDataBaseImplement.Models [DataMember] public DateTime? DateImplement { get; set; } + [DataMember] public int Id { get; set; } public virtual Ship Ship { get; set; } public virtual Client Client { get; set; } -- 2.25.1