SUBD_LAB/SUBD_LABA/View/FormComments.cs

90 lines
1.9 KiB
C#
Raw Permalink Normal View History

2024-05-14 22:32:28 +04:00
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 FormComments : Form
{
private readonly Abstracts db;
public FormComments(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComment));
if (service is FormComment form)
{
form.CommentId = 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.DeleteComment(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(FormComment));
if (service is FormComment form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void DatesForm_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = db.GetComments();
dataGridView1.DataSource = list;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}