From 0bcba6c95f2e6e6838a5cad2c371367de02ac663 Mon Sep 17 00:00:00 2001 From: malimova Date: Mon, 3 Jun 2024 22:03:45 +0400 Subject: [PATCH] =?UTF-8?q?+=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormImplementer.Designer.cs | 166 ++++++++++++++++++ .../ConfectioneryView/FormImplementer.cs | 103 +++++++++++ .../ConfectioneryView/FormImplementer.resx | 120 +++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 Confectionery/ConfectioneryView/FormImplementer.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormImplementer.cs create mode 100644 Confectionery/ConfectioneryView/FormImplementer.resx diff --git a/Confectionery/ConfectioneryView/FormImplementer.Designer.cs b/Confectionery/ConfectioneryView/FormImplementer.Designer.cs new file mode 100644 index 0000000..24e90b4 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementer.Designer.cs @@ -0,0 +1,166 @@ +namespace ConfectioneryView +{ + partial class FormImplementer + { + /// + /// 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() + { + labelName = new Label(); + labelPassword = new Label(); + labelWorkExp = new Label(); + labelQualif = new Label(); + textBoxFIO = new TextBox(); + textBoxPassword = new TextBox(); + numericUpDownWorkExperience = new NumericUpDown(); + numericUpDownQualification = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(114, 85); + labelName.Name = "labelName"; + labelName.Size = new Size(56, 25); + labelName.TabIndex = 0; + labelName.Text = "ФИО:"; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(99, 160); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(78, 25); + labelPassword.TabIndex = 1; + labelPassword.Text = "Пароль:"; + // + // labelWorkExp + // + labelWorkExp.AutoSize = true; + labelWorkExp.Location = new Point(55, 244); + labelWorkExp.Name = "labelWorkExp"; + labelWorkExp.Size = new Size(122, 25); + labelWorkExp.TabIndex = 2; + labelWorkExp.Text = "Стаж работы:"; + // + // labelQualif + // + labelQualif.AutoSize = true; + labelQualif.Location = new Point(36, 319); + labelQualif.Name = "labelQualif"; + labelQualif.Size = new Size(134, 25); + labelQualif.TabIndex = 3; + labelQualif.Text = "Квалификация:"; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(204, 82); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(544, 31); + textBoxFIO.TabIndex = 4; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(204, 154); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(544, 31); + textBoxPassword.TabIndex = 5; + // + // numericUpDownWorkExperience + // + numericUpDownWorkExperience.Location = new Point(204, 244); + numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + numericUpDownWorkExperience.Size = new Size(180, 31); + numericUpDownWorkExperience.TabIndex = 6; + // + // numericUpDownQualification + // + numericUpDownQualification.Location = new Point(204, 317); + numericUpDownQualification.Name = "numericUpDownQualification"; + numericUpDownQualification.Size = new Size(180, 31); + numericUpDownQualification.TabIndex = 7; + // + // buttonSave + // + buttonSave.Location = new Point(600, 397); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(160, 61); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(792, 397); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(160, 61); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1028, 495); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownQualification); + Controls.Add(numericUpDownWorkExperience); + Controls.Add(textBoxPassword); + Controls.Add(textBoxFIO); + Controls.Add(labelQualif); + Controls.Add(labelWorkExp); + Controls.Add(labelPassword); + Controls.Add(labelName); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPassword; + private Label labelWorkExp; + private Label labelQualif; + private TextBox textBoxFIO; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownWorkExperience; + private NumericUpDown numericUpDownQualification; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormImplementer.cs b/Confectionery/ConfectioneryView/FormImplementer.cs new file mode 100644 index 0000000..653e7e1 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementer.cs @@ -0,0 +1,103 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.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 ConfectioneryView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownWorkExperience.Value = view.WorkExperience; + numericUpDownQualification.Value = view.Qualification; + } + } + 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(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = (int)numericUpDownWorkExperience.Value, + Qualification = (int)numericUpDownQualification.Value + }; + 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/Confectionery/ConfectioneryView/FormImplementer.resx b/Confectionery/ConfectioneryView/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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