2024-11-05 17:54:04 +04:00
|
|
|
|
using ProjectFamilyBudget.Entities;
|
|
|
|
|
using ProjectFamilyBudget.Repositories;
|
2024-11-03 16:04:27 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Unity;
|
|
|
|
|
|
|
|
|
|
namespace ProjectFamilyBudget.Forms
|
|
|
|
|
{
|
2024-11-05 17:54:04 +04:00
|
|
|
|
public partial class FormPeopleIncomes : Form
|
2024-11-03 16:04:27 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly IUnityContainer _container;
|
2024-11-05 17:54:04 +04:00
|
|
|
|
private readonly IPeopleIncome _peopleIncome;
|
|
|
|
|
public FormPeopleIncomes(IUnityContainer container, IPeopleIncome peopleIncome)
|
2024-11-03 16:04:27 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_container = container ??
|
|
|
|
|
throw new ArgumentNullException(nameof(container));
|
2024-11-05 17:54:04 +04:00
|
|
|
|
_peopleIncome = peopleIncome ??
|
|
|
|
|
throw new ArgumentNullException(nameof(peopleIncome));
|
2024-11-03 16:04:27 +04:00
|
|
|
|
}
|
2024-11-05 17:54:04 +04:00
|
|
|
|
private void FormPeopleIncomes_Load(object sender, EventArgs e)
|
2024-11-03 16:04:27 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-11-05 17:54:04 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
2024-11-03 16:04:27 +04:00
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 17:54:04 +04:00
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
2024-11-03 16:04:27 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-05 17:54:04 +04:00
|
|
|
|
_container.Resolve<FormPeopleIncome>().ShowDialog();
|
2024-11-03 16:04:27 +04:00
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-11-05 17:54:04 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
2024-11-03 16:04:27 +04:00
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCansel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить запись?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-05 17:54:04 +04:00
|
|
|
|
_peopleIncome.DeletPeopleIncome(findId);
|
2024-11-03 16:04:27 +04:00
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-16 14:12:58 +04:00
|
|
|
|
private void LoadList() => dataGridViewData.DataSource = _peopleIncome.ReadPeopleIncome();
|
2024-11-03 16:04:27 +04:00
|
|
|
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|
|
|
|
{
|
|
|
|
|
id = 0;
|
|
|
|
|
if (dataGridViewData.SelectedRows.Count < 1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
id =
|
|
|
|
|
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|