done
This commit is contained in:
parent
d243c03fc8
commit
2ef7829897
@ -17,14 +17,14 @@ public class Driver
|
|||||||
|
|
||||||
public int TruckId { get;private set; }
|
public int TruckId { get;private set; }
|
||||||
|
|
||||||
public static Driver CreateDriver(int id, string fname, string lname, int tryckid)
|
public static Driver CreateDriver(int id, string fname, string lname, int truckid)
|
||||||
{
|
{
|
||||||
return new Driver
|
return new Driver
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Fname = fname,
|
Fname = fname,
|
||||||
Lname = lname,
|
Lname = lname,
|
||||||
TruckId = tryckid
|
TruckId = truckid
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public class FuelReplenishment
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int DriverId { get; private set; }
|
public int DriverId { get; private set; }
|
||||||
public DateTime Date { get; private set; }
|
public DateTime ReplenishmentDate { get; private set; }
|
||||||
public IEnumerable<FuelFuelReplenishment> FuelFuelReplenishments { get; private set;} = [];
|
public IEnumerable<FuelFuelReplenishment> FuelFuelReplenishments { get; private set;} = [];
|
||||||
|
|
||||||
public static FuelReplenishment CreateOpeartion(int id, int driverId, IEnumerable<FuelFuelReplenishment> fuelFuelReplenishments)
|
public static FuelReplenishment CreateOpeartion(int id, int driverId, IEnumerable<FuelFuelReplenishment> fuelFuelReplenishments)
|
||||||
@ -19,7 +19,7 @@ public class FuelReplenishment
|
|||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
DriverId = driverId,
|
DriverId = driverId,
|
||||||
Date = DateTime.Now,
|
ReplenishmentDate = DateTime.Now,
|
||||||
FuelFuelReplenishments = fuelFuelReplenishments
|
FuelFuelReplenishments = fuelFuelReplenishments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ namespace ProjectGarage.Forms
|
|||||||
public partial class FormDriver : Form
|
public partial class FormDriver : Form
|
||||||
{
|
{
|
||||||
private readonly IDriverRepository _driverRepository;
|
private readonly IDriverRepository _driverRepository;
|
||||||
|
|
||||||
private int? _driverId;
|
private int? _driverId;
|
||||||
|
|
||||||
public int Id
|
public int Id
|
||||||
@ -32,7 +33,7 @@ namespace ProjectGarage.Forms
|
|||||||
}
|
}
|
||||||
textBoxFirstName.Text = driver.Fname;
|
textBoxFirstName.Text = driver.Fname;
|
||||||
textBoxLastName.Text = driver.Lname;
|
textBoxLastName.Text = driver.Lname;
|
||||||
//comboBoxTruckID.SelectedItem = driver.TruckId;
|
comboBoxTruckID.SelectedItem = driver.TruckId;
|
||||||
_driverId = value;
|
_driverId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -81,6 +82,6 @@ namespace ProjectGarage.Forms
|
|||||||
private void ButtonCancelDriver_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancelDriver_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
private Driver CreateDriver(int id) => Driver.CreateDriver(id, textBoxFirstName.Text,
|
private Driver CreateDriver(int id) => Driver.CreateDriver(id, textBoxFirstName.Text,
|
||||||
textBoxLastName.Text, (int)comboBoxTruckID.SelectedIndex!);
|
textBoxLastName.Text, (int)comboBoxTruckID.SelectedIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
ProjectGarage/Forms/FormDrivers.Designer.cs
generated
6
ProjectGarage/Forms/FormDrivers.Designer.cs
generated
@ -52,7 +52,7 @@
|
|||||||
dataGridViewDrivers.RowHeadersVisible = false;
|
dataGridViewDrivers.RowHeadersVisible = false;
|
||||||
dataGridViewDrivers.RowHeadersWidth = 51;
|
dataGridViewDrivers.RowHeadersWidth = 51;
|
||||||
dataGridViewDrivers.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridViewDrivers.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridViewDrivers.Size = new Size(639, 367);
|
dataGridViewDrivers.Size = new Size(648, 367);
|
||||||
dataGridViewDrivers.TabIndex = 3;
|
dataGridViewDrivers.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// panelFormDriversButtons
|
// panelFormDriversButtons
|
||||||
@ -61,7 +61,7 @@
|
|||||||
panelFormDriversButtons.Controls.Add(buttonDeleteDriver);
|
panelFormDriversButtons.Controls.Add(buttonDeleteDriver);
|
||||||
panelFormDriversButtons.Controls.Add(buttonAddDriver);
|
panelFormDriversButtons.Controls.Add(buttonAddDriver);
|
||||||
panelFormDriversButtons.Dock = DockStyle.Right;
|
panelFormDriversButtons.Dock = DockStyle.Right;
|
||||||
panelFormDriversButtons.Location = new Point(639, 0);
|
panelFormDriversButtons.Location = new Point(648, 0);
|
||||||
panelFormDriversButtons.Name = "panelFormDriversButtons";
|
panelFormDriversButtons.Name = "panelFormDriversButtons";
|
||||||
panelFormDriversButtons.Size = new Size(161, 367);
|
panelFormDriversButtons.Size = new Size(161, 367);
|
||||||
panelFormDriversButtons.TabIndex = 2;
|
panelFormDriversButtons.TabIndex = 2;
|
||||||
@ -103,7 +103,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 367);
|
ClientSize = new Size(809, 367);
|
||||||
Controls.Add(dataGridViewDrivers);
|
Controls.Add(dataGridViewDrivers);
|
||||||
Controls.Add(panelFormDriversButtons);
|
Controls.Add(panelFormDriversButtons);
|
||||||
Name = "FormDrivers";
|
Name = "FormDrivers";
|
||||||
|
@ -105,8 +105,7 @@ namespace ProjectGarage.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
id =
|
id = Convert.ToInt32(dataGridViewDrivers.SelectedRows[0].Cells["Id"].Value);
|
||||||
Convert.ToInt32(dataGridViewDrivers.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace ProjectGarage.Forms
|
|||||||
public partial class FormFuel : Form
|
public partial class FormFuel : Form
|
||||||
{
|
{
|
||||||
private readonly IFuelRepository _fuelRepository;
|
private readonly IFuelRepository _fuelRepository;
|
||||||
|
|
||||||
private int? _fuelId;
|
private int? _fuelId;
|
||||||
|
|
||||||
public int Id
|
public int Id
|
||||||
@ -39,6 +40,7 @@ namespace ProjectGarage.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
textBoxFuelName.Text = fuel.FuelName;
|
textBoxFuelName.Text = fuel.FuelName;
|
||||||
|
numericUpDownFuelPrice.Value = fuel.Price;
|
||||||
_fuelId = value;
|
_fuelId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -25,10 +25,10 @@ namespace ProjectGarage.Forms
|
|||||||
_replenishmentRepository = replenishmentRepository ??
|
_replenishmentRepository = replenishmentRepository ??
|
||||||
throw new ArgumentNullException(nameof(replenishmentRepository));
|
throw new ArgumentNullException(nameof(replenishmentRepository));
|
||||||
comboBoxReplenishmentDriver.DataSource = driverRepository.ReadDrivers();
|
comboBoxReplenishmentDriver.DataSource = driverRepository.ReadDrivers();
|
||||||
comboBoxReplenishmentDriver.DisplayMember = "First_name";
|
comboBoxReplenishmentDriver.DisplayMember = "Fname";
|
||||||
comboBoxReplenishmentDriver.ValueMember = "Id";
|
comboBoxReplenishmentDriver.ValueMember = "Id";
|
||||||
ColumnFuel.DataSource = fuelRepository.ReadFuels();
|
ColumnFuel.DataSource = fuelRepository.ReadFuels();
|
||||||
ColumnFuel.DisplayMember = "Name";
|
ColumnFuel.DisplayMember = "FuelName";
|
||||||
ColumnFuel.ValueMember = "Id";
|
ColumnFuel.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +58,13 @@ namespace ProjectGarage.Forms
|
|||||||
var list = new List<FuelFuelReplenishment>();
|
var list = new List<FuelFuelReplenishment>();
|
||||||
foreach (DataGridViewRow row in dataGridViewReplenishment.Rows)
|
foreach (DataGridViewRow row in dataGridViewReplenishment.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColumnFeed"].Value == null ||
|
if (row.Cells["ColumnFuel"].Value == null ||
|
||||||
row.Cells["ColumnCount"].Value == null)
|
row.Cells["ColumnAmount"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list.Add(FuelFuelReplenishment.CreateElement(0, Convert.ToInt32(row.Cells["ColumnFeed"].Value),
|
list.Add(FuelFuelReplenishment.CreateElement(0, Convert.ToInt32(row.Cells["ColumnFuel"].Value),
|
||||||
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
Convert.ToInt32(row.Cells["ColumnAmount"].Value)));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ namespace ProjectGarage.Forms
|
|||||||
throw new InvalidDataException(nameof(route));
|
throw new InvalidDataException(nameof(route));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textBoxRouteName.Text = route.RouteName;
|
||||||
textBoxRouteStart.Text = route.StartP;
|
textBoxRouteStart.Text = route.StartP;
|
||||||
textBoxRouteFinal.Text = route.FinalP;
|
textBoxRouteFinal.Text = route.FinalP;
|
||||||
numericUpDownRouteLen.Value = route.Length;
|
numericUpDownRouteLen.Value = route.Length;
|
||||||
|
@ -53,21 +53,30 @@ namespace ProjectGarage.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ButtonUpdateRoute_Click(object sender, EventArgs e)
|
private void ButtonDeleteRoute_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_container.Resolve<FormRoute>().ShowDialog();
|
_routeRepository.DeleteRoute(findId);
|
||||||
LoadList();
|
LoadList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonDeleteRoute_Click(object sender, EventArgs e)
|
private void ButtonUpdateRoute_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ namespace ProjectGarage
|
|||||||
container.RegisterType<IRouteRepository, RouteRepository>();
|
container.RegisterType<IRouteRepository, RouteRepository>();
|
||||||
container.RegisterType<IDriverRepository, DriverRepository>();
|
container.RegisterType<IDriverRepository, DriverRepository>();
|
||||||
container.RegisterType<ITransportationRepository, TransportationRepository>();
|
container.RegisterType<ITransportationRepository, TransportationRepository>();
|
||||||
container.RegisterType<IReplenishmentRepository, FuelReplishmentRepository>();
|
container.RegisterType<IReplenishmentRepository, ReplenishmentRepository>();
|
||||||
|
|
||||||
container.RegisterType<IConnectionString, ConnectionString>();
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
|
@ -47,17 +47,17 @@ INSERT INTO driver (Fname, Lname, TruckId) VALUES
|
|||||||
public void UpdateDriver(Driver driver)
|
public void UpdateDriver(Driver driver)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Редактирование объекта");
|
_logger.LogInformation("Редактирование объекта");
|
||||||
_logger.LogDebug("Объект: {json}",
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver));
|
||||||
JsonConvert.SerializeObject(driver));
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE driver
|
UPDATE driver
|
||||||
SET
|
SET
|
||||||
Fname=@Fname,
|
Fname=@Fname,
|
||||||
Lname=@Lname,
|
Lname=@Lname,
|
||||||
TruckId=@TruckId
|
TruckId=@TruckId
|
||||||
WHERE Id=@Id";
|
WHERE Id=@Id";
|
||||||
connection.Execute(queryUpdate, driver);
|
connection.Execute(queryUpdate, driver);
|
||||||
}
|
}
|
||||||
|
@ -53,9 +53,9 @@ INSERT INTO fuel (FuelName, FuelType, Price) VALUES
|
|||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE fuel
|
UPDATE fuel
|
||||||
SET
|
SET
|
||||||
FuelName=@FuelName,
|
FuelName=@FuelName,
|
||||||
FuelType=@Startp,
|
FuelType=@FuelType,
|
||||||
Price=@Price
|
Price=@Price
|
||||||
WHERE Id=@Id";
|
WHERE Id=@Id";
|
||||||
connection.Execute(queryUpdate, fuel);
|
connection.Execute(queryUpdate, fuel);
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,101 @@
|
|||||||
using ProjectGarage.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectGarage.Entities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ProjectGarage.Repositories.Implementations;
|
namespace ProjectGarage.Repositories.Implementations;
|
||||||
|
|
||||||
public class FuelReplishmentRepository : IReplenishmentRepository
|
public class ReplenishmentRepository : IReplenishmentRepository
|
||||||
{
|
{
|
||||||
public void CreateFuelReplenishment(FuelReplenishment fuelReplenishment)
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<ReplenishmentRepository> _logger;
|
||||||
|
|
||||||
|
public ReplenishmentRepository(IConnectionString connectionString, ILogger<ReplenishmentRepository> logger)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
public void CreateFuelReplenishment(FuelReplenishment replenishment)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(replenishment));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO fuelreplenishment (DriverId, ReplenishmentDate)
|
||||||
|
VALUES (@DriverId, @ReplenishmentDate);
|
||||||
|
SELECT MAX(Id) FROM fuelreplenishment";
|
||||||
|
var ReplenishmentId = connection.QueryFirst<int>(queryInsert, replenishment, transaction);
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO fuel_fuelreplenishment (ReplenishmentId, FuelId, Amount)
|
||||||
|
VALUES (@ReplenishmentId, @FuelId, @Amount)";
|
||||||
|
foreach (var elem in replenishment.FuelFuelReplenishments)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
ReplenishmentId,
|
||||||
|
elem.FuelId,
|
||||||
|
elem.Amount
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFuelReplenishment(int id)
|
public void DeleteFuelReplenishment(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM fuelreplenishment
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<FuelReplenishment> ReadFuelReplenishment(DateTime? dateForm = null, DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null)
|
public IEnumerable<FuelReplenishment> ReadFuelReplenishment(DateTime? dateForm = null,
|
||||||
|
DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM fuelreplenishment";
|
||||||
|
var replenishments = connection.Query<FuelReplenishment>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(replenishments));
|
||||||
|
return replenishments;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user