sad
This commit is contained in:
parent
e461145e65
commit
7f086ae865
@ -2,6 +2,7 @@
|
||||
using ProjectHotel.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -11,11 +12,19 @@ namespace ProjectHotel.Entities;
|
||||
public class Athlete
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя")]
|
||||
public string FirstName { get; private set; } = string.Empty;
|
||||
[DisplayName("Фмилия")]
|
||||
public string LastName { get; private set; } = string.Empty;
|
||||
[DisplayName("Отчество")]
|
||||
public string FatherName { get; private set; } = string.Empty;
|
||||
[Browsable(false)]
|
||||
public string FullName => $"{FirstName} {LastName} {FatherName}" ;
|
||||
[DisplayName("Вид спорта")]
|
||||
public Sport Sport { get; private set; }
|
||||
[DisplayName("Разряд")]
|
||||
public AthleteClass AthleteClass { get; private set; }
|
||||
|
||||
public static Athlete CreateEntity(int id, string first, string last, string father, Sport sport, AthleteClass athleteClass)
|
||||
{
|
||||
return new Athlete
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,9 +9,15 @@ namespace ProjectHotel.Entities;
|
||||
|
||||
public class AthletePlacingAthlete
|
||||
{
|
||||
|
||||
public int Id { get; set; }
|
||||
[Browsable(false)]
|
||||
public int AthleteId { get; private set; }
|
||||
[DisplayName("Спортсмен")]
|
||||
public string AthleteName { get; private set; } = string.Empty;
|
||||
|
||||
public int PlacingAthleteId{ get; private set; }
|
||||
[DisplayName("Длительность проживания")]
|
||||
public int LengthOfStay { get; private set; }
|
||||
public static AthletePlacingAthlete CreateElement(int id, int athleteId, int lengthOfStay)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,8 +9,13 @@ namespace ProjectHotel.Entities;
|
||||
|
||||
public class CleaningRoom
|
||||
{
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public int RoomId { get; set; }
|
||||
[DisplayName("Название комнаты")]
|
||||
public string RoomName { get; set; } = string.Empty;
|
||||
[DisplayName("Дата уборки")]
|
||||
public DateTime CleaningDate { get; private set; }
|
||||
public static CleaningRoom CreateOperation(int id, int roomId)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,8 +9,11 @@ namespace ProjectHotel.Entities;
|
||||
|
||||
public class Hotel
|
||||
{
|
||||
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,9 +9,21 @@ namespace ProjectHotel.Entities;
|
||||
|
||||
public class PlacingAthlete
|
||||
{
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
|
||||
public int RoomId { get; private set; }
|
||||
|
||||
[DisplayName("Комната")]
|
||||
public string RoomName { get; private set; } = string.Empty;
|
||||
[DisplayName("Дата заселения")]
|
||||
public DateTime PlacingDate { get; private set; }
|
||||
[DisplayName("Корма")]
|
||||
public string athlete => AthletePlacingAthlete != null ?
|
||||
string.Join(", ", AthletePlacingAthlete.Select(x => $"{x.AthleteName} {x.Count}")) : string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<AthletePlacingAthlete> AthletePlacingAthletes
|
||||
{
|
||||
get;
|
||||
@ -27,14 +40,12 @@ public class PlacingAthlete
|
||||
};
|
||||
}
|
||||
|
||||
public static PlacingAthlete CreateOpeartion(TempAthletePlacingAthlete tempAthletePlacingAthlete, IEnumerable<AthletePlacingAthlete> athletePlacingAthletes)
|
||||
|
||||
public void SetAthletePlacingAthlete(IEnumerable<AthletePlacingAthlete> athletePlacingAthletes)
|
||||
{
|
||||
return new PlacingAthlete
|
||||
if (athletePlacingAthletes != null && athletePlacingAthletes.Any())
|
||||
{
|
||||
Id = tempAthletePlacingAthlete.Id,
|
||||
RoomId = tempAthletePlacingAthlete.RoomId,
|
||||
PlacingDate = DateTime.Now,
|
||||
AthletePlacingAthletes = athletePlacingAthletes
|
||||
};
|
||||
AthletePlacingAthletes = athletePlacingAthletes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,9 +10,15 @@ namespace ProjectHotel.Entities;
|
||||
|
||||
public class Room
|
||||
{
|
||||
|
||||
public int Id { get; private set; }
|
||||
[Browsable(false)]
|
||||
public int HotelId { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[DisplayName("Название отеля")]
|
||||
public string HotelName { get; private set; } = string.Empty;
|
||||
[DisplayName("Название")]
|
||||
public string RoomName { get; private set; } = string.Empty;
|
||||
[DisplayName("Вместимость")]
|
||||
public int Capacity { get; private set; }
|
||||
public static Room CreateEntity(int id, int hotel, string name, int capacity)
|
||||
{
|
||||
@ -19,7 +26,7 @@ public class Room
|
||||
{
|
||||
Id = id,
|
||||
HotelId = hotel,
|
||||
Name = name,
|
||||
RoomName = name,
|
||||
Capacity = capacity
|
||||
};
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectHotel.Entities;
|
||||
|
||||
public class TempAthletePlacingAthlete
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int RoomId { get; private set; }
|
||||
public DateTime PlacingDate { get; private set; }
|
||||
public int AthleteId { get; private set; }
|
||||
public int PlacingAthleteId { get; private set; }
|
||||
public int LengthOfStay { get; private set; }
|
||||
}
|
@ -89,7 +89,12 @@ public partial class FormAthletes : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _athleteRepository.ReadAthletes();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _athleteRepository.ReadAthletes();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["FullName"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -48,9 +48,14 @@ public partial class FormCleaningRooms : Form
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _cleaningRoomRepository.ReadCleaningRooms();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _cleaningRoomRepository.ReadCleaningRooms();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["RoomName"].Visible = false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@ public partial class FormPlacingAthlete : Form
|
||||
comboBoxRoom.DisplayMember = "Name";
|
||||
comboBoxRoom.ValueMember = "Id";
|
||||
ColumnAthlete.DataSource = athleteRepository.ReadAthletes();
|
||||
ColumnAthlete.DisplayMember = "FirstName";
|
||||
ColumnAthlete.DisplayMember = "FullName";
|
||||
ColumnAthlete.ValueMember = "Id";
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
@ -63,6 +63,8 @@ public partial class FormPlacingAthlete : Form
|
||||
list.Add(AthletePlacingAthlete.CreateElement(0,
|
||||
Convert.ToInt32(row.Cells["ColumnAthlete"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnLengthOfStay"].Value)));
|
||||
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -71,8 +71,12 @@ public partial class FormPlacingAthletes : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource =
|
||||
_placingAthleteRepository.ReadPlacingAthlete();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _placingAthleteRepository.ReadPlacingAthlete();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["PlacingDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -28,7 +28,7 @@ namespace ProjectHotel.Forms
|
||||
throw new
|
||||
InvalidDataException(nameof(room));
|
||||
}
|
||||
textBoxRoomName.Text = room.Name;
|
||||
textBoxRoomName.Text = room.RoomName;
|
||||
numericUpDownCapacity.Value = room.Capacity;
|
||||
_roomId = value;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ x.LastName,x.FatherName, x.Sport.ToString(), x.AthleteClass.ToString() }),
|
||||
["Отель", "Номер", "Вместимость"],
|
||||
.. _roomRepository
|
||||
.ReadRooms()
|
||||
.Select(x => new string[] { x.HotelId.ToString(), x.Name,
|
||||
.Select(x => new string[] { x.HotelId.ToString(), x.RoomName,
|
||||
x.Capacity.ToString() }),
|
||||
];
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Dapper;
|
||||
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
@ -53,7 +54,7 @@ internal class PlacingAthleteRepository : IPlacingAthleteRepository
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
@ -86,18 +87,48 @@ internal class PlacingAthleteRepository : IPlacingAthleteRepository
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (placing.HasValue)
|
||||
{
|
||||
builder.AddCondition("pa.PlacingDate = @PlacingDate");
|
||||
}
|
||||
|
||||
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT pa.*,apa.*
|
||||
var querySelect = @"SELECT pa.*, apa.*, r.Name AS RoomName
|
||||
FROM PlacingAthlete pa
|
||||
INNER JOIN AthletePlacingAthlete apa ON apa.PlacingAthleteId = pa.Id
|
||||
";
|
||||
var placingAthletes = connection.Query<TempAthletePlacingAthlete>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(placingAthletes));
|
||||
return placingAthletes.GroupBy(x => x.Id, y => y, (key, value) =>
|
||||
PlacingAthlete.CreateOpeartion(value.First(), value.Select(z =>
|
||||
AthletePlacingAthlete.CreateElement(0, z.AthleteId, z.LengthOfStay)))).ToList();
|
||||
INNER JOIN AthletePlacingAthlete apa ON apa.PlacingAthleteId = pa.Id
|
||||
LEFT JOIN Rooms r ON r.Id = pa.RoomId
|
||||
{builder.Build()};";
|
||||
//var placingAthletes = connection.Query<TempAthletePlacingAthlete>(querySelect);
|
||||
var placingAthletesDict = new Dictionary<int, List<AthletePlacingAthlete>>();
|
||||
|
||||
var placingAthlete = connection.Query<PlacingAthlete, AthletePlacingAthlete, PlacingAthlete>(querySelect, (placingAthlete, athletePlacingAthlete) =>
|
||||
{
|
||||
if (!placingAthletesDict.TryGetValue(placingAthlete.Id, out var pa))
|
||||
{
|
||||
pa = [];
|
||||
placingAthletesDict.Add(placingAthlete.Id, pa);
|
||||
}
|
||||
|
||||
pa.Add(athletePlacingAthlete);
|
||||
return placingAthlete;
|
||||
}, splitOn: "RoomId", param: new
|
||||
{
|
||||
placing
|
||||
});
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(placingAthlete));
|
||||
return placingAthletesDict.Select(x =>
|
||||
{
|
||||
var c = placingAthlete.First(y => y.Id == x.Key);
|
||||
c.SetAthletePlacingAthlete(x.Value);
|
||||
return c;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectHotel.Repositories.Implementations;
|
||||
|
||||
internal class QueryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public QueryBuilder()
|
||||
{
|
||||
_builder = new();
|
||||
}
|
||||
|
||||
public QueryBuilder AddCondition(string condition)
|
||||
{
|
||||
if (_builder.Length > 0)
|
||||
{
|
||||
_builder.Append(" AND ");
|
||||
}
|
||||
|
||||
_builder.Append(condition);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Build()
|
||||
{
|
||||
if (_builder.Length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return $"WHERE {_builder}";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user