78 lines
2.9 KiB
C#
78 lines
2.9 KiB
C#
|
|
|||
|
using ProjectOptika.Scripts.Entities;
|
|||
|
using ProjectOptika.Scripts.Repositories;
|
|||
|
using ProjectOptika.Scripts.Repositories.Implementations;
|
|||
|
|
|||
|
namespace ProjectOptika.Scripts.Forms
|
|||
|
{
|
|||
|
public partial class FormItemOrder : Form
|
|||
|
{
|
|||
|
private readonly IOrderRepository _orderRepository;
|
|||
|
|
|||
|
public FormItemOrder(IOrderRepository orderRepository, IEmployeeRepository employeeRepository, IClientRepositiory clientRepositiory, IAccessoriesRepository accessoriesRepository)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
_orderRepository = orderRepository ??
|
|||
|
throw new ArgumentNullException(nameof(orderRepository));
|
|||
|
|
|||
|
comboBoxEmployee.DataSource = employeeRepository.GetEmployees();
|
|||
|
comboBoxEmployee.DisplayMember = "Surname";
|
|||
|
comboBoxEmployee.ValueMember = "ID";
|
|||
|
|
|||
|
comboBoxClient.DataSource = clientRepositiory.GetClients();
|
|||
|
comboBoxClient.DisplayMember = "Surname";
|
|||
|
comboBoxClient.ValueMember = "ID";
|
|||
|
|
|||
|
ColumnAccessory.DataSource = accessoriesRepository.GetAccessories();
|
|||
|
ColumnAccessory.DisplayMember = "Name";
|
|||
|
ColumnAccessory.ValueMember = "ID";
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (comboBoxClient.SelectedIndex < 0 ||
|
|||
|
comboBoxEmployee.SelectedIndex < 0 ||
|
|||
|
dataGridViewAccessories.RowCount < 1)
|
|||
|
{
|
|||
|
throw new Exception("Имеются незаполненные поля");
|
|||
|
}
|
|||
|
_orderRepository.CreateOrder(Order.CreateOperation(0,
|
|||
|
(int)comboBoxEmployee.SelectedValue!,
|
|||
|
(int)comboBoxClient.SelectedValue!,
|
|||
|
(double)numericUpDownNumTotalCost.Value,
|
|||
|
CreateListAccessoriesOrderReceptionsFromDataGrid()));
|
|||
|
Close();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private List<AccessoriesOrder> CreateListAccessoriesOrderReceptionsFromDataGrid()
|
|||
|
|
|||
|
{
|
|||
|
var list = new List<AccessoriesOrder>();
|
|||
|
foreach (DataGridViewRow row in dataGridViewAccessories.Rows)
|
|||
|
{
|
|||
|
if (row.Cells["ColumnAccessory"].Value == null ||
|
|||
|
row.Cells["ColumnCount"].Value == null)
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
list.Add(AccessoriesOrder.CreateElement(0,
|
|||
|
Convert.ToInt32(row.Cells["ColumnAccessory"].Value),
|
|||
|
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
|||
|
}
|
|||
|
return list;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|||
|
}
|
|||
|
}
|