67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using LDBproject.Entities;
|
|
using LDBproject.Repositories;
|
|
using LDBproject.Repositories.Implementations;
|
|
|
|
namespace LDBproject.AdditionalForms;
|
|
|
|
public partial class RegOrder : Form
|
|
{
|
|
private readonly IOrderRep _orderRepository;
|
|
|
|
public RegOrder(IOrderRep orderRep, ICustomerCardsRep readerRep,
|
|
ILibrarianRep employeeRep, IBookRep bookRep)
|
|
{
|
|
InitializeComponent();
|
|
_orderRepository = orderRep ?? throw new ArgumentNullException(nameof(orderRep));
|
|
|
|
LibrarianCBox.DataSource = employeeRep.GetCards();
|
|
LibrarianCBox.DisplayMember = "FIO";
|
|
LibrarianCBox.ValueMember = "CardID";
|
|
|
|
CardCBox.DataSource = readerRep.GetCards();
|
|
CardCBox.DisplayMember = "FIO";
|
|
CardCBox.ValueMember = "CardID";
|
|
|
|
BookColumnCBox.DataSource = bookRep.GetBookList();
|
|
BookColumnCBox.DisplayMember = "Title";
|
|
BookColumnCBox.ValueMember = "BookID";
|
|
}
|
|
|
|
private void SaveBtn_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (DataGV.RowCount < 1 || LibrarianCBox.SelectedIndex < 0)
|
|
{
|
|
throw new Exception("[ Blanck space left ]");
|
|
}
|
|
_orderRepository.CreateOrder(Order.NewOrder(0, (int)CardCBox.SelectedValue, (int)LibrarianCBox.SelectedValue,
|
|
CreateBookListFromDG(), BorrowDTPicker.Value));
|
|
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Order Form [ Error while saving order ]",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private List<Registration> CreateBookListFromDG()
|
|
{
|
|
List<Registration> registrations = new List<Registration>();
|
|
foreach (DataGridViewRow row in DataGV.Rows)
|
|
{
|
|
if (row.Cells["BookColumnCBox"].Value != null)
|
|
{
|
|
var bookId = (int)row.Cells["BookColumnCBox"].Value;
|
|
var notes = row.Cells["NoteColumn"].Value?.ToString();
|
|
registrations.Add(Registration.OrderReg(0, bookId, notes));
|
|
}
|
|
}
|
|
return registrations;
|
|
}
|
|
|
|
private void BackBtn_Click(object sender, EventArgs e) => Close();
|
|
}
|