diff --git a/ComponentProgramming/BusinessLogics/BusinessLogics.csproj b/ComponentProgramming/BusinessLogics/BusinessLogics.csproj new file mode 100644 index 0000000..1d1cdeb --- /dev/null +++ b/ComponentProgramming/BusinessLogics/BusinessLogics.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/ComponentProgramming/BusinessLogics/BusinessLogics/OrganisationTypeLogic.cs b/ComponentProgramming/BusinessLogics/BusinessLogics/OrganisationTypeLogic.cs new file mode 100644 index 0000000..315a8d0 --- /dev/null +++ b/ComponentProgramming/BusinessLogics/BusinessLogics/OrganisationTypeLogic.cs @@ -0,0 +1,93 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogicsContracts; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogics.BusinessLogics +{ + public class OrganisationTypeLogic : IOrganisationTypeLogic + { + private readonly IOrganisationTypeStorage _orgTypeStorage; + + public OrganisationTypeLogic(IOrganisationTypeStorage orgTypeStorage) + { + _orgTypeStorage = orgTypeStorage; + } + + public List? ReadList(OrganisationTypeSearchModel? model) + { + var list = model == null ? _orgTypeStorage.GetFullList() : _orgTypeStorage.GetFilteredList(model); + + if (list == null) + { + return null; + } + return list; + } + + public OrganisationTypeViewModel? ReadElement(OrganisationTypeSearchModel? model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _orgTypeStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public bool Create(OrganisationTypeBindingModel model) + { + CheckModel(model); + if (_orgTypeStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(OrganisationTypeBindingModel model) + { + CheckModel(model); + if (_orgTypeStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(OrganisationTypeBindingModel model) + { + CheckModel(model, false); + if (_orgTypeStorage.Delete(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(OrganisationTypeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentException("Введите название типа", nameof(model.Name)); + } + } + } +} diff --git a/ComponentProgramming/BusinessLogics/BusinessLogics/ProviderLogic.cs b/ComponentProgramming/BusinessLogics/BusinessLogics/ProviderLogic.cs new file mode 100644 index 0000000..8f5249c --- /dev/null +++ b/ComponentProgramming/BusinessLogics/BusinessLogics/ProviderLogic.cs @@ -0,0 +1,102 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogicsContracts; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogics.BusinessLogics +{ + public class ProviderLogic : IProviderLogic + { + + private readonly IProviderStorage _providerStorage; + + public ProviderLogic(IProviderStorage providerStorage) + { + _providerStorage = providerStorage; + } + + public List? ReadList(ProviderSearchModel? model) + { + var list = model == null ? _providerStorage.GetFullList() : _providerStorage.GetFilteredList(model); + + if(list == null) + { + return null; + } + return list; + } + + public ProviderViewModel? ReadElement(ProviderSearchModel? model) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _providerStorage.GetElement(model); + if(element == null) + { + return null; + } + return element; + } + + public bool Create(ProviderBindingModel model) + { + CheckModel(model); + if(_providerStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(ProviderBindingModel model) + { + CheckModel(model); + if(_providerStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(ProviderBindingModel model) + { + CheckModel(model, false); + if(_providerStorage.Delete(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(ProviderBindingModel model, bool withParams = true) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentException("Введите название поставщика", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.FurnitureType)) + { + throw new ArgumentException("Введите тип мебели", nameof(model.FurnitureType)); + } + if (string.IsNullOrEmpty(model.OrganisationType)) + { + throw new ArgumentException("Выберите тип организации", nameof(model.OrganisationType)); + } + } + } +} diff --git a/ComponentProgramming/ComponentProgramming.sln b/ComponentProgramming/ComponentProgramming.sln index b2c5b1b..f087c26 100644 --- a/ComponentProgramming/ComponentProgramming.sln +++ b/ComponentProgramming/ComponentProgramming.sln @@ -3,9 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34714.143 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentProgramming", "ComponentProgramming\ComponentProgramming.csproj", "{97AC6509-906E-4688-9C6F-67406629A6CA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentProgramming", "ComponentProgramming\ComponentProgramming.csproj", "{97AC6509-906E-4688-9C6F-67406629A6CA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{A490A64E-3A3B-4782-B0DB-142543BDC6A5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Forms", "Forms\Forms.csproj", "{A490A64E-3A3B-4782-B0DB-142543BDC6A5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{6D33E2A8-3992-4213-B563-E4E7FDC0F5AB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{0770DB50-E976-4257-9DB5-8032D28881FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogics", "BusinessLogics\BusinessLogics.csproj", "{70711FA1-A2EC-4BF8-8798-8DCBBC8A7FB2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{3F0166B4-E2B0-4499-96EE-0FFFE57855BD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +29,22 @@ Global {A490A64E-3A3B-4782-B0DB-142543BDC6A5}.Debug|Any CPU.Build.0 = Debug|Any CPU {A490A64E-3A3B-4782-B0DB-142543BDC6A5}.Release|Any CPU.ActiveCfg = Release|Any CPU {A490A64E-3A3B-4782-B0DB-142543BDC6A5}.Release|Any CPU.Build.0 = Release|Any CPU + {6D33E2A8-3992-4213-B563-E4E7FDC0F5AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D33E2A8-3992-4213-B563-E4E7FDC0F5AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D33E2A8-3992-4213-B563-E4E7FDC0F5AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D33E2A8-3992-4213-B563-E4E7FDC0F5AB}.Release|Any CPU.Build.0 = Release|Any CPU + {0770DB50-E976-4257-9DB5-8032D28881FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0770DB50-E976-4257-9DB5-8032D28881FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0770DB50-E976-4257-9DB5-8032D28881FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0770DB50-E976-4257-9DB5-8032D28881FC}.Release|Any CPU.Build.0 = Release|Any CPU + {70711FA1-A2EC-4BF8-8798-8DCBBC8A7FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70711FA1-A2EC-4BF8-8798-8DCBBC8A7FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70711FA1-A2EC-4BF8-8798-8DCBBC8A7FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70711FA1-A2EC-4BF8-8798-8DCBBC8A7FB2}.Release|Any CPU.Build.0 = Release|Any CPU + {3F0166B4-E2B0-4499-96EE-0FFFE57855BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F0166B4-E2B0-4499-96EE-0FFFE57855BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F0166B4-E2B0-4499-96EE-0FFFE57855BD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F0166B4-E2B0-4499-96EE-0FFFE57855BD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ComponentProgramming/ComponentProgramming/Components/testComp.Designer.cs b/ComponentProgramming/ComponentProgramming/Components/testComp.Designer.cs deleted file mode 100644 index 1e9a77b..0000000 --- a/ComponentProgramming/ComponentProgramming/Components/testComp.Designer.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace ComponentProgramming -{ - partial class testComp - { - /// - /// Обязательная переменная конструктора. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Освободить все используемые ресурсы. - /// - /// истинно, если управляемый ресурс должен быть удален; иначе ложно. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Код, автоматически созданный конструктором компонентов - - /// - /// Требуемый метод для поддержки конструктора — не изменяйте - /// содержимое этого метода с помощью редактора кода. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - } - - #endregion - } -} diff --git a/ComponentProgramming/ComponentProgramming/Components/testComp.cs b/ComponentProgramming/ComponentProgramming/Components/testComp.cs deleted file mode 100644 index e30d048..0000000 --- a/ComponentProgramming/ComponentProgramming/Components/testComp.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComponentProgramming -{ - public partial class testComp : Component - { - - private string _fileName; - - public string FileName - { - set - { - if (string.IsNullOrEmpty(value)) return; - if (!value.EndsWith(".txt")) - { - throw new ArgumentException("No txt file"); - } - _fileName = value; - } - } - - public testComp() - { - InitializeComponent(); - _fileName = string.Empty; - } - - public testComp(IContainer container) - { - container.Add(this); - - InitializeComponent(); - _fileName = string.Empty; - } - - public bool saveToFile(string[] texts) - { - CheckFileExist(); - using var writer = new StreamWriter(_fileName, true); - foreach (var text in texts) - { - writer.WriteLine(text); - } - writer.Flush(); - return true; - } - - private void CheckFileExist() - { - if (string.IsNullOrEmpty(_fileName)) - { - throw new ArgumentNullException(_fileName); - } - if(!File.Exists("../"+_fileName)) - { - throw new FileNotFoundException(_fileName); - } - } - } -} diff --git a/ComponentProgramming/ComponentProgramming/Control/ControlImage.Designer.cs b/ComponentProgramming/ComponentProgramming/Control/ControlImage.Designer.cs deleted file mode 100644 index 9df1a7c..0000000 --- a/ComponentProgramming/ComponentProgramming/Control/ControlImage.Designer.cs +++ /dev/null @@ -1,72 +0,0 @@ -namespace ComponentProgramming -{ - partial class ControlImage - { - /// - /// Обязательная переменная конструктора. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Освободить все используемые ресурсы. - /// - /// истинно, если управляемый ресурс должен быть удален; иначе ложно. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Код, автоматически созданный конструктором компонентов - - /// - /// Требуемый метод для поддержки конструктора — не изменяйте - /// содержимое этого метода с помощью редактора кода. - /// - private void InitializeComponent() - { - pictureBoxAvatar = new PictureBox(); - buttonLoad = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxAvatar).BeginInit(); - SuspendLayout(); - // - // pictureBoxAvatar - // - pictureBoxAvatar.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - pictureBoxAvatar.Location = new Point(3, 3); - pictureBoxAvatar.Name = "pictureBoxAvatar"; - pictureBoxAvatar.Size = new Size(144, 115); - pictureBoxAvatar.TabIndex = 0; - pictureBoxAvatar.TabStop = false; - // - // buttonLoad - // - buttonLoad.Anchor = AnchorStyles.Bottom; - buttonLoad.Location = new Point(35, 124); - buttonLoad.Name = "buttonLoad"; - buttonLoad.Size = new Size(75, 23); - buttonLoad.TabIndex = 1; - buttonLoad.Text = "Загрузить"; - buttonLoad.UseVisualStyleBackColor = true; - buttonLoad.Click += buttonLoad_Click; - // - // Control - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - Controls.Add(buttonLoad); - Controls.Add(pictureBoxAvatar); - Name = "Control"; - ((System.ComponentModel.ISupportInitialize)pictureBoxAvatar).EndInit(); - ResumeLayout(false); - } - - #endregion - - private PictureBox pictureBoxAvatar; - private Button buttonLoad; - } -} diff --git a/ComponentProgramming/ComponentProgramming/Control/ControlImage.cs b/ComponentProgramming/ComponentProgramming/Control/ControlImage.cs deleted file mode 100644 index 2f81f49..0000000 --- a/ComponentProgramming/ComponentProgramming/Control/ControlImage.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ComponentProgramming -{ - public partial class ControlImage : UserControl - { - private event EventHandler? _avatarChanged; - private event Action? _errorOccured; - public string Error { get; private set; } - public Image Avatar - { - get - { - return pictureBoxAvatar.Image; - } - set - { - pictureBoxAvatar.Image = value; - } - } - - public event EventHandler AvatarChanged - { - add { _avatarChanged += value; } - remove { _avatarChanged -= value; } - } - - public event Action AnErrorOccured - { - add { _errorOccured += value; } - remove { _errorOccured -= value; } - } - - public ControlImage() - { - InitializeComponent(); - Error = string.Empty; - } - - private void buttonLoad_Click(object sender, EventArgs e) - { - var ofd = new OpenFileDialog(); - if(ofd.ShowDialog() == DialogResult.OK) - { - try - { - pictureBoxAvatar.Image = Image.FromFile(ofd.FileName); - pictureBoxAvatar.Width = pictureBoxAvatar.Image.Width; - _avatarChanged?.Invoke(this, e); - } - catch( Exception ex) - { - Error = ex.Message; - _errorOccured?.Invoke(); - } - } - } - } -} diff --git a/ComponentProgramming/ComponentProgramming/Control/Person.cs b/ComponentProgramming/ComponentProgramming/Control/Person.cs deleted file mode 100644 index feaeacc..0000000 --- a/ComponentProgramming/ComponentProgramming/Control/Person.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComponentProgramming.Control -{ - public class Person - { - public int Id { get; set; } - public string Name { get; set; } - public string Surname { get; set; } - - public Person() { } - - public Person(int id, string name, string surname) - { - Name = name; - Id = id; - Surname = surname; - } - } -} diff --git a/ComponentProgramming/Contracts/BindingModels/OrganisationTypeBindingModel.cs b/ComponentProgramming/Contracts/BindingModels/OrganisationTypeBindingModel.cs new file mode 100644 index 0000000..548c748 --- /dev/null +++ b/ComponentProgramming/Contracts/BindingModels/OrganisationTypeBindingModel.cs @@ -0,0 +1,17 @@ +using Models.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BindingModels +{ + public class OrganisationTypeBindingModel : IOrganisationTypeModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + } +} diff --git a/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs b/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs new file mode 100644 index 0000000..fe743cd --- /dev/null +++ b/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs @@ -0,0 +1,22 @@ +using Models.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BindingModels +{ + public class ProviderBindingModel : IProviderModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string FurnitureType { get; set; } = string.Empty; + + public string OrganisationType { get; set; } = string.Empty; + + public DateTime? DateLastDelivery { get; set; } + } +} diff --git a/ComponentProgramming/Contracts/BusinessLogicsContracts/IOrganisationTypeLogic.cs b/ComponentProgramming/Contracts/BusinessLogicsContracts/IOrganisationTypeLogic.cs new file mode 100644 index 0000000..38630c6 --- /dev/null +++ b/ComponentProgramming/Contracts/BusinessLogicsContracts/IOrganisationTypeLogic.cs @@ -0,0 +1,22 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IOrganisationTypeLogic + { + List? ReadList(OrganisationTypeSearchModel? model); + + OrganisationTypeViewModel? ReadElement(OrganisationTypeSearchModel? model); + + bool Create(OrganisationTypeBindingModel model); + bool Update(OrganisationTypeBindingModel model); + bool Delete(OrganisationTypeBindingModel model); + } +} diff --git a/ComponentProgramming/Contracts/BusinessLogicsContracts/IProviderLogic.cs b/ComponentProgramming/Contracts/BusinessLogicsContracts/IProviderLogic.cs new file mode 100644 index 0000000..c4a7f82 --- /dev/null +++ b/ComponentProgramming/Contracts/BusinessLogicsContracts/IProviderLogic.cs @@ -0,0 +1,22 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IProviderLogic + { + List? ReadList(ProviderSearchModel? model); + + ProviderViewModel? ReadElement (ProviderSearchModel? model); + + bool Create(ProviderBindingModel model); + bool Update(ProviderBindingModel model); + bool Delete(ProviderBindingModel model); + } +} diff --git a/ComponentProgramming/Contracts/Contracts.csproj b/ComponentProgramming/Contracts/Contracts.csproj new file mode 100644 index 0000000..8dcc508 --- /dev/null +++ b/ComponentProgramming/Contracts/Contracts.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/ComponentProgramming/Contracts/SearchModels/OrganisationTypeSearchModel.cs b/ComponentProgramming/Contracts/SearchModels/OrganisationTypeSearchModel.cs new file mode 100644 index 0000000..985965d --- /dev/null +++ b/ComponentProgramming/Contracts/SearchModels/OrganisationTypeSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.SearchModels +{ + public class OrganisationTypeSearchModel + { + public string? Name { get; set; } + } +} diff --git a/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs b/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs new file mode 100644 index 0000000..705a3fd --- /dev/null +++ b/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.SearchModels +{ + public class ProviderSearchModel + { + public string? Name { get; set; } + + public string? OrganisationType { get; set; } + + public DateTime? DateLastDelivery { get; set; } + } +} diff --git a/ComponentProgramming/Contracts/StorageContracts/IOrganisationTypeStorage.cs b/ComponentProgramming/Contracts/StorageContracts/IOrganisationTypeStorage.cs new file mode 100644 index 0000000..29c86b3 --- /dev/null +++ b/ComponentProgramming/Contracts/StorageContracts/IOrganisationTypeStorage.cs @@ -0,0 +1,22 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.StorageContracts +{ + public interface IOrganisationTypeStorage + { + List GetFullList(); + List GetFilteredList(OrganisationTypeSearchModel model); + OrganisationTypeViewModel? GetElement(OrganisationTypeSearchModel model); + + OrganisationTypeViewModel? Insert(OrganisationTypeBindingModel model); + OrganisationTypeViewModel? Update(OrganisationTypeBindingModel model); + OrganisationTypeViewModel? Delete(OrganisationTypeBindingModel model); + } +} diff --git a/ComponentProgramming/Contracts/StorageContracts/IProviderStorage.cs b/ComponentProgramming/Contracts/StorageContracts/IProviderStorage.cs new file mode 100644 index 0000000..70d198a --- /dev/null +++ b/ComponentProgramming/Contracts/StorageContracts/IProviderStorage.cs @@ -0,0 +1,22 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.StorageContracts +{ + public interface IProviderStorage + { + List GetFullList(); + List GetFilteredList(ProviderSearchModel model); + ProviderViewModel? GetElement(ProviderSearchModel model); + + ProviderViewModel? Insert(ProviderBindingModel model); + ProviderViewModel? Update(ProviderBindingModel model); + ProviderViewModel? Delete(ProviderBindingModel model); + } +} diff --git a/ComponentProgramming/Contracts/ViewModels/OrganisationTypeViewModel.cs b/ComponentProgramming/Contracts/ViewModels/OrganisationTypeViewModel.cs new file mode 100644 index 0000000..494bdf4 --- /dev/null +++ b/ComponentProgramming/Contracts/ViewModels/OrganisationTypeViewModel.cs @@ -0,0 +1,19 @@ +using Models.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class OrganisationTypeViewModel : IOrganisationTypeModel + { + public int Id { get; set; } + + [DisplayName("Название типа")] + public string Name { get; set; } = string.Empty; + + } +} diff --git a/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs b/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs new file mode 100644 index 0000000..344121c --- /dev/null +++ b/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs @@ -0,0 +1,28 @@ +using Models.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class ProviderViewModel : IProviderModel + { + public int Id { get; set; } + + [DisplayName("Название организации")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Перечернь производимой мебели")] + public string FurnitureType { get; set; } = string.Empty; + + [DisplayName("Тип организации")] + public string OrganisationType { get; set; } = string.Empty; + + [DisplayName("Дата последней доставки")] + public DateTime? DateLastDelivery { get; set; } + + } +} diff --git a/ComponentProgramming/DatabaseImplement/Database.cs b/ComponentProgramming/DatabaseImplement/Database.cs new file mode 100644 index 0000000..3add9f9 --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Database.cs @@ -0,0 +1,20 @@ +using DatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace DatabaseImplement +{ + public class Database : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=ProvidersDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Providers { get; set; } + public virtual DbSet OrganisationTypes { get; set; } + } +} diff --git a/ComponentProgramming/DatabaseImplement/DatabaseImplement.csproj b/ComponentProgramming/DatabaseImplement/DatabaseImplement.csproj new file mode 100644 index 0000000..ec24965 --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/DatabaseImplement.csproj @@ -0,0 +1,24 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs b/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs new file mode 100644 index 0000000..9a5246a --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs @@ -0,0 +1,75 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using DatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class ProviderStorage : IProviderStorage + { + public List GetFullList() + { + using var context = new Database(); + return context.Providers.Select(x=>x.GetViewModel).ToList(); + } + + public List GetFilteredList(ProviderSearchModel model) + { + if (string.IsNullOrEmpty(model.OrganisationType)) + { + return new(); + } + using var context = new Database(); + return context.Providers.Where(x => x.OrganisationType == model.OrganisationType).Select(x=> x.GetViewModel).ToList(); + } + + public ProviderViewModel? GetElement(ProviderSearchModel model) + { + if(string.IsNullOrEmpty(model.Name)) + { + return null; + } + using var context = new Database(); + return context.Providers.FirstOrDefault(x => x.Name == model.Name)?.GetViewModel; + } + + public ProviderViewModel? Insert(ProviderBindingModel model) + { + var newProvider = Provider.Create(model); + if (newProvider == null) return null; + using var context = new Database(); + context.Providers.Add(newProvider); + context.SaveChanges(); + return newProvider.GetViewModel; + } + + public ProviderViewModel? Update(ProviderBindingModel model) + { + using var context = new Database(); + var provider = context.Providers.FirstOrDefault(x=> x.Id == model.Id); + if(provider == null) return null; + provider.Update(model); + context.SaveChanges(); + return provider.GetViewModel; + } + + public ProviderViewModel? Delete(ProviderBindingModel model) + { + using var context = new Database(); + var element = context.Providers.FirstOrDefault(x=>x.Id == model.Id); + if(element != null) + { + context.Providers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/ComponentProgramming/DatabaseImplement/Models/OrganisationType.cs b/ComponentProgramming/DatabaseImplement/Models/OrganisationType.cs new file mode 100644 index 0000000..51c31ed --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Models/OrganisationType.cs @@ -0,0 +1,44 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using Models.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + public class OrganisationType : IOrganisationTypeModel + { + public int Id { get; private set; } + + [Required] + public string Name { get; private set; } = string.Empty; + + public static OrganisationType? Create(OrganisationTypeBindingModel model) + { + if(model == null) return null; + + return new OrganisationType + { + Id = model.Id, + Name = model.Name, + }; + } + + public void Update(OrganisationTypeBindingModel model) + { + if (model == null) return; + + Name = model.Name; + } + + public OrganisationTypeViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + }; + } +} diff --git a/ComponentProgramming/DatabaseImplement/Models/Provider.cs b/ComponentProgramming/DatabaseImplement/Models/Provider.cs new file mode 100644 index 0000000..3d04711 --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Models/Provider.cs @@ -0,0 +1,61 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using Models.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + public class Provider : IProviderModel + { + public int Id { get; private set; } + + [Required] + public string Name { get; private set; } = string.Empty; + + [Required] + public string FurnitureType { get; private set; } = string.Empty; + + [Required] + public string OrganisationType { get; private set; } = string.Empty; + + public DateTime? DateLastDelivery { get; private set; } + + public static Provider? Create(ProviderBindingModel model) + { + if(model == null) return null; + + return new Provider + { + Id = model.Id, + Name = model.Name, + FurnitureType = model.FurnitureType, + OrganisationType = model.OrganisationType, + DateLastDelivery = model.DateLastDelivery, + }; + } + + public void Update(ProviderBindingModel model) + { + if (model == null) return; + + Name = model.Name; + FurnitureType = model.FurnitureType; + OrganisationType = model.OrganisationType; + DateLastDelivery = model.DateLastDelivery; + } + + public ProviderViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + FurnitureType = FurnitureType, + OrganisationType = OrganisationType, + DateLastDelivery = DateLastDelivery, + }; + } +} diff --git a/ComponentProgramming/Forms/Form.Designer.cs b/ComponentProgramming/Forms/Form.Designer.cs deleted file mode 100644 index c5ab029..0000000 --- a/ComponentProgramming/Forms/Form.Designer.cs +++ /dev/null @@ -1,119 +0,0 @@ -namespace Forms -{ - partial class Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - controlComboBox = new ComponentProgramming.ControlComboBox(); - controlTextBox = new ComponentProgramming.ControlTextBox(); - buttonGetObj = new Button(); - buttonEnter = new Button(); - controlListBox = new ComponentProgramming.ControlListBox(); - tableComponent = new ComponentProgramming.Components.TableComponent(components); - diagramComponent = new ComponentProgramming.DiagramComponent(components); - largeTextComponent = new ComponentProgramming.Components.LargeTextComponent(components); - SuspendLayout(); - // - // controlComboBox - // - controlComboBox.Location = new Point(14, 4); - controlComboBox.Margin = new Padding(3, 5, 3, 5); - controlComboBox.Name = "controlComboBox"; - controlComboBox.SelectedItem = ""; - controlComboBox.Size = new Size(202, 41); - controlComboBox.TabIndex = 0; - controlComboBox.ComboBoxChanged += controlComboBox_ComboBoxChanged; - // - // controlTextBox - // - controlTextBox.Location = new Point(258, 4); - controlTextBox.Margin = new Padding(3, 5, 3, 5); - controlTextBox.Name = "controlTextBox"; - controlTextBox.NumPattern = null; - controlTextBox.Size = new Size(171, 39); - controlTextBox.TabIndex = 1; - // - // buttonGetObj - // - buttonGetObj.Location = new Point(14, 553); - buttonGetObj.Margin = new Padding(3, 4, 3, 4); - buttonGetObj.Name = "buttonGetObj"; - buttonGetObj.Size = new Size(144, 31); - buttonGetObj.TabIndex = 3; - buttonGetObj.Text = "Получить объект"; - buttonGetObj.UseVisualStyleBackColor = true; - buttonGetObj.Click += buttonGetObj_Click; - // - // buttonEnter - // - buttonEnter.Location = new Point(311, 48); - buttonEnter.Name = "buttonEnter"; - buttonEnter.Size = new Size(85, 32); - buttonEnter.TabIndex = 5; - buttonEnter.Text = "Ввод"; - buttonEnter.UseVisualStyleBackColor = true; - buttonEnter.Click += buttonEnter_Click; - // - // controlListBox - // - controlListBox.GetIndex = -1; - controlListBox.Location = new Point(14, 87); - controlListBox.Margin = new Padding(3, 5, 3, 5); - controlListBox.Name = "controlListBox"; - controlListBox.Size = new Size(382, 459); - controlListBox.TabIndex = 7; - // - // Form - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(410, 600); - Controls.Add(controlListBox); - Controls.Add(buttonEnter); - Controls.Add(buttonGetObj); - Controls.Add(controlTextBox); - Controls.Add(controlComboBox); - Margin = new Padding(3, 4, 3, 4); - Name = "Form"; - Text = "Form"; - ResumeLayout(false); - } - - #endregion - - private ComponentProgramming.ControlImage control; - private ComponentProgramming.ControlComboBox controlComboBox; - private ComponentProgramming.ControlTextBox controlTextBox; - private Button buttonGetObj; - private Button buttonEnter; - private ComponentProgramming.ControlListBox controlListBox; - private ComponentProgramming.Components.TableComponent tableComponent; - private ComponentProgramming.DiagramComponent diagramComponent; - private ComponentProgramming.Components.LargeTextComponent largeTextComponent; - } -} diff --git a/ComponentProgramming/Forms/Form.cs b/ComponentProgramming/Forms/Form.cs deleted file mode 100644 index 1c218ca..0000000 --- a/ComponentProgramming/Forms/Form.cs +++ /dev/null @@ -1,93 +0,0 @@ -using ComponentProgramming.Components.Models; - -namespace Forms -{ - public partial class Form : System.Windows.Forms.Form - { - public Form() - { - InitializeComponent(); - FillBox(); - FillTextBox(); - FillList(); - string[] strings = new string[] { " , ( )", " ( ) ( )" }; - largeTextComponent.CreateDocument("C:\\Users\\\\source\\repos\\PIbd-31_Yakovlev.M.G._COP_16\\ComponentProgramming\\Forms\\text.pdf", "", strings); - List colInfos = new List() - { - new ColumnInfo("Name","",50), - new ColumnInfo("Surname","",100), - new ColumnInfo("Phone","",100), - new ColumnInfo("Email","",200), - new ColumnInfo("Password","",50), - }; - List mergeCells = new List() - { - new MergeCells("", new int[] {0,3,4}) - }; - List workers = new List() - { - new Worker("", "", "+88005553535", "mail@gmail.ru", "pass123"), - new Worker("", "", "+88005553535", "mail@gmail.ru", "pass123"), - new Worker("", "", "+88005553535", "mail@gmail.ru", "pass123"), - new Worker("", "", "+88005553535", "mail@gmail.ru", "pass123"), - }; - tableComponent.CreateTable("C:\\Users\\\\source\\repos\\PIbd-31_Yakovlev.M.G._COP_16\\ComponentProgramming\\Forms\\table.pdf", "", mergeCells, colInfos, workers); - - Dictionary> data = new Dictionary>(); - data.Add("1", new List { 0.5, 1, 2, 5, 2 }); - data.Add("2", new List { 3, 2, 1, 3, 6 }); - data.Add("3", new List { 7, 3, 1, 2, 5 }); - - diagramComponent.CreateLineDiagram("C:\\Users\\\\source\\repos\\PIbd-31_Yakovlev.M.G._COP_16\\ComponentProgramming\\Forms\\diagram.pdf", "", " ", data, LegendAlign.bottom); - } - - private void FillBox() - { - controlComboBox.ComboBoxItems.Add(" 1"); - controlComboBox.ComboBoxItems.Add(" 2"); - controlComboBox.ComboBoxItems.Add(" 3"); - controlComboBox.ComboBoxItems.Add(" 4"); - controlComboBox.SelectedItem = "dafafadsf"; - } - private void FillTextBox() - { - controlTextBox.NumPattern = @"^\+7\d{10}$"; - controlTextBox.text = "+79063908075"; - } - private void FillList() - { - controlListBox.SetTemplateString(" [Name] [Surname]", "[", "]"); - controlListBox.FillProp(new Person(1, "", ""), 0, "Name"); - controlListBox.FillProp(new Person(2, "", ""), 4, "Surname"); - } - - private void controlComboBox_ComboBoxChanged(object sender, EventArgs e) - { - var elem = controlComboBox.SelectedItem; - MessageBox.Show($": {elem}"); - } - - private void controlTextBox_CheckBoxChanged(object sender, EventArgs e) - { - if (controlTextBox.text == null) - { - MessageBox.Show($"CheckBox checked"); - } - else - { - MessageBox.Show($"CheckBox not checked"); - } - } - - private void buttonGetObj_Click(object sender, EventArgs e) - { - var obj = controlListBox.GetSelectedObject(); - MessageBox.Show($"{obj.Name} {obj.Surname}"); - } - private void buttonEnter_Click(object sender, EventArgs e) - { - var val = controlTextBox.text; - MessageBox.Show($" {val}"); - } - } -} diff --git a/ComponentProgramming/Forms/Form.resx b/ComponentProgramming/Forms/Form.resx deleted file mode 100644 index 458d54c..0000000 --- a/ComponentProgramming/Forms/Form.resx +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - - 161, 17 - - - 351, 17 - - \ No newline at end of file diff --git a/ComponentProgramming/Forms/Forms.csproj b/ComponentProgramming/Forms/Forms.csproj index 212408f..8a9f1ad 100644 --- a/ComponentProgramming/Forms/Forms.csproj +++ b/ComponentProgramming/Forms/Forms.csproj @@ -9,6 +9,8 @@ + + diff --git a/ComponentProgramming/Forms/MainForm.Designer.cs b/ComponentProgramming/Forms/MainForm.Designer.cs new file mode 100644 index 0000000..5249cac --- /dev/null +++ b/ComponentProgramming/Forms/MainForm.Designer.cs @@ -0,0 +1,45 @@ +namespace Forms +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + SuspendLayout(); + // + // MainForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Name = "MainForm"; + Text = "Основная форма"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/ComponentProgramming/Forms/MainForm.cs b/ComponentProgramming/Forms/MainForm.cs new file mode 100644 index 0000000..9b3c80d --- /dev/null +++ b/ComponentProgramming/Forms/MainForm.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Forms +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + } +} diff --git a/ComponentProgramming/ComponentProgramming/Control/ControlImage.resx b/ComponentProgramming/Forms/MainForm.resx similarity index 100% rename from ComponentProgramming/ComponentProgramming/Control/ControlImage.resx rename to ComponentProgramming/Forms/MainForm.resx diff --git a/ComponentProgramming/Forms/Person.cs b/ComponentProgramming/Forms/Person.cs deleted file mode 100644 index 6eaaa59..0000000 --- a/ComponentProgramming/Forms/Person.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Forms -{ - public class Person - { - public int Id { get; set; } - public string Name { get; set; } - public string Surname { get; set; } - - public Person() { } - - public Person(int id, string name, string surname) - { - Name = name; - Id = id; - Surname = surname; - } - } -} diff --git a/ComponentProgramming/Forms/Program.cs b/ComponentProgramming/Forms/Program.cs deleted file mode 100644 index 3e01fbd..0000000 --- a/ComponentProgramming/Forms/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Forms -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form()); - } - } -} \ No newline at end of file diff --git a/ComponentProgramming/Forms/Worker.cs b/ComponentProgramming/Forms/Worker.cs deleted file mode 100644 index f2975d7..0000000 --- a/ComponentProgramming/Forms/Worker.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Forms -{ - public class Worker - { - public string Name { get; set; } = string.Empty; - - public string Surname { get; set; } = string.Empty; - - public string Phone { get; set; } = string.Empty; - - public string Email { get; set; } = string.Empty; - - public string Password { get; set; } = string.Empty; - - public Worker() { } - - public Worker(string name, string surname, string phone, string email, string password) - { - Name = name; - Surname = surname; - Phone = phone; - Email = email; - Password = password; - } - } -} diff --git a/ComponentProgramming/Forms/diagram.pdf b/ComponentProgramming/Forms/diagram.pdf deleted file mode 100644 index b86bdcf..0000000 Binary files a/ComponentProgramming/Forms/diagram.pdf and /dev/null differ diff --git a/ComponentProgramming/Forms/table.pdf b/ComponentProgramming/Forms/table.pdf deleted file mode 100644 index b57b302..0000000 Binary files a/ComponentProgramming/Forms/table.pdf and /dev/null differ diff --git a/ComponentProgramming/Forms/text.pdf b/ComponentProgramming/Forms/text.pdf deleted file mode 100644 index df43276..0000000 Binary files a/ComponentProgramming/Forms/text.pdf and /dev/null differ diff --git a/ComponentProgramming/Models/IId.cs b/ComponentProgramming/Models/IId.cs new file mode 100644 index 0000000..2aa05a6 --- /dev/null +++ b/ComponentProgramming/Models/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models +{ + public interface IId + { + int Id { get; } + } +} diff --git a/ComponentProgramming/Models/Models.csproj b/ComponentProgramming/Models/Models.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/ComponentProgramming/Models/Models.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/ComponentProgramming/Models/Models/IOrganisationTypeModel.cs b/ComponentProgramming/Models/Models/IOrganisationTypeModel.cs new file mode 100644 index 0000000..a0fca8b --- /dev/null +++ b/ComponentProgramming/Models/Models/IOrganisationTypeModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models.Models +{ + public interface IOrganisationTypeModel: IId + { + string Name { get; } + } +} diff --git a/ComponentProgramming/Models/Models/IProviderModel.cs b/ComponentProgramming/Models/Models/IProviderModel.cs new file mode 100644 index 0000000..77074e0 --- /dev/null +++ b/ComponentProgramming/Models/Models/IProviderModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models.Models +{ + public interface IProviderModel : IId + { + + string Name { get;} + + string FurnitureType { get;} + + string OrganisationType { get; } + + DateTime? DateLastDelivery { get; } + } +}