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 MySql.Data.MySqlClient;

namespace sport_invent_modul_14._05
{
    public partial class Form2 : Form
    {
        private DataTable allProducts;
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            try
            {
                var conn = DB.getInstance().getConnection();
                DB.getInstance().OpenConnection();

                string query = @"SELECT 
                                    p.Article,
                                    p.Name,
                                    c.Category,
                                    p.Description,
                                    m.Manufacturer,
                                    s.Supplier,
                                    p.Price,
                                    p.Discount,
                                    p.Quantity,
                                    u.Edinica,
                                    p.Photo
                                FROM Product p
                                LEFT JOIN Category c ON p.CategoryID = c.idCategory
                                LEFT JOIN Manufacturer m ON p.ManufacturerID = m.idManufacturer
                                LEFT JOIN Supplier s ON p.SupplierID = s.idSupplier
                                LEFT JOIN Edinica u ON p.EdinicaID = u.idEdinica";

                MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
                allProducts = new DataTable();
                adapter.Fill(allProducts);

                dataGridView1.DataSource = allProducts;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка при загрузке данных: " + ex.Message);
            }
        }
    }
}
