77 lines
2.8 KiB
C#
77 lines
2.8 KiB
C#
using ProjectFuel.Entities.Enums;
|
|
using ProjectFuel.Entities;
|
|
using ProjectFuel.Repositories;
|
|
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;
|
|
using ProjectFuel.Repositories.Implementations;
|
|
|
|
namespace ProjectFuel.Forms_
|
|
{
|
|
public partial class FormTrip : Form
|
|
{
|
|
private readonly ITripRepository _tripRepository;
|
|
|
|
|
|
public FormTrip(ITripRepository tripRepository, ICarRepository carRepository, IDriverRepository driverRepository, IRouteRepository routeRepository)
|
|
{
|
|
InitializeComponent();
|
|
_tripRepository = tripRepository ??
|
|
throw new ArgumentNullException(nameof(tripRepository));
|
|
|
|
comboBoxCarID.DataSource = tripRepository.ReadTrips();
|
|
comboBoxCarID.DisplayMember = "Car_Mark";
|
|
comboBoxCarID.ValueMember = "Car_ID";
|
|
|
|
comboBoxDriverID.DataSource = tripRepository.ReadTrips();
|
|
comboBoxDriverID.DisplayMember = "Firstname";
|
|
comboBoxDriverID.ValueMember = "Driver_ID";
|
|
|
|
ColumnRoute.DataSource = routeRepository.ReadRoutes();
|
|
ColumnRoute.DisplayMember = "Start_Point";
|
|
ColumnRoute.ValueMember = "Route_ID";
|
|
|
|
|
|
|
|
}
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (comboBoxCarID.SelectedIndex < 0 || comboBoxDriverID.SelectedIndex < 0 || dataGridViewRoutes.RowCount < 0)
|
|
throw new Exception("Имеются незаполненные поля");
|
|
|
|
_tripRepository.CreateTrip(Trip.CreateOperation(0, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value, (Shift)comboBoxShift.SelectedItem!, (float)numericUpDownConsumptionRate.Value, (int)comboBoxCarID.SelectedValue!, (int)comboBoxDriverID.SelectedValue!, CreateListDriversFromDataGrid()));
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
}
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|
private List<Route> CreateListDriversFromDataGrid()
|
|
{
|
|
var list = new List<Route>();
|
|
foreach (DataGridViewRow row in dataGridViewRoutes.Rows)
|
|
{
|
|
if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnEndPoint"].Value == null)
|
|
continue;
|
|
|
|
list.Add(Route.CreateEntity(0, (string)row.Cells["ColumnRoute"].Value, (string)row.Cells["ColumnEndPoint"].Value, 0));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
}
|
|
}
|