diff --git a/Confectionery/ConfectioneryView/FormImplementer.Designer.cs b/Confectionery/ConfectioneryView/FormImplementer.Designer.cs new file mode 100644 index 0000000..38dab7a --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementer.Designer.cs @@ -0,0 +1,165 @@ +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(91, 87); + labelName.Name = "labelName"; + labelName.Size = new Size(56, 25); + labelName.TabIndex = 0; + labelName.Text = "ФИО:"; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(69, 147); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(78, 25); + labelPassword.TabIndex = 1; + labelPassword.Text = "Пароль:"; + // + // labelWorkExp + // + labelWorkExp.AutoSize = true; + labelWorkExp.Location = new Point(37, 213); + labelWorkExp.Name = "labelWorkExp"; + labelWorkExp.Size = new Size(122, 25); + labelWorkExp.TabIndex = 2; + labelWorkExp.Text = "Стаж работы:"; + // + // labelQualif + // + labelQualif.AutoSize = true; + labelQualif.Location = new Point(25, 282); + labelQualif.Name = "labelQualif"; + labelQualif.Size = new Size(134, 25); + labelQualif.TabIndex = 3; + labelQualif.Text = "Квалификация:"; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(196, 84); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(510, 31); + textBoxFIO.TabIndex = 4; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(196, 144); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(510, 31); + textBoxPassword.TabIndex = 5; + // + // numericUpDownWorkExperience + // + numericUpDownWorkExperience.Location = new Point(199, 215); + numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + numericUpDownWorkExperience.Size = new Size(189, 31); + numericUpDownWorkExperience.TabIndex = 6; + // + // numericUpDownQualification + // + numericUpDownQualification.Location = new Point(196, 287); + numericUpDownQualification.Name = "numericUpDownQualification"; + numericUpDownQualification.Size = new Size(192, 31); + numericUpDownQualification.TabIndex = 7; + // + // buttonSave + // + buttonSave.Location = new Point(460, 344); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(169, 61); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(691, 344); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(169, 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(929, 450); + 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 = "Исполнитель"; + ((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 diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 50617db..84c333b 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -37,7 +37,9 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -53,6 +55,7 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } } } \ No newline at end of file