150 lines
4.5 KiB
C#
150 lines
4.5 KiB
C#
using SewingDressesContracts.BusinessLogicsContracts;
|
|
using SewingDressesContracts.SearchModels;
|
|
using SewingDressesContracts.ViewModels;
|
|
using SewingDressesDataModels.Models;
|
|
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 SewingDressesView
|
|
{
|
|
public partial class SupplyForm : Form
|
|
{
|
|
private readonly List<DressViewModel>? _dressList;
|
|
private readonly List<ShopViewModel>? _shopsList;
|
|
IShopLogic _shopLogic;
|
|
IDressLogic _dressLogic;
|
|
public int ShopId
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToInt32(ShopComboBox.SelectedValue);
|
|
}
|
|
set
|
|
{
|
|
ShopComboBox.SelectedValue = value;
|
|
}
|
|
}
|
|
public int DressId
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToInt32(DressComboBox.SelectedValue);
|
|
}
|
|
set
|
|
{
|
|
DressComboBox.SelectedValue = value;
|
|
}
|
|
}
|
|
|
|
public IDressModel? DressModel
|
|
{
|
|
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(CountTextBox.Text); }
|
|
set
|
|
{ CountTextBox.Text = value.ToString(); }
|
|
}
|
|
public SupplyForm(IDressLogic dressLogic, IShopLogic shopLogic)
|
|
{
|
|
InitializeComponent();
|
|
_shopLogic = shopLogic;
|
|
_dressLogic = dressLogic;
|
|
_dressList = dressLogic.ReadList(null);
|
|
_shopsList = shopLogic.ReadList(null);
|
|
if (_dressList != null)
|
|
{
|
|
DressComboBox.DisplayMember = "DressName";
|
|
DressComboBox.ValueMember = "Id";
|
|
DressComboBox.DataSource = _dressList;
|
|
DressComboBox.SelectedItem = null;
|
|
}
|
|
if (_shopsList != null)
|
|
{
|
|
ShopComboBox.DisplayMember = "ShopName";
|
|
ShopComboBox.ValueMember = "Id";
|
|
ShopComboBox.DataSource = _shopsList;
|
|
ShopComboBox.SelectedItem = null;
|
|
}
|
|
}
|
|
|
|
private void SaveButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(CountTextBox.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (DressComboBox.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите платье", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (ShopComboBox.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите магазин", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
int count = Convert.ToInt32(CountTextBox.Text);
|
|
|
|
bool res = _shopLogic.MakeSupply(
|
|
new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) },
|
|
_dressLogic.ReadElement(new() { Id = Convert.ToInt32(DressComboBox.SelectedValue) }),
|
|
count
|
|
);
|
|
|
|
if (!res)
|
|
{
|
|
throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
|
|
}
|
|
|
|
MessageBox.Show("Пополнение прошло успешно");
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
|
|
}
|
|
catch (Exception er)
|
|
{
|
|
MessageBox.Show("Ошибка пополнения");
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void CancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|