86 lines
1.8 KiB
C#
86 lines
1.8 KiB
C#
using Database;
|
|
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 Type = Database.Type;
|
|
|
|
namespace View
|
|
{
|
|
public partial class TypesForm : Form
|
|
{
|
|
private Abstracts abstracts;
|
|
public TypesForm(Abstracts abstracts)
|
|
{
|
|
InitializeComponent();
|
|
this.abstracts = abstracts;
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
List<Type> types = abstracts.GetTypes();
|
|
dataGridView1.Rows.Clear();
|
|
if (dataGridView1.Columns.Count == 0)
|
|
{
|
|
dataGridView1.Columns.Add("Id", "Id");
|
|
dataGridView1.Columns.Add("Title", "title");
|
|
}
|
|
|
|
foreach (Type type in types)
|
|
{
|
|
dataGridView1.Rows.Add(type.Id, type.title);
|
|
}
|
|
}
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(TypeForm));
|
|
if (service is TypeForm form)
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonReload_Click(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView1.SelectedRows.Count == 1)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(TypeForm));
|
|
if (service is TypeForm form)
|
|
{
|
|
form.TypeId = 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)
|
|
{
|
|
var i = dataGridView1.CurrentCell.RowIndex;
|
|
var elem = (int)dataGridView1.Rows[i].Cells["Id"].Value;
|
|
|
|
abstracts.DeleteType(elem);
|
|
LoadData();
|
|
}
|
|
}
|
|
}
|
|
}
|