2024-11-19 19:46:02 +04:00
|
|
|
|
using ProjectLibrary.Repositories;
|
|
|
|
|
using ProjectLibrary.Entites;
|
2024-11-20 19:31:06 +04:00
|
|
|
|
using System.Xml.Linq;
|
2024-12-08 13:24:07 +04:00
|
|
|
|
using ProjectLibrary.Repositores;
|
|
|
|
|
using System.Windows.Forms;
|
2024-11-19 19:46:02 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectLibrary.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class FOrder : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IOrderRepository _orderRepository;
|
2024-12-08 13:24:07 +04:00
|
|
|
|
private readonly IBookRepository _bookRepository;
|
2024-11-19 19:46:02 +04:00
|
|
|
|
|
2024-12-08 13:24:07 +04:00
|
|
|
|
public FOrder(IOrderRepository orderRepository, IReaderRepository _readerRepository, IBookRepository bookRepository)
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-12-08 13:24:07 +04:00
|
|
|
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
|
|
|
|
_bookRepository = bookRepository ?? throw new ArgumentNullException(nameof(_bookRepository));
|
|
|
|
|
comboBox.DataSource = _readerRepository.ReadReaders();
|
|
|
|
|
comboBox.DisplayMember = "Name";
|
|
|
|
|
comboBox.ValueMember = "Id";
|
2024-11-19 19:46:02 +04:00
|
|
|
|
|
2024-12-08 13:24:07 +04:00
|
|
|
|
Book.DataSource = bookRepository.ReadBooks();
|
|
|
|
|
Book.DisplayMember = "Name";
|
|
|
|
|
Book.ValueMember = "Id";
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 19:31:06 +04:00
|
|
|
|
private List<Book_Orders> CreateListBooksFromDataGrid()
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
|
|
|
|
var list = new List<Book_Orders>();
|
2024-11-20 19:31:06 +04:00
|
|
|
|
foreach (DataGridViewRow row in dataGridViewBook.Rows)
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
2024-12-08 13:24:07 +04:00
|
|
|
|
if (row.Cells["Book"].Value == null)
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-12-20 01:07:20 +04:00
|
|
|
|
list.Add(Book_Orders.CreateEntity(0, Convert.ToInt32(row.Cells["Book"].Value), Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2024-11-20 19:31:06 +04:00
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-12-08 13:24:07 +04:00
|
|
|
|
if (comboBox.SelectedItem == null)
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Не все поля заполнены.");
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 19:31:06 +04:00
|
|
|
|
var order = Orders.CreateEntity(
|
2024-12-08 13:24:07 +04:00
|
|
|
|
0,
|
|
|
|
|
dtptxtReturnDate.Value,
|
|
|
|
|
Convert.ToInt32(comboBox.SelectedValue),
|
2024-11-20 19:31:06 +04:00
|
|
|
|
CreateListBooksFromDataGrid()
|
2024-11-19 19:46:02 +04:00
|
|
|
|
);
|
|
|
|
|
|
2024-12-08 13:24:07 +04:00
|
|
|
|
_orderRepository.CreateOrder(order);
|
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при сохранении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|