готовая 4
This commit is contained in:
parent
93545117ac
commit
15b05413b0
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,11 +10,26 @@ namespace ProjectTourismCompany.Entities;
|
||||
public class Check
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
//public string TripTitle { get; private set; } = string.Empty;
|
||||
|
||||
|
||||
[DisplayName("Дата сделки")]
|
||||
public DateTime PurchaseDate { get; private set; }
|
||||
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public int Price { get; private set; }
|
||||
|
||||
|
||||
|
||||
public int TripId { get; private set; }
|
||||
[DisplayName("Название тура")]
|
||||
public string TripName { get; private set; } = string.Empty;
|
||||
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
[DisplayName("Имя клиента")]
|
||||
public string ClientName { get; private set; } = string.Empty;
|
||||
|
||||
public static Check CreateCheck(int id, DateTime purchaseDate, int price, int tripId, int clientId)//string triptitle,
|
||||
{
|
||||
return new Check() { Id = id, PurchaseDate = purchaseDate, Price = price, TripId = tripId, ClientId = clientId };//TripTitle = triptitle,
|
||||
|
@ -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 ProjectTourismCompany.Entities.Enums;
|
||||
public class Client
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Имя")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public string Description => $"{Name} {Status}";
|
||||
[DisplayName("Дата рождения")]
|
||||
public DateTime BirthDate { get; private set; }
|
||||
[DisplayName("Льготы")]
|
||||
public ClientStatus Status { get; private set; }
|
||||
[DisplayName("Телефон")]
|
||||
public string Phone { get; private set; }= string.Empty;
|
||||
public static Client CreateClient(int id, string name, DateTime birth, ClientStatus status, string phone)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,8 +10,13 @@ namespace ProjectTourismCompany.Entities;
|
||||
public class Company
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Название Компании")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public int CountryId { get; private set; }
|
||||
[DisplayName("Страна нахождения")]
|
||||
public string CountryName { get; private set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
public static Company CreateCompany(int id, string name, int countryId)
|
||||
|
@ -10,6 +10,7 @@ public class CompanyTrip
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int CompanyId { get; private set; }
|
||||
public string CompanyName { get; private set; } = string.Empty;
|
||||
public int TripId { get; private set; }
|
||||
public int AdditionalPrice { get; private set; }
|
||||
public static CompanyTrip CreateCompanyTrip(int id, int companyId ,int tripId, int additionalPrice)//
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,6 +10,7 @@ namespace ProjectTourismCompany.Entities;
|
||||
public class Country
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Название страны")]
|
||||
public string CountryName { get; private set; }=string.Empty;
|
||||
public static Country CreateCountry(int id, string countryName)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using ProjectTourismCompany.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,15 +11,31 @@ namespace ProjectTourismCompany.Entities;
|
||||
public class Trip
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Название путевки")]
|
||||
public string Title { get; private set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public int Price { get; private set; }
|
||||
[DisplayName("Вместительность")]
|
||||
public int HumanCapacity { get; private set; }
|
||||
[DisplayName("Дата начала")]
|
||||
public DateTime StartDate { get; private set; }
|
||||
|
||||
[DisplayName("Дата конца")]
|
||||
public DateTime EndDate { get; private set;}
|
||||
|
||||
[DisplayName("Стартовый город")]
|
||||
public string StartCity { get; private set; }=string.Empty;
|
||||
|
||||
[DisplayName("Конечный город")]
|
||||
public string EndCity { get; private set;} =string.Empty;
|
||||
[DisplayName("Тип путешествия")]
|
||||
public TravelType TravelType { get; private set; }
|
||||
|
||||
[DisplayName("Компании")]
|
||||
public string Company => CompanyTrip != null ?
|
||||
string.Join(", ", CompanyTrip.Select(x => $"{x.CompanyName} {x.AdditionalPrice}")) : string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<CompanyTrip> CompanyTrip
|
||||
{
|
||||
get;
|
||||
@ -44,21 +61,30 @@ public class Trip
|
||||
|
||||
|
||||
|
||||
public static Trip CreateOpeartion(TempCompanyTrip tempCompanyTrip,IEnumerable<CompanyTrip> companyTrip)
|
||||
{
|
||||
return new Trip
|
||||
{
|
||||
Title = tempCompanyTrip.Title,
|
||||
Id = tempCompanyTrip.Id,
|
||||
Price = tempCompanyTrip.Price,
|
||||
HumanCapacity=tempCompanyTrip.HumanCapacity,
|
||||
StartDate = tempCompanyTrip.StartDate,
|
||||
EndDate = tempCompanyTrip.EndDate,
|
||||
StartCity = tempCompanyTrip.StartCity,
|
||||
EndCity = tempCompanyTrip.EndCity,
|
||||
TravelType = tempCompanyTrip.TravelType,
|
||||
CompanyTrip = companyTrip
|
||||
//public static Trip CreateOpeartion(TempCompanyTrip tempCompanyTrip,IEnumerable<CompanyTrip> companyTrip)
|
||||
//{
|
||||
// return new Trip
|
||||
// {
|
||||
// Title = tempCompanyTrip.Title,
|
||||
// Id = tempCompanyTrip.Id,
|
||||
// Price = tempCompanyTrip.Price,
|
||||
// HumanCapacity=tempCompanyTrip.HumanCapacity,
|
||||
// StartDate = tempCompanyTrip.StartDate,
|
||||
// EndDate = tempCompanyTrip.EndDate,
|
||||
// StartCity = tempCompanyTrip.StartCity,
|
||||
// EndCity = tempCompanyTrip.EndCity,
|
||||
// TravelType = tempCompanyTrip.TravelType,
|
||||
// CompanyTrip = companyTrip
|
||||
|
||||
};
|
||||
// };
|
||||
//}
|
||||
|
||||
|
||||
public void SetCompanyTrip(IEnumerable<CompanyTrip> companyTrips)
|
||||
{
|
||||
if (companyTrips != null && companyTrips.Any())
|
||||
{
|
||||
CompanyTrip = companyTrips;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public partial class FormCheck : Form
|
||||
_checkRepository = checkRepository ?? throw new ArgumentNullException(nameof(checkRepository));
|
||||
|
||||
comboBoxClient.DataSource = clientRepository.ReadClients();
|
||||
comboBoxClient.DisplayMember = "Name";
|
||||
comboBoxClient.DisplayMember = "Description";
|
||||
comboBoxClient.ValueMember = "Id";
|
||||
|
||||
comboBoxTripId.DataSource = tripRepository.ReadTrips();
|
||||
|
@ -94,7 +94,14 @@ public partial class FormChecks : Form
|
||||
}
|
||||
|
||||
|
||||
private void LoadList() => dataGridViewChecks.DataSource =
|
||||
_checkRepository.ReadChecks();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewChecks.DataSource = _checkRepository.ReadChecks();
|
||||
dataGridViewChecks.Columns["Id"].Visible = false;
|
||||
dataGridViewChecks.Columns["clientId"].Visible = false;
|
||||
dataGridViewChecks.Columns["tripId"].Visible = false;
|
||||
dataGridViewChecks.Columns["PurchaseDate"].DefaultCellStyle.Format = "dd:MM:yyyy";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,12 @@ public partial class FormClients : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewClient.DataSource =
|
||||
_clientRepository.ReadClients();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewClient.DataSource = _clientRepository.ReadClients();
|
||||
dataGridViewClient.Columns["Id"].Visible = false;
|
||||
dataGridViewClient.Columns["Description"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@
|
||||
dataGridViewCompanies.RowHeadersVisible = false;
|
||||
dataGridViewCompanies.RowHeadersWidth = 51;
|
||||
dataGridViewCompanies.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewCompanies.Size = new Size(800, 450);
|
||||
dataGridViewCompanies.Size = new Size(665, 450);
|
||||
dataGridViewCompanies.TabIndex = 0;
|
||||
//
|
||||
// panel1
|
||||
@ -105,8 +105,8 @@
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(panel1);
|
||||
Controls.Add(dataGridViewCompanies);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormCompanies";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Компании";
|
||||
|
@ -93,8 +93,12 @@ public partial class FormCompanies : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewCompanies.DataSource =
|
||||
_companyRepository.ReadCompanies();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewCompanies.DataSource = _companyRepository.ReadCompanies();
|
||||
dataGridViewCompanies.Columns["Id"].Visible = false;
|
||||
dataGridViewCompanies.Columns["countryId"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -98,8 +98,11 @@ public partial class FormCountries : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource =
|
||||
_countryRepository.ReadCountries();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = _countryRepository.ReadCountries();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ Enum.GetValues(typeof(TravelType)))
|
||||
Convert.ToInt32(row.Cells["ColumnAdditionalPrice"].Value)));
|
||||
}
|
||||
return list.GroupBy(
|
||||
x => x.TripId,
|
||||
x => x.CompanyId ,
|
||||
x => new { x.AdditionalPrice, x.CompanyId },
|
||||
(id, counts) => CompanyTrip.CreateCompanyTrip(
|
||||
0,
|
||||
|
@ -58,8 +58,13 @@ public partial class FormTrips : Form
|
||||
|
||||
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource =
|
||||
_tripRepository.ReadTrips();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = _tripRepository.ReadTrips();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
dataGridView1.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
dataGridView1.Columns["EndDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ public class TableReport
|
||||
.Union(
|
||||
_tripRepository
|
||||
.ReadTrips()
|
||||
.Where(x => x.CompanyTrip.Any(y => y.CompanyId == companyId)) //TODO поиск по компании
|
||||
.Select(x => new { human = (int?)null, Date = x.EndDate, CountIn = (int?)null, CountOut = (int?)x.CompanyTrip.FirstOrDefault(y => y.CompanyId == companyId).AdditionalPrice }))
|
||||
//.Where(x => x.CompanyTrip.Any(y => y.CompanyId == companyId))
|
||||
.Select(x => new { human = (int?)null, Date = x.EndDate, CountIn = (int?)null, CountOut = (int?)100 })) //.CompanyTrip.FirstOrDefault(y => y.CompanyId == companyId).AdditionalPrice
|
||||
.OrderBy(x => x.Date);
|
||||
return
|
||||
new List<string[]>() { item }
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Dapper;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using Newtonsoft.Json;
|
||||
@ -9,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectTourismCompany.Repositories.Implementations;
|
||||
|
||||
@ -69,7 +71,11 @@ internal class CheckRepository : ICheckRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Receipt";
|
||||
var querySelect =
|
||||
@"SELECT re.*, cl.name as ClientName, tr.Title as TripName
|
||||
From receipt re LEFT JOIN client cl ON re.clientId = cl.Id
|
||||
LEFT JOIN Trip tr ON tr.Id = re.tripId";
|
||||
|
||||
var expenses = connection.Query<Check>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(expenses));
|
||||
return expenses;
|
||||
|
@ -84,7 +84,7 @@ internal class CompanyRepository : ICompanyRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Company";
|
||||
var querySelect = "SELECT co.*, coun.CountryName as CountryName FROM Company co LEFT JOIN Country coun on co.countryId = coun.Id";
|
||||
var peopleExpenses = connection.Query<Company>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(peopleExpenses));
|
||||
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTourismCompany.Repositories.Implementations;
|
||||
|
||||
public 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}";
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using PdfSharp.Drawing;
|
||||
using ProjectTourismCompany.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -84,18 +85,59 @@ internal class TripRepository : ITripRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Trip> ReadTrips(DateTime? dateForm = null, DateTime? dateTo = null, int? tripId = null, int? companyId = null)
|
||||
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? clientId = null, int? companyId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("t.StartDate >= @dateFrom");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("t.EndDate <= @dateTo");
|
||||
}
|
||||
if (clientId.HasValue)
|
||||
{
|
||||
builder.AddCondition("t.ClientId = @clientId");
|
||||
}
|
||||
if (companyId.HasValue)
|
||||
{
|
||||
builder.AddCondition("ct.companyId = @companyId");
|
||||
}
|
||||
|
||||
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT t.*, ct.companyId, ct.additionalPrice FROM Trip t INNER JOIN companyTrip ct ON ct.tripId = t.Id";
|
||||
var trips = connection.Query<TempCompanyTrip>(querySelect);
|
||||
var querySelect = @$"SELECT t.*, ct.tripId, ct.AdditionalPrice,comp.Name as CompanyName
|
||||
FROM Trip t
|
||||
INNER JOIN companyTrip ct ON ct.tripId = t.Id
|
||||
Inner JOIN Company comp ON ct.companyId = comp.Id
|
||||
{builder.Build()}";
|
||||
|
||||
var tripDict = new Dictionary<int, List<CompanyTrip>>();
|
||||
|
||||
|
||||
var trips = connection.Query<Trip, CompanyTrip, Trip>(querySelect, (trip, companyTrip) =>
|
||||
{
|
||||
if (!tripDict.TryGetValue(trip.Id, out var ct))
|
||||
{
|
||||
ct = [];
|
||||
tripDict.Add(trip.Id, ct);
|
||||
}
|
||||
ct.Add(companyTrip);
|
||||
return trip;
|
||||
|
||||
}, splitOn: "tripId", param: new { dateFrom , dateTo, clientId, companyId});
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(trips));
|
||||
return trips.GroupBy(x => x.Id, y => y,
|
||||
(key, value) => Trip.CreateOpeartion(value.First(),
|
||||
value.Select(z => CompanyTrip.CreateCompanyTrip(0, z.CompanyId, z.TripId, z.AdditionalPrice )))).ToList();
|
||||
return tripDict.Select(x =>
|
||||
{
|
||||
var tr = trips.First(y => y.Id == x.Key);
|
||||
tr.SetCompanyTrip(x.Value);
|
||||
return tr;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user