diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 0290134..58552f6 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Confectionery", "Confection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{B1066AB3-A781-49D8-9629-DAEEB7AEB926}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{6FFC8BF0-172F-4A99-AF4E-8FCEC210FF36}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{6FFC8BF0-172F-4A99-AF4E-8FCEC210FF36}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{A8B0F9F7-FBAA-41C1-A211-DAA3685C9F4E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{A8B0F9F7-FBAA-41C1-A211-DAA3685C9F4E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{BE302C97-48E7-4982-8D16-309157B55944}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{BE302C97-48E7-4982-8D16-309157B55944}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{90E59686-3070-4B0F-BCBF-AAE0FEFE35FA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {BE302C97-48E7-4982-8D16-309157B55944}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE302C97-48E7-4982-8D16-309157B55944}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE302C97-48E7-4982-8D16-309157B55944}.Release|Any CPU.Build.0 = Release|Any CPU + {90E59686-3070-4B0F-BCBF-AAE0FEFE35FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90E59686-3070-4B0F-BCBF-AAE0FEFE35FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90E59686-3070-4B0F-BCBF-AAE0FEFE35FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90E59686-3070-4B0F-BCBF-AAE0FEFE35FA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj new file mode 100644 index 0000000..b51a6d5 --- /dev/null +++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj @@ -0,0 +1,16 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.Designer.cs b/Confectionery/ConfectioneryView/FormComponent.Designer.cs new file mode 100644 index 0000000..3f8bc03 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.Designer.cs @@ -0,0 +1,115 @@ +namespace ConfectioneryView +{ + 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() + { + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonCreate = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(90, 63); + label1.Name = "label1"; + label1.Size = new Size(94, 25); + label1.TabIndex = 0; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(127, 120); + label2.Name = "label2"; + label2.Size = new Size(57, 25); + label2.TabIndex = 1; + label2.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(190, 63); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(285, 31); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(190, 120); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(150, 31); + textBoxCost.TabIndex = 3; + // + // buttonCreate + // + buttonCreate.Location = new Point(501, 162); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(112, 58); + buttonCreate.TabIndex = 4; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + // + // buttonCancel + // + buttonCancel.Location = new Point(636, 162); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 58); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(803, 243); + Controls.Add(buttonCancel); + Controls.Add(buttonCreate); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonCreate; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.cs b/Confectionery/ConfectioneryView/FormComponent.cs new file mode 100644 index 0000000..abb3e79 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.cs @@ -0,0 +1,84 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + 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 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 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 ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.resx b/Confectionery/ConfectioneryView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs new file mode 100644 index 0000000..a590e70 --- /dev/null +++ b/Confectionery/ConfectioneryView/Program.cs @@ -0,0 +1,17 @@ +namespace ConfectioneryView +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormComponent()); + } + } +} \ No newline at end of file