diff --git a/.gitignore b/.gitignore index ca1c7a3..52737dc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# dll файлы +*.dll + # Mono auto generated files mono_crash.* diff --git a/PrecastConcretePlant/.gitignore b/PrecastConcretePlant/.gitignore new file mode 100644 index 0000000..52737dc --- /dev/null +++ b/PrecastConcretePlant/.gitignore @@ -0,0 +1,403 @@ +# ---> VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# dll файлы +*.dll + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + diff --git a/PrecastConcretePlant/PrecastConcretePlant/DataGridViewExtension.cs b/PrecastConcretePlant/PrecastConcretePlant/DataGridViewExtension.cs new file mode 100644 index 0000000..0f857b4 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using PrecastConcretePlantContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantView +{ + 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/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs b/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs index 2c6313b..7cc008c 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs @@ -28,13 +28,7 @@ namespace PrecastConcretePlantView { 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/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs b/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs index 29062ff..1fc19ba 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -35,15 +36,7 @@ namespace PrecastConcretePlantView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } @@ -56,30 +49,21 @@ namespace PrecastConcretePlantView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index 4815b91..7066649 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -39,11 +39,12 @@ this.компонентыПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); - this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -55,7 +56,8 @@ this.СправочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.создатьБекапToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); @@ -140,6 +142,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; @@ -184,12 +193,12 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // письмаToolStripMenuItem + // создатьБекапToolStripMenuItem // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); - this.письмаToolStripMenuItem.Text = "Письма"; - this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(123, 24); + this.создатьБекапToolStripMenuItem.Text = "Создать бекап"; + this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.создатьБекапToolStripMenuItem_Click); // // FormMain // @@ -232,5 +241,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 2c3314c..65d2d72 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -2,6 +2,7 @@ using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.DI; using PrecastConcretePlantDataModels.Enums; using System; using System.Collections.Generic; @@ -22,13 +23,15 @@ namespace PrecastConcretePlantView 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; LoadData(); } @@ -39,58 +42,36 @@ namespace PrecastConcretePlantView private void LoadData() { - _logger.LogInformation("Загрузка заказов"); - try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["ReinforcedId"].Visible = false; - DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["ImplementerId"].Visible = false; - } - + DataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforceds)); - - if (service is FormReinforceds form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void CreateOrderButton_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 TakeOrderInWorkButton_Click(object sender, EventArgs e) @@ -203,55 +184,65 @@ namespace PrecastConcretePlantView private void компонентыПоДокументамToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportReinforcedComponents)); - if (service is FormReportReinforcedComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrder)); - if (service is FormReportOrder 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) { - _workProcess.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, - _orderLogic); + _workProcess.DoWork( + DependencyManager.Instance.Resolve(), + _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers)); - if (service is FormViewImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormViewMail)); - if (service is FormViewMail form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.cs index 79e3c61..7a36515 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.cs @@ -12,6 +12,7 @@ using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantDataModels.Models; using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.DI; namespace PrecastConcretePlantView { @@ -85,29 +86,27 @@ namespace PrecastConcretePlantView } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedComponent)); - - if (service is FormReinforcedComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { if (form.ComponentModel == null) { return; } - - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - + _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", + form.ComponentModel.ComponentName, form.Count); if (_reinforcedComponents.ContainsKey(form.Id)) { - _reinforcedComponents[form.Id] = (form.ComponentModel, form.Count); + _reinforcedComponents[form.Id] = (form.ComponentModel, + form.Count); } - else { - _reinforcedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + _reinforcedComponents.Add(form.Id, (form.ComponentModel, + form.Count)); } - LoadData(); } } @@ -117,25 +116,20 @@ namespace PrecastConcretePlantView { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedComponent)); - - if (service is FormReinforcedComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _reinforcedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _reinforcedComponents[id].Item2; - - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _reinforcedComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", + form.ComponentModel.ComponentName, form.Count); + _reinforcedComponents[id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs index e52aca8..d28f3ac 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.DI; namespace PrecastConcretePlantView { @@ -35,16 +36,7 @@ namespace PrecastConcretePlantView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ReinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["ReinforcedComponents"].Visible = false; - } - + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } @@ -57,30 +49,21 @@ namespace PrecastConcretePlantView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforced)); - - if (service is FormReinforced form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforced)); - - if (service is FormReinforced 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/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs index f9b9ad5..aeef48e 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using PrecastConcretePlantContracts.DI; namespace PrecastConcretePlantView { @@ -32,15 +33,9 @@ namespace PrecastConcretePlantView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка исполнителей"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки исполнителей"); @@ -50,28 +45,22 @@ namespace PrecastConcretePlantView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewMail.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewMail.cs index a7716d9..16a64eb 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormViewMail.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewMail.cs @@ -30,16 +30,9 @@ namespace PrecastConcretePlantView { 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; - } - _logger.LogInformation("Загрузка списка писем"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки писем"); diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 1e4222f..7bfa98c 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -9,25 +9,21 @@ using PrecastConcretePlantBusinessLogic.OfficePackage.Implements; using PrecastConcretePlantBusinessLogic.OfficePackage; using PrecastConcretePlantBusinessLogic.MailWorker; using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.DI; namespace PrecastConcretePlantView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; [STAThread] static void Main() { ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); - mailSender?.MailConfig(new MailConfigBindingModel + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, @@ -41,53 +37,52 @@ namespace PrecastConcretePlantView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "<22><> <20><> <20> <20><>"); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + 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/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/BackUpLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..3955c2b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantDataModels; +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 PrecastConcretePlantBusinessLogic.BusinessLogic +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBindingModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/BackUpSaveBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..754a1f1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/MessageInfoBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/MessageInfoBindingModel.cs index f4d2dc6..1bd8cfd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/MessageInfoBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,6 @@ namespace PrecastConcretePlantContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + public int Id => throw new NotImplementedException(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IBackUpLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..53c1090 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using PrecastConcretePlantContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBindingModel model); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/DI/DependencyManager.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..610ff41 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/DependencyManager.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/DI/IDependencyContainer.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..5e7c967 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/IDependencyContainer.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/DI/IImplementationExtension.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..1bd32bd --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/DI/ServiceDependencyContainer.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..370a42e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/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 PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/DI/ServiceProviderLoader.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..794bb5e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.DI +{ + public class ServiceProviderLoader + { + 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/PrecastConcretePlant/PrecastConcretePlantContracts/DI/UnityDependencyContainer.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..bd94b31 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Lifetime; +using Unity.Microsoft.Logging; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj b/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj index dae7eac..d55914a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IBackUpInfo.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..c42b350 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs index 30f78db..98dcac4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs @@ -5,15 +5,17 @@ using System.Text; using System.Threading.Tasks; using PrecastConcretePlantDataModels.Models; using System.ComponentModel; +using PrecastConcretePlantContracts.Attributes; namespace PrecastConcretePlantContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 80)] public double Cost { get; set; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs index b41daf9..d8003df 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using PrecastConcretePlantDataModels.Models; +using PrecastConcretePlantContracts.Attributes; +using PrecastConcretePlantDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace PrecastConcretePlantContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/MessageInfoViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/MessageInfoViewModel.cs index bd23073..0c01135 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/MessageInfoViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using PrecastConcretePlantDataModels.Models; +using PrecastConcretePlantContracts.Attributes; +using PrecastConcretePlantDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,23 @@ namespace PrecastConcretePlantContracts.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("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column("Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column("Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs index b80245e..81402a7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -6,40 +6,46 @@ using System.Threading.Tasks; using PrecastConcretePlantDataModels.Enums; using PrecastConcretePlantDataModels.Models; using System.ComponentModel; +using PrecastConcretePlantContracts.Attributes; namespace PrecastConcretePlantContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } + + [Column(visible: false)] public int ReinforcedId { get; set; } - [DisplayName("Документ")] - public string ReinforcedName { get; set; } = string.Empty; + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("ФИО клиента")] + + [Column("Фамилия клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Фамилия исполнителя")] + [Column("Фамилия исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + + [Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string ReinforcedName { get; set; } = string.Empty; + + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } - - } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs index 5fa9981..cc5e8e9 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs @@ -5,16 +5,19 @@ using System.Text; using System.Threading.Tasks; using PrecastConcretePlantDataModels.Models; using System.ComponentModel; +using PrecastConcretePlantContracts.Attributes; namespace PrecastConcretePlantContracts.ViewModels { public class ReinforcedViewModel : IReinforcedModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ReinforcedName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } + [Column(visible: false)] public Dictionary ReinforcedComponents { get; diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IMessageInfoModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IMessageInfoModel.cs index 5da4404..1b604b3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IMessageInfoModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace PrecastConcretePlantDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/DatabaseImplementationExtension.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..9727f50 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,29 @@ +using PrecastConcretePlantContracts.DI; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantDatabaseImplement.Implements; +using PrecastConcretePlantDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement +{ + 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/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/BackUpInfo.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/BackUpInfo.cs new file mode 100644 index 0000000..239e748 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/BackUpInfo.cs @@ -0,0 +1,31 @@ +using PrecastConcretePlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Models +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new PrecastConcretePlantDataBase(); + 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/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Client.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Client.cs index 559af70..9a4ba35 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Client.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Client.cs @@ -8,20 +8,25 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace PrecastConcretePlantDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int Id { get; private set; } [ForeignKey("ClientId")] diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs index 2ce507d..d3e6621 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs @@ -6,19 +6,24 @@ 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 PrecastConcretePlantDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs index a99f089..b3ebc43 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs @@ -5,21 +5,24 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace PrecastConcretePlantDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/MessageInfo.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/MessageInfo.cs index b5c9577..978bf62 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/MessageInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/MessageInfo.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 PrecastConcretePlantDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -54,5 +57,6 @@ namespace PrecastConcretePlantDatabaseImplement.Models DateDelivery = DateDelivery, }; + public int Id => throw new NotImplementedException(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs index c282176..1e0dfb8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs @@ -6,28 +6,37 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection.Metadata; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace PrecastConcretePlantDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { public int Id { get; private set; } [Required] + [DataMember] public int ReinforcedId { get; private set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; - + [DataMember] public DateTime? DateImplement { get; private set; } public virtual Reinforced Reinforced { get; set; } public virtual Client Client { get; set; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs index 1c91633..2ceffda 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs @@ -6,24 +6,30 @@ 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 PrecastConcretePlantDatabaseImplement.Models { + [DataContract] public class Reinforced : IReinforcedModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ReinforcedName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _reinforcedComponents = null; [NotMapped] + [DataMember] public Dictionary ReinforcedComponents { get diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj index 77c9e22..991fb4f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -20,4 +20,8 @@ + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/FileImplementationExtension.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..dc0c5c3 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/FileImplementationExtension.cs @@ -0,0 +1,28 @@ +using PrecastConcretePlantContracts.DI; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/BackUpInfo.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..1fc095f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,34 @@ +using PrecastConcretePlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + // Получаем значения из singleton-объекта универсального свойства содержащее тип T + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Client.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Client.cs index c4bd50c..28e89d0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Client.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Client.cs @@ -4,20 +4,26 @@ using PrecastConcretePlantDataModels.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 PrecastConcretePlantFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public string ClientFIO { get; private set; } = string.Empty; + [DataMember] public string Email { get; private set; } = string.Empty; + [DataMember] public string Password { get; private set; } = string.Empty; + [DataMember] public int Id { get; private set; } public static Client? Create(ClientBindingModel model) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs index 82f5656..25068fd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs @@ -4,17 +4,21 @@ using PrecastConcretePlantDataModels.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 PrecastConcretePlantFileImplement.Models { - + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs index 59a2872..a5f05ca 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs @@ -4,22 +4,25 @@ using PrecastConcretePlantDataModels.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 PrecastConcretePlantFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } public static Implementer? Create(XElement element) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/MessageInfo.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/MessageInfo.cs index 9da260c..374873e 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/MessageInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/MessageInfo.cs @@ -4,24 +4,27 @@ using PrecastConcretePlantDataModels.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 PrecastConcretePlantFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; private set; } = string.Empty; - + [DataMember] public int? ClientId { get; private set; } - + [DataMember] public string SenderName { get; private set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; private set; } = DateTime.Now; - + [DataMember] public string Subject { get; private set; } = string.Empty; - + [DataMember] public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) @@ -76,5 +79,7 @@ namespace PrecastConcretePlantFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + + public int Id => throw new NotImplementedException(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs index 19d4bb8..a676084 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs @@ -4,28 +4,33 @@ using PrecastConcretePlantDataModels.Enums; 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 PrecastConcretePlantFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int ReinforcedId { get; private set; } + [DataMember] public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; set; } - + [DataMember] public int Count { get; private set; } - + [DataMember] public double Sum { get; private set; } - + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; - + [DataMember] public DateTime? DateImplement { get; private set; } - + [DataMember] public int Id { get; private set; } public static Order? Create(OrderBindingModel model) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs index 68ee806..2fa1ef6 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs @@ -4,20 +4,25 @@ using PrecastConcretePlantDataModels.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 PrecastConcretePlantFileImplement.Models { + [DataContract] public class Reinforced : IReinforcedModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ReinforcedName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); - private Dictionary? _reinforcedComponents = - null; + private Dictionary? _reinforcedComponents = null; + [DataMember] public Dictionary ReinforcedComponents { get diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj index d3856ff..6031537 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/BackUpInfo.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..a9e2b09 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using PrecastConcretePlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.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/PrecastConcretePlant/PrecastConcretePlantListImplement/ListImplementationExtension.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..4d72cbb --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ListImplementationExtension.cs @@ -0,0 +1,28 @@ +using PrecastConcretePlantContracts.DI; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement +{ + 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/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/MessageInfo.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/MessageInfo.cs index 2b6d057..7085b37 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/MessageInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/MessageInfo.cs @@ -49,6 +49,6 @@ namespace PrecastConcretePlantListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - + public int Id => throw new NotImplementedException(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj index d3bab3e..524aa83 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/PrecastConcretePlant/README.md b/PrecastConcretePlant/README.md new file mode 100644 index 0000000..f3baca6 --- /dev/null +++ b/PrecastConcretePlant/README.md @@ -0,0 +1,2 @@ +# PIbd-22_Kashin_M.I_PrecastConcretePlant +