diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.Designer.cs new file mode 100644 index 0000000..469c233 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.Designer.cs @@ -0,0 +1,89 @@ +namespace BlacksmithWorkshopView +{ + partial class FormClients + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 1); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(529, 447); + this.dataGridView.TabIndex = 0; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(536, 12); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(153, 23); + this.buttonDel.TabIndex = 1; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(536, 41); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(153, 23); + this.buttonRef.TabIndex = 1; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_click); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(701, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Text = "FormClients"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs new file mode 100644 index 0000000..b81aff1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs @@ -0,0 +1,73 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление клиента"); + try + { + if (!_logic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 47781ff..5d40fe3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -42,6 +42,7 @@ this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); + this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -61,7 +62,8 @@ // this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.componentsToolStripMenuItem, - this.manufacturesToolStripMenuItem}); + this.manufacturesToolStripMenuItem, + this.clientsToolStripMenuItem}); this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem"; this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.refbooksToolStripMenuItem.Text = "Справочники"; @@ -69,14 +71,14 @@ // componentsToolStripMenuItem // this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentsToolStripMenuItem.Text = "Компоненты"; this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // // manufacturesToolStripMenuItem // this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem"; - this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.manufacturesToolStripMenuItem.Text = "Изделия"; this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click); // @@ -176,6 +178,13 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // + // clientsToolStripMenuItem + // + this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.clientsToolStripMenuItem.Text = "Клиенты"; + this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -216,5 +225,6 @@ private ToolStripMenuItem reportComponentsToolStripMenuItem; private ToolStripMenuItem reportManufactureComponentsToolStripMenuItem; private ToolStripMenuItem reportOrdersToolStripMenuItem; + private ToolStripMenuItem clientsToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index d7c5f4d..dfcff61 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -176,5 +176,14 @@ namespace BlacksmithWorkshopView LoadData(); } } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + LoadData(); + } + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index fbcb514..83c781a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -55,6 +55,7 @@ namespace BlacksmithWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs index f4db7bd..8d7d60c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -11,7 +11,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IClientStorage _clientStorage; - public ClientLogic(ILogger logger, IClientStorage clientStorage) + public ClientLogic(ILogger logger, IClientStorage clientStorage) { _logger= logger; _clientStorage = clientStorage; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327122648_Lab5Migration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327122648_Lab5Migration.Designer.cs deleted file mode 100644 index fd513be..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327122648_Lab5Migration.Designer.cs +++ /dev/null @@ -1,208 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatebaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDatabase))] - [Migration("20230327122648_Lab5Migration")] - partial class Lab5Migration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") - .WithMany("ManufactureComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Components") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", null) - .WithMany("Orders") - .HasForeignKey("ClientId"); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Navigation("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327122648_Lab5Migration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327122648_Lab5Migration.cs deleted file mode 100644 index 47efb82..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230327122648_Lab5Migration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatebaseImplement.Migrations -{ - /// - public partial class Lab5Migration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -}