обновил формы

This commit is contained in:
Андрей Байгулов 2024-05-03 23:12:06 +04:00
parent 2fb30acd26
commit a2d340d325
4 changed files with 255 additions and 218 deletions

View File

@ -20,119 +20,140 @@
base.Dispose(disposing);
}
#region Windows Form Designer generated code
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelSushi = new Label();
labelCount = new Label();
labelSum = new Label();
textBoxCount = new TextBox();
comboBoxSushi = new ComboBox();
textBoxSum = new TextBox();
ButtonSave = new Button();
ButtonCancel = new Button();
SuspendLayout();
//
// labelSushi
//
labelSushi.AutoSize = true;
labelSushi.Location = new Point(42, 27);
labelSushi.Name = "labelSushi";
labelSushi.Size = new Size(42, 15);
labelSushi.TabIndex = 0;
labelSushi.Text = "Суши:";
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(42, 56);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 1;
labelCount.Text = "Количество:";
//
// labelSum
//
labelSum.AutoSize = true;
labelSum.Location = new Point(42, 84);
labelSum.Name = "labelSum";
labelSum.Size = new Size(48, 15);
labelSum.TabIndex = 2;
labelSum.Text = "Сумма:";
//
// textBoxCount
//
textBoxCount.Location = new Point(123, 53);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(276, 23);
textBoxCount.TabIndex = 3;
this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCost_TextChanged);
//
// comboBoxSushi
//
comboBoxSushi.FormattingEnabled = true;
comboBoxSushi.Location = new Point(123, 24);
comboBoxSushi.Name = "comboBoxSushi";
comboBoxSushi.Size = new Size(276, 23);
comboBoxSushi.TabIndex = 4;
comboBoxSushi.SelectedIndexChanged += comboBoxSushi_SelectedIndexChanged;
//
// textBoxSum
//
textBoxSum.Location = new Point(123, 84);
textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(276, 23);
textBoxSum.TabIndex = 5;
//
// ButtonSave
//
ButtonSave.Location = new Point(192, 124);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(98, 41);
ButtonSave.TabIndex = 6;
ButtonSave.Text = "Сохранить";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// ButtonCancel
//
ButtonCancel.Location = new Point(296, 124);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(98, 41);
ButtonCancel.TabIndex = 7;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(411, 177);
Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(textBoxSum);
Controls.Add(comboBoxSushi);
Controls.Add(textBoxCount);
Controls.Add(labelSum);
Controls.Add(labelCount);
Controls.Add(labelSushi);
Name = "FormCreateOrder";
Text = "Заказ";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelSushi = new Label();
labelCount = new Label();
labelSum = new Label();
textBoxCount = new TextBox();
comboBoxSushi = new ComboBox();
textBoxSum = new TextBox();
ButtonSave = new Button();
ButtonCancel = new Button();
comboBoxUser = new ComboBox();
labelUser = new Label();
SuspendLayout();
//
// labelSushi
//
labelSushi.AutoSize = true;
labelSushi.Location = new Point(33, 66);
labelSushi.Name = "labelSushi";
labelSushi.Size = new Size(42, 15);
labelSushi.TabIndex = 0;
labelSushi.Text = "Суши:";
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(33, 95);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 1;
labelCount.Text = "Количество:";
//
// labelSum
//
labelSum.AutoSize = true;
labelSum.Location = new Point(33, 124);
labelSum.Name = "labelSum";
labelSum.Size = new Size(48, 15);
labelSum.TabIndex = 2;
labelSum.Text = "Сумма:";
//
// textBoxCount
//
textBoxCount.Location = new Point(123, 95);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(276, 23);
textBoxCount.TabIndex = 3;
textBoxCount.TextChanged += textBoxCost_TextChanged;
//
// comboBoxSushi
//
comboBoxSushi.FormattingEnabled = true;
comboBoxSushi.Location = new Point(123, 66);
comboBoxSushi.Name = "comboBoxSushi";
comboBoxSushi.Size = new Size(276, 23);
comboBoxSushi.TabIndex = 4;
comboBoxSushi.SelectedIndexChanged += comboBoxSushi_SelectedIndexChanged;
//
// textBoxSum
//
textBoxSum.Location = new Point(123, 124);
textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(276, 23);
textBoxSum.TabIndex = 5;
//
// ButtonSave
//
ButtonSave.Location = new Point(197, 168);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(98, 41);
ButtonSave.TabIndex = 6;
ButtonSave.Text = "Сохранить";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// ButtonCancel
//
ButtonCancel.Location = new Point(301, 168);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(98, 41);
ButtonCancel.TabIndex = 7;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// comboBoxUser
//
comboBoxUser.FormattingEnabled = true;
comboBoxUser.Location = new Point(123, 37);
comboBoxUser.Name = "comboBoxUser";
comboBoxUser.Size = new Size(276, 23);
comboBoxUser.TabIndex = 8;
//
// labelUser
//
labelUser.AutoSize = true;
labelUser.Location = new Point(33, 40);
labelUser.Name = "labelUser";
labelUser.Size = new Size(87, 15);
labelUser.TabIndex = 9;
labelUser.Text = "Пользователь:";
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(411, 217);
Controls.Add(labelUser);
Controls.Add(comboBoxUser);
Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(textBoxSum);
Controls.Add(comboBoxSushi);
Controls.Add(textBoxCount);
Controls.Add(labelSum);
Controls.Add(labelCount);
Controls.Add(labelSushi);
Name = "FormCreateOrder";
Text = "Заказ";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
#endregion
private Label labelSushi;
private Label labelSushi;
private Label labelCount;
private Label labelSum;
private TextBox textBoxCount;
@ -140,5 +161,7 @@
private TextBox textBoxSum;
private Button ButtonSave;
private Button ButtonCancel;
}
private ComboBox comboBoxUser;
private Label labelUser;
}
}

View File

@ -16,113 +16,126 @@ using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logicP;
private readonly IOrderLogic _logicO;
private List<SushiViewModel>? _list;
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logicP;
private readonly IOrderLogic _logicO;
private readonly IClientLogic _logicC;
private List<SushiViewModel>? _list;
private List<ClientViewModel>? _listClients;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISushiLogic logicP, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicO = logicO;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка суши для заказа");
_list = _logicP.ReadList(null);
if (_list != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = _list;
comboBoxSushi.SelectedItem = null;
_logger.LogInformation("Загрузка суши для заказа");
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Выберите суши", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SushiId = Convert.ToInt32(comboBoxSushi.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 CalcSum()
{
if (comboBoxSushi.SelectedValue != null &&
!string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
var sushi = _logicP.ReadElement(new SushiSearchModel
{
Id
= id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0),
2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISushiLogic logicP, IOrderLogic logicO, IClientLogic logicC)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicO = logicO;
_logicC = logicC;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка суши для заказа");
_list = _logicP.ReadList(null);
if (_list != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = _list;
comboBoxSushi.SelectedItem = null;
_logger.LogInformation("Загрузка суши для заказа");
}
_listClients = _logicC.ReadList(null);
if (_listClients != null)
{
comboBoxUser.DisplayMember = "ClientFIO";
comboBoxUser.ValueMember = "Id";
comboBoxUser.DataSource = _listClients;
comboBoxUser.SelectedItem = null;
_logger.LogInformation("Загрузка клиентов для заказа");
}
private void comboBoxSushi_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 (comboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Выберите суши", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SushiId = Convert.ToInt32(comboBoxSushi.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 CalcSum()
{
if (comboBoxSushi.SelectedValue != null &&
!string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
var sushi = _logicP.ReadElement(new SushiSearchModel
{
Id
= id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0),
2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void textBoxCost_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void comboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
private void textBoxCost_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -169,7 +169,7 @@
clientToolStripMenuItem.Name = "clientToolStripMenuItem";
clientToolStripMenuItem.Size = new Size(180, 22);
clientToolStripMenuItem.Text = "Клиент";
clientToolStripMenuItem.Click += клиентToolStripMenuItem_Click;
clientToolStripMenuItem.Click += clientToolStripMenuItem_Click;
//
// FormMain
//

View File

@ -51,7 +51,8 @@ namespace SushiBarView
services.AddTransient<FormSushi>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormReportSushiComponents>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<FormClients>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();