87 lines
3.0 KiB
C#
87 lines
3.0 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
|
using PlumbingRepairContracts.BindingModels;
|
|
|
|
namespace PlumbingRepairView
|
|
{
|
|
public partial class FormSellWorks : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly IWorkLogic _workLogic;
|
|
|
|
private readonly IShopLogic _logicShop;
|
|
|
|
public FormSellWorks(ILogger<FormStoreReplenishment> logger, IWorkLogic workLogic, IShopLogic logicShop)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_workLogic = workLogic;
|
|
_logicShop = logicShop;
|
|
}
|
|
|
|
private void FormSellWorks_Load(object sender, EventArgs e)
|
|
{
|
|
_logger.LogInformation("Ice creams loading");
|
|
try
|
|
{
|
|
var list = _workLogic.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
comboBoxWork.DisplayMember = "WorkName";
|
|
comboBoxWork.ValueMember = "Id";
|
|
comboBoxWork.DataSource = list;
|
|
comboBoxWork.SelectedItem = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Works loading error");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonSale_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxWork.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите работу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("work sale");
|
|
try
|
|
{
|
|
var operationResult = _logicShop.SellWork(
|
|
new WorkBindingModel
|
|
{
|
|
Id = Convert.ToInt32(comboBoxWork.SelectedValue)
|
|
},
|
|
Convert.ToInt32(textBoxCount.Text)
|
|
);
|
|
if (!operationResult)
|
|
{
|
|
throw new Exception("Ошибка при продаже.");
|
|
}
|
|
MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Work sale error");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
} |