Вроде готово

This commit is contained in:
Vladislave 2024-12-05 23:28:10 +03:00
parent 922fe3c585
commit c2dca0a3b6
29 changed files with 688 additions and 250 deletions

View 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
};
}
}

View File

@ -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
};
}
}

View File

@ -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
};
}
}

View File

@ -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
};
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProjectTransportation.Entities.Enums; namespace ProjectTransportation.Entities;
public enum EmployeePost public enum EmployeePost
{ {

View File

@ -1,15 +1,19 @@
namespace ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities.Enums;
using ProjectTransportation.Entities.Enums;
namespace ProjectTransportation.Entities;
public class GoToService public class GoToService
{ {
public int Id { get; private set; } public int Id { get; private set; }
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)
{ {
@ -17,10 +21,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
}; };
} }
} }

View File

@ -1,25 +1,20 @@
using System; namespace ProjectTransportation.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTransportation.Entities;
public class RouteList 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
}; };
} }
} }

View File

@ -1,21 +1,18 @@
using System; using ProjectTransportation.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTransportation.Entities; namespace ProjectTransportation.Entities;
public class StartingShift public class StartingShift
{ {
public int Id { get; private set; } public int Id { get; private set; }
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)
@ -24,9 +21,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
}; };
} }
} }

View File

@ -1,25 +1,20 @@
using System; namespace ProjectTransportation.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTransportation.Entities;
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
}; };
} }
} }

View File

@ -32,50 +32,46 @@ namespace ProjectTransportation.Forms
/// </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(18, 23); labelLicencePlate.Location = new Point(27, 34);
labelLicensePlate.Margin = new Padding(2, 0, 2, 0); labelLicencePlate.Name = "labelLicencePlate";
labelLicensePlate.Name = "labelLicensePlate"; labelLicencePlate.Size = new Size(107, 30);
labelLicensePlate.Size = new Size(78, 20); labelLicencePlate.TabIndex = 0;
labelLicensePlate.TabIndex = 0; labelLicencePlate.Text = "Госномер";
labelLicensePlate.Text = "Госномер";
// //
// textBoxLicensePlate // textBoxLicencePlate
// //
textBoxLicensePlate.Location = new Point(154, 21); textBoxLicencePlate.Location = new Point(231, 31);
textBoxLicensePlate.Margin = new Padding(2, 2, 2, 2); textBoxLicencePlate.MaxLength = 10;
textBoxLicensePlate.MaxLength = 10; textBoxLicencePlate.Name = "textBoxLicencePlate";
textBoxLicensePlate.Name = "textBoxLicensePlate"; textBoxLicencePlate.Size = new Size(240, 35);
textBoxLicensePlate.Size = new Size(161, 27); textBoxLicencePlate.TabIndex = 1;
textBoxLicensePlate.TabIndex = 1;
// //
// labelBusTypeName // labelBusTypeName
// //
labelBusTypeName.AutoSize = true; labelBusTypeName.AutoSize = true;
labelBusTypeName.Location = new Point(18, 66); labelBusTypeName.Location = new Point(27, 99);
labelBusTypeName.Margin = new Padding(2, 0, 2, 0);
labelBusTypeName.Name = "labelBusTypeName"; labelBusTypeName.Name = "labelBusTypeName";
labelBusTypeName.Size = new Size(129, 20); labelBusTypeName.Size = new Size(180, 30);
labelBusTypeName.TabIndex = 2; labelBusTypeName.TabIndex = 2;
labelBusTypeName.Text = "Модель автобуса"; labelBusTypeName.Text = "Модель автобуса";
// //
// buttonSave // buttonSave
// //
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(48, 152); buttonSave.Location = new Point(72, 164);
buttonSave.Margin = new Padding(2, 2, 2, 2);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(117, 33); buttonSave.Size = new Size(135, 50);
buttonSave.TabIndex = 6; buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
@ -84,10 +80,9 @@ namespace ProjectTransportation.Forms
// buttonCancel // buttonCancel
// //
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(266, 152); buttonCancel.Location = new Point(284, 164);
buttonCancel.Margin = new Padding(2, 2, 2, 2);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(120, 33); buttonCancel.Size = new Size(135, 50);
buttonCancel.TabIndex = 7; buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
@ -95,25 +90,23 @@ namespace ProjectTransportation.Forms
// //
// textBoxModel // textBoxModel
// //
textBoxModel.Location = new Point(154, 64); textBoxModel.Location = new Point(231, 96);
textBoxModel.Margin = new Padding(2, 2, 2, 2);
textBoxModel.MaxLength = 10; textBoxModel.MaxLength = 10;
textBoxModel.Name = "textBoxModel"; textBoxModel.Name = "textBoxModel";
textBoxModel.Size = new Size(161, 27); textBoxModel.Size = new Size(240, 35);
textBoxModel.TabIndex = 8; textBoxModel.TabIndex = 8;
// //
// FormBus // FormBus
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(444, 194); ClientSize = new Size(506, 226);
Controls.Add(textBoxModel); Controls.Add(textBoxModel);
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);
Margin = new Padding(2, 2, 2, 2);
Name = "FormBus"; Name = "FormBus";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "Автобус"; Text = "Автобус";
@ -123,8 +116,8 @@ namespace ProjectTransportation.Forms
#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;

View File

@ -1,7 +1,6 @@
using ProjectTransportation.Entities; using ProjectTransportation.Entities;
using ProjectTransportation.Entities.Enums;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
using ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
namespace ProjectTransportation.Forms namespace ProjectTransportation.Forms
@ -24,7 +23,7 @@ namespace ProjectTransportation.Forms
throw new InvalidDataException(nameof(bus)); throw new InvalidDataException(nameof(bus));
} }
textBoxLicensePlate.Text = bus.LicensePlate; textBoxLicencePlate.Text = bus.Licence_plate;
textBoxModel.Text = bus.Model; textBoxModel.Text = bus.Model;
_busId = value; _busId = value;
} }
@ -46,7 +45,7 @@ namespace ProjectTransportation.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("Имеются незаполненные поля");
} }
@ -70,7 +69,6 @@ namespace ProjectTransportation.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);
} }
} }

View File

@ -1,7 +1,7 @@
using ProjectTransportation.Entities; using ProjectTransportation.Entities;
using ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities.Enums;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
using ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
namespace ProjectTransportation.Forms namespace ProjectTransportation.Forms
@ -25,8 +25,8 @@ namespace ProjectTransportation.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;
} }

View File

@ -49,29 +49,26 @@ namespace ProjectTransportation.Forms
// //
comboBoxBus.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxBus.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxBus.FormattingEnabled = true; comboBoxBus.FormattingEnabled = true;
comboBoxBus.Location = new Point(112, 259); comboBoxBus.Location = new Point(168, 389);
comboBoxBus.Margin = new Padding(2, 2, 2, 2);
comboBoxBus.Name = "comboBoxBus"; comboBoxBus.Name = "comboBoxBus";
comboBoxBus.Size = new Size(165, 28); comboBoxBus.Size = new Size(245, 38);
comboBoxBus.TabIndex = 9; comboBoxBus.TabIndex = 9;
// //
// labelBus // labelBus
// //
labelBus.AutoSize = true; labelBus.AutoSize = true;
labelBus.Location = new Point(17, 261); labelBus.Location = new Point(25, 392);
labelBus.Margin = new Padding(2, 0, 2, 0);
labelBus.Name = "labelBus"; labelBus.Name = "labelBus";
labelBus.Size = new Size(65, 20); labelBus.Size = new Size(91, 30);
labelBus.TabIndex = 8; labelBus.TabIndex = 8;
labelBus.Text = "Автобус"; labelBus.Text = "Автобус";
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(187, 306); buttonCancel.Location = new Point(241, 459);
buttonCancel.Margin = new Padding(2, 2, 2, 2);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(90, 33); buttonCancel.Size = new Size(135, 50);
buttonCancel.TabIndex = 19; buttonCancel.TabIndex = 19;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
@ -80,10 +77,9 @@ namespace ProjectTransportation.Forms
// buttonSave // buttonSave
// //
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(43, 306); buttonSave.Location = new Point(64, 459);
buttonSave.Margin = new Padding(2, 2, 2, 2);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(99, 33); buttonSave.Size = new Size(135, 50);
buttonSave.TabIndex = 18; buttonSave.TabIndex = 18;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
@ -92,63 +88,58 @@ namespace ProjectTransportation.Forms
// labelPrice // labelPrice
// //
labelPrice.AutoSize = true; labelPrice.AutoSize = true;
labelPrice.Location = new Point(17, 208); labelPrice.Location = new Point(25, 312);
labelPrice.Margin = new Padding(2, 0, 2, 0);
labelPrice.Name = "labelPrice"; labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(83, 20); labelPrice.Size = new Size(116, 30);
labelPrice.TabIndex = 20; labelPrice.TabIndex = 20;
labelPrice.Text = "Стоимость"; labelPrice.Text = "Стоимость";
// //
// numericUpDownPrice // numericUpDownPrice
// //
numericUpDownPrice.Location = new Point(112, 207); numericUpDownPrice.Location = new Point(168, 310);
numericUpDownPrice.Margin = new Padding(2, 2, 2, 2); numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
numericUpDownPrice.Name = "numericUpDownPrice"; numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(163, 27); numericUpDownPrice.Size = new Size(245, 35);
numericUpDownPrice.TabIndex = 21; numericUpDownPrice.TabIndex = 21;
// //
// checkedListBoxBrokenElements // checkedListBoxBrokenElements
// //
checkedListBoxBrokenElements.FormattingEnabled = true; checkedListBoxBrokenElements.FormattingEnabled = true;
checkedListBoxBrokenElements.Location = new Point(112, 68); checkedListBoxBrokenElements.Location = new Point(168, 102);
checkedListBoxBrokenElements.Margin = new Padding(2, 2, 2, 2);
checkedListBoxBrokenElements.Name = "checkedListBoxBrokenElements"; checkedListBoxBrokenElements.Name = "checkedListBoxBrokenElements";
checkedListBoxBrokenElements.Size = new Size(166, 92); checkedListBoxBrokenElements.Size = new Size(247, 164);
checkedListBoxBrokenElements.TabIndex = 22; checkedListBoxBrokenElements.TabIndex = 22;
// //
// labelBrokenElement // labelBrokenElement
// //
labelBrokenElement.Location = new Point(17, 68); labelBrokenElement.Location = new Point(25, 102);
labelBrokenElement.Margin = new Padding(2, 0, 2, 0);
labelBrokenElement.Name = "labelBrokenElement"; labelBrokenElement.Name = "labelBrokenElement";
labelBrokenElement.Size = new Size(85, 45); labelBrokenElement.Size = new Size(128, 68);
labelBrokenElement.TabIndex = 23; labelBrokenElement.TabIndex = 23;
labelBrokenElement.Text = "Сломанная деталь"; labelBrokenElement.Text = "Сломанная деталь";
// //
// dateTimePickerServiceDate // dateTimePickerServiceDate
// //
dateTimePickerServiceDate.Enabled = false; dateTimePickerServiceDate.Enabled = false;
dateTimePickerServiceDate.Location = new Point(112, 18); dateTimePickerServiceDate.Location = new Point(168, 27);
dateTimePickerServiceDate.Margin = new Padding(2, 2, 2, 2);
dateTimePickerServiceDate.Name = "dateTimePickerServiceDate"; dateTimePickerServiceDate.Name = "dateTimePickerServiceDate";
dateTimePickerServiceDate.Size = new Size(166, 27); dateTimePickerServiceDate.Size = new Size(247, 35);
dateTimePickerServiceDate.TabIndex = 24; dateTimePickerServiceDate.TabIndex = 24;
// //
// labelDate // labelDate
// //
labelDate.AutoSize = true; labelDate.AutoSize = true;
labelDate.Location = new Point(17, 21); labelDate.Location = new Point(25, 31);
labelDate.Margin = new Padding(2, 0, 2, 0);
labelDate.Name = "labelDate"; labelDate.Name = "labelDate";
labelDate.Size = new Size(41, 20); labelDate.Size = new Size(59, 30);
labelDate.TabIndex = 25; labelDate.TabIndex = 25;
labelDate.Text = "Дата"; labelDate.Text = "Дата";
// //
// FormGoToService // FormGoToService
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(320, 347); ClientSize = new Size(441, 521);
Controls.Add(labelDate); Controls.Add(labelDate);
Controls.Add(dateTimePickerServiceDate); Controls.Add(dateTimePickerServiceDate);
Controls.Add(labelBrokenElement); Controls.Add(labelBrokenElement);
@ -159,7 +150,6 @@ namespace ProjectTransportation.Forms
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(comboBoxBus); Controls.Add(comboBoxBus);
Controls.Add(labelBus); Controls.Add(labelBus);
Margin = new Padding(2, 2, 2, 2);
Name = "FormGoToService"; Name = "FormGoToService";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "Тех. обслуживание"; Text = "Тех. обслуживание";

View File

@ -1,7 +1,6 @@
using ProjectTransportation.Entities; using ProjectTransportation.Entities;
using ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities.Enums;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
using ProjectTransportation.Entities.Enums;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
namespace ProjectTransportation.Forms namespace ProjectTransportation.Forms

View File

@ -23,10 +23,10 @@ namespace ProjectTransportation.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)
@ -67,7 +67,7 @@ namespace ProjectTransportation.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));
} }
} }

View File

@ -19,10 +19,10 @@ namespace ProjectTransportation.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";
} }
@ -57,8 +57,8 @@ namespace ProjectTransportation.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;
} }

View File

@ -49,46 +49,42 @@ namespace ProjectTransportation.Forms
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill; dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0); dataGridViewData.Location = new Point(0, 0);
dataGridViewData.Margin = new Padding(2, 2, 2, 2);
dataGridViewData.MultiSelect = false; dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData"; dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true; dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false; dataGridViewData.RowHeadersVisible = false;
dataGridViewData.RowHeadersWidth = 72; dataGridViewData.RowHeadersWidth = 72;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(740, 321); 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(740, 0); panelButtons.Location = new Point(1280, 0);
panelButtons.Margin = new Padding(2, 2, 2, 2);
panelButtons.Name = "panelButtons"; panelButtons.Name = "panelButtons";
panelButtons.Size = new Size(131, 321); panelButtons.Size = new Size(196, 636);
panelButtons.TabIndex = 4; panelButtons.TabIndex = 4;
// //
// buttonAdd // buttonAdd
// //
buttonAdd.BackgroundImage = Properties.Resources.plus; buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(33, 19); buttonAdd.Location = new Point(50, 29);
buttonAdd.Margin = new Padding(2, 2, 2, 2);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(67, 67); buttonAdd.Size = new Size(100, 100);
buttonAdd.TabIndex = 0; buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true; buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click; buttonAdd.Click += ButtonAdd_Click;
// //
// FormStartingShifts // FormStartingShifts
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(871, 321); ClientSize = new Size(1476, 636);
Controls.Add(dataGridViewData); Controls.Add(dataGridViewData);
Controls.Add(panelButtons); Controls.Add(panelButtons);
Margin = new Padding(2, 2, 2, 2);
Name = "FormStartingShifts"; Name = "FormStartingShifts";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "Смены"; Text = "Смены";

View File

@ -2,6 +2,12 @@ using ProjectTransportation.Repositories.Implementations;
using ProjectTransportation.Repositories; using ProjectTransportation.Repositories;
using Unity.Lifetime; using Unity.Lifetime;
using Unity; 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 namespace ProjectTransportation
{ {
@ -23,13 +29,30 @@ namespace ProjectTransportation
{ {
var container = new UnityContainer(); var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IBusRepository, BusRepository>(new TransientLifetimeManager()); container.RegisterType<IBusRepository, BusRepository>(new TransientLifetimeManager());
container.RegisterType<IEmployeeRepository, EmployeeRepository>(new TransientLifetimeManager()); container.RegisterType<IEmployeeRepository, EmployeeRepository>(new TransientLifetimeManager());
container.RegisterType<IRouteListRepository, RouteListRepository>(new TransientLifetimeManager()); container.RegisterType<IRouteListRepository, RouteListRepository>(new TransientLifetimeManager());
container.RegisterType<IGoToServiceRepository, GoToServiceRepository>(new TransientLifetimeManager()); container.RegisterType<IGoToServiceRepository, GoToServiceRepository>(new TransientLifetimeManager());
container.RegisterType<IStartingShiftRepository, StartingShiftRepository>(new TransientLifetimeManager()); container.RegisterType<IStartingShiftRepository, StartingShiftRepository>(new TransientLifetimeManager());
container.RegisterType<IConnectionString, ConnectionString>(new TransientLifetimeManager());
return container; 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;
}
} }
} }

View File

@ -9,7 +9,18 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <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" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -27,4 +38,10 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -1,4 +1,5 @@
using ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities;
using ProjectTransportation.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -0,0 +1,6 @@
namespace ProjectTransportation.Repositories;
public interface IConnectionString
{
public string ConnectionString { get; }
}

View File

@ -1,4 +1,4 @@
using ProjectTransportation.Entities.Enums; using ProjectTransportation.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -1,33 +1,126 @@
using ProjectTransportation.Entities; using Dapper;
using ProjectTransportation.Entities.Enums; using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectTransportation.Entities;
using ProjectTransportation.Entities;
using ProjectTransportation.Repositories;
namespace ProjectTransportation.Repositories.Implementations; namespace ProjectTransportation.Repositories.Implementations;
public class BusRepository : IBusRepository 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) public void CreateBus(Bus bus)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
} try
public void DeleteBus(int id)
{ {
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)
public Bus ReadBusById(int busId)
{ {
return Bus.CreateEntity(0, string.Empty, string.Empty); _logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
} }
public IEnumerable<Bus> ReadBuses()
{
return [];
} }
public void UpdateBus(Bus bus) 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;
}
} }
} }

View File

@ -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";
}

View File

@ -1,32 +1,127 @@
using ProjectTransportation.Entities; using Dapper;
using ProjectTransportation.Entities.Enums; using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectTransportation.Entities;
using ProjectTransportation.Entities;
using ProjectTransportation.Repositories;
namespace ProjectTransportation.Repositories.Implementations; namespace ProjectTransportation.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));
} try
public void DeleteEmployee(int id)
{ {
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)
public Employee ReadEmployeeById(int employeeId)
{ {
return Employee.CreateEntity(0, string.Empty, string.Empty, EmployeePost.None); _logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
} }
public IEnumerable<Employee> ReadEmployees()
{
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;
}
} }
} }

View File

@ -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.Enums;
using ProjectTransportation.Entities;
using ProjectTransportation.Repositories;
namespace ProjectTransportation.Repositories.Implementations; namespace ProjectTransportation.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;
}
} }
} }

View File

@ -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; namespace ProjectTransportation.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));
} try
public void DeleteRouteList(int id)
{ {
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)
public RouteList ReadRouteListById(int routeListId)
{ {
return RouteList.CreateEntity(0, new TimeOnly(0, 0), new TimeOnly(0, 0)); _logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
} }
public IEnumerable<RouteList> ReadRouteLists()
{
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;
}
} }
} }

View File

@ -1,21 +1,72 @@
using ProjectTransportation.Entities; using Dapper;
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic; using Newtonsoft.Json;
using System.Linq; using Npgsql;
using System.Text; using ProjectTransportation.Entities;
using System.Threading.Tasks; using ProjectTransportation.Entities;
using ProjectTransportation.Repositories;
namespace ProjectTransportation.Repositories.Implementations; namespace ProjectTransportation.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;
}
} }
} }

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/bus_transportation_log.txt",
"rollingInterval": "Day"
}
}
]
}
}