diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs index 1c71dfa..c888b1b 100644 --- a/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs @@ -140,6 +140,7 @@ buttonSave.TabIndex = 7; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; // // buttonCancel // @@ -150,6 +151,7 @@ buttonCancel.TabIndex = 8; buttonCancel.Text = "Закрыть"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // FormShop // @@ -167,6 +169,7 @@ Controls.Add(labelName); Name = "FormShop"; Text = "Магазин"; + Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs index 9a26ee8..202b48c 100644 --- a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs @@ -28,12 +28,119 @@ /// 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 = "FormShopSupply"; + comboBoxShop = new ComboBox(); + comboBoxSecure = new ComboBox(); + labelShop = new Label(); + label2 = new Label(); + label3 = new Label(); + buttonSupply = new Button(); + buttonCancel = new Button(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(125, 6); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(432, 28); + comboBoxShop.TabIndex = 0; + // + // comboBoxSecure + // + comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSecure.FormattingEnabled = true; + comboBoxSecure.Location = new Point(125, 47); + comboBoxSecure.Name = "comboBoxSecure"; + comboBoxSecure.Size = new Size(432, 28); + comboBoxSecure.TabIndex = 1; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 9); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 3; + labelShop.Text = "Магазин:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 50); + label2.Name = "label2"; + label2.Size = new Size(71, 20); + label2.TabIndex = 4; + label2.Text = "Изделие:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 89); + label3.Name = "label3"; + label3.Size = new Size(93, 20); + label3.TabIndex = 5; + label3.Text = "Количество:"; + // + // buttonSupply + // + buttonSupply.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSupply.Location = new Point(342, 130); + buttonSupply.Name = "buttonSupply"; + buttonSupply.Size = new Size(94, 29); + buttonSupply.TabIndex = 6; + buttonSupply.Text = "Поставить"; + buttonSupply.UseVisualStyleBackColor = true; + buttonSupply.Click += buttonSupply_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(463, 130); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(125, 89); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(167, 27); + textBoxCount.TabIndex = 8; + // + // FormShopSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(569, 169); + Controls.Add(textBoxCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSupply); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(labelShop); + Controls.Add(comboBoxSecure); + Controls.Add(comboBoxShop); + Name = "FormShopSupply"; + Text = "Поставка изделия"; + Load += FormShopSupply_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxSecure; + private Label labelShop; + private Label label2; + private Label label3; + private Button buttonSupply; + private Button buttonCancel; + private TextBox textBoxCount; } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs index 463d314..ff14ef8 100644 --- a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs @@ -1,20 +1,117 @@ -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; +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; namespace SecuritySystemView { public partial class FormShopSupply : Form { - public FormShopSupply() + private readonly ILogger _logger; + private readonly ISecureLogic _logicSecure; + private readonly IShopLogic _logicShop; + + public FormShopSupply(ILogger logger, ISecureLogic logicSecure, IShopLogic logicShop) { InitializeComponent(); + _logger = logger; + _logicSecure = logicSecure; + _logicShop = logicShop; + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка secure для пополнения"); + + try + { + var list = _logicSecure.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка secure"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка магазинов для пополнения"); + + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "Name"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSupply_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите secure", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание поставки"); + + try + { + var operationResult = _logicShop.SupplySecures( + new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text }, + new SecureBindingModel { Id = Convert.ToInt32(comboBoxSecure.SelectedValue), SecureName = comboBoxSecure.Text }, + Convert.ToInt32(textBoxCount.Text) + ); + + 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/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx index 1af7de1..a395bff 100644 --- a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx @@ -1,24 +1,24 @@  -