76 lines
2.8 KiB
C#
76 lines
2.8 KiB
C#
using ProjectOptika.Scripts.Entities;
|
|
using ProjectOptika.Scripts.Repositories;
|
|
|
|
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 = "FullName";
|
|
comboBoxEmployee.ValueMember = "ID";
|
|
|
|
comboBoxClient.DataSource = clientRepositiory.GetClients();
|
|
comboBoxClient.DisplayMember = "FullName";
|
|
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();
|
|
}
|
|
}
|