diff --git a/AircraftPlant/AircraftPlant/FormCreateOrder.Designer.cs b/AircraftPlant/AircraftPlant/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..3e1daf5 --- /dev/null +++ b/AircraftPlant/AircraftPlant/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace AircraftPlantView +{ + 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() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxPlane = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(21, 18); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(71, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Самолет:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(21, 52); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(21, 85); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(58, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxPlane + // + this.comboBoxPlane.FormattingEnabled = true; + this.comboBoxPlane.Location = new System.Drawing.Point(156, 15); + this.comboBoxPlane.Name = "comboBoxPlane"; + this.comboBoxPlane.Size = new System.Drawing.Size(297, 28); + this.comboBoxPlane.TabIndex = 3; + this.comboBoxPlane.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPlane_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(156, 49); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(297, 27); + this.textBoxCount.TabIndex = 4; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(156, 82); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(297, 27); + this.textBoxSum.TabIndex = 5; + this.textBoxSum.TextChanged += new System.EventHandler(this.TextBoxSum_TextChanged); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(249, 125); + 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(359, 125); + 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); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(480, 171); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPlane); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelName); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPlane; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlant/FormCreateOrder.cs b/AircraftPlant/AircraftPlant/FormCreateOrder.cs new file mode 100644 index 0000000..4a3d9c5 --- /dev/null +++ b/AircraftPlant/AircraftPlant/FormCreateOrder.cs @@ -0,0 +1,129 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.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 AircraftPlantView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPlaneLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPlaneLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка самолетов для заказа"); + // прописать логику + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxPlane.DisplayMember = "PlaneName"; + comboBoxPlane.ValueMember = "Id"; + comboBoxPlane.DataSource = list; + comboBoxPlane.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка самолетов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxPlane.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPlane.SelectedValue); + var product = _logicP.ReadElement(new PlaneSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void TextBoxSum_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxPlane_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPlane.SelectedValue == null) + { + MessageBox.Show("Выберите самолет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PlaneId = Convert.ToInt32(comboBoxPlane.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 ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AircraftPlant/AircraftPlant/FormCreateOrder.resx b/AircraftPlant/AircraftPlant/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlant/FormCreateOrder.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/AircraftPlant/AircraftPlant/Program.cs b/AircraftPlant/AircraftPlant/Program.cs index 54ac301..352d8e5 100644 --- a/AircraftPlant/AircraftPlant/Program.cs +++ b/AircraftPlant/AircraftPlant/Program.cs @@ -49,7 +49,7 @@ namespace AircraftPlant //services.AddTransient(); services.AddTransient(); services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file