Вроде готово
This commit is contained in:
parent
922fe3c585
commit
c2dca0a3b6
23
ProjectTransportation/ProjectTransportation/Entities/Bus.cs
Normal file
23
ProjectTransportation/ProjectTransportation/Entities/Bus.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
public class Bus
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string Licence_plate { get; private set; } = string.Empty;
|
||||
public string Model { get; private set; } = string.Empty;
|
||||
|
||||
public static Bus CreateEntity(int id, string licencePlate, string model)
|
||||
{
|
||||
return new Bus
|
||||
{
|
||||
Id = id,
|
||||
Licence_plate = licencePlate,
|
||||
Model = model
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities;
|
||||
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
public class Employee
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string First_name { get; private set; } = string.Empty;
|
||||
|
||||
public string Last_name { get; private set; } = string.Empty;
|
||||
|
||||
public EmployeePost Post { get; private set; }
|
||||
|
||||
public static Employee CreateEntity(int id, string first, string last, EmployeePost post)
|
||||
{
|
||||
return new Employee
|
||||
{
|
||||
Id = id,
|
||||
First_name = first ?? string.Empty,
|
||||
Last_name = last ?? string.Empty,
|
||||
Post = post
|
||||
};
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
namespace ProjectTransportation.Entities.Enums;
|
||||
|
||||
public class Bus
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string LicensePlate { get; private set; } = string.Empty;
|
||||
|
||||
public string Model { get; private set; } = string.Empty;
|
||||
|
||||
public static Bus CreateEntity(int id, string licensePlate, string model)
|
||||
{
|
||||
return new Bus
|
||||
{
|
||||
Id = id,
|
||||
LicensePlate = licensePlate,
|
||||
Model = model
|
||||
};
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
namespace ProjectTransportation.Entities.Enums;
|
||||
|
||||
public class Employee
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string FirstName { get; private set; } = string.Empty;
|
||||
|
||||
public string LastName { get; private set; } = string.Empty;
|
||||
|
||||
public EmployeePost Post { get; private set; }
|
||||
|
||||
public static Employee CreateEntity(int id, string first, string last, EmployeePost post)
|
||||
{
|
||||
return new Employee
|
||||
{
|
||||
Id = id,
|
||||
FirstName = first ?? string.Empty,
|
||||
LastName = last ?? string.Empty,
|
||||
Post = post
|
||||
};
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTransportation.Entities.Enums;
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
public enum EmployeePost
|
||||
{
|
||||
|
@ -1,15 +1,19 @@
|
||||
namespace ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
public class GoToService
|
||||
{
|
||||
public int Id { 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 BusId { get; private set; }
|
||||
public int Bus_id { get; private set; }
|
||||
|
||||
public static GoToService CreateOperation(int id, BrokenElements brokenElements, int price, int busId)
|
||||
{
|
||||
@ -17,10 +21,9 @@ public class GoToService
|
||||
{
|
||||
Id = id,
|
||||
Date = DateTime.Now,
|
||||
BrokenElements = brokenElements,
|
||||
Broken_elements = brokenElements,
|
||||
Price = price,
|
||||
BusId = busId
|
||||
Bus_id = busId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
namespace ProjectTransportation.Entities;
|
||||
public class RouteList
|
||||
{
|
||||
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
|
||||
{
|
||||
Id = id,
|
||||
Start = start,
|
||||
Finish = finish
|
||||
Route_start = start,
|
||||
Route_finish = finish
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTransportation.Entities;
|
||||
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
public class StartingShift
|
||||
{
|
||||
public int Id { 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,
|
||||
IEnumerable<StartingShiftEmployee> startingShiftEmployees)
|
||||
@ -24,9 +21,9 @@ public class StartingShift
|
||||
{
|
||||
Id = id,
|
||||
Date = DateTime.Now,
|
||||
RouteListId = routeListId,
|
||||
BusId = busId,
|
||||
StartingShiftEmployees = startingShiftEmployees
|
||||
Route_list_id = routeListId,
|
||||
Bus_id = busId,
|
||||
Starting_shift_employees = startingShiftEmployees
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace ProjectTransportation.Entities;
|
||||
|
||||
namespace ProjectTransportation.Entities;
|
||||
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
|
||||
{
|
||||
StartingShiftId = startingShiftId,
|
||||
EmployeeId = employeeId,
|
||||
WorkHours = workHours
|
||||
Starting_shift_id = startingShiftId,
|
||||
Employee_id = employeeId,
|
||||
Work_time = workTime
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -32,50 +32,46 @@ namespace ProjectTransportation.Forms
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
labelLicensePlate = new Label();
|
||||
textBoxLicensePlate = new TextBox();
|
||||
labelLicencePlate = new Label();
|
||||
textBoxLicencePlate = new TextBox();
|
||||
labelBusTypeName = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
textBoxModel = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelLicensePlate
|
||||
// labelLicencePlate
|
||||
//
|
||||
labelLicensePlate.AutoSize = true;
|
||||
labelLicensePlate.Location = new Point(18, 23);
|
||||
labelLicensePlate.Margin = new Padding(2, 0, 2, 0);
|
||||
labelLicensePlate.Name = "labelLicensePlate";
|
||||
labelLicensePlate.Size = new Size(78, 20);
|
||||
labelLicensePlate.TabIndex = 0;
|
||||
labelLicensePlate.Text = "Госномер";
|
||||
labelLicencePlate.AutoSize = true;
|
||||
labelLicencePlate.Location = new Point(27, 34);
|
||||
labelLicencePlate.Name = "labelLicencePlate";
|
||||
labelLicencePlate.Size = new Size(107, 30);
|
||||
labelLicencePlate.TabIndex = 0;
|
||||
labelLicencePlate.Text = "Госномер";
|
||||
//
|
||||
// textBoxLicensePlate
|
||||
// textBoxLicencePlate
|
||||
//
|
||||
textBoxLicensePlate.Location = new Point(154, 21);
|
||||
textBoxLicensePlate.Margin = new Padding(2, 2, 2, 2);
|
||||
textBoxLicensePlate.MaxLength = 10;
|
||||
textBoxLicensePlate.Name = "textBoxLicensePlate";
|
||||
textBoxLicensePlate.Size = new Size(161, 27);
|
||||
textBoxLicensePlate.TabIndex = 1;
|
||||
textBoxLicencePlate.Location = new Point(231, 31);
|
||||
textBoxLicencePlate.MaxLength = 10;
|
||||
textBoxLicencePlate.Name = "textBoxLicencePlate";
|
||||
textBoxLicencePlate.Size = new Size(240, 35);
|
||||
textBoxLicencePlate.TabIndex = 1;
|
||||
//
|
||||
// labelBusTypeName
|
||||
//
|
||||
labelBusTypeName.AutoSize = true;
|
||||
labelBusTypeName.Location = new Point(18, 66);
|
||||
labelBusTypeName.Margin = new Padding(2, 0, 2, 0);
|
||||
labelBusTypeName.Location = new Point(27, 99);
|
||||
labelBusTypeName.Name = "labelBusTypeName";
|
||||
labelBusTypeName.Size = new Size(129, 20);
|
||||
labelBusTypeName.Size = new Size(180, 30);
|
||||
labelBusTypeName.TabIndex = 2;
|
||||
labelBusTypeName.Text = "Модель автобуса";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonSave.Location = new Point(48, 152);
|
||||
buttonSave.Margin = new Padding(2, 2, 2, 2);
|
||||
buttonSave.Location = new Point(72, 164);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(117, 33);
|
||||
buttonSave.Size = new Size(135, 50);
|
||||
buttonSave.TabIndex = 6;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
@ -84,10 +80,9 @@ namespace ProjectTransportation.Forms
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(266, 152);
|
||||
buttonCancel.Margin = new Padding(2, 2, 2, 2);
|
||||
buttonCancel.Location = new Point(284, 164);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(120, 33);
|
||||
buttonCancel.Size = new Size(135, 50);
|
||||
buttonCancel.TabIndex = 7;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -95,25 +90,23 @@ namespace ProjectTransportation.Forms
|
||||
//
|
||||
// textBoxModel
|
||||
//
|
||||
textBoxModel.Location = new Point(154, 64);
|
||||
textBoxModel.Margin = new Padding(2, 2, 2, 2);
|
||||
textBoxModel.Location = new Point(231, 96);
|
||||
textBoxModel.MaxLength = 10;
|
||||
textBoxModel.Name = "textBoxModel";
|
||||
textBoxModel.Size = new Size(161, 27);
|
||||
textBoxModel.Size = new Size(240, 35);
|
||||
textBoxModel.TabIndex = 8;
|
||||
//
|
||||
// FormBus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(444, 194);
|
||||
ClientSize = new Size(506, 226);
|
||||
Controls.Add(textBoxModel);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(labelBusTypeName);
|
||||
Controls.Add(textBoxLicensePlate);
|
||||
Controls.Add(labelLicensePlate);
|
||||
Margin = new Padding(2, 2, 2, 2);
|
||||
Controls.Add(textBoxLicencePlate);
|
||||
Controls.Add(labelLicencePlate);
|
||||
Name = "FormBus";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Автобус";
|
||||
@ -123,8 +116,8 @@ namespace ProjectTransportation.Forms
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelLicensePlate;
|
||||
private TextBox textBoxLicensePlate;
|
||||
private Label labelLicencePlate;
|
||||
private TextBox textBoxLicencePlate;
|
||||
private Label labelBusTypeName;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Repositories;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Forms
|
||||
@ -24,7 +23,7 @@ namespace ProjectTransportation.Forms
|
||||
throw new InvalidDataException(nameof(bus));
|
||||
}
|
||||
|
||||
textBoxLicensePlate.Text = bus.LicensePlate;
|
||||
textBoxLicencePlate.Text = bus.Licence_plate;
|
||||
textBoxModel.Text = bus.Model;
|
||||
_busId = value;
|
||||
}
|
||||
@ -46,7 +45,7 @@ namespace ProjectTransportation.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
|
||||
if (string.IsNullOrWhiteSpace(textBoxLicencePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
@ -70,7 +69,6 @@ namespace ProjectTransportation.Forms
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Repositories;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Forms
|
||||
@ -25,8 +25,8 @@ namespace ProjectTransportation.Forms
|
||||
throw new InvalidDataException(nameof(employee));
|
||||
}
|
||||
|
||||
textBoxFirstName.Text = employee.FirstName;
|
||||
textBoxLastName.Text = employee.LastName;
|
||||
textBoxFirstName.Text = employee.First_name;
|
||||
textBoxLastName.Text = employee.Last_name;
|
||||
comboBoxPost.SelectedItem = employee.Post;
|
||||
_employeeId = value;
|
||||
}
|
||||
|
@ -49,29 +49,26 @@ namespace ProjectTransportation.Forms
|
||||
//
|
||||
comboBoxBus.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxBus.FormattingEnabled = true;
|
||||
comboBoxBus.Location = new Point(112, 259);
|
||||
comboBoxBus.Margin = new Padding(2, 2, 2, 2);
|
||||
comboBoxBus.Location = new Point(168, 389);
|
||||
comboBoxBus.Name = "comboBoxBus";
|
||||
comboBoxBus.Size = new Size(165, 28);
|
||||
comboBoxBus.Size = new Size(245, 38);
|
||||
comboBoxBus.TabIndex = 9;
|
||||
//
|
||||
// labelBus
|
||||
//
|
||||
labelBus.AutoSize = true;
|
||||
labelBus.Location = new Point(17, 261);
|
||||
labelBus.Margin = new Padding(2, 0, 2, 0);
|
||||
labelBus.Location = new Point(25, 392);
|
||||
labelBus.Name = "labelBus";
|
||||
labelBus.Size = new Size(65, 20);
|
||||
labelBus.Size = new Size(91, 30);
|
||||
labelBus.TabIndex = 8;
|
||||
labelBus.Text = "Автобус";
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(187, 306);
|
||||
buttonCancel.Margin = new Padding(2, 2, 2, 2);
|
||||
buttonCancel.Location = new Point(241, 459);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(90, 33);
|
||||
buttonCancel.Size = new Size(135, 50);
|
||||
buttonCancel.TabIndex = 19;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -80,10 +77,9 @@ namespace ProjectTransportation.Forms
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonSave.Location = new Point(43, 306);
|
||||
buttonSave.Margin = new Padding(2, 2, 2, 2);
|
||||
buttonSave.Location = new Point(64, 459);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(99, 33);
|
||||
buttonSave.Size = new Size(135, 50);
|
||||
buttonSave.TabIndex = 18;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
@ -92,63 +88,58 @@ namespace ProjectTransportation.Forms
|
||||
// labelPrice
|
||||
//
|
||||
labelPrice.AutoSize = true;
|
||||
labelPrice.Location = new Point(17, 208);
|
||||
labelPrice.Margin = new Padding(2, 0, 2, 0);
|
||||
labelPrice.Location = new Point(25, 312);
|
||||
labelPrice.Name = "labelPrice";
|
||||
labelPrice.Size = new Size(83, 20);
|
||||
labelPrice.Size = new Size(116, 30);
|
||||
labelPrice.TabIndex = 20;
|
||||
labelPrice.Text = "Стоимость";
|
||||
//
|
||||
// numericUpDownPrice
|
||||
//
|
||||
numericUpDownPrice.Location = new Point(112, 207);
|
||||
numericUpDownPrice.Margin = new Padding(2, 2, 2, 2);
|
||||
numericUpDownPrice.Location = new Point(168, 310);
|
||||
numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
|
||||
numericUpDownPrice.Name = "numericUpDownPrice";
|
||||
numericUpDownPrice.Size = new Size(163, 27);
|
||||
numericUpDownPrice.Size = new Size(245, 35);
|
||||
numericUpDownPrice.TabIndex = 21;
|
||||
//
|
||||
// checkedListBoxBrokenElements
|
||||
//
|
||||
checkedListBoxBrokenElements.FormattingEnabled = true;
|
||||
checkedListBoxBrokenElements.Location = new Point(112, 68);
|
||||
checkedListBoxBrokenElements.Margin = new Padding(2, 2, 2, 2);
|
||||
checkedListBoxBrokenElements.Location = new Point(168, 102);
|
||||
checkedListBoxBrokenElements.Name = "checkedListBoxBrokenElements";
|
||||
checkedListBoxBrokenElements.Size = new Size(166, 92);
|
||||
checkedListBoxBrokenElements.Size = new Size(247, 164);
|
||||
checkedListBoxBrokenElements.TabIndex = 22;
|
||||
//
|
||||
// labelBrokenElement
|
||||
//
|
||||
labelBrokenElement.Location = new Point(17, 68);
|
||||
labelBrokenElement.Margin = new Padding(2, 0, 2, 0);
|
||||
labelBrokenElement.Location = new Point(25, 102);
|
||||
labelBrokenElement.Name = "labelBrokenElement";
|
||||
labelBrokenElement.Size = new Size(85, 45);
|
||||
labelBrokenElement.Size = new Size(128, 68);
|
||||
labelBrokenElement.TabIndex = 23;
|
||||
labelBrokenElement.Text = "Сломанная деталь";
|
||||
//
|
||||
// dateTimePickerServiceDate
|
||||
//
|
||||
dateTimePickerServiceDate.Enabled = false;
|
||||
dateTimePickerServiceDate.Location = new Point(112, 18);
|
||||
dateTimePickerServiceDate.Margin = new Padding(2, 2, 2, 2);
|
||||
dateTimePickerServiceDate.Location = new Point(168, 27);
|
||||
dateTimePickerServiceDate.Name = "dateTimePickerServiceDate";
|
||||
dateTimePickerServiceDate.Size = new Size(166, 27);
|
||||
dateTimePickerServiceDate.Size = new Size(247, 35);
|
||||
dateTimePickerServiceDate.TabIndex = 24;
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(17, 21);
|
||||
labelDate.Margin = new Padding(2, 0, 2, 0);
|
||||
labelDate.Location = new Point(25, 31);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(41, 20);
|
||||
labelDate.Size = new Size(59, 30);
|
||||
labelDate.TabIndex = 25;
|
||||
labelDate.Text = "Дата";
|
||||
//
|
||||
// FormGoToService
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(320, 347);
|
||||
ClientSize = new Size(441, 521);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(dateTimePickerServiceDate);
|
||||
Controls.Add(labelBrokenElement);
|
||||
@ -159,7 +150,6 @@ namespace ProjectTransportation.Forms
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(comboBoxBus);
|
||||
Controls.Add(labelBus);
|
||||
Margin = new Padding(2, 2, 2, 2);
|
||||
Name = "FormGoToService";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Тех. обслуживание";
|
||||
|
@ -1,7 +1,6 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Repositories;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Forms
|
||||
|
@ -23,10 +23,10 @@ namespace ProjectTransportation.Forms
|
||||
throw new InvalidDataException(nameof(routeList));
|
||||
}
|
||||
|
||||
numericUpDownStartHour.Value = routeList.Start.Hour;
|
||||
numericUpDownStartMin.Value = routeList.Start.Minute;
|
||||
numericUpDownFinishHour.Value = routeList.Finish.Hour;
|
||||
numericUpDownFinishMin.Value = routeList.Finish.Minute;
|
||||
numericUpDownStartHour.Value = (decimal)routeList.Route_start.Hours;
|
||||
numericUpDownStartMin.Value = (decimal)routeList.Route_start.Minutes;
|
||||
numericUpDownFinishHour.Value = (decimal)routeList.Route_finish.Hours;
|
||||
numericUpDownFinishMin.Value = (decimal)routeList.Route_finish.Minutes;
|
||||
_routeListId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -67,7 +67,7 @@ namespace ProjectTransportation.Forms
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private RouteList CreateRouteList(int id) => RouteList.CreateEntity(id,
|
||||
new TimeOnly(Convert.ToInt32(numericUpDownStartHour.Value), Convert.ToInt32(numericUpDownStartMin.Value)),
|
||||
new TimeOnly(Convert.ToInt32(numericUpDownFinishHour.Value), Convert.ToInt32(numericUpDownFinishMin.Value)));
|
||||
new TimeSpan(Convert.ToInt32(numericUpDownStartHour.Value), Convert.ToInt32(numericUpDownStartMin.Value), 0),
|
||||
new TimeSpan(Convert.ToInt32(numericUpDownFinishHour.Value), Convert.ToInt32(numericUpDownFinishMin.Value), 0));
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ namespace ProjectTransportation.Forms
|
||||
comboBoxRouteList.DisplayMember = "Id";
|
||||
comboBoxRouteList.ValueMember = "Id";
|
||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||
comboBoxBus.DisplayMember = "LicensePlate";
|
||||
comboBoxBus.DisplayMember = "Licence_plate";
|
||||
comboBoxBus.ValueMember = "Id";
|
||||
ColumnEmployees.DataSource = employeeRepository.ReadEmployees();
|
||||
ColumnEmployees.DisplayMember = "FirstName";
|
||||
ColumnEmployees.DisplayMember = "First_name";
|
||||
ColumnEmployees.ValueMember = "Id";
|
||||
}
|
||||
|
||||
@ -57,8 +57,8 @@ namespace ProjectTransportation.Forms
|
||||
var list = new List<StartingShiftEmployee>();
|
||||
foreach (DataGridViewRow row in dataGridViewEmployees.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnFeed"].Value == null ||
|
||||
row.Cells["ColumnCount"].Value == null)
|
||||
if (row.Cells["ColumnEmployees"].Value == null ||
|
||||
row.Cells["ColumnWorkHours"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -49,46 +49,42 @@ namespace ProjectTransportation.Forms
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(2, 2, 2, 2);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 72;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(740, 321);
|
||||
dataGridViewData.Size = new Size(1280, 636);
|
||||
dataGridViewData.TabIndex = 5;
|
||||
//
|
||||
// panelButtons
|
||||
//
|
||||
panelButtons.Controls.Add(buttonAdd);
|
||||
panelButtons.Dock = DockStyle.Right;
|
||||
panelButtons.Location = new Point(740, 0);
|
||||
panelButtons.Margin = new Padding(2, 2, 2, 2);
|
||||
panelButtons.Location = new Point(1280, 0);
|
||||
panelButtons.Name = "panelButtons";
|
||||
panelButtons.Size = new Size(131, 321);
|
||||
panelButtons.Size = new Size(196, 636);
|
||||
panelButtons.TabIndex = 4;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.plus;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(33, 19);
|
||||
buttonAdd.Margin = new Padding(2, 2, 2, 2);
|
||||
buttonAdd.Location = new Point(50, 29);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(67, 67);
|
||||
buttonAdd.Size = new Size(100, 100);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// FormStartingShifts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(871, 321);
|
||||
ClientSize = new Size(1476, 636);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Margin = new Padding(2, 2, 2, 2);
|
||||
Name = "FormStartingShifts";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Смены";
|
||||
|
@ -2,6 +2,12 @@ using ProjectTransportation.Repositories.Implementations;
|
||||
using ProjectTransportation.Repositories;
|
||||
using Unity.Lifetime;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using ProjectTransportation.Repositories.Implementations;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation
|
||||
{
|
||||
@ -23,13 +29,30 @@ namespace ProjectTransportation
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IBusRepository, BusRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IEmployeeRepository, EmployeeRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IRouteListRepository, RouteListRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IGoToServiceRepository, GoToServiceRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IStartingShiftRepository, StartingShiftRepository>(new TransientLifetimeManager());
|
||||
|
||||
container.RegisterType<IConnectionString, ConnectionString>(new TransientLifetimeManager());
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private static LoggerFactory CreateLoggerFactory()
|
||||
{
|
||||
var loggerFactory = new LoggerFactory();
|
||||
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build())
|
||||
.CreateLogger());
|
||||
|
||||
return loggerFactory;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -27,4 +38,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,4 +1,5 @@
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace ProjectTransportation.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -1,33 +1,126 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Repositories.Implementations;
|
||||
|
||||
public class BusRepository : IBusRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<BusRepository> _logger;
|
||||
|
||||
public BusRepository(IConnectionString connectionString, ILogger<BusRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateBus(Bus bus)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
|
||||
|
||||
}
|
||||
|
||||
public void DeleteBus(int id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Bus ReadBusById(int busId)
|
||||
{
|
||||
return Bus.CreateEntity(0, string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
public IEnumerable<Bus> ReadBuses()
|
||||
{
|
||||
return [];
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO bus (licence_plate, model)
|
||||
VALUES (@Licence_plate, @Model)";
|
||||
connection.Execute(queryInsert, bus);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateBus(Bus bus)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE bus
|
||||
SET
|
||||
licence_plate=@Licence_plate,
|
||||
model=@Model
|
||||
WHERE id=@Id";
|
||||
connection.Execute(queryUpdate, bus);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteBus(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM bus
|
||||
WHERE id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Bus ReadBusById(int busId)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", busId);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM bus
|
||||
WHERE id=@busId";
|
||||
var bus = connection.QueryFirst<Bus>(querySelect, new { busId });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus));
|
||||
|
||||
return bus;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Bus> ReadBuses()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM bus";
|
||||
var buses = connection.Query<Bus>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(buses));
|
||||
return buses;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace ProjectTransportation.Repositories.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=bustransportation";
|
||||
}
|
@ -1,32 +1,127 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Repositories.Implementations;
|
||||
|
||||
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)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
|
||||
}
|
||||
|
||||
public void DeleteEmployee(int id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Employee ReadEmployeeById(int employeeId)
|
||||
{
|
||||
return Employee.CreateEntity(0, string.Empty, string.Empty, EmployeePost.None);
|
||||
}
|
||||
|
||||
public IEnumerable<Employee> ReadEmployees()
|
||||
{
|
||||
return [];
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO employee (first_name, last_name, post)
|
||||
VALUES (@First_name, @Last_name, @Post)";
|
||||
connection.Execute(queryInsert, employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
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,21 +1,83 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities.Enums;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Repositories.Implementations;
|
||||
|
||||
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)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
_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,30 +1,127 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
using System;
|
||||
|
||||
namespace ProjectTransportation.Repositories.Implementations;
|
||||
|
||||
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)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||
|
||||
}
|
||||
|
||||
public void DeleteRouteList(int id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RouteList ReadRouteListById(int routeListId)
|
||||
{
|
||||
return RouteList.CreateEntity(0, new TimeOnly(0, 0), new TimeOnly(0, 0));
|
||||
}
|
||||
|
||||
public IEnumerable<RouteList> ReadRouteLists()
|
||||
{
|
||||
return [];
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO route_list (route_start, route_finish)
|
||||
VALUES (@Route_start, @Route_finish)";
|
||||
connection.Execute(queryInsert, routeList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
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,21 +1,72 @@
|
||||
using ProjectTransportation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Entities;
|
||||
using ProjectTransportation.Repositories;
|
||||
|
||||
namespace ProjectTransportation.Repositories.Implementations;
|
||||
|
||||
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)
|
||||
{
|
||||
_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,
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
ProjectTransportation/ProjectTransportation/appsettings.json
Normal file
15
ProjectTransportation/ProjectTransportation/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/bus_transportation_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user