104 lines
3.4 KiB
C#
104 lines
3.4 KiB
C#
using JewelryStoreContracts.BusinessLogicsContracts;
|
||
using JewelryStoreContracts.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 JewelryStore
|
||
{
|
||
public partial class FormSellJewel : Form
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IJewelLogic _logicJewel;
|
||
private readonly IStoreLogic _logicStore;
|
||
public FormSellJewel(ILogger<FormSellJewel> logger, IJewelLogic logicJewel, IStoreLogic logicStore)
|
||
{
|
||
InitializeComponent();
|
||
_logger = logger;
|
||
_logicJewel = logicJewel;
|
||
_logicStore = logicStore;
|
||
LoadData();
|
||
}
|
||
|
||
private void FormSellJewel_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
|
||
private void LoadData()
|
||
{
|
||
_logger.LogInformation("Loading jewels for sale.");
|
||
|
||
try
|
||
{
|
||
var list = _logicJewel.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
JewelСomboBox.DisplayMember = "JewelName";
|
||
JewelСomboBox.ValueMember = "Id";
|
||
JewelСomboBox.DataSource = list;
|
||
JewelСomboBox.SelectedItem = null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "List loading error.");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
|
||
private void SaveButton_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(QuantityTextBox.Text))
|
||
{
|
||
MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
|
||
if (JewelСomboBox.SelectedValue == null)
|
||
{
|
||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
|
||
_logger.LogInformation("Jewel sale.");
|
||
|
||
try
|
||
{
|
||
var operationResult = _logicStore.SellJewel(_logicJewel.ReadElement(new JewelSearchModel()
|
||
{
|
||
Id = Convert.ToInt32(JewelСomboBox.SelectedValue)
|
||
})!, Convert.ToInt32(QuantityTextBox.Text));
|
||
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах.");
|
||
}
|
||
|
||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
DialogResult = DialogResult.OK;
|
||
|
||
Close();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Jewel sale error.");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
|
||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||
{
|
||
DialogResult = DialogResult.Cancel;
|
||
Close();
|
||
}
|
||
}
|
||
}
|