From 1683d1b350949eb8e3f7af08415a7adc30b64929 Mon Sep 17 00:00:00 2001 From: Safgerd Date: Sun, 12 Feb 2023 23:26:14 +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=BA=D0=BE=D0=BC=D0=BF=D0=BE?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D1=82=D0=B0,=20=D0=B8=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlant/AutomobilePlant.csproj | 11 ++ .../AutomobilePlant/Form1.Designer.cs | 39 ------ AutomobilePlant/AutomobilePlant/Form1.cs | 10 -- AutomobilePlant/AutomobilePlant/Form1.resx | 120 ------------------ .../AutomobilePlant/FormComponent.Designer.cs | 118 +++++++++++++++++ .../AutomobilePlant/FormComponent.cs | 94 ++++++++++++++ .../AutomobilePlant/FormComponent.resx | 60 +++++++++ .../Models/Order.cs | 1 + 8 files changed, 284 insertions(+), 169 deletions(-) delete mode 100644 AutomobilePlant/AutomobilePlant/Form1.Designer.cs delete mode 100644 AutomobilePlant/AutomobilePlant/Form1.cs delete mode 100644 AutomobilePlant/AutomobilePlant/Form1.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormComponent.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormComponent.resx diff --git a/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj b/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj index b57c89e..c11f656 100644 --- a/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj +++ b/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj @@ -8,4 +8,15 @@ enable + + + + + + + + + + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/Form1.Designer.cs b/AutomobilePlant/AutomobilePlant/Form1.Designer.cs deleted file mode 100644 index 18f1244..0000000 --- a/AutomobilePlant/AutomobilePlant/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AutomobilePlant -{ - 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/AutomobilePlant/AutomobilePlant/Form1.cs b/AutomobilePlant/AutomobilePlant/Form1.cs deleted file mode 100644 index 137e235..0000000 --- a/AutomobilePlant/AutomobilePlant/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AutomobilePlant -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/Form1.resx b/AutomobilePlant/AutomobilePlant/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/AutomobilePlant/AutomobilePlant/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/AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs b/AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs new file mode 100644 index 0000000..ebcaddf --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace AutomobilePlant +{ + 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(27, 19); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(80, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(27, 70); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(48, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(113, 16); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(257, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(113, 67); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(257, 27); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(176, 108); + 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(276, 108); + 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(400, 149); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormComponent"; + this.Text = "FormComponent"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormComponent.cs b/AutomobilePlant/AutomobilePlant/FormComponent.cs new file mode 100644 index 0000000..769ba77 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponent.cs @@ -0,0 +1,94 @@ +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; +using AutomobilePlantContracts.BusinessLogicContracts; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; + +namespace AutomobilePlant +{ + 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) + { + textBoxName.Text = view.ComponentName; + textBoxCost.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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.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/AutomobilePlant/AutomobilePlant/FormComponent.resx b/AutomobilePlant/AutomobilePlant/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/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/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs b/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs index 8468ea4..c39798a 100644 --- a/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs @@ -51,6 +51,7 @@ namespace AutomobilePlantListImplements.Models return; } Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new()