90 lines
1.9 KiB
C#
90 lines
1.9 KiB
C#
|
using Commentbase;
|
|||
|
using Microsoft.VisualBasic;
|
|||
|
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;
|
|||
|
|
|||
|
namespace View
|
|||
|
{
|
|||
|
public partial class FormPhotos : Form
|
|||
|
{
|
|||
|
private readonly Abstracts db;
|
|||
|
public FormPhotos(Abstracts abstracts)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
db = abstracts;
|
|||
|
}
|
|||
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dataGridView1.SelectedRows.Count == 1)
|
|||
|
{
|
|||
|
var service = Program.ServiceProvider?.GetService(typeof(FormPhoto));
|
|||
|
if (service is FormPhoto form)
|
|||
|
{
|
|||
|
form.PhotoId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
|||
|
if (form.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dataGridView1.SelectedRows.Count == 1)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
|||
|
db.DeletePhoto(id);
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void buttonReload_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
|
|||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var service = Program.ServiceProvider?.GetService(typeof(FormPhoto));
|
|||
|
if (service is FormPhoto form)
|
|||
|
{
|
|||
|
if (form.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void FormPhotos_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
private void LoadData()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var list = db.GetPhotos();
|
|||
|
dataGridView1.DataSource = list;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|