diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 0d261a7..0d78b48 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -17,4 +17,10 @@ + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..e3eb734 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace BlacksmithWorkshop +{ + partial class FormCreateOrder + { + /// + /// 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(); + labelCount = new Label(); + labelSum = new Label(); + TextBoxCount = new TextBox(); + ComboBoxManufacture = new ComboBox(); + TextBoxSum = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(22, 17); + labelName.Name = "labelName"; + labelName.Size = new Size(56, 15); + labelName.TabIndex = 0; + labelName.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(22, 46); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(22, 75); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(48, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // TextBoxCount + // + TextBoxCount.Location = new Point(125, 43); + TextBoxCount.Name = "TextBoxCount"; + TextBoxCount.Size = new Size(214, 23); + TextBoxCount.TabIndex = 3; + TextBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // ComboBoxManufacture + // + ComboBoxManufacture.FormattingEnabled = true; + ComboBoxManufacture.Location = new Point(125, 14); + ComboBoxManufacture.Name = "ComboBoxManufacture"; + ComboBoxManufacture.Size = new Size(214, 23); + ComboBoxManufacture.TabIndex = 4; + ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged; + // + // TextBoxSum + // + TextBoxSum.Location = new Point(125, 72); + TextBoxSum.Name = "TextBoxSum"; + TextBoxSum.ReadOnly = true; + TextBoxSum.Size = new Size(214, 23); + TextBoxSum.TabIndex = 5; + TextBoxSum.TextChanged += TextBoxSum_TextChanged; + // + // buttonCancel + // + buttonCancel.Location = new Point(247, 104); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(77, 24); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += CancelButton_Click; + // + // buttonSave + // + buttonSave.Location = new Point(164, 104); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(77, 24); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(349, 139); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(TextBoxSum); + Controls.Add(ComboBoxManufacture); + Controls.Add(TextBoxCount); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelName); + Name = "FormCreateOrder"; + Text = "FormCreateOrder"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCount; + private Label labelSum; + private TextBox TextBoxCount; + private ComboBox ComboBoxManufacture; + private TextBox TextBoxSum; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs new file mode 100644 index 0000000..bbeb795 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -0,0 +1,135 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logicI; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IManufactureLogic + logicI, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + _logicO = logicO; + } + private void FormCreateOrder_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; + } + _logger.LogInformation("Мороженное загружено"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки мороженного"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + private void CalcSum() + { + if (ComboBoxManufacture.SelectedValue != null && + !string.IsNullOrEmpty(TextBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(ComboBoxManufacture.SelectedValue); + var Manufacture = _logicI.ReadElement(new ManufactureSearchModel + { + Id = id + }); + int count = Convert.ToInt32(TextBoxCount.Text); + TextBoxSum.Text = Math.Round(count * (Manufacture?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void TextBoxSum_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void SaveButton_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 = _logicO.CreateOrder(new OrderBindingModel + { + ManufactureId = Convert.ToInt32(ComboBoxManufacture.SelectedValue), + Count = Convert.ToInt32(TextBoxCount.Text), + Sum = Convert.ToDouble(TextBoxSum.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 CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.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