4 лабораторная работа
This commit is contained in:
parent
46c7949db2
commit
96d73d100b
@ -1,20 +1,23 @@
|
|||||||
using System;
|
using ProjectFamilyBudget.Entities.Enums;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ProjectFamilyBudget.Entities.Enums;
|
|
||||||
|
|
||||||
namespace ProjectFamilyBudget.Entities;
|
namespace ProjectFamilyBudget.Entities;
|
||||||
|
|
||||||
public class Expense
|
public class Expense
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Тип расхода")]
|
||||||
public IncomeExpenseType ExpenseType { get; private set; }
|
public IncomeExpenseType ExpenseType { get; private set; }
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Категория")]
|
||||||
public string ExpenseCategory { get; private set; } = string.Empty;
|
public string ExpenseCategory { get; private set; } = string.Empty;
|
||||||
|
public static Expense CreateEntity(int id,IncomeExpenseType expenseType, string name, string expenseCategory)
|
||||||
public static Expense CreateEntity(int id, IncomeExpenseType expenseType, string name, string expenseCategory)
|
|
||||||
{
|
{
|
||||||
return new Expense
|
return new Expense
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ public class ExpensePeopleExpense
|
|||||||
public int PeopleExpenseId { get; private set; }
|
public int PeopleExpenseId { get; private set; }
|
||||||
public int ExpenseId { get; private set; }
|
public int ExpenseId { get; private set; }
|
||||||
public int Sum { get; private set; }
|
public int Sum { get; private set; }
|
||||||
|
public string ExpenseName { get; private set; } = string.Empty;
|
||||||
public static ExpensePeopleExpense CreateElement(int peopleExpenseId, int expenseId, int sum)
|
public static ExpensePeopleExpense CreateElement(int peopleExpenseId, int expenseId, int sum)
|
||||||
{
|
{
|
||||||
return new ExpensePeopleExpense
|
return new ExpensePeopleExpense
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
using System;
|
using ProjectFamilyBudget.Entities.Enums;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ProjectFamilyBudget.Entities.Enums;
|
|
||||||
|
|
||||||
namespace ProjectFamilyBudget.Entities;
|
namespace ProjectFamilyBudget.Entities;
|
||||||
|
|
||||||
public class Income
|
public class Income
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Тип дохода")]
|
||||||
public IncomeExpenseType IncomeType { get; private set; }
|
public IncomeExpenseType IncomeType { get; private set; }
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Категория")]
|
||||||
public string IncomeCategory { get; private set; } = string.Empty;
|
public string IncomeCategory { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static Income CreateEntity(int id, IncomeExpenseType incomeType, string name, string incomeCategory)
|
public static Income CreateEntity(int id, IncomeExpenseType incomeType, string name, string incomeCategory)
|
||||||
@ -25,4 +29,3 @@ public class Income
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ public class IncomePeopleIncome
|
|||||||
public int PeopleIncomeId { get; private set; }
|
public int PeopleIncomeId { get; private set; }
|
||||||
public int IncomeId { get; private set; }
|
public int IncomeId { get; private set; }
|
||||||
public int Sum { get; private set; }
|
public int Sum { get; private set; }
|
||||||
|
public string IncomeName { get; private set; } = string.Empty;
|
||||||
public static IncomePeopleIncome CreateElement(int peopleIncomeId,int incomeId, int sum)
|
public static IncomePeopleIncome CreateElement(int peopleIncomeId,int incomeId, int sum)
|
||||||
{
|
{
|
||||||
return new IncomePeopleIncome
|
return new IncomePeopleIncome
|
||||||
|
@ -1,20 +1,27 @@
|
|||||||
using System;
|
using Microsoft.VisualBasic.FileIO;
|
||||||
|
using ProjectFamilyBudget.Entities.Enums;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ProjectFamilyBudget.Entities.Enums;
|
|
||||||
|
|
||||||
namespace ProjectFamilyBudget.Entities;
|
namespace ProjectFamilyBudget.Entities;
|
||||||
|
|
||||||
public class People
|
public class People
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string LastName { get; private set; } = string.Empty;
|
public string LastName { get; private set; } = string.Empty;
|
||||||
public int Age { get; private set; }
|
public string FullName => $"{Name} {LastName}";
|
||||||
|
[DisplayName("Возраст")]
|
||||||
|
public int Age { get; private set; }
|
||||||
|
[DisplayName("Член семьи")]
|
||||||
public FamilyMemberType MemberType { get; private set; }
|
public FamilyMemberType MemberType { get; private set; }
|
||||||
public static People CreateEntity(int id, string name, string lastName, int age, FamilyMemberType memberType)
|
public static People CreateEntity(int id, string name,string lastName, int age, FamilyMemberType memberType)
|
||||||
{
|
{
|
||||||
return new People
|
return new People
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,8 +10,16 @@ namespace ProjectFamilyBudget.Entities;
|
|||||||
public class PeopleExpense
|
public class PeopleExpense
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int PeopleId { get; private set; }
|
public int PeopleId { get; private set; }
|
||||||
|
[DisplayName("Человек")]
|
||||||
|
public string PeopleName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Дата")]
|
||||||
public DateTime DataReciept { get; private set; }
|
public DateTime DataReciept { get; private set; }
|
||||||
|
[DisplayName("Расходы")]
|
||||||
|
public string Expense => ExpensePeopleExpenses != null ?
|
||||||
|
string.Join(", ", ExpensePeopleExpenses.Select(x => $"{x.ExpenseName} {x.Sum}")) : string.Empty;
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<ExpensePeopleExpense> ExpensePeopleExpenses { get; private set; } = [];
|
public IEnumerable<ExpensePeopleExpense> ExpensePeopleExpenses { get; private set; } = [];
|
||||||
public static PeopleExpense CreateOperation(int id, int peopleId, DateTime dataReciept,IEnumerable<ExpensePeopleExpense> expensePeopleExpenses)
|
public static PeopleExpense CreateOperation(int id, int peopleId, DateTime dataReciept,IEnumerable<ExpensePeopleExpense> expensePeopleExpenses)
|
||||||
{
|
{
|
||||||
@ -22,14 +31,11 @@ public class PeopleExpense
|
|||||||
ExpensePeopleExpenses = expensePeopleExpenses
|
ExpensePeopleExpenses = expensePeopleExpenses
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static PeopleExpense CreateOperation(TempExpensePeopleExpense tempExpensePeopleExpense, IEnumerable<ExpensePeopleExpense> expensePeopleExpenses)
|
public void SetExpensePeopleExpenses(IEnumerable<ExpensePeopleExpense> expensePeopleExpenses)
|
||||||
{
|
{
|
||||||
return new PeopleExpense
|
if (expensePeopleExpenses != null && expensePeopleExpenses.Any())
|
||||||
{
|
{
|
||||||
Id = tempExpensePeopleExpense.Id,
|
ExpensePeopleExpenses = expensePeopleExpenses;
|
||||||
PeopleId = tempExpensePeopleExpense.PeopleId,
|
}
|
||||||
DataReciept = tempExpensePeopleExpense.DataReciept,
|
|
||||||
ExpensePeopleExpenses = expensePeopleExpenses
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ProjectFamilyBudget.Entities.Enums;
|
using ProjectFamilyBudget.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,8 +11,16 @@ namespace ProjectFamilyBudget.Entities;
|
|||||||
public class PeopleIncome
|
public class PeopleIncome
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int PeopleId { get; private set; }
|
public int PeopleId { get; private set; }
|
||||||
|
[DisplayName("Человек")]
|
||||||
|
public string PeopleName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Дата")]
|
||||||
public DateTime DataReciept { get; private set; }
|
public DateTime DataReciept { get; private set; }
|
||||||
|
[DisplayName("Доходы")]
|
||||||
|
public string Income => IncomePeopleIncomes != null ?
|
||||||
|
string.Join(", ", IncomePeopleIncomes.Select(x => $"{x.IncomeName} {x.Sum}")) : string.Empty;
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<IncomePeopleIncome> IncomePeopleIncomes { get; private set; } = [];
|
public IEnumerable<IncomePeopleIncome> IncomePeopleIncomes { get; private set; } = [];
|
||||||
public static PeopleIncome CreateOperation(int id, int peopleId,DateTime dataReciept,IEnumerable<IncomePeopleIncome> incomePeopleIncomes)
|
public static PeopleIncome CreateOperation(int id, int peopleId,DateTime dataReciept,IEnumerable<IncomePeopleIncome> incomePeopleIncomes)
|
||||||
{
|
{
|
||||||
@ -23,14 +32,11 @@ public class PeopleIncome
|
|||||||
IncomePeopleIncomes = incomePeopleIncomes
|
IncomePeopleIncomes = incomePeopleIncomes
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static PeopleIncome CreateOperation(TempIncomePeopleIncome tempIncomePeopleIncome, IEnumerable<IncomePeopleIncome> incomePeopleIncomes)
|
public void SetIncomePeopleIncomes(IEnumerable<IncomePeopleIncome> incomePeopleIncomes)
|
||||||
{
|
{
|
||||||
return new PeopleIncome
|
if (incomePeopleIncomes != null && incomePeopleIncomes.Any())
|
||||||
{
|
{
|
||||||
Id = tempIncomePeopleIncome.Id,
|
IncomePeopleIncomes = incomePeopleIncomes;
|
||||||
PeopleId = tempIncomePeopleIncome.PeopleId,
|
}
|
||||||
DataReciept = tempIncomePeopleIncome.DataReciept,
|
|
||||||
IncomePeopleIncomes = incomePeopleIncomes
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectFamilyBudget.Entities;
|
|
||||||
|
|
||||||
public class TempExpensePeopleExpense
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
public int PeopleId { get; private set; }
|
|
||||||
public DateTime DataReciept { get; private set; }
|
|
||||||
public int ExpenseId { get; private set; }
|
|
||||||
public int Sum { get; private set; }
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectFamilyBudget.Entities;
|
|
||||||
|
|
||||||
public class TempIncomePeopleIncome
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
public int PeopleId { get; private set; }
|
|
||||||
public DateTime DataReciept { get; private set; }
|
|
||||||
public int IncomeId { get; private set; }
|
|
||||||
public int Sum { get; private set; }
|
|
||||||
}
|
|
@ -93,7 +93,12 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridViewData.DataSource = _expense.ReadExpense();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _expense.ReadExpense();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -94,7 +94,12 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridViewData.DataSource = _income.ReadIncome();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _income.ReadIncome();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -21,7 +21,7 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
_peopleEpxense = peopleEpxense ??
|
_peopleEpxense = peopleEpxense ??
|
||||||
throw new ArgumentNullException(nameof(peopleEpxense));
|
throw new ArgumentNullException(nameof(peopleEpxense));
|
||||||
comboBoxPeople.DataSource = people.ReadPeople();
|
comboBoxPeople.DataSource = people.ReadPeople();
|
||||||
comboBoxPeople.DisplayMember = "Name";
|
comboBoxPeople.DisplayMember = "FullName";
|
||||||
comboBoxPeople.ValueMember = "Id";
|
comboBoxPeople.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnExpense.DataSource = expense.ReadExpense();
|
ColumnExpense.DataSource = expense.ReadExpense();
|
||||||
|
@ -76,7 +76,13 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridViewData.DataSource = _peopleExpense.ReadPeopleExpense();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _peopleExpense.ReadPeopleExpense();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["DataReciept"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -21,7 +21,7 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
_peopleIncome = peopleIncome ??
|
_peopleIncome = peopleIncome ??
|
||||||
throw new ArgumentNullException(nameof(peopleIncome));
|
throw new ArgumentNullException(nameof(peopleIncome));
|
||||||
comboBoxPeople.DataSource = people.ReadPeople();
|
comboBoxPeople.DataSource = people.ReadPeople();
|
||||||
comboBoxPeople.DisplayMember = "Name";
|
comboBoxPeople.DisplayMember = "FullName";
|
||||||
comboBoxPeople.ValueMember = "Id";
|
comboBoxPeople.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnIncome.DataSource = income.ReadIncome();
|
ColumnIncome.DataSource = income.ReadIncome();
|
||||||
|
@ -74,7 +74,13 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridViewData.DataSource = _peopleIncome.ReadPeopleIncome();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _peopleIncome.ReadPeopleIncome();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["DataReciept"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -92,7 +92,13 @@ namespace ProjectFamilyBudget.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridViewData.DataSource = _people.ReadPeople();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _people.ReadPeople();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["FullName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -25,8 +25,8 @@ public class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Траты людей")
|
.AddHeader("Траты людей")
|
||||||
.AddPieChart("Виды трат", GetData(expenseId, dateTime))
|
.AddPieChart($"Траты за {dateTime:dd MMMM yyyy}", GetData(expenseId, dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -38,14 +38,13 @@ public class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(int expenseId, DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(int expenseId, DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _peopleExpense
|
return _peopleExpense
|
||||||
.ReadPeopleExpense()
|
.ReadPeopleExpense(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1),expenseId: expenseId)
|
||||||
.Where(x => x.DataReciept.Date == dateTime.Date)
|
.GroupBy(x => x.PeopleName, (key, group) => new
|
||||||
.GroupBy(x => x.PeopleId, (key, group) => new
|
|
||||||
{
|
{
|
||||||
Id = key,
|
PeopleName = key,
|
||||||
Count = group.Sum(x => x.ExpensePeopleExpenses.FirstOrDefault(y => y.ExpenseId == expenseId)?.Sum ?? 0)
|
Count = group.Sum(x => x.ExpensePeopleExpenses.FirstOrDefault(y => y.ExpenseId == expenseId)?.Sum ?? 0)
|
||||||
})
|
})
|
||||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
.Select(x => (x.PeopleName, (double)x.Count))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по движению денег", 0, 4)
|
.AddHeader("Сводка по движению денег", 0, 4)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}",0)
|
||||||
.AddTable([15, 10, 15, 15], GetData(incomeId, expenseId, startDate, endDate))
|
.AddTable([15, 10, 15, 15], GetData(incomeId, expenseId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -40,21 +40,22 @@ public class TableReport
|
|||||||
private List<string[]> GetData(int incomeId,int expenseId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int incomeId,int expenseId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _peopleIncomeRepository
|
var data = _peopleIncomeRepository
|
||||||
.ReadPeopleIncome()
|
.ReadPeopleIncome(dateForm: startDate, dateTo: endDate, incomeId: incomeId)
|
||||||
.Where(x => x.DataReciept >= startDate && x.DataReciept <= endDate && x.IncomePeopleIncomes.Any(y => y.IncomeId == incomeId))
|
.Select(x => new { x.PeopleName, Date = x.DataReciept,
|
||||||
.Select(x => new { x.PeopleId, Date = x.DataReciept, CountIn = x.IncomePeopleIncomes.FirstOrDefault(y => y.IncomeId == incomeId)?.Sum, CountOut = (int?)null })
|
CountIn = x.IncomePeopleIncomes.FirstOrDefault(y => y.IncomeId == incomeId)?.Sum, CountOut = (int?)null })
|
||||||
.Union(
|
.Union(
|
||||||
_peopleExpenseRepository
|
_peopleExpenseRepository
|
||||||
.ReadPeopleExpense()
|
.ReadPeopleExpense(dateForm: startDate, dateTo: endDate, expenseId: expenseId)
|
||||||
.Where(x => x.DataReciept >= startDate && x.DataReciept <= endDate && x.ExpensePeopleExpenses.Any(y => y.ExpenseId == expenseId))
|
.Select(x => new { x.PeopleName, Date = x.DataReciept, CountIn = (int?)null,
|
||||||
.Select(x => new { x.PeopleId, Date = x.DataReciept, CountIn = (int?)null, CountOut = x.ExpensePeopleExpenses.FirstOrDefault(y => y.ExpenseId == expenseId)?.Sum }))
|
CountOut = x.ExpensePeopleExpenses.FirstOrDefault(y => y.ExpenseId == expenseId)?.Sum }))
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date);
|
||||||
return
|
return
|
||||||
new List<string[]>() { item }
|
new List<string[]>() { item }
|
||||||
.Union(data.Select(x => new string[] {x.PeopleId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty,x.CountOut?.ToString() ?? string.Empty }))
|
|
||||||
.Union(
|
.Union(
|
||||||
[[ "Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString() ]]
|
data.Select(x => new string[] {x.PeopleName, x.Date.ToString("dd.MM.yyyy"), x.CountIn?.ToString("N0") ?? string.Empty,
|
||||||
)
|
x.CountOut?.ToString("N0") ?? string.Empty }))
|
||||||
|
.Union(
|
||||||
|
[[ "Всего", "", data.Sum(x => x.CountIn ?? 0).ToString("N0"), data.Sum(x => x.CountOut ?? 0).ToString("N0") ]])
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,14 +90,58 @@ public class PeopleExpenseRepository : IPeopleExpense
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateForm.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("pe.DataReciept >= @dateForm");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("pe.DataReciept <= @dateTo");
|
||||||
|
}
|
||||||
|
if (peopleId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("pe.PeopleId = @peopleId");
|
||||||
|
}
|
||||||
|
if (expenseId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("epe.ExpenseId = @expenseId");
|
||||||
|
}
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT pe.*, epe.ExpenseId, epe.Sum FROM PeopleExpense pe
|
var querySelect = $@"SELECT
|
||||||
INNER JOIN ExpensePeopleExpense epe on epe.PeopleExpenseId = pe.Id";
|
pe.*,
|
||||||
var peopleExpenses = connection.Query<TempExpensePeopleExpense>(querySelect);
|
CONCAT(p.Name, ' ', p.LastName) as PeopleName,
|
||||||
|
epe.ExpenseId,
|
||||||
|
epe.Sum,
|
||||||
|
e.Name as ExpenseName
|
||||||
|
FROM PeopleExpense pe
|
||||||
|
LEFT JOIN People p on p.Id = pe.PeopleId
|
||||||
|
INNER JOIN ExpensePeopleExpense epe on epe.PeopleExpenseId = pe.Id
|
||||||
|
LEFT JOIN Expense e on e.Id = epe.ExpenseId
|
||||||
|
{builder.Build()}";
|
||||||
|
var expenseDict = new Dictionary<int, List<ExpensePeopleExpense>>();
|
||||||
|
|
||||||
|
var peopleExpenses = connection.Query<PeopleExpense, ExpensePeopleExpense, PeopleExpense>(querySelect,
|
||||||
|
(expense, peopleExpenses) =>
|
||||||
|
{
|
||||||
|
if (!expenseDict.TryGetValue(expense.Id, out var epe))
|
||||||
|
{
|
||||||
|
epe = [];
|
||||||
|
expenseDict.Add(expense.Id, epe);
|
||||||
|
}
|
||||||
|
|
||||||
|
epe.Add(peopleExpenses);
|
||||||
|
return expense;
|
||||||
|
}, splitOn: "ExpenseId", param: new { dateForm, dateTo, peopleId, expenseId });
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(peopleExpenses));
|
JsonConvert.SerializeObject(peopleExpenses));
|
||||||
return peopleExpenses.GroupBy(x => x.Id, y => y, (key, value) => PeopleExpense.CreateOperation(value.First(),
|
|
||||||
value.Select(z => ExpensePeopleExpense.CreateElement(0, z.ExpenseId, z.Sum)))).ToList();
|
return expenseDict.Select(x =>
|
||||||
|
{
|
||||||
|
var pe = peopleExpenses.First(y => y.Id == x.Key);
|
||||||
|
pe.SetExpensePeopleExpenses(x.Value);
|
||||||
|
return pe;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||||
@ -93,13 +93,58 @@ public class PeopleIncomeRepository : IPeopleIncome
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateForm.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("pi.DataReciept >= @dateForm");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("pi.DataReciept <= @dateTo");
|
||||||
|
}
|
||||||
|
if (peopleId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("pi.PeopleId = @peopleId");
|
||||||
|
}
|
||||||
|
if (incomeId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ipi.IncomeId = @incomeId");
|
||||||
|
}
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT pi.*, ipi.IncomeId, ipi.Sum FROM PeopleIncome pi
|
var querySelect = $@"SELECT
|
||||||
INNER JOIN IncomePeopleIncome ipi on ipi.PeopleIncomeId = pi.Id";
|
pi.*,
|
||||||
var peopleIncomes = connection.Query<TempIncomePeopleIncome>(querySelect);
|
CONCAT(p.Name, ' ', p.LastName) as PeopleName,
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(peopleIncomes));
|
ipi.IncomeId,
|
||||||
return peopleIncomes.GroupBy(x => x.Id, y => y, (key, value) => PeopleIncome.CreateOperation(value.First(),
|
ipi.Sum,
|
||||||
value.Select(z => IncomePeopleIncome.CreateElement(0, z.IncomeId, z.Sum)))).ToList();
|
i.Name as IncomeName
|
||||||
|
FROM PeopleIncome pi
|
||||||
|
LEFT JOIN People p on p.Id = pi.PeopleId
|
||||||
|
INNER JOIN IncomePeopleIncome ipi on ipi.PeopleIncomeId = pi.Id
|
||||||
|
LEFT JOIN Income i on i.Id = ipi.IncomeId
|
||||||
|
{builder.Build()}";
|
||||||
|
var incomeDict = new Dictionary<int, List<IncomePeopleIncome>>();
|
||||||
|
|
||||||
|
var peopleIncomes = connection.Query<PeopleIncome, IncomePeopleIncome, PeopleIncome>(querySelect,
|
||||||
|
(income, peopleIncomes) =>
|
||||||
|
{
|
||||||
|
if (!incomeDict.TryGetValue(income.Id, out var ipi))
|
||||||
|
{
|
||||||
|
ipi = [];
|
||||||
|
incomeDict.Add(income.Id, ipi);
|
||||||
|
}
|
||||||
|
|
||||||
|
ipi.Add(peopleIncomes);
|
||||||
|
return income;
|
||||||
|
}, splitOn: "IncomeId", param: new { dateForm, dateTo, peopleId, incomeId });
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(peopleIncomes));
|
||||||
|
|
||||||
|
return incomeDict.Select(x =>
|
||||||
|
{
|
||||||
|
var pi = peopleIncomes.First(y => y.Id == x.Key);
|
||||||
|
pi.SetIncomePeopleIncomes(x.Value);
|
||||||
|
return pi;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectFamilyBudget.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}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user