From 48e9f2ec28b3bc0acd9b903f158cc0b8f2b04dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Tue, 22 Oct 2024 19:58:21 +0400 Subject: [PATCH] T.T --- .../BindingModels/ProviderBindingModel.cs | 2 +- .../SearchModels/ProviderSearchModel.cs | 1 + .../Contracts/ViewModels/ProviderViewModel.cs | 2 +- .../Implements/OrganisationTypeStorage.cs | 76 ++++++++ .../Implements/ProviderStorage.cs | 4 +- .../20241022152445_InitMigration.Designer.cs | 74 ++++++++ .../20241022152445_InitMigration.cs | 53 ++++++ .../Migrations/DatabaseModelSnapshot.cs | 71 ++++++++ .../DatabaseImplement/Models/Provider.cs | 2 +- ComponentProgramming/Forms/Forms.csproj | 7 +- .../Forms/MainForm.Designer.cs | 54 +++++- ComponentProgramming/Forms/MainForm.cs | 61 ++++++- ComponentProgramming/Forms/MainForm.resx | 3 + .../Forms/OrganisationTypeForm.Designer.cs | 74 ++++++++ .../Forms/OrganisationTypeForm.cs | 93 ++++++++++ .../Forms/OrganisationTypeForm.resx | 123 +++++++++++++ ComponentProgramming/Forms/Program.cs | 43 +++++ .../Forms/ProviderForm.Designer.cs | 170 ++++++++++++++++++ ComponentProgramming/Forms/ProviderForm.cs | 97 ++++++++++ ComponentProgramming/Forms/ProviderForm.resx | 120 +++++++++++++ .../Models/Models/IProviderModel.cs | 2 +- 21 files changed, 1122 insertions(+), 10 deletions(-) create mode 100644 ComponentProgramming/DatabaseImplement/Implements/OrganisationTypeStorage.cs create mode 100644 ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.Designer.cs create mode 100644 ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.cs create mode 100644 ComponentProgramming/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs create mode 100644 ComponentProgramming/Forms/OrganisationTypeForm.Designer.cs create mode 100644 ComponentProgramming/Forms/OrganisationTypeForm.cs create mode 100644 ComponentProgramming/Forms/OrganisationTypeForm.resx create mode 100644 ComponentProgramming/Forms/Program.cs create mode 100644 ComponentProgramming/Forms/ProviderForm.Designer.cs create mode 100644 ComponentProgramming/Forms/ProviderForm.cs create mode 100644 ComponentProgramming/Forms/ProviderForm.resx diff --git a/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs b/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs index fe743cd..7a4c8f2 100644 --- a/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs +++ b/ComponentProgramming/Contracts/BindingModels/ProviderBindingModel.cs @@ -17,6 +17,6 @@ namespace Contracts.BindingModels public string OrganisationType { get; set; } = string.Empty; - public DateTime? DateLastDelivery { get; set; } + public string? DateLastDelivery { get; set; } } } diff --git a/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs b/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs index 705a3fd..e78339f 100644 --- a/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs +++ b/ComponentProgramming/Contracts/SearchModels/ProviderSearchModel.cs @@ -8,6 +8,7 @@ namespace Contracts.SearchModels { public class ProviderSearchModel { + public int? Id { get; set; } public string? Name { get; set; } public string? OrganisationType { get; set; } diff --git a/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs b/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs index 344121c..abcb09a 100644 --- a/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs +++ b/ComponentProgramming/Contracts/ViewModels/ProviderViewModel.cs @@ -22,7 +22,7 @@ namespace Contracts.ViewModels public string OrganisationType { get; set; } = string.Empty; [DisplayName("Дата последней доставки")] - public DateTime? DateLastDelivery { get; set; } + public string? DateLastDelivery { get; set; } } } diff --git a/ComponentProgramming/DatabaseImplement/Implements/OrganisationTypeStorage.cs b/ComponentProgramming/DatabaseImplement/Implements/OrganisationTypeStorage.cs new file mode 100644 index 0000000..789994f --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Implements/OrganisationTypeStorage.cs @@ -0,0 +1,76 @@ +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 OrganisationTypeStorage : IOrganisationTypeStorage + { + public List GetFullList() + { + using var context = new Database(); + return context.OrganisationTypes.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(OrganisationTypeSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + using var context = new Database(); + return context.OrganisationTypes.Where(x => x.Name == model.Name).Select(x=> x.GetViewModel).ToList(); + } + + public OrganisationTypeViewModel? GetElement(OrganisationTypeSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return null; + } + using var context = new Database(); + return context.OrganisationTypes.FirstOrDefault(x => x.Name == model.Name)?.GetViewModel; + } + + + public OrganisationTypeViewModel? Insert(OrganisationTypeBindingModel model) + { + var newType = OrganisationType.Create(model); + if(newType == null) return null; + using var context = new Database(); + context.OrganisationTypes.Add(newType); + context.SaveChanges(); + return newType.GetViewModel; + } + + public OrganisationTypeViewModel? Update(OrganisationTypeBindingModel model) + { + using var context = new Database(); + var type = context.OrganisationTypes.FirstOrDefault(x => x.Id == model.Id); + if(type == null) return null; + type.Update(model); + context.SaveChanges(); + return type.GetViewModel; + } + + public OrganisationTypeViewModel? Delete(OrganisationTypeBindingModel model) + { + using var context = new Database(); + var element = context.OrganisationTypes.FirstOrDefault(x => x.Name == model.Name); + if(element != null) + { + context.OrganisationTypes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs b/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs index 9a5246a..3cb4dc7 100644 --- a/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs +++ b/ComponentProgramming/DatabaseImplement/Implements/ProviderStorage.cs @@ -31,12 +31,12 @@ namespace DatabaseImplement.Implements public ProviderViewModel? GetElement(ProviderSearchModel model) { - if(string.IsNullOrEmpty(model.Name)) + if(!model.Id.HasValue) { return null; } using var context = new Database(); - return context.Providers.FirstOrDefault(x => x.Name == model.Name)?.GetViewModel; + return context.Providers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public ProviderViewModel? Insert(ProviderBindingModel model) diff --git a/ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.Designer.cs b/ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.Designer.cs new file mode 100644 index 0000000..a66fb2b --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.Designer.cs @@ -0,0 +1,74 @@ +// +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20241022152445_InitMigration")] + partial class InitMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.Models.OrganisationType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OrganisationTypes"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Provider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateLastDelivery") + .HasColumnType("nvarchar(max)"); + + b.Property("FurnitureType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OrganisationType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Providers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.cs b/ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.cs new file mode 100644 index 0000000..47cc7f3 --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Migrations/20241022152445_InitMigration.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class InitMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "OrganisationTypes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrganisationTypes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Providers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + FurnitureType = table.Column(type: "nvarchar(max)", nullable: false), + OrganisationType = table.Column(type: "nvarchar(max)", nullable: false), + DateLastDelivery = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Providers", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "OrganisationTypes"); + + migrationBuilder.DropTable( + name: "Providers"); + } + } +} diff --git a/ComponentProgramming/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs b/ComponentProgramming/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs new file mode 100644 index 0000000..5398d39 --- /dev/null +++ b/ComponentProgramming/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -0,0 +1,71 @@ +// +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(Database))] + partial class DatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.Models.OrganisationType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OrganisationTypes"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Provider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateLastDelivery") + .HasColumnType("nvarchar(max)"); + + b.Property("FurnitureType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OrganisationType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Providers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComponentProgramming/DatabaseImplement/Models/Provider.cs b/ComponentProgramming/DatabaseImplement/Models/Provider.cs index 3d04711..f375d30 100644 --- a/ComponentProgramming/DatabaseImplement/Models/Provider.cs +++ b/ComponentProgramming/DatabaseImplement/Models/Provider.cs @@ -23,7 +23,7 @@ namespace DatabaseImplement.Models [Required] public string OrganisationType { get; private set; } = string.Empty; - public DateTime? DateLastDelivery { get; private set; } + public string? DateLastDelivery { get; private set; } public static Provider? Create(ProviderBindingModel model) { diff --git a/ComponentProgramming/Forms/Forms.csproj b/ComponentProgramming/Forms/Forms.csproj index 8a9f1ad..08761a0 100644 --- a/ComponentProgramming/Forms/Forms.csproj +++ b/ComponentProgramming/Forms/Forms.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows + net8.0-windows7.0 enable true enable @@ -11,11 +11,16 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + \ No newline at end of file diff --git a/ComponentProgramming/Forms/MainForm.Designer.cs b/ComponentProgramming/Forms/MainForm.Designer.cs index 5249cac..d870a29 100644 --- a/ComponentProgramming/Forms/MainForm.Designer.cs +++ b/ComponentProgramming/Forms/MainForm.Designer.cs @@ -28,18 +28,68 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); + controlDataTreeTable = new ControlsLibraryNet60.Data.ControlDataTreeTable(); + contextMenuStrip1 = new ContextMenuStrip(components); + organisationTypesToolStripMenuItem = new ToolStripMenuItem(); + addProviderToolStripMenuItem = new ToolStripMenuItem(); + editProviderToolStripMenuItem = new ToolStripMenuItem(); + contextMenuStrip1.SuspendLayout(); SuspendLayout(); // + // controlDataTreeTable + // + controlDataTreeTable.ContextMenuStrip = contextMenuStrip1; + controlDataTreeTable.Location = new Point(13, 12); + controlDataTreeTable.Margin = new Padding(4, 3, 4, 3); + controlDataTreeTable.Name = "controlDataTreeTable"; + controlDataTreeTable.Size = new Size(337, 382); + controlDataTreeTable.TabIndex = 1; + // + // contextMenuStrip1 + // + contextMenuStrip1.Items.AddRange(new ToolStripItem[] { organisationTypesToolStripMenuItem, addProviderToolStripMenuItem, editProviderToolStripMenuItem }); + contextMenuStrip1.Name = "contextMenuStrip1"; + contextMenuStrip1.Size = new Size(181, 92); + // + // organisationTypesToolStripMenuItem + // + organisationTypesToolStripMenuItem.Name = "organisationTypesToolStripMenuItem"; + organisationTypesToolStripMenuItem.Size = new Size(180, 22); + organisationTypesToolStripMenuItem.Text = "Organisation types"; + organisationTypesToolStripMenuItem.Click += organisationTypesToolStripMenuItem_Click; + // + // addProviderToolStripMenuItem + // + addProviderToolStripMenuItem.Name = "addProviderToolStripMenuItem"; + addProviderToolStripMenuItem.Size = new Size(180, 22); + addProviderToolStripMenuItem.Text = "Add provider"; + addProviderToolStripMenuItem.Click += addProviderToolStripMenuItem_Click; + // + // editProviderToolStripMenuItem + // + editProviderToolStripMenuItem.Name = "editProviderToolStripMenuItem"; + editProviderToolStripMenuItem.Size = new Size(180, 22); + editProviderToolStripMenuItem.Text = "Edit provider"; + editProviderToolStripMenuItem.Click += editProviderToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(358, 403); + Controls.Add(controlDataTreeTable); Name = "MainForm"; - Text = "Основная форма"; + Text = "Main Form"; + contextMenuStrip1.ResumeLayout(false); ResumeLayout(false); } #endregion + private ControlsLibraryNet60.Data.ControlDataTreeTable controlDataTreeTable; + private ContextMenuStrip contextMenuStrip1; + private ToolStripMenuItem organisationTypesToolStripMenuItem; + private ToolStripMenuItem addProviderToolStripMenuItem; + private ToolStripMenuItem editProviderToolStripMenuItem; } } \ No newline at end of file diff --git a/ComponentProgramming/Forms/MainForm.cs b/ComponentProgramming/Forms/MainForm.cs index 9b3c80d..ce05d39 100644 --- a/ComponentProgramming/Forms/MainForm.cs +++ b/ComponentProgramming/Forms/MainForm.cs @@ -7,14 +7,73 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ComponentsLibraryNet60; +using Contracts.BusinessLogicsContracts; +using Contracts.ViewModels; +using ControlsLibraryNet60.Data; +using ControlsLibraryNet60.Models; namespace Forms { public partial class MainForm : Form { - public MainForm() + + private readonly IProviderLogic _logic; + + public MainForm(IProviderLogic logic) { InitializeComponent(); + _logic = logic; + LoadData(); + } + + private void LoadData() + { + var list = _logic.ReadList(null); + if (list != null) + { + DataTreeNodeConfig treeConfig = new(); + treeConfig.NodeNames = new(); + treeConfig.NodeNames.Enqueue("OrganisationType"); + treeConfig.NodeNames.Enqueue("DateLastDelivery"); + treeConfig.NodeNames.Enqueue("Id"); + treeConfig.NodeNames.Enqueue("Name"); + + controlDataTreeTable.LoadConfig(treeConfig); + controlDataTreeTable.AddTable(list); + } + } + private void organisationTypesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(OrganisationTypeForm)); + if (service is OrganisationTypeForm form) + { + form.ShowDialog(); + } + } + + private void addProviderToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ProviderForm)); + if (service is ProviderForm form) + { + form.ShowDialog(); + } + LoadData(); + } + + private void editProviderToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ProviderForm)); + if(service is ProviderForm form) + { + int id = Convert.ToInt32(controlDataTreeTable.GetSelectedObject()?.Id); + form.Id = id; + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } } } } diff --git a/ComponentProgramming/Forms/MainForm.resx b/ComponentProgramming/Forms/MainForm.resx index af32865..8f17a46 100644 --- a/ComponentProgramming/Forms/MainForm.resx +++ b/ComponentProgramming/Forms/MainForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 132, 17 + \ No newline at end of file diff --git a/ComponentProgramming/Forms/OrganisationTypeForm.Designer.cs b/ComponentProgramming/Forms/OrganisationTypeForm.Designer.cs new file mode 100644 index 0000000..d84bcf4 --- /dev/null +++ b/ComponentProgramming/Forms/OrganisationTypeForm.Designer.cs @@ -0,0 +1,74 @@ +namespace Forms +{ + partial class OrganisationTypeForm + { + /// + /// 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() + { + dataGridView = new DataGridView(); + Type = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Type }); + dataGridView.GridColor = Color.Gray; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.Size = new Size(181, 286); + dataGridView.TabIndex = 0; + dataGridView.CellValueChanged += dataGridView_CellValueChanged; + dataGridView.KeyDown += dataGridView_KeyDown; + // + // Type + // + Type.HeaderText = "Тип организации"; + Type.Name = "Type"; + // + // OrganisationTypeForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(205, 308); + Controls.Add(dataGridView); + Name = "OrganisationTypeForm"; + Text = "Справочник"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Type; + } +} \ No newline at end of file diff --git a/ComponentProgramming/Forms/OrganisationTypeForm.cs b/ComponentProgramming/Forms/OrganisationTypeForm.cs new file mode 100644 index 0000000..bdcfcb9 --- /dev/null +++ b/ComponentProgramming/Forms/OrganisationTypeForm.cs @@ -0,0 +1,93 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogicsContracts; +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 OrganisationTypeForm : Form + { + + private readonly IOrganisationTypeLogic _logic; + + public OrganisationTypeForm(IOrganisationTypeLogic logic) + { + InitializeComponent(); + _logic = logic; + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + foreach (var item in list) + { + dataGridView.Rows.Add(item.Name); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void dataGridView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Insert) + { + for(int i = 0;i 0) { + var name = dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); + if (string.IsNullOrEmpty(name)) + { + MessageBox.Show("Введите название!"); + return; + } + _logic.Create(new OrganisationTypeBindingModel + { + Name = name, + }); + } + } + + } +} diff --git a/ComponentProgramming/Forms/OrganisationTypeForm.resx b/ComponentProgramming/Forms/OrganisationTypeForm.resx new file mode 100644 index 0000000..6ad535d --- /dev/null +++ b/ComponentProgramming/Forms/OrganisationTypeForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + \ No newline at end of file diff --git a/ComponentProgramming/Forms/Program.cs b/ComponentProgramming/Forms/Program.cs new file mode 100644 index 0000000..71eba37 --- /dev/null +++ b/ComponentProgramming/Forms/Program.cs @@ -0,0 +1,43 @@ +using BusinessLogics.BusinessLogics; +using Contracts.BusinessLogicsContracts; +using Contracts.StorageContracts; +using DatabaseImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + + +namespace Forms +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + + /// + /// 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(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + + private static void ConfigureServices(ServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/ComponentProgramming/Forms/ProviderForm.Designer.cs b/ComponentProgramming/Forms/ProviderForm.Designer.cs new file mode 100644 index 0000000..c1c495b --- /dev/null +++ b/ComponentProgramming/Forms/ProviderForm.Designer.cs @@ -0,0 +1,170 @@ +namespace Forms +{ + partial class ProviderForm + { + /// + /// 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() + { + controlInputNullableDate = new ControlsLibraryNet60.Input.ControlInputNullableDate(); + controlSelectedComboBoxList = new ControlsLibraryNet60.Selected.ControlSelectedComboBoxList(); + textBoxName = new TextBox(); + label1 = new Label(); + textBoxFurnitureType = new TextBox(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // controlInputNullableDate + // + controlInputNullableDate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + controlInputNullableDate.Location = new Point(12, 164); + controlInputNullableDate.Margin = new Padding(4, 3, 4, 3); + controlInputNullableDate.Name = "controlInputNullableDate"; + controlInputNullableDate.Size = new Size(254, 23); + controlInputNullableDate.TabIndex = 0; + controlInputNullableDate.Value = null; + // + // controlSelectedComboBoxList + // + controlSelectedComboBoxList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + controlSelectedComboBoxList.Location = new Point(12, 119); + controlSelectedComboBoxList.Margin = new Padding(5, 3, 5, 3); + controlSelectedComboBoxList.Name = "controlSelectedComboBoxList"; + controlSelectedComboBoxList.SelectedElement = ""; + controlSelectedComboBoxList.Size = new Size(254, 24); + controlSelectedComboBoxList.TabIndex = 1; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + textBoxName.Location = new Point(12, 27); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(254, 23); + textBoxName.TabIndex = 2; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(42, 15); + label1.TabIndex = 3; + label1.Text = "Name:"; + // + // textBoxFurnitureType + // + textBoxFurnitureType.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + textBoxFurnitureType.Location = new Point(12, 73); + textBoxFurnitureType.Name = "textBoxFurnitureType"; + textBoxFurnitureType.Size = new Size(254, 23); + textBoxFurnitureType.TabIndex = 4; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 55); + label2.Name = "label2"; + label2.Size = new Size(84, 15); + label2.TabIndex = 5; + label2.Text = "Furniture type:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 101); + label3.Name = "label3"; + label3.Size = new Size(104, 15); + label3.TabIndex = 6; + label3.Text = "Organisation type:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(12, 146); + label4.Name = "label4"; + label4.Size = new Size(75, 15); + label4.TabIndex = 7; + label4.Text = "Last delivery:"; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; + buttonAdd.Location = new Point(12, 193); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 36); + buttonAdd.TabIndex = 8; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; + buttonCancel.Location = new Point(173, 193); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 36); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + // + // ProviderForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(279, 241); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(textBoxFurnitureType); + Controls.Add(label1); + Controls.Add(textBoxName); + Controls.Add(controlSelectedComboBoxList); + Controls.Add(controlInputNullableDate); + Name = "ProviderForm"; + Text = "Create Provider"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ControlsLibraryNet60.Input.ControlInputNullableDate controlInputNullableDate; + private ControlsLibraryNet60.Selected.ControlSelectedComboBoxList controlSelectedComboBoxList; + private TextBox textBoxName; + private Label label1; + private TextBox textBoxFurnitureType; + private Label label2; + private Label label3; + private Label label4; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComponentProgramming/Forms/ProviderForm.cs b/ComponentProgramming/Forms/ProviderForm.cs new file mode 100644 index 0000000..a4fb960 --- /dev/null +++ b/ComponentProgramming/Forms/ProviderForm.cs @@ -0,0 +1,97 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogicsContracts; +using Contracts.SearchModels; +using DocumentFormat.OpenXml.Spreadsheet; +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 ProviderForm : Form + { + private int? _id; + public int Id { set { _id = value; } } + private readonly IProviderLogic _pLogic; + private readonly IOrganisationTypeLogic _oLogic; + private bool isEdited; + + public ProviderForm(IProviderLogic plogic, IOrganisationTypeLogic ologic) + { + InitializeComponent(); + _pLogic = plogic; + _oLogic = ologic; + isEdited = false; + LoadData(); + } + + private void LoadData() + { + var list = _oLogic.ReadList(null); + if (list != null) + { + List strList = new List(); + foreach (var item in list) + { + strList.Add(item.Name); + } + controlSelectedComboBoxList.AddList(strList); + } + if (_id.HasValue) + { + var view = _pLogic.ReadElement(new ProviderSearchModel + { + Id = _id.Value, + }); + controlSelectedComboBoxList.SelectedElement = view!.OrganisationType; + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + if(string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните поле Название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFurnitureType.Text)) + { + MessageBox.Show("Заполните Перечень мебели ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if(string.IsNullOrEmpty(controlSelectedComboBoxList.SelectedElement)) + { + MessageBox.Show("Выберите Тип организации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var s = controlInputNullableDate.Value.ToString(); + try + { + var OperationResult = _pLogic.Create(new ProviderBindingModel + { + Name = textBoxName.Text, + FurnitureType = textBoxFurnitureType.Text, + DateLastDelivery = controlInputNullableDate.Value.ToString() == "" ? "No date" : controlInputNullableDate.Value.ToString(), + OrganisationType = controlSelectedComboBoxList.SelectedElement + }); + if (!OperationResult) + { + throw new Exception("Ошибка при создании поставщика."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ComponentProgramming/Forms/ProviderForm.resx b/ComponentProgramming/Forms/ProviderForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ComponentProgramming/Forms/ProviderForm.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/ComponentProgramming/Models/Models/IProviderModel.cs b/ComponentProgramming/Models/Models/IProviderModel.cs index 77074e0..f370bd7 100644 --- a/ComponentProgramming/Models/Models/IProviderModel.cs +++ b/ComponentProgramming/Models/Models/IProviderModel.cs @@ -15,6 +15,6 @@ namespace Models.Models string OrganisationType { get; } - DateTime? DateLastDelivery { get; } + string? DateLastDelivery { get; } } }