using MySql.Data.MySqlClient;
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 ekz_lednev
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form5_Load(object sender, EventArgs e)
        {
            DB dB = DB.GetInstance();
            DataTable dt = new DataTable();
            MySqlDataAdapter adp = new MySqlDataAdapter();
            MySqlCommand cmd = new MySqlCommand($@"
                SELECT * From `product_type`
            ", dB.GetConnection());

            adp.SelectCommand = cmd;
            adp.Fill(dt);
            dataGridView1.DataSource = dt;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Страница работы с доп. информацией");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormNewDop formNewDop = new FormNewDop();
            formNewDop.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FormEditDop formEditDop = new FormEditDop();
            formEditDop.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataGridViewRow dtRow = dataGridView1.SelectedRows[0];
            int id = Convert.ToInt32(dtRow.Cells["id"].Value);

            DB dB = DB.GetInstance();
            MySqlCommand cmd = new MySqlCommand($"DELETE FROM `pozorisp_lednev_ekz`.`product_type` WHERE (`id` = '{id}');", dB.GetConnection());
            cmd.ExecuteNonQuery();

            MessageBox.Show("Удалено!");
            Application.Restart();
        }
    }
}
