using Contracts.BindingModels; using Contracts.StoragesContracts; 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 WinForm { public partial class FormCreateBook : Form { public readonly IBookStorage _bookStorage; public readonly IShapeStorage _shapeStorage; private int? _id; public int Id { set { _id = value; } } public FormCreateBook(IBookStorage bookStorage, IShapeStorage shapeStorage) { InitializeComponent(); _bookStorage = bookStorage; _shapeStorage = shapeStorage; input_text1.MinLen = 2; input_text1.MaxLen = 40; LoadData(); } private void LoadData() { var list = _shapeStorage.GetFullList(); foreach (var item in list) { booksForm1.FillValues(item.Name); } } private void buttonSave_Click_1(object sender, EventArgs e) { if (String.IsNullOrEmpty(input_text1.Element) || String.IsNullOrEmpty(textBoxReaders.Text) || booksForm1.SelectedValue == null) { MessageBox.Show("Заполните поля"); } else { var model = new BookBindingModel { Id = _id ?? 0, Name = input_text1.Element, Readers = textBoxReaders.Text, Shape = booksForm1.SelectedValue.ToString(), Annotation = textBoxAnnotation.Text, }; if (!_id.HasValue) { _bookStorage.Insert(model); } else { _bookStorage.Update(model); } Close(); } } } }