diff --git a/ProjectTransportation/ProjectTransportation/Entities/Bus.cs b/ProjectTransportation/ProjectTransportation/Entities/Bus.cs new file mode 100644 index 0000000..fb5ae28 --- /dev/null +++ b/ProjectTransportation/ProjectTransportation/Entities/Bus.cs @@ -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 + }; + } +} diff --git a/ProjectTransportation/ProjectTransportation/Entities/Employee.cs b/ProjectTransportation/ProjectTransportation/Entities/Employee.cs new file mode 100644 index 0000000..bfaf1e6 --- /dev/null +++ b/ProjectTransportation/ProjectTransportation/Entities/Employee.cs @@ -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 + }; + } +} diff --git a/ProjectTransportation/ProjectTransportation/Entities/Enums/Bus.cs b/ProjectTransportation/ProjectTransportation/Entities/Enums/Bus.cs deleted file mode 100644 index b53e7f3..0000000 --- a/ProjectTransportation/ProjectTransportation/Entities/Enums/Bus.cs +++ /dev/null @@ -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 - }; - } -} diff --git a/ProjectTransportation/ProjectTransportation/Entities/Enums/Employee.cs b/ProjectTransportation/ProjectTransportation/Entities/Enums/Employee.cs deleted file mode 100644 index d9bbe53..0000000 --- a/ProjectTransportation/ProjectTransportation/Entities/Enums/Employee.cs +++ /dev/null @@ -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 - }; - } -} \ No newline at end of file diff --git a/ProjectTransportation/ProjectTransportation/Entities/Enums/EmployeePost.cs b/ProjectTransportation/ProjectTransportation/Entities/Enums/EmployeePost.cs index 4db0c93..4ade0d8 100644 --- a/ProjectTransportation/ProjectTransportation/Entities/Enums/EmployeePost.cs +++ b/ProjectTransportation/ProjectTransportation/Entities/Enums/EmployeePost.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectTransportation.Entities.Enums; +namespace ProjectTransportation.Entities; public enum EmployeePost { diff --git a/ProjectTransportation/ProjectTransportation/Entities/Enums/GoToService.cs b/ProjectTransportation/ProjectTransportation/Entities/GoToService.cs similarity index 56% rename from ProjectTransportation/ProjectTransportation/Entities/Enums/GoToService.cs rename to ProjectTransportation/ProjectTransportation/Entities/GoToService.cs index 318a46a..d74186e 100644 --- a/ProjectTransportation/ProjectTransportation/Entities/Enums/GoToService.cs +++ b/ProjectTransportation/ProjectTransportation/Entities/GoToService.cs @@ -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 }; } } - diff --git a/ProjectTransportation/ProjectTransportation/Entities/RouteList.cs b/ProjectTransportation/ProjectTransportation/Entities/RouteList.cs index c776d7a..58b2bfc 100644 --- a/ProjectTransportation/ProjectTransportation/Entities/RouteList.cs +++ b/ProjectTransportation/ProjectTransportation/Entities/RouteList.cs @@ -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 }; } } diff --git a/ProjectTransportation/ProjectTransportation/Entities/StartingShift.cs b/ProjectTransportation/ProjectTransportation/Entities/StartingShift.cs index 20c1c15..a0fe182 100644 --- a/ProjectTransportation/ProjectTransportation/Entities/StartingShift.cs +++ b/ProjectTransportation/ProjectTransportation/Entities/StartingShift.cs @@ -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 StartingShiftEmployees { get; private set; } = []; + public IEnumerable Starting_shift_employees { get; private set; } = []; public static StartingShift CreateOperation(int id, int routeListId, int busId, IEnumerable 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 }; } } diff --git a/ProjectTransportation/ProjectTransportation/Entities/StartingShiftEmployee.cs b/ProjectTransportation/ProjectTransportation/Entities/StartingShiftEmployee.cs index 7731c31..32ad8fb 100644 --- a/ProjectTransportation/ProjectTransportation/Entities/StartingShiftEmployee.cs +++ b/ProjectTransportation/ProjectTransportation/Entities/StartingShiftEmployee.cs @@ -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 }; } } diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormBus.Designer.cs b/ProjectTransportation/ProjectTransportation/Forms/FormBus.Designer.cs index 0533605..3c6959b 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormBus.Designer.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormBus.Designer.cs @@ -32,50 +32,46 @@ namespace ProjectTransportation.Forms /// 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; diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormBus.cs b/ProjectTransportation/ProjectTransportation/Forms/FormBus.cs index 84a83ea..47b999f 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormBus.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormBus.cs @@ -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); } } - diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormEmployee.cs b/ProjectTransportation/ProjectTransportation/Forms/FormEmployee.cs index f0d0062..175e3e5 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormEmployee.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormEmployee.cs @@ -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; } diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.Designer.cs b/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.Designer.cs index f0c5600..2847609 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.Designer.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.Designer.cs @@ -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 = "Тех. обслуживание"; diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.cs b/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.cs index 3ea12bd..eedfcb3 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormGoToService.cs @@ -1,7 +1,6 @@ using ProjectTransportation.Entities; using ProjectTransportation.Entities.Enums; using ProjectTransportation.Repositories; -using ProjectTransportation.Entities.Enums; using ProjectTransportation.Repositories; namespace ProjectTransportation.Forms diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormRouteList.cs b/ProjectTransportation/ProjectTransportation/Forms/FormRouteList.cs index 337d7d9..c683c18 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormRouteList.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormRouteList.cs @@ -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)); } } diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormStartingShift.cs b/ProjectTransportation/ProjectTransportation/Forms/FormStartingShift.cs index bb6ba8e..b52e7b1 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormStartingShift.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormStartingShift.cs @@ -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(); 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; } diff --git a/ProjectTransportation/ProjectTransportation/Forms/FormStartingShifts.Designer.cs b/ProjectTransportation/ProjectTransportation/Forms/FormStartingShifts.Designer.cs index 3228efd..1e0db16 100644 --- a/ProjectTransportation/ProjectTransportation/Forms/FormStartingShifts.Designer.cs +++ b/ProjectTransportation/ProjectTransportation/Forms/FormStartingShifts.Designer.cs @@ -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 = "Смены"; diff --git a/ProjectTransportation/ProjectTransportation/Program.cs b/ProjectTransportation/ProjectTransportation/Program.cs index 674438e..881a64f 100644 --- a/ProjectTransportation/ProjectTransportation/Program.cs +++ b/ProjectTransportation/ProjectTransportation/Program.cs @@ -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(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(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; + } } } \ No newline at end of file diff --git a/ProjectTransportation/ProjectTransportation/ProjectTransportation.csproj b/ProjectTransportation/ProjectTransportation/ProjectTransportation.csproj index e32799a..0c90c97 100644 --- a/ProjectTransportation/ProjectTransportation/ProjectTransportation.csproj +++ b/ProjectTransportation/ProjectTransportation/ProjectTransportation.csproj @@ -9,7 +9,18 @@ + + + + + + + + + + + @@ -27,4 +38,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/ProjectTransportation/ProjectTransportation/Repositories/IBusRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/IBusRepository.cs index aec17a0..d6b72ca 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/IBusRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/IBusRepository.cs @@ -1,4 +1,5 @@ -using ProjectTransportation.Entities.Enums; +using ProjectTransportation.Entities; +using ProjectTransportation.Entities; using System; using System.Collections.Generic; using System.Linq; diff --git a/ProjectTransportation/ProjectTransportation/Repositories/IConnectionString.cs b/ProjectTransportation/ProjectTransportation/Repositories/IConnectionString.cs new file mode 100644 index 0000000..99c5702 --- /dev/null +++ b/ProjectTransportation/ProjectTransportation/Repositories/IConnectionString.cs @@ -0,0 +1,6 @@ +namespace ProjectTransportation.Repositories; + +public interface IConnectionString +{ + public string ConnectionString { get; } +} diff --git a/ProjectTransportation/ProjectTransportation/Repositories/IEmployeeRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/IEmployeeRepository.cs index 60ac07c..9fb0b49 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/IEmployeeRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/IEmployeeRepository.cs @@ -1,4 +1,4 @@ -using ProjectTransportation.Entities.Enums; +using ProjectTransportation.Entities; using System; using System.Collections.Generic; using System.Linq; diff --git a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/BusRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/BusRepository.cs index 21ff809..245fac6 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/BusRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/BusRepository.cs @@ -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 _logger; + + public BusRepository(IConnectionString connectionString, ILogger 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 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(querySelect, new { busId }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus)); + + return bus; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + + public IEnumerable ReadBuses() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @"SELECT * FROM bus"; + var buses = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(buses)); + return buses; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } - diff --git a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/ConnectionString.cs b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..d914c72 --- /dev/null +++ b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/ConnectionString.cs @@ -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"; +} diff --git a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/EmployeeRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/EmployeeRepository.cs index 51d7865..d2aaa88 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/EmployeeRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/EmployeeRepository.cs @@ -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 _logger; + + public EmployeeRepository(IConnectionString connectionString, ILogger 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 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; + } } -} \ No newline at end of file + + 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(querySelect, new { employeeId }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(employee)); + + return employee; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + + public IEnumerable ReadEmployees() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM employee"; + var employees = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(employees)); + return employees; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } +} diff --git a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/GoToServiceRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/GoToServiceRepository.cs index ccb5164..1391a6d 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/GoToServiceRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/GoToServiceRepository.cs @@ -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 _logger; + + public GoToServiceRepository(IConnectionString connectionString, ILogger 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 ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null, BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null) + public IEnumerable 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(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services)); + return services; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } diff --git a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/RouteListRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/RouteListRepository.cs index 0d33b40..cf4f122 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/RouteListRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/RouteListRepository.cs @@ -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 _logger; + + public RouteListRepository(IConnectionString connectionString, ILogger 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 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(querySelect, new { routeListId }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(routeList)); + + return routeList; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + + public IEnumerable ReadRouteLists() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @"SELECT * FROM route_list"; + var routeLists = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routeLists)); + return routeLists; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } diff --git a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/StartingShiftRepository.cs b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/StartingShiftRepository.cs index 29fa177..217327c 100644 --- a/ProjectTransportation/ProjectTransportation/Repositories/Implementations/StartingShiftRepository.cs +++ b/ProjectTransportation/ProjectTransportation/Repositories/Implementations/StartingShiftRepository.cs @@ -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 _logger; + + public StartingShiftRepository(IConnectionString connectionString, ILogger 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(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 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(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts)); + return startingShifts; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } -} \ No newline at end of file +} diff --git a/ProjectTransportation/ProjectTransportation/appsettings.json b/ProjectTransportation/ProjectTransportation/appsettings.json new file mode 100644 index 0000000..1bc1cae --- /dev/null +++ b/ProjectTransportation/ProjectTransportation/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/bus_transportation_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file