From cfb7d9086c72535e5cb120027e7cbf0257163ec7 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 20:14:00 +0400 Subject: [PATCH] FormComponent --- JewelryStore/Form1.Designer.cs | 39 -------- JewelryStore/Form1.cs | 10 --- JewelryStore/Form1.resx | 120 ------------------------- JewelryStore/FormComponent.Designer.cs | 119 ++++++++++++++++++++++++ JewelryStore/FormComponent.cs | 92 +++++++++++++++++++ JewelryStore/FormComponent.resx | 60 +++++++++++++ JewelryStore/JewelryStore.csproj | 8 ++ JewelryStore/Program.cs | 1 - 8 files changed, 279 insertions(+), 170 deletions(-) delete mode 100644 JewelryStore/Form1.Designer.cs delete mode 100644 JewelryStore/Form1.cs delete mode 100644 JewelryStore/Form1.resx create mode 100644 JewelryStore/FormComponent.Designer.cs create mode 100644 JewelryStore/FormComponent.cs create mode 100644 JewelryStore/FormComponent.resx diff --git a/JewelryStore/Form1.Designer.cs b/JewelryStore/Form1.Designer.cs deleted file mode 100644 index d1c38a9..0000000 --- a/JewelryStore/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace JewelryStore -{ - 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/JewelryStore/Form1.cs b/JewelryStore/Form1.cs deleted file mode 100644 index f3212bd..0000000 --- a/JewelryStore/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace JewelryStore -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/JewelryStore/Form1.resx b/JewelryStore/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/JewelryStore/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/JewelryStore/FormComponent.Designer.cs b/JewelryStore/FormComponent.Designer.cs new file mode 100644 index 0000000..759487b --- /dev/null +++ b/JewelryStore/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace JewelryStore +{ + 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(554, 353); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(676, 353); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(90, 113); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(90, 160); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(57, 25); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(212, 113); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(150, 31); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(212, 160); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(150, 31); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/JewelryStore/FormComponent.cs b/JewelryStore/FormComponent.cs new file mode 100644 index 0000000..7495460 --- /dev/null +++ b/JewelryStore/FormComponent.cs @@ -0,0 +1,92 @@ +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; + + +namespace JewelryStore +{ + 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(); + } + + + } + +} \ No newline at end of file diff --git a/JewelryStore/FormComponent.resx b/JewelryStore/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/JewelryStore/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/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index b57c89e..74fe05f 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -8,4 +8,12 @@ enable + + + + + + + + \ No newline at end of file diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index c4650cd..666baa8 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -11,7 +11,6 @@ namespace JewelryStore // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); } } } \ No newline at end of file