121 lines
3.4 KiB
C#
121 lines
3.4 KiB
C#
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;
|
|
using SewingDressesContracts.BusinessLogicsContracts;
|
|
using SewingDressesContracts.ViewModels;
|
|
using SewingDressesDataModels.Models;
|
|
|
|
namespace SewingDressesView
|
|
{
|
|
public partial class SellForm : Form
|
|
{
|
|
private readonly List<DressViewModel>? _dressList;
|
|
IShopLogic _shopLogic;
|
|
IDressLogic _dressLogic;
|
|
public SellForm(IDressLogic dressLogic, IShopLogic shopLogic)
|
|
{
|
|
InitializeComponent();
|
|
_shopLogic = shopLogic;
|
|
_dressLogic = dressLogic;
|
|
_dressList = dressLogic.ReadList(null);
|
|
if (_dressList != null)
|
|
{
|
|
comboBoxDress.DisplayMember = "DressName";
|
|
comboBoxDress.ValueMember = "Id";
|
|
comboBoxDress.DataSource = _dressList;
|
|
comboBoxDress.SelectedItem = null;
|
|
}
|
|
}
|
|
public int DressId
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToInt32(comboBoxDress.SelectedValue);
|
|
}
|
|
set
|
|
{
|
|
comboBoxDress.SelectedValue = value;
|
|
}
|
|
}
|
|
|
|
public IDressModel? IceCreamModel
|
|
{
|
|
get
|
|
{
|
|
if (_dressList == null)
|
|
{
|
|
return null;
|
|
}
|
|
foreach (var elem in _dressList)
|
|
{
|
|
if (elem.Id == DressId)
|
|
{
|
|
return elem;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public int Count
|
|
{
|
|
get { return Convert.ToInt32(textBoxCount.Text); }
|
|
set
|
|
{ textBoxCount.Text = value.ToString(); }
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (comboBoxDress.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите мороженное", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
int count = Convert.ToInt32(textBoxCount.Text);
|
|
|
|
bool res = _shopLogic.MakeSell(
|
|
_dressLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxDress.SelectedValue) }),
|
|
count
|
|
);
|
|
|
|
if (!res)
|
|
{
|
|
throw new Exception("Ошибка при продаже.");
|
|
}
|
|
|
|
MessageBox.Show("Продажа прошла успешно");
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
MessageBox.Show("Ошибка продажи");
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
}
|