diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs index 05b68d7..546bd48 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs @@ -28,12 +28,94 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.labelManufacture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxManufacture = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelManufacture + // + this.labelManufacture.AutoSize = true; + this.labelManufacture.Location = new System.Drawing.Point(32, 32); + this.labelManufacture.Name = "labelManufacture"; + this.labelManufacture.Size = new System.Drawing.Size(71, 20); + this.labelManufacture.TabIndex = 0; + this.labelManufacture.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(34, 85); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxManufacture + // + this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxManufacture.FormattingEnabled = true; + this.comboBoxManufacture.Location = new System.Drawing.Point(170, 32); + this.comboBoxManufacture.Name = "comboBoxManufacture"; + this.comboBoxManufacture.Size = new System.Drawing.Size(262, 28); + this.comboBoxManufacture.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(170, 85); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(262, 27); + this.textBoxCount.TabIndex = 4; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(239, 141); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(339, 141); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellManufacture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormSellManufacture"; + this.ClientSize = new System.Drawing.Size(440, 180); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxManufacture); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelManufacture); + this.Name = "FormSellManufacture"; + this.Text = "Продажа изделий"; + this.Load += new System.EventHandler(this.FormSellManufacture_Load); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private Label labelManufacture; + private Label labelCount; + private ComboBox comboBoxManufacture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs index baf2751..8c017a6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs @@ -1,4 +1,7 @@ -using System; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,86 @@ namespace BlacksmithWorkshop { public partial class FormSellManufacture : Form { - public FormSellManufacture() + private readonly ILogger _logger; + + private readonly IManufactureLogic _logicI; + + private readonly IShopLogic _logicS; + + public FormSellManufacture(ILogger logger, IManufactureLogic logicI, IShopLogic logicS) { InitializeComponent(); + + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormSellManufacture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для продажи"); + + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + comboBoxManufacture.DisplayMember = "ManufactureName"; + comboBoxManufacture.ValueMember = "Id"; + comboBoxManufacture.DataSource = list; + comboBoxManufacture.SelectedItem = null; + } + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxManufacture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Продажа изделия"); + + try + { + var operationResult = _logicS.SellManufatures(_logicI.ReadElement(new ManufactureSearchModel() + { + Id = Convert.ToInt32(comboBoxManufacture.SelectedValue) + })!, 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/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx index 1af7de1..f298a7b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx @@ -1,64 +1,4 @@ - - - +