From 48647bef3e2957a1894daf24c964e1e64cff5ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D1=8F=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=84=D0=BE=D1=80=D0=BE=D0=B2=D0=B0?= Date: Wed, 1 Feb 2023 01:55:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B1=D0=BB=D0=B0=D0=BD=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AircraftPlant/AircraftPlant.sln | 2 +- ...tPlant.csproj => AircraftPlantView.csproj} | 8 ++ AircraftPlant/AircraftPlant/Form1.Designer.cs | 39 ------ AircraftPlant/AircraftPlant/Form1.cs | 10 -- AircraftPlant/AircraftPlant/Form1.resx | 120 ------------------ .../AircraftPlant/FormComponent.Designer.cs | 119 +++++++++++++++++ AircraftPlant/AircraftPlant/FormComponent.cs | 95 ++++++++++++++ .../AircraftPlant/FormComponent.resx | 60 +++++++++ AircraftPlant/AircraftPlant/Program.cs | 2 +- 9 files changed, 284 insertions(+), 171 deletions(-) rename AircraftPlant/AircraftPlant/{AircraftPlant.csproj => AircraftPlantView.csproj} (52%) delete mode 100644 AircraftPlant/AircraftPlant/Form1.Designer.cs delete mode 100644 AircraftPlant/AircraftPlant/Form1.cs delete mode 100644 AircraftPlant/AircraftPlant/Form1.resx create mode 100644 AircraftPlant/AircraftPlant/FormComponent.Designer.cs create mode 100644 AircraftPlant/AircraftPlant/FormComponent.cs create mode 100644 AircraftPlant/AircraftPlant/FormComponent.resx diff --git a/AircraftPlant/AircraftPlant.sln b/AircraftPlant/AircraftPlant.sln index 9d57269..94496dd 100644 --- a/AircraftPlant/AircraftPlant.sln +++ b/AircraftPlant/AircraftPlant.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftPlant", "AircraftPlant\AircraftPlant.csproj", "{E434A570-19A4-486C-AD38-3E2C07E6DB01}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftPlantView", "AircraftPlant\AircraftPlantView.csproj", "{E434A570-19A4-486C-AD38-3E2C07E6DB01}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantDataModels", "AircraftPlantDataModels\AircraftPlantDataModels.csproj", "{F35C01BC-BCB8-4870-8143-529291F7AD5D}" EndProject diff --git a/AircraftPlant/AircraftPlant/AircraftPlant.csproj b/AircraftPlant/AircraftPlant/AircraftPlantView.csproj similarity index 52% rename from AircraftPlant/AircraftPlant/AircraftPlant.csproj rename to AircraftPlant/AircraftPlant/AircraftPlantView.csproj index b57c89e..49ad9e8 100644 --- a/AircraftPlant/AircraftPlant/AircraftPlant.csproj +++ b/AircraftPlant/AircraftPlant/AircraftPlantView.csproj @@ -8,4 +8,12 @@ enable + + + + + + + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlant/Form1.Designer.cs b/AircraftPlant/AircraftPlant/Form1.Designer.cs deleted file mode 100644 index 12db62c..0000000 --- a/AircraftPlant/AircraftPlant/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AircraftPlant -{ - 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/AircraftPlant/AircraftPlant/Form1.cs b/AircraftPlant/AircraftPlant/Form1.cs deleted file mode 100644 index 0d75b4b..0000000 --- a/AircraftPlant/AircraftPlant/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AircraftPlant -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlant/Form1.resx b/AircraftPlant/AircraftPlant/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/AircraftPlant/AircraftPlant/Form1.resx +++ /dev/null @@ -1,120 +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 - - \ No newline at end of file diff --git a/AircraftPlant/AircraftPlant/FormComponent.Designer.cs b/AircraftPlant/AircraftPlant/FormComponent.Designer.cs new file mode 100644 index 0000000..2d830f6 --- /dev/null +++ b/AircraftPlant/AircraftPlant/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace AircraftPlantView +{ + partial class FormComponent + { + /// + /// 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.labelComponentName = new System.Windows.Forms.Label(); + this.labelComponentPrice = new System.Windows.Forms.Label(); + this.textBoxComponentName = new System.Windows.Forms.TextBox(); + this.textBoxComponentPrice = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponentName + // + this.labelComponentName.AutoSize = true; + this.labelComponentName.Location = new System.Drawing.Point(22, 22); + this.labelComponentName.Name = "labelComponentName"; + this.labelComponentName.Size = new System.Drawing.Size(80, 20); + this.labelComponentName.TabIndex = 0; + this.labelComponentName.Text = "Название:"; + // + // labelComponentPrice + // + this.labelComponentPrice.AutoSize = true; + this.labelComponentPrice.Location = new System.Drawing.Point(22, 55); + this.labelComponentPrice.Name = "labelComponentPrice"; + this.labelComponentPrice.Size = new System.Drawing.Size(48, 20); + this.labelComponentPrice.TabIndex = 1; + this.labelComponentPrice.Text = "Цена:"; + // + // textBoxComponentName + // + this.textBoxComponentName.Location = new System.Drawing.Point(121, 19); + this.textBoxComponentName.Name = "textBoxComponentName"; + this.textBoxComponentName.Size = new System.Drawing.Size(283, 27); + this.textBoxComponentName.TabIndex = 2; + // + // textBoxComponentPrice + // + this.textBoxComponentPrice.Location = new System.Drawing.Point(121, 52); + this.textBoxComponentPrice.Name = "textBoxComponentPrice"; + this.textBoxComponentPrice.Size = new System.Drawing.Size(144, 27); + this.textBoxComponentPrice.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(200, 95); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(310, 95); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(429, 145); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxComponentPrice); + this.Controls.Add(this.textBoxComponentName); + this.Controls.Add(this.labelComponentPrice); + this.Controls.Add(this.labelComponentName); + this.Name = "FormComponent"; + this.Text = "Комплектующий"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponentName; + private Label labelComponentPrice; + private TextBox textBoxComponentName; + private TextBox textBoxComponentPrice; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlant/FormComponent.cs b/AircraftPlant/AircraftPlant/FormComponent.cs new file mode 100644 index 0000000..c68c123 --- /dev/null +++ b/AircraftPlant/AircraftPlant/FormComponent.cs @@ -0,0 +1,95 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.SearchModels; +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 AircraftPlantView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение комплектующего"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxComponentName.Text = view.ComponentName; + textBoxComponentPrice.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения комплектующего"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxComponentName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение комплектующего"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxComponentName.Text, + Cost = Convert.ToDouble(textBoxComponentPrice.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения комплектующего"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AircraftPlant/AircraftPlant/FormComponent.resx b/AircraftPlant/AircraftPlant/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlant/FormComponent.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/AircraftPlant/AircraftPlant/Program.cs b/AircraftPlant/AircraftPlant/Program.cs index 16d7633..e19a14c 100644 --- a/AircraftPlant/AircraftPlant/Program.cs +++ b/AircraftPlant/AircraftPlant/Program.cs @@ -11,7 +11,7 @@ namespace AircraftPlant // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormCompone()); } } } \ No newline at end of file