diff --git a/WinForm/AppView/AppView.csproj b/WinForm/AppView/AppView.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/WinForm/AppView/AppView.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/WinForm/AppView/Form1.Designer.cs b/WinForm/AppView/Form1.Designer.cs new file mode 100644 index 0000000..1b9a8ab --- /dev/null +++ b/WinForm/AppView/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace AppView +{ + partial class Form1 + { + /// + /// 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() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/WinForm/AppView/Form1.cs b/WinForm/AppView/Form1.cs new file mode 100644 index 0000000..c023e9d --- /dev/null +++ b/WinForm/AppView/Form1.cs @@ -0,0 +1,10 @@ +namespace AppView +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/WinForm/AppView/Form1.resx b/WinForm/AppView/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinForm/AppView/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/WinForm/AppView/Program.cs b/WinForm/AppView/Program.cs new file mode 100644 index 0000000..5561de2 --- /dev/null +++ b/WinForm/AppView/Program.cs @@ -0,0 +1,17 @@ +namespace AppView +{ + 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 Form1()); + } + } +} \ No newline at end of file diff --git a/WinForm/Contracts/BindingModels/ProviderBindingModel.cs b/WinForm/Contracts/BindingModels/ProviderBindingModel.cs new file mode 100644 index 0000000..43aec63 --- /dev/null +++ b/WinForm/Contracts/BindingModels/ProviderBindingModel.cs @@ -0,0 +1,26 @@ +using DataModels.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 string Name { get; set; } + public string Type { get; set; } + public string Furniture { get; set; } + public DateTime? SupplyDate { get; set; } + + public int Id { get; set; } + + public ProviderBindingModel() { } + + public ProviderBindingModel(IProviderModel provider) + { + Id = provider.Id; + } + } +} diff --git a/WinForm/Contracts/BindingModels/TypeBindingModel.cs b/WinForm/Contracts/BindingModels/TypeBindingModel.cs new file mode 100644 index 0000000..2f90efe --- /dev/null +++ b/WinForm/Contracts/BindingModels/TypeBindingModel.cs @@ -0,0 +1,22 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BindingModels +{ + public class TypeBindingModel : ITypeModel + { + public string Name { get; set; } + public int Id { get; set; } + + public TypeBindingModel() { } + + public TypeBindingModel(ITypeModel type) + { + Id = type.Id; + } + } +} diff --git a/WinForm/Contracts/Contracts.csproj b/WinForm/Contracts/Contracts.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/WinForm/Contracts/Contracts.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/WinForm/Contracts/SearchModels/ProviderSearchModel.cs b/WinForm/Contracts/SearchModels/ProviderSearchModel.cs new file mode 100644 index 0000000..a508436 --- /dev/null +++ b/WinForm/Contracts/SearchModels/ProviderSearchModel.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 ProviderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/WinForm/Contracts/SearchModels/TypeSearchModel.cs b/WinForm/Contracts/SearchModels/TypeSearchModel.cs new file mode 100644 index 0000000..825496a --- /dev/null +++ b/WinForm/Contracts/SearchModels/TypeSearchModel.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 TypeSearchModel + { + public int? Id { get; set; } + } +} diff --git a/WinForm/Contracts/StoragesContracts/IProviderStorage.cs b/WinForm/Contracts/StoragesContracts/IProviderStorage.cs new file mode 100644 index 0000000..d5bb29d --- /dev/null +++ b/WinForm/Contracts/StoragesContracts/IProviderStorage.cs @@ -0,0 +1,21 @@ +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.StoragesContracts +{ + public interface IProviderStorage + { + List GetFullList(); + ProviderViewModel? GetElement(ProviderSearchModel model); + List GetFilteredList(ProviderSearchModel model); + ProviderViewModel? Insert(ProviderBindingModel model); + ProviderViewModel? Update(ProviderBindingModel model); + ProviderViewModel? Delete(ProviderBindingModel model); + } +} diff --git a/WinForm/Contracts/StoragesContracts/ITypeStorage.cs b/WinForm/Contracts/StoragesContracts/ITypeStorage.cs new file mode 100644 index 0000000..59a1581 --- /dev/null +++ b/WinForm/Contracts/StoragesContracts/ITypeStorage.cs @@ -0,0 +1,20 @@ +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.StoragesContracts +{ + public interface ITypeStorage + { + List GetFullList(); + TypeViewModel? GetElement(TypeSearchModel model); + TypeViewModel? Insert(TypeBindingModel model); + TypeViewModel? Update(TypeBindingModel model); + TypeViewModel? Delete(TypeBindingModel model); + } +} diff --git a/WinForm/Contracts/ViewModels/ProviderViewModel.cs b/WinForm/Contracts/ViewModels/ProviderViewModel.cs new file mode 100644 index 0000000..7a34857 --- /dev/null +++ b/WinForm/Contracts/ViewModels/ProviderViewModel.cs @@ -0,0 +1,19 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class ProviderViewModel : IProviderModel + { + public string Name { get; set; } + public string Type { get; set; } + public string Furniture { get; set; } + public DateTime? SupplyDate { get; set; } + public string? SupplyDateTime { get; set; } + public int Id { get; set; } + } +} diff --git a/WinForm/Contracts/ViewModels/TypeViewModel.cs b/WinForm/Contracts/ViewModels/TypeViewModel.cs new file mode 100644 index 0000000..7ede071 --- /dev/null +++ b/WinForm/Contracts/ViewModels/TypeViewModel.cs @@ -0,0 +1,15 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class TypeViewModel : ITypeModel + { + public string Name { get; set; } + public int Id { get; set; } + } +} diff --git a/WinForm/DataBaseImplement/DBContext.cs b/WinForm/DataBaseImplement/DBContext.cs new file mode 100644 index 0000000..eda6741 --- /dev/null +++ b/WinForm/DataBaseImplement/DBContext.cs @@ -0,0 +1,18 @@ +using DatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace DatabaseImplement +{ + public class DBContext:DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if(!optionsBuilder.IsConfigured) + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=COP;Username=courseuser;Password=courseuser"); + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Providers { get; set; } + public virtual DbSet Types { get; set; } + } +} \ No newline at end of file diff --git a/WinForm/DataBaseImplement/DataBaseImplement.csproj b/WinForm/DataBaseImplement/DataBaseImplement.csproj new file mode 100644 index 0000000..7ca6022 --- /dev/null +++ b/WinForm/DataBaseImplement/DataBaseImplement.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/WinForm/DataBaseImplement/Implements/ProviderStorage.cs b/WinForm/DataBaseImplement/Implements/ProviderStorage.cs new file mode 100644 index 0000000..0b32045 --- /dev/null +++ b/WinForm/DataBaseImplement/Implements/ProviderStorage.cs @@ -0,0 +1,89 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StoragesContracts; +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 ProviderViewModel? Delete(ProviderBindingModel model) + { + using var context = new DBContext(); + var element = context.Providers.FirstOrDefault(x => x.Id == model.Id); + + if (element == null) + { + return null; + } + + context.Providers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + public ProviderViewModel? GetElement(ProviderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new DBContext(); + return context.Providers.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ProviderSearchModel model) + { + using var context = new DBContext(); + return context.Providers + .Where(x => model.Id.HasValue && x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new DBContext(); + return context.Providers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ProviderViewModel? Insert(ProviderBindingModel model) + { + var newProvider = Provider.Create(model); + + if (newProvider == null) + { + return null; + } + + using var context = new DBContext(); + context.Providers.Add(newProvider); + context.SaveChanges(); + return newProvider.GetViewModel; + } + + public ProviderViewModel? Update(ProviderBindingModel model) + { + using var context = new DBContext(); + var provider = context.Providers.FirstOrDefault(x => x.Id == model.Id); + + if (provider == null) + { + return null; + } + + provider.Update(model); + context.SaveChanges(); + return provider.GetViewModel; + } + } +} diff --git a/WinForm/DataBaseImplement/Implements/TypeStorage.cs b/WinForm/DataBaseImplement/Implements/TypeStorage.cs new file mode 100644 index 0000000..204b078 --- /dev/null +++ b/WinForm/DataBaseImplement/Implements/TypeStorage.cs @@ -0,0 +1,79 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StoragesContracts; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class TypeStorage : ITypeStorage + { + public TypeViewModel? Delete(TypeBindingModel model) + { + using var context = new DBContext(); + var element = context.Types.FirstOrDefault(x => x.Id == x.Id); + + if (element == null) + { + return null; + } + + context.Types.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + public TypeViewModel? GetElement(TypeSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new DBContext(); + return context.Types.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFullList() + { + using var context = new DBContext(); + return context.Types + .Select(x => x.GetViewModel) + .ToList(); + } + + public TypeViewModel? Insert(TypeBindingModel model) + { + var newType = Models.Type.Create(model); + + if (newType == null) + { + return null; + } + + using var context = new DBContext(); + context.Types.Add(newType); + context.SaveChanges(); + return newType.GetViewModel; + } + + public TypeViewModel? Update(TypeBindingModel model) + { + using var context = new DBContext(); + var type = context.Types.FirstOrDefault(x => x.Id == model.Id); + + if (type == null) + { + return null; + } + + type.Update(model); + context.SaveChanges(); + return type.GetViewModel; + } + } +} diff --git a/WinForm/DataBaseImplement/Models/Provider.cs b/WinForm/DataBaseImplement/Models/Provider.cs new file mode 100644 index 0000000..29866a2 --- /dev/null +++ b/WinForm/DataBaseImplement/Models/Provider.cs @@ -0,0 +1,55 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.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; set; } + [Required] + public string Name { get; set; } + [Required] + public string Type { get; set; } + [Required] + public string Furniture { get; set; } + public DateTime? SupplyDate { get; set; } = DateTime.MinValue; + + public static Provider? Create(ProviderBindingModel model) + { + if (model == null) return null; + return new Provider() + { + Id = model.Id, + Name = model.Name, + Type = model.Type, + Furniture = model.Furniture, + SupplyDate = model.SupplyDate, + }; + } + + public void Update(ProviderBindingModel model) + { + if (model == null) return; + Name = model.Name; + Type = model.Type; + Furniture = model.Furniture; + SupplyDate = model.SupplyDate; + } + + public ProviderViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Type = Type, + Furniture = Furniture, + SupplyDate = SupplyDate, + }; + } +} diff --git a/WinForm/DataBaseImplement/Models/Type.cs b/WinForm/DataBaseImplement/Models/Type.cs new file mode 100644 index 0000000..864042e --- /dev/null +++ b/WinForm/DataBaseImplement/Models/Type.cs @@ -0,0 +1,41 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.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 Type : ITypeModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } + + public static Type? Create(TypeBindingModel model) + { + if (model == null) return null; + return new Type() + { + Id = model.Id, + Name = model.Name, + }; + } + + public void Update(TypeBindingModel? model) + { + if (model == null) return; + Name = model.Name; + } + + public TypeViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + }; + } +} diff --git a/WinForm/DataModels/DataModels.csproj b/WinForm/DataModels/DataModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/WinForm/DataModels/DataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/WinForm/DataModels/IId.cs b/WinForm/DataModels/IId.cs new file mode 100644 index 0000000..dd022c4 --- /dev/null +++ b/WinForm/DataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/WinForm/DataModels/Models/IProviderModel.cs b/WinForm/DataModels/Models/IProviderModel.cs new file mode 100644 index 0000000..b72e056 --- /dev/null +++ b/WinForm/DataModels/Models/IProviderModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataModels.Models +{ + public interface IProviderModel : IId + { + string Name { get; set; } + string Type { get; set; } + string Furniture { get; set; } + DateTime? SupplyDate { get; set; } + } +} diff --git a/WinForm/DataModels/Models/ITypeModel.cs b/WinForm/DataModels/Models/ITypeModel.cs new file mode 100644 index 0000000..50193b0 --- /dev/null +++ b/WinForm/DataModels/Models/ITypeModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataModels.Models +{ + public interface ITypeModel : IId + { + string Name { get; } + } +} diff --git a/WinForm/WinForm.sln b/WinForm/WinForm.sln index 6efa8df..2932ba5 100644 --- a/WinForm/WinForm.sln +++ b/WinForm/WinForm.sln @@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm", "WinForm\WinForm. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{B617E65D-B482-4120-BC74-66B760D66FEF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +25,14 @@ Global {B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.Build.0 = Release|Any CPU + {D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Release|Any CPU.Build.0 = Release|Any CPU + {B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE