78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
using BookShopContracts.BusinessLogicsContracts;
|
|
using BookShopContracts.ViewModels;
|
|
using BookShopDataModels.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 BookShopView
|
|
{
|
|
public partial class FormBookAuthor : Form
|
|
{
|
|
private readonly List<AuthorViewModel>? _list;
|
|
public int Id
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToInt32(comboBoxAuthor.SelectedValue);
|
|
}
|
|
set
|
|
{
|
|
comboBoxAuthor.SelectedValue = value;
|
|
}
|
|
}
|
|
public IAuthorModel? AuthorModel
|
|
{
|
|
get
|
|
{
|
|
if (_list == null)
|
|
{
|
|
return null;
|
|
}
|
|
foreach (var elem in _list)
|
|
{
|
|
if (elem.Id == Id)
|
|
{
|
|
return elem;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
public FormBookAuthor(IAuthorLogic logic)
|
|
{
|
|
InitializeComponent();
|
|
_list = logic.ReadList(null);
|
|
if (_list != null)
|
|
{
|
|
comboBoxAuthor.DisplayMember = "AuthorSurname";
|
|
comboBoxAuthor.ValueMember = "Id";
|
|
comboBoxAuthor.DataSource = _list;
|
|
comboBoxAuthor.SelectedItem = null;
|
|
}
|
|
}
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxAuthor.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите автора", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|