diff --git a/FuelAccounting/FuelAccounting/Entities/Car.cs b/FuelAccounting/FuelAccounting/Entities/Car.cs index 3ca6a6b..0be44aa 100644 --- a/FuelAccounting/FuelAccounting/Entities/Car.cs +++ b/FuelAccounting/FuelAccounting/Entities/Car.cs @@ -1,4 +1,5 @@ using FuelAccounting.Entities.Enums; +using System.ComponentModel; namespace FuelAccounting.Entities; @@ -6,12 +7,18 @@ public class Car { public int Id { get; private set; } + [DisplayName("Модель")] public string Model { get; private set; } = string.Empty; + [DisplayName("Категория")] public CarCategory Category { get; private set; } + [Browsable(false)] public int DriverID { get; private set; } + [DisplayName("Закрепленный водитель")] + public string DriverName { get; private set; } = string.Empty; + public static Car CreateEntity(int id, string model, CarCategory category, int driverId) { return new Car diff --git a/FuelAccounting/FuelAccounting/Entities/Driver.cs b/FuelAccounting/FuelAccounting/Entities/Driver.cs index 6c6bddb..2615839 100644 --- a/FuelAccounting/FuelAccounting/Entities/Driver.cs +++ b/FuelAccounting/FuelAccounting/Entities/Driver.cs @@ -1,4 +1,5 @@ using FuelAccounting.Entities.Enums; +using System.ComponentModel; namespace FuelAccounting.Entities; @@ -6,10 +7,15 @@ public class Driver { public int Id { get; private set; } + [DisplayName("Имя")] public string FirstName { get; private set; } = string.Empty; + [DisplayName("Фамилия")] public string LastName { get; private set; } = string.Empty; + public string DriverName => $"{FirstName} {LastName}"; + + [DisplayName("Категория прав")] public DriverLicenceCategory DriverLicenceCategory { get; private set; } public static Driver CreateEntity(int id, string firstName, string lastName, DriverLicenceCategory driverLicenceCategory) diff --git a/FuelAccounting/FuelAccounting/Entities/Equipage.cs b/FuelAccounting/FuelAccounting/Entities/Equipage.cs index caee5d6..0af0083 100644 --- a/FuelAccounting/FuelAccounting/Entities/Equipage.cs +++ b/FuelAccounting/FuelAccounting/Entities/Equipage.cs @@ -1,17 +1,38 @@ -namespace FuelAccounting.Entities; +using System.ComponentModel; + +namespace FuelAccounting.Entities; public class Equipage { public int Id { get; private set; } + [Browsable(false)] public int CarId { get; private set; } + [Browsable(false)] public int DriverId { get; private set; } + [Browsable(false)] public int ShiftId { get; private set; } + [Browsable(false)] public IEnumerable RoutesEqipage { get; private set; } = []; + [DisplayName("Автомобиль")] + public string CarModel { get; private set; } = string.Empty; + + [DisplayName("Водитель")] + public string DriverName { get; private set; } = string.Empty; + + [DisplayName("Смена")] + public string ShiftDescription { get; private set; } = string.Empty; + + [DisplayName("Маршруты")] + public string Route => RoutesEqipage != null ? + string.Join(", ", RoutesEqipage.Select(x => $"{x.RouteDescription} {x.Count}")) : + string.Empty; + + [DisplayName("Дата выезда")] public DateTime EquipageDate { get; private set; } public static Equipage CreateOperation(int id, int carId, int driverId, int shiftId, IEnumerable routesEqipage) @@ -27,17 +48,11 @@ public class Equipage }; } - public static Equipage CreateOperation(TempRoutesEquipage tempRoutesEquipage, - IEnumerable routesEqipage) + public void SetRoutesEquipage(IEnumerable routesEquipage) { - return new Equipage + if (routesEquipage != null && routesEquipage.Any()) { - Id = tempRoutesEquipage.Id, - CarId = tempRoutesEquipage.CarId, - DriverId = tempRoutesEquipage.DriverId, - ShiftId = tempRoutesEquipage.ShiftId, - RoutesEqipage = routesEqipage, - EquipageDate = tempRoutesEquipage.EquipageDate - }; + RoutesEqipage = routesEquipage; + } } } diff --git a/FuelAccounting/FuelAccounting/Entities/Refueling.cs b/FuelAccounting/FuelAccounting/Entities/Refueling.cs index a637a63..993b74c 100644 --- a/FuelAccounting/FuelAccounting/Entities/Refueling.cs +++ b/FuelAccounting/FuelAccounting/Entities/Refueling.cs @@ -1,19 +1,30 @@ -namespace FuelAccounting.Entities; +using System.ComponentModel; + +namespace FuelAccounting.Entities; public class Refueling { public int Id { get; private set; } + [Browsable(false)] public int CarId { get; private set; } + [DisplayName("Автомобиль")] + public string CarModel { get; private set; } = string.Empty; + + [DisplayName("Километров пойдено")] public double Kilometers { get; private set; } + [DisplayName("Литров заправлено")] public double LitersSpent { get; private set; } + [DisplayName("Тип топлива")] public string TypeOfFuel { get; private set; } = string.Empty; + [DisplayName("Дата заправки")] public DateTime RefuelingDate { get; private set; } + public static Refueling CreateOperation(int id, int carId, double kilometers, double litersSpent, string typeOfFuel) { return new Refueling diff --git a/FuelAccounting/FuelAccounting/Entities/Route.cs b/FuelAccounting/FuelAccounting/Entities/Route.cs index 0cde77f..69ad8aa 100644 --- a/FuelAccounting/FuelAccounting/Entities/Route.cs +++ b/FuelAccounting/FuelAccounting/Entities/Route.cs @@ -1,11 +1,15 @@ -namespace FuelAccounting.Entities; +using System.ComponentModel; + +namespace FuelAccounting.Entities; public class Route { public int Id { get; private set; } + [DisplayName("Описание")] public string Description { get; private set; } = string.Empty; + public static Route CreateEntity(int id, string description) { return new Route diff --git a/FuelAccounting/FuelAccounting/Entities/RoutesEqipage.cs b/FuelAccounting/FuelAccounting/Entities/RoutesEqipage.cs index a65406b..8dd72cf 100644 --- a/FuelAccounting/FuelAccounting/Entities/RoutesEqipage.cs +++ b/FuelAccounting/FuelAccounting/Entities/RoutesEqipage.cs @@ -6,6 +6,8 @@ public class RoutesEqipage public int RouteId { get; private set; } + public string RouteDescription { get; private set; } = string.Empty; + public int Count { get; private set; } public static RoutesEqipage CreateElement(int id, int routeId, int count) diff --git a/FuelAccounting/FuelAccounting/Entities/Shift.cs b/FuelAccounting/FuelAccounting/Entities/Shift.cs index 0192722..c4b148a 100644 --- a/FuelAccounting/FuelAccounting/Entities/Shift.cs +++ b/FuelAccounting/FuelAccounting/Entities/Shift.cs @@ -1,11 +1,15 @@ -namespace FuelAccounting.Entities; +using System.ComponentModel; + +namespace FuelAccounting.Entities; public class Shift { public int Id { get; private set; } + [DisplayName("Количество часов")] public int AmountOfHours { get; private set; } + [DisplayName("Описание")] public string Description { get; private set; } = string.Empty; public static Shift CreateEntity(int id, int amountOfHours, string description) diff --git a/FuelAccounting/FuelAccounting/Entities/TempRoutesEquipage.cs b/FuelAccounting/FuelAccounting/Entities/TempRoutesEquipage.cs deleted file mode 100644 index 56adc8c..0000000 --- a/FuelAccounting/FuelAccounting/Entities/TempRoutesEquipage.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace FuelAccounting.Entities; - -public class TempRoutesEquipage -{ - public int Id { get; private set; } - - public int CarId { get; private set; } - - public int DriverId { get; private set; } - - public int ShiftId { get; private set; } - - public int RouteId { get; private set; } - - public int Count { get; private set; } - - public DateTime EquipageDate { get; private set; } -} diff --git a/FuelAccounting/FuelAccounting/Forms/FormCar.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormCar.Designer.cs index fd30abf..97da997 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormCar.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormCar.Designer.cs @@ -52,9 +52,9 @@ label2.AutoSize = true; label2.Location = new Point(12, 101); label2.Name = "label2"; - label2.Size = new Size(170, 15); + label2.Size = new Size(142, 15); label2.TabIndex = 1; - label2.Text = "ID закрепленного сотрудника"; + label2.Text = "Закрепленный водитель"; // // label3 // @@ -104,9 +104,9 @@ // comboBoxDriverId // comboBoxDriverId.FormattingEnabled = true; - comboBoxDriverId.Location = new Point(188, 98); + comboBoxDriverId.Location = new Point(167, 98); comboBoxDriverId.Name = "comboBoxDriverId"; - comboBoxDriverId.Size = new Size(84, 23); + comboBoxDriverId.Size = new Size(105, 23); comboBoxDriverId.TabIndex = 8; // // FormCar @@ -123,6 +123,7 @@ Controls.Add(label2); Controls.Add(label1); Name = "FormCar"; + StartPosition = FormStartPosition.CenterScreen; Text = "Автомобиль"; ResumeLayout(false); PerformLayout(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormCar.cs b/FuelAccounting/FuelAccounting/Forms/FormCar.cs index 7ef1a7f..280f863 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormCar.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormCar.cs @@ -24,7 +24,14 @@ namespace FuelAccounting.Forms textBoxModel.Text = car.Model; comboBoxCategory.SelectedItem = car.Category; - comboBoxDriverId.SelectedItem = car.DriverID; + if (car.DriverID != 0) + { + comboBoxDriverId.SelectedValue = car.DriverID; + } + else + { + comboBoxDriverId.SelectedIndex = 0; + } _carId = value; } catch (Exception ex) @@ -44,7 +51,7 @@ namespace FuelAccounting.Forms comboBoxCategory.DataSource = Enum.GetValues(typeof(CarCategory)); comboBoxDriverId.DataSource = driversRepository.ReadDrivers(); - comboBoxDriverId.DisplayMember = "FirstName"; + comboBoxDriverId.DisplayMember = "DriverName"; comboBoxDriverId.ValueMember = "Id"; } diff --git a/FuelAccounting/FuelAccounting/Forms/FormCars.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormCars.Designer.cs index 346af6f..7856eb6 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormCars.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormCars.Designer.cs @@ -106,6 +106,7 @@ Controls.Add(dataGridViewData); Controls.Add(panelButtons); Name = "FormCars"; + StartPosition = FormStartPosition.CenterScreen; Text = "Автомобили"; Load += FormCars_Load; ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormCars.cs b/FuelAccounting/FuelAccounting/Forms/FormCars.cs index f0677d5..84e0213 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormCars.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormCars.cs @@ -84,7 +84,11 @@ namespace FuelAccounting.Forms } } - private void LoadList() => dataGridViewData.DataSource = _carsRepository.ReadCars(); + private void LoadList() + { + dataGridViewData.DataSource = _carsRepository.ReadCars(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/FuelAccounting/FuelAccounting/Forms/FormDriver.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormDriver.Designer.cs index 324c49a..e05f637 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormDriver.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormDriver.Designer.cs @@ -121,6 +121,7 @@ Controls.Add(label1); Controls.Add(checkedListBoxDriverLicenceCategory); Name = "FormDriver"; + StartPosition = FormStartPosition.CenterScreen; Text = "FormDriver"; ResumeLayout(false); PerformLayout(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormDrivers.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormDrivers.Designer.cs index 48cbea3..cb2119d 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormDrivers.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormDrivers.Designer.cs @@ -106,6 +106,7 @@ Controls.Add(dataGridViewData); Controls.Add(panelButtons); Name = "FormDrivers"; + StartPosition = FormStartPosition.CenterScreen; Text = "Водители"; Load += FormDrivers_Load; ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormDrivers.cs b/FuelAccounting/FuelAccounting/Forms/FormDrivers.cs index 7a0f242..34c1f4f 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormDrivers.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormDrivers.cs @@ -94,7 +94,12 @@ namespace FuelAccounting.Forms } } - private void LoadList() => dataGridViewData.DataSource = _driversRepository.ReadDrivers(); + private void LoadList() + { + dataGridViewData.DataSource = _driversRepository.ReadDrivers(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["DriverName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/FuelAccounting/FuelAccounting/Forms/FormEquipage.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormEquipage.Designer.cs index 4e65e01..d8d735d 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormEquipage.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormEquipage.Designer.cs @@ -169,6 +169,7 @@ Controls.Add(comboBoxCar); Controls.Add(label1); Name = "FormEquipage"; + StartPosition = FormStartPosition.CenterScreen; Text = "Выезд"; groupBoxRoutes.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormEquipage.cs b/FuelAccounting/FuelAccounting/Forms/FormEquipage.cs index cca29ff..0d77621 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormEquipage.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormEquipage.cs @@ -30,7 +30,7 @@ namespace FuelAccounting.Forms comboBoxCar.ValueMember = "Id"; comboBoxDriver.DataSource = driversRepository.ReadDrivers(); - comboBoxDriver.DisplayMember = "FirstName"; + comboBoxDriver.DisplayMember = "DriverName"; comboBoxDriver.ValueMember = "Id"; comboBoxShift.DataSource = shiftRepository.ReadShifts(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormEquipages.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormEquipages.Designer.cs index ace13f1..a82be81 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormEquipages.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormEquipages.Designer.cs @@ -30,8 +30,8 @@ { dataGridViewData = new DataGridView(); panelButtons = new Panel(); - buttonAdd = new Button(); buttonDelete = new Button(); + buttonAdd = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); panelButtons.SuspendLayout(); SuspendLayout(); @@ -63,17 +63,6 @@ panelButtons.Size = new Size(160, 450); panelButtons.TabIndex = 10; // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.pngimg_com___plus_PNG84; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(18, 12); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(130, 130); - buttonAdd.TabIndex = 2; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; - // // buttonDelete // buttonDelete.BackgroundImage = Properties.Resources.images; @@ -85,6 +74,17 @@ buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDelete_Click; // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.pngimg_com___plus_PNG84; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(18, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(130, 130); + buttonAdd.TabIndex = 2; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // // FormEquipages // AutoScaleDimensions = new SizeF(7F, 15F); @@ -93,6 +93,7 @@ Controls.Add(dataGridViewData); Controls.Add(panelButtons); Name = "FormEquipages"; + StartPosition = FormStartPosition.CenterScreen; Text = "Выезды"; Load += FormEquipages_Load; ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormEquipages.cs b/FuelAccounting/FuelAccounting/Forms/FormEquipages.cs index 161d777..0b7eaa4 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormEquipages.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormEquipages.cs @@ -53,7 +53,12 @@ namespace FuelAccounting.Forms } } - private void LoadList() => dataGridViewData.DataSource = _equipageRepository.ReadEquipages(); + private void LoadList() + { + dataGridViewData.DataSource = _equipageRepository.ReadEquipages(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["EquipageDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm"; + } private void ButtonDelete_Click(object sender, EventArgs e) { diff --git a/FuelAccounting/FuelAccounting/Forms/FormRefueling.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormRefueling.Designer.cs index cae9385..f1d0166 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormRefueling.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormRefueling.Designer.cs @@ -74,7 +74,7 @@ label4.AutoSize = true; label4.Location = new Point(12, 126); label4.Name = "label4"; - label4.Size = new Size(75, 15); + label4.Size = new Size(76, 15); label4.TabIndex = 3; label4.Text = "Тип топлива"; // @@ -149,6 +149,7 @@ Controls.Add(label2); Controls.Add(label1); Name = "FormRefueling"; + StartPosition = FormStartPosition.CenterScreen; Text = "FormRefueling"; ((System.ComponentModel.ISupportInitialize)numericUpDownKm).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownLiters).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormRefuelings.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormRefuelings.Designer.cs index d998f5b..644a234 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormRefuelings.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormRefuelings.Designer.cs @@ -44,7 +44,7 @@ buttonAdd.Size = new Size(130, 130); buttonAdd.TabIndex = 2; buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; + buttonAdd.Click += ButtonAdd_Click; // // dataGridViewData // @@ -80,6 +80,7 @@ Controls.Add(dataGridViewData); Controls.Add(panelButtons); Name = "FormRefuelings"; + StartPosition = FormStartPosition.CenterScreen; Text = "Заправки"; Load += FormRefuelings_Load; ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormRefuelings.cs b/FuelAccounting/FuelAccounting/Forms/FormRefuelings.cs index 3426de7..ffb13b2 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormRefuelings.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormRefuelings.cs @@ -40,7 +40,7 @@ namespace FuelAccounting.Forms } } - private void buttonAdd_Click(object sender, EventArgs e) + private void ButtonAdd_Click(object sender, EventArgs e) { try { @@ -53,6 +53,11 @@ namespace FuelAccounting.Forms } } - private void LoadList() => dataGridViewData.DataSource = _refuelingRepository.ReadRefuelings(); + private void LoadList() + { + dataGridViewData.DataSource = _refuelingRepository.ReadRefuelings(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["RefuelingDate"].DefaultCellStyle.Format = "dd.MM.yyyy hh:mm"; + } } } diff --git a/FuelAccounting/FuelAccounting/Forms/FormRoutes.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormRoutes.Designer.cs index 8fa0409..f442c5e 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormRoutes.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormRoutes.Designer.cs @@ -57,7 +57,7 @@ buttonDelete.Size = new Size(130, 130); buttonDelete.TabIndex = 4; buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; + buttonDelete.Click += ButtonDelete_Click; // // buttonUpdate // @@ -68,7 +68,7 @@ buttonUpdate.Size = new Size(130, 130); buttonUpdate.TabIndex = 3; buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += buttonUpdate_Click; + buttonUpdate.Click += ButtonUpdate_Click; // // buttonAdd // @@ -79,7 +79,7 @@ buttonAdd.Size = new Size(130, 130); buttonAdd.TabIndex = 2; buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; + buttonAdd.Click += ButtonAdd_Click; // // dataGridViewData // diff --git a/FuelAccounting/FuelAccounting/Forms/FormRoutes.cs b/FuelAccounting/FuelAccounting/Forms/FormRoutes.cs index 89e625a..899b8c7 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormRoutes.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormRoutes.cs @@ -37,7 +37,7 @@ namespace FuelAccounting.Forms } } - private void buttonAdd_Click(object sender, EventArgs e) + private void ButtonAdd_Click(object sender, EventArgs e) { try { @@ -50,7 +50,7 @@ namespace FuelAccounting.Forms } } - private void buttonUpdate_Click(object sender, EventArgs e) + private void ButtonUpdate_Click(object sender, EventArgs e) { if (!TryGetIdentifierFromSelectedRow(out var findId)) { @@ -70,7 +70,7 @@ namespace FuelAccounting.Forms } } - private void buttonDelete_Click(object sender, EventArgs e) + private void ButtonDelete_Click(object sender, EventArgs e) { if (!TryGetIdentifierFromSelectedRow(out var findId)) { @@ -93,7 +93,11 @@ namespace FuelAccounting.Forms } } - private void LoadList() => dataGridViewData.DataSource = _routeRepository.ReadRoutes(); + private void LoadList() + { + dataGridViewData.DataSource = _routeRepository.ReadRoutes(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/FuelAccounting/FuelAccounting/Forms/FormShifts.Designer.cs b/FuelAccounting/FuelAccounting/Forms/FormShifts.Designer.cs index 151e14d..9af648b 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormShifts.Designer.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormShifts.Designer.cs @@ -106,6 +106,7 @@ Controls.Add(dataGridViewData); Controls.Add(panelButtons); Name = "FormShifts"; + StartPosition = FormStartPosition.CenterScreen; Text = "Смены"; Load += FormShifts_Load; ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); diff --git a/FuelAccounting/FuelAccounting/Forms/FormShifts.cs b/FuelAccounting/FuelAccounting/Forms/FormShifts.cs index d488f3a..fe7ff77 100644 --- a/FuelAccounting/FuelAccounting/Forms/FormShifts.cs +++ b/FuelAccounting/FuelAccounting/Forms/FormShifts.cs @@ -85,7 +85,11 @@ namespace FuelAccounting.Forms } } - private void LoadList() => dataGridViewData.DataSource = _shiftRepository.ReadShifts(); + private void LoadList() + { + dataGridViewData.DataSource = _shiftRepository.ReadShifts(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/FuelAccounting/FuelAccounting/Repositories/Implementations/CarRepository.cs b/FuelAccounting/FuelAccounting/Repositories/Implementations/CarRepository.cs index 879bf1f..e978df9 100644 --- a/FuelAccounting/FuelAccounting/Repositories/Implementations/CarRepository.cs +++ b/FuelAccounting/FuelAccounting/Repositories/Implementations/CarRepository.cs @@ -111,12 +111,13 @@ WHERE id = @id"; { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @" -SELECT - id, - model, - category, - driver_id AS DriverID -FROM Cars"; +SELECT + c.id, + c.model, + c.category, + CONCAT(d.first_name, ' ', d.last_name) AS DriverName +FROM Cars c +LEFT JOIN Drivers d on d.id = c.driver_id"; var cars = connection.Query(querySelect); _logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(cars)); return cars; diff --git a/FuelAccounting/FuelAccounting/Repositories/Implementations/EquipageRepository.cs b/FuelAccounting/FuelAccounting/Repositories/Implementations/EquipageRepository.cs index 478231d..12608f3 100644 --- a/FuelAccounting/FuelAccounting/Repositories/Implementations/EquipageRepository.cs +++ b/FuelAccounting/FuelAccounting/Repositories/Implementations/EquipageRepository.cs @@ -81,15 +81,43 @@ WHERE id = @id"; { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @" -SELECT e.id, e.car_id AS CarId, e.driver_id AS DriverId, e.shift_id AS ShiftId, - e.equipage_date AS EquipageDate, re.route_id AS RouteId, re.count AS Count +SELECT + e.id, + c.model AS CarModel, + CONCAT(d.first_name, ' ', last_name) AS DriverName, + s.description AS ShiftDescription, + e.equipage_date AS EquipageDate, + re.route_id AS RouteId, + r.description AS RouteDescription, + re.count AS Count FROM Equipage e -INNER JOIN RoutesEquipage re ON re.equipage_id = e.id"; - var equipages = connection.Query(querySelect); +INNER JOIN RoutesEquipage re ON re.equipage_id = e.id +LEFT JOIN Cars c on c.id = e.car_id +LEFT JOIN Drivers d on d.id = e.driver_id +LEFT JOIN Shift s on s.id = e.shift_id +LEFT JOIN Routes r on r.id = re.route_id;"; + var equipageDict = new Dictionary>(); + + var equipages = connection.Query(querySelect, + (equip, equipages) => + { + if (!equipageDict.TryGetValue(equip.Id, out var re)) + { + re = []; + equipageDict.Add(equip.Id, re); + } + + re.Add(equipages); + return equip; + }, splitOn: "RouteId"); _logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(equipages)); - return equipages.GroupBy(x => x.Id, y => y, - (key, value) => Equipage.CreateOperation(value.First(), - value.Select(z => RoutesEqipage.CreateElement(0, z.RouteId, z.CarId)))).ToList(); + + return equipageDict.Select(x => + { + var e = equipages.First(y => y.Id == x.Key); + e.SetRoutesEquipage(x.Value); + return e; + }).ToArray(); } catch (Exception ex) { diff --git a/FuelAccounting/FuelAccounting/Repositories/Implementations/RefuelingRepository.cs b/FuelAccounting/FuelAccounting/Repositories/Implementations/RefuelingRepository.cs index 0bf9e53..14ff281 100644 --- a/FuelAccounting/FuelAccounting/Repositories/Implementations/RefuelingRepository.cs +++ b/FuelAccounting/FuelAccounting/Repositories/Implementations/RefuelingRepository.cs @@ -45,13 +45,14 @@ VALUES (@CarId, @Kilometers, @LitersSpent, @TypeOfFuel, @RefuelingDate)"; using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @" SELECT - id, - car_id AS CarId, - km AS Kilometers, - liters_spent AS LitersSpent, - type_of_fuel AS TypeOfFuel, - refueling_date AS RefuelingDate -FROM Refueling"; + r.id, + c.model AS CarModel, + r.km AS Kilometers, + r.liters_spent AS LitersSpent, + r.type_of_fuel AS TypeOfFuel, + r.refueling_date AS RefuelingDate +FROM Refueling r +LEFT JOIN Cars c on c.id = r.car_id"; var refuelings = connection.Query(querySelect); _logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(refuelings)); return refuelings;