102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using Microsoft.Extensions.Logging;
|
||
using SoftwareInstallationContracts.BusinessLogicsContracts;
|
||
using SoftwareInstallationContracts.SearchModels;
|
||
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 SoftwareInstallationView
|
||
{
|
||
public partial class FormSellPackage : Form
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IPackageLogic _logicPackage;
|
||
private readonly IShopLogic _logicStore;
|
||
public FormSellPackage(ILogger<FormSellPackage> logger, IPackageLogic logicPackage, IShopLogic logicStore)
|
||
{
|
||
InitializeComponent();
|
||
_logger = logger;
|
||
_logicPackage = logicPackage;
|
||
_logicStore = logicStore;
|
||
LoadData();
|
||
}
|
||
private void FormSellPackage_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
private void LoadData()
|
||
{
|
||
_logger.LogInformation("Loading packages for sale.");
|
||
|
||
try
|
||
{
|
||
var list = _logicPackage.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
PackageСomboBox.DisplayMember = "PackageName";
|
||
PackageСomboBox.ValueMember = "Id";
|
||
PackageСomboBox.DataSource = list;
|
||
PackageС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(CountTextBox.Text))
|
||
{
|
||
MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
|
||
if (PackageСomboBox.SelectedValue == null)
|
||
{
|
||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
|
||
_logger.LogInformation("Package sale.");
|
||
|
||
try
|
||
{
|
||
var operationResult = _logicStore.SellPackage(_logicPackage.ReadElement(new PackageSearchModel()
|
||
{
|
||
Id = Convert.ToInt32(PackageСomboBox.SelectedValue)
|
||
})!, Convert.ToInt32(CountTextBox.Text));
|
||
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах.");
|
||
}
|
||
|
||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
DialogResult = DialogResult.OK;
|
||
|
||
Close();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Package sale error.");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
|
||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||
{
|
||
DialogResult = DialogResult.Cancel;
|
||
Close();
|
||
}
|
||
}
|
||
}
|