Upload files to 'ShipyardView'

This commit is contained in:
Ivan_Starostin 2024-06-02 17:22:30 +04:00
parent b1ee7c922e
commit 1865aa693a
2 changed files with 304 additions and 259 deletions

View File

@ -1,143 +1,166 @@
namespace ShipyardView namespace ShipyardView
{ {
partial class FormCreateOrder partial class FormCreateOrder
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
textBoxCount = new TextBox(); textBoxCount = new TextBox();
textBoxSum = new TextBox(); textBoxSum = new TextBox();
ComboBoxManufacture = new ComboBox(); ComboBoxManufacture = new ComboBox();
ButtonCancel = new Button(); ButtonCancel = new Button();
ButtonSave = new Button(); ButtonSave = new Button();
labelItem = new Label(); labelItem = new Label();
labelcount = new Label(); labelcount = new Label();
labeltotal = new Label(); labeltotal = new Label();
SuspendLayout(); ComboBoxClient = new ComboBox();
// labelClient = new Label();
// textBoxCount SuspendLayout();
// //
textBoxCount.Location = new Point(455, 56); // textBoxCount
textBoxCount.Name = "textBoxCount"; //
textBoxCount.Size = new Size(125, 27); textBoxCount.Location = new Point(343, 62);
textBoxCount.TabIndex = 1; textBoxCount.Name = "textBoxCount";
textBoxCount.TextChanged += textBoxCount_TextChanged; textBoxCount.Size = new Size(125, 27);
// textBoxCount.TabIndex = 1;
// textBoxSum textBoxCount.TextChanged += textBoxCount_TextChanged;
// //
textBoxSum.Location = new Point(377, 109); // textBoxSum
textBoxSum.Name = "textBoxSum"; //
textBoxSum.ReadOnly = true; textBoxSum.Location = new Point(377, 109);
textBoxSum.Size = new Size(125, 27); textBoxSum.Name = "textBoxSum";
textBoxSum.TabIndex = 2; textBoxSum.ReadOnly = true;
// textBoxSum.Size = new Size(125, 27);
// ComboBoxManufacture textBoxSum.TabIndex = 2;
// //
ComboBoxManufacture.FormattingEnabled = true; // ComboBoxManufacture
ComboBoxManufacture.Location = new Point(271, 55); //
ComboBoxManufacture.Name = "ComboBoxManufacture"; ComboBoxManufacture.FormattingEnabled = true;
ComboBoxManufacture.Size = new Size(151, 28); ComboBoxManufacture.Location = new Point(129, 55);
ComboBoxManufacture.TabIndex = 3; ComboBoxManufacture.Name = "ComboBoxManufacture";
ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged; ComboBoxManufacture.Size = new Size(151, 28);
// ComboBoxManufacture.TabIndex = 3;
// ButtonCancel ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged;
// //
ButtonCancel.Location = new Point(440, 168); // ButtonCancel
ButtonCancel.Name = "ButtonCancel"; //
ButtonCancel.Size = new Size(94, 29); ButtonCancel.Location = new Point(440, 168);
ButtonCancel.TabIndex = 4; ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Text = "отмена"; ButtonCancel.Size = new Size(94, 29);
ButtonCancel.UseVisualStyleBackColor = true; ButtonCancel.TabIndex = 4;
ButtonCancel.Click += ButtonCancel_Click; ButtonCancel.Text = "отмена";
// ButtonCancel.UseVisualStyleBackColor = true;
// ButtonSave ButtonCancel.Click += ButtonCancel_Click;
// //
ButtonSave.Location = new Point(307, 168); // ButtonSave
ButtonSave.Name = "ButtonSave"; //
ButtonSave.Size = new Size(94, 29); ButtonSave.Location = new Point(307, 168);
ButtonSave.TabIndex = 5; ButtonSave.Name = "ButtonSave";
ButtonSave.Text = "сохранить"; ButtonSave.Size = new Size(94, 29);
ButtonSave.UseVisualStyleBackColor = true; ButtonSave.TabIndex = 5;
ButtonSave.Click += ButtonSave_Click; ButtonSave.Text = "сохранить";
// ButtonSave.UseVisualStyleBackColor = true;
// labelItem ButtonSave.Click += ButtonSave_Click;
// //
labelItem.AutoSize = true; // labelItem
labelItem.Location = new Point(271, 22); //
labelItem.Name = "labelItem"; labelItem.AutoSize = true;
labelItem.Size = new Size(67, 20); labelItem.Location = new Point(165, 22);
labelItem.TabIndex = 6; labelItem.Name = "labelItem";
labelItem.Text = "корабль"; labelItem.Size = new Size(67, 20);
// labelItem.TabIndex = 6;
// labelcount labelItem.Text = "корабль";
// //
labelcount.AutoSize = true; // labelcount
labelcount.Location = new Point(455, 22); //
labelcount.Name = "labelcount"; labelcount.AutoSize = true;
labelcount.Size = new Size(88, 20); labelcount.Location = new Point(360, 22);
labelcount.TabIndex = 7; labelcount.Name = "labelcount";
labelcount.Text = "количество"; labelcount.Size = new Size(88, 20);
// labelcount.TabIndex = 7;
// labeltotal labelcount.Text = "количество";
// //
labeltotal.AutoSize = true; // labeltotal
labeltotal.Location = new Point(307, 112); //
labeltotal.Name = "labeltotal"; labeltotal.AutoSize = true;
labeltotal.Size = new Size(51, 20); labeltotal.Location = new Point(307, 112);
labeltotal.TabIndex = 8; labeltotal.Name = "labeltotal";
labeltotal.Text = "итого:"; labeltotal.Size = new Size(51, 20);
// labeltotal.TabIndex = 8;
// FormCreateOrder labeltotal.Text = "итого:";
// //
AutoScaleDimensions = new SizeF(8F, 20F); // ComboBoxClient
AutoScaleMode = AutoScaleMode.Font; //
ClientSize = new Size(800, 209); ComboBoxClient.FormattingEnabled = true;
Controls.Add(labeltotal); ComboBoxClient.Location = new Point(511, 62);
Controls.Add(labelcount); ComboBoxClient.Name = "ComboBoxClient";
Controls.Add(labelItem); ComboBoxClient.Size = new Size(151, 28);
Controls.Add(ButtonSave); ComboBoxClient.TabIndex = 9;
Controls.Add(ButtonCancel); //
Controls.Add(ComboBoxManufacture); // labelClient
Controls.Add(textBoxSum); //
Controls.Add(textBoxCount); labelClient.AutoSize = true;
Name = "FormCreateOrder"; labelClient.Location = new Point(537, 19);
Text = "FormCreateOrder"; labelClient.Name = "labelClient";
Load += FormCreateOrder_Load; labelClient.Size = new Size(56, 20);
ResumeLayout(false); labelClient.TabIndex = 10;
PerformLayout(); labelClient.Text = "клиент";
} //
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 209);
Controls.Add(labelClient);
Controls.Add(ComboBoxClient);
Controls.Add(labeltotal);
Controls.Add(labelcount);
Controls.Add(labelItem);
Controls.Add(ButtonSave);
Controls.Add(ButtonCancel);
Controls.Add(ComboBoxManufacture);
Controls.Add(textBoxSum);
Controls.Add(textBoxCount);
Name = "FormCreateOrder";
Text = "FormCreateOrder";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion #endregion
private TextBox textBoxCount; private TextBox textBoxCount;
private TextBox textBoxSum; private TextBox textBoxSum;
private ComboBox ComboBoxManufacture; private ComboBox ComboBoxManufacture;
private Button ButtonCancel; private Button ButtonCancel;
private Button ButtonSave; private Button ButtonSave;
private Label labelItem; private Label labelItem;
private Label labelcount; private Label labelcount;
private Label labeltotal; private Label labeltotal;
} private ComboBox ComboBoxClient;
private Label labelClient;
}
} }

View File

@ -1,133 +1,155 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ShipyardContracts.BindingModels; using ShipyardContracts.BindingModels;
using ShipyardContracts.BusinessLogicContracts;
using ShipyardContracts.BusinessLogicsContracts; using ShipyardContracts.BusinessLogicsContracts;
using ShipyardContracts.SearchModels; using ShipyardContracts.SearchModels;
namespace ShipyardView namespace ShipyardView
{ {
public partial class FormCreateOrder : Form public partial class FormCreateOrder : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IShipLogic _logicP; private readonly IShipLogic _logicP;
private readonly IOrderLogic _logicO; private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IShipLogic private readonly IClientLogic _logicC;
logicP, IOrderLogic logicO) public FormCreateOrder(ILogger<FormCreateOrder> logger, IShipLogic
{ logicP, IOrderLogic logicO, IClientLogic logicC)
InitializeComponent(); {
_logger = logger; InitializeComponent();
_logicP = logicP; _logger = logger;
_logicO = logicO; _logicP = logicP;
} _logicO = logicO;
private void FormCreateOrder_Load(object sender, EventArgs e) _logicC = logicC;
{ }
_logger.LogInformation("Загрузка кораблей для заказа"); private void FormCreateOrder_Load(object sender, EventArgs e)
try {
{ _logger.LogInformation("Загрузка кораблей для заказа");
var list = _logicP.ReadList(null); try
if (list != null) {
{ var list = _logicP.ReadList(null);
ComboBoxManufacture.DisplayMember = "ShipName"; if (list != null)
ComboBoxManufacture.ValueMember = "Id"; {
ComboBoxManufacture.DataSource = list; ComboBoxManufacture.DisplayMember = "ShipName";
ComboBoxManufacture.SelectedItem = null; ComboBoxManufacture.ValueMember = "Id";
} ComboBoxManufacture.DataSource = list;
_logger.LogInformation("корабли загружены"); ComboBoxManufacture.SelectedItem = null;
} }
catch (Exception ex) _logger.LogInformation("корабли загружены");
{ }
_logger.LogError(ex, "Ошибка загрузки кораблей"); catch (Exception ex)
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, {
MessageBoxIcon.Error); _logger.LogError(ex, "Ошибка загрузки кораблей");
} MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
} MessageBoxIcon.Error);
private void CalcSum() }
{ _logger.LogInformation("Загрузка клиентов для заказа");
if (ComboBoxManufacture.SelectedValue != null && try
!string.IsNullOrEmpty(textBoxCount.Text)) {
{ var list = _logicC.ReadList(null);
try if (list != null)
{ {
int id = Convert.ToInt32(ComboBoxManufacture.SelectedValue); ComboBoxClient.DisplayMember = "ClientFIO";
var product = _logicP.ReadElement(new ShipSearchModel ComboBoxClient.ValueMember = "Id";
{ ComboBoxClient.DataSource = list;
Id ComboBoxClient.SelectedItem = null;
= id }
}); _logger.LogInformation("Клиенты загружены");
int count = Convert.ToInt32(textBoxCount.Text); }
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), catch (Exception ex)
2).ToString(); {
_logger.LogInformation("Расчет суммы заказа"); _logger.LogError(ex, "Ошибка загрузки клиентов");
} MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
catch (Exception ex) }
{ }
_logger.LogError(ex, "Ошибка расчета суммы заказа"); private void CalcSum()
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, {
MessageBoxIcon.Error); if (ComboBoxManufacture.SelectedValue != null &&
} !string.IsNullOrEmpty(textBoxCount.Text))
} {
} try
private void ComboBoxProduct_SelectedIndexChanged(object sender, {
EventArgs e) int id = Convert.ToInt32(ComboBoxManufacture.SelectedValue);
{ var product = _logicP.ReadElement(new ShipSearchModel
CalcSum(); {
} Id
private void ButtonSave_Click(object sender, EventArgs e) = id
{ });
if (string.IsNullOrEmpty(textBoxCount.Text)) int count = Convert.ToInt32(textBoxCount.Text);
{ textBoxSum.Text = Math.Round(count * (product?.Price ?? 0),
MessageBox.Show("Заполните поле Количество", "Ошибка", 2).ToString();
MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogInformation("Расчет суммы заказа");
return; }
} catch (Exception ex)
if (ComboBoxManufacture.SelectedValue == null) {
{ _logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show("Выберите корабль", "Ошибка", MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxIcon.Error);
return; }
} }
_logger.LogInformation("Создание заказа"); }
try private void ComboBoxProduct_SelectedIndexChanged(object sender,
{ EventArgs e)
var operationResult = _logicO.CreateOrder(new OrderBindingModel {
{ CalcSum();
ShipId = Convert.ToInt32(ComboBoxManufacture.SelectedValue), }
Count = Convert.ToInt32(textBoxCount.Text), private void ButtonSave_Click(object sender, EventArgs e)
Sum = Convert.ToDouble(textBoxSum.Text) {
}); if (string.IsNullOrEmpty(textBoxCount.Text))
if (!operationResult) {
{ MessageBox.Show("Заполните поле Количество", "Ошибка",
throw new Exception("Ошибка при создании заказа.Дополнительная информация в логах."); MessageBoxButtons.OK, MessageBoxIcon.Error);
} return;
MessageBox.Show("Сохранение прошло успешно", "Сообщение", }
MessageBoxButtons.OK, MessageBoxIcon.Information); if (ComboBoxManufacture.SelectedValue == null)
DialogResult = DialogResult.OK; {
Close(); MessageBox.Show("Выберите корабль", "Ошибка",
} MessageBoxButtons.OK, MessageBoxIcon.Error);
catch (Exception ex) return;
{ }
_logger.LogError(ex, "Ошибка создания заказа"); _logger.LogInformation("Создание заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, try
MessageBoxIcon.Error); {
} var operationResult = _logicO.CreateOrder(new OrderBindingModel
} {
private void ButtonCancel_Click(object sender, EventArgs e) ShipId = Convert.ToInt32(ComboBoxManufacture.SelectedValue),
{ ClientId = Convert.ToInt32(ComboBoxClient.SelectedValue),
DialogResult = DialogResult.Cancel; Count = Convert.ToInt32(textBoxCount.Text),
Close(); Sum = Convert.ToDouble(textBoxSum.Text)
} });
private void textBoxCount_TextChanged(object sender, EventArgs e) if (!operationResult)
{ {
CalcSum(); 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();
}
private void textBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e)
{ {
CalcSum(); CalcSum();
} }
private void textBoxSum_TextChanged(object sender, EventArgs e) private void textBoxSum_TextChanged(object sender, EventArgs e)
{ {
CalcSum(); CalcSum();
} }
} }
} }