From b33e1094daaf18f8733e7711a3799ce683af1097 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 22 Apr 2024 11:35:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementer/FormImplementer.Designer.cs | 145 ++++++++++++++++++ .../Implementer/FormImplementer.cs | 114 ++++++++++++++ .../Implementer/FormImplementer.resx | 120 +++++++++++++++ 3 files changed, 379 insertions(+) create mode 100644 SecuritySystem/SecuritySystemView/Implementer/FormImplementer.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/Implementer/FormImplementer.cs create mode 100644 SecuritySystem/SecuritySystemView/Implementer/FormImplementer.resx diff --git a/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.Designer.cs b/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.Designer.cs new file mode 100644 index 0000000..e754381 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.Designer.cs @@ -0,0 +1,145 @@ +namespace SecuritySystemView.Implementer +{ + 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() + { + buttonCancel = new Button(); + buttonSave = new Button(); + labelFIO = new Label(); + labelWorkExp = new Label(); + labelQualification = new Label(); + textBoxFIO = new TextBox(); + textBoxWorkExp = new TextBox(); + textBoxQualification = new TextBox(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(438, 141); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(122, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(301, 141); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(115, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(12, 15); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(42, 20); + labelFIO.TabIndex = 6; + labelFIO.Text = "ФИО"; + // + // labelWorkExp + // + labelWorkExp.AutoSize = true; + labelWorkExp.Location = new Point(12, 57); + labelWorkExp.Name = "labelWorkExp"; + labelWorkExp.Size = new Size(105, 20); + labelWorkExp.TabIndex = 7; + labelWorkExp.Text = "Опыт работы:"; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(12, 97); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(114, 20); + labelQualification.TabIndex = 8; + labelQualification.Text = "Квалификация:"; + // + // textBoxFIO + // + textBoxFIO.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxFIO.Location = new Point(60, 12); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(500, 27); + textBoxFIO.TabIndex = 9; + // + // textBoxWorkExp + // + textBoxWorkExp.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxWorkExp.Location = new Point(157, 54); + textBoxWorkExp.Name = "textBoxWorkExp"; + textBoxWorkExp.Size = new Size(180, 27); + textBoxWorkExp.TabIndex = 10; + // + // textBoxQualification + // + textBoxQualification.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxQualification.Location = new Point(157, 94); + textBoxQualification.Name = "textBoxQualification"; + textBoxQualification.Size = new Size(180, 27); + textBoxQualification.TabIndex = 11; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(577, 182); + Controls.Add(textBoxQualification); + Controls.Add(textBoxWorkExp); + Controls.Add(textBoxFIO); + Controls.Add(labelQualification); + Controls.Add(labelWorkExp); + Controls.Add(labelFIO); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += Form_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label labelFIO; + private Label labelWorkExp; + private Label labelQualification; + private TextBox textBoxFIO; + private TextBox textBoxWorkExp; + private TextBox textBoxQualification; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.cs b/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.cs new file mode 100644 index 0000000..c6a781f --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using Microsoft.IdentityModel.Tokens; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; + +namespace SecuritySystemView.Implementer +{ + 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) + { + InitializeImplementer(); + _logger = logger; + _logic = logic; + } + private void Form_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; + textBoxQualification.Text = view.Qualification.ToString(); + textBoxWorkExp.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (!CheckFieldsIsValid()) + { + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExp.Text), + Qualification = Convert.ToInt32(textBoxQualification.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(); + } + + private bool CheckFieldsIsValid() + { + string errMsg = string.Empty; + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + errMsg = "Заполните ФИО"; + } + else if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + errMsg = "Заполните квалификацию"; + } + else if (!int.TryParse(textBoxQualification.Text, out _)) + { + errMsg = "В поле квалификации должны быть только цифры"; + } + else if (!int.TryParse(textBoxWorkExp.Text, out _)) + { + errMsg = "Заполните квалификацию"; + } + else if (string.IsNullOrEmpty(textBoxWorkExp.Text)) + { + errMsg = "В поле опыта работы должны быть только цифры"; + } + + if (!errMsg.IsNullOrEmpty()) + { + MessageBox.Show(errMsg, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + return true; + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.resx b/SecuritySystem/SecuritySystemView/Implementer/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Implementer/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