2024-05-05 22:00:25 +04:00
|
|
|
|
using Database;
|
|
|
|
|
using System;
|
2024-04-16 22:38:56 +04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace View
|
|
|
|
|
{
|
|
|
|
|
public partial class UsersForm : Form
|
|
|
|
|
{
|
2024-05-05 22:00:25 +04:00
|
|
|
|
private Abstracts db;
|
|
|
|
|
public UsersForm(Abstracts abstracts)
|
2024-04-16 22:38:56 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-05 22:00:25 +04:00
|
|
|
|
db = abstracts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonReload_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView1.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(UserForm));
|
|
|
|
|
if (service is UserForm form)
|
|
|
|
|
{
|
|
|
|
|
form.UserId = id;
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView1.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.DeleteUser(id);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(UserForm));
|
|
|
|
|
if (service is UserForm form)
|
|
|
|
|
{
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView1.ColumnCount == 0)
|
|
|
|
|
{
|
|
|
|
|
dataGridView1.Columns.Add("Id", "Id");
|
|
|
|
|
dataGridView1.Columns.Add("Name", "Name");
|
|
|
|
|
dataGridView1.Columns.Add("Email", "Email");
|
|
|
|
|
dataGridView1.Columns.Add("Birthday", "Birthday");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = db.GetUsers();
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView1.Rows.Clear();
|
|
|
|
|
foreach (var user in list)
|
|
|
|
|
{
|
|
|
|
|
dataGridView1.Rows.Add(user.Id, user.name, user.email, user.birthday);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UsersForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
2024-04-16 22:38:56 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|