лаба 2 готова
This commit is contained in:
parent
07835de7ef
commit
7110647bdd
@ -6,16 +6,16 @@ public class Bus
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public string LicensePlate { get; private set; } = string.Empty;
|
public string Licence_plate { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public string Model { get; private set; } = string.Empty;
|
public string Model { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static Bus CreateEntity(int id, string licensePlate, string model)
|
public static Bus CreateEntity(int id, string licencePlate, string model)
|
||||||
{
|
{
|
||||||
return new Bus
|
return new Bus
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
LicensePlate = licensePlate,
|
Licence_plate = licencePlate,
|
||||||
Model = model
|
Model = model
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ public class Employee
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public string FirstName { get; private set; } = string.Empty;
|
public string First_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public string LastName { get; private set; } = string.Empty;
|
public string Last_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public EmployeePost Post { get; private set; }
|
public EmployeePost Post { get; private set; }
|
||||||
|
|
||||||
@ -17,8 +17,8 @@ public class Employee
|
|||||||
return new Employee
|
return new Employee
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
FirstName = first ?? string.Empty,
|
First_name = first ?? string.Empty,
|
||||||
LastName = last ?? string.Empty,
|
Last_name = last ?? string.Empty,
|
||||||
Post = post
|
Post = post
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ public class GoToService
|
|||||||
|
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
public BrokenElements BrokenElements { get; private set; }
|
public BrokenElements Broken_elements { get; private set; }
|
||||||
|
|
||||||
public int Price { get; private set; }
|
public int Price { get; private set; }
|
||||||
|
|
||||||
public int BusId { get; private set; }
|
public int Bus_id { get; private set; }
|
||||||
|
|
||||||
public static GoToService CreateOperation(int id, BrokenElements brokenElements, int price, int busId)
|
public static GoToService CreateOperation(int id, BrokenElements brokenElements, int price, int busId)
|
||||||
{
|
{
|
||||||
@ -20,9 +20,9 @@ public class GoToService
|
|||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Date = DateTime.Now,
|
Date = DateTime.Now,
|
||||||
BrokenElements = brokenElements,
|
Broken_elements = brokenElements,
|
||||||
Price = price,
|
Price = price,
|
||||||
BusId = busId
|
Bus_id = busId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,17 @@ public class RouteList
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public TimeOnly Start { get; private set; }
|
public TimeSpan Route_start { get; private set; }
|
||||||
|
|
||||||
public TimeOnly Finish { get; private set; }
|
public TimeSpan Route_finish { get; private set; }
|
||||||
|
|
||||||
public static RouteList CreateEntity(int id, TimeOnly start, TimeOnly finish)
|
public static RouteList CreateEntity(int id, TimeSpan start, TimeSpan finish)
|
||||||
{
|
{
|
||||||
return new RouteList
|
return new RouteList
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Start = start,
|
Route_start = start,
|
||||||
Finish = finish
|
Route_finish = finish
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@ public class StartingShift
|
|||||||
|
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
public int RouteListId { get; private set; }
|
public int Route_list_id { get; private set; }
|
||||||
|
|
||||||
public int BusId { get; private set; }
|
public int Bus_id { get; private set; }
|
||||||
|
|
||||||
public IEnumerable<StartingShiftEmployee> StartingShiftEmployees { get; private set; } = [];
|
public IEnumerable<StartingShiftEmployee> Starting_shift_employees { get; private set; } = [];
|
||||||
|
|
||||||
public static StartingShift CreateOperation(int id, int routeListId, int busId,
|
public static StartingShift CreateOperation(int id, int routeListId, int busId,
|
||||||
IEnumerable<StartingShiftEmployee> startingShiftEmployees)
|
IEnumerable<StartingShiftEmployee> startingShiftEmployees)
|
||||||
@ -19,9 +19,9 @@ public class StartingShift
|
|||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Date = DateTime.Now,
|
Date = DateTime.Now,
|
||||||
RouteListId = routeListId,
|
Route_list_id = routeListId,
|
||||||
BusId = busId,
|
Bus_id = busId,
|
||||||
StartingShiftEmployees = startingShiftEmployees
|
Starting_shift_employees = startingShiftEmployees
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
public class StartingShiftEmployee
|
public class StartingShiftEmployee
|
||||||
{
|
{
|
||||||
public int StartingShiftId { get; private set; }
|
public int Starting_shift_id { get; private set; }
|
||||||
|
|
||||||
public int EmployeeId { get; private set; }
|
public int Employee_id { get; private set; }
|
||||||
|
|
||||||
public int WorkHours { get; private set; }
|
public int Work_time { get; private set; }
|
||||||
|
|
||||||
public static StartingShiftEmployee CreateElement(int startingShiftId, int employeeId, int workHours)
|
public static StartingShiftEmployee CreateElement(int startingShiftId, int employeeId, int workTime)
|
||||||
{
|
{
|
||||||
return new StartingShiftEmployee
|
return new StartingShiftEmployee
|
||||||
{
|
{
|
||||||
StartingShiftId = startingShiftId,
|
Starting_shift_id = startingShiftId,
|
||||||
EmployeeId = employeeId,
|
Employee_id = employeeId,
|
||||||
WorkHours = workHours
|
Work_time = workTime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,30 +28,30 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
labelLicensePlate = new Label();
|
labelLicencePlate = new Label();
|
||||||
textBoxLicensePlate = new TextBox();
|
textBoxLicencePlate = new TextBox();
|
||||||
labelBusTypeName = new Label();
|
labelBusTypeName = new Label();
|
||||||
buttonSave = new Button();
|
buttonSave = new Button();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
textBoxModel = new TextBox();
|
textBoxModel = new TextBox();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// labelLicensePlate
|
// labelLicencePlate
|
||||||
//
|
//
|
||||||
labelLicensePlate.AutoSize = true;
|
labelLicencePlate.AutoSize = true;
|
||||||
labelLicensePlate.Location = new Point(27, 34);
|
labelLicencePlate.Location = new Point(27, 34);
|
||||||
labelLicensePlate.Name = "labelLicensePlate";
|
labelLicencePlate.Name = "labelLicencePlate";
|
||||||
labelLicensePlate.Size = new Size(107, 30);
|
labelLicencePlate.Size = new Size(107, 30);
|
||||||
labelLicensePlate.TabIndex = 0;
|
labelLicencePlate.TabIndex = 0;
|
||||||
labelLicensePlate.Text = "Госномер";
|
labelLicencePlate.Text = "Госномер";
|
||||||
//
|
//
|
||||||
// textBoxLicensePlate
|
// textBoxLicencePlate
|
||||||
//
|
//
|
||||||
textBoxLicensePlate.Location = new Point(231, 31);
|
textBoxLicencePlate.Location = new Point(231, 31);
|
||||||
textBoxLicensePlate.MaxLength = 10;
|
textBoxLicencePlate.MaxLength = 10;
|
||||||
textBoxLicensePlate.Name = "textBoxLicensePlate";
|
textBoxLicencePlate.Name = "textBoxLicencePlate";
|
||||||
textBoxLicensePlate.Size = new Size(240, 35);
|
textBoxLicencePlate.Size = new Size(240, 35);
|
||||||
textBoxLicensePlate.TabIndex = 1;
|
textBoxLicencePlate.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// labelBusTypeName
|
// labelBusTypeName
|
||||||
//
|
//
|
||||||
@ -101,8 +101,8 @@
|
|||||||
Controls.Add(buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
Controls.Add(buttonSave);
|
Controls.Add(buttonSave);
|
||||||
Controls.Add(labelBusTypeName);
|
Controls.Add(labelBusTypeName);
|
||||||
Controls.Add(textBoxLicensePlate);
|
Controls.Add(textBoxLicencePlate);
|
||||||
Controls.Add(labelLicensePlate);
|
Controls.Add(labelLicencePlate);
|
||||||
Name = "FormBus";
|
Name = "FormBus";
|
||||||
StartPosition = FormStartPosition.CenterParent;
|
StartPosition = FormStartPosition.CenterParent;
|
||||||
Text = "Автобус";
|
Text = "Автобус";
|
||||||
@ -112,8 +112,8 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Label labelLicensePlate;
|
private Label labelLicencePlate;
|
||||||
private TextBox textBoxLicensePlate;
|
private TextBox textBoxLicencePlate;
|
||||||
private Label labelBusTypeName;
|
private Label labelBusTypeName;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using ProjectPassengerTransportation.Entities;
|
using ProjectPassengerTransportation.Entities;
|
||||||
using ProjectPassengerTransportation.Entities.Enums;
|
|
||||||
using ProjectPassengerTransportation.Repositories;
|
using ProjectPassengerTransportation.Repositories;
|
||||||
|
|
||||||
namespace ProjectPassengerTransportation.Forms
|
namespace ProjectPassengerTransportation.Forms
|
||||||
@ -22,8 +21,8 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
throw new InvalidDataException(nameof(bus));
|
throw new InvalidDataException(nameof(bus));
|
||||||
}
|
}
|
||||||
|
|
||||||
textBoxLicensePlate.Text = bus.LicensePlate;
|
textBoxLicencePlate.Text = bus.Licence_plate;
|
||||||
comboBoxBusType.SelectedItem = bus.Model;
|
textBoxModel.Text = bus.Model;
|
||||||
_busId = value;
|
_busId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -44,7 +43,7 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
|
if (string.IsNullOrWhiteSpace(textBoxLicencePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
@ -68,6 +67,6 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
private Bus CreateBus(int id) => Bus.CreateEntity(id, textBoxLicensePlate.Text, textBoxModel.Text);
|
private Bus CreateBus(int id) => Bus.CreateEntity(id, textBoxLicencePlate.Text, textBoxModel.Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
throw new InvalidDataException(nameof(employee));
|
throw new InvalidDataException(nameof(employee));
|
||||||
}
|
}
|
||||||
|
|
||||||
textBoxFirstName.Text = employee.FirstName;
|
textBoxFirstName.Text = employee.First_name;
|
||||||
textBoxLastName.Text = employee.LastName;
|
textBoxLastName.Text = employee.Last_name;
|
||||||
comboBoxPost.SelectedItem = employee.Post;
|
comboBoxPost.SelectedItem = employee.Post;
|
||||||
_employeeId = value;
|
_employeeId = value;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@
|
|||||||
// numericUpDownPrice
|
// numericUpDownPrice
|
||||||
//
|
//
|
||||||
numericUpDownPrice.Location = new Point(168, 310);
|
numericUpDownPrice.Location = new Point(168, 310);
|
||||||
|
numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
|
||||||
numericUpDownPrice.Name = "numericUpDownPrice";
|
numericUpDownPrice.Name = "numericUpDownPrice";
|
||||||
numericUpDownPrice.Size = new Size(245, 35);
|
numericUpDownPrice.Size = new Size(245, 35);
|
||||||
numericUpDownPrice.TabIndex = 21;
|
numericUpDownPrice.TabIndex = 21;
|
||||||
|
@ -13,7 +13,7 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_goToServiceRepository = goToServiceRepository ?? throw new ArgumentNullException(nameof(goToServiceRepository));
|
_goToServiceRepository = goToServiceRepository ?? throw new ArgumentNullException(nameof(goToServiceRepository));
|
||||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||||
comboBoxBus.DisplayMember = "LicensePlate";
|
comboBoxBus.DisplayMember = "Licence_plate";
|
||||||
comboBoxBus.ValueMember = "Id";
|
comboBoxBus.ValueMember = "Id";
|
||||||
foreach (var elem in Enum.GetValues(typeof(BrokenElements)))
|
foreach (var elem in Enum.GetValues(typeof(BrokenElements)))
|
||||||
{
|
{
|
||||||
|
@ -21,10 +21,10 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
throw new InvalidDataException(nameof(routeList));
|
throw new InvalidDataException(nameof(routeList));
|
||||||
}
|
}
|
||||||
|
|
||||||
numericUpDownStartHour.Value = routeList.Start.Hour;
|
numericUpDownStartHour.Value = (decimal)routeList.Route_start.Hours;
|
||||||
numericUpDownStartMin.Value = routeList.Start.Minute;
|
numericUpDownStartMin.Value = (decimal)routeList.Route_start.Minutes;
|
||||||
numericUpDownFinishHour.Value = routeList.Finish.Hour;
|
numericUpDownFinishHour.Value = (decimal)routeList.Route_finish.Hours;
|
||||||
numericUpDownFinishMin.Value = routeList.Finish.Minute;
|
numericUpDownFinishMin.Value = (decimal)routeList.Route_finish.Minutes;
|
||||||
_routeListId = value;
|
_routeListId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -65,7 +65,7 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
private RouteList CreateRouteList(int id) => RouteList.CreateEntity(id,
|
private RouteList CreateRouteList(int id) => RouteList.CreateEntity(id,
|
||||||
new TimeOnly(Convert.ToInt32(numericUpDownStartHour.Value), Convert.ToInt32(numericUpDownStartMin.Value)),
|
new TimeSpan(Convert.ToInt32(numericUpDownStartHour.Value), Convert.ToInt32(numericUpDownStartMin.Value), 0),
|
||||||
new TimeOnly(Convert.ToInt32(numericUpDownFinishHour.Value), Convert.ToInt32(numericUpDownFinishMin.Value)));
|
new TimeSpan(Convert.ToInt32(numericUpDownFinishHour.Value), Convert.ToInt32(numericUpDownFinishMin.Value), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,10 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
comboBoxRouteList.DisplayMember = "Id";
|
comboBoxRouteList.DisplayMember = "Id";
|
||||||
comboBoxRouteList.ValueMember = "Id";
|
comboBoxRouteList.ValueMember = "Id";
|
||||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||||
comboBoxBus.DisplayMember = "LicensePlate";
|
comboBoxBus.DisplayMember = "Licence_plate";
|
||||||
comboBoxBus.ValueMember = "Id";
|
comboBoxBus.ValueMember = "Id";
|
||||||
ColumnEmployees.DataSource = employeeRepository.ReadEmployees();
|
ColumnEmployees.DataSource = employeeRepository.ReadEmployees();
|
||||||
ColumnEmployees.DisplayMember = "FirstName";
|
ColumnEmployees.DisplayMember = "First_name";
|
||||||
ColumnEmployees.ValueMember = "Id";
|
ColumnEmployees.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
var list = new List<StartingShiftEmployee>();
|
var list = new List<StartingShiftEmployee>();
|
||||||
foreach (DataGridViewRow row in dataGridViewEmployees.Rows)
|
foreach (DataGridViewRow row in dataGridViewEmployees.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColumnFeed"].Value == null ||
|
if (row.Cells["ColumnEmployees"].Value == null ||
|
||||||
row.Cells["ColumnCount"].Value == null)
|
row.Cells["ColumnWorkHours"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -51,16 +51,16 @@
|
|||||||
dataGridViewData.RowHeadersVisible = false;
|
dataGridViewData.RowHeadersVisible = false;
|
||||||
dataGridViewData.RowHeadersWidth = 72;
|
dataGridViewData.RowHeadersWidth = 72;
|
||||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridViewData.Size = new Size(845, 481);
|
dataGridViewData.Size = new Size(1280, 636);
|
||||||
dataGridViewData.TabIndex = 5;
|
dataGridViewData.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// panelButtons
|
// panelButtons
|
||||||
//
|
//
|
||||||
panelButtons.Controls.Add(buttonAdd);
|
panelButtons.Controls.Add(buttonAdd);
|
||||||
panelButtons.Dock = DockStyle.Right;
|
panelButtons.Dock = DockStyle.Right;
|
||||||
panelButtons.Location = new Point(845, 0);
|
panelButtons.Location = new Point(1280, 0);
|
||||||
panelButtons.Name = "panelButtons";
|
panelButtons.Name = "panelButtons";
|
||||||
panelButtons.Size = new Size(196, 481);
|
panelButtons.Size = new Size(196, 636);
|
||||||
panelButtons.TabIndex = 4;
|
panelButtons.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
@ -78,7 +78,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
AutoScaleDimensions = new SizeF(12F, 30F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1041, 481);
|
ClientSize = new Size(1476, 636);
|
||||||
Controls.Add(dataGridViewData);
|
Controls.Add(dataGridViewData);
|
||||||
Controls.Add(panelButtons);
|
Controls.Add(panelButtons);
|
||||||
Name = "FormStartingShifts";
|
Name = "FormStartingShifts";
|
||||||
|
@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using ProjectPassengerTransportation.Entities;
|
using ProjectPassengerTransportation.Entities;
|
||||||
using System.Data.SqlClient;
|
|
||||||
|
|
||||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
@ -23,13 +22,13 @@ public class BusRepository : IBusRepository
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Добавление объекта");
|
_logger.LogInformation("Добавление объекта");
|
||||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO bus (licence_plate, bus_type_id)
|
INSERT INTO bus (licence_plate, model)
|
||||||
VALUES (@LicencePlate, @Type)";
|
VALUES (@Licence_plate, @Model)";
|
||||||
connection.Execute(queryInsert, bus);
|
connection.Execute(queryInsert, bus);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -50,8 +49,8 @@ VALUES (@LicencePlate, @Type)";
|
|||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE bus
|
UPDATE bus
|
||||||
SET
|
SET
|
||||||
licence_plate=@LicencePlate,
|
licence_plate=@Licence_plate,
|
||||||
bus_type_id=@Type
|
model=@Model
|
||||||
WHERE id=@Id";
|
WHERE id=@Id";
|
||||||
connection.Execute(queryUpdate, bus);
|
connection.Execute(queryUpdate, bus);
|
||||||
}
|
}
|
||||||
@ -82,18 +81,18 @@ WHERE id=@id";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bus ReadBusById(int id)
|
public Bus ReadBusById(int busId)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение объекта по идентификатору");
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
_logger.LogDebug("Объект: {id}", id);
|
_logger.LogDebug("Объект: {id}", busId);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @"
|
||||||
SELECT * FROM bus
|
SELECT * FROM bus
|
||||||
WHERE [id]=@id";
|
WHERE id=@busId";
|
||||||
var bus = connection.QueryFirst<Bus>(querySelect, new { id });
|
var bus = connection.QueryFirst<Bus>(querySelect, new { busId });
|
||||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus));
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus));
|
||||||
|
|
||||||
return bus;
|
return bus;
|
||||||
@ -111,7 +110,7 @@ WHERE [id]=@id";
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM bus";
|
var querySelect = @"SELECT * FROM bus";
|
||||||
var buses = connection.Query<Bus>(querySelect);
|
var buses = connection.Query<Bus>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(buses));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(buses));
|
||||||
return buses;
|
return buses;
|
||||||
|
@ -1,32 +1,125 @@
|
|||||||
using ProjectPassengerTransportation.Entities;
|
using Dapper;
|
||||||
using ProjectPassengerTransportation.Entities.Enums;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPassengerTransportation.Entities;
|
||||||
|
|
||||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
public class EmployeeRepository : IEmployeeRepository
|
public class EmployeeRepository : IEmployeeRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<EmployeeRepository> _logger;
|
||||||
|
|
||||||
|
public EmployeeRepository(IConnectionString connectionString, ILogger<EmployeeRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateEmployee(Employee employee)
|
public void CreateEmployee(Employee employee)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
}
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||||
|
|
||||||
public void DeleteEmployee(int id)
|
try
|
||||||
{
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
}
|
var queryInsert = @"
|
||||||
|
INSERT INTO employee (first_name, last_name, post)
|
||||||
public Employee ReadEmployeeById(int employeeId)
|
VALUES (@First_name, @Last_name, @Post)";
|
||||||
{
|
connection.Execute(queryInsert, employee);
|
||||||
return Employee.CreateEntity(0, string.Empty, string.Empty, EmployeePost.None);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
|
{
|
||||||
public IEnumerable<Employee> ReadEmployees()
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
{
|
throw;
|
||||||
return [];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateEmployee(Employee employee)
|
public void UpdateEmployee(Employee employee)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE employee
|
||||||
|
SET
|
||||||
|
first_name=@First_name,
|
||||||
|
last_name=@Last_name,
|
||||||
|
post=@Post
|
||||||
|
WHERE id=@Id";
|
||||||
|
connection.Execute(queryUpdate, employee);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteEmployee(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM employee
|
||||||
|
WHERE id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Employee ReadEmployeeById(int employeeId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", employeeId);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM employee
|
||||||
|
WHERE id=@employeeId";
|
||||||
|
var employee = connection.QueryFirst<Employee>(querySelect, new { employeeId });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(employee));
|
||||||
|
|
||||||
|
return employee;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Employee> ReadEmployees()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM employee";
|
||||||
|
var employees = connection.Query<Employee>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(employees));
|
||||||
|
return employees;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,80 @@
|
|||||||
using ProjectPassengerTransportation.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPassengerTransportation.Entities;
|
||||||
using ProjectPassengerTransportation.Entities.Enums;
|
using ProjectPassengerTransportation.Entities.Enums;
|
||||||
|
|
||||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
public class GoToServiceRepository : IGoToServiceRepository
|
public class GoToServiceRepository : IGoToServiceRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<GoToServiceRepository> _logger;
|
||||||
|
|
||||||
|
public GoToServiceRepository(IConnectionString connectionString, ILogger<GoToServiceRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateGoToService(GoToService goToService)
|
public void CreateGoToService(GoToService goToService)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(goToService));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO go_to_service (date, price, bus_id, broken_elements)
|
||||||
|
VALUES (@Date, @Price, @Bus_id, @Broken_elements)";
|
||||||
|
connection.Execute(queryInsert, goToService);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteGoToService(int id)
|
public void DeleteGoToService(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM go_to_service
|
||||||
|
WHERE id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null, BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null)
|
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
|
BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM go_to_service";
|
||||||
|
var services = connection.Query<GoToService>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,125 @@
|
|||||||
using ProjectPassengerTransportation.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPassengerTransportation.Entities;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
public class RouteListRepository : IRouteListRepository
|
public class RouteListRepository : IRouteListRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<RouteListRepository> _logger;
|
||||||
|
|
||||||
|
public RouteListRepository(IConnectionString connectionString, ILogger<RouteListRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateRouteList(RouteList routeList)
|
public void CreateRouteList(RouteList routeList)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
}
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||||
|
|
||||||
public void DeleteRouteList(int id)
|
try
|
||||||
{
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
}
|
var queryInsert = @"
|
||||||
|
INSERT INTO route_list (route_start, route_finish)
|
||||||
public RouteList ReadRouteListById(int routeListId)
|
VALUES (@Route_start, @Route_finish)";
|
||||||
{
|
connection.Execute(queryInsert, routeList);
|
||||||
return RouteList.CreateEntity(0, new TimeOnly(0, 0), new TimeOnly(0, 0));
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
|
{
|
||||||
public IEnumerable<RouteList> ReadRouteLists()
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
{
|
throw;
|
||||||
return [];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRouteList(RouteList routeList)
|
public void UpdateRouteList(RouteList routeList)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE route_list
|
||||||
|
SET
|
||||||
|
route_start=@Route_start,
|
||||||
|
route_finish=@Route_finish
|
||||||
|
WHERE id=@Id";
|
||||||
|
connection.Execute(queryUpdate, routeList);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteRouteList(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM route_list
|
||||||
|
WHERE id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RouteList ReadRouteListById(int routeListId)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", routeListId);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM route_list
|
||||||
|
WHERE id=@routeListId";
|
||||||
|
var routeList = connection.QueryFirst<RouteList>(querySelect, new { routeListId });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||||
|
|
||||||
|
return routeList;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<RouteList> ReadRouteLists()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM route_list";
|
||||||
|
var routeLists = connection.Query<RouteList>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routeLists));
|
||||||
|
return routeLists;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,70 @@
|
|||||||
using ProjectPassengerTransportation.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPassengerTransportation.Entities;
|
||||||
|
|
||||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
public class StartingShiftRepository : IStartingShiftRepository
|
public class StartingShiftRepository : IStartingShiftRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<StartingShiftRepository> _logger;
|
||||||
|
|
||||||
|
public StartingShiftRepository(IConnectionString connectionString, ILogger<StartingShiftRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateStartingShift(StartingShift startingShift)
|
public void CreateStartingShift(StartingShift startingShift)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(startingShift));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO starting_shift (date, route_list_id, bus_id)
|
||||||
|
VALUES (@Date, @Route_list_id, @Bus_id);
|
||||||
|
SELECT MAX(Id) FROM starting_shift";
|
||||||
|
var starting_shift_id = connection.QueryFirst<int>(queryInsert, startingShift, transaction);
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO starting_shift_employee (starting_shift_id, employee_id, work_time)
|
||||||
|
VALUES (@Starting_shift_id, @Employee_id, @Work_time)";
|
||||||
|
foreach (var elem in startingShift.Starting_shift_employees)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new { starting_shift_id, elem.Employee_id, elem.Work_time }, transaction);
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
int? routeListId = null, int? employeeId = null, int? busId = null)
|
int? routeListId = null, int? employeeId = null, int? busId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM starting_shift";
|
||||||
|
var startingShifts = connection.Query<StartingShift>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts));
|
||||||
|
return startingShifts;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user