2 лабораторная работа
This commit is contained in:
parent
6d42a1dc3c
commit
a1f04bea39
@ -8,14 +8,14 @@ namespace ProjectFamilyBudget.Entities;
|
||||
|
||||
public class ExpensePeopleExpense
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PeopleExpenseId { get; private set; }
|
||||
public int ExpenseId { get; private set; }
|
||||
public int Sum { get; private set; }
|
||||
public static ExpensePeopleExpense CreateElement(int id, int expenseId, int sum)
|
||||
public static ExpensePeopleExpense CreateElement(int peopleExpenseId, int expenseId, int sum)
|
||||
{
|
||||
return new ExpensePeopleExpense
|
||||
{
|
||||
Id = id,
|
||||
PeopleExpenseId = peopleExpenseId,
|
||||
ExpenseId = expenseId,
|
||||
Sum = sum
|
||||
};
|
||||
|
@ -8,16 +8,16 @@ namespace ProjectFamilyBudget.Entities;
|
||||
|
||||
public class IncomePeopleIncome
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PeopleIncomeId { get; private set; }
|
||||
public int IncomeId { get; private set; }
|
||||
public int Sum { get; private set; }
|
||||
public static IncomePeopleIncome CreateElement(int id, int incomeId, int sum)
|
||||
public static IncomePeopleIncome CreateElement(int peopleIncomeId,int incomeId, int sum)
|
||||
{
|
||||
return new IncomePeopleIncome
|
||||
{
|
||||
Id = id,
|
||||
PeopleIncomeId = peopleIncomeId,
|
||||
IncomeId = incomeId,
|
||||
Sum = sum
|
||||
Sum = sum
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,16 @@ public class PeopleExpense
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PeopleId { get; private set; }
|
||||
public DateTime DataReceipt { get; private set; }
|
||||
public DateTime DataReciept { get; private set; }
|
||||
public IEnumerable<ExpensePeopleExpense> ExpensePeopleExpenses { get; private set; } = [];
|
||||
public static PeopleExpense CreateOperation(int id, int peopleId, IEnumerable<ExpensePeopleExpense> expensePeopleExpenses)
|
||||
public static PeopleExpense CreateOperation(int id, int peopleId, DateTime dataReciept,IEnumerable<ExpensePeopleExpense> expensePeopleExpenses)
|
||||
{
|
||||
return new PeopleExpense
|
||||
{
|
||||
Id = id,
|
||||
PeopleId = peopleId,
|
||||
DataReceipt = DateTime.Now,
|
||||
DataReciept = dataReciept,
|
||||
ExpensePeopleExpenses = expensePeopleExpenses
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -10,17 +11,16 @@ public class PeopleIncome
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PeopleId { get; private set; }
|
||||
public DateTime DataReceipt { get; private set; }
|
||||
public DateTime DataReciept { get; private set; }
|
||||
public IEnumerable<IncomePeopleIncome> IncomePeopleIncomes { get; private set; } = [];
|
||||
public static PeopleIncome CreateOperation(int id, int peopleId, IEnumerable<IncomePeopleIncome> incomePeopleIncomes)
|
||||
public static PeopleIncome CreateOperation(int id, int peopleId,DateTime dataReciept,IEnumerable<IncomePeopleIncome> incomePeopleIncomes)
|
||||
{
|
||||
return new PeopleIncome
|
||||
{
|
||||
Id = id,
|
||||
PeopleId = peopleId,
|
||||
DataReceipt = DateTime.Now,
|
||||
DataReciept = dataReciept,
|
||||
IncomePeopleIncomes = incomePeopleIncomes
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,7 +9,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
@ -92,8 +93,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _expense.ReadExpense;
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _expense.ReadExpense();
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
@ -106,6 +106,6 @@ namespace ProjectFamilyBudget.Forms
|
||||
id =
|
||||
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,7 +9,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
@ -93,7 +94,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _income.ReadIncome;
|
||||
private void LoadList() => dataGridViewData.DataSource = _income.ReadIncome();
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -30,14 +30,14 @@
|
||||
{
|
||||
label1 = new Label();
|
||||
comboBoxPeople = new ComboBox();
|
||||
label3 = new Label();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
groupBox = new GroupBox();
|
||||
dataGridView = new DataGridView();
|
||||
ColumnExpense = new DataGridViewComboBoxColumn();
|
||||
ColumnSum = new DataGridViewTextBoxColumn();
|
||||
buttonSave = new Button();
|
||||
buttonCansel = new Button();
|
||||
label3 = new Label();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
groupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -60,23 +60,6 @@
|
||||
comboBoxPeople.Size = new Size(212, 23);
|
||||
comboBoxPeople.TabIndex = 3;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(57, 70);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(32, 15);
|
||||
label3.TabIndex = 8;
|
||||
label3.Text = "Дата";
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Enabled = false;
|
||||
dateTimePicker.Location = new Point(140, 64);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(212, 23);
|
||||
dateTimePicker.TabIndex = 9;
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
@ -135,6 +118,22 @@
|
||||
buttonCansel.UseVisualStyleBackColor = true;
|
||||
buttonCansel.Click += buttonCansel_Click;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(57, 70);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(32, 15);
|
||||
label3.TabIndex = 8;
|
||||
label3.Text = "Дата";
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(140, 64);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(212, 23);
|
||||
dateTimePicker.TabIndex = 9;
|
||||
//
|
||||
// FormPeopleExpense
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -160,13 +159,13 @@
|
||||
|
||||
private Label label1;
|
||||
private ComboBox comboBoxPeople;
|
||||
private Label label3;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private GroupBox groupBox;
|
||||
private DataGridView dataGridView;
|
||||
private DataGridViewComboBoxColumn ColumnExpense;
|
||||
private DataGridViewTextBoxColumn ColumnSum;
|
||||
private Button buttonSave;
|
||||
private Button buttonCansel;
|
||||
private Label label3;
|
||||
private DateTimePicker dateTimePicker;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,8 +9,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
_peopleEpxense.CreatePeopleExpense(PeopleExpense.CreateOperation(0, (int)comboBoxPeople.SelectedValue!,
|
||||
_peopleEpxense.CreatePeopleExpense(PeopleExpense.CreateOperation(0, (int)comboBoxPeople.SelectedValue!, dateTimePicker.Value,
|
||||
CreateListPeopleExpenseFromDataGrid()));
|
||||
Close();
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
@ -117,4 +117,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="ColumnExpense.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnSum.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,7 +9,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System.Xml.Linq;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
@ -74,7 +76,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _peopleExpense.ReadPeopleExpense;
|
||||
private void LoadList() => dataGridViewData.DataSource = _peopleExpense.ReadPeopleExpense();
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -37,8 +37,8 @@
|
||||
ColumnSum = new DataGridViewTextBoxColumn();
|
||||
buttonSave = new Button();
|
||||
buttonCansel = new Button();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
label3 = new Label();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
groupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -129,14 +129,6 @@
|
||||
buttonCansel.UseVisualStyleBackColor = true;
|
||||
buttonCansel.Click += buttonCansel_Click;
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Enabled = false;
|
||||
dateTimePicker.Location = new Point(127, 62);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(216, 23);
|
||||
dateTimePicker.TabIndex = 6;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
@ -146,6 +138,13 @@
|
||||
label3.TabIndex = 7;
|
||||
label3.Text = "Дата";
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(127, 62);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(216, 23);
|
||||
dateTimePicker.TabIndex = 6;
|
||||
//
|
||||
// FormPeopleIncome
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -179,7 +178,7 @@
|
||||
private Button buttonCansel;
|
||||
private DataGridViewComboBoxColumn ColumnIncome;
|
||||
private DataGridViewTextBoxColumn ColumnSum;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private Label label3;
|
||||
private DateTimePicker dateTimePicker;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,8 +9,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
_peopleIncome.CreatePeopleIncome(PeopleIncome.CreateOperation(0, (int)comboBoxPeople.SelectedValue!,
|
||||
_peopleIncome.CreatePeopleIncome(PeopleIncome.CreateOperation(0, (int)comboBoxPeople.SelectedValue!, dateTimePicker.Value,
|
||||
CreateListPeopleIncomeFromDataGrid()));
|
||||
Close();
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,7 +9,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
@ -73,7 +74,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _peopleIncome.ReadPeopleIncome;
|
||||
private void LoadList() => dataGridViewData.DataSource = _peopleIncome.ReadPeopleIncome();
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -43,20 +43,18 @@
|
||||
panel1.Controls.Add(buttonEdit);
|
||||
panel1.Controls.Add(buttonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(696, 0);
|
||||
panel1.Margin = new Padding(3, 4, 3, 4);
|
||||
panel1.Location = new Point(609, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(218, 600);
|
||||
panel1.Size = new Size(191, 450);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// buttonCansel
|
||||
//
|
||||
buttonCansel.BackgroundImage = Properties.Resources.minus;
|
||||
buttonCansel.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonCansel.Location = new Point(47, 333);
|
||||
buttonCansel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCansel.Location = new Point(41, 250);
|
||||
buttonCansel.Name = "buttonCansel";
|
||||
buttonCansel.Size = new Size(126, 85);
|
||||
buttonCansel.Size = new Size(110, 64);
|
||||
buttonCansel.TabIndex = 2;
|
||||
buttonCansel.UseVisualStyleBackColor = true;
|
||||
buttonCansel.Click += buttonCansel_Click;
|
||||
@ -65,10 +63,9 @@
|
||||
//
|
||||
buttonEdit.BackgroundImage = Properties.Resources.pen;
|
||||
buttonEdit.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonEdit.Location = new Point(47, 181);
|
||||
buttonEdit.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonEdit.Location = new Point(41, 136);
|
||||
buttonEdit.Name = "buttonEdit";
|
||||
buttonEdit.Size = new Size(126, 85);
|
||||
buttonEdit.Size = new Size(110, 64);
|
||||
buttonEdit.TabIndex = 1;
|
||||
buttonEdit.UseVisualStyleBackColor = true;
|
||||
buttonEdit.Click += buttonEdit_Click;
|
||||
@ -77,10 +74,9 @@
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.plus;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonAdd.Location = new Point(47, 40);
|
||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAdd.Location = new Point(41, 30);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(126, 85);
|
||||
buttonAdd.Size = new Size(110, 64);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
@ -95,23 +91,21 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(3, 4, 3, 4);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.Size = new Size(696, 600);
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(609, 450);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormPeoples
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 600);
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormPeoples";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Люди";
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -7,7 +9,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Forms
|
||||
@ -91,7 +92,7 @@ namespace ProjectFamilyBudget.Forms
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _people.ReadPeople;
|
||||
private void LoadList() => dataGridViewData.DataSource = _people.ReadPeople();
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
@ -106,4 +107,4 @@ namespace ProjectFamilyBudget.Forms
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,54 @@
|
||||
using Unity;
|
||||
using Unity.Lifetime; // Äëÿ óïðàâëåíèÿ âðåìåíåì æèçíè îáúåêòîâ
|
||||
using ProjectFamilyBudget.Repositories; // Ïðîñòðàíñòâî èìåí äëÿ ðåïîçèòîðèåâ
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectFamilyBudget.Repositories;
|
||||
using ProjectFamilyBudget.Repositories.Implementations;
|
||||
using ProjectFamilyBudget; // Ïðîñòðàíñòâî èìåí äëÿ ðåàëèçàöèé ðåïîçèòîðèåâ
|
||||
using Serilog;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
internal static class Program
|
||||
namespace ProjectFamilyBudget
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
internal static class Program
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(CreateContainer().Resolve<FormFamilyBudget>());
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(CreateContainer().Resolve<FormFamilyBudget>());
|
||||
|
||||
}
|
||||
|
||||
private static IUnityContainer CreateContainer()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IPeople, PeopleRepository>();
|
||||
container.RegisterType<IIncome, IncomeRepository>();
|
||||
container.RegisterType<IExpense, ExpenseRepository>();
|
||||
container.RegisterType<IPeopleIncome, PeopleIncomeRepository>();
|
||||
container.RegisterType<IPeopleExpense, PeopleExpenseRepository>();
|
||||
|
||||
container.RegisterType<IConnectionString, ConnectionString>();
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static IUnityContainer CreateContainer()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.RegisterType<IPeople, PeopleRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IIncome, IncomeRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IExpense, ExpenseRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IPeopleIncome, PeopleIncomeRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IPeopleExpense, PeopleExpenseRepository>(new TransientLifetimeManager());
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -27,4 +38,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=postgres";
|
||||
}
|
@ -1,37 +1,123 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||
|
||||
public class ExpenseRepository : IExpense
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<ExpenseRepository> _logger;
|
||||
public ExpenseRepository(IConnectionString connectionString, ILogger<ExpenseRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateExpense(Expense expense)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(expense));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Expense (ExpenseType, Name, ExpenseCategory)
|
||||
VALUES (@ExpenseType, @Name, @ExpenseCategory)";
|
||||
connection.Execute(queryInsert, expense);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateExpense(Expense expense)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(expense));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Expense
|
||||
SET
|
||||
ExpenseType=@ExpenseType,
|
||||
Name=@Name,
|
||||
ExpenseCategory=@ExpenseCategory
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, expense);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteExpense(int id)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Expense
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Expense ReadExpenseById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Expense
|
||||
WHERE Id=@id";
|
||||
var expense = connection.QueryFirst<Expense>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(expense));
|
||||
return expense;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Expense> ReadExpense()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public Expense ReadExpenseById(int id)
|
||||
{
|
||||
return Expense.CreateEntity(0, IncomeExpenseType.None, string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
public void UpdateExpense(Expense expense)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Expense";
|
||||
var expenses = connection.Query<Expense>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(expenses));
|
||||
return expenses;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,122 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||
|
||||
public class IncomeRepository : IIncome
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<IncomeRepository> _logger;
|
||||
public IncomeRepository(IConnectionString connectionString, ILogger<IncomeRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateIncome(Income income)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(income));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Income (IncomeType, Name, IncomeCategory)
|
||||
VALUES (@IncomeType, @Name, @IncomeCategory)";
|
||||
connection.Execute(queryInsert, income);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateIncome(Income income)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(income));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Income
|
||||
SET
|
||||
IncomeType=@IncomeType,
|
||||
Name=@Name,
|
||||
IncomeCategory=@IncomeCategory
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, income);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteIncome(int id)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Income
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Income ReadIncomeById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Income
|
||||
WHERE Id=@id";
|
||||
var income = connection.QueryFirst<Income>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(income));
|
||||
return income;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Income> ReadIncome()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Income";
|
||||
var incomes = connection.Query<Income>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(incomes));
|
||||
return incomes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Income ReadIncomeById(int id)
|
||||
{
|
||||
return Income.CreateEntity(0, IncomeExpenseType.None, string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
public void UpdateIncome(Income income)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,106 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||
|
||||
public class PeopleExpenseRepository : IPeopleExpense
|
||||
{
|
||||
public IEnumerable<PeopleExpense> ReadPeopleExpense(DateTime? dateForm = null, DateTime? dateTo = null, int? peopleId = null, int? expenseId = null)
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<PeopleExpenseRepository> _logger;
|
||||
public PeopleExpenseRepository(IConnectionString connectionString, ILogger<PeopleExpenseRepository> logger)
|
||||
{
|
||||
return [];
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreatePeopleExpense(PeopleExpense peopleExpense)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(peopleExpense));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO PeopleExpense (PeopleId, DataReciept)
|
||||
VALUES (@PeopleId, @DataReciept);
|
||||
SELECT MAX(Id) FROM PeopleExpense";
|
||||
var peopleExpenseId =
|
||||
connection.QueryFirst<int>(queryInsert, peopleExpense, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO ExpensePeopleExpense (ExpenseId, PeopleExpenseId, Sum)
|
||||
VALUES (@ExpenseId, @PeopleExpenseId, @Sum)";
|
||||
foreach (var elem in peopleExpense.ExpensePeopleExpenses)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
peopleExpenseId,
|
||||
elem.ExpenseId,
|
||||
elem.Sum
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeletPeopleExpense(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryDeleteSub = @"
|
||||
DELETE FROM ExpensePeopleExpense
|
||||
WHERE PeopleExpenseId = @id";
|
||||
connection.Execute(queryDeleteSub, new { id }, transaction);
|
||||
|
||||
var queryDelete = @"
|
||||
DELETE FROM PeopleExpense
|
||||
WHERE Id = @id";
|
||||
connection.Execute(queryDelete, new { id }, transaction);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<PeopleExpense> ReadPeopleExpense(DateTime? dateForm = null, DateTime? dateTo = null, int? peopleId = null, int? expenseId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM PeopleExpense";
|
||||
var peopleExpenses = connection.Query<PeopleExpense>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(peopleExpenses));
|
||||
return peopleExpenses;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,109 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Windows.Forms;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||
|
||||
public class PeopleIncomeRepository : IPeopleIncome
|
||||
{
|
||||
public IEnumerable<PeopleIncome> ReadPeopleIncome(DateTime? dateForm = null, DateTime? dateTo = null, int? peopleId = null, int? incomeId = null)
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<PeopleIncomeRepository> _logger;
|
||||
|
||||
public PeopleIncomeRepository(IConnectionString connectionString, ILogger<PeopleIncomeRepository> logger)
|
||||
{
|
||||
return [];
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreatePeopleIncome(PeopleIncome peopleIncome)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(peopleIncome));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO PeopleIncome (PeopleId, DataReciept)
|
||||
VALUES (@PeopleId, @DataReciept);
|
||||
SELECT MAX(Id) FROM PeopleIncome";
|
||||
var peopleIncomeId =
|
||||
connection.QueryFirst<int>(queryInsert, peopleIncome, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO IncomePeopleIncome (IncomeId, PeopleIncomeId, Sum)
|
||||
VALUES (@IncomeId, @PeopleIncomeId, @Sum)";
|
||||
foreach (var elem in peopleIncome.IncomePeopleIncomes)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
peopleIncomeId,
|
||||
elem.IncomeId,
|
||||
elem.Sum
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeletPeopleIncome(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryDeleteSub = @"
|
||||
DELETE FROM IncomePeopleIncome
|
||||
WHERE PeopleIncomeId = @id";
|
||||
connection.Execute(queryDeleteSub, new { id }, transaction);
|
||||
|
||||
var queryDelete = @"
|
||||
DELETE FROM PeopleIncome
|
||||
WHERE Id = @id";
|
||||
connection.Execute(queryDelete, new { id }, transaction);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<PeopleIncome> ReadPeopleIncome(DateTime? dateForm = null, DateTime? dateTo = null, int? peopleId = null, int? incomeId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM PeopleIncome";
|
||||
var peopleIncomes = connection.Query<PeopleIncome>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(peopleIncomes));
|
||||
return peopleIncomes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,38 +1,125 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectFamilyBudget.Entities.Enums;
|
||||
using ProjectFamilyBudget.Entities;
|
||||
|
||||
namespace ProjectFamilyBudget.Repositories.Implementations;
|
||||
|
||||
public class PeopleRepository : IPeople
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<PeopleRepository> _logger;
|
||||
public PeopleRepository(IConnectionString connectionString, ILogger<PeopleRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreatePeople(People people)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(people));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO People (Name, LastName, Age, MemberType)
|
||||
VALUES (@Name, @LastName, @Age, @MemberType)";
|
||||
connection.Execute(queryInsert, people);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdatePeople(People people)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}",JsonConvert.SerializeObject(people));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE People
|
||||
SET
|
||||
Name=@Name,
|
||||
LastName=@LastName,
|
||||
Age=@Age,
|
||||
MemberType=@MemberType
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, people);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeletePeople(int id)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM People
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public People ReadPeopleById(int id)
|
||||
{
|
||||
return People.CreateEntity(0, string.Empty, string.Empty, 0, FamilyMemberType.None);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM People
|
||||
WHERE Id=@id";
|
||||
var people = connection.QueryFirst<People>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(people));
|
||||
return people;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<People> ReadPeople()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdatePeople(People people)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM People";
|
||||
var peoples = connection.Query<People>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",JsonConvert.SerializeObject(peoples));
|
||||
return peoples;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
15
ProjectFamilyBudget/ProjectFamilyBudget/appsettings.json
Normal file
15
ProjectFamilyBudget/ProjectFamilyBudget/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/budget_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user