73 lines
2.8 KiB
C#
73 lines
2.8 KiB
C#
using ProjectAirline.Entities;
|
|
using ProjectAirline.Repositories;
|
|
using ProjectAirline.Repositories.Implementations;
|
|
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 ProjectAirline.Forms
|
|
{
|
|
public partial class FormFlight : Form
|
|
{
|
|
private readonly IFlightRepository _flightRepository;
|
|
public FormFlight(IFlightRepository flightRepository, IAirplaneRepository airplaneRepository, IEmployeeRepository employeeRepository)
|
|
{
|
|
InitializeComponent();
|
|
_flightRepository = flightRepository ?? throw new ArgumentNullException(nameof(flightRepository));
|
|
|
|
comboBoxAirplane.DataSource = airplaneRepository.ReadAirplanes();
|
|
comboBoxAirplane.DisplayMember = "Model";
|
|
comboBoxAirplane.ValueMember = "Id";
|
|
|
|
ColumnEmployee.DataSource = employeeRepository.ReadEmployees();
|
|
ColumnEmployee.DisplayMember = "FirstName";
|
|
ColumnEmployee.ValueMember = "Id";
|
|
}
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.RowCount < 1 || comboBoxAirplane.SelectedIndex < 0 || numericUpDownPrice.Value <= 0)
|
|
{
|
|
throw new Exception("Имеются незаполненны поля");
|
|
}
|
|
try
|
|
{
|
|
_flightRepository.CreateFlight(Flight.CreateOperation(0, (int)comboBoxAirplane.SelectedValue,
|
|
dateTimePickerDeparture.Value, dateTimePickerArrival.Value,
|
|
textBoxDestination.Text, textBoxDeparture.Text,
|
|
(int)numericUpDownPrice.Value, CreateListFlightFromDataGrid()));
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
private List<EmployeeFlight> CreateListFlightFromDataGrid()
|
|
{
|
|
var list = new List<EmployeeFlight>();
|
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
|
{
|
|
if (row.Cells["ColumnEmployee"].Value == null || row.Cells["ColumnFlight"].Value == null || row.Cells["ColumnHoursWork"].Value == null)
|
|
{
|
|
continue;
|
|
}
|
|
list.Add(EmployeeFlight.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnEmployee"].Value),
|
|
Convert.ToInt32(row.Cells["ColumnFlight"].Value), Convert.ToInt32(row.Cells["ColumnHoursWork"].Value) ));
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
}
|