From d0e07767173e3307061330a747b72a85224f23c1 Mon Sep 17 00:00:00 2001 From: the Date: Sun, 23 Jun 2024 12:07:01 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D0=B5=20=D0=B2=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D1=8F=20=D0=BD=D0=B0=D1=87=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=82=D1=8C=20=D0=BA=D1=80=D1=83?= =?UTF-8?q?=D0=B4=20=D0=B4=D1=80=D1=83=D0=B7=D1=8C=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DatabaseImplement/Implements/SellStorage.cs | 2 +- DatabaseImplement/Models/Purchase.cs | 4 +- WinFormsApp/Form1.Designer.cs | 39 ---------- WinFormsApp/Form1.cs | 10 --- WinFormsApp/FormMain.Designer.cs | 84 +++++++++++++++++++++ WinFormsApp/FormMain.cs | 55 ++++++++++++++ WinFormsApp/{Form1.resx => FormMain.resx} | 53 +++++++------ WinFormsApp/Program.cs | 35 ++++++++- WinFormsApp/WinFormsApp.csproj | 15 ++++ 9 files changed, 220 insertions(+), 77 deletions(-) delete mode 100644 WinFormsApp/Form1.Designer.cs delete mode 100644 WinFormsApp/Form1.cs create mode 100644 WinFormsApp/FormMain.Designer.cs create mode 100644 WinFormsApp/FormMain.cs rename WinFormsApp/{Form1.resx => FormMain.resx} (91%) diff --git a/DatabaseImplement/Implements/SellStorage.cs b/DatabaseImplement/Implements/SellStorage.cs index aeac65f..6f72f11 100644 --- a/DatabaseImplement/Implements/SellStorage.cs +++ b/DatabaseImplement/Implements/SellStorage.cs @@ -13,7 +13,7 @@ namespace DatabaseImplement.Implements { public SellBindingModel? Delete(SellSearchModel model) { - + return new(); } public SellBindingModel? GetElement(SellSearchModel model) diff --git a/DatabaseImplement/Models/Purchase.cs b/DatabaseImplement/Models/Purchase.cs index 5430b34..e3c4a11 100644 --- a/DatabaseImplement/Models/Purchase.cs +++ b/DatabaseImplement/Models/Purchase.cs @@ -21,7 +21,9 @@ namespace DatabaseImplement.Models public PurchaseBindingModel GetBindingModel() => new() { Id = Id, - DatePurchase = DatePurchase + DatePurchase = DatePurchase, + User = null, + Products = new(), }; public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new() diff --git a/WinFormsApp/Form1.Designer.cs b/WinFormsApp/Form1.Designer.cs deleted file mode 100644 index 81df421..0000000 --- a/WinFormsApp/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace WinFormsApp -{ - 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 - } -} diff --git a/WinFormsApp/Form1.cs b/WinFormsApp/Form1.cs deleted file mode 100644 index c9f239e..0000000 --- a/WinFormsApp/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace WinFormsApp -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs new file mode 100644 index 0000000..4ed9f16 --- /dev/null +++ b/WinFormsApp/FormMain.Designer.cs @@ -0,0 +1,84 @@ +namespace WinFormsApp +{ + partial class FormMain + { + /// + /// 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(); + buttonCreateSupply = new Button(); + toolStrip1 = new ToolStrip(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 28); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(614, 321); + dataGridView.TabIndex = 0; + // + // buttonCreateSupply + // + buttonCreateSupply.Location = new Point(632, 28); + buttonCreateSupply.Name = "buttonCreateSupply"; + buttonCreateSupply.Size = new Size(154, 23); + buttonCreateSupply.TabIndex = 1; + buttonCreateSupply.Text = "Оформить поставку"; + buttonCreateSupply.UseVisualStyleBackColor = true; + // + // toolStrip1 + // + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(798, 25); + toolStrip1.TabIndex = 2; + toolStrip1.Text = "toolStrip1"; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(798, 361); + Controls.Add(toolStrip1); + Controls.Add(buttonCreateSupply); + Controls.Add(dataGridView); + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreateSupply; + private ToolStrip toolStrip1; + } +} \ No newline at end of file diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs new file mode 100644 index 0000000..9fe695e --- /dev/null +++ b/WinFormsApp/FormMain.cs @@ -0,0 +1,55 @@ +using Contracts.BusinessLogicContracts; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Logging; +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 WinFormsApp +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly ISupplyLogic _supplyLogic; + private readonly IProductLogic _productLogic; + private readonly ISupplierLogic _supplierLogic; + public FormMain(ILogger logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic) + { + InitializeComponent(); + _supplierLogic = supplierLogic; + _supplyLogic = supplyLogic; + _productLogic = productLogic; + _logger = logger; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка поставок"); + try + { + var list = _supplyLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + } + _logger.LogInformation("Загрузка поставок"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки поставок"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/WinFormsApp/Form1.resx b/WinFormsApp/FormMain.resx similarity index 91% rename from WinFormsApp/Form1.resx rename to WinFormsApp/FormMain.resx index 1af7de1..c354583 100644 --- a/WinFormsApp/Form1.resx +++ b/WinFormsApp/FormMain.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs index 7b63611..0519d54 100644 --- a/WinFormsApp/Program.cs +++ b/WinFormsApp/Program.cs @@ -1,7 +1,18 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using NLog.Extensions.Logging; +using Microsoft.Extensions.Logging; +using Contracts.StorageContracts; +using DatabaseImplement.Implements; +using Contracts.BusinessLogicContracts; +using BusinessLogic.BusinessLogic; + namespace WinFormsApp { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,29 @@ namespace WinFormsApp // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + //services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + //services.AddTransient<, ImplementerStorage>(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); } } } \ No newline at end of file diff --git a/WinFormsApp/WinFormsApp.csproj b/WinFormsApp/WinFormsApp.csproj index 663fdb8..4a12fd9 100644 --- a/WinFormsApp/WinFormsApp.csproj +++ b/WinFormsApp/WinFormsApp.csproj @@ -8,4 +8,19 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + \ No newline at end of file